aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-02-01 12:51:57 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2018-02-01 12:51:57 -0500
commit5d8515bc232172963a4cef007e97b08c5e4d0533 (patch)
tree13e774dbe2d663ca1fbf2a77933ef8deabd4d507
parentdb5933225f2fe50d3b91ebbba73ed9c3b703b99a (diff)
parent3384e01179eff2b2fe91ba7bcad98ee2be5f87f7 (diff)
Merge tag 'staging-4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging/IIO updates from Greg KH: "Here is the big Staging and IIO driver patches for 4.16-rc1. There is the normal amount of new IIO drivers added, like all releases. The networking IPX and the ncpfs filesystem are moved into the staging tree, as they are on their way out of the kernel due to lack of use anymore. The visorbus subsystem finall has started moving out of the staging tree to the "real" part of the kernel, and the most and fsl-mc codebases are almost ready to move out, that will probably happen for 4.17-rc1 if all goes well. Other than that, there is a bunch of license header cleanups in the tree, along with the normal amount of coding style churn that we all know and love for this codebase. I also got frustrated at the Meltdown/Spectre mess and took it out on the dgnc tty driver, deleting huge chunks of it that were never even being used. Full details of everything is in the shortlog. All of these patches have been in linux-next for a while with no reported issues" * tag 'staging-4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (627 commits) staging: rtlwifi: remove redundant initialization of 'cfg_cmd' staging: rtl8723bs: remove a couple of redundant initializations staging: comedi: reformat lines to 80 chars or less staging: lustre: separate a connection destroy from free struct kib_conn Staging: rtl8723bs: Use !x instead of NULL comparison Staging: rtl8723bs: Remove dead code Staging: rtl8723bs: Change names to conform to the kernel code staging: ccree: Fix missing blank line after declaration staging: rtl8188eu: remove redundant initialization of 'pwrcfgcmd' staging: rtlwifi: remove unused RTLHALMAC_ST and RTLPHYDM_ST staging: fbtft: remove unused FB_TFT_SSD1325 kconfig staging: comedi: dt2811: remove redundant initialization of 'ns' staging: wilc1000: fix alignments to match open parenthesis staging: wilc1000: removed unnecessary defined enums typedef staging: wilc1000: remove unnecessary use of parentheses staging: rtl8192u: remove redundant initialization of 'timeout' staging: sm750fb: fix CamelCase for dispSet var staging: lustre: lnet/selftest: fix compile error on UP build staging: rtl8723bs: hal_com_phycfg: Remove unneeded semicolons staging: rts5208: Fix "seg_no" calculation in reset_ms_card() ...
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio14
-rw-r--r--Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt1
-rw-r--r--Documentation/devicetree/bindings/iio/adc/aspeed_adc.txt4
-rw-r--r--Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt7
-rw-r--r--Documentation/devicetree/bindings/iio/adc/st,stm32-adc.txt24
-rw-r--r--Documentation/devicetree/bindings/iio/health/max30102.txt8
-rw-r--r--Documentation/devicetree/bindings/iio/light/uvis25.txt23
-rw-r--r--MAINTAINERS19
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/iio/accel/bmc150-accel-i2c.c12
-rw-r--r--drivers/iio/accel/da280.c31
-rw-r--r--drivers/iio/accel/kxsd9-i2c.c3
-rw-r--r--drivers/iio/accel/mma8452.c20
-rw-r--r--drivers/iio/accel/st_accel_core.c5
-rw-r--r--drivers/iio/adc/Kconfig3
-rw-r--r--drivers/iio/adc/aspeed_adc.c25
-rw-r--r--drivers/iio/adc/at91-sama5d2_adc.c456
-rw-r--r--drivers/iio/adc/at91_adc.c4
-rw-r--r--drivers/iio/adc/axp288_adc.c20
-rw-r--r--drivers/iio/adc/hx711.c134
-rw-r--r--drivers/iio/adc/ina2xx-adc.c317
-rw-r--r--drivers/iio/adc/meson_saradc.c60
-rw-r--r--drivers/iio/adc/qcom-vadc-common.c4
-rw-r--r--drivers/iio/adc/stm32-adc-core.c14
-rw-r--r--drivers/iio/adc/stm32-adc-core.h14
-rw-r--r--drivers/iio/adc/stm32-adc.c199
-rw-r--r--drivers/iio/adc/ti_am335x_adc.c2
-rw-r--r--drivers/iio/chemical/ccs811.c13
-rw-r--r--drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c2
-rw-r--r--drivers/iio/common/ssp_sensors/ssp.h2
-rw-r--r--drivers/iio/common/ssp_sensors/ssp_dev.c2
-rw-r--r--drivers/iio/common/ssp_sensors/ssp_spi.c5
-rw-r--r--drivers/iio/counter/stm32-lptimer-cnt.c2
-rw-r--r--drivers/iio/dac/mcp4725.c2
-rw-r--r--drivers/iio/dac/stm32-dac-core.c14
-rw-r--r--drivers/iio/dac/stm32-dac-core.h15
-rw-r--r--drivers/iio/dac/stm32-dac.c15
-rw-r--r--drivers/iio/dummy/iio_dummy_evgen.c2
-rw-r--r--drivers/iio/gyro/adis16136.c15
-rw-r--r--drivers/iio/gyro/bmg160_core.c1
-rw-r--r--drivers/iio/health/max30102.c308
-rw-r--r--drivers/iio/humidity/hts221.h3
-rw-r--r--drivers/iio/humidity/hts221_core.c18
-rw-r--r--drivers/iio/humidity/hts221_i2c.c18
-rw-r--r--drivers/iio/humidity/hts221_spi.c18
-rw-r--r--drivers/iio/imu/adis16480.c28
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c3
-rw-r--r--drivers/iio/imu/st_lsm6dsx/Kconfig2
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h39
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c107
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c115
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c55
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c70
-rw-r--r--drivers/iio/industrialio-buffer.c15
-rw-r--r--drivers/iio/industrialio-core.c1
-rw-r--r--drivers/iio/light/Kconfig34
-rw-r--r--drivers/iio/light/Makefile4
-rw-r--r--drivers/iio/light/cros_ec_light_prox.c2
-rw-r--r--drivers/iio/light/st_uvis25.h37
-rw-r--r--drivers/iio/light/st_uvis25_core.c359
-rw-r--r--drivers/iio/light/st_uvis25_i2c.c69
-rw-r--r--drivers/iio/light/st_uvis25_spi.c68
-rw-r--r--drivers/iio/light/zopt2201.c568
-rw-r--r--drivers/iio/magnetometer/ak8975.c1
-rw-r--r--drivers/iio/pressure/bmp280-core.c203
-rw-r--r--drivers/iio/proximity/sx9500.c1
-rw-r--r--drivers/iio/trigger/stm32-lptimer-trigger.c3
-rw-r--r--drivers/iio/trigger/stm32-timer-trigger.c2
-rw-r--r--drivers/staging/Kconfig4
-rw-r--r--drivers/staging/Makefile2
-rw-r--r--drivers/staging/android/ashmem.c37
-rw-r--r--drivers/staging/android/ashmem.h1
-rw-r--r--drivers/staging/android/ion/ion-ioctl.c16
-rw-r--r--drivers/staging/android/ion/ion.c40
-rw-r--r--drivers/staging/android/ion/ion.h16
-rw-r--r--drivers/staging/android/ion/ion_carveout_heap.c11
-rw-r--r--drivers/staging/android/ion/ion_chunk_heap.c11
-rw-r--r--drivers/staging/android/ion/ion_cma_heap.c11
-rw-r--r--drivers/staging/android/ion/ion_heap.c16
-rw-r--r--drivers/staging/android/ion/ion_page_pool.c11
-rw-r--r--drivers/staging/android/ion/ion_system_heap.c13
-rw-r--r--drivers/staging/android/uapi/ashmem.h1
-rw-r--r--drivers/staging/android/uapi/ion.h11
-rw-r--r--drivers/staging/ccree/Documentation/devicetree/bindings/crypto/arm-cryptocell.txt27
-rw-r--r--drivers/staging/ccree/Kconfig2
-rw-r--r--drivers/staging/ccree/Makefile8
-rw-r--r--drivers/staging/ccree/TODO22
-rw-r--r--drivers/staging/ccree/cc_aead.c (renamed from drivers/staging/ccree/ssi_aead.c)1119
-rw-r--r--drivers/staging/ccree/cc_aead.h (renamed from drivers/staging/ccree/ssi_aead.h)56
-rw-r--r--drivers/staging/ccree/cc_buffer_mgr.c (renamed from drivers/staging/ccree/ssi_buffer_mgr.c)1085
-rw-r--r--drivers/staging/ccree/cc_buffer_mgr.h74
-rw-r--r--drivers/staging/ccree/cc_cipher.c (renamed from drivers/staging/ccree/ssi_cipher.c)715
-rw-r--r--drivers/staging/ccree/cc_cipher.h74
-rw-r--r--drivers/staging/ccree/cc_crypto_ctx.h38
-rw-r--r--drivers/staging/ccree/cc_debugfs.c101
-rw-r--r--drivers/staging/ccree/cc_debugfs.h32
-rw-r--r--drivers/staging/ccree/cc_driver.c (renamed from drivers/staging/ccree/ssi_driver.c)346
-rw-r--r--drivers/staging/ccree/cc_driver.h194
-rw-r--r--drivers/staging/ccree/cc_fips.c (renamed from drivers/staging/ccree/ssi_fips.c)45
-rw-r--r--drivers/staging/ccree/cc_fips.h37
-rw-r--r--drivers/staging/ccree/cc_hash.c (renamed from drivers/staging/ccree/ssi_hash.c)1820
-rw-r--r--drivers/staging/ccree/cc_hash.h114
-rw-r--r--drivers/staging/ccree/cc_host_regs.h142
-rw-r--r--drivers/staging/ccree/cc_hw_queue_defs.h40
-rw-r--r--drivers/staging/ccree/cc_ivgen.c (renamed from drivers/staging/ccree/ssi_ivgen.c)139
-rw-r--r--drivers/staging/ccree/cc_ivgen.h55
-rw-r--r--drivers/staging/ccree/cc_kernel_regs.h167
-rw-r--r--drivers/staging/ccree/cc_lli_defs.h19
-rw-r--r--drivers/staging/ccree/cc_pm.c122
-rw-r--r--drivers/staging/ccree/cc_pm.h57
-rw-r--r--drivers/staging/ccree/cc_request_mgr.c713
-rw-r--r--drivers/staging/ccree/cc_request_mgr.h51
-rw-r--r--drivers/staging/ccree/cc_sram_mgr.c (renamed from drivers/staging/ccree/ssi_sram_mgr.c)70
-rw-r--r--drivers/staging/ccree/cc_sram_mgr.h65
-rw-r--r--drivers/staging/ccree/dx_crys_kernel.h180
-rw-r--r--drivers/staging/ccree/dx_host.h155
-rw-r--r--drivers/staging/ccree/dx_reg_common.h26
-rw-r--r--drivers/staging/ccree/hash_defs.h36
-rw-r--r--drivers/staging/ccree/ssi_buffer_mgr.h91
-rw-r--r--drivers/staging/ccree/ssi_cipher.h84
-rw-r--r--drivers/staging/ccree/ssi_config.h36
-rw-r--r--drivers/staging/ccree/ssi_driver.h206
-rw-r--r--drivers/staging/ccree/ssi_fips.h49
-rw-r--r--drivers/staging/ccree/ssi_hash.h103
-rw-r--r--drivers/staging/ccree/ssi_ivgen.h71
-rw-r--r--drivers/staging/ccree/ssi_pm.c145
-rw-r--r--drivers/staging/ccree/ssi_pm.h43
-rw-r--r--drivers/staging/ccree/ssi_request_mgr.c610
-rw-r--r--drivers/staging/ccree/ssi_request_mgr.h60
-rw-r--r--drivers/staging/ccree/ssi_sram_mgr.h79
-rw-r--r--drivers/staging/ccree/ssi_sysfs.c172
-rw-r--r--drivers/staging/ccree/ssi_sysfs.h55
-rw-r--r--drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c13
-rw-r--r--drivers/staging/comedi/comedi.h11
-rw-r--r--drivers/staging/comedi/comedi_buf.c11
-rw-r--r--drivers/staging/comedi/comedi_compat32.c11
-rw-r--r--drivers/staging/comedi/comedi_compat32.h11
-rw-r--r--drivers/staging/comedi/comedi_fops.c11
-rw-r--r--drivers/staging/comedi/comedi_pci.c11
-rw-r--r--drivers/staging/comedi/comedi_pci.h11
-rw-r--r--drivers/staging/comedi/comedi_pcmcia.c11
-rw-r--r--drivers/staging/comedi/comedi_pcmcia.h11
-rw-r--r--drivers/staging/comedi/comedi_usb.c11
-rw-r--r--drivers/staging/comedi/comedi_usb.h11
-rw-r--r--drivers/staging/comedi/comedidev.h51
-rw-r--r--drivers/staging/comedi/comedilib.h11
-rw-r--r--drivers/staging/comedi/drivers.c11
-rw-r--r--drivers/staging/comedi/drivers/8255.c11
-rw-r--r--drivers/staging/comedi/drivers/8255.h11
-rw-r--r--drivers/staging/comedi/drivers/8255_pci.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1032.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1500.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1516.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1564.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_16xx.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_2032.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_2200.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3120.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3501.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3xxx.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_watchdog.c11
-rw-r--r--drivers/staging/comedi/drivers/adl_pci6208.c11
-rw-r--r--drivers/staging/comedi/drivers/adl_pci7x3x.c11
-rw-r--r--drivers/staging/comedi/drivers/adl_pci8164.c11
-rw-r--r--drivers/staging/comedi/drivers/adl_pci9111.c11
-rw-r--r--drivers/staging/comedi/drivers/adl_pci9118.c1
-rw-r--r--drivers/staging/comedi/drivers/adq12b.c11
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1710.c1
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1720.c11
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1723.c11
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1724.c11
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1760.c13
-rw-r--r--drivers/staging/comedi/drivers/adv_pci_dio.c1
-rw-r--r--drivers/staging/comedi/drivers/aio_aio12_8.c11
-rw-r--r--drivers/staging/comedi/drivers/aio_iiro_16.c11
-rw-r--r--drivers/staging/comedi/drivers/amplc_dio200.c11
-rw-r--r--drivers/staging/comedi/drivers/amplc_dio200.h11
-rw-r--r--drivers/staging/comedi/drivers/amplc_dio200_common.c11
-rw-r--r--drivers/staging/comedi/drivers/amplc_dio200_pci.c11
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc236.c11
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc236.h11
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc236_common.c11
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc263.c11
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci224.c11
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci230.c11
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci236.c11
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci263.c11
-rw-r--r--drivers/staging/comedi/drivers/c6xdigio.c11
-rw-r--r--drivers/staging/comedi/drivers/cb_das16_cs.c11
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidas.c11
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidas64.c11
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidda.c11
-rw-r--r--drivers/staging/comedi/drivers/cb_pcimdas.c11
-rw-r--r--drivers/staging/comedi/drivers/cb_pcimdda.c11
-rw-r--r--drivers/staging/comedi/drivers/comedi_8254.c11
-rw-r--r--drivers/staging/comedi/drivers/comedi_8254.h11
-rw-r--r--drivers/staging/comedi/drivers/comedi_8255.c11
-rw-r--r--drivers/staging/comedi/drivers/comedi_bond.c11
-rw-r--r--drivers/staging/comedi/drivers/comedi_isadma.c11
-rw-r--r--drivers/staging/comedi/drivers/comedi_isadma.h11
-rw-r--r--drivers/staging/comedi/drivers/comedi_parport.c11
-rw-r--r--drivers/staging/comedi/drivers/comedi_test.c11
-rw-r--r--drivers/staging/comedi/drivers/contec_pci_dio.c11
-rw-r--r--drivers/staging/comedi/drivers/dac02.c11
-rw-r--r--drivers/staging/comedi/drivers/daqboard2000.c11
-rw-r--r--drivers/staging/comedi/drivers/das08.c11
-rw-r--r--drivers/staging/comedi/drivers/das08.h11
-rw-r--r--drivers/staging/comedi/drivers/das08_cs.c11
-rw-r--r--drivers/staging/comedi/drivers/das08_isa.c11
-rw-r--r--drivers/staging/comedi/drivers/das08_pci.c11
-rw-r--r--drivers/staging/comedi/drivers/das16.c11
-rw-r--r--drivers/staging/comedi/drivers/das16m1.c11
-rw-r--r--drivers/staging/comedi/drivers/das1800.c11
-rw-r--r--drivers/staging/comedi/drivers/das6402.c11
-rw-r--r--drivers/staging/comedi/drivers/das800.c11
-rw-r--r--drivers/staging/comedi/drivers/dmm32at.c11
-rw-r--r--drivers/staging/comedi/drivers/dt2801.c1
-rw-r--r--drivers/staging/comedi/drivers/dt2811.c13
-rw-r--r--drivers/staging/comedi/drivers/dt2814.c11
-rw-r--r--drivers/staging/comedi/drivers/dt2815.c11
-rw-r--r--drivers/staging/comedi/drivers/dt2817.c11
-rw-r--r--drivers/staging/comedi/drivers/dt282x.c11
-rw-r--r--drivers/staging/comedi/drivers/dt3000.c11
-rw-r--r--drivers/staging/comedi/drivers/dt9812.c11
-rw-r--r--drivers/staging/comedi/drivers/dyna_pci10xx.c11
-rw-r--r--drivers/staging/comedi/drivers/fl512.c11
-rw-r--r--drivers/staging/comedi/drivers/gsc_hpdi.c11
-rw-r--r--drivers/staging/comedi/drivers/icp_multi.c11
-rw-r--r--drivers/staging/comedi/drivers/ii_pci20kc.c1
-rw-r--r--drivers/staging/comedi/drivers/jr3_pci.c11
-rw-r--r--drivers/staging/comedi/drivers/ke_counter.c11
-rw-r--r--drivers/staging/comedi/drivers/me4000.c11
-rw-r--r--drivers/staging/comedi/drivers/me_daq.c11
-rw-r--r--drivers/staging/comedi/drivers/mf6x4.c11
-rw-r--r--drivers/staging/comedi/drivers/mite.c11
-rw-r--r--drivers/staging/comedi/drivers/mite.h11
-rw-r--r--drivers/staging/comedi/drivers/mpc624.c11
-rw-r--r--drivers/staging/comedi/drivers/multiq3.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_6527.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_65xx.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_660x.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_670x.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_at_a2150.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_at_ao.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_atmio.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_atmio16d.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_daq_700.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_daq_dio24.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc.h11
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc_common.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc_cs.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc_isadma.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc_pci.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_mio_common.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_mio_cs.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_pcidio.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_pcimio.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_stc.h11
-rw-r--r--drivers/staging/comedi/drivers/ni_tio.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_tio.h11
-rw-r--r--drivers/staging/comedi/drivers/ni_tio_internal.h11
-rw-r--r--drivers/staging/comedi/drivers/ni_tiocmd.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_usb6501.c11
-rw-r--r--drivers/staging/comedi/drivers/pcl711.c11
-rw-r--r--drivers/staging/comedi/drivers/pcl724.c1
-rw-r--r--drivers/staging/comedi/drivers/pcl726.c11
-rw-r--r--drivers/staging/comedi/drivers/pcl730.c1
-rw-r--r--drivers/staging/comedi/drivers/pcl812.c1
-rw-r--r--drivers/staging/comedi/drivers/pcl816.c1
-rw-r--r--drivers/staging/comedi/drivers/pcl818.c1
-rw-r--r--drivers/staging/comedi/drivers/pcm3724.c1
-rw-r--r--drivers/staging/comedi/drivers/pcmad.c11
-rw-r--r--drivers/staging/comedi/drivers/pcmda12.c11
-rw-r--r--drivers/staging/comedi/drivers/pcmmio.c11
-rw-r--r--drivers/staging/comedi/drivers/pcmuio.c11
-rw-r--r--drivers/staging/comedi/drivers/plx9052.h11
-rw-r--r--drivers/staging/comedi/drivers/plx9080.h6
-rw-r--r--drivers/staging/comedi/drivers/rtd520.c11
-rw-r--r--drivers/staging/comedi/drivers/rti800.c11
-rw-r--r--drivers/staging/comedi/drivers/rti802.c11
-rw-r--r--drivers/staging/comedi/drivers/s526.c11
-rw-r--r--drivers/staging/comedi/drivers/s626.c20
-rw-r--r--drivers/staging/comedi/drivers/s626.h11
-rw-r--r--drivers/staging/comedi/drivers/serial2002.c12
-rw-r--r--drivers/staging/comedi/drivers/ssv_dnp.c11
-rw-r--r--drivers/staging/comedi/drivers/usbdux.c14
-rw-r--r--drivers/staging/comedi/drivers/usbduxfast.c11
-rw-r--r--drivers/staging/comedi/drivers/usbduxsigma.c11
-rw-r--r--drivers/staging/comedi/drivers/vmk80xx.c11
-rw-r--r--drivers/staging/comedi/kcomedilib/kcomedilib_main.c11
-rw-r--r--drivers/staging/comedi/proc.c11
-rw-r--r--drivers/staging/comedi/range.c11
-rw-r--r--drivers/staging/dgnc/Makefile3
-rw-r--r--drivers/staging/dgnc/dgnc_cls.c38
-rw-r--r--drivers/staging/dgnc/dgnc_cls.h11
-rw-r--r--drivers/staging/dgnc/dgnc_driver.c160
-rw-r--r--drivers/staging/dgnc/dgnc_driver.h52
-rw-r--r--drivers/staging/dgnc/dgnc_mgmt.c248
-rw-r--r--drivers/staging/dgnc/dgnc_mgmt.h26
-rw-r--r--drivers/staging/dgnc/dgnc_neo.c1690
-rw-r--r--drivers/staging/dgnc/dgnc_neo.h175
-rw-r--r--drivers/staging/dgnc/dgnc_pci.h69
-rw-r--r--drivers/staging/dgnc/dgnc_tty.c20
-rw-r--r--drivers/staging/dgnc/dgnc_tty.h11
-rw-r--r--drivers/staging/dgnc/dgnc_utils.c17
-rw-r--r--drivers/staging/dgnc/dgnc_utils.h7
-rw-r--r--drivers/staging/dgnc/digi.h88
-rw-r--r--drivers/staging/emxx_udc/emxx_udc.c10
-rw-r--r--drivers/staging/emxx_udc/emxx_udc.h10
-rw-r--r--drivers/staging/fbtft/Kconfig6
-rw-r--r--drivers/staging/fbtft/fb_agm1264k-fl.c11
-rw-r--r--drivers/staging/fbtft/fb_bd663474.c11
-rw-r--r--drivers/staging/fbtft/fb_hx8340bn.c11
-rw-r--r--drivers/staging/fbtft/fb_hx8347d.c11
-rw-r--r--drivers/staging/fbtft/fb_hx8353d.c11
-rw-r--r--drivers/staging/fbtft/fb_hx8357d.c11
-rw-r--r--drivers/staging/fbtft/fb_hx8357d.h1
-rw-r--r--drivers/staging/fbtft/fb_ili9163.c11
-rw-r--r--drivers/staging/fbtft/fb_ili9320.c11
-rw-r--r--drivers/staging/fbtft/fb_ili9325.c11
-rw-r--r--drivers/staging/fbtft/fb_ili9340.c11
-rw-r--r--drivers/staging/fbtft/fb_ili9341.c11
-rw-r--r--drivers/staging/fbtft/fb_ili9481.c11
-rw-r--r--drivers/staging/fbtft/fb_ili9486.c11
-rw-r--r--drivers/staging/fbtft/fb_pcd8544.c11
-rw-r--r--drivers/staging/fbtft/fb_ra8875.c11
-rw-r--r--drivers/staging/fbtft/fb_s6d02a1.c11
-rw-r--r--drivers/staging/fbtft/fb_s6d1121.c11
-rw-r--r--drivers/staging/fbtft/fb_sh1106.c11
-rw-r--r--drivers/staging/fbtft/fb_ssd1289.c11
-rw-r--r--drivers/staging/fbtft/fb_ssd1305.c11
-rw-r--r--drivers/staging/fbtft/fb_ssd1306.c11
-rw-r--r--drivers/staging/fbtft/fb_ssd1325.c11
-rw-r--r--drivers/staging/fbtft/fb_ssd1331.c1
-rw-r--r--drivers/staging/fbtft/fb_ssd1351.c1
-rw-r--r--drivers/staging/fbtft/fb_st7735r.c11
-rw-r--r--drivers/staging/fbtft/fb_st7789v.c11
-rw-r--r--drivers/staging/fbtft/fb_tinylcd.c11
-rw-r--r--drivers/staging/fbtft/fb_tls8204.c11
-rw-r--r--drivers/staging/fbtft/fb_uc1611.c11
-rw-r--r--drivers/staging/fbtft/fb_uc1701.c11
-rw-r--r--drivers/staging/fbtft/fb_upd161704.c11
-rw-r--r--drivers/staging/fbtft/fb_watterott.c11
-rw-r--r--drivers/staging/fbtft/fbtft-core.c27
-rw-r--r--drivers/staging/fbtft/fbtft.h15
-rw-r--r--drivers/staging/fbtft/fbtft_device.c11
-rw-r--r--drivers/staging/fbtft/flexfb.c11
-rw-r--r--drivers/staging/fbtft/internal.h16
-rw-r--r--drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c165
-rw-r--r--drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h35
-rw-r--r--drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c1
-rw-r--r--drivers/staging/fsl-mc/Kconfig1
-rw-r--r--drivers/staging/fsl-mc/Makefile1
-rw-r--r--drivers/staging/fsl-mc/README.txt386
-rw-r--r--drivers/staging/fsl-mc/bus/Kconfig3
-rw-r--r--drivers/staging/fsl-mc/bus/Makefile3
-rw-r--r--drivers/staging/fsl-mc/bus/dpbp-cmd.h28
-rw-r--r--drivers/staging/fsl-mc/bus/dpbp.c44
-rw-r--r--drivers/staging/fsl-mc/bus/dpcon-cmd.h34
-rw-r--r--drivers/staging/fsl-mc/bus/dpcon.c115
-rw-r--r--drivers/staging/fsl-mc/bus/dpio/Makefile1
-rw-r--r--drivers/staging/fsl-mc/bus/dpio/dpio-cmd.h28
-rw-r--r--drivers/staging/fsl-mc/bus/dpio/dpio-driver.c27
-rw-r--r--drivers/staging/fsl-mc/bus/dpio/dpio-service.c129
-rw-r--r--drivers/staging/fsl-mc/bus/dpio/dpio.c28
-rw-r--r--drivers/staging/fsl-mc/bus/dpio/dpio.h28
-rw-r--r--drivers/staging/fsl-mc/bus/dpio/qbman-portal.c27
-rw-r--r--drivers/staging/fsl-mc/bus/dpio/qbman-portal.h27
-rw-r--r--drivers/staging/fsl-mc/bus/dpmcp-cmd.h56
-rw-r--r--drivers/staging/fsl-mc/bus/dpmcp.c63
-rw-r--r--drivers/staging/fsl-mc/bus/dpmcp.h60
-rw-r--r--drivers/staging/fsl-mc/bus/dpmng-cmd.h58
-rw-r--r--drivers/staging/fsl-mc/bus/dprc-cmd.h451
-rw-r--r--drivers/staging/fsl-mc/bus/dprc-driver.c82
-rw-r--r--drivers/staging/fsl-mc/bus/dprc.c268
-rw-r--r--drivers/staging/fsl-mc/bus/dprc.h268
-rw-r--r--drivers/staging/fsl-mc/bus/fsl-mc-allocator.c117
-rw-r--r--drivers/staging/fsl-mc/bus/fsl-mc-bus.c112
-rw-r--r--drivers/staging/fsl-mc/bus/fsl-mc-msi.c19
-rw-r--r--drivers/staging/fsl-mc/bus/fsl-mc-private.h379
-rw-r--r--drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c34
-rw-r--r--drivers/staging/fsl-mc/bus/mc-io.c62
-rw-r--r--drivers/staging/fsl-mc/bus/mc-sys.c37
-rw-r--r--drivers/staging/fsl-mc/include/dpaa2-fd.h27
-rw-r--r--drivers/staging/fsl-mc/include/dpaa2-global.h27
-rw-r--r--drivers/staging/fsl-mc/include/dpaa2-io.h33
-rw-r--r--drivers/staging/fsl-mc/include/dpbp.h29
-rw-r--r--drivers/staging/fsl-mc/include/dpcon.h42
-rw-r--r--drivers/staging/fsl-mc/include/mc.h61
-rw-r--r--drivers/staging/fsl-mc/overview.rst404
-rw-r--r--drivers/staging/fwserial/dma_fifo.c11
-rw-r--r--drivers/staging/fwserial/dma_fifo.h11
-rw-r--r--drivers/staging/fwserial/fwserial.c11
-rw-r--r--drivers/staging/greybus/arche-apb-ctrl.c39
-rw-r--r--drivers/staging/greybus/arche-platform.c21
-rw-r--r--drivers/staging/greybus/audio_codec.c23
-rw-r--r--drivers/staging/greybus/audio_codec.h12
-rw-r--r--drivers/staging/greybus/authentication.c2
-rw-r--r--drivers/staging/greybus/camera.c16
-rw-r--r--drivers/staging/gs_fpgaboot/io.h5
-rw-r--r--drivers/staging/iio/adc/ad7192.c2
-rw-r--r--drivers/staging/iio/cdc/ad7152.c25
-rw-r--r--drivers/staging/iio/cdc/ad7746.c17
-rw-r--r--drivers/staging/iio/light/tsl2x7x.c9
-rw-r--r--drivers/staging/iio/trigger/iio-trig-bfin-timer.c19
-rw-r--r--drivers/staging/ipx/Kconfig (renamed from net/ipx/Kconfig)1
-rw-r--r--drivers/staging/ipx/Makefile (renamed from net/ipx/Makefile)0
-rw-r--r--drivers/staging/ipx/TODO4
-rw-r--r--drivers/staging/ipx/af_ipx.c (renamed from net/ipx/af_ipx.c)0
-rw-r--r--drivers/staging/ipx/ipx_proc.c (renamed from net/ipx/ipx_proc.c)0
-rw-r--r--drivers/staging/ipx/ipx_route.c (renamed from net/ipx/ipx_route.c)0
-rw-r--r--drivers/staging/ipx/pe2.c (renamed from net/ipx/pe2.c)0
-rw-r--r--drivers/staging/ipx/sysctl_net_ipx.c (renamed from net/ipx/sysctl_net_ipx.c)0
-rw-r--r--drivers/staging/irda/drivers/pxaficp_ir.c1
-rw-r--r--drivers/staging/irda/net/irlmp.c4
-rw-r--r--drivers/staging/ks7010/ks_wlan_net.c4
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs.h13
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h4
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_private.h130
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_string.h5
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h107
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/linux/linux-cpu.h4
-rw-r--r--drivers/staging/lustre/include/linux/lnet/lib-lnet.h63
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c160
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h2
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c10
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c4
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c61
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c6
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c8
-rw-r--r--drivers/staging/lustre/lnet/libcfs/Makefile2
-rw-r--r--drivers/staging/lustre/lnet/libcfs/fail.c2
-rw-r--r--drivers/staging/lustre/lnet/libcfs/hash.c100
-rw-r--r--drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/libcfs_lock.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/libcfs_mem.c24
-rw-r--r--drivers/staging/lustre/lnet/libcfs/libcfs_string.c32
-rw-r--r--drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c151
-rw-r--r--drivers/staging/lustre/lnet/libcfs/linux/linux-module.c4
-rw-r--r--drivers/staging/lustre/lnet/libcfs/module.c36
-rw-r--r--drivers/staging/lustre/lnet/libcfs/prng.c137
-rw-r--r--drivers/staging/lustre/lnet/libcfs/tracefile.c2
-rw-r--r--drivers/staging/lustre/lnet/libcfs/workitem.c466
-rw-r--r--drivers/staging/lustre/lnet/lnet/api-ni.c36
-rw-r--r--drivers/staging/lustre/lnet/lnet/config.c53
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-eq.c15
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-md.c8
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-me.c10
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-move.c25
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-msg.c20
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-ptl.c8
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-socket.c14
-rw-r--r--drivers/staging/lustre/lnet/lnet/net_fault.c48
-rw-r--r--drivers/staging/lustre/lnet/lnet/nidstrings.c8
-rw-r--r--drivers/staging/lustre/lnet/lnet/peer.c10
-rw-r--r--drivers/staging/lustre/lnet/lnet/router.c60
-rw-r--r--drivers/staging/lustre/lnet/lnet/router_proc.c42
-rw-r--r--drivers/staging/lustre/lnet/selftest/conctl.c191
-rw-r--r--drivers/staging/lustre/lnet/selftest/conrpc.c10
-rw-r--r--drivers/staging/lustre/lnet/selftest/console.c83
-rw-r--r--drivers/staging/lustre/lnet/selftest/framework.c40
-rw-r--r--drivers/staging/lustre/lnet/selftest/module.c48
-rw-r--r--drivers/staging/lustre/lnet/selftest/rpc.c96
-rw-r--r--drivers/staging/lustre/lnet/selftest/selftest.h46
-rw-r--r--drivers/staging/lustre/lustre/fld/fld_cache.c13
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_disk.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_sec.h4
-rw-r--r--drivers/staging/lustre/lustre/include/obd_class.h305
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_extent.c4
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lock.c18
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c14
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_pool.c8
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_request.c12
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_resource.c20
-rw-r--r--drivers/staging/lustre/lustre/llite/dir.c4
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_internal.h2
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_lib.c11
-rw-r--r--drivers/staging/lustre/lustre/llite/super25.c23
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_dev.c2
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_io.c2
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_internal.h12
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_obd.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_object.c2
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_request.c10
-rw-r--r--drivers/staging/lustre/lustre/mgc/mgc_request.c4
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_lock.c9
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_object.c8
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_page.c4
-rw-r--r--drivers/staging/lustre/lustre/obdclass/class_obd.c3
-rw-r--r--drivers/staging/lustre/lustre/obdclass/linux/linux-module.c3
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lprocfs_status.c21
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lu_object.c24
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lustre_handles.c9
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obd_config.c2
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obd_mount.c63
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_request.c4
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/client.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c8
-rw-r--r--drivers/staging/media/imx/imx-media-csi.c8
-rw-r--r--drivers/staging/media/imx/imx-media-fim.c30
-rw-r--r--drivers/staging/media/imx/imx-media.h2
-rw-r--r--drivers/staging/most/Documentation/ABI/sysfs-bus-most.txt313
-rw-r--r--drivers/staging/most/Documentation/driver_usage.txt192
-rw-r--r--drivers/staging/most/Kconfig27
-rw-r--r--drivers/staging/most/Makefile19
-rw-r--r--drivers/staging/most/aim-cdev/Makefile4
-rw-r--r--drivers/staging/most/aim-network/Makefile4
-rw-r--r--drivers/staging/most/aim-sound/Makefile4
-rw-r--r--drivers/staging/most/aim-v4l2/Makefile5
-rw-r--r--drivers/staging/most/cdev/Kconfig (renamed from drivers/staging/most/aim-cdev/Kconfig)6
-rw-r--r--drivers/staging/most/cdev/Makefile4
-rw-r--r--drivers/staging/most/cdev/cdev.c (renamed from drivers/staging/most/aim-cdev/cdev.c)194
-rw-r--r--drivers/staging/most/core.c1603
-rw-r--r--drivers/staging/most/core.h (renamed from drivers/staging/most/mostcore/mostcore.h)77
-rw-r--r--drivers/staging/most/dim2/Kconfig (renamed from drivers/staging/most/hdm-dim2/Kconfig)6
-rw-r--r--drivers/staging/most/dim2/Makefile4
-rw-r--r--drivers/staging/most/dim2/dim2.c (renamed from drivers/staging/most/hdm-dim2/dim2_hdm.c)45
-rw-r--r--drivers/staging/most/dim2/dim2.h (renamed from drivers/staging/most/hdm-dim2/dim2_hdm.h)10
-rw-r--r--drivers/staging/most/dim2/errors.h (renamed from drivers/staging/most/hdm-dim2/dim2_errors.h)10
-rw-r--r--drivers/staging/most/dim2/hal.c (renamed from drivers/staging/most/hdm-dim2/dim2_hal.c)16
-rw-r--r--drivers/staging/most/dim2/hal.h (renamed from drivers/staging/most/hdm-dim2/dim2_hal.h)12
-rw-r--r--drivers/staging/most/dim2/reg.h (renamed from drivers/staging/most/hdm-dim2/dim2_reg.h)10
-rw-r--r--drivers/staging/most/dim2/sysfs.c49
-rw-r--r--drivers/staging/most/dim2/sysfs.h30
-rw-r--r--drivers/staging/most/hdm-dim2/Makefile5
-rw-r--r--drivers/staging/most/hdm-dim2/dim2_sysfs.c115
-rw-r--r--drivers/staging/most/hdm-dim2/dim2_sysfs.h36
-rw-r--r--drivers/staging/most/hdm-i2c/Makefile3
-rw-r--r--drivers/staging/most/hdm-usb/Makefile4
-rw-r--r--drivers/staging/most/i2c/Kconfig (renamed from drivers/staging/most/hdm-i2c/Kconfig)6
-rw-r--r--drivers/staging/most/i2c/Makefile4
-rw-r--r--drivers/staging/most/i2c/i2c.c (renamed from drivers/staging/most/hdm-i2c/hdm_i2c.c)19
-rw-r--r--drivers/staging/most/mostcore/Kconfig14
-rw-r--r--drivers/staging/most/mostcore/Makefile3
-rw-r--r--drivers/staging/most/mostcore/core.c1949
-rw-r--r--drivers/staging/most/net/Kconfig (renamed from drivers/staging/most/aim-network/Kconfig)6
-rw-r--r--drivers/staging/most/net/Makefile4
-rw-r--r--drivers/staging/most/net/net.c (renamed from drivers/staging/most/aim-network/networking.c)71
-rw-r--r--drivers/staging/most/sound/Kconfig (renamed from drivers/staging/most/aim-sound/Kconfig)6
-rw-r--r--drivers/staging/most/sound/Makefile4
-rw-r--r--drivers/staging/most/sound/sound.c (renamed from drivers/staging/most/aim-sound/sound.c)33
-rw-r--r--drivers/staging/most/usb/Kconfig (renamed from drivers/staging/most/hdm-usb/Kconfig)7
-rw-r--r--drivers/staging/most/usb/Makefile4
-rw-r--r--drivers/staging/most/usb/usb.c (renamed from drivers/staging/most/hdm-usb/hdm_usb.c)276
-rw-r--r--drivers/staging/most/video/Kconfig (renamed from drivers/staging/most/aim-v4l2/Kconfig)6
-rw-r--r--drivers/staging/most/video/Makefile4
-rw-r--r--drivers/staging/most/video/video.c (renamed from drivers/staging/most/aim-v4l2/video.c)167
-rw-r--r--drivers/staging/ncpfs/Kconfig (renamed from fs/ncpfs/Kconfig)0
-rw-r--r--drivers/staging/ncpfs/Makefile (renamed from fs/ncpfs/Makefile)0
-rw-r--r--drivers/staging/ncpfs/TODO4
-rw-r--r--drivers/staging/ncpfs/dir.c (renamed from fs/ncpfs/dir.c)0
-rw-r--r--drivers/staging/ncpfs/file.c (renamed from fs/ncpfs/file.c)0
-rw-r--r--drivers/staging/ncpfs/getopt.c (renamed from fs/ncpfs/getopt.c)0
-rw-r--r--drivers/staging/ncpfs/getopt.h (renamed from fs/ncpfs/getopt.h)0
-rw-r--r--drivers/staging/ncpfs/inode.c (renamed from fs/ncpfs/inode.c)3
-rw-r--r--drivers/staging/ncpfs/ioctl.c (renamed from fs/ncpfs/ioctl.c)0
-rw-r--r--drivers/staging/ncpfs/mmap.c (renamed from fs/ncpfs/mmap.c)0
-rw-r--r--drivers/staging/ncpfs/ncp_fs.h (renamed from fs/ncpfs/ncp_fs.h)0
-rw-r--r--drivers/staging/ncpfs/ncp_fs_i.h (renamed from fs/ncpfs/ncp_fs_i.h)0
-rw-r--r--drivers/staging/ncpfs/ncp_fs_sb.h (renamed from fs/ncpfs/ncp_fs_sb.h)0
-rw-r--r--drivers/staging/ncpfs/ncplib_kernel.c (renamed from fs/ncpfs/ncplib_kernel.c)0
-rw-r--r--drivers/staging/ncpfs/ncplib_kernel.h (renamed from fs/ncpfs/ncplib_kernel.h)0
-rw-r--r--drivers/staging/ncpfs/ncpsign_kernel.c (renamed from fs/ncpfs/ncpsign_kernel.c)0
-rw-r--r--drivers/staging/ncpfs/ncpsign_kernel.h (renamed from fs/ncpfs/ncpsign_kernel.h)0
-rw-r--r--drivers/staging/ncpfs/sock.c (renamed from fs/ncpfs/sock.c)0
-rw-r--r--drivers/staging/ncpfs/symlink.c (renamed from fs/ncpfs/symlink.c)0
-rw-r--r--drivers/staging/nvec/nvec-keytable.h14
-rw-r--r--drivers/staging/nvec/nvec.c6
-rw-r--r--drivers/staging/nvec/nvec.h6
-rw-r--r--drivers/staging/nvec/nvec_kbd.c6
-rw-r--r--drivers/staging/nvec/nvec_paz00.c6
-rw-r--r--drivers/staging/nvec/nvec_power.c6
-rw-r--r--drivers/staging/nvec/nvec_ps2.c6
-rw-r--r--drivers/staging/octeon/Makefile4
-rw-r--r--drivers/staging/octeon/ethernet-defines.h5
-rw-r--r--drivers/staging/octeon/ethernet-mdio.c5
-rw-r--r--drivers/staging/octeon/ethernet-mdio.h5
-rw-r--r--drivers/staging/octeon/ethernet-mem.c5
-rw-r--r--drivers/staging/octeon/ethernet-mem.h5
-rw-r--r--drivers/staging/octeon/ethernet-rgmii.c5
-rw-r--r--drivers/staging/octeon/ethernet-rx.c5
-rw-r--r--drivers/staging/octeon/ethernet-rx.h5
-rw-r--r--drivers/staging/octeon/ethernet-sgmii.c5
-rw-r--r--drivers/staging/octeon/ethernet-spi.c5
-rw-r--r--drivers/staging/octeon/ethernet-tx.c5
-rw-r--r--drivers/staging/octeon/ethernet-tx.h5
-rw-r--r--drivers/staging/octeon/ethernet-util.h5
-rw-r--r--drivers/staging/octeon/ethernet.c5
-rw-r--r--drivers/staging/octeon/octeon-ethernet.h5
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon.c30
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon.h30
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon_xo_1.c2
-rw-r--r--drivers/staging/pi433/Documentation/devicetree/pi433-overlay.dts32
-rw-r--r--drivers/staging/pi433/Documentation/pi433.txt18
-rw-r--r--drivers/staging/pi433/pi433_if.c607
-rw-r--r--drivers/staging/pi433/pi433_if.h38
-rw-r--r--drivers/staging/pi433/rf69.c905
-rw-r--r--drivers/staging/pi433/rf69.h37
-rw-r--r--drivers/staging/pi433/rf69_enum.h298
-rw-r--r--drivers/staging/pi433/rf69_registers.h48
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme_ext.c4
-rw-r--r--drivers/staging/rtl8188eu/hal/pwrseqcmd.c2
-rw-r--r--drivers/staging/rtl8192e/rtllib_rx.c1
-rw-r--r--drivers/staging/rtl8192e/rtllib_softmac.c2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/dot11d.c2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c12
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c2
-rw-r--r--drivers/staging/rtl8192u/r8192U_core.c2
-rw-r--r--drivers/staging/rtl8712/hal_init.c1
-rw-r--r--drivers/staging/rtl8712/ieee80211.c6
-rw-r--r--drivers/staging/rtl8712/os_intfs.c5
-rw-r--r--drivers/staging/rtl8712/rtl8712_cmd.c18
-rw-r--r--drivers/staging/rtl8712/rtl8712_recv.c55
-rw-r--r--drivers/staging/rtl8712/rtl8712_xmit.c3
-rw-r--r--drivers/staging/rtl8712/rtl871x_cmd.c36
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_linux.c106
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_set.c72
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.c9
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.h3
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp.c2
-rw-r--r--drivers/staging/rtl8712/rtl871x_security.c44
-rw-r--r--drivers/staging/rtl8712/usb_ops_linux.c2
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_cmd.c4
-rw-r--r--drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c2
-rw-r--r--drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c2
-rw-r--r--drivers/staging/rtl8723bs/hal/hal_com_phycfg.c16
-rw-r--r--drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c2
-rw-r--r--drivers/staging/rtl8723bs/hal/sdio_ops.c768
-rw-r--r--drivers/staging/rtl8723bs/os_dep/ioctl_linux.c4
-rw-r--r--drivers/staging/rtlwifi/Kconfig10
-rw-r--r--drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c20
-rw-r--r--drivers/staging/rtlwifi/cam.c4
-rw-r--r--drivers/staging/rtlwifi/core.c10
-rw-r--r--drivers/staging/rtlwifi/rtl8822be/fw.c2
-rw-r--r--drivers/staging/rtlwifi/wifi.h2
-rw-r--r--drivers/staging/rts5208/ms.c3
-rw-r--r--drivers/staging/rts5208/rtsx.c17
-rw-r--r--drivers/staging/rts5208/rtsx.h2
-rw-r--r--drivers/staging/rts5208/sd.h2
-rw-r--r--drivers/staging/sm750fb/TODO4
-rw-r--r--drivers/staging/sm750fb/ddk750_sii164.c8
-rw-r--r--drivers/staging/sm750fb/ddk750_sii164.h2
-rw-r--r--drivers/staging/sm750fb/sm750_hw.c14
-rw-r--r--drivers/staging/speakup/buffers.c1
-rw-r--r--drivers/staging/speakup/fakekey.c11
-rw-r--r--drivers/staging/speakup/keyhelp.c11
-rw-r--r--drivers/staging/speakup/kobjects.c1
-rw-r--r--drivers/staging/speakup/main.c11
-rw-r--r--drivers/staging/speakup/selection.c9
-rw-r--r--drivers/staging/speakup/serialio.c1
-rw-r--r--drivers/staging/speakup/speakup_acntpc.c10
-rw-r--r--drivers/staging/speakup/speakup_acntsa.c11
-rw-r--r--drivers/staging/speakup/speakup_apollo.c11
-rw-r--r--drivers/staging/speakup/speakup_audptr.c11
-rw-r--r--drivers/staging/speakup/speakup_bns.c11
-rw-r--r--drivers/staging/speakup/speakup_decext.c11
-rw-r--r--drivers/staging/speakup/speakup_decpc.c11
-rw-r--r--drivers/staging/speakup/speakup_dectlk.c11
-rw-r--r--drivers/staging/speakup/speakup_dtlk.c11
-rw-r--r--drivers/staging/speakup/speakup_dummy.c11
-rw-r--r--drivers/staging/speakup/speakup_keypc.c11
-rw-r--r--drivers/staging/speakup/speakup_ltlk.c11
-rw-r--r--drivers/staging/speakup/speakup_soft.c12
-rw-r--r--drivers/staging/speakup/speakup_spkout.c11
-rw-r--r--drivers/staging/speakup/speakup_txprt.c11
-rw-r--r--drivers/staging/speakup/spk_priv.h11
-rw-r--r--drivers/staging/speakup/spk_priv_keyinfo.h11
-rw-r--r--drivers/staging/speakup/spk_ttyio.c1
-rw-r--r--drivers/staging/speakup/synth.c1
-rw-r--r--drivers/staging/speakup/thread.c1
-rw-r--r--drivers/staging/speakup/varhandlers.c1
-rw-r--r--drivers/staging/typec/tcpci.c28
-rw-r--r--drivers/staging/typec/tcpci.h11
-rw-r--r--drivers/staging/unisys/Kconfig4
-rw-r--r--drivers/staging/unisys/Makefile1
-rw-r--r--drivers/staging/unisys/include/iochannel.h15
-rw-r--r--drivers/staging/unisys/include/visorchannel.h189
-rw-r--r--drivers/staging/unisys/visorhba/visorhba_main.c14
-rw-r--r--drivers/staging/unisys/visorinput/ultrainputreport.h11
-rw-r--r--drivers/staging/unisys/visorinput/visorinput.c13
-rw-r--r--drivers/staging/unisys/visornic/visornic_main.c13
-rw-r--r--drivers/staging/vboxvideo/vbox_fb.c2
-rw-r--r--drivers/staging/vboxvideo/vbox_main.c2
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c15
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c15
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c15
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835.c16
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835.h15
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h15
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c61
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h7
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/controls.c5
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/mmal-common.h5
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/mmal-encodings.h5
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/mmal-msg-common.h5
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/mmal-msg-format.h5
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/mmal-msg-port.h5
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/mmal-msg.h5
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/mmal-parameters.h5
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c12
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h5
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c6
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c12
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c9
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c50
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c3
-rw-r--r--drivers/staging/vme/devices/vme_user.c18
-rw-r--r--drivers/staging/vt6655/baseband.c11
-rw-r--r--drivers/staging/vt6655/baseband.h11
-rw-r--r--drivers/staging/vt6655/card.c11
-rw-r--r--drivers/staging/vt6655/card.h11
-rw-r--r--drivers/staging/vt6655/channel.c11
-rw-r--r--drivers/staging/vt6655/channel.h12
-rw-r--r--drivers/staging/vt6655/desc.h11
-rw-r--r--drivers/staging/vt6655/device.h11
-rw-r--r--drivers/staging/vt6655/device_cfg.h11
-rw-r--r--drivers/staging/vt6655/device_main.c19
-rw-r--r--drivers/staging/vt6655/dpc.c11
-rw-r--r--drivers/staging/vt6655/dpc.h11
-rw-r--r--drivers/staging/vt6655/key.c11
-rw-r--r--drivers/staging/vt6655/key.h11
-rw-r--r--drivers/staging/vt6655/mac.c11
-rw-r--r--drivers/staging/vt6655/mac.h11
-rw-r--r--drivers/staging/vt6655/power.c11
-rw-r--r--drivers/staging/vt6655/power.h11
-rw-r--r--drivers/staging/vt6655/rf.c11
-rw-r--r--drivers/staging/vt6655/rf.h11
-rw-r--r--drivers/staging/vt6655/rxtx.c11
-rw-r--r--drivers/staging/vt6655/rxtx.h11
-rw-r--r--drivers/staging/vt6655/srom.c11
-rw-r--r--drivers/staging/vt6655/srom.h11
-rw-r--r--drivers/staging/vt6655/tmacro.h11
-rw-r--r--drivers/staging/vt6655/upc.h11
-rw-r--r--drivers/staging/vt6656/baseband.c12
-rw-r--r--drivers/staging/vt6656/baseband.h12
-rw-r--r--drivers/staging/vt6656/card.c12
-rw-r--r--drivers/staging/vt6656/card.h12
-rw-r--r--drivers/staging/vt6656/channel.c12
-rw-r--r--drivers/staging/vt6656/channel.h12
-rw-r--r--drivers/staging/vt6656/desc.h12
-rw-r--r--drivers/staging/vt6656/device.h12
-rw-r--r--drivers/staging/vt6656/dpc.c12
-rw-r--r--drivers/staging/vt6656/dpc.h12
-rw-r--r--drivers/staging/vt6656/firmware.c12
-rw-r--r--drivers/staging/vt6656/firmware.h12
-rw-r--r--drivers/staging/vt6656/int.c12
-rw-r--r--drivers/staging/vt6656/int.h12
-rw-r--r--drivers/staging/vt6656/key.c12
-rw-r--r--drivers/staging/vt6656/key.h12
-rw-r--r--drivers/staging/vt6656/mac.c12
-rw-r--r--drivers/staging/vt6656/mac.h12
-rw-r--r--drivers/staging/vt6656/main_usb.c17
-rw-r--r--drivers/staging/vt6656/power.c12
-rw-r--r--drivers/staging/vt6656/power.h12
-rw-r--r--drivers/staging/vt6656/rf.c12
-rw-r--r--drivers/staging/vt6656/rf.h12
-rw-r--r--drivers/staging/vt6656/rxtx.c12
-rw-r--r--drivers/staging/vt6656/rxtx.h12
-rw-r--r--drivers/staging/vt6656/usbpipe.c12
-rw-r--r--drivers/staging/vt6656/usbpipe.h12
-rw-r--r--drivers/staging/vt6656/wcmd.c12
-rw-r--r--drivers/staging/vt6656/wcmd.h12
-rw-r--r--drivers/staging/wilc1000/coreconfigurator.c2
-rw-r--r--drivers/staging/wilc1000/host_interface.c40
-rw-r--r--drivers/staging/wilc1000/linux_wlan.c11
-rw-r--r--drivers/staging/wilc1000/wilc_debugfs.c1
-rw-r--r--drivers/staging/wilc1000/wilc_sdio.c5
-rw-r--r--drivers/staging/wilc1000/wilc_spi.c21
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_cfgoperations.c566
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_netdevice.h29
-rw-r--r--drivers/staging/wilc1000/wilc_wlan.c9
-rw-r--r--drivers/staging/wilc1000/wilc_wlan_cfg.c6
-rw-r--r--drivers/staging/wilc1000/wilc_wlan_if.h100
-rw-r--r--drivers/staging/wlan-ng/hfa384x.h1
-rw-r--r--drivers/staging/wlan-ng/hfa384x_usb.c7
-rw-r--r--drivers/staging/wlan-ng/p80211conv.c1
-rw-r--r--drivers/staging/wlan-ng/p80211conv.h1
-rw-r--r--drivers/staging/wlan-ng/p80211hdr.h1
-rw-r--r--drivers/staging/wlan-ng/p80211ioctl.h1
-rw-r--r--drivers/staging/wlan-ng/p80211metadef.h1
-rw-r--r--drivers/staging/wlan-ng/p80211metastruct.h1
-rw-r--r--drivers/staging/wlan-ng/p80211mgmt.h1
-rw-r--r--drivers/staging/wlan-ng/p80211msg.h1
-rw-r--r--drivers/staging/wlan-ng/p80211netdev.c4
-rw-r--r--drivers/staging/wlan-ng/p80211netdev.h1
-rw-r--r--drivers/staging/wlan-ng/p80211req.c1
-rw-r--r--drivers/staging/wlan-ng/p80211req.h1
-rw-r--r--drivers/staging/wlan-ng/p80211types.h1
-rw-r--r--drivers/staging/wlan-ng/p80211wep.c1
-rw-r--r--drivers/staging/wlan-ng/prism2fw.c1
-rw-r--r--drivers/staging/wlan-ng/prism2mgmt.c1
-rw-r--r--drivers/staging/wlan-ng/prism2mgmt.h1
-rw-r--r--drivers/staging/wlan-ng/prism2mib.c1
-rw-r--r--drivers/staging/wlan-ng/prism2sta.c1
-rw-r--r--drivers/staging/xgifb/XGI_main.h13
-rw-r--r--drivers/staging/xgifb/XGI_main_26.c224
-rw-r--r--drivers/staging/xgifb/vb_setmode.c81
-rw-r--r--drivers/staging/xgifb/vb_table.h4
-rw-r--r--drivers/visorbus/Kconfig (renamed from drivers/staging/unisys/visorbus/Kconfig)2
-rw-r--r--drivers/visorbus/Makefile (renamed from drivers/staging/unisys/visorbus/Makefile)2
-rw-r--r--drivers/visorbus/controlvmchannel.h (renamed from drivers/staging/unisys/visorbus/controlvmchannel.h)14
-rw-r--r--drivers/visorbus/vbuschannel.h (renamed from drivers/staging/unisys/visorbus/vbuschannel.h)13
-rw-r--r--drivers/visorbus/visorbus_main.c (renamed from drivers/staging/unisys/visorbus/visorbus_main.c)13
-rw-r--r--drivers/visorbus/visorbus_private.h (renamed from drivers/staging/unisys/visorbus/visorbus_private.h)13
-rw-r--r--drivers/visorbus/visorchannel.c (renamed from drivers/staging/unisys/visorbus/visorchannel.c)13
-rw-r--r--drivers/visorbus/visorchipset.c (renamed from drivers/staging/unisys/visorbus/visorchipset.c)20
-rw-r--r--fs/Kconfig1
-rw-r--r--fs/Makefile1
-rw-r--r--include/linux/iio/iio.h4
-rw-r--r--include/linux/iio/machine.h7
-rw-r--r--include/linux/iio/trigger.h3
-rw-r--r--include/linux/visorbus.h (renamed from drivers/staging/unisys/include/visorbus.h)178
-rw-r--r--kernel/workqueue.c1
-rw-r--r--net/Kconfig1
-rw-r--r--net/Makefile1
819 files changed, 14848 insertions, 22474 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 2e3f919485f4..6a5f34b4d5b9 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -32,7 +32,7 @@ Description:
32 Description of the physical chip / device for device X. 32 Description of the physical chip / device for device X.
33 Typically a part number. 33 Typically a part number.
34 34
35What: /sys/bus/iio/devices/iio:deviceX/timestamp_clock 35What: /sys/bus/iio/devices/iio:deviceX/current_timestamp_clock
36KernelVersion: 4.5 36KernelVersion: 4.5
37Contact: linux-iio@vger.kernel.org 37Contact: linux-iio@vger.kernel.org
38Description: 38Description:
@@ -1290,7 +1290,7 @@ KernelVersion: 3.4
1290Contact: linux-iio@vger.kernel.org 1290Contact: linux-iio@vger.kernel.org
1291Description: 1291Description:
1292 Unit-less light intensity. Modifiers both and ir indicate 1292 Unit-less light intensity. Modifiers both and ir indicate
1293 that measurements contains visible and infrared light 1293 that measurements contain visible and infrared light
1294 components or just infrared light, respectively. Modifier uv indicates 1294 components or just infrared light, respectively. Modifier uv indicates
1295 that measurements contain ultraviolet light components. 1295 that measurements contain ultraviolet light components.
1296 1296
@@ -1413,6 +1413,16 @@ Description:
1413 the available samples after the timeout expires and thus have a 1413 the available samples after the timeout expires and thus have a
1414 maximum delay guarantee. 1414 maximum delay guarantee.
1415 1415
1416What: /sys/bus/iio/devices/iio:deviceX/buffer/data_available
1417KernelVersion: 4.16
1418Contact: linux-iio@vger.kernel.org
1419Description:
1420 A read-only value indicating the bytes of data available in the
1421 buffer. In the case of an output buffer, this indicates the
1422 amount of empty space available to write data to. In the case of
1423 an input buffer, this indicates the amount of data available for
1424 reading.
1425
1416What: /sys/bus/iio/devices/iio:deviceX/buffer/hwfifo_enabled 1426What: /sys/bus/iio/devices/iio:deviceX/buffer/hwfifo_enabled
1417KernelVersion: 4.2 1427KernelVersion: 4.2
1418Contact: linux-iio@vger.kernel.org 1428Contact: linux-iio@vger.kernel.org
diff --git a/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt b/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt
index f413e82c8b83..1e6ee3deb4fa 100644
--- a/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt
@@ -15,7 +15,6 @@ Required properties:
15 - "clkin" for the reference clock (typically XTAL) 15 - "clkin" for the reference clock (typically XTAL)
16 - "core" for the SAR ADC core clock 16 - "core" for the SAR ADC core clock
17 optional clocks: 17 optional clocks:
18 - "sana" for the analog clock
19 - "adc_clk" for the ADC (sampling) clock 18 - "adc_clk" for the ADC (sampling) clock
20 - "adc_sel" for the ADC (sampling) clock mux 19 - "adc_sel" for the ADC (sampling) clock mux
21- vref-supply: the regulator supply for the ADC reference voltage 20- vref-supply: the regulator supply for the ADC reference voltage
diff --git a/Documentation/devicetree/bindings/iio/adc/aspeed_adc.txt b/Documentation/devicetree/bindings/iio/adc/aspeed_adc.txt
index 674e133b7cd7..034fc2ba100e 100644
--- a/Documentation/devicetree/bindings/iio/adc/aspeed_adc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/aspeed_adc.txt
@@ -8,6 +8,7 @@ Required properties:
8- reg: memory window mapping address and length 8- reg: memory window mapping address and length
9- clocks: Input clock used to derive the sample clock. Expected to be the 9- clocks: Input clock used to derive the sample clock. Expected to be the
10 SoC's APB clock. 10 SoC's APB clock.
11- resets: Reset controller phandle
11- #io-channel-cells: Must be set to <1> to indicate channels are selected 12- #io-channel-cells: Must be set to <1> to indicate channels are selected
12 by index. 13 by index.
13 14
@@ -15,6 +16,7 @@ Example:
15 adc@1e6e9000 { 16 adc@1e6e9000 {
16 compatible = "aspeed,ast2400-adc"; 17 compatible = "aspeed,ast2400-adc";
17 reg = <0x1e6e9000 0xb0>; 18 reg = <0x1e6e9000 0xb0>;
18 clocks = <&clk_apb>; 19 clocks = <&syscon ASPEED_CLK_APB>;
20 resets = <&syscon ASPEED_RESET_ADC>;
19 #io-channel-cells = <1>; 21 #io-channel-cells = <1>;
20 }; 22 };
diff --git a/Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt b/Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt
index 552e7a83951d..6469a4cd2a6d 100644
--- a/Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt
@@ -17,6 +17,11 @@ Required properties:
17 This property uses the IRQ edge types values: IRQ_TYPE_EDGE_RISING , 17 This property uses the IRQ edge types values: IRQ_TYPE_EDGE_RISING ,
18 IRQ_TYPE_EDGE_FALLING or IRQ_TYPE_EDGE_BOTH 18 IRQ_TYPE_EDGE_FALLING or IRQ_TYPE_EDGE_BOTH
19 19
20Optional properties:
21 - dmas: Phandle to dma channel for the ADC.
22 - dma-names: Must be "rx" when dmas property is being used.
23 See ../../dma/dma.txt for details.
24
20Example: 25Example:
21 26
22adc: adc@fc030000 { 27adc: adc@fc030000 {
@@ -31,4 +36,6 @@ adc: adc@fc030000 {
31 vddana-supply = <&vdd_3v3_lp_reg>; 36 vddana-supply = <&vdd_3v3_lp_reg>;
32 vref-supply = <&vdd_3v3_lp_reg>; 37 vref-supply = <&vdd_3v3_lp_reg>;
33 atmel,trigger-edge-type = <IRQ_TYPE_EDGE_BOTH>; 38 atmel,trigger-edge-type = <IRQ_TYPE_EDGE_BOTH>;
39 dmas = <&dma0 (AT91_XDMAC_DT_MEM_IF(0) | AT91_XDMAC_DT_PER_IF(1) | AT91_XDMAC_DT_PERID(25))>;
40 dma-names = "rx";
34} 41}
diff --git a/Documentation/devicetree/bindings/iio/adc/st,stm32-adc.txt b/Documentation/devicetree/bindings/iio/adc/st,stm32-adc.txt
index 48bfcaa3ffcd..e8bb8243e92c 100644
--- a/Documentation/devicetree/bindings/iio/adc/st,stm32-adc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/st,stm32-adc.txt
@@ -62,6 +62,15 @@ Required properties:
62- st,adc-channels: List of single-ended channels muxed for this ADC. 62- st,adc-channels: List of single-ended channels muxed for this ADC.
63 It can have up to 16 channels on stm32f4 or 20 channels on stm32h7, numbered 63 It can have up to 16 channels on stm32f4 or 20 channels on stm32h7, numbered
64 from 0 to 15 or 19 (resp. for in0..in15 or in0..in19). 64 from 0 to 15 or 19 (resp. for in0..in15 or in0..in19).
65- st,adc-diff-channels: List of differential channels muxed for this ADC.
66 Depending on part used, some channels can be configured as differential
67 instead of single-ended (e.g. stm32h7). List here positive and negative
68 inputs pairs as <vinp vinn>, <vinp vinn>,... vinp and vinn are numbered
69 from 0 to 19 on stm32h7)
70 Note: At least one of "st,adc-channels" or "st,adc-diff-channels" is required.
71 Both properties can be used together. Some channels can be used as
72 single-ended and some other ones as differential (mixed). But channels
73 can't be configured both as single-ended and differential (invalid).
65- #io-channel-cells = <1>: See the IIO bindings section "IIO consumers" in 74- #io-channel-cells = <1>: See the IIO bindings section "IIO consumers" in
66 Documentation/devicetree/bindings/iio/iio-bindings.txt 75 Documentation/devicetree/bindings/iio/iio-bindings.txt
67 76
@@ -111,3 +120,18 @@ Example:
111 ... 120 ...
112 other adc child nodes follow... 121 other adc child nodes follow...
113 }; 122 };
123
124Example to setup:
125- channel 1 as single-ended
126- channels 2 & 3 as differential (with resp. 6 & 7 negative inputs)
127
128 adc: adc@40022000 {
129 compatible = "st,stm32h7-adc-core";
130 ...
131 adc1: adc@0 {
132 compatible = "st,stm32h7-adc";
133 ...
134 st,adc-channels = <1>;
135 st,adc-diff-channels = <2 6>, <3 7>;
136 };
137 };
diff --git a/Documentation/devicetree/bindings/iio/health/max30102.txt b/Documentation/devicetree/bindings/iio/health/max30102.txt
index 8629c18b0e78..ef2ca0a0306f 100644
--- a/Documentation/devicetree/bindings/iio/health/max30102.txt
+++ b/Documentation/devicetree/bindings/iio/health/max30102.txt
@@ -1,9 +1,11 @@
1Maxim MAX30102 heart rate and pulse oximeter sensor 1Maxim MAX30102 heart rate and pulse oximeter sensor
2Maxim MAX30105 optical particle-sensing module
2 3
3* https://datasheets.maximintegrated.com/en/ds/MAX30102.pdf 4* https://datasheets.maximintegrated.com/en/ds/MAX30102.pdf
5* https://datasheets.maximintegrated.com/en/ds/MAX30105.pdf
4 6
5Required properties: 7Required properties:
6 - compatible: must be "maxim,max30102" 8 - compatible: must be "maxim,max30102" or "maxim,max30105"
7 - reg: the I2C address of the sensor 9 - reg: the I2C address of the sensor
8 - interrupt-parent: should be the phandle for the interrupt controller 10 - interrupt-parent: should be the phandle for the interrupt controller
9 - interrupts: the sole interrupt generated by the device 11 - interrupts: the sole interrupt generated by the device
@@ -12,8 +14,10 @@ Required properties:
12 interrupt client node bindings. 14 interrupt client node bindings.
13 15
14Optional properties: 16Optional properties:
15 - maxim,red-led-current-microamp: configuration for RED LED current 17 - maxim,red-led-current-microamp: configuration for red LED current
16 - maxim,ir-led-current-microamp: configuration for IR LED current 18 - maxim,ir-led-current-microamp: configuration for IR LED current
19 - maxim,green-led-current-microamp: configuration for green LED current
20 (max30105 only)
17 21
18 Note that each step is approximately 200 microamps, ranging from 0 uA to 22 Note that each step is approximately 200 microamps, ranging from 0 uA to
19 50800 uA. 23 50800 uA.
diff --git a/Documentation/devicetree/bindings/iio/light/uvis25.txt b/Documentation/devicetree/bindings/iio/light/uvis25.txt
new file mode 100644
index 000000000000..3041207e3f3c
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/light/uvis25.txt
@@ -0,0 +1,23 @@
1* ST UVIS25 uv sensor
2
3Required properties:
4- compatible: should be "st,uvis25"
5- reg: i2c address of the sensor / spi cs line
6
7Optional properties:
8- interrupt-parent: should be the phandle for the interrupt controller
9- interrupts: interrupt mapping for IRQ. It should be configured with
10 flags IRQ_TYPE_LEVEL_HIGH, IRQ_TYPE_EDGE_RISING, IRQ_TYPE_LEVEL_LOW or
11 IRQ_TYPE_EDGE_FALLING.
12
13 Refer to interrupt-controller/interrupts.txt for generic interrupt
14 client node bindings.
15
16Example:
17
18uvis25@47 {
19 compatible = "st,uvis25";
20 reg = <0x47>;
21 interrupt-parent = <&gpio0>;
22 interrupts = <0 IRQ_TYPE_EDGE_RISING>;
23};
diff --git a/MAINTAINERS b/MAINTAINERS
index 48c7ff07bfdc..64c47587d1d4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -270,6 +270,7 @@ ACCES 104-QUAD-8 IIO DRIVER
270M: William Breathitt Gray <vilhelm.gray@gmail.com> 270M: William Breathitt Gray <vilhelm.gray@gmail.com>
271L: linux-iio@vger.kernel.org 271L: linux-iio@vger.kernel.org
272S: Maintained 272S: Maintained
273F: Documentation/ABI/testing/sysfs-bus-iio-counter-104-quad-8
273F: drivers/iio/counter/104-quad-8.c 274F: drivers/iio/counter/104-quad-8.c
274 275
275ACCES PCI-IDIO-16 GPIO DRIVER 276ACCES PCI-IDIO-16 GPIO DRIVER
@@ -859,6 +860,8 @@ M: Michael Hennerich <Michael.Hennerich@analog.com>
859W: http://wiki.analog.com/ 860W: http://wiki.analog.com/
860W: http://ez.analog.com/community/linux-device-drivers 861W: http://ez.analog.com/community/linux-device-drivers
861S: Supported 862S: Supported
863F: Documentation/ABI/testing/sysfs-bus-iio-frequency-ad9523
864F: Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4350
862F: drivers/iio/*/ad* 865F: drivers/iio/*/ad*
863F: drivers/iio/adc/ltc2497* 866F: drivers/iio/adc/ltc2497*
864X: drivers/iio/*/adjd* 867X: drivers/iio/*/adjd*
@@ -4145,6 +4148,7 @@ DEVANTECH SRF ULTRASONIC RANGER IIO DRIVER
4145M: Andreas Klinger <ak@it-klinger.de> 4148M: Andreas Klinger <ak@it-klinger.de>
4146L: linux-iio@vger.kernel.org 4149L: linux-iio@vger.kernel.org
4147S: Maintained 4150S: Maintained
4151F: Documentation/ABI/testing/sysfs-bus-iio-distance-srf08
4148F: drivers/iio/proximity/srf*.c 4152F: drivers/iio/proximity/srf*.c
4149 4153
4150DEVICE COREDUMP (DEV_COREDUMP) 4154DEVICE COREDUMP (DEV_COREDUMP)
@@ -6850,6 +6854,8 @@ R: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
6850L: linux-iio@vger.kernel.org 6854L: linux-iio@vger.kernel.org
6851T: git git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git 6855T: git git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git
6852S: Maintained 6856S: Maintained
6857F: Documentation/ABI/testing/configfs-iio*
6858F: Documentation/ABI/testing/sysfs-bus-iio*
6853F: Documentation/devicetree/bindings/iio/ 6859F: Documentation/devicetree/bindings/iio/
6854F: drivers/iio/ 6860F: drivers/iio/
6855F: drivers/staging/iio/ 6861F: drivers/staging/iio/
@@ -7331,17 +7337,16 @@ F: drivers/tty/ipwireless/
7331 7337
7332IPX NETWORK LAYER 7338IPX NETWORK LAYER
7333L: netdev@vger.kernel.org 7339L: netdev@vger.kernel.org
7334S: Odd fixes 7340S: Obsolete
7335F: include/net/ipx.h
7336F: include/uapi/linux/ipx.h 7341F: include/uapi/linux/ipx.h
7337F: net/ipx/ 7342F: drivers/staging/ipx/
7338 7343
7339IRDA SUBSYSTEM 7344IRDA SUBSYSTEM
7340M: Samuel Ortiz <samuel@sortiz.org> 7345M: Samuel Ortiz <samuel@sortiz.org>
7341L: irda-users@lists.sourceforge.net (subscribers-only) 7346L: irda-users@lists.sourceforge.net (subscribers-only)
7342L: netdev@vger.kernel.org 7347L: netdev@vger.kernel.org
7343W: http://irda.sourceforge.net/ 7348W: http://irda.sourceforge.net/
7344S: Maintained 7349S: Obsolete
7345T: git git://git.kernel.org/pub/scm/linux/kernel/git/sameo/irda-2.6.git 7350T: git git://git.kernel.org/pub/scm/linux/kernel/git/sameo/irda-2.6.git
7346F: Documentation/networking/irda.txt 7351F: Documentation/networking/irda.txt
7347F: drivers/staging/irda/ 7352F: drivers/staging/irda/
@@ -9408,8 +9413,8 @@ F: drivers/net/ethernet/natsemi/natsemi.c
9408 9413
9409NCP FILESYSTEM 9414NCP FILESYSTEM
9410M: Petr Vandrovec <petr@vandrovec.name> 9415M: Petr Vandrovec <petr@vandrovec.name>
9411S: Odd Fixes 9416S: Obsolete
9412F: fs/ncpfs/ 9417F: drivers/staging/ncpfs/
9413 9418
9414NCR 5380 SCSI DRIVERS 9419NCR 5380 SCSI DRIVERS
9415M: Finn Thain <fthain@telegraphics.com.au> 9420M: Finn Thain <fthain@telegraphics.com.au>
@@ -14119,6 +14124,8 @@ UNISYS S-PAR DRIVERS
14119M: David Kershner <david.kershner@unisys.com> 14124M: David Kershner <david.kershner@unisys.com>
14120L: sparmaintainer@unisys.com (Unisys internal) 14125L: sparmaintainer@unisys.com (Unisys internal)
14121S: Supported 14126S: Supported
14127F: include/linux/visorbus.h
14128F: drivers/visorbus/
14122F: drivers/staging/unisys/ 14129F: drivers/staging/unisys/
14123 14130
14124UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER 14131UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 152744c5ef0f..ef5fb8395d76 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -211,4 +211,6 @@ source "drivers/mux/Kconfig"
211 211
212source "drivers/opp/Kconfig" 212source "drivers/opp/Kconfig"
213 213
214source "drivers/visorbus/Kconfig"
215
214endmenu 216endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index e06f7f633f73..7a2330077e47 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -184,3 +184,4 @@ obj-$(CONFIG_FPGA) += fpga/
184obj-$(CONFIG_FSI) += fsi/ 184obj-$(CONFIG_FSI) += fsi/
185obj-$(CONFIG_TEE) += tee/ 185obj-$(CONFIG_TEE) += tee/
186obj-$(CONFIG_MULTIPLEXER) += mux/ 186obj-$(CONFIG_MULTIPLEXER) += mux/
187obj-$(CONFIG_UNISYS_VISORBUS) += visorbus/
diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c
index f85014fbaa12..8ffc308d5fd0 100644
--- a/drivers/iio/accel/bmc150-accel-i2c.c
+++ b/drivers/iio/accel/bmc150-accel-i2c.c
@@ -81,9 +81,21 @@ static const struct i2c_device_id bmc150_accel_id[] = {
81 81
82MODULE_DEVICE_TABLE(i2c, bmc150_accel_id); 82MODULE_DEVICE_TABLE(i2c, bmc150_accel_id);
83 83
84static const struct of_device_id bmc150_accel_of_match[] = {
85 { .compatible = "bosch,bmc150_accel" },
86 { .compatible = "bosch,bmi055_accel" },
87 { .compatible = "bosch,bma255" },
88 { .compatible = "bosch,bma250e" },
89 { .compatible = "bosch,bma222e" },
90 { .compatible = "bosch,bma280" },
91 { },
92};
93MODULE_DEVICE_TABLE(of, bmc150_accel_of_match);
94
84static struct i2c_driver bmc150_accel_driver = { 95static struct i2c_driver bmc150_accel_driver = {
85 .driver = { 96 .driver = {
86 .name = "bmc150_accel_i2c", 97 .name = "bmc150_accel_i2c",
98 .of_match_table = bmc150_accel_of_match,
87 .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match), 99 .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match),
88 .pm = &bmc150_accel_pm_ops, 100 .pm = &bmc150_accel_pm_ops,
89 }, 101 },
diff --git a/drivers/iio/accel/da280.c b/drivers/iio/accel/da280.c
index 6c214783241c..d4b555203427 100644
--- a/drivers/iio/accel/da280.c
+++ b/drivers/iio/accel/da280.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/acpi.h>
14#include <linux/iio/iio.h> 15#include <linux/iio/iio.h>
15#include <linux/iio/sysfs.h> 16#include <linux/iio/sysfs.h>
16#include <linux/byteorder/generic.h> 17#include <linux/byteorder/generic.h>
@@ -25,7 +26,7 @@
25#define DA280_MODE_ENABLE 0x1e 26#define DA280_MODE_ENABLE 0x1e
26#define DA280_MODE_DISABLE 0x9e 27#define DA280_MODE_DISABLE 0x9e
27 28
28enum { da226, da280 }; 29enum da280_chipset { da226, da280 };
29 30
30/* 31/*
31 * a value of + or -4096 corresponds to + or - 1G 32 * a value of + or -4096 corresponds to + or - 1G
@@ -91,12 +92,24 @@ static const struct iio_info da280_info = {
91 .read_raw = da280_read_raw, 92 .read_raw = da280_read_raw,
92}; 93};
93 94
95static enum da280_chipset da280_match_acpi_device(struct device *dev)
96{
97 const struct acpi_device_id *id;
98
99 id = acpi_match_device(dev->driver->acpi_match_table, dev);
100 if (!id)
101 return -EINVAL;
102
103 return (enum da280_chipset) id->driver_data;
104}
105
94static int da280_probe(struct i2c_client *client, 106static int da280_probe(struct i2c_client *client,
95 const struct i2c_device_id *id) 107 const struct i2c_device_id *id)
96{ 108{
97 int ret; 109 int ret;
98 struct iio_dev *indio_dev; 110 struct iio_dev *indio_dev;
99 struct da280_data *data; 111 struct da280_data *data;
112 enum da280_chipset chip;
100 113
101 ret = i2c_smbus_read_byte_data(client, DA280_REG_CHIP_ID); 114 ret = i2c_smbus_read_byte_data(client, DA280_REG_CHIP_ID);
102 if (ret != DA280_CHIP_ID) 115 if (ret != DA280_CHIP_ID)
@@ -114,7 +127,14 @@ static int da280_probe(struct i2c_client *client,
114 indio_dev->info = &da280_info; 127 indio_dev->info = &da280_info;
115 indio_dev->modes = INDIO_DIRECT_MODE; 128 indio_dev->modes = INDIO_DIRECT_MODE;
116 indio_dev->channels = da280_channels; 129 indio_dev->channels = da280_channels;
117 if (id->driver_data == da226) { 130
131 if (ACPI_HANDLE(&client->dev)) {
132 chip = da280_match_acpi_device(&client->dev);
133 } else {
134 chip = id->driver_data;
135 }
136
137 if (chip == da226) {
118 indio_dev->name = "da226"; 138 indio_dev->name = "da226";
119 indio_dev->num_channels = 2; 139 indio_dev->num_channels = 2;
120 } else { 140 } else {
@@ -158,6 +178,12 @@ static int da280_resume(struct device *dev)
158 178
159static SIMPLE_DEV_PM_OPS(da280_pm_ops, da280_suspend, da280_resume); 179static SIMPLE_DEV_PM_OPS(da280_pm_ops, da280_suspend, da280_resume);
160 180
181static const struct acpi_device_id da280_acpi_match[] = {
182 {"MIRAACC", da280},
183 {},
184};
185MODULE_DEVICE_TABLE(acpi, da280_acpi_match);
186
161static const struct i2c_device_id da280_i2c_id[] = { 187static const struct i2c_device_id da280_i2c_id[] = {
162 { "da226", da226 }, 188 { "da226", da226 },
163 { "da280", da280 }, 189 { "da280", da280 },
@@ -168,6 +194,7 @@ MODULE_DEVICE_TABLE(i2c, da280_i2c_id);
168static struct i2c_driver da280_driver = { 194static struct i2c_driver da280_driver = {
169 .driver = { 195 .driver = {
170 .name = "da280", 196 .name = "da280",
197 .acpi_match_table = ACPI_PTR(da280_acpi_match),
171 .pm = &da280_pm_ops, 198 .pm = &da280_pm_ops,
172 }, 199 },
173 .probe = da280_probe, 200 .probe = da280_probe,
diff --git a/drivers/iio/accel/kxsd9-i2c.c b/drivers/iio/accel/kxsd9-i2c.c
index 98fbb628d5bd..38411e1c155b 100644
--- a/drivers/iio/accel/kxsd9-i2c.c
+++ b/drivers/iio/accel/kxsd9-i2c.c
@@ -63,3 +63,6 @@ static struct i2c_driver kxsd9_i2c_driver = {
63 .id_table = kxsd9_i2c_id, 63 .id_table = kxsd9_i2c_id,
64}; 64};
65module_i2c_driver(kxsd9_i2c_driver); 65module_i2c_driver(kxsd9_i2c_driver);
66
67MODULE_LICENSE("GPL v2");
68MODULE_DESCRIPTION("KXSD9 accelerometer I2C interface");
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index bfd4bc806fc2..7a2da7f9d4dc 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * mma8452.c - Support for following Freescale / NXP 3-axis accelerometers: 3 * mma8452.c - Support for following Freescale / NXP 3-axis accelerometers:
3 * 4 *
@@ -13,9 +14,6 @@
13 * Copyright 2015 Martin Kepplinger <martink@posteo.de> 14 * Copyright 2015 Martin Kepplinger <martink@posteo.de>
14 * Copyright 2014 Peter Meerwald <pmeerw@pmeerw.net> 15 * Copyright 2014 Peter Meerwald <pmeerw@pmeerw.net>
15 * 16 *
16 * This file is subject to the terms and conditions of version 2 of
17 * the GNU General Public License. See the file COPYING in the main
18 * directory of this archive for more details.
19 * 17 *
20 * TODO: orientation events 18 * TODO: orientation events
21 */ 19 */
@@ -135,7 +133,7 @@ struct mma8452_event_regs {
135 u8 ev_count; 133 u8 ev_count;
136}; 134};
137 135
138static const struct mma8452_event_regs ev_regs_accel_falling = { 136static const struct mma8452_event_regs ff_mt_ev_regs = {
139 .ev_cfg = MMA8452_FF_MT_CFG, 137 .ev_cfg = MMA8452_FF_MT_CFG,
140 .ev_cfg_ele = MMA8452_FF_MT_CFG_ELE, 138 .ev_cfg_ele = MMA8452_FF_MT_CFG_ELE,
141 .ev_cfg_chan_shift = MMA8452_FF_MT_CHAN_SHIFT, 139 .ev_cfg_chan_shift = MMA8452_FF_MT_CHAN_SHIFT,
@@ -145,7 +143,7 @@ static const struct mma8452_event_regs ev_regs_accel_falling = {
145 .ev_count = MMA8452_FF_MT_COUNT 143 .ev_count = MMA8452_FF_MT_COUNT
146}; 144};
147 145
148static const struct mma8452_event_regs ev_regs_accel_rising = { 146static const struct mma8452_event_regs trans_ev_regs = {
149 .ev_cfg = MMA8452_TRANSIENT_CFG, 147 .ev_cfg = MMA8452_TRANSIENT_CFG,
150 .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE, 148 .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE,
151 .ev_cfg_chan_shift = MMA8452_TRANSIENT_CHAN_SHIFT, 149 .ev_cfg_chan_shift = MMA8452_TRANSIENT_CHAN_SHIFT,
@@ -284,7 +282,7 @@ static const int mma8452_samp_freq[8][2] = {
284}; 282};
285 283
286/* Datasheet table: step time "Relationship with the ODR" (sample frequency) */ 284/* Datasheet table: step time "Relationship with the ODR" (sample frequency) */
287static const unsigned int mma8452_transient_time_step_us[4][8] = { 285static const unsigned int mma8452_time_step_us[4][8] = {
288 { 1250, 2500, 5000, 10000, 20000, 20000, 20000, 20000 }, /* normal */ 286 { 1250, 2500, 5000, 10000, 20000, 20000, 20000, 20000 }, /* normal */
289 { 1250, 2500, 5000, 10000, 20000, 80000, 80000, 80000 }, /* l p l n */ 287 { 1250, 2500, 5000, 10000, 20000, 80000, 80000, 80000 }, /* l p l n */
290 { 1250, 2500, 2500, 2500, 2500, 2500, 2500, 2500 }, /* high res*/ 288 { 1250, 2500, 2500, 2500, 2500, 2500, 2500, 2500 }, /* high res*/
@@ -777,12 +775,12 @@ static int mma8452_get_event_regs(struct mma8452_data *data,
777 & MMA8452_INT_TRANS) && 775 & MMA8452_INT_TRANS) &&
778 (data->chip_info->enabled_events 776 (data->chip_info->enabled_events
779 & MMA8452_INT_TRANS)) 777 & MMA8452_INT_TRANS))
780 *ev_reg = &ev_regs_accel_rising; 778 *ev_reg = &trans_ev_regs;
781 else 779 else
782 *ev_reg = &ev_regs_accel_falling; 780 *ev_reg = &ff_mt_ev_regs;
783 return 0; 781 return 0;
784 case IIO_EV_DIR_FALLING: 782 case IIO_EV_DIR_FALLING:
785 *ev_reg = &ev_regs_accel_falling; 783 *ev_reg = &ff_mt_ev_regs;
786 return 0; 784 return 0;
787 default: 785 default:
788 return -EINVAL; 786 return -EINVAL;
@@ -826,7 +824,7 @@ static int mma8452_read_event_value(struct iio_dev *indio_dev,
826 if (power_mode < 0) 824 if (power_mode < 0)
827 return power_mode; 825 return power_mode;
828 826
829 us = ret * mma8452_transient_time_step_us[power_mode][ 827 us = ret * mma8452_time_step_us[power_mode][
830 mma8452_get_odr_index(data)]; 828 mma8452_get_odr_index(data)];
831 *val = us / USEC_PER_SEC; 829 *val = us / USEC_PER_SEC;
832 *val2 = us % USEC_PER_SEC; 830 *val2 = us % USEC_PER_SEC;
@@ -883,7 +881,7 @@ static int mma8452_write_event_value(struct iio_dev *indio_dev,
883 return ret; 881 return ret;
884 882
885 steps = (val * USEC_PER_SEC + val2) / 883 steps = (val * USEC_PER_SEC + val2) /
886 mma8452_transient_time_step_us[ret][ 884 mma8452_time_step_us[ret][
887 mma8452_get_odr_index(data)]; 885 mma8452_get_odr_index(data)];
888 886
889 if (steps < 0 || steps > 0xff) 887 if (steps < 0 || steps > 0xff)
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 460aa58e0159..6fe995cf16a6 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -920,8 +920,6 @@ static const struct iio_trigger_ops st_accel_trigger_ops = {
920int st_accel_common_probe(struct iio_dev *indio_dev) 920int st_accel_common_probe(struct iio_dev *indio_dev)
921{ 921{
922 struct st_sensor_data *adata = iio_priv(indio_dev); 922 struct st_sensor_data *adata = iio_priv(indio_dev);
923 struct st_sensors_platform_data *pdata =
924 (struct st_sensors_platform_data *)adata->dev->platform_data;
925 int irq = adata->get_irq_data_ready(indio_dev); 923 int irq = adata->get_irq_data_ready(indio_dev);
926 int err; 924 int err;
927 925
@@ -948,9 +946,6 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
948 &adata->sensor_settings->fs.fs_avl[0]; 946 &adata->sensor_settings->fs.fs_avl[0];
949 adata->odr = adata->sensor_settings->odr.odr_avl[0].hz; 947 adata->odr = adata->sensor_settings->odr.odr_avl[0].hz;
950 948
951 if (!pdata)
952 pdata = (struct st_sensors_platform_data *)&default_accel_pdata;
953
954 err = st_sensors_init_sensor(indio_dev, adata->dev->platform_data); 949 err = st_sensors_init_sensor(indio_dev, adata->dev->platform_data);
955 if (err < 0) 950 if (err < 0)
956 goto st_accel_power_off; 951 goto st_accel_power_off;
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 39e3b345a6c8..72bc2b71765a 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -158,6 +158,7 @@ config AT91_SAMA5D2_ADC
158 tristate "Atmel AT91 SAMA5D2 ADC" 158 tristate "Atmel AT91 SAMA5D2 ADC"
159 depends on ARCH_AT91 || COMPILE_TEST 159 depends on ARCH_AT91 || COMPILE_TEST
160 depends on HAS_IOMEM 160 depends on HAS_IOMEM
161 depends on HAS_DMA
161 select IIO_TRIGGERED_BUFFER 162 select IIO_TRIGGERED_BUFFER
162 help 163 help
163 Say yes here to build support for Atmel SAMA5D2 ADC which is 164 Say yes here to build support for Atmel SAMA5D2 ADC which is
@@ -318,6 +319,8 @@ config HI8435
318config HX711 319config HX711
319 tristate "AVIA HX711 ADC for weight cells" 320 tristate "AVIA HX711 ADC for weight cells"
320 depends on GPIOLIB 321 depends on GPIOLIB
322 select IIO_BUFFER
323 select IIO_TRIGGERED_BUFFER
321 help 324 help
322 If you say yes here you get support for AVIA HX711 ADC which is used 325 If you say yes here you get support for AVIA HX711 ADC which is used
323 for weigh cells 326 for weigh cells
diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c
index 8a958d5f1905..327a49ba1991 100644
--- a/drivers/iio/adc/aspeed_adc.c
+++ b/drivers/iio/adc/aspeed_adc.c
@@ -17,6 +17,7 @@
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/of_platform.h> 18#include <linux/of_platform.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/reset.h>
20#include <linux/spinlock.h> 21#include <linux/spinlock.h>
21#include <linux/types.h> 22#include <linux/types.h>
22 23
@@ -53,11 +54,12 @@ struct aspeed_adc_model_data {
53}; 54};
54 55
55struct aspeed_adc_data { 56struct aspeed_adc_data {
56 struct device *dev; 57 struct device *dev;
57 void __iomem *base; 58 void __iomem *base;
58 spinlock_t clk_lock; 59 spinlock_t clk_lock;
59 struct clk_hw *clk_prescaler; 60 struct clk_hw *clk_prescaler;
60 struct clk_hw *clk_scaler; 61 struct clk_hw *clk_scaler;
62 struct reset_control *rst;
61}; 63};
62 64
63#define ASPEED_CHAN(_idx, _data_reg_addr) { \ 65#define ASPEED_CHAN(_idx, _data_reg_addr) { \
@@ -217,6 +219,15 @@ static int aspeed_adc_probe(struct platform_device *pdev)
217 goto scaler_error; 219 goto scaler_error;
218 } 220 }
219 221
222 data->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
223 if (IS_ERR(data->rst)) {
224 dev_err(&pdev->dev,
225 "invalid or missing reset controller device tree entry");
226 ret = PTR_ERR(data->rst);
227 goto reset_error;
228 }
229 reset_control_deassert(data->rst);
230
220 model_data = of_device_get_match_data(&pdev->dev); 231 model_data = of_device_get_match_data(&pdev->dev);
221 232
222 if (model_data->wait_init_sequence) { 233 if (model_data->wait_init_sequence) {
@@ -263,9 +274,10 @@ iio_register_error:
263 writel(ASPEED_OPERATION_MODE_POWER_DOWN, 274 writel(ASPEED_OPERATION_MODE_POWER_DOWN,
264 data->base + ASPEED_REG_ENGINE_CONTROL); 275 data->base + ASPEED_REG_ENGINE_CONTROL);
265 clk_disable_unprepare(data->clk_scaler->clk); 276 clk_disable_unprepare(data->clk_scaler->clk);
277reset_error:
278 reset_control_assert(data->rst);
266clk_enable_error: 279clk_enable_error:
267 clk_hw_unregister_divider(data->clk_scaler); 280 clk_hw_unregister_divider(data->clk_scaler);
268
269scaler_error: 281scaler_error:
270 clk_hw_unregister_divider(data->clk_prescaler); 282 clk_hw_unregister_divider(data->clk_prescaler);
271 return ret; 283 return ret;
@@ -280,6 +292,7 @@ static int aspeed_adc_remove(struct platform_device *pdev)
280 writel(ASPEED_OPERATION_MODE_POWER_DOWN, 292 writel(ASPEED_OPERATION_MODE_POWER_DOWN,
281 data->base + ASPEED_REG_ENGINE_CONTROL); 293 data->base + ASPEED_REG_ENGINE_CONTROL);
282 clk_disable_unprepare(data->clk_scaler->clk); 294 clk_disable_unprepare(data->clk_scaler->clk);
295 reset_control_assert(data->rst);
283 clk_hw_unregister_divider(data->clk_scaler); 296 clk_hw_unregister_divider(data->clk_scaler);
284 clk_hw_unregister_divider(data->clk_prescaler); 297 clk_hw_unregister_divider(data->clk_prescaler);
285 298
diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
index 755a493c2a2c..4eff8351ce29 100644
--- a/drivers/iio/adc/at91-sama5d2_adc.c
+++ b/drivers/iio/adc/at91-sama5d2_adc.c
@@ -16,6 +16,8 @@
16 16
17#include <linux/bitops.h> 17#include <linux/bitops.h>
18#include <linux/clk.h> 18#include <linux/clk.h>
19#include <linux/dma-mapping.h>
20#include <linux/dmaengine.h>
19#include <linux/interrupt.h> 21#include <linux/interrupt.h>
20#include <linux/io.h> 22#include <linux/io.h>
21#include <linux/module.h> 23#include <linux/module.h>
@@ -100,6 +102,8 @@
100#define AT91_SAMA5D2_LCDR 0x20 102#define AT91_SAMA5D2_LCDR 0x20
101/* Interrupt Enable Register */ 103/* Interrupt Enable Register */
102#define AT91_SAMA5D2_IER 0x24 104#define AT91_SAMA5D2_IER 0x24
105/* Interrupt Enable Register - general overrun error */
106#define AT91_SAMA5D2_IER_GOVRE BIT(25)
103/* Interrupt Disable Register */ 107/* Interrupt Disable Register */
104#define AT91_SAMA5D2_IDR 0x28 108#define AT91_SAMA5D2_IDR 0x28
105/* Interrupt Mask Register */ 109/* Interrupt Mask Register */
@@ -167,13 +171,19 @@
167 171
168/* 172/*
169 * Maximum number of bytes to hold conversion from all channels 173 * Maximum number of bytes to hold conversion from all channels
170 * plus the timestamp 174 * without the timestamp.
171 */ 175 */
172#define AT91_BUFFER_MAX_BYTES ((AT91_SAMA5D2_SINGLE_CHAN_CNT + \ 176#define AT91_BUFFER_MAX_CONVERSION_BYTES ((AT91_SAMA5D2_SINGLE_CHAN_CNT + \
173 AT91_SAMA5D2_DIFF_CHAN_CNT) * 2 + 8) 177 AT91_SAMA5D2_DIFF_CHAN_CNT) * 2)
178
179/* This total must also include the timestamp */
180#define AT91_BUFFER_MAX_BYTES (AT91_BUFFER_MAX_CONVERSION_BYTES + 8)
174 181
175#define AT91_BUFFER_MAX_HWORDS (AT91_BUFFER_MAX_BYTES / 2) 182#define AT91_BUFFER_MAX_HWORDS (AT91_BUFFER_MAX_BYTES / 2)
176 183
184#define AT91_HWFIFO_MAX_SIZE_STR "128"
185#define AT91_HWFIFO_MAX_SIZE 128
186
177#define AT91_SAMA5D2_CHAN_SINGLE(num, addr) \ 187#define AT91_SAMA5D2_CHAN_SINGLE(num, addr) \
178 { \ 188 { \
179 .type = IIO_VOLTAGE, \ 189 .type = IIO_VOLTAGE, \
@@ -228,6 +238,28 @@ struct at91_adc_trigger {
228 bool hw_trig; 238 bool hw_trig;
229}; 239};
230 240
241/**
242 * at91_adc_dma - at91-sama5d2 dma information struct
243 * @dma_chan: the dma channel acquired
244 * @rx_buf: dma coherent allocated area
245 * @rx_dma_buf: dma handler for the buffer
246 * @phys_addr: physical address of the ADC base register
247 * @buf_idx: index inside the dma buffer where reading was last done
248 * @rx_buf_sz: size of buffer used by DMA operation
249 * @watermark: number of conversions to copy before DMA triggers irq
250 * @dma_ts: hold the start timestamp of dma operation
251 */
252struct at91_adc_dma {
253 struct dma_chan *dma_chan;
254 u8 *rx_buf;
255 dma_addr_t rx_dma_buf;
256 phys_addr_t phys_addr;
257 int buf_idx;
258 int rx_buf_sz;
259 int watermark;
260 s64 dma_ts;
261};
262
231struct at91_adc_state { 263struct at91_adc_state {
232 void __iomem *base; 264 void __iomem *base;
233 int irq; 265 int irq;
@@ -242,6 +274,7 @@ struct at91_adc_state {
242 u32 conversion_value; 274 u32 conversion_value;
243 struct at91_adc_soc_info soc_info; 275 struct at91_adc_soc_info soc_info;
244 wait_queue_head_t wq_data_available; 276 wait_queue_head_t wq_data_available;
277 struct at91_adc_dma dma_st;
245 u16 buffer[AT91_BUFFER_MAX_HWORDS]; 278 u16 buffer[AT91_BUFFER_MAX_HWORDS];
246 /* 279 /*
247 * lock to prevent concurrent 'single conversion' requests through 280 * lock to prevent concurrent 'single conversion' requests through
@@ -322,11 +355,17 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state)
322 if (state) { 355 if (state) {
323 at91_adc_writel(st, AT91_SAMA5D2_CHER, 356 at91_adc_writel(st, AT91_SAMA5D2_CHER,
324 BIT(chan->channel)); 357 BIT(chan->channel));
325 at91_adc_writel(st, AT91_SAMA5D2_IER, 358 /* enable irq only if not using DMA */
326 BIT(chan->channel)); 359 if (!st->dma_st.dma_chan) {
360 at91_adc_writel(st, AT91_SAMA5D2_IER,
361 BIT(chan->channel));
362 }
327 } else { 363 } else {
328 at91_adc_writel(st, AT91_SAMA5D2_IDR, 364 /* disable irq only if not using DMA */
329 BIT(chan->channel)); 365 if (!st->dma_st.dma_chan) {
366 at91_adc_writel(st, AT91_SAMA5D2_IDR,
367 BIT(chan->channel));
368 }
330 at91_adc_writel(st, AT91_SAMA5D2_CHDR, 369 at91_adc_writel(st, AT91_SAMA5D2_CHDR,
331 BIT(chan->channel)); 370 BIT(chan->channel));
332 } 371 }
@@ -340,6 +379,10 @@ static int at91_adc_reenable_trigger(struct iio_trigger *trig)
340 struct iio_dev *indio = iio_trigger_get_drvdata(trig); 379 struct iio_dev *indio = iio_trigger_get_drvdata(trig);
341 struct at91_adc_state *st = iio_priv(indio); 380 struct at91_adc_state *st = iio_priv(indio);
342 381
382 /* if we are using DMA, we must not reenable irq after each trigger */
383 if (st->dma_st.dma_chan)
384 return 0;
385
343 enable_irq(st->irq); 386 enable_irq(st->irq);
344 387
345 /* Needed to ACK the DRDY interruption */ 388 /* Needed to ACK the DRDY interruption */
@@ -350,6 +393,153 @@ static int at91_adc_reenable_trigger(struct iio_trigger *trig)
350static const struct iio_trigger_ops at91_adc_trigger_ops = { 393static const struct iio_trigger_ops at91_adc_trigger_ops = {
351 .set_trigger_state = &at91_adc_configure_trigger, 394 .set_trigger_state = &at91_adc_configure_trigger,
352 .try_reenable = &at91_adc_reenable_trigger, 395 .try_reenable = &at91_adc_reenable_trigger,
396 .validate_device = iio_trigger_validate_own_device,
397};
398
399static int at91_adc_dma_size_done(struct at91_adc_state *st)
400{
401 struct dma_tx_state state;
402 enum dma_status status;
403 int i, size;
404
405 status = dmaengine_tx_status(st->dma_st.dma_chan,
406 st->dma_st.dma_chan->cookie,
407 &state);
408 if (status != DMA_IN_PROGRESS)
409 return 0;
410
411 /* Transferred length is size in bytes from end of buffer */
412 i = st->dma_st.rx_buf_sz - state.residue;
413
414 /* Return available bytes */
415 if (i >= st->dma_st.buf_idx)
416 size = i - st->dma_st.buf_idx;
417 else
418 size = st->dma_st.rx_buf_sz + i - st->dma_st.buf_idx;
419 return size;
420}
421
422static void at91_dma_buffer_done(void *data)
423{
424 struct iio_dev *indio_dev = data;
425
426 iio_trigger_poll_chained(indio_dev->trig);
427}
428
429static int at91_adc_dma_start(struct iio_dev *indio_dev)
430{
431 struct at91_adc_state *st = iio_priv(indio_dev);
432 struct dma_async_tx_descriptor *desc;
433 dma_cookie_t cookie;
434 int ret;
435 u8 bit;
436
437 if (!st->dma_st.dma_chan)
438 return 0;
439
440 /* we start a new DMA, so set buffer index to start */
441 st->dma_st.buf_idx = 0;
442
443 /*
444 * compute buffer size w.r.t. watermark and enabled channels.
445 * scan_bytes is aligned so we need an exact size for DMA
446 */
447 st->dma_st.rx_buf_sz = 0;
448
449 for_each_set_bit(bit, indio_dev->active_scan_mask,
450 indio_dev->num_channels) {
451 struct iio_chan_spec const *chan = indio_dev->channels + bit;
452
453 st->dma_st.rx_buf_sz += chan->scan_type.storagebits / 8;
454 }
455 st->dma_st.rx_buf_sz *= st->dma_st.watermark;
456
457 /* Prepare a DMA cyclic transaction */
458 desc = dmaengine_prep_dma_cyclic(st->dma_st.dma_chan,
459 st->dma_st.rx_dma_buf,
460 st->dma_st.rx_buf_sz,
461 st->dma_st.rx_buf_sz / 2,
462 DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
463
464 if (!desc) {
465 dev_err(&indio_dev->dev, "cannot prepare DMA cyclic\n");
466 return -EBUSY;
467 }
468
469 desc->callback = at91_dma_buffer_done;
470 desc->callback_param = indio_dev;
471
472 cookie = dmaengine_submit(desc);
473 ret = dma_submit_error(cookie);
474 if (ret) {
475 dev_err(&indio_dev->dev, "cannot submit DMA cyclic\n");
476 dmaengine_terminate_async(st->dma_st.dma_chan);
477 return ret;
478 }
479
480 /* enable general overrun error signaling */
481 at91_adc_writel(st, AT91_SAMA5D2_IER, AT91_SAMA5D2_IER_GOVRE);
482 /* Issue pending DMA requests */
483 dma_async_issue_pending(st->dma_st.dma_chan);
484
485 /* consider current time as DMA start time for timestamps */
486 st->dma_st.dma_ts = iio_get_time_ns(indio_dev);
487
488 dev_dbg(&indio_dev->dev, "DMA cyclic started\n");
489
490 return 0;
491}
492
493static int at91_adc_buffer_postenable(struct iio_dev *indio_dev)
494{
495 int ret;
496
497 ret = at91_adc_dma_start(indio_dev);
498 if (ret) {
499 dev_err(&indio_dev->dev, "buffer postenable failed\n");
500 return ret;
501 }
502
503 return iio_triggered_buffer_postenable(indio_dev);
504}
505
506static int at91_adc_buffer_predisable(struct iio_dev *indio_dev)
507{
508 struct at91_adc_state *st = iio_priv(indio_dev);
509 int ret;
510 u8 bit;
511
512 ret = iio_triggered_buffer_predisable(indio_dev);
513 if (ret < 0)
514 dev_err(&indio_dev->dev, "buffer predisable failed\n");
515
516 if (!st->dma_st.dma_chan)
517 return ret;
518
519 /* if we are using DMA we must clear registers and end DMA */
520 dmaengine_terminate_sync(st->dma_st.dma_chan);
521
522 /*
523 * For each enabled channel we must read the last converted value
524 * to clear EOC status and not get a possible interrupt later.
525 * This value is being read by DMA from LCDR anyway
526 */
527 for_each_set_bit(bit, indio_dev->active_scan_mask,
528 indio_dev->num_channels) {
529 struct iio_chan_spec const *chan = indio_dev->channels + bit;
530
531 if (st->dma_st.dma_chan)
532 at91_adc_readl(st, chan->address);
533 }
534
535 /* read overflow register to clear possible overflow status */
536 at91_adc_readl(st, AT91_SAMA5D2_OVER);
537 return ret;
538}
539
540static const struct iio_buffer_setup_ops at91_buffer_setup_ops = {
541 .postenable = &at91_adc_buffer_postenable,
542 .predisable = &at91_adc_buffer_predisable,
353}; 543};
354 544
355static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *indio, 545static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *indio,
@@ -388,24 +578,77 @@ static int at91_adc_trigger_init(struct iio_dev *indio)
388 return 0; 578 return 0;
389} 579}
390 580
391static irqreturn_t at91_adc_trigger_handler(int irq, void *p) 581static void at91_adc_trigger_handler_nodma(struct iio_dev *indio_dev,
582 struct iio_poll_func *pf)
392{ 583{
393 struct iio_poll_func *pf = p; 584 struct at91_adc_state *st = iio_priv(indio_dev);
394 struct iio_dev *indio = pf->indio_dev;
395 struct at91_adc_state *st = iio_priv(indio);
396 int i = 0; 585 int i = 0;
397 u8 bit; 586 u8 bit;
398 587
399 for_each_set_bit(bit, indio->active_scan_mask, indio->num_channels) { 588 for_each_set_bit(bit, indio_dev->active_scan_mask,
400 struct iio_chan_spec const *chan = indio->channels + bit; 589 indio_dev->num_channels) {
590 struct iio_chan_spec const *chan = indio_dev->channels + bit;
401 591
402 st->buffer[i] = at91_adc_readl(st, chan->address); 592 st->buffer[i] = at91_adc_readl(st, chan->address);
403 i++; 593 i++;
404 } 594 }
595 iio_push_to_buffers_with_timestamp(indio_dev, st->buffer,
596 pf->timestamp);
597}
405 598
406 iio_push_to_buffers_with_timestamp(indio, st->buffer, pf->timestamp); 599static void at91_adc_trigger_handler_dma(struct iio_dev *indio_dev)
600{
601 struct at91_adc_state *st = iio_priv(indio_dev);
602 int transferred_len = at91_adc_dma_size_done(st);
603 s64 ns = iio_get_time_ns(indio_dev);
604 s64 interval;
605 int sample_index = 0, sample_count, sample_size;
606
607 u32 status = at91_adc_readl(st, AT91_SAMA5D2_ISR);
608 /* if we reached this point, we cannot sample faster */
609 if (status & AT91_SAMA5D2_IER_GOVRE)
610 pr_info_ratelimited("%s: conversion overrun detected\n",
611 indio_dev->name);
407 612
408 iio_trigger_notify_done(indio->trig); 613 sample_size = div_s64(st->dma_st.rx_buf_sz, st->dma_st.watermark);
614
615 sample_count = div_s64(transferred_len, sample_size);
616
617 /*
618 * interval between samples is total time since last transfer handling
619 * divided by the number of samples (total size divided by sample size)
620 */
621 interval = div_s64((ns - st->dma_st.dma_ts), sample_count);
622
623 while (transferred_len >= sample_size) {
624 iio_push_to_buffers_with_timestamp(indio_dev,
625 (st->dma_st.rx_buf + st->dma_st.buf_idx),
626 (st->dma_st.dma_ts + interval * sample_index));
627 /* adjust remaining length */
628 transferred_len -= sample_size;
629 /* adjust buffer index */
630 st->dma_st.buf_idx += sample_size;
631 /* in case of reaching end of buffer, reset index */
632 if (st->dma_st.buf_idx >= st->dma_st.rx_buf_sz)
633 st->dma_st.buf_idx = 0;
634 sample_index++;
635 }
636 /* adjust saved time for next transfer handling */
637 st->dma_st.dma_ts = iio_get_time_ns(indio_dev);
638}
639
640static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
641{
642 struct iio_poll_func *pf = p;
643 struct iio_dev *indio_dev = pf->indio_dev;
644 struct at91_adc_state *st = iio_priv(indio_dev);
645
646 if (st->dma_st.dma_chan)
647 at91_adc_trigger_handler_dma(indio_dev);
648 else
649 at91_adc_trigger_handler_nodma(indio_dev, pf);
650
651 iio_trigger_notify_done(indio_dev->trig);
409 652
410 return IRQ_HANDLED; 653 return IRQ_HANDLED;
411} 654}
@@ -414,7 +657,7 @@ static int at91_adc_buffer_init(struct iio_dev *indio)
414{ 657{
415 return devm_iio_triggered_buffer_setup(&indio->dev, indio, 658 return devm_iio_triggered_buffer_setup(&indio->dev, indio,
416 &iio_pollfunc_store_time, 659 &iio_pollfunc_store_time,
417 &at91_adc_trigger_handler, NULL); 660 &at91_adc_trigger_handler, &at91_buffer_setup_ops);
418} 661}
419 662
420static unsigned at91_adc_startup_time(unsigned startup_time_min, 663static unsigned at91_adc_startup_time(unsigned startup_time_min,
@@ -485,10 +728,13 @@ static irqreturn_t at91_adc_interrupt(int irq, void *private)
485 if (!(status & imr)) 728 if (!(status & imr))
486 return IRQ_NONE; 729 return IRQ_NONE;
487 730
488 if (iio_buffer_enabled(indio)) { 731 if (iio_buffer_enabled(indio) && !st->dma_st.dma_chan) {
489 disable_irq_nosync(irq); 732 disable_irq_nosync(irq);
490 iio_trigger_poll(indio->trig); 733 iio_trigger_poll(indio->trig);
491 } else { 734 } else if (iio_buffer_enabled(indio) && st->dma_st.dma_chan) {
735 disable_irq_nosync(irq);
736 WARN(true, "Unexpected irq occurred\n");
737 } else if (!iio_buffer_enabled(indio)) {
492 st->conversion_value = at91_adc_readl(st, st->chan->address); 738 st->conversion_value = at91_adc_readl(st, st->chan->address);
493 st->conversion_done = true; 739 st->conversion_done = true;
494 wake_up_interruptible(&st->wq_data_available); 740 wake_up_interruptible(&st->wq_data_available);
@@ -510,7 +756,6 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev,
510 ret = iio_device_claim_direct_mode(indio_dev); 756 ret = iio_device_claim_direct_mode(indio_dev);
511 if (ret) 757 if (ret)
512 return ret; 758 return ret;
513
514 mutex_lock(&st->lock); 759 mutex_lock(&st->lock);
515 760
516 st->chan = chan; 761 st->chan = chan;
@@ -541,6 +786,9 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev,
541 at91_adc_writel(st, AT91_SAMA5D2_IDR, BIT(chan->channel)); 786 at91_adc_writel(st, AT91_SAMA5D2_IDR, BIT(chan->channel));
542 at91_adc_writel(st, AT91_SAMA5D2_CHDR, BIT(chan->channel)); 787 at91_adc_writel(st, AT91_SAMA5D2_CHDR, BIT(chan->channel));
543 788
789 /* Needed to ACK the DRDY interruption */
790 at91_adc_readl(st, AT91_SAMA5D2_LCDR);
791
544 mutex_unlock(&st->lock); 792 mutex_unlock(&st->lock);
545 793
546 iio_device_release_direct_mode(indio_dev); 794 iio_device_release_direct_mode(indio_dev);
@@ -580,9 +828,123 @@ static int at91_adc_write_raw(struct iio_dev *indio_dev,
580 return 0; 828 return 0;
581} 829}
582 830
831static void at91_adc_dma_init(struct platform_device *pdev)
832{
833 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
834 struct at91_adc_state *st = iio_priv(indio_dev);
835 struct dma_slave_config config = {0};
836 /*
837 * We make the buffer double the size of the fifo,
838 * such that DMA uses one half of the buffer (full fifo size)
839 * and the software uses the other half to read/write.
840 */
841 unsigned int pages = DIV_ROUND_UP(AT91_HWFIFO_MAX_SIZE *
842 AT91_BUFFER_MAX_CONVERSION_BYTES * 2,
843 PAGE_SIZE);
844
845 if (st->dma_st.dma_chan)
846 return;
847
848 st->dma_st.dma_chan = dma_request_slave_channel(&pdev->dev, "rx");
849
850 if (!st->dma_st.dma_chan) {
851 dev_info(&pdev->dev, "can't get DMA channel\n");
852 goto dma_exit;
853 }
854
855 st->dma_st.rx_buf = dma_alloc_coherent(st->dma_st.dma_chan->device->dev,
856 pages * PAGE_SIZE,
857 &st->dma_st.rx_dma_buf,
858 GFP_KERNEL);
859 if (!st->dma_st.rx_buf) {
860 dev_info(&pdev->dev, "can't allocate coherent DMA area\n");
861 goto dma_chan_disable;
862 }
863
864 /* Configure DMA channel to read data register */
865 config.direction = DMA_DEV_TO_MEM;
866 config.src_addr = (phys_addr_t)(st->dma_st.phys_addr
867 + AT91_SAMA5D2_LCDR);
868 config.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
869 config.src_maxburst = 1;
870 config.dst_maxburst = 1;
871
872 if (dmaengine_slave_config(st->dma_st.dma_chan, &config)) {
873 dev_info(&pdev->dev, "can't configure DMA slave\n");
874 goto dma_free_area;
875 }
876
877 dev_info(&pdev->dev, "using %s for rx DMA transfers\n",
878 dma_chan_name(st->dma_st.dma_chan));
879
880 return;
881
882dma_free_area:
883 dma_free_coherent(st->dma_st.dma_chan->device->dev, pages * PAGE_SIZE,
884 st->dma_st.rx_buf, st->dma_st.rx_dma_buf);
885dma_chan_disable:
886 dma_release_channel(st->dma_st.dma_chan);
887 st->dma_st.dma_chan = 0;
888dma_exit:
889 dev_info(&pdev->dev, "continuing without DMA support\n");
890}
891
892static void at91_adc_dma_disable(struct platform_device *pdev)
893{
894 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
895 struct at91_adc_state *st = iio_priv(indio_dev);
896 unsigned int pages = DIV_ROUND_UP(AT91_HWFIFO_MAX_SIZE *
897 AT91_BUFFER_MAX_CONVERSION_BYTES * 2,
898 PAGE_SIZE);
899
900 /* if we are not using DMA, just return */
901 if (!st->dma_st.dma_chan)
902 return;
903
904 /* wait for all transactions to be terminated first*/
905 dmaengine_terminate_sync(st->dma_st.dma_chan);
906
907 dma_free_coherent(st->dma_st.dma_chan->device->dev, pages * PAGE_SIZE,
908 st->dma_st.rx_buf, st->dma_st.rx_dma_buf);
909 dma_release_channel(st->dma_st.dma_chan);
910 st->dma_st.dma_chan = 0;
911
912 dev_info(&pdev->dev, "continuing without DMA support\n");
913}
914
915static int at91_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val)
916{
917 struct at91_adc_state *st = iio_priv(indio_dev);
918
919 if (val > AT91_HWFIFO_MAX_SIZE)
920 return -EINVAL;
921
922 if (!st->selected_trig->hw_trig) {
923 dev_dbg(&indio_dev->dev, "we need hw trigger for DMA\n");
924 return 0;
925 }
926
927 dev_dbg(&indio_dev->dev, "new watermark is %u\n", val);
928 st->dma_st.watermark = val;
929
930 /*
931 * The logic here is: if we have watermark 1, it means we do
932 * each conversion with it's own IRQ, thus we don't need DMA.
933 * If the watermark is higher, we do DMA to do all the transfers in bulk
934 */
935
936 if (val == 1)
937 at91_adc_dma_disable(to_platform_device(&indio_dev->dev));
938 else if (val > 1)
939 at91_adc_dma_init(to_platform_device(&indio_dev->dev));
940
941 return 0;
942}
943
583static const struct iio_info at91_adc_info = { 944static const struct iio_info at91_adc_info = {
584 .read_raw = &at91_adc_read_raw, 945 .read_raw = &at91_adc_read_raw,
585 .write_raw = &at91_adc_write_raw, 946 .write_raw = &at91_adc_write_raw,
947 .hwfifo_set_watermark = &at91_adc_set_watermark,
586}; 948};
587 949
588static void at91_adc_hw_init(struct at91_adc_state *st) 950static void at91_adc_hw_init(struct at91_adc_state *st)
@@ -599,6 +961,42 @@ static void at91_adc_hw_init(struct at91_adc_state *st)
599 at91_adc_setup_samp_freq(st, st->soc_info.min_sample_rate); 961 at91_adc_setup_samp_freq(st, st->soc_info.min_sample_rate);
600} 962}
601 963
964static ssize_t at91_adc_get_fifo_state(struct device *dev,
965 struct device_attribute *attr, char *buf)
966{
967 struct iio_dev *indio_dev =
968 platform_get_drvdata(to_platform_device(dev));
969 struct at91_adc_state *st = iio_priv(indio_dev);
970
971 return scnprintf(buf, PAGE_SIZE, "%d\n", !!st->dma_st.dma_chan);
972}
973
974static ssize_t at91_adc_get_watermark(struct device *dev,
975 struct device_attribute *attr, char *buf)
976{
977 struct iio_dev *indio_dev =
978 platform_get_drvdata(to_platform_device(dev));
979 struct at91_adc_state *st = iio_priv(indio_dev);
980
981 return scnprintf(buf, PAGE_SIZE, "%d\n", st->dma_st.watermark);
982}
983
984static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
985 at91_adc_get_fifo_state, NULL, 0);
986static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
987 at91_adc_get_watermark, NULL, 0);
988
989static IIO_CONST_ATTR(hwfifo_watermark_min, "2");
990static IIO_CONST_ATTR(hwfifo_watermark_max, AT91_HWFIFO_MAX_SIZE_STR);
991
992static const struct attribute *at91_adc_fifo_attributes[] = {
993 &iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
994 &iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
995 &iio_dev_attr_hwfifo_watermark.dev_attr.attr,
996 &iio_dev_attr_hwfifo_enabled.dev_attr.attr,
997 NULL,
998};
999
602static int at91_adc_probe(struct platform_device *pdev) 1000static int at91_adc_probe(struct platform_device *pdev)
603{ 1001{
604 struct iio_dev *indio_dev; 1002 struct iio_dev *indio_dev;
@@ -674,6 +1072,9 @@ static int at91_adc_probe(struct platform_device *pdev)
674 if (!res) 1072 if (!res)
675 return -EINVAL; 1073 return -EINVAL;
676 1074
1075 /* if we plan to use DMA, we need the physical address of the regs */
1076 st->dma_st.phys_addr = res->start;
1077
677 st->base = devm_ioremap_resource(&pdev->dev, res); 1078 st->base = devm_ioremap_resource(&pdev->dev, res);
678 if (IS_ERR(st->base)) 1079 if (IS_ERR(st->base))
679 return PTR_ERR(st->base); 1080 return PTR_ERR(st->base);
@@ -737,11 +1138,22 @@ static int at91_adc_probe(struct platform_device *pdev)
737 dev_err(&pdev->dev, "couldn't setup the triggers.\n"); 1138 dev_err(&pdev->dev, "couldn't setup the triggers.\n");
738 goto per_clk_disable_unprepare; 1139 goto per_clk_disable_unprepare;
739 } 1140 }
1141 /*
1142 * Initially the iio buffer has a length of 2 and
1143 * a watermark of 1
1144 */
1145 st->dma_st.watermark = 1;
1146
1147 iio_buffer_set_attrs(indio_dev->buffer,
1148 at91_adc_fifo_attributes);
740 } 1149 }
741 1150
1151 if (dma_coerce_mask_and_coherent(&indio_dev->dev, DMA_BIT_MASK(32)))
1152 dev_info(&pdev->dev, "cannot set DMA mask to 32-bit\n");
1153
742 ret = iio_device_register(indio_dev); 1154 ret = iio_device_register(indio_dev);
743 if (ret < 0) 1155 if (ret < 0)
744 goto per_clk_disable_unprepare; 1156 goto dma_disable;
745 1157
746 if (st->selected_trig->hw_trig) 1158 if (st->selected_trig->hw_trig)
747 dev_info(&pdev->dev, "setting up trigger as %s\n", 1159 dev_info(&pdev->dev, "setting up trigger as %s\n",
@@ -752,6 +1164,8 @@ static int at91_adc_probe(struct platform_device *pdev)
752 1164
753 return 0; 1165 return 0;
754 1166
1167dma_disable:
1168 at91_adc_dma_disable(pdev);
755per_clk_disable_unprepare: 1169per_clk_disable_unprepare:
756 clk_disable_unprepare(st->per_clk); 1170 clk_disable_unprepare(st->per_clk);
757vref_disable: 1171vref_disable:
@@ -768,6 +1182,8 @@ static int at91_adc_remove(struct platform_device *pdev)
768 1182
769 iio_device_unregister(indio_dev); 1183 iio_device_unregister(indio_dev);
770 1184
1185 at91_adc_dma_disable(pdev);
1186
771 clk_disable_unprepare(st->per_clk); 1187 clk_disable_unprepare(st->per_clk);
772 1188
773 regulator_disable(st->vref); 1189 regulator_disable(st->vref);
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 3836d4222a3e..71a5ee652b79 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -1177,9 +1177,9 @@ static int at91_adc_probe(struct platform_device *pdev)
1177 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1177 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1178 1178
1179 st->reg_base = devm_ioremap_resource(&pdev->dev, res); 1179 st->reg_base = devm_ioremap_resource(&pdev->dev, res);
1180 if (IS_ERR(st->reg_base)) { 1180 if (IS_ERR(st->reg_base))
1181 return PTR_ERR(st->reg_base); 1181 return PTR_ERR(st->reg_base);
1182 } 1182
1183 1183
1184 /* 1184 /*
1185 * Disable all IRQs before setting up the handler 1185 * Disable all IRQs before setting up the handler
diff --git a/drivers/iio/adc/axp288_adc.c b/drivers/iio/adc/axp288_adc.c
index 60c9e853dd81..031d568b4972 100644
--- a/drivers/iio/adc/axp288_adc.c
+++ b/drivers/iio/adc/axp288_adc.c
@@ -92,22 +92,14 @@ static const struct iio_chan_spec axp288_adc_channels[] = {
92 }, 92 },
93}; 93};
94 94
95#define AXP288_ADC_MAP(_adc_channel_label, _consumer_dev_name, \
96 _consumer_channel) \
97 { \
98 .adc_channel_label = _adc_channel_label, \
99 .consumer_dev_name = _consumer_dev_name, \
100 .consumer_channel = _consumer_channel, \
101 }
102
103/* for consumer drivers */ 95/* for consumer drivers */
104static struct iio_map axp288_adc_default_maps[] = { 96static struct iio_map axp288_adc_default_maps[] = {
105 AXP288_ADC_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"), 97 IIO_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"),
106 AXP288_ADC_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"), 98 IIO_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"),
107 AXP288_ADC_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"), 99 IIO_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"),
108 AXP288_ADC_MAP("BATT_CHG_I", "axp288-chrg", "axp288-chrg-curr"), 100 IIO_MAP("BATT_CHG_I", "axp288-chrg", "axp288-chrg-curr"),
109 AXP288_ADC_MAP("BATT_DISCHRG_I", "axp288-chrg", "axp288-chrg-d-curr"), 101 IIO_MAP("BATT_DISCHRG_I", "axp288-chrg", "axp288-chrg-d-curr"),
110 AXP288_ADC_MAP("BATT_V", "axp288-batt", "axp288-batt-volt"), 102 IIO_MAP("BATT_V", "axp288-batt", "axp288-batt-volt"),
111 {}, 103 {},
112}; 104};
113 105
diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
index d10b9f13d557..9430b54121e0 100644
--- a/drivers/iio/adc/hx711.c
+++ b/drivers/iio/adc/hx711.c
@@ -24,6 +24,9 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/iio/iio.h> 25#include <linux/iio/iio.h>
26#include <linux/iio/sysfs.h> 26#include <linux/iio/sysfs.h>
27#include <linux/iio/buffer.h>
28#include <linux/iio/trigger_consumer.h>
29#include <linux/iio/triggered_buffer.h>
27#include <linux/gpio/consumer.h> 30#include <linux/gpio/consumer.h>
28#include <linux/regulator/consumer.h> 31#include <linux/regulator/consumer.h>
29 32
@@ -89,6 +92,11 @@ struct hx711_data {
89 int gain_set; /* gain set on device */ 92 int gain_set; /* gain set on device */
90 int gain_chan_a; /* gain for channel A */ 93 int gain_chan_a; /* gain for channel A */
91 struct mutex lock; 94 struct mutex lock;
95 /*
96 * triggered buffer
97 * 2x32-bit channel + 64-bit timestamp
98 */
99 u32 buffer[4];
92}; 100};
93 101
94static int hx711_cycle(struct hx711_data *hx711_data) 102static int hx711_cycle(struct hx711_data *hx711_data)
@@ -145,15 +153,16 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data)
145 int i, val; 153 int i, val;
146 154
147 /* 155 /*
148 * a maximum reset cycle time of 56 ms was measured. 156 * in some rare cases the reset takes quite a long time
149 * we round it up to 100 ms 157 * especially when the channel is changed.
158 * Allow up to one second for it
150 */ 159 */
151 for (i = 0; i < 100; i++) { 160 for (i = 0; i < 100; i++) {
152 val = gpiod_get_value(hx711_data->gpiod_dout); 161 val = gpiod_get_value(hx711_data->gpiod_dout);
153 if (!val) 162 if (!val)
154 break; 163 break;
155 /* sleep at least 1 ms */ 164 /* sleep at least 10 ms */
156 msleep(1); 165 msleep(10);
157 } 166 }
158 if (val) 167 if (val)
159 return -EIO; 168 return -EIO;
@@ -195,9 +204,7 @@ static int hx711_reset(struct hx711_data *hx711_data)
195 * after a dummy read we need to wait vor readiness 204 * after a dummy read we need to wait vor readiness
196 * for not mixing gain pulses with the clock 205 * for not mixing gain pulses with the clock
197 */ 206 */
198 ret = hx711_wait_for_ready(hx711_data); 207 val = hx711_wait_for_ready(hx711_data);
199 if (ret)
200 return ret;
201 } 208 }
202 209
203 return val; 210 return val;
@@ -236,34 +243,40 @@ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)
236 return 0; 243 return 0;
237} 244}
238 245
246static int hx711_reset_read(struct hx711_data *hx711_data, int chan)
247{
248 int ret;
249 int val;
250
251 /*
252 * hx711_reset() must be called from here
253 * because it could be calling hx711_read() by itself
254 */
255 if (hx711_reset(hx711_data)) {
256 dev_err(hx711_data->dev, "reset failed!");
257 return -EIO;
258 }
259
260 ret = hx711_set_gain_for_channel(hx711_data, chan);
261 if (ret < 0)
262 return ret;
263
264 val = hx711_read(hx711_data);
265
266 return val;
267}
268
239static int hx711_read_raw(struct iio_dev *indio_dev, 269static int hx711_read_raw(struct iio_dev *indio_dev,
240 const struct iio_chan_spec *chan, 270 const struct iio_chan_spec *chan,
241 int *val, int *val2, long mask) 271 int *val, int *val2, long mask)
242{ 272{
243 struct hx711_data *hx711_data = iio_priv(indio_dev); 273 struct hx711_data *hx711_data = iio_priv(indio_dev);
244 int ret;
245 274
246 switch (mask) { 275 switch (mask) {
247 case IIO_CHAN_INFO_RAW: 276 case IIO_CHAN_INFO_RAW:
248 mutex_lock(&hx711_data->lock); 277 mutex_lock(&hx711_data->lock);
249 278
250 /* 279 *val = hx711_reset_read(hx711_data, chan->channel);
251 * hx711_reset() must be called from here
252 * because it could be calling hx711_read() by itself
253 */
254 if (hx711_reset(hx711_data)) {
255 mutex_unlock(&hx711_data->lock);
256 dev_err(hx711_data->dev, "reset failed!");
257 return -EIO;
258 }
259
260 ret = hx711_set_gain_for_channel(hx711_data, chan->channel);
261 if (ret < 0) {
262 mutex_unlock(&hx711_data->lock);
263 return ret;
264 }
265
266 *val = hx711_read(hx711_data);
267 280
268 mutex_unlock(&hx711_data->lock); 281 mutex_unlock(&hx711_data->lock);
269 282
@@ -339,6 +352,36 @@ static int hx711_write_raw_get_fmt(struct iio_dev *indio_dev,
339 return IIO_VAL_INT_PLUS_NANO; 352 return IIO_VAL_INT_PLUS_NANO;
340} 353}
341 354
355static irqreturn_t hx711_trigger(int irq, void *p)
356{
357 struct iio_poll_func *pf = p;
358 struct iio_dev *indio_dev = pf->indio_dev;
359 struct hx711_data *hx711_data = iio_priv(indio_dev);
360 int i, j = 0;
361
362 mutex_lock(&hx711_data->lock);
363
364 memset(hx711_data->buffer, 0, sizeof(hx711_data->buffer));
365
366 for (i = 0; i < indio_dev->masklength; i++) {
367 if (!test_bit(i, indio_dev->active_scan_mask))
368 continue;
369
370 hx711_data->buffer[j] = hx711_reset_read(hx711_data,
371 indio_dev->channels[i].channel);
372 j++;
373 }
374
375 iio_push_to_buffers_with_timestamp(indio_dev, hx711_data->buffer,
376 pf->timestamp);
377
378 mutex_unlock(&hx711_data->lock);
379
380 iio_trigger_notify_done(indio_dev->trig);
381
382 return IRQ_HANDLED;
383}
384
342static ssize_t hx711_scale_available_show(struct device *dev, 385static ssize_t hx711_scale_available_show(struct device *dev,
343 struct device_attribute *attr, 386 struct device_attribute *attr,
344 char *buf) 387 char *buf)
@@ -387,6 +430,13 @@ static const struct iio_chan_spec hx711_chan_spec[] = {
387 .indexed = 1, 430 .indexed = 1,
388 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 431 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
389 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 432 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
433 .scan_index = 0,
434 .scan_type = {
435 .sign = 'u',
436 .realbits = 24,
437 .storagebits = 32,
438 .endianness = IIO_CPU,
439 },
390 }, 440 },
391 { 441 {
392 .type = IIO_VOLTAGE, 442 .type = IIO_VOLTAGE,
@@ -394,7 +444,15 @@ static const struct iio_chan_spec hx711_chan_spec[] = {
394 .indexed = 1, 444 .indexed = 1,
395 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 445 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
396 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 446 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
447 .scan_index = 1,
448 .scan_type = {
449 .sign = 'u',
450 .realbits = 24,
451 .storagebits = 32,
452 .endianness = IIO_CPU,
453 },
397 }, 454 },
455 IIO_CHAN_SOFT_TIMESTAMP(2),
398}; 456};
399 457
400static int hx711_probe(struct platform_device *pdev) 458static int hx711_probe(struct platform_device *pdev)
@@ -459,10 +517,9 @@ static int hx711_probe(struct platform_device *pdev)
459 * 1 LSB = (AVDD * 100) / GAIN / 1678 [10^-9 mV] 517 * 1 LSB = (AVDD * 100) / GAIN / 1678 [10^-9 mV]
460 */ 518 */
461 ret = regulator_get_voltage(hx711_data->reg_avdd); 519 ret = regulator_get_voltage(hx711_data->reg_avdd);
462 if (ret < 0) { 520 if (ret < 0)
463 regulator_disable(hx711_data->reg_avdd); 521 goto error_regulator;
464 return ret; 522
465 }
466 /* we need 10^-9 mV */ 523 /* we need 10^-9 mV */
467 ret *= 100; 524 ret *= 100;
468 525
@@ -482,12 +539,27 @@ static int hx711_probe(struct platform_device *pdev)
482 indio_dev->channels = hx711_chan_spec; 539 indio_dev->channels = hx711_chan_spec;
483 indio_dev->num_channels = ARRAY_SIZE(hx711_chan_spec); 540 indio_dev->num_channels = ARRAY_SIZE(hx711_chan_spec);
484 541
542 ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time,
543 hx711_trigger, NULL);
544 if (ret < 0) {
545 dev_err(dev, "setup of iio triggered buffer failed\n");
546 goto error_regulator;
547 }
548
485 ret = iio_device_register(indio_dev); 549 ret = iio_device_register(indio_dev);
486 if (ret < 0) { 550 if (ret < 0) {
487 dev_err(dev, "Couldn't register the device\n"); 551 dev_err(dev, "Couldn't register the device\n");
488 regulator_disable(hx711_data->reg_avdd); 552 goto error_buffer;
489 } 553 }
490 554
555 return 0;
556
557error_buffer:
558 iio_triggered_buffer_cleanup(indio_dev);
559
560error_regulator:
561 regulator_disable(hx711_data->reg_avdd);
562
491 return ret; 563 return ret;
492} 564}
493 565
@@ -501,6 +573,8 @@ static int hx711_remove(struct platform_device *pdev)
501 573
502 iio_device_unregister(indio_dev); 574 iio_device_unregister(indio_dev);
503 575
576 iio_triggered_buffer_cleanup(indio_dev);
577
504 regulator_disable(hx711_data->reg_avdd); 578 regulator_disable(hx711_data->reg_avdd);
505 579
506 return 0; 580 return 0;
diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
index 84a43871f7dc..0635a79864bf 100644
--- a/drivers/iio/adc/ina2xx-adc.c
+++ b/drivers/iio/adc/ina2xx-adc.c
@@ -44,13 +44,14 @@
44 44
45#define INA226_MASK_ENABLE 0x06 45#define INA226_MASK_ENABLE 0x06
46#define INA226_CVRF BIT(3) 46#define INA226_CVRF BIT(3)
47#define INA219_CNVR BIT(1)
48 47
49#define INA2XX_MAX_REGISTERS 8 48#define INA2XX_MAX_REGISTERS 8
50 49
51/* settings - depend on use case */ 50/* settings - depend on use case */
52#define INA219_CONFIG_DEFAULT 0x399F /* PGA=8 */ 51#define INA219_CONFIG_DEFAULT 0x399F /* PGA=1/8, BRNG=32V */
53#define INA219_DEFAULT_IT 532 52#define INA219_DEFAULT_IT 532
53#define INA219_DEFAULT_BRNG 1 /* 32V */
54#define INA219_DEFAULT_PGA 125 /* 1000/8 */
54#define INA226_CONFIG_DEFAULT 0x4327 55#define INA226_CONFIG_DEFAULT 0x4327
55#define INA226_DEFAULT_AVG 4 56#define INA226_DEFAULT_AVG 4
56#define INA226_DEFAULT_IT 1110 57#define INA226_DEFAULT_IT 1110
@@ -63,6 +64,14 @@
63 */ 64 */
64#define INA2XX_MODE_MASK GENMASK(3, 0) 65#define INA2XX_MODE_MASK GENMASK(3, 0)
65 66
67/* Gain for VShunt: 1/8 (default), 1/4, 1/2, 1 */
68#define INA219_PGA_MASK GENMASK(12, 11)
69#define INA219_SHIFT_PGA(val) ((val) << 11)
70
71/* VBus range: 32V (default), 16V */
72#define INA219_BRNG_MASK BIT(13)
73#define INA219_SHIFT_BRNG(val) ((val) << 13)
74
66/* Averaging for VBus/VShunt/Power */ 75/* Averaging for VBus/VShunt/Power */
67#define INA226_AVG_MASK GENMASK(11, 9) 76#define INA226_AVG_MASK GENMASK(11, 9)
68#define INA226_SHIFT_AVG(val) ((val) << 9) 77#define INA226_SHIFT_AVG(val) ((val) << 9)
@@ -79,6 +88,11 @@
79#define INA226_ITS_MASK GENMASK(5, 3) 88#define INA226_ITS_MASK GENMASK(5, 3)
80#define INA226_SHIFT_ITS(val) ((val) << 3) 89#define INA226_SHIFT_ITS(val) ((val) << 3)
81 90
91/* INA219 Bus voltage register, low bits are flags */
92#define INA219_OVF BIT(0)
93#define INA219_CNVR BIT(1)
94#define INA219_BUS_VOLTAGE_SHIFT 3
95
82/* Cosmetic macro giving the sampling period for a full P=UxI cycle */ 96/* Cosmetic macro giving the sampling period for a full P=UxI cycle */
83#define SAMPLING_PERIOD(c) ((c->int_time_vbus + c->int_time_vshunt) \ 97#define SAMPLING_PERIOD(c) ((c->int_time_vbus + c->int_time_vshunt) \
84 * c->avg) 98 * c->avg)
@@ -110,11 +124,12 @@ enum ina2xx_ids { ina219, ina226 };
110 124
111struct ina2xx_config { 125struct ina2xx_config {
112 u16 config_default; 126 u16 config_default;
113 int calibration_factor; 127 int calibration_value;
114 int shunt_div; 128 int shunt_voltage_lsb; /* nV */
115 int bus_voltage_shift; 129 int bus_voltage_shift; /* position of lsb */
116 int bus_voltage_lsb; /* uV */ 130 int bus_voltage_lsb; /* uV */
117 int power_lsb; /* uW */ 131 /* fixed relation between current and power lsb, uW/uA */
132 int power_lsb_factor;
118 enum ina2xx_ids chip_id; 133 enum ina2xx_ids chip_id;
119}; 134};
120 135
@@ -127,26 +142,28 @@ struct ina2xx_chip_info {
127 int avg; 142 int avg;
128 int int_time_vbus; /* Bus voltage integration time uS */ 143 int int_time_vbus; /* Bus voltage integration time uS */
129 int int_time_vshunt; /* Shunt voltage integration time uS */ 144 int int_time_vshunt; /* Shunt voltage integration time uS */
145 int range_vbus; /* Bus voltage maximum in V */
146 int pga_gain_vshunt; /* Shunt voltage PGA gain */
130 bool allow_async_readout; 147 bool allow_async_readout;
131}; 148};
132 149
133static const struct ina2xx_config ina2xx_config[] = { 150static const struct ina2xx_config ina2xx_config[] = {
134 [ina219] = { 151 [ina219] = {
135 .config_default = INA219_CONFIG_DEFAULT, 152 .config_default = INA219_CONFIG_DEFAULT,
136 .calibration_factor = 40960000, 153 .calibration_value = 4096,
137 .shunt_div = 100, 154 .shunt_voltage_lsb = 10000,
138 .bus_voltage_shift = 3, 155 .bus_voltage_shift = INA219_BUS_VOLTAGE_SHIFT,
139 .bus_voltage_lsb = 4000, 156 .bus_voltage_lsb = 4000,
140 .power_lsb = 20000, 157 .power_lsb_factor = 20,
141 .chip_id = ina219, 158 .chip_id = ina219,
142 }, 159 },
143 [ina226] = { 160 [ina226] = {
144 .config_default = INA226_CONFIG_DEFAULT, 161 .config_default = INA226_CONFIG_DEFAULT,
145 .calibration_factor = 5120000, 162 .calibration_value = 2048,
146 .shunt_div = 400, 163 .shunt_voltage_lsb = 2500,
147 .bus_voltage_shift = 0, 164 .bus_voltage_shift = 0,
148 .bus_voltage_lsb = 1250, 165 .bus_voltage_lsb = 1250,
149 .power_lsb = 25000, 166 .power_lsb_factor = 25,
150 .chip_id = ina226, 167 .chip_id = ina226,
151 }, 168 },
152}; 169};
@@ -170,6 +187,9 @@ static int ina2xx_read_raw(struct iio_dev *indio_dev,
170 else 187 else
171 *val = regval; 188 *val = regval;
172 189
190 if (chan->address == INA2XX_BUS_VOLTAGE)
191 *val >>= chip->config->bus_voltage_shift;
192
173 return IIO_VAL_INT; 193 return IIO_VAL_INT;
174 194
175 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 195 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
@@ -197,26 +217,48 @@ static int ina2xx_read_raw(struct iio_dev *indio_dev,
197 case IIO_CHAN_INFO_SCALE: 217 case IIO_CHAN_INFO_SCALE:
198 switch (chan->address) { 218 switch (chan->address) {
199 case INA2XX_SHUNT_VOLTAGE: 219 case INA2XX_SHUNT_VOLTAGE:
200 /* processed (mV) = raw/shunt_div */ 220 /* processed (mV) = raw * lsb(nV) / 1000000 */
201 *val2 = chip->config->shunt_div; 221 *val = chip->config->shunt_voltage_lsb;
202 *val = 1; 222 *val2 = 1000000;
203 return IIO_VAL_FRACTIONAL; 223 return IIO_VAL_FRACTIONAL;
204 224
205 case INA2XX_BUS_VOLTAGE: 225 case INA2XX_BUS_VOLTAGE:
206 /* processed (mV) = raw*lsb (uV) / (1000 << shift) */ 226 /* processed (mV) = raw * lsb (uV) / 1000 */
207 *val = chip->config->bus_voltage_lsb; 227 *val = chip->config->bus_voltage_lsb;
208 *val2 = 1000 << chip->config->bus_voltage_shift; 228 *val2 = 1000;
229 return IIO_VAL_FRACTIONAL;
230
231 case INA2XX_CURRENT:
232 /*
233 * processed (mA) = raw * current_lsb (mA)
234 * current_lsb (mA) = shunt_voltage_lsb (nV) /
235 * shunt_resistor (uOhm)
236 */
237 *val = chip->config->shunt_voltage_lsb;
238 *val2 = chip->shunt_resistor_uohm;
209 return IIO_VAL_FRACTIONAL; 239 return IIO_VAL_FRACTIONAL;
210 240
211 case INA2XX_POWER: 241 case INA2XX_POWER:
212 /* processed (mW) = raw*lsb (uW) / 1000 */ 242 /*
213 *val = chip->config->power_lsb; 243 * processed (mW) = raw * power_lsb (mW)
244 * power_lsb (mW) = power_lsb_factor (mW/mA) *
245 * current_lsb (mA)
246 */
247 *val = chip->config->power_lsb_factor *
248 chip->config->shunt_voltage_lsb;
249 *val2 = chip->shunt_resistor_uohm;
250 return IIO_VAL_FRACTIONAL;
251 }
252
253 case IIO_CHAN_INFO_HARDWAREGAIN:
254 switch (chan->address) {
255 case INA2XX_SHUNT_VOLTAGE:
256 *val = chip->pga_gain_vshunt;
214 *val2 = 1000; 257 *val2 = 1000;
215 return IIO_VAL_FRACTIONAL; 258 return IIO_VAL_FRACTIONAL;
216 259
217 case INA2XX_CURRENT: 260 case INA2XX_BUS_VOLTAGE:
218 /* processed (mA) = raw (mA) */ 261 *val = chip->range_vbus == 32 ? 1 : 2;
219 *val = 1;
220 return IIO_VAL_INT; 262 return IIO_VAL_INT;
221 } 263 }
222 } 264 }
@@ -353,6 +395,74 @@ static int ina219_set_int_time_vshunt(struct ina2xx_chip_info *chip,
353 return 0; 395 return 0;
354} 396}
355 397
398static const int ina219_vbus_range_tab[] = { 1, 2 };
399static int ina219_set_vbus_range_denom(struct ina2xx_chip_info *chip,
400 unsigned int range,
401 unsigned int *config)
402{
403 if (range == 1)
404 chip->range_vbus = 32;
405 else if (range == 2)
406 chip->range_vbus = 16;
407 else
408 return -EINVAL;
409
410 *config &= ~INA219_BRNG_MASK;
411 *config |= INA219_SHIFT_BRNG(range == 1 ? 1 : 0) & INA219_BRNG_MASK;
412
413 return 0;
414}
415
416static const int ina219_vshunt_gain_tab[] = { 125, 250, 500, 1000 };
417static const int ina219_vshunt_gain_frac[] = {
418 125, 1000, 250, 1000, 500, 1000, 1000, 1000 };
419
420static int ina219_set_vshunt_pga_gain(struct ina2xx_chip_info *chip,
421 unsigned int gain,
422 unsigned int *config)
423{
424 int bits;
425
426 if (gain < 125 || gain > 1000)
427 return -EINVAL;
428
429 bits = find_closest(gain, ina219_vshunt_gain_tab,
430 ARRAY_SIZE(ina219_vshunt_gain_tab));
431
432 chip->pga_gain_vshunt = ina219_vshunt_gain_tab[bits];
433 bits = 3 - bits;
434
435 *config &= ~INA219_PGA_MASK;
436 *config |= INA219_SHIFT_PGA(bits) & INA219_PGA_MASK;
437
438 return 0;
439}
440
441static int ina2xx_read_avail(struct iio_dev *indio_dev,
442 struct iio_chan_spec const *chan,
443 const int **vals, int *type, int *length,
444 long mask)
445{
446 switch (mask) {
447 case IIO_CHAN_INFO_HARDWAREGAIN:
448 switch (chan->address) {
449 case INA2XX_SHUNT_VOLTAGE:
450 *type = IIO_VAL_FRACTIONAL;
451 *length = sizeof(ina219_vshunt_gain_frac) / sizeof(int);
452 *vals = ina219_vshunt_gain_frac;
453 return IIO_AVAIL_LIST;
454
455 case INA2XX_BUS_VOLTAGE:
456 *type = IIO_VAL_INT;
457 *length = sizeof(ina219_vbus_range_tab) / sizeof(int);
458 *vals = ina219_vbus_range_tab;
459 return IIO_AVAIL_LIST;
460 }
461 }
462
463 return -EINVAL;
464}
465
356static int ina2xx_write_raw(struct iio_dev *indio_dev, 466static int ina2xx_write_raw(struct iio_dev *indio_dev,
357 struct iio_chan_spec const *chan, 467 struct iio_chan_spec const *chan,
358 int val, int val2, long mask) 468 int val, int val2, long mask)
@@ -395,6 +505,14 @@ static int ina2xx_write_raw(struct iio_dev *indio_dev,
395 } 505 }
396 break; 506 break;
397 507
508 case IIO_CHAN_INFO_HARDWAREGAIN:
509 if (chan->address == INA2XX_SHUNT_VOLTAGE)
510 ret = ina219_set_vshunt_pga_gain(chip, val * 1000 +
511 val2 / 1000, &tmp);
512 else
513 ret = ina219_set_vbus_range_denom(chip, val, &tmp);
514 break;
515
398 default: 516 default:
399 ret = -EINVAL; 517 ret = -EINVAL;
400 } 518 }
@@ -434,25 +552,21 @@ static ssize_t ina2xx_allow_async_readout_store(struct device *dev,
434} 552}
435 553
436/* 554/*
437 * Set current LSB to 1mA, shunt is in uOhms 555 * Calibration register is set to the best value, which eliminates
438 * (equation 13 in datasheet). We hardcode a Current_LSB 556 * truncation errors on calculating current register in hardware.
439 * of 1.0 x10-3. The only remaining parameter is RShunt. 557 * According to datasheet (INA 226: eq. 3, INA219: eq. 4) the best values
440 * There is no need to expose the CALIBRATION register 558 * are 2048 for ina226 and 4096 for ina219. They are hardcoded as
441 * to the user for now. But we need to reset this register 559 * calibration_value.
442 * if the user updates RShunt after driver init, e.g upon
443 * reading an EEPROM/Probe-type value.
444 */ 560 */
445static int ina2xx_set_calibration(struct ina2xx_chip_info *chip) 561static int ina2xx_set_calibration(struct ina2xx_chip_info *chip)
446{ 562{
447 u16 regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor, 563 return regmap_write(chip->regmap, INA2XX_CALIBRATION,
448 chip->shunt_resistor_uohm); 564 chip->config->calibration_value);
449
450 return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval);
451} 565}
452 566
453static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val) 567static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val)
454{ 568{
455 if (val <= 0 || val > chip->config->calibration_factor) 569 if (val == 0 || val > INT_MAX)
456 return -EINVAL; 570 return -EINVAL;
457 571
458 chip->shunt_resistor_uohm = val; 572 chip->shunt_resistor_uohm = val;
@@ -485,11 +599,6 @@ static ssize_t ina2xx_shunt_resistor_store(struct device *dev,
485 if (ret) 599 if (ret)
486 return ret; 600 return ret;
487 601
488 /* Update the Calibration register */
489 ret = ina2xx_set_calibration(chip);
490 if (ret)
491 return ret;
492
493 return len; 602 return len;
494} 603}
495 604
@@ -532,19 +641,23 @@ static ssize_t ina2xx_shunt_resistor_store(struct device *dev,
532 * Sampling Freq is a consequence of the integration times of 641 * Sampling Freq is a consequence of the integration times of
533 * the Voltage channels. 642 * the Voltage channels.
534 */ 643 */
535#define INA219_CHAN_VOLTAGE(_index, _address) { \ 644#define INA219_CHAN_VOLTAGE(_index, _address, _shift) { \
536 .type = IIO_VOLTAGE, \ 645 .type = IIO_VOLTAGE, \
537 .address = (_address), \ 646 .address = (_address), \
538 .indexed = 1, \ 647 .indexed = 1, \
539 .channel = (_index), \ 648 .channel = (_index), \
540 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 649 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
541 BIT(IIO_CHAN_INFO_SCALE) | \ 650 BIT(IIO_CHAN_INFO_SCALE) | \
542 BIT(IIO_CHAN_INFO_INT_TIME), \ 651 BIT(IIO_CHAN_INFO_INT_TIME) | \
652 BIT(IIO_CHAN_INFO_HARDWAREGAIN), \
653 .info_mask_separate_available = \
654 BIT(IIO_CHAN_INFO_HARDWAREGAIN), \
543 .info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 655 .info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
544 .scan_index = (_index), \ 656 .scan_index = (_index), \
545 .scan_type = { \ 657 .scan_type = { \
546 .sign = 'u', \ 658 .sign = 'u', \
547 .realbits = 16, \ 659 .shift = _shift, \
660 .realbits = 16 - _shift, \
548 .storagebits = 16, \ 661 .storagebits = 16, \
549 .endianness = IIO_LE, \ 662 .endianness = IIO_LE, \
550 } \ 663 } \
@@ -579,23 +692,18 @@ static const struct iio_chan_spec ina226_channels[] = {
579}; 692};
580 693
581static const struct iio_chan_spec ina219_channels[] = { 694static const struct iio_chan_spec ina219_channels[] = {
582 INA219_CHAN_VOLTAGE(0, INA2XX_SHUNT_VOLTAGE), 695 INA219_CHAN_VOLTAGE(0, INA2XX_SHUNT_VOLTAGE, 0),
583 INA219_CHAN_VOLTAGE(1, INA2XX_BUS_VOLTAGE), 696 INA219_CHAN_VOLTAGE(1, INA2XX_BUS_VOLTAGE, INA219_BUS_VOLTAGE_SHIFT),
584 INA219_CHAN(IIO_POWER, 2, INA2XX_POWER), 697 INA219_CHAN(IIO_POWER, 2, INA2XX_POWER),
585 INA219_CHAN(IIO_CURRENT, 3, INA2XX_CURRENT), 698 INA219_CHAN(IIO_CURRENT, 3, INA2XX_CURRENT),
586 IIO_CHAN_SOFT_TIMESTAMP(4), 699 IIO_CHAN_SOFT_TIMESTAMP(4),
587}; 700};
588 701
589static int ina2xx_work_buffer(struct iio_dev *indio_dev) 702static int ina2xx_conversion_ready(struct iio_dev *indio_dev)
590{ 703{
591 struct ina2xx_chip_info *chip = iio_priv(indio_dev); 704 struct ina2xx_chip_info *chip = iio_priv(indio_dev);
592 unsigned short data[8]; 705 int ret;
593 int bit, ret, i = 0;
594 s64 time_a, time_b;
595 unsigned int alert; 706 unsigned int alert;
596 int cnvr_need_clear = 0;
597
598 time_a = iio_get_time_ns(indio_dev);
599 707
600 /* 708 /*
601 * Because the timer thread and the chip conversion clock 709 * Because the timer thread and the chip conversion clock
@@ -608,23 +716,31 @@ static int ina2xx_work_buffer(struct iio_dev *indio_dev)
608 * For now, we do an extra read of the MASK_ENABLE register (INA226) 716 * For now, we do an extra read of the MASK_ENABLE register (INA226)
609 * resp. the BUS_VOLTAGE register (INA219). 717 * resp. the BUS_VOLTAGE register (INA219).
610 */ 718 */
611 if (!chip->allow_async_readout) 719 if (chip->config->chip_id == ina226) {
612 do { 720 ret = regmap_read(chip->regmap,
613 if (chip->config->chip_id == ina226) { 721 INA226_MASK_ENABLE, &alert);
614 ret = regmap_read(chip->regmap, 722 alert &= INA226_CVRF;
615 INA226_MASK_ENABLE, &alert); 723 } else {
616 alert &= INA226_CVRF; 724 ret = regmap_read(chip->regmap,
617 } else { 725 INA2XX_BUS_VOLTAGE, &alert);
618 ret = regmap_read(chip->regmap, 726 alert &= INA219_CNVR;
619 INA2XX_BUS_VOLTAGE, &alert); 727 }
620 alert &= INA219_CNVR;
621 cnvr_need_clear = alert;
622 }
623 728
624 if (ret < 0) 729 if (ret < 0)
625 return ret; 730 return ret;
731
732 return !!alert;
733}
734
735static int ina2xx_work_buffer(struct iio_dev *indio_dev)
736{
737 struct ina2xx_chip_info *chip = iio_priv(indio_dev);
738 /* data buffer needs space for channel data and timestap */
739 unsigned short data[4 + sizeof(s64)/sizeof(short)];
740 int bit, ret, i = 0;
741 s64 time;
626 742
627 } while (!alert); 743 time = iio_get_time_ns(indio_dev);
628 744
629 /* 745 /*
630 * Single register reads: bulk_read will not work with ina226/219 746 * Single register reads: bulk_read will not work with ina226/219
@@ -640,26 +756,11 @@ static int ina2xx_work_buffer(struct iio_dev *indio_dev)
640 return ret; 756 return ret;
641 757
642 data[i++] = val; 758 data[i++] = val;
643
644 if (INA2XX_SHUNT_VOLTAGE + bit == INA2XX_POWER)
645 cnvr_need_clear = 0;
646 }
647
648 /* Dummy read on INA219 power register to clear CNVR flag */
649 if (cnvr_need_clear && chip->config->chip_id == ina219) {
650 unsigned int val;
651
652 ret = regmap_read(chip->regmap, INA2XX_POWER, &val);
653 if (ret < 0)
654 return ret;
655 } 759 }
656 760
657 time_b = iio_get_time_ns(indio_dev); 761 iio_push_to_buffers_with_timestamp(indio_dev, data, time);
658 762
659 iio_push_to_buffers_with_timestamp(indio_dev, 763 return 0;
660 (unsigned int *)data, time_a);
661
662 return (unsigned long)(time_b - time_a) / 1000;
663}; 764};
664 765
665static int ina2xx_capture_thread(void *data) 766static int ina2xx_capture_thread(void *data)
@@ -667,7 +768,9 @@ static int ina2xx_capture_thread(void *data)
667 struct iio_dev *indio_dev = data; 768 struct iio_dev *indio_dev = data;
668 struct ina2xx_chip_info *chip = iio_priv(indio_dev); 769 struct ina2xx_chip_info *chip = iio_priv(indio_dev);
669 int sampling_us = SAMPLING_PERIOD(chip); 770 int sampling_us = SAMPLING_PERIOD(chip);
670 int buffer_us; 771 int ret;
772 struct timespec64 next, now, delta;
773 s64 delay_us;
671 774
672 /* 775 /*
673 * Poll a bit faster than the chip internal Fs, in case 776 * Poll a bit faster than the chip internal Fs, in case
@@ -676,13 +779,43 @@ static int ina2xx_capture_thread(void *data)
676 if (!chip->allow_async_readout) 779 if (!chip->allow_async_readout)
677 sampling_us -= 200; 780 sampling_us -= 200;
678 781
782 ktime_get_ts64(&next);
783
679 do { 784 do {
680 buffer_us = ina2xx_work_buffer(indio_dev); 785 while (!chip->allow_async_readout) {
681 if (buffer_us < 0) 786 ret = ina2xx_conversion_ready(indio_dev);
682 return buffer_us; 787 if (ret < 0)
788 return ret;
683 789
684 if (sampling_us > buffer_us) 790 /*
685 udelay(sampling_us - buffer_us); 791 * If the conversion was not yet finished,
792 * reset the reference timestamp.
793 */
794 if (ret == 0)
795 ktime_get_ts64(&next);
796 else
797 break;
798 }
799
800 ret = ina2xx_work_buffer(indio_dev);
801 if (ret < 0)
802 return ret;
803
804 ktime_get_ts64(&now);
805
806 /*
807 * Advance the timestamp for the next poll by one sampling
808 * interval, and sleep for the remainder (next - now)
809 * In case "next" has already passed, the interval is added
810 * multiple times, i.e. samples are dropped.
811 */
812 do {
813 timespec64_add_ns(&next, 1000 * sampling_us);
814 delta = timespec64_sub(next, now);
815 delay_us = div_s64(timespec64_to_ns(&delta), 1000);
816 } while (delay_us <= 0);
817
818 usleep_range(delay_us, (delay_us * 3) >> 1);
686 819
687 } while (!kthread_should_stop()); 820 } while (!kthread_should_stop());
688 821
@@ -746,7 +879,6 @@ static IIO_CONST_ATTR_NAMED(ina226_integration_time_available,
746 integration_time_available, 879 integration_time_available,
747 "0.000140 0.000204 0.000332 0.000588 0.001100 0.002116 0.004156 0.008244"); 880 "0.000140 0.000204 0.000332 0.000588 0.001100 0.002116 0.004156 0.008244");
748 881
749
750static IIO_DEVICE_ATTR(in_allow_async_readout, S_IRUGO | S_IWUSR, 882static IIO_DEVICE_ATTR(in_allow_async_readout, S_IRUGO | S_IWUSR,
751 ina2xx_allow_async_readout_show, 883 ina2xx_allow_async_readout_show,
752 ina2xx_allow_async_readout_store, 0); 884 ina2xx_allow_async_readout_store, 0);
@@ -780,6 +912,7 @@ static const struct attribute_group ina226_attribute_group = {
780static const struct iio_info ina219_info = { 912static const struct iio_info ina219_info = {
781 .attrs = &ina219_attribute_group, 913 .attrs = &ina219_attribute_group,
782 .read_raw = ina2xx_read_raw, 914 .read_raw = ina2xx_read_raw,
915 .read_avail = ina2xx_read_avail,
783 .write_raw = ina2xx_write_raw, 916 .write_raw = ina2xx_write_raw,
784 .debugfs_reg_access = ina2xx_debug_reg, 917 .debugfs_reg_access = ina2xx_debug_reg,
785}; 918};
@@ -860,6 +993,8 @@ static int ina2xx_probe(struct i2c_client *client,
860 chip->avg = 1; 993 chip->avg = 1;
861 ina219_set_int_time_vbus(chip, INA219_DEFAULT_IT, &val); 994 ina219_set_int_time_vbus(chip, INA219_DEFAULT_IT, &val);
862 ina219_set_int_time_vshunt(chip, INA219_DEFAULT_IT, &val); 995 ina219_set_int_time_vshunt(chip, INA219_DEFAULT_IT, &val);
996 ina219_set_vbus_range_denom(chip, INA219_DEFAULT_BRNG, &val);
997 ina219_set_vshunt_pga_gain(chip, INA219_DEFAULT_PGA, &val);
863 } 998 }
864 999
865 ret = ina2xx_init(chip, val); 1000 ret = ina2xx_init(chip, val);
diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index 36047147ce7c..29fa7736d80c 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -96,8 +96,8 @@
96 #define MESON_SAR_ADC_FIFO_RD_SAMPLE_VALUE_MASK GENMASK(11, 0) 96 #define MESON_SAR_ADC_FIFO_RD_SAMPLE_VALUE_MASK GENMASK(11, 0)
97 97
98#define MESON_SAR_ADC_AUX_SW 0x1c 98#define MESON_SAR_ADC_AUX_SW 0x1c
99 #define MESON_SAR_ADC_AUX_SW_MUX_SEL_CHAN_MASK(_chan) \ 99 #define MESON_SAR_ADC_AUX_SW_MUX_SEL_CHAN_SHIFT(_chan) \
100 (GENMASK(10, 8) << (((_chan) - 2) * 2)) 100 (8 + (((_chan) - 2) * 3))
101 #define MESON_SAR_ADC_AUX_SW_VREF_P_MUX BIT(6) 101 #define MESON_SAR_ADC_AUX_SW_VREF_P_MUX BIT(6)
102 #define MESON_SAR_ADC_AUX_SW_VREF_N_MUX BIT(5) 102 #define MESON_SAR_ADC_AUX_SW_VREF_N_MUX BIT(5)
103 #define MESON_SAR_ADC_AUX_SW_MODE_SEL BIT(4) 103 #define MESON_SAR_ADC_AUX_SW_MODE_SEL BIT(4)
@@ -221,6 +221,7 @@ enum meson_sar_adc_chan7_mux_sel {
221 221
222struct meson_sar_adc_data { 222struct meson_sar_adc_data {
223 bool has_bl30_integration; 223 bool has_bl30_integration;
224 unsigned long clock_rate;
224 u32 bandgap_reg; 225 u32 bandgap_reg;
225 unsigned int resolution; 226 unsigned int resolution;
226 const char *name; 227 const char *name;
@@ -233,7 +234,6 @@ struct meson_sar_adc_priv {
233 const struct meson_sar_adc_data *data; 234 const struct meson_sar_adc_data *data;
234 struct clk *clkin; 235 struct clk *clkin;
235 struct clk *core_clk; 236 struct clk *core_clk;
236 struct clk *sana_clk;
237 struct clk *adc_sel_clk; 237 struct clk *adc_sel_clk;
238 struct clk *adc_clk; 238 struct clk *adc_clk;
239 struct clk_gate clk_gate; 239 struct clk_gate clk_gate;
@@ -622,7 +622,7 @@ static int meson_sar_adc_clk_init(struct iio_dev *indio_dev,
622static int meson_sar_adc_init(struct iio_dev *indio_dev) 622static int meson_sar_adc_init(struct iio_dev *indio_dev)
623{ 623{
624 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 624 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
625 int regval, ret; 625 int regval, i, ret;
626 626
627 /* 627 /*
628 * make sure we start at CH7 input since the other muxes are only used 628 * make sure we start at CH7 input since the other muxes are only used
@@ -677,6 +677,32 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev)
677 FIELD_PREP(MESON_SAR_ADC_DELAY_INPUT_DLY_SEL_MASK, 677 FIELD_PREP(MESON_SAR_ADC_DELAY_INPUT_DLY_SEL_MASK,
678 1)); 678 1));
679 679
680 /*
681 * set up the input channel muxes in MESON_SAR_ADC_CHAN_10_SW
682 * (0 = SAR_ADC_CH0, 1 = SAR_ADC_CH1)
683 */
684 regval = FIELD_PREP(MESON_SAR_ADC_CHAN_10_SW_CHAN0_MUX_SEL_MASK, 0);
685 regmap_update_bits(priv->regmap, MESON_SAR_ADC_CHAN_10_SW,
686 MESON_SAR_ADC_CHAN_10_SW_CHAN0_MUX_SEL_MASK,
687 regval);
688 regval = FIELD_PREP(MESON_SAR_ADC_CHAN_10_SW_CHAN1_MUX_SEL_MASK, 1);
689 regmap_update_bits(priv->regmap, MESON_SAR_ADC_CHAN_10_SW,
690 MESON_SAR_ADC_CHAN_10_SW_CHAN1_MUX_SEL_MASK,
691 regval);
692
693 /*
694 * set up the input channel muxes in MESON_SAR_ADC_AUX_SW
695 * (2 = SAR_ADC_CH2, 3 = SAR_ADC_CH3, ...) and enable
696 * MESON_SAR_ADC_AUX_SW_YP_DRIVE_SW and
697 * MESON_SAR_ADC_AUX_SW_XP_DRIVE_SW like the vendor driver.
698 */
699 regval = 0;
700 for (i = 2; i <= 7; i++)
701 regval |= i << MESON_SAR_ADC_AUX_SW_MUX_SEL_CHAN_SHIFT(i);
702 regval |= MESON_SAR_ADC_AUX_SW_YP_DRIVE_SW;
703 regval |= MESON_SAR_ADC_AUX_SW_XP_DRIVE_SW;
704 regmap_write(priv->regmap, MESON_SAR_ADC_AUX_SW, regval);
705
680 ret = clk_set_parent(priv->adc_sel_clk, priv->clkin); 706 ret = clk_set_parent(priv->adc_sel_clk, priv->clkin);
681 if (ret) { 707 if (ret) {
682 dev_err(indio_dev->dev.parent, 708 dev_err(indio_dev->dev.parent,
@@ -684,7 +710,7 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev)
684 return ret; 710 return ret;
685 } 711 }
686 712
687 ret = clk_set_rate(priv->adc_clk, 1200000); 713 ret = clk_set_rate(priv->adc_clk, priv->data->clock_rate);
688 if (ret) { 714 if (ret) {
689 dev_err(indio_dev->dev.parent, 715 dev_err(indio_dev->dev.parent,
690 "failed to set adc clock rate\n"); 716 "failed to set adc clock rate\n");
@@ -731,12 +757,6 @@ static int meson_sar_adc_hw_enable(struct iio_dev *indio_dev)
731 goto err_core_clk; 757 goto err_core_clk;
732 } 758 }
733 759
734 ret = clk_prepare_enable(priv->sana_clk);
735 if (ret) {
736 dev_err(indio_dev->dev.parent, "failed to enable sana clk\n");
737 goto err_sana_clk;
738 }
739
740 regval = FIELD_PREP(MESON_SAR_ADC_REG0_FIFO_CNT_IRQ_MASK, 1); 760 regval = FIELD_PREP(MESON_SAR_ADC_REG0_FIFO_CNT_IRQ_MASK, 1);
741 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0, 761 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0,
742 MESON_SAR_ADC_REG0_FIFO_CNT_IRQ_MASK, regval); 762 MESON_SAR_ADC_REG0_FIFO_CNT_IRQ_MASK, regval);
@@ -763,8 +783,6 @@ err_adc_clk:
763 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3, 783 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3,
764 MESON_SAR_ADC_REG3_ADC_EN, 0); 784 MESON_SAR_ADC_REG3_ADC_EN, 0);
765 meson_sar_adc_set_bandgap(indio_dev, false); 785 meson_sar_adc_set_bandgap(indio_dev, false);
766 clk_disable_unprepare(priv->sana_clk);
767err_sana_clk:
768 clk_disable_unprepare(priv->core_clk); 786 clk_disable_unprepare(priv->core_clk);
769err_core_clk: 787err_core_clk:
770 regulator_disable(priv->vref); 788 regulator_disable(priv->vref);
@@ -790,7 +808,6 @@ static int meson_sar_adc_hw_disable(struct iio_dev *indio_dev)
790 808
791 meson_sar_adc_set_bandgap(indio_dev, false); 809 meson_sar_adc_set_bandgap(indio_dev, false);
792 810
793 clk_disable_unprepare(priv->sana_clk);
794 clk_disable_unprepare(priv->core_clk); 811 clk_disable_unprepare(priv->core_clk);
795 812
796 regulator_disable(priv->vref); 813 regulator_disable(priv->vref);
@@ -866,6 +883,7 @@ static const struct iio_info meson_sar_adc_iio_info = {
866 883
867static const struct meson_sar_adc_data meson_sar_adc_meson8_data = { 884static const struct meson_sar_adc_data meson_sar_adc_meson8_data = {
868 .has_bl30_integration = false, 885 .has_bl30_integration = false,
886 .clock_rate = 1150000,
869 .bandgap_reg = MESON_SAR_ADC_DELTA_10, 887 .bandgap_reg = MESON_SAR_ADC_DELTA_10,
870 .regmap_config = &meson_sar_adc_regmap_config_meson8, 888 .regmap_config = &meson_sar_adc_regmap_config_meson8,
871 .resolution = 10, 889 .resolution = 10,
@@ -874,6 +892,7 @@ static const struct meson_sar_adc_data meson_sar_adc_meson8_data = {
874 892
875static const struct meson_sar_adc_data meson_sar_adc_meson8b_data = { 893static const struct meson_sar_adc_data meson_sar_adc_meson8b_data = {
876 .has_bl30_integration = false, 894 .has_bl30_integration = false,
895 .clock_rate = 1150000,
877 .bandgap_reg = MESON_SAR_ADC_DELTA_10, 896 .bandgap_reg = MESON_SAR_ADC_DELTA_10,
878 .regmap_config = &meson_sar_adc_regmap_config_meson8, 897 .regmap_config = &meson_sar_adc_regmap_config_meson8,
879 .resolution = 10, 898 .resolution = 10,
@@ -882,6 +901,7 @@ static const struct meson_sar_adc_data meson_sar_adc_meson8b_data = {
882 901
883static const struct meson_sar_adc_data meson_sar_adc_gxbb_data = { 902static const struct meson_sar_adc_data meson_sar_adc_gxbb_data = {
884 .has_bl30_integration = true, 903 .has_bl30_integration = true,
904 .clock_rate = 1200000,
885 .bandgap_reg = MESON_SAR_ADC_REG11, 905 .bandgap_reg = MESON_SAR_ADC_REG11,
886 .regmap_config = &meson_sar_adc_regmap_config_gxbb, 906 .regmap_config = &meson_sar_adc_regmap_config_gxbb,
887 .resolution = 10, 907 .resolution = 10,
@@ -890,6 +910,7 @@ static const struct meson_sar_adc_data meson_sar_adc_gxbb_data = {
890 910
891static const struct meson_sar_adc_data meson_sar_adc_gxl_data = { 911static const struct meson_sar_adc_data meson_sar_adc_gxl_data = {
892 .has_bl30_integration = true, 912 .has_bl30_integration = true,
913 .clock_rate = 1200000,
893 .bandgap_reg = MESON_SAR_ADC_REG11, 914 .bandgap_reg = MESON_SAR_ADC_REG11,
894 .regmap_config = &meson_sar_adc_regmap_config_gxbb, 915 .regmap_config = &meson_sar_adc_regmap_config_gxbb,
895 .resolution = 12, 916 .resolution = 12,
@@ -898,6 +919,7 @@ static const struct meson_sar_adc_data meson_sar_adc_gxl_data = {
898 919
899static const struct meson_sar_adc_data meson_sar_adc_gxm_data = { 920static const struct meson_sar_adc_data meson_sar_adc_gxm_data = {
900 .has_bl30_integration = true, 921 .has_bl30_integration = true,
922 .clock_rate = 1200000,
901 .bandgap_reg = MESON_SAR_ADC_REG11, 923 .bandgap_reg = MESON_SAR_ADC_REG11,
902 .regmap_config = &meson_sar_adc_regmap_config_gxbb, 924 .regmap_config = &meson_sar_adc_regmap_config_gxbb,
903 .resolution = 12, 925 .resolution = 12,
@@ -993,16 +1015,6 @@ static int meson_sar_adc_probe(struct platform_device *pdev)
993 return PTR_ERR(priv->core_clk); 1015 return PTR_ERR(priv->core_clk);
994 } 1016 }
995 1017
996 priv->sana_clk = devm_clk_get(&pdev->dev, "sana");
997 if (IS_ERR(priv->sana_clk)) {
998 if (PTR_ERR(priv->sana_clk) == -ENOENT) {
999 priv->sana_clk = NULL;
1000 } else {
1001 dev_err(&pdev->dev, "failed to get sana clk\n");
1002 return PTR_ERR(priv->sana_clk);
1003 }
1004 }
1005
1006 priv->adc_clk = devm_clk_get(&pdev->dev, "adc_clk"); 1018 priv->adc_clk = devm_clk_get(&pdev->dev, "adc_clk");
1007 if (IS_ERR(priv->adc_clk)) { 1019 if (IS_ERR(priv->adc_clk)) {
1008 if (PTR_ERR(priv->adc_clk) == -ENOENT) { 1020 if (PTR_ERR(priv->adc_clk) == -ENOENT) {
diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
index 47d24ae5462f..fe3d7826783c 100644
--- a/drivers/iio/adc/qcom-vadc-common.c
+++ b/drivers/iio/adc/qcom-vadc-common.c
@@ -5,6 +5,7 @@
5#include <linux/math64.h> 5#include <linux/math64.h>
6#include <linux/log2.h> 6#include <linux/log2.h>
7#include <linux/err.h> 7#include <linux/err.h>
8#include <linux/module.h>
8 9
9#include "qcom-vadc-common.h" 10#include "qcom-vadc-common.h"
10 11
@@ -229,3 +230,6 @@ int qcom_vadc_decimation_from_dt(u32 value)
229 return __ffs64(value / VADC_DECIMATION_MIN); 230 return __ffs64(value / VADC_DECIMATION_MIN);
230} 231}
231EXPORT_SYMBOL(qcom_vadc_decimation_from_dt); 232EXPORT_SYMBOL(qcom_vadc_decimation_from_dt);
233
234MODULE_LICENSE("GPL v2");
235MODULE_DESCRIPTION("Qualcomm ADC common functionality");
diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
index 6aefef99f935..40be7d9fadbf 100644
--- a/drivers/iio/adc/stm32-adc-core.c
+++ b/drivers/iio/adc/stm32-adc-core.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is part of STM32 ADC driver 3 * This file is part of STM32 ADC driver
3 * 4 *
@@ -6,19 +7,6 @@
6 * 7 *
7 * Inspired from: fsl-imx25-tsadc 8 * Inspired from: fsl-imx25-tsadc
8 * 9 *
9 * License type: GPLv2
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as published by
13 * the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE.
18 * See the GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * this program. If not, see <http://www.gnu.org/licenses/>.
22 */ 10 */
23 11
24#include <linux/clk.h> 12#include <linux/clk.h>
diff --git a/drivers/iio/adc/stm32-adc-core.h b/drivers/iio/adc/stm32-adc-core.h
index 250ee958a669..8af507b3f32d 100644
--- a/drivers/iio/adc/stm32-adc-core.h
+++ b/drivers/iio/adc/stm32-adc-core.h
@@ -1,22 +1,10 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This file is part of STM32 ADC driver 3 * This file is part of STM32 ADC driver
3 * 4 *
4 * Copyright (C) 2016, STMicroelectronics - All Rights Reserved 5 * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
5 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>. 6 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>.
6 * 7 *
7 * License type: GPLv2
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published by
11 * the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
20 */ 8 */
21 9
22#ifndef __STM32_ADC_H 10#ifndef __STM32_ADC_H
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index c9d96f935dba..7f5def465340 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -1,22 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is part of STM32 ADC driver 3 * This file is part of STM32 ADC driver
3 * 4 *
4 * Copyright (C) 2016, STMicroelectronics - All Rights Reserved 5 * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
5 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>. 6 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>.
6 *
7 * License type: GPLv2
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published by
11 * the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
20 */ 7 */
21 8
22#include <linux/clk.h> 9#include <linux/clk.h>
@@ -92,6 +79,7 @@
92#define STM32H7_ADC_SQR3 0x38 79#define STM32H7_ADC_SQR3 0x38
93#define STM32H7_ADC_SQR4 0x3C 80#define STM32H7_ADC_SQR4 0x3C
94#define STM32H7_ADC_DR 0x40 81#define STM32H7_ADC_DR 0x40
82#define STM32H7_ADC_DIFSEL 0xC0
95#define STM32H7_ADC_CALFACT 0xC4 83#define STM32H7_ADC_CALFACT 0xC4
96#define STM32H7_ADC_CALFACT2 0xC8 84#define STM32H7_ADC_CALFACT2 0xC8
97 85
@@ -153,6 +141,8 @@ enum stm32h7_adc_dmngt {
153/* BOOST bit must be set on STM32H7 when ADC clock is above 20MHz */ 141/* BOOST bit must be set on STM32H7 when ADC clock is above 20MHz */
154#define STM32H7_BOOST_CLKRATE 20000000UL 142#define STM32H7_BOOST_CLKRATE 20000000UL
155 143
144#define STM32_ADC_CH_MAX 20 /* max number of channels */
145#define STM32_ADC_CH_SZ 10 /* max channel name size */
156#define STM32_ADC_MAX_SQ 16 /* SQ1..SQ16 */ 146#define STM32_ADC_MAX_SQ 16 /* SQ1..SQ16 */
157#define STM32_ADC_MAX_SMP 7 /* SMPx range is [0..7] */ 147#define STM32_ADC_MAX_SMP 7 /* SMPx range is [0..7] */
158#define STM32_ADC_TIMEOUT_US 100000 148#define STM32_ADC_TIMEOUT_US 100000
@@ -297,9 +287,11 @@ struct stm32_adc_cfg {
297 * @rx_buf: dma rx buffer cpu address 287 * @rx_buf: dma rx buffer cpu address
298 * @rx_dma_buf: dma rx buffer bus address 288 * @rx_dma_buf: dma rx buffer bus address
299 * @rx_buf_sz: dma rx buffer size 289 * @rx_buf_sz: dma rx buffer size
290 * @difsel bitmask to set single-ended/differential channel
300 * @pcsel bitmask to preselect channels on some devices 291 * @pcsel bitmask to preselect channels on some devices
301 * @smpr_val: sampling time settings (e.g. smpr1 / smpr2) 292 * @smpr_val: sampling time settings (e.g. smpr1 / smpr2)
302 * @cal: optional calibration data on some devices 293 * @cal: optional calibration data on some devices
294 * @chan_name: channel name array
303 */ 295 */
304struct stm32_adc { 296struct stm32_adc {
305 struct stm32_adc_common *common; 297 struct stm32_adc_common *common;
@@ -318,72 +310,37 @@ struct stm32_adc {
318 u8 *rx_buf; 310 u8 *rx_buf;
319 dma_addr_t rx_dma_buf; 311 dma_addr_t rx_dma_buf;
320 unsigned int rx_buf_sz; 312 unsigned int rx_buf_sz;
313 u32 difsel;
321 u32 pcsel; 314 u32 pcsel;
322 u32 smpr_val[2]; 315 u32 smpr_val[2];
323 struct stm32_adc_calib cal; 316 struct stm32_adc_calib cal;
317 char chan_name[STM32_ADC_CH_MAX][STM32_ADC_CH_SZ];
324}; 318};
325 319
326/** 320struct stm32_adc_diff_channel {
327 * struct stm32_adc_chan_spec - specification of stm32 adc channel 321 u32 vinp;
328 * @type: IIO channel type 322 u32 vinn;
329 * @channel: channel number (single ended)
330 * @name: channel name (single ended)
331 */
332struct stm32_adc_chan_spec {
333 enum iio_chan_type type;
334 int channel;
335 const char *name;
336}; 323};
337 324
338/** 325/**
339 * struct stm32_adc_info - stm32 ADC, per instance config data 326 * struct stm32_adc_info - stm32 ADC, per instance config data
340 * @channels: Reference to stm32 channels spec
341 * @max_channels: Number of channels 327 * @max_channels: Number of channels
342 * @resolutions: available resolutions 328 * @resolutions: available resolutions
343 * @num_res: number of available resolutions 329 * @num_res: number of available resolutions
344 */ 330 */
345struct stm32_adc_info { 331struct stm32_adc_info {
346 const struct stm32_adc_chan_spec *channels;
347 int max_channels; 332 int max_channels;
348 const unsigned int *resolutions; 333 const unsigned int *resolutions;
349 const unsigned int num_res; 334 const unsigned int num_res;
350}; 335};
351 336
352/*
353 * Input definitions common for all instances:
354 * stm32f4 can have up to 16 channels
355 * stm32h7 can have up to 20 channels
356 */
357static const struct stm32_adc_chan_spec stm32_adc_channels[] = {
358 { IIO_VOLTAGE, 0, "in0" },
359 { IIO_VOLTAGE, 1, "in1" },
360 { IIO_VOLTAGE, 2, "in2" },
361 { IIO_VOLTAGE, 3, "in3" },
362 { IIO_VOLTAGE, 4, "in4" },
363 { IIO_VOLTAGE, 5, "in5" },
364 { IIO_VOLTAGE, 6, "in6" },
365 { IIO_VOLTAGE, 7, "in7" },
366 { IIO_VOLTAGE, 8, "in8" },
367 { IIO_VOLTAGE, 9, "in9" },
368 { IIO_VOLTAGE, 10, "in10" },
369 { IIO_VOLTAGE, 11, "in11" },
370 { IIO_VOLTAGE, 12, "in12" },
371 { IIO_VOLTAGE, 13, "in13" },
372 { IIO_VOLTAGE, 14, "in14" },
373 { IIO_VOLTAGE, 15, "in15" },
374 { IIO_VOLTAGE, 16, "in16" },
375 { IIO_VOLTAGE, 17, "in17" },
376 { IIO_VOLTAGE, 18, "in18" },
377 { IIO_VOLTAGE, 19, "in19" },
378};
379
380static const unsigned int stm32f4_adc_resolutions[] = { 337static const unsigned int stm32f4_adc_resolutions[] = {
381 /* sorted values so the index matches RES[1:0] in STM32F4_ADC_CR1 */ 338 /* sorted values so the index matches RES[1:0] in STM32F4_ADC_CR1 */
382 12, 10, 8, 6, 339 12, 10, 8, 6,
383}; 340};
384 341
342/* stm32f4 can have up to 16 channels */
385static const struct stm32_adc_info stm32f4_adc_info = { 343static const struct stm32_adc_info stm32f4_adc_info = {
386 .channels = stm32_adc_channels,
387 .max_channels = 16, 344 .max_channels = 16,
388 .resolutions = stm32f4_adc_resolutions, 345 .resolutions = stm32f4_adc_resolutions,
389 .num_res = ARRAY_SIZE(stm32f4_adc_resolutions), 346 .num_res = ARRAY_SIZE(stm32f4_adc_resolutions),
@@ -394,9 +351,9 @@ static const unsigned int stm32h7_adc_resolutions[] = {
394 16, 14, 12, 10, 8, 351 16, 14, 12, 10, 8,
395}; 352};
396 353
354/* stm32h7 can have up to 20 channels */
397static const struct stm32_adc_info stm32h7_adc_info = { 355static const struct stm32_adc_info stm32h7_adc_info = {
398 .channels = stm32_adc_channels, 356 .max_channels = STM32_ADC_CH_MAX,
399 .max_channels = 20,
400 .resolutions = stm32h7_adc_resolutions, 357 .resolutions = stm32h7_adc_resolutions,
401 .num_res = ARRAY_SIZE(stm32h7_adc_resolutions), 358 .num_res = ARRAY_SIZE(stm32h7_adc_resolutions),
402}; 359};
@@ -983,15 +940,19 @@ pwr_dwn:
983 * stm32h7_adc_prepare() - Leave power down mode to enable ADC. 940 * stm32h7_adc_prepare() - Leave power down mode to enable ADC.
984 * @adc: stm32 adc instance 941 * @adc: stm32 adc instance
985 * Leave power down mode. 942 * Leave power down mode.
943 * Configure channels as single ended or differential before enabling ADC.
986 * Enable ADC. 944 * Enable ADC.
987 * Restore calibration data. 945 * Restore calibration data.
988 * Pre-select channels that may be used in PCSEL (required by input MUX / IO). 946 * Pre-select channels that may be used in PCSEL (required by input MUX / IO):
947 * - Only one input is selected for single ended (e.g. 'vinp')
948 * - Two inputs are selected for differential channels (e.g. 'vinp' & 'vinn')
989 */ 949 */
990static int stm32h7_adc_prepare(struct stm32_adc *adc) 950static int stm32h7_adc_prepare(struct stm32_adc *adc)
991{ 951{
992 int ret; 952 int ret;
993 953
994 stm32h7_adc_exit_pwr_down(adc); 954 stm32h7_adc_exit_pwr_down(adc);
955 stm32_adc_writel(adc, STM32H7_ADC_DIFSEL, adc->difsel);
995 956
996 ret = stm32h7_adc_enable(adc); 957 ret = stm32h7_adc_enable(adc);
997 if (ret) 958 if (ret)
@@ -1263,10 +1224,23 @@ static int stm32_adc_read_raw(struct iio_dev *indio_dev,
1263 return ret; 1224 return ret;
1264 1225
1265 case IIO_CHAN_INFO_SCALE: 1226 case IIO_CHAN_INFO_SCALE:
1266 *val = adc->common->vref_mv; 1227 if (chan->differential) {
1267 *val2 = chan->scan_type.realbits; 1228 *val = adc->common->vref_mv * 2;
1229 *val2 = chan->scan_type.realbits;
1230 } else {
1231 *val = adc->common->vref_mv;
1232 *val2 = chan->scan_type.realbits;
1233 }
1268 return IIO_VAL_FRACTIONAL_LOG2; 1234 return IIO_VAL_FRACTIONAL_LOG2;
1269 1235
1236 case IIO_CHAN_INFO_OFFSET:
1237 if (chan->differential)
1238 /* ADC_full_scale / 2 */
1239 *val = -((1 << chan->scan_type.realbits) / 2);
1240 else
1241 *val = 0;
1242 return IIO_VAL_INT;
1243
1270 default: 1244 default:
1271 return -EINVAL; 1245 return -EINVAL;
1272 } 1246 }
@@ -1315,6 +1289,7 @@ static int stm32_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val)
1315{ 1289{
1316 struct stm32_adc *adc = iio_priv(indio_dev); 1290 struct stm32_adc *adc = iio_priv(indio_dev);
1317 unsigned int watermark = STM32_DMA_BUFFER_SIZE / 2; 1291 unsigned int watermark = STM32_DMA_BUFFER_SIZE / 2;
1292 unsigned int rx_buf_sz = STM32_DMA_BUFFER_SIZE;
1318 1293
1319 /* 1294 /*
1320 * dma cyclic transfers are used, buffer is split into two periods. 1295 * dma cyclic transfers are used, buffer is split into two periods.
@@ -1323,7 +1298,7 @@ static int stm32_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val)
1323 * - one buffer (period) driver can push with iio_trigger_poll(). 1298 * - one buffer (period) driver can push with iio_trigger_poll().
1324 */ 1299 */
1325 watermark = min(watermark, val * (unsigned)(sizeof(u16))); 1300 watermark = min(watermark, val * (unsigned)(sizeof(u16)));
1326 adc->rx_buf_sz = watermark * 2; 1301 adc->rx_buf_sz = min(rx_buf_sz, watermark * 2 * adc->num_conv);
1327 1302
1328 return 0; 1303 return 0;
1329} 1304}
@@ -1628,29 +1603,40 @@ static void stm32_adc_smpr_init(struct stm32_adc *adc, int channel, u32 smp_ns)
1628} 1603}
1629 1604
1630static void stm32_adc_chan_init_one(struct iio_dev *indio_dev, 1605static void stm32_adc_chan_init_one(struct iio_dev *indio_dev,
1631 struct iio_chan_spec *chan, 1606 struct iio_chan_spec *chan, u32 vinp,
1632 const struct stm32_adc_chan_spec *channel, 1607 u32 vinn, int scan_index, bool differential)
1633 int scan_index, u32 smp)
1634{ 1608{
1635 struct stm32_adc *adc = iio_priv(indio_dev); 1609 struct stm32_adc *adc = iio_priv(indio_dev);
1636 1610 char *name = adc->chan_name[vinp];
1637 chan->type = channel->type; 1611
1638 chan->channel = channel->channel; 1612 chan->type = IIO_VOLTAGE;
1639 chan->datasheet_name = channel->name; 1613 chan->channel = vinp;
1614 if (differential) {
1615 chan->differential = 1;
1616 chan->channel2 = vinn;
1617 snprintf(name, STM32_ADC_CH_SZ, "in%d-in%d", vinp, vinn);
1618 } else {
1619 snprintf(name, STM32_ADC_CH_SZ, "in%d", vinp);
1620 }
1621 chan->datasheet_name = name;
1640 chan->scan_index = scan_index; 1622 chan->scan_index = scan_index;
1641 chan->indexed = 1; 1623 chan->indexed = 1;
1642 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); 1624 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
1643 chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); 1625 chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |
1626 BIT(IIO_CHAN_INFO_OFFSET);
1644 chan->scan_type.sign = 'u'; 1627 chan->scan_type.sign = 'u';
1645 chan->scan_type.realbits = adc->cfg->adc_info->resolutions[adc->res]; 1628 chan->scan_type.realbits = adc->cfg->adc_info->resolutions[adc->res];
1646 chan->scan_type.storagebits = 16; 1629 chan->scan_type.storagebits = 16;
1647 chan->ext_info = stm32_adc_ext_info; 1630 chan->ext_info = stm32_adc_ext_info;
1648 1631
1649 /* Prepare sampling time settings */
1650 stm32_adc_smpr_init(adc, chan->channel, smp);
1651
1652 /* pre-build selected channels mask */ 1632 /* pre-build selected channels mask */
1653 adc->pcsel |= BIT(chan->channel); 1633 adc->pcsel |= BIT(chan->channel);
1634 if (differential) {
1635 /* pre-build diff channels mask */
1636 adc->difsel |= BIT(chan->channel);
1637 /* Also add negative input to pre-selected channels */
1638 adc->pcsel |= BIT(chan->channel2);
1639 }
1654} 1640}
1655 1641
1656static int stm32_adc_chan_of_init(struct iio_dev *indio_dev) 1642static int stm32_adc_chan_of_init(struct iio_dev *indio_dev)
@@ -1658,17 +1644,40 @@ static int stm32_adc_chan_of_init(struct iio_dev *indio_dev)
1658 struct device_node *node = indio_dev->dev.of_node; 1644 struct device_node *node = indio_dev->dev.of_node;
1659 struct stm32_adc *adc = iio_priv(indio_dev); 1645 struct stm32_adc *adc = iio_priv(indio_dev);
1660 const struct stm32_adc_info *adc_info = adc->cfg->adc_info; 1646 const struct stm32_adc_info *adc_info = adc->cfg->adc_info;
1647 struct stm32_adc_diff_channel diff[STM32_ADC_CH_MAX];
1661 struct property *prop; 1648 struct property *prop;
1662 const __be32 *cur; 1649 const __be32 *cur;
1663 struct iio_chan_spec *channels; 1650 struct iio_chan_spec *channels;
1664 int scan_index = 0, num_channels, ret; 1651 int scan_index = 0, num_channels = 0, num_diff = 0, ret, i;
1665 u32 val, smp = 0; 1652 u32 val, smp = 0;
1666 1653
1667 num_channels = of_property_count_u32_elems(node, "st,adc-channels"); 1654 ret = of_property_count_u32_elems(node, "st,adc-channels");
1668 if (num_channels < 0 || 1655 if (ret > adc_info->max_channels) {
1669 num_channels > adc_info->max_channels) {
1670 dev_err(&indio_dev->dev, "Bad st,adc-channels?\n"); 1656 dev_err(&indio_dev->dev, "Bad st,adc-channels?\n");
1671 return num_channels < 0 ? num_channels : -EINVAL; 1657 return -EINVAL;
1658 } else if (ret > 0) {
1659 num_channels += ret;
1660 }
1661
1662 ret = of_property_count_elems_of_size(node, "st,adc-diff-channels",
1663 sizeof(*diff));
1664 if (ret > adc_info->max_channels) {
1665 dev_err(&indio_dev->dev, "Bad st,adc-diff-channels?\n");
1666 return -EINVAL;
1667 } else if (ret > 0) {
1668 int size = ret * sizeof(*diff) / sizeof(u32);
1669
1670 num_diff = ret;
1671 num_channels += ret;
1672 ret = of_property_read_u32_array(node, "st,adc-diff-channels",
1673 (u32 *)diff, size);
1674 if (ret)
1675 return ret;
1676 }
1677
1678 if (!num_channels) {
1679 dev_err(&indio_dev->dev, "No channels configured\n");
1680 return -ENODATA;
1672 } 1681 }
1673 1682
1674 /* Optional sample time is provided either for each, or all channels */ 1683 /* Optional sample time is provided either for each, or all channels */
@@ -1689,6 +1698,33 @@ static int stm32_adc_chan_of_init(struct iio_dev *indio_dev)
1689 return -EINVAL; 1698 return -EINVAL;
1690 } 1699 }
1691 1700
1701 /* Channel can't be configured both as single-ended & diff */
1702 for (i = 0; i < num_diff; i++) {
1703 if (val == diff[i].vinp) {
1704 dev_err(&indio_dev->dev,
1705 "channel %d miss-configured\n", val);
1706 return -EINVAL;
1707 }
1708 }
1709 stm32_adc_chan_init_one(indio_dev, &channels[scan_index], val,
1710 0, scan_index, false);
1711 scan_index++;
1712 }
1713
1714 for (i = 0; i < num_diff; i++) {
1715 if (diff[i].vinp >= adc_info->max_channels ||
1716 diff[i].vinn >= adc_info->max_channels) {
1717 dev_err(&indio_dev->dev, "Invalid channel in%d-in%d\n",
1718 diff[i].vinp, diff[i].vinn);
1719 return -EINVAL;
1720 }
1721 stm32_adc_chan_init_one(indio_dev, &channels[scan_index],
1722 diff[i].vinp, diff[i].vinn, scan_index,
1723 true);
1724 scan_index++;
1725 }
1726
1727 for (i = 0; i < scan_index; i++) {
1692 /* 1728 /*
1693 * Using of_property_read_u32_index(), smp value will only be 1729 * Using of_property_read_u32_index(), smp value will only be
1694 * modified if valid u32 value can be decoded. This allows to 1730 * modified if valid u32 value can be decoded. This allows to
@@ -1696,12 +1732,9 @@ static int stm32_adc_chan_of_init(struct iio_dev *indio_dev)
1696 * value per channel. 1732 * value per channel.
1697 */ 1733 */
1698 of_property_read_u32_index(node, "st,min-sample-time-nsecs", 1734 of_property_read_u32_index(node, "st,min-sample-time-nsecs",
1699 scan_index, &smp); 1735 i, &smp);
1700 1736 /* Prepare sampling time settings */
1701 stm32_adc_chan_init_one(indio_dev, &channels[scan_index], 1737 stm32_adc_smpr_init(adc, channels[i].channel, smp);
1702 &adc_info->channels[val],
1703 scan_index, smp);
1704 scan_index++;
1705 } 1738 }
1706 1739
1707 indio_dev->num_channels = scan_index; 1740 indio_dev->num_channels = scan_index;
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index b3e573cc6f5f..80df5a377d30 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -523,7 +523,7 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
523 } 523 }
524 am335x_tsc_se_adc_done(adc_dev->mfd_tscadc); 524 am335x_tsc_se_adc_done(adc_dev->mfd_tscadc);
525 525
526 if (found == false) 526 if (!found)
527 ret = -EBUSY; 527 ret = -EBUSY;
528 528
529err_unlock: 529err_unlock:
diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c
index 97bce8345c6a..fbe2431f5b81 100644
--- a/drivers/iio/chemical/ccs811.c
+++ b/drivers/iio/chemical/ccs811.c
@@ -96,7 +96,6 @@ static const struct iio_chan_spec ccs811_channels[] = {
96 .channel2 = IIO_MOD_CO2, 96 .channel2 = IIO_MOD_CO2,
97 .modified = 1, 97 .modified = 1,
98 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 98 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
99 BIT(IIO_CHAN_INFO_OFFSET) |
100 BIT(IIO_CHAN_INFO_SCALE), 99 BIT(IIO_CHAN_INFO_SCALE),
101 .scan_index = 0, 100 .scan_index = 0,
102 .scan_type = { 101 .scan_type = {
@@ -255,24 +254,18 @@ static int ccs811_read_raw(struct iio_dev *indio_dev,
255 switch (chan->channel2) { 254 switch (chan->channel2) {
256 case IIO_MOD_CO2: 255 case IIO_MOD_CO2:
257 *val = 0; 256 *val = 0;
258 *val2 = 12834; 257 *val2 = 100;
259 return IIO_VAL_INT_PLUS_MICRO; 258 return IIO_VAL_INT_PLUS_MICRO;
260 case IIO_MOD_VOC: 259 case IIO_MOD_VOC:
261 *val = 0; 260 *val = 0;
262 *val2 = 84246; 261 *val2 = 100;
263 return IIO_VAL_INT_PLUS_MICRO; 262 return IIO_VAL_INT_PLUS_NANO;
264 default: 263 default:
265 return -EINVAL; 264 return -EINVAL;
266 } 265 }
267 default: 266 default:
268 return -EINVAL; 267 return -EINVAL;
269 } 268 }
270 case IIO_CHAN_INFO_OFFSET:
271 if (!(chan->type == IIO_CONCENTRATION &&
272 chan->channel2 == IIO_MOD_CO2))
273 return -EINVAL;
274 *val = -400;
275 return IIO_VAL_INT;
276 default: 269 default:
277 return -EINVAL; 270 return -EINVAL;
278 } 271 }
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
index ed8063f2da99..7d30c59da3e2 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
@@ -191,7 +191,6 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)
191{ 191{
192 struct device *dev = &pdev->dev; 192 struct device *dev = &pdev->dev;
193 struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent); 193 struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
194 struct cros_ec_device *ec_device;
195 struct iio_dev *indio_dev; 194 struct iio_dev *indio_dev;
196 struct cros_ec_sensors_state *state; 195 struct cros_ec_sensors_state *state;
197 struct iio_chan_spec *channel; 196 struct iio_chan_spec *channel;
@@ -201,7 +200,6 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)
201 dev_warn(&pdev->dev, "No CROS EC device found.\n"); 200 dev_warn(&pdev->dev, "No CROS EC device found.\n");
202 return -EINVAL; 201 return -EINVAL;
203 } 202 }
204 ec_device = ec_dev->ec_dev;
205 203
206 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state)); 204 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state));
207 if (!indio_dev) 205 if (!indio_dev)
diff --git a/drivers/iio/common/ssp_sensors/ssp.h b/drivers/iio/common/ssp_sensors/ssp.h
index b910e91d7c0d..82a01addd919 100644
--- a/drivers/iio/common/ssp_sensors/ssp.h
+++ b/drivers/iio/common/ssp_sensors/ssp.h
@@ -188,7 +188,7 @@ struct ssp_sensorhub_info {
188 */ 188 */
189struct ssp_data { 189struct ssp_data {
190 struct spi_device *spi; 190 struct spi_device *spi;
191 struct ssp_sensorhub_info *sensorhub_info; 191 const struct ssp_sensorhub_info *sensorhub_info;
192 struct timer_list wdt_timer; 192 struct timer_list wdt_timer;
193 struct work_struct work_wdt; 193 struct work_struct work_wdt;
194 struct delayed_work work_refresh; 194 struct delayed_work work_refresh;
diff --git a/drivers/iio/common/ssp_sensors/ssp_dev.c b/drivers/iio/common/ssp_sensors/ssp_dev.c
index 2ba2ff5e59c4..af3aa38f67cd 100644
--- a/drivers/iio/common/ssp_sensors/ssp_dev.c
+++ b/drivers/iio/common/ssp_sensors/ssp_dev.c
@@ -486,7 +486,7 @@ static struct ssp_data *ssp_parse_dt(struct device *dev)
486 if (!match) 486 if (!match)
487 goto err_mcu_reset_gpio; 487 goto err_mcu_reset_gpio;
488 488
489 data->sensorhub_info = (struct ssp_sensorhub_info *)match->data; 489 data->sensorhub_info = match->data;
490 490
491 dev_set_drvdata(dev, data); 491 dev_set_drvdata(dev, data);
492 492
diff --git a/drivers/iio/common/ssp_sensors/ssp_spi.c b/drivers/iio/common/ssp_sensors/ssp_spi.c
index 704284a475ae..2ab106bb3e03 100644
--- a/drivers/iio/common/ssp_sensors/ssp_spi.c
+++ b/drivers/iio/common/ssp_sensors/ssp_spi.c
@@ -277,12 +277,9 @@ static int ssp_handle_big_data(struct ssp_data *data, char *dataframe, int *idx)
277static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len) 277static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)
278{ 278{
279 int idx, sd; 279 int idx, sd;
280 struct timespec ts;
281 struct ssp_sensor_data *spd; 280 struct ssp_sensor_data *spd;
282 struct iio_dev **indio_devs = data->sensor_devs; 281 struct iio_dev **indio_devs = data->sensor_devs;
283 282
284 getnstimeofday(&ts);
285
286 for (idx = 0; idx < len;) { 283 for (idx = 0; idx < len;) {
287 switch (dataframe[idx++]) { 284 switch (dataframe[idx++]) {
288 case SSP_MSG2AP_INST_BYPASS_DATA: 285 case SSP_MSG2AP_INST_BYPASS_DATA:
@@ -329,7 +326,7 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)
329 } 326 }
330 327
331 if (data->time_syncing) 328 if (data->time_syncing)
332 data->timestamp = ts.tv_sec * 1000000000ULL + ts.tv_nsec; 329 data->timestamp = ktime_get_real_ns();
333 330
334 return 0; 331 return 0;
335} 332}
diff --git a/drivers/iio/counter/stm32-lptimer-cnt.c b/drivers/iio/counter/stm32-lptimer-cnt.c
index 81ae5f74216d..42fb8ba67090 100644
--- a/drivers/iio/counter/stm32-lptimer-cnt.c
+++ b/drivers/iio/counter/stm32-lptimer-cnt.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * STM32 Low-Power Timer Encoder and Counter driver 3 * STM32 Low-Power Timer Encoder and Counter driver
3 * 4 *
@@ -7,7 +8,6 @@
7 * 8 *
8 * Inspired by 104-quad-8 and stm32-timer-trigger drivers. 9 * Inspired by 104-quad-8 and stm32-timer-trigger drivers.
9 * 10 *
10 * License terms: GNU General Public License (GPL), version 2
11 */ 11 */
12 12
13#include <linux/bitfield.h> 13#include <linux/bitfield.h>
diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
index afa856d10c26..8b5aad4c32d9 100644
--- a/drivers/iio/dac/mcp4725.c
+++ b/drivers/iio/dac/mcp4725.c
@@ -476,7 +476,7 @@ static int mcp4725_probe(struct i2c_client *client,
476 goto err_disable_vref_reg; 476 goto err_disable_vref_reg;
477 } 477 }
478 pd = (inbuf[0] >> 1) & 0x3; 478 pd = (inbuf[0] >> 1) & 0x3;
479 data->powerdown = pd > 0 ? true : false; 479 data->powerdown = pd > 0;
480 data->powerdown_mode = pd ? pd - 1 : 2; /* largest resistor to gnd */ 480 data->powerdown_mode = pd ? pd - 1 : 2; /* largest resistor to gnd */
481 data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4); 481 data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4);
482 if (data->id == MCP4726) 482 if (data->id == MCP4726)
diff --git a/drivers/iio/dac/stm32-dac-core.c b/drivers/iio/dac/stm32-dac-core.c
index 55026fe1c610..d0fb3124de07 100644
--- a/drivers/iio/dac/stm32-dac-core.c
+++ b/drivers/iio/dac/stm32-dac-core.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is part of STM32 DAC driver 3 * This file is part of STM32 DAC driver
3 * 4 *
4 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved 5 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
5 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>. 6 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>.
6 * 7 *
7 * License type: GPLv2
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published by
11 * the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
20 */ 8 */
21 9
22#include <linux/clk.h> 10#include <linux/clk.h>
diff --git a/drivers/iio/dac/stm32-dac-core.h b/drivers/iio/dac/stm32-dac-core.h
index daf09931857c..d3b415fb9575 100644
--- a/drivers/iio/dac/stm32-dac-core.h
+++ b/drivers/iio/dac/stm32-dac-core.h
@@ -1,22 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This file is part of STM32 DAC driver 3 * This file is part of STM32 DAC driver
3 * 4 *
4 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved 5 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
5 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>. 6 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>.
6 *
7 * License type: GPLv2
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published by
11 * the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
20 */ 7 */
21 8
22#ifndef __STM32_DAC_CORE_H 9#ifndef __STM32_DAC_CORE_H
diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
index 9ffab02bf9f9..cce26a3a6627 100644
--- a/drivers/iio/dac/stm32-dac.c
+++ b/drivers/iio/dac/stm32-dac.c
@@ -1,23 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is part of STM32 DAC driver 3 * This file is part of STM32 DAC driver
3 * 4 *
4 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved 5 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
5 * Authors: Amelie Delaunay <amelie.delaunay@st.com> 6 * Authors: Amelie Delaunay <amelie.delaunay@st.com>
6 * Fabrice Gasnier <fabrice.gasnier@st.com> 7 * Fabrice Gasnier <fabrice.gasnier@st.com>
7 *
8 * License type: GPLv2
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */ 8 */
22 9
23#include <linux/bitfield.h> 10#include <linux/bitfield.h>
diff --git a/drivers/iio/dummy/iio_dummy_evgen.c b/drivers/iio/dummy/iio_dummy_evgen.c
index fe8884543da0..efd0005f59b4 100644
--- a/drivers/iio/dummy/iio_dummy_evgen.c
+++ b/drivers/iio/dummy/iio_dummy_evgen.c
@@ -56,7 +56,7 @@ static int iio_dummy_evgen_create(void)
56 return -ENOMEM; 56 return -ENOMEM;
57 57
58 ret = irq_sim_init(&iio_evgen->irq_sim, IIO_EVENTGEN_NO); 58 ret = irq_sim_init(&iio_evgen->irq_sim, IIO_EVENTGEN_NO);
59 if (ret) { 59 if (ret < 0) {
60 kfree(iio_evgen); 60 kfree(iio_evgen);
61 return ret; 61 return ret;
62 } 62 }
diff --git a/drivers/iio/gyro/adis16136.c b/drivers/iio/gyro/adis16136.c
index 90ec4bed62b7..605eee23780c 100644
--- a/drivers/iio/gyro/adis16136.c
+++ b/drivers/iio/gyro/adis16136.c
@@ -124,7 +124,7 @@ static int adis16136_show_product_id(void *arg, u64 *val)
124 124
125 return 0; 125 return 0;
126} 126}
127DEFINE_SIMPLE_ATTRIBUTE(adis16136_product_id_fops, 127DEFINE_DEBUGFS_ATTRIBUTE(adis16136_product_id_fops,
128 adis16136_show_product_id, NULL, "%llu\n"); 128 adis16136_show_product_id, NULL, "%llu\n");
129 129
130static int adis16136_show_flash_count(void *arg, u64 *val) 130static int adis16136_show_flash_count(void *arg, u64 *val)
@@ -142,18 +142,21 @@ static int adis16136_show_flash_count(void *arg, u64 *val)
142 142
143 return 0; 143 return 0;
144} 144}
145DEFINE_SIMPLE_ATTRIBUTE(adis16136_flash_count_fops, 145DEFINE_DEBUGFS_ATTRIBUTE(adis16136_flash_count_fops,
146 adis16136_show_flash_count, NULL, "%lld\n"); 146 adis16136_show_flash_count, NULL, "%lld\n");
147 147
148static int adis16136_debugfs_init(struct iio_dev *indio_dev) 148static int adis16136_debugfs_init(struct iio_dev *indio_dev)
149{ 149{
150 struct adis16136 *adis16136 = iio_priv(indio_dev); 150 struct adis16136 *adis16136 = iio_priv(indio_dev);
151 151
152 debugfs_create_file("serial_number", 0400, indio_dev->debugfs_dentry, 152 debugfs_create_file_unsafe("serial_number", 0400,
153 adis16136, &adis16136_serial_fops); 153 indio_dev->debugfs_dentry, adis16136,
154 debugfs_create_file("product_id", 0400, indio_dev->debugfs_dentry, 154 &adis16136_serial_fops);
155 debugfs_create_file_unsafe("product_id", 0400,
156 indio_dev->debugfs_dentry,
155 adis16136, &adis16136_product_id_fops); 157 adis16136, &adis16136_product_id_fops);
156 debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry, 158 debugfs_create_file_unsafe("flash_count", 0400,
159 indio_dev->debugfs_dentry,
157 adis16136, &adis16136_flash_count_fops); 160 adis16136, &adis16136_flash_count_fops);
158 161
159 return 0; 162 return 0;
diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
index 15046172e437..63ca31628a93 100644
--- a/drivers/iio/gyro/bmg160_core.c
+++ b/drivers/iio/gyro/bmg160_core.c
@@ -27,7 +27,6 @@
27#include <linux/iio/trigger_consumer.h> 27#include <linux/iio/trigger_consumer.h>
28#include <linux/iio/triggered_buffer.h> 28#include <linux/iio/triggered_buffer.h>
29#include <linux/regmap.h> 29#include <linux/regmap.h>
30#include <linux/delay.h>
31#include "bmg160.h" 30#include "bmg160.h"
32 31
33#define BMG160_IRQ_NAME "bmg160_event" 32#define BMG160_IRQ_NAME "bmg160_event"
diff --git a/drivers/iio/health/max30102.c b/drivers/iio/health/max30102.c
index 147a8c14235f..15ccadc74891 100644
--- a/drivers/iio/health/max30102.c
+++ b/drivers/iio/health/max30102.c
@@ -3,6 +3,9 @@
3 * 3 *
4 * Copyright (C) 2017 Matt Ranostay <matt@ranostay.consulting> 4 * Copyright (C) 2017 Matt Ranostay <matt@ranostay.consulting>
5 * 5 *
6 * Support for MAX30105 optical particle sensor
7 * Copyright (C) 2017 Peter Meerwald-Stadler <pmeerw@pmeerw.net>
8 *
6 * 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
7 * 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
8 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
@@ -13,6 +16,7 @@
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 17 * GNU General Public License for more details.
15 * 18 *
19 * 7-bit I2C chip address: 0x57
16 * TODO: proximity power saving feature 20 * TODO: proximity power saving feature
17 */ 21 */
18 22
@@ -32,6 +36,18 @@
32 36
33#define MAX30102_REGMAP_NAME "max30102_regmap" 37#define MAX30102_REGMAP_NAME "max30102_regmap"
34#define MAX30102_DRV_NAME "max30102" 38#define MAX30102_DRV_NAME "max30102"
39#define MAX30102_PART_NUMBER 0x15
40
41enum max30102_chip_id {
42 max30102,
43 max30105,
44};
45
46enum max3012_led_idx {
47 MAX30102_LED_RED,
48 MAX30102_LED_IR,
49 MAX30105_LED_GREEN,
50};
35 51
36#define MAX30102_REG_INT_STATUS 0x00 52#define MAX30102_REG_INT_STATUS 0x00
37#define MAX30102_REG_INT_STATUS_PWR_RDY BIT(0) 53#define MAX30102_REG_INT_STATUS_PWR_RDY BIT(0)
@@ -52,7 +68,7 @@
52#define MAX30102_REG_FIFO_OVR_CTR 0x05 68#define MAX30102_REG_FIFO_OVR_CTR 0x05
53#define MAX30102_REG_FIFO_RD_PTR 0x06 69#define MAX30102_REG_FIFO_RD_PTR 0x06
54#define MAX30102_REG_FIFO_DATA 0x07 70#define MAX30102_REG_FIFO_DATA 0x07
55#define MAX30102_REG_FIFO_DATA_ENTRY_LEN 6 71#define MAX30102_REG_FIFO_DATA_BYTES 3
56 72
57#define MAX30102_REG_FIFO_CONFIG 0x08 73#define MAX30102_REG_FIFO_CONFIG 0x08
58#define MAX30102_REG_FIFO_CONFIG_AVG_4SAMPLES BIT(1) 74#define MAX30102_REG_FIFO_CONFIG_AVG_4SAMPLES BIT(1)
@@ -60,11 +76,18 @@
60#define MAX30102_REG_FIFO_CONFIG_AFULL BIT(0) 76#define MAX30102_REG_FIFO_CONFIG_AFULL BIT(0)
61 77
62#define MAX30102_REG_MODE_CONFIG 0x09 78#define MAX30102_REG_MODE_CONFIG 0x09
63#define MAX30102_REG_MODE_CONFIG_MODE_SPO2_EN BIT(0) 79#define MAX30102_REG_MODE_CONFIG_MODE_NONE 0x00
64#define MAX30102_REG_MODE_CONFIG_MODE_HR_EN BIT(1) 80#define MAX30102_REG_MODE_CONFIG_MODE_HR 0x02 /* red LED */
65#define MAX30102_REG_MODE_CONFIG_MODE_MASK 0x03 81#define MAX30102_REG_MODE_CONFIG_MODE_HR_SPO2 0x03 /* red + IR LED */
82#define MAX30102_REG_MODE_CONFIG_MODE_MULTI 0x07 /* multi-LED mode */
83#define MAX30102_REG_MODE_CONFIG_MODE_MASK GENMASK(2, 0)
66#define MAX30102_REG_MODE_CONFIG_PWR BIT(7) 84#define MAX30102_REG_MODE_CONFIG_PWR BIT(7)
67 85
86#define MAX30102_REG_MODE_CONTROL_SLOT21 0x11 /* multi-LED control */
87#define MAX30102_REG_MODE_CONTROL_SLOT43 0x12
88#define MAX30102_REG_MODE_CONTROL_SLOT_MASK (GENMASK(6, 4) | GENMASK(2, 0))
89#define MAX30102_REG_MODE_CONTROL_SLOT_SHIFT 4
90
68#define MAX30102_REG_SPO2_CONFIG 0x0a 91#define MAX30102_REG_SPO2_CONFIG 0x0a
69#define MAX30102_REG_SPO2_CONFIG_PULSE_411_US 0x03 92#define MAX30102_REG_SPO2_CONFIG_PULSE_411_US 0x03
70#define MAX30102_REG_SPO2_CONFIG_SR_400HZ 0x03 93#define MAX30102_REG_SPO2_CONFIG_SR_400HZ 0x03
@@ -75,6 +98,7 @@
75 98
76#define MAX30102_REG_RED_LED_CONFIG 0x0c 99#define MAX30102_REG_RED_LED_CONFIG 0x0c
77#define MAX30102_REG_IR_LED_CONFIG 0x0d 100#define MAX30102_REG_IR_LED_CONFIG 0x0d
101#define MAX30105_REG_GREEN_LED_CONFIG 0x0e
78 102
79#define MAX30102_REG_TEMP_CONFIG 0x21 103#define MAX30102_REG_TEMP_CONFIG 0x21
80#define MAX30102_REG_TEMP_CONFIG_TEMP_EN BIT(0) 104#define MAX30102_REG_TEMP_CONFIG_TEMP_EN BIT(0)
@@ -82,14 +106,18 @@
82#define MAX30102_REG_TEMP_INTEGER 0x1f 106#define MAX30102_REG_TEMP_INTEGER 0x1f
83#define MAX30102_REG_TEMP_FRACTION 0x20 107#define MAX30102_REG_TEMP_FRACTION 0x20
84 108
109#define MAX30102_REG_REV_ID 0xfe
110#define MAX30102_REG_PART_ID 0xff
111
85struct max30102_data { 112struct max30102_data {
86 struct i2c_client *client; 113 struct i2c_client *client;
87 struct iio_dev *indio_dev; 114 struct iio_dev *indio_dev;
88 struct mutex lock; 115 struct mutex lock;
89 struct regmap *regmap; 116 struct regmap *regmap;
117 enum max30102_chip_id chip_id;
90 118
91 u8 buffer[8]; 119 u8 buffer[12];
92 __be32 processed_buffer[2]; /* 2 x 18-bit (padded to 32-bits) */ 120 __be32 processed_buffer[3]; /* 3 x 18-bit (padded to 32-bits) */
93}; 121};
94 122
95static const struct regmap_config max30102_regmap_config = { 123static const struct regmap_config max30102_regmap_config = {
@@ -99,37 +127,47 @@ static const struct regmap_config max30102_regmap_config = {
99 .val_bits = 8, 127 .val_bits = 8,
100}; 128};
101 129
102static const unsigned long max30102_scan_masks[] = {0x3, 0}; 130static const unsigned long max30102_scan_masks[] = {
131 BIT(MAX30102_LED_RED) | BIT(MAX30102_LED_IR),
132 0
133};
134
135static const unsigned long max30105_scan_masks[] = {
136 BIT(MAX30102_LED_RED) | BIT(MAX30102_LED_IR),
137 BIT(MAX30102_LED_RED) | BIT(MAX30102_LED_IR) |
138 BIT(MAX30105_LED_GREEN),
139 0
140};
141
142#define MAX30102_INTENSITY_CHANNEL(_si, _mod) { \
143 .type = IIO_INTENSITY, \
144 .channel2 = _mod, \
145 .modified = 1, \
146 .scan_index = _si, \
147 .scan_type = { \
148 .sign = 'u', \
149 .shift = 8, \
150 .realbits = 18, \
151 .storagebits = 32, \
152 .endianness = IIO_BE, \
153 }, \
154 }
103 155
104static const struct iio_chan_spec max30102_channels[] = { 156static const struct iio_chan_spec max30102_channels[] = {
157 MAX30102_INTENSITY_CHANNEL(MAX30102_LED_RED, IIO_MOD_LIGHT_RED),
158 MAX30102_INTENSITY_CHANNEL(MAX30102_LED_IR, IIO_MOD_LIGHT_IR),
105 { 159 {
106 .type = IIO_INTENSITY, 160 .type = IIO_TEMP,
107 .channel2 = IIO_MOD_LIGHT_RED, 161 .info_mask_separate =
108 .modified = 1, 162 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
109 163 .scan_index = -1,
110 .scan_index = 0,
111 .scan_type = {
112 .sign = 'u',
113 .shift = 8,
114 .realbits = 18,
115 .storagebits = 32,
116 .endianness = IIO_BE,
117 },
118 },
119 {
120 .type = IIO_INTENSITY,
121 .channel2 = IIO_MOD_LIGHT_IR,
122 .modified = 1,
123
124 .scan_index = 1,
125 .scan_type = {
126 .sign = 'u',
127 .shift = 8,
128 .realbits = 18,
129 .storagebits = 32,
130 .endianness = IIO_BE,
131 },
132 }, 164 },
165};
166
167static const struct iio_chan_spec max30105_channels[] = {
168 MAX30102_INTENSITY_CHANNEL(MAX30102_LED_RED, IIO_MOD_LIGHT_RED),
169 MAX30102_INTENSITY_CHANNEL(MAX30102_LED_IR, IIO_MOD_LIGHT_IR),
170 MAX30102_INTENSITY_CHANNEL(MAX30105_LED_GREEN, IIO_MOD_LIGHT_GREEN),
133 { 171 {
134 .type = IIO_TEMP, 172 .type = IIO_TEMP,
135 .info_mask_separate = 173 .info_mask_separate =
@@ -138,25 +176,69 @@ static const struct iio_chan_spec max30102_channels[] = {
138 }, 176 },
139}; 177};
140 178
141static int max30102_set_powermode(struct max30102_data *data, bool state) 179static int max30102_set_power(struct max30102_data *data, bool en)
142{ 180{
143 return regmap_update_bits(data->regmap, MAX30102_REG_MODE_CONFIG, 181 return regmap_update_bits(data->regmap, MAX30102_REG_MODE_CONFIG,
144 MAX30102_REG_MODE_CONFIG_PWR, 182 MAX30102_REG_MODE_CONFIG_PWR,
145 state ? 0 : MAX30102_REG_MODE_CONFIG_PWR); 183 en ? 0 : MAX30102_REG_MODE_CONFIG_PWR);
146} 184}
147 185
186static int max30102_set_powermode(struct max30102_data *data, u8 mode, bool en)
187{
188 u8 reg = mode;
189
190 if (!en)
191 reg |= MAX30102_REG_MODE_CONFIG_PWR;
192
193 return regmap_update_bits(data->regmap, MAX30102_REG_MODE_CONFIG,
194 MAX30102_REG_MODE_CONFIG_PWR |
195 MAX30102_REG_MODE_CONFIG_MODE_MASK, reg);
196}
197
198#define MAX30102_MODE_CONTROL_LED_SLOTS(slot2, slot1) \
199 ((slot2 << MAX30102_REG_MODE_CONTROL_SLOT_SHIFT) | slot1)
200
148static int max30102_buffer_postenable(struct iio_dev *indio_dev) 201static int max30102_buffer_postenable(struct iio_dev *indio_dev)
149{ 202{
150 struct max30102_data *data = iio_priv(indio_dev); 203 struct max30102_data *data = iio_priv(indio_dev);
204 int ret;
205 u8 reg;
151 206
152 return max30102_set_powermode(data, true); 207 switch (*indio_dev->active_scan_mask) {
208 case BIT(MAX30102_LED_RED) | BIT(MAX30102_LED_IR):
209 reg = MAX30102_REG_MODE_CONFIG_MODE_HR_SPO2;
210 break;
211 case BIT(MAX30102_LED_RED) | BIT(MAX30102_LED_IR) |
212 BIT(MAX30105_LED_GREEN):
213 ret = regmap_update_bits(data->regmap,
214 MAX30102_REG_MODE_CONTROL_SLOT21,
215 MAX30102_REG_MODE_CONTROL_SLOT_MASK,
216 MAX30102_MODE_CONTROL_LED_SLOTS(2, 1));
217 if (ret)
218 return ret;
219
220 ret = regmap_update_bits(data->regmap,
221 MAX30102_REG_MODE_CONTROL_SLOT43,
222 MAX30102_REG_MODE_CONTROL_SLOT_MASK,
223 MAX30102_MODE_CONTROL_LED_SLOTS(0, 3));
224 if (ret)
225 return ret;
226
227 reg = MAX30102_REG_MODE_CONFIG_MODE_MULTI;
228 break;
229 default:
230 return -EINVAL;
231 }
232
233 return max30102_set_powermode(data, reg, true);
153} 234}
154 235
155static int max30102_buffer_predisable(struct iio_dev *indio_dev) 236static int max30102_buffer_predisable(struct iio_dev *indio_dev)
156{ 237{
157 struct max30102_data *data = iio_priv(indio_dev); 238 struct max30102_data *data = iio_priv(indio_dev);
158 239
159 return max30102_set_powermode(data, false); 240 return max30102_set_powermode(data, MAX30102_REG_MODE_CONFIG_MODE_NONE,
241 false);
160} 242}
161 243
162static const struct iio_buffer_setup_ops max30102_buffer_setup_ops = { 244static const struct iio_buffer_setup_ops max30102_buffer_setup_ops = {
@@ -180,32 +262,51 @@ static inline int max30102_fifo_count(struct max30102_data *data)
180 return 0; 262 return 0;
181} 263}
182 264
183static int max30102_read_measurement(struct max30102_data *data) 265#define MAX30102_COPY_DATA(i) \
266 memcpy(&data->processed_buffer[(i)], \
267 &buffer[(i) * MAX30102_REG_FIFO_DATA_BYTES], \
268 MAX30102_REG_FIFO_DATA_BYTES)
269
270static int max30102_read_measurement(struct max30102_data *data,
271 unsigned int measurements)
184{ 272{
185 int ret; 273 int ret;
186 u8 *buffer = (u8 *) &data->buffer; 274 u8 *buffer = (u8 *) &data->buffer;
187 275
188 ret = i2c_smbus_read_i2c_block_data(data->client, 276 ret = i2c_smbus_read_i2c_block_data(data->client,
189 MAX30102_REG_FIFO_DATA, 277 MAX30102_REG_FIFO_DATA,
190 MAX30102_REG_FIFO_DATA_ENTRY_LEN, 278 measurements *
279 MAX30102_REG_FIFO_DATA_BYTES,
191 buffer); 280 buffer);
192 281
193 memcpy(&data->processed_buffer[0], &buffer[0], 3); 282 switch (measurements) {
194 memcpy(&data->processed_buffer[1], &buffer[3], 3); 283 case 3:
284 MAX30102_COPY_DATA(2);
285 case 2: /* fall-through */
286 MAX30102_COPY_DATA(1);
287 case 1: /* fall-through */
288 MAX30102_COPY_DATA(0);
289 break;
290 default:
291 return -EINVAL;
292 }
195 293
196 return (ret == MAX30102_REG_FIFO_DATA_ENTRY_LEN) ? 0 : -EINVAL; 294 return (ret == measurements * MAX30102_REG_FIFO_DATA_BYTES) ?
295 0 : -EINVAL;
197} 296}
198 297
199static irqreturn_t max30102_interrupt_handler(int irq, void *private) 298static irqreturn_t max30102_interrupt_handler(int irq, void *private)
200{ 299{
201 struct iio_dev *indio_dev = private; 300 struct iio_dev *indio_dev = private;
202 struct max30102_data *data = iio_priv(indio_dev); 301 struct max30102_data *data = iio_priv(indio_dev);
302 unsigned int measurements = bitmap_weight(indio_dev->active_scan_mask,
303 indio_dev->masklength);
203 int ret, cnt = 0; 304 int ret, cnt = 0;
204 305
205 mutex_lock(&data->lock); 306 mutex_lock(&data->lock);
206 307
207 while (cnt || (cnt = max30102_fifo_count(data)) > 0) { 308 while (cnt || (cnt = max30102_fifo_count(data)) > 0) {
208 ret = max30102_read_measurement(data); 309 ret = max30102_read_measurement(data, measurements);
209 if (ret) 310 if (ret)
210 break; 311 break;
211 312
@@ -251,6 +352,29 @@ static int max30102_led_init(struct max30102_data *data)
251 if (ret) 352 if (ret)
252 return ret; 353 return ret;
253 354
355 if (data->chip_id == max30105) {
356 ret = of_property_read_u32(np,
357 "maxim,green-led-current-microamp", &val);
358 if (ret) {
359 dev_info(dev, "no green-led-current-microamp set\n");
360
361 /* Default to 7 mA green LED */
362 val = 7000;
363 }
364
365 ret = max30102_get_current_idx(val, &reg);
366 if (ret) {
367 dev_err(dev, "invalid green LED current setting %d\n",
368 val);
369 return ret;
370 }
371
372 ret = regmap_write(data->regmap, MAX30105_REG_GREEN_LED_CONFIG,
373 reg);
374 if (ret)
375 return ret;
376 }
377
254 ret = of_property_read_u32(np, "maxim,ir-led-current-microamp", &val); 378 ret = of_property_read_u32(np, "maxim,ir-led-current-microamp", &val);
255 if (ret) { 379 if (ret) {
256 dev_info(dev, "no ir-led-current-microamp set\n"); 380 dev_info(dev, "no ir-led-current-microamp set\n");
@@ -261,7 +385,7 @@ static int max30102_led_init(struct max30102_data *data)
261 385
262 ret = max30102_get_current_idx(val, &reg); 386 ret = max30102_get_current_idx(val, &reg);
263 if (ret) { 387 if (ret) {
264 dev_err(dev, "invalid IR LED current setting %d", val); 388 dev_err(dev, "invalid IR LED current setting %d\n", val);
265 return ret; 389 return ret;
266 } 390 }
267 391
@@ -277,7 +401,7 @@ static int max30102_chip_init(struct max30102_data *data)
277 if (ret) 401 if (ret)
278 return ret; 402 return ret;
279 403
280 /* enable 18-bit HR + SPO2 readings at 400Hz */ 404 /* configure 18-bit HR + SpO2 readings at 400Hz */
281 ret = regmap_write(data->regmap, MAX30102_REG_SPO2_CONFIG, 405 ret = regmap_write(data->regmap, MAX30102_REG_SPO2_CONFIG,
282 (MAX30102_REG_SPO2_CONFIG_ADC_4096_STEPS 406 (MAX30102_REG_SPO2_CONFIG_ADC_4096_STEPS
283 << MAX30102_REG_SPO2_CONFIG_ADC_MASK_SHIFT) | 407 << MAX30102_REG_SPO2_CONFIG_ADC_MASK_SHIFT) |
@@ -287,14 +411,6 @@ static int max30102_chip_init(struct max30102_data *data)
287 if (ret) 411 if (ret)
288 return ret; 412 return ret;
289 413
290 /* enable SPO2 mode */
291 ret = regmap_update_bits(data->regmap, MAX30102_REG_MODE_CONFIG,
292 MAX30102_REG_MODE_CONFIG_MODE_MASK,
293 MAX30102_REG_MODE_CONFIG_MODE_HR_EN |
294 MAX30102_REG_MODE_CONFIG_MODE_SPO2_EN);
295 if (ret)
296 return ret;
297
298 /* average 4 samples + generate FIFO interrupt */ 414 /* average 4 samples + generate FIFO interrupt */
299 ret = regmap_write(data->regmap, MAX30102_REG_FIFO_CONFIG, 415 ret = regmap_write(data->regmap, MAX30102_REG_FIFO_CONFIG,
300 (MAX30102_REG_FIFO_CONFIG_AVG_4SAMPLES 416 (MAX30102_REG_FIFO_CONFIG_AVG_4SAMPLES
@@ -329,20 +445,31 @@ static int max30102_read_temp(struct max30102_data *data, int *val)
329 return 0; 445 return 0;
330} 446}
331 447
332static int max30102_get_temp(struct max30102_data *data, int *val) 448static int max30102_get_temp(struct max30102_data *data, int *val, bool en)
333{ 449{
334 int ret; 450 int ret;
335 451
452 if (en) {
453 ret = max30102_set_power(data, true);
454 if (ret)
455 return ret;
456 }
457
336 /* start acquisition */ 458 /* start acquisition */
337 ret = regmap_update_bits(data->regmap, MAX30102_REG_TEMP_CONFIG, 459 ret = regmap_update_bits(data->regmap, MAX30102_REG_TEMP_CONFIG,
338 MAX30102_REG_TEMP_CONFIG_TEMP_EN, 460 MAX30102_REG_TEMP_CONFIG_TEMP_EN,
339 MAX30102_REG_TEMP_CONFIG_TEMP_EN); 461 MAX30102_REG_TEMP_CONFIG_TEMP_EN);
340 if (ret) 462 if (ret)
341 return ret; 463 goto out;
342 464
343 msleep(35); 465 msleep(35);
466 ret = max30102_read_temp(data, val);
344 467
345 return max30102_read_temp(data, val); 468out:
469 if (en)
470 max30102_set_power(data, false);
471
472 return ret;
346} 473}
347 474
348static int max30102_read_raw(struct iio_dev *indio_dev, 475static int max30102_read_raw(struct iio_dev *indio_dev,
@@ -355,20 +482,19 @@ static int max30102_read_raw(struct iio_dev *indio_dev,
355 switch (mask) { 482 switch (mask) {
356 case IIO_CHAN_INFO_RAW: 483 case IIO_CHAN_INFO_RAW:
357 /* 484 /*
358 * Temperature reading can only be acquired while engine 485 * Temperature reading can only be acquired when not in
359 * is running 486 * shutdown; leave shutdown briefly when buffer not running
360 */ 487 */
361 mutex_lock(&indio_dev->mlock); 488 mutex_lock(&indio_dev->mlock);
362
363 if (!iio_buffer_enabled(indio_dev)) 489 if (!iio_buffer_enabled(indio_dev))
364 ret = -EBUSY; 490 ret = max30102_get_temp(data, val, true);
365 else { 491 else
366 ret = max30102_get_temp(data, val); 492 ret = max30102_get_temp(data, val, false);
367 if (!ret)
368 ret = IIO_VAL_INT;
369 }
370
371 mutex_unlock(&indio_dev->mlock); 493 mutex_unlock(&indio_dev->mlock);
494 if (ret)
495 return ret;
496
497 ret = IIO_VAL_INT;
372 break; 498 break;
373 case IIO_CHAN_INFO_SCALE: 499 case IIO_CHAN_INFO_SCALE:
374 *val = 1000; /* 62.5 */ 500 *val = 1000; /* 62.5 */
@@ -391,6 +517,7 @@ static int max30102_probe(struct i2c_client *client,
391 struct iio_buffer *buffer; 517 struct iio_buffer *buffer;
392 struct iio_dev *indio_dev; 518 struct iio_dev *indio_dev;
393 int ret; 519 int ret;
520 unsigned int reg;
394 521
395 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 522 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
396 if (!indio_dev) 523 if (!indio_dev)
@@ -403,10 +530,7 @@ static int max30102_probe(struct i2c_client *client,
403 iio_device_attach_buffer(indio_dev, buffer); 530 iio_device_attach_buffer(indio_dev, buffer);
404 531
405 indio_dev->name = MAX30102_DRV_NAME; 532 indio_dev->name = MAX30102_DRV_NAME;
406 indio_dev->channels = max30102_channels;
407 indio_dev->info = &max30102_info; 533 indio_dev->info = &max30102_info;
408 indio_dev->num_channels = ARRAY_SIZE(max30102_channels);
409 indio_dev->available_scan_masks = max30102_scan_masks;
410 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE); 534 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
411 indio_dev->setup_ops = &max30102_buffer_setup_ops; 535 indio_dev->setup_ops = &max30102_buffer_setup_ops;
412 indio_dev->dev.parent = &client->dev; 536 indio_dev->dev.parent = &client->dev;
@@ -414,16 +538,50 @@ static int max30102_probe(struct i2c_client *client,
414 data = iio_priv(indio_dev); 538 data = iio_priv(indio_dev);
415 data->indio_dev = indio_dev; 539 data->indio_dev = indio_dev;
416 data->client = client; 540 data->client = client;
541 data->chip_id = id->driver_data;
417 542
418 mutex_init(&data->lock); 543 mutex_init(&data->lock);
419 i2c_set_clientdata(client, indio_dev); 544 i2c_set_clientdata(client, indio_dev);
420 545
546 switch (data->chip_id) {
547 case max30105:
548 indio_dev->channels = max30105_channels;
549 indio_dev->num_channels = ARRAY_SIZE(max30105_channels);
550 indio_dev->available_scan_masks = max30105_scan_masks;
551 break;
552 case max30102:
553 indio_dev->channels = max30102_channels;
554 indio_dev->num_channels = ARRAY_SIZE(max30102_channels);
555 indio_dev->available_scan_masks = max30102_scan_masks;
556 break;
557 default:
558 return -ENODEV;
559 }
560
421 data->regmap = devm_regmap_init_i2c(client, &max30102_regmap_config); 561 data->regmap = devm_regmap_init_i2c(client, &max30102_regmap_config);
422 if (IS_ERR(data->regmap)) { 562 if (IS_ERR(data->regmap)) {
423 dev_err(&client->dev, "regmap initialization failed.\n"); 563 dev_err(&client->dev, "regmap initialization failed\n");
424 return PTR_ERR(data->regmap); 564 return PTR_ERR(data->regmap);
425 } 565 }
426 max30102_set_powermode(data, false); 566
567 /* check part ID */
568 ret = regmap_read(data->regmap, MAX30102_REG_PART_ID, &reg);
569 if (ret)
570 return ret;
571 if (reg != MAX30102_PART_NUMBER)
572 return -ENODEV;
573
574 /* show revision ID */
575 ret = regmap_read(data->regmap, MAX30102_REG_REV_ID, &reg);
576 if (ret)
577 return ret;
578 dev_dbg(&client->dev, "max3010x revision %02x\n", reg);
579
580 /* clear mode setting, chip shutdown */
581 ret = max30102_set_powermode(data, MAX30102_REG_MODE_CONFIG_MODE_NONE,
582 false);
583 if (ret)
584 return ret;
427 585
428 ret = max30102_chip_init(data); 586 ret = max30102_chip_init(data);
429 if (ret) 587 if (ret)
@@ -452,19 +610,21 @@ static int max30102_remove(struct i2c_client *client)
452 struct max30102_data *data = iio_priv(indio_dev); 610 struct max30102_data *data = iio_priv(indio_dev);
453 611
454 iio_device_unregister(indio_dev); 612 iio_device_unregister(indio_dev);
455 max30102_set_powermode(data, false); 613 max30102_set_power(data, false);
456 614
457 return 0; 615 return 0;
458} 616}
459 617
460static const struct i2c_device_id max30102_id[] = { 618static const struct i2c_device_id max30102_id[] = {
461 { "max30102", 0 }, 619 { "max30102", max30102 },
620 { "max30105", max30105 },
462 {} 621 {}
463}; 622};
464MODULE_DEVICE_TABLE(i2c, max30102_id); 623MODULE_DEVICE_TABLE(i2c, max30102_id);
465 624
466static const struct of_device_id max30102_dt_ids[] = { 625static const struct of_device_id max30102_dt_ids[] = {
467 { .compatible = "maxim,max30102" }, 626 { .compatible = "maxim,max30102" },
627 { .compatible = "maxim,max30105" },
468 { } 628 { }
469}; 629};
470MODULE_DEVICE_TABLE(of, max30102_dt_ids); 630MODULE_DEVICE_TABLE(of, max30102_dt_ids);
@@ -481,5 +641,5 @@ static struct i2c_driver max30102_driver = {
481module_i2c_driver(max30102_driver); 641module_i2c_driver(max30102_driver);
482 642
483MODULE_AUTHOR("Matt Ranostay <matt@ranostay.consulting>"); 643MODULE_AUTHOR("Matt Ranostay <matt@ranostay.consulting>");
484MODULE_DESCRIPTION("MAX30102 heart rate and pulse oximeter sensor"); 644MODULE_DESCRIPTION("MAX30102 heart rate/pulse oximeter and MAX30105 particle sensor driver");
485MODULE_LICENSE("GPL"); 645MODULE_LICENSE("GPL");
diff --git a/drivers/iio/humidity/hts221.h b/drivers/iio/humidity/hts221.h
index 51d021966222..c581af8c0f5d 100644
--- a/drivers/iio/humidity/hts221.h
+++ b/drivers/iio/humidity/hts221.h
@@ -61,7 +61,8 @@ struct hts221_hw {
61extern const struct dev_pm_ops hts221_pm_ops; 61extern const struct dev_pm_ops hts221_pm_ops;
62 62
63int hts221_write_with_mask(struct hts221_hw *hw, u8 addr, u8 mask, u8 val); 63int hts221_write_with_mask(struct hts221_hw *hw, u8 addr, u8 mask, u8 val);
64int hts221_probe(struct iio_dev *iio_dev); 64int hts221_probe(struct device *dev, int irq, const char *name,
65 const struct hts221_transfer_function *tf_ops);
65int hts221_set_enable(struct hts221_hw *hw, bool enable); 66int hts221_set_enable(struct hts221_hw *hw, bool enable);
66int hts221_allocate_buffers(struct hts221_hw *hw); 67int hts221_allocate_buffers(struct hts221_hw *hw);
67int hts221_allocate_trigger(struct hts221_hw *hw); 68int hts221_allocate_trigger(struct hts221_hw *hw);
diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
index daef177219b6..d3f7904766bd 100644
--- a/drivers/iio/humidity/hts221_core.c
+++ b/drivers/iio/humidity/hts221_core.c
@@ -581,12 +581,26 @@ static const struct iio_info hts221_info = {
581 581
582static const unsigned long hts221_scan_masks[] = {0x3, 0x0}; 582static const unsigned long hts221_scan_masks[] = {0x3, 0x0};
583 583
584int hts221_probe(struct iio_dev *iio_dev) 584int hts221_probe(struct device *dev, int irq, const char *name,
585 const struct hts221_transfer_function *tf_ops)
585{ 586{
586 struct hts221_hw *hw = iio_priv(iio_dev); 587 struct iio_dev *iio_dev;
588 struct hts221_hw *hw;
587 int err; 589 int err;
588 u8 data; 590 u8 data;
589 591
592 iio_dev = devm_iio_device_alloc(dev, sizeof(*hw));
593 if (!iio_dev)
594 return -ENOMEM;
595
596 dev_set_drvdata(dev, (void *)iio_dev);
597
598 hw = iio_priv(iio_dev);
599 hw->name = name;
600 hw->dev = dev;
601 hw->irq = irq;
602 hw->tf = tf_ops;
603
590 mutex_init(&hw->lock); 604 mutex_init(&hw->lock);
591 605
592 err = hts221_check_whoami(hw); 606 err = hts221_check_whoami(hw);
diff --git a/drivers/iio/humidity/hts221_i2c.c b/drivers/iio/humidity/hts221_i2c.c
index f38e4b7e0160..2c97350a0f76 100644
--- a/drivers/iio/humidity/hts221_i2c.c
+++ b/drivers/iio/humidity/hts221_i2c.c
@@ -66,22 +66,8 @@ static const struct hts221_transfer_function hts221_transfer_fn = {
66static int hts221_i2c_probe(struct i2c_client *client, 66static int hts221_i2c_probe(struct i2c_client *client,
67 const struct i2c_device_id *id) 67 const struct i2c_device_id *id)
68{ 68{
69 struct hts221_hw *hw; 69 return hts221_probe(&client->dev, client->irq,
70 struct iio_dev *iio_dev; 70 client->name, &hts221_transfer_fn);
71
72 iio_dev = devm_iio_device_alloc(&client->dev, sizeof(*hw));
73 if (!iio_dev)
74 return -ENOMEM;
75
76 i2c_set_clientdata(client, iio_dev);
77
78 hw = iio_priv(iio_dev);
79 hw->name = client->name;
80 hw->dev = &client->dev;
81 hw->irq = client->irq;
82 hw->tf = &hts221_transfer_fn;
83
84 return hts221_probe(iio_dev);
85} 71}
86 72
87static const struct acpi_device_id hts221_acpi_match[] = { 73static const struct acpi_device_id hts221_acpi_match[] = {
diff --git a/drivers/iio/humidity/hts221_spi.c b/drivers/iio/humidity/hts221_spi.c
index 57cbc256771b..55b29b53b9d1 100644
--- a/drivers/iio/humidity/hts221_spi.c
+++ b/drivers/iio/humidity/hts221_spi.c
@@ -80,22 +80,8 @@ static const struct hts221_transfer_function hts221_transfer_fn = {
80 80
81static int hts221_spi_probe(struct spi_device *spi) 81static int hts221_spi_probe(struct spi_device *spi)
82{ 82{
83 struct hts221_hw *hw; 83 return hts221_probe(&spi->dev, spi->irq,
84 struct iio_dev *iio_dev; 84 spi->modalias, &hts221_transfer_fn);
85
86 iio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*hw));
87 if (!iio_dev)
88 return -ENOMEM;
89
90 spi_set_drvdata(spi, iio_dev);
91
92 hw = iio_priv(iio_dev);
93 hw->name = spi->modalias;
94 hw->dev = &spi->dev;
95 hw->irq = spi->irq;
96 hw->tf = &hts221_transfer_fn;
97
98 return hts221_probe(iio_dev);
99} 85}
100 86
101static const struct of_device_id hts221_spi_of_match[] = { 87static const struct of_device_id hts221_spi_of_match[] = {
diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 7a33d6bd60e0..a27fe208f3ae 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -194,7 +194,7 @@ static int adis16480_show_serial_number(void *arg, u64 *val)
194 194
195 return 0; 195 return 0;
196} 196}
197DEFINE_SIMPLE_ATTRIBUTE(adis16480_serial_number_fops, 197DEFINE_DEBUGFS_ATTRIBUTE(adis16480_serial_number_fops,
198 adis16480_show_serial_number, NULL, "0x%.4llx\n"); 198 adis16480_show_serial_number, NULL, "0x%.4llx\n");
199 199
200static int adis16480_show_product_id(void *arg, u64 *val) 200static int adis16480_show_product_id(void *arg, u64 *val)
@@ -212,7 +212,7 @@ static int adis16480_show_product_id(void *arg, u64 *val)
212 212
213 return 0; 213 return 0;
214} 214}
215DEFINE_SIMPLE_ATTRIBUTE(adis16480_product_id_fops, 215DEFINE_DEBUGFS_ATTRIBUTE(adis16480_product_id_fops,
216 adis16480_show_product_id, NULL, "%llu\n"); 216 adis16480_show_product_id, NULL, "%llu\n");
217 217
218static int adis16480_show_flash_count(void *arg, u64 *val) 218static int adis16480_show_flash_count(void *arg, u64 *val)
@@ -230,24 +230,28 @@ static int adis16480_show_flash_count(void *arg, u64 *val)
230 230
231 return 0; 231 return 0;
232} 232}
233DEFINE_SIMPLE_ATTRIBUTE(adis16480_flash_count_fops, 233DEFINE_DEBUGFS_ATTRIBUTE(adis16480_flash_count_fops,
234 adis16480_show_flash_count, NULL, "%lld\n"); 234 adis16480_show_flash_count, NULL, "%lld\n");
235 235
236static int adis16480_debugfs_init(struct iio_dev *indio_dev) 236static int adis16480_debugfs_init(struct iio_dev *indio_dev)
237{ 237{
238 struct adis16480 *adis16480 = iio_priv(indio_dev); 238 struct adis16480 *adis16480 = iio_priv(indio_dev);
239 239
240 debugfs_create_file("firmware_revision", 0400, 240 debugfs_create_file_unsafe("firmware_revision", 0400,
241 indio_dev->debugfs_dentry, adis16480, 241 indio_dev->debugfs_dentry, adis16480,
242 &adis16480_firmware_revision_fops); 242 &adis16480_firmware_revision_fops);
243 debugfs_create_file("firmware_date", 0400, indio_dev->debugfs_dentry, 243 debugfs_create_file_unsafe("firmware_date", 0400,
244 adis16480, &adis16480_firmware_date_fops); 244 indio_dev->debugfs_dentry, adis16480,
245 debugfs_create_file("serial_number", 0400, indio_dev->debugfs_dentry, 245 &adis16480_firmware_date_fops);
246 adis16480, &adis16480_serial_number_fops); 246 debugfs_create_file_unsafe("serial_number", 0400,
247 debugfs_create_file("product_id", 0400, indio_dev->debugfs_dentry, 247 indio_dev->debugfs_dentry, adis16480,
248 adis16480, &adis16480_product_id_fops); 248 &adis16480_serial_number_fops);
249 debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry, 249 debugfs_create_file_unsafe("product_id", 0400,
250 adis16480, &adis16480_flash_count_fops); 250 indio_dev->debugfs_dentry, adis16480,
251 &adis16480_product_id_fops);
252 debugfs_create_file_unsafe("flash_count", 0400,
253 indio_dev->debugfs_dentry, adis16480,
254 &adis16480_flash_count_fops);
251 255
252 return 0; 256 return 0;
253} 257}
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
index dd6fc6d21f9d..d78a10403bac 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
@@ -196,8 +196,7 @@ void inv_mpu_acpi_delete_mux_client(struct i2c_client *client)
196{ 196{
197 struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(&client->dev)); 197 struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(&client->dev));
198 198
199 if (st->mux_client) 199 i2c_unregister_device(st->mux_client);
200 i2c_unregister_device(st->mux_client);
201} 200}
202#else 201#else
203 202
diff --git a/drivers/iio/imu/st_lsm6dsx/Kconfig b/drivers/iio/imu/st_lsm6dsx/Kconfig
index e57337159b57..14f2eb6e9fb7 100644
--- a/drivers/iio/imu/st_lsm6dsx/Kconfig
+++ b/drivers/iio/imu/st_lsm6dsx/Kconfig
@@ -16,7 +16,9 @@ config IIO_ST_LSM6DSX
16config IIO_ST_LSM6DSX_I2C 16config IIO_ST_LSM6DSX_I2C
17 tristate 17 tristate
18 depends on IIO_ST_LSM6DSX 18 depends on IIO_ST_LSM6DSX
19 select REGMAP_I2C
19 20
20config IIO_ST_LSM6DSX_SPI 21config IIO_ST_LSM6DSX_SPI
21 tristate 22 tristate
22 depends on IIO_ST_LSM6DSX 23 depends on IIO_ST_LSM6DSX
24 select REGMAP_SPI
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 4fdb7fcc3ea8..8fdd723afa05 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -27,23 +27,12 @@ enum st_lsm6dsx_hw_id {
27 ST_LSM6DSX_MAX_ID, 27 ST_LSM6DSX_MAX_ID,
28}; 28};
29 29
30#define ST_LSM6DSX_BUFF_SIZE 256
30#define ST_LSM6DSX_CHAN_SIZE 2 31#define ST_LSM6DSX_CHAN_SIZE 2
31#define ST_LSM6DSX_SAMPLE_SIZE 6 32#define ST_LSM6DSX_SAMPLE_SIZE 6
32 33#define ST_LSM6DSX_MAX_WORD_LEN ((32 / ST_LSM6DSX_SAMPLE_SIZE) * \
33#if defined(CONFIG_SPI_MASTER) 34 ST_LSM6DSX_SAMPLE_SIZE)
34#define ST_LSM6DSX_RX_MAX_LENGTH 256 35#define ST_LSM6DSX_SHIFT_VAL(val, mask) (((val) << __ffs(mask)) & (mask))
35#define ST_LSM6DSX_TX_MAX_LENGTH 8
36
37struct st_lsm6dsx_transfer_buffer {
38 u8 rx_buf[ST_LSM6DSX_RX_MAX_LENGTH];
39 u8 tx_buf[ST_LSM6DSX_TX_MAX_LENGTH] ____cacheline_aligned;
40};
41#endif /* CONFIG_SPI_MASTER */
42
43struct st_lsm6dsx_transfer_function {
44 int (*read)(struct device *dev, u8 addr, int len, u8 *data);
45 int (*write)(struct device *dev, u8 addr, int len, u8 *data);
46};
47 36
48struct st_lsm6dsx_reg { 37struct st_lsm6dsx_reg {
49 u8 addr; 38 u8 addr;
@@ -127,47 +116,43 @@ struct st_lsm6dsx_sensor {
127/** 116/**
128 * struct st_lsm6dsx_hw - ST IMU MEMS hw instance 117 * struct st_lsm6dsx_hw - ST IMU MEMS hw instance
129 * @dev: Pointer to instance of struct device (I2C or SPI). 118 * @dev: Pointer to instance of struct device (I2C or SPI).
119 * @regmap: Register map of the device.
130 * @irq: Device interrupt line (I2C or SPI). 120 * @irq: Device interrupt line (I2C or SPI).
131 * @lock: Mutex to protect read and write operations.
132 * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO. 121 * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO.
122 * @conf_lock: Mutex to prevent concurrent FIFO configuration update.
133 * @fifo_mode: FIFO operating mode supported by the device. 123 * @fifo_mode: FIFO operating mode supported by the device.
134 * @enable_mask: Enabled sensor bitmask. 124 * @enable_mask: Enabled sensor bitmask.
135 * @sip: Total number of samples (acc/gyro) in a given pattern. 125 * @sip: Total number of samples (acc/gyro) in a given pattern.
126 * @buff: Device read buffer.
136 * @iio_devs: Pointers to acc/gyro iio_dev instances. 127 * @iio_devs: Pointers to acc/gyro iio_dev instances.
137 * @settings: Pointer to the specific sensor settings in use. 128 * @settings: Pointer to the specific sensor settings in use.
138 * @tf: Transfer function structure used by I/O operations.
139 * @tb: Transfer buffers used by SPI I/O operations.
140 */ 129 */
141struct st_lsm6dsx_hw { 130struct st_lsm6dsx_hw {
142 struct device *dev; 131 struct device *dev;
132 struct regmap *regmap;
143 int irq; 133 int irq;
144 134
145 struct mutex lock;
146 struct mutex fifo_lock; 135 struct mutex fifo_lock;
136 struct mutex conf_lock;
147 137
148 enum st_lsm6dsx_fifo_mode fifo_mode; 138 enum st_lsm6dsx_fifo_mode fifo_mode;
149 u8 enable_mask; 139 u8 enable_mask;
150 u8 sip; 140 u8 sip;
151 141
142 u8 *buff;
143
152 struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX]; 144 struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX];
153 145
154 const struct st_lsm6dsx_settings *settings; 146 const struct st_lsm6dsx_settings *settings;
155
156 const struct st_lsm6dsx_transfer_function *tf;
157#if defined(CONFIG_SPI_MASTER)
158 struct st_lsm6dsx_transfer_buffer tb;
159#endif /* CONFIG_SPI_MASTER */
160}; 147};
161 148
162extern const struct dev_pm_ops st_lsm6dsx_pm_ops; 149extern const struct dev_pm_ops st_lsm6dsx_pm_ops;
163 150
164int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name, 151int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
165 const struct st_lsm6dsx_transfer_function *tf_ops); 152 struct regmap *regmap);
166int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor); 153int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor);
167int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor); 154int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor);
168int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw); 155int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw);
169int st_lsm6dsx_write_with_mask(struct st_lsm6dsx_hw *hw, u8 addr, u8 mask,
170 u8 val);
171int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, 156int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
172 u16 watermark); 157 u16 watermark);
173int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw); 158int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw);
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
index 755c472e8a05..1d6aa9b1a4cf 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -30,6 +30,8 @@
30#include <linux/iio/kfifo_buf.h> 30#include <linux/iio/kfifo_buf.h>
31#include <linux/iio/iio.h> 31#include <linux/iio/iio.h>
32#include <linux/iio/buffer.h> 32#include <linux/iio/buffer.h>
33#include <linux/regmap.h>
34#include <linux/bitfield.h>
33 35
34#include <linux/platform_data/st_sensors_pdata.h> 36#include <linux/platform_data/st_sensors_pdata.h>
35 37
@@ -120,8 +122,10 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw)
120 122
121 dec_reg = &hw->settings->decimator[sensor->id]; 123 dec_reg = &hw->settings->decimator[sensor->id];
122 if (dec_reg->addr) { 124 if (dec_reg->addr) {
123 err = st_lsm6dsx_write_with_mask(hw, dec_reg->addr, 125 int val = ST_LSM6DSX_SHIFT_VAL(data, dec_reg->mask);
124 dec_reg->mask, data); 126
127 err = regmap_update_bits(hw->regmap, dec_reg->addr,
128 dec_reg->mask, val);
125 if (err < 0) 129 if (err < 0)
126 return err; 130 return err;
127 } 131 }
@@ -137,8 +141,10 @@ int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
137{ 141{
138 int err; 142 int err;
139 143
140 err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_FIFO_MODE_ADDR, 144 err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_FIFO_MODE_ADDR,
141 ST_LSM6DSX_FIFO_MODE_MASK, fifo_mode); 145 ST_LSM6DSX_FIFO_MODE_MASK,
146 FIELD_PREP(ST_LSM6DSX_FIFO_MODE_MASK,
147 fifo_mode));
142 if (err < 0) 148 if (err < 0)
143 return err; 149 return err;
144 150
@@ -154,8 +160,9 @@ static int st_lsm6dsx_set_fifo_odr(struct st_lsm6dsx_sensor *sensor,
154 u8 data; 160 u8 data;
155 161
156 data = hw->enable_mask ? ST_LSM6DSX_MAX_FIFO_ODR_VAL : 0; 162 data = hw->enable_mask ? ST_LSM6DSX_MAX_FIFO_ODR_VAL : 0;
157 return st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_FIFO_MODE_ADDR, 163 return regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_FIFO_MODE_ADDR,
158 ST_LSM6DSX_FIFO_ODR_MASK, data); 164 ST_LSM6DSX_FIFO_ODR_MASK,
165 FIELD_PREP(ST_LSM6DSX_FIFO_ODR_MASK, data));
159} 166}
160 167
161int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark) 168int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
@@ -163,9 +170,8 @@ int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
163 u16 fifo_watermark = ~0, cur_watermark, sip = 0, fifo_th_mask; 170 u16 fifo_watermark = ~0, cur_watermark, sip = 0, fifo_th_mask;
164 struct st_lsm6dsx_hw *hw = sensor->hw; 171 struct st_lsm6dsx_hw *hw = sensor->hw;
165 struct st_lsm6dsx_sensor *cur_sensor; 172 struct st_lsm6dsx_sensor *cur_sensor;
173 int i, err, data;
166 __le16 wdata; 174 __le16 wdata;
167 int i, err;
168 u8 data;
169 175
170 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 176 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
171 cur_sensor = iio_priv(hw->iio_devs[i]); 177 cur_sensor = iio_priv(hw->iio_devs[i]);
@@ -187,24 +193,42 @@ int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
187 fifo_watermark = (fifo_watermark / sip) * sip; 193 fifo_watermark = (fifo_watermark / sip) * sip;
188 fifo_watermark = fifo_watermark * hw->settings->fifo_ops.th_wl; 194 fifo_watermark = fifo_watermark * hw->settings->fifo_ops.th_wl;
189 195
190 mutex_lock(&hw->lock); 196 err = regmap_read(hw->regmap, hw->settings->fifo_ops.fifo_th.addr + 1,
191 197 &data);
192 err = hw->tf->read(hw->dev, hw->settings->fifo_ops.fifo_th.addr + 1,
193 sizeof(data), &data);
194 if (err < 0) 198 if (err < 0)
195 goto out; 199 return err;
196 200
197 fifo_th_mask = hw->settings->fifo_ops.fifo_th.mask; 201 fifo_th_mask = hw->settings->fifo_ops.fifo_th.mask;
198 fifo_watermark = ((data << 8) & ~fifo_th_mask) | 202 fifo_watermark = ((data << 8) & ~fifo_th_mask) |
199 (fifo_watermark & fifo_th_mask); 203 (fifo_watermark & fifo_th_mask);
200 204
201 wdata = cpu_to_le16(fifo_watermark); 205 wdata = cpu_to_le16(fifo_watermark);
202 err = hw->tf->write(hw->dev, hw->settings->fifo_ops.fifo_th.addr, 206 return regmap_bulk_write(hw->regmap,
203 sizeof(wdata), (u8 *)&wdata); 207 hw->settings->fifo_ops.fifo_th.addr,
204out: 208 &wdata, sizeof(wdata));
205 mutex_unlock(&hw->lock); 209}
206 210
207 return err < 0 ? err : 0; 211/*
212 * Set max bulk read to ST_LSM6DSX_MAX_WORD_LEN in order to avoid
213 * a kmalloc for each bus access
214 */
215static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 *data,
216 unsigned int data_len)
217{
218 unsigned int word_len, read_len = 0;
219 int err;
220
221 while (read_len < data_len) {
222 word_len = min_t(unsigned int, data_len - read_len,
223 ST_LSM6DSX_MAX_WORD_LEN);
224 err = regmap_bulk_read(hw->regmap,
225 ST_LSM6DSX_REG_FIFO_OUTL_ADDR,
226 data + read_len, word_len);
227 if (err < 0)
228 return err;
229 read_len += word_len;
230 }
231 return 0;
208} 232}
209 233
210/** 234/**
@@ -223,11 +247,11 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
223 struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor; 247 struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor;
224 s64 acc_ts, acc_delta_ts, gyro_ts, gyro_delta_ts; 248 s64 acc_ts, acc_delta_ts, gyro_ts, gyro_delta_ts;
225 u8 iio_buff[ALIGN(ST_LSM6DSX_SAMPLE_SIZE, sizeof(s64)) + sizeof(s64)]; 249 u8 iio_buff[ALIGN(ST_LSM6DSX_SAMPLE_SIZE, sizeof(s64)) + sizeof(s64)];
226 u8 buff[pattern_len];
227 __le16 fifo_status; 250 __le16 fifo_status;
228 251
229 err = hw->tf->read(hw->dev, hw->settings->fifo_ops.fifo_diff.addr, 252 err = regmap_bulk_read(hw->regmap,
230 sizeof(fifo_status), (u8 *)&fifo_status); 253 hw->settings->fifo_ops.fifo_diff.addr,
254 &fifo_status, sizeof(fifo_status));
231 if (err < 0) 255 if (err < 0)
232 return err; 256 return err;
233 257
@@ -255,8 +279,7 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
255 samples); 279 samples);
256 280
257 for (read_len = 0; read_len < fifo_len; read_len += pattern_len) { 281 for (read_len = 0; read_len < fifo_len; read_len += pattern_len) {
258 err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_OUTL_ADDR, 282 err = st_lsm6dsx_read_block(hw, hw->buff, pattern_len);
259 sizeof(buff), buff);
260 if (err < 0) 283 if (err < 0)
261 return err; 284 return err;
262 285
@@ -281,7 +304,7 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
281 304
282 while (acc_sip > 0 || gyro_sip > 0) { 305 while (acc_sip > 0 || gyro_sip > 0) {
283 if (gyro_sip-- > 0) { 306 if (gyro_sip-- > 0) {
284 memcpy(iio_buff, &buff[offset], 307 memcpy(iio_buff, &hw->buff[offset],
285 ST_LSM6DSX_SAMPLE_SIZE); 308 ST_LSM6DSX_SAMPLE_SIZE);
286 iio_push_to_buffers_with_timestamp( 309 iio_push_to_buffers_with_timestamp(
287 hw->iio_devs[ST_LSM6DSX_ID_GYRO], 310 hw->iio_devs[ST_LSM6DSX_ID_GYRO],
@@ -291,7 +314,7 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
291 } 314 }
292 315
293 if (acc_sip-- > 0) { 316 if (acc_sip-- > 0) {
294 memcpy(iio_buff, &buff[offset], 317 memcpy(iio_buff, &hw->buff[offset],
295 ST_LSM6DSX_SAMPLE_SIZE); 318 ST_LSM6DSX_SAMPLE_SIZE);
296 iio_push_to_buffers_with_timestamp( 319 iio_push_to_buffers_with_timestamp(
297 hw->iio_devs[ST_LSM6DSX_ID_ACC], 320 hw->iio_devs[ST_LSM6DSX_ID_ACC],
@@ -325,38 +348,40 @@ static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable)
325 struct st_lsm6dsx_hw *hw = sensor->hw; 348 struct st_lsm6dsx_hw *hw = sensor->hw;
326 int err; 349 int err;
327 350
351 mutex_lock(&hw->conf_lock);
352
328 if (hw->fifo_mode != ST_LSM6DSX_FIFO_BYPASS) { 353 if (hw->fifo_mode != ST_LSM6DSX_FIFO_BYPASS) {
329 err = st_lsm6dsx_flush_fifo(hw); 354 err = st_lsm6dsx_flush_fifo(hw);
330 if (err < 0) 355 if (err < 0)
331 return err; 356 goto out;
332 } 357 }
333 358
334 if (enable) { 359 if (enable) {
335 err = st_lsm6dsx_sensor_enable(sensor); 360 err = st_lsm6dsx_sensor_enable(sensor);
336 if (err < 0) 361 if (err < 0)
337 return err; 362 goto out;
338 } else { 363 } else {
339 err = st_lsm6dsx_sensor_disable(sensor); 364 err = st_lsm6dsx_sensor_disable(sensor);
340 if (err < 0) 365 if (err < 0)
341 return err; 366 goto out;
342 } 367 }
343 368
344 err = st_lsm6dsx_set_fifo_odr(sensor, enable); 369 err = st_lsm6dsx_set_fifo_odr(sensor, enable);
345 if (err < 0) 370 if (err < 0)
346 return err; 371 goto out;
347 372
348 err = st_lsm6dsx_update_decimators(hw); 373 err = st_lsm6dsx_update_decimators(hw);
349 if (err < 0) 374 if (err < 0)
350 return err; 375 goto out;
351 376
352 err = st_lsm6dsx_update_watermark(sensor, sensor->watermark); 377 err = st_lsm6dsx_update_watermark(sensor, sensor->watermark);
353 if (err < 0) 378 if (err < 0)
354 return err; 379 goto out;
355 380
356 if (hw->enable_mask) { 381 if (hw->enable_mask) {
357 err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_CONT); 382 err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_CONT);
358 if (err < 0) 383 if (err < 0)
359 return err; 384 goto out;
360 385
361 /* 386 /*
362 * store enable buffer timestamp as reference to compute 387 * store enable buffer timestamp as reference to compute
@@ -365,7 +390,10 @@ static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable)
365 sensor->ts = iio_get_time_ns(iio_dev); 390 sensor->ts = iio_get_time_ns(iio_dev);
366 } 391 }
367 392
368 return 0; 393out:
394 mutex_unlock(&hw->conf_lock);
395
396 return err;
369} 397}
370 398
371static irqreturn_t st_lsm6dsx_handler_irq(int irq, void *private) 399static irqreturn_t st_lsm6dsx_handler_irq(int irq, void *private)
@@ -444,17 +472,20 @@ int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)
444 return -EINVAL; 472 return -EINVAL;
445 } 473 }
446 474
447 err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_HLACTIVE_ADDR, 475 err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_HLACTIVE_ADDR,
448 ST_LSM6DSX_REG_HLACTIVE_MASK, 476 ST_LSM6DSX_REG_HLACTIVE_MASK,
449 irq_active_low); 477 FIELD_PREP(ST_LSM6DSX_REG_HLACTIVE_MASK,
478 irq_active_low));
450 if (err < 0) 479 if (err < 0)
451 return err; 480 return err;
452 481
453 pdata = (struct st_sensors_platform_data *)hw->dev->platform_data; 482 pdata = (struct st_sensors_platform_data *)hw->dev->platform_data;
454 if ((np && of_property_read_bool(np, "drive-open-drain")) || 483 if ((np && of_property_read_bool(np, "drive-open-drain")) ||
455 (pdata && pdata->open_drain)) { 484 (pdata && pdata->open_drain)) {
456 err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_PP_OD_ADDR, 485 err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_PP_OD_ADDR,
457 ST_LSM6DSX_REG_PP_OD_MASK, 1); 486 ST_LSM6DSX_REG_PP_OD_MASK,
487 FIELD_PREP(ST_LSM6DSX_REG_PP_OD_MASK,
488 1));
458 if (err < 0) 489 if (err < 0)
459 return err; 490 return err;
460 491
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 239c735242be..c2fa3239b9c6 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -37,6 +37,8 @@
37#include <linux/iio/iio.h> 37#include <linux/iio/iio.h>
38#include <linux/iio/sysfs.h> 38#include <linux/iio/sysfs.h>
39#include <linux/pm.h> 39#include <linux/pm.h>
40#include <linux/regmap.h>
41#include <linux/bitfield.h>
40 42
41#include <linux/platform_data/st_sensors_pdata.h> 43#include <linux/platform_data/st_sensors_pdata.h>
42 44
@@ -277,36 +279,9 @@ static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = {
277 IIO_CHAN_SOFT_TIMESTAMP(3), 279 IIO_CHAN_SOFT_TIMESTAMP(3),
278}; 280};
279 281
280int st_lsm6dsx_write_with_mask(struct st_lsm6dsx_hw *hw, u8 addr, u8 mask,
281 u8 val)
282{
283 u8 data;
284 int err;
285
286 mutex_lock(&hw->lock);
287
288 err = hw->tf->read(hw->dev, addr, sizeof(data), &data);
289 if (err < 0) {
290 dev_err(hw->dev, "failed to read %02x register\n", addr);
291 goto out;
292 }
293
294 data = (data & ~mask) | ((val << __ffs(mask)) & mask);
295
296 err = hw->tf->write(hw->dev, addr, sizeof(data), &data);
297 if (err < 0)
298 dev_err(hw->dev, "failed to write %02x register\n", addr);
299
300out:
301 mutex_unlock(&hw->lock);
302
303 return err;
304}
305
306static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id) 282static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id)
307{ 283{
308 int err, i, j; 284 int err, i, j, data;
309 u8 data;
310 285
311 for (i = 0; i < ARRAY_SIZE(st_lsm6dsx_sensor_settings); i++) { 286 for (i = 0; i < ARRAY_SIZE(st_lsm6dsx_sensor_settings); i++) {
312 for (j = 0; j < ST_LSM6DSX_MAX_ID; j++) { 287 for (j = 0; j < ST_LSM6DSX_MAX_ID; j++) {
@@ -322,8 +297,7 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id)
322 return -ENODEV; 297 return -ENODEV;
323 } 298 }
324 299
325 err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_WHOAMI_ADDR, sizeof(data), 300 err = regmap_read(hw->regmap, ST_LSM6DSX_REG_WHOAMI_ADDR, &data);
326 &data);
327 if (err < 0) { 301 if (err < 0) {
328 dev_err(hw->dev, "failed to read whoami register\n"); 302 dev_err(hw->dev, "failed to read whoami register\n");
329 return err; 303 return err;
@@ -342,22 +316,22 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id)
342static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor, 316static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
343 u32 gain) 317 u32 gain)
344{ 318{
345 enum st_lsm6dsx_sensor_id id = sensor->id; 319 struct st_lsm6dsx_hw *hw = sensor->hw;
320 const struct st_lsm6dsx_reg *reg;
346 int i, err; 321 int i, err;
347 u8 val; 322 u8 val;
348 323
349 for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) 324 for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++)
350 if (st_lsm6dsx_fs_table[id].fs_avl[i].gain == gain) 325 if (st_lsm6dsx_fs_table[sensor->id].fs_avl[i].gain == gain)
351 break; 326 break;
352 327
353 if (i == ST_LSM6DSX_FS_LIST_SIZE) 328 if (i == ST_LSM6DSX_FS_LIST_SIZE)
354 return -EINVAL; 329 return -EINVAL;
355 330
356 val = st_lsm6dsx_fs_table[id].fs_avl[i].val; 331 val = st_lsm6dsx_fs_table[sensor->id].fs_avl[i].val;
357 err = st_lsm6dsx_write_with_mask(sensor->hw, 332 reg = &st_lsm6dsx_fs_table[sensor->id].reg;
358 st_lsm6dsx_fs_table[id].reg.addr, 333 err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
359 st_lsm6dsx_fs_table[id].reg.mask, 334 ST_LSM6DSX_SHIFT_VAL(val, reg->mask));
360 val);
361 if (err < 0) 335 if (err < 0)
362 return err; 336 return err;
363 337
@@ -385,7 +359,8 @@ static int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr,
385 359
386static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr) 360static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
387{ 361{
388 enum st_lsm6dsx_sensor_id id = sensor->id; 362 struct st_lsm6dsx_hw *hw = sensor->hw;
363 const struct st_lsm6dsx_reg *reg;
389 int err; 364 int err;
390 u8 val; 365 u8 val;
391 366
@@ -393,10 +368,9 @@ static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
393 if (err < 0) 368 if (err < 0)
394 return err; 369 return err;
395 370
396 return st_lsm6dsx_write_with_mask(sensor->hw, 371 reg = &st_lsm6dsx_odr_table[sensor->id].reg;
397 st_lsm6dsx_odr_table[id].reg.addr, 372 return regmap_update_bits(hw->regmap, reg->addr, reg->mask,
398 st_lsm6dsx_odr_table[id].reg.mask, 373 ST_LSM6DSX_SHIFT_VAL(val, reg->mask));
399 val);
400} 374}
401 375
402int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor) 376int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor)
@@ -414,16 +388,17 @@ int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor)
414 388
415int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor) 389int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor)
416{ 390{
417 enum st_lsm6dsx_sensor_id id = sensor->id; 391 struct st_lsm6dsx_hw *hw = sensor->hw;
392 const struct st_lsm6dsx_reg *reg;
418 int err; 393 int err;
419 394
420 err = st_lsm6dsx_write_with_mask(sensor->hw, 395 reg = &st_lsm6dsx_odr_table[sensor->id].reg;
421 st_lsm6dsx_odr_table[id].reg.addr, 396 err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
422 st_lsm6dsx_odr_table[id].reg.mask, 0); 397 ST_LSM6DSX_SHIFT_VAL(0, reg->mask));
423 if (err < 0) 398 if (err < 0)
424 return err; 399 return err;
425 400
426 sensor->hw->enable_mask &= ~BIT(id); 401 sensor->hw->enable_mask &= ~BIT(sensor->id);
427 402
428 return 0; 403 return 0;
429} 404}
@@ -431,6 +406,7 @@ int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor)
431static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor, 406static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
432 u8 addr, int *val) 407 u8 addr, int *val)
433{ 408{
409 struct st_lsm6dsx_hw *hw = sensor->hw;
434 int err, delay; 410 int err, delay;
435 __le16 data; 411 __le16 data;
436 412
@@ -441,14 +417,13 @@ static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
441 delay = 1000000 / sensor->odr; 417 delay = 1000000 / sensor->odr;
442 usleep_range(delay, 2 * delay); 418 usleep_range(delay, 2 * delay);
443 419
444 err = sensor->hw->tf->read(sensor->hw->dev, addr, sizeof(data), 420 err = regmap_bulk_read(hw->regmap, addr, &data, sizeof(data));
445 (u8 *)&data);
446 if (err < 0) 421 if (err < 0)
447 return err; 422 return err;
448 423
449 st_lsm6dsx_sensor_disable(sensor); 424 st_lsm6dsx_sensor_disable(sensor);
450 425
451 *val = (s16)data; 426 *val = (s16)le16_to_cpu(data);
452 427
453 return IIO_VAL_INT; 428 return IIO_VAL_INT;
454} 429}
@@ -528,7 +503,12 @@ static int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val)
528 if (val < 1 || val > hw->settings->max_fifo_size) 503 if (val < 1 || val > hw->settings->max_fifo_size)
529 return -EINVAL; 504 return -EINVAL;
530 505
506 mutex_lock(&hw->conf_lock);
507
531 err = st_lsm6dsx_update_watermark(sensor, val); 508 err = st_lsm6dsx_update_watermark(sensor, val);
509
510 mutex_unlock(&hw->conf_lock);
511
532 if (err < 0) 512 if (err < 0)
533 return err; 513 return err;
534 514
@@ -652,20 +632,20 @@ static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
652 632
653static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw) 633static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
654{ 634{
655 u8 data, drdy_int_reg; 635 u8 drdy_int_reg;
656 int err; 636 int err;
657 637
658 data = ST_LSM6DSX_REG_RESET_MASK; 638 err = regmap_write(hw->regmap, ST_LSM6DSX_REG_RESET_ADDR,
659 err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_RESET_ADDR, sizeof(data), 639 ST_LSM6DSX_REG_RESET_MASK);
660 &data);
661 if (err < 0) 640 if (err < 0)
662 return err; 641 return err;
663 642
664 msleep(200); 643 msleep(200);
665 644
666 /* enable Block Data Update */ 645 /* enable Block Data Update */
667 err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_BDU_ADDR, 646 err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_BDU_ADDR,
668 ST_LSM6DSX_REG_BDU_MASK, 1); 647 ST_LSM6DSX_REG_BDU_MASK,
648 FIELD_PREP(ST_LSM6DSX_REG_BDU_MASK, 1));
669 if (err < 0) 649 if (err < 0)
670 return err; 650 return err;
671 651
@@ -674,8 +654,10 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
674 if (err < 0) 654 if (err < 0)
675 return err; 655 return err;
676 656
677 return st_lsm6dsx_write_with_mask(hw, drdy_int_reg, 657 return regmap_update_bits(hw->regmap, drdy_int_reg,
678 ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK, 1); 658 ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK,
659 FIELD_PREP(ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK,
660 1));
679} 661}
680 662
681static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw, 663static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
@@ -726,7 +708,7 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
726} 708}
727 709
728int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name, 710int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
729 const struct st_lsm6dsx_transfer_function *tf_ops) 711 struct regmap *regmap)
730{ 712{
731 struct st_lsm6dsx_hw *hw; 713 struct st_lsm6dsx_hw *hw;
732 int i, err; 714 int i, err;
@@ -737,12 +719,16 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
737 719
738 dev_set_drvdata(dev, (void *)hw); 720 dev_set_drvdata(dev, (void *)hw);
739 721
740 mutex_init(&hw->lock);
741 mutex_init(&hw->fifo_lock); 722 mutex_init(&hw->fifo_lock);
723 mutex_init(&hw->conf_lock);
724
725 hw->buff = devm_kzalloc(dev, ST_LSM6DSX_BUFF_SIZE, GFP_KERNEL);
726 if (!hw->buff)
727 return -ENOMEM;
742 728
743 hw->dev = dev; 729 hw->dev = dev;
744 hw->irq = irq; 730 hw->irq = irq;
745 hw->tf = tf_ops; 731 hw->regmap = regmap;
746 732
747 err = st_lsm6dsx_check_whoami(hw, hw_id); 733 err = st_lsm6dsx_check_whoami(hw, hw_id);
748 if (err < 0) 734 if (err < 0)
@@ -778,6 +764,7 @@ static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)
778{ 764{
779 struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev); 765 struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev);
780 struct st_lsm6dsx_sensor *sensor; 766 struct st_lsm6dsx_sensor *sensor;
767 const struct st_lsm6dsx_reg *reg;
781 int i, err = 0; 768 int i, err = 0;
782 769
783 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 770 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
@@ -785,9 +772,9 @@ static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)
785 if (!(hw->enable_mask & BIT(sensor->id))) 772 if (!(hw->enable_mask & BIT(sensor->id)))
786 continue; 773 continue;
787 774
788 err = st_lsm6dsx_write_with_mask(hw, 775 reg = &st_lsm6dsx_odr_table[sensor->id].reg;
789 st_lsm6dsx_odr_table[sensor->id].reg.addr, 776 err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
790 st_lsm6dsx_odr_table[sensor->id].reg.mask, 0); 777 ST_LSM6DSX_SHIFT_VAL(0, reg->mask));
791 if (err < 0) 778 if (err < 0)
792 return err; 779 return err;
793 } 780 }
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
index 305fec712ab0..41525dd2aab7 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
@@ -14,55 +14,30 @@
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/of.h> 16#include <linux/of.h>
17#include <linux/regmap.h>
17 18
18#include "st_lsm6dsx.h" 19#include "st_lsm6dsx.h"
19 20
20static int st_lsm6dsx_i2c_read(struct device *dev, u8 addr, int len, u8 *data) 21static const struct regmap_config st_lsm6dsx_i2c_regmap_config = {
21{ 22 .reg_bits = 8,
22 struct i2c_client *client = to_i2c_client(dev); 23 .val_bits = 8,
23 struct i2c_msg msg[2];
24
25 msg[0].addr = client->addr;
26 msg[0].flags = client->flags;
27 msg[0].len = 1;
28 msg[0].buf = &addr;
29
30 msg[1].addr = client->addr;
31 msg[1].flags = client->flags | I2C_M_RD;
32 msg[1].len = len;
33 msg[1].buf = data;
34
35 return i2c_transfer(client->adapter, msg, 2);
36}
37
38static int st_lsm6dsx_i2c_write(struct device *dev, u8 addr, int len, u8 *data)
39{
40 struct i2c_client *client = to_i2c_client(dev);
41 struct i2c_msg msg;
42 u8 send[len + 1];
43
44 send[0] = addr;
45 memcpy(&send[1], data, len * sizeof(u8));
46
47 msg.addr = client->addr;
48 msg.flags = client->flags;
49 msg.len = len + 1;
50 msg.buf = send;
51
52 return i2c_transfer(client->adapter, &msg, 1);
53}
54
55static const struct st_lsm6dsx_transfer_function st_lsm6dsx_transfer_fn = {
56 .read = st_lsm6dsx_i2c_read,
57 .write = st_lsm6dsx_i2c_write,
58}; 24};
59 25
60static int st_lsm6dsx_i2c_probe(struct i2c_client *client, 26static int st_lsm6dsx_i2c_probe(struct i2c_client *client,
61 const struct i2c_device_id *id) 27 const struct i2c_device_id *id)
62{ 28{
29 int hw_id = id->driver_data;
30 struct regmap *regmap;
31
32 regmap = devm_regmap_init_i2c(client, &st_lsm6dsx_i2c_regmap_config);
33 if (IS_ERR(regmap)) {
34 dev_err(&client->dev, "Failed to register i2c regmap %d\n",
35 (int)PTR_ERR(regmap));
36 return PTR_ERR(regmap);
37 }
38
63 return st_lsm6dsx_probe(&client->dev, client->irq, 39 return st_lsm6dsx_probe(&client->dev, client->irq,
64 (int)id->driver_data, id->name, 40 hw_id, id->name, regmap);
65 &st_lsm6dsx_transfer_fn);
66} 41}
67 42
68static const struct of_device_id st_lsm6dsx_i2c_of_match[] = { 43static const struct of_device_id st_lsm6dsx_i2c_of_match[] = {
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
index 95472f153ad2..2c8135834479 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
@@ -14,72 +14,30 @@
14#include <linux/spi/spi.h> 14#include <linux/spi/spi.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/of.h> 16#include <linux/of.h>
17#include <linux/regmap.h>
17 18
18#include "st_lsm6dsx.h" 19#include "st_lsm6dsx.h"
19 20
20#define SENSORS_SPI_READ BIT(7) 21static const struct regmap_config st_lsm6dsx_spi_regmap_config = {
21 22 .reg_bits = 8,
22static int st_lsm6dsx_spi_read(struct device *dev, u8 addr, int len, 23 .val_bits = 8,
23 u8 *data)
24{
25 struct spi_device *spi = to_spi_device(dev);
26 struct st_lsm6dsx_hw *hw = spi_get_drvdata(spi);
27 int err;
28
29 struct spi_transfer xfers[] = {
30 {
31 .tx_buf = hw->tb.tx_buf,
32 .bits_per_word = 8,
33 .len = 1,
34 },
35 {
36 .rx_buf = hw->tb.rx_buf,
37 .bits_per_word = 8,
38 .len = len,
39 }
40 };
41
42 hw->tb.tx_buf[0] = addr | SENSORS_SPI_READ;
43
44 err = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers));
45 if (err < 0)
46 return err;
47
48 memcpy(data, hw->tb.rx_buf, len * sizeof(u8));
49
50 return len;
51}
52
53static int st_lsm6dsx_spi_write(struct device *dev, u8 addr, int len,
54 u8 *data)
55{
56 struct st_lsm6dsx_hw *hw;
57 struct spi_device *spi;
58
59 if (len >= ST_LSM6DSX_TX_MAX_LENGTH)
60 return -ENOMEM;
61
62 spi = to_spi_device(dev);
63 hw = spi_get_drvdata(spi);
64
65 hw->tb.tx_buf[0] = addr;
66 memcpy(&hw->tb.tx_buf[1], data, len);
67
68 return spi_write(spi, hw->tb.tx_buf, len + 1);
69}
70
71static const struct st_lsm6dsx_transfer_function st_lsm6dsx_transfer_fn = {
72 .read = st_lsm6dsx_spi_read,
73 .write = st_lsm6dsx_spi_write,
74}; 24};
75 25
76static int st_lsm6dsx_spi_probe(struct spi_device *spi) 26static int st_lsm6dsx_spi_probe(struct spi_device *spi)
77{ 27{
78 const struct spi_device_id *id = spi_get_device_id(spi); 28 const struct spi_device_id *id = spi_get_device_id(spi);
29 int hw_id = id->driver_data;
30 struct regmap *regmap;
31
32 regmap = devm_regmap_init_spi(spi, &st_lsm6dsx_spi_regmap_config);
33 if (IS_ERR(regmap)) {
34 dev_err(&spi->dev, "Failed to register spi regmap %d\n",
35 (int)PTR_ERR(regmap));
36 return PTR_ERR(regmap);
37 }
79 38
80 return st_lsm6dsx_probe(&spi->dev, spi->irq, 39 return st_lsm6dsx_probe(&spi->dev, spi->irq,
81 (int)id->driver_data, id->name, 40 hw_id, id->name, regmap);
82 &st_lsm6dsx_transfer_fn);
83} 41}
84 42
85static const struct of_device_id st_lsm6dsx_spi_of_match[] = { 43static const struct of_device_id st_lsm6dsx_spi_of_match[] = {
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 0bc2fe31f211..6184c100a94a 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -1198,6 +1198,18 @@ out:
1198 return ret ? ret : len; 1198 return ret ? ret : len;
1199} 1199}
1200 1200
1201static ssize_t iio_dma_show_data_available(struct device *dev,
1202 struct device_attribute *attr,
1203 char *buf)
1204{
1205 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1206 size_t bytes;
1207
1208 bytes = iio_buffer_data_available(indio_dev->buffer);
1209
1210 return sprintf(buf, "%zu\n", bytes);
1211}
1212
1201static DEVICE_ATTR(length, S_IRUGO | S_IWUSR, iio_buffer_read_length, 1213static DEVICE_ATTR(length, S_IRUGO | S_IWUSR, iio_buffer_read_length,
1202 iio_buffer_write_length); 1214 iio_buffer_write_length);
1203static struct device_attribute dev_attr_length_ro = __ATTR(length, 1215static struct device_attribute dev_attr_length_ro = __ATTR(length,
@@ -1208,11 +1220,14 @@ static DEVICE_ATTR(watermark, S_IRUGO | S_IWUSR,
1208 iio_buffer_show_watermark, iio_buffer_store_watermark); 1220 iio_buffer_show_watermark, iio_buffer_store_watermark);
1209static struct device_attribute dev_attr_watermark_ro = __ATTR(watermark, 1221static struct device_attribute dev_attr_watermark_ro = __ATTR(watermark,
1210 S_IRUGO, iio_buffer_show_watermark, NULL); 1222 S_IRUGO, iio_buffer_show_watermark, NULL);
1223static DEVICE_ATTR(data_available, S_IRUGO,
1224 iio_dma_show_data_available, NULL);
1211 1225
1212static struct attribute *iio_buffer_attrs[] = { 1226static struct attribute *iio_buffer_attrs[] = {
1213 &dev_attr_length.attr, 1227 &dev_attr_length.attr,
1214 &dev_attr_enable.attr, 1228 &dev_attr_enable.attr,
1215 &dev_attr_watermark.attr, 1229 &dev_attr_watermark.attr,
1230 &dev_attr_data_available.attr,
1216}; 1231};
1217 1232
1218int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) 1233int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 2f0998ebeed2..19bdf3d2962a 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -588,6 +588,7 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type,
588 return snprintf(buf, len, "%d", vals[0]); 588 return snprintf(buf, len, "%d", vals[0]);
589 case IIO_VAL_INT_PLUS_MICRO_DB: 589 case IIO_VAL_INT_PLUS_MICRO_DB:
590 scale_db = true; 590 scale_db = true;
591 /* fall through */
591 case IIO_VAL_INT_PLUS_MICRO: 592 case IIO_VAL_INT_PLUS_MICRO:
592 if (vals[1] < 0) 593 if (vals[1] < 0)
593 return snprintf(buf, len, "-%d.%06u%s", abs(vals[0]), 594 return snprintf(buf, len, "-%d.%06u%s", abs(vals[0]),
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 2356ed9285df..93fd421b10d7 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -334,6 +334,30 @@ config STK3310
334 Choosing M will build the driver as a module. If so, the module 334 Choosing M will build the driver as a module. If so, the module
335 will be called stk3310. 335 will be called stk3310.
336 336
337config ST_UVIS25
338 tristate "STMicroelectronics UVIS25 sensor driver"
339 depends on (I2C || SPI)
340 select IIO_BUFFER
341 select IIO_TRIGGERED_BUFFER
342 select ST_UVIS25_I2C if (I2C)
343 select ST_UVIS25_SPI if (SPI_MASTER)
344 help
345 Say yes here to build support for STMicroelectronics UVIS25
346 uv sensor
347
348 To compile this driver as a module, choose M here: the module
349 will be called st_uvis25.
350
351config ST_UVIS25_I2C
352 tristate
353 depends on ST_UVIS25
354 select REGMAP_I2C
355
356config ST_UVIS25_SPI
357 tristate
358 depends on ST_UVIS25
359 select REGMAP_SPI
360
337config TCS3414 361config TCS3414
338 tristate "TAOS TCS3414 digital color sensor" 362 tristate "TAOS TCS3414 digital color sensor"
339 depends on I2C 363 depends on I2C
@@ -425,4 +449,14 @@ config VL6180
425 To compile this driver as a module, choose M here: the 449 To compile this driver as a module, choose M here: the
426 module will be called vl6180. 450 module will be called vl6180.
427 451
452config ZOPT2201
453 tristate "ZOPT2201 ALS and UV B sensor"
454 depends on I2C
455 help
456 Say Y here if you want to build a driver for the IDT
457 ZOPT2201 ambient light and UV B sensor.
458
459 To compile this driver as a module, choose M here: the
460 module will be called zopt2201.
461
428endmenu 462endmenu
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index c263469b7ce9..f714067a7816 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -33,6 +33,9 @@ obj-$(CONFIG_RPR0521) += rpr0521.o
33obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o 33obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o
34obj-$(CONFIG_SI1145) += si1145.o 34obj-$(CONFIG_SI1145) += si1145.o
35obj-$(CONFIG_STK3310) += stk3310.o 35obj-$(CONFIG_STK3310) += stk3310.o
36obj-$(CONFIG_ST_UVIS25) += st_uvis25_core.o
37obj-$(CONFIG_ST_UVIS25_I2C) += st_uvis25_i2c.o
38obj-$(CONFIG_ST_UVIS25_SPI) += st_uvis25_spi.o
36obj-$(CONFIG_TCS3414) += tcs3414.o 39obj-$(CONFIG_TCS3414) += tcs3414.o
37obj-$(CONFIG_TCS3472) += tcs3472.o 40obj-$(CONFIG_TCS3472) += tcs3472.o
38obj-$(CONFIG_TSL2583) += tsl2583.o 41obj-$(CONFIG_TSL2583) += tsl2583.o
@@ -41,3 +44,4 @@ obj-$(CONFIG_US5182D) += us5182d.o
41obj-$(CONFIG_VCNL4000) += vcnl4000.o 44obj-$(CONFIG_VCNL4000) += vcnl4000.o
42obj-$(CONFIG_VEML6070) += veml6070.o 45obj-$(CONFIG_VEML6070) += veml6070.o
43obj-$(CONFIG_VL6180) += vl6180.o 46obj-$(CONFIG_VL6180) += vl6180.o
47obj-$(CONFIG_ZOPT2201) += zopt2201.o
diff --git a/drivers/iio/light/cros_ec_light_prox.c b/drivers/iio/light/cros_ec_light_prox.c
index b2a46b390d5c..acfad4aeb27a 100644
--- a/drivers/iio/light/cros_ec_light_prox.c
+++ b/drivers/iio/light/cros_ec_light_prox.c
@@ -181,7 +181,6 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev)
181{ 181{
182 struct device *dev = &pdev->dev; 182 struct device *dev = &pdev->dev;
183 struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent); 183 struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
184 struct cros_ec_device *ec_device;
185 struct iio_dev *indio_dev; 184 struct iio_dev *indio_dev;
186 struct cros_ec_light_prox_state *state; 185 struct cros_ec_light_prox_state *state;
187 struct iio_chan_spec *channel; 186 struct iio_chan_spec *channel;
@@ -191,7 +190,6 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev)
191 dev_warn(dev, "No CROS EC device found.\n"); 190 dev_warn(dev, "No CROS EC device found.\n");
192 return -EINVAL; 191 return -EINVAL;
193 } 192 }
194 ec_device = ec_dev->ec_dev;
195 193
196 indio_dev = devm_iio_device_alloc(dev, sizeof(*state)); 194 indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
197 if (!indio_dev) 195 if (!indio_dev)
diff --git a/drivers/iio/light/st_uvis25.h b/drivers/iio/light/st_uvis25.h
new file mode 100644
index 000000000000..5e970ab480cd
--- /dev/null
+++ b/drivers/iio/light/st_uvis25.h
@@ -0,0 +1,37 @@
1/*
2 * STMicroelectronics uvis25 sensor driver
3 *
4 * Copyright 2017 STMicroelectronics Inc.
5 *
6 * Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#ifndef ST_UVIS25_H
12#define ST_UVIS25_H
13
14#define ST_UVIS25_DEV_NAME "uvis25"
15
16#include <linux/iio/iio.h>
17
18/**
19 * struct st_uvis25_hw - ST UVIS25 sensor instance
20 * @regmap: Register map of the device.
21 * @trig: The trigger in use by the driver.
22 * @enabled: Status of the sensor (false->off, true->on).
23 * @irq: Device interrupt line (I2C or SPI).
24 */
25struct st_uvis25_hw {
26 struct regmap *regmap;
27
28 struct iio_trigger *trig;
29 bool enabled;
30 int irq;
31};
32
33extern const struct dev_pm_ops st_uvis25_pm_ops;
34
35int st_uvis25_probe(struct device *dev, int irq, struct regmap *regmap);
36
37#endif /* ST_UVIS25_H */
diff --git a/drivers/iio/light/st_uvis25_core.c b/drivers/iio/light/st_uvis25_core.c
new file mode 100644
index 000000000000..302635836e6b
--- /dev/null
+++ b/drivers/iio/light/st_uvis25_core.c
@@ -0,0 +1,359 @@
1/*
2 * STMicroelectronics uvis25 sensor driver
3 *
4 * Copyright 2017 STMicroelectronics Inc.
5 *
6 * Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/device.h>
14#include <linux/iio/sysfs.h>
15#include <linux/delay.h>
16#include <linux/pm.h>
17#include <linux/interrupt.h>
18#include <linux/irqreturn.h>
19#include <linux/iio/trigger.h>
20#include <linux/iio/trigger_consumer.h>
21#include <linux/iio/triggered_buffer.h>
22#include <linux/iio/buffer.h>
23#include <linux/regmap.h>
24
25#include "st_uvis25.h"
26
27#define ST_UVIS25_REG_WHOAMI_ADDR 0x0f
28#define ST_UVIS25_REG_WHOAMI_VAL 0xca
29#define ST_UVIS25_REG_CTRL1_ADDR 0x20
30#define ST_UVIS25_REG_ODR_MASK BIT(0)
31#define ST_UVIS25_REG_BDU_MASK BIT(1)
32#define ST_UVIS25_REG_CTRL2_ADDR 0x21
33#define ST_UVIS25_REG_BOOT_MASK BIT(7)
34#define ST_UVIS25_REG_CTRL3_ADDR 0x22
35#define ST_UVIS25_REG_HL_MASK BIT(7)
36#define ST_UVIS25_REG_STATUS_ADDR 0x27
37#define ST_UVIS25_REG_UV_DA_MASK BIT(0)
38#define ST_UVIS25_REG_OUT_ADDR 0x28
39
40static const struct iio_chan_spec st_uvis25_channels[] = {
41 {
42 .type = IIO_UVINDEX,
43 .address = ST_UVIS25_REG_OUT_ADDR,
44 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
45 .scan_index = 0,
46 .scan_type = {
47 .sign = 'u',
48 .realbits = 8,
49 .storagebits = 8,
50 },
51 },
52 IIO_CHAN_SOFT_TIMESTAMP(1),
53};
54
55static int st_uvis25_check_whoami(struct st_uvis25_hw *hw)
56{
57 int err, data;
58
59 err = regmap_read(hw->regmap, ST_UVIS25_REG_WHOAMI_ADDR, &data);
60 if (err < 0) {
61 dev_err(regmap_get_device(hw->regmap),
62 "failed to read whoami register\n");
63 return err;
64 }
65
66 if (data != ST_UVIS25_REG_WHOAMI_VAL) {
67 dev_err(regmap_get_device(hw->regmap),
68 "wrong whoami {%02x vs %02x}\n",
69 data, ST_UVIS25_REG_WHOAMI_VAL);
70 return -ENODEV;
71 }
72
73 return 0;
74}
75
76static int st_uvis25_set_enable(struct st_uvis25_hw *hw, bool enable)
77{
78 int err;
79
80 err = regmap_update_bits(hw->regmap, ST_UVIS25_REG_CTRL1_ADDR,
81 ST_UVIS25_REG_ODR_MASK, enable);
82 if (err < 0)
83 return err;
84
85 hw->enabled = enable;
86
87 return 0;
88}
89
90static int st_uvis25_read_oneshot(struct st_uvis25_hw *hw, u8 addr, int *val)
91{
92 int err;
93
94 err = st_uvis25_set_enable(hw, true);
95 if (err < 0)
96 return err;
97
98 msleep(1500);
99
100 /*
101 * in order to avoid possible race conditions with interrupt
102 * generation, disable the sensor first and then poll output
103 * register. That sequence guarantees the interrupt will be reset
104 * when irq line is unmasked
105 */
106 err = st_uvis25_set_enable(hw, false);
107 if (err < 0)
108 return err;
109
110 err = regmap_read(hw->regmap, addr, val);
111
112 return err < 0 ? err : IIO_VAL_INT;
113}
114
115static int st_uvis25_read_raw(struct iio_dev *iio_dev,
116 struct iio_chan_spec const *ch,
117 int *val, int *val2, long mask)
118{
119 int ret;
120
121 ret = iio_device_claim_direct_mode(iio_dev);
122 if (ret)
123 return ret;
124
125 switch (mask) {
126 case IIO_CHAN_INFO_PROCESSED: {
127 struct st_uvis25_hw *hw = iio_priv(iio_dev);
128
129 /*
130 * mask irq line during oneshot read since the sensor
131 * does not export the capability to disable data-ready line
132 * in the register map and it is enabled by default.
133 * If the line is unmasked during read_raw() it will be set
134 * active and never reset since the trigger is disabled
135 */
136 if (hw->irq > 0)
137 disable_irq(hw->irq);
138 ret = st_uvis25_read_oneshot(hw, ch->address, val);
139 if (hw->irq > 0)
140 enable_irq(hw->irq);
141 break;
142 }
143 default:
144 ret = -EINVAL;
145 break;
146 }
147
148 iio_device_release_direct_mode(iio_dev);
149
150 return ret;
151}
152
153static irqreturn_t st_uvis25_trigger_handler_thread(int irq, void *private)
154{
155 struct st_uvis25_hw *hw = private;
156 int err, status;
157
158 err = regmap_read(hw->regmap, ST_UVIS25_REG_STATUS_ADDR, &status);
159 if (err < 0)
160 return IRQ_HANDLED;
161
162 if (!(status & ST_UVIS25_REG_UV_DA_MASK))
163 return IRQ_NONE;
164
165 iio_trigger_poll_chained(hw->trig);
166
167 return IRQ_HANDLED;
168}
169
170static int st_uvis25_allocate_trigger(struct iio_dev *iio_dev)
171{
172 struct st_uvis25_hw *hw = iio_priv(iio_dev);
173 struct device *dev = regmap_get_device(hw->regmap);
174 bool irq_active_low = false;
175 unsigned long irq_type;
176 int err;
177
178 irq_type = irqd_get_trigger_type(irq_get_irq_data(hw->irq));
179
180 switch (irq_type) {
181 case IRQF_TRIGGER_HIGH:
182 case IRQF_TRIGGER_RISING:
183 break;
184 case IRQF_TRIGGER_LOW:
185 case IRQF_TRIGGER_FALLING:
186 irq_active_low = true;
187 break;
188 default:
189 dev_info(dev, "mode %lx unsupported\n", irq_type);
190 return -EINVAL;
191 }
192
193 err = regmap_update_bits(hw->regmap, ST_UVIS25_REG_CTRL3_ADDR,
194 ST_UVIS25_REG_HL_MASK, irq_active_low);
195 if (err < 0)
196 return err;
197
198 err = devm_request_threaded_irq(dev, hw->irq, NULL,
199 st_uvis25_trigger_handler_thread,
200 irq_type | IRQF_ONESHOT,
201 iio_dev->name, hw);
202 if (err) {
203 dev_err(dev, "failed to request trigger irq %d\n",
204 hw->irq);
205 return err;
206 }
207
208 hw->trig = devm_iio_trigger_alloc(dev, "%s-trigger",
209 iio_dev->name);
210 if (!hw->trig)
211 return -ENOMEM;
212
213 iio_trigger_set_drvdata(hw->trig, iio_dev);
214 hw->trig->dev.parent = dev;
215
216 return devm_iio_trigger_register(dev, hw->trig);
217}
218
219static int st_uvis25_buffer_preenable(struct iio_dev *iio_dev)
220{
221 return st_uvis25_set_enable(iio_priv(iio_dev), true);
222}
223
224static int st_uvis25_buffer_postdisable(struct iio_dev *iio_dev)
225{
226 return st_uvis25_set_enable(iio_priv(iio_dev), false);
227}
228
229static const struct iio_buffer_setup_ops st_uvis25_buffer_ops = {
230 .preenable = st_uvis25_buffer_preenable,
231 .postenable = iio_triggered_buffer_postenable,
232 .predisable = iio_triggered_buffer_predisable,
233 .postdisable = st_uvis25_buffer_postdisable,
234};
235
236static irqreturn_t st_uvis25_buffer_handler_thread(int irq, void *p)
237{
238 u8 buffer[ALIGN(sizeof(u8), sizeof(s64)) + sizeof(s64)];
239 struct iio_poll_func *pf = p;
240 struct iio_dev *iio_dev = pf->indio_dev;
241 struct st_uvis25_hw *hw = iio_priv(iio_dev);
242 int err;
243
244 err = regmap_read(hw->regmap, ST_UVIS25_REG_OUT_ADDR, (int *)buffer);
245 if (err < 0)
246 goto out;
247
248 iio_push_to_buffers_with_timestamp(iio_dev, buffer,
249 iio_get_time_ns(iio_dev));
250
251out:
252 iio_trigger_notify_done(hw->trig);
253
254 return IRQ_HANDLED;
255}
256
257static int st_uvis25_allocate_buffer(struct iio_dev *iio_dev)
258{
259 struct st_uvis25_hw *hw = iio_priv(iio_dev);
260
261 return devm_iio_triggered_buffer_setup(regmap_get_device(hw->regmap),
262 iio_dev, NULL,
263 st_uvis25_buffer_handler_thread,
264 &st_uvis25_buffer_ops);
265}
266
267static const struct iio_info st_uvis25_info = {
268 .read_raw = st_uvis25_read_raw,
269};
270
271static int st_uvis25_init_sensor(struct st_uvis25_hw *hw)
272{
273 int err;
274
275 err = regmap_update_bits(hw->regmap, ST_UVIS25_REG_CTRL2_ADDR,
276 ST_UVIS25_REG_BOOT_MASK, 1);
277 if (err < 0)
278 return err;
279
280 msleep(2000);
281
282 return regmap_update_bits(hw->regmap, ST_UVIS25_REG_CTRL1_ADDR,
283 ST_UVIS25_REG_BDU_MASK, 1);
284}
285
286int st_uvis25_probe(struct device *dev, int irq, struct regmap *regmap)
287{
288 struct st_uvis25_hw *hw;
289 struct iio_dev *iio_dev;
290 int err;
291
292 iio_dev = devm_iio_device_alloc(dev, sizeof(*hw));
293 if (!iio_dev)
294 return -ENOMEM;
295
296 dev_set_drvdata(dev, (void *)iio_dev);
297
298 hw = iio_priv(iio_dev);
299 hw->irq = irq;
300 hw->regmap = regmap;
301
302 err = st_uvis25_check_whoami(hw);
303 if (err < 0)
304 return err;
305
306 iio_dev->modes = INDIO_DIRECT_MODE;
307 iio_dev->dev.parent = dev;
308 iio_dev->channels = st_uvis25_channels;
309 iio_dev->num_channels = ARRAY_SIZE(st_uvis25_channels);
310 iio_dev->name = ST_UVIS25_DEV_NAME;
311 iio_dev->info = &st_uvis25_info;
312
313 err = st_uvis25_init_sensor(hw);
314 if (err < 0)
315 return err;
316
317 if (hw->irq > 0) {
318 err = st_uvis25_allocate_buffer(iio_dev);
319 if (err < 0)
320 return err;
321
322 err = st_uvis25_allocate_trigger(iio_dev);
323 if (err)
324 return err;
325 }
326
327 return devm_iio_device_register(dev, iio_dev);
328}
329EXPORT_SYMBOL(st_uvis25_probe);
330
331static int __maybe_unused st_uvis25_suspend(struct device *dev)
332{
333 struct iio_dev *iio_dev = dev_get_drvdata(dev);
334 struct st_uvis25_hw *hw = iio_priv(iio_dev);
335
336 return regmap_update_bits(hw->regmap, ST_UVIS25_REG_CTRL1_ADDR,
337 ST_UVIS25_REG_ODR_MASK, 0);
338}
339
340static int __maybe_unused st_uvis25_resume(struct device *dev)
341{
342 struct iio_dev *iio_dev = dev_get_drvdata(dev);
343 struct st_uvis25_hw *hw = iio_priv(iio_dev);
344
345 if (hw->enabled)
346 return regmap_update_bits(hw->regmap, ST_UVIS25_REG_CTRL1_ADDR,
347 ST_UVIS25_REG_ODR_MASK, 1);
348
349 return 0;
350}
351
352const struct dev_pm_ops st_uvis25_pm_ops = {
353 SET_SYSTEM_SLEEP_PM_OPS(st_uvis25_suspend, st_uvis25_resume)
354};
355EXPORT_SYMBOL(st_uvis25_pm_ops);
356
357MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
358MODULE_DESCRIPTION("STMicroelectronics uvis25 sensor driver");
359MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/light/st_uvis25_i2c.c b/drivers/iio/light/st_uvis25_i2c.c
new file mode 100644
index 000000000000..afd6eb01a202
--- /dev/null
+++ b/drivers/iio/light/st_uvis25_i2c.c
@@ -0,0 +1,69 @@
1/*
2 * STMicroelectronics uvis25 i2c driver
3 *
4 * Copyright 2017 STMicroelectronics Inc.
5 *
6 * Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/acpi.h>
14#include <linux/i2c.h>
15#include <linux/slab.h>
16#include <linux/regmap.h>
17
18#include "st_uvis25.h"
19
20#define UVIS25_I2C_AUTO_INCREMENT BIT(7)
21
22static const struct regmap_config st_uvis25_i2c_regmap_config = {
23 .reg_bits = 8,
24 .val_bits = 8,
25 .write_flag_mask = UVIS25_I2C_AUTO_INCREMENT,
26 .read_flag_mask = UVIS25_I2C_AUTO_INCREMENT,
27};
28
29static int st_uvis25_i2c_probe(struct i2c_client *client,
30 const struct i2c_device_id *id)
31{
32 struct regmap *regmap;
33
34 regmap = devm_regmap_init_i2c(client, &st_uvis25_i2c_regmap_config);
35 if (IS_ERR(regmap)) {
36 dev_err(&client->dev, "Failed to register i2c regmap %d\n",
37 (int)PTR_ERR(regmap));
38 return PTR_ERR(regmap);
39 }
40
41 return st_uvis25_probe(&client->dev, client->irq, regmap);
42}
43
44static const struct of_device_id st_uvis25_i2c_of_match[] = {
45 { .compatible = "st,uvis25", },
46 {},
47};
48MODULE_DEVICE_TABLE(of, st_uvis25_i2c_of_match);
49
50static const struct i2c_device_id st_uvis25_i2c_id_table[] = {
51 { ST_UVIS25_DEV_NAME },
52 {},
53};
54MODULE_DEVICE_TABLE(i2c, st_uvis25_i2c_id_table);
55
56static struct i2c_driver st_uvis25_driver = {
57 .driver = {
58 .name = "st_uvis25_i2c",
59 .pm = &st_uvis25_pm_ops,
60 .of_match_table = of_match_ptr(st_uvis25_i2c_of_match),
61 },
62 .probe = st_uvis25_i2c_probe,
63 .id_table = st_uvis25_i2c_id_table,
64};
65module_i2c_driver(st_uvis25_driver);
66
67MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
68MODULE_DESCRIPTION("STMicroelectronics uvis25 i2c driver");
69MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/light/st_uvis25_spi.c b/drivers/iio/light/st_uvis25_spi.c
new file mode 100644
index 000000000000..cdfee5e84d5e
--- /dev/null
+++ b/drivers/iio/light/st_uvis25_spi.c
@@ -0,0 +1,68 @@
1/*
2 * STMicroelectronics uvis25 spi driver
3 *
4 * Copyright 2017 STMicroelectronics Inc.
5 *
6 * Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/spi/spi.h>
14#include <linux/slab.h>
15#include <linux/regmap.h>
16
17#include "st_uvis25.h"
18
19#define UVIS25_SENSORS_SPI_READ BIT(7)
20#define UVIS25_SPI_AUTO_INCREMENT BIT(6)
21
22static const struct regmap_config st_uvis25_spi_regmap_config = {
23 .reg_bits = 8,
24 .val_bits = 8,
25 .read_flag_mask = UVIS25_SENSORS_SPI_READ | UVIS25_SPI_AUTO_INCREMENT,
26 .write_flag_mask = UVIS25_SPI_AUTO_INCREMENT,
27};
28
29static int st_uvis25_spi_probe(struct spi_device *spi)
30{
31 struct regmap *regmap;
32
33 regmap = devm_regmap_init_spi(spi, &st_uvis25_spi_regmap_config);
34 if (IS_ERR(regmap)) {
35 dev_err(&spi->dev, "Failed to register spi regmap %d\n",
36 (int)PTR_ERR(regmap));
37 return PTR_ERR(regmap);
38 }
39
40 return st_uvis25_probe(&spi->dev, spi->irq, regmap);
41}
42
43static const struct of_device_id st_uvis25_spi_of_match[] = {
44 { .compatible = "st,uvis25", },
45 {},
46};
47MODULE_DEVICE_TABLE(of, st_uvis25_spi_of_match);
48
49static const struct spi_device_id st_uvis25_spi_id_table[] = {
50 { ST_UVIS25_DEV_NAME },
51 {},
52};
53MODULE_DEVICE_TABLE(spi, st_uvis25_spi_id_table);
54
55static struct spi_driver st_uvis25_driver = {
56 .driver = {
57 .name = "st_uvis25_spi",
58 .pm = &st_uvis25_pm_ops,
59 .of_match_table = of_match_ptr(st_uvis25_spi_of_match),
60 },
61 .probe = st_uvis25_spi_probe,
62 .id_table = st_uvis25_spi_id_table,
63};
64module_spi_driver(st_uvis25_driver);
65
66MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
67MODULE_DESCRIPTION("STMicroelectronics uvis25 spi driver");
68MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/light/zopt2201.c b/drivers/iio/light/zopt2201.c
new file mode 100644
index 000000000000..041ac9effdb0
--- /dev/null
+++ b/drivers/iio/light/zopt2201.c
@@ -0,0 +1,568 @@
1/*
2 * zopt2201.c - Support for IDT ZOPT2201 ambient light and UV B sensor
3 *
4 * Copyright 2017 Peter Meerwald-Stadler <pmeerw@pmeerw.net>
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 * Datasheet: https://www.idt.com/document/dst/zopt2201-datasheet
11 * 7-bit I2C slave addresses 0x53 (default) or 0x52 (programmed)
12 *
13 * TODO: interrupt support, ALS/UVB raw mode
14 */
15
16#include <linux/module.h>
17#include <linux/i2c.h>
18#include <linux/mutex.h>
19#include <linux/err.h>
20#include <linux/delay.h>
21
22#include <linux/iio/iio.h>
23#include <linux/iio/sysfs.h>
24
25#define ZOPT2201_DRV_NAME "zopt2201"
26
27/* Registers */
28#define ZOPT2201_MAIN_CTRL 0x00
29#define ZOPT2201_LS_MEAS_RATE 0x04
30#define ZOPT2201_LS_GAIN 0x05
31#define ZOPT2201_PART_ID 0x06
32#define ZOPT2201_MAIN_STATUS 0x07
33#define ZOPT2201_ALS_DATA 0x0d /* LSB first, 13 to 20 bits */
34#define ZOPT2201_UVB_DATA 0x10 /* LSB first, 13 to 20 bits */
35#define ZOPT2201_UV_COMP_DATA 0x13 /* LSB first, 13 to 20 bits */
36#define ZOPT2201_COMP_DATA 0x16 /* LSB first, 13 to 20 bits */
37#define ZOPT2201_INT_CFG 0x19
38#define ZOPT2201_INT_PST 0x1a
39
40#define ZOPT2201_MAIN_CTRL_LS_MODE BIT(3) /* 0 .. ALS, 1 .. UV B */
41#define ZOPT2201_MAIN_CTRL_LS_EN BIT(1)
42
43/* Values for ZOPT2201_LS_MEAS_RATE resolution / bit width */
44#define ZOPT2201_MEAS_RES_20BIT 0 /* takes 400 ms */
45#define ZOPT2201_MEAS_RES_19BIT 1 /* takes 200 ms */
46#define ZOPT2201_MEAS_RES_18BIT 2 /* takes 100 ms, default */
47#define ZOPT2201_MEAS_RES_17BIT 3 /* takes 50 ms */
48#define ZOPT2201_MEAS_RES_16BIT 4 /* takes 25 ms */
49#define ZOPT2201_MEAS_RES_13BIT 5 /* takes 3.125 ms */
50#define ZOPT2201_MEAS_RES_SHIFT 4
51
52/* Values for ZOPT2201_LS_MEAS_RATE measurement rate */
53#define ZOPT2201_MEAS_FREQ_25MS 0
54#define ZOPT2201_MEAS_FREQ_50MS 1
55#define ZOPT2201_MEAS_FREQ_100MS 2 /* default */
56#define ZOPT2201_MEAS_FREQ_200MS 3
57#define ZOPT2201_MEAS_FREQ_500MS 4
58#define ZOPT2201_MEAS_FREQ_1000MS 5
59#define ZOPT2201_MEAS_FREQ_2000MS 6
60
61/* Values for ZOPT2201_LS_GAIN */
62#define ZOPT2201_LS_GAIN_1 0
63#define ZOPT2201_LS_GAIN_3 1
64#define ZOPT2201_LS_GAIN_6 2
65#define ZOPT2201_LS_GAIN_9 3
66#define ZOPT2201_LS_GAIN_18 4
67
68/* Values for ZOPT2201_MAIN_STATUS */
69#define ZOPT2201_MAIN_STATUS_POWERON BIT(5)
70#define ZOPT2201_MAIN_STATUS_INT BIT(4)
71#define ZOPT2201_MAIN_STATUS_DRDY BIT(3)
72
73#define ZOPT2201_PART_NUMBER 0xb2
74
75struct zopt2201_data {
76 struct i2c_client *client;
77 struct mutex lock;
78 u8 gain;
79 u8 res;
80 u8 rate;
81};
82
83static const struct {
84 unsigned int gain; /* gain factor */
85 unsigned int scale; /* micro lux per count */
86} zopt2201_gain_als[] = {
87 { 1, 19200000 },
88 { 3, 6400000 },
89 { 6, 3200000 },
90 { 9, 2133333 },
91 { 18, 1066666 },
92};
93
94static const struct {
95 unsigned int gain; /* gain factor */
96 unsigned int scale; /* micro W/m2 per count */
97} zopt2201_gain_uvb[] = {
98 { 1, 460800 },
99 { 3, 153600 },
100 { 6, 76800 },
101 { 9, 51200 },
102 { 18, 25600 },
103};
104
105static const struct {
106 unsigned int bits; /* sensor resolution in bits */
107 unsigned long us; /* measurement time in micro seconds */
108} zopt2201_resolution[] = {
109 { 20, 400000 },
110 { 19, 200000 },
111 { 18, 100000 },
112 { 17, 50000 },
113 { 16, 25000 },
114 { 13, 3125 },
115};
116
117static const struct {
118 unsigned int scale, uscale; /* scale factor as integer + micro */
119 u8 gain; /* gain register value */
120 u8 res; /* resolution register value */
121} zopt2201_scale_als[] = {
122 { 19, 200000, 0, 5 },
123 { 6, 400000, 1, 5 },
124 { 3, 200000, 2, 5 },
125 { 2, 400000, 0, 4 },
126 { 2, 133333, 3, 5 },
127 { 1, 200000, 0, 3 },
128 { 1, 66666, 4, 5 },
129 { 0, 800000, 1, 4 },
130 { 0, 600000, 0, 2 },
131 { 0, 400000, 2, 4 },
132 { 0, 300000, 0, 1 },
133 { 0, 266666, 3, 4 },
134 { 0, 200000, 2, 3 },
135 { 0, 150000, 0, 0 },
136 { 0, 133333, 4, 4 },
137 { 0, 100000, 2, 2 },
138 { 0, 66666, 4, 3 },
139 { 0, 50000, 2, 1 },
140 { 0, 33333, 4, 2 },
141 { 0, 25000, 2, 0 },
142 { 0, 16666, 4, 1 },
143 { 0, 8333, 4, 0 },
144};
145
146static const struct {
147 unsigned int scale, uscale; /* scale factor as integer + micro */
148 u8 gain; /* gain register value */
149 u8 res; /* resolution register value */
150} zopt2201_scale_uvb[] = {
151 { 0, 460800, 0, 5 },
152 { 0, 153600, 1, 5 },
153 { 0, 76800, 2, 5 },
154 { 0, 57600, 0, 4 },
155 { 0, 51200, 3, 5 },
156 { 0, 28800, 0, 3 },
157 { 0, 25600, 4, 5 },
158 { 0, 19200, 1, 4 },
159 { 0, 14400, 0, 2 },
160 { 0, 9600, 2, 4 },
161 { 0, 7200, 0, 1 },
162 { 0, 6400, 3, 4 },
163 { 0, 4800, 2, 3 },
164 { 0, 3600, 0, 0 },
165 { 0, 3200, 4, 4 },
166 { 0, 2400, 2, 2 },
167 { 0, 1600, 4, 3 },
168 { 0, 1200, 2, 1 },
169 { 0, 800, 4, 2 },
170 { 0, 600, 2, 0 },
171 { 0, 400, 4, 1 },
172 { 0, 200, 4, 0 },
173};
174
175static int zopt2201_enable_mode(struct zopt2201_data *data, bool uvb_mode)
176{
177 u8 out = ZOPT2201_MAIN_CTRL_LS_EN;
178
179 if (uvb_mode)
180 out |= ZOPT2201_MAIN_CTRL_LS_MODE;
181
182 return i2c_smbus_write_byte_data(data->client, ZOPT2201_MAIN_CTRL, out);
183}
184
185static int zopt2201_read(struct zopt2201_data *data, u8 reg)
186{
187 struct i2c_client *client = data->client;
188 int tries = 10;
189 u8 buf[3];
190 int ret;
191
192 mutex_lock(&data->lock);
193 ret = zopt2201_enable_mode(data, reg == ZOPT2201_UVB_DATA);
194 if (ret < 0)
195 goto fail;
196
197 while (tries--) {
198 unsigned long t = zopt2201_resolution[data->res].us;
199
200 if (t <= 20000)
201 usleep_range(t, t + 1000);
202 else
203 msleep(t / 1000);
204 ret = i2c_smbus_read_byte_data(client, ZOPT2201_MAIN_STATUS);
205 if (ret < 0)
206 goto fail;
207 if (ret & ZOPT2201_MAIN_STATUS_DRDY)
208 break;
209 }
210
211 if (tries < 0) {
212 ret = -ETIMEDOUT;
213 goto fail;
214 }
215
216 ret = i2c_smbus_read_i2c_block_data(client, reg, sizeof(buf), buf);
217 if (ret < 0)
218 goto fail;
219
220 ret = i2c_smbus_write_byte_data(client, ZOPT2201_MAIN_CTRL, 0x00);
221 if (ret < 0)
222 goto fail;
223 mutex_unlock(&data->lock);
224
225 return (buf[2] << 16) | (buf[1] << 8) | buf[0];
226
227fail:
228 mutex_unlock(&data->lock);
229 return ret;
230}
231
232static const struct iio_chan_spec zopt2201_channels[] = {
233 {
234 .type = IIO_LIGHT,
235 .address = ZOPT2201_ALS_DATA,
236 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
237 BIT(IIO_CHAN_INFO_SCALE),
238 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME),
239 },
240 {
241 .type = IIO_INTENSITY,
242 .modified = 1,
243 .channel2 = IIO_MOD_LIGHT_UV,
244 .address = ZOPT2201_UVB_DATA,
245 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
246 BIT(IIO_CHAN_INFO_SCALE),
247 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME),
248 },
249 {
250 .type = IIO_UVINDEX,
251 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
252 },
253};
254
255static int zopt2201_read_raw(struct iio_dev *indio_dev,
256 struct iio_chan_spec const *chan,
257 int *val, int *val2, long mask)
258{
259 struct zopt2201_data *data = iio_priv(indio_dev);
260 u64 tmp;
261 int ret;
262
263 switch (mask) {
264 case IIO_CHAN_INFO_RAW:
265 ret = zopt2201_read(data, chan->address);
266 if (ret < 0)
267 return ret;
268 *val = ret;
269 return IIO_VAL_INT;
270 case IIO_CHAN_INFO_PROCESSED:
271 ret = zopt2201_read(data, ZOPT2201_UVB_DATA);
272 if (ret < 0)
273 return ret;
274 *val = ret * 18 *
275 (1 << (20 - zopt2201_resolution[data->res].bits)) /
276 zopt2201_gain_uvb[data->gain].gain;
277 return IIO_VAL_INT;
278 case IIO_CHAN_INFO_SCALE:
279 switch (chan->address) {
280 case ZOPT2201_ALS_DATA:
281 *val = zopt2201_gain_als[data->gain].scale;
282 break;
283 case ZOPT2201_UVB_DATA:
284 *val = zopt2201_gain_uvb[data->gain].scale;
285 break;
286 default:
287 return -EINVAL;
288 }
289
290 *val2 = 1000000;
291 *val2 *= (1 << (zopt2201_resolution[data->res].bits - 13));
292 tmp = div_s64(*val * 1000000ULL, *val2);
293 *val = div_s64_rem(tmp, 1000000, val2);
294
295 return IIO_VAL_INT_PLUS_MICRO;
296 case IIO_CHAN_INFO_INT_TIME:
297 *val = 0;
298 *val2 = zopt2201_resolution[data->res].us;
299 return IIO_VAL_INT_PLUS_MICRO;
300 default:
301 return -EINVAL;
302 }
303}
304
305static int zopt2201_set_resolution(struct zopt2201_data *data, u8 res)
306{
307 int ret;
308
309 ret = i2c_smbus_write_byte_data(data->client, ZOPT2201_LS_MEAS_RATE,
310 (res << ZOPT2201_MEAS_RES_SHIFT) |
311 data->rate);
312 if (ret < 0)
313 return ret;
314
315 data->res = res;
316
317 return 0;
318}
319
320static int zopt2201_write_resolution(struct zopt2201_data *data,
321 int val, int val2)
322{
323 int i, ret;
324
325 if (val != 0)
326 return -EINVAL;
327
328 for (i = 0; i < ARRAY_SIZE(zopt2201_resolution); i++)
329 if (val2 == zopt2201_resolution[i].us) {
330 mutex_lock(&data->lock);
331 ret = zopt2201_set_resolution(data, i);
332 mutex_unlock(&data->lock);
333 return ret;
334 }
335
336 return -EINVAL;
337}
338
339static int zopt2201_set_gain(struct zopt2201_data *data, u8 gain)
340{
341 int ret;
342
343 ret = i2c_smbus_write_byte_data(data->client, ZOPT2201_LS_GAIN, gain);
344 if (ret < 0)
345 return ret;
346
347 data->gain = gain;
348
349 return 0;
350}
351
352static int zopt2201_write_scale_als_by_idx(struct zopt2201_data *data, int idx)
353{
354 int ret;
355
356 mutex_lock(&data->lock);
357 ret = zopt2201_set_resolution(data, zopt2201_scale_als[idx].res);
358 if (ret < 0)
359 goto unlock;
360
361 ret = zopt2201_set_gain(data, zopt2201_scale_als[idx].gain);
362
363unlock:
364 mutex_unlock(&data->lock);
365 return ret;
366}
367
368static int zopt2201_write_scale_als(struct zopt2201_data *data,
369 int val, int val2)
370{
371 int i;
372
373 for (i = 0; i < ARRAY_SIZE(zopt2201_scale_als); i++)
374 if (val == zopt2201_scale_als[i].scale &&
375 val2 == zopt2201_scale_als[i].uscale) {
376 return zopt2201_write_scale_als_by_idx(data, i);
377 }
378
379 return -EINVAL;
380}
381
382static int zopt2201_write_scale_uvb_by_idx(struct zopt2201_data *data, int idx)
383{
384 int ret;
385
386 mutex_lock(&data->lock);
387 ret = zopt2201_set_resolution(data, zopt2201_scale_als[idx].res);
388 if (ret < 0)
389 goto unlock;
390
391 ret = zopt2201_set_gain(data, zopt2201_scale_als[idx].gain);
392
393unlock:
394 mutex_unlock(&data->lock);
395 return ret;
396}
397
398static int zopt2201_write_scale_uvb(struct zopt2201_data *data,
399 int val, int val2)
400{
401 int i;
402
403 for (i = 0; i < ARRAY_SIZE(zopt2201_scale_uvb); i++)
404 if (val == zopt2201_scale_uvb[i].scale &&
405 val2 == zopt2201_scale_uvb[i].uscale)
406 return zopt2201_write_scale_uvb_by_idx(data, i);
407
408 return -EINVAL;
409}
410
411static int zopt2201_write_raw(struct iio_dev *indio_dev,
412 struct iio_chan_spec const *chan,
413 int val, int val2, long mask)
414{
415 struct zopt2201_data *data = iio_priv(indio_dev);
416
417 switch (mask) {
418 case IIO_CHAN_INFO_INT_TIME:
419 return zopt2201_write_resolution(data, val, val2);
420 case IIO_CHAN_INFO_SCALE:
421 switch (chan->address) {
422 case ZOPT2201_ALS_DATA:
423 return zopt2201_write_scale_als(data, val, val2);
424 case ZOPT2201_UVB_DATA:
425 return zopt2201_write_scale_uvb(data, val, val2);
426 default:
427 return -EINVAL;
428 }
429 }
430
431 return -EINVAL;
432}
433
434static ssize_t zopt2201_show_int_time_available(struct device *dev,
435 struct device_attribute *attr,
436 char *buf)
437{
438 size_t len = 0;
439 int i;
440
441 for (i = 0; i < ARRAY_SIZE(zopt2201_resolution); i++)
442 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06lu ",
443 zopt2201_resolution[i].us);
444 buf[len - 1] = '\n';
445
446 return len;
447}
448
449static IIO_DEV_ATTR_INT_TIME_AVAIL(zopt2201_show_int_time_available);
450
451static ssize_t zopt2201_show_als_scale_avail(struct device *dev,
452 struct device_attribute *attr,
453 char *buf)
454{
455 ssize_t len = 0;
456 int i;
457
458 for (i = 0; i < ARRAY_SIZE(zopt2201_scale_als); i++)
459 len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06u ",
460 zopt2201_scale_als[i].scale,
461 zopt2201_scale_als[i].uscale);
462 buf[len - 1] = '\n';
463
464 return len;
465}
466
467static ssize_t zopt2201_show_uvb_scale_avail(struct device *dev,
468 struct device_attribute *attr,
469 char *buf)
470{
471 ssize_t len = 0;
472 int i;
473
474 for (i = 0; i < ARRAY_SIZE(zopt2201_scale_uvb); i++)
475 len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06u ",
476 zopt2201_scale_uvb[i].scale,
477 zopt2201_scale_uvb[i].uscale);
478 buf[len - 1] = '\n';
479
480 return len;
481}
482
483static IIO_DEVICE_ATTR(in_illuminance_scale_available, 0444,
484 zopt2201_show_als_scale_avail, NULL, 0);
485static IIO_DEVICE_ATTR(in_intensity_uv_scale_available, 0444,
486 zopt2201_show_uvb_scale_avail, NULL, 0);
487
488static struct attribute *zopt2201_attributes[] = {
489 &iio_dev_attr_integration_time_available.dev_attr.attr,
490 &iio_dev_attr_in_illuminance_scale_available.dev_attr.attr,
491 &iio_dev_attr_in_intensity_uv_scale_available.dev_attr.attr,
492 NULL
493};
494
495static const struct attribute_group zopt2201_attribute_group = {
496 .attrs = zopt2201_attributes,
497};
498
499static const struct iio_info zopt2201_info = {
500 .read_raw = zopt2201_read_raw,
501 .write_raw = zopt2201_write_raw,
502 .attrs = &zopt2201_attribute_group,
503};
504
505static int zopt2201_probe(struct i2c_client *client,
506 const struct i2c_device_id *id)
507{
508 struct zopt2201_data *data;
509 struct iio_dev *indio_dev;
510 int ret;
511
512 if (!i2c_check_functionality(client->adapter,
513 I2C_FUNC_SMBUS_READ_I2C_BLOCK))
514 return -EOPNOTSUPP;
515
516 ret = i2c_smbus_read_byte_data(client, ZOPT2201_PART_ID);
517 if (ret < 0)
518 return ret;
519 if (ret != ZOPT2201_PART_NUMBER)
520 return -ENODEV;
521
522 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
523 if (!indio_dev)
524 return -ENOMEM;
525
526 data = iio_priv(indio_dev);
527 i2c_set_clientdata(client, indio_dev);
528 data->client = client;
529 mutex_init(&data->lock);
530
531 indio_dev->dev.parent = &client->dev;
532 indio_dev->info = &zopt2201_info;
533 indio_dev->channels = zopt2201_channels;
534 indio_dev->num_channels = ARRAY_SIZE(zopt2201_channels);
535 indio_dev->name = ZOPT2201_DRV_NAME;
536 indio_dev->modes = INDIO_DIRECT_MODE;
537
538 data->rate = ZOPT2201_MEAS_FREQ_100MS;
539 ret = zopt2201_set_resolution(data, ZOPT2201_MEAS_RES_18BIT);
540 if (ret < 0)
541 return ret;
542
543 ret = zopt2201_set_gain(data, ZOPT2201_LS_GAIN_3);
544 if (ret < 0)
545 return ret;
546
547 return devm_iio_device_register(&client->dev, indio_dev);
548}
549
550static const struct i2c_device_id zopt2201_id[] = {
551 { "zopt2201", 0 },
552 { }
553};
554MODULE_DEVICE_TABLE(i2c, zopt2201_id);
555
556static struct i2c_driver zopt2201_driver = {
557 .driver = {
558 .name = ZOPT2201_DRV_NAME,
559 },
560 .probe = zopt2201_probe,
561 .id_table = zopt2201_id,
562};
563
564module_i2c_driver(zopt2201_driver);
565
566MODULE_AUTHOR("Peter Meerwald-Stadler <pmeerw@pmeerw.net>");
567MODULE_DESCRIPTION("IDT ZOPT2201 ambient light and UV B sensor driver");
568MODULE_LICENSE("GPL");
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index c09329069d0a..42a827a66512 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -788,6 +788,7 @@ static const struct acpi_device_id ak_acpi_match[] = {
788 {"AK8975", AK8975}, 788 {"AK8975", AK8975},
789 {"AK8963", AK8963}, 789 {"AK8963", AK8963},
790 {"INVN6500", AK8963}, 790 {"INVN6500", AK8963},
791 {"AK009911", AK09911},
791 {"AK09911", AK09911}, 792 {"AK09911", AK09911},
792 {"AK09912", AK09912}, 793 {"AK09912", AK09912},
793 { }, 794 { },
diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index fd1da26a62e4..5ec3e41b65f2 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -55,6 +55,28 @@ struct bmp180_calib {
55 s16 MD; 55 s16 MD;
56}; 56};
57 57
58/* See datasheet Section 4.2.2. */
59struct bmp280_calib {
60 u16 T1;
61 s16 T2;
62 s16 T3;
63 u16 P1;
64 s16 P2;
65 s16 P3;
66 s16 P4;
67 s16 P5;
68 s16 P6;
69 s16 P7;
70 s16 P8;
71 s16 P9;
72 u8 H1;
73 s16 H2;
74 u8 H3;
75 s16 H4;
76 s16 H5;
77 s8 H6;
78};
79
58struct bmp280_data { 80struct bmp280_data {
59 struct device *dev; 81 struct device *dev;
60 struct mutex lock; 82 struct mutex lock;
@@ -62,7 +84,10 @@ struct bmp280_data {
62 struct completion done; 84 struct completion done;
63 bool use_eoc; 85 bool use_eoc;
64 const struct bmp280_chip_info *chip_info; 86 const struct bmp280_chip_info *chip_info;
65 struct bmp180_calib calib; 87 union {
88 struct bmp180_calib bmp180;
89 struct bmp280_calib bmp280;
90 } calib;
66 struct regulator *vddd; 91 struct regulator *vddd;
67 struct regulator *vdda; 92 struct regulator *vdda;
68 unsigned int start_up_time; /* in microseconds */ 93 unsigned int start_up_time; /* in microseconds */
@@ -120,67 +145,121 @@ static const struct iio_chan_spec bmp280_channels[] = {
120 }, 145 },
121}; 146};
122 147
123/* 148static int bmp280_read_calib(struct bmp280_data *data,
124 * Returns humidity in percent, resolution is 0.01 percent. Output value of 149 struct bmp280_calib *calib,
125 * "47445" represents 47445/1024 = 46.333 %RH. 150 unsigned int chip)
126 *
127 * Taken from BME280 datasheet, Section 4.2.3, "Compensation formula".
128 */
129
130static u32 bmp280_compensate_humidity(struct bmp280_data *data,
131 s32 adc_humidity)
132{ 151{
152 int ret;
153 unsigned int tmp;
133 struct device *dev = data->dev; 154 struct device *dev = data->dev;
134 unsigned int H1, H3, tmp; 155 __le16 t_buf[BMP280_COMP_TEMP_REG_COUNT / 2];
135 int H2, H4, H5, H6, ret, var; 156 __le16 p_buf[BMP280_COMP_PRESS_REG_COUNT / 2];
157
158 /* Read temperature calibration values. */
159 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_TEMP_START,
160 t_buf, BMP280_COMP_TEMP_REG_COUNT);
161 if (ret < 0) {
162 dev_err(data->dev,
163 "failed to read temperature calibration parameters\n");
164 return ret;
165 }
166
167 calib->T1 = le16_to_cpu(t_buf[T1]);
168 calib->T2 = le16_to_cpu(t_buf[T2]);
169 calib->T3 = le16_to_cpu(t_buf[T3]);
136 170
137 ret = regmap_read(data->regmap, BMP280_REG_COMP_H1, &H1); 171 /* Read pressure calibration values. */
172 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_PRESS_START,
173 p_buf, BMP280_COMP_PRESS_REG_COUNT);
174 if (ret < 0) {
175 dev_err(data->dev,
176 "failed to read pressure calibration parameters\n");
177 return ret;
178 }
179
180 calib->P1 = le16_to_cpu(p_buf[P1]);
181 calib->P2 = le16_to_cpu(p_buf[P2]);
182 calib->P3 = le16_to_cpu(p_buf[P3]);
183 calib->P4 = le16_to_cpu(p_buf[P4]);
184 calib->P5 = le16_to_cpu(p_buf[P5]);
185 calib->P6 = le16_to_cpu(p_buf[P6]);
186 calib->P7 = le16_to_cpu(p_buf[P7]);
187 calib->P8 = le16_to_cpu(p_buf[P8]);
188 calib->P9 = le16_to_cpu(p_buf[P9]);
189
190 /*
191 * Read humidity calibration values.
192 * Due to some odd register addressing we cannot just
193 * do a big bulk read. Instead, we have to read each Hx
194 * value separately and sometimes do some bit shifting...
195 * Humidity data is only available on BME280.
196 */
197 if (chip != BME280_CHIP_ID)
198 return 0;
199
200 ret = regmap_read(data->regmap, BMP280_REG_COMP_H1, &tmp);
138 if (ret < 0) { 201 if (ret < 0) {
139 dev_err(dev, "failed to read H1 comp value\n"); 202 dev_err(dev, "failed to read H1 comp value\n");
140 return ret; 203 return ret;
141 } 204 }
205 calib->H1 = tmp;
142 206
143 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H2, &tmp, 2); 207 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H2, &tmp, 2);
144 if (ret < 0) { 208 if (ret < 0) {
145 dev_err(dev, "failed to read H2 comp value\n"); 209 dev_err(dev, "failed to read H2 comp value\n");
146 return ret; 210 return ret;
147 } 211 }
148 H2 = sign_extend32(le16_to_cpu(tmp), 15); 212 calib->H2 = sign_extend32(le16_to_cpu(tmp), 15);
149 213
150 ret = regmap_read(data->regmap, BMP280_REG_COMP_H3, &H3); 214 ret = regmap_read(data->regmap, BMP280_REG_COMP_H3, &tmp);
151 if (ret < 0) { 215 if (ret < 0) {
152 dev_err(dev, "failed to read H3 comp value\n"); 216 dev_err(dev, "failed to read H3 comp value\n");
153 return ret; 217 return ret;
154 } 218 }
219 calib->H3 = tmp;
155 220
156 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H4, &tmp, 2); 221 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H4, &tmp, 2);
157 if (ret < 0) { 222 if (ret < 0) {
158 dev_err(dev, "failed to read H4 comp value\n"); 223 dev_err(dev, "failed to read H4 comp value\n");
159 return ret; 224 return ret;
160 } 225 }
161 H4 = sign_extend32(((be16_to_cpu(tmp) >> 4) & 0xff0) | 226 calib->H4 = sign_extend32(((be16_to_cpu(tmp) >> 4) & 0xff0) |
162 (be16_to_cpu(tmp) & 0xf), 11); 227 (be16_to_cpu(tmp) & 0xf), 11);
163 228
164 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H5, &tmp, 2); 229 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H5, &tmp, 2);
165 if (ret < 0) { 230 if (ret < 0) {
166 dev_err(dev, "failed to read H5 comp value\n"); 231 dev_err(dev, "failed to read H5 comp value\n");
167 return ret; 232 return ret;
168 } 233 }
169 H5 = sign_extend32(((le16_to_cpu(tmp) >> 4) & 0xfff), 11); 234 calib->H5 = sign_extend32(((le16_to_cpu(tmp) >> 4) & 0xfff), 11);
170 235
171 ret = regmap_read(data->regmap, BMP280_REG_COMP_H6, &tmp); 236 ret = regmap_read(data->regmap, BMP280_REG_COMP_H6, &tmp);
172 if (ret < 0) { 237 if (ret < 0) {
173 dev_err(dev, "failed to read H6 comp value\n"); 238 dev_err(dev, "failed to read H6 comp value\n");
174 return ret; 239 return ret;
175 } 240 }
176 H6 = sign_extend32(tmp, 7); 241 calib->H6 = sign_extend32(tmp, 7);
242
243 return 0;
244}
245/*
246 * Returns humidity in percent, resolution is 0.01 percent. Output value of
247 * "47445" represents 47445/1024 = 46.333 %RH.
248 *
249 * Taken from BME280 datasheet, Section 4.2.3, "Compensation formula".
250 */
251static u32 bmp280_compensate_humidity(struct bmp280_data *data,
252 s32 adc_humidity)
253{
254 s32 var;
255 struct bmp280_calib *calib = &data->calib.bmp280;
177 256
178 var = ((s32)data->t_fine) - (s32)76800; 257 var = ((s32)data->t_fine) - (s32)76800;
179 var = ((((adc_humidity << 14) - (H4 << 20) - (H5 * var)) 258 var = ((((adc_humidity << 14) - (calib->H4 << 20) - (calib->H5 * var))
180 + (s32)16384) >> 15) * (((((((var * H6) >> 10) 259 + (s32)16384) >> 15) * (((((((var * calib->H6) >> 10)
181 * (((var * (s32)H3) >> 11) + (s32)32768)) >> 10) 260 * (((var * (s32)calib->H3) >> 11) + (s32)32768)) >> 10)
182 + (s32)2097152) * H2 + 8192) >> 14); 261 + (s32)2097152) * calib->H2 + 8192) >> 14);
183 var -= ((((var >> 15) * (var >> 15)) >> 7) * (s32)H1) >> 4; 262 var -= ((((var >> 15) * (var >> 15)) >> 7) * (s32)calib->H1) >> 4;
184 263
185 return var >> 12; 264 return var >> 12;
186}; 265};
@@ -195,31 +274,14 @@ static u32 bmp280_compensate_humidity(struct bmp280_data *data,
195static s32 bmp280_compensate_temp(struct bmp280_data *data, 274static s32 bmp280_compensate_temp(struct bmp280_data *data,
196 s32 adc_temp) 275 s32 adc_temp)
197{ 276{
198 int ret;
199 s32 var1, var2; 277 s32 var1, var2;
200 __le16 buf[BMP280_COMP_TEMP_REG_COUNT / 2]; 278 struct bmp280_calib *calib = &data->calib.bmp280;
201 279
202 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_TEMP_START, 280 var1 = (((adc_temp >> 3) - ((s32)calib->T1 << 1)) *
203 buf, BMP280_COMP_TEMP_REG_COUNT); 281 ((s32)calib->T2)) >> 11;
204 if (ret < 0) { 282 var2 = (((((adc_temp >> 4) - ((s32)calib->T1)) *
205 dev_err(data->dev, 283 ((adc_temp >> 4) - ((s32)calib->T1))) >> 12) *
206 "failed to read temperature calibration parameters\n"); 284 ((s32)calib->T3)) >> 14;
207 return ret;
208 }
209
210 /*
211 * The double casts are necessary because le16_to_cpu returns an
212 * unsigned 16-bit value. Casting that value directly to a
213 * signed 32-bit will not do proper sign extension.
214 *
215 * Conversely, T1 and P1 are unsigned values, so they can be
216 * cast straight to the larger type.
217 */
218 var1 = (((adc_temp >> 3) - ((s32)le16_to_cpu(buf[T1]) << 1)) *
219 ((s32)(s16)le16_to_cpu(buf[T2]))) >> 11;
220 var2 = (((((adc_temp >> 4) - ((s32)le16_to_cpu(buf[T1]))) *
221 ((adc_temp >> 4) - ((s32)le16_to_cpu(buf[T1])))) >> 12) *
222 ((s32)(s16)le16_to_cpu(buf[T3]))) >> 14;
223 data->t_fine = var1 + var2; 285 data->t_fine = var1 + var2;
224 286
225 return (data->t_fine * 5 + 128) >> 8; 287 return (data->t_fine * 5 + 128) >> 8;
@@ -235,34 +297,25 @@ static s32 bmp280_compensate_temp(struct bmp280_data *data,
235static u32 bmp280_compensate_press(struct bmp280_data *data, 297static u32 bmp280_compensate_press(struct bmp280_data *data,
236 s32 adc_press) 298 s32 adc_press)
237{ 299{
238 int ret;
239 s64 var1, var2, p; 300 s64 var1, var2, p;
240 __le16 buf[BMP280_COMP_PRESS_REG_COUNT / 2]; 301 struct bmp280_calib *calib = &data->calib.bmp280;
241
242 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_PRESS_START,
243 buf, BMP280_COMP_PRESS_REG_COUNT);
244 if (ret < 0) {
245 dev_err(data->dev,
246 "failed to read pressure calibration parameters\n");
247 return ret;
248 }
249 302
250 var1 = ((s64)data->t_fine) - 128000; 303 var1 = ((s64)data->t_fine) - 128000;
251 var2 = var1 * var1 * (s64)(s16)le16_to_cpu(buf[P6]); 304 var2 = var1 * var1 * (s64)calib->P6;
252 var2 += (var1 * (s64)(s16)le16_to_cpu(buf[P5])) << 17; 305 var2 += (var1 * (s64)calib->P5) << 17;
253 var2 += ((s64)(s16)le16_to_cpu(buf[P4])) << 35; 306 var2 += ((s64)calib->P4) << 35;
254 var1 = ((var1 * var1 * (s64)(s16)le16_to_cpu(buf[P3])) >> 8) + 307 var1 = ((var1 * var1 * (s64)calib->P3) >> 8) +
255 ((var1 * (s64)(s16)le16_to_cpu(buf[P2])) << 12); 308 ((var1 * (s64)calib->P2) << 12);
256 var1 = ((((s64)1) << 47) + var1) * ((s64)le16_to_cpu(buf[P1])) >> 33; 309 var1 = ((((s64)1) << 47) + var1) * ((s64)calib->P1) >> 33;
257 310
258 if (var1 == 0) 311 if (var1 == 0)
259 return 0; 312 return 0;
260 313
261 p = ((((s64)1048576 - adc_press) << 31) - var2) * 3125; 314 p = ((((s64)1048576 - adc_press) << 31) - var2) * 3125;
262 p = div64_s64(p, var1); 315 p = div64_s64(p, var1);
263 var1 = (((s64)(s16)le16_to_cpu(buf[P9])) * (p >> 13) * (p >> 13)) >> 25; 316 var1 = (((s64)calib->P9) * (p >> 13) * (p >> 13)) >> 25;
264 var2 = (((s64)(s16)le16_to_cpu(buf[P8])) * p) >> 19; 317 var2 = ((s64)(calib->P8) * p) >> 19;
265 p = ((p + var1 + var2) >> 8) + (((s64)(s16)le16_to_cpu(buf[P7])) << 4); 318 p = ((p + var1 + var2) >> 8) + (((s64)calib->P7) << 4);
266 319
267 return (u32)p; 320 return (u32)p;
268} 321}
@@ -752,7 +805,7 @@ static int bmp180_read_calib(struct bmp280_data *data,
752static s32 bmp180_compensate_temp(struct bmp280_data *data, s32 adc_temp) 805static s32 bmp180_compensate_temp(struct bmp280_data *data, s32 adc_temp)
753{ 806{
754 s32 x1, x2; 807 s32 x1, x2;
755 struct bmp180_calib *calib = &data->calib; 808 struct bmp180_calib *calib = &data->calib.bmp180;
756 809
757 x1 = ((adc_temp - calib->AC6) * calib->AC5) >> 15; 810 x1 = ((adc_temp - calib->AC6) * calib->AC5) >> 15;
758 x2 = (calib->MC << 11) / (x1 + calib->MD); 811 x2 = (calib->MC << 11) / (x1 + calib->MD);
@@ -814,7 +867,7 @@ static u32 bmp180_compensate_press(struct bmp280_data *data, s32 adc_press)
814 s32 b3, b6; 867 s32 b3, b6;
815 u32 b4, b7; 868 u32 b4, b7;
816 s32 oss = data->oversampling_press; 869 s32 oss = data->oversampling_press;
817 struct bmp180_calib *calib = &data->calib; 870 struct bmp180_calib *calib = &data->calib.bmp180;
818 871
819 b6 = data->t_fine - 4000; 872 b6 = data->t_fine - 4000;
820 x1 = (calib->B2 * (b6 * b6 >> 12)) >> 11; 873 x1 = (calib->B2 * (b6 * b6 >> 12)) >> 11;
@@ -1028,11 +1081,19 @@ int bmp280_common_probe(struct device *dev,
1028 dev_set_drvdata(dev, indio_dev); 1081 dev_set_drvdata(dev, indio_dev);
1029 1082
1030 /* 1083 /*
1031 * The BMP085 and BMP180 has calibration in an E2PROM, read it out 1084 * Some chips have calibration parameters "programmed into the devices'
1032 * at probe time. It will not change. 1085 * non-volatile memory during production". Let's read them out at probe
1086 * time once. They will not change.
1033 */ 1087 */
1034 if (chip_id == BMP180_CHIP_ID) { 1088 if (chip_id == BMP180_CHIP_ID) {
1035 ret = bmp180_read_calib(data, &data->calib); 1089 ret = bmp180_read_calib(data, &data->calib.bmp180);
1090 if (ret < 0) {
1091 dev_err(data->dev,
1092 "failed to read calibration coefficients\n");
1093 goto out_disable_vdda;
1094 }
1095 } else if (chip_id == BMP280_CHIP_ID || chip_id == BME280_CHIP_ID) {
1096 ret = bmp280_read_calib(data, &data->calib.bmp280, chip_id);
1036 if (ret < 0) { 1097 if (ret < 0) {
1037 dev_err(data->dev, 1098 dev_err(data->dev,
1038 "failed to read calibration coefficients\n"); 1099 "failed to read calibration coefficients\n");
diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c
index df23dbcc030a..b8a2c2c8cac5 100644
--- a/drivers/iio/proximity/sx9500.c
+++ b/drivers/iio/proximity/sx9500.c
@@ -1031,6 +1031,7 @@ static const struct dev_pm_ops sx9500_pm_ops = {
1031 1031
1032static const struct acpi_device_id sx9500_acpi_match[] = { 1032static const struct acpi_device_id sx9500_acpi_match[] = {
1033 {"SSX9500", 0}, 1033 {"SSX9500", 0},
1034 {"SASX9500", 0},
1034 { }, 1035 { },
1035}; 1036};
1036MODULE_DEVICE_TABLE(acpi, sx9500_acpi_match); 1037MODULE_DEVICE_TABLE(acpi, sx9500_acpi_match);
diff --git a/drivers/iio/trigger/stm32-lptimer-trigger.c b/drivers/iio/trigger/stm32-lptimer-trigger.c
index de361d879929..98cdc7e47f3d 100644
--- a/drivers/iio/trigger/stm32-lptimer-trigger.c
+++ b/drivers/iio/trigger/stm32-lptimer-trigger.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * STM32 Low-Power Timer Trigger driver 3 * STM32 Low-Power Timer Trigger driver
3 * 4 *
@@ -5,8 +6,6 @@
5 * 6 *
6 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>. 7 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>.
7 * 8 *
8 * License terms: GNU General Public License (GPL), version 2
9 *
10 * Inspired by Benjamin Gaignard's stm32-timer-trigger driver 9 * Inspired by Benjamin Gaignard's stm32-timer-trigger driver
11 */ 10 */
12 11
diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c
index b542dc484969..ccf1ce653b25 100644
--- a/drivers/iio/trigger/stm32-timer-trigger.c
+++ b/drivers/iio/trigger/stm32-timer-trigger.c
@@ -1,9 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) STMicroelectronics 2016 3 * Copyright (C) STMicroelectronics 2016
3 * 4 *
4 * Author: Benjamin Gaignard <benjamin.gaignard@st.com> 5 * Author: Benjamin Gaignard <benjamin.gaignard@st.com>
5 * 6 *
6 * License terms: GNU General Public License (GPL), version 2
7 */ 7 */
8 8
9#include <linux/iio/iio.h> 9#include <linux/iio/iio.h>
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 554683912cff..e95ab683331e 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -26,6 +26,10 @@ if STAGING
26 26
27source "drivers/staging/irda/net/Kconfig" 27source "drivers/staging/irda/net/Kconfig"
28 28
29source "drivers/staging/ipx/Kconfig"
30
31source "drivers/staging/ncpfs/Kconfig"
32
29source "drivers/staging/wlan-ng/Kconfig" 33source "drivers/staging/wlan-ng/Kconfig"
30 34
31source "drivers/staging/comedi/Kconfig" 35source "drivers/staging/comedi/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 6e536020029a..af8cd6a3a1f6 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -3,6 +3,8 @@
3 3
4obj-y += media/ 4obj-y += media/
5obj-y += typec/ 5obj-y += typec/
6obj-$(CONFIG_IPX) += ipx/
7obj-$(CONFIG_NCP_FS) += ncpfs/
6obj-$(CONFIG_IRDA) += irda/net/ 8obj-$(CONFIG_IRDA) += irda/net/
7obj-$(CONFIG_IRDA) += irda/drivers/ 9obj-$(CONFIG_IRDA) += irda/drivers/
8obj-$(CONFIG_PRISM2_USB) += wlan-ng/ 10obj-$(CONFIG_PRISM2_USB) += wlan-ng/
diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 372ce9913e6d..bbdc53b686dd 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* mm/ashmem.c 2/* mm/ashmem.c
2 * 3 *
3 * Anonymous Shared Memory Subsystem, ashmem 4 * Anonymous Shared Memory Subsystem, ashmem
@@ -5,15 +6,6 @@
5 * Copyright (C) 2008 Google, Inc. 6 * Copyright (C) 2008 Google, Inc.
6 * 7 *
7 * Robert Love <rlove@google.com> 8 * Robert Love <rlove@google.com>
8 *
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 9 */
18 10
19#define pr_fmt(fmt) "ashmem: " fmt 11#define pr_fmt(fmt) "ashmem: " fmt
@@ -818,7 +810,23 @@ static long compat_ashmem_ioctl(struct file *file, unsigned int cmd,
818 return ashmem_ioctl(file, cmd, arg); 810 return ashmem_ioctl(file, cmd, arg);
819} 811}
820#endif 812#endif
813#ifdef CONFIG_PROC_FS
814static void ashmem_show_fdinfo(struct seq_file *m, struct file *file)
815{
816 struct ashmem_area *asma = file->private_data;
817
818 mutex_lock(&ashmem_mutex);
819
820 if (asma->file)
821 seq_printf(m, "inode:\t%ld\n", file_inode(asma->file)->i_ino);
822
823 if (asma->name[ASHMEM_NAME_PREFIX_LEN] != '\0')
824 seq_printf(m, "name:\t%s\n",
825 asma->name + ASHMEM_NAME_PREFIX_LEN);
821 826
827 mutex_unlock(&ashmem_mutex);
828}
829#endif
822static const struct file_operations ashmem_fops = { 830static const struct file_operations ashmem_fops = {
823 .owner = THIS_MODULE, 831 .owner = THIS_MODULE,
824 .open = ashmem_open, 832 .open = ashmem_open,
@@ -830,6 +838,9 @@ static const struct file_operations ashmem_fops = {
830#ifdef CONFIG_COMPAT 838#ifdef CONFIG_COMPAT
831 .compat_ioctl = compat_ashmem_ioctl, 839 .compat_ioctl = compat_ashmem_ioctl,
832#endif 840#endif
841#ifdef CONFIG_PROC_FS
842 .show_fdinfo = ashmem_show_fdinfo,
843#endif
833}; 844};
834 845
835static struct miscdevice ashmem_misc = { 846static struct miscdevice ashmem_misc = {
@@ -864,12 +875,18 @@ static int __init ashmem_init(void)
864 goto out_free2; 875 goto out_free2;
865 } 876 }
866 877
867 register_shrinker(&ashmem_shrinker); 878 ret = register_shrinker(&ashmem_shrinker);
879 if (ret) {
880 pr_err("failed to register shrinker!\n");
881 goto out_demisc;
882 }
868 883
869 pr_info("initialized\n"); 884 pr_info("initialized\n");
870 885
871 return 0; 886 return 0;
872 887
888out_demisc:
889 misc_deregister(&ashmem_misc);
873out_free2: 890out_free2:
874 kmem_cache_destroy(ashmem_range_cachep); 891 kmem_cache_destroy(ashmem_range_cachep);
875out_free1: 892out_free1:
diff --git a/drivers/staging/android/ashmem.h b/drivers/staging/android/ashmem.h
index 5abcfd7aa706..60d7208f110a 100644
--- a/drivers/staging/android/ashmem.h
+++ b/drivers/staging/android/ashmem.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR Apache-2.0)
1/* 2/*
2 * include/linux/ashmem.h 3 * include/linux/ashmem.h
3 * 4 *
diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c
index c78989351f9c..a8d3cc412fb9 100644
--- a/drivers/staging/android/ion/ion-ioctl.c
+++ b/drivers/staging/android/ion/ion-ioctl.c
@@ -1,16 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 *
3 * Copyright (C) 2011 Google, Inc. 3 * Copyright (C) 2011 Google, Inc.
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */ 4 */
15 5
16#include <linux/kernel.h> 6#include <linux/kernel.h>
@@ -70,8 +60,10 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
70 return -EFAULT; 60 return -EFAULT;
71 61
72 ret = validate_ioctl_arg(cmd, &data); 62 ret = validate_ioctl_arg(cmd, &data);
73 if (WARN_ON_ONCE(ret)) 63 if (ret) {
64 pr_warn_once("%s: ioctl validate failed\n", __func__);
74 return ret; 65 return ret;
66 }
75 67
76 if (!(dir & _IOC_WRITE)) 68 if (!(dir & _IOC_WRITE))
77 memset(&data, 0, sizeof(data)); 69 memset(&data, 0, sizeof(data));
diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index f480885e346b..57e0d8035b2e 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -1,42 +1,32 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 *
3 * drivers/staging/android/ion/ion.c 3 * drivers/staging/android/ion/ion.c
4 * 4 *
5 * Copyright (C) 2011 Google, Inc. 5 * Copyright (C) 2011 Google, Inc.
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */ 6 */
17 7
8#include <linux/anon_inodes.h>
9#include <linux/debugfs.h>
18#include <linux/device.h> 10#include <linux/device.h>
11#include <linux/dma-buf.h>
19#include <linux/err.h> 12#include <linux/err.h>
13#include <linux/export.h>
20#include <linux/file.h> 14#include <linux/file.h>
21#include <linux/freezer.h> 15#include <linux/freezer.h>
22#include <linux/fs.h> 16#include <linux/fs.h>
23#include <linux/anon_inodes.h> 17#include <linux/idr.h>
24#include <linux/kthread.h> 18#include <linux/kthread.h>
25#include <linux/list.h> 19#include <linux/list.h>
26#include <linux/memblock.h> 20#include <linux/memblock.h>
27#include <linux/miscdevice.h> 21#include <linux/miscdevice.h>
28#include <linux/export.h>
29#include <linux/mm.h> 22#include <linux/mm.h>
30#include <linux/mm_types.h> 23#include <linux/mm_types.h>
31#include <linux/rbtree.h> 24#include <linux/rbtree.h>
32#include <linux/slab.h> 25#include <linux/sched/task.h>
33#include <linux/seq_file.h> 26#include <linux/seq_file.h>
27#include <linux/slab.h>
34#include <linux/uaccess.h> 28#include <linux/uaccess.h>
35#include <linux/vmalloc.h> 29#include <linux/vmalloc.h>
36#include <linux/debugfs.h>
37#include <linux/dma-buf.h>
38#include <linux/idr.h>
39#include <linux/sched/task.h>
40 30
41#include "ion.h" 31#include "ion.h"
42 32
@@ -539,6 +529,7 @@ void ion_device_add_heap(struct ion_heap *heap)
539{ 529{
540 struct dentry *debug_file; 530 struct dentry *debug_file;
541 struct ion_device *dev = internal_dev; 531 struct ion_device *dev = internal_dev;
532 int ret;
542 533
543 if (!heap->ops->allocate || !heap->ops->free) 534 if (!heap->ops->allocate || !heap->ops->free)
544 pr_err("%s: can not add heap with invalid ops struct.\n", 535 pr_err("%s: can not add heap with invalid ops struct.\n",
@@ -550,8 +541,11 @@ void ion_device_add_heap(struct ion_heap *heap)
550 if (heap->flags & ION_HEAP_FLAG_DEFER_FREE) 541 if (heap->flags & ION_HEAP_FLAG_DEFER_FREE)
551 ion_heap_init_deferred_free(heap); 542 ion_heap_init_deferred_free(heap);
552 543
553 if ((heap->flags & ION_HEAP_FLAG_DEFER_FREE) || heap->ops->shrink) 544 if ((heap->flags & ION_HEAP_FLAG_DEFER_FREE) || heap->ops->shrink) {
554 ion_heap_init_shrinker(heap); 545 ret = ion_heap_init_shrinker(heap);
546 if (ret)
547 pr_err("%s: Failed to register shrinker\n", __func__);
548 }
555 549
556 heap->dev = dev; 550 heap->dev = dev;
557 down_write(&dev->lock); 551 down_write(&dev->lock);
@@ -567,9 +561,9 @@ void ion_device_add_heap(struct ion_heap *heap)
567 char debug_name[64]; 561 char debug_name[64];
568 562
569 snprintf(debug_name, 64, "%s_shrink", heap->name); 563 snprintf(debug_name, 64, "%s_shrink", heap->name);
570 debug_file = debugfs_create_file( 564 debug_file = debugfs_create_file(debug_name,
571 debug_name, 0644, dev->debug_root, heap, 565 0644, dev->debug_root, heap,
572 &debug_shrink_fops); 566 &debug_shrink_fops);
573 if (!debug_file) { 567 if (!debug_file) {
574 char buf[256], *path; 568 char buf[256], *path;
575 569
diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h
index f5f9cd63f8e9..a238f23c9116 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * drivers/staging/android/ion/ion.h 3 * drivers/staging/android/ion/ion.h
3 * 4 *
4 * Copyright (C) 2011 Google, Inc. 5 * Copyright (C) 2011 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 */ 6 */
16 7
17#ifndef _ION_H 8#ifndef _ION_H
@@ -189,7 +180,8 @@ struct ion_heap {
189 wait_queue_head_t waitqueue; 180 wait_queue_head_t waitqueue;
190 struct task_struct *task; 181 struct task_struct *task;
191 182
192 int (*debug_show)(struct ion_heap *heap, struct seq_file *, void *); 183 int (*debug_show)(struct ion_heap *heap, struct seq_file *s,
184 void *unused);
193}; 185};
194 186
195/** 187/**
@@ -238,7 +230,7 @@ int ion_alloc(size_t len,
238 * this function will be called to setup a shrinker to shrink the freelists 230 * this function will be called to setup a shrinker to shrink the freelists
239 * and call the heap's shrink op. 231 * and call the heap's shrink op.
240 */ 232 */
241void ion_heap_init_shrinker(struct ion_heap *heap); 233int ion_heap_init_shrinker(struct ion_heap *heap);
242 234
243/** 235/**
244 * ion_heap_init_deferred_free -- initialize deferred free functionality 236 * ion_heap_init_deferred_free -- initialize deferred free functionality
diff --git a/drivers/staging/android/ion/ion_carveout_heap.c b/drivers/staging/android/ion/ion_carveout_heap.c
index fee7650d6fbb..e129237a0417 100644
--- a/drivers/staging/android/ion/ion_carveout_heap.c
+++ b/drivers/staging/android/ion/ion_carveout_heap.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * drivers/staging/android/ion/ion_carveout_heap.c 3 * drivers/staging/android/ion/ion_carveout_heap.c
3 * 4 *
4 * Copyright (C) 2011 Google, Inc. 5 * Copyright (C) 2011 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 */ 6 */
16#include <linux/spinlock.h> 7#include <linux/spinlock.h>
17#include <linux/dma-mapping.h> 8#include <linux/dma-mapping.h>
diff --git a/drivers/staging/android/ion/ion_chunk_heap.c b/drivers/staging/android/ion/ion_chunk_heap.c
index 102c09398317..159d72f5bc42 100644
--- a/drivers/staging/android/ion/ion_chunk_heap.c
+++ b/drivers/staging/android/ion/ion_chunk_heap.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * drivers/staging/android/ion/ion_chunk_heap.c 3 * drivers/staging/android/ion/ion_chunk_heap.c
3 * 4 *
4 * Copyright (C) 2012 Google, Inc. 5 * 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 */ 6 */
16#include <linux/dma-mapping.h> 7#include <linux/dma-mapping.h>
17#include <linux/err.h> 8#include <linux/err.h>
diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
index 86196ffd2faf..94e06925c712 100644
--- a/drivers/staging/android/ion/ion_cma_heap.c
+++ b/drivers/staging/android/ion/ion_cma_heap.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * drivers/staging/android/ion/ion_cma_heap.c 3 * drivers/staging/android/ion/ion_cma_heap.c
3 * 4 *
4 * Copyright (C) Linaro 2012 5 * Copyright (C) Linaro 2012
5 * Author: <benjamin.gaignard@linaro.org> for ST-Ericsson. 6 * Author: <benjamin.gaignard@linaro.org> for ST-Ericsson.
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */ 7 */
17 8
18#include <linux/device.h> 9#include <linux/device.h>
diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c
index 91faa7f035b9..772dad65396e 100644
--- a/drivers/staging/android/ion/ion_heap.c
+++ b/drivers/staging/android/ion/ion_heap.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * drivers/staging/android/ion/ion_heap.c 3 * drivers/staging/android/ion/ion_heap.c
3 * 4 *
4 * Copyright (C) 2011 Google, Inc. 5 * Copyright (C) 2011 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 */ 6 */
16 7
17#include <linux/err.h> 8#include <linux/err.h>
@@ -306,11 +297,12 @@ static unsigned long ion_heap_shrink_scan(struct shrinker *shrinker,
306 return freed; 297 return freed;
307} 298}
308 299
309void ion_heap_init_shrinker(struct ion_heap *heap) 300int ion_heap_init_shrinker(struct ion_heap *heap)
310{ 301{
311 heap->shrinker.count_objects = ion_heap_shrink_count; 302 heap->shrinker.count_objects = ion_heap_shrink_count;
312 heap->shrinker.scan_objects = ion_heap_shrink_scan; 303 heap->shrinker.scan_objects = ion_heap_shrink_scan;
313 heap->shrinker.seeks = DEFAULT_SEEKS; 304 heap->shrinker.seeks = DEFAULT_SEEKS;
314 heap->shrinker.batch = 0; 305 heap->shrinker.batch = 0;
315 register_shrinker(&heap->shrinker); 306
307 return register_shrinker(&heap->shrinker);
316} 308}
diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c
index 817849df9de3..b3017f12835f 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * drivers/staging/android/ion/ion_mem_pool.c 3 * drivers/staging/android/ion/ion_mem_pool.c
3 * 4 *
4 * Copyright (C) 2011 Google, Inc. 5 * Copyright (C) 2011 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 */ 6 */
16 7
17#include <linux/debugfs.h> 8#include <linux/debugfs.h>
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index 4dc5d7a589c2..bc19cdd30637 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * drivers/staging/android/ion/ion_system_heap.c 3 * drivers/staging/android/ion/ion_system_heap.c
3 * 4 *
4 * Copyright (C) 2011 Google, Inc. 5 * Copyright (C) 2011 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 */ 6 */
16 7
17#include <asm/page.h> 8#include <asm/page.h>
@@ -371,7 +362,7 @@ static int ion_system_contig_heap_allocate(struct ion_heap *heap,
371 unsigned long i; 362 unsigned long i;
372 int ret; 363 int ret;
373 364
374 page = alloc_pages(low_order_gfp_flags, order); 365 page = alloc_pages(low_order_gfp_flags | __GFP_NOWARN, order);
375 if (!page) 366 if (!page)
376 return -ENOMEM; 367 return -ENOMEM;
377 368
diff --git a/drivers/staging/android/uapi/ashmem.h b/drivers/staging/android/uapi/ashmem.h
index 13df42d200b7..5b531af6820e 100644
--- a/drivers/staging/android/uapi/ashmem.h
+++ b/drivers/staging/android/uapi/ashmem.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR Apache-2.0)
1/* 2/*
2 * drivers/staging/android/uapi/ashmem.h 3 * drivers/staging/android/uapi/ashmem.h
3 * 4 *
diff --git a/drivers/staging/android/uapi/ion.h b/drivers/staging/android/uapi/ion.h
index 9e21451149d0..825d3e95ccd3 100644
--- a/drivers/staging/android/uapi/ion.h
+++ b/drivers/staging/android/uapi/ion.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * drivers/staging/android/uapi/ion.h 3 * drivers/staging/android/uapi/ion.h
3 * 4 *
4 * Copyright (C) 2011 Google, Inc. 5 * Copyright (C) 2011 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 */ 6 */
16 7
17#ifndef _UAPI_LINUX_ION_H 8#ifndef _UAPI_LINUX_ION_H
diff --git a/drivers/staging/ccree/Documentation/devicetree/bindings/crypto/arm-cryptocell.txt b/drivers/staging/ccree/Documentation/devicetree/bindings/crypto/arm-cryptocell.txt
deleted file mode 100644
index 2ea65175c032..000000000000
--- a/drivers/staging/ccree/Documentation/devicetree/bindings/crypto/arm-cryptocell.txt
+++ /dev/null
@@ -1,27 +0,0 @@
1Arm TrustZone CryptoCell cryptographic accelerators
2
3Required properties:
4- compatible: must be "arm,cryptocell-712-ree".
5- reg: shall contain base register location and length.
6 Typically length is 0x10000.
7- interrupts: shall contain the interrupt for the device.
8
9Optional properties:
10- interrupt-parent: can designate the interrupt controller the
11 device interrupt is connected to, if needed.
12- clocks: may contain the clock handling the device, if needed.
13- power-domains: may contain a reference to the PM domain, if applicable.
14
15
16Examples:
17
18Zynq FPGA device
19----------------
20
21 arm_cc7x: arm_cc7x@80000000 {
22 compatible = "arm,cryptocell-712-ree";
23 interrupt-parent = <&intc>;
24 interrupts = < 0 30 4 >;
25 reg = < 0x80000000 0x10000 >;
26 };
27
diff --git a/drivers/staging/ccree/Kconfig b/drivers/staging/ccree/Kconfig
index 0b3092ba2fcb..c94dfe8adb63 100644
--- a/drivers/staging/ccree/Kconfig
+++ b/drivers/staging/ccree/Kconfig
@@ -1,3 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2
1config CRYPTO_DEV_CCREE 3config CRYPTO_DEV_CCREE
2 tristate "Support for ARM TrustZone CryptoCell C7XX family of Crypto accelerators" 4 tristate "Support for ARM TrustZone CryptoCell C7XX family of Crypto accelerators"
3 depends on CRYPTO && CRYPTO_HW && OF && HAS_DMA 5 depends on CRYPTO && CRYPTO_HW && OF && HAS_DMA
diff --git a/drivers/staging/ccree/Makefile b/drivers/staging/ccree/Makefile
index ae702f3b5369..bdc27970f95f 100644
--- a/drivers/staging/ccree/Makefile
+++ b/drivers/staging/ccree/Makefile
@@ -1,3 +1,7 @@
1# SPDX-License-Identifier: GPL-2.0
2
1obj-$(CONFIG_CRYPTO_DEV_CCREE) := ccree.o 3obj-$(CONFIG_CRYPTO_DEV_CCREE) := ccree.o
2ccree-y := ssi_driver.o ssi_sysfs.o ssi_buffer_mgr.o ssi_request_mgr.o ssi_cipher.o ssi_hash.o ssi_aead.o ssi_ivgen.o ssi_sram_mgr.o ssi_pm.o 4ccree-y := cc_driver.o cc_buffer_mgr.o cc_request_mgr.o cc_cipher.o cc_hash.o cc_aead.o cc_ivgen.o cc_sram_mgr.o
3ccree-$(CONFIG_CRYPTO_FIPS) += ssi_fips.o 5ccree-$(CONFIG_CRYPTO_FIPS) += cc_fips.o
6ccree-$(CONFIG_DEBUG_FS) += cc_debugfs.o
7ccree-$(CONFIG_PM) += cc_pm.o
diff --git a/drivers/staging/ccree/TODO b/drivers/staging/ccree/TODO
index c9f5754d062d..b8e163d98f91 100644
--- a/drivers/staging/ccree/TODO
+++ b/drivers/staging/ccree/TODO
@@ -6,25 +6,5 @@
6* * 6* *
7************************************************************************* 7*************************************************************************
8 8
9ccree specific items 91. ???
10a.k.a stuff fixing for this driver to move out of staging
11~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 10
131. Move to using Crypto Engine to handle backlog queueing.
142. Remove synchronous algorithm support leftovers.
153. Separate platform specific code for FIPS and power management into separate platform modules.
164. Drop legacy kernel support code.
175. Move most (all?) #ifdef CONFIG into inline functions.
186. Remove all unused definitions.
197. Re-factor to accomediate newer/older HW revisions besides the 712.
208. Handle the many checkpatch errors.
219. Implement ahash import/export correctly.
2210. Go through a proper review of DT bindings and sysfs ABI
2311. Sort out FIPS mode: bake tests into testmgr, sort out behaviour on error,
24 figure if 3DES weak key check is needed
25
26Kernel infrastructure items
27a.k.a stuff we either neither need to fix in the kernel or understand what we're doing wrong
28~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291. ahash import/export context has a PAGE_SIZE/8 size limit. We need more.
302. Crypto Engine seems to be built for HW with hardware queue depth of 1, we have 600++.
diff --git a/drivers/staging/ccree/ssi_aead.c b/drivers/staging/ccree/cc_aead.c
index ba0954e4d2e5..b58413172231 100644
--- a/drivers/staging/ccree/ssi_aead.c
+++ b/drivers/staging/ccree/cc_aead.c
@@ -1,41 +1,19 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17#include <linux/kernel.h> 4#include <linux/kernel.h>
18#include <linux/module.h> 5#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <crypto/algapi.h> 6#include <crypto/algapi.h>
21#include <crypto/internal/skcipher.h>
22#include <crypto/internal/hash.h>
23#include <crypto/internal/aead.h> 7#include <crypto/internal/aead.h>
24#include <crypto/sha.h>
25#include <crypto/ctr.h>
26#include <crypto/authenc.h> 8#include <crypto/authenc.h>
27#include <crypto/aes.h>
28#include <crypto/des.h> 9#include <crypto/des.h>
29#include <linux/rtnetlink.h> 10#include <linux/rtnetlink.h>
30#include <linux/version.h> 11#include "cc_driver.h"
31#include "ssi_config.h" 12#include "cc_buffer_mgr.h"
32#include "ssi_driver.h" 13#include "cc_aead.h"
33#include "ssi_buffer_mgr.h" 14#include "cc_request_mgr.h"
34#include "ssi_aead.h" 15#include "cc_hash.h"
35#include "ssi_request_mgr.h" 16#include "cc_sram_mgr.h"
36#include "ssi_hash.h"
37#include "ssi_sysfs.h"
38#include "ssi_sram_mgr.h"
39 17
40#define template_aead template_u.aead 18#define template_aead template_u.aead
41 19
@@ -51,8 +29,8 @@
51/* Value of each ICV_CMP byte (of 8) in case of success */ 29/* Value of each ICV_CMP byte (of 8) in case of success */
52#define ICV_VERIF_OK 0x01 30#define ICV_VERIF_OK 0x01
53 31
54struct ssi_aead_handle { 32struct cc_aead_handle {
55 ssi_sram_addr_t sram_workspace_addr; 33 cc_sram_addr_t sram_workspace_addr;
56 struct list_head aead_list; 34 struct list_head aead_list;
57}; 35};
58 36
@@ -68,8 +46,8 @@ struct cc_xcbc_s {
68 dma_addr_t xcbc_keys_dma_addr; 46 dma_addr_t xcbc_keys_dma_addr;
69}; 47};
70 48
71struct ssi_aead_ctx { 49struct cc_aead_ctx {
72 struct ssi_drvdata *drvdata; 50 struct cc_drvdata *drvdata;
73 u8 ctr_nonce[MAX_NONCE_SIZE]; /* used for ctr3686 iv and aes ccm */ 51 u8 ctr_nonce[MAX_NONCE_SIZE]; /* used for ctr3686 iv and aes ccm */
74 u8 *enckey; 52 u8 *enckey;
75 dma_addr_t enckey_dma_addr; 53 dma_addr_t enckey_dma_addr;
@@ -90,9 +68,9 @@ static inline bool valid_assoclen(struct aead_request *req)
90 return ((req->assoclen == 16) || (req->assoclen == 20)); 68 return ((req->assoclen == 16) || (req->assoclen == 20));
91} 69}
92 70
93static void ssi_aead_exit(struct crypto_aead *tfm) 71static void cc_aead_exit(struct crypto_aead *tfm)
94{ 72{
95 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 73 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
96 struct device *dev = drvdata_to_dev(ctx->drvdata); 74 struct device *dev = drvdata_to_dev(ctx->drvdata);
97 75
98 dev_dbg(dev, "Clearing context @%p for %s\n", crypto_aead_ctx(tfm), 76 dev_dbg(dev, "Clearing context @%p for %s\n", crypto_aead_ctx(tfm),
@@ -100,7 +78,8 @@ static void ssi_aead_exit(struct crypto_aead *tfm)
100 78
101 /* Unmap enckey buffer */ 79 /* Unmap enckey buffer */
102 if (ctx->enckey) { 80 if (ctx->enckey) {
103 dma_free_coherent(dev, AES_MAX_KEY_SIZE, ctx->enckey, ctx->enckey_dma_addr); 81 dma_free_coherent(dev, AES_MAX_KEY_SIZE, ctx->enckey,
82 ctx->enckey_dma_addr);
104 dev_dbg(dev, "Freed enckey DMA buffer enckey_dma_addr=%pad\n", 83 dev_dbg(dev, "Freed enckey DMA buffer enckey_dma_addr=%pad\n",
105 &ctx->enckey_dma_addr); 84 &ctx->enckey_dma_addr);
106 ctx->enckey_dma_addr = 0; 85 ctx->enckey_dma_addr = 0;
@@ -143,22 +122,22 @@ static void ssi_aead_exit(struct crypto_aead *tfm)
143 } 122 }
144} 123}
145 124
146static int ssi_aead_init(struct crypto_aead *tfm) 125static int cc_aead_init(struct crypto_aead *tfm)
147{ 126{
148 struct aead_alg *alg = crypto_aead_alg(tfm); 127 struct aead_alg *alg = crypto_aead_alg(tfm);
149 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 128 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
150 struct ssi_crypto_alg *ssi_alg = 129 struct cc_crypto_alg *cc_alg =
151 container_of(alg, struct ssi_crypto_alg, aead_alg); 130 container_of(alg, struct cc_crypto_alg, aead_alg);
152 struct device *dev = drvdata_to_dev(ssi_alg->drvdata); 131 struct device *dev = drvdata_to_dev(cc_alg->drvdata);
153 132
154 dev_dbg(dev, "Initializing context @%p for %s\n", ctx, 133 dev_dbg(dev, "Initializing context @%p for %s\n", ctx,
155 crypto_tfm_alg_name(&tfm->base)); 134 crypto_tfm_alg_name(&tfm->base));
156 135
157 /* Initialize modes in instance */ 136 /* Initialize modes in instance */
158 ctx->cipher_mode = ssi_alg->cipher_mode; 137 ctx->cipher_mode = cc_alg->cipher_mode;
159 ctx->flow_mode = ssi_alg->flow_mode; 138 ctx->flow_mode = cc_alg->flow_mode;
160 ctx->auth_mode = ssi_alg->auth_mode; 139 ctx->auth_mode = cc_alg->auth_mode;
161 ctx->drvdata = ssi_alg->drvdata; 140 ctx->drvdata = cc_alg->drvdata;
162 crypto_aead_set_reqsize(tfm, sizeof(struct aead_req_ctx)); 141 crypto_aead_set_reqsize(tfm, sizeof(struct aead_req_ctx));
163 142
164 /* Allocate key buffer, cache line aligned */ 143 /* Allocate key buffer, cache line aligned */
@@ -221,23 +200,25 @@ static int ssi_aead_init(struct crypto_aead *tfm)
221 return 0; 200 return 0;
222 201
223init_failed: 202init_failed:
224 ssi_aead_exit(tfm); 203 cc_aead_exit(tfm);
225 return -ENOMEM; 204 return -ENOMEM;
226} 205}
227 206
228static void ssi_aead_complete(struct device *dev, void *ssi_req, void __iomem *cc_base) 207static void cc_aead_complete(struct device *dev, void *cc_req, int err)
229{ 208{
230 struct aead_request *areq = (struct aead_request *)ssi_req; 209 struct aead_request *areq = (struct aead_request *)cc_req;
231 struct aead_req_ctx *areq_ctx = aead_request_ctx(areq); 210 struct aead_req_ctx *areq_ctx = aead_request_ctx(areq);
232 struct crypto_aead *tfm = crypto_aead_reqtfm(ssi_req); 211 struct crypto_aead *tfm = crypto_aead_reqtfm(cc_req);
233 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 212 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
234 int err = 0;
235 213
236 ssi_buffer_mgr_unmap_aead_request(dev, areq); 214 cc_unmap_aead_request(dev, areq);
237 215
238 /* Restore ordinary iv pointer */ 216 /* Restore ordinary iv pointer */
239 areq->iv = areq_ctx->backup_iv; 217 areq->iv = areq_ctx->backup_iv;
240 218
219 if (err)
220 goto done;
221
241 if (areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT) { 222 if (areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT) {
242 if (memcmp(areq_ctx->mac_buf, areq_ctx->icv_virt_addr, 223 if (memcmp(areq_ctx->mac_buf, areq_ctx->icv_virt_addr,
243 ctx->authsize) != 0) { 224 ctx->authsize) != 0) {
@@ -246,36 +227,43 @@ static void ssi_aead_complete(struct device *dev, void *ssi_req, void __iomem *c
246 /* In case of payload authentication failure, MUST NOT 227 /* In case of payload authentication failure, MUST NOT
247 * revealed the decrypted message --> zero its memory. 228 * revealed the decrypted message --> zero its memory.
248 */ 229 */
249 ssi_buffer_mgr_zero_sgl(areq->dst, areq_ctx->cryptlen); 230 cc_zero_sgl(areq->dst, areq_ctx->cryptlen);
250 err = -EBADMSG; 231 err = -EBADMSG;
251 } 232 }
252 } else { /*ENCRYPT*/ 233 } else { /*ENCRYPT*/
253 if (unlikely(areq_ctx->is_icv_fragmented)) 234 if (areq_ctx->is_icv_fragmented) {
254 ssi_buffer_mgr_copy_scatterlist_portion( 235 u32 skip = areq->cryptlen + areq_ctx->dst_offset;
255 dev, areq_ctx->mac_buf, areq_ctx->dst_sgl, 236
256 areq->cryptlen + areq_ctx->dst_offset, 237 cc_copy_sg_portion(dev, areq_ctx->mac_buf,
257 (areq->cryptlen + areq_ctx->dst_offset + 238 areq_ctx->dst_sgl, skip,
258 ctx->authsize), 239 (skip + ctx->authsize),
259 SSI_SG_FROM_BUF); 240 CC_SG_FROM_BUF);
260 241 }
261 /* If an IV was generated, copy it back to the user provided buffer. */ 242
243 /* If an IV was generated, copy it back to the user provided
244 * buffer.
245 */
262 if (areq_ctx->backup_giv) { 246 if (areq_ctx->backup_giv) {
263 if (ctx->cipher_mode == DRV_CIPHER_CTR) 247 if (ctx->cipher_mode == DRV_CIPHER_CTR)
264 memcpy(areq_ctx->backup_giv, areq_ctx->ctr_iv + CTR_RFC3686_NONCE_SIZE, CTR_RFC3686_IV_SIZE); 248 memcpy(areq_ctx->backup_giv, areq_ctx->ctr_iv +
249 CTR_RFC3686_NONCE_SIZE,
250 CTR_RFC3686_IV_SIZE);
265 else if (ctx->cipher_mode == DRV_CIPHER_CCM) 251 else if (ctx->cipher_mode == DRV_CIPHER_CCM)
266 memcpy(areq_ctx->backup_giv, areq_ctx->ctr_iv + CCM_BLOCK_IV_OFFSET, CCM_BLOCK_IV_SIZE); 252 memcpy(areq_ctx->backup_giv, areq_ctx->ctr_iv +
253 CCM_BLOCK_IV_OFFSET, CCM_BLOCK_IV_SIZE);
267 } 254 }
268 } 255 }
269 256done:
270 aead_request_complete(areq, err); 257 aead_request_complete(areq, err);
271} 258}
272 259
273static int xcbc_setkey(struct cc_hw_desc *desc, struct ssi_aead_ctx *ctx) 260static int xcbc_setkey(struct cc_hw_desc *desc, struct cc_aead_ctx *ctx)
274{ 261{
275 /* Load the AES key */ 262 /* Load the AES key */
276 hw_desc_init(&desc[0]); 263 hw_desc_init(&desc[0]);
277 /* We are using for the source/user key the same buffer as for the output keys, 264 /* We are using for the source/user key the same buffer
278 * because after this key loading it is not needed anymore 265 * as for the output keys, * because after this key loading it
266 * is not needed anymore
279 */ 267 */
280 set_din_type(&desc[0], DMA_DLLI, 268 set_din_type(&desc[0], DMA_DLLI,
281 ctx->auth_state.xcbc.xcbc_keys_dma_addr, ctx->auth_keylen, 269 ctx->auth_state.xcbc.xcbc_keys_dma_addr, ctx->auth_keylen,
@@ -309,7 +297,7 @@ static int xcbc_setkey(struct cc_hw_desc *desc, struct ssi_aead_ctx *ctx)
309 return 4; 297 return 4;
310} 298}
311 299
312static int hmac_setkey(struct cc_hw_desc *desc, struct ssi_aead_ctx *ctx) 300static int hmac_setkey(struct cc_hw_desc *desc, struct cc_aead_ctx *ctx)
313{ 301{
314 unsigned int hmac_pad_const[2] = { HMAC_IPAD_CONST, HMAC_OPAD_CONST }; 302 unsigned int hmac_pad_const[2] = { HMAC_IPAD_CONST, HMAC_OPAD_CONST };
315 unsigned int digest_ofs = 0; 303 unsigned int digest_ofs = 0;
@@ -328,8 +316,8 @@ static int hmac_setkey(struct cc_hw_desc *desc, struct ssi_aead_ctx *ctx)
328 hw_desc_init(&desc[idx]); 316 hw_desc_init(&desc[idx]);
329 set_cipher_mode(&desc[idx], hash_mode); 317 set_cipher_mode(&desc[idx], hash_mode);
330 set_din_sram(&desc[idx], 318 set_din_sram(&desc[idx],
331 ssi_ahash_get_larval_digest_sram_addr( 319 cc_larval_digest_addr(ctx->drvdata,
332 ctx->drvdata, ctx->auth_mode), 320 ctx->auth_mode),
333 digest_size); 321 digest_size);
334 set_flow_mode(&desc[idx], S_DIN_to_HASH); 322 set_flow_mode(&desc[idx], S_DIN_to_HASH);
335 set_setup_mode(&desc[idx], SETUP_LOAD_STATE0); 323 set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
@@ -378,7 +366,7 @@ static int hmac_setkey(struct cc_hw_desc *desc, struct ssi_aead_ctx *ctx)
378 return idx; 366 return idx;
379} 367}
380 368
381static int validate_keys_sizes(struct ssi_aead_ctx *ctx) 369static int validate_keys_sizes(struct cc_aead_ctx *ctx)
382{ 370{
383 struct device *dev = drvdata_to_dev(ctx->drvdata); 371 struct device *dev = drvdata_to_dev(ctx->drvdata);
384 372
@@ -390,9 +378,9 @@ static int validate_keys_sizes(struct ssi_aead_ctx *ctx)
390 case DRV_HASH_SHA256: 378 case DRV_HASH_SHA256:
391 break; 379 break;
392 case DRV_HASH_XCBC_MAC: 380 case DRV_HASH_XCBC_MAC:
393 if ((ctx->auth_keylen != AES_KEYSIZE_128) && 381 if (ctx->auth_keylen != AES_KEYSIZE_128 &&
394 (ctx->auth_keylen != AES_KEYSIZE_192) && 382 ctx->auth_keylen != AES_KEYSIZE_192 &&
395 (ctx->auth_keylen != AES_KEYSIZE_256)) 383 ctx->auth_keylen != AES_KEYSIZE_256)
396 return -ENOTSUPP; 384 return -ENOTSUPP;
397 break; 385 break;
398 case DRV_HASH_NULL: /* Not authenc (e.g., CCM) - no auth_key) */ 386 case DRV_HASH_NULL: /* Not authenc (e.g., CCM) - no auth_key) */
@@ -404,16 +392,16 @@ static int validate_keys_sizes(struct ssi_aead_ctx *ctx)
404 return -EINVAL; 392 return -EINVAL;
405 } 393 }
406 /* Check cipher key size */ 394 /* Check cipher key size */
407 if (unlikely(ctx->flow_mode == S_DIN_to_DES)) { 395 if (ctx->flow_mode == S_DIN_to_DES) {
408 if (ctx->enc_keylen != DES3_EDE_KEY_SIZE) { 396 if (ctx->enc_keylen != DES3_EDE_KEY_SIZE) {
409 dev_err(dev, "Invalid cipher(3DES) key size: %u\n", 397 dev_err(dev, "Invalid cipher(3DES) key size: %u\n",
410 ctx->enc_keylen); 398 ctx->enc_keylen);
411 return -EINVAL; 399 return -EINVAL;
412 } 400 }
413 } else { /* Default assumed to be AES ciphers */ 401 } else { /* Default assumed to be AES ciphers */
414 if ((ctx->enc_keylen != AES_KEYSIZE_128) && 402 if (ctx->enc_keylen != AES_KEYSIZE_128 &&
415 (ctx->enc_keylen != AES_KEYSIZE_192) && 403 ctx->enc_keylen != AES_KEYSIZE_192 &&
416 (ctx->enc_keylen != AES_KEYSIZE_256)) { 404 ctx->enc_keylen != AES_KEYSIZE_256) {
417 dev_err(dev, "Invalid cipher(AES) key size: %u\n", 405 dev_err(dev, "Invalid cipher(AES) key size: %u\n",
418 ctx->enc_keylen); 406 ctx->enc_keylen);
419 return -EINVAL; 407 return -EINVAL;
@@ -427,14 +415,14 @@ static int validate_keys_sizes(struct ssi_aead_ctx *ctx)
427 * (copy to intenral buffer or hash in case of key longer than block 415 * (copy to intenral buffer or hash in case of key longer than block
428 */ 416 */
429static int 417static int
430ssi_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) 418cc_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *key,
419 unsigned int keylen)
431{ 420{
432 dma_addr_t key_dma_addr = 0; 421 dma_addr_t key_dma_addr = 0;
433 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 422 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
434 struct device *dev = drvdata_to_dev(ctx->drvdata); 423 struct device *dev = drvdata_to_dev(ctx->drvdata);
435 u32 larval_addr = ssi_ahash_get_larval_digest_sram_addr( 424 u32 larval_addr = cc_larval_digest_addr(ctx->drvdata, ctx->auth_mode);
436 ctx->drvdata, ctx->auth_mode); 425 struct cc_crypto_req cc_req = {};
437 struct ssi_crypto_req ssi_req = {};
438 unsigned int blocksize; 426 unsigned int blocksize;
439 unsigned int digestsize; 427 unsigned int digestsize;
440 unsigned int hashmode; 428 unsigned int hashmode;
@@ -457,9 +445,10 @@ ssi_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *key, unsigned int keyl
457 hashmode = DRV_HASH_HW_SHA256; 445 hashmode = DRV_HASH_HW_SHA256;
458 } 446 }
459 447
460 if (likely(keylen != 0)) { 448 if (keylen != 0) {
461 key_dma_addr = dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE); 449 key_dma_addr = dma_map_single(dev, (void *)key, keylen,
462 if (unlikely(dma_mapping_error(dev, key_dma_addr))) { 450 DMA_TO_DEVICE);
451 if (dma_mapping_error(dev, key_dma_addr)) {
463 dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n", 452 dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n",
464 key, keylen); 453 key, keylen);
465 return -ENOMEM; 454 return -ENOMEM;
@@ -537,22 +526,22 @@ ssi_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *key, unsigned int keyl
537 idx++; 526 idx++;
538 } 527 }
539 528
540 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0); 529 rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, idx);
541 if (unlikely(rc != 0)) 530 if (rc)
542 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 531 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
543 532
544 if (likely(key_dma_addr != 0)) 533 if (key_dma_addr)
545 dma_unmap_single(dev, key_dma_addr, keylen, DMA_TO_DEVICE); 534 dma_unmap_single(dev, key_dma_addr, keylen, DMA_TO_DEVICE);
546 535
547 return rc; 536 return rc;
548} 537}
549 538
550static int 539static int
551ssi_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) 540cc_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
552{ 541{
553 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 542 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
554 struct rtattr *rta = (struct rtattr *)key; 543 struct rtattr *rta = (struct rtattr *)key;
555 struct ssi_crypto_req ssi_req = {}; 544 struct cc_crypto_req cc_req = {};
556 struct crypto_authenc_key_param *param; 545 struct crypto_authenc_key_param *param;
557 struct cc_hw_desc desc[MAX_AEAD_SETKEY_SEQ]; 546 struct cc_hw_desc desc[MAX_AEAD_SETKEY_SEQ];
558 int seq_len = 0, rc = -EINVAL; 547 int seq_len = 0, rc = -EINVAL;
@@ -586,8 +575,9 @@ ssi_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
586 /* Copy nonce from last 4 bytes in CTR key to 575 /* Copy nonce from last 4 bytes in CTR key to
587 * first 4 bytes in CTR IV 576 * first 4 bytes in CTR IV
588 */ 577 */
589 memcpy(ctx->ctr_nonce, key + ctx->auth_keylen + ctx->enc_keylen - 578 memcpy(ctx->ctr_nonce, key + ctx->auth_keylen +
590 CTR_RFC3686_NONCE_SIZE, CTR_RFC3686_NONCE_SIZE); 579 ctx->enc_keylen - CTR_RFC3686_NONCE_SIZE,
580 CTR_RFC3686_NONCE_SIZE);
591 /* Set CTR key size */ 581 /* Set CTR key size */
592 ctx->enc_keylen -= CTR_RFC3686_NONCE_SIZE; 582 ctx->enc_keylen -= CTR_RFC3686_NONCE_SIZE;
593 } 583 }
@@ -597,7 +587,7 @@ ssi_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
597 } 587 }
598 588
599 rc = validate_keys_sizes(ctx); 589 rc = validate_keys_sizes(ctx);
600 if (unlikely(rc != 0)) 590 if (rc)
601 goto badkey; 591 goto badkey;
602 592
603 /* STAT_PHASE_1: Copy key to ctx */ 593 /* STAT_PHASE_1: Copy key to ctx */
@@ -609,8 +599,8 @@ ssi_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
609 if (ctx->auth_mode == DRV_HASH_XCBC_MAC) { 599 if (ctx->auth_mode == DRV_HASH_XCBC_MAC) {
610 memcpy(ctx->auth_state.xcbc.xcbc_keys, key, ctx->auth_keylen); 600 memcpy(ctx->auth_state.xcbc.xcbc_keys, key, ctx->auth_keylen);
611 } else if (ctx->auth_mode != DRV_HASH_NULL) { /* HMAC */ 601 } else if (ctx->auth_mode != DRV_HASH_NULL) { /* HMAC */
612 rc = ssi_get_plain_hmac_key(tfm, key, ctx->auth_keylen); 602 rc = cc_get_plain_hmac_key(tfm, key, ctx->auth_keylen);
613 if (rc != 0) 603 if (rc)
614 goto badkey; 604 goto badkey;
615 } 605 }
616 606
@@ -635,8 +625,8 @@ ssi_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
635 /* STAT_PHASE_3: Submit sequence to HW */ 625 /* STAT_PHASE_3: Submit sequence to HW */
636 626
637 if (seq_len > 0) { /* For CCM there is no sequence to setup the key */ 627 if (seq_len > 0) { /* For CCM there is no sequence to setup the key */
638 rc = send_request(ctx->drvdata, &ssi_req, desc, seq_len, 0); 628 rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, seq_len);
639 if (unlikely(rc != 0)) { 629 if (rc) {
640 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 630 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
641 goto setkey_error; 631 goto setkey_error;
642 } 632 }
@@ -652,10 +642,10 @@ setkey_error:
652 return rc; 642 return rc;
653} 643}
654 644
655#if SSI_CC_HAS_AES_CCM 645static int cc_rfc4309_ccm_setkey(struct crypto_aead *tfm, const u8 *key,
656static int ssi_rfc4309_ccm_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) 646 unsigned int keylen)
657{ 647{
658 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 648 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
659 649
660 if (keylen < 3) 650 if (keylen < 3)
661 return -EINVAL; 651 return -EINVAL;
@@ -663,20 +653,18 @@ static int ssi_rfc4309_ccm_setkey(struct crypto_aead *tfm, const u8 *key, unsign
663 keylen -= 3; 653 keylen -= 3;
664 memcpy(ctx->ctr_nonce, key + keylen, 3); 654 memcpy(ctx->ctr_nonce, key + keylen, 3);
665 655
666 return ssi_aead_setkey(tfm, key, keylen); 656 return cc_aead_setkey(tfm, key, keylen);
667} 657}
668#endif /*SSI_CC_HAS_AES_CCM*/
669 658
670static int ssi_aead_setauthsize( 659static int cc_aead_setauthsize(struct crypto_aead *authenc,
671 struct crypto_aead *authenc, 660 unsigned int authsize)
672 unsigned int authsize)
673{ 661{
674 struct ssi_aead_ctx *ctx = crypto_aead_ctx(authenc); 662 struct cc_aead_ctx *ctx = crypto_aead_ctx(authenc);
675 struct device *dev = drvdata_to_dev(ctx->drvdata); 663 struct device *dev = drvdata_to_dev(ctx->drvdata);
676 664
677 /* Unsupported auth. sizes */ 665 /* Unsupported auth. sizes */
678 if ((authsize == 0) || 666 if (authsize == 0 ||
679 (authsize > crypto_aead_maxauthsize(authenc))) { 667 authsize > crypto_aead_maxauthsize(authenc)) {
680 return -ENOTSUPP; 668 return -ENOTSUPP;
681 } 669 }
682 670
@@ -686,9 +674,8 @@ static int ssi_aead_setauthsize(
686 return 0; 674 return 0;
687} 675}
688 676
689#if SSI_CC_HAS_AES_CCM 677static int cc_rfc4309_ccm_setauthsize(struct crypto_aead *authenc,
690static int ssi_rfc4309_ccm_setauthsize(struct crypto_aead *authenc, 678 unsigned int authsize)
691 unsigned int authsize)
692{ 679{
693 switch (authsize) { 680 switch (authsize) {
694 case 8: 681 case 8:
@@ -699,11 +686,11 @@ static int ssi_rfc4309_ccm_setauthsize(struct crypto_aead *authenc,
699 return -EINVAL; 686 return -EINVAL;
700 } 687 }
701 688
702 return ssi_aead_setauthsize(authenc, authsize); 689 return cc_aead_setauthsize(authenc, authsize);
703} 690}
704 691
705static int ssi_ccm_setauthsize(struct crypto_aead *authenc, 692static int cc_ccm_setauthsize(struct crypto_aead *authenc,
706 unsigned int authsize) 693 unsigned int authsize)
707{ 694{
708 switch (authsize) { 695 switch (authsize) {
709 case 4: 696 case 4:
@@ -718,46 +705,41 @@ static int ssi_ccm_setauthsize(struct crypto_aead *authenc,
718 return -EINVAL; 705 return -EINVAL;
719 } 706 }
720 707
721 return ssi_aead_setauthsize(authenc, authsize); 708 return cc_aead_setauthsize(authenc, authsize);
722} 709}
723#endif /*SSI_CC_HAS_AES_CCM*/ 710
724 711static void cc_set_assoc_desc(struct aead_request *areq, unsigned int flow_mode,
725static inline void 712 struct cc_hw_desc desc[], unsigned int *seq_size)
726ssi_aead_create_assoc_desc(
727 struct aead_request *areq,
728 unsigned int flow_mode,
729 struct cc_hw_desc desc[],
730 unsigned int *seq_size)
731{ 713{
732 struct crypto_aead *tfm = crypto_aead_reqtfm(areq); 714 struct crypto_aead *tfm = crypto_aead_reqtfm(areq);
733 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 715 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
734 struct aead_req_ctx *areq_ctx = aead_request_ctx(areq); 716 struct aead_req_ctx *areq_ctx = aead_request_ctx(areq);
735 enum ssi_req_dma_buf_type assoc_dma_type = areq_ctx->assoc_buff_type; 717 enum cc_req_dma_buf_type assoc_dma_type = areq_ctx->assoc_buff_type;
736 unsigned int idx = *seq_size; 718 unsigned int idx = *seq_size;
737 struct device *dev = drvdata_to_dev(ctx->drvdata); 719 struct device *dev = drvdata_to_dev(ctx->drvdata);
738 720
739 switch (assoc_dma_type) { 721 switch (assoc_dma_type) {
740 case SSI_DMA_BUF_DLLI: 722 case CC_DMA_BUF_DLLI:
741 dev_dbg(dev, "ASSOC buffer type DLLI\n"); 723 dev_dbg(dev, "ASSOC buffer type DLLI\n");
742 hw_desc_init(&desc[idx]); 724 hw_desc_init(&desc[idx]);
743 set_din_type(&desc[idx], DMA_DLLI, sg_dma_address(areq->src), 725 set_din_type(&desc[idx], DMA_DLLI, sg_dma_address(areq->src),
744 areq->assoclen, NS_BIT); set_flow_mode(&desc[idx], 726 areq->assoclen, NS_BIT);
745 flow_mode); 727 set_flow_mode(&desc[idx], flow_mode);
746 if ((ctx->auth_mode == DRV_HASH_XCBC_MAC) && 728 if (ctx->auth_mode == DRV_HASH_XCBC_MAC &&
747 (areq_ctx->cryptlen > 0)) 729 areq_ctx->cryptlen > 0)
748 set_din_not_last_indication(&desc[idx]); 730 set_din_not_last_indication(&desc[idx]);
749 break; 731 break;
750 case SSI_DMA_BUF_MLLI: 732 case CC_DMA_BUF_MLLI:
751 dev_dbg(dev, "ASSOC buffer type MLLI\n"); 733 dev_dbg(dev, "ASSOC buffer type MLLI\n");
752 hw_desc_init(&desc[idx]); 734 hw_desc_init(&desc[idx]);
753 set_din_type(&desc[idx], DMA_MLLI, areq_ctx->assoc.sram_addr, 735 set_din_type(&desc[idx], DMA_MLLI, areq_ctx->assoc.sram_addr,
754 areq_ctx->assoc.mlli_nents, NS_BIT); 736 areq_ctx->assoc.mlli_nents, NS_BIT);
755 set_flow_mode(&desc[idx], flow_mode); 737 set_flow_mode(&desc[idx], flow_mode);
756 if ((ctx->auth_mode == DRV_HASH_XCBC_MAC) && 738 if (ctx->auth_mode == DRV_HASH_XCBC_MAC &&
757 (areq_ctx->cryptlen > 0)) 739 areq_ctx->cryptlen > 0)
758 set_din_not_last_indication(&desc[idx]); 740 set_din_not_last_indication(&desc[idx]);
759 break; 741 break;
760 case SSI_DMA_BUF_NULL: 742 case CC_DMA_BUF_NULL:
761 default: 743 default:
762 dev_err(dev, "Invalid ASSOC buffer type\n"); 744 dev_err(dev, "Invalid ASSOC buffer type\n");
763 } 745 }
@@ -765,23 +747,20 @@ ssi_aead_create_assoc_desc(
765 *seq_size = (++idx); 747 *seq_size = (++idx);
766} 748}
767 749
768static inline void 750static void cc_proc_authen_desc(struct aead_request *areq,
769ssi_aead_process_authenc_data_desc( 751 unsigned int flow_mode,
770 struct aead_request *areq, 752 struct cc_hw_desc desc[],
771 unsigned int flow_mode, 753 unsigned int *seq_size, int direct)
772 struct cc_hw_desc desc[],
773 unsigned int *seq_size,
774 int direct)
775{ 754{
776 struct aead_req_ctx *areq_ctx = aead_request_ctx(areq); 755 struct aead_req_ctx *areq_ctx = aead_request_ctx(areq);
777 enum ssi_req_dma_buf_type data_dma_type = areq_ctx->data_buff_type; 756 enum cc_req_dma_buf_type data_dma_type = areq_ctx->data_buff_type;
778 unsigned int idx = *seq_size; 757 unsigned int idx = *seq_size;
779 struct crypto_aead *tfm = crypto_aead_reqtfm(areq); 758 struct crypto_aead *tfm = crypto_aead_reqtfm(areq);
780 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 759 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
781 struct device *dev = drvdata_to_dev(ctx->drvdata); 760 struct device *dev = drvdata_to_dev(ctx->drvdata);
782 761
783 switch (data_dma_type) { 762 switch (data_dma_type) {
784 case SSI_DMA_BUF_DLLI: 763 case CC_DMA_BUF_DLLI:
785 { 764 {
786 struct scatterlist *cipher = 765 struct scatterlist *cipher =
787 (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ? 766 (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ?
@@ -798,16 +777,16 @@ ssi_aead_process_authenc_data_desc(
798 set_flow_mode(&desc[idx], flow_mode); 777 set_flow_mode(&desc[idx], flow_mode);
799 break; 778 break;
800 } 779 }
801 case SSI_DMA_BUF_MLLI: 780 case CC_DMA_BUF_MLLI:
802 { 781 {
803 /* DOUBLE-PASS flow (as default) 782 /* DOUBLE-PASS flow (as default)
804 * assoc. + iv + data -compact in one table 783 * assoc. + iv + data -compact in one table
805 * if assoclen is ZERO only IV perform 784 * if assoclen is ZERO only IV perform
806 */ 785 */
807 ssi_sram_addr_t mlli_addr = areq_ctx->assoc.sram_addr; 786 cc_sram_addr_t mlli_addr = areq_ctx->assoc.sram_addr;
808 u32 mlli_nents = areq_ctx->assoc.mlli_nents; 787 u32 mlli_nents = areq_ctx->assoc.mlli_nents;
809 788
810 if (likely(areq_ctx->is_single_pass)) { 789 if (areq_ctx->is_single_pass) {
811 if (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) { 790 if (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) {
812 mlli_addr = areq_ctx->dst.sram_addr; 791 mlli_addr = areq_ctx->dst.sram_addr;
813 mlli_nents = areq_ctx->dst.mlli_nents; 792 mlli_nents = areq_ctx->dst.mlli_nents;
@@ -824,7 +803,7 @@ ssi_aead_process_authenc_data_desc(
824 set_flow_mode(&desc[idx], flow_mode); 803 set_flow_mode(&desc[idx], flow_mode);
825 break; 804 break;
826 } 805 }
827 case SSI_DMA_BUF_NULL: 806 case CC_DMA_BUF_NULL:
828 default: 807 default:
829 dev_err(dev, "AUTHENC: Invalid SRC/DST buffer type\n"); 808 dev_err(dev, "AUTHENC: Invalid SRC/DST buffer type\n");
830 } 809 }
@@ -832,37 +811,36 @@ ssi_aead_process_authenc_data_desc(
832 *seq_size = (++idx); 811 *seq_size = (++idx);
833} 812}
834 813
835static inline void 814static void cc_proc_cipher_desc(struct aead_request *areq,
836ssi_aead_process_cipher_data_desc( 815 unsigned int flow_mode,
837 struct aead_request *areq, 816 struct cc_hw_desc desc[],
838 unsigned int flow_mode, 817 unsigned int *seq_size)
839 struct cc_hw_desc desc[],
840 unsigned int *seq_size)
841{ 818{
842 unsigned int idx = *seq_size; 819 unsigned int idx = *seq_size;
843 struct aead_req_ctx *areq_ctx = aead_request_ctx(areq); 820 struct aead_req_ctx *areq_ctx = aead_request_ctx(areq);
844 enum ssi_req_dma_buf_type data_dma_type = areq_ctx->data_buff_type; 821 enum cc_req_dma_buf_type data_dma_type = areq_ctx->data_buff_type;
845 struct crypto_aead *tfm = crypto_aead_reqtfm(areq); 822 struct crypto_aead *tfm = crypto_aead_reqtfm(areq);
846 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 823 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
847 struct device *dev = drvdata_to_dev(ctx->drvdata); 824 struct device *dev = drvdata_to_dev(ctx->drvdata);
848 825
849 if (areq_ctx->cryptlen == 0) 826 if (areq_ctx->cryptlen == 0)
850 return; /*null processing*/ 827 return; /*null processing*/
851 828
852 switch (data_dma_type) { 829 switch (data_dma_type) {
853 case SSI_DMA_BUF_DLLI: 830 case CC_DMA_BUF_DLLI:
854 dev_dbg(dev, "CIPHER: SRC/DST buffer type DLLI\n"); 831 dev_dbg(dev, "CIPHER: SRC/DST buffer type DLLI\n");
855 hw_desc_init(&desc[idx]); 832 hw_desc_init(&desc[idx]);
856 set_din_type(&desc[idx], DMA_DLLI, 833 set_din_type(&desc[idx], DMA_DLLI,
857 (sg_dma_address(areq_ctx->src_sgl) + 834 (sg_dma_address(areq_ctx->src_sgl) +
858 areq_ctx->src_offset), areq_ctx->cryptlen, NS_BIT); 835 areq_ctx->src_offset), areq_ctx->cryptlen,
836 NS_BIT);
859 set_dout_dlli(&desc[idx], 837 set_dout_dlli(&desc[idx],
860 (sg_dma_address(areq_ctx->dst_sgl) + 838 (sg_dma_address(areq_ctx->dst_sgl) +
861 areq_ctx->dst_offset), 839 areq_ctx->dst_offset),
862 areq_ctx->cryptlen, NS_BIT, 0); 840 areq_ctx->cryptlen, NS_BIT, 0);
863 set_flow_mode(&desc[idx], flow_mode); 841 set_flow_mode(&desc[idx], flow_mode);
864 break; 842 break;
865 case SSI_DMA_BUF_MLLI: 843 case CC_DMA_BUF_MLLI:
866 dev_dbg(dev, "CIPHER: SRC/DST buffer type MLLI\n"); 844 dev_dbg(dev, "CIPHER: SRC/DST buffer type MLLI\n");
867 hw_desc_init(&desc[idx]); 845 hw_desc_init(&desc[idx]);
868 set_din_type(&desc[idx], DMA_MLLI, areq_ctx->src.sram_addr, 846 set_din_type(&desc[idx], DMA_MLLI, areq_ctx->src.sram_addr,
@@ -871,7 +849,7 @@ ssi_aead_process_cipher_data_desc(
871 areq_ctx->dst.mlli_nents, NS_BIT, 0); 849 areq_ctx->dst.mlli_nents, NS_BIT, 0);
872 set_flow_mode(&desc[idx], flow_mode); 850 set_flow_mode(&desc[idx], flow_mode);
873 break; 851 break;
874 case SSI_DMA_BUF_NULL: 852 case CC_DMA_BUF_NULL:
875 default: 853 default:
876 dev_err(dev, "CIPHER: Invalid SRC/DST buffer type\n"); 854 dev_err(dev, "CIPHER: Invalid SRC/DST buffer type\n");
877 } 855 }
@@ -879,13 +857,12 @@ ssi_aead_process_cipher_data_desc(
879 *seq_size = (++idx); 857 *seq_size = (++idx);
880} 858}
881 859
882static inline void ssi_aead_process_digest_result_desc( 860static void cc_proc_digest_desc(struct aead_request *req,
883 struct aead_request *req, 861 struct cc_hw_desc desc[],
884 struct cc_hw_desc desc[], 862 unsigned int *seq_size)
885 unsigned int *seq_size)
886{ 863{
887 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 864 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
888 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 865 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
889 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 866 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
890 unsigned int idx = *seq_size; 867 unsigned int idx = *seq_size;
891 unsigned int hash_mode = (ctx->auth_mode == DRV_HASH_SHA1) ? 868 unsigned int hash_mode = (ctx->auth_mode == DRV_HASH_SHA1) ?
@@ -930,13 +907,12 @@ static inline void ssi_aead_process_digest_result_desc(
930 *seq_size = (++idx); 907 *seq_size = (++idx);
931} 908}
932 909
933static inline void ssi_aead_setup_cipher_desc( 910static void cc_set_cipher_desc(struct aead_request *req,
934 struct aead_request *req, 911 struct cc_hw_desc desc[],
935 struct cc_hw_desc desc[], 912 unsigned int *seq_size)
936 unsigned int *seq_size)
937{ 913{
938 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 914 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
939 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 915 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
940 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 916 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
941 unsigned int hw_iv_size = req_ctx->hw_iv_size; 917 unsigned int hw_iv_size = req_ctx->hw_iv_size;
942 unsigned int idx = *seq_size; 918 unsigned int idx = *seq_size;
@@ -976,11 +952,8 @@ static inline void ssi_aead_setup_cipher_desc(
976 *seq_size = idx; 952 *seq_size = idx;
977} 953}
978 954
979static inline void ssi_aead_process_cipher( 955static void cc_proc_cipher(struct aead_request *req, struct cc_hw_desc desc[],
980 struct aead_request *req, 956 unsigned int *seq_size, unsigned int data_flow_mode)
981 struct cc_hw_desc desc[],
982 unsigned int *seq_size,
983 unsigned int data_flow_mode)
984{ 957{
985 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 958 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
986 int direct = req_ctx->gen_ctx.op_type; 959 int direct = req_ctx->gen_ctx.op_type;
@@ -989,8 +962,8 @@ static inline void ssi_aead_process_cipher(
989 if (req_ctx->cryptlen == 0) 962 if (req_ctx->cryptlen == 0)
990 return; /*null processing*/ 963 return; /*null processing*/
991 964
992 ssi_aead_setup_cipher_desc(req, desc, &idx); 965 cc_set_cipher_desc(req, desc, &idx);
993 ssi_aead_process_cipher_data_desc(req, data_flow_mode, desc, &idx); 966 cc_proc_cipher_desc(req, data_flow_mode, desc, &idx);
994 if (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) { 967 if (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) {
995 /* We must wait for DMA to write all cipher */ 968 /* We must wait for DMA to write all cipher */
996 hw_desc_init(&desc[idx]); 969 hw_desc_init(&desc[idx]);
@@ -1002,13 +975,11 @@ static inline void ssi_aead_process_cipher(
1002 *seq_size = idx; 975 *seq_size = idx;
1003} 976}
1004 977
1005static inline void ssi_aead_hmac_setup_digest_desc( 978static void cc_set_hmac_desc(struct aead_request *req, struct cc_hw_desc desc[],
1006 struct aead_request *req, 979 unsigned int *seq_size)
1007 struct cc_hw_desc desc[],
1008 unsigned int *seq_size)
1009{ 980{
1010 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 981 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1011 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 982 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1012 unsigned int hash_mode = (ctx->auth_mode == DRV_HASH_SHA1) ? 983 unsigned int hash_mode = (ctx->auth_mode == DRV_HASH_SHA1) ?
1013 DRV_HASH_HW_SHA1 : DRV_HASH_HW_SHA256; 984 DRV_HASH_HW_SHA1 : DRV_HASH_HW_SHA256;
1014 unsigned int digest_size = (ctx->auth_mode == DRV_HASH_SHA1) ? 985 unsigned int digest_size = (ctx->auth_mode == DRV_HASH_SHA1) ?
@@ -1028,10 +999,8 @@ static inline void ssi_aead_hmac_setup_digest_desc(
1028 /* Load init. digest len (64 bytes) */ 999 /* Load init. digest len (64 bytes) */
1029 hw_desc_init(&desc[idx]); 1000 hw_desc_init(&desc[idx]);
1030 set_cipher_mode(&desc[idx], hash_mode); 1001 set_cipher_mode(&desc[idx], hash_mode);
1031 set_din_sram(&desc[idx], 1002 set_din_sram(&desc[idx], cc_digest_len_addr(ctx->drvdata, hash_mode),
1032 ssi_ahash_get_initial_digest_len_sram_addr(ctx->drvdata, 1003 HASH_LEN_SIZE);
1033 hash_mode),
1034 HASH_LEN_SIZE);
1035 set_flow_mode(&desc[idx], S_DIN_to_HASH); 1004 set_flow_mode(&desc[idx], S_DIN_to_HASH);
1036 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0); 1005 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
1037 idx++; 1006 idx++;
@@ -1039,13 +1008,11 @@ static inline void ssi_aead_hmac_setup_digest_desc(
1039 *seq_size = idx; 1008 *seq_size = idx;
1040} 1009}
1041 1010
1042static inline void ssi_aead_xcbc_setup_digest_desc( 1011static void cc_set_xcbc_desc(struct aead_request *req, struct cc_hw_desc desc[],
1043 struct aead_request *req, 1012 unsigned int *seq_size)
1044 struct cc_hw_desc desc[],
1045 unsigned int *seq_size)
1046{ 1013{
1047 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1014 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1048 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1015 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1049 unsigned int idx = *seq_size; 1016 unsigned int idx = *seq_size;
1050 1017
1051 /* Loading MAC state */ 1018 /* Loading MAC state */
@@ -1101,28 +1068,26 @@ static inline void ssi_aead_xcbc_setup_digest_desc(
1101 *seq_size = idx; 1068 *seq_size = idx;
1102} 1069}
1103 1070
1104static inline void ssi_aead_process_digest_header_desc( 1071static void cc_proc_header_desc(struct aead_request *req,
1105 struct aead_request *req, 1072 struct cc_hw_desc desc[],
1106 struct cc_hw_desc desc[], 1073 unsigned int *seq_size)
1107 unsigned int *seq_size)
1108{ 1074{
1109 unsigned int idx = *seq_size; 1075 unsigned int idx = *seq_size;
1110 /* Hash associated data */ 1076 /* Hash associated data */
1111 if (req->assoclen > 0) 1077 if (req->assoclen > 0)
1112 ssi_aead_create_assoc_desc(req, DIN_HASH, desc, &idx); 1078 cc_set_assoc_desc(req, DIN_HASH, desc, &idx);
1113 1079
1114 /* Hash IV */ 1080 /* Hash IV */
1115 *seq_size = idx; 1081 *seq_size = idx;
1116} 1082}
1117 1083
1118static inline void ssi_aead_process_digest_scheme_desc( 1084static void cc_proc_scheme_desc(struct aead_request *req,
1119 struct aead_request *req, 1085 struct cc_hw_desc desc[],
1120 struct cc_hw_desc desc[], 1086 unsigned int *seq_size)
1121 unsigned int *seq_size)
1122{ 1087{
1123 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1088 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1124 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1089 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1125 struct ssi_aead_handle *aead_handle = ctx->drvdata->aead_handle; 1090 struct cc_aead_handle *aead_handle = ctx->drvdata->aead_handle;
1126 unsigned int hash_mode = (ctx->auth_mode == DRV_HASH_SHA1) ? 1091 unsigned int hash_mode = (ctx->auth_mode == DRV_HASH_SHA1) ?
1127 DRV_HASH_HW_SHA1 : DRV_HASH_HW_SHA256; 1092 DRV_HASH_HW_SHA1 : DRV_HASH_HW_SHA256;
1128 unsigned int digest_size = (ctx->auth_mode == DRV_HASH_SHA1) ? 1093 unsigned int digest_size = (ctx->auth_mode == DRV_HASH_SHA1) ?
@@ -1161,9 +1126,7 @@ static inline void ssi_aead_process_digest_scheme_desc(
1161 /* Load init. digest len (64 bytes) */ 1126 /* Load init. digest len (64 bytes) */
1162 hw_desc_init(&desc[idx]); 1127 hw_desc_init(&desc[idx]);
1163 set_cipher_mode(&desc[idx], hash_mode); 1128 set_cipher_mode(&desc[idx], hash_mode);
1164 set_din_sram(&desc[idx], 1129 set_din_sram(&desc[idx], cc_digest_len_addr(ctx->drvdata, hash_mode),
1165 ssi_ahash_get_initial_digest_len_sram_addr(ctx->drvdata,
1166 hash_mode),
1167 HASH_LEN_SIZE); 1130 HASH_LEN_SIZE);
1168 set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED); 1131 set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED);
1169 set_flow_mode(&desc[idx], S_DIN_to_HASH); 1132 set_flow_mode(&desc[idx], S_DIN_to_HASH);
@@ -1180,20 +1143,17 @@ static inline void ssi_aead_process_digest_scheme_desc(
1180 *seq_size = idx; 1143 *seq_size = idx;
1181} 1144}
1182 1145
1183static inline void ssi_aead_load_mlli_to_sram( 1146static void cc_mlli_to_sram(struct aead_request *req,
1184 struct aead_request *req, 1147 struct cc_hw_desc desc[], unsigned int *seq_size)
1185 struct cc_hw_desc desc[],
1186 unsigned int *seq_size)
1187{ 1148{
1188 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 1149 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1189 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1150 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1190 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1151 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1191 struct device *dev = drvdata_to_dev(ctx->drvdata); 1152 struct device *dev = drvdata_to_dev(ctx->drvdata);
1192 1153
1193 if (unlikely( 1154 if (req_ctx->assoc_buff_type == CC_DMA_BUF_MLLI ||
1194 (req_ctx->assoc_buff_type == SSI_DMA_BUF_MLLI) || 1155 req_ctx->data_buff_type == CC_DMA_BUF_MLLI ||
1195 (req_ctx->data_buff_type == SSI_DMA_BUF_MLLI) || 1156 !req_ctx->is_single_pass) {
1196 !req_ctx->is_single_pass)) {
1197 dev_dbg(dev, "Copy-to-sram: mlli_dma=%08x, mlli_size=%u\n", 1157 dev_dbg(dev, "Copy-to-sram: mlli_dma=%08x, mlli_size=%u\n",
1198 (unsigned int)ctx->drvdata->mlli_sram_addr, 1158 (unsigned int)ctx->drvdata->mlli_sram_addr,
1199 req_ctx->mlli_params.mlli_len); 1159 req_ctx->mlli_params.mlli_len);
@@ -1210,54 +1170,52 @@ static inline void ssi_aead_load_mlli_to_sram(
1210 } 1170 }
1211} 1171}
1212 1172
1213static inline enum cc_flow_mode ssi_aead_get_data_flow_mode( 1173static enum cc_flow_mode cc_get_data_flow(enum drv_crypto_direction direct,
1214 enum drv_crypto_direction direct, 1174 enum cc_flow_mode setup_flow_mode,
1215 enum cc_flow_mode setup_flow_mode, 1175 bool is_single_pass)
1216 bool is_single_pass)
1217{ 1176{
1218 enum cc_flow_mode data_flow_mode; 1177 enum cc_flow_mode data_flow_mode;
1219 1178
1220 if (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) { 1179 if (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) {
1221 if (setup_flow_mode == S_DIN_to_AES) 1180 if (setup_flow_mode == S_DIN_to_AES)
1222 data_flow_mode = likely(is_single_pass) ? 1181 data_flow_mode = is_single_pass ?
1223 AES_to_HASH_and_DOUT : DIN_AES_DOUT; 1182 AES_to_HASH_and_DOUT : DIN_AES_DOUT;
1224 else 1183 else
1225 data_flow_mode = likely(is_single_pass) ? 1184 data_flow_mode = is_single_pass ?
1226 DES_to_HASH_and_DOUT : DIN_DES_DOUT; 1185 DES_to_HASH_and_DOUT : DIN_DES_DOUT;
1227 } else { /* Decrypt */ 1186 } else { /* Decrypt */
1228 if (setup_flow_mode == S_DIN_to_AES) 1187 if (setup_flow_mode == S_DIN_to_AES)
1229 data_flow_mode = likely(is_single_pass) ? 1188 data_flow_mode = is_single_pass ?
1230 AES_and_HASH : DIN_AES_DOUT; 1189 AES_and_HASH : DIN_AES_DOUT;
1231 else 1190 else
1232 data_flow_mode = likely(is_single_pass) ? 1191 data_flow_mode = is_single_pass ?
1233 DES_and_HASH : DIN_DES_DOUT; 1192 DES_and_HASH : DIN_DES_DOUT;
1234 } 1193 }
1235 1194
1236 return data_flow_mode; 1195 return data_flow_mode;
1237} 1196}
1238 1197
1239static inline void ssi_aead_hmac_authenc( 1198static void cc_hmac_authenc(struct aead_request *req, struct cc_hw_desc desc[],
1240 struct aead_request *req, 1199 unsigned int *seq_size)
1241 struct cc_hw_desc desc[],
1242 unsigned int *seq_size)
1243{ 1200{
1244 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1201 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1245 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1202 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1246 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 1203 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1247 int direct = req_ctx->gen_ctx.op_type; 1204 int direct = req_ctx->gen_ctx.op_type;
1248 unsigned int data_flow_mode = ssi_aead_get_data_flow_mode( 1205 unsigned int data_flow_mode =
1249 direct, ctx->flow_mode, req_ctx->is_single_pass); 1206 cc_get_data_flow(direct, ctx->flow_mode,
1207 req_ctx->is_single_pass);
1250 1208
1251 if (req_ctx->is_single_pass) { 1209 if (req_ctx->is_single_pass) {
1252 /** 1210 /**
1253 * Single-pass flow 1211 * Single-pass flow
1254 */ 1212 */
1255 ssi_aead_hmac_setup_digest_desc(req, desc, seq_size); 1213 cc_set_hmac_desc(req, desc, seq_size);
1256 ssi_aead_setup_cipher_desc(req, desc, seq_size); 1214 cc_set_cipher_desc(req, desc, seq_size);
1257 ssi_aead_process_digest_header_desc(req, desc, seq_size); 1215 cc_proc_header_desc(req, desc, seq_size);
1258 ssi_aead_process_cipher_data_desc(req, data_flow_mode, desc, seq_size); 1216 cc_proc_cipher_desc(req, data_flow_mode, desc, seq_size);
1259 ssi_aead_process_digest_scheme_desc(req, desc, seq_size); 1217 cc_proc_scheme_desc(req, desc, seq_size);
1260 ssi_aead_process_digest_result_desc(req, desc, seq_size); 1218 cc_proc_digest_desc(req, desc, seq_size);
1261 return; 1219 return;
1262 } 1220 }
1263 1221
@@ -1268,49 +1226,48 @@ static inline void ssi_aead_hmac_authenc(
1268 */ 1226 */
1269 if (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) { 1227 if (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) {
1270 /* encrypt first.. */ 1228 /* encrypt first.. */
1271 ssi_aead_process_cipher(req, desc, seq_size, data_flow_mode); 1229 cc_proc_cipher(req, desc, seq_size, data_flow_mode);
1272 /* authenc after..*/ 1230 /* authenc after..*/
1273 ssi_aead_hmac_setup_digest_desc(req, desc, seq_size); 1231 cc_set_hmac_desc(req, desc, seq_size);
1274 ssi_aead_process_authenc_data_desc(req, DIN_HASH, desc, seq_size, direct); 1232 cc_proc_authen_desc(req, DIN_HASH, desc, seq_size, direct);
1275 ssi_aead_process_digest_scheme_desc(req, desc, seq_size); 1233 cc_proc_scheme_desc(req, desc, seq_size);
1276 ssi_aead_process_digest_result_desc(req, desc, seq_size); 1234 cc_proc_digest_desc(req, desc, seq_size);
1277 1235
1278 } else { /*DECRYPT*/ 1236 } else { /*DECRYPT*/
1279 /* authenc first..*/ 1237 /* authenc first..*/
1280 ssi_aead_hmac_setup_digest_desc(req, desc, seq_size); 1238 cc_set_hmac_desc(req, desc, seq_size);
1281 ssi_aead_process_authenc_data_desc(req, DIN_HASH, desc, seq_size, direct); 1239 cc_proc_authen_desc(req, DIN_HASH, desc, seq_size, direct);
1282 ssi_aead_process_digest_scheme_desc(req, desc, seq_size); 1240 cc_proc_scheme_desc(req, desc, seq_size);
1283 /* decrypt after.. */ 1241 /* decrypt after.. */
1284 ssi_aead_process_cipher(req, desc, seq_size, data_flow_mode); 1242 cc_proc_cipher(req, desc, seq_size, data_flow_mode);
1285 /* read the digest result with setting the completion bit 1243 /* read the digest result with setting the completion bit
1286 * must be after the cipher operation 1244 * must be after the cipher operation
1287 */ 1245 */
1288 ssi_aead_process_digest_result_desc(req, desc, seq_size); 1246 cc_proc_digest_desc(req, desc, seq_size);
1289 } 1247 }
1290} 1248}
1291 1249
1292static inline void 1250static void
1293ssi_aead_xcbc_authenc( 1251cc_xcbc_authenc(struct aead_request *req, struct cc_hw_desc desc[],
1294 struct aead_request *req, 1252 unsigned int *seq_size)
1295 struct cc_hw_desc desc[],
1296 unsigned int *seq_size)
1297{ 1253{
1298 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1254 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1299 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1255 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1300 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 1256 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1301 int direct = req_ctx->gen_ctx.op_type; 1257 int direct = req_ctx->gen_ctx.op_type;
1302 unsigned int data_flow_mode = ssi_aead_get_data_flow_mode( 1258 unsigned int data_flow_mode =
1303 direct, ctx->flow_mode, req_ctx->is_single_pass); 1259 cc_get_data_flow(direct, ctx->flow_mode,
1260 req_ctx->is_single_pass);
1304 1261
1305 if (req_ctx->is_single_pass) { 1262 if (req_ctx->is_single_pass) {
1306 /** 1263 /**
1307 * Single-pass flow 1264 * Single-pass flow
1308 */ 1265 */
1309 ssi_aead_xcbc_setup_digest_desc(req, desc, seq_size); 1266 cc_set_xcbc_desc(req, desc, seq_size);
1310 ssi_aead_setup_cipher_desc(req, desc, seq_size); 1267 cc_set_cipher_desc(req, desc, seq_size);
1311 ssi_aead_process_digest_header_desc(req, desc, seq_size); 1268 cc_proc_header_desc(req, desc, seq_size);
1312 ssi_aead_process_cipher_data_desc(req, data_flow_mode, desc, seq_size); 1269 cc_proc_cipher_desc(req, data_flow_mode, desc, seq_size);
1313 ssi_aead_process_digest_result_desc(req, desc, seq_size); 1270 cc_proc_digest_desc(req, desc, seq_size);
1314 return; 1271 return;
1315 } 1272 }
1316 1273
@@ -1321,25 +1278,25 @@ ssi_aead_xcbc_authenc(
1321 */ 1278 */
1322 if (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) { 1279 if (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) {
1323 /* encrypt first.. */ 1280 /* encrypt first.. */
1324 ssi_aead_process_cipher(req, desc, seq_size, data_flow_mode); 1281 cc_proc_cipher(req, desc, seq_size, data_flow_mode);
1325 /* authenc after.. */ 1282 /* authenc after.. */
1326 ssi_aead_xcbc_setup_digest_desc(req, desc, seq_size); 1283 cc_set_xcbc_desc(req, desc, seq_size);
1327 ssi_aead_process_authenc_data_desc(req, DIN_HASH, desc, seq_size, direct); 1284 cc_proc_authen_desc(req, DIN_HASH, desc, seq_size, direct);
1328 ssi_aead_process_digest_result_desc(req, desc, seq_size); 1285 cc_proc_digest_desc(req, desc, seq_size);
1329 } else { /*DECRYPT*/ 1286 } else { /*DECRYPT*/
1330 /* authenc first.. */ 1287 /* authenc first.. */
1331 ssi_aead_xcbc_setup_digest_desc(req, desc, seq_size); 1288 cc_set_xcbc_desc(req, desc, seq_size);
1332 ssi_aead_process_authenc_data_desc(req, DIN_HASH, desc, seq_size, direct); 1289 cc_proc_authen_desc(req, DIN_HASH, desc, seq_size, direct);
1333 /* decrypt after..*/ 1290 /* decrypt after..*/
1334 ssi_aead_process_cipher(req, desc, seq_size, data_flow_mode); 1291 cc_proc_cipher(req, desc, seq_size, data_flow_mode);
1335 /* read the digest result with setting the completion bit 1292 /* read the digest result with setting the completion bit
1336 * must be after the cipher operation 1293 * must be after the cipher operation
1337 */ 1294 */
1338 ssi_aead_process_digest_result_desc(req, desc, seq_size); 1295 cc_proc_digest_desc(req, desc, seq_size);
1339 } 1296 }
1340} 1297}
1341 1298
1342static int validate_data_size(struct ssi_aead_ctx *ctx, 1299static int validate_data_size(struct cc_aead_ctx *ctx,
1343 enum drv_crypto_direction direct, 1300 enum drv_crypto_direction direct,
1344 struct aead_request *req) 1301 struct aead_request *req)
1345{ 1302{
@@ -1349,16 +1306,16 @@ static int validate_data_size(struct ssi_aead_ctx *ctx,
1349 unsigned int cipherlen = (direct == DRV_CRYPTO_DIRECTION_DECRYPT) ? 1306 unsigned int cipherlen = (direct == DRV_CRYPTO_DIRECTION_DECRYPT) ?
1350 (req->cryptlen - ctx->authsize) : req->cryptlen; 1307 (req->cryptlen - ctx->authsize) : req->cryptlen;
1351 1308
1352 if (unlikely((direct == DRV_CRYPTO_DIRECTION_DECRYPT) && 1309 if (direct == DRV_CRYPTO_DIRECTION_DECRYPT &&
1353 (req->cryptlen < ctx->authsize))) 1310 req->cryptlen < ctx->authsize)
1354 goto data_size_err; 1311 goto data_size_err;
1355 1312
1356 areq_ctx->is_single_pass = true; /*defaulted to fast flow*/ 1313 areq_ctx->is_single_pass = true; /*defaulted to fast flow*/
1357 1314
1358 switch (ctx->flow_mode) { 1315 switch (ctx->flow_mode) {
1359 case S_DIN_to_AES: 1316 case S_DIN_to_AES:
1360 if (unlikely((ctx->cipher_mode == DRV_CIPHER_CBC) && 1317 if (ctx->cipher_mode == DRV_CIPHER_CBC &&
1361 !IS_ALIGNED(cipherlen, AES_BLOCK_SIZE))) 1318 !IS_ALIGNED(cipherlen, AES_BLOCK_SIZE))
1362 goto data_size_err; 1319 goto data_size_err;
1363 if (ctx->cipher_mode == DRV_CIPHER_CCM) 1320 if (ctx->cipher_mode == DRV_CIPHER_CCM)
1364 break; 1321 break;
@@ -1371,15 +1328,15 @@ static int validate_data_size(struct ssi_aead_ctx *ctx,
1371 if (!IS_ALIGNED(assoclen, sizeof(u32))) 1328 if (!IS_ALIGNED(assoclen, sizeof(u32)))
1372 areq_ctx->is_single_pass = false; 1329 areq_ctx->is_single_pass = false;
1373 1330
1374 if ((ctx->cipher_mode == DRV_CIPHER_CTR) && 1331 if (ctx->cipher_mode == DRV_CIPHER_CTR &&
1375 !IS_ALIGNED(cipherlen, sizeof(u32))) 1332 !IS_ALIGNED(cipherlen, sizeof(u32)))
1376 areq_ctx->is_single_pass = false; 1333 areq_ctx->is_single_pass = false;
1377 1334
1378 break; 1335 break;
1379 case S_DIN_to_DES: 1336 case S_DIN_to_DES:
1380 if (unlikely(!IS_ALIGNED(cipherlen, DES_BLOCK_SIZE))) 1337 if (!IS_ALIGNED(cipherlen, DES_BLOCK_SIZE))
1381 goto data_size_err; 1338 goto data_size_err;
1382 if (unlikely(!IS_ALIGNED(assoclen, DES_BLOCK_SIZE))) 1339 if (!IS_ALIGNED(assoclen, DES_BLOCK_SIZE))
1383 areq_ctx->is_single_pass = false; 1340 areq_ctx->is_single_pass = false;
1384 break; 1341 break;
1385 default: 1342 default:
@@ -1393,7 +1350,6 @@ data_size_err:
1393 return -EINVAL; 1350 return -EINVAL;
1394} 1351}
1395 1352
1396#if SSI_CC_HAS_AES_CCM
1397static unsigned int format_ccm_a0(u8 *pa0_buff, u32 header_size) 1353static unsigned int format_ccm_a0(u8 *pa0_buff, u32 header_size)
1398{ 1354{
1399 unsigned int len = 0; 1355 unsigned int len = 0;
@@ -1438,13 +1394,11 @@ static int set_msg_len(u8 *block, unsigned int msglen, unsigned int csize)
1438 return 0; 1394 return 0;
1439} 1395}
1440 1396
1441static inline int ssi_aead_ccm( 1397static int cc_ccm(struct aead_request *req, struct cc_hw_desc desc[],
1442 struct aead_request *req, 1398 unsigned int *seq_size)
1443 struct cc_hw_desc desc[],
1444 unsigned int *seq_size)
1445{ 1399{
1446 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1400 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1447 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1401 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1448 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 1402 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1449 unsigned int idx = *seq_size; 1403 unsigned int idx = *seq_size;
1450 unsigned int cipher_flow_mode; 1404 unsigned int cipher_flow_mode;
@@ -1508,7 +1462,7 @@ static inline int ssi_aead_ccm(
1508 1462
1509 /* process assoc data */ 1463 /* process assoc data */
1510 if (req->assoclen > 0) { 1464 if (req->assoclen > 0) {
1511 ssi_aead_create_assoc_desc(req, DIN_HASH, desc, &idx); 1465 cc_set_assoc_desc(req, DIN_HASH, desc, &idx);
1512 } else { 1466 } else {
1513 hw_desc_init(&desc[idx]); 1467 hw_desc_init(&desc[idx]);
1514 set_din_type(&desc[idx], DMA_DLLI, 1468 set_din_type(&desc[idx], DMA_DLLI,
@@ -1519,8 +1473,8 @@ static inline int ssi_aead_ccm(
1519 } 1473 }
1520 1474
1521 /* process the cipher */ 1475 /* process the cipher */
1522 if (req_ctx->cryptlen != 0) 1476 if (req_ctx->cryptlen)
1523 ssi_aead_process_cipher_data_desc(req, cipher_flow_mode, desc, &idx); 1477 cc_proc_cipher_desc(req, cipher_flow_mode, desc, &idx);
1524 1478
1525 /* Read temporal MAC */ 1479 /* Read temporal MAC */
1526 hw_desc_init(&desc[idx]); 1480 hw_desc_init(&desc[idx]);
@@ -1565,12 +1519,14 @@ static inline int ssi_aead_ccm(
1565static int config_ccm_adata(struct aead_request *req) 1519static int config_ccm_adata(struct aead_request *req)
1566{ 1520{
1567 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1521 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1568 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1522 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1569 struct device *dev = drvdata_to_dev(ctx->drvdata); 1523 struct device *dev = drvdata_to_dev(ctx->drvdata);
1570 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 1524 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1571 //unsigned int size_of_a = 0, rem_a_size = 0; 1525 //unsigned int size_of_a = 0, rem_a_size = 0;
1572 unsigned int lp = req->iv[0]; 1526 unsigned int lp = req->iv[0];
1573 /* Note: The code assume that req->iv[0] already contains the value of L' of RFC3610 */ 1527 /* Note: The code assume that req->iv[0] already contains the value
1528 * of L' of RFC3610
1529 */
1574 unsigned int l = lp + 1; /* This is L' of RFC 3610. */ 1530 unsigned int l = lp + 1; /* This is L' of RFC 3610. */
1575 unsigned int m = ctx->authsize; /* This is M' of RFC 3610. */ 1531 unsigned int m = ctx->authsize; /* This is M' of RFC 3610. */
1576 u8 *b0 = req_ctx->ccm_config + CCM_B0_OFFSET; 1532 u8 *b0 = req_ctx->ccm_config + CCM_B0_OFFSET;
@@ -1601,7 +1557,7 @@ static int config_ccm_adata(struct aead_request *req)
1601 *b0 |= 64; /* Enable bit 6 if Adata exists. */ 1557 *b0 |= 64; /* Enable bit 6 if Adata exists. */
1602 1558
1603 rc = set_msg_len(b0 + 16 - l, cryptlen, l); /* Write L'. */ 1559 rc = set_msg_len(b0 + 16 - l, cryptlen, l); /* Write L'. */
1604 if (rc != 0) { 1560 if (rc) {
1605 dev_err(dev, "message len overflow detected"); 1561 dev_err(dev, "message len overflow detected");
1606 return rc; 1562 return rc;
1607 } 1563 }
@@ -1619,33 +1575,35 @@ static int config_ccm_adata(struct aead_request *req)
1619 return 0; 1575 return 0;
1620} 1576}
1621 1577
1622static void ssi_rfc4309_ccm_process(struct aead_request *req) 1578static void cc_proc_rfc4309_ccm(struct aead_request *req)
1623{ 1579{
1624 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1580 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1625 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1581 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1626 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 1582 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
1627 1583
1628 /* L' */ 1584 /* L' */
1629 memset(areq_ctx->ctr_iv, 0, AES_BLOCK_SIZE); 1585 memset(areq_ctx->ctr_iv, 0, AES_BLOCK_SIZE);
1630 areq_ctx->ctr_iv[0] = 3; /* For RFC 4309, always use 4 bytes for message length (at most 2^32-1 bytes). */ 1586 /* For RFC 4309, always use 4 bytes for message length
1587 * (at most 2^32-1 bytes).
1588 */
1589 areq_ctx->ctr_iv[0] = 3;
1631 1590
1632 /* In RFC 4309 there is an 11-bytes nonce+IV part, that we build here. */ 1591 /* In RFC 4309 there is an 11-bytes nonce+IV part,
1633 memcpy(areq_ctx->ctr_iv + CCM_BLOCK_NONCE_OFFSET, ctx->ctr_nonce, CCM_BLOCK_NONCE_SIZE); 1592 * that we build here.
1634 memcpy(areq_ctx->ctr_iv + CCM_BLOCK_IV_OFFSET, req->iv, CCM_BLOCK_IV_SIZE); 1593 */
1594 memcpy(areq_ctx->ctr_iv + CCM_BLOCK_NONCE_OFFSET, ctx->ctr_nonce,
1595 CCM_BLOCK_NONCE_SIZE);
1596 memcpy(areq_ctx->ctr_iv + CCM_BLOCK_IV_OFFSET, req->iv,
1597 CCM_BLOCK_IV_SIZE);
1635 req->iv = areq_ctx->ctr_iv; 1598 req->iv = areq_ctx->ctr_iv;
1636 req->assoclen -= CCM_BLOCK_IV_SIZE; 1599 req->assoclen -= CCM_BLOCK_IV_SIZE;
1637} 1600}
1638#endif /*SSI_CC_HAS_AES_CCM*/
1639
1640#if SSI_CC_HAS_AES_GCM
1641 1601
1642static inline void ssi_aead_gcm_setup_ghash_desc( 1602static void cc_set_ghash_desc(struct aead_request *req,
1643 struct aead_request *req, 1603 struct cc_hw_desc desc[], unsigned int *seq_size)
1644 struct cc_hw_desc desc[],
1645 unsigned int *seq_size)
1646{ 1604{
1647 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1605 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1648 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1606 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1649 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 1607 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1650 unsigned int idx = *seq_size; 1608 unsigned int idx = *seq_size;
1651 1609
@@ -1703,7 +1661,9 @@ static inline void ssi_aead_gcm_setup_ghash_desc(
1703 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0); 1661 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
1704 idx++; 1662 idx++;
1705 1663
1706 /* Load GHASH initial STATE (which is 0). (for any hash there is an initial state) */ 1664 /* Load GHASH initial STATE (which is 0). (for any hash there is an
1665 * initial state)
1666 */
1707 hw_desc_init(&desc[idx]); 1667 hw_desc_init(&desc[idx]);
1708 set_din_const(&desc[idx], 0x0, AES_BLOCK_SIZE); 1668 set_din_const(&desc[idx], 0x0, AES_BLOCK_SIZE);
1709 set_dout_no_dma(&desc[idx], 0, 0, 1); 1669 set_dout_no_dma(&desc[idx], 0, 0, 1);
@@ -1717,13 +1677,11 @@ static inline void ssi_aead_gcm_setup_ghash_desc(
1717 *seq_size = idx; 1677 *seq_size = idx;
1718} 1678}
1719 1679
1720static inline void ssi_aead_gcm_setup_gctr_desc( 1680static void cc_set_gctr_desc(struct aead_request *req, struct cc_hw_desc desc[],
1721 struct aead_request *req, 1681 unsigned int *seq_size)
1722 struct cc_hw_desc desc[],
1723 unsigned int *seq_size)
1724{ 1682{
1725 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1683 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1726 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1684 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1727 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 1685 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1728 unsigned int idx = *seq_size; 1686 unsigned int idx = *seq_size;
1729 1687
@@ -1738,7 +1696,7 @@ static inline void ssi_aead_gcm_setup_gctr_desc(
1738 set_flow_mode(&desc[idx], S_DIN_to_AES); 1696 set_flow_mode(&desc[idx], S_DIN_to_AES);
1739 idx++; 1697 idx++;
1740 1698
1741 if ((req_ctx->cryptlen != 0) && (!req_ctx->plaintext_authenticate_only)) { 1699 if (req_ctx->cryptlen && !req_ctx->plaintext_authenticate_only) {
1742 /* load AES/CTR initial CTR value inc by 2*/ 1700 /* load AES/CTR initial CTR value inc by 2*/
1743 hw_desc_init(&desc[idx]); 1701 hw_desc_init(&desc[idx]);
1744 set_cipher_mode(&desc[idx], DRV_CIPHER_GCTR); 1702 set_cipher_mode(&desc[idx], DRV_CIPHER_GCTR);
@@ -1755,13 +1713,12 @@ static inline void ssi_aead_gcm_setup_gctr_desc(
1755 *seq_size = idx; 1713 *seq_size = idx;
1756} 1714}
1757 1715
1758static inline void ssi_aead_process_gcm_result_desc( 1716static void cc_proc_gcm_result(struct aead_request *req,
1759 struct aead_request *req, 1717 struct cc_hw_desc desc[],
1760 struct cc_hw_desc desc[], 1718 unsigned int *seq_size)
1761 unsigned int *seq_size)
1762{ 1719{
1763 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1720 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1764 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1721 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1765 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 1722 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1766 dma_addr_t mac_result; 1723 dma_addr_t mac_result;
1767 unsigned int idx = *seq_size; 1724 unsigned int idx = *seq_size;
@@ -1821,10 +1778,8 @@ static inline void ssi_aead_process_gcm_result_desc(
1821 *seq_size = idx; 1778 *seq_size = idx;
1822} 1779}
1823 1780
1824static inline int ssi_aead_gcm( 1781static int cc_gcm(struct aead_request *req, struct cc_hw_desc desc[],
1825 struct aead_request *req, 1782 unsigned int *seq_size)
1826 struct cc_hw_desc desc[],
1827 unsigned int *seq_size)
1828{ 1783{
1829 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 1784 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1830 unsigned int cipher_flow_mode; 1785 unsigned int cipher_flow_mode;
@@ -1837,77 +1792,33 @@ static inline int ssi_aead_gcm(
1837 1792
1838 //in RFC4543 no data to encrypt. just copy data from src to dest. 1793 //in RFC4543 no data to encrypt. just copy data from src to dest.
1839 if (req_ctx->plaintext_authenticate_only) { 1794 if (req_ctx->plaintext_authenticate_only) {
1840 ssi_aead_process_cipher_data_desc(req, BYPASS, desc, seq_size); 1795 cc_proc_cipher_desc(req, BYPASS, desc, seq_size);
1841 ssi_aead_gcm_setup_ghash_desc(req, desc, seq_size); 1796 cc_set_ghash_desc(req, desc, seq_size);
1842 /* process(ghash) assoc data */ 1797 /* process(ghash) assoc data */
1843 ssi_aead_create_assoc_desc(req, DIN_HASH, desc, seq_size); 1798 cc_set_assoc_desc(req, DIN_HASH, desc, seq_size);
1844 ssi_aead_gcm_setup_gctr_desc(req, desc, seq_size); 1799 cc_set_gctr_desc(req, desc, seq_size);
1845 ssi_aead_process_gcm_result_desc(req, desc, seq_size); 1800 cc_proc_gcm_result(req, desc, seq_size);
1846 return 0; 1801 return 0;
1847 } 1802 }
1848 1803
1849 // for gcm and rfc4106. 1804 // for gcm and rfc4106.
1850 ssi_aead_gcm_setup_ghash_desc(req, desc, seq_size); 1805 cc_set_ghash_desc(req, desc, seq_size);
1851 /* process(ghash) assoc data */ 1806 /* process(ghash) assoc data */
1852 if (req->assoclen > 0) 1807 if (req->assoclen > 0)
1853 ssi_aead_create_assoc_desc(req, DIN_HASH, desc, seq_size); 1808 cc_set_assoc_desc(req, DIN_HASH, desc, seq_size);
1854 ssi_aead_gcm_setup_gctr_desc(req, desc, seq_size); 1809 cc_set_gctr_desc(req, desc, seq_size);
1855 /* process(gctr+ghash) */ 1810 /* process(gctr+ghash) */
1856 if (req_ctx->cryptlen != 0) 1811 if (req_ctx->cryptlen)
1857 ssi_aead_process_cipher_data_desc(req, cipher_flow_mode, desc, seq_size); 1812 cc_proc_cipher_desc(req, cipher_flow_mode, desc, seq_size);
1858 ssi_aead_process_gcm_result_desc(req, desc, seq_size); 1813 cc_proc_gcm_result(req, desc, seq_size);
1859 1814
1860 return 0; 1815 return 0;
1861} 1816}
1862 1817
1863#ifdef CC_DEBUG
1864static inline void ssi_aead_dump_gcm(
1865 const char *title,
1866 struct aead_request *req)
1867{
1868 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1869 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm);
1870 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1871
1872 if (ctx->cipher_mode != DRV_CIPHER_GCTR)
1873 return;
1874
1875 if (title) {
1876 dev_dbg(dev, "----------------------------------------------------------------------------------");
1877 dev_dbg(dev, "%s\n", title);
1878 }
1879
1880 dev_dbg(dev, "cipher_mode %d, authsize %d, enc_keylen %d, assoclen %d, cryptlen %d\n",
1881 ctx->cipher_mode, ctx->authsize, ctx->enc_keylen,
1882 req->assoclen, req_ctx->cryptlen);
1883
1884 if (ctx->enckey)
1885 dump_byte_array("mac key", ctx->enckey, 16);
1886
1887 dump_byte_array("req->iv", req->iv, AES_BLOCK_SIZE);
1888
1889 dump_byte_array("gcm_iv_inc1", req_ctx->gcm_iv_inc1, AES_BLOCK_SIZE);
1890
1891 dump_byte_array("gcm_iv_inc2", req_ctx->gcm_iv_inc2, AES_BLOCK_SIZE);
1892
1893 dump_byte_array("hkey", req_ctx->hkey, AES_BLOCK_SIZE);
1894
1895 dump_byte_array("mac_buf", req_ctx->mac_buf, AES_BLOCK_SIZE);
1896
1897 dump_byte_array("gcm_len_block", req_ctx->gcm_len_block.len_a, AES_BLOCK_SIZE);
1898
1899 if (req->src && req->cryptlen)
1900 dump_byte_array("req->src", sg_virt(req->src), req->cryptlen + req->assoclen);
1901
1902 if (req->dst)
1903 dump_byte_array("req->dst", sg_virt(req->dst), req->cryptlen + ctx->authsize + req->assoclen);
1904}
1905#endif
1906
1907static int config_gcm_context(struct aead_request *req) 1818static int config_gcm_context(struct aead_request *req)
1908{ 1819{
1909 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1820 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1910 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1821 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1911 struct aead_req_ctx *req_ctx = aead_request_ctx(req); 1822 struct aead_req_ctx *req_ctx = aead_request_ctx(req);
1912 struct device *dev = drvdata_to_dev(ctx->drvdata); 1823 struct device *dev = drvdata_to_dev(ctx->drvdata);
1913 1824
@@ -1938,10 +1849,14 @@ static int config_gcm_context(struct aead_request *req)
1938 memcpy(&req_ctx->gcm_len_block.len_a, &temp64, sizeof(temp64)); 1849 memcpy(&req_ctx->gcm_len_block.len_a, &temp64, sizeof(temp64));
1939 temp64 = cpu_to_be64(cryptlen * 8); 1850 temp64 = cpu_to_be64(cryptlen * 8);
1940 memcpy(&req_ctx->gcm_len_block.len_c, &temp64, 8); 1851 memcpy(&req_ctx->gcm_len_block.len_c, &temp64, 8);
1941 } else { //rfc4543=> all data(AAD,IV,Plain) are considered additional data that is nothing is encrypted. 1852 } else {
1853 /* rfc4543=> all data(AAD,IV,Plain) are considered additional
1854 * data that is nothing is encrypted.
1855 */
1942 __be64 temp64; 1856 __be64 temp64;
1943 1857
1944 temp64 = cpu_to_be64((req->assoclen + GCM_BLOCK_RFC4_IV_SIZE + cryptlen) * 8); 1858 temp64 = cpu_to_be64((req->assoclen + GCM_BLOCK_RFC4_IV_SIZE +
1859 cryptlen) * 8);
1945 memcpy(&req_ctx->gcm_len_block.len_a, &temp64, sizeof(temp64)); 1860 memcpy(&req_ctx->gcm_len_block.len_a, &temp64, sizeof(temp64));
1946 temp64 = 0; 1861 temp64 = 0;
1947 memcpy(&req_ctx->gcm_len_block.len_c, &temp64, 8); 1862 memcpy(&req_ctx->gcm_len_block.len_c, &temp64, 8);
@@ -1950,30 +1865,31 @@ static int config_gcm_context(struct aead_request *req)
1950 return 0; 1865 return 0;
1951} 1866}
1952 1867
1953static void ssi_rfc4_gcm_process(struct aead_request *req) 1868static void cc_proc_rfc4_gcm(struct aead_request *req)
1954{ 1869{
1955 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1870 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1956 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1871 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1957 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 1872 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
1958 1873
1959 memcpy(areq_ctx->ctr_iv + GCM_BLOCK_RFC4_NONCE_OFFSET, ctx->ctr_nonce, GCM_BLOCK_RFC4_NONCE_SIZE); 1874 memcpy(areq_ctx->ctr_iv + GCM_BLOCK_RFC4_NONCE_OFFSET,
1960 memcpy(areq_ctx->ctr_iv + GCM_BLOCK_RFC4_IV_OFFSET, req->iv, GCM_BLOCK_RFC4_IV_SIZE); 1875 ctx->ctr_nonce, GCM_BLOCK_RFC4_NONCE_SIZE);
1876 memcpy(areq_ctx->ctr_iv + GCM_BLOCK_RFC4_IV_OFFSET, req->iv,
1877 GCM_BLOCK_RFC4_IV_SIZE);
1961 req->iv = areq_ctx->ctr_iv; 1878 req->iv = areq_ctx->ctr_iv;
1962 req->assoclen -= GCM_BLOCK_RFC4_IV_SIZE; 1879 req->assoclen -= GCM_BLOCK_RFC4_IV_SIZE;
1963} 1880}
1964 1881
1965#endif /*SSI_CC_HAS_AES_GCM*/ 1882static int cc_proc_aead(struct aead_request *req,
1966 1883 enum drv_crypto_direction direct)
1967static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction direct)
1968{ 1884{
1969 int rc = 0; 1885 int rc = 0;
1970 int seq_len = 0; 1886 int seq_len = 0;
1971 struct cc_hw_desc desc[MAX_AEAD_PROCESS_SEQ]; 1887 struct cc_hw_desc desc[MAX_AEAD_PROCESS_SEQ];
1972 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1888 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1973 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 1889 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
1974 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 1890 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
1975 struct device *dev = drvdata_to_dev(ctx->drvdata); 1891 struct device *dev = drvdata_to_dev(ctx->drvdata);
1976 struct ssi_crypto_req ssi_req = {}; 1892 struct cc_crypto_req cc_req = {};
1977 1893
1978 dev_dbg(dev, "%s context=%p req=%p iv=%p src=%p src_ofs=%d dst=%p dst_ofs=%d cryptolen=%d\n", 1894 dev_dbg(dev, "%s context=%p req=%p iv=%p src=%p src_ofs=%d dst=%p dst_ofs=%d cryptolen=%d\n",
1979 ((direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ? "Enc" : "Dec"), 1895 ((direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ? "Enc" : "Dec"),
@@ -1983,7 +1899,7 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction
1983 /* STAT_PHASE_0: Init and sanity checks */ 1899 /* STAT_PHASE_0: Init and sanity checks */
1984 1900
1985 /* Check data length according to mode */ 1901 /* Check data length according to mode */
1986 if (unlikely(validate_data_size(ctx, direct, req) != 0)) { 1902 if (validate_data_size(ctx, direct, req)) {
1987 dev_err(dev, "Unsupported crypt/assoc len %d/%d.\n", 1903 dev_err(dev, "Unsupported crypt/assoc len %d/%d.\n",
1988 req->cryptlen, req->assoclen); 1904 req->cryptlen, req->assoclen);
1989 crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_BLOCK_LEN); 1905 crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_BLOCK_LEN);
@@ -1991,8 +1907,8 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction
1991 } 1907 }
1992 1908
1993 /* Setup DX request structure */ 1909 /* Setup DX request structure */
1994 ssi_req.user_cb = (void *)ssi_aead_complete; 1910 cc_req.user_cb = (void *)cc_aead_complete;
1995 ssi_req.user_arg = (void *)req; 1911 cc_req.user_arg = (void *)req;
1996 1912
1997 /* Setup request context */ 1913 /* Setup request context */
1998 areq_ctx->gen_ctx.op_type = direct; 1914 areq_ctx->gen_ctx.op_type = direct;
@@ -2005,7 +1921,8 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction
2005 /* Build CTR IV - Copy nonce from last 4 bytes in 1921 /* Build CTR IV - Copy nonce from last 4 bytes in
2006 * CTR key to first 4 bytes in CTR IV 1922 * CTR key to first 4 bytes in CTR IV
2007 */ 1923 */
2008 memcpy(areq_ctx->ctr_iv, ctx->ctr_nonce, CTR_RFC3686_NONCE_SIZE); 1924 memcpy(areq_ctx->ctr_iv, ctx->ctr_nonce,
1925 CTR_RFC3686_NONCE_SIZE);
2009 if (!areq_ctx->backup_giv) /*User none-generated IV*/ 1926 if (!areq_ctx->backup_giv) /*User none-generated IV*/
2010 memcpy(areq_ctx->ctr_iv + CTR_RFC3686_NONCE_SIZE, 1927 memcpy(areq_ctx->ctr_iv + CTR_RFC3686_NONCE_SIZE,
2011 req->iv, CTR_RFC3686_IV_SIZE); 1928 req->iv, CTR_RFC3686_IV_SIZE);
@@ -2020,17 +1937,17 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction
2020 (ctx->cipher_mode == DRV_CIPHER_GCTR)) { 1937 (ctx->cipher_mode == DRV_CIPHER_GCTR)) {
2021 areq_ctx->hw_iv_size = AES_BLOCK_SIZE; 1938 areq_ctx->hw_iv_size = AES_BLOCK_SIZE;
2022 if (areq_ctx->ctr_iv != req->iv) { 1939 if (areq_ctx->ctr_iv != req->iv) {
2023 memcpy(areq_ctx->ctr_iv, req->iv, crypto_aead_ivsize(tfm)); 1940 memcpy(areq_ctx->ctr_iv, req->iv,
1941 crypto_aead_ivsize(tfm));
2024 req->iv = areq_ctx->ctr_iv; 1942 req->iv = areq_ctx->ctr_iv;
2025 } 1943 }
2026 } else { 1944 } else {
2027 areq_ctx->hw_iv_size = crypto_aead_ivsize(tfm); 1945 areq_ctx->hw_iv_size = crypto_aead_ivsize(tfm);
2028 } 1946 }
2029 1947
2030#if SSI_CC_HAS_AES_CCM
2031 if (ctx->cipher_mode == DRV_CIPHER_CCM) { 1948 if (ctx->cipher_mode == DRV_CIPHER_CCM) {
2032 rc = config_ccm_adata(req); 1949 rc = config_ccm_adata(req);
2033 if (unlikely(rc != 0)) { 1950 if (rc) {
2034 dev_dbg(dev, "config_ccm_adata() returned with a failure %d!", 1951 dev_dbg(dev, "config_ccm_adata() returned with a failure %d!",
2035 rc); 1952 rc);
2036 goto exit; 1953 goto exit;
@@ -2038,23 +1955,18 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction
2038 } else { 1955 } else {
2039 areq_ctx->ccm_hdr_size = ccm_header_size_null; 1956 areq_ctx->ccm_hdr_size = ccm_header_size_null;
2040 } 1957 }
2041#else
2042 areq_ctx->ccm_hdr_size = ccm_header_size_null;
2043#endif /*SSI_CC_HAS_AES_CCM*/
2044 1958
2045#if SSI_CC_HAS_AES_GCM
2046 if (ctx->cipher_mode == DRV_CIPHER_GCTR) { 1959 if (ctx->cipher_mode == DRV_CIPHER_GCTR) {
2047 rc = config_gcm_context(req); 1960 rc = config_gcm_context(req);
2048 if (unlikely(rc != 0)) { 1961 if (rc) {
2049 dev_dbg(dev, "config_gcm_context() returned with a failure %d!", 1962 dev_dbg(dev, "config_gcm_context() returned with a failure %d!",
2050 rc); 1963 rc);
2051 goto exit; 1964 goto exit;
2052 } 1965 }
2053 } 1966 }
2054#endif /*SSI_CC_HAS_AES_GCM*/
2055 1967
2056 rc = ssi_buffer_mgr_map_aead_request(ctx->drvdata, req); 1968 rc = cc_map_aead_request(ctx->drvdata, req);
2057 if (unlikely(rc != 0)) { 1969 if (rc) {
2058 dev_err(dev, "map_request() failed\n"); 1970 dev_err(dev, "map_request() failed\n");
2059 goto exit; 1971 goto exit;
2060 } 1972 }
@@ -2063,74 +1975,77 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction
2063 if (areq_ctx->backup_giv) { 1975 if (areq_ctx->backup_giv) {
2064 /* set the DMA mapped IV address*/ 1976 /* set the DMA mapped IV address*/
2065 if (ctx->cipher_mode == DRV_CIPHER_CTR) { 1977 if (ctx->cipher_mode == DRV_CIPHER_CTR) {
2066 ssi_req.ivgen_dma_addr[0] = areq_ctx->gen_ctx.iv_dma_addr + CTR_RFC3686_NONCE_SIZE; 1978 cc_req.ivgen_dma_addr[0] =
2067 ssi_req.ivgen_dma_addr_len = 1; 1979 areq_ctx->gen_ctx.iv_dma_addr +
1980 CTR_RFC3686_NONCE_SIZE;
1981 cc_req.ivgen_dma_addr_len = 1;
2068 } else if (ctx->cipher_mode == DRV_CIPHER_CCM) { 1982 } else if (ctx->cipher_mode == DRV_CIPHER_CCM) {
2069 /* In ccm, the IV needs to exist both inside B0 and inside the counter. 1983 /* In ccm, the IV needs to exist both inside B0 and
2070 * It is also copied to iv_dma_addr for other reasons (like returning 1984 * inside the counter.It is also copied to iv_dma_addr
2071 * it to the user). 1985 * for other reasons (like returning it to the user).
2072 * So, using 3 (identical) IV outputs. 1986 * So, using 3 (identical) IV outputs.
2073 */ 1987 */
2074 ssi_req.ivgen_dma_addr[0] = areq_ctx->gen_ctx.iv_dma_addr + CCM_BLOCK_IV_OFFSET; 1988 cc_req.ivgen_dma_addr[0] =
2075 ssi_req.ivgen_dma_addr[1] = sg_dma_address(&areq_ctx->ccm_adata_sg) + CCM_B0_OFFSET + CCM_BLOCK_IV_OFFSET; 1989 areq_ctx->gen_ctx.iv_dma_addr +
2076 ssi_req.ivgen_dma_addr[2] = sg_dma_address(&areq_ctx->ccm_adata_sg) + CCM_CTR_COUNT_0_OFFSET + CCM_BLOCK_IV_OFFSET; 1990 CCM_BLOCK_IV_OFFSET;
2077 ssi_req.ivgen_dma_addr_len = 3; 1991 cc_req.ivgen_dma_addr[1] =
1992 sg_dma_address(&areq_ctx->ccm_adata_sg) +
1993 CCM_B0_OFFSET + CCM_BLOCK_IV_OFFSET;
1994 cc_req.ivgen_dma_addr[2] =
1995 sg_dma_address(&areq_ctx->ccm_adata_sg) +
1996 CCM_CTR_COUNT_0_OFFSET + CCM_BLOCK_IV_OFFSET;
1997 cc_req.ivgen_dma_addr_len = 3;
2078 } else { 1998 } else {
2079 ssi_req.ivgen_dma_addr[0] = areq_ctx->gen_ctx.iv_dma_addr; 1999 cc_req.ivgen_dma_addr[0] =
2080 ssi_req.ivgen_dma_addr_len = 1; 2000 areq_ctx->gen_ctx.iv_dma_addr;
2001 cc_req.ivgen_dma_addr_len = 1;
2081 } 2002 }
2082 2003
2083 /* set the IV size (8/16 B long)*/ 2004 /* set the IV size (8/16 B long)*/
2084 ssi_req.ivgen_size = crypto_aead_ivsize(tfm); 2005 cc_req.ivgen_size = crypto_aead_ivsize(tfm);
2085 } 2006 }
2086 2007
2087 /* STAT_PHASE_2: Create sequence */ 2008 /* STAT_PHASE_2: Create sequence */
2088 2009
2089 /* Load MLLI tables to SRAM if necessary */ 2010 /* Load MLLI tables to SRAM if necessary */
2090 ssi_aead_load_mlli_to_sram(req, desc, &seq_len); 2011 cc_mlli_to_sram(req, desc, &seq_len);
2091 2012
2092 /*TODO: move seq len by reference */ 2013 /*TODO: move seq len by reference */
2093 switch (ctx->auth_mode) { 2014 switch (ctx->auth_mode) {
2094 case DRV_HASH_SHA1: 2015 case DRV_HASH_SHA1:
2095 case DRV_HASH_SHA256: 2016 case DRV_HASH_SHA256:
2096 ssi_aead_hmac_authenc(req, desc, &seq_len); 2017 cc_hmac_authenc(req, desc, &seq_len);
2097 break; 2018 break;
2098 case DRV_HASH_XCBC_MAC: 2019 case DRV_HASH_XCBC_MAC:
2099 ssi_aead_xcbc_authenc(req, desc, &seq_len); 2020 cc_xcbc_authenc(req, desc, &seq_len);
2100 break; 2021 break;
2101#if (SSI_CC_HAS_AES_CCM || SSI_CC_HAS_AES_GCM)
2102 case DRV_HASH_NULL: 2022 case DRV_HASH_NULL:
2103#if SSI_CC_HAS_AES_CCM
2104 if (ctx->cipher_mode == DRV_CIPHER_CCM) 2023 if (ctx->cipher_mode == DRV_CIPHER_CCM)
2105 ssi_aead_ccm(req, desc, &seq_len); 2024 cc_ccm(req, desc, &seq_len);
2106#endif /*SSI_CC_HAS_AES_CCM*/
2107#if SSI_CC_HAS_AES_GCM
2108 if (ctx->cipher_mode == DRV_CIPHER_GCTR) 2025 if (ctx->cipher_mode == DRV_CIPHER_GCTR)
2109 ssi_aead_gcm(req, desc, &seq_len); 2026 cc_gcm(req, desc, &seq_len);
2110#endif /*SSI_CC_HAS_AES_GCM*/ 2027 break;
2111 break;
2112#endif
2113 default: 2028 default:
2114 dev_err(dev, "Unsupported authenc (%d)\n", ctx->auth_mode); 2029 dev_err(dev, "Unsupported authenc (%d)\n", ctx->auth_mode);
2115 ssi_buffer_mgr_unmap_aead_request(dev, req); 2030 cc_unmap_aead_request(dev, req);
2116 rc = -ENOTSUPP; 2031 rc = -ENOTSUPP;
2117 goto exit; 2032 goto exit;
2118 } 2033 }
2119 2034
2120 /* STAT_PHASE_3: Lock HW and push sequence */ 2035 /* STAT_PHASE_3: Lock HW and push sequence */
2121 2036
2122 rc = send_request(ctx->drvdata, &ssi_req, desc, seq_len, 1); 2037 rc = cc_send_request(ctx->drvdata, &cc_req, desc, seq_len, &req->base);
2123 2038
2124 if (unlikely(rc != -EINPROGRESS)) { 2039 if (rc != -EINPROGRESS && rc != -EBUSY) {
2125 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 2040 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
2126 ssi_buffer_mgr_unmap_aead_request(dev, req); 2041 cc_unmap_aead_request(dev, req);
2127 } 2042 }
2128 2043
2129exit: 2044exit:
2130 return rc; 2045 return rc;
2131} 2046}
2132 2047
2133static int ssi_aead_encrypt(struct aead_request *req) 2048static int cc_aead_encrypt(struct aead_request *req)
2134{ 2049{
2135 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 2050 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2136 int rc; 2051 int rc;
@@ -2142,21 +2057,20 @@ static int ssi_aead_encrypt(struct aead_request *req)
2142 2057
2143 areq_ctx->plaintext_authenticate_only = false; 2058 areq_ctx->plaintext_authenticate_only = false;
2144 2059
2145 rc = ssi_aead_process(req, DRV_CRYPTO_DIRECTION_ENCRYPT); 2060 rc = cc_proc_aead(req, DRV_CRYPTO_DIRECTION_ENCRYPT);
2146 if (rc != -EINPROGRESS) 2061 if (rc != -EINPROGRESS && rc != -EBUSY)
2147 req->iv = areq_ctx->backup_iv; 2062 req->iv = areq_ctx->backup_iv;
2148 2063
2149 return rc; 2064 return rc;
2150} 2065}
2151 2066
2152#if SSI_CC_HAS_AES_CCM 2067static int cc_rfc4309_ccm_encrypt(struct aead_request *req)
2153static int ssi_rfc4309_ccm_encrypt(struct aead_request *req)
2154{ 2068{
2155 /* Very similar to ssi_aead_encrypt() above. */ 2069 /* Very similar to cc_aead_encrypt() above. */
2156 2070
2157 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 2071 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2158 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 2072 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2159 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 2073 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2160 struct device *dev = drvdata_to_dev(ctx->drvdata); 2074 struct device *dev = drvdata_to_dev(ctx->drvdata);
2161 int rc = -EINVAL; 2075 int rc = -EINVAL;
2162 2076
@@ -2170,17 +2084,16 @@ static int ssi_rfc4309_ccm_encrypt(struct aead_request *req)
2170 areq_ctx->backup_giv = NULL; 2084 areq_ctx->backup_giv = NULL;
2171 areq_ctx->is_gcm4543 = true; 2085 areq_ctx->is_gcm4543 = true;
2172 2086
2173 ssi_rfc4309_ccm_process(req); 2087 cc_proc_rfc4309_ccm(req);
2174 2088
2175 rc = ssi_aead_process(req, DRV_CRYPTO_DIRECTION_ENCRYPT); 2089 rc = cc_proc_aead(req, DRV_CRYPTO_DIRECTION_ENCRYPT);
2176 if (rc != -EINPROGRESS) 2090 if (rc != -EINPROGRESS && rc != -EBUSY)
2177 req->iv = areq_ctx->backup_iv; 2091 req->iv = areq_ctx->backup_iv;
2178out: 2092out:
2179 return rc; 2093 return rc;
2180} 2094}
2181#endif /* SSI_CC_HAS_AES_CCM */
2182 2095
2183static int ssi_aead_decrypt(struct aead_request *req) 2096static int cc_aead_decrypt(struct aead_request *req)
2184{ 2097{
2185 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 2098 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2186 int rc; 2099 int rc;
@@ -2192,18 +2105,17 @@ static int ssi_aead_decrypt(struct aead_request *req)
2192 2105
2193 areq_ctx->plaintext_authenticate_only = false; 2106 areq_ctx->plaintext_authenticate_only = false;
2194 2107
2195 rc = ssi_aead_process(req, DRV_CRYPTO_DIRECTION_DECRYPT); 2108 rc = cc_proc_aead(req, DRV_CRYPTO_DIRECTION_DECRYPT);
2196 if (rc != -EINPROGRESS) 2109 if (rc != -EINPROGRESS && rc != -EBUSY)
2197 req->iv = areq_ctx->backup_iv; 2110 req->iv = areq_ctx->backup_iv;
2198 2111
2199 return rc; 2112 return rc;
2200} 2113}
2201 2114
2202#if SSI_CC_HAS_AES_CCM 2115static int cc_rfc4309_ccm_decrypt(struct aead_request *req)
2203static int ssi_rfc4309_ccm_decrypt(struct aead_request *req)
2204{ 2116{
2205 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 2117 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2206 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 2118 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2207 struct device *dev = drvdata_to_dev(ctx->drvdata); 2119 struct device *dev = drvdata_to_dev(ctx->drvdata);
2208 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 2120 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2209 int rc = -EINVAL; 2121 int rc = -EINVAL;
@@ -2218,22 +2130,20 @@ static int ssi_rfc4309_ccm_decrypt(struct aead_request *req)
2218 areq_ctx->backup_giv = NULL; 2130 areq_ctx->backup_giv = NULL;
2219 2131
2220 areq_ctx->is_gcm4543 = true; 2132 areq_ctx->is_gcm4543 = true;
2221 ssi_rfc4309_ccm_process(req); 2133 cc_proc_rfc4309_ccm(req);
2222 2134
2223 rc = ssi_aead_process(req, DRV_CRYPTO_DIRECTION_DECRYPT); 2135 rc = cc_proc_aead(req, DRV_CRYPTO_DIRECTION_DECRYPT);
2224 if (rc != -EINPROGRESS) 2136 if (rc != -EINPROGRESS && rc != -EBUSY)
2225 req->iv = areq_ctx->backup_iv; 2137 req->iv = areq_ctx->backup_iv;
2226 2138
2227out: 2139out:
2228 return rc; 2140 return rc;
2229} 2141}
2230#endif /* SSI_CC_HAS_AES_CCM */
2231
2232#if SSI_CC_HAS_AES_GCM
2233 2142
2234static int ssi_rfc4106_gcm_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) 2143static int cc_rfc4106_gcm_setkey(struct crypto_aead *tfm, const u8 *key,
2144 unsigned int keylen)
2235{ 2145{
2236 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 2146 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2237 struct device *dev = drvdata_to_dev(ctx->drvdata); 2147 struct device *dev = drvdata_to_dev(ctx->drvdata);
2238 2148
2239 dev_dbg(dev, "%s() keylen %d, key %p\n", __func__, keylen, key); 2149 dev_dbg(dev, "%s() keylen %d, key %p\n", __func__, keylen, key);
@@ -2244,12 +2154,13 @@ static int ssi_rfc4106_gcm_setkey(struct crypto_aead *tfm, const u8 *key, unsign
2244 keylen -= 4; 2154 keylen -= 4;
2245 memcpy(ctx->ctr_nonce, key + keylen, 4); 2155 memcpy(ctx->ctr_nonce, key + keylen, 4);
2246 2156
2247 return ssi_aead_setkey(tfm, key, keylen); 2157 return cc_aead_setkey(tfm, key, keylen);
2248} 2158}
2249 2159
2250static int ssi_rfc4543_gcm_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) 2160static int cc_rfc4543_gcm_setkey(struct crypto_aead *tfm, const u8 *key,
2161 unsigned int keylen)
2251{ 2162{
2252 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 2163 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2253 struct device *dev = drvdata_to_dev(ctx->drvdata); 2164 struct device *dev = drvdata_to_dev(ctx->drvdata);
2254 2165
2255 dev_dbg(dev, "%s() keylen %d, key %p\n", __func__, keylen, key); 2166 dev_dbg(dev, "%s() keylen %d, key %p\n", __func__, keylen, key);
@@ -2260,11 +2171,11 @@ static int ssi_rfc4543_gcm_setkey(struct crypto_aead *tfm, const u8 *key, unsign
2260 keylen -= 4; 2171 keylen -= 4;
2261 memcpy(ctx->ctr_nonce, key + keylen, 4); 2172 memcpy(ctx->ctr_nonce, key + keylen, 4);
2262 2173
2263 return ssi_aead_setkey(tfm, key, keylen); 2174 return cc_aead_setkey(tfm, key, keylen);
2264} 2175}
2265 2176
2266static int ssi_gcm_setauthsize(struct crypto_aead *authenc, 2177static int cc_gcm_setauthsize(struct crypto_aead *authenc,
2267 unsigned int authsize) 2178 unsigned int authsize)
2268{ 2179{
2269 switch (authsize) { 2180 switch (authsize) {
2270 case 4: 2181 case 4:
@@ -2279,13 +2190,13 @@ static int ssi_gcm_setauthsize(struct crypto_aead *authenc,
2279 return -EINVAL; 2190 return -EINVAL;
2280 } 2191 }
2281 2192
2282 return ssi_aead_setauthsize(authenc, authsize); 2193 return cc_aead_setauthsize(authenc, authsize);
2283} 2194}
2284 2195
2285static int ssi_rfc4106_gcm_setauthsize(struct crypto_aead *authenc, 2196static int cc_rfc4106_gcm_setauthsize(struct crypto_aead *authenc,
2286 unsigned int authsize) 2197 unsigned int authsize)
2287{ 2198{
2288 struct ssi_aead_ctx *ctx = crypto_aead_ctx(authenc); 2199 struct cc_aead_ctx *ctx = crypto_aead_ctx(authenc);
2289 struct device *dev = drvdata_to_dev(ctx->drvdata); 2200 struct device *dev = drvdata_to_dev(ctx->drvdata);
2290 2201
2291 dev_dbg(dev, "authsize %d\n", authsize); 2202 dev_dbg(dev, "authsize %d\n", authsize);
@@ -2299,13 +2210,13 @@ static int ssi_rfc4106_gcm_setauthsize(struct crypto_aead *authenc,
2299 return -EINVAL; 2210 return -EINVAL;
2300 } 2211 }
2301 2212
2302 return ssi_aead_setauthsize(authenc, authsize); 2213 return cc_aead_setauthsize(authenc, authsize);
2303} 2214}
2304 2215
2305static int ssi_rfc4543_gcm_setauthsize(struct crypto_aead *authenc, 2216static int cc_rfc4543_gcm_setauthsize(struct crypto_aead *authenc,
2306 unsigned int authsize) 2217 unsigned int authsize)
2307{ 2218{
2308 struct ssi_aead_ctx *ctx = crypto_aead_ctx(authenc); 2219 struct cc_aead_ctx *ctx = crypto_aead_ctx(authenc);
2309 struct device *dev = drvdata_to_dev(ctx->drvdata); 2220 struct device *dev = drvdata_to_dev(ctx->drvdata);
2310 2221
2311 dev_dbg(dev, "authsize %d\n", authsize); 2222 dev_dbg(dev, "authsize %d\n", authsize);
@@ -2313,15 +2224,15 @@ static int ssi_rfc4543_gcm_setauthsize(struct crypto_aead *authenc,
2313 if (authsize != 16) 2224 if (authsize != 16)
2314 return -EINVAL; 2225 return -EINVAL;
2315 2226
2316 return ssi_aead_setauthsize(authenc, authsize); 2227 return cc_aead_setauthsize(authenc, authsize);
2317} 2228}
2318 2229
2319static int ssi_rfc4106_gcm_encrypt(struct aead_request *req) 2230static int cc_rfc4106_gcm_encrypt(struct aead_request *req)
2320{ 2231{
2321 /* Very similar to ssi_aead_encrypt() above. */ 2232 /* Very similar to cc_aead_encrypt() above. */
2322 2233
2323 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 2234 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2324 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 2235 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2325 struct device *dev = drvdata_to_dev(ctx->drvdata); 2236 struct device *dev = drvdata_to_dev(ctx->drvdata);
2326 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 2237 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2327 int rc = -EINVAL; 2238 int rc = -EINVAL;
@@ -2337,19 +2248,19 @@ static int ssi_rfc4106_gcm_encrypt(struct aead_request *req)
2337 2248
2338 areq_ctx->plaintext_authenticate_only = false; 2249 areq_ctx->plaintext_authenticate_only = false;
2339 2250
2340 ssi_rfc4_gcm_process(req); 2251 cc_proc_rfc4_gcm(req);
2341 areq_ctx->is_gcm4543 = true; 2252 areq_ctx->is_gcm4543 = true;
2342 2253
2343 rc = ssi_aead_process(req, DRV_CRYPTO_DIRECTION_ENCRYPT); 2254 rc = cc_proc_aead(req, DRV_CRYPTO_DIRECTION_ENCRYPT);
2344 if (rc != -EINPROGRESS) 2255 if (rc != -EINPROGRESS && rc != -EBUSY)
2345 req->iv = areq_ctx->backup_iv; 2256 req->iv = areq_ctx->backup_iv;
2346out: 2257out:
2347 return rc; 2258 return rc;
2348} 2259}
2349 2260
2350static int ssi_rfc4543_gcm_encrypt(struct aead_request *req) 2261static int cc_rfc4543_gcm_encrypt(struct aead_request *req)
2351{ 2262{
2352 /* Very similar to ssi_aead_encrypt() above. */ 2263 /* Very similar to cc_aead_encrypt() above. */
2353 2264
2354 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 2265 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2355 int rc; 2266 int rc;
@@ -2361,22 +2272,22 @@ static int ssi_rfc4543_gcm_encrypt(struct aead_request *req)
2361 areq_ctx->backup_iv = req->iv; 2272 areq_ctx->backup_iv = req->iv;
2362 areq_ctx->backup_giv = NULL; 2273 areq_ctx->backup_giv = NULL;
2363 2274
2364 ssi_rfc4_gcm_process(req); 2275 cc_proc_rfc4_gcm(req);
2365 areq_ctx->is_gcm4543 = true; 2276 areq_ctx->is_gcm4543 = true;
2366 2277
2367 rc = ssi_aead_process(req, DRV_CRYPTO_DIRECTION_ENCRYPT); 2278 rc = cc_proc_aead(req, DRV_CRYPTO_DIRECTION_ENCRYPT);
2368 if (rc != -EINPROGRESS) 2279 if (rc != -EINPROGRESS && rc != -EBUSY)
2369 req->iv = areq_ctx->backup_iv; 2280 req->iv = areq_ctx->backup_iv;
2370 2281
2371 return rc; 2282 return rc;
2372} 2283}
2373 2284
2374static int ssi_rfc4106_gcm_decrypt(struct aead_request *req) 2285static int cc_rfc4106_gcm_decrypt(struct aead_request *req)
2375{ 2286{
2376 /* Very similar to ssi_aead_decrypt() above. */ 2287 /* Very similar to cc_aead_decrypt() above. */
2377 2288
2378 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 2289 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2379 struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); 2290 struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2380 struct device *dev = drvdata_to_dev(ctx->drvdata); 2291 struct device *dev = drvdata_to_dev(ctx->drvdata);
2381 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 2292 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2382 int rc = -EINVAL; 2293 int rc = -EINVAL;
@@ -2392,19 +2303,19 @@ static int ssi_rfc4106_gcm_decrypt(struct aead_request *req)
2392 2303
2393 areq_ctx->plaintext_authenticate_only = false; 2304 areq_ctx->plaintext_authenticate_only = false;
2394 2305
2395 ssi_rfc4_gcm_process(req); 2306 cc_proc_rfc4_gcm(req);
2396 areq_ctx->is_gcm4543 = true; 2307 areq_ctx->is_gcm4543 = true;
2397 2308
2398 rc = ssi_aead_process(req, DRV_CRYPTO_DIRECTION_DECRYPT); 2309 rc = cc_proc_aead(req, DRV_CRYPTO_DIRECTION_DECRYPT);
2399 if (rc != -EINPROGRESS) 2310 if (rc != -EINPROGRESS && rc != -EBUSY)
2400 req->iv = areq_ctx->backup_iv; 2311 req->iv = areq_ctx->backup_iv;
2401out: 2312out:
2402 return rc; 2313 return rc;
2403} 2314}
2404 2315
2405static int ssi_rfc4543_gcm_decrypt(struct aead_request *req) 2316static int cc_rfc4543_gcm_decrypt(struct aead_request *req)
2406{ 2317{
2407 /* Very similar to ssi_aead_decrypt() above. */ 2318 /* Very similar to cc_aead_decrypt() above. */
2408 2319
2409 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 2320 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2410 int rc; 2321 int rc;
@@ -2416,31 +2327,30 @@ static int ssi_rfc4543_gcm_decrypt(struct aead_request *req)
2416 areq_ctx->backup_iv = req->iv; 2327 areq_ctx->backup_iv = req->iv;
2417 areq_ctx->backup_giv = NULL; 2328 areq_ctx->backup_giv = NULL;
2418 2329
2419 ssi_rfc4_gcm_process(req); 2330 cc_proc_rfc4_gcm(req);
2420 areq_ctx->is_gcm4543 = true; 2331 areq_ctx->is_gcm4543 = true;
2421 2332
2422 rc = ssi_aead_process(req, DRV_CRYPTO_DIRECTION_DECRYPT); 2333 rc = cc_proc_aead(req, DRV_CRYPTO_DIRECTION_DECRYPT);
2423 if (rc != -EINPROGRESS) 2334 if (rc != -EINPROGRESS && rc != -EBUSY)
2424 req->iv = areq_ctx->backup_iv; 2335 req->iv = areq_ctx->backup_iv;
2425 2336
2426 return rc; 2337 return rc;
2427} 2338}
2428#endif /* SSI_CC_HAS_AES_GCM */
2429 2339
2430/* DX Block aead alg */ 2340/* DX Block aead alg */
2431static struct ssi_alg_template aead_algs[] = { 2341static struct cc_alg_template aead_algs[] = {
2432 { 2342 {
2433 .name = "authenc(hmac(sha1),cbc(aes))", 2343 .name = "authenc(hmac(sha1),cbc(aes))",
2434 .driver_name = "authenc-hmac-sha1-cbc-aes-dx", 2344 .driver_name = "authenc-hmac-sha1-cbc-aes-dx",
2435 .blocksize = AES_BLOCK_SIZE, 2345 .blocksize = AES_BLOCK_SIZE,
2436 .type = CRYPTO_ALG_TYPE_AEAD, 2346 .type = CRYPTO_ALG_TYPE_AEAD,
2437 .template_aead = { 2347 .template_aead = {
2438 .setkey = ssi_aead_setkey, 2348 .setkey = cc_aead_setkey,
2439 .setauthsize = ssi_aead_setauthsize, 2349 .setauthsize = cc_aead_setauthsize,
2440 .encrypt = ssi_aead_encrypt, 2350 .encrypt = cc_aead_encrypt,
2441 .decrypt = ssi_aead_decrypt, 2351 .decrypt = cc_aead_decrypt,
2442 .init = ssi_aead_init, 2352 .init = cc_aead_init,
2443 .exit = ssi_aead_exit, 2353 .exit = cc_aead_exit,
2444 .ivsize = AES_BLOCK_SIZE, 2354 .ivsize = AES_BLOCK_SIZE,
2445 .maxauthsize = SHA1_DIGEST_SIZE, 2355 .maxauthsize = SHA1_DIGEST_SIZE,
2446 }, 2356 },
@@ -2454,12 +2364,12 @@ static struct ssi_alg_template aead_algs[] = {
2454 .blocksize = DES3_EDE_BLOCK_SIZE, 2364 .blocksize = DES3_EDE_BLOCK_SIZE,
2455 .type = CRYPTO_ALG_TYPE_AEAD, 2365 .type = CRYPTO_ALG_TYPE_AEAD,
2456 .template_aead = { 2366 .template_aead = {
2457 .setkey = ssi_aead_setkey, 2367 .setkey = cc_aead_setkey,
2458 .setauthsize = ssi_aead_setauthsize, 2368 .setauthsize = cc_aead_setauthsize,
2459 .encrypt = ssi_aead_encrypt, 2369 .encrypt = cc_aead_encrypt,
2460 .decrypt = ssi_aead_decrypt, 2370 .decrypt = cc_aead_decrypt,
2461 .init = ssi_aead_init, 2371 .init = cc_aead_init,
2462 .exit = ssi_aead_exit, 2372 .exit = cc_aead_exit,
2463 .ivsize = DES3_EDE_BLOCK_SIZE, 2373 .ivsize = DES3_EDE_BLOCK_SIZE,
2464 .maxauthsize = SHA1_DIGEST_SIZE, 2374 .maxauthsize = SHA1_DIGEST_SIZE,
2465 }, 2375 },
@@ -2473,12 +2383,12 @@ static struct ssi_alg_template aead_algs[] = {
2473 .blocksize = AES_BLOCK_SIZE, 2383 .blocksize = AES_BLOCK_SIZE,
2474 .type = CRYPTO_ALG_TYPE_AEAD, 2384 .type = CRYPTO_ALG_TYPE_AEAD,
2475 .template_aead = { 2385 .template_aead = {
2476 .setkey = ssi_aead_setkey, 2386 .setkey = cc_aead_setkey,
2477 .setauthsize = ssi_aead_setauthsize, 2387 .setauthsize = cc_aead_setauthsize,
2478 .encrypt = ssi_aead_encrypt, 2388 .encrypt = cc_aead_encrypt,
2479 .decrypt = ssi_aead_decrypt, 2389 .decrypt = cc_aead_decrypt,
2480 .init = ssi_aead_init, 2390 .init = cc_aead_init,
2481 .exit = ssi_aead_exit, 2391 .exit = cc_aead_exit,
2482 .ivsize = AES_BLOCK_SIZE, 2392 .ivsize = AES_BLOCK_SIZE,
2483 .maxauthsize = SHA256_DIGEST_SIZE, 2393 .maxauthsize = SHA256_DIGEST_SIZE,
2484 }, 2394 },
@@ -2492,12 +2402,12 @@ static struct ssi_alg_template aead_algs[] = {
2492 .blocksize = DES3_EDE_BLOCK_SIZE, 2402 .blocksize = DES3_EDE_BLOCK_SIZE,
2493 .type = CRYPTO_ALG_TYPE_AEAD, 2403 .type = CRYPTO_ALG_TYPE_AEAD,
2494 .template_aead = { 2404 .template_aead = {
2495 .setkey = ssi_aead_setkey, 2405 .setkey = cc_aead_setkey,
2496 .setauthsize = ssi_aead_setauthsize, 2406 .setauthsize = cc_aead_setauthsize,
2497 .encrypt = ssi_aead_encrypt, 2407 .encrypt = cc_aead_encrypt,
2498 .decrypt = ssi_aead_decrypt, 2408 .decrypt = cc_aead_decrypt,
2499 .init = ssi_aead_init, 2409 .init = cc_aead_init,
2500 .exit = ssi_aead_exit, 2410 .exit = cc_aead_exit,
2501 .ivsize = DES3_EDE_BLOCK_SIZE, 2411 .ivsize = DES3_EDE_BLOCK_SIZE,
2502 .maxauthsize = SHA256_DIGEST_SIZE, 2412 .maxauthsize = SHA256_DIGEST_SIZE,
2503 }, 2413 },
@@ -2511,12 +2421,12 @@ static struct ssi_alg_template aead_algs[] = {
2511 .blocksize = AES_BLOCK_SIZE, 2421 .blocksize = AES_BLOCK_SIZE,
2512 .type = CRYPTO_ALG_TYPE_AEAD, 2422 .type = CRYPTO_ALG_TYPE_AEAD,
2513 .template_aead = { 2423 .template_aead = {
2514 .setkey = ssi_aead_setkey, 2424 .setkey = cc_aead_setkey,
2515 .setauthsize = ssi_aead_setauthsize, 2425 .setauthsize = cc_aead_setauthsize,
2516 .encrypt = ssi_aead_encrypt, 2426 .encrypt = cc_aead_encrypt,
2517 .decrypt = ssi_aead_decrypt, 2427 .decrypt = cc_aead_decrypt,
2518 .init = ssi_aead_init, 2428 .init = cc_aead_init,
2519 .exit = ssi_aead_exit, 2429 .exit = cc_aead_exit,
2520 .ivsize = AES_BLOCK_SIZE, 2430 .ivsize = AES_BLOCK_SIZE,
2521 .maxauthsize = AES_BLOCK_SIZE, 2431 .maxauthsize = AES_BLOCK_SIZE,
2522 }, 2432 },
@@ -2530,12 +2440,12 @@ static struct ssi_alg_template aead_algs[] = {
2530 .blocksize = 1, 2440 .blocksize = 1,
2531 .type = CRYPTO_ALG_TYPE_AEAD, 2441 .type = CRYPTO_ALG_TYPE_AEAD,
2532 .template_aead = { 2442 .template_aead = {
2533 .setkey = ssi_aead_setkey, 2443 .setkey = cc_aead_setkey,
2534 .setauthsize = ssi_aead_setauthsize, 2444 .setauthsize = cc_aead_setauthsize,
2535 .encrypt = ssi_aead_encrypt, 2445 .encrypt = cc_aead_encrypt,
2536 .decrypt = ssi_aead_decrypt, 2446 .decrypt = cc_aead_decrypt,
2537 .init = ssi_aead_init, 2447 .init = cc_aead_init,
2538 .exit = ssi_aead_exit, 2448 .exit = cc_aead_exit,
2539 .ivsize = CTR_RFC3686_IV_SIZE, 2449 .ivsize = CTR_RFC3686_IV_SIZE,
2540 .maxauthsize = SHA1_DIGEST_SIZE, 2450 .maxauthsize = SHA1_DIGEST_SIZE,
2541 }, 2451 },
@@ -2549,12 +2459,12 @@ static struct ssi_alg_template aead_algs[] = {
2549 .blocksize = 1, 2459 .blocksize = 1,
2550 .type = CRYPTO_ALG_TYPE_AEAD, 2460 .type = CRYPTO_ALG_TYPE_AEAD,
2551 .template_aead = { 2461 .template_aead = {
2552 .setkey = ssi_aead_setkey, 2462 .setkey = cc_aead_setkey,
2553 .setauthsize = ssi_aead_setauthsize, 2463 .setauthsize = cc_aead_setauthsize,
2554 .encrypt = ssi_aead_encrypt, 2464 .encrypt = cc_aead_encrypt,
2555 .decrypt = ssi_aead_decrypt, 2465 .decrypt = cc_aead_decrypt,
2556 .init = ssi_aead_init, 2466 .init = cc_aead_init,
2557 .exit = ssi_aead_exit, 2467 .exit = cc_aead_exit,
2558 .ivsize = CTR_RFC3686_IV_SIZE, 2468 .ivsize = CTR_RFC3686_IV_SIZE,
2559 .maxauthsize = SHA256_DIGEST_SIZE, 2469 .maxauthsize = SHA256_DIGEST_SIZE,
2560 }, 2470 },
@@ -2568,12 +2478,12 @@ static struct ssi_alg_template aead_algs[] = {
2568 .blocksize = 1, 2478 .blocksize = 1,
2569 .type = CRYPTO_ALG_TYPE_AEAD, 2479 .type = CRYPTO_ALG_TYPE_AEAD,
2570 .template_aead = { 2480 .template_aead = {
2571 .setkey = ssi_aead_setkey, 2481 .setkey = cc_aead_setkey,
2572 .setauthsize = ssi_aead_setauthsize, 2482 .setauthsize = cc_aead_setauthsize,
2573 .encrypt = ssi_aead_encrypt, 2483 .encrypt = cc_aead_encrypt,
2574 .decrypt = ssi_aead_decrypt, 2484 .decrypt = cc_aead_decrypt,
2575 .init = ssi_aead_init, 2485 .init = cc_aead_init,
2576 .exit = ssi_aead_exit, 2486 .exit = cc_aead_exit,
2577 .ivsize = CTR_RFC3686_IV_SIZE, 2487 .ivsize = CTR_RFC3686_IV_SIZE,
2578 .maxauthsize = AES_BLOCK_SIZE, 2488 .maxauthsize = AES_BLOCK_SIZE,
2579 }, 2489 },
@@ -2581,19 +2491,18 @@ static struct ssi_alg_template aead_algs[] = {
2581 .flow_mode = S_DIN_to_AES, 2491 .flow_mode = S_DIN_to_AES,
2582 .auth_mode = DRV_HASH_XCBC_MAC, 2492 .auth_mode = DRV_HASH_XCBC_MAC,
2583 }, 2493 },
2584#if SSI_CC_HAS_AES_CCM
2585 { 2494 {
2586 .name = "ccm(aes)", 2495 .name = "ccm(aes)",
2587 .driver_name = "ccm-aes-dx", 2496 .driver_name = "ccm-aes-dx",
2588 .blocksize = 1, 2497 .blocksize = 1,
2589 .type = CRYPTO_ALG_TYPE_AEAD, 2498 .type = CRYPTO_ALG_TYPE_AEAD,
2590 .template_aead = { 2499 .template_aead = {
2591 .setkey = ssi_aead_setkey, 2500 .setkey = cc_aead_setkey,
2592 .setauthsize = ssi_ccm_setauthsize, 2501 .setauthsize = cc_ccm_setauthsize,
2593 .encrypt = ssi_aead_encrypt, 2502 .encrypt = cc_aead_encrypt,
2594 .decrypt = ssi_aead_decrypt, 2503 .decrypt = cc_aead_decrypt,
2595 .init = ssi_aead_init, 2504 .init = cc_aead_init,
2596 .exit = ssi_aead_exit, 2505 .exit = cc_aead_exit,
2597 .ivsize = AES_BLOCK_SIZE, 2506 .ivsize = AES_BLOCK_SIZE,
2598 .maxauthsize = AES_BLOCK_SIZE, 2507 .maxauthsize = AES_BLOCK_SIZE,
2599 }, 2508 },
@@ -2607,12 +2516,12 @@ static struct ssi_alg_template aead_algs[] = {
2607 .blocksize = 1, 2516 .blocksize = 1,
2608 .type = CRYPTO_ALG_TYPE_AEAD, 2517 .type = CRYPTO_ALG_TYPE_AEAD,
2609 .template_aead = { 2518 .template_aead = {
2610 .setkey = ssi_rfc4309_ccm_setkey, 2519 .setkey = cc_rfc4309_ccm_setkey,
2611 .setauthsize = ssi_rfc4309_ccm_setauthsize, 2520 .setauthsize = cc_rfc4309_ccm_setauthsize,
2612 .encrypt = ssi_rfc4309_ccm_encrypt, 2521 .encrypt = cc_rfc4309_ccm_encrypt,
2613 .decrypt = ssi_rfc4309_ccm_decrypt, 2522 .decrypt = cc_rfc4309_ccm_decrypt,
2614 .init = ssi_aead_init, 2523 .init = cc_aead_init,
2615 .exit = ssi_aead_exit, 2524 .exit = cc_aead_exit,
2616 .ivsize = CCM_BLOCK_IV_SIZE, 2525 .ivsize = CCM_BLOCK_IV_SIZE,
2617 .maxauthsize = AES_BLOCK_SIZE, 2526 .maxauthsize = AES_BLOCK_SIZE,
2618 }, 2527 },
@@ -2620,20 +2529,18 @@ static struct ssi_alg_template aead_algs[] = {
2620 .flow_mode = S_DIN_to_AES, 2529 .flow_mode = S_DIN_to_AES,
2621 .auth_mode = DRV_HASH_NULL, 2530 .auth_mode = DRV_HASH_NULL,
2622 }, 2531 },
2623#endif /*SSI_CC_HAS_AES_CCM*/
2624#if SSI_CC_HAS_AES_GCM
2625 { 2532 {
2626 .name = "gcm(aes)", 2533 .name = "gcm(aes)",
2627 .driver_name = "gcm-aes-dx", 2534 .driver_name = "gcm-aes-dx",
2628 .blocksize = 1, 2535 .blocksize = 1,
2629 .type = CRYPTO_ALG_TYPE_AEAD, 2536 .type = CRYPTO_ALG_TYPE_AEAD,
2630 .template_aead = { 2537 .template_aead = {
2631 .setkey = ssi_aead_setkey, 2538 .setkey = cc_aead_setkey,
2632 .setauthsize = ssi_gcm_setauthsize, 2539 .setauthsize = cc_gcm_setauthsize,
2633 .encrypt = ssi_aead_encrypt, 2540 .encrypt = cc_aead_encrypt,
2634 .decrypt = ssi_aead_decrypt, 2541 .decrypt = cc_aead_decrypt,
2635 .init = ssi_aead_init, 2542 .init = cc_aead_init,
2636 .exit = ssi_aead_exit, 2543 .exit = cc_aead_exit,
2637 .ivsize = 12, 2544 .ivsize = 12,
2638 .maxauthsize = AES_BLOCK_SIZE, 2545 .maxauthsize = AES_BLOCK_SIZE,
2639 }, 2546 },
@@ -2647,12 +2554,12 @@ static struct ssi_alg_template aead_algs[] = {
2647 .blocksize = 1, 2554 .blocksize = 1,
2648 .type = CRYPTO_ALG_TYPE_AEAD, 2555 .type = CRYPTO_ALG_TYPE_AEAD,
2649 .template_aead = { 2556 .template_aead = {
2650 .setkey = ssi_rfc4106_gcm_setkey, 2557 .setkey = cc_rfc4106_gcm_setkey,
2651 .setauthsize = ssi_rfc4106_gcm_setauthsize, 2558 .setauthsize = cc_rfc4106_gcm_setauthsize,
2652 .encrypt = ssi_rfc4106_gcm_encrypt, 2559 .encrypt = cc_rfc4106_gcm_encrypt,
2653 .decrypt = ssi_rfc4106_gcm_decrypt, 2560 .decrypt = cc_rfc4106_gcm_decrypt,
2654 .init = ssi_aead_init, 2561 .init = cc_aead_init,
2655 .exit = ssi_aead_exit, 2562 .exit = cc_aead_exit,
2656 .ivsize = GCM_BLOCK_RFC4_IV_SIZE, 2563 .ivsize = GCM_BLOCK_RFC4_IV_SIZE,
2657 .maxauthsize = AES_BLOCK_SIZE, 2564 .maxauthsize = AES_BLOCK_SIZE,
2658 }, 2565 },
@@ -2666,12 +2573,12 @@ static struct ssi_alg_template aead_algs[] = {
2666 .blocksize = 1, 2573 .blocksize = 1,
2667 .type = CRYPTO_ALG_TYPE_AEAD, 2574 .type = CRYPTO_ALG_TYPE_AEAD,
2668 .template_aead = { 2575 .template_aead = {
2669 .setkey = ssi_rfc4543_gcm_setkey, 2576 .setkey = cc_rfc4543_gcm_setkey,
2670 .setauthsize = ssi_rfc4543_gcm_setauthsize, 2577 .setauthsize = cc_rfc4543_gcm_setauthsize,
2671 .encrypt = ssi_rfc4543_gcm_encrypt, 2578 .encrypt = cc_rfc4543_gcm_encrypt,
2672 .decrypt = ssi_rfc4543_gcm_decrypt, 2579 .decrypt = cc_rfc4543_gcm_decrypt,
2673 .init = ssi_aead_init, 2580 .init = cc_aead_init,
2674 .exit = ssi_aead_exit, 2581 .exit = cc_aead_exit,
2675 .ivsize = GCM_BLOCK_RFC4_IV_SIZE, 2582 .ivsize = GCM_BLOCK_RFC4_IV_SIZE,
2676 .maxauthsize = AES_BLOCK_SIZE, 2583 .maxauthsize = AES_BLOCK_SIZE,
2677 }, 2584 },
@@ -2679,52 +2586,51 @@ static struct ssi_alg_template aead_algs[] = {
2679 .flow_mode = S_DIN_to_AES, 2586 .flow_mode = S_DIN_to_AES,
2680 .auth_mode = DRV_HASH_NULL, 2587 .auth_mode = DRV_HASH_NULL,
2681 }, 2588 },
2682#endif /*SSI_CC_HAS_AES_GCM*/
2683}; 2589};
2684 2590
2685static struct ssi_crypto_alg *ssi_aead_create_alg( 2591static struct cc_crypto_alg *cc_create_aead_alg(struct cc_alg_template *tmpl,
2686 struct ssi_alg_template *template, 2592 struct device *dev)
2687 struct device *dev)
2688{ 2593{
2689 struct ssi_crypto_alg *t_alg; 2594 struct cc_crypto_alg *t_alg;
2690 struct aead_alg *alg; 2595 struct aead_alg *alg;
2691 2596
2692 t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL); 2597 t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
2693 if (!t_alg) 2598 if (!t_alg)
2694 return ERR_PTR(-ENOMEM); 2599 return ERR_PTR(-ENOMEM);
2695 2600
2696 alg = &template->template_aead; 2601 alg = &tmpl->template_aead;
2697 2602
2698 snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name); 2603 snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s", tmpl->name);
2699 snprintf(alg->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", 2604 snprintf(alg->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
2700 template->driver_name); 2605 tmpl->driver_name);
2701 alg->base.cra_module = THIS_MODULE; 2606 alg->base.cra_module = THIS_MODULE;
2702 alg->base.cra_priority = SSI_CRA_PRIO; 2607 alg->base.cra_priority = CC_CRA_PRIO;
2703 2608
2704 alg->base.cra_ctxsize = sizeof(struct ssi_aead_ctx); 2609 alg->base.cra_ctxsize = sizeof(struct cc_aead_ctx);
2705 alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY | 2610 alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
2706 template->type; 2611 tmpl->type;
2707 alg->init = ssi_aead_init; 2612 alg->init = cc_aead_init;
2708 alg->exit = ssi_aead_exit; 2613 alg->exit = cc_aead_exit;
2709 2614
2710 t_alg->aead_alg = *alg; 2615 t_alg->aead_alg = *alg;
2711 2616
2712 t_alg->cipher_mode = template->cipher_mode; 2617 t_alg->cipher_mode = tmpl->cipher_mode;
2713 t_alg->flow_mode = template->flow_mode; 2618 t_alg->flow_mode = tmpl->flow_mode;
2714 t_alg->auth_mode = template->auth_mode; 2619 t_alg->auth_mode = tmpl->auth_mode;
2715 2620
2716 return t_alg; 2621 return t_alg;
2717} 2622}
2718 2623
2719int ssi_aead_free(struct ssi_drvdata *drvdata) 2624int cc_aead_free(struct cc_drvdata *drvdata)
2720{ 2625{
2721 struct ssi_crypto_alg *t_alg, *n; 2626 struct cc_crypto_alg *t_alg, *n;
2722 struct ssi_aead_handle *aead_handle = 2627 struct cc_aead_handle *aead_handle =
2723 (struct ssi_aead_handle *)drvdata->aead_handle; 2628 (struct cc_aead_handle *)drvdata->aead_handle;
2724 2629
2725 if (aead_handle) { 2630 if (aead_handle) {
2726 /* Remove registered algs */ 2631 /* Remove registered algs */
2727 list_for_each_entry_safe(t_alg, n, &aead_handle->aead_list, entry) { 2632 list_for_each_entry_safe(t_alg, n, &aead_handle->aead_list,
2633 entry) {
2728 crypto_unregister_aead(&t_alg->aead_alg); 2634 crypto_unregister_aead(&t_alg->aead_alg);
2729 list_del(&t_alg->entry); 2635 list_del(&t_alg->entry);
2730 kfree(t_alg); 2636 kfree(t_alg);
@@ -2736,10 +2642,10 @@ int ssi_aead_free(struct ssi_drvdata *drvdata)
2736 return 0; 2642 return 0;
2737} 2643}
2738 2644
2739int ssi_aead_alloc(struct ssi_drvdata *drvdata) 2645int cc_aead_alloc(struct cc_drvdata *drvdata)
2740{ 2646{
2741 struct ssi_aead_handle *aead_handle; 2647 struct cc_aead_handle *aead_handle;
2742 struct ssi_crypto_alg *t_alg; 2648 struct cc_crypto_alg *t_alg;
2743 int rc = -ENOMEM; 2649 int rc = -ENOMEM;
2744 int alg; 2650 int alg;
2745 struct device *dev = drvdata_to_dev(drvdata); 2651 struct device *dev = drvdata_to_dev(drvdata);
@@ -2753,8 +2659,9 @@ int ssi_aead_alloc(struct ssi_drvdata *drvdata)
2753 INIT_LIST_HEAD(&aead_handle->aead_list); 2659 INIT_LIST_HEAD(&aead_handle->aead_list);
2754 drvdata->aead_handle = aead_handle; 2660 drvdata->aead_handle = aead_handle;
2755 2661
2756 aead_handle->sram_workspace_addr = ssi_sram_mgr_alloc( 2662 aead_handle->sram_workspace_addr = cc_sram_alloc(drvdata,
2757 drvdata, MAX_HMAC_DIGEST_SIZE); 2663 MAX_HMAC_DIGEST_SIZE);
2664
2758 if (aead_handle->sram_workspace_addr == NULL_SRAM_ADDR) { 2665 if (aead_handle->sram_workspace_addr == NULL_SRAM_ADDR) {
2759 dev_err(dev, "SRAM pool exhausted\n"); 2666 dev_err(dev, "SRAM pool exhausted\n");
2760 rc = -ENOMEM; 2667 rc = -ENOMEM;
@@ -2763,7 +2670,7 @@ int ssi_aead_alloc(struct ssi_drvdata *drvdata)
2763 2670
2764 /* Linux crypto */ 2671 /* Linux crypto */
2765 for (alg = 0; alg < ARRAY_SIZE(aead_algs); alg++) { 2672 for (alg = 0; alg < ARRAY_SIZE(aead_algs); alg++) {
2766 t_alg = ssi_aead_create_alg(&aead_algs[alg], dev); 2673 t_alg = cc_create_aead_alg(&aead_algs[alg], dev);
2767 if (IS_ERR(t_alg)) { 2674 if (IS_ERR(t_alg)) {
2768 rc = PTR_ERR(t_alg); 2675 rc = PTR_ERR(t_alg);
2769 dev_err(dev, "%s alg allocation failed\n", 2676 dev_err(dev, "%s alg allocation failed\n",
@@ -2772,7 +2679,7 @@ int ssi_aead_alloc(struct ssi_drvdata *drvdata)
2772 } 2679 }
2773 t_alg->drvdata = drvdata; 2680 t_alg->drvdata = drvdata;
2774 rc = crypto_register_aead(&t_alg->aead_alg); 2681 rc = crypto_register_aead(&t_alg->aead_alg);
2775 if (unlikely(rc != 0)) { 2682 if (rc) {
2776 dev_err(dev, "%s alg registration failed\n", 2683 dev_err(dev, "%s alg registration failed\n",
2777 t_alg->aead_alg.base.cra_driver_name); 2684 t_alg->aead_alg.base.cra_driver_name);
2778 goto fail2; 2685 goto fail2;
@@ -2788,7 +2695,7 @@ int ssi_aead_alloc(struct ssi_drvdata *drvdata)
2788fail2: 2695fail2:
2789 kfree(t_alg); 2696 kfree(t_alg);
2790fail1: 2697fail1:
2791 ssi_aead_free(drvdata); 2698 cc_aead_free(drvdata);
2792fail0: 2699fail0:
2793 return rc; 2700 return rc;
2794} 2701}
diff --git a/drivers/staging/ccree/ssi_aead.h b/drivers/staging/ccree/cc_aead.h
index e85bcd917e7b..5edf3b351fa4 100644
--- a/drivers/staging/ccree/ssi_aead.h
+++ b/drivers/staging/ccree/cc_aead.h
@@ -1,25 +1,12 @@
1/* 1/* SPDX-License-Identifier: GPL-2.0 */
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17/* \file ssi_aead.h 4/* \file cc_aead.h
18 * ARM CryptoCell AEAD Crypto API 5 * ARM CryptoCell AEAD Crypto API
19 */ 6 */
20 7
21#ifndef __SSI_AEAD_H__ 8#ifndef __CC_AEAD_H__
22#define __SSI_AEAD_H__ 9#define __CC_AEAD_H__
23 10
24#include <linux/kernel.h> 11#include <linux/kernel.h>
25#include <crypto/algapi.h> 12#include <crypto/algapi.h>
@@ -28,7 +15,7 @@
28/* mac_cmp - HW writes 8 B but all bytes hold the same value */ 15/* mac_cmp - HW writes 8 B but all bytes hold the same value */
29#define ICV_CMP_SIZE 8 16#define ICV_CMP_SIZE 8
30#define CCM_CONFIG_BUF_SIZE (AES_BLOCK_SIZE * 3) 17#define CCM_CONFIG_BUF_SIZE (AES_BLOCK_SIZE * 3)
31#define MAX_MAC_SIZE MAX(SHA256_DIGEST_SIZE, AES_BLOCK_SIZE) 18#define MAX_MAC_SIZE SHA256_DIGEST_SIZE
32 19
33/* defines for AES GCM configuration buffer */ 20/* defines for AES GCM configuration buffer */
34#define GCM_BLOCK_LEN_SIZE 8 21#define GCM_BLOCK_LEN_SIZE 8
@@ -74,32 +61,37 @@ struct aead_req_ctx {
74 } gcm_len_block; 61 } gcm_len_block;
75 62
76 u8 ccm_config[CCM_CONFIG_BUF_SIZE] ____cacheline_aligned; 63 u8 ccm_config[CCM_CONFIG_BUF_SIZE] ____cacheline_aligned;
77 unsigned int hw_iv_size ____cacheline_aligned; /*HW actual size input*/ 64 /* HW actual size input */
78 u8 backup_mac[MAX_MAC_SIZE]; /*used to prevent cache coherence problem*/ 65 unsigned int hw_iv_size ____cacheline_aligned;
66 /* used to prevent cache coherence problem */
67 u8 backup_mac[MAX_MAC_SIZE];
79 u8 *backup_iv; /*store iv for generated IV flow*/ 68 u8 *backup_iv; /*store iv for generated IV flow*/
80 u8 *backup_giv; /*store iv for rfc3686(ctr) flow*/ 69 u8 *backup_giv; /*store iv for rfc3686(ctr) flow*/
81 dma_addr_t mac_buf_dma_addr; /* internal ICV DMA buffer */ 70 dma_addr_t mac_buf_dma_addr; /* internal ICV DMA buffer */
82 dma_addr_t ccm_iv0_dma_addr; /* buffer for internal ccm configurations */ 71 /* buffer for internal ccm configurations */
72 dma_addr_t ccm_iv0_dma_addr;
83 dma_addr_t icv_dma_addr; /* Phys. address of ICV */ 73 dma_addr_t icv_dma_addr; /* Phys. address of ICV */
84 74
85 //used in gcm 75 //used in gcm
86 dma_addr_t gcm_iv_inc1_dma_addr; /* buffer for internal gcm configurations */ 76 /* buffer for internal gcm configurations */
87 dma_addr_t gcm_iv_inc2_dma_addr; /* buffer for internal gcm configurations */ 77 dma_addr_t gcm_iv_inc1_dma_addr;
78 /* buffer for internal gcm configurations */
79 dma_addr_t gcm_iv_inc2_dma_addr;
88 dma_addr_t hkey_dma_addr; /* Phys. address of hkey */ 80 dma_addr_t hkey_dma_addr; /* Phys. address of hkey */
89 dma_addr_t gcm_block_len_dma_addr; /* Phys. address of gcm block len */ 81 dma_addr_t gcm_block_len_dma_addr; /* Phys. address of gcm block len */
90 bool is_gcm4543; 82 bool is_gcm4543;
91 83
92 u8 *icv_virt_addr; /* Virt. address of ICV */ 84 u8 *icv_virt_addr; /* Virt. address of ICV */
93 struct async_gen_req_ctx gen_ctx; 85 struct async_gen_req_ctx gen_ctx;
94 struct ssi_mlli assoc; 86 struct cc_mlli assoc;
95 struct ssi_mlli src; 87 struct cc_mlli src;
96 struct ssi_mlli dst; 88 struct cc_mlli dst;
97 struct scatterlist *src_sgl; 89 struct scatterlist *src_sgl;
98 struct scatterlist *dst_sgl; 90 struct scatterlist *dst_sgl;
99 unsigned int src_offset; 91 unsigned int src_offset;
100 unsigned int dst_offset; 92 unsigned int dst_offset;
101 enum ssi_req_dma_buf_type assoc_buff_type; 93 enum cc_req_dma_buf_type assoc_buff_type;
102 enum ssi_req_dma_buf_type data_buff_type; 94 enum cc_req_dma_buf_type data_buff_type;
103 struct mlli_params mlli_params; 95 struct mlli_params mlli_params;
104 unsigned int cryptlen; 96 unsigned int cryptlen;
105 struct scatterlist ccm_adata_sg; 97 struct scatterlist ccm_adata_sg;
@@ -111,7 +103,7 @@ struct aead_req_ctx {
111 bool plaintext_authenticate_only; //for gcm_rfc4543 103 bool plaintext_authenticate_only; //for gcm_rfc4543
112}; 104};
113 105
114int ssi_aead_alloc(struct ssi_drvdata *drvdata); 106int cc_aead_alloc(struct cc_drvdata *drvdata);
115int ssi_aead_free(struct ssi_drvdata *drvdata); 107int cc_aead_free(struct cc_drvdata *drvdata);
116 108
117#endif /*__SSI_AEAD_H__*/ 109#endif /*__CC_AEAD_H__*/
diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c b/drivers/staging/ccree/cc_buffer_mgr.c
index 1f8a225530a8..14b2eabbf70a 100644
--- a/drivers/staging/ccree/ssi_buffer_mgr.c
+++ b/drivers/staging/ccree/cc_buffer_mgr.c
@@ -1,42 +1,17 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17#include <linux/crypto.h>
18#include <linux/version.h>
19#include <crypto/algapi.h>
20#include <crypto/internal/aead.h> 4#include <crypto/internal/aead.h>
21#include <crypto/hash.h>
22#include <crypto/authenc.h> 5#include <crypto/authenc.h>
23#include <crypto/scatterwalk.h> 6#include <crypto/scatterwalk.h>
24#include <linux/dmapool.h> 7#include <linux/dmapool.h>
25#include <linux/dma-mapping.h> 8#include <linux/dma-mapping.h>
26#include <linux/crypto.h>
27#include <linux/module.h>
28#include <linux/platform_device.h>
29 9
30#include "ssi_buffer_mgr.h" 10#include "cc_buffer_mgr.h"
31#include "cc_lli_defs.h" 11#include "cc_lli_defs.h"
32#include "ssi_cipher.h" 12#include "cc_cipher.h"
33#include "ssi_hash.h" 13#include "cc_hash.h"
34#include "ssi_aead.h" 14#include "cc_aead.h"
35
36#define GET_DMA_BUFFER_TYPE(buff_type) ( \
37 ((buff_type) == SSI_DMA_BUF_NULL) ? "BUF_NULL" : \
38 ((buff_type) == SSI_DMA_BUF_DLLI) ? "BUF_DLLI" : \
39 ((buff_type) == SSI_DMA_BUF_MLLI) ? "BUF_MLLI" : "BUF_INVALID")
40 15
41enum dma_buffer_type { 16enum dma_buffer_type {
42 DMA_NULL_TYPE = -1, 17 DMA_NULL_TYPE = -1,
@@ -64,25 +39,62 @@ struct buffer_array {
64 u32 *mlli_nents[MAX_NUM_OF_BUFFERS_IN_MLLI]; 39 u32 *mlli_nents[MAX_NUM_OF_BUFFERS_IN_MLLI];
65}; 40};
66 41
42static inline char *cc_dma_buf_type(enum cc_req_dma_buf_type type)
43{
44 switch (type) {
45 case CC_DMA_BUF_NULL:
46 return "BUF_NULL";
47 case CC_DMA_BUF_DLLI:
48 return "BUF_DLLI";
49 case CC_DMA_BUF_MLLI:
50 return "BUF_MLLI";
51 default:
52 return "BUF_INVALID";
53 }
54}
55
67/** 56/**
68 * ssi_buffer_mgr_get_sgl_nents() - Get scatterlist number of entries. 57 * cc_copy_mac() - Copy MAC to temporary location
58 *
59 * @dev: device object
60 * @req: aead request object
61 * @dir: [IN] copy from/to sgl
62 */
63static void cc_copy_mac(struct device *dev, struct aead_request *req,
64 enum cc_sg_cpy_direct dir)
65{
66 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
67 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
68 u32 skip = req->assoclen + req->cryptlen;
69
70 if (areq_ctx->is_gcm4543)
71 skip += crypto_aead_ivsize(tfm);
72
73 cc_copy_sg_portion(dev, areq_ctx->backup_mac, req->src,
74 (skip - areq_ctx->req_authsize), skip, dir);
75}
76
77/**
78 * cc_get_sgl_nents() - Get scatterlist number of entries.
69 * 79 *
70 * @sg_list: SG list 80 * @sg_list: SG list
71 * @nbytes: [IN] Total SGL data bytes. 81 * @nbytes: [IN] Total SGL data bytes.
72 * @lbytes: [OUT] Returns the amount of bytes at the last entry 82 * @lbytes: [OUT] Returns the amount of bytes at the last entry
73 */ 83 */
74static unsigned int ssi_buffer_mgr_get_sgl_nents( 84static unsigned int cc_get_sgl_nents(struct device *dev,
75 struct device *dev, struct scatterlist *sg_list, 85 struct scatterlist *sg_list,
76 unsigned int nbytes, u32 *lbytes, bool *is_chained) 86 unsigned int nbytes, u32 *lbytes,
87 bool *is_chained)
77{ 88{
78 unsigned int nents = 0; 89 unsigned int nents = 0;
79 90
80 while (nbytes != 0) { 91 while (nbytes && sg_list) {
81 if (sg_list->length != 0) { 92 if (sg_list->length) {
82 nents++; 93 nents++;
83 /* get the number of bytes in the last entry */ 94 /* get the number of bytes in the last entry */
84 *lbytes = nbytes; 95 *lbytes = nbytes;
85 nbytes -= (sg_list->length > nbytes) ? nbytes : sg_list->length; 96 nbytes -= (sg_list->length > nbytes) ?
97 nbytes : sg_list->length;
86 sg_list = sg_next(sg_list); 98 sg_list = sg_next(sg_list);
87 } else { 99 } else {
88 sg_list = (struct scatterlist *)sg_page(sg_list); 100 sg_list = (struct scatterlist *)sg_page(sg_list);
@@ -95,11 +107,11 @@ static unsigned int ssi_buffer_mgr_get_sgl_nents(
95} 107}
96 108
97/** 109/**
98 * ssi_buffer_mgr_zero_sgl() - Zero scatter scatter list data. 110 * cc_zero_sgl() - Zero scatter scatter list data.
99 * 111 *
100 * @sgl: 112 * @sgl:
101 */ 113 */
102void ssi_buffer_mgr_zero_sgl(struct scatterlist *sgl, u32 data_len) 114void cc_zero_sgl(struct scatterlist *sgl, u32 data_len)
103{ 115{
104 struct scatterlist *current_sg = sgl; 116 struct scatterlist *current_sg = sgl;
105 int sg_index = 0; 117 int sg_index = 0;
@@ -116,7 +128,7 @@ void ssi_buffer_mgr_zero_sgl(struct scatterlist *sgl, u32 data_len)
116} 128}
117 129
118/** 130/**
119 * ssi_buffer_mgr_copy_scatterlist_portion() - Copy scatter list data, 131 * cc_copy_sg_portion() - Copy scatter list data,
120 * from to_skip to end, to dest and vice versa 132 * from to_skip to end, to dest and vice versa
121 * 133 *
122 * @dest: 134 * @dest:
@@ -125,21 +137,19 @@ void ssi_buffer_mgr_zero_sgl(struct scatterlist *sgl, u32 data_len)
125 * @end: 137 * @end:
126 * @direct: 138 * @direct:
127 */ 139 */
128void ssi_buffer_mgr_copy_scatterlist_portion( 140void cc_copy_sg_portion(struct device *dev, u8 *dest, struct scatterlist *sg,
129 struct device *dev, u8 *dest, 141 u32 to_skip, u32 end, enum cc_sg_cpy_direct direct)
130 struct scatterlist *sg, u32 to_skip,
131 u32 end, enum ssi_sg_cpy_direct direct)
132{ 142{
133 u32 nents, lbytes; 143 u32 nents, lbytes;
134 144
135 nents = ssi_buffer_mgr_get_sgl_nents(dev, sg, end, &lbytes, NULL); 145 nents = cc_get_sgl_nents(dev, sg, end, &lbytes, NULL);
136 sg_copy_buffer(sg, nents, (void *)dest, (end - to_skip + 1), to_skip, 146 sg_copy_buffer(sg, nents, (void *)dest, (end - to_skip + 1), to_skip,
137 (direct == SSI_SG_TO_BUF)); 147 (direct == CC_SG_TO_BUF));
138} 148}
139 149
140static inline int ssi_buffer_mgr_render_buff_to_mlli( 150static int cc_render_buff_to_mlli(struct device *dev, dma_addr_t buff_dma,
141 struct device *dev, dma_addr_t buff_dma, u32 buff_size, 151 u32 buff_size, u32 *curr_nents,
142 u32 *curr_nents, u32 **mlli_entry_pp) 152 u32 **mlli_entry_pp)
143{ 153{
144 u32 *mlli_entry_p = *mlli_entry_pp; 154 u32 *mlli_entry_p = *mlli_entry_pp;
145 u32 new_nents; 155 u32 new_nents;
@@ -173,26 +183,25 @@ static inline int ssi_buffer_mgr_render_buff_to_mlli(
173 return 0; 183 return 0;
174} 184}
175 185
176static inline int ssi_buffer_mgr_render_scatterlist_to_mlli( 186static int cc_render_sg_to_mlli(struct device *dev, struct scatterlist *sgl,
177 struct device *dev, struct scatterlist *sgl, 187 u32 sgl_data_len, u32 sgl_offset,
178 u32 sgl_data_len, u32 sgl_offset, u32 *curr_nents, 188 u32 *curr_nents, u32 **mlli_entry_pp)
179 u32 **mlli_entry_pp)
180{ 189{
181 struct scatterlist *curr_sgl = sgl; 190 struct scatterlist *curr_sgl = sgl;
182 u32 *mlli_entry_p = *mlli_entry_pp; 191 u32 *mlli_entry_p = *mlli_entry_pp;
183 s32 rc = 0; 192 s32 rc = 0;
184 193
185 for ( ; (curr_sgl) && (sgl_data_len != 0); 194 for ( ; (curr_sgl && sgl_data_len);
186 curr_sgl = sg_next(curr_sgl)) { 195 curr_sgl = sg_next(curr_sgl)) {
187 u32 entry_data_len = 196 u32 entry_data_len =
188 (sgl_data_len > sg_dma_len(curr_sgl) - sgl_offset) ? 197 (sgl_data_len > sg_dma_len(curr_sgl) - sgl_offset) ?
189 sg_dma_len(curr_sgl) - sgl_offset : 198 sg_dma_len(curr_sgl) - sgl_offset :
190 sgl_data_len; 199 sgl_data_len;
191 sgl_data_len -= entry_data_len; 200 sgl_data_len -= entry_data_len;
192 rc = ssi_buffer_mgr_render_buff_to_mlli( 201 rc = cc_render_buff_to_mlli(dev, sg_dma_address(curr_sgl) +
193 dev, sg_dma_address(curr_sgl) + sgl_offset, 202 sgl_offset, entry_data_len,
194 entry_data_len, curr_nents, &mlli_entry_p); 203 curr_nents, &mlli_entry_p);
195 if (rc != 0) 204 if (rc)
196 return rc; 205 return rc;
197 206
198 sgl_offset = 0; 207 sgl_offset = 0;
@@ -201,10 +210,8 @@ static inline int ssi_buffer_mgr_render_scatterlist_to_mlli(
201 return 0; 210 return 0;
202} 211}
203 212
204static int ssi_buffer_mgr_generate_mlli( 213static int cc_generate_mlli(struct device *dev, struct buffer_array *sg_data,
205 struct device *dev, 214 struct mlli_params *mlli_params, gfp_t flags)
206 struct buffer_array *sg_data,
207 struct mlli_params *mlli_params)
208{ 215{
209 u32 *mlli_p; 216 u32 *mlli_p;
210 u32 total_nents = 0, prev_total_nents = 0; 217 u32 total_nents = 0, prev_total_nents = 0;
@@ -213,10 +220,10 @@ static int ssi_buffer_mgr_generate_mlli(
213 dev_dbg(dev, "NUM of SG's = %d\n", sg_data->num_of_buffers); 220 dev_dbg(dev, "NUM of SG's = %d\n", sg_data->num_of_buffers);
214 221
215 /* Allocate memory from the pointed pool */ 222 /* Allocate memory from the pointed pool */
216 mlli_params->mlli_virt_addr = dma_pool_alloc( 223 mlli_params->mlli_virt_addr =
217 mlli_params->curr_pool, GFP_KERNEL, 224 dma_pool_alloc(mlli_params->curr_pool, flags,
218 &mlli_params->mlli_dma_addr); 225 &mlli_params->mlli_dma_addr);
219 if (unlikely(!mlli_params->mlli_virt_addr)) { 226 if (!mlli_params->mlli_virt_addr) {
220 dev_err(dev, "dma_pool_alloc() failed\n"); 227 dev_err(dev, "dma_pool_alloc() failed\n");
221 rc = -ENOMEM; 228 rc = -ENOMEM;
222 goto build_mlli_exit; 229 goto build_mlli_exit;
@@ -225,17 +232,19 @@ static int ssi_buffer_mgr_generate_mlli(
225 mlli_p = (u32 *)mlli_params->mlli_virt_addr; 232 mlli_p = (u32 *)mlli_params->mlli_virt_addr;
226 /* go over all SG's and link it to one MLLI table */ 233 /* go over all SG's and link it to one MLLI table */
227 for (i = 0; i < sg_data->num_of_buffers; i++) { 234 for (i = 0; i < sg_data->num_of_buffers; i++) {
235 union buffer_array_entry *entry = &sg_data->entry[i];
236 u32 tot_len = sg_data->total_data_len[i];
237 u32 offset = sg_data->offset[i];
238
228 if (sg_data->type[i] == DMA_SGL_TYPE) 239 if (sg_data->type[i] == DMA_SGL_TYPE)
229 rc = ssi_buffer_mgr_render_scatterlist_to_mlli( 240 rc = cc_render_sg_to_mlli(dev, entry->sgl, tot_len,
230 dev, sg_data->entry[i].sgl, 241 offset, &total_nents,
231 sg_data->total_data_len[i], sg_data->offset[i], 242 &mlli_p);
232 &total_nents, &mlli_p);
233 else /*DMA_BUFF_TYPE*/ 243 else /*DMA_BUFF_TYPE*/
234 rc = ssi_buffer_mgr_render_buff_to_mlli( 244 rc = cc_render_buff_to_mlli(dev, entry->buffer_dma,
235 dev, sg_data->entry[i].buffer_dma, 245 tot_len, &total_nents,
236 sg_data->total_data_len[i], &total_nents, 246 &mlli_p);
237 &mlli_p); 247 if (rc)
238 if (rc != 0)
239 return rc; 248 return rc;
240 249
241 /* set last bit in the current table */ 250 /* set last bit in the current table */
@@ -260,10 +269,10 @@ build_mlli_exit:
260 return rc; 269 return rc;
261} 270}
262 271
263static inline void ssi_buffer_mgr_add_buffer_entry( 272static void cc_add_buffer_entry(struct device *dev,
264 struct device *dev, struct buffer_array *sgl_data, 273 struct buffer_array *sgl_data,
265 dma_addr_t buffer_dma, unsigned int buffer_len, 274 dma_addr_t buffer_dma, unsigned int buffer_len,
266 bool is_last_entry, u32 *mlli_nents) 275 bool is_last_entry, u32 *mlli_nents)
267{ 276{
268 unsigned int index = sgl_data->num_of_buffers; 277 unsigned int index = sgl_data->num_of_buffers;
269 278
@@ -281,15 +290,10 @@ static inline void ssi_buffer_mgr_add_buffer_entry(
281 sgl_data->num_of_buffers++; 290 sgl_data->num_of_buffers++;
282} 291}
283 292
284static inline void ssi_buffer_mgr_add_scatterlist_entry( 293static void cc_add_sg_entry(struct device *dev, struct buffer_array *sgl_data,
285 struct device *dev, 294 unsigned int nents, struct scatterlist *sgl,
286 struct buffer_array *sgl_data, 295 unsigned int data_len, unsigned int data_offset,
287 unsigned int nents, 296 bool is_last_table, u32 *mlli_nents)
288 struct scatterlist *sgl,
289 unsigned int data_len,
290 unsigned int data_offset,
291 bool is_last_table,
292 u32 *mlli_nents)
293{ 297{
294 unsigned int index = sgl_data->num_of_buffers; 298 unsigned int index = sgl_data->num_of_buffers;
295 299
@@ -307,9 +311,8 @@ static inline void ssi_buffer_mgr_add_scatterlist_entry(
307 sgl_data->num_of_buffers++; 311 sgl_data->num_of_buffers++;
308} 312}
309 313
310static int 314static int cc_dma_map_sg(struct device *dev, struct scatterlist *sg, u32 nents,
311ssi_buffer_mgr_dma_map_sg(struct device *dev, struct scatterlist *sg, u32 nents, 315 enum dma_data_direction direction)
312 enum dma_data_direction direction)
313{ 316{
314 u32 i, j; 317 u32 i, j;
315 struct scatterlist *l_sg = sg; 318 struct scatterlist *l_sg = sg;
@@ -317,7 +320,7 @@ ssi_buffer_mgr_dma_map_sg(struct device *dev, struct scatterlist *sg, u32 nents,
317 for (i = 0; i < nents; i++) { 320 for (i = 0; i < nents; i++) {
318 if (!l_sg) 321 if (!l_sg)
319 break; 322 break;
320 if (unlikely(dma_map_sg(dev, l_sg, 1, direction) != 1)) { 323 if (dma_map_sg(dev, l_sg, 1, direction) != 1) {
321 dev_err(dev, "dma_map_page() sg buffer failed\n"); 324 dev_err(dev, "dma_map_page() sg buffer failed\n");
322 goto err; 325 goto err;
323 } 326 }
@@ -336,17 +339,15 @@ err:
336 return 0; 339 return 0;
337} 340}
338 341
339static int ssi_buffer_mgr_map_scatterlist( 342static int cc_map_sg(struct device *dev, struct scatterlist *sg,
340 struct device *dev, struct scatterlist *sg, 343 unsigned int nbytes, int direction, u32 *nents,
341 unsigned int nbytes, int direction, 344 u32 max_sg_nents, u32 *lbytes, u32 *mapped_nents)
342 u32 *nents, u32 max_sg_nents,
343 u32 *lbytes, u32 *mapped_nents)
344{ 345{
345 bool is_chained = false; 346 bool is_chained = false;
346 347
347 if (sg_is_last(sg)) { 348 if (sg_is_last(sg)) {
348 /* One entry only case -set to DLLI */ 349 /* One entry only case -set to DLLI */
349 if (unlikely(dma_map_sg(dev, sg, 1, direction) != 1)) { 350 if (dma_map_sg(dev, sg, 1, direction) != 1) {
350 dev_err(dev, "dma_map_sg() single buffer failed\n"); 351 dev_err(dev, "dma_map_sg() single buffer failed\n");
351 return -ENOMEM; 352 return -ENOMEM;
352 } 353 }
@@ -357,8 +358,8 @@ static int ssi_buffer_mgr_map_scatterlist(
357 *nents = 1; 358 *nents = 1;
358 *mapped_nents = 1; 359 *mapped_nents = 1;
359 } else { /*sg_is_last*/ 360 } else { /*sg_is_last*/
360 *nents = ssi_buffer_mgr_get_sgl_nents(dev, sg, nbytes, lbytes, 361 *nents = cc_get_sgl_nents(dev, sg, nbytes, lbytes,
361 &is_chained); 362 &is_chained);
362 if (*nents > max_sg_nents) { 363 if (*nents > max_sg_nents) {
363 *nents = 0; 364 *nents = 0;
364 dev_err(dev, "Too many fragments. current %d max %d\n", 365 dev_err(dev, "Too many fragments. current %d max %d\n",
@@ -370,7 +371,7 @@ static int ssi_buffer_mgr_map_scatterlist(
370 * be changed from the original sgl nents 371 * be changed from the original sgl nents
371 */ 372 */
372 *mapped_nents = dma_map_sg(dev, sg, *nents, direction); 373 *mapped_nents = dma_map_sg(dev, sg, *nents, direction);
373 if (unlikely(*mapped_nents == 0)) { 374 if (*mapped_nents == 0) {
374 *nents = 0; 375 *nents = 0;
375 dev_err(dev, "dma_map_sg() sg buffer failed\n"); 376 dev_err(dev, "dma_map_sg() sg buffer failed\n");
376 return -ENOMEM; 377 return -ENOMEM;
@@ -379,11 +380,9 @@ static int ssi_buffer_mgr_map_scatterlist(
379 /*In this case the driver maps entry by entry so it 380 /*In this case the driver maps entry by entry so it
380 * must have the same nents before and after map 381 * must have the same nents before and after map
381 */ 382 */
382 *mapped_nents = ssi_buffer_mgr_dma_map_sg(dev, 383 *mapped_nents = cc_dma_map_sg(dev, sg, *nents,
383 sg, 384 direction);
384 *nents, 385 if (*mapped_nents != *nents) {
385 direction);
386 if (unlikely(*mapped_nents != *nents)) {
387 *nents = *mapped_nents; 386 *nents = *mapped_nents;
388 dev_err(dev, "dma_map_sg() sg buffer failed\n"); 387 dev_err(dev, "dma_map_sg() sg buffer failed\n");
389 return -ENOMEM; 388 return -ENOMEM;
@@ -394,18 +393,16 @@ static int ssi_buffer_mgr_map_scatterlist(
394 return 0; 393 return 0;
395} 394}
396 395
397static inline int 396static int
398ssi_aead_handle_config_buf(struct device *dev, 397cc_set_aead_conf_buf(struct device *dev, struct aead_req_ctx *areq_ctx,
399 struct aead_req_ctx *areq_ctx, 398 u8 *config_data, struct buffer_array *sg_data,
400 u8 *config_data, 399 unsigned int assoclen)
401 struct buffer_array *sg_data,
402 unsigned int assoclen)
403{ 400{
404 dev_dbg(dev, " handle additional data config set to DLLI\n"); 401 dev_dbg(dev, " handle additional data config set to DLLI\n");
405 /* create sg for the current buffer */ 402 /* create sg for the current buffer */
406 sg_init_one(&areq_ctx->ccm_adata_sg, config_data, AES_BLOCK_SIZE + areq_ctx->ccm_hdr_size); 403 sg_init_one(&areq_ctx->ccm_adata_sg, config_data,
407 if (unlikely(dma_map_sg(dev, &areq_ctx->ccm_adata_sg, 1, 404 AES_BLOCK_SIZE + areq_ctx->ccm_hdr_size);
408 DMA_TO_DEVICE) != 1)) { 405 if (dma_map_sg(dev, &areq_ctx->ccm_adata_sg, 1, DMA_TO_DEVICE) != 1) {
409 dev_err(dev, "dma_map_sg() config buffer failed\n"); 406 dev_err(dev, "dma_map_sg() config buffer failed\n");
410 return -ENOMEM; 407 return -ENOMEM;
411 } 408 }
@@ -416,25 +413,21 @@ ssi_aead_handle_config_buf(struct device *dev,
416 areq_ctx->ccm_adata_sg.offset, areq_ctx->ccm_adata_sg.length); 413 areq_ctx->ccm_adata_sg.offset, areq_ctx->ccm_adata_sg.length);
417 /* prepare for case of MLLI */ 414 /* prepare for case of MLLI */
418 if (assoclen > 0) { 415 if (assoclen > 0) {
419 ssi_buffer_mgr_add_scatterlist_entry(dev, sg_data, 1, 416 cc_add_sg_entry(dev, sg_data, 1, &areq_ctx->ccm_adata_sg,
420 &areq_ctx->ccm_adata_sg, 417 (AES_BLOCK_SIZE + areq_ctx->ccm_hdr_size),
421 (AES_BLOCK_SIZE + areq_ctx->ccm_hdr_size), 418 0, false, NULL);
422 0, false, NULL);
423 } 419 }
424 return 0; 420 return 0;
425} 421}
426 422
427static inline int ssi_ahash_handle_curr_buf(struct device *dev, 423static int cc_set_hash_buf(struct device *dev, struct ahash_req_ctx *areq_ctx,
428 struct ahash_req_ctx *areq_ctx, 424 u8 *curr_buff, u32 curr_buff_cnt,
429 u8 *curr_buff, 425 struct buffer_array *sg_data)
430 u32 curr_buff_cnt,
431 struct buffer_array *sg_data)
432{ 426{
433 dev_dbg(dev, " handle curr buff %x set to DLLI\n", curr_buff_cnt); 427 dev_dbg(dev, " handle curr buff %x set to DLLI\n", curr_buff_cnt);
434 /* create sg for the current buffer */ 428 /* create sg for the current buffer */
435 sg_init_one(areq_ctx->buff_sg, curr_buff, curr_buff_cnt); 429 sg_init_one(areq_ctx->buff_sg, curr_buff, curr_buff_cnt);
436 if (unlikely(dma_map_sg(dev, areq_ctx->buff_sg, 1, 430 if (dma_map_sg(dev, areq_ctx->buff_sg, 1, DMA_TO_DEVICE) != 1) {
437 DMA_TO_DEVICE) != 1)) {
438 dev_err(dev, "dma_map_sg() src buffer failed\n"); 431 dev_err(dev, "dma_map_sg() src buffer failed\n");
439 return -ENOMEM; 432 return -ENOMEM;
440 } 433 }
@@ -442,25 +435,22 @@ static inline int ssi_ahash_handle_curr_buf(struct device *dev,
442 &sg_dma_address(areq_ctx->buff_sg), sg_page(areq_ctx->buff_sg), 435 &sg_dma_address(areq_ctx->buff_sg), sg_page(areq_ctx->buff_sg),
443 sg_virt(areq_ctx->buff_sg), areq_ctx->buff_sg->offset, 436 sg_virt(areq_ctx->buff_sg), areq_ctx->buff_sg->offset,
444 areq_ctx->buff_sg->length); 437 areq_ctx->buff_sg->length);
445 areq_ctx->data_dma_buf_type = SSI_DMA_BUF_DLLI; 438 areq_ctx->data_dma_buf_type = CC_DMA_BUF_DLLI;
446 areq_ctx->curr_sg = areq_ctx->buff_sg; 439 areq_ctx->curr_sg = areq_ctx->buff_sg;
447 areq_ctx->in_nents = 0; 440 areq_ctx->in_nents = 0;
448 /* prepare for case of MLLI */ 441 /* prepare for case of MLLI */
449 ssi_buffer_mgr_add_scatterlist_entry(dev, sg_data, 1, areq_ctx->buff_sg, 442 cc_add_sg_entry(dev, sg_data, 1, areq_ctx->buff_sg, curr_buff_cnt, 0,
450 curr_buff_cnt, 0, false, NULL); 443 false, NULL);
451 return 0; 444 return 0;
452} 445}
453 446
454void ssi_buffer_mgr_unmap_blkcipher_request( 447void cc_unmap_blkcipher_request(struct device *dev, void *ctx,
455 struct device *dev, 448 unsigned int ivsize, struct scatterlist *src,
456 void *ctx, 449 struct scatterlist *dst)
457 unsigned int ivsize,
458 struct scatterlist *src,
459 struct scatterlist *dst)
460{ 450{
461 struct blkcipher_req_ctx *req_ctx = (struct blkcipher_req_ctx *)ctx; 451 struct blkcipher_req_ctx *req_ctx = (struct blkcipher_req_ctx *)ctx;
462 452
463 if (likely(req_ctx->gen_ctx.iv_dma_addr != 0)) { 453 if (req_ctx->gen_ctx.iv_dma_addr) {
464 dev_dbg(dev, "Unmapped iv: iv_dma_addr=%pad iv_size=%u\n", 454 dev_dbg(dev, "Unmapped iv: iv_dma_addr=%pad iv_size=%u\n",
465 &req_ctx->gen_ctx.iv_dma_addr, ivsize); 455 &req_ctx->gen_ctx.iv_dma_addr, ivsize);
466 dma_unmap_single(dev, req_ctx->gen_ctx.iv_dma_addr, 456 dma_unmap_single(dev, req_ctx->gen_ctx.iv_dma_addr,
@@ -469,7 +459,8 @@ void ssi_buffer_mgr_unmap_blkcipher_request(
469 DMA_TO_DEVICE); 459 DMA_TO_DEVICE);
470 } 460 }
471 /* Release pool */ 461 /* Release pool */
472 if (req_ctx->dma_buf_type == SSI_DMA_BUF_MLLI) { 462 if (req_ctx->dma_buf_type == CC_DMA_BUF_MLLI &&
463 req_ctx->mlli_params.mlli_virt_addr) {
473 dma_pool_free(req_ctx->mlli_params.curr_pool, 464 dma_pool_free(req_ctx->mlli_params.curr_pool,
474 req_ctx->mlli_params.mlli_virt_addr, 465 req_ctx->mlli_params.mlli_virt_addr,
475 req_ctx->mlli_params.mlli_dma_addr); 466 req_ctx->mlli_params.mlli_dma_addr);
@@ -484,14 +475,10 @@ void ssi_buffer_mgr_unmap_blkcipher_request(
484 } 475 }
485} 476}
486 477
487int ssi_buffer_mgr_map_blkcipher_request( 478int cc_map_blkcipher_request(struct cc_drvdata *drvdata, void *ctx,
488 struct ssi_drvdata *drvdata, 479 unsigned int ivsize, unsigned int nbytes,
489 void *ctx, 480 void *info, struct scatterlist *src,
490 unsigned int ivsize, 481 struct scatterlist *dst, gfp_t flags)
491 unsigned int nbytes,
492 void *info,
493 struct scatterlist *src,
494 struct scatterlist *dst)
495{ 482{
496 struct blkcipher_req_ctx *req_ctx = (struct blkcipher_req_ctx *)ctx; 483 struct blkcipher_req_ctx *req_ctx = (struct blkcipher_req_ctx *)ctx;
497 struct mlli_params *mlli_params = &req_ctx->mlli_params; 484 struct mlli_params *mlli_params = &req_ctx->mlli_params;
@@ -502,20 +489,19 @@ int ssi_buffer_mgr_map_blkcipher_request(
502 int rc = 0; 489 int rc = 0;
503 u32 mapped_nents = 0; 490 u32 mapped_nents = 0;
504 491
505 req_ctx->dma_buf_type = SSI_DMA_BUF_DLLI; 492 req_ctx->dma_buf_type = CC_DMA_BUF_DLLI;
506 mlli_params->curr_pool = NULL; 493 mlli_params->curr_pool = NULL;
507 sg_data.num_of_buffers = 0; 494 sg_data.num_of_buffers = 0;
508 495
509 /* Map IV buffer */ 496 /* Map IV buffer */
510 if (likely(ivsize != 0)) { 497 if (ivsize) {
511 dump_byte_array("iv", (u8 *)info, ivsize); 498 dump_byte_array("iv", (u8 *)info, ivsize);
512 req_ctx->gen_ctx.iv_dma_addr = 499 req_ctx->gen_ctx.iv_dma_addr =
513 dma_map_single(dev, (void *)info, 500 dma_map_single(dev, (void *)info,
514 ivsize, 501 ivsize,
515 req_ctx->is_giv ? DMA_BIDIRECTIONAL : 502 req_ctx->is_giv ? DMA_BIDIRECTIONAL :
516 DMA_TO_DEVICE); 503 DMA_TO_DEVICE);
517 if (unlikely(dma_mapping_error(dev, 504 if (dma_mapping_error(dev, req_ctx->gen_ctx.iv_dma_addr)) {
518 req_ctx->gen_ctx.iv_dma_addr))) {
519 dev_err(dev, "Mapping iv %u B at va=%pK for DMA failed\n", 505 dev_err(dev, "Mapping iv %u B at va=%pK for DMA failed\n",
520 ivsize, info); 506 ivsize, info);
521 return -ENOMEM; 507 return -ENOMEM;
@@ -527,121 +513,107 @@ int ssi_buffer_mgr_map_blkcipher_request(
527 } 513 }
528 514
529 /* Map the src SGL */ 515 /* Map the src SGL */
530 rc = ssi_buffer_mgr_map_scatterlist(dev, src, 516 rc = cc_map_sg(dev, src, nbytes, DMA_BIDIRECTIONAL, &req_ctx->in_nents,
531 nbytes, DMA_BIDIRECTIONAL, 517 LLI_MAX_NUM_OF_DATA_ENTRIES, &dummy, &mapped_nents);
532 &req_ctx->in_nents, 518 if (rc) {
533 LLI_MAX_NUM_OF_DATA_ENTRIES, &dummy,
534 &mapped_nents);
535 if (unlikely(rc != 0)) {
536 rc = -ENOMEM; 519 rc = -ENOMEM;
537 goto ablkcipher_exit; 520 goto ablkcipher_exit;
538 } 521 }
539 if (mapped_nents > 1) 522 if (mapped_nents > 1)
540 req_ctx->dma_buf_type = SSI_DMA_BUF_MLLI; 523 req_ctx->dma_buf_type = CC_DMA_BUF_MLLI;
541 524
542 if (unlikely(src == dst)) { 525 if (src == dst) {
543 /* Handle inplace operation */ 526 /* Handle inplace operation */
544 if (unlikely(req_ctx->dma_buf_type == SSI_DMA_BUF_MLLI)) { 527 if (req_ctx->dma_buf_type == CC_DMA_BUF_MLLI) {
545 req_ctx->out_nents = 0; 528 req_ctx->out_nents = 0;
546 ssi_buffer_mgr_add_scatterlist_entry(dev, &sg_data, 529 cc_add_sg_entry(dev, &sg_data, req_ctx->in_nents, src,
547 req_ctx->in_nents, 530 nbytes, 0, true,
548 src, nbytes, 0, 531 &req_ctx->in_mlli_nents);
549 true,
550 &req_ctx->in_mlli_nents);
551 } 532 }
552 } else { 533 } else {
553 /* Map the dst sg */ 534 /* Map the dst sg */
554 if (unlikely(ssi_buffer_mgr_map_scatterlist( 535 if (cc_map_sg(dev, dst, nbytes, DMA_BIDIRECTIONAL,
555 dev, dst, nbytes, 536 &req_ctx->out_nents, LLI_MAX_NUM_OF_DATA_ENTRIES,
556 DMA_BIDIRECTIONAL, &req_ctx->out_nents, 537 &dummy, &mapped_nents)) {
557 LLI_MAX_NUM_OF_DATA_ENTRIES, &dummy,
558 &mapped_nents))){
559 rc = -ENOMEM; 538 rc = -ENOMEM;
560 goto ablkcipher_exit; 539 goto ablkcipher_exit;
561 } 540 }
562 if (mapped_nents > 1) 541 if (mapped_nents > 1)
563 req_ctx->dma_buf_type = SSI_DMA_BUF_MLLI; 542 req_ctx->dma_buf_type = CC_DMA_BUF_MLLI;
564 543
565 if (unlikely((req_ctx->dma_buf_type == SSI_DMA_BUF_MLLI))) { 544 if (req_ctx->dma_buf_type == CC_DMA_BUF_MLLI) {
566 ssi_buffer_mgr_add_scatterlist_entry(dev, &sg_data, 545 cc_add_sg_entry(dev, &sg_data, req_ctx->in_nents, src,
567 req_ctx->in_nents, 546 nbytes, 0, true,
568 src, nbytes, 0, 547 &req_ctx->in_mlli_nents);
569 true, 548 cc_add_sg_entry(dev, &sg_data, req_ctx->out_nents, dst,
570 &req_ctx->in_mlli_nents); 549 nbytes, 0, true,
571 ssi_buffer_mgr_add_scatterlist_entry(dev, &sg_data, 550 &req_ctx->out_mlli_nents);
572 req_ctx->out_nents,
573 dst, nbytes, 0,
574 true,
575 &req_ctx->out_mlli_nents);
576 } 551 }
577 } 552 }
578 553
579 if (unlikely(req_ctx->dma_buf_type == SSI_DMA_BUF_MLLI)) { 554 if (req_ctx->dma_buf_type == CC_DMA_BUF_MLLI) {
580 mlli_params->curr_pool = buff_mgr->mlli_buffs_pool; 555 mlli_params->curr_pool = buff_mgr->mlli_buffs_pool;
581 rc = ssi_buffer_mgr_generate_mlli(dev, &sg_data, mlli_params); 556 rc = cc_generate_mlli(dev, &sg_data, mlli_params, flags);
582 if (unlikely(rc != 0)) 557 if (rc)
583 goto ablkcipher_exit; 558 goto ablkcipher_exit;
584 } 559 }
585 560
586 dev_dbg(dev, "areq_ctx->dma_buf_type = %s\n", 561 dev_dbg(dev, "areq_ctx->dma_buf_type = %s\n",
587 GET_DMA_BUFFER_TYPE(req_ctx->dma_buf_type)); 562 cc_dma_buf_type(req_ctx->dma_buf_type));
588 563
589 return 0; 564 return 0;
590 565
591ablkcipher_exit: 566ablkcipher_exit:
592 ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst); 567 cc_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst);
593 return rc; 568 return rc;
594} 569}
595 570
596void ssi_buffer_mgr_unmap_aead_request( 571void cc_unmap_aead_request(struct device *dev, struct aead_request *req)
597 struct device *dev, struct aead_request *req)
598{ 572{
599 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 573 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
600 unsigned int hw_iv_size = areq_ctx->hw_iv_size; 574 unsigned int hw_iv_size = areq_ctx->hw_iv_size;
601 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 575 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
602 struct ssi_drvdata *drvdata = dev_get_drvdata(dev); 576 struct cc_drvdata *drvdata = dev_get_drvdata(dev);
603 u32 dummy; 577 u32 dummy;
604 bool chained; 578 bool chained;
605 u32 size_to_unmap = 0; 579 u32 size_to_unmap = 0;
606 580
607 if (areq_ctx->mac_buf_dma_addr != 0) { 581 if (areq_ctx->mac_buf_dma_addr) {
608 dma_unmap_single(dev, areq_ctx->mac_buf_dma_addr, 582 dma_unmap_single(dev, areq_ctx->mac_buf_dma_addr,
609 MAX_MAC_SIZE, DMA_BIDIRECTIONAL); 583 MAX_MAC_SIZE, DMA_BIDIRECTIONAL);
610 } 584 }
611 585
612#if SSI_CC_HAS_AES_GCM
613 if (areq_ctx->cipher_mode == DRV_CIPHER_GCTR) { 586 if (areq_ctx->cipher_mode == DRV_CIPHER_GCTR) {
614 if (areq_ctx->hkey_dma_addr != 0) { 587 if (areq_ctx->hkey_dma_addr) {
615 dma_unmap_single(dev, areq_ctx->hkey_dma_addr, 588 dma_unmap_single(dev, areq_ctx->hkey_dma_addr,
616 AES_BLOCK_SIZE, DMA_BIDIRECTIONAL); 589 AES_BLOCK_SIZE, DMA_BIDIRECTIONAL);
617 } 590 }
618 591
619 if (areq_ctx->gcm_block_len_dma_addr != 0) { 592 if (areq_ctx->gcm_block_len_dma_addr) {
620 dma_unmap_single(dev, areq_ctx->gcm_block_len_dma_addr, 593 dma_unmap_single(dev, areq_ctx->gcm_block_len_dma_addr,
621 AES_BLOCK_SIZE, DMA_TO_DEVICE); 594 AES_BLOCK_SIZE, DMA_TO_DEVICE);
622 } 595 }
623 596
624 if (areq_ctx->gcm_iv_inc1_dma_addr != 0) { 597 if (areq_ctx->gcm_iv_inc1_dma_addr) {
625 dma_unmap_single(dev, areq_ctx->gcm_iv_inc1_dma_addr, 598 dma_unmap_single(dev, areq_ctx->gcm_iv_inc1_dma_addr,
626 AES_BLOCK_SIZE, DMA_TO_DEVICE); 599 AES_BLOCK_SIZE, DMA_TO_DEVICE);
627 } 600 }
628 601
629 if (areq_ctx->gcm_iv_inc2_dma_addr != 0) { 602 if (areq_ctx->gcm_iv_inc2_dma_addr) {
630 dma_unmap_single(dev, areq_ctx->gcm_iv_inc2_dma_addr, 603 dma_unmap_single(dev, areq_ctx->gcm_iv_inc2_dma_addr,
631 AES_BLOCK_SIZE, DMA_TO_DEVICE); 604 AES_BLOCK_SIZE, DMA_TO_DEVICE);
632 } 605 }
633 } 606 }
634#endif
635 607
636 if (areq_ctx->ccm_hdr_size != ccm_header_size_null) { 608 if (areq_ctx->ccm_hdr_size != ccm_header_size_null) {
637 if (areq_ctx->ccm_iv0_dma_addr != 0) { 609 if (areq_ctx->ccm_iv0_dma_addr) {
638 dma_unmap_single(dev, areq_ctx->ccm_iv0_dma_addr, 610 dma_unmap_single(dev, areq_ctx->ccm_iv0_dma_addr,
639 AES_BLOCK_SIZE, DMA_TO_DEVICE); 611 AES_BLOCK_SIZE, DMA_TO_DEVICE);
640 } 612 }
641 613
642 dma_unmap_sg(dev, &areq_ctx->ccm_adata_sg, 1, DMA_TO_DEVICE); 614 dma_unmap_sg(dev, &areq_ctx->ccm_adata_sg, 1, DMA_TO_DEVICE);
643 } 615 }
644 if (areq_ctx->gen_ctx.iv_dma_addr != 0) { 616 if (areq_ctx->gen_ctx.iv_dma_addr) {
645 dma_unmap_single(dev, areq_ctx->gen_ctx.iv_dma_addr, 617 dma_unmap_single(dev, areq_ctx->gen_ctx.iv_dma_addr,
646 hw_iv_size, DMA_BIDIRECTIONAL); 618 hw_iv_size, DMA_BIDIRECTIONAL);
647 } 619 }
@@ -668,46 +640,37 @@ void ssi_buffer_mgr_unmap_aead_request(
668 size_to_unmap += crypto_aead_ivsize(tfm); 640 size_to_unmap += crypto_aead_ivsize(tfm);
669 641
670 dma_unmap_sg(dev, req->src, 642 dma_unmap_sg(dev, req->src,
671 ssi_buffer_mgr_get_sgl_nents(dev, req->src, size_to_unmap, 643 cc_get_sgl_nents(dev, req->src, size_to_unmap,
672 &dummy, &chained), 644 &dummy, &chained),
673 DMA_BIDIRECTIONAL); 645 DMA_BIDIRECTIONAL);
674 if (unlikely(req->src != req->dst)) { 646 if (req->src != req->dst) {
675 dev_dbg(dev, "Unmapping dst sgl: req->dst=%pK\n", 647 dev_dbg(dev, "Unmapping dst sgl: req->dst=%pK\n",
676 sg_virt(req->dst)); 648 sg_virt(req->dst));
677 dma_unmap_sg(dev, req->dst, 649 dma_unmap_sg(dev, req->dst,
678 ssi_buffer_mgr_get_sgl_nents(dev, req->dst, 650 cc_get_sgl_nents(dev, req->dst, size_to_unmap,
679 size_to_unmap, 651 &dummy, &chained),
680 &dummy, &chained),
681 DMA_BIDIRECTIONAL); 652 DMA_BIDIRECTIONAL);
682 } 653 }
683 if (drvdata->coherent && 654 if (drvdata->coherent &&
684 (areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT) && 655 areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT &&
685 likely(req->src == req->dst)) { 656 req->src == req->dst) {
686 u32 size_to_skip = req->assoclen; 657 /* copy back mac from temporary location to deal with possible
687 658 * data memory overriding that caused by cache coherence
688 if (areq_ctx->is_gcm4543) 659 * problem.
689 size_to_skip += crypto_aead_ivsize(tfm);
690
691 /* copy mac to a temporary location to deal with possible
692 * data memory overriding that caused by cache coherence problem.
693 */ 660 */
694 ssi_buffer_mgr_copy_scatterlist_portion( 661 cc_copy_mac(dev, req, CC_SG_FROM_BUF);
695 dev, areq_ctx->backup_mac, req->src,
696 size_to_skip + req->cryptlen - areq_ctx->req_authsize,
697 size_to_skip + req->cryptlen, SSI_SG_FROM_BUF);
698 } 662 }
699} 663}
700 664
701static inline int ssi_buffer_mgr_get_aead_icv_nents( 665static int cc_get_aead_icv_nents(struct device *dev, struct scatterlist *sgl,
702 struct device *dev, 666 unsigned int sgl_nents, unsigned int authsize,
703 struct scatterlist *sgl, 667 u32 last_entry_data_size,
704 unsigned int sgl_nents, 668 bool *is_icv_fragmented)
705 unsigned int authsize,
706 u32 last_entry_data_size,
707 bool *is_icv_fragmented)
708{ 669{
709 unsigned int icv_max_size = 0; 670 unsigned int icv_max_size = 0;
710 unsigned int icv_required_size = authsize > last_entry_data_size ? (authsize - last_entry_data_size) : authsize; 671 unsigned int icv_required_size = authsize > last_entry_data_size ?
672 (authsize - last_entry_data_size) :
673 authsize;
711 unsigned int nents; 674 unsigned int nents;
712 unsigned int i; 675 unsigned int i;
713 676
@@ -726,10 +689,12 @@ static inline int ssi_buffer_mgr_get_aead_icv_nents(
726 icv_max_size = sgl->length; 689 icv_max_size = sgl->length;
727 690
728 if (last_entry_data_size > authsize) { 691 if (last_entry_data_size > authsize) {
729 nents = 0; /* ICV attached to data in last entry (not fragmented!) */ 692 /* ICV attached to data in last entry (not fragmented!) */
693 nents = 0;
730 *is_icv_fragmented = false; 694 *is_icv_fragmented = false;
731 } else if (last_entry_data_size == authsize) { 695 } else if (last_entry_data_size == authsize) {
732 nents = 1; /* ICV placed in whole last entry (not fragmented!) */ 696 /* ICV placed in whole last entry (not fragmented!) */
697 nents = 1;
733 *is_icv_fragmented = false; 698 *is_icv_fragmented = false;
734 } else if (icv_max_size > icv_required_size) { 699 } else if (icv_max_size > icv_required_size) {
735 nents = 1; 700 nents = 1;
@@ -748,25 +713,25 @@ static inline int ssi_buffer_mgr_get_aead_icv_nents(
748 return nents; 713 return nents;
749} 714}
750 715
751static inline int ssi_buffer_mgr_aead_chain_iv( 716static int cc_aead_chain_iv(struct cc_drvdata *drvdata,
752 struct ssi_drvdata *drvdata, 717 struct aead_request *req,
753 struct aead_request *req, 718 struct buffer_array *sg_data,
754 struct buffer_array *sg_data, 719 bool is_last, bool do_chain)
755 bool is_last, bool do_chain)
756{ 720{
757 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 721 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
758 unsigned int hw_iv_size = areq_ctx->hw_iv_size; 722 unsigned int hw_iv_size = areq_ctx->hw_iv_size;
759 struct device *dev = drvdata_to_dev(drvdata); 723 struct device *dev = drvdata_to_dev(drvdata);
760 int rc = 0; 724 int rc = 0;
761 725
762 if (unlikely(!req->iv)) { 726 if (!req->iv) {
763 areq_ctx->gen_ctx.iv_dma_addr = 0; 727 areq_ctx->gen_ctx.iv_dma_addr = 0;
764 goto chain_iv_exit; 728 goto chain_iv_exit;
765 } 729 }
766 730
767 areq_ctx->gen_ctx.iv_dma_addr = dma_map_single(dev, req->iv, hw_iv_size, 731 areq_ctx->gen_ctx.iv_dma_addr = dma_map_single(dev, req->iv,
732 hw_iv_size,
768 DMA_BIDIRECTIONAL); 733 DMA_BIDIRECTIONAL);
769 if (unlikely(dma_mapping_error(dev, areq_ctx->gen_ctx.iv_dma_addr))) { 734 if (dma_mapping_error(dev, areq_ctx->gen_ctx.iv_dma_addr)) {
770 dev_err(dev, "Mapping iv %u B at va=%pK for DMA failed\n", 735 dev_err(dev, "Mapping iv %u B at va=%pK for DMA failed\n",
771 hw_iv_size, req->iv); 736 hw_iv_size, req->iv);
772 rc = -ENOMEM; 737 rc = -ENOMEM;
@@ -775,28 +740,27 @@ static inline int ssi_buffer_mgr_aead_chain_iv(
775 740
776 dev_dbg(dev, "Mapped iv %u B at va=%pK to dma=%pad\n", 741 dev_dbg(dev, "Mapped iv %u B at va=%pK to dma=%pad\n",
777 hw_iv_size, req->iv, &areq_ctx->gen_ctx.iv_dma_addr); 742 hw_iv_size, req->iv, &areq_ctx->gen_ctx.iv_dma_addr);
778 if (do_chain && areq_ctx->plaintext_authenticate_only) { // TODO: what about CTR?? ask Ron 743 // TODO: what about CTR?? ask Ron
744 if (do_chain && areq_ctx->plaintext_authenticate_only) {
779 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 745 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
780 unsigned int iv_size_to_authenc = crypto_aead_ivsize(tfm); 746 unsigned int iv_size_to_authenc = crypto_aead_ivsize(tfm);
781 unsigned int iv_ofs = GCM_BLOCK_RFC4_IV_OFFSET; 747 unsigned int iv_ofs = GCM_BLOCK_RFC4_IV_OFFSET;
782 /* Chain to given list */ 748 /* Chain to given list */
783 ssi_buffer_mgr_add_buffer_entry( 749 cc_add_buffer_entry(dev, sg_data,
784 dev, sg_data, 750 (areq_ctx->gen_ctx.iv_dma_addr + iv_ofs),
785 areq_ctx->gen_ctx.iv_dma_addr + iv_ofs, 751 iv_size_to_authenc, is_last,
786 iv_size_to_authenc, is_last, 752 &areq_ctx->assoc.mlli_nents);
787 &areq_ctx->assoc.mlli_nents); 753 areq_ctx->assoc_buff_type = CC_DMA_BUF_MLLI;
788 areq_ctx->assoc_buff_type = SSI_DMA_BUF_MLLI;
789 } 754 }
790 755
791chain_iv_exit: 756chain_iv_exit:
792 return rc; 757 return rc;
793} 758}
794 759
795static inline int ssi_buffer_mgr_aead_chain_assoc( 760static int cc_aead_chain_assoc(struct cc_drvdata *drvdata,
796 struct ssi_drvdata *drvdata, 761 struct aead_request *req,
797 struct aead_request *req, 762 struct buffer_array *sg_data,
798 struct buffer_array *sg_data, 763 bool is_last, bool do_chain)
799 bool is_last, bool do_chain)
800{ 764{
801 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 765 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
802 int rc = 0; 766 int rc = 0;
@@ -815,12 +779,12 @@ static inline int ssi_buffer_mgr_aead_chain_assoc(
815 goto chain_assoc_exit; 779 goto chain_assoc_exit;
816 } 780 }
817 781
818 if (unlikely(req->assoclen == 0)) { 782 if (req->assoclen == 0) {
819 areq_ctx->assoc_buff_type = SSI_DMA_BUF_NULL; 783 areq_ctx->assoc_buff_type = CC_DMA_BUF_NULL;
820 areq_ctx->assoc.nents = 0; 784 areq_ctx->assoc.nents = 0;
821 areq_ctx->assoc.mlli_nents = 0; 785 areq_ctx->assoc.mlli_nents = 0;
822 dev_dbg(dev, "Chain assoc of length 0: buff_type=%s nents=%u\n", 786 dev_dbg(dev, "Chain assoc of length 0: buff_type=%s nents=%u\n",
823 GET_DMA_BUFFER_TYPE(areq_ctx->assoc_buff_type), 787 cc_dma_buf_type(areq_ctx->assoc_buff_type),
824 areq_ctx->assoc.nents); 788 areq_ctx->assoc.nents);
825 goto chain_assoc_exit; 789 goto chain_assoc_exit;
826 } 790 }
@@ -828,12 +792,15 @@ static inline int ssi_buffer_mgr_aead_chain_assoc(
828 //iterate over the sgl to see how many entries are for associated data 792 //iterate over the sgl to see how many entries are for associated data
829 //it is assumed that if we reach here , the sgl is already mapped 793 //it is assumed that if we reach here , the sgl is already mapped
830 sg_index = current_sg->length; 794 sg_index = current_sg->length;
831 if (sg_index > size_of_assoc) { //the first entry in the scatter list contains all the associated data 795 //the first entry in the scatter list contains all the associated data
796 if (sg_index > size_of_assoc) {
832 mapped_nents++; 797 mapped_nents++;
833 } else { 798 } else {
834 while (sg_index <= size_of_assoc) { 799 while (sg_index <= size_of_assoc) {
835 current_sg = sg_next(current_sg); 800 current_sg = sg_next(current_sg);
836 //if have reached the end of the sgl, then this is unexpected 801 /* if have reached the end of the sgl, then this is
802 * unexpected
803 */
837 if (!current_sg) { 804 if (!current_sg) {
838 dev_err(dev, "reached end of sg list. unexpected\n"); 805 dev_err(dev, "reached end of sg list. unexpected\n");
839 return -EINVAL; 806 return -EINVAL;
@@ -842,7 +809,7 @@ static inline int ssi_buffer_mgr_aead_chain_assoc(
842 mapped_nents++; 809 mapped_nents++;
843 } 810 }
844 } 811 }
845 if (unlikely(mapped_nents > LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES)) { 812 if (mapped_nents > LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES) {
846 dev_err(dev, "Too many fragments. current %d max %d\n", 813 dev_err(dev, "Too many fragments. current %d max %d\n",
847 mapped_nents, LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES); 814 mapped_nents, LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES);
848 return -ENOMEM; 815 return -ENOMEM;
@@ -853,8 +820,7 @@ static inline int ssi_buffer_mgr_aead_chain_assoc(
853 * ccm header configurations 820 * ccm header configurations
854 */ 821 */
855 if (areq_ctx->ccm_hdr_size != ccm_header_size_null) { 822 if (areq_ctx->ccm_hdr_size != ccm_header_size_null) {
856 if (unlikely((mapped_nents + 1) > 823 if ((mapped_nents + 1) > LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES) {
857 LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES)) {
858 dev_err(dev, "CCM case.Too many fragments. Current %d max %d\n", 824 dev_err(dev, "CCM case.Too many fragments. Current %d max %d\n",
859 (areq_ctx->assoc.nents + 1), 825 (areq_ctx->assoc.nents + 1),
860 LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES); 826 LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES);
@@ -863,227 +829,175 @@ static inline int ssi_buffer_mgr_aead_chain_assoc(
863 } 829 }
864 } 830 }
865 831
866 if (likely(mapped_nents == 1) && 832 if (mapped_nents == 1 && areq_ctx->ccm_hdr_size == ccm_header_size_null)
867 (areq_ctx->ccm_hdr_size == ccm_header_size_null)) 833 areq_ctx->assoc_buff_type = CC_DMA_BUF_DLLI;
868 areq_ctx->assoc_buff_type = SSI_DMA_BUF_DLLI;
869 else 834 else
870 areq_ctx->assoc_buff_type = SSI_DMA_BUF_MLLI; 835 areq_ctx->assoc_buff_type = CC_DMA_BUF_MLLI;
871 836
872 if (unlikely((do_chain) || 837 if (do_chain || areq_ctx->assoc_buff_type == CC_DMA_BUF_MLLI) {
873 (areq_ctx->assoc_buff_type == SSI_DMA_BUF_MLLI))) {
874 dev_dbg(dev, "Chain assoc: buff_type=%s nents=%u\n", 838 dev_dbg(dev, "Chain assoc: buff_type=%s nents=%u\n",
875 GET_DMA_BUFFER_TYPE(areq_ctx->assoc_buff_type), 839 cc_dma_buf_type(areq_ctx->assoc_buff_type),
876 areq_ctx->assoc.nents); 840 areq_ctx->assoc.nents);
877 ssi_buffer_mgr_add_scatterlist_entry( 841 cc_add_sg_entry(dev, sg_data, areq_ctx->assoc.nents, req->src,
878 dev, sg_data, areq_ctx->assoc.nents, 842 req->assoclen, 0, is_last,
879 req->src, req->assoclen, 0, is_last, 843 &areq_ctx->assoc.mlli_nents);
880 &areq_ctx->assoc.mlli_nents); 844 areq_ctx->assoc_buff_type = CC_DMA_BUF_MLLI;
881 areq_ctx->assoc_buff_type = SSI_DMA_BUF_MLLI;
882 } 845 }
883 846
884chain_assoc_exit: 847chain_assoc_exit:
885 return rc; 848 return rc;
886} 849}
887 850
888static inline void ssi_buffer_mgr_prepare_aead_data_dlli( 851static void cc_prepare_aead_data_dlli(struct aead_request *req,
889 struct aead_request *req, 852 u32 *src_last_bytes, u32 *dst_last_bytes)
890 u32 *src_last_bytes, u32 *dst_last_bytes)
891{ 853{
892 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 854 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
893 enum drv_crypto_direction direct = areq_ctx->gen_ctx.op_type; 855 enum drv_crypto_direction direct = areq_ctx->gen_ctx.op_type;
894 unsigned int authsize = areq_ctx->req_authsize; 856 unsigned int authsize = areq_ctx->req_authsize;
895 857
896 areq_ctx->is_icv_fragmented = false; 858 areq_ctx->is_icv_fragmented = false;
897 if (likely(req->src == req->dst)) { 859 if (req->src == req->dst) {
898 /*INPLACE*/ 860 /*INPLACE*/
899 areq_ctx->icv_dma_addr = sg_dma_address( 861 areq_ctx->icv_dma_addr = sg_dma_address(areq_ctx->src_sgl) +
900 areq_ctx->src_sgl) +
901 (*src_last_bytes - authsize); 862 (*src_last_bytes - authsize);
902 areq_ctx->icv_virt_addr = sg_virt( 863 areq_ctx->icv_virt_addr = sg_virt(areq_ctx->src_sgl) +
903 areq_ctx->src_sgl) +
904 (*src_last_bytes - authsize); 864 (*src_last_bytes - authsize);
905 } else if (direct == DRV_CRYPTO_DIRECTION_DECRYPT) { 865 } else if (direct == DRV_CRYPTO_DIRECTION_DECRYPT) {
906 /*NON-INPLACE and DECRYPT*/ 866 /*NON-INPLACE and DECRYPT*/
907 areq_ctx->icv_dma_addr = sg_dma_address( 867 areq_ctx->icv_dma_addr = sg_dma_address(areq_ctx->src_sgl) +
908 areq_ctx->src_sgl) +
909 (*src_last_bytes - authsize); 868 (*src_last_bytes - authsize);
910 areq_ctx->icv_virt_addr = sg_virt( 869 areq_ctx->icv_virt_addr = sg_virt(areq_ctx->src_sgl) +
911 areq_ctx->src_sgl) +
912 (*src_last_bytes - authsize); 870 (*src_last_bytes - authsize);
913 } else { 871 } else {
914 /*NON-INPLACE and ENCRYPT*/ 872 /*NON-INPLACE and ENCRYPT*/
915 areq_ctx->icv_dma_addr = sg_dma_address( 873 areq_ctx->icv_dma_addr = sg_dma_address(areq_ctx->dst_sgl) +
916 areq_ctx->dst_sgl) +
917 (*dst_last_bytes - authsize); 874 (*dst_last_bytes - authsize);
918 areq_ctx->icv_virt_addr = sg_virt( 875 areq_ctx->icv_virt_addr = sg_virt(areq_ctx->dst_sgl) +
919 areq_ctx->dst_sgl) +
920 (*dst_last_bytes - authsize); 876 (*dst_last_bytes - authsize);
921 } 877 }
922} 878}
923 879
924static inline int ssi_buffer_mgr_prepare_aead_data_mlli( 880static int cc_prepare_aead_data_mlli(struct cc_drvdata *drvdata,
925 struct ssi_drvdata *drvdata, 881 struct aead_request *req,
926 struct aead_request *req, 882 struct buffer_array *sg_data,
927 struct buffer_array *sg_data, 883 u32 *src_last_bytes, u32 *dst_last_bytes,
928 u32 *src_last_bytes, u32 *dst_last_bytes, 884 bool is_last_table)
929 bool is_last_table)
930{ 885{
931 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 886 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
932 enum drv_crypto_direction direct = areq_ctx->gen_ctx.op_type; 887 enum drv_crypto_direction direct = areq_ctx->gen_ctx.op_type;
933 unsigned int authsize = areq_ctx->req_authsize; 888 unsigned int authsize = areq_ctx->req_authsize;
934 int rc = 0, icv_nents; 889 int rc = 0, icv_nents;
935 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
936 struct device *dev = drvdata_to_dev(drvdata); 890 struct device *dev = drvdata_to_dev(drvdata);
891 struct scatterlist *sg;
937 892
938 if (likely(req->src == req->dst)) { 893 if (req->src == req->dst) {
939 /*INPLACE*/ 894 /*INPLACE*/
940 ssi_buffer_mgr_add_scatterlist_entry(dev, sg_data, 895 cc_add_sg_entry(dev, sg_data, areq_ctx->src.nents,
941 areq_ctx->src.nents, 896 areq_ctx->src_sgl, areq_ctx->cryptlen,
942 areq_ctx->src_sgl, 897 areq_ctx->src_offset, is_last_table,
943 areq_ctx->cryptlen, 898 &areq_ctx->src.mlli_nents);
944 areq_ctx->src_offset, 899
945 is_last_table, 900 icv_nents = cc_get_aead_icv_nents(dev, areq_ctx->src_sgl,
946 &areq_ctx->src.mlli_nents); 901 areq_ctx->src.nents,
947 902 authsize, *src_last_bytes,
948 icv_nents = ssi_buffer_mgr_get_aead_icv_nents(dev, 903 &areq_ctx->is_icv_fragmented);
949 areq_ctx->src_sgl, 904 if (icv_nents < 0) {
950 areq_ctx->src.nents,
951 authsize,
952 *src_last_bytes,
953 &areq_ctx->is_icv_fragmented);
954 if (unlikely(icv_nents < 0)) {
955 rc = -ENOTSUPP; 905 rc = -ENOTSUPP;
956 goto prepare_data_mlli_exit; 906 goto prepare_data_mlli_exit;
957 } 907 }
958 908
959 if (unlikely(areq_ctx->is_icv_fragmented)) { 909 if (areq_ctx->is_icv_fragmented) {
960 /* Backup happens only when ICV is fragmented, ICV 910 /* Backup happens only when ICV is fragmented, ICV
961 * verification is made by CPU compare in order to simplify 911 * verification is made by CPU compare in order to
962 * MAC verification upon request completion 912 * simplify MAC verification upon request completion
963 */ 913 */
964 if (direct == DRV_CRYPTO_DIRECTION_DECRYPT) { 914 if (direct == DRV_CRYPTO_DIRECTION_DECRYPT) {
965 if (!drvdata->coherent) {
966 /* In coherent platforms (e.g. ACP) 915 /* In coherent platforms (e.g. ACP)
967 * already copying ICV for any 916 * already copying ICV for any
968 * INPLACE-DECRYPT operation, hence 917 * INPLACE-DECRYPT operation, hence
969 * we must neglect this code. 918 * we must neglect this code.
970 */ 919 */
971 u32 skip = req->assoclen; 920 if (!drvdata->coherent)
972 921 cc_copy_mac(dev, req, CC_SG_TO_BUF);
973 if (areq_ctx->is_gcm4543) 922
974 skip += crypto_aead_ivsize(tfm);
975
976 ssi_buffer_mgr_copy_scatterlist_portion(
977 dev, areq_ctx->backup_mac,
978 req->src,
979 (skip + req->cryptlen -
980 areq_ctx->req_authsize),
981 skip + req->cryptlen,
982 SSI_SG_TO_BUF);
983 }
984 areq_ctx->icv_virt_addr = areq_ctx->backup_mac; 923 areq_ctx->icv_virt_addr = areq_ctx->backup_mac;
985 } else { 924 } else {
986 areq_ctx->icv_virt_addr = areq_ctx->mac_buf; 925 areq_ctx->icv_virt_addr = areq_ctx->mac_buf;
987 areq_ctx->icv_dma_addr = areq_ctx->mac_buf_dma_addr; 926 areq_ctx->icv_dma_addr =
927 areq_ctx->mac_buf_dma_addr;
988 } 928 }
989 } else { /* Contig. ICV */ 929 } else { /* Contig. ICV */
930 sg = &areq_ctx->src_sgl[areq_ctx->src.nents - 1];
990 /*Should hanlde if the sg is not contig.*/ 931 /*Should hanlde if the sg is not contig.*/
991 areq_ctx->icv_dma_addr = sg_dma_address( 932 areq_ctx->icv_dma_addr = sg_dma_address(sg) +
992 &areq_ctx->src_sgl[areq_ctx->src.nents - 1]) +
993 (*src_last_bytes - authsize); 933 (*src_last_bytes - authsize);
994 areq_ctx->icv_virt_addr = sg_virt( 934 areq_ctx->icv_virt_addr = sg_virt(sg) +
995 &areq_ctx->src_sgl[areq_ctx->src.nents - 1]) +
996 (*src_last_bytes - authsize); 935 (*src_last_bytes - authsize);
997 } 936 }
998 937
999 } else if (direct == DRV_CRYPTO_DIRECTION_DECRYPT) { 938 } else if (direct == DRV_CRYPTO_DIRECTION_DECRYPT) {
1000 /*NON-INPLACE and DECRYPT*/ 939 /*NON-INPLACE and DECRYPT*/
1001 ssi_buffer_mgr_add_scatterlist_entry(dev, sg_data, 940 cc_add_sg_entry(dev, sg_data, areq_ctx->src.nents,
1002 areq_ctx->src.nents, 941 areq_ctx->src_sgl, areq_ctx->cryptlen,
1003 areq_ctx->src_sgl, 942 areq_ctx->src_offset, is_last_table,
1004 areq_ctx->cryptlen, 943 &areq_ctx->src.mlli_nents);
1005 areq_ctx->src_offset, 944 cc_add_sg_entry(dev, sg_data, areq_ctx->dst.nents,
1006 is_last_table, 945 areq_ctx->dst_sgl, areq_ctx->cryptlen,
1007 &areq_ctx->src.mlli_nents); 946 areq_ctx->dst_offset, is_last_table,
1008 ssi_buffer_mgr_add_scatterlist_entry(dev, sg_data, 947 &areq_ctx->dst.mlli_nents);
1009 areq_ctx->dst.nents, 948
1010 areq_ctx->dst_sgl, 949 icv_nents = cc_get_aead_icv_nents(dev, areq_ctx->src_sgl,
1011 areq_ctx->cryptlen, 950 areq_ctx->src.nents,
1012 areq_ctx->dst_offset, 951 authsize, *src_last_bytes,
1013 is_last_table, 952 &areq_ctx->is_icv_fragmented);
1014 &areq_ctx->dst.mlli_nents); 953 if (icv_nents < 0) {
1015
1016 icv_nents = ssi_buffer_mgr_get_aead_icv_nents(dev,
1017 areq_ctx->src_sgl,
1018 areq_ctx->src.nents,
1019 authsize,
1020 *src_last_bytes,
1021 &areq_ctx->is_icv_fragmented);
1022 if (unlikely(icv_nents < 0)) {
1023 rc = -ENOTSUPP; 954 rc = -ENOTSUPP;
1024 goto prepare_data_mlli_exit; 955 goto prepare_data_mlli_exit;
1025 } 956 }
1026 957
1027 if (unlikely(areq_ctx->is_icv_fragmented)) { 958 /* Backup happens only when ICV is fragmented, ICV
1028 /* Backup happens only when ICV is fragmented, ICV 959 * verification is made by CPU compare in order to simplify
1029 * verification is made by CPU compare in order to simplify 960 * MAC verification upon request completion
1030 * MAC verification upon request completion 961 */
1031 */ 962 if (areq_ctx->is_icv_fragmented) {
1032 u32 size_to_skip = req->assoclen; 963 cc_copy_mac(dev, req, CC_SG_TO_BUF);
1033
1034 if (areq_ctx->is_gcm4543)
1035 size_to_skip += crypto_aead_ivsize(tfm);
1036
1037 ssi_buffer_mgr_copy_scatterlist_portion(
1038 dev, areq_ctx->backup_mac, req->src,
1039 size_to_skip + req->cryptlen - areq_ctx->req_authsize,
1040 size_to_skip + req->cryptlen, SSI_SG_TO_BUF);
1041 areq_ctx->icv_virt_addr = areq_ctx->backup_mac; 964 areq_ctx->icv_virt_addr = areq_ctx->backup_mac;
965
1042 } else { /* Contig. ICV */ 966 } else { /* Contig. ICV */
967 sg = &areq_ctx->src_sgl[areq_ctx->src.nents - 1];
1043 /*Should hanlde if the sg is not contig.*/ 968 /*Should hanlde if the sg is not contig.*/
1044 areq_ctx->icv_dma_addr = sg_dma_address( 969 areq_ctx->icv_dma_addr = sg_dma_address(sg) +
1045 &areq_ctx->src_sgl[areq_ctx->src.nents - 1]) +
1046 (*src_last_bytes - authsize); 970 (*src_last_bytes - authsize);
1047 areq_ctx->icv_virt_addr = sg_virt( 971 areq_ctx->icv_virt_addr = sg_virt(sg) +
1048 &areq_ctx->src_sgl[areq_ctx->src.nents - 1]) +
1049 (*src_last_bytes - authsize); 972 (*src_last_bytes - authsize);
1050 } 973 }
1051 974
1052 } else { 975 } else {
1053 /*NON-INPLACE and ENCRYPT*/ 976 /*NON-INPLACE and ENCRYPT*/
1054 ssi_buffer_mgr_add_scatterlist_entry(dev, sg_data, 977 cc_add_sg_entry(dev, sg_data, areq_ctx->dst.nents,
1055 areq_ctx->dst.nents, 978 areq_ctx->dst_sgl, areq_ctx->cryptlen,
1056 areq_ctx->dst_sgl, 979 areq_ctx->dst_offset, is_last_table,
1057 areq_ctx->cryptlen, 980 &areq_ctx->dst.mlli_nents);
1058 areq_ctx->dst_offset, 981 cc_add_sg_entry(dev, sg_data, areq_ctx->src.nents,
1059 is_last_table, 982 areq_ctx->src_sgl, areq_ctx->cryptlen,
1060 &areq_ctx->dst.mlli_nents); 983 areq_ctx->src_offset, is_last_table,
1061 ssi_buffer_mgr_add_scatterlist_entry(dev, sg_data, 984 &areq_ctx->src.mlli_nents);
1062 areq_ctx->src.nents, 985
1063 areq_ctx->src_sgl, 986 icv_nents = cc_get_aead_icv_nents(dev, areq_ctx->dst_sgl,
1064 areq_ctx->cryptlen, 987 areq_ctx->dst.nents,
1065 areq_ctx->src_offset, 988 authsize, *dst_last_bytes,
1066 is_last_table, 989 &areq_ctx->is_icv_fragmented);
1067 &areq_ctx->src.mlli_nents); 990 if (icv_nents < 0) {
1068
1069 icv_nents = ssi_buffer_mgr_get_aead_icv_nents(dev,
1070 areq_ctx->dst_sgl,
1071 areq_ctx->dst.nents,
1072 authsize,
1073 *dst_last_bytes,
1074 &areq_ctx->is_icv_fragmented);
1075 if (unlikely(icv_nents < 0)) {
1076 rc = -ENOTSUPP; 991 rc = -ENOTSUPP;
1077 goto prepare_data_mlli_exit; 992 goto prepare_data_mlli_exit;
1078 } 993 }
1079 994
1080 if (likely(!areq_ctx->is_icv_fragmented)) { 995 if (!areq_ctx->is_icv_fragmented) {
996 sg = &areq_ctx->dst_sgl[areq_ctx->dst.nents - 1];
1081 /* Contig. ICV */ 997 /* Contig. ICV */
1082 areq_ctx->icv_dma_addr = sg_dma_address( 998 areq_ctx->icv_dma_addr = sg_dma_address(sg) +
1083 &areq_ctx->dst_sgl[areq_ctx->dst.nents - 1]) +
1084 (*dst_last_bytes - authsize); 999 (*dst_last_bytes - authsize);
1085 areq_ctx->icv_virt_addr = sg_virt( 1000 areq_ctx->icv_virt_addr = sg_virt(sg) +
1086 &areq_ctx->dst_sgl[areq_ctx->dst.nents - 1]) +
1087 (*dst_last_bytes - authsize); 1001 (*dst_last_bytes - authsize);
1088 } else { 1002 } else {
1089 areq_ctx->icv_dma_addr = areq_ctx->mac_buf_dma_addr; 1003 areq_ctx->icv_dma_addr = areq_ctx->mac_buf_dma_addr;
@@ -1095,11 +1009,10 @@ prepare_data_mlli_exit:
1095 return rc; 1009 return rc;
1096} 1010}
1097 1011
1098static inline int ssi_buffer_mgr_aead_chain_data( 1012static int cc_aead_chain_data(struct cc_drvdata *drvdata,
1099 struct ssi_drvdata *drvdata, 1013 struct aead_request *req,
1100 struct aead_request *req, 1014 struct buffer_array *sg_data,
1101 struct buffer_array *sg_data, 1015 bool is_last_table, bool do_chain)
1102 bool is_last_table, bool do_chain)
1103{ 1016{
1104 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 1017 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
1105 struct device *dev = drvdata_to_dev(drvdata); 1018 struct device *dev = drvdata_to_dev(drvdata);
@@ -1109,7 +1022,8 @@ static inline int ssi_buffer_mgr_aead_chain_data(
1109 int rc = 0; 1022 int rc = 0;
1110 u32 src_mapped_nents = 0, dst_mapped_nents = 0; 1023 u32 src_mapped_nents = 0, dst_mapped_nents = 0;
1111 u32 offset = 0; 1024 u32 offset = 0;
1112 unsigned int size_for_map = req->assoclen + req->cryptlen; /*non-inplace mode*/ 1025 /* non-inplace mode */
1026 unsigned int size_for_map = req->assoclen + req->cryptlen;
1113 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1027 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1114 u32 sg_index = 0; 1028 u32 sg_index = 0;
1115 bool chained = false; 1029 bool chained = false;
@@ -1130,11 +1044,10 @@ static inline int ssi_buffer_mgr_aead_chain_data(
1130 if (is_gcm4543) 1044 if (is_gcm4543)
1131 size_for_map += crypto_aead_ivsize(tfm); 1045 size_for_map += crypto_aead_ivsize(tfm);
1132 1046
1133 size_for_map += (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ? authsize : 0; 1047 size_for_map += (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ?
1134 src_mapped_nents = ssi_buffer_mgr_get_sgl_nents(dev, req->src, 1048 authsize : 0;
1135 size_for_map, 1049 src_mapped_nents = cc_get_sgl_nents(dev, req->src, size_for_map,
1136 &src_last_bytes, 1050 &src_last_bytes, &chained);
1137 &chained);
1138 sg_index = areq_ctx->src_sgl->length; 1051 sg_index = areq_ctx->src_sgl->length;
1139 //check where the data starts 1052 //check where the data starts
1140 while (sg_index <= size_to_skip) { 1053 while (sg_index <= size_to_skip) {
@@ -1148,7 +1061,7 @@ static inline int ssi_buffer_mgr_aead_chain_data(
1148 sg_index += areq_ctx->src_sgl->length; 1061 sg_index += areq_ctx->src_sgl->length;
1149 src_mapped_nents--; 1062 src_mapped_nents--;
1150 } 1063 }
1151 if (unlikely(src_mapped_nents > LLI_MAX_NUM_OF_DATA_ENTRIES)) { 1064 if (src_mapped_nents > LLI_MAX_NUM_OF_DATA_ENTRIES) {
1152 dev_err(dev, "Too many fragments. current %d max %d\n", 1065 dev_err(dev, "Too many fragments. current %d max %d\n",
1153 src_mapped_nents, LLI_MAX_NUM_OF_DATA_ENTRIES); 1066 src_mapped_nents, LLI_MAX_NUM_OF_DATA_ENTRIES);
1154 return -ENOMEM; 1067 return -ENOMEM;
@@ -1160,26 +1073,23 @@ static inline int ssi_buffer_mgr_aead_chain_data(
1160 1073
1161 if (req->src != req->dst) { 1074 if (req->src != req->dst) {
1162 size_for_map = req->assoclen + req->cryptlen; 1075 size_for_map = req->assoclen + req->cryptlen;
1163 size_for_map += (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ? authsize : 0; 1076 size_for_map += (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ?
1077 authsize : 0;
1164 if (is_gcm4543) 1078 if (is_gcm4543)
1165 size_for_map += crypto_aead_ivsize(tfm); 1079 size_for_map += crypto_aead_ivsize(tfm);
1166 1080
1167 rc = ssi_buffer_mgr_map_scatterlist(dev, req->dst, size_for_map, 1081 rc = cc_map_sg(dev, req->dst, size_for_map, DMA_BIDIRECTIONAL,
1168 DMA_BIDIRECTIONAL, 1082 &areq_ctx->dst.nents,
1169 &areq_ctx->dst.nents, 1083 LLI_MAX_NUM_OF_DATA_ENTRIES, &dst_last_bytes,
1170 LLI_MAX_NUM_OF_DATA_ENTRIES, 1084 &dst_mapped_nents);
1171 &dst_last_bytes, 1085 if (rc) {
1172 &dst_mapped_nents);
1173 if (unlikely(rc != 0)) {
1174 rc = -ENOMEM; 1086 rc = -ENOMEM;
1175 goto chain_data_exit; 1087 goto chain_data_exit;
1176 } 1088 }
1177 } 1089 }
1178 1090
1179 dst_mapped_nents = ssi_buffer_mgr_get_sgl_nents(dev, req->dst, 1091 dst_mapped_nents = cc_get_sgl_nents(dev, req->dst, size_for_map,
1180 size_for_map, 1092 &dst_last_bytes, &chained);
1181 &dst_last_bytes,
1182 &chained);
1183 sg_index = areq_ctx->dst_sgl->length; 1093 sg_index = areq_ctx->dst_sgl->length;
1184 offset = size_to_skip; 1094 offset = size_to_skip;
1185 1095
@@ -1195,45 +1105,43 @@ static inline int ssi_buffer_mgr_aead_chain_data(
1195 sg_index += areq_ctx->dst_sgl->length; 1105 sg_index += areq_ctx->dst_sgl->length;
1196 dst_mapped_nents--; 1106 dst_mapped_nents--;
1197 } 1107 }
1198 if (unlikely(dst_mapped_nents > LLI_MAX_NUM_OF_DATA_ENTRIES)) { 1108 if (dst_mapped_nents > LLI_MAX_NUM_OF_DATA_ENTRIES) {
1199 dev_err(dev, "Too many fragments. current %d max %d\n", 1109 dev_err(dev, "Too many fragments. current %d max %d\n",
1200 dst_mapped_nents, LLI_MAX_NUM_OF_DATA_ENTRIES); 1110 dst_mapped_nents, LLI_MAX_NUM_OF_DATA_ENTRIES);
1201 return -ENOMEM; 1111 return -ENOMEM;
1202 } 1112 }
1203 areq_ctx->dst.nents = dst_mapped_nents; 1113 areq_ctx->dst.nents = dst_mapped_nents;
1204 areq_ctx->dst_offset = offset; 1114 areq_ctx->dst_offset = offset;
1205 if ((src_mapped_nents > 1) || 1115 if (src_mapped_nents > 1 ||
1206 (dst_mapped_nents > 1) || 1116 dst_mapped_nents > 1 ||
1207 do_chain) { 1117 do_chain) {
1208 areq_ctx->data_buff_type = SSI_DMA_BUF_MLLI; 1118 areq_ctx->data_buff_type = CC_DMA_BUF_MLLI;
1209 rc = ssi_buffer_mgr_prepare_aead_data_mlli(drvdata, req, 1119 rc = cc_prepare_aead_data_mlli(drvdata, req, sg_data,
1210 sg_data, 1120 &src_last_bytes,
1211 &src_last_bytes, 1121 &dst_last_bytes, is_last_table);
1212 &dst_last_bytes,
1213 is_last_table);
1214 } else { 1122 } else {
1215 areq_ctx->data_buff_type = SSI_DMA_BUF_DLLI; 1123 areq_ctx->data_buff_type = CC_DMA_BUF_DLLI;
1216 ssi_buffer_mgr_prepare_aead_data_dlli( 1124 cc_prepare_aead_data_dlli(req, &src_last_bytes,
1217 req, &src_last_bytes, &dst_last_bytes); 1125 &dst_last_bytes);
1218 } 1126 }
1219 1127
1220chain_data_exit: 1128chain_data_exit:
1221 return rc; 1129 return rc;
1222} 1130}
1223 1131
1224static void ssi_buffer_mgr_update_aead_mlli_nents(struct ssi_drvdata *drvdata, 1132static void cc_update_aead_mlli_nents(struct cc_drvdata *drvdata,
1225 struct aead_request *req) 1133 struct aead_request *req)
1226{ 1134{
1227 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 1135 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
1228 u32 curr_mlli_size = 0; 1136 u32 curr_mlli_size = 0;
1229 1137
1230 if (areq_ctx->assoc_buff_type == SSI_DMA_BUF_MLLI) { 1138 if (areq_ctx->assoc_buff_type == CC_DMA_BUF_MLLI) {
1231 areq_ctx->assoc.sram_addr = drvdata->mlli_sram_addr; 1139 areq_ctx->assoc.sram_addr = drvdata->mlli_sram_addr;
1232 curr_mlli_size = areq_ctx->assoc.mlli_nents * 1140 curr_mlli_size = areq_ctx->assoc.mlli_nents *
1233 LLI_ENTRY_BYTE_SIZE; 1141 LLI_ENTRY_BYTE_SIZE;
1234 } 1142 }
1235 1143
1236 if (areq_ctx->data_buff_type == SSI_DMA_BUF_MLLI) { 1144 if (areq_ctx->data_buff_type == CC_DMA_BUF_MLLI) {
1237 /*Inplace case dst nents equal to src nents*/ 1145 /*Inplace case dst nents equal to src nents*/
1238 if (req->src == req->dst) { 1146 if (req->src == req->dst) {
1239 areq_ctx->dst.mlli_nents = areq_ctx->src.mlli_nents; 1147 areq_ctx->dst.mlli_nents = areq_ctx->src.mlli_nents;
@@ -1272,8 +1180,7 @@ static void ssi_buffer_mgr_update_aead_mlli_nents(struct ssi_drvdata *drvdata,
1272 } 1180 }
1273} 1181}
1274 1182
1275int ssi_buffer_mgr_map_aead_request( 1183int cc_map_aead_request(struct cc_drvdata *drvdata, struct aead_request *req)
1276 struct ssi_drvdata *drvdata, struct aead_request *req)
1277{ 1184{
1278 struct aead_req_ctx *areq_ctx = aead_request_ctx(req); 1185 struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
1279 struct mlli_params *mlli_params = &areq_ctx->mlli_params; 1186 struct mlli_params *mlli_params = &areq_ctx->mlli_params;
@@ -1284,30 +1191,22 @@ int ssi_buffer_mgr_map_aead_request(
1284 int rc = 0; 1191 int rc = 0;
1285 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1192 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1286 bool is_gcm4543 = areq_ctx->is_gcm4543; 1193 bool is_gcm4543 = areq_ctx->is_gcm4543;
1287 1194 dma_addr_t dma_addr;
1288 u32 mapped_nents = 0; 1195 u32 mapped_nents = 0;
1289 u32 dummy = 0; /*used for the assoc data fragments */ 1196 u32 dummy = 0; /*used for the assoc data fragments */
1290 u32 size_to_map = 0; 1197 u32 size_to_map = 0;
1198 gfp_t flags = cc_gfp_flags(&req->base);
1291 1199
1292 mlli_params->curr_pool = NULL; 1200 mlli_params->curr_pool = NULL;
1293 sg_data.num_of_buffers = 0; 1201 sg_data.num_of_buffers = 0;
1294 1202
1203 /* copy mac to a temporary location to deal with possible
1204 * data memory overriding that caused by cache coherence problem.
1205 */
1295 if (drvdata->coherent && 1206 if (drvdata->coherent &&
1296 (areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT) && 1207 areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT &&
1297 likely(req->src == req->dst)) { 1208 req->src == req->dst)
1298 u32 size_to_skip = req->assoclen; 1209 cc_copy_mac(dev, req, CC_SG_TO_BUF);
1299
1300 if (is_gcm4543)
1301 size_to_skip += crypto_aead_ivsize(tfm);
1302
1303 /* copy mac to a temporary location to deal with possible
1304 * data memory overriding that caused by cache coherence problem.
1305 */
1306 ssi_buffer_mgr_copy_scatterlist_portion(
1307 dev, areq_ctx->backup_mac, req->src,
1308 size_to_skip + req->cryptlen - areq_ctx->req_authsize,
1309 size_to_skip + req->cryptlen, SSI_SG_TO_BUF);
1310 }
1311 1210
1312 /* cacluate the size for cipher remove ICV in decrypt*/ 1211 /* cacluate the size for cipher remove ICV in decrypt*/
1313 areq_ctx->cryptlen = (areq_ctx->gen_ctx.op_type == 1212 areq_ctx->cryptlen = (areq_ctx->gen_ctx.op_type ==
@@ -1315,90 +1214,83 @@ int ssi_buffer_mgr_map_aead_request(
1315 req->cryptlen : 1214 req->cryptlen :
1316 (req->cryptlen - authsize); 1215 (req->cryptlen - authsize);
1317 1216
1318 areq_ctx->mac_buf_dma_addr = dma_map_single(dev, areq_ctx->mac_buf, 1217 dma_addr = dma_map_single(dev, areq_ctx->mac_buf, MAX_MAC_SIZE,
1319 MAX_MAC_SIZE, 1218 DMA_BIDIRECTIONAL);
1320 DMA_BIDIRECTIONAL); 1219 if (dma_mapping_error(dev, dma_addr)) {
1321 if (unlikely(dma_mapping_error(dev, areq_ctx->mac_buf_dma_addr))) {
1322 dev_err(dev, "Mapping mac_buf %u B at va=%pK for DMA failed\n", 1220 dev_err(dev, "Mapping mac_buf %u B at va=%pK for DMA failed\n",
1323 MAX_MAC_SIZE, areq_ctx->mac_buf); 1221 MAX_MAC_SIZE, areq_ctx->mac_buf);
1324 rc = -ENOMEM; 1222 rc = -ENOMEM;
1325 goto aead_map_failure; 1223 goto aead_map_failure;
1326 } 1224 }
1225 areq_ctx->mac_buf_dma_addr = dma_addr;
1327 1226
1328 if (areq_ctx->ccm_hdr_size != ccm_header_size_null) { 1227 if (areq_ctx->ccm_hdr_size != ccm_header_size_null) {
1329 areq_ctx->ccm_iv0_dma_addr = dma_map_single(dev, 1228 void *addr = areq_ctx->ccm_config + CCM_CTR_COUNT_0_OFFSET;
1330 (areq_ctx->ccm_config + CCM_CTR_COUNT_0_OFFSET),
1331 AES_BLOCK_SIZE,
1332 DMA_TO_DEVICE);
1333 1229
1334 if (unlikely(dma_mapping_error(dev, areq_ctx->ccm_iv0_dma_addr))) { 1230 dma_addr = dma_map_single(dev, addr, AES_BLOCK_SIZE,
1231 DMA_TO_DEVICE);
1232
1233 if (dma_mapping_error(dev, dma_addr)) {
1335 dev_err(dev, "Mapping mac_buf %u B at va=%pK for DMA failed\n", 1234 dev_err(dev, "Mapping mac_buf %u B at va=%pK for DMA failed\n",
1336 AES_BLOCK_SIZE, 1235 AES_BLOCK_SIZE, addr);
1337 (areq_ctx->ccm_config +
1338 CCM_CTR_COUNT_0_OFFSET));
1339 areq_ctx->ccm_iv0_dma_addr = 0; 1236 areq_ctx->ccm_iv0_dma_addr = 0;
1340 rc = -ENOMEM; 1237 rc = -ENOMEM;
1341 goto aead_map_failure; 1238 goto aead_map_failure;
1342 } 1239 }
1343 if (ssi_aead_handle_config_buf(dev, areq_ctx, 1240 areq_ctx->ccm_iv0_dma_addr = dma_addr;
1344 areq_ctx->ccm_config, &sg_data, 1241
1345 req->assoclen) != 0) { 1242 if (cc_set_aead_conf_buf(dev, areq_ctx, areq_ctx->ccm_config,
1243 &sg_data, req->assoclen)) {
1346 rc = -ENOMEM; 1244 rc = -ENOMEM;
1347 goto aead_map_failure; 1245 goto aead_map_failure;
1348 } 1246 }
1349 } 1247 }
1350 1248
1351#if SSI_CC_HAS_AES_GCM
1352 if (areq_ctx->cipher_mode == DRV_CIPHER_GCTR) { 1249 if (areq_ctx->cipher_mode == DRV_CIPHER_GCTR) {
1353 areq_ctx->hkey_dma_addr = dma_map_single(dev, 1250 dma_addr = dma_map_single(dev, areq_ctx->hkey, AES_BLOCK_SIZE,
1354 areq_ctx->hkey, 1251 DMA_BIDIRECTIONAL);
1355 AES_BLOCK_SIZE, 1252 if (dma_mapping_error(dev, dma_addr)) {
1356 DMA_BIDIRECTIONAL);
1357 if (unlikely(dma_mapping_error(dev, areq_ctx->hkey_dma_addr))) {
1358 dev_err(dev, "Mapping hkey %u B at va=%pK for DMA failed\n", 1253 dev_err(dev, "Mapping hkey %u B at va=%pK for DMA failed\n",
1359 AES_BLOCK_SIZE, areq_ctx->hkey); 1254 AES_BLOCK_SIZE, areq_ctx->hkey);
1360 rc = -ENOMEM; 1255 rc = -ENOMEM;
1361 goto aead_map_failure; 1256 goto aead_map_failure;
1362 } 1257 }
1258 areq_ctx->hkey_dma_addr = dma_addr;
1363 1259
1364 areq_ctx->gcm_block_len_dma_addr = dma_map_single(dev, 1260 dma_addr = dma_map_single(dev, &areq_ctx->gcm_len_block,
1365 &areq_ctx->gcm_len_block, 1261 AES_BLOCK_SIZE, DMA_TO_DEVICE);
1366 AES_BLOCK_SIZE, 1262 if (dma_mapping_error(dev, dma_addr)) {
1367 DMA_TO_DEVICE);
1368 if (unlikely(dma_mapping_error(dev, areq_ctx->gcm_block_len_dma_addr))) {
1369 dev_err(dev, "Mapping gcm_len_block %u B at va=%pK for DMA failed\n", 1263 dev_err(dev, "Mapping gcm_len_block %u B at va=%pK for DMA failed\n",
1370 AES_BLOCK_SIZE, &areq_ctx->gcm_len_block); 1264 AES_BLOCK_SIZE, &areq_ctx->gcm_len_block);
1371 rc = -ENOMEM; 1265 rc = -ENOMEM;
1372 goto aead_map_failure; 1266 goto aead_map_failure;
1373 } 1267 }
1268 areq_ctx->gcm_block_len_dma_addr = dma_addr;
1374 1269
1375 areq_ctx->gcm_iv_inc1_dma_addr = dma_map_single(dev, 1270 dma_addr = dma_map_single(dev, areq_ctx->gcm_iv_inc1,
1376 areq_ctx->gcm_iv_inc1, 1271 AES_BLOCK_SIZE, DMA_TO_DEVICE);
1377 AES_BLOCK_SIZE,
1378 DMA_TO_DEVICE);
1379 1272
1380 if (unlikely(dma_mapping_error(dev, areq_ctx->gcm_iv_inc1_dma_addr))) { 1273 if (dma_mapping_error(dev, dma_addr)) {
1381 dev_err(dev, "Mapping gcm_iv_inc1 %u B at va=%pK for DMA failed\n", 1274 dev_err(dev, "Mapping gcm_iv_inc1 %u B at va=%pK for DMA failed\n",
1382 AES_BLOCK_SIZE, (areq_ctx->gcm_iv_inc1)); 1275 AES_BLOCK_SIZE, (areq_ctx->gcm_iv_inc1));
1383 areq_ctx->gcm_iv_inc1_dma_addr = 0; 1276 areq_ctx->gcm_iv_inc1_dma_addr = 0;
1384 rc = -ENOMEM; 1277 rc = -ENOMEM;
1385 goto aead_map_failure; 1278 goto aead_map_failure;
1386 } 1279 }
1280 areq_ctx->gcm_iv_inc1_dma_addr = dma_addr;
1387 1281
1388 areq_ctx->gcm_iv_inc2_dma_addr = dma_map_single(dev, 1282 dma_addr = dma_map_single(dev, areq_ctx->gcm_iv_inc2,
1389 areq_ctx->gcm_iv_inc2, 1283 AES_BLOCK_SIZE, DMA_TO_DEVICE);
1390 AES_BLOCK_SIZE,
1391 DMA_TO_DEVICE);
1392 1284
1393 if (unlikely(dma_mapping_error(dev, areq_ctx->gcm_iv_inc2_dma_addr))) { 1285 if (dma_mapping_error(dev, dma_addr)) {
1394 dev_err(dev, "Mapping gcm_iv_inc2 %u B at va=%pK for DMA failed\n", 1286 dev_err(dev, "Mapping gcm_iv_inc2 %u B at va=%pK for DMA failed\n",
1395 AES_BLOCK_SIZE, (areq_ctx->gcm_iv_inc2)); 1287 AES_BLOCK_SIZE, (areq_ctx->gcm_iv_inc2));
1396 areq_ctx->gcm_iv_inc2_dma_addr = 0; 1288 areq_ctx->gcm_iv_inc2_dma_addr = 0;
1397 rc = -ENOMEM; 1289 rc = -ENOMEM;
1398 goto aead_map_failure; 1290 goto aead_map_failure;
1399 } 1291 }
1292 areq_ctx->gcm_iv_inc2_dma_addr = dma_addr;
1400 } 1293 }
1401#endif /*SSI_CC_HAS_AES_GCM*/
1402 1294
1403 size_to_map = req->cryptlen + req->assoclen; 1295 size_to_map = req->cryptlen + req->assoclen;
1404 if (areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_ENCRYPT) 1296 if (areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_ENCRYPT)
@@ -1406,29 +1298,31 @@ int ssi_buffer_mgr_map_aead_request(
1406 1298
1407 if (is_gcm4543) 1299 if (is_gcm4543)
1408 size_to_map += crypto_aead_ivsize(tfm); 1300 size_to_map += crypto_aead_ivsize(tfm);
1409 rc = ssi_buffer_mgr_map_scatterlist(dev, req->src, 1301 rc = cc_map_sg(dev, req->src, size_to_map, DMA_BIDIRECTIONAL,
1410 size_to_map, DMA_BIDIRECTIONAL, &areq_ctx->src.nents, 1302 &areq_ctx->src.nents,
1411 LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES + LLI_MAX_NUM_OF_DATA_ENTRIES, &dummy, &mapped_nents); 1303 (LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES +
1412 if (unlikely(rc != 0)) { 1304 LLI_MAX_NUM_OF_DATA_ENTRIES),
1305 &dummy, &mapped_nents);
1306 if (rc) {
1413 rc = -ENOMEM; 1307 rc = -ENOMEM;
1414 goto aead_map_failure; 1308 goto aead_map_failure;
1415 } 1309 }
1416 1310
1417 if (likely(areq_ctx->is_single_pass)) { 1311 if (areq_ctx->is_single_pass) {
1418 /* 1312 /*
1419 * Create MLLI table for: 1313 * Create MLLI table for:
1420 * (1) Assoc. data 1314 * (1) Assoc. data
1421 * (2) Src/Dst SGLs 1315 * (2) Src/Dst SGLs
1422 * Note: IV is contg. buffer (not an SGL) 1316 * Note: IV is contg. buffer (not an SGL)
1423 */ 1317 */
1424 rc = ssi_buffer_mgr_aead_chain_assoc(drvdata, req, &sg_data, true, false); 1318 rc = cc_aead_chain_assoc(drvdata, req, &sg_data, true, false);
1425 if (unlikely(rc != 0)) 1319 if (rc)
1426 goto aead_map_failure; 1320 goto aead_map_failure;
1427 rc = ssi_buffer_mgr_aead_chain_iv(drvdata, req, &sg_data, true, false); 1321 rc = cc_aead_chain_iv(drvdata, req, &sg_data, true, false);
1428 if (unlikely(rc != 0)) 1322 if (rc)
1429 goto aead_map_failure; 1323 goto aead_map_failure;
1430 rc = ssi_buffer_mgr_aead_chain_data(drvdata, req, &sg_data, true, false); 1324 rc = cc_aead_chain_data(drvdata, req, &sg_data, true, false);
1431 if (unlikely(rc != 0)) 1325 if (rc)
1432 goto aead_map_failure; 1326 goto aead_map_failure;
1433 } else { /* DOUBLE-PASS flow */ 1327 } else { /* DOUBLE-PASS flow */
1434 /* 1328 /*
@@ -1451,27 +1345,28 @@ int ssi_buffer_mgr_map_aead_request(
1451 * (3) MLLI for src 1345 * (3) MLLI for src
1452 * (4) MLLI for dst 1346 * (4) MLLI for dst
1453 */ 1347 */
1454 rc = ssi_buffer_mgr_aead_chain_assoc(drvdata, req, &sg_data, false, true); 1348 rc = cc_aead_chain_assoc(drvdata, req, &sg_data, false, true);
1455 if (unlikely(rc != 0)) 1349 if (rc)
1456 goto aead_map_failure; 1350 goto aead_map_failure;
1457 rc = ssi_buffer_mgr_aead_chain_iv(drvdata, req, &sg_data, false, true); 1351 rc = cc_aead_chain_iv(drvdata, req, &sg_data, false, true);
1458 if (unlikely(rc != 0)) 1352 if (rc)
1459 goto aead_map_failure; 1353 goto aead_map_failure;
1460 rc = ssi_buffer_mgr_aead_chain_data(drvdata, req, &sg_data, true, true); 1354 rc = cc_aead_chain_data(drvdata, req, &sg_data, true, true);
1461 if (unlikely(rc != 0)) 1355 if (rc)
1462 goto aead_map_failure; 1356 goto aead_map_failure;
1463 } 1357 }
1464 1358
1465 /* Mlli support -start building the MLLI according to the above results */ 1359 /* Mlli support -start building the MLLI according to the above
1466 if (unlikely( 1360 * results
1467 (areq_ctx->assoc_buff_type == SSI_DMA_BUF_MLLI) || 1361 */
1468 (areq_ctx->data_buff_type == SSI_DMA_BUF_MLLI))) { 1362 if (areq_ctx->assoc_buff_type == CC_DMA_BUF_MLLI ||
1363 areq_ctx->data_buff_type == CC_DMA_BUF_MLLI) {
1469 mlli_params->curr_pool = buff_mgr->mlli_buffs_pool; 1364 mlli_params->curr_pool = buff_mgr->mlli_buffs_pool;
1470 rc = ssi_buffer_mgr_generate_mlli(dev, &sg_data, mlli_params); 1365 rc = cc_generate_mlli(dev, &sg_data, mlli_params, flags);
1471 if (unlikely(rc != 0)) 1366 if (rc)
1472 goto aead_map_failure; 1367 goto aead_map_failure;
1473 1368
1474 ssi_buffer_mgr_update_aead_mlli_nents(drvdata, req); 1369 cc_update_aead_mlli_nents(drvdata, req);
1475 dev_dbg(dev, "assoc params mn %d\n", 1370 dev_dbg(dev, "assoc params mn %d\n",
1476 areq_ctx->assoc.mlli_nents); 1371 areq_ctx->assoc.mlli_nents);
1477 dev_dbg(dev, "src params mn %d\n", areq_ctx->src.mlli_nents); 1372 dev_dbg(dev, "src params mn %d\n", areq_ctx->src.mlli_nents);
@@ -1480,19 +1375,18 @@ int ssi_buffer_mgr_map_aead_request(
1480 return 0; 1375 return 0;
1481 1376
1482aead_map_failure: 1377aead_map_failure:
1483 ssi_buffer_mgr_unmap_aead_request(dev, req); 1378 cc_unmap_aead_request(dev, req);
1484 return rc; 1379 return rc;
1485} 1380}
1486 1381
1487int ssi_buffer_mgr_map_hash_request_final( 1382int cc_map_hash_request_final(struct cc_drvdata *drvdata, void *ctx,
1488 struct ssi_drvdata *drvdata, void *ctx, struct scatterlist *src, unsigned int nbytes, bool do_update) 1383 struct scatterlist *src, unsigned int nbytes,
1384 bool do_update, gfp_t flags)
1489{ 1385{
1490 struct ahash_req_ctx *areq_ctx = (struct ahash_req_ctx *)ctx; 1386 struct ahash_req_ctx *areq_ctx = (struct ahash_req_ctx *)ctx;
1491 struct device *dev = drvdata_to_dev(drvdata); 1387 struct device *dev = drvdata_to_dev(drvdata);
1492 u8 *curr_buff = areq_ctx->buff_index ? areq_ctx->buff1 : 1388 u8 *curr_buff = cc_hash_buf(areq_ctx);
1493 areq_ctx->buff0; 1389 u32 *curr_buff_cnt = cc_hash_buf_cnt(areq_ctx);
1494 u32 *curr_buff_cnt = areq_ctx->buff_index ? &areq_ctx->buff1_cnt :
1495 &areq_ctx->buff0_cnt;
1496 struct mlli_params *mlli_params = &areq_ctx->mlli_params; 1390 struct mlli_params *mlli_params = &areq_ctx->mlli_params;
1497 struct buffer_array sg_data; 1391 struct buffer_array sg_data;
1498 struct buff_mgr_handle *buff_mgr = drvdata->buff_mgr_handle; 1392 struct buff_mgr_handle *buff_mgr = drvdata->buff_mgr_handle;
@@ -1502,88 +1396,78 @@ int ssi_buffer_mgr_map_hash_request_final(
1502 dev_dbg(dev, "final params : curr_buff=%pK curr_buff_cnt=0x%X nbytes = 0x%X src=%pK curr_index=%u\n", 1396 dev_dbg(dev, "final params : curr_buff=%pK curr_buff_cnt=0x%X nbytes = 0x%X src=%pK curr_index=%u\n",
1503 curr_buff, *curr_buff_cnt, nbytes, src, areq_ctx->buff_index); 1397 curr_buff, *curr_buff_cnt, nbytes, src, areq_ctx->buff_index);
1504 /* Init the type of the dma buffer */ 1398 /* Init the type of the dma buffer */
1505 areq_ctx->data_dma_buf_type = SSI_DMA_BUF_NULL; 1399 areq_ctx->data_dma_buf_type = CC_DMA_BUF_NULL;
1506 mlli_params->curr_pool = NULL; 1400 mlli_params->curr_pool = NULL;
1507 sg_data.num_of_buffers = 0; 1401 sg_data.num_of_buffers = 0;
1508 areq_ctx->in_nents = 0; 1402 areq_ctx->in_nents = 0;
1509 1403
1510 if (unlikely(nbytes == 0 && *curr_buff_cnt == 0)) { 1404 if (nbytes == 0 && *curr_buff_cnt == 0) {
1511 /* nothing to do */ 1405 /* nothing to do */
1512 return 0; 1406 return 0;
1513 } 1407 }
1514 1408
1515 /*TODO: copy data in case that buffer is enough for operation */ 1409 /*TODO: copy data in case that buffer is enough for operation */
1516 /* map the previous buffer */ 1410 /* map the previous buffer */
1517 if (*curr_buff_cnt != 0) { 1411 if (*curr_buff_cnt) {
1518 if (ssi_ahash_handle_curr_buf(dev, areq_ctx, curr_buff, 1412 if (cc_set_hash_buf(dev, areq_ctx, curr_buff, *curr_buff_cnt,
1519 *curr_buff_cnt, &sg_data) != 0) { 1413 &sg_data)) {
1520 return -ENOMEM; 1414 return -ENOMEM;
1521 } 1415 }
1522 } 1416 }
1523 1417
1524 if (src && (nbytes > 0) && do_update) { 1418 if (src && nbytes > 0 && do_update) {
1525 if (unlikely(ssi_buffer_mgr_map_scatterlist(dev, src, nbytes, 1419 if (cc_map_sg(dev, src, nbytes, DMA_TO_DEVICE,
1526 DMA_TO_DEVICE, 1420 &areq_ctx->in_nents, LLI_MAX_NUM_OF_DATA_ENTRIES,
1527 &areq_ctx->in_nents, 1421 &dummy, &mapped_nents)) {
1528 LLI_MAX_NUM_OF_DATA_ENTRIES,
1529 &dummy,
1530 &mapped_nents))){
1531 goto unmap_curr_buff; 1422 goto unmap_curr_buff;
1532 } 1423 }
1533 if (src && (mapped_nents == 1) 1424 if (src && mapped_nents == 1 &&
1534 && (areq_ctx->data_dma_buf_type == SSI_DMA_BUF_NULL)) { 1425 areq_ctx->data_dma_buf_type == CC_DMA_BUF_NULL) {
1535 memcpy(areq_ctx->buff_sg, src, 1426 memcpy(areq_ctx->buff_sg, src,
1536 sizeof(struct scatterlist)); 1427 sizeof(struct scatterlist));
1537 areq_ctx->buff_sg->length = nbytes; 1428 areq_ctx->buff_sg->length = nbytes;
1538 areq_ctx->curr_sg = areq_ctx->buff_sg; 1429 areq_ctx->curr_sg = areq_ctx->buff_sg;
1539 areq_ctx->data_dma_buf_type = SSI_DMA_BUF_DLLI; 1430 areq_ctx->data_dma_buf_type = CC_DMA_BUF_DLLI;
1540 } else { 1431 } else {
1541 areq_ctx->data_dma_buf_type = SSI_DMA_BUF_MLLI; 1432 areq_ctx->data_dma_buf_type = CC_DMA_BUF_MLLI;
1542 } 1433 }
1543 } 1434 }
1544 1435
1545 /*build mlli */ 1436 /*build mlli */
1546 if (unlikely(areq_ctx->data_dma_buf_type == SSI_DMA_BUF_MLLI)) { 1437 if (areq_ctx->data_dma_buf_type == CC_DMA_BUF_MLLI) {
1547 mlli_params->curr_pool = buff_mgr->mlli_buffs_pool; 1438 mlli_params->curr_pool = buff_mgr->mlli_buffs_pool;
1548 /* add the src data to the sg_data */ 1439 /* add the src data to the sg_data */
1549 ssi_buffer_mgr_add_scatterlist_entry(dev, &sg_data, 1440 cc_add_sg_entry(dev, &sg_data, areq_ctx->in_nents, src, nbytes,
1550 areq_ctx->in_nents, 1441 0, true, &areq_ctx->mlli_nents);
1551 src, nbytes, 0, true, 1442 if (cc_generate_mlli(dev, &sg_data, mlli_params, flags))
1552 &areq_ctx->mlli_nents);
1553 if (unlikely(ssi_buffer_mgr_generate_mlli(dev, &sg_data,
1554 mlli_params) != 0)) {
1555 goto fail_unmap_din; 1443 goto fail_unmap_din;
1556 }
1557 } 1444 }
1558 /* change the buffer index for the unmap function */ 1445 /* change the buffer index for the unmap function */
1559 areq_ctx->buff_index = (areq_ctx->buff_index ^ 1); 1446 areq_ctx->buff_index = (areq_ctx->buff_index ^ 1);
1560 dev_dbg(dev, "areq_ctx->data_dma_buf_type = %s\n", 1447 dev_dbg(dev, "areq_ctx->data_dma_buf_type = %s\n",
1561 GET_DMA_BUFFER_TYPE(areq_ctx->data_dma_buf_type)); 1448 cc_dma_buf_type(areq_ctx->data_dma_buf_type));
1562 return 0; 1449 return 0;
1563 1450
1564fail_unmap_din: 1451fail_unmap_din:
1565 dma_unmap_sg(dev, src, areq_ctx->in_nents, DMA_TO_DEVICE); 1452 dma_unmap_sg(dev, src, areq_ctx->in_nents, DMA_TO_DEVICE);
1566 1453
1567unmap_curr_buff: 1454unmap_curr_buff:
1568 if (*curr_buff_cnt != 0) 1455 if (*curr_buff_cnt)
1569 dma_unmap_sg(dev, areq_ctx->buff_sg, 1, DMA_TO_DEVICE); 1456 dma_unmap_sg(dev, areq_ctx->buff_sg, 1, DMA_TO_DEVICE);
1570 1457
1571 return -ENOMEM; 1458 return -ENOMEM;
1572} 1459}
1573 1460
1574int ssi_buffer_mgr_map_hash_request_update( 1461int cc_map_hash_request_update(struct cc_drvdata *drvdata, void *ctx,
1575 struct ssi_drvdata *drvdata, void *ctx, struct scatterlist *src, unsigned int nbytes, unsigned int block_size) 1462 struct scatterlist *src, unsigned int nbytes,
1463 unsigned int block_size, gfp_t flags)
1576{ 1464{
1577 struct ahash_req_ctx *areq_ctx = (struct ahash_req_ctx *)ctx; 1465 struct ahash_req_ctx *areq_ctx = (struct ahash_req_ctx *)ctx;
1578 struct device *dev = drvdata_to_dev(drvdata); 1466 struct device *dev = drvdata_to_dev(drvdata);
1579 u8 *curr_buff = areq_ctx->buff_index ? areq_ctx->buff1 : 1467 u8 *curr_buff = cc_hash_buf(areq_ctx);
1580 areq_ctx->buff0; 1468 u32 *curr_buff_cnt = cc_hash_buf_cnt(areq_ctx);
1581 u32 *curr_buff_cnt = areq_ctx->buff_index ? &areq_ctx->buff1_cnt : 1469 u8 *next_buff = cc_next_buf(areq_ctx);
1582 &areq_ctx->buff0_cnt; 1470 u32 *next_buff_cnt = cc_next_buf_cnt(areq_ctx);
1583 u8 *next_buff = areq_ctx->buff_index ? areq_ctx->buff0 :
1584 areq_ctx->buff1;
1585 u32 *next_buff_cnt = areq_ctx->buff_index ? &areq_ctx->buff0_cnt :
1586 &areq_ctx->buff1_cnt;
1587 struct mlli_params *mlli_params = &areq_ctx->mlli_params; 1471 struct mlli_params *mlli_params = &areq_ctx->mlli_params;
1588 unsigned int update_data_len; 1472 unsigned int update_data_len;
1589 u32 total_in_len = nbytes + *curr_buff_cnt; 1473 u32 total_in_len = nbytes + *curr_buff_cnt;
@@ -1596,18 +1480,17 @@ int ssi_buffer_mgr_map_hash_request_update(
1596 dev_dbg(dev, " update params : curr_buff=%pK curr_buff_cnt=0x%X nbytes=0x%X src=%pK curr_index=%u\n", 1480 dev_dbg(dev, " update params : curr_buff=%pK curr_buff_cnt=0x%X nbytes=0x%X src=%pK curr_index=%u\n",
1597 curr_buff, *curr_buff_cnt, nbytes, src, areq_ctx->buff_index); 1481 curr_buff, *curr_buff_cnt, nbytes, src, areq_ctx->buff_index);
1598 /* Init the type of the dma buffer */ 1482 /* Init the type of the dma buffer */
1599 areq_ctx->data_dma_buf_type = SSI_DMA_BUF_NULL; 1483 areq_ctx->data_dma_buf_type = CC_DMA_BUF_NULL;
1600 mlli_params->curr_pool = NULL; 1484 mlli_params->curr_pool = NULL;
1601 areq_ctx->curr_sg = NULL; 1485 areq_ctx->curr_sg = NULL;
1602 sg_data.num_of_buffers = 0; 1486 sg_data.num_of_buffers = 0;
1603 areq_ctx->in_nents = 0; 1487 areq_ctx->in_nents = 0;
1604 1488
1605 if (unlikely(total_in_len < block_size)) { 1489 if (total_in_len < block_size) {
1606 dev_dbg(dev, " less than one block: curr_buff=%pK *curr_buff_cnt=0x%X copy_to=%pK\n", 1490 dev_dbg(dev, " less than one block: curr_buff=%pK *curr_buff_cnt=0x%X copy_to=%pK\n",
1607 curr_buff, *curr_buff_cnt, &curr_buff[*curr_buff_cnt]); 1491 curr_buff, *curr_buff_cnt, &curr_buff[*curr_buff_cnt]);
1608 areq_ctx->in_nents = 1492 areq_ctx->in_nents =
1609 ssi_buffer_mgr_get_sgl_nents(dev, src, nbytes, &dummy, 1493 cc_get_sgl_nents(dev, src, nbytes, &dummy, NULL);
1610 NULL);
1611 sg_copy_to_buffer(src, areq_ctx->in_nents, 1494 sg_copy_to_buffer(src, areq_ctx->in_nents,
1612 &curr_buff[*curr_buff_cnt], nbytes); 1495 &curr_buff[*curr_buff_cnt], nbytes);
1613 *curr_buff_cnt += nbytes; 1496 *curr_buff_cnt += nbytes;
@@ -1623,20 +1506,20 @@ int ssi_buffer_mgr_map_hash_request_update(
1623 *next_buff_cnt, update_data_len); 1506 *next_buff_cnt, update_data_len);
1624 1507
1625 /* Copy the new residue to next buffer */ 1508 /* Copy the new residue to next buffer */
1626 if (*next_buff_cnt != 0) { 1509 if (*next_buff_cnt) {
1627 dev_dbg(dev, " handle residue: next buff %pK skip data %u residue %u\n", 1510 dev_dbg(dev, " handle residue: next buff %pK skip data %u residue %u\n",
1628 next_buff, (update_data_len - *curr_buff_cnt), 1511 next_buff, (update_data_len - *curr_buff_cnt),
1629 *next_buff_cnt); 1512 *next_buff_cnt);
1630 ssi_buffer_mgr_copy_scatterlist_portion(dev, next_buff, src, 1513 cc_copy_sg_portion(dev, next_buff, src,
1631 (update_data_len - *curr_buff_cnt), 1514 (update_data_len - *curr_buff_cnt),
1632 nbytes, SSI_SG_TO_BUF); 1515 nbytes, CC_SG_TO_BUF);
1633 /* change the buffer index for next operation */ 1516 /* change the buffer index for next operation */
1634 swap_index = 1; 1517 swap_index = 1;
1635 } 1518 }
1636 1519
1637 if (*curr_buff_cnt != 0) { 1520 if (*curr_buff_cnt) {
1638 if (ssi_ahash_handle_curr_buf(dev, areq_ctx, curr_buff, 1521 if (cc_set_hash_buf(dev, areq_ctx, curr_buff, *curr_buff_cnt,
1639 *curr_buff_cnt, &sg_data) != 0) { 1522 &sg_data)) {
1640 return -ENOMEM; 1523 return -ENOMEM;
1641 } 1524 }
1642 /* change the buffer index for next operation */ 1525 /* change the buffer index for next operation */
@@ -1644,42 +1527,33 @@ int ssi_buffer_mgr_map_hash_request_update(
1644 } 1527 }
1645 1528
1646 if (update_data_len > *curr_buff_cnt) { 1529 if (update_data_len > *curr_buff_cnt) {
1647 if (unlikely(ssi_buffer_mgr_map_scatterlist(dev, src, 1530 if (cc_map_sg(dev, src, (update_data_len - *curr_buff_cnt),
1648 (update_data_len - *curr_buff_cnt), 1531 DMA_TO_DEVICE, &areq_ctx->in_nents,
1649 DMA_TO_DEVICE, 1532 LLI_MAX_NUM_OF_DATA_ENTRIES, &dummy,
1650 &areq_ctx->in_nents, 1533 &mapped_nents)) {
1651 LLI_MAX_NUM_OF_DATA_ENTRIES,
1652 &dummy,
1653 &mapped_nents))){
1654 goto unmap_curr_buff; 1534 goto unmap_curr_buff;
1655 } 1535 }
1656 if ((mapped_nents == 1) 1536 if (mapped_nents == 1 &&
1657 && (areq_ctx->data_dma_buf_type == SSI_DMA_BUF_NULL)) { 1537 areq_ctx->data_dma_buf_type == CC_DMA_BUF_NULL) {
1658 /* only one entry in the SG and no previous data */ 1538 /* only one entry in the SG and no previous data */
1659 memcpy(areq_ctx->buff_sg, src, 1539 memcpy(areq_ctx->buff_sg, src,
1660 sizeof(struct scatterlist)); 1540 sizeof(struct scatterlist));
1661 areq_ctx->buff_sg->length = update_data_len; 1541 areq_ctx->buff_sg->length = update_data_len;
1662 areq_ctx->data_dma_buf_type = SSI_DMA_BUF_DLLI; 1542 areq_ctx->data_dma_buf_type = CC_DMA_BUF_DLLI;
1663 areq_ctx->curr_sg = areq_ctx->buff_sg; 1543 areq_ctx->curr_sg = areq_ctx->buff_sg;
1664 } else { 1544 } else {
1665 areq_ctx->data_dma_buf_type = SSI_DMA_BUF_MLLI; 1545 areq_ctx->data_dma_buf_type = CC_DMA_BUF_MLLI;
1666 } 1546 }
1667 } 1547 }
1668 1548
1669 if (unlikely(areq_ctx->data_dma_buf_type == SSI_DMA_BUF_MLLI)) { 1549 if (areq_ctx->data_dma_buf_type == CC_DMA_BUF_MLLI) {
1670 mlli_params->curr_pool = buff_mgr->mlli_buffs_pool; 1550 mlli_params->curr_pool = buff_mgr->mlli_buffs_pool;
1671 /* add the src data to the sg_data */ 1551 /* add the src data to the sg_data */
1672 ssi_buffer_mgr_add_scatterlist_entry(dev, &sg_data, 1552 cc_add_sg_entry(dev, &sg_data, areq_ctx->in_nents, src,
1673 areq_ctx->in_nents, 1553 (update_data_len - *curr_buff_cnt), 0, true,
1674 src, 1554 &areq_ctx->mlli_nents);
1675 (update_data_len - *curr_buff_cnt), 1555 if (cc_generate_mlli(dev, &sg_data, mlli_params, flags))
1676 0,
1677 true,
1678 &areq_ctx->mlli_nents);
1679 if (unlikely(ssi_buffer_mgr_generate_mlli(dev, &sg_data,
1680 mlli_params) != 0)) {
1681 goto fail_unmap_din; 1556 goto fail_unmap_din;
1682 }
1683 } 1557 }
1684 areq_ctx->buff_index = (areq_ctx->buff_index ^ swap_index); 1558 areq_ctx->buff_index = (areq_ctx->buff_index ^ swap_index);
1685 1559
@@ -1689,18 +1563,17 @@ fail_unmap_din:
1689 dma_unmap_sg(dev, src, areq_ctx->in_nents, DMA_TO_DEVICE); 1563 dma_unmap_sg(dev, src, areq_ctx->in_nents, DMA_TO_DEVICE);
1690 1564
1691unmap_curr_buff: 1565unmap_curr_buff:
1692 if (*curr_buff_cnt != 0) 1566 if (*curr_buff_cnt)
1693 dma_unmap_sg(dev, areq_ctx->buff_sg, 1, DMA_TO_DEVICE); 1567 dma_unmap_sg(dev, areq_ctx->buff_sg, 1, DMA_TO_DEVICE);
1694 1568
1695 return -ENOMEM; 1569 return -ENOMEM;
1696} 1570}
1697 1571
1698void ssi_buffer_mgr_unmap_hash_request( 1572void cc_unmap_hash_request(struct device *dev, void *ctx,
1699 struct device *dev, void *ctx, struct scatterlist *src, bool do_revert) 1573 struct scatterlist *src, bool do_revert)
1700{ 1574{
1701 struct ahash_req_ctx *areq_ctx = (struct ahash_req_ctx *)ctx; 1575 struct ahash_req_ctx *areq_ctx = (struct ahash_req_ctx *)ctx;
1702 u32 *prev_len = areq_ctx->buff_index ? &areq_ctx->buff0_cnt : 1576 u32 *prev_len = cc_next_buf_cnt(areq_ctx);
1703 &areq_ctx->buff1_cnt;
1704 1577
1705 /*In case a pool was set, a table was 1578 /*In case a pool was set, a table was
1706 *allocated and should be released 1579 *allocated and should be released
@@ -1714,21 +1587,23 @@ void ssi_buffer_mgr_unmap_hash_request(
1714 areq_ctx->mlli_params.mlli_dma_addr); 1587 areq_ctx->mlli_params.mlli_dma_addr);
1715 } 1588 }
1716 1589
1717 if ((src) && likely(areq_ctx->in_nents != 0)) { 1590 if (src && areq_ctx->in_nents) {
1718 dev_dbg(dev, "Unmapped sg src: virt=%pK dma=%pad len=0x%X\n", 1591 dev_dbg(dev, "Unmapped sg src: virt=%pK dma=%pad len=0x%X\n",
1719 sg_virt(src), &sg_dma_address(src), sg_dma_len(src)); 1592 sg_virt(src), &sg_dma_address(src), sg_dma_len(src));
1720 dma_unmap_sg(dev, src, 1593 dma_unmap_sg(dev, src,
1721 areq_ctx->in_nents, DMA_TO_DEVICE); 1594 areq_ctx->in_nents, DMA_TO_DEVICE);
1722 } 1595 }
1723 1596
1724 if (*prev_len != 0) { 1597 if (*prev_len) {
1725 dev_dbg(dev, "Unmapped buffer: areq_ctx->buff_sg=%pK dma=%pad len 0x%X\n", 1598 dev_dbg(dev, "Unmapped buffer: areq_ctx->buff_sg=%pK dma=%pad len 0x%X\n",
1726 sg_virt(areq_ctx->buff_sg), 1599 sg_virt(areq_ctx->buff_sg),
1727 &sg_dma_address(areq_ctx->buff_sg), 1600 &sg_dma_address(areq_ctx->buff_sg),
1728 sg_dma_len(areq_ctx->buff_sg)); 1601 sg_dma_len(areq_ctx->buff_sg));
1729 dma_unmap_sg(dev, areq_ctx->buff_sg, 1, DMA_TO_DEVICE); 1602 dma_unmap_sg(dev, areq_ctx->buff_sg, 1, DMA_TO_DEVICE);
1730 if (!do_revert) { 1603 if (!do_revert) {
1731 /* clean the previous data length for update operation */ 1604 /* clean the previous data length for update
1605 * operation
1606 */
1732 *prev_len = 0; 1607 *prev_len = 0;
1733 } else { 1608 } else {
1734 areq_ctx->buff_index ^= 1; 1609 areq_ctx->buff_index ^= 1;
@@ -1736,7 +1611,7 @@ void ssi_buffer_mgr_unmap_hash_request(
1736 } 1611 }
1737} 1612}
1738 1613
1739int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata) 1614int cc_buffer_mgr_init(struct cc_drvdata *drvdata)
1740{ 1615{
1741 struct buff_mgr_handle *buff_mgr_handle; 1616 struct buff_mgr_handle *buff_mgr_handle;
1742 struct device *dev = drvdata_to_dev(drvdata); 1617 struct device *dev = drvdata_to_dev(drvdata);
@@ -1747,23 +1622,23 @@ int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata)
1747 1622
1748 drvdata->buff_mgr_handle = buff_mgr_handle; 1623 drvdata->buff_mgr_handle = buff_mgr_handle;
1749 1624
1750 buff_mgr_handle->mlli_buffs_pool = dma_pool_create( 1625 buff_mgr_handle->mlli_buffs_pool =
1751 "dx_single_mlli_tables", dev, 1626 dma_pool_create("dx_single_mlli_tables", dev,
1752 MAX_NUM_OF_TOTAL_MLLI_ENTRIES * 1627 MAX_NUM_OF_TOTAL_MLLI_ENTRIES *
1753 LLI_ENTRY_BYTE_SIZE, 1628 LLI_ENTRY_BYTE_SIZE,
1754 MLLI_TABLE_MIN_ALIGNMENT, 0); 1629 MLLI_TABLE_MIN_ALIGNMENT, 0);
1755 1630
1756 if (unlikely(!buff_mgr_handle->mlli_buffs_pool)) 1631 if (!buff_mgr_handle->mlli_buffs_pool)
1757 goto error; 1632 goto error;
1758 1633
1759 return 0; 1634 return 0;
1760 1635
1761error: 1636error:
1762 ssi_buffer_mgr_fini(drvdata); 1637 cc_buffer_mgr_fini(drvdata);
1763 return -ENOMEM; 1638 return -ENOMEM;
1764} 1639}
1765 1640
1766int ssi_buffer_mgr_fini(struct ssi_drvdata *drvdata) 1641int cc_buffer_mgr_fini(struct cc_drvdata *drvdata)
1767{ 1642{
1768 struct buff_mgr_handle *buff_mgr_handle = drvdata->buff_mgr_handle; 1643 struct buff_mgr_handle *buff_mgr_handle = drvdata->buff_mgr_handle;
1769 1644
diff --git a/drivers/staging/ccree/cc_buffer_mgr.h b/drivers/staging/ccree/cc_buffer_mgr.h
new file mode 100644
index 000000000000..99b752aa1077
--- /dev/null
+++ b/drivers/staging/ccree/cc_buffer_mgr.h
@@ -0,0 +1,74 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4/* \file cc_buffer_mgr.h
5 * Buffer Manager
6 */
7
8#ifndef __CC_BUFFER_MGR_H__
9#define __CC_BUFFER_MGR_H__
10
11#include <crypto/algapi.h>
12
13#include "cc_driver.h"
14
15enum cc_req_dma_buf_type {
16 CC_DMA_BUF_NULL = 0,
17 CC_DMA_BUF_DLLI,
18 CC_DMA_BUF_MLLI
19};
20
21enum cc_sg_cpy_direct {
22 CC_SG_TO_BUF = 0,
23 CC_SG_FROM_BUF = 1
24};
25
26struct cc_mlli {
27 cc_sram_addr_t sram_addr;
28 unsigned int nents; //sg nents
29 unsigned int mlli_nents; //mlli nents might be different than the above
30};
31
32struct mlli_params {
33 struct dma_pool *curr_pool;
34 u8 *mlli_virt_addr;
35 dma_addr_t mlli_dma_addr;
36 u32 mlli_len;
37};
38
39int cc_buffer_mgr_init(struct cc_drvdata *drvdata);
40
41int cc_buffer_mgr_fini(struct cc_drvdata *drvdata);
42
43int cc_map_blkcipher_request(struct cc_drvdata *drvdata, void *ctx,
44 unsigned int ivsize, unsigned int nbytes,
45 void *info, struct scatterlist *src,
46 struct scatterlist *dst, gfp_t flags);
47
48void cc_unmap_blkcipher_request(struct device *dev, void *ctx,
49 unsigned int ivsize,
50 struct scatterlist *src,
51 struct scatterlist *dst);
52
53int cc_map_aead_request(struct cc_drvdata *drvdata, struct aead_request *req);
54
55void cc_unmap_aead_request(struct device *dev, struct aead_request *req);
56
57int cc_map_hash_request_final(struct cc_drvdata *drvdata, void *ctx,
58 struct scatterlist *src, unsigned int nbytes,
59 bool do_update, gfp_t flags);
60
61int cc_map_hash_request_update(struct cc_drvdata *drvdata, void *ctx,
62 struct scatterlist *src, unsigned int nbytes,
63 unsigned int block_size, gfp_t flags);
64
65void cc_unmap_hash_request(struct device *dev, void *ctx,
66 struct scatterlist *src, bool do_revert);
67
68void cc_copy_sg_portion(struct device *dev, u8 *dest, struct scatterlist *sg,
69 u32 to_skip, u32 end, enum cc_sg_cpy_direct direct);
70
71void cc_zero_sgl(struct scatterlist *sgl, u32 data_len);
72
73#endif /*__BUFFER_MGR_H__*/
74
diff --git a/drivers/staging/ccree/ssi_cipher.c b/drivers/staging/ccree/cc_cipher.c
index ee85cbf7c9ae..d4ac0ff2ffcf 100644
--- a/drivers/staging/ccree/ssi_cipher.c
+++ b/drivers/staging/ccree/cc_cipher.c
@@ -1,46 +1,27 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17#include <linux/kernel.h> 4#include <linux/kernel.h>
18#include <linux/module.h> 5#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <linux/semaphore.h>
21#include <crypto/algapi.h> 6#include <crypto/algapi.h>
22#include <crypto/internal/skcipher.h> 7#include <crypto/internal/skcipher.h>
23#include <crypto/aes.h>
24#include <crypto/ctr.h>
25#include <crypto/des.h> 8#include <crypto/des.h>
26#include <crypto/xts.h> 9#include <crypto/xts.h>
27#include <crypto/scatterwalk.h> 10#include <crypto/scatterwalk.h>
28 11
29#include "ssi_config.h" 12#include "cc_driver.h"
30#include "ssi_driver.h"
31#include "cc_lli_defs.h" 13#include "cc_lli_defs.h"
32#include "ssi_buffer_mgr.h" 14#include "cc_buffer_mgr.h"
33#include "ssi_cipher.h" 15#include "cc_cipher.h"
34#include "ssi_request_mgr.h" 16#include "cc_request_mgr.h"
35#include "ssi_sysfs.h"
36 17
37#define MAX_ABLKCIPHER_SEQ_LEN 6 18#define MAX_ABLKCIPHER_SEQ_LEN 6
38 19
39#define template_ablkcipher template_u.ablkcipher 20#define template_ablkcipher template_u.ablkcipher
40 21
41#define SSI_MIN_AES_XTS_SIZE 0x10 22#define CC_MIN_AES_XTS_SIZE 0x10
42#define SSI_MAX_AES_XTS_SIZE 0x2000 23#define CC_MAX_AES_XTS_SIZE 0x2000
43struct ssi_blkcipher_handle { 24struct cc_cipher_handle {
44 struct list_head blkcipher_alg_list; 25 struct list_head blkcipher_alg_list;
45}; 26};
46 27
@@ -54,8 +35,8 @@ struct cc_hw_key_info {
54 enum cc_hw_crypto_key key2_slot; 35 enum cc_hw_crypto_key key2_slot;
55}; 36};
56 37
57struct ssi_ablkcipher_ctx { 38struct cc_cipher_ctx {
58 struct ssi_drvdata *drvdata; 39 struct cc_drvdata *drvdata;
59 int keylen; 40 int keylen;
60 int key_round_number; 41 int key_round_number;
61 int cipher_mode; 42 int cipher_mode;
@@ -67,61 +48,56 @@ struct ssi_ablkcipher_ctx {
67 struct crypto_shash *shash_tfm; 48 struct crypto_shash *shash_tfm;
68}; 49};
69 50
70static void ssi_ablkcipher_complete(struct device *dev, void *ssi_req, void __iomem *cc_base); 51static void cc_cipher_complete(struct device *dev, void *cc_req, int err);
71 52
72static int validate_keys_sizes(struct ssi_ablkcipher_ctx *ctx_p, u32 size) 53static int validate_keys_sizes(struct cc_cipher_ctx *ctx_p, u32 size)
73{ 54{
74 switch (ctx_p->flow_mode) { 55 switch (ctx_p->flow_mode) {
75 case S_DIN_to_AES: 56 case S_DIN_to_AES:
76 switch (size) { 57 switch (size) {
77 case CC_AES_128_BIT_KEY_SIZE: 58 case CC_AES_128_BIT_KEY_SIZE:
78 case CC_AES_192_BIT_KEY_SIZE: 59 case CC_AES_192_BIT_KEY_SIZE:
79 if (likely((ctx_p->cipher_mode != DRV_CIPHER_XTS) && 60 if (ctx_p->cipher_mode != DRV_CIPHER_XTS &&
80 (ctx_p->cipher_mode != DRV_CIPHER_ESSIV) && 61 ctx_p->cipher_mode != DRV_CIPHER_ESSIV &&
81 (ctx_p->cipher_mode != DRV_CIPHER_BITLOCKER))) 62 ctx_p->cipher_mode != DRV_CIPHER_BITLOCKER)
82 return 0; 63 return 0;
83 break; 64 break;
84 case CC_AES_256_BIT_KEY_SIZE: 65 case CC_AES_256_BIT_KEY_SIZE:
85 return 0; 66 return 0;
86 case (CC_AES_192_BIT_KEY_SIZE * 2): 67 case (CC_AES_192_BIT_KEY_SIZE * 2):
87 case (CC_AES_256_BIT_KEY_SIZE * 2): 68 case (CC_AES_256_BIT_KEY_SIZE * 2):
88 if (likely((ctx_p->cipher_mode == DRV_CIPHER_XTS) || 69 if (ctx_p->cipher_mode == DRV_CIPHER_XTS ||
89 (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) || 70 ctx_p->cipher_mode == DRV_CIPHER_ESSIV ||
90 (ctx_p->cipher_mode == DRV_CIPHER_BITLOCKER))) 71 ctx_p->cipher_mode == DRV_CIPHER_BITLOCKER)
91 return 0; 72 return 0;
92 break; 73 break;
93 default: 74 default:
94 break; 75 break;
95 } 76 }
96 case S_DIN_to_DES: 77 case S_DIN_to_DES:
97 if (likely(size == DES3_EDE_KEY_SIZE || size == DES_KEY_SIZE)) 78 if (size == DES3_EDE_KEY_SIZE || size == DES_KEY_SIZE)
98 return 0; 79 return 0;
99 break; 80 break;
100#if SSI_CC_HAS_MULTI2
101 case S_DIN_to_MULTI2:
102 if (likely(size == CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE))
103 return 0;
104 break;
105#endif
106 default: 81 default:
107 break; 82 break;
108 } 83 }
109 return -EINVAL; 84 return -EINVAL;
110} 85}
111 86
112static int validate_data_size(struct ssi_ablkcipher_ctx *ctx_p, unsigned int size) 87static int validate_data_size(struct cc_cipher_ctx *ctx_p,
88 unsigned int size)
113{ 89{
114 switch (ctx_p->flow_mode) { 90 switch (ctx_p->flow_mode) {
115 case S_DIN_to_AES: 91 case S_DIN_to_AES:
116 switch (ctx_p->cipher_mode) { 92 switch (ctx_p->cipher_mode) {
117 case DRV_CIPHER_XTS: 93 case DRV_CIPHER_XTS:
118 if ((size >= SSI_MIN_AES_XTS_SIZE) && 94 if (size >= CC_MIN_AES_XTS_SIZE &&
119 (size <= SSI_MAX_AES_XTS_SIZE) && 95 size <= CC_MAX_AES_XTS_SIZE &&
120 IS_ALIGNED(size, AES_BLOCK_SIZE)) 96 IS_ALIGNED(size, AES_BLOCK_SIZE))
121 return 0; 97 return 0;
122 break; 98 break;
123 case DRV_CIPHER_CBC_CTS: 99 case DRV_CIPHER_CBC_CTS:
124 if (likely(size >= AES_BLOCK_SIZE)) 100 if (size >= AES_BLOCK_SIZE)
125 return 0; 101 return 0;
126 break; 102 break;
127 case DRV_CIPHER_OFB: 103 case DRV_CIPHER_OFB:
@@ -131,7 +107,7 @@ static int validate_data_size(struct ssi_ablkcipher_ctx *ctx_p, unsigned int siz
131 case DRV_CIPHER_CBC: 107 case DRV_CIPHER_CBC:
132 case DRV_CIPHER_ESSIV: 108 case DRV_CIPHER_ESSIV:
133 case DRV_CIPHER_BITLOCKER: 109 case DRV_CIPHER_BITLOCKER:
134 if (likely(IS_ALIGNED(size, AES_BLOCK_SIZE))) 110 if (IS_ALIGNED(size, AES_BLOCK_SIZE))
135 return 0; 111 return 0;
136 break; 112 break;
137 default: 113 default:
@@ -139,23 +115,9 @@ static int validate_data_size(struct ssi_ablkcipher_ctx *ctx_p, unsigned int siz
139 } 115 }
140 break; 116 break;
141 case S_DIN_to_DES: 117 case S_DIN_to_DES:
142 if (likely(IS_ALIGNED(size, DES_BLOCK_SIZE))) 118 if (IS_ALIGNED(size, DES_BLOCK_SIZE))
143 return 0;
144 break;
145#if SSI_CC_HAS_MULTI2
146 case S_DIN_to_MULTI2:
147 switch (ctx_p->cipher_mode) {
148 case DRV_MULTI2_CBC:
149 if (likely(IS_ALIGNED(size, CC_MULTI2_BLOCK_SIZE)))
150 return 0;
151 break;
152 case DRV_MULTI2_OFB:
153 return 0; 119 return 0;
154 default:
155 break;
156 }
157 break; 120 break;
158#endif /*SSI_CC_HAS_MULTI2*/
159 default: 121 default:
160 break; 122 break;
161 } 123 }
@@ -164,36 +126,42 @@ static int validate_data_size(struct ssi_ablkcipher_ctx *ctx_p, unsigned int siz
164 126
165static unsigned int get_max_keysize(struct crypto_tfm *tfm) 127static unsigned int get_max_keysize(struct crypto_tfm *tfm)
166{ 128{
167 struct ssi_crypto_alg *ssi_alg = container_of(tfm->__crt_alg, struct ssi_crypto_alg, crypto_alg); 129 struct cc_crypto_alg *cc_alg =
130 container_of(tfm->__crt_alg, struct cc_crypto_alg, crypto_alg);
168 131
169 if ((ssi_alg->crypto_alg.cra_flags & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_ABLKCIPHER) 132 if ((cc_alg->crypto_alg.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
170 return ssi_alg->crypto_alg.cra_ablkcipher.max_keysize; 133 CRYPTO_ALG_TYPE_ABLKCIPHER)
134 return cc_alg->crypto_alg.cra_ablkcipher.max_keysize;
171 135
172 if ((ssi_alg->crypto_alg.cra_flags & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_BLKCIPHER) 136 if ((cc_alg->crypto_alg.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
173 return ssi_alg->crypto_alg.cra_blkcipher.max_keysize; 137 CRYPTO_ALG_TYPE_BLKCIPHER)
138 return cc_alg->crypto_alg.cra_blkcipher.max_keysize;
174 139
175 return 0; 140 return 0;
176} 141}
177 142
178static int ssi_blkcipher_init(struct crypto_tfm *tfm) 143static int cc_cipher_init(struct crypto_tfm *tfm)
179{ 144{
180 struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm); 145 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
181 struct crypto_alg *alg = tfm->__crt_alg; 146 struct crypto_alg *alg = tfm->__crt_alg;
182 struct ssi_crypto_alg *ssi_alg = 147 struct cc_crypto_alg *cc_alg =
183 container_of(alg, struct ssi_crypto_alg, crypto_alg); 148 container_of(alg, struct cc_crypto_alg, crypto_alg);
184 struct device *dev = drvdata_to_dev(ssi_alg->drvdata); 149 struct device *dev = drvdata_to_dev(cc_alg->drvdata);
185 int rc = 0; 150 int rc = 0;
186 unsigned int max_key_buf_size = get_max_keysize(tfm); 151 unsigned int max_key_buf_size = get_max_keysize(tfm);
152 struct ablkcipher_tfm *ablktfm = &tfm->crt_ablkcipher;
187 153
188 dev_dbg(dev, "Initializing context @%p for %s\n", ctx_p, 154 dev_dbg(dev, "Initializing context @%p for %s\n", ctx_p,
189 crypto_tfm_alg_name(tfm)); 155 crypto_tfm_alg_name(tfm));
190 156
191 ctx_p->cipher_mode = ssi_alg->cipher_mode; 157 ablktfm->reqsize = sizeof(struct blkcipher_req_ctx);
192 ctx_p->flow_mode = ssi_alg->flow_mode; 158
193 ctx_p->drvdata = ssi_alg->drvdata; 159 ctx_p->cipher_mode = cc_alg->cipher_mode;
160 ctx_p->flow_mode = cc_alg->flow_mode;
161 ctx_p->drvdata = cc_alg->drvdata;
194 162
195 /* Allocate key buffer, cache line aligned */ 163 /* Allocate key buffer, cache line aligned */
196 ctx_p->user.key = kmalloc(max_key_buf_size, GFP_KERNEL | GFP_DMA); 164 ctx_p->user.key = kmalloc(max_key_buf_size, GFP_KERNEL);
197 if (!ctx_p->user.key) 165 if (!ctx_p->user.key)
198 return -ENOMEM; 166 return -ENOMEM;
199 167
@@ -224,9 +192,9 @@ static int ssi_blkcipher_init(struct crypto_tfm *tfm)
224 return rc; 192 return rc;
225} 193}
226 194
227static void ssi_blkcipher_exit(struct crypto_tfm *tfm) 195static void cc_cipher_exit(struct crypto_tfm *tfm)
228{ 196{
229 struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm); 197 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
230 struct device *dev = drvdata_to_dev(ctx_p->drvdata); 198 struct device *dev = drvdata_to_dev(ctx_p->drvdata);
231 unsigned int max_key_buf_size = get_max_keysize(tfm); 199 unsigned int max_key_buf_size = get_max_keysize(tfm);
232 200
@@ -262,13 +230,15 @@ static const u8 zero_buff[] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
262 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; 230 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
263 231
264/* The function verifies that tdes keys are not weak.*/ 232/* The function verifies that tdes keys are not weak.*/
265static int ssi_verify_3des_keys(const u8 *key, unsigned int keylen) 233static int cc_verify_3des_keys(const u8 *key, unsigned int keylen)
266{ 234{
267 struct tdes_keys *tdes_key = (struct tdes_keys *)key; 235 struct tdes_keys *tdes_key = (struct tdes_keys *)key;
268 236
269 /* verify key1 != key2 and key3 != key2*/ 237 /* verify key1 != key2 and key3 != key2*/
270 if (unlikely((memcmp((u8 *)tdes_key->key1, (u8 *)tdes_key->key2, sizeof(tdes_key->key1)) == 0) || 238 if ((memcmp((u8 *)tdes_key->key1, (u8 *)tdes_key->key2,
271 (memcmp((u8 *)tdes_key->key3, (u8 *)tdes_key->key2, sizeof(tdes_key->key3)) == 0))) { 239 sizeof(tdes_key->key1)) == 0) ||
240 (memcmp((u8 *)tdes_key->key3, (u8 *)tdes_key->key2,
241 sizeof(tdes_key->key3)) == 0)) {
272 return -ENOEXEC; 242 return -ENOEXEC;
273 } 243 }
274 244
@@ -290,11 +260,11 @@ static enum cc_hw_crypto_key hw_key_to_cc_hw_key(int slot_num)
290 return END_OF_KEYS; 260 return END_OF_KEYS;
291} 261}
292 262
293static int ssi_blkcipher_setkey(struct crypto_tfm *tfm, 263static int cc_cipher_setkey(struct crypto_ablkcipher *atfm, const u8 *key,
294 const u8 *key, 264 unsigned int keylen)
295 unsigned int keylen)
296{ 265{
297 struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm); 266 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(atfm);
267 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
298 struct device *dev = drvdata_to_dev(ctx_p->drvdata); 268 struct device *dev = drvdata_to_dev(ctx_p->drvdata);
299 u32 tmp[DES_EXPKEY_WORDS]; 269 u32 tmp[DES_EXPKEY_WORDS];
300 unsigned int max_key_buf_size = get_max_keysize(tfm); 270 unsigned int max_key_buf_size = get_max_keysize(tfm);
@@ -305,44 +275,39 @@ static int ssi_blkcipher_setkey(struct crypto_tfm *tfm,
305 275
306 /* STAT_PHASE_0: Init and sanity checks */ 276 /* STAT_PHASE_0: Init and sanity checks */
307 277
308#if SSI_CC_HAS_MULTI2 278 if (validate_keys_sizes(ctx_p, keylen)) {
309 /*last byte of key buffer is round number and should not be a part of key size*/
310 if (ctx_p->flow_mode == S_DIN_to_MULTI2)
311 keylen -= 1;
312#endif /*SSI_CC_HAS_MULTI2*/
313
314 if (unlikely(validate_keys_sizes(ctx_p, keylen) != 0)) {
315 dev_err(dev, "Unsupported key size %d.\n", keylen); 279 dev_err(dev, "Unsupported key size %d.\n", keylen);
316 crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); 280 crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
317 return -EINVAL; 281 return -EINVAL;
318 } 282 }
319 283
320 if (ssi_is_hw_key(tfm)) { 284 if (cc_is_hw_key(tfm)) {
321 /* setting HW key slots */ 285 /* setting HW key slots */
322 struct arm_hw_key_info *hki = (struct arm_hw_key_info *)key; 286 struct arm_hw_key_info *hki = (struct arm_hw_key_info *)key;
323 287
324 if (unlikely(ctx_p->flow_mode != S_DIN_to_AES)) { 288 if (ctx_p->flow_mode != S_DIN_to_AES) {
325 dev_err(dev, "HW key not supported for non-AES flows\n"); 289 dev_err(dev, "HW key not supported for non-AES flows\n");
326 return -EINVAL; 290 return -EINVAL;
327 } 291 }
328 292
329 ctx_p->hw.key1_slot = hw_key_to_cc_hw_key(hki->hw_key1); 293 ctx_p->hw.key1_slot = hw_key_to_cc_hw_key(hki->hw_key1);
330 if (unlikely(ctx_p->hw.key1_slot == END_OF_KEYS)) { 294 if (ctx_p->hw.key1_slot == END_OF_KEYS) {
331 dev_err(dev, "Unsupported hw key1 number (%d)\n", 295 dev_err(dev, "Unsupported hw key1 number (%d)\n",
332 hki->hw_key1); 296 hki->hw_key1);
333 return -EINVAL; 297 return -EINVAL;
334 } 298 }
335 299
336 if ((ctx_p->cipher_mode == DRV_CIPHER_XTS) || 300 if (ctx_p->cipher_mode == DRV_CIPHER_XTS ||
337 (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) || 301 ctx_p->cipher_mode == DRV_CIPHER_ESSIV ||
338 (ctx_p->cipher_mode == DRV_CIPHER_BITLOCKER)) { 302 ctx_p->cipher_mode == DRV_CIPHER_BITLOCKER) {
339 if (unlikely(hki->hw_key1 == hki->hw_key2)) { 303 if (hki->hw_key1 == hki->hw_key2) {
340 dev_err(dev, "Illegal hw key numbers (%d,%d)\n", 304 dev_err(dev, "Illegal hw key numbers (%d,%d)\n",
341 hki->hw_key1, hki->hw_key2); 305 hki->hw_key1, hki->hw_key2);
342 return -EINVAL; 306 return -EINVAL;
343 } 307 }
344 ctx_p->hw.key2_slot = hw_key_to_cc_hw_key(hki->hw_key2); 308 ctx_p->hw.key2_slot =
345 if (unlikely(ctx_p->hw.key2_slot == END_OF_KEYS)) { 309 hw_key_to_cc_hw_key(hki->hw_key2);
310 if (ctx_p->hw.key2_slot == END_OF_KEYS) {
346 dev_err(dev, "Unsupported hw key2 number (%d)\n", 311 dev_err(dev, "Unsupported hw key2 number (%d)\n",
347 hki->hw_key2); 312 hki->hw_key2);
348 return -EINVAL; 313 return -EINVAL;
@@ -350,28 +315,28 @@ static int ssi_blkcipher_setkey(struct crypto_tfm *tfm,
350 } 315 }
351 316
352 ctx_p->keylen = keylen; 317 ctx_p->keylen = keylen;
353 dev_dbg(dev, "ssi_is_hw_key ret 0"); 318 dev_dbg(dev, "cc_is_hw_key ret 0");
354 319
355 return 0; 320 return 0;
356 } 321 }
357 322
358 // verify weak keys 323 // verify weak keys
359 if (ctx_p->flow_mode == S_DIN_to_DES) { 324 if (ctx_p->flow_mode == S_DIN_to_DES) {
360 if (unlikely(!des_ekey(tmp, key)) && 325 if (!des_ekey(tmp, key) &&
361 (crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_WEAK_KEY)) { 326 (crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_WEAK_KEY)) {
362 tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; 327 tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
363 dev_dbg(dev, "weak DES key"); 328 dev_dbg(dev, "weak DES key");
364 return -EINVAL; 329 return -EINVAL;
365 } 330 }
366 } 331 }
367 if ((ctx_p->cipher_mode == DRV_CIPHER_XTS) && 332 if (ctx_p->cipher_mode == DRV_CIPHER_XTS &&
368 xts_check_key(tfm, key, keylen) != 0) { 333 xts_check_key(tfm, key, keylen)) {
369 dev_dbg(dev, "weak XTS key"); 334 dev_dbg(dev, "weak XTS key");
370 return -EINVAL; 335 return -EINVAL;
371 } 336 }
372 if ((ctx_p->flow_mode == S_DIN_to_DES) && 337 if (ctx_p->flow_mode == S_DIN_to_DES &&
373 (keylen == DES3_EDE_KEY_SIZE) && 338 keylen == DES3_EDE_KEY_SIZE &&
374 ssi_verify_3des_keys(key, keylen) != 0) { 339 cc_verify_3des_keys(key, keylen)) {
375 dev_dbg(dev, "weak 3DES key"); 340 dev_dbg(dev, "weak 3DES key");
376 return -EINVAL; 341 return -EINVAL;
377 } 342 }
@@ -380,34 +345,24 @@ static int ssi_blkcipher_setkey(struct crypto_tfm *tfm,
380 dma_sync_single_for_cpu(dev, ctx_p->user.key_dma_addr, 345 dma_sync_single_for_cpu(dev, ctx_p->user.key_dma_addr,
381 max_key_buf_size, DMA_TO_DEVICE); 346 max_key_buf_size, DMA_TO_DEVICE);
382 347
383 if (ctx_p->flow_mode == S_DIN_to_MULTI2) { 348 memcpy(ctx_p->user.key, key, keylen);
384#if SSI_CC_HAS_MULTI2 349 if (keylen == 24)
385 memcpy(ctx_p->user.key, key, CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE); 350 memset(ctx_p->user.key + 24, 0, CC_AES_KEY_SIZE_MAX - 24);
386 ctx_p->key_round_number = key[CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE]; 351
387 if (ctx_p->key_round_number < CC_MULTI2_MIN_NUM_ROUNDS || 352 if (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) {
388 ctx_p->key_round_number > CC_MULTI2_MAX_NUM_ROUNDS) { 353 /* sha256 for key2 - use sw implementation */
389 crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); 354 int key_len = keylen >> 1;
390 dev_dbg(dev, "SSI_CC_HAS_MULTI2 einval"); 355 int err;
391 return -EINVAL; 356
392#endif /*SSI_CC_HAS_MULTI2*/ 357 SHASH_DESC_ON_STACK(desc, ctx_p->shash_tfm);
393 } else { 358
394 memcpy(ctx_p->user.key, key, keylen); 359 desc->tfm = ctx_p->shash_tfm;
395 if (keylen == 24) 360
396 memset(ctx_p->user.key + 24, 0, CC_AES_KEY_SIZE_MAX - 24); 361 err = crypto_shash_digest(desc, ctx_p->user.key, key_len,
397 362 ctx_p->user.key + key_len);
398 if (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) { 363 if (err) {
399 /* sha256 for key2 - use sw implementation */ 364 dev_err(dev, "Failed to hash ESSIV key.\n");
400 int key_len = keylen >> 1; 365 return err;
401 int err;
402 SHASH_DESC_ON_STACK(desc, ctx_p->shash_tfm);
403
404 desc->tfm = ctx_p->shash_tfm;
405
406 err = crypto_shash_digest(desc, ctx_p->user.key, key_len, ctx_p->user.key + key_len);
407 if (err) {
408 dev_err(dev, "Failed to hash ESSIV key.\n");
409 return err;
410 }
411 } 366 }
412 } 367 }
413 dma_sync_single_for_device(dev, ctx_p->user.key_dma_addr, 368 dma_sync_single_for_device(dev, ctx_p->user.key_dma_addr,
@@ -418,16 +373,13 @@ static int ssi_blkcipher_setkey(struct crypto_tfm *tfm,
418 return 0; 373 return 0;
419} 374}
420 375
421static inline void 376static void cc_setup_cipher_desc(struct crypto_tfm *tfm,
422ssi_blkcipher_create_setup_desc( 377 struct blkcipher_req_ctx *req_ctx,
423 struct crypto_tfm *tfm, 378 unsigned int ivsize, unsigned int nbytes,
424 struct blkcipher_req_ctx *req_ctx, 379 struct cc_hw_desc desc[],
425 unsigned int ivsize, 380 unsigned int *seq_size)
426 unsigned int nbytes,
427 struct cc_hw_desc desc[],
428 unsigned int *seq_size)
429{ 381{
430 struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm); 382 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
431 struct device *dev = drvdata_to_dev(ctx_p->drvdata); 383 struct device *dev = drvdata_to_dev(ctx_p->drvdata);
432 int cipher_mode = ctx_p->cipher_mode; 384 int cipher_mode = ctx_p->cipher_mode;
433 int flow_mode = ctx_p->flow_mode; 385 int flow_mode = ctx_p->flow_mode;
@@ -437,11 +389,14 @@ ssi_blkcipher_create_setup_desc(
437 dma_addr_t iv_dma_addr = req_ctx->gen_ctx.iv_dma_addr; 389 dma_addr_t iv_dma_addr = req_ctx->gen_ctx.iv_dma_addr;
438 unsigned int du_size = nbytes; 390 unsigned int du_size = nbytes;
439 391
440 struct ssi_crypto_alg *ssi_alg = container_of(tfm->__crt_alg, struct ssi_crypto_alg, crypto_alg); 392 struct cc_crypto_alg *cc_alg =
393 container_of(tfm->__crt_alg, struct cc_crypto_alg, crypto_alg);
441 394
442 if ((ssi_alg->crypto_alg.cra_flags & CRYPTO_ALG_BULK_MASK) == CRYPTO_ALG_BULK_DU_512) 395 if ((cc_alg->crypto_alg.cra_flags & CRYPTO_ALG_BULK_MASK) ==
396 CRYPTO_ALG_BULK_DU_512)
443 du_size = 512; 397 du_size = 512;
444 if ((ssi_alg->crypto_alg.cra_flags & CRYPTO_ALG_BULK_MASK) == CRYPTO_ALG_BULK_DU_4096) 398 if ((cc_alg->crypto_alg.cra_flags & CRYPTO_ALG_BULK_MASK) ==
399 CRYPTO_ALG_BULK_DU_4096)
445 du_size = 4096; 400 du_size = 4096;
446 401
447 switch (cipher_mode) { 402 switch (cipher_mode) {
@@ -456,8 +411,8 @@ ssi_blkcipher_create_setup_desc(
456 set_cipher_config0(&desc[*seq_size], direction); 411 set_cipher_config0(&desc[*seq_size], direction);
457 set_flow_mode(&desc[*seq_size], flow_mode); 412 set_flow_mode(&desc[*seq_size], flow_mode);
458 set_cipher_mode(&desc[*seq_size], cipher_mode); 413 set_cipher_mode(&desc[*seq_size], cipher_mode);
459 if ((cipher_mode == DRV_CIPHER_CTR) || 414 if (cipher_mode == DRV_CIPHER_CTR ||
460 (cipher_mode == DRV_CIPHER_OFB)) { 415 cipher_mode == DRV_CIPHER_OFB) {
461 set_setup_mode(&desc[*seq_size], SETUP_LOAD_STATE1); 416 set_setup_mode(&desc[*seq_size], SETUP_LOAD_STATE1);
462 } else { 417 } else {
463 set_setup_mode(&desc[*seq_size], SETUP_LOAD_STATE0); 418 set_setup_mode(&desc[*seq_size], SETUP_LOAD_STATE0);
@@ -470,7 +425,7 @@ ssi_blkcipher_create_setup_desc(
470 set_cipher_mode(&desc[*seq_size], cipher_mode); 425 set_cipher_mode(&desc[*seq_size], cipher_mode);
471 set_cipher_config0(&desc[*seq_size], direction); 426 set_cipher_config0(&desc[*seq_size], direction);
472 if (flow_mode == S_DIN_to_AES) { 427 if (flow_mode == S_DIN_to_AES) {
473 if (ssi_is_hw_key(tfm)) { 428 if (cc_is_hw_key(tfm)) {
474 set_hw_crypto_key(&desc[*seq_size], 429 set_hw_crypto_key(&desc[*seq_size],
475 ctx_p->hw.key1_slot); 430 ctx_p->hw.key1_slot);
476 } else { 431 } else {
@@ -497,7 +452,7 @@ ssi_blkcipher_create_setup_desc(
497 hw_desc_init(&desc[*seq_size]); 452 hw_desc_init(&desc[*seq_size]);
498 set_cipher_mode(&desc[*seq_size], cipher_mode); 453 set_cipher_mode(&desc[*seq_size], cipher_mode);
499 set_cipher_config0(&desc[*seq_size], direction); 454 set_cipher_config0(&desc[*seq_size], direction);
500 if (ssi_is_hw_key(tfm)) { 455 if (cc_is_hw_key(tfm)) {
501 set_hw_crypto_key(&desc[*seq_size], 456 set_hw_crypto_key(&desc[*seq_size],
502 ctx_p->hw.key1_slot); 457 ctx_p->hw.key1_slot);
503 } else { 458 } else {
@@ -513,7 +468,7 @@ ssi_blkcipher_create_setup_desc(
513 hw_desc_init(&desc[*seq_size]); 468 hw_desc_init(&desc[*seq_size]);
514 set_cipher_mode(&desc[*seq_size], cipher_mode); 469 set_cipher_mode(&desc[*seq_size], cipher_mode);
515 set_cipher_config0(&desc[*seq_size], direction); 470 set_cipher_config0(&desc[*seq_size], direction);
516 if (ssi_is_hw_key(tfm)) { 471 if (cc_is_hw_key(tfm)) {
517 set_hw_crypto_key(&desc[*seq_size], 472 set_hw_crypto_key(&desc[*seq_size],
518 ctx_p->hw.key2_slot); 473 ctx_p->hw.key2_slot);
519 } else { 474 } else {
@@ -543,62 +498,14 @@ ssi_blkcipher_create_setup_desc(
543 } 498 }
544} 499}
545 500
546#if SSI_CC_HAS_MULTI2 501static void cc_setup_cipher_data(struct crypto_tfm *tfm,
547static inline void ssi_blkcipher_create_multi2_setup_desc( 502 struct blkcipher_req_ctx *req_ctx,
548 struct crypto_tfm *tfm, 503 struct scatterlist *dst,
549 struct blkcipher_req_ctx *req_ctx, 504 struct scatterlist *src, unsigned int nbytes,
550 unsigned int ivsize, 505 void *areq, struct cc_hw_desc desc[],
551 struct cc_hw_desc desc[], 506 unsigned int *seq_size)
552 unsigned int *seq_size)
553{
554 struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
555
556 int direction = req_ctx->gen_ctx.op_type;
557 /* Load system key */
558 hw_desc_init(&desc[*seq_size]);
559 set_cipher_mode(&desc[*seq_size], ctx_p->cipher_mode);
560 set_cipher_config0(&desc[*seq_size], direction);
561 set_din_type(&desc[*seq_size], DMA_DLLI, ctx_p->user.key_dma_addr,
562 CC_MULTI2_SYSTEM_KEY_SIZE, NS_BIT);
563 set_flow_mode(&desc[*seq_size], ctx_p->flow_mode);
564 set_setup_mode(&desc[*seq_size], SETUP_LOAD_KEY0);
565 (*seq_size)++;
566
567 /* load data key */
568 hw_desc_init(&desc[*seq_size]);
569 set_din_type(&desc[*seq_size], DMA_DLLI,
570 (ctx_p->user.key_dma_addr + CC_MULTI2_SYSTEM_KEY_SIZE),
571 CC_MULTI2_DATA_KEY_SIZE, NS_BIT);
572 set_multi2_num_rounds(&desc[*seq_size], ctx_p->key_round_number);
573 set_flow_mode(&desc[*seq_size], ctx_p->flow_mode);
574 set_cipher_mode(&desc[*seq_size], ctx_p->cipher_mode);
575 set_cipher_config0(&desc[*seq_size], direction);
576 set_setup_mode(&desc[*seq_size], SETUP_LOAD_STATE0);
577 (*seq_size)++;
578
579 /* Set state */
580 hw_desc_init(&desc[*seq_size]);
581 set_din_type(&desc[*seq_size], DMA_DLLI, req_ctx->gen_ctx.iv_dma_addr,
582 ivsize, NS_BIT);
583 set_cipher_config0(&desc[*seq_size], direction);
584 set_flow_mode(&desc[*seq_size], ctx_p->flow_mode);
585 set_cipher_mode(&desc[*seq_size], ctx_p->cipher_mode);
586 set_setup_mode(&desc[*seq_size], SETUP_LOAD_STATE1);
587 (*seq_size)++;
588}
589#endif /*SSI_CC_HAS_MULTI2*/
590
591static inline void
592ssi_blkcipher_create_data_desc(
593 struct crypto_tfm *tfm,
594 struct blkcipher_req_ctx *req_ctx,
595 struct scatterlist *dst, struct scatterlist *src,
596 unsigned int nbytes,
597 void *areq,
598 struct cc_hw_desc desc[],
599 unsigned int *seq_size)
600{ 507{
601 struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm); 508 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
602 struct device *dev = drvdata_to_dev(ctx_p->drvdata); 509 struct device *dev = drvdata_to_dev(ctx_p->drvdata);
603 unsigned int flow_mode = ctx_p->flow_mode; 510 unsigned int flow_mode = ctx_p->flow_mode;
604 511
@@ -609,17 +516,12 @@ ssi_blkcipher_create_data_desc(
609 case S_DIN_to_DES: 516 case S_DIN_to_DES:
610 flow_mode = DIN_DES_DOUT; 517 flow_mode = DIN_DES_DOUT;
611 break; 518 break;
612#if SSI_CC_HAS_MULTI2
613 case S_DIN_to_MULTI2:
614 flow_mode = DIN_MULTI2_DOUT;
615 break;
616#endif /*SSI_CC_HAS_MULTI2*/
617 default: 519 default:
618 dev_err(dev, "invalid flow mode, flow_mode = %d\n", flow_mode); 520 dev_err(dev, "invalid flow mode, flow_mode = %d\n", flow_mode);
619 return; 521 return;
620 } 522 }
621 /* Process */ 523 /* Process */
622 if (likely(req_ctx->dma_buf_type == SSI_DMA_BUF_DLLI)) { 524 if (req_ctx->dma_buf_type == CC_DMA_BUF_DLLI) {
623 dev_dbg(dev, " data params addr %pad length 0x%X\n", 525 dev_dbg(dev, " data params addr %pad length 0x%X\n",
624 &sg_dma_address(src), nbytes); 526 &sg_dma_address(src), nbytes);
625 dev_dbg(dev, " data params addr %pad length 0x%X\n", 527 dev_dbg(dev, " data params addr %pad length 0x%X\n",
@@ -682,68 +584,63 @@ ssi_blkcipher_create_data_desc(
682 } 584 }
683} 585}
684 586
685static int ssi_blkcipher_complete(struct device *dev, 587static void cc_cipher_complete(struct device *dev, void *cc_req, int err)
686 struct ssi_ablkcipher_ctx *ctx_p,
687 struct blkcipher_req_ctx *req_ctx,
688 struct scatterlist *dst,
689 struct scatterlist *src,
690 unsigned int ivsize,
691 void *areq,
692 void __iomem *cc_base)
693{ 588{
694 int completion_error = 0; 589 struct ablkcipher_request *areq = (struct ablkcipher_request *)cc_req;
590 struct scatterlist *dst = areq->dst;
591 struct scatterlist *src = areq->src;
592 struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(areq);
593 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(areq);
594 unsigned int ivsize = crypto_ablkcipher_ivsize(tfm);
695 struct ablkcipher_request *req = (struct ablkcipher_request *)areq; 595 struct ablkcipher_request *req = (struct ablkcipher_request *)areq;
696 596
697 ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst); 597 cc_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst);
698 kfree(req_ctx->iv); 598 kfree(req_ctx->iv);
699 599
700 if (areq) { 600 /*
701 /* 601 * The crypto API expects us to set the req->info to the last
702 * The crypto API expects us to set the req->info to the last 602 * ciphertext block. For encrypt, simply copy from the result.
703 * ciphertext block. For encrypt, simply copy from the result. 603 * For decrypt, we must copy from a saved buffer since this
704 * For decrypt, we must copy from a saved buffer since this 604 * could be an in-place decryption operation and the src is
705 * could be an in-place decryption operation and the src is 605 * lost by this point.
706 * lost by this point. 606 */
707 */ 607 if (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT) {
708 if (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT) { 608 memcpy(req->info, req_ctx->backup_info, ivsize);
709 memcpy(req->info, req_ctx->backup_info, ivsize); 609 kfree(req_ctx->backup_info);
710 kfree(req_ctx->backup_info); 610 } else if (!err) {
711 } else { 611 scatterwalk_map_and_copy(req->info, req->dst,
712 scatterwalk_map_and_copy(req->info, req->dst, 612 (req->nbytes - ivsize), ivsize, 0);
713 (req->nbytes - ivsize),
714 ivsize, 0);
715 }
716
717 ablkcipher_request_complete(areq, completion_error);
718 return 0;
719 } 613 }
720 return completion_error; 614
615 ablkcipher_request_complete(areq, err);
721} 616}
722 617
723static int ssi_blkcipher_process( 618static int cc_cipher_process(struct ablkcipher_request *req,
724 struct crypto_tfm *tfm, 619 enum drv_crypto_direction direction)
725 struct blkcipher_req_ctx *req_ctx,
726 struct scatterlist *dst, struct scatterlist *src,
727 unsigned int nbytes,
728 void *info, //req info
729 unsigned int ivsize,
730 void *areq,
731 enum drv_crypto_direction direction)
732{ 620{
733 struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm); 621 struct crypto_ablkcipher *ablk_tfm = crypto_ablkcipher_reqtfm(req);
622 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablk_tfm);
623 struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(req);
624 unsigned int ivsize = crypto_ablkcipher_ivsize(ablk_tfm);
625 struct scatterlist *dst = req->dst;
626 struct scatterlist *src = req->src;
627 unsigned int nbytes = req->nbytes;
628 void *info = req->info;
629 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
734 struct device *dev = drvdata_to_dev(ctx_p->drvdata); 630 struct device *dev = drvdata_to_dev(ctx_p->drvdata);
735 struct cc_hw_desc desc[MAX_ABLKCIPHER_SEQ_LEN]; 631 struct cc_hw_desc desc[MAX_ABLKCIPHER_SEQ_LEN];
736 struct ssi_crypto_req ssi_req = {}; 632 struct cc_crypto_req cc_req = {};
737 int rc, seq_len = 0, cts_restore_flag = 0; 633 int rc, seq_len = 0, cts_restore_flag = 0;
634 gfp_t flags = cc_gfp_flags(&req->base);
738 635
739 dev_dbg(dev, "%s areq=%p info=%p nbytes=%d\n", 636 dev_dbg(dev, "%s req=%p info=%p nbytes=%d\n",
740 ((direction == DRV_CRYPTO_DIRECTION_ENCRYPT) ? 637 ((direction == DRV_CRYPTO_DIRECTION_ENCRYPT) ?
741 "Encrypt" : "Decrypt"), areq, info, nbytes); 638 "Encrypt" : "Decrypt"), req, info, nbytes);
742 639
743 /* STAT_PHASE_0: Init and sanity checks */ 640 /* STAT_PHASE_0: Init and sanity checks */
744 641
745 /* TODO: check data length according to mode */ 642 /* TODO: check data length according to mode */
746 if (unlikely(validate_data_size(ctx_p, nbytes))) { 643 if (validate_data_size(ctx_p, nbytes)) {
747 dev_err(dev, "Unsupported data size %d.\n", nbytes); 644 dev_err(dev, "Unsupported data size %d.\n", nbytes);
748 crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_BLOCK_LEN); 645 crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_BLOCK_LEN);
749 rc = -EINVAL; 646 rc = -EINVAL;
@@ -758,7 +655,7 @@ static int ssi_blkcipher_process(
758 /* The IV we are handed may be allocted from the stack so 655 /* The IV we are handed may be allocted from the stack so
759 * we must copy it to a DMAable buffer before use. 656 * we must copy it to a DMAable buffer before use.
760 */ 657 */
761 req_ctx->iv = kmalloc(ivsize, GFP_KERNEL); 658 req_ctx->iv = kmalloc(ivsize, flags);
762 if (!req_ctx->iv) { 659 if (!req_ctx->iv) {
763 rc = -ENOMEM; 660 rc = -ENOMEM;
764 goto exit_process; 661 goto exit_process;
@@ -766,17 +663,18 @@ static int ssi_blkcipher_process(
766 memcpy(req_ctx->iv, info, ivsize); 663 memcpy(req_ctx->iv, info, ivsize);
767 664
768 /*For CTS in case of data size aligned to 16 use CBC mode*/ 665 /*For CTS in case of data size aligned to 16 use CBC mode*/
769 if (((nbytes % AES_BLOCK_SIZE) == 0) && (ctx_p->cipher_mode == DRV_CIPHER_CBC_CTS)) { 666 if (((nbytes % AES_BLOCK_SIZE) == 0) &&
667 ctx_p->cipher_mode == DRV_CIPHER_CBC_CTS) {
770 ctx_p->cipher_mode = DRV_CIPHER_CBC; 668 ctx_p->cipher_mode = DRV_CIPHER_CBC;
771 cts_restore_flag = 1; 669 cts_restore_flag = 1;
772 } 670 }
773 671
774 /* Setup DX request structure */ 672 /* Setup DX request structure */
775 ssi_req.user_cb = (void *)ssi_ablkcipher_complete; 673 cc_req.user_cb = (void *)cc_cipher_complete;
776 ssi_req.user_arg = (void *)areq; 674 cc_req.user_arg = (void *)req;
777 675
778#ifdef ENABLE_CYCLE_COUNT 676#ifdef ENABLE_CYCLE_COUNT
779 ssi_req.op_type = (direction == DRV_CRYPTO_DIRECTION_DECRYPT) ? 677 cc_req.op_type = (direction == DRV_CRYPTO_DIRECTION_DECRYPT) ?
780 STAT_OP_TYPE_DECODE : STAT_OP_TYPE_ENCODE; 678 STAT_OP_TYPE_DECODE : STAT_OP_TYPE_ENCODE;
781 679
782#endif 680#endif
@@ -786,10 +684,9 @@ static int ssi_blkcipher_process(
786 684
787 /* STAT_PHASE_1: Map buffers */ 685 /* STAT_PHASE_1: Map buffers */
788 686
789 rc = ssi_buffer_mgr_map_blkcipher_request(ctx_p->drvdata, req_ctx, 687 rc = cc_map_blkcipher_request(ctx_p->drvdata, req_ctx, ivsize, nbytes,
790 ivsize, nbytes, req_ctx->iv, 688 req_ctx->iv, src, dst, flags);
791 src, dst); 689 if (rc) {
792 if (unlikely(rc != 0)) {
793 dev_err(dev, "map_request() failed\n"); 690 dev_err(dev, "map_request() failed\n");
794 goto exit_process; 691 goto exit_process;
795 } 692 }
@@ -797,50 +694,35 @@ static int ssi_blkcipher_process(
797 /* STAT_PHASE_2: Create sequence */ 694 /* STAT_PHASE_2: Create sequence */
798 695
799 /* Setup processing */ 696 /* Setup processing */
800#if SSI_CC_HAS_MULTI2 697 cc_setup_cipher_desc(tfm, req_ctx, ivsize, nbytes, desc, &seq_len);
801 if (ctx_p->flow_mode == S_DIN_to_MULTI2)
802 ssi_blkcipher_create_multi2_setup_desc(tfm, req_ctx, ivsize,
803 desc, &seq_len);
804 else
805#endif /*SSI_CC_HAS_MULTI2*/
806 ssi_blkcipher_create_setup_desc(tfm, req_ctx, ivsize, nbytes,
807 desc, &seq_len);
808 /* Data processing */ 698 /* Data processing */
809 ssi_blkcipher_create_data_desc(tfm, req_ctx, dst, src, nbytes, areq, 699 cc_setup_cipher_data(tfm, req_ctx, dst, src, nbytes, req, desc,
810 desc, &seq_len); 700 &seq_len);
811 701
812 /* do we need to generate IV? */ 702 /* do we need to generate IV? */
813 if (req_ctx->is_giv) { 703 if (req_ctx->is_giv) {
814 ssi_req.ivgen_dma_addr[0] = req_ctx->gen_ctx.iv_dma_addr; 704 cc_req.ivgen_dma_addr[0] = req_ctx->gen_ctx.iv_dma_addr;
815 ssi_req.ivgen_dma_addr_len = 1; 705 cc_req.ivgen_dma_addr_len = 1;
816 /* set the IV size (8/16 B long)*/ 706 /* set the IV size (8/16 B long)*/
817 ssi_req.ivgen_size = ivsize; 707 cc_req.ivgen_size = ivsize;
818 } 708 }
819 709
820 /* STAT_PHASE_3: Lock HW and push sequence */ 710 /* STAT_PHASE_3: Lock HW and push sequence */
821 711
822 rc = send_request(ctx_p->drvdata, &ssi_req, desc, seq_len, (!areq) ? 0 : 1); 712 rc = cc_send_request(ctx_p->drvdata, &cc_req, desc, seq_len,
823 if (areq) { 713 &req->base);
824 if (unlikely(rc != -EINPROGRESS)) { 714 if (rc != -EINPROGRESS && rc != -EBUSY) {
825 /* Failed to send the request or request completed synchronously */ 715 /* Failed to send the request or request completed
826 ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst); 716 * synchronously
827 } 717 */
828 718 cc_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst);
829 } else {
830 if (rc != 0) {
831 ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst);
832 } else {
833 rc = ssi_blkcipher_complete(dev, ctx_p, req_ctx, dst,
834 src, ivsize, NULL,
835 ctx_p->drvdata->cc_base);
836 }
837 } 719 }
838 720
839exit_process: 721exit_process:
840 if (cts_restore_flag != 0) 722 if (cts_restore_flag)
841 ctx_p->cipher_mode = DRV_CIPHER_CBC_CTS; 723 ctx_p->cipher_mode = DRV_CIPHER_CBC_CTS;
842 724
843 if (rc != -EINPROGRESS) { 725 if (rc != -EINPROGRESS && rc != -EBUSY) {
844 kfree(req_ctx->backup_info); 726 kfree(req_ctx->backup_info);
845 kfree(req_ctx->iv); 727 kfree(req_ctx->iv);
846 } 728 }
@@ -848,60 +730,28 @@ exit_process:
848 return rc; 730 return rc;
849} 731}
850 732
851static void ssi_ablkcipher_complete(struct device *dev, void *ssi_req, void __iomem *cc_base) 733static int cc_cipher_encrypt(struct ablkcipher_request *req)
852{
853 struct ablkcipher_request *areq = (struct ablkcipher_request *)ssi_req;
854 struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(areq);
855 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(areq);
856 struct ssi_ablkcipher_ctx *ctx_p = crypto_ablkcipher_ctx(tfm);
857 unsigned int ivsize = crypto_ablkcipher_ivsize(tfm);
858
859 ssi_blkcipher_complete(dev, ctx_p, req_ctx, areq->dst, areq->src,
860 ivsize, areq, cc_base);
861}
862
863/* Async wrap functions */
864
865static int ssi_ablkcipher_init(struct crypto_tfm *tfm)
866{
867 struct ablkcipher_tfm *ablktfm = &tfm->crt_ablkcipher;
868
869 ablktfm->reqsize = sizeof(struct blkcipher_req_ctx);
870
871 return ssi_blkcipher_init(tfm);
872}
873
874static int ssi_ablkcipher_setkey(struct crypto_ablkcipher *tfm,
875 const u8 *key,
876 unsigned int keylen)
877{
878 return ssi_blkcipher_setkey(crypto_ablkcipher_tfm(tfm), key, keylen);
879}
880
881static int ssi_ablkcipher_encrypt(struct ablkcipher_request *req)
882{ 734{
883 struct crypto_ablkcipher *ablk_tfm = crypto_ablkcipher_reqtfm(req);
884 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablk_tfm);
885 struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(req); 735 struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(req);
886 unsigned int ivsize = crypto_ablkcipher_ivsize(ablk_tfm);
887 736
888 req_ctx->is_giv = false; 737 req_ctx->is_giv = false;
738 req_ctx->backup_info = NULL;
889 739
890 return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src, req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_ENCRYPT); 740 return cc_cipher_process(req, DRV_CRYPTO_DIRECTION_ENCRYPT);
891} 741}
892 742
893static int ssi_ablkcipher_decrypt(struct ablkcipher_request *req) 743static int cc_cipher_decrypt(struct ablkcipher_request *req)
894{ 744{
895 struct crypto_ablkcipher *ablk_tfm = crypto_ablkcipher_reqtfm(req); 745 struct crypto_ablkcipher *ablk_tfm = crypto_ablkcipher_reqtfm(req);
896 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablk_tfm);
897 struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(req); 746 struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(req);
898 unsigned int ivsize = crypto_ablkcipher_ivsize(ablk_tfm); 747 unsigned int ivsize = crypto_ablkcipher_ivsize(ablk_tfm);
748 gfp_t flags = cc_gfp_flags(&req->base);
899 749
900 /* 750 /*
901 * Allocate and save the last IV sized bytes of the source, which will 751 * Allocate and save the last IV sized bytes of the source, which will
902 * be lost in case of in-place decryption and might be needed for CTS. 752 * be lost in case of in-place decryption and might be needed for CTS.
903 */ 753 */
904 req_ctx->backup_info = kmalloc(ivsize, GFP_KERNEL); 754 req_ctx->backup_info = kmalloc(ivsize, flags);
905 if (!req_ctx->backup_info) 755 if (!req_ctx->backup_info)
906 return -ENOMEM; 756 return -ENOMEM;
907 757
@@ -909,22 +759,20 @@ static int ssi_ablkcipher_decrypt(struct ablkcipher_request *req)
909 (req->nbytes - ivsize), ivsize, 0); 759 (req->nbytes - ivsize), ivsize, 0);
910 req_ctx->is_giv = false; 760 req_ctx->is_giv = false;
911 761
912 return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src, req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_DECRYPT); 762 return cc_cipher_process(req, DRV_CRYPTO_DIRECTION_DECRYPT);
913} 763}
914 764
915/* DX Block cipher alg */ 765/* DX Block cipher alg */
916static struct ssi_alg_template blkcipher_algs[] = { 766static struct cc_alg_template blkcipher_algs[] = {
917/* Async template */
918#if SSI_CC_HAS_AES_XTS
919 { 767 {
920 .name = "xts(aes)", 768 .name = "xts(aes)",
921 .driver_name = "xts-aes-dx", 769 .driver_name = "xts-aes-dx",
922 .blocksize = AES_BLOCK_SIZE, 770 .blocksize = AES_BLOCK_SIZE,
923 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 771 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
924 .template_ablkcipher = { 772 .template_ablkcipher = {
925 .setkey = ssi_ablkcipher_setkey, 773 .setkey = cc_cipher_setkey,
926 .encrypt = ssi_ablkcipher_encrypt, 774 .encrypt = cc_cipher_encrypt,
927 .decrypt = ssi_ablkcipher_decrypt, 775 .decrypt = cc_cipher_decrypt,
928 .min_keysize = AES_MIN_KEY_SIZE * 2, 776 .min_keysize = AES_MIN_KEY_SIZE * 2,
929 .max_keysize = AES_MAX_KEY_SIZE * 2, 777 .max_keysize = AES_MAX_KEY_SIZE * 2,
930 .ivsize = AES_BLOCK_SIZE, 778 .ivsize = AES_BLOCK_SIZE,
@@ -939,9 +787,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
939 .blocksize = AES_BLOCK_SIZE, 787 .blocksize = AES_BLOCK_SIZE,
940 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_512, 788 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_512,
941 .template_ablkcipher = { 789 .template_ablkcipher = {
942 .setkey = ssi_ablkcipher_setkey, 790 .setkey = cc_cipher_setkey,
943 .encrypt = ssi_ablkcipher_encrypt, 791 .encrypt = cc_cipher_encrypt,
944 .decrypt = ssi_ablkcipher_decrypt, 792 .decrypt = cc_cipher_decrypt,
945 .min_keysize = AES_MIN_KEY_SIZE * 2, 793 .min_keysize = AES_MIN_KEY_SIZE * 2,
946 .max_keysize = AES_MAX_KEY_SIZE * 2, 794 .max_keysize = AES_MAX_KEY_SIZE * 2,
947 .ivsize = AES_BLOCK_SIZE, 795 .ivsize = AES_BLOCK_SIZE,
@@ -955,9 +803,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
955 .blocksize = AES_BLOCK_SIZE, 803 .blocksize = AES_BLOCK_SIZE,
956 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_4096, 804 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_4096,
957 .template_ablkcipher = { 805 .template_ablkcipher = {
958 .setkey = ssi_ablkcipher_setkey, 806 .setkey = cc_cipher_setkey,
959 .encrypt = ssi_ablkcipher_encrypt, 807 .encrypt = cc_cipher_encrypt,
960 .decrypt = ssi_ablkcipher_decrypt, 808 .decrypt = cc_cipher_decrypt,
961 .min_keysize = AES_MIN_KEY_SIZE * 2, 809 .min_keysize = AES_MIN_KEY_SIZE * 2,
962 .max_keysize = AES_MAX_KEY_SIZE * 2, 810 .max_keysize = AES_MAX_KEY_SIZE * 2,
963 .ivsize = AES_BLOCK_SIZE, 811 .ivsize = AES_BLOCK_SIZE,
@@ -965,17 +813,15 @@ static struct ssi_alg_template blkcipher_algs[] = {
965 .cipher_mode = DRV_CIPHER_XTS, 813 .cipher_mode = DRV_CIPHER_XTS,
966 .flow_mode = S_DIN_to_AES, 814 .flow_mode = S_DIN_to_AES,
967 }, 815 },
968#endif /*SSI_CC_HAS_AES_XTS*/
969#if SSI_CC_HAS_AES_ESSIV
970 { 816 {
971 .name = "essiv(aes)", 817 .name = "essiv(aes)",
972 .driver_name = "essiv-aes-dx", 818 .driver_name = "essiv-aes-dx",
973 .blocksize = AES_BLOCK_SIZE, 819 .blocksize = AES_BLOCK_SIZE,
974 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 820 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
975 .template_ablkcipher = { 821 .template_ablkcipher = {
976 .setkey = ssi_ablkcipher_setkey, 822 .setkey = cc_cipher_setkey,
977 .encrypt = ssi_ablkcipher_encrypt, 823 .encrypt = cc_cipher_encrypt,
978 .decrypt = ssi_ablkcipher_decrypt, 824 .decrypt = cc_cipher_decrypt,
979 .min_keysize = AES_MIN_KEY_SIZE * 2, 825 .min_keysize = AES_MIN_KEY_SIZE * 2,
980 .max_keysize = AES_MAX_KEY_SIZE * 2, 826 .max_keysize = AES_MAX_KEY_SIZE * 2,
981 .ivsize = AES_BLOCK_SIZE, 827 .ivsize = AES_BLOCK_SIZE,
@@ -989,9 +835,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
989 .blocksize = AES_BLOCK_SIZE, 835 .blocksize = AES_BLOCK_SIZE,
990 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_512, 836 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_512,
991 .template_ablkcipher = { 837 .template_ablkcipher = {
992 .setkey = ssi_ablkcipher_setkey, 838 .setkey = cc_cipher_setkey,
993 .encrypt = ssi_ablkcipher_encrypt, 839 .encrypt = cc_cipher_encrypt,
994 .decrypt = ssi_ablkcipher_decrypt, 840 .decrypt = cc_cipher_decrypt,
995 .min_keysize = AES_MIN_KEY_SIZE * 2, 841 .min_keysize = AES_MIN_KEY_SIZE * 2,
996 .max_keysize = AES_MAX_KEY_SIZE * 2, 842 .max_keysize = AES_MAX_KEY_SIZE * 2,
997 .ivsize = AES_BLOCK_SIZE, 843 .ivsize = AES_BLOCK_SIZE,
@@ -1005,9 +851,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
1005 .blocksize = AES_BLOCK_SIZE, 851 .blocksize = AES_BLOCK_SIZE,
1006 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_4096, 852 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_4096,
1007 .template_ablkcipher = { 853 .template_ablkcipher = {
1008 .setkey = ssi_ablkcipher_setkey, 854 .setkey = cc_cipher_setkey,
1009 .encrypt = ssi_ablkcipher_encrypt, 855 .encrypt = cc_cipher_encrypt,
1010 .decrypt = ssi_ablkcipher_decrypt, 856 .decrypt = cc_cipher_decrypt,
1011 .min_keysize = AES_MIN_KEY_SIZE * 2, 857 .min_keysize = AES_MIN_KEY_SIZE * 2,
1012 .max_keysize = AES_MAX_KEY_SIZE * 2, 858 .max_keysize = AES_MAX_KEY_SIZE * 2,
1013 .ivsize = AES_BLOCK_SIZE, 859 .ivsize = AES_BLOCK_SIZE,
@@ -1015,17 +861,15 @@ static struct ssi_alg_template blkcipher_algs[] = {
1015 .cipher_mode = DRV_CIPHER_ESSIV, 861 .cipher_mode = DRV_CIPHER_ESSIV,
1016 .flow_mode = S_DIN_to_AES, 862 .flow_mode = S_DIN_to_AES,
1017 }, 863 },
1018#endif /*SSI_CC_HAS_AES_ESSIV*/
1019#if SSI_CC_HAS_AES_BITLOCKER
1020 { 864 {
1021 .name = "bitlocker(aes)", 865 .name = "bitlocker(aes)",
1022 .driver_name = "bitlocker-aes-dx", 866 .driver_name = "bitlocker-aes-dx",
1023 .blocksize = AES_BLOCK_SIZE, 867 .blocksize = AES_BLOCK_SIZE,
1024 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 868 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1025 .template_ablkcipher = { 869 .template_ablkcipher = {
1026 .setkey = ssi_ablkcipher_setkey, 870 .setkey = cc_cipher_setkey,
1027 .encrypt = ssi_ablkcipher_encrypt, 871 .encrypt = cc_cipher_encrypt,
1028 .decrypt = ssi_ablkcipher_decrypt, 872 .decrypt = cc_cipher_decrypt,
1029 .min_keysize = AES_MIN_KEY_SIZE * 2, 873 .min_keysize = AES_MIN_KEY_SIZE * 2,
1030 .max_keysize = AES_MAX_KEY_SIZE * 2, 874 .max_keysize = AES_MAX_KEY_SIZE * 2,
1031 .ivsize = AES_BLOCK_SIZE, 875 .ivsize = AES_BLOCK_SIZE,
@@ -1039,9 +883,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
1039 .blocksize = AES_BLOCK_SIZE, 883 .blocksize = AES_BLOCK_SIZE,
1040 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_512, 884 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_512,
1041 .template_ablkcipher = { 885 .template_ablkcipher = {
1042 .setkey = ssi_ablkcipher_setkey, 886 .setkey = cc_cipher_setkey,
1043 .encrypt = ssi_ablkcipher_encrypt, 887 .encrypt = cc_cipher_encrypt,
1044 .decrypt = ssi_ablkcipher_decrypt, 888 .decrypt = cc_cipher_decrypt,
1045 .min_keysize = AES_MIN_KEY_SIZE * 2, 889 .min_keysize = AES_MIN_KEY_SIZE * 2,
1046 .max_keysize = AES_MAX_KEY_SIZE * 2, 890 .max_keysize = AES_MAX_KEY_SIZE * 2,
1047 .ivsize = AES_BLOCK_SIZE, 891 .ivsize = AES_BLOCK_SIZE,
@@ -1055,9 +899,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
1055 .blocksize = AES_BLOCK_SIZE, 899 .blocksize = AES_BLOCK_SIZE,
1056 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_4096, 900 .type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_BULK_DU_4096,
1057 .template_ablkcipher = { 901 .template_ablkcipher = {
1058 .setkey = ssi_ablkcipher_setkey, 902 .setkey = cc_cipher_setkey,
1059 .encrypt = ssi_ablkcipher_encrypt, 903 .encrypt = cc_cipher_encrypt,
1060 .decrypt = ssi_ablkcipher_decrypt, 904 .decrypt = cc_cipher_decrypt,
1061 .min_keysize = AES_MIN_KEY_SIZE * 2, 905 .min_keysize = AES_MIN_KEY_SIZE * 2,
1062 .max_keysize = AES_MAX_KEY_SIZE * 2, 906 .max_keysize = AES_MAX_KEY_SIZE * 2,
1063 .ivsize = AES_BLOCK_SIZE, 907 .ivsize = AES_BLOCK_SIZE,
@@ -1065,16 +909,15 @@ static struct ssi_alg_template blkcipher_algs[] = {
1065 .cipher_mode = DRV_CIPHER_BITLOCKER, 909 .cipher_mode = DRV_CIPHER_BITLOCKER,
1066 .flow_mode = S_DIN_to_AES, 910 .flow_mode = S_DIN_to_AES,
1067 }, 911 },
1068#endif /*SSI_CC_HAS_AES_BITLOCKER*/
1069 { 912 {
1070 .name = "ecb(aes)", 913 .name = "ecb(aes)",
1071 .driver_name = "ecb-aes-dx", 914 .driver_name = "ecb-aes-dx",
1072 .blocksize = AES_BLOCK_SIZE, 915 .blocksize = AES_BLOCK_SIZE,
1073 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 916 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1074 .template_ablkcipher = { 917 .template_ablkcipher = {
1075 .setkey = ssi_ablkcipher_setkey, 918 .setkey = cc_cipher_setkey,
1076 .encrypt = ssi_ablkcipher_encrypt, 919 .encrypt = cc_cipher_encrypt,
1077 .decrypt = ssi_ablkcipher_decrypt, 920 .decrypt = cc_cipher_decrypt,
1078 .min_keysize = AES_MIN_KEY_SIZE, 921 .min_keysize = AES_MIN_KEY_SIZE,
1079 .max_keysize = AES_MAX_KEY_SIZE, 922 .max_keysize = AES_MAX_KEY_SIZE,
1080 .ivsize = 0, 923 .ivsize = 0,
@@ -1088,9 +931,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
1088 .blocksize = AES_BLOCK_SIZE, 931 .blocksize = AES_BLOCK_SIZE,
1089 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 932 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1090 .template_ablkcipher = { 933 .template_ablkcipher = {
1091 .setkey = ssi_ablkcipher_setkey, 934 .setkey = cc_cipher_setkey,
1092 .encrypt = ssi_ablkcipher_encrypt, 935 .encrypt = cc_cipher_encrypt,
1093 .decrypt = ssi_ablkcipher_decrypt, 936 .decrypt = cc_cipher_decrypt,
1094 .min_keysize = AES_MIN_KEY_SIZE, 937 .min_keysize = AES_MIN_KEY_SIZE,
1095 .max_keysize = AES_MAX_KEY_SIZE, 938 .max_keysize = AES_MAX_KEY_SIZE,
1096 .ivsize = AES_BLOCK_SIZE, 939 .ivsize = AES_BLOCK_SIZE,
@@ -1104,9 +947,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
1104 .blocksize = AES_BLOCK_SIZE, 947 .blocksize = AES_BLOCK_SIZE,
1105 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 948 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1106 .template_ablkcipher = { 949 .template_ablkcipher = {
1107 .setkey = ssi_ablkcipher_setkey, 950 .setkey = cc_cipher_setkey,
1108 .encrypt = ssi_ablkcipher_encrypt, 951 .encrypt = cc_cipher_encrypt,
1109 .decrypt = ssi_ablkcipher_decrypt, 952 .decrypt = cc_cipher_decrypt,
1110 .min_keysize = AES_MIN_KEY_SIZE, 953 .min_keysize = AES_MIN_KEY_SIZE,
1111 .max_keysize = AES_MAX_KEY_SIZE, 954 .max_keysize = AES_MAX_KEY_SIZE,
1112 .ivsize = AES_BLOCK_SIZE, 955 .ivsize = AES_BLOCK_SIZE,
@@ -1114,16 +957,15 @@ static struct ssi_alg_template blkcipher_algs[] = {
1114 .cipher_mode = DRV_CIPHER_OFB, 957 .cipher_mode = DRV_CIPHER_OFB,
1115 .flow_mode = S_DIN_to_AES, 958 .flow_mode = S_DIN_to_AES,
1116 }, 959 },
1117#if SSI_CC_HAS_AES_CTS
1118 { 960 {
1119 .name = "cts1(cbc(aes))", 961 .name = "cts1(cbc(aes))",
1120 .driver_name = "cts1-cbc-aes-dx", 962 .driver_name = "cts1-cbc-aes-dx",
1121 .blocksize = AES_BLOCK_SIZE, 963 .blocksize = AES_BLOCK_SIZE,
1122 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 964 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1123 .template_ablkcipher = { 965 .template_ablkcipher = {
1124 .setkey = ssi_ablkcipher_setkey, 966 .setkey = cc_cipher_setkey,
1125 .encrypt = ssi_ablkcipher_encrypt, 967 .encrypt = cc_cipher_encrypt,
1126 .decrypt = ssi_ablkcipher_decrypt, 968 .decrypt = cc_cipher_decrypt,
1127 .min_keysize = AES_MIN_KEY_SIZE, 969 .min_keysize = AES_MIN_KEY_SIZE,
1128 .max_keysize = AES_MAX_KEY_SIZE, 970 .max_keysize = AES_MAX_KEY_SIZE,
1129 .ivsize = AES_BLOCK_SIZE, 971 .ivsize = AES_BLOCK_SIZE,
@@ -1131,16 +973,15 @@ static struct ssi_alg_template blkcipher_algs[] = {
1131 .cipher_mode = DRV_CIPHER_CBC_CTS, 973 .cipher_mode = DRV_CIPHER_CBC_CTS,
1132 .flow_mode = S_DIN_to_AES, 974 .flow_mode = S_DIN_to_AES,
1133 }, 975 },
1134#endif
1135 { 976 {
1136 .name = "ctr(aes)", 977 .name = "ctr(aes)",
1137 .driver_name = "ctr-aes-dx", 978 .driver_name = "ctr-aes-dx",
1138 .blocksize = 1, 979 .blocksize = 1,
1139 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 980 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1140 .template_ablkcipher = { 981 .template_ablkcipher = {
1141 .setkey = ssi_ablkcipher_setkey, 982 .setkey = cc_cipher_setkey,
1142 .encrypt = ssi_ablkcipher_encrypt, 983 .encrypt = cc_cipher_encrypt,
1143 .decrypt = ssi_ablkcipher_decrypt, 984 .decrypt = cc_cipher_decrypt,
1144 .min_keysize = AES_MIN_KEY_SIZE, 985 .min_keysize = AES_MIN_KEY_SIZE,
1145 .max_keysize = AES_MAX_KEY_SIZE, 986 .max_keysize = AES_MAX_KEY_SIZE,
1146 .ivsize = AES_BLOCK_SIZE, 987 .ivsize = AES_BLOCK_SIZE,
@@ -1154,9 +995,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
1154 .blocksize = DES3_EDE_BLOCK_SIZE, 995 .blocksize = DES3_EDE_BLOCK_SIZE,
1155 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 996 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1156 .template_ablkcipher = { 997 .template_ablkcipher = {
1157 .setkey = ssi_ablkcipher_setkey, 998 .setkey = cc_cipher_setkey,
1158 .encrypt = ssi_ablkcipher_encrypt, 999 .encrypt = cc_cipher_encrypt,
1159 .decrypt = ssi_ablkcipher_decrypt, 1000 .decrypt = cc_cipher_decrypt,
1160 .min_keysize = DES3_EDE_KEY_SIZE, 1001 .min_keysize = DES3_EDE_KEY_SIZE,
1161 .max_keysize = DES3_EDE_KEY_SIZE, 1002 .max_keysize = DES3_EDE_KEY_SIZE,
1162 .ivsize = DES3_EDE_BLOCK_SIZE, 1003 .ivsize = DES3_EDE_BLOCK_SIZE,
@@ -1170,9 +1011,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
1170 .blocksize = DES3_EDE_BLOCK_SIZE, 1011 .blocksize = DES3_EDE_BLOCK_SIZE,
1171 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 1012 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1172 .template_ablkcipher = { 1013 .template_ablkcipher = {
1173 .setkey = ssi_ablkcipher_setkey, 1014 .setkey = cc_cipher_setkey,
1174 .encrypt = ssi_ablkcipher_encrypt, 1015 .encrypt = cc_cipher_encrypt,
1175 .decrypt = ssi_ablkcipher_decrypt, 1016 .decrypt = cc_cipher_decrypt,
1176 .min_keysize = DES3_EDE_KEY_SIZE, 1017 .min_keysize = DES3_EDE_KEY_SIZE,
1177 .max_keysize = DES3_EDE_KEY_SIZE, 1018 .max_keysize = DES3_EDE_KEY_SIZE,
1178 .ivsize = 0, 1019 .ivsize = 0,
@@ -1186,9 +1027,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
1186 .blocksize = DES_BLOCK_SIZE, 1027 .blocksize = DES_BLOCK_SIZE,
1187 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 1028 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1188 .template_ablkcipher = { 1029 .template_ablkcipher = {
1189 .setkey = ssi_ablkcipher_setkey, 1030 .setkey = cc_cipher_setkey,
1190 .encrypt = ssi_ablkcipher_encrypt, 1031 .encrypt = cc_cipher_encrypt,
1191 .decrypt = ssi_ablkcipher_decrypt, 1032 .decrypt = cc_cipher_decrypt,
1192 .min_keysize = DES_KEY_SIZE, 1033 .min_keysize = DES_KEY_SIZE,
1193 .max_keysize = DES_KEY_SIZE, 1034 .max_keysize = DES_KEY_SIZE,
1194 .ivsize = DES_BLOCK_SIZE, 1035 .ivsize = DES_BLOCK_SIZE,
@@ -1202,9 +1043,9 @@ static struct ssi_alg_template blkcipher_algs[] = {
1202 .blocksize = DES_BLOCK_SIZE, 1043 .blocksize = DES_BLOCK_SIZE,
1203 .type = CRYPTO_ALG_TYPE_ABLKCIPHER, 1044 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1204 .template_ablkcipher = { 1045 .template_ablkcipher = {
1205 .setkey = ssi_ablkcipher_setkey, 1046 .setkey = cc_cipher_setkey,
1206 .encrypt = ssi_ablkcipher_encrypt, 1047 .encrypt = cc_cipher_encrypt,
1207 .decrypt = ssi_ablkcipher_decrypt, 1048 .decrypt = cc_cipher_decrypt,
1208 .min_keysize = DES_KEY_SIZE, 1049 .min_keysize = DES_KEY_SIZE,
1209 .max_keysize = DES_KEY_SIZE, 1050 .max_keysize = DES_KEY_SIZE,
1210 .ivsize = 0, 1051 .ivsize = 0,
@@ -1212,47 +1053,13 @@ static struct ssi_alg_template blkcipher_algs[] = {
1212 .cipher_mode = DRV_CIPHER_ECB, 1053 .cipher_mode = DRV_CIPHER_ECB,
1213 .flow_mode = S_DIN_to_DES, 1054 .flow_mode = S_DIN_to_DES,
1214 }, 1055 },
1215#if SSI_CC_HAS_MULTI2
1216 {
1217 .name = "cbc(multi2)",
1218 .driver_name = "cbc-multi2-dx",
1219 .blocksize = CC_MULTI2_BLOCK_SIZE,
1220 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1221 .template_ablkcipher = {
1222 .setkey = ssi_ablkcipher_setkey,
1223 .encrypt = ssi_ablkcipher_encrypt,
1224 .decrypt = ssi_ablkcipher_decrypt,
1225 .min_keysize = CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE + 1,
1226 .max_keysize = CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE + 1,
1227 .ivsize = CC_MULTI2_IV_SIZE,
1228 },
1229 .cipher_mode = DRV_MULTI2_CBC,
1230 .flow_mode = S_DIN_to_MULTI2,
1231 },
1232 {
1233 .name = "ofb(multi2)",
1234 .driver_name = "ofb-multi2-dx",
1235 .blocksize = 1,
1236 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1237 .template_ablkcipher = {
1238 .setkey = ssi_ablkcipher_setkey,
1239 .encrypt = ssi_ablkcipher_encrypt,
1240 .decrypt = ssi_ablkcipher_encrypt,
1241 .min_keysize = CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE + 1,
1242 .max_keysize = CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE + 1,
1243 .ivsize = CC_MULTI2_IV_SIZE,
1244 },
1245 .cipher_mode = DRV_MULTI2_OFB,
1246 .flow_mode = S_DIN_to_MULTI2,
1247 },
1248#endif /*SSI_CC_HAS_MULTI2*/
1249}; 1056};
1250 1057
1251static 1058static
1252struct ssi_crypto_alg *ssi_ablkcipher_create_alg(struct ssi_alg_template 1059struct cc_crypto_alg *cc_cipher_create_alg(struct cc_alg_template *template,
1253 *template, struct device *dev) 1060 struct device *dev)
1254{ 1061{
1255 struct ssi_crypto_alg *t_alg; 1062 struct cc_crypto_alg *t_alg;
1256 struct crypto_alg *alg; 1063 struct crypto_alg *alg;
1257 1064
1258 t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL); 1065 t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
@@ -1265,13 +1072,13 @@ struct ssi_crypto_alg *ssi_ablkcipher_create_alg(struct ssi_alg_template
1265 snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", 1072 snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
1266 template->driver_name); 1073 template->driver_name);
1267 alg->cra_module = THIS_MODULE; 1074 alg->cra_module = THIS_MODULE;
1268 alg->cra_priority = SSI_CRA_PRIO; 1075 alg->cra_priority = CC_CRA_PRIO;
1269 alg->cra_blocksize = template->blocksize; 1076 alg->cra_blocksize = template->blocksize;
1270 alg->cra_alignmask = 0; 1077 alg->cra_alignmask = 0;
1271 alg->cra_ctxsize = sizeof(struct ssi_ablkcipher_ctx); 1078 alg->cra_ctxsize = sizeof(struct cc_cipher_ctx);
1272 1079
1273 alg->cra_init = ssi_ablkcipher_init; 1080 alg->cra_init = cc_cipher_init;
1274 alg->cra_exit = ssi_blkcipher_exit; 1081 alg->cra_exit = cc_cipher_exit;
1275 alg->cra_type = &crypto_ablkcipher_type; 1082 alg->cra_type = &crypto_ablkcipher_type;
1276 alg->cra_ablkcipher = template->template_ablkcipher; 1083 alg->cra_ablkcipher = template->template_ablkcipher;
1277 alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY | 1084 alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
@@ -1283,11 +1090,11 @@ struct ssi_crypto_alg *ssi_ablkcipher_create_alg(struct ssi_alg_template
1283 return t_alg; 1090 return t_alg;
1284} 1091}
1285 1092
1286int ssi_ablkcipher_free(struct ssi_drvdata *drvdata) 1093int cc_cipher_free(struct cc_drvdata *drvdata)
1287{ 1094{
1288 struct ssi_crypto_alg *t_alg, *n; 1095 struct cc_crypto_alg *t_alg, *n;
1289 struct ssi_blkcipher_handle *blkcipher_handle = 1096 struct cc_cipher_handle *blkcipher_handle = drvdata->blkcipher_handle;
1290 drvdata->blkcipher_handle; 1097
1291 if (blkcipher_handle) { 1098 if (blkcipher_handle) {
1292 /* Remove registered algs */ 1099 /* Remove registered algs */
1293 list_for_each_entry_safe(t_alg, n, 1100 list_for_each_entry_safe(t_alg, n,
@@ -1303,10 +1110,10 @@ int ssi_ablkcipher_free(struct ssi_drvdata *drvdata)
1303 return 0; 1110 return 0;
1304} 1111}
1305 1112
1306int ssi_ablkcipher_alloc(struct ssi_drvdata *drvdata) 1113int cc_cipher_alloc(struct cc_drvdata *drvdata)
1307{ 1114{
1308 struct ssi_blkcipher_handle *ablkcipher_handle; 1115 struct cc_cipher_handle *ablkcipher_handle;
1309 struct ssi_crypto_alg *t_alg; 1116 struct cc_crypto_alg *t_alg;
1310 struct device *dev = drvdata_to_dev(drvdata); 1117 struct device *dev = drvdata_to_dev(drvdata);
1311 int rc = -ENOMEM; 1118 int rc = -ENOMEM;
1312 int alg; 1119 int alg;
@@ -1323,7 +1130,7 @@ int ssi_ablkcipher_alloc(struct ssi_drvdata *drvdata)
1323 ARRAY_SIZE(blkcipher_algs)); 1130 ARRAY_SIZE(blkcipher_algs));
1324 for (alg = 0; alg < ARRAY_SIZE(blkcipher_algs); alg++) { 1131 for (alg = 0; alg < ARRAY_SIZE(blkcipher_algs); alg++) {
1325 dev_dbg(dev, "creating %s\n", blkcipher_algs[alg].driver_name); 1132 dev_dbg(dev, "creating %s\n", blkcipher_algs[alg].driver_name);
1326 t_alg = ssi_ablkcipher_create_alg(&blkcipher_algs[alg], dev); 1133 t_alg = cc_cipher_create_alg(&blkcipher_algs[alg], dev);
1327 if (IS_ERR(t_alg)) { 1134 if (IS_ERR(t_alg)) {
1328 rc = PTR_ERR(t_alg); 1135 rc = PTR_ERR(t_alg);
1329 dev_err(dev, "%s alg allocation failed\n", 1136 dev_err(dev, "%s alg allocation failed\n",
@@ -1337,7 +1144,7 @@ int ssi_ablkcipher_alloc(struct ssi_drvdata *drvdata)
1337 rc = crypto_register_alg(&t_alg->crypto_alg); 1144 rc = crypto_register_alg(&t_alg->crypto_alg);
1338 dev_dbg(dev, "%s alg registration rc = %x\n", 1145 dev_dbg(dev, "%s alg registration rc = %x\n",
1339 t_alg->crypto_alg.cra_driver_name, rc); 1146 t_alg->crypto_alg.cra_driver_name, rc);
1340 if (unlikely(rc != 0)) { 1147 if (rc) {
1341 dev_err(dev, "%s alg registration failed\n", 1148 dev_err(dev, "%s alg registration failed\n",
1342 t_alg->crypto_alg.cra_driver_name); 1149 t_alg->crypto_alg.cra_driver_name);
1343 kfree(t_alg); 1150 kfree(t_alg);
@@ -1352,6 +1159,6 @@ int ssi_ablkcipher_alloc(struct ssi_drvdata *drvdata)
1352 return 0; 1159 return 0;
1353 1160
1354fail0: 1161fail0:
1355 ssi_ablkcipher_free(drvdata); 1162 cc_cipher_free(drvdata);
1356 return rc; 1163 return rc;
1357} 1164}
diff --git a/drivers/staging/ccree/cc_cipher.h b/drivers/staging/ccree/cc_cipher.h
new file mode 100644
index 000000000000..4c181c721723
--- /dev/null
+++ b/drivers/staging/ccree/cc_cipher.h
@@ -0,0 +1,74 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4/* \file cc_cipher.h
5 * ARM CryptoCell Cipher Crypto API
6 */
7
8#ifndef __CC_CIPHER_H__
9#define __CC_CIPHER_H__
10
11#include <linux/kernel.h>
12#include <crypto/algapi.h>
13#include "cc_driver.h"
14#include "cc_buffer_mgr.h"
15
16/* Crypto cipher flags */
17#define CC_CRYPTO_CIPHER_KEY_KFDE0 BIT(0)
18#define CC_CRYPTO_CIPHER_KEY_KFDE1 BIT(1)
19#define CC_CRYPTO_CIPHER_KEY_KFDE2 BIT(2)
20#define CC_CRYPTO_CIPHER_KEY_KFDE3 BIT(3)
21#define CC_CRYPTO_CIPHER_DU_SIZE_512B BIT(4)
22
23#define CC_CRYPTO_CIPHER_KEY_KFDE_MASK (CC_CRYPTO_CIPHER_KEY_KFDE0 | \
24 CC_CRYPTO_CIPHER_KEY_KFDE1 | \
25 CC_CRYPTO_CIPHER_KEY_KFDE2 | \
26 CC_CRYPTO_CIPHER_KEY_KFDE3)
27
28struct blkcipher_req_ctx {
29 struct async_gen_req_ctx gen_ctx;
30 enum cc_req_dma_buf_type dma_buf_type;
31 u32 in_nents;
32 u32 in_mlli_nents;
33 u32 out_nents;
34 u32 out_mlli_nents;
35 u8 *backup_info; /*store iv for generated IV flow*/
36 u8 *iv;
37 bool is_giv;
38 struct mlli_params mlli_params;
39};
40
41int cc_cipher_alloc(struct cc_drvdata *drvdata);
42
43int cc_cipher_free(struct cc_drvdata *drvdata);
44
45#ifndef CRYPTO_ALG_BULK_MASK
46
47#define CRYPTO_ALG_BULK_DU_512 0x00002000
48#define CRYPTO_ALG_BULK_DU_4096 0x00004000
49#define CRYPTO_ALG_BULK_MASK (CRYPTO_ALG_BULK_DU_512 |\
50 CRYPTO_ALG_BULK_DU_4096)
51#endif /* CRYPTO_ALG_BULK_MASK */
52
53#ifdef CRYPTO_TFM_REQ_HW_KEY
54
55static inline bool cc_is_hw_key(struct crypto_tfm *tfm)
56{
57 return (crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_HW_KEY);
58}
59
60#else
61
62struct arm_hw_key_info {
63 int hw_key1;
64 int hw_key2;
65};
66
67static inline bool cc_is_hw_key(struct crypto_tfm *tfm)
68{
69 return false;
70}
71
72#endif /* CRYPTO_TFM_REQ_HW_KEY */
73
74#endif /*__CC_CIPHER_H__*/
diff --git a/drivers/staging/ccree/cc_crypto_ctx.h b/drivers/staging/ccree/cc_crypto_ctx.h
index 591f6fdadc59..eb16842d7db9 100644
--- a/drivers/staging/ccree/cc_crypto_ctx.h
+++ b/drivers/staging/ccree/cc_crypto_ctx.h
@@ -1,18 +1,5 @@
1/* 1/* SPDX-License-Identifier: GPL-2.0 */
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17#ifndef _CC_CRYPTO_CTX_H_ 4#ifndef _CC_CRYPTO_CTX_H_
18#define _CC_CRYPTO_CTX_H_ 5#define _CC_CRYPTO_CTX_H_
@@ -21,7 +8,7 @@
21 8
22/* context size */ 9/* context size */
23#ifndef CC_CTX_SIZE_LOG2 10#ifndef CC_CTX_SIZE_LOG2
24#if (CC_SUPPORT_SHA > 256) 11#if (CC_DEV_SHA_MAX > 256)
25#define CC_CTX_SIZE_LOG2 8 12#define CC_CTX_SIZE_LOG2 8
26#else 13#else
27#define CC_CTX_SIZE_LOG2 7 14#define CC_CTX_SIZE_LOG2 7
@@ -72,7 +59,7 @@
72#define CC_SHA384_BLOCK_SIZE 128 59#define CC_SHA384_BLOCK_SIZE 128
73#define CC_SHA512_BLOCK_SIZE 128 60#define CC_SHA512_BLOCK_SIZE 128
74 61
75#if (CC_SUPPORT_SHA > 256) 62#if (CC_DEV_SHA_MAX > 256)
76#define CC_DIGEST_SIZE_MAX CC_SHA512_DIGEST_SIZE 63#define CC_DIGEST_SIZE_MAX CC_SHA512_DIGEST_SIZE
77#define CC_HASH_BLOCK_SIZE_MAX CC_SHA512_BLOCK_SIZE /*1024b*/ 64#define CC_HASH_BLOCK_SIZE_MAX CC_SHA512_BLOCK_SIZE /*1024b*/
78#else /* Only up to SHA256 */ 65#else /* Only up to SHA256 */
@@ -82,15 +69,6 @@
82 69
83#define CC_HMAC_BLOCK_SIZE_MAX CC_HASH_BLOCK_SIZE_MAX 70#define CC_HMAC_BLOCK_SIZE_MAX CC_HASH_BLOCK_SIZE_MAX
84 71
85#define CC_MULTI2_SYSTEM_KEY_SIZE 32
86#define CC_MULTI2_DATA_KEY_SIZE 8
87#define CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE \
88 (CC_MULTI2_SYSTEM_KEY_SIZE + CC_MULTI2_DATA_KEY_SIZE)
89#define CC_MULTI2_BLOCK_SIZE 8
90#define CC_MULTI2_IV_SIZE 8
91#define CC_MULTI2_MIN_NUM_ROUNDS 8
92#define CC_MULTI2_MAX_NUM_ROUNDS 128
93
94#define CC_DRV_ALG_MAX_BLOCK_SIZE CC_HASH_BLOCK_SIZE_MAX 72#define CC_DRV_ALG_MAX_BLOCK_SIZE CC_HASH_BLOCK_SIZE_MAX
95 73
96enum drv_engine_type { 74enum drv_engine_type {
@@ -168,14 +146,6 @@ enum drv_hash_hw_mode {
168 DRV_HASH_HW_RESERVE32B = S32_MAX 146 DRV_HASH_HW_RESERVE32B = S32_MAX
169}; 147};
170 148
171enum drv_multi2_mode {
172 DRV_MULTI2_NULL = -1,
173 DRV_MULTI2_ECB = 0,
174 DRV_MULTI2_CBC = 1,
175 DRV_MULTI2_OFB = 2,
176 DRV_MULTI2_RESERVE32B = S32_MAX
177};
178
179/* drv_crypto_key_type[1:0] is mapped to cipher_do[1:0] */ 149/* drv_crypto_key_type[1:0] is mapped to cipher_do[1:0] */
180/* drv_crypto_key_type[2] is mapped to cipher_config2 */ 150/* drv_crypto_key_type[2] is mapped to cipher_config2 */
181enum drv_crypto_key_type { 151enum drv_crypto_key_type {
diff --git a/drivers/staging/ccree/cc_debugfs.c b/drivers/staging/ccree/cc_debugfs.c
new file mode 100644
index 000000000000..08f8db489cf0
--- /dev/null
+++ b/drivers/staging/ccree/cc_debugfs.c
@@ -0,0 +1,101 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4#include <linux/kernel.h>
5#include <linux/debugfs.h>
6#include <linux/stringify.h>
7#include "cc_driver.h"
8#include "cc_crypto_ctx.h"
9#include "cc_debugfs.h"
10
11struct cc_debugfs_ctx {
12 struct dentry *dir;
13};
14
15#define CC_DEBUG_REG(_X) { \
16 .name = __stringify(_X),\
17 .offset = CC_REG(_X) \
18 }
19
20/*
21 * This is a global var for the dentry of the
22 * debugfs ccree/ dir. It is not tied down to
23 * a specific instance of ccree, hence it is
24 * global.
25 */
26static struct dentry *cc_debugfs_dir;
27
28static struct debugfs_reg32 debug_regs[] = {
29 CC_DEBUG_REG(HOST_SIGNATURE),
30 CC_DEBUG_REG(HOST_IRR),
31 CC_DEBUG_REG(HOST_POWER_DOWN_EN),
32 CC_DEBUG_REG(AXIM_MON_ERR),
33 CC_DEBUG_REG(DSCRPTR_QUEUE_CONTENT),
34 CC_DEBUG_REG(HOST_IMR),
35 CC_DEBUG_REG(AXIM_CFG),
36 CC_DEBUG_REG(AXIM_CACHE_PARAMS),
37 CC_DEBUG_REG(HOST_VERSION),
38 CC_DEBUG_REG(GPR_HOST),
39 CC_DEBUG_REG(AXIM_MON_COMP),
40};
41
42int __init cc_debugfs_global_init(void)
43{
44 cc_debugfs_dir = debugfs_create_dir("ccree", NULL);
45
46 return !cc_debugfs_dir;
47}
48
49void __exit cc_debugfs_global_fini(void)
50{
51 debugfs_remove(cc_debugfs_dir);
52}
53
54int cc_debugfs_init(struct cc_drvdata *drvdata)
55{
56 struct device *dev = drvdata_to_dev(drvdata);
57 struct cc_debugfs_ctx *ctx;
58 struct debugfs_regset32 *regset;
59 struct dentry *file;
60
61 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
62 if (!ctx)
63 return -ENOMEM;
64
65 regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL);
66 if (!regset)
67 return -ENOMEM;
68
69 regset->regs = debug_regs;
70 regset->nregs = ARRAY_SIZE(debug_regs);
71 regset->base = drvdata->cc_base;
72
73 ctx->dir = debugfs_create_dir(drvdata->plat_dev->name, cc_debugfs_dir);
74 if (!ctx->dir)
75 return -ENFILE;
76
77 file = debugfs_create_regset32("regs", 0400, ctx->dir, regset);
78 if (!file) {
79 debugfs_remove(ctx->dir);
80 return -ENFILE;
81 }
82
83 file = debugfs_create_bool("coherent", 0400, ctx->dir,
84 &drvdata->coherent);
85
86 if (!file) {
87 debugfs_remove_recursive(ctx->dir);
88 return -ENFILE;
89 }
90
91 drvdata->debugfs = ctx;
92
93 return 0;
94}
95
96void cc_debugfs_fini(struct cc_drvdata *drvdata)
97{
98 struct cc_debugfs_ctx *ctx = (struct cc_debugfs_ctx *)drvdata->debugfs;
99
100 debugfs_remove_recursive(ctx->dir);
101}
diff --git a/drivers/staging/ccree/cc_debugfs.h b/drivers/staging/ccree/cc_debugfs.h
new file mode 100644
index 000000000000..5b5320eca7d2
--- /dev/null
+++ b/drivers/staging/ccree/cc_debugfs.h
@@ -0,0 +1,32 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4#ifndef __CC_DEBUGFS_H__
5#define __CC_DEBUGFS_H__
6
7#ifdef CONFIG_DEBUG_FS
8int cc_debugfs_global_init(void);
9void cc_debugfs_global_fini(void);
10
11int cc_debugfs_init(struct cc_drvdata *drvdata);
12void cc_debugfs_fini(struct cc_drvdata *drvdata);
13
14#else
15
16static inline int cc_debugfs_global_init(void)
17{
18 return 0;
19}
20
21static inline void cc_debugfs_global_fini(void) {}
22
23static inline int cc_debugfs_init(struct cc_drvdata *drvdata)
24{
25 return 0;
26}
27
28static inline void cc_debugfs_fini(struct cc_drvdata *drvdata) {}
29
30#endif
31
32#endif /*__CC_SYSFS_H__*/
diff --git a/drivers/staging/ccree/ssi_driver.c b/drivers/staging/ccree/cc_driver.c
index 1a3c481fa92a..3a1cb0c98648 100644
--- a/drivers/staging/ccree/ssi_driver.c
+++ b/drivers/staging/ccree/cc_driver.c
@@ -1,96 +1,56 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17#include <linux/kernel.h> 4#include <linux/kernel.h>
18#include <linux/module.h> 5#include <linux/module.h>
19 6
20#include <linux/crypto.h> 7#include <linux/crypto.h>
21#include <crypto/algapi.h>
22#include <crypto/aes.h>
23#include <crypto/sha.h>
24#include <crypto/aead.h>
25#include <crypto/authenc.h>
26#include <crypto/scatterwalk.h>
27#include <crypto/internal/skcipher.h>
28
29#include <linux/init.h>
30#include <linux/moduleparam.h> 8#include <linux/moduleparam.h>
31#include <linux/types.h> 9#include <linux/types.h>
32#include <linux/random.h>
33#include <linux/ioport.h>
34#include <linux/interrupt.h> 10#include <linux/interrupt.h>
35#include <linux/fcntl.h>
36#include <linux/poll.h>
37#include <linux/proc_fs.h>
38#include <linux/mutex.h>
39#include <linux/sysctl.h>
40#include <linux/fs.h>
41#include <linux/cdev.h>
42#include <linux/platform_device.h> 11#include <linux/platform_device.h>
43#include <linux/mm.h>
44#include <linux/delay.h>
45#include <linux/dma-mapping.h>
46#include <linux/dmapool.h>
47#include <linux/list.h>
48#include <linux/slab.h> 12#include <linux/slab.h>
49#include <linux/spinlock.h> 13#include <linux/spinlock.h>
50#include <linux/pm.h>
51
52/* cache.h required for L1_CACHE_ALIGN() and cache_line_size() */
53#include <linux/cache.h>
54#include <linux/io.h>
55#include <linux/uaccess.h>
56#include <linux/pagemap.h>
57#include <linux/sched.h>
58#include <linux/random.h>
59#include <linux/of.h> 14#include <linux/of.h>
60#include <linux/clk.h> 15#include <linux/clk.h>
61#include <linux/of_address.h> 16#include <linux/of_address.h>
62 17
63#include "ssi_config.h" 18#include "cc_driver.h"
64#include "ssi_driver.h" 19#include "cc_request_mgr.h"
65#include "ssi_request_mgr.h" 20#include "cc_buffer_mgr.h"
66#include "ssi_buffer_mgr.h" 21#include "cc_debugfs.h"
67#include "ssi_sysfs.h" 22#include "cc_cipher.h"
68#include "ssi_cipher.h" 23#include "cc_aead.h"
69#include "ssi_aead.h" 24#include "cc_hash.h"
70#include "ssi_hash.h" 25#include "cc_ivgen.h"
71#include "ssi_ivgen.h" 26#include "cc_sram_mgr.h"
72#include "ssi_sram_mgr.h" 27#include "cc_pm.h"
73#include "ssi_pm.h" 28#include "cc_fips.h"
74#include "ssi_fips.h" 29
75 30bool cc_dump_desc;
76#ifdef DX_DUMP_BYTES 31module_param_named(dump_desc, cc_dump_desc, bool, 0600);
77void dump_byte_array(const char *name, const u8 *buf, size_t len) 32MODULE_PARM_DESC(cc_dump_desc, "Dump descriptors to kernel log as debugging aid");
33
34bool cc_dump_bytes;
35module_param_named(dump_bytes, cc_dump_bytes, bool, 0600);
36MODULE_PARM_DESC(cc_dump_bytes, "Dump buffers to kernel log as debugging aid");
37
38void __dump_byte_array(const char *name, const u8 *buf, size_t len)
78{ 39{
79 char prefix[NAME_LEN]; 40 char prefix[64];
80 41
81 if (!buf) 42 if (!buf)
82 return; 43 return;
83 44
84 snprintf(prefix, sizeof(prefix), "%s[%lu]: ", name, len); 45 snprintf(prefix, sizeof(prefix), "%s[%zu]: ", name, len);
85 46
86 print_hex_dump(KERN_DEBUG, prefix, DUMP_PREFIX_ADDRESS, 16, 1, len, 47 print_hex_dump(KERN_DEBUG, prefix, DUMP_PREFIX_ADDRESS, 16, 1, buf,
87 false); 48 len, false);
88} 49}
89#endif
90 50
91static irqreturn_t cc_isr(int irq, void *dev_id) 51static irqreturn_t cc_isr(int irq, void *dev_id)
92{ 52{
93 struct ssi_drvdata *drvdata = (struct ssi_drvdata *)dev_id; 53 struct cc_drvdata *drvdata = (struct cc_drvdata *)dev_id;
94 struct device *dev = drvdata_to_dev(drvdata); 54 struct device *dev = drvdata_to_dev(drvdata);
95 u32 irr; 55 u32 irr;
96 u32 imr; 56 u32 imr;
@@ -100,7 +60,7 @@ static irqreturn_t cc_isr(int irq, void *dev_id)
100 /* read the interrupt status */ 60 /* read the interrupt status */
101 irr = cc_ioread(drvdata, CC_REG(HOST_IRR)); 61 irr = cc_ioread(drvdata, CC_REG(HOST_IRR));
102 dev_dbg(dev, "Got IRR=0x%08X\n", irr); 62 dev_dbg(dev, "Got IRR=0x%08X\n", irr);
103 if (unlikely(irr == 0)) { /* Probably shared interrupt line */ 63 if (irr == 0) { /* Probably shared interrupt line */
104 dev_err(dev, "Got interrupt with empty IRR\n"); 64 dev_err(dev, "Got interrupt with empty IRR\n");
105 return IRQ_NONE; 65 return IRQ_NONE;
106 } 66 }
@@ -111,23 +71,27 @@ static irqreturn_t cc_isr(int irq, void *dev_id)
111 71
112 drvdata->irq = irr; 72 drvdata->irq = irr;
113 /* Completion interrupt - most probable */ 73 /* Completion interrupt - most probable */
114 if (likely((irr & SSI_COMP_IRQ_MASK) != 0)) { 74 if (irr & CC_COMP_IRQ_MASK) {
115 /* Mask AXI completion interrupt - will be unmasked in Deferred service handler */ 75 /* Mask AXI completion interrupt - will be unmasked in
116 cc_iowrite(drvdata, CC_REG(HOST_IMR), imr | SSI_COMP_IRQ_MASK); 76 * Deferred service handler
117 irr &= ~SSI_COMP_IRQ_MASK; 77 */
78 cc_iowrite(drvdata, CC_REG(HOST_IMR), imr | CC_COMP_IRQ_MASK);
79 irr &= ~CC_COMP_IRQ_MASK;
118 complete_request(drvdata); 80 complete_request(drvdata);
119 } 81 }
120#ifdef CC_SUPPORT_FIPS 82#ifdef CONFIG_CRYPTO_FIPS
121 /* TEE FIPS interrupt */ 83 /* TEE FIPS interrupt */
122 if (likely((irr & SSI_GPR0_IRQ_MASK) != 0)) { 84 if (irr & CC_GPR0_IRQ_MASK) {
123 /* Mask interrupt - will be unmasked in Deferred service handler */ 85 /* Mask interrupt - will be unmasked in Deferred service
124 cc_iowrite(drvdata, CC_REG(HOST_IMR), imr | SSI_GPR0_IRQ_MASK); 86 * handler
125 irr &= ~SSI_GPR0_IRQ_MASK; 87 */
88 cc_iowrite(drvdata, CC_REG(HOST_IMR), imr | CC_GPR0_IRQ_MASK);
89 irr &= ~CC_GPR0_IRQ_MASK;
126 fips_handler(drvdata); 90 fips_handler(drvdata);
127 } 91 }
128#endif 92#endif
129 /* AXI error interrupt */ 93 /* AXI error interrupt */
130 if (unlikely((irr & SSI_AXI_ERR_IRQ_MASK) != 0)) { 94 if (irr & CC_AXI_ERR_IRQ_MASK) {
131 u32 axi_err; 95 u32 axi_err;
132 96
133 /* Read the AXI error ID */ 97 /* Read the AXI error ID */
@@ -135,10 +99,10 @@ static irqreturn_t cc_isr(int irq, void *dev_id)
135 dev_dbg(dev, "AXI completion error: axim_mon_err=0x%08X\n", 99 dev_dbg(dev, "AXI completion error: axim_mon_err=0x%08X\n",
136 axi_err); 100 axi_err);
137 101
138 irr &= ~SSI_AXI_ERR_IRQ_MASK; 102 irr &= ~CC_AXI_ERR_IRQ_MASK;
139 } 103 }
140 104
141 if (unlikely(irr != 0)) { 105 if (irr) {
142 dev_dbg(dev, "IRR includes unknown cause bits (0x%08X)\n", 106 dev_dbg(dev, "IRR includes unknown cause bits (0x%08X)\n",
143 irr); 107 irr);
144 /* Just warning */ 108 /* Just warning */
@@ -147,14 +111,14 @@ static irqreturn_t cc_isr(int irq, void *dev_id)
147 return IRQ_HANDLED; 111 return IRQ_HANDLED;
148} 112}
149 113
150int init_cc_regs(struct ssi_drvdata *drvdata, bool is_probe) 114int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe)
151{ 115{
152 unsigned int val, cache_params; 116 unsigned int val, cache_params;
153 struct device *dev = drvdata_to_dev(drvdata); 117 struct device *dev = drvdata_to_dev(drvdata);
154 118
155 /* Unmask all AXI interrupt sources AXI_CFG1 register */ 119 /* Unmask all AXI interrupt sources AXI_CFG1 register */
156 val = cc_ioread(drvdata, CC_REG(AXIM_CFG)); 120 val = cc_ioread(drvdata, CC_REG(AXIM_CFG));
157 cc_iowrite(drvdata, CC_REG(AXIM_CFG), val & ~SSI_AXI_IRQ_MASK); 121 cc_iowrite(drvdata, CC_REG(AXIM_CFG), val & ~CC_AXI_IRQ_MASK);
158 dev_dbg(dev, "AXIM_CFG=0x%08X\n", 122 dev_dbg(dev, "AXIM_CFG=0x%08X\n",
159 cc_ioread(drvdata, CC_REG(AXIM_CFG))); 123 cc_ioread(drvdata, CC_REG(AXIM_CFG)));
160 124
@@ -164,21 +128,10 @@ int init_cc_regs(struct ssi_drvdata *drvdata, bool is_probe)
164 cc_iowrite(drvdata, CC_REG(HOST_ICR), val); 128 cc_iowrite(drvdata, CC_REG(HOST_ICR), val);
165 129
166 /* Unmask relevant interrupt cause */ 130 /* Unmask relevant interrupt cause */
167 val = (unsigned int)(~(SSI_COMP_IRQ_MASK | SSI_AXI_ERR_IRQ_MASK | 131 val = (unsigned int)(~(CC_COMP_IRQ_MASK | CC_AXI_ERR_IRQ_MASK |
168 SSI_GPR0_IRQ_MASK)); 132 CC_GPR0_IRQ_MASK));
169 cc_iowrite(drvdata, CC_REG(HOST_IMR), val); 133 cc_iowrite(drvdata, CC_REG(HOST_IMR), val);
170 134
171#ifdef DX_HOST_IRQ_TIMER_INIT_VAL_REG_OFFSET
172#ifdef DX_IRQ_DELAY
173 /* Set CC IRQ delay */
174 cc_iowrite(drvdata, CC_REG(HOST_IRQ_TIMER_INIT_VAL), DX_IRQ_DELAY);
175#endif
176 if (cc_ioread(drvdata, CC_REG(HOST_IRQ_TIMER_INIT_VAL)) > 0) {
177 dev_dbg(dev, "irq_delay=%d CC cycles\n",
178 cc_ioread(drvdata, CC_REG(HOST_IRQ_TIMER_INIT_VAL)));
179 }
180#endif
181
182 cache_params = (drvdata->coherent ? CC_COHERENT_CACHE_PARAMS : 0x0); 135 cache_params = (drvdata->coherent ? CC_COHERENT_CACHE_PARAMS : 0x0);
183 136
184 val = cc_ioread(drvdata, CC_REG(AXIM_CACHE_PARAMS)); 137 val = cc_ioread(drvdata, CC_REG(AXIM_CACHE_PARAMS));
@@ -199,12 +152,11 @@ int init_cc_regs(struct ssi_drvdata *drvdata, bool is_probe)
199static int init_cc_resources(struct platform_device *plat_dev) 152static int init_cc_resources(struct platform_device *plat_dev)
200{ 153{
201 struct resource *req_mem_cc_regs = NULL; 154 struct resource *req_mem_cc_regs = NULL;
202 void __iomem *cc_base = NULL; 155 struct cc_drvdata *new_drvdata;
203 struct ssi_drvdata *new_drvdata;
204 struct device *dev = &plat_dev->dev; 156 struct device *dev = &plat_dev->dev;
205 struct device_node *np = dev->of_node; 157 struct device_node *np = dev->of_node;
206 u32 signature_val; 158 u32 signature_val;
207 dma_addr_t dma_mask; 159 u64 dma_mask;
208 int rc = 0; 160 int rc = 0;
209 161
210 new_drvdata = devm_kzalloc(dev, sizeof(*new_drvdata), GFP_KERNEL); 162 new_drvdata = devm_kzalloc(dev, sizeof(*new_drvdata), GFP_KERNEL);
@@ -222,18 +174,14 @@ static int init_cc_resources(struct platform_device *plat_dev)
222 req_mem_cc_regs = platform_get_resource(plat_dev, IORESOURCE_MEM, 0); 174 req_mem_cc_regs = platform_get_resource(plat_dev, IORESOURCE_MEM, 0);
223 /* Map registers space */ 175 /* Map registers space */
224 new_drvdata->cc_base = devm_ioremap_resource(dev, req_mem_cc_regs); 176 new_drvdata->cc_base = devm_ioremap_resource(dev, req_mem_cc_regs);
225 if (IS_ERR(new_drvdata->cc_base)) { 177 if (IS_ERR(new_drvdata->cc_base))
226 dev_err(dev, "Failed to ioremap registers");
227 return PTR_ERR(new_drvdata->cc_base); 178 return PTR_ERR(new_drvdata->cc_base);
228 }
229 179
230 dev_dbg(dev, "Got MEM resource (%s): %pR\n", req_mem_cc_regs->name, 180 dev_dbg(dev, "Got MEM resource (%s): %pR\n", req_mem_cc_regs->name,
231 req_mem_cc_regs); 181 req_mem_cc_regs);
232 dev_dbg(dev, "CC registers mapped from %pa to 0x%p\n", 182 dev_dbg(dev, "CC registers mapped from %pa to 0x%p\n",
233 &req_mem_cc_regs->start, new_drvdata->cc_base); 183 &req_mem_cc_regs->start, new_drvdata->cc_base);
234 184
235 cc_base = new_drvdata->cc_base;
236
237 /* Then IRQ */ 185 /* Then IRQ */
238 new_drvdata->irq = platform_get_irq(plat_dev, 0); 186 new_drvdata->irq = platform_get_irq(plat_dev, 0);
239 if (new_drvdata->irq < 0) { 187 if (new_drvdata->irq < 0) {
@@ -250,10 +198,12 @@ static int init_cc_resources(struct platform_device *plat_dev)
250 } 198 }
251 dev_dbg(dev, "Registered to IRQ: %d\n", new_drvdata->irq); 199 dev_dbg(dev, "Registered to IRQ: %d\n", new_drvdata->irq);
252 200
201 init_completion(&new_drvdata->hw_queue_avail);
202
253 if (!plat_dev->dev.dma_mask) 203 if (!plat_dev->dev.dma_mask)
254 plat_dev->dev.dma_mask = &plat_dev->dev.coherent_dma_mask; 204 plat_dev->dev.dma_mask = &plat_dev->dev.coherent_dma_mask;
255 205
256 dma_mask = (dma_addr_t)(DMA_BIT_MASK(DMA_BIT_MASK_LEN)); 206 dma_mask = DMA_BIT_MASK(DMA_BIT_MASK_LEN);
257 while (dma_mask > 0x7fffffffUL) { 207 while (dma_mask > 0x7fffffffUL) {
258 if (dma_supported(&plat_dev->dev, dma_mask)) { 208 if (dma_supported(&plat_dev->dev, dma_mask)) {
259 rc = dma_set_coherent_mask(&plat_dev->dev, dma_mask); 209 rc = dma_set_coherent_mask(&plat_dev->dev, dma_mask);
@@ -264,8 +214,7 @@ static int init_cc_resources(struct platform_device *plat_dev)
264 } 214 }
265 215
266 if (rc) { 216 if (rc) {
267 dev_err(dev, "Failed in dma_set_mask, mask=%par\n", 217 dev_err(dev, "Failed in dma_set_mask, mask=%par\n", &dma_mask);
268 &dma_mask);
269 return rc; 218 return rc;
270 } 219 }
271 220
@@ -277,9 +226,9 @@ static int init_cc_resources(struct platform_device *plat_dev)
277 226
278 /* Verify correct mapping */ 227 /* Verify correct mapping */
279 signature_val = cc_ioread(new_drvdata, CC_REG(HOST_SIGNATURE)); 228 signature_val = cc_ioread(new_drvdata, CC_REG(HOST_SIGNATURE));
280 if (signature_val != DX_DEV_SIGNATURE) { 229 if (signature_val != CC_DEV_SIGNATURE) {
281 dev_err(dev, "Invalid CC signature: SIGNATURE=0x%08X != expected=0x%08X\n", 230 dev_err(dev, "Invalid CC signature: SIGNATURE=0x%08X != expected=0x%08X\n",
282 signature_val, (u32)DX_DEV_SIGNATURE); 231 signature_val, (u32)CC_DEV_SIGNATURE);
283 rc = -EINVAL; 232 rc = -EINVAL;
284 goto post_clk_err; 233 goto post_clk_err;
285 } 234 }
@@ -287,84 +236,82 @@ static int init_cc_resources(struct platform_device *plat_dev)
287 236
288 /* Display HW versions */ 237 /* Display HW versions */
289 dev_info(dev, "ARM CryptoCell %s Driver: HW version 0x%08X, Driver version %s\n", 238 dev_info(dev, "ARM CryptoCell %s Driver: HW version 0x%08X, Driver version %s\n",
290 SSI_DEV_NAME_STR, 239 CC_DEV_NAME_STR,
291 cc_ioread(new_drvdata, CC_REG(HOST_VERSION)), 240 cc_ioread(new_drvdata, CC_REG(HOST_VERSION)),
292 DRV_MODULE_VERSION); 241 DRV_MODULE_VERSION);
293 242
294 rc = init_cc_regs(new_drvdata, true); 243 rc = init_cc_regs(new_drvdata, true);
295 if (unlikely(rc != 0)) { 244 if (rc) {
296 dev_err(dev, "init_cc_regs failed\n"); 245 dev_err(dev, "init_cc_regs failed\n");
297 goto post_clk_err; 246 goto post_clk_err;
298 } 247 }
299 248
300#ifdef ENABLE_CC_SYSFS 249 rc = cc_debugfs_init(new_drvdata);
301 rc = ssi_sysfs_init(&dev->kobj, new_drvdata); 250 if (rc) {
302 if (unlikely(rc != 0)) { 251 dev_err(dev, "Failed registering debugfs interface\n");
303 dev_err(dev, "init_stat_db failed\n");
304 goto post_regs_err; 252 goto post_regs_err;
305 } 253 }
306#endif
307 254
308 rc = ssi_fips_init(new_drvdata); 255 rc = cc_fips_init(new_drvdata);
309 if (unlikely(rc != 0)) { 256 if (rc) {
310 dev_err(dev, "SSI_FIPS_INIT failed 0x%x\n", rc); 257 dev_err(dev, "CC_FIPS_INIT failed 0x%x\n", rc);
311 goto post_sysfs_err; 258 goto post_debugfs_err;
312 } 259 }
313 rc = ssi_sram_mgr_init(new_drvdata); 260 rc = cc_sram_mgr_init(new_drvdata);
314 if (unlikely(rc != 0)) { 261 if (rc) {
315 dev_err(dev, "ssi_sram_mgr_init failed\n"); 262 dev_err(dev, "cc_sram_mgr_init failed\n");
316 goto post_fips_init_err; 263 goto post_fips_init_err;
317 } 264 }
318 265
319 new_drvdata->mlli_sram_addr = 266 new_drvdata->mlli_sram_addr =
320 ssi_sram_mgr_alloc(new_drvdata, MAX_MLLI_BUFF_SIZE); 267 cc_sram_alloc(new_drvdata, MAX_MLLI_BUFF_SIZE);
321 if (unlikely(new_drvdata->mlli_sram_addr == NULL_SRAM_ADDR)) { 268 if (new_drvdata->mlli_sram_addr == NULL_SRAM_ADDR) {
322 dev_err(dev, "Failed to alloc MLLI Sram buffer\n"); 269 dev_err(dev, "Failed to alloc MLLI Sram buffer\n");
323 rc = -ENOMEM; 270 rc = -ENOMEM;
324 goto post_sram_mgr_err; 271 goto post_sram_mgr_err;
325 } 272 }
326 273
327 rc = request_mgr_init(new_drvdata); 274 rc = cc_req_mgr_init(new_drvdata);
328 if (unlikely(rc != 0)) { 275 if (rc) {
329 dev_err(dev, "request_mgr_init failed\n"); 276 dev_err(dev, "cc_req_mgr_init failed\n");
330 goto post_sram_mgr_err; 277 goto post_sram_mgr_err;
331 } 278 }
332 279
333 rc = ssi_buffer_mgr_init(new_drvdata); 280 rc = cc_buffer_mgr_init(new_drvdata);
334 if (unlikely(rc != 0)) { 281 if (rc) {
335 dev_err(dev, "buffer_mgr_init failed\n"); 282 dev_err(dev, "buffer_mgr_init failed\n");
336 goto post_req_mgr_err; 283 goto post_req_mgr_err;
337 } 284 }
338 285
339 rc = ssi_power_mgr_init(new_drvdata); 286 rc = cc_pm_init(new_drvdata);
340 if (unlikely(rc != 0)) { 287 if (rc) {
341 dev_err(dev, "ssi_power_mgr_init failed\n"); 288 dev_err(dev, "ssi_power_mgr_init failed\n");
342 goto post_buf_mgr_err; 289 goto post_buf_mgr_err;
343 } 290 }
344 291
345 rc = ssi_ivgen_init(new_drvdata); 292 rc = cc_ivgen_init(new_drvdata);
346 if (unlikely(rc != 0)) { 293 if (rc) {
347 dev_err(dev, "ssi_ivgen_init failed\n"); 294 dev_err(dev, "cc_ivgen_init failed\n");
348 goto post_power_mgr_err; 295 goto post_power_mgr_err;
349 } 296 }
350 297
351 /* Allocate crypto algs */ 298 /* Allocate crypto algs */
352 rc = ssi_ablkcipher_alloc(new_drvdata); 299 rc = cc_cipher_alloc(new_drvdata);
353 if (unlikely(rc != 0)) { 300 if (rc) {
354 dev_err(dev, "ssi_ablkcipher_alloc failed\n"); 301 dev_err(dev, "cc_cipher_alloc failed\n");
355 goto post_ivgen_err; 302 goto post_ivgen_err;
356 } 303 }
357 304
358 /* hash must be allocated before aead since hash exports APIs */ 305 /* hash must be allocated before aead since hash exports APIs */
359 rc = ssi_hash_alloc(new_drvdata); 306 rc = cc_hash_alloc(new_drvdata);
360 if (unlikely(rc != 0)) { 307 if (rc) {
361 dev_err(dev, "ssi_hash_alloc failed\n"); 308 dev_err(dev, "cc_hash_alloc failed\n");
362 goto post_cipher_err; 309 goto post_cipher_err;
363 } 310 }
364 311
365 rc = ssi_aead_alloc(new_drvdata); 312 rc = cc_aead_alloc(new_drvdata);
366 if (unlikely(rc != 0)) { 313 if (rc) {
367 dev_err(dev, "ssi_aead_alloc failed\n"); 314 dev_err(dev, "cc_aead_alloc failed\n");
368 goto post_hash_err; 315 goto post_hash_err;
369 } 316 }
370 317
@@ -377,25 +324,23 @@ static int init_cc_resources(struct platform_device *plat_dev)
377 return 0; 324 return 0;
378 325
379post_hash_err: 326post_hash_err:
380 ssi_hash_free(new_drvdata); 327 cc_hash_free(new_drvdata);
381post_cipher_err: 328post_cipher_err:
382 ssi_ablkcipher_free(new_drvdata); 329 cc_cipher_free(new_drvdata);
383post_ivgen_err: 330post_ivgen_err:
384 ssi_ivgen_fini(new_drvdata); 331 cc_ivgen_fini(new_drvdata);
385post_power_mgr_err: 332post_power_mgr_err:
386 ssi_power_mgr_fini(new_drvdata); 333 cc_pm_fini(new_drvdata);
387post_buf_mgr_err: 334post_buf_mgr_err:
388 ssi_buffer_mgr_fini(new_drvdata); 335 cc_buffer_mgr_fini(new_drvdata);
389post_req_mgr_err: 336post_req_mgr_err:
390 request_mgr_fini(new_drvdata); 337 cc_req_mgr_fini(new_drvdata);
391post_sram_mgr_err: 338post_sram_mgr_err:
392 ssi_sram_mgr_fini(new_drvdata); 339 cc_sram_mgr_fini(new_drvdata);
393post_fips_init_err: 340post_fips_init_err:
394 ssi_fips_fini(new_drvdata); 341 cc_fips_fini(new_drvdata);
395post_sysfs_err: 342post_debugfs_err:
396#ifdef ENABLE_CC_SYSFS 343 cc_debugfs_fini(new_drvdata);
397 ssi_sysfs_fini();
398#endif
399post_regs_err: 344post_regs_err:
400 fini_cc_regs(new_drvdata); 345 fini_cc_regs(new_drvdata);
401post_clk_err: 346post_clk_err:
@@ -403,7 +348,7 @@ post_clk_err:
403 return rc; 348 return rc;
404} 349}
405 350
406void fini_cc_regs(struct ssi_drvdata *drvdata) 351void fini_cc_regs(struct cc_drvdata *drvdata)
407{ 352{
408 /* Mask all interrupts */ 353 /* Mask all interrupts */
409 cc_iowrite(drvdata, CC_REG(HOST_IMR), 0xFFFFFFFF); 354 cc_iowrite(drvdata, CC_REG(HOST_IMR), 0xFFFFFFFF);
@@ -411,26 +356,24 @@ void fini_cc_regs(struct ssi_drvdata *drvdata)
411 356
412static void cleanup_cc_resources(struct platform_device *plat_dev) 357static void cleanup_cc_resources(struct platform_device *plat_dev)
413{ 358{
414 struct ssi_drvdata *drvdata = 359 struct cc_drvdata *drvdata =
415 (struct ssi_drvdata *)platform_get_drvdata(plat_dev); 360 (struct cc_drvdata *)platform_get_drvdata(plat_dev);
416 361
417 ssi_aead_free(drvdata); 362 cc_aead_free(drvdata);
418 ssi_hash_free(drvdata); 363 cc_hash_free(drvdata);
419 ssi_ablkcipher_free(drvdata); 364 cc_cipher_free(drvdata);
420 ssi_ivgen_fini(drvdata); 365 cc_ivgen_fini(drvdata);
421 ssi_power_mgr_fini(drvdata); 366 cc_pm_fini(drvdata);
422 ssi_buffer_mgr_fini(drvdata); 367 cc_buffer_mgr_fini(drvdata);
423 request_mgr_fini(drvdata); 368 cc_req_mgr_fini(drvdata);
424 ssi_sram_mgr_fini(drvdata); 369 cc_sram_mgr_fini(drvdata);
425 ssi_fips_fini(drvdata); 370 cc_fips_fini(drvdata);
426#ifdef ENABLE_CC_SYSFS 371 cc_debugfs_fini(drvdata);
427 ssi_sysfs_fini();
428#endif
429 fini_cc_regs(drvdata); 372 fini_cc_regs(drvdata);
430 cc_clk_off(drvdata); 373 cc_clk_off(drvdata);
431} 374}
432 375
433int cc_clk_on(struct ssi_drvdata *drvdata) 376int cc_clk_on(struct cc_drvdata *drvdata)
434{ 377{
435 struct clk *clk = drvdata->clk; 378 struct clk *clk = drvdata->clk;
436 int rc; 379 int rc;
@@ -446,7 +389,7 @@ int cc_clk_on(struct ssi_drvdata *drvdata)
446 return 0; 389 return 0;
447} 390}
448 391
449void cc_clk_off(struct ssi_drvdata *drvdata) 392void cc_clk_off(struct cc_drvdata *drvdata)
450{ 393{
451 struct clk *clk = drvdata->clk; 394 struct clk *clk = drvdata->clk;
452 395
@@ -461,23 +404,10 @@ static int cc7x_probe(struct platform_device *plat_dev)
461{ 404{
462 int rc; 405 int rc;
463 struct device *dev = &plat_dev->dev; 406 struct device *dev = &plat_dev->dev;
464#if defined(CONFIG_ARM) && defined(CC_DEBUG)
465 u32 ctr, cacheline_size;
466
467 asm volatile("mrc p15, 0, %0, c0, c0, 1" : "=r" (ctr));
468 cacheline_size = 4 << ((ctr >> 16) & 0xf);
469 dev_dbg(dev, "CP15(L1_CACHE_BYTES) = %u , Kconfig(L1_CACHE_BYTES) = %u\n",
470 cacheline_size, L1_CACHE_BYTES);
471
472 asm volatile("mrc p15, 0, %0, c0, c0, 0" : "=r" (ctr));
473 dev_dbg(dev, "Main ID register (MIDR): Implementer 0x%02X, Arch 0x%01X, Part 0x%03X, Rev r%dp%d\n",
474 (ctr >> 24), (ctr >> 16) & 0xF, (ctr >> 4) & 0xFFF,
475 (ctr >> 20) & 0xF, ctr & 0xF);
476#endif
477 407
478 /* Map registers space */ 408 /* Map registers space */
479 rc = init_cc_resources(plat_dev); 409 rc = init_cc_resources(plat_dev);
480 if (rc != 0) 410 if (rc)
481 return rc; 411 return rc;
482 412
483 dev_info(dev, "ARM ccree device initialized\n"); 413 dev_info(dev, "ARM ccree device initialized\n");
@@ -498,38 +428,44 @@ static int cc7x_remove(struct platform_device *plat_dev)
498 return 0; 428 return 0;
499} 429}
500 430
501#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
502static const struct dev_pm_ops arm_cc7x_driver_pm = {
503 SET_RUNTIME_PM_OPS(ssi_power_mgr_runtime_suspend, ssi_power_mgr_runtime_resume, NULL)
504};
505#endif
506
507#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
508#define DX_DRIVER_RUNTIME_PM (&arm_cc7x_driver_pm)
509#else
510#define DX_DRIVER_RUNTIME_PM NULL
511#endif
512
513#ifdef CONFIG_OF
514static const struct of_device_id arm_cc7x_dev_of_match[] = { 431static const struct of_device_id arm_cc7x_dev_of_match[] = {
515 {.compatible = "arm,cryptocell-712-ree"}, 432 {.compatible = "arm,cryptocell-712-ree"},
516 {} 433 {}
517}; 434};
518MODULE_DEVICE_TABLE(of, arm_cc7x_dev_of_match); 435MODULE_DEVICE_TABLE(of, arm_cc7x_dev_of_match);
519#endif
520 436
521static struct platform_driver cc7x_driver = { 437static struct platform_driver cc7x_driver = {
522 .driver = { 438 .driver = {
523 .name = "cc7xree", 439 .name = "cc7xree",
524#ifdef CONFIG_OF
525 .of_match_table = arm_cc7x_dev_of_match, 440 .of_match_table = arm_cc7x_dev_of_match,
441#ifdef CONFIG_PM
442 .pm = &ccree_pm,
526#endif 443#endif
527 .pm = DX_DRIVER_RUNTIME_PM,
528 }, 444 },
529 .probe = cc7x_probe, 445 .probe = cc7x_probe,
530 .remove = cc7x_remove, 446 .remove = cc7x_remove,
531}; 447};
532module_platform_driver(cc7x_driver); 448
449static int __init ccree_init(void)
450{
451 int ret;
452
453 cc_hash_global_init();
454
455 ret = cc_debugfs_global_init();
456 if (ret)
457 return ret;
458
459 return platform_driver_register(&cc7x_driver);
460}
461module_init(ccree_init);
462
463static void __exit ccree_exit(void)
464{
465 platform_driver_unregister(&cc7x_driver);
466 cc_debugfs_global_fini();
467}
468module_exit(ccree_exit);
533 469
534/* Module description */ 470/* Module description */
535MODULE_DESCRIPTION("ARM TrustZone CryptoCell REE Driver"); 471MODULE_DESCRIPTION("ARM TrustZone CryptoCell REE Driver");
diff --git a/drivers/staging/ccree/cc_driver.h b/drivers/staging/ccree/cc_driver.h
new file mode 100644
index 000000000000..773ac591c45c
--- /dev/null
+++ b/drivers/staging/ccree/cc_driver.h
@@ -0,0 +1,194 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4/* \file cc_driver.h
5 * ARM CryptoCell Linux Crypto Driver
6 */
7
8#ifndef __CC_DRIVER_H__
9#define __CC_DRIVER_H__
10
11#ifdef COMP_IN_WQ
12#include <linux/workqueue.h>
13#else
14#include <linux/interrupt.h>
15#endif
16#include <linux/dma-mapping.h>
17#include <crypto/algapi.h>
18#include <crypto/internal/skcipher.h>
19#include <crypto/aes.h>
20#include <crypto/sha.h>
21#include <crypto/aead.h>
22#include <crypto/authenc.h>
23#include <crypto/hash.h>
24#include <linux/version.h>
25#include <linux/clk.h>
26#include <linux/platform_device.h>
27
28/* Registers definitions from shared/hw/ree_include */
29#include "cc_host_regs.h"
30#define CC_DEV_SHA_MAX 512
31#include "cc_crypto_ctx.h"
32#include "cc_hw_queue_defs.h"
33#include "cc_sram_mgr.h"
34
35extern bool cc_dump_desc;
36extern bool cc_dump_bytes;
37
38#define DRV_MODULE_VERSION "3.0"
39
40#define CC_DEV_NAME_STR "cc715ree"
41#define CC_COHERENT_CACHE_PARAMS 0xEEE
42
43/* Maximum DMA mask supported by IP */
44#define DMA_BIT_MASK_LEN 48
45
46#define CC_DEV_SIGNATURE 0xDCC71200UL
47
48#define CC_AXI_IRQ_MASK ((1 << CC_AXIM_CFG_BRESPMASK_BIT_SHIFT) | \
49 (1 << CC_AXIM_CFG_RRESPMASK_BIT_SHIFT) | \
50 (1 << CC_AXIM_CFG_INFLTMASK_BIT_SHIFT) | \
51 (1 << CC_AXIM_CFG_COMPMASK_BIT_SHIFT))
52
53#define CC_AXI_ERR_IRQ_MASK BIT(CC_HOST_IRR_AXI_ERR_INT_BIT_SHIFT)
54
55#define CC_COMP_IRQ_MASK BIT(CC_HOST_IRR_AXIM_COMP_INT_BIT_SHIFT)
56
57#define AXIM_MON_COMP_VALUE GENMASK(CC_AXIM_MON_COMP_VALUE_BIT_SIZE + \
58 CC_AXIM_MON_COMP_VALUE_BIT_SHIFT, \
59 CC_AXIM_MON_COMP_VALUE_BIT_SHIFT)
60
61/* Register name mangling macro */
62#define CC_REG(reg_name) CC_ ## reg_name ## _REG_OFFSET
63
64/* TEE FIPS status interrupt */
65#define CC_GPR0_IRQ_MASK BIT(CC_HOST_IRR_GPR0_BIT_SHIFT)
66
67#define CC_CRA_PRIO 3000
68
69#define MIN_HW_QUEUE_SIZE 50 /* Minimum size required for proper function */
70
71#define MAX_REQUEST_QUEUE_SIZE 4096
72#define MAX_MLLI_BUFF_SIZE 2080
73#define MAX_ICV_NENTS_SUPPORTED 2
74
75/* Definitions for HW descriptors DIN/DOUT fields */
76#define NS_BIT 1
77#define AXI_ID 0
78/* AXI_ID is not actually the AXI ID of the transaction but the value of AXI_ID
79 * field in the HW descriptor. The DMA engine +8 that value.
80 */
81
82#define CC_MAX_IVGEN_DMA_ADDRESSES 3
83struct cc_crypto_req {
84 void (*user_cb)(struct device *dev, void *req, int err);
85 void *user_arg;
86 dma_addr_t ivgen_dma_addr[CC_MAX_IVGEN_DMA_ADDRESSES];
87 /* For the first 'ivgen_dma_addr_len' addresses of this array,
88 * generated IV would be placed in it by send_request().
89 * Same generated IV for all addresses!
90 */
91 /* Amount of 'ivgen_dma_addr' elements to be filled. */
92 unsigned int ivgen_dma_addr_len;
93 /* The generated IV size required, 8/16 B allowed. */
94 unsigned int ivgen_size;
95 struct completion seq_compl; /* request completion */
96};
97
98/**
99 * struct cc_drvdata - driver private data context
100 * @cc_base: virt address of the CC registers
101 * @irq: device IRQ number
102 * @irq_mask: Interrupt mask shadow (1 for masked interrupts)
103 * @fw_ver: SeP loaded firmware version
104 */
105struct cc_drvdata {
106 void __iomem *cc_base;
107 int irq;
108 u32 irq_mask;
109 u32 fw_ver;
110 struct completion hw_queue_avail; /* wait for HW queue availability */
111 struct platform_device *plat_dev;
112 cc_sram_addr_t mlli_sram_addr;
113 void *buff_mgr_handle;
114 void *hash_handle;
115 void *aead_handle;
116 void *blkcipher_handle;
117 void *request_mgr_handle;
118 void *fips_handle;
119 void *ivgen_handle;
120 void *sram_mgr_handle;
121 void *debugfs;
122 struct clk *clk;
123 bool coherent;
124};
125
126struct cc_crypto_alg {
127 struct list_head entry;
128 int cipher_mode;
129 int flow_mode; /* Note: currently, refers to the cipher mode only. */
130 int auth_mode;
131 struct cc_drvdata *drvdata;
132 struct crypto_alg crypto_alg;
133 struct aead_alg aead_alg;
134};
135
136struct cc_alg_template {
137 char name[CRYPTO_MAX_ALG_NAME];
138 char driver_name[CRYPTO_MAX_ALG_NAME];
139 unsigned int blocksize;
140 u32 type;
141 union {
142 struct ablkcipher_alg ablkcipher;
143 struct aead_alg aead;
144 struct blkcipher_alg blkcipher;
145 struct cipher_alg cipher;
146 struct compress_alg compress;
147 } template_u;
148 int cipher_mode;
149 int flow_mode; /* Note: currently, refers to the cipher mode only. */
150 int auth_mode;
151 struct cc_drvdata *drvdata;
152};
153
154struct async_gen_req_ctx {
155 dma_addr_t iv_dma_addr;
156 enum drv_crypto_direction op_type;
157};
158
159static inline struct device *drvdata_to_dev(struct cc_drvdata *drvdata)
160{
161 return &drvdata->plat_dev->dev;
162}
163
164void __dump_byte_array(const char *name, const u8 *buf, size_t len);
165static inline void dump_byte_array(const char *name, const u8 *the_array,
166 size_t size)
167{
168 if (cc_dump_bytes)
169 __dump_byte_array(name, the_array, size);
170}
171
172int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe);
173void fini_cc_regs(struct cc_drvdata *drvdata);
174int cc_clk_on(struct cc_drvdata *drvdata);
175void cc_clk_off(struct cc_drvdata *drvdata);
176
177static inline void cc_iowrite(struct cc_drvdata *drvdata, u32 reg, u32 val)
178{
179 iowrite32(val, (drvdata->cc_base + reg));
180}
181
182static inline u32 cc_ioread(struct cc_drvdata *drvdata, u32 reg)
183{
184 return ioread32(drvdata->cc_base + reg);
185}
186
187static inline gfp_t cc_gfp_flags(struct crypto_async_request *req)
188{
189 return (req->flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
190 GFP_KERNEL : GFP_ATOMIC;
191}
192
193#endif /*__CC_DRIVER_H__*/
194
diff --git a/drivers/staging/ccree/ssi_fips.c b/drivers/staging/ccree/cc_fips.c
index 4aea99fa129f..de08af976b7f 100644
--- a/drivers/staging/ccree/ssi_fips.c
+++ b/drivers/staging/ccree/cc_fips.c
@@ -1,36 +1,22 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17#include <linux/kernel.h> 4#include <linux/kernel.h>
18#include <linux/fips.h> 5#include <linux/fips.h>
19 6
20#include "ssi_config.h" 7#include "cc_driver.h"
21#include "ssi_driver.h" 8#include "cc_fips.h"
22#include "ssi_fips.h"
23 9
24static void fips_dsr(unsigned long devarg); 10static void fips_dsr(unsigned long devarg);
25 11
26struct ssi_fips_handle { 12struct cc_fips_handle {
27 struct tasklet_struct tasklet; 13 struct tasklet_struct tasklet;
28}; 14};
29 15
30/* The function called once at driver entry point to check 16/* The function called once at driver entry point to check
31 * whether TEE FIPS error occurred. 17 * whether TEE FIPS error occurred.
32 */ 18 */
33static bool cc_get_tee_fips_status(struct ssi_drvdata *drvdata) 19static bool cc_get_tee_fips_status(struct cc_drvdata *drvdata)
34{ 20{
35 u32 reg; 21 u32 reg;
36 22
@@ -42,7 +28,7 @@ static bool cc_get_tee_fips_status(struct ssi_drvdata *drvdata)
42 * This function should push the FIPS REE library status towards the TEE library 28 * This function should push the FIPS REE library status towards the TEE library
43 * by writing the error state to HOST_GPR0 register. 29 * by writing the error state to HOST_GPR0 register.
44 */ 30 */
45void cc_set_ree_fips_status(struct ssi_drvdata *drvdata, bool status) 31void cc_set_ree_fips_status(struct cc_drvdata *drvdata, bool status)
46{ 32{
47 int val = CC_FIPS_SYNC_REE_STATUS; 33 int val = CC_FIPS_SYNC_REE_STATUS;
48 34
@@ -51,9 +37,9 @@ void cc_set_ree_fips_status(struct ssi_drvdata *drvdata, bool status)
51 cc_iowrite(drvdata, CC_REG(HOST_GPR0), val); 37 cc_iowrite(drvdata, CC_REG(HOST_GPR0), val);
52} 38}
53 39
54void ssi_fips_fini(struct ssi_drvdata *drvdata) 40void cc_fips_fini(struct cc_drvdata *drvdata)
55{ 41{
56 struct ssi_fips_handle *fips_h = drvdata->fips_handle; 42 struct cc_fips_handle *fips_h = drvdata->fips_handle;
57 43
58 if (!fips_h) 44 if (!fips_h)
59 return; /* Not allocated */ 45 return; /* Not allocated */
@@ -65,10 +51,9 @@ void ssi_fips_fini(struct ssi_drvdata *drvdata)
65 drvdata->fips_handle = NULL; 51 drvdata->fips_handle = NULL;
66} 52}
67 53
68void fips_handler(struct ssi_drvdata *drvdata) 54void fips_handler(struct cc_drvdata *drvdata)
69{ 55{
70 struct ssi_fips_handle *fips_handle_ptr = 56 struct cc_fips_handle *fips_handle_ptr = drvdata->fips_handle;
71 drvdata->fips_handle;
72 57
73 tasklet_schedule(&fips_handle_ptr->tasklet); 58 tasklet_schedule(&fips_handle_ptr->tasklet);
74} 59}
@@ -84,11 +69,11 @@ static inline void tee_fips_error(struct device *dev)
84/* Deferred service handler, run as interrupt-fired tasklet */ 69/* Deferred service handler, run as interrupt-fired tasklet */
85static void fips_dsr(unsigned long devarg) 70static void fips_dsr(unsigned long devarg)
86{ 71{
87 struct ssi_drvdata *drvdata = (struct ssi_drvdata *)devarg; 72 struct cc_drvdata *drvdata = (struct cc_drvdata *)devarg;
88 struct device *dev = drvdata_to_dev(drvdata); 73 struct device *dev = drvdata_to_dev(drvdata);
89 u32 irq, state, val; 74 u32 irq, state, val;
90 75
91 irq = (drvdata->irq & (SSI_GPR0_IRQ_MASK)); 76 irq = (drvdata->irq & (CC_GPR0_IRQ_MASK));
92 77
93 if (irq) { 78 if (irq) {
94 state = cc_ioread(drvdata, CC_REG(GPR_HOST)); 79 state = cc_ioread(drvdata, CC_REG(GPR_HOST));
@@ -105,9 +90,9 @@ static void fips_dsr(unsigned long devarg)
105} 90}
106 91
107/* The function called once at driver entry point .*/ 92/* The function called once at driver entry point .*/
108int ssi_fips_init(struct ssi_drvdata *p_drvdata) 93int cc_fips_init(struct cc_drvdata *p_drvdata)
109{ 94{
110 struct ssi_fips_handle *fips_h; 95 struct cc_fips_handle *fips_h;
111 struct device *dev = drvdata_to_dev(p_drvdata); 96 struct device *dev = drvdata_to_dev(p_drvdata);
112 97
113 fips_h = kzalloc(sizeof(*fips_h), GFP_KERNEL); 98 fips_h = kzalloc(sizeof(*fips_h), GFP_KERNEL);
diff --git a/drivers/staging/ccree/cc_fips.h b/drivers/staging/ccree/cc_fips.h
new file mode 100644
index 000000000000..0d520030095b
--- /dev/null
+++ b/drivers/staging/ccree/cc_fips.h
@@ -0,0 +1,37 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4#ifndef __CC_FIPS_H__
5#define __CC_FIPS_H__
6
7#ifdef CONFIG_CRYPTO_FIPS
8
9enum cc_fips_status {
10 CC_FIPS_SYNC_MODULE_OK = 0x0,
11 CC_FIPS_SYNC_MODULE_ERROR = 0x1,
12 CC_FIPS_SYNC_REE_STATUS = 0x4,
13 CC_FIPS_SYNC_TEE_STATUS = 0x8,
14 CC_FIPS_SYNC_STATUS_RESERVE32B = S32_MAX
15};
16
17int cc_fips_init(struct cc_drvdata *p_drvdata);
18void cc_fips_fini(struct cc_drvdata *drvdata);
19void fips_handler(struct cc_drvdata *drvdata);
20void cc_set_ree_fips_status(struct cc_drvdata *drvdata, bool ok);
21
22#else /* CONFIG_CRYPTO_FIPS */
23
24static inline int cc_fips_init(struct cc_drvdata *p_drvdata)
25{
26 return 0;
27}
28
29static inline void cc_fips_fini(struct cc_drvdata *drvdata) {}
30static inline void cc_set_ree_fips_status(struct cc_drvdata *drvdata,
31 bool ok) {}
32static inline void fips_handler(struct cc_drvdata *drvdata) {}
33
34#endif /* CONFIG_CRYPTO_FIPS */
35
36#endif /*__CC_FIPS_H__*/
37
diff --git a/drivers/staging/ccree/ssi_hash.c b/drivers/staging/ccree/cc_hash.c
index 2035835b62dc..8afc39f10bb3 100644
--- a/drivers/staging/ccree/ssi_hash.c
+++ b/drivers/staging/ccree/cc_hash.c
@@ -1,44 +1,26 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17#include <linux/kernel.h> 4#include <linux/kernel.h>
18#include <linux/module.h> 5#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <crypto/algapi.h> 6#include <crypto/algapi.h>
21#include <crypto/hash.h> 7#include <crypto/hash.h>
22#include <crypto/sha.h>
23#include <crypto/md5.h> 8#include <crypto/md5.h>
24#include <crypto/internal/hash.h> 9#include <crypto/internal/hash.h>
25 10
26#include "ssi_config.h" 11#include "cc_driver.h"
27#include "ssi_driver.h" 12#include "cc_request_mgr.h"
28#include "ssi_request_mgr.h" 13#include "cc_buffer_mgr.h"
29#include "ssi_buffer_mgr.h" 14#include "cc_hash.h"
30#include "ssi_sysfs.h" 15#include "cc_sram_mgr.h"
31#include "ssi_hash.h"
32#include "ssi_sram_mgr.h"
33 16
34#define SSI_MAX_AHASH_SEQ_LEN 12 17#define CC_MAX_HASH_SEQ_LEN 12
35#define SSI_MAX_HASH_OPAD_TMP_KEYS_SIZE MAX(SSI_MAX_HASH_BLCK_SIZE, 3 * AES_BLOCK_SIZE) 18#define CC_MAX_OPAD_KEYS_SIZE CC_MAX_HASH_BLCK_SIZE
36 19
37struct ssi_hash_handle { 20struct cc_hash_handle {
38 ssi_sram_addr_t digest_len_sram_addr; /* const value in SRAM*/ 21 cc_sram_addr_t digest_len_sram_addr; /* const value in SRAM*/
39 ssi_sram_addr_t larval_digest_sram_addr; /* const value in SRAM */ 22 cc_sram_addr_t larval_digest_sram_addr; /* const value in SRAM */
40 struct list_head hash_list; 23 struct list_head hash_list;
41 struct completion init_comp;
42}; 24};
43 25
44static const u32 digest_len_init[] = { 26static const u32 digest_len_init[] = {
@@ -53,32 +35,31 @@ static const u32 sha224_init[] = {
53static const u32 sha256_init[] = { 35static const u32 sha256_init[] = {
54 SHA256_H7, SHA256_H6, SHA256_H5, SHA256_H4, 36 SHA256_H7, SHA256_H6, SHA256_H5, SHA256_H4,
55 SHA256_H3, SHA256_H2, SHA256_H1, SHA256_H0 }; 37 SHA256_H3, SHA256_H2, SHA256_H1, SHA256_H0 };
56#if (DX_DEV_SHA_MAX > 256) 38#if (CC_DEV_SHA_MAX > 256)
57static const u32 digest_len_sha512_init[] = { 39static const u32 digest_len_sha512_init[] = {
58 0x00000080, 0x00000000, 0x00000000, 0x00000000 }; 40 0x00000080, 0x00000000, 0x00000000, 0x00000000 };
59static const u64 sha384_init[] = { 41static u64 sha384_init[] = {
60 SHA384_H7, SHA384_H6, SHA384_H5, SHA384_H4, 42 SHA384_H7, SHA384_H6, SHA384_H5, SHA384_H4,
61 SHA384_H3, SHA384_H2, SHA384_H1, SHA384_H0 }; 43 SHA384_H3, SHA384_H2, SHA384_H1, SHA384_H0 };
62static const u64 sha512_init[] = { 44static u64 sha512_init[] = {
63 SHA512_H7, SHA512_H6, SHA512_H5, SHA512_H4, 45 SHA512_H7, SHA512_H6, SHA512_H5, SHA512_H4,
64 SHA512_H3, SHA512_H2, SHA512_H1, SHA512_H0 }; 46 SHA512_H3, SHA512_H2, SHA512_H1, SHA512_H0 };
65#endif 47#endif
66 48
67static void ssi_hash_create_xcbc_setup( 49static void cc_setup_xcbc(struct ahash_request *areq, struct cc_hw_desc desc[],
68 struct ahash_request *areq, 50 unsigned int *seq_size);
69 struct cc_hw_desc desc[], 51
70 unsigned int *seq_size); 52static void cc_setup_cmac(struct ahash_request *areq, struct cc_hw_desc desc[],
53 unsigned int *seq_size);
71 54
72static void ssi_hash_create_cmac_setup(struct ahash_request *areq, 55static const void *cc_larval_digest(struct device *dev, u32 mode);
73 struct cc_hw_desc desc[],
74 unsigned int *seq_size);
75 56
76struct ssi_hash_alg { 57struct cc_hash_alg {
77 struct list_head entry; 58 struct list_head entry;
78 int hash_mode; 59 int hash_mode;
79 int hw_mode; 60 int hw_mode;
80 int inter_digestsize; 61 int inter_digestsize;
81 struct ssi_drvdata *drvdata; 62 struct cc_drvdata *drvdata;
82 struct ahash_alg ahash_alg; 63 struct ahash_alg ahash_alg;
83}; 64};
84 65
@@ -88,13 +69,13 @@ struct hash_key_req_ctx {
88}; 69};
89 70
90/* hash per-session context */ 71/* hash per-session context */
91struct ssi_hash_ctx { 72struct cc_hash_ctx {
92 struct ssi_drvdata *drvdata; 73 struct cc_drvdata *drvdata;
93 /* holds the origin digest; the digest after "setkey" if HMAC,* 74 /* holds the origin digest; the digest after "setkey" if HMAC,*
94 * the initial digest if HASH. 75 * the initial digest if HASH.
95 */ 76 */
96 u8 digest_buff[SSI_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned; 77 u8 digest_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned;
97 u8 opad_tmp_keys_buff[SSI_MAX_HASH_OPAD_TMP_KEYS_SIZE] ____cacheline_aligned; 78 u8 opad_tmp_keys_buff[CC_MAX_OPAD_KEYS_SIZE] ____cacheline_aligned;
98 79
99 dma_addr_t opad_tmp_keys_dma_addr ____cacheline_aligned; 80 dma_addr_t opad_tmp_keys_dma_addr ____cacheline_aligned;
100 dma_addr_t digest_buff_dma_addr; 81 dma_addr_t digest_buff_dma_addr;
@@ -107,33 +88,27 @@ struct ssi_hash_ctx {
107 bool is_hmac; 88 bool is_hmac;
108}; 89};
109 90
110static void ssi_hash_create_data_desc( 91static void cc_set_desc(struct ahash_req_ctx *areq_ctx, struct cc_hash_ctx *ctx,
111 struct ahash_req_ctx *areq_ctx, 92 unsigned int flow_mode, struct cc_hw_desc desc[],
112 struct ssi_hash_ctx *ctx, 93 bool is_not_last_data, unsigned int *seq_size);
113 unsigned int flow_mode, struct cc_hw_desc desc[],
114 bool is_not_last_data,
115 unsigned int *seq_size);
116 94
117static inline void ssi_set_hash_endianity(u32 mode, struct cc_hw_desc *desc) 95static void cc_set_endianity(u32 mode, struct cc_hw_desc *desc)
118{ 96{
119 if (unlikely((mode == DRV_HASH_MD5) || 97 if (mode == DRV_HASH_MD5 || mode == DRV_HASH_SHA384 ||
120 (mode == DRV_HASH_SHA384) || 98 mode == DRV_HASH_SHA512) {
121 (mode == DRV_HASH_SHA512))) {
122 set_bytes_swap(desc, 1); 99 set_bytes_swap(desc, 1);
123 } else { 100 } else {
124 set_cipher_config0(desc, HASH_DIGEST_RESULT_LITTLE_ENDIAN); 101 set_cipher_config0(desc, HASH_DIGEST_RESULT_LITTLE_ENDIAN);
125 } 102 }
126} 103}
127 104
128static int ssi_hash_map_result(struct device *dev, 105static int cc_map_result(struct device *dev, struct ahash_req_ctx *state,
129 struct ahash_req_ctx *state, 106 unsigned int digestsize)
130 unsigned int digestsize)
131{ 107{
132 state->digest_result_dma_addr = 108 state->digest_result_dma_addr =
133 dma_map_single(dev, (void *)state->digest_result_buff, 109 dma_map_single(dev, state->digest_result_buff,
134 digestsize, 110 digestsize, DMA_BIDIRECTIONAL);
135 DMA_BIDIRECTIONAL); 111 if (dma_mapping_error(dev, state->digest_result_dma_addr)) {
136 if (unlikely(dma_mapping_error(dev, state->digest_result_dma_addr))) {
137 dev_err(dev, "Mapping digest result buffer %u B for DMA failed\n", 112 dev_err(dev, "Mapping digest result buffer %u B for DMA failed\n",
138 digestsize); 113 digestsize);
139 return -ENOMEM; 114 return -ENOMEM;
@@ -145,302 +120,331 @@ static int ssi_hash_map_result(struct device *dev,
145 return 0; 120 return 0;
146} 121}
147 122
148static int ssi_hash_map_request(struct device *dev, 123static void cc_init_req(struct device *dev, struct ahash_req_ctx *state,
149 struct ahash_req_ctx *state, 124 struct cc_hash_ctx *ctx)
150 struct ssi_hash_ctx *ctx)
151{ 125{
152 bool is_hmac = ctx->is_hmac; 126 bool is_hmac = ctx->is_hmac;
153 ssi_sram_addr_t larval_digest_addr = ssi_ahash_get_larval_digest_sram_addr(
154 ctx->drvdata, ctx->hash_mode);
155 struct ssi_crypto_req ssi_req = {};
156 struct cc_hw_desc desc;
157 int rc = -ENOMEM;
158
159 state->buff0 = kzalloc(SSI_MAX_HASH_BLCK_SIZE, GFP_KERNEL | GFP_DMA);
160 if (!state->buff0)
161 goto fail0;
162
163 state->buff1 = kzalloc(SSI_MAX_HASH_BLCK_SIZE, GFP_KERNEL | GFP_DMA);
164 if (!state->buff1)
165 goto fail_buff0;
166
167 state->digest_result_buff = kzalloc(SSI_MAX_HASH_DIGEST_SIZE, GFP_KERNEL | GFP_DMA);
168 if (!state->digest_result_buff)
169 goto fail_buff1;
170
171 state->digest_buff = kzalloc(ctx->inter_digestsize, GFP_KERNEL | GFP_DMA);
172 if (!state->digest_buff)
173 goto fail_digest_result_buff;
174
175 dev_dbg(dev, "Allocated digest-buffer in context ctx->digest_buff=@%p\n",
176 state->digest_buff);
177 if (ctx->hw_mode != DRV_CIPHER_XCBC_MAC) {
178 state->digest_bytes_len = kzalloc(HASH_LEN_SIZE, GFP_KERNEL | GFP_DMA);
179 if (!state->digest_bytes_len)
180 goto fail1;
181 127
182 dev_dbg(dev, "Allocated digest-bytes-len in context state->>digest_bytes_len=@%p\n", 128 memset(state, 0, sizeof(*state));
183 state->digest_bytes_len);
184 } else {
185 state->digest_bytes_len = NULL;
186 }
187
188 state->opad_digest_buff = kzalloc(ctx->inter_digestsize, GFP_KERNEL | GFP_DMA);
189 if (!state->opad_digest_buff)
190 goto fail2;
191
192 dev_dbg(dev, "Allocated opad-digest-buffer in context state->digest_bytes_len=@%p\n",
193 state->opad_digest_buff);
194
195 state->digest_buff_dma_addr = dma_map_single(dev, (void *)state->digest_buff, ctx->inter_digestsize, DMA_BIDIRECTIONAL);
196 if (dma_mapping_error(dev, state->digest_buff_dma_addr)) {
197 dev_err(dev, "Mapping digest len %d B at va=%pK for DMA failed\n",
198 ctx->inter_digestsize, state->digest_buff);
199 goto fail3;
200 }
201 dev_dbg(dev, "Mapped digest %d B at va=%pK to dma=%pad\n",
202 ctx->inter_digestsize, state->digest_buff,
203 &state->digest_buff_dma_addr);
204 129
205 if (is_hmac) { 130 if (is_hmac) {
206 dma_sync_single_for_cpu(dev, ctx->digest_buff_dma_addr, ctx->inter_digestsize, DMA_BIDIRECTIONAL); 131 if (ctx->hw_mode != DRV_CIPHER_XCBC_MAC &&
207 if ((ctx->hw_mode == DRV_CIPHER_XCBC_MAC) || (ctx->hw_mode == DRV_CIPHER_CMAC)) { 132 ctx->hw_mode != DRV_CIPHER_CMAC) {
208 memset(state->digest_buff, 0, ctx->inter_digestsize); 133 dma_sync_single_for_cpu(dev, ctx->digest_buff_dma_addr,
209 } else { /*sha*/ 134 ctx->inter_digestsize,
210 memcpy(state->digest_buff, ctx->digest_buff, ctx->inter_digestsize); 135 DMA_BIDIRECTIONAL);
211#if (DX_DEV_SHA_MAX > 256) 136
212 if (unlikely((ctx->hash_mode == DRV_HASH_SHA512) || (ctx->hash_mode == DRV_HASH_SHA384))) 137 memcpy(state->digest_buff, ctx->digest_buff,
213 memcpy(state->digest_bytes_len, digest_len_sha512_init, HASH_LEN_SIZE); 138 ctx->inter_digestsize);
139#if (CC_DEV_SHA_MAX > 256)
140 if (ctx->hash_mode == DRV_HASH_SHA512 ||
141 ctx->hash_mode == DRV_HASH_SHA384)
142 memcpy(state->digest_bytes_len,
143 digest_len_sha512_init, HASH_LEN_SIZE);
214 else 144 else
215 memcpy(state->digest_bytes_len, digest_len_init, HASH_LEN_SIZE); 145 memcpy(state->digest_bytes_len,
146 digest_len_init, HASH_LEN_SIZE);
216#else 147#else
217 memcpy(state->digest_bytes_len, digest_len_init, HASH_LEN_SIZE); 148 memcpy(state->digest_bytes_len, digest_len_init,
149 HASH_LEN_SIZE);
218#endif 150#endif
219 } 151 }
220 dma_sync_single_for_device(dev, state->digest_buff_dma_addr, ctx->inter_digestsize, DMA_BIDIRECTIONAL);
221 152
222 if (ctx->hash_mode != DRV_HASH_NULL) { 153 if (ctx->hash_mode != DRV_HASH_NULL) {
223 dma_sync_single_for_cpu(dev, ctx->opad_tmp_keys_dma_addr, ctx->inter_digestsize, DMA_BIDIRECTIONAL); 154 dma_sync_single_for_cpu(dev,
224 memcpy(state->opad_digest_buff, ctx->opad_tmp_keys_buff, ctx->inter_digestsize); 155 ctx->opad_tmp_keys_dma_addr,
156 ctx->inter_digestsize,
157 DMA_BIDIRECTIONAL);
158 memcpy(state->opad_digest_buff,
159 ctx->opad_tmp_keys_buff, ctx->inter_digestsize);
225 } 160 }
226 } else { /*hash*/ 161 } else { /*hash*/
227 /* Copy the initial digests if hash flow. The SRAM contains the 162 /* Copy the initial digests if hash flow. */
228 * initial digests in the expected order for all SHA* 163 const void *larval = cc_larval_digest(dev, ctx->hash_mode);
229 */ 164
230 hw_desc_init(&desc); 165 memcpy(state->digest_buff, larval, ctx->inter_digestsize);
231 set_din_sram(&desc, larval_digest_addr, ctx->inter_digestsize); 166 }
232 set_dout_dlli(&desc, state->digest_buff_dma_addr, 167}
233 ctx->inter_digestsize, NS_BIT, 0); 168
234 set_flow_mode(&desc, BYPASS); 169static int cc_map_req(struct device *dev, struct ahash_req_ctx *state,
235 170 struct cc_hash_ctx *ctx)
236 rc = send_request(ctx->drvdata, &ssi_req, &desc, 1, 0); 171{
237 if (unlikely(rc != 0)) { 172 bool is_hmac = ctx->is_hmac;
238 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 173
239 goto fail4; 174 state->digest_buff_dma_addr =
240 } 175 dma_map_single(dev, state->digest_buff,
176 ctx->inter_digestsize, DMA_BIDIRECTIONAL);
177 if (dma_mapping_error(dev, state->digest_buff_dma_addr)) {
178 dev_err(dev, "Mapping digest len %d B at va=%pK for DMA failed\n",
179 ctx->inter_digestsize, state->digest_buff);
180 return -EINVAL;
241 } 181 }
182 dev_dbg(dev, "Mapped digest %d B at va=%pK to dma=%pad\n",
183 ctx->inter_digestsize, state->digest_buff,
184 &state->digest_buff_dma_addr);
242 185
243 if (ctx->hw_mode != DRV_CIPHER_XCBC_MAC) { 186 if (ctx->hw_mode != DRV_CIPHER_XCBC_MAC) {
244 state->digest_bytes_len_dma_addr = dma_map_single(dev, (void *)state->digest_bytes_len, HASH_LEN_SIZE, DMA_BIDIRECTIONAL); 187 state->digest_bytes_len_dma_addr =
188 dma_map_single(dev, state->digest_bytes_len,
189 HASH_LEN_SIZE, DMA_BIDIRECTIONAL);
245 if (dma_mapping_error(dev, state->digest_bytes_len_dma_addr)) { 190 if (dma_mapping_error(dev, state->digest_bytes_len_dma_addr)) {
246 dev_err(dev, "Mapping digest len %u B at va=%pK for DMA failed\n", 191 dev_err(dev, "Mapping digest len %u B at va=%pK for DMA failed\n",
247 HASH_LEN_SIZE, state->digest_bytes_len); 192 HASH_LEN_SIZE, state->digest_bytes_len);
248 goto fail4; 193 goto unmap_digest_buf;
249 } 194 }
250 dev_dbg(dev, "Mapped digest len %u B at va=%pK to dma=%pad\n", 195 dev_dbg(dev, "Mapped digest len %u B at va=%pK to dma=%pad\n",
251 HASH_LEN_SIZE, state->digest_bytes_len, 196 HASH_LEN_SIZE, state->digest_bytes_len,
252 &state->digest_bytes_len_dma_addr); 197 &state->digest_bytes_len_dma_addr);
253 } else {
254 state->digest_bytes_len_dma_addr = 0;
255 } 198 }
256 199
257 if (is_hmac && ctx->hash_mode != DRV_HASH_NULL) { 200 if (is_hmac && ctx->hash_mode != DRV_HASH_NULL) {
258 state->opad_digest_dma_addr = dma_map_single(dev, (void *)state->opad_digest_buff, ctx->inter_digestsize, DMA_BIDIRECTIONAL); 201 state->opad_digest_dma_addr =
202 dma_map_single(dev, state->opad_digest_buff,
203 ctx->inter_digestsize,
204 DMA_BIDIRECTIONAL);
259 if (dma_mapping_error(dev, state->opad_digest_dma_addr)) { 205 if (dma_mapping_error(dev, state->opad_digest_dma_addr)) {
260 dev_err(dev, "Mapping opad digest %d B at va=%pK for DMA failed\n", 206 dev_err(dev, "Mapping opad digest %d B at va=%pK for DMA failed\n",
261 ctx->inter_digestsize, 207 ctx->inter_digestsize,
262 state->opad_digest_buff); 208 state->opad_digest_buff);
263 goto fail5; 209 goto unmap_digest_len;
264 } 210 }
265 dev_dbg(dev, "Mapped opad digest %d B at va=%pK to dma=%pad\n", 211 dev_dbg(dev, "Mapped opad digest %d B at va=%pK to dma=%pad\n",
266 ctx->inter_digestsize, state->opad_digest_buff, 212 ctx->inter_digestsize, state->opad_digest_buff,
267 &state->opad_digest_dma_addr); 213 &state->opad_digest_dma_addr);
268 } else {
269 state->opad_digest_dma_addr = 0;
270 } 214 }
271 state->buff0_cnt = 0;
272 state->buff1_cnt = 0;
273 state->buff_index = 0;
274 state->mlli_params.curr_pool = NULL;
275 215
276 return 0; 216 return 0;
277 217
278fail5: 218unmap_digest_len:
279 if (state->digest_bytes_len_dma_addr != 0) { 219 if (state->digest_bytes_len_dma_addr) {
280 dma_unmap_single(dev, state->digest_bytes_len_dma_addr, HASH_LEN_SIZE, DMA_BIDIRECTIONAL); 220 dma_unmap_single(dev, state->digest_bytes_len_dma_addr,
221 HASH_LEN_SIZE, DMA_BIDIRECTIONAL);
281 state->digest_bytes_len_dma_addr = 0; 222 state->digest_bytes_len_dma_addr = 0;
282 } 223 }
283fail4: 224unmap_digest_buf:
284 if (state->digest_buff_dma_addr != 0) { 225 if (state->digest_buff_dma_addr) {
285 dma_unmap_single(dev, state->digest_buff_dma_addr, ctx->inter_digestsize, DMA_BIDIRECTIONAL); 226 dma_unmap_single(dev, state->digest_buff_dma_addr,
227 ctx->inter_digestsize, DMA_BIDIRECTIONAL);
286 state->digest_buff_dma_addr = 0; 228 state->digest_buff_dma_addr = 0;
287 } 229 }
288fail3: 230
289 kfree(state->opad_digest_buff); 231 return -EINVAL;
290fail2:
291 kfree(state->digest_bytes_len);
292fail1:
293 kfree(state->digest_buff);
294fail_digest_result_buff:
295 kfree(state->digest_result_buff);
296 state->digest_result_buff = NULL;
297fail_buff1:
298 kfree(state->buff1);
299 state->buff1 = NULL;
300fail_buff0:
301 kfree(state->buff0);
302 state->buff0 = NULL;
303fail0:
304 return rc;
305} 232}
306 233
307static void ssi_hash_unmap_request(struct device *dev, 234static void cc_unmap_req(struct device *dev, struct ahash_req_ctx *state,
308 struct ahash_req_ctx *state, 235 struct cc_hash_ctx *ctx)
309 struct ssi_hash_ctx *ctx)
310{ 236{
311 if (state->digest_buff_dma_addr != 0) { 237 if (state->digest_buff_dma_addr) {
312 dma_unmap_single(dev, state->digest_buff_dma_addr, 238 dma_unmap_single(dev, state->digest_buff_dma_addr,
313 ctx->inter_digestsize, DMA_BIDIRECTIONAL); 239 ctx->inter_digestsize, DMA_BIDIRECTIONAL);
314 dev_dbg(dev, "Unmapped digest-buffer: digest_buff_dma_addr=%pad\n", 240 dev_dbg(dev, "Unmapped digest-buffer: digest_buff_dma_addr=%pad\n",
315 &state->digest_buff_dma_addr); 241 &state->digest_buff_dma_addr);
316 state->digest_buff_dma_addr = 0; 242 state->digest_buff_dma_addr = 0;
317 } 243 }
318 if (state->digest_bytes_len_dma_addr != 0) { 244 if (state->digest_bytes_len_dma_addr) {
319 dma_unmap_single(dev, state->digest_bytes_len_dma_addr, 245 dma_unmap_single(dev, state->digest_bytes_len_dma_addr,
320 HASH_LEN_SIZE, DMA_BIDIRECTIONAL); 246 HASH_LEN_SIZE, DMA_BIDIRECTIONAL);
321 dev_dbg(dev, "Unmapped digest-bytes-len buffer: digest_bytes_len_dma_addr=%pad\n", 247 dev_dbg(dev, "Unmapped digest-bytes-len buffer: digest_bytes_len_dma_addr=%pad\n",
322 &state->digest_bytes_len_dma_addr); 248 &state->digest_bytes_len_dma_addr);
323 state->digest_bytes_len_dma_addr = 0; 249 state->digest_bytes_len_dma_addr = 0;
324 } 250 }
325 if (state->opad_digest_dma_addr != 0) { 251 if (state->opad_digest_dma_addr) {
326 dma_unmap_single(dev, state->opad_digest_dma_addr, 252 dma_unmap_single(dev, state->opad_digest_dma_addr,
327 ctx->inter_digestsize, DMA_BIDIRECTIONAL); 253 ctx->inter_digestsize, DMA_BIDIRECTIONAL);
328 dev_dbg(dev, "Unmapped opad-digest: opad_digest_dma_addr=%pad\n", 254 dev_dbg(dev, "Unmapped opad-digest: opad_digest_dma_addr=%pad\n",
329 &state->opad_digest_dma_addr); 255 &state->opad_digest_dma_addr);
330 state->opad_digest_dma_addr = 0; 256 state->opad_digest_dma_addr = 0;
331 } 257 }
332
333 kfree(state->opad_digest_buff);
334 kfree(state->digest_bytes_len);
335 kfree(state->digest_buff);
336 kfree(state->digest_result_buff);
337 kfree(state->buff1);
338 kfree(state->buff0);
339} 258}
340 259
341static void ssi_hash_unmap_result(struct device *dev, 260static void cc_unmap_result(struct device *dev, struct ahash_req_ctx *state,
342 struct ahash_req_ctx *state, 261 unsigned int digestsize, u8 *result)
343 unsigned int digestsize, u8 *result)
344{ 262{
345 if (state->digest_result_dma_addr != 0) { 263 if (state->digest_result_dma_addr) {
346 dma_unmap_single(dev, 264 dma_unmap_single(dev, state->digest_result_dma_addr, digestsize,
347 state->digest_result_dma_addr, 265 DMA_BIDIRECTIONAL);
348 digestsize,
349 DMA_BIDIRECTIONAL);
350 dev_dbg(dev, "unmpa digest result buffer va (%pK) pa (%pad) len %u\n", 266 dev_dbg(dev, "unmpa digest result buffer va (%pK) pa (%pad) len %u\n",
351 state->digest_result_buff, 267 state->digest_result_buff,
352 &state->digest_result_dma_addr, digestsize); 268 &state->digest_result_dma_addr, digestsize);
353 memcpy(result, 269 memcpy(result, state->digest_result_buff, digestsize);
354 state->digest_result_buff,
355 digestsize);
356 } 270 }
357 state->digest_result_dma_addr = 0; 271 state->digest_result_dma_addr = 0;
358} 272}
359 273
360static void ssi_hash_update_complete(struct device *dev, void *ssi_req, void __iomem *cc_base) 274static void cc_update_complete(struct device *dev, void *cc_req, int err)
361{ 275{
362 struct ahash_request *req = (struct ahash_request *)ssi_req; 276 struct ahash_request *req = (struct ahash_request *)cc_req;
363 struct ahash_req_ctx *state = ahash_request_ctx(req); 277 struct ahash_req_ctx *state = ahash_request_ctx(req);
278 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
279 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
364 280
365 dev_dbg(dev, "req=%pK\n", req); 281 dev_dbg(dev, "req=%pK\n", req);
366 282
367 ssi_buffer_mgr_unmap_hash_request(dev, state, req->src, false); 283 cc_unmap_hash_request(dev, state, req->src, false);
368 req->base.complete(&req->base, 0); 284 cc_unmap_req(dev, state, ctx);
285 req->base.complete(&req->base, err);
369} 286}
370 287
371static void ssi_hash_digest_complete(struct device *dev, void *ssi_req, void __iomem *cc_base) 288static void cc_digest_complete(struct device *dev, void *cc_req, int err)
372{ 289{
373 struct ahash_request *req = (struct ahash_request *)ssi_req; 290 struct ahash_request *req = (struct ahash_request *)cc_req;
374 struct ahash_req_ctx *state = ahash_request_ctx(req); 291 struct ahash_req_ctx *state = ahash_request_ctx(req);
375 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 292 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
376 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm); 293 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
377 u32 digestsize = crypto_ahash_digestsize(tfm); 294 u32 digestsize = crypto_ahash_digestsize(tfm);
378 295
379 dev_dbg(dev, "req=%pK\n", req); 296 dev_dbg(dev, "req=%pK\n", req);
380 297
381 ssi_buffer_mgr_unmap_hash_request(dev, state, req->src, false); 298 cc_unmap_hash_request(dev, state, req->src, false);
382 ssi_hash_unmap_result(dev, state, digestsize, req->result); 299 cc_unmap_result(dev, state, digestsize, req->result);
383 ssi_hash_unmap_request(dev, state, ctx); 300 cc_unmap_req(dev, state, ctx);
384 req->base.complete(&req->base, 0); 301 req->base.complete(&req->base, err);
385} 302}
386 303
387static void ssi_hash_complete(struct device *dev, void *ssi_req, void __iomem *cc_base) 304static void cc_hash_complete(struct device *dev, void *cc_req, int err)
388{ 305{
389 struct ahash_request *req = (struct ahash_request *)ssi_req; 306 struct ahash_request *req = (struct ahash_request *)cc_req;
390 struct ahash_req_ctx *state = ahash_request_ctx(req); 307 struct ahash_req_ctx *state = ahash_request_ctx(req);
391 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 308 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
392 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm); 309 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
393 u32 digestsize = crypto_ahash_digestsize(tfm); 310 u32 digestsize = crypto_ahash_digestsize(tfm);
394 311
395 dev_dbg(dev, "req=%pK\n", req); 312 dev_dbg(dev, "req=%pK\n", req);
396 313
397 ssi_buffer_mgr_unmap_hash_request(dev, state, req->src, false); 314 cc_unmap_hash_request(dev, state, req->src, false);
398 ssi_hash_unmap_result(dev, state, digestsize, req->result); 315 cc_unmap_result(dev, state, digestsize, req->result);
399 ssi_hash_unmap_request(dev, state, ctx); 316 cc_unmap_req(dev, state, ctx);
400 req->base.complete(&req->base, 0); 317 req->base.complete(&req->base, err);
318}
319
320static int cc_fin_result(struct cc_hw_desc *desc, struct ahash_request *req,
321 int idx)
322{
323 struct ahash_req_ctx *state = ahash_request_ctx(req);
324 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
325 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
326 u32 digestsize = crypto_ahash_digestsize(tfm);
327
328 /* Get final MAC result */
329 hw_desc_init(&desc[idx]);
330 set_cipher_mode(&desc[idx], ctx->hw_mode);
331 /* TODO */
332 set_dout_dlli(&desc[idx], state->digest_result_dma_addr, digestsize,
333 NS_BIT, 1);
334 set_queue_last_ind(&desc[idx]);
335 set_flow_mode(&desc[idx], S_HASH_to_DOUT);
336 set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
337 set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED);
338 cc_set_endianity(ctx->hash_mode, &desc[idx]);
339 idx++;
340
341 return idx;
342}
343
344static int cc_fin_hmac(struct cc_hw_desc *desc, struct ahash_request *req,
345 int idx)
346{
347 struct ahash_req_ctx *state = ahash_request_ctx(req);
348 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
349 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
350 u32 digestsize = crypto_ahash_digestsize(tfm);
351
352 /* store the hash digest result in the context */
353 hw_desc_init(&desc[idx]);
354 set_cipher_mode(&desc[idx], ctx->hw_mode);
355 set_dout_dlli(&desc[idx], state->digest_buff_dma_addr, digestsize,
356 NS_BIT, 0);
357 set_flow_mode(&desc[idx], S_HASH_to_DOUT);
358 cc_set_endianity(ctx->hash_mode, &desc[idx]);
359 set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
360 idx++;
361
362 /* Loading hash opad xor key state */
363 hw_desc_init(&desc[idx]);
364 set_cipher_mode(&desc[idx], ctx->hw_mode);
365 set_din_type(&desc[idx], DMA_DLLI, state->opad_digest_dma_addr,
366 ctx->inter_digestsize, NS_BIT);
367 set_flow_mode(&desc[idx], S_DIN_to_HASH);
368 set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
369 idx++;
370
371 /* Load the hash current length */
372 hw_desc_init(&desc[idx]);
373 set_cipher_mode(&desc[idx], ctx->hw_mode);
374 set_din_sram(&desc[idx],
375 cc_digest_len_addr(ctx->drvdata, ctx->hash_mode),
376 HASH_LEN_SIZE);
377 set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED);
378 set_flow_mode(&desc[idx], S_DIN_to_HASH);
379 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
380 idx++;
381
382 /* Memory Barrier: wait for IPAD/OPAD axi write to complete */
383 hw_desc_init(&desc[idx]);
384 set_din_no_dma(&desc[idx], 0, 0xfffff0);
385 set_dout_no_dma(&desc[idx], 0, 0, 1);
386 idx++;
387
388 /* Perform HASH update */
389 hw_desc_init(&desc[idx]);
390 set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
391 digestsize, NS_BIT);
392 set_flow_mode(&desc[idx], DIN_HASH);
393 idx++;
394
395 return idx;
401} 396}
402 397
403static int ssi_hash_digest(struct ahash_req_ctx *state, 398static int cc_hash_digest(struct ahash_request *req)
404 struct ssi_hash_ctx *ctx,
405 unsigned int digestsize,
406 struct scatterlist *src,
407 unsigned int nbytes, u8 *result,
408 void *async_req)
409{ 399{
400 struct ahash_req_ctx *state = ahash_request_ctx(req);
401 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
402 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
403 u32 digestsize = crypto_ahash_digestsize(tfm);
404 struct scatterlist *src = req->src;
405 unsigned int nbytes = req->nbytes;
406 u8 *result = req->result;
410 struct device *dev = drvdata_to_dev(ctx->drvdata); 407 struct device *dev = drvdata_to_dev(ctx->drvdata);
411 bool is_hmac = ctx->is_hmac; 408 bool is_hmac = ctx->is_hmac;
412 struct ssi_crypto_req ssi_req = {}; 409 struct cc_crypto_req cc_req = {};
413 struct cc_hw_desc desc[SSI_MAX_AHASH_SEQ_LEN]; 410 struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
414 ssi_sram_addr_t larval_digest_addr = ssi_ahash_get_larval_digest_sram_addr( 411 cc_sram_addr_t larval_digest_addr =
415 ctx->drvdata, ctx->hash_mode); 412 cc_larval_digest_addr(ctx->drvdata, ctx->hash_mode);
416 int idx = 0; 413 int idx = 0;
417 int rc = 0; 414 int rc = 0;
415 gfp_t flags = cc_gfp_flags(&req->base);
418 416
419 dev_dbg(dev, "===== %s-digest (%d) ====\n", is_hmac ? "hmac" : "hash", 417 dev_dbg(dev, "===== %s-digest (%d) ====\n", is_hmac ? "hmac" : "hash",
420 nbytes); 418 nbytes);
421 419
422 if (unlikely(ssi_hash_map_request(dev, state, ctx) != 0)) { 420 cc_init_req(dev, state, ctx);
421
422 if (cc_map_req(dev, state, ctx)) {
423 dev_err(dev, "map_ahash_source() failed\n"); 423 dev_err(dev, "map_ahash_source() failed\n");
424 return -ENOMEM; 424 return -ENOMEM;
425 } 425 }
426 426
427 if (unlikely(ssi_hash_map_result(dev, state, digestsize) != 0)) { 427 if (cc_map_result(dev, state, digestsize)) {
428 dev_err(dev, "map_ahash_digest() failed\n"); 428 dev_err(dev, "map_ahash_digest() failed\n");
429 cc_unmap_req(dev, state, ctx);
429 return -ENOMEM; 430 return -ENOMEM;
430 } 431 }
431 432
432 if (unlikely(ssi_buffer_mgr_map_hash_request_final(ctx->drvdata, state, src, nbytes, 1) != 0)) { 433 if (cc_map_hash_request_final(ctx->drvdata, state, src, nbytes, 1,
434 flags)) {
433 dev_err(dev, "map_ahash_request_final() failed\n"); 435 dev_err(dev, "map_ahash_request_final() failed\n");
436 cc_unmap_result(dev, state, digestsize, result);
437 cc_unmap_req(dev, state, ctx);
434 return -ENOMEM; 438 return -ENOMEM;
435 } 439 }
436 440
437 if (async_req) { 441 /* Setup DX request structure */
438 /* Setup DX request structure */ 442 cc_req.user_cb = cc_digest_complete;
439 ssi_req.user_cb = (void *)ssi_hash_digest_complete; 443 cc_req.user_arg = req;
440 ssi_req.user_arg = (void *)async_req;
441 }
442 444
443 /* If HMAC then load hash IPAD xor key, if HASH then load initial digest */ 445 /* If HMAC then load hash IPAD xor key, if HASH then load initial
446 * digest
447 */
444 hw_desc_init(&desc[idx]); 448 hw_desc_init(&desc[idx]);
445 set_cipher_mode(&desc[idx], ctx->hw_mode); 449 set_cipher_mode(&desc[idx], ctx->hw_mode);
446 if (is_hmac) { 450 if (is_hmac) {
@@ -464,7 +468,7 @@ static int ssi_hash_digest(struct ahash_req_ctx *state,
464 NS_BIT); 468 NS_BIT);
465 } else { 469 } else {
466 set_din_const(&desc[idx], 0, HASH_LEN_SIZE); 470 set_din_const(&desc[idx], 0, HASH_LEN_SIZE);
467 if (likely(nbytes != 0)) 471 if (nbytes)
468 set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED); 472 set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED);
469 else 473 else
470 set_cipher_do(&desc[idx], DO_PAD); 474 set_cipher_do(&desc[idx], DO_PAD);
@@ -473,7 +477,7 @@ static int ssi_hash_digest(struct ahash_req_ctx *state,
473 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0); 477 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
474 idx++; 478 idx++;
475 479
476 ssi_hash_create_data_desc(state, ctx, DIN_HASH, desc, false, &idx); 480 cc_set_desc(state, ctx, DIN_HASH, desc, false, &idx);
477 481
478 if (is_hmac) { 482 if (is_hmac) {
479 /* HW last hash block padding (aka. "DO_PAD") */ 483 /* HW last hash block padding (aka. "DO_PAD") */
@@ -486,98 +490,62 @@ static int ssi_hash_digest(struct ahash_req_ctx *state,
486 set_cipher_do(&desc[idx], DO_PAD); 490 set_cipher_do(&desc[idx], DO_PAD);
487 idx++; 491 idx++;
488 492
489 /* store the hash digest result in the context */ 493 idx = cc_fin_hmac(desc, req, idx);
490 hw_desc_init(&desc[idx]); 494 }
491 set_cipher_mode(&desc[idx], ctx->hw_mode);
492 set_dout_dlli(&desc[idx], state->digest_buff_dma_addr,
493 digestsize, NS_BIT, 0);
494 set_flow_mode(&desc[idx], S_HASH_to_DOUT);
495 ssi_set_hash_endianity(ctx->hash_mode, &desc[idx]);
496 set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
497 idx++;
498
499 /* Loading hash opad xor key state */
500 hw_desc_init(&desc[idx]);
501 set_cipher_mode(&desc[idx], ctx->hw_mode);
502 set_din_type(&desc[idx], DMA_DLLI, state->opad_digest_dma_addr,
503 ctx->inter_digestsize, NS_BIT);
504 set_flow_mode(&desc[idx], S_DIN_to_HASH);
505 set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
506 idx++;
507
508 /* Load the hash current length */
509 hw_desc_init(&desc[idx]);
510 set_cipher_mode(&desc[idx], ctx->hw_mode);
511 set_din_sram(&desc[idx],
512 ssi_ahash_get_initial_digest_len_sram_addr(
513ctx->drvdata, ctx->hash_mode), HASH_LEN_SIZE);
514 set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED);
515 set_flow_mode(&desc[idx], S_DIN_to_HASH);
516 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
517 idx++;
518 495
519 /* Memory Barrier: wait for IPAD/OPAD axi write to complete */ 496 idx = cc_fin_result(desc, req, idx);
520 hw_desc_init(&desc[idx]);
521 set_din_no_dma(&desc[idx], 0, 0xfffff0);
522 set_dout_no_dma(&desc[idx], 0, 0, 1);
523 idx++;
524 497
525 /* Perform HASH update */ 498 rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
526 hw_desc_init(&desc[idx]); 499 if (rc != -EINPROGRESS && rc != -EBUSY) {
527 set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr, 500 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
528 digestsize, NS_BIT); 501 cc_unmap_hash_request(dev, state, src, true);
529 set_flow_mode(&desc[idx], DIN_HASH); 502 cc_unmap_result(dev, state, digestsize, result);
530 idx++; 503 cc_unmap_req(dev, state, ctx);
531 } 504 }
505 return rc;
506}
532 507
533 /* Get final MAC result */ 508static int cc_restore_hash(struct cc_hw_desc *desc, struct cc_hash_ctx *ctx,
509 struct ahash_req_ctx *state, int idx)
510{
511 /* Restore hash digest */
512 hw_desc_init(&desc[idx]);
513 set_cipher_mode(&desc[idx], ctx->hw_mode);
514 set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
515 ctx->inter_digestsize, NS_BIT);
516 set_flow_mode(&desc[idx], S_DIN_to_HASH);
517 set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
518 idx++;
519
520 /* Restore hash current length */
534 hw_desc_init(&desc[idx]); 521 hw_desc_init(&desc[idx]);
535 set_cipher_mode(&desc[idx], ctx->hw_mode); 522 set_cipher_mode(&desc[idx], ctx->hw_mode);
536 /* TODO */
537 set_dout_dlli(&desc[idx], state->digest_result_dma_addr, digestsize,
538 NS_BIT, (async_req ? 1 : 0));
539 if (async_req)
540 set_queue_last_ind(&desc[idx]);
541 set_flow_mode(&desc[idx], S_HASH_to_DOUT);
542 set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
543 set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED); 523 set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED);
544 ssi_set_hash_endianity(ctx->hash_mode, &desc[idx]); 524 set_din_type(&desc[idx], DMA_DLLI, state->digest_bytes_len_dma_addr,
525 HASH_LEN_SIZE, NS_BIT);
526 set_flow_mode(&desc[idx], S_DIN_to_HASH);
527 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
545 idx++; 528 idx++;
546 529
547 if (async_req) { 530 cc_set_desc(state, ctx, DIN_HASH, desc, false, &idx);
548 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 1); 531
549 if (unlikely(rc != -EINPROGRESS)) { 532 return idx;
550 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
551 ssi_buffer_mgr_unmap_hash_request(dev, state, src, true);
552 ssi_hash_unmap_result(dev, state, digestsize, result);
553 ssi_hash_unmap_request(dev, state, ctx);
554 }
555 } else {
556 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0);
557 if (rc != 0) {
558 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
559 ssi_buffer_mgr_unmap_hash_request(dev, state, src, true);
560 } else {
561 ssi_buffer_mgr_unmap_hash_request(dev, state, src, false);
562 }
563 ssi_hash_unmap_result(dev, state, digestsize, result);
564 ssi_hash_unmap_request(dev, state, ctx);
565 }
566 return rc;
567} 533}
568 534
569static int ssi_hash_update(struct ahash_req_ctx *state, 535static int cc_hash_update(struct ahash_request *req)
570 struct ssi_hash_ctx *ctx,
571 unsigned int block_size,
572 struct scatterlist *src,
573 unsigned int nbytes,
574 void *async_req)
575{ 536{
537 struct ahash_req_ctx *state = ahash_request_ctx(req);
538 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
539 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
540 unsigned int block_size = crypto_tfm_alg_blocksize(&tfm->base);
541 struct scatterlist *src = req->src;
542 unsigned int nbytes = req->nbytes;
576 struct device *dev = drvdata_to_dev(ctx->drvdata); 543 struct device *dev = drvdata_to_dev(ctx->drvdata);
577 struct ssi_crypto_req ssi_req = {}; 544 struct cc_crypto_req cc_req = {};
578 struct cc_hw_desc desc[SSI_MAX_AHASH_SEQ_LEN]; 545 struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
579 u32 idx = 0; 546 u32 idx = 0;
580 int rc; 547 int rc;
548 gfp_t flags = cc_gfp_flags(&req->base);
581 549
582 dev_dbg(dev, "===== %s-update (%d) ====\n", ctx->is_hmac ? 550 dev_dbg(dev, "===== %s-update (%d) ====\n", ctx->is_hmac ?
583 "hmac" : "hash", nbytes); 551 "hmac" : "hash", nbytes);
@@ -587,8 +555,9 @@ static int ssi_hash_update(struct ahash_req_ctx *state,
587 return 0; 555 return 0;
588 } 556 }
589 557
590 rc = ssi_buffer_mgr_map_hash_request_update(ctx->drvdata, state, src, nbytes, block_size); 558 rc = cc_map_hash_request_update(ctx->drvdata, state, src, nbytes,
591 if (unlikely(rc)) { 559 block_size, flags);
560 if (rc) {
592 if (rc == 1) { 561 if (rc == 1) {
593 dev_dbg(dev, " data size not require HW update %x\n", 562 dev_dbg(dev, " data size not require HW update %x\n",
594 nbytes); 563 nbytes);
@@ -599,30 +568,17 @@ static int ssi_hash_update(struct ahash_req_ctx *state,
599 return -ENOMEM; 568 return -ENOMEM;
600 } 569 }
601 570
602 if (async_req) { 571 if (cc_map_req(dev, state, ctx)) {
603 /* Setup DX request structure */ 572 dev_err(dev, "map_ahash_source() failed\n");
604 ssi_req.user_cb = (void *)ssi_hash_update_complete; 573 cc_unmap_hash_request(dev, state, src, true);
605 ssi_req.user_arg = async_req; 574 return -EINVAL;
606 } 575 }
607 576
608 /* Restore hash digest */ 577 /* Setup DX request structure */
609 hw_desc_init(&desc[idx]); 578 cc_req.user_cb = cc_update_complete;
610 set_cipher_mode(&desc[idx], ctx->hw_mode); 579 cc_req.user_arg = req;
611 set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
612 ctx->inter_digestsize, NS_BIT);
613 set_flow_mode(&desc[idx], S_DIN_to_HASH);
614 set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
615 idx++;
616 /* Restore hash current length */
617 hw_desc_init(&desc[idx]);
618 set_cipher_mode(&desc[idx], ctx->hw_mode);
619 set_din_type(&desc[idx], DMA_DLLI, state->digest_bytes_len_dma_addr,
620 HASH_LEN_SIZE, NS_BIT);
621 set_flow_mode(&desc[idx], S_DIN_to_HASH);
622 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
623 idx++;
624 580
625 ssi_hash_create_data_desc(state, ctx, DIN_HASH, desc, false, &idx); 581 idx = cc_restore_hash(desc, ctx, state, idx);
626 582
627 /* store the hash digest result in context */ 583 /* store the hash digest result in context */
628 hw_desc_init(&desc[idx]); 584 hw_desc_init(&desc[idx]);
@@ -637,220 +593,124 @@ static int ssi_hash_update(struct ahash_req_ctx *state,
637 hw_desc_init(&desc[idx]); 593 hw_desc_init(&desc[idx]);
638 set_cipher_mode(&desc[idx], ctx->hw_mode); 594 set_cipher_mode(&desc[idx], ctx->hw_mode);
639 set_dout_dlli(&desc[idx], state->digest_bytes_len_dma_addr, 595 set_dout_dlli(&desc[idx], state->digest_bytes_len_dma_addr,
640 HASH_LEN_SIZE, NS_BIT, (async_req ? 1 : 0)); 596 HASH_LEN_SIZE, NS_BIT, 1);
641 if (async_req) 597 set_queue_last_ind(&desc[idx]);
642 set_queue_last_ind(&desc[idx]);
643 set_flow_mode(&desc[idx], S_HASH_to_DOUT); 598 set_flow_mode(&desc[idx], S_HASH_to_DOUT);
644 set_setup_mode(&desc[idx], SETUP_WRITE_STATE1); 599 set_setup_mode(&desc[idx], SETUP_WRITE_STATE1);
645 idx++; 600 idx++;
646 601
647 if (async_req) { 602 rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
648 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 1); 603 if (rc != -EINPROGRESS && rc != -EBUSY) {
649 if (unlikely(rc != -EINPROGRESS)) { 604 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
650 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 605 cc_unmap_hash_request(dev, state, src, true);
651 ssi_buffer_mgr_unmap_hash_request(dev, state, src, true); 606 cc_unmap_req(dev, state, ctx);
652 }
653 } else {
654 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0);
655 if (rc != 0) {
656 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
657 ssi_buffer_mgr_unmap_hash_request(dev, state, src, true);
658 } else {
659 ssi_buffer_mgr_unmap_hash_request(dev, state, src, false);
660 }
661 } 607 }
662 return rc; 608 return rc;
663} 609}
664 610
665static int ssi_hash_finup(struct ahash_req_ctx *state, 611static int cc_hash_finup(struct ahash_request *req)
666 struct ssi_hash_ctx *ctx,
667 unsigned int digestsize,
668 struct scatterlist *src,
669 unsigned int nbytes,
670 u8 *result,
671 void *async_req)
672{ 612{
613 struct ahash_req_ctx *state = ahash_request_ctx(req);
614 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
615 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
616 u32 digestsize = crypto_ahash_digestsize(tfm);
617 struct scatterlist *src = req->src;
618 unsigned int nbytes = req->nbytes;
619 u8 *result = req->result;
673 struct device *dev = drvdata_to_dev(ctx->drvdata); 620 struct device *dev = drvdata_to_dev(ctx->drvdata);
674 bool is_hmac = ctx->is_hmac; 621 bool is_hmac = ctx->is_hmac;
675 struct ssi_crypto_req ssi_req = {}; 622 struct cc_crypto_req cc_req = {};
676 struct cc_hw_desc desc[SSI_MAX_AHASH_SEQ_LEN]; 623 struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
677 int idx = 0; 624 int idx = 0;
678 int rc; 625 int rc;
626 gfp_t flags = cc_gfp_flags(&req->base);
679 627
680 dev_dbg(dev, "===== %s-finup (%d) ====\n", is_hmac ? "hmac" : "hash", 628 dev_dbg(dev, "===== %s-finup (%d) ====\n", is_hmac ? "hmac" : "hash",
681 nbytes); 629 nbytes);
682 630
683 if (unlikely(ssi_buffer_mgr_map_hash_request_final(ctx->drvdata, state, src, nbytes, 1) != 0)) { 631 if (cc_map_req(dev, state, ctx)) {
632 dev_err(dev, "map_ahash_source() failed\n");
633 return -EINVAL;
634 }
635
636 if (cc_map_hash_request_final(ctx->drvdata, state, src, nbytes, 1,
637 flags)) {
684 dev_err(dev, "map_ahash_request_final() failed\n"); 638 dev_err(dev, "map_ahash_request_final() failed\n");
639 cc_unmap_req(dev, state, ctx);
685 return -ENOMEM; 640 return -ENOMEM;
686 } 641 }
687 if (unlikely(ssi_hash_map_result(dev, state, digestsize) != 0)) { 642 if (cc_map_result(dev, state, digestsize)) {
688 dev_err(dev, "map_ahash_digest() failed\n"); 643 dev_err(dev, "map_ahash_digest() failed\n");
644 cc_unmap_hash_request(dev, state, src, true);
645 cc_unmap_req(dev, state, ctx);
689 return -ENOMEM; 646 return -ENOMEM;
690 } 647 }
691 648
692 if (async_req) { 649 /* Setup DX request structure */
693 /* Setup DX request structure */ 650 cc_req.user_cb = cc_hash_complete;
694 ssi_req.user_cb = (void *)ssi_hash_complete; 651 cc_req.user_arg = req;
695 ssi_req.user_arg = async_req;
696 }
697
698 /* Restore hash digest */
699 hw_desc_init(&desc[idx]);
700 set_cipher_mode(&desc[idx], ctx->hw_mode);
701 set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
702 ctx->inter_digestsize, NS_BIT);
703 set_flow_mode(&desc[idx], S_DIN_to_HASH);
704 set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
705 idx++;
706
707 /* Restore hash current length */
708 hw_desc_init(&desc[idx]);
709 set_cipher_mode(&desc[idx], ctx->hw_mode);
710 set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED);
711 set_din_type(&desc[idx], DMA_DLLI, state->digest_bytes_len_dma_addr,
712 HASH_LEN_SIZE, NS_BIT);
713 set_flow_mode(&desc[idx], S_DIN_to_HASH);
714 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
715 idx++;
716
717 ssi_hash_create_data_desc(state, ctx, DIN_HASH, desc, false, &idx);
718
719 if (is_hmac) {
720 /* Store the hash digest result in the context */
721 hw_desc_init(&desc[idx]);
722 set_cipher_mode(&desc[idx], ctx->hw_mode);
723 set_dout_dlli(&desc[idx], state->digest_buff_dma_addr,
724 digestsize, NS_BIT, 0);
725 ssi_set_hash_endianity(ctx->hash_mode, &desc[idx]);
726 set_flow_mode(&desc[idx], S_HASH_to_DOUT);
727 set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
728 idx++;
729
730 /* Loading hash OPAD xor key state */
731 hw_desc_init(&desc[idx]);
732 set_cipher_mode(&desc[idx], ctx->hw_mode);
733 set_din_type(&desc[idx], DMA_DLLI, state->opad_digest_dma_addr,
734 ctx->inter_digestsize, NS_BIT);
735 set_flow_mode(&desc[idx], S_DIN_to_HASH);
736 set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
737 idx++;
738
739 /* Load the hash current length */
740 hw_desc_init(&desc[idx]);
741 set_cipher_mode(&desc[idx], ctx->hw_mode);
742 set_din_sram(&desc[idx],
743 ssi_ahash_get_initial_digest_len_sram_addr(
744ctx->drvdata, ctx->hash_mode), HASH_LEN_SIZE);
745 set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED);
746 set_flow_mode(&desc[idx], S_DIN_to_HASH);
747 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
748 idx++;
749 652
750 /* Memory Barrier: wait for IPAD/OPAD axi write to complete */ 653 idx = cc_restore_hash(desc, ctx, state, idx);
751 hw_desc_init(&desc[idx]);
752 set_din_no_dma(&desc[idx], 0, 0xfffff0);
753 set_dout_no_dma(&desc[idx], 0, 0, 1);
754 idx++;
755 654
756 /* Perform HASH update on last digest */ 655 if (is_hmac)
757 hw_desc_init(&desc[idx]); 656 idx = cc_fin_hmac(desc, req, idx);
758 set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
759 digestsize, NS_BIT);
760 set_flow_mode(&desc[idx], DIN_HASH);
761 idx++;
762 }
763 657
764 /* Get final MAC result */ 658 idx = cc_fin_result(desc, req, idx);
765 hw_desc_init(&desc[idx]);
766 /* TODO */
767 set_dout_dlli(&desc[idx], state->digest_result_dma_addr, digestsize,
768 NS_BIT, (async_req ? 1 : 0));
769 if (async_req)
770 set_queue_last_ind(&desc[idx]);
771 set_flow_mode(&desc[idx], S_HASH_to_DOUT);
772 set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED);
773 set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
774 ssi_set_hash_endianity(ctx->hash_mode, &desc[idx]);
775 set_cipher_mode(&desc[idx], ctx->hw_mode);
776 idx++;
777 659
778 if (async_req) { 660 rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
779 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 1); 661 if (rc != -EINPROGRESS && rc != -EBUSY) {
780 if (unlikely(rc != -EINPROGRESS)) { 662 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
781 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 663 cc_unmap_hash_request(dev, state, src, true);
782 ssi_buffer_mgr_unmap_hash_request(dev, state, src, true); 664 cc_unmap_result(dev, state, digestsize, result);
783 ssi_hash_unmap_result(dev, state, digestsize, result); 665 cc_unmap_req(dev, state, ctx);
784 }
785 } else {
786 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0);
787 if (rc != 0) {
788 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
789 ssi_buffer_mgr_unmap_hash_request(dev, state, src, true);
790 ssi_hash_unmap_result(dev, state, digestsize, result);
791 } else {
792 ssi_buffer_mgr_unmap_hash_request(dev, state, src, false);
793 ssi_hash_unmap_result(dev, state, digestsize, result);
794 ssi_hash_unmap_request(dev, state, ctx);
795 }
796 } 666 }
797 return rc; 667 return rc;
798} 668}
799 669
800static int ssi_hash_final(struct ahash_req_ctx *state, 670static int cc_hash_final(struct ahash_request *req)
801 struct ssi_hash_ctx *ctx,
802 unsigned int digestsize,
803 struct scatterlist *src,
804 unsigned int nbytes,
805 u8 *result,
806 void *async_req)
807{ 671{
672 struct ahash_req_ctx *state = ahash_request_ctx(req);
673 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
674 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
675 u32 digestsize = crypto_ahash_digestsize(tfm);
676 struct scatterlist *src = req->src;
677 unsigned int nbytes = req->nbytes;
678 u8 *result = req->result;
808 struct device *dev = drvdata_to_dev(ctx->drvdata); 679 struct device *dev = drvdata_to_dev(ctx->drvdata);
809 bool is_hmac = ctx->is_hmac; 680 bool is_hmac = ctx->is_hmac;
810 struct ssi_crypto_req ssi_req = {}; 681 struct cc_crypto_req cc_req = {};
811 struct cc_hw_desc desc[SSI_MAX_AHASH_SEQ_LEN]; 682 struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
812 int idx = 0; 683 int idx = 0;
813 int rc; 684 int rc;
685 gfp_t flags = cc_gfp_flags(&req->base);
814 686
815 dev_dbg(dev, "===== %s-final (%d) ====\n", is_hmac ? "hmac" : "hash", 687 dev_dbg(dev, "===== %s-final (%d) ====\n", is_hmac ? "hmac" : "hash",
816 nbytes); 688 nbytes);
817 689
818 if (unlikely(ssi_buffer_mgr_map_hash_request_final(ctx->drvdata, state, src, nbytes, 0) != 0)) { 690 if (cc_map_req(dev, state, ctx)) {
691 dev_err(dev, "map_ahash_source() failed\n");
692 return -EINVAL;
693 }
694
695 if (cc_map_hash_request_final(ctx->drvdata, state, src, nbytes, 0,
696 flags)) {
819 dev_err(dev, "map_ahash_request_final() failed\n"); 697 dev_err(dev, "map_ahash_request_final() failed\n");
698 cc_unmap_req(dev, state, ctx);
820 return -ENOMEM; 699 return -ENOMEM;
821 } 700 }
822 701
823 if (unlikely(ssi_hash_map_result(dev, state, digestsize) != 0)) { 702 if (cc_map_result(dev, state, digestsize)) {
824 dev_err(dev, "map_ahash_digest() failed\n"); 703 dev_err(dev, "map_ahash_digest() failed\n");
704 cc_unmap_hash_request(dev, state, src, true);
705 cc_unmap_req(dev, state, ctx);
825 return -ENOMEM; 706 return -ENOMEM;
826 } 707 }
827 708
828 if (async_req) { 709 /* Setup DX request structure */
829 /* Setup DX request structure */ 710 cc_req.user_cb = cc_hash_complete;
830 ssi_req.user_cb = (void *)ssi_hash_complete; 711 cc_req.user_arg = req;
831 ssi_req.user_arg = async_req;
832 }
833
834 /* Restore hash digest */
835 hw_desc_init(&desc[idx]);
836 set_cipher_mode(&desc[idx], ctx->hw_mode);
837 set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
838 ctx->inter_digestsize, NS_BIT);
839 set_flow_mode(&desc[idx], S_DIN_to_HASH);
840 set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
841 idx++;
842
843 /* Restore hash current length */
844 hw_desc_init(&desc[idx]);
845 set_cipher_mode(&desc[idx], ctx->hw_mode);
846 set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED);
847 set_din_type(&desc[idx], DMA_DLLI, state->digest_bytes_len_dma_addr,
848 HASH_LEN_SIZE, NS_BIT);
849 set_flow_mode(&desc[idx], S_DIN_to_HASH);
850 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
851 idx++;
852 712
853 ssi_hash_create_data_desc(state, ctx, DIN_HASH, desc, false, &idx); 713 idx = cc_restore_hash(desc, ctx, state, idx);
854 714
855 /* "DO-PAD" must be enabled only when writing current length to HW */ 715 /* "DO-PAD" must be enabled only when writing current length to HW */
856 hw_desc_init(&desc[idx]); 716 hw_desc_init(&desc[idx]);
@@ -862,121 +722,56 @@ static int ssi_hash_final(struct ahash_req_ctx *state,
862 set_flow_mode(&desc[idx], S_HASH_to_DOUT); 722 set_flow_mode(&desc[idx], S_HASH_to_DOUT);
863 idx++; 723 idx++;
864 724
865 if (is_hmac) { 725 if (is_hmac)
866 /* Store the hash digest result in the context */ 726 idx = cc_fin_hmac(desc, req, idx);
867 hw_desc_init(&desc[idx]);
868 set_cipher_mode(&desc[idx], ctx->hw_mode);
869 set_dout_dlli(&desc[idx], state->digest_buff_dma_addr,
870 digestsize, NS_BIT, 0);
871 ssi_set_hash_endianity(ctx->hash_mode, &desc[idx]);
872 set_flow_mode(&desc[idx], S_HASH_to_DOUT);
873 set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
874 idx++;
875
876 /* Loading hash OPAD xor key state */
877 hw_desc_init(&desc[idx]);
878 set_cipher_mode(&desc[idx], ctx->hw_mode);
879 set_din_type(&desc[idx], DMA_DLLI, state->opad_digest_dma_addr,
880 ctx->inter_digestsize, NS_BIT);
881 set_flow_mode(&desc[idx], S_DIN_to_HASH);
882 set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
883 idx++;
884
885 /* Load the hash current length */
886 hw_desc_init(&desc[idx]);
887 set_cipher_mode(&desc[idx], ctx->hw_mode);
888 set_din_sram(&desc[idx],
889 ssi_ahash_get_initial_digest_len_sram_addr(
890ctx->drvdata, ctx->hash_mode), HASH_LEN_SIZE);
891 set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED);
892 set_flow_mode(&desc[idx], S_DIN_to_HASH);
893 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
894 idx++;
895
896 /* Memory Barrier: wait for IPAD/OPAD axi write to complete */
897 hw_desc_init(&desc[idx]);
898 set_din_no_dma(&desc[idx], 0, 0xfffff0);
899 set_dout_no_dma(&desc[idx], 0, 0, 1);
900 idx++;
901
902 /* Perform HASH update on last digest */
903 hw_desc_init(&desc[idx]);
904 set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
905 digestsize, NS_BIT);
906 set_flow_mode(&desc[idx], DIN_HASH);
907 idx++;
908 }
909 727
910 /* Get final MAC result */ 728 idx = cc_fin_result(desc, req, idx);
911 hw_desc_init(&desc[idx]);
912 set_dout_dlli(&desc[idx], state->digest_result_dma_addr, digestsize,
913 NS_BIT, (async_req ? 1 : 0));
914 if (async_req)
915 set_queue_last_ind(&desc[idx]);
916 set_flow_mode(&desc[idx], S_HASH_to_DOUT);
917 set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED);
918 set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
919 ssi_set_hash_endianity(ctx->hash_mode, &desc[idx]);
920 set_cipher_mode(&desc[idx], ctx->hw_mode);
921 idx++;
922 729
923 if (async_req) { 730 rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
924 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 1); 731 if (rc != -EINPROGRESS && rc != -EBUSY) {
925 if (unlikely(rc != -EINPROGRESS)) { 732 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
926 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 733 cc_unmap_hash_request(dev, state, src, true);
927 ssi_buffer_mgr_unmap_hash_request(dev, state, src, true); 734 cc_unmap_result(dev, state, digestsize, result);
928 ssi_hash_unmap_result(dev, state, digestsize, result); 735 cc_unmap_req(dev, state, ctx);
929 }
930 } else {
931 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0);
932 if (rc != 0) {
933 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
934 ssi_buffer_mgr_unmap_hash_request(dev, state, src, true);
935 ssi_hash_unmap_result(dev, state, digestsize, result);
936 } else {
937 ssi_buffer_mgr_unmap_hash_request(dev, state, src, false);
938 ssi_hash_unmap_result(dev, state, digestsize, result);
939 ssi_hash_unmap_request(dev, state, ctx);
940 }
941 } 736 }
942 return rc; 737 return rc;
943} 738}
944 739
945static int ssi_hash_init(struct ahash_req_ctx *state, struct ssi_hash_ctx *ctx) 740static int cc_hash_init(struct ahash_request *req)
946{ 741{
742 struct ahash_req_ctx *state = ahash_request_ctx(req);
743 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
744 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
947 struct device *dev = drvdata_to_dev(ctx->drvdata); 745 struct device *dev = drvdata_to_dev(ctx->drvdata);
948 746
949 state->xcbc_count = 0; 747 dev_dbg(dev, "===== init (%d) ====\n", req->nbytes);
950 748
951 ssi_hash_map_request(dev, state, ctx); 749 cc_init_req(dev, state, ctx);
952 750
953 return 0; 751 return 0;
954} 752}
955 753
956static int ssi_hash_setkey(void *hash, 754static int cc_hash_setkey(struct crypto_ahash *ahash, const u8 *key,
957 const u8 *key, 755 unsigned int keylen)
958 unsigned int keylen,
959 bool synchronize)
960{ 756{
961 unsigned int hmac_pad_const[2] = { HMAC_IPAD_CONST, HMAC_OPAD_CONST }; 757 unsigned int hmac_pad_const[2] = { HMAC_IPAD_CONST, HMAC_OPAD_CONST };
962 struct ssi_crypto_req ssi_req = {}; 758 struct cc_crypto_req cc_req = {};
963 struct ssi_hash_ctx *ctx = NULL; 759 struct cc_hash_ctx *ctx = NULL;
964 int blocksize = 0; 760 int blocksize = 0;
965 int digestsize = 0; 761 int digestsize = 0;
966 int i, idx = 0, rc = 0; 762 int i, idx = 0, rc = 0;
967 struct cc_hw_desc desc[SSI_MAX_AHASH_SEQ_LEN]; 763 struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
968 ssi_sram_addr_t larval_addr; 764 cc_sram_addr_t larval_addr;
969 struct device *dev; 765 struct device *dev;
970 766
971 ctx = crypto_ahash_ctx(((struct crypto_ahash *)hash)); 767 ctx = crypto_ahash_ctx(ahash);
972 dev = drvdata_to_dev(ctx->drvdata); 768 dev = drvdata_to_dev(ctx->drvdata);
973 dev_dbg(dev, "start keylen: %d", keylen); 769 dev_dbg(dev, "start keylen: %d", keylen);
974 770
975 blocksize = crypto_tfm_alg_blocksize(&((struct crypto_ahash *)hash)->base); 771 blocksize = crypto_tfm_alg_blocksize(&ahash->base);
976 digestsize = crypto_ahash_digestsize(((struct crypto_ahash *)hash)); 772 digestsize = crypto_ahash_digestsize(ahash);
977 773
978 larval_addr = ssi_ahash_get_larval_digest_sram_addr( 774 larval_addr = cc_larval_digest_addr(ctx->drvdata, ctx->hash_mode);
979 ctx->drvdata, ctx->hash_mode);
980 775
981 /* The keylen value distinguishes HASH in case keylen is ZERO bytes, 776 /* The keylen value distinguishes HASH in case keylen is ZERO bytes,
982 * any NON-ZERO value utilizes HMAC flow 777 * any NON-ZERO value utilizes HMAC flow
@@ -985,12 +780,10 @@ static int ssi_hash_setkey(void *hash,
985 ctx->key_params.key_dma_addr = 0; 780 ctx->key_params.key_dma_addr = 0;
986 ctx->is_hmac = true; 781 ctx->is_hmac = true;
987 782
988 if (keylen != 0) { 783 if (keylen) {
989 ctx->key_params.key_dma_addr = dma_map_single( 784 ctx->key_params.key_dma_addr =
990 dev, (void *)key, 785 dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE);
991 keylen, DMA_TO_DEVICE); 786 if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) {
992 if (unlikely(dma_mapping_error(dev,
993 ctx->key_params.key_dma_addr))) {
994 dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n", 787 dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n",
995 key, keylen); 788 key, keylen);
996 return -ENOMEM; 789 return -ENOMEM;
@@ -1032,14 +825,15 @@ static int ssi_hash_setkey(void *hash,
1032 set_flow_mode(&desc[idx], S_HASH_to_DOUT); 825 set_flow_mode(&desc[idx], S_HASH_to_DOUT);
1033 set_setup_mode(&desc[idx], SETUP_WRITE_STATE0); 826 set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
1034 set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED); 827 set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED);
1035 ssi_set_hash_endianity(ctx->hash_mode, &desc[idx]); 828 cc_set_endianity(ctx->hash_mode, &desc[idx]);
1036 idx++; 829 idx++;
1037 830
1038 hw_desc_init(&desc[idx]); 831 hw_desc_init(&desc[idx]);
1039 set_din_const(&desc[idx], 0, (blocksize - digestsize)); 832 set_din_const(&desc[idx], 0, (blocksize - digestsize));
1040 set_flow_mode(&desc[idx], BYPASS); 833 set_flow_mode(&desc[idx], BYPASS);
1041 set_dout_dlli(&desc[idx], (ctx->opad_tmp_keys_dma_addr + 834 set_dout_dlli(&desc[idx],
1042 digestsize), 835 (ctx->opad_tmp_keys_dma_addr +
836 digestsize),
1043 (blocksize - digestsize), NS_BIT, 0); 837 (blocksize - digestsize), NS_BIT, 0);
1044 idx++; 838 idx++;
1045 } else { 839 } else {
@@ -1052,7 +846,7 @@ static int ssi_hash_setkey(void *hash,
1052 keylen, NS_BIT, 0); 846 keylen, NS_BIT, 0);
1053 idx++; 847 idx++;
1054 848
1055 if ((blocksize - keylen) != 0) { 849 if ((blocksize - keylen)) {
1056 hw_desc_init(&desc[idx]); 850 hw_desc_init(&desc[idx]);
1057 set_din_const(&desc[idx], 0, 851 set_din_const(&desc[idx], 0,
1058 (blocksize - keylen)); 852 (blocksize - keylen));
@@ -1073,8 +867,8 @@ static int ssi_hash_setkey(void *hash,
1073 idx++; 867 idx++;
1074 } 868 }
1075 869
1076 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0); 870 rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, idx);
1077 if (unlikely(rc != 0)) { 871 if (rc) {
1078 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 872 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
1079 goto out; 873 goto out;
1080 } 874 }
@@ -1114,7 +908,9 @@ static int ssi_hash_setkey(void *hash,
1114 set_flow_mode(&desc[idx], DIN_HASH); 908 set_flow_mode(&desc[idx], DIN_HASH);
1115 idx++; 909 idx++;
1116 910
1117 /* Get the IPAD/OPAD xor key (Note, IPAD is the initial digest of the first HASH "update" state) */ 911 /* Get the IPAD/OPAD xor key (Note, IPAD is the initial digest
912 * of the first HASH "update" state)
913 */
1118 hw_desc_init(&desc[idx]); 914 hw_desc_init(&desc[idx]);
1119 set_cipher_mode(&desc[idx], ctx->hw_mode); 915 set_cipher_mode(&desc[idx], ctx->hw_mode);
1120 if (i > 0) /* Not first iteration */ 916 if (i > 0) /* Not first iteration */
@@ -1128,11 +924,11 @@ static int ssi_hash_setkey(void *hash,
1128 idx++; 924 idx++;
1129 } 925 }
1130 926
1131 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0); 927 rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, idx);
1132 928
1133out: 929out:
1134 if (rc) 930 if (rc)
1135 crypto_ahash_set_flags((struct crypto_ahash *)hash, CRYPTO_TFM_RES_BAD_KEY_LEN); 931 crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN);
1136 932
1137 if (ctx->key_params.key_dma_addr) { 933 if (ctx->key_params.key_dma_addr) {
1138 dma_unmap_single(dev, ctx->key_params.key_dma_addr, 934 dma_unmap_single(dev, ctx->key_params.key_dma_addr,
@@ -1143,14 +939,14 @@ out:
1143 return rc; 939 return rc;
1144} 940}
1145 941
1146static int ssi_xcbc_setkey(struct crypto_ahash *ahash, 942static int cc_xcbc_setkey(struct crypto_ahash *ahash,
1147 const u8 *key, unsigned int keylen) 943 const u8 *key, unsigned int keylen)
1148{ 944{
1149 struct ssi_crypto_req ssi_req = {}; 945 struct cc_crypto_req cc_req = {};
1150 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(ahash); 946 struct cc_hash_ctx *ctx = crypto_ahash_ctx(ahash);
1151 struct device *dev = drvdata_to_dev(ctx->drvdata); 947 struct device *dev = drvdata_to_dev(ctx->drvdata);
1152 int idx = 0, rc = 0; 948 int idx = 0, rc = 0;
1153 struct cc_hw_desc desc[SSI_MAX_AHASH_SEQ_LEN]; 949 struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
1154 950
1155 dev_dbg(dev, "===== setkey (%d) ====\n", keylen); 951 dev_dbg(dev, "===== setkey (%d) ====\n", keylen);
1156 952
@@ -1165,10 +961,9 @@ static int ssi_xcbc_setkey(struct crypto_ahash *ahash,
1165 961
1166 ctx->key_params.keylen = keylen; 962 ctx->key_params.keylen = keylen;
1167 963
1168 ctx->key_params.key_dma_addr = dma_map_single( 964 ctx->key_params.key_dma_addr =
1169 dev, (void *)key, 965 dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE);
1170 keylen, DMA_TO_DEVICE); 966 if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) {
1171 if (unlikely(dma_mapping_error(dev, ctx->key_params.key_dma_addr))) {
1172 dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n", 967 dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n",
1173 key, keylen); 968 key, keylen);
1174 return -ENOMEM; 969 return -ENOMEM;
@@ -1191,30 +986,30 @@ static int ssi_xcbc_setkey(struct crypto_ahash *ahash,
1191 hw_desc_init(&desc[idx]); 986 hw_desc_init(&desc[idx]);
1192 set_din_const(&desc[idx], 0x01010101, CC_AES_128_BIT_KEY_SIZE); 987 set_din_const(&desc[idx], 0x01010101, CC_AES_128_BIT_KEY_SIZE);
1193 set_flow_mode(&desc[idx], DIN_AES_DOUT); 988 set_flow_mode(&desc[idx], DIN_AES_DOUT);
1194 set_dout_dlli(&desc[idx], (ctx->opad_tmp_keys_dma_addr + 989 set_dout_dlli(&desc[idx],
1195 XCBC_MAC_K1_OFFSET), 990 (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K1_OFFSET),
1196 CC_AES_128_BIT_KEY_SIZE, NS_BIT, 0); 991 CC_AES_128_BIT_KEY_SIZE, NS_BIT, 0);
1197 idx++; 992 idx++;
1198 993
1199 hw_desc_init(&desc[idx]); 994 hw_desc_init(&desc[idx]);
1200 set_din_const(&desc[idx], 0x02020202, CC_AES_128_BIT_KEY_SIZE); 995 set_din_const(&desc[idx], 0x02020202, CC_AES_128_BIT_KEY_SIZE);
1201 set_flow_mode(&desc[idx], DIN_AES_DOUT); 996 set_flow_mode(&desc[idx], DIN_AES_DOUT);
1202 set_dout_dlli(&desc[idx], (ctx->opad_tmp_keys_dma_addr + 997 set_dout_dlli(&desc[idx],
1203 XCBC_MAC_K2_OFFSET), 998 (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K2_OFFSET),
1204 CC_AES_128_BIT_KEY_SIZE, NS_BIT, 0); 999 CC_AES_128_BIT_KEY_SIZE, NS_BIT, 0);
1205 idx++; 1000 idx++;
1206 1001
1207 hw_desc_init(&desc[idx]); 1002 hw_desc_init(&desc[idx]);
1208 set_din_const(&desc[idx], 0x03030303, CC_AES_128_BIT_KEY_SIZE); 1003 set_din_const(&desc[idx], 0x03030303, CC_AES_128_BIT_KEY_SIZE);
1209 set_flow_mode(&desc[idx], DIN_AES_DOUT); 1004 set_flow_mode(&desc[idx], DIN_AES_DOUT);
1210 set_dout_dlli(&desc[idx], (ctx->opad_tmp_keys_dma_addr + 1005 set_dout_dlli(&desc[idx],
1211 XCBC_MAC_K3_OFFSET), 1006 (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K3_OFFSET),
1212 CC_AES_128_BIT_KEY_SIZE, NS_BIT, 0); 1007 CC_AES_128_BIT_KEY_SIZE, NS_BIT, 0);
1213 idx++; 1008 idx++;
1214 1009
1215 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0); 1010 rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, idx);
1216 1011
1217 if (rc != 0) 1012 if (rc)
1218 crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN); 1013 crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN);
1219 1014
1220 dma_unmap_single(dev, ctx->key_params.key_dma_addr, 1015 dma_unmap_single(dev, ctx->key_params.key_dma_addr,
@@ -1225,11 +1020,10 @@ static int ssi_xcbc_setkey(struct crypto_ahash *ahash,
1225 return rc; 1020 return rc;
1226} 1021}
1227 1022
1228#if SSI_CC_HAS_CMAC 1023static int cc_cmac_setkey(struct crypto_ahash *ahash,
1229static int ssi_cmac_setkey(struct crypto_ahash *ahash, 1024 const u8 *key, unsigned int keylen)
1230 const u8 *key, unsigned int keylen)
1231{ 1025{
1232 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(ahash); 1026 struct cc_hash_ctx *ctx = crypto_ahash_ctx(ahash);
1233 struct device *dev = drvdata_to_dev(ctx->drvdata); 1027 struct device *dev = drvdata_to_dev(ctx->drvdata);
1234 1028
1235 dev_dbg(dev, "===== setkey (%d) ====\n", keylen); 1029 dev_dbg(dev, "===== setkey (%d) ====\n", keylen);
@@ -1253,8 +1047,10 @@ static int ssi_cmac_setkey(struct crypto_ahash *ahash,
1253 keylen, DMA_TO_DEVICE); 1047 keylen, DMA_TO_DEVICE);
1254 1048
1255 memcpy(ctx->opad_tmp_keys_buff, key, keylen); 1049 memcpy(ctx->opad_tmp_keys_buff, key, keylen);
1256 if (keylen == 24) 1050 if (keylen == 24) {
1257 memset(ctx->opad_tmp_keys_buff + 24, 0, CC_AES_KEY_SIZE_MAX - 24); 1051 memset(ctx->opad_tmp_keys_buff + 24, 0,
1052 CC_AES_KEY_SIZE_MAX - 24);
1053 }
1258 1054
1259 dma_sync_single_for_device(dev, ctx->opad_tmp_keys_dma_addr, 1055 dma_sync_single_for_device(dev, ctx->opad_tmp_keys_dma_addr,
1260 keylen, DMA_TO_DEVICE); 1056 keylen, DMA_TO_DEVICE);
@@ -1263,20 +1059,19 @@ static int ssi_cmac_setkey(struct crypto_ahash *ahash,
1263 1059
1264 return 0; 1060 return 0;
1265} 1061}
1266#endif
1267 1062
1268static void ssi_hash_free_ctx(struct ssi_hash_ctx *ctx) 1063static void cc_free_ctx(struct cc_hash_ctx *ctx)
1269{ 1064{
1270 struct device *dev = drvdata_to_dev(ctx->drvdata); 1065 struct device *dev = drvdata_to_dev(ctx->drvdata);
1271 1066
1272 if (ctx->digest_buff_dma_addr != 0) { 1067 if (ctx->digest_buff_dma_addr) {
1273 dma_unmap_single(dev, ctx->digest_buff_dma_addr, 1068 dma_unmap_single(dev, ctx->digest_buff_dma_addr,
1274 sizeof(ctx->digest_buff), DMA_BIDIRECTIONAL); 1069 sizeof(ctx->digest_buff), DMA_BIDIRECTIONAL);
1275 dev_dbg(dev, "Unmapped digest-buffer: digest_buff_dma_addr=%pad\n", 1070 dev_dbg(dev, "Unmapped digest-buffer: digest_buff_dma_addr=%pad\n",
1276 &ctx->digest_buff_dma_addr); 1071 &ctx->digest_buff_dma_addr);
1277 ctx->digest_buff_dma_addr = 0; 1072 ctx->digest_buff_dma_addr = 0;
1278 } 1073 }
1279 if (ctx->opad_tmp_keys_dma_addr != 0) { 1074 if (ctx->opad_tmp_keys_dma_addr) {
1280 dma_unmap_single(dev, ctx->opad_tmp_keys_dma_addr, 1075 dma_unmap_single(dev, ctx->opad_tmp_keys_dma_addr,
1281 sizeof(ctx->opad_tmp_keys_buff), 1076 sizeof(ctx->opad_tmp_keys_buff),
1282 DMA_BIDIRECTIONAL); 1077 DMA_BIDIRECTIONAL);
@@ -1288,13 +1083,15 @@ static void ssi_hash_free_ctx(struct ssi_hash_ctx *ctx)
1288 ctx->key_params.keylen = 0; 1083 ctx->key_params.keylen = 0;
1289} 1084}
1290 1085
1291static int ssi_hash_alloc_ctx(struct ssi_hash_ctx *ctx) 1086static int cc_alloc_ctx(struct cc_hash_ctx *ctx)
1292{ 1087{
1293 struct device *dev = drvdata_to_dev(ctx->drvdata); 1088 struct device *dev = drvdata_to_dev(ctx->drvdata);
1294 1089
1295 ctx->key_params.keylen = 0; 1090 ctx->key_params.keylen = 0;
1296 1091
1297 ctx->digest_buff_dma_addr = dma_map_single(dev, (void *)ctx->digest_buff, sizeof(ctx->digest_buff), DMA_BIDIRECTIONAL); 1092 ctx->digest_buff_dma_addr =
1093 dma_map_single(dev, (void *)ctx->digest_buff,
1094 sizeof(ctx->digest_buff), DMA_BIDIRECTIONAL);
1298 if (dma_mapping_error(dev, ctx->digest_buff_dma_addr)) { 1095 if (dma_mapping_error(dev, ctx->digest_buff_dma_addr)) {
1299 dev_err(dev, "Mapping digest len %zu B at va=%pK for DMA failed\n", 1096 dev_err(dev, "Mapping digest len %zu B at va=%pK for DMA failed\n",
1300 sizeof(ctx->digest_buff), ctx->digest_buff); 1097 sizeof(ctx->digest_buff), ctx->digest_buff);
@@ -1304,7 +1101,10 @@ static int ssi_hash_alloc_ctx(struct ssi_hash_ctx *ctx)
1304 sizeof(ctx->digest_buff), ctx->digest_buff, 1101 sizeof(ctx->digest_buff), ctx->digest_buff,
1305 &ctx->digest_buff_dma_addr); 1102 &ctx->digest_buff_dma_addr);
1306 1103
1307 ctx->opad_tmp_keys_dma_addr = dma_map_single(dev, (void *)ctx->opad_tmp_keys_buff, sizeof(ctx->opad_tmp_keys_buff), DMA_BIDIRECTIONAL); 1104 ctx->opad_tmp_keys_dma_addr =
1105 dma_map_single(dev, (void *)ctx->opad_tmp_keys_buff,
1106 sizeof(ctx->opad_tmp_keys_buff),
1107 DMA_BIDIRECTIONAL);
1308 if (dma_mapping_error(dev, ctx->opad_tmp_keys_dma_addr)) { 1108 if (dma_mapping_error(dev, ctx->opad_tmp_keys_dma_addr)) {
1309 dev_err(dev, "Mapping opad digest %zu B at va=%pK for DMA failed\n", 1109 dev_err(dev, "Mapping opad digest %zu B at va=%pK for DMA failed\n",
1310 sizeof(ctx->opad_tmp_keys_buff), 1110 sizeof(ctx->opad_tmp_keys_buff),
@@ -1319,51 +1119,52 @@ static int ssi_hash_alloc_ctx(struct ssi_hash_ctx *ctx)
1319 return 0; 1119 return 0;
1320 1120
1321fail: 1121fail:
1322 ssi_hash_free_ctx(ctx); 1122 cc_free_ctx(ctx);
1323 return -ENOMEM; 1123 return -ENOMEM;
1324} 1124}
1325 1125
1326static int ssi_ahash_cra_init(struct crypto_tfm *tfm) 1126static int cc_cra_init(struct crypto_tfm *tfm)
1327{ 1127{
1328 struct ssi_hash_ctx *ctx = crypto_tfm_ctx(tfm); 1128 struct cc_hash_ctx *ctx = crypto_tfm_ctx(tfm);
1329 struct hash_alg_common *hash_alg_common = 1129 struct hash_alg_common *hash_alg_common =
1330 container_of(tfm->__crt_alg, struct hash_alg_common, base); 1130 container_of(tfm->__crt_alg, struct hash_alg_common, base);
1331 struct ahash_alg *ahash_alg = 1131 struct ahash_alg *ahash_alg =
1332 container_of(hash_alg_common, struct ahash_alg, halg); 1132 container_of(hash_alg_common, struct ahash_alg, halg);
1333 struct ssi_hash_alg *ssi_alg = 1133 struct cc_hash_alg *cc_alg =
1334 container_of(ahash_alg, struct ssi_hash_alg, ahash_alg); 1134 container_of(ahash_alg, struct cc_hash_alg, ahash_alg);
1335 1135
1336 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), 1136 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
1337 sizeof(struct ahash_req_ctx)); 1137 sizeof(struct ahash_req_ctx));
1338 1138
1339 ctx->hash_mode = ssi_alg->hash_mode; 1139 ctx->hash_mode = cc_alg->hash_mode;
1340 ctx->hw_mode = ssi_alg->hw_mode; 1140 ctx->hw_mode = cc_alg->hw_mode;
1341 ctx->inter_digestsize = ssi_alg->inter_digestsize; 1141 ctx->inter_digestsize = cc_alg->inter_digestsize;
1342 ctx->drvdata = ssi_alg->drvdata; 1142 ctx->drvdata = cc_alg->drvdata;
1343 1143
1344 return ssi_hash_alloc_ctx(ctx); 1144 return cc_alloc_ctx(ctx);
1345} 1145}
1346 1146
1347static void ssi_hash_cra_exit(struct crypto_tfm *tfm) 1147static void cc_cra_exit(struct crypto_tfm *tfm)
1348{ 1148{
1349 struct ssi_hash_ctx *ctx = crypto_tfm_ctx(tfm); 1149 struct cc_hash_ctx *ctx = crypto_tfm_ctx(tfm);
1350 struct device *dev = drvdata_to_dev(ctx->drvdata); 1150 struct device *dev = drvdata_to_dev(ctx->drvdata);
1351 1151
1352 dev_dbg(dev, "ssi_hash_cra_exit"); 1152 dev_dbg(dev, "cc_cra_exit");
1353 ssi_hash_free_ctx(ctx); 1153 cc_free_ctx(ctx);
1354} 1154}
1355 1155
1356static int ssi_mac_update(struct ahash_request *req) 1156static int cc_mac_update(struct ahash_request *req)
1357{ 1157{
1358 struct ahash_req_ctx *state = ahash_request_ctx(req); 1158 struct ahash_req_ctx *state = ahash_request_ctx(req);
1359 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 1159 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1360 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm); 1160 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
1361 struct device *dev = drvdata_to_dev(ctx->drvdata); 1161 struct device *dev = drvdata_to_dev(ctx->drvdata);
1362 unsigned int block_size = crypto_tfm_alg_blocksize(&tfm->base); 1162 unsigned int block_size = crypto_tfm_alg_blocksize(&tfm->base);
1363 struct ssi_crypto_req ssi_req = {}; 1163 struct cc_crypto_req cc_req = {};
1364 struct cc_hw_desc desc[SSI_MAX_AHASH_SEQ_LEN]; 1164 struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
1365 int rc; 1165 int rc;
1366 u32 idx = 0; 1166 u32 idx = 0;
1167 gfp_t flags = cc_gfp_flags(&req->base);
1367 1168
1368 if (req->nbytes == 0) { 1169 if (req->nbytes == 0) {
1369 /* no real updates required */ 1170 /* no real updates required */
@@ -1372,8 +1173,9 @@ static int ssi_mac_update(struct ahash_request *req)
1372 1173
1373 state->xcbc_count++; 1174 state->xcbc_count++;
1374 1175
1375 rc = ssi_buffer_mgr_map_hash_request_update(ctx->drvdata, state, req->src, req->nbytes, block_size); 1176 rc = cc_map_hash_request_update(ctx->drvdata, state, req->src,
1376 if (unlikely(rc)) { 1177 req->nbytes, block_size, flags);
1178 if (rc) {
1377 if (rc == 1) { 1179 if (rc == 1) {
1378 dev_dbg(dev, " data size not require HW update %x\n", 1180 dev_dbg(dev, " data size not require HW update %x\n",
1379 req->nbytes); 1181 req->nbytes);
@@ -1384,12 +1186,17 @@ static int ssi_mac_update(struct ahash_request *req)
1384 return -ENOMEM; 1186 return -ENOMEM;
1385 } 1187 }
1386 1188
1189 if (cc_map_req(dev, state, ctx)) {
1190 dev_err(dev, "map_ahash_source() failed\n");
1191 return -EINVAL;
1192 }
1193
1387 if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC) 1194 if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC)
1388 ssi_hash_create_xcbc_setup(req, desc, &idx); 1195 cc_setup_xcbc(req, desc, &idx);
1389 else 1196 else
1390 ssi_hash_create_cmac_setup(req, desc, &idx); 1197 cc_setup_cmac(req, desc, &idx);
1391 1198
1392 ssi_hash_create_data_desc(state, ctx, DIN_AES_DOUT, desc, true, &idx); 1199 cc_set_desc(state, ctx, DIN_AES_DOUT, desc, true, &idx);
1393 1200
1394 /* store the hash digest result in context */ 1201 /* store the hash digest result in context */
1395 hw_desc_init(&desc[idx]); 1202 hw_desc_init(&desc[idx]);
@@ -1402,32 +1209,32 @@ static int ssi_mac_update(struct ahash_request *req)
1402 idx++; 1209 idx++;
1403 1210
1404 /* Setup DX request structure */ 1211 /* Setup DX request structure */
1405 ssi_req.user_cb = (void *)ssi_hash_update_complete; 1212 cc_req.user_cb = (void *)cc_update_complete;
1406 ssi_req.user_arg = (void *)req; 1213 cc_req.user_arg = (void *)req;
1407 1214
1408 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 1); 1215 rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
1409 if (unlikely(rc != -EINPROGRESS)) { 1216 if (rc != -EINPROGRESS && rc != -EBUSY) {
1410 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 1217 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
1411 ssi_buffer_mgr_unmap_hash_request(dev, state, req->src, true); 1218 cc_unmap_hash_request(dev, state, req->src, true);
1219 cc_unmap_req(dev, state, ctx);
1412 } 1220 }
1413 return rc; 1221 return rc;
1414} 1222}
1415 1223
1416static int ssi_mac_final(struct ahash_request *req) 1224static int cc_mac_final(struct ahash_request *req)
1417{ 1225{
1418 struct ahash_req_ctx *state = ahash_request_ctx(req); 1226 struct ahash_req_ctx *state = ahash_request_ctx(req);
1419 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 1227 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1420 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm); 1228 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
1421 struct device *dev = drvdata_to_dev(ctx->drvdata); 1229 struct device *dev = drvdata_to_dev(ctx->drvdata);
1422 struct ssi_crypto_req ssi_req = {}; 1230 struct cc_crypto_req cc_req = {};
1423 struct cc_hw_desc desc[SSI_MAX_AHASH_SEQ_LEN]; 1231 struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
1424 int idx = 0; 1232 int idx = 0;
1425 int rc = 0; 1233 int rc = 0;
1426 u32 key_size, key_len; 1234 u32 key_size, key_len;
1427 u32 digestsize = crypto_ahash_digestsize(tfm); 1235 u32 digestsize = crypto_ahash_digestsize(tfm);
1428 1236 gfp_t flags = cc_gfp_flags(&req->base);
1429 u32 rem_cnt = state->buff_index ? state->buff1_cnt : 1237 u32 rem_cnt = *cc_hash_buf_cnt(state);
1430 state->buff0_cnt;
1431 1238
1432 if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC) { 1239 if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC) {
1433 key_size = CC_AES_128_BIT_KEY_SIZE; 1240 key_size = CC_AES_128_BIT_KEY_SIZE;
@@ -1440,34 +1247,45 @@ static int ssi_mac_final(struct ahash_request *req)
1440 1247
1441 dev_dbg(dev, "===== final xcbc reminder (%d) ====\n", rem_cnt); 1248 dev_dbg(dev, "===== final xcbc reminder (%d) ====\n", rem_cnt);
1442 1249
1443 if (unlikely(ssi_buffer_mgr_map_hash_request_final(ctx->drvdata, state, req->src, req->nbytes, 0) != 0)) { 1250 if (cc_map_req(dev, state, ctx)) {
1251 dev_err(dev, "map_ahash_source() failed\n");
1252 return -EINVAL;
1253 }
1254
1255 if (cc_map_hash_request_final(ctx->drvdata, state, req->src,
1256 req->nbytes, 0, flags)) {
1444 dev_err(dev, "map_ahash_request_final() failed\n"); 1257 dev_err(dev, "map_ahash_request_final() failed\n");
1258 cc_unmap_req(dev, state, ctx);
1445 return -ENOMEM; 1259 return -ENOMEM;
1446 } 1260 }
1447 1261
1448 if (unlikely(ssi_hash_map_result(dev, state, digestsize) != 0)) { 1262 if (cc_map_result(dev, state, digestsize)) {
1449 dev_err(dev, "map_ahash_digest() failed\n"); 1263 dev_err(dev, "map_ahash_digest() failed\n");
1264 cc_unmap_hash_request(dev, state, req->src, true);
1265 cc_unmap_req(dev, state, ctx);
1450 return -ENOMEM; 1266 return -ENOMEM;
1451 } 1267 }
1452 1268
1453 /* Setup DX request structure */ 1269 /* Setup DX request structure */
1454 ssi_req.user_cb = (void *)ssi_hash_complete; 1270 cc_req.user_cb = (void *)cc_hash_complete;
1455 ssi_req.user_arg = (void *)req; 1271 cc_req.user_arg = (void *)req;
1456 1272
1457 if (state->xcbc_count && (rem_cnt == 0)) { 1273 if (state->xcbc_count && rem_cnt == 0) {
1458 /* Load key for ECB decryption */ 1274 /* Load key for ECB decryption */
1459 hw_desc_init(&desc[idx]); 1275 hw_desc_init(&desc[idx]);
1460 set_cipher_mode(&desc[idx], DRV_CIPHER_ECB); 1276 set_cipher_mode(&desc[idx], DRV_CIPHER_ECB);
1461 set_cipher_config0(&desc[idx], DRV_CRYPTO_DIRECTION_DECRYPT); 1277 set_cipher_config0(&desc[idx], DRV_CRYPTO_DIRECTION_DECRYPT);
1462 set_din_type(&desc[idx], DMA_DLLI, 1278 set_din_type(&desc[idx], DMA_DLLI,
1463 (ctx->opad_tmp_keys_dma_addr + 1279 (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K1_OFFSET),
1464 XCBC_MAC_K1_OFFSET), key_size, NS_BIT); 1280 key_size, NS_BIT);
1465 set_key_size_aes(&desc[idx], key_len); 1281 set_key_size_aes(&desc[idx], key_len);
1466 set_flow_mode(&desc[idx], S_DIN_to_AES); 1282 set_flow_mode(&desc[idx], S_DIN_to_AES);
1467 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0); 1283 set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
1468 idx++; 1284 idx++;
1469 1285
1470 /* Initiate decryption of block state to previous block_state-XOR-M[n] */ 1286 /* Initiate decryption of block state to previous
1287 * block_state-XOR-M[n]
1288 */
1471 hw_desc_init(&desc[idx]); 1289 hw_desc_init(&desc[idx]);
1472 set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr, 1290 set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
1473 CC_AES_BLOCK_SIZE, NS_BIT); 1291 CC_AES_BLOCK_SIZE, NS_BIT);
@@ -1484,9 +1302,9 @@ static int ssi_mac_final(struct ahash_request *req)
1484 } 1302 }
1485 1303
1486 if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC) 1304 if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC)
1487 ssi_hash_create_xcbc_setup(req, desc, &idx); 1305 cc_setup_xcbc(req, desc, &idx);
1488 else 1306 else
1489 ssi_hash_create_cmac_setup(req, desc, &idx); 1307 cc_setup_cmac(req, desc, &idx);
1490 1308
1491 if (state->xcbc_count == 0) { 1309 if (state->xcbc_count == 0) {
1492 hw_desc_init(&desc[idx]); 1310 hw_desc_init(&desc[idx]);
@@ -1496,7 +1314,7 @@ static int ssi_mac_final(struct ahash_request *req)
1496 set_flow_mode(&desc[idx], S_DIN_to_AES); 1314 set_flow_mode(&desc[idx], S_DIN_to_AES);
1497 idx++; 1315 idx++;
1498 } else if (rem_cnt > 0) { 1316 } else if (rem_cnt > 0) {
1499 ssi_hash_create_data_desc(state, ctx, DIN_AES_DOUT, desc, false, &idx); 1317 cc_set_desc(state, ctx, DIN_AES_DOUT, desc, false, &idx);
1500 } else { 1318 } else {
1501 hw_desc_init(&desc[idx]); 1319 hw_desc_init(&desc[idx]);
1502 set_din_const(&desc[idx], 0x00, CC_AES_BLOCK_SIZE); 1320 set_din_const(&desc[idx], 0x00, CC_AES_BLOCK_SIZE);
@@ -1515,53 +1333,64 @@ static int ssi_mac_final(struct ahash_request *req)
1515 set_cipher_mode(&desc[idx], ctx->hw_mode); 1333 set_cipher_mode(&desc[idx], ctx->hw_mode);
1516 idx++; 1334 idx++;
1517 1335
1518 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 1); 1336 rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
1519 if (unlikely(rc != -EINPROGRESS)) { 1337 if (rc != -EINPROGRESS && rc != -EBUSY) {
1520 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 1338 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
1521 ssi_buffer_mgr_unmap_hash_request(dev, state, req->src, true); 1339 cc_unmap_hash_request(dev, state, req->src, true);
1522 ssi_hash_unmap_result(dev, state, digestsize, req->result); 1340 cc_unmap_result(dev, state, digestsize, req->result);
1341 cc_unmap_req(dev, state, ctx);
1523 } 1342 }
1524 return rc; 1343 return rc;
1525} 1344}
1526 1345
1527static int ssi_mac_finup(struct ahash_request *req) 1346static int cc_mac_finup(struct ahash_request *req)
1528{ 1347{
1529 struct ahash_req_ctx *state = ahash_request_ctx(req); 1348 struct ahash_req_ctx *state = ahash_request_ctx(req);
1530 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 1349 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1531 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm); 1350 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
1532 struct device *dev = drvdata_to_dev(ctx->drvdata); 1351 struct device *dev = drvdata_to_dev(ctx->drvdata);
1533 struct ssi_crypto_req ssi_req = {}; 1352 struct cc_crypto_req cc_req = {};
1534 struct cc_hw_desc desc[SSI_MAX_AHASH_SEQ_LEN]; 1353 struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
1535 int idx = 0; 1354 int idx = 0;
1536 int rc = 0; 1355 int rc = 0;
1537 u32 key_len = 0; 1356 u32 key_len = 0;
1538 u32 digestsize = crypto_ahash_digestsize(tfm); 1357 u32 digestsize = crypto_ahash_digestsize(tfm);
1358 gfp_t flags = cc_gfp_flags(&req->base);
1539 1359
1540 dev_dbg(dev, "===== finup xcbc(%d) ====\n", req->nbytes); 1360 dev_dbg(dev, "===== finup xcbc(%d) ====\n", req->nbytes);
1541 if (state->xcbc_count > 0 && req->nbytes == 0) { 1361 if (state->xcbc_count > 0 && req->nbytes == 0) {
1542 dev_dbg(dev, "No data to update. Call to fdx_mac_final\n"); 1362 dev_dbg(dev, "No data to update. Call to fdx_mac_final\n");
1543 return ssi_mac_final(req); 1363 return cc_mac_final(req);
1364 }
1365
1366 if (cc_map_req(dev, state, ctx)) {
1367 dev_err(dev, "map_ahash_source() failed\n");
1368 return -EINVAL;
1544 } 1369 }
1545 1370
1546 if (unlikely(ssi_buffer_mgr_map_hash_request_final(ctx->drvdata, state, req->src, req->nbytes, 1) != 0)) { 1371 if (cc_map_hash_request_final(ctx->drvdata, state, req->src,
1372 req->nbytes, 1, flags)) {
1547 dev_err(dev, "map_ahash_request_final() failed\n"); 1373 dev_err(dev, "map_ahash_request_final() failed\n");
1374 cc_unmap_req(dev, state, ctx);
1548 return -ENOMEM; 1375 return -ENOMEM;
1549 } 1376 }
1550 if (unlikely(ssi_hash_map_result(dev, state, digestsize) != 0)) { 1377 if (cc_map_result(dev, state, digestsize)) {
1551 dev_err(dev, "map_ahash_digest() failed\n"); 1378 dev_err(dev, "map_ahash_digest() failed\n");
1379 cc_unmap_hash_request(dev, state, req->src, true);
1380 cc_unmap_req(dev, state, ctx);
1552 return -ENOMEM; 1381 return -ENOMEM;
1553 } 1382 }
1554 1383
1555 /* Setup DX request structure */ 1384 /* Setup DX request structure */
1556 ssi_req.user_cb = (void *)ssi_hash_complete; 1385 cc_req.user_cb = (void *)cc_hash_complete;
1557 ssi_req.user_arg = (void *)req; 1386 cc_req.user_arg = (void *)req;
1558 1387
1559 if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC) { 1388 if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC) {
1560 key_len = CC_AES_128_BIT_KEY_SIZE; 1389 key_len = CC_AES_128_BIT_KEY_SIZE;
1561 ssi_hash_create_xcbc_setup(req, desc, &idx); 1390 cc_setup_xcbc(req, desc, &idx);
1562 } else { 1391 } else {
1563 key_len = ctx->key_params.keylen; 1392 key_len = ctx->key_params.keylen;
1564 ssi_hash_create_cmac_setup(req, desc, &idx); 1393 cc_setup_cmac(req, desc, &idx);
1565 } 1394 }
1566 1395
1567 if (req->nbytes == 0) { 1396 if (req->nbytes == 0) {
@@ -1572,7 +1401,7 @@ static int ssi_mac_finup(struct ahash_request *req)
1572 set_flow_mode(&desc[idx], S_DIN_to_AES); 1401 set_flow_mode(&desc[idx], S_DIN_to_AES);
1573 idx++; 1402 idx++;
1574 } else { 1403 } else {
1575 ssi_hash_create_data_desc(state, ctx, DIN_AES_DOUT, desc, false, &idx); 1404 cc_set_desc(state, ctx, DIN_AES_DOUT, desc, false, &idx);
1576 } 1405 }
1577 1406
1578 /* Get final MAC result */ 1407 /* Get final MAC result */
@@ -1586,54 +1415,61 @@ static int ssi_mac_finup(struct ahash_request *req)
1586 set_cipher_mode(&desc[idx], ctx->hw_mode); 1415 set_cipher_mode(&desc[idx], ctx->hw_mode);
1587 idx++; 1416 idx++;
1588 1417
1589 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 1); 1418 rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
1590 if (unlikely(rc != -EINPROGRESS)) { 1419 if (rc != -EINPROGRESS && rc != -EBUSY) {
1591 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 1420 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
1592 ssi_buffer_mgr_unmap_hash_request(dev, state, req->src, true); 1421 cc_unmap_hash_request(dev, state, req->src, true);
1593 ssi_hash_unmap_result(dev, state, digestsize, req->result); 1422 cc_unmap_result(dev, state, digestsize, req->result);
1423 cc_unmap_req(dev, state, ctx);
1594 } 1424 }
1595 return rc; 1425 return rc;
1596} 1426}
1597 1427
1598static int ssi_mac_digest(struct ahash_request *req) 1428static int cc_mac_digest(struct ahash_request *req)
1599{ 1429{
1600 struct ahash_req_ctx *state = ahash_request_ctx(req); 1430 struct ahash_req_ctx *state = ahash_request_ctx(req);
1601 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 1431 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1602 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm); 1432 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
1603 struct device *dev = drvdata_to_dev(ctx->drvdata); 1433 struct device *dev = drvdata_to_dev(ctx->drvdata);
1604 u32 digestsize = crypto_ahash_digestsize(tfm); 1434 u32 digestsize = crypto_ahash_digestsize(tfm);
1605 struct ssi_crypto_req ssi_req = {}; 1435 struct cc_crypto_req cc_req = {};
1606 struct cc_hw_desc desc[SSI_MAX_AHASH_SEQ_LEN]; 1436 struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
1607 u32 key_len; 1437 u32 key_len;
1608 int idx = 0; 1438 int idx = 0;
1609 int rc; 1439 int rc;
1440 gfp_t flags = cc_gfp_flags(&req->base);
1610 1441
1611 dev_dbg(dev, "===== -digest mac (%d) ====\n", req->nbytes); 1442 dev_dbg(dev, "===== -digest mac (%d) ====\n", req->nbytes);
1612 1443
1613 if (unlikely(ssi_hash_map_request(dev, state, ctx) != 0)) { 1444 cc_init_req(dev, state, ctx);
1445
1446 if (cc_map_req(dev, state, ctx)) {
1614 dev_err(dev, "map_ahash_source() failed\n"); 1447 dev_err(dev, "map_ahash_source() failed\n");
1615 return -ENOMEM; 1448 return -ENOMEM;
1616 } 1449 }
1617 if (unlikely(ssi_hash_map_result(dev, state, digestsize) != 0)) { 1450 if (cc_map_result(dev, state, digestsize)) {
1618 dev_err(dev, "map_ahash_digest() failed\n"); 1451 dev_err(dev, "map_ahash_digest() failed\n");
1452 cc_unmap_req(dev, state, ctx);
1619 return -ENOMEM; 1453 return -ENOMEM;
1620 } 1454 }
1621 1455
1622 if (unlikely(ssi_buffer_mgr_map_hash_request_final(ctx->drvdata, state, req->src, req->nbytes, 1) != 0)) { 1456 if (cc_map_hash_request_final(ctx->drvdata, state, req->src,
1457 req->nbytes, 1, flags)) {
1623 dev_err(dev, "map_ahash_request_final() failed\n"); 1458 dev_err(dev, "map_ahash_request_final() failed\n");
1459 cc_unmap_req(dev, state, ctx);
1624 return -ENOMEM; 1460 return -ENOMEM;
1625 } 1461 }
1626 1462
1627 /* Setup DX request structure */ 1463 /* Setup DX request structure */
1628 ssi_req.user_cb = (void *)ssi_hash_digest_complete; 1464 cc_req.user_cb = (void *)cc_digest_complete;
1629 ssi_req.user_arg = (void *)req; 1465 cc_req.user_arg = (void *)req;
1630 1466
1631 if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC) { 1467 if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC) {
1632 key_len = CC_AES_128_BIT_KEY_SIZE; 1468 key_len = CC_AES_128_BIT_KEY_SIZE;
1633 ssi_hash_create_xcbc_setup(req, desc, &idx); 1469 cc_setup_xcbc(req, desc, &idx);
1634 } else { 1470 } else {
1635 key_len = ctx->key_params.keylen; 1471 key_len = ctx->key_params.keylen;
1636 ssi_hash_create_cmac_setup(req, desc, &idx); 1472 cc_setup_cmac(req, desc, &idx);
1637 } 1473 }
1638 1474
1639 if (req->nbytes == 0) { 1475 if (req->nbytes == 0) {
@@ -1644,7 +1480,7 @@ static int ssi_mac_digest(struct ahash_request *req)
1644 set_flow_mode(&desc[idx], S_DIN_to_AES); 1480 set_flow_mode(&desc[idx], S_DIN_to_AES);
1645 idx++; 1481 idx++;
1646 } else { 1482 } else {
1647 ssi_hash_create_data_desc(state, ctx, DIN_AES_DOUT, desc, false, &idx); 1483 cc_set_desc(state, ctx, DIN_AES_DOUT, desc, false, &idx);
1648 } 1484 }
1649 1485
1650 /* Get final MAC result */ 1486 /* Get final MAC result */
@@ -1658,96 +1494,32 @@ static int ssi_mac_digest(struct ahash_request *req)
1658 set_cipher_mode(&desc[idx], ctx->hw_mode); 1494 set_cipher_mode(&desc[idx], ctx->hw_mode);
1659 idx++; 1495 idx++;
1660 1496
1661 rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 1); 1497 rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
1662 if (unlikely(rc != -EINPROGRESS)) { 1498 if (rc != -EINPROGRESS && rc != -EBUSY) {
1663 dev_err(dev, "send_request() failed (rc=%d)\n", rc); 1499 dev_err(dev, "send_request() failed (rc=%d)\n", rc);
1664 ssi_buffer_mgr_unmap_hash_request(dev, state, req->src, true); 1500 cc_unmap_hash_request(dev, state, req->src, true);
1665 ssi_hash_unmap_result(dev, state, digestsize, req->result); 1501 cc_unmap_result(dev, state, digestsize, req->result);
1666 ssi_hash_unmap_request(dev, state, ctx); 1502 cc_unmap_req(dev, state, ctx);
1667 } 1503 }
1668 return rc; 1504 return rc;
1669} 1505}
1670 1506
1671//ahash wrap functions 1507static int cc_hash_export(struct ahash_request *req, void *out)
1672static int ssi_ahash_digest(struct ahash_request *req)
1673{
1674 struct ahash_req_ctx *state = ahash_request_ctx(req);
1675 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1676 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm);
1677 u32 digestsize = crypto_ahash_digestsize(tfm);
1678
1679 return ssi_hash_digest(state, ctx, digestsize, req->src, req->nbytes, req->result, (void *)req);
1680}
1681
1682static int ssi_ahash_update(struct ahash_request *req)
1683{
1684 struct ahash_req_ctx *state = ahash_request_ctx(req);
1685 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1686 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm);
1687 unsigned int block_size = crypto_tfm_alg_blocksize(&tfm->base);
1688
1689 return ssi_hash_update(state, ctx, block_size, req->src, req->nbytes, (void *)req);
1690}
1691
1692static int ssi_ahash_finup(struct ahash_request *req)
1693{
1694 struct ahash_req_ctx *state = ahash_request_ctx(req);
1695 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1696 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm);
1697 u32 digestsize = crypto_ahash_digestsize(tfm);
1698
1699 return ssi_hash_finup(state, ctx, digestsize, req->src, req->nbytes, req->result, (void *)req);
1700}
1701
1702static int ssi_ahash_final(struct ahash_request *req)
1703{
1704 struct ahash_req_ctx *state = ahash_request_ctx(req);
1705 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1706 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm);
1707 u32 digestsize = crypto_ahash_digestsize(tfm);
1708
1709 return ssi_hash_final(state, ctx, digestsize, req->src, req->nbytes, req->result, (void *)req);
1710}
1711
1712static int ssi_ahash_init(struct ahash_request *req)
1713{
1714 struct ahash_req_ctx *state = ahash_request_ctx(req);
1715 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1716 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm);
1717 struct device *dev = drvdata_to_dev(ctx->drvdata);
1718
1719 dev_dbg(dev, "===== init (%d) ====\n", req->nbytes);
1720
1721 return ssi_hash_init(state, ctx);
1722}
1723
1724static int ssi_ahash_export(struct ahash_request *req, void *out)
1725{ 1508{
1726 struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); 1509 struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
1727 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(ahash); 1510 struct cc_hash_ctx *ctx = crypto_ahash_ctx(ahash);
1728 struct device *dev = drvdata_to_dev(ctx->drvdata);
1729 struct ahash_req_ctx *state = ahash_request_ctx(req); 1511 struct ahash_req_ctx *state = ahash_request_ctx(req);
1730 u8 *curr_buff = state->buff_index ? state->buff1 : state->buff0; 1512 u8 *curr_buff = cc_hash_buf(state);
1731 u32 curr_buff_cnt = state->buff_index ? state->buff1_cnt : 1513 u32 curr_buff_cnt = *cc_hash_buf_cnt(state);
1732 state->buff0_cnt;
1733 const u32 tmp = CC_EXPORT_MAGIC; 1514 const u32 tmp = CC_EXPORT_MAGIC;
1734 1515
1735 memcpy(out, &tmp, sizeof(u32)); 1516 memcpy(out, &tmp, sizeof(u32));
1736 out += sizeof(u32); 1517 out += sizeof(u32);
1737 1518
1738 dma_sync_single_for_cpu(dev, state->digest_buff_dma_addr,
1739 ctx->inter_digestsize, DMA_BIDIRECTIONAL);
1740 memcpy(out, state->digest_buff, ctx->inter_digestsize); 1519 memcpy(out, state->digest_buff, ctx->inter_digestsize);
1741 out += ctx->inter_digestsize; 1520 out += ctx->inter_digestsize;
1742 1521
1743 if (state->digest_bytes_len_dma_addr) { 1522 memcpy(out, state->digest_bytes_len, HASH_LEN_SIZE);
1744 dma_sync_single_for_cpu(dev, state->digest_bytes_len_dma_addr,
1745 HASH_LEN_SIZE, DMA_BIDIRECTIONAL);
1746 memcpy(out, state->digest_bytes_len, HASH_LEN_SIZE);
1747 } else {
1748 /* Poison the unused exported digest len field. */
1749 memset(out, 0x5F, HASH_LEN_SIZE);
1750 }
1751 out += HASH_LEN_SIZE; 1523 out += HASH_LEN_SIZE;
1752 1524
1753 memcpy(out, &curr_buff_cnt, sizeof(u32)); 1525 memcpy(out, &curr_buff_cnt, sizeof(u32));
@@ -1755,80 +1527,43 @@ static int ssi_ahash_export(struct ahash_request *req, void *out)
1755 1527
1756 memcpy(out, curr_buff, curr_buff_cnt); 1528 memcpy(out, curr_buff, curr_buff_cnt);
1757 1529
1758 /* No sync for device ineeded since we did not change the data,
1759 * we only copy it
1760 */
1761
1762 return 0; 1530 return 0;
1763} 1531}
1764 1532
1765static int ssi_ahash_import(struct ahash_request *req, const void *in) 1533static int cc_hash_import(struct ahash_request *req, const void *in)
1766{ 1534{
1767 struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); 1535 struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
1768 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(ahash); 1536 struct cc_hash_ctx *ctx = crypto_ahash_ctx(ahash);
1769 struct device *dev = drvdata_to_dev(ctx->drvdata); 1537 struct device *dev = drvdata_to_dev(ctx->drvdata);
1770 struct ahash_req_ctx *state = ahash_request_ctx(req); 1538 struct ahash_req_ctx *state = ahash_request_ctx(req);
1771 u32 tmp; 1539 u32 tmp;
1772 int rc = 0;
1773 1540
1774 memcpy(&tmp, in, sizeof(u32)); 1541 memcpy(&tmp, in, sizeof(u32));
1775 if (tmp != CC_EXPORT_MAGIC) { 1542 if (tmp != CC_EXPORT_MAGIC)
1776 rc = -EINVAL; 1543 return -EINVAL;
1777 goto out;
1778 }
1779 in += sizeof(u32); 1544 in += sizeof(u32);
1780 1545
1781 /* call init() to allocate bufs if the user hasn't */ 1546 cc_init_req(dev, state, ctx);
1782 if (!state->digest_buff) {
1783 rc = ssi_hash_init(state, ctx);
1784 if (rc)
1785 goto out;
1786 }
1787 1547
1788 dma_sync_single_for_cpu(dev, state->digest_buff_dma_addr,
1789 ctx->inter_digestsize, DMA_BIDIRECTIONAL);
1790 memcpy(state->digest_buff, in, ctx->inter_digestsize); 1548 memcpy(state->digest_buff, in, ctx->inter_digestsize);
1791 in += ctx->inter_digestsize; 1549 in += ctx->inter_digestsize;
1792 1550
1793 if (state->digest_bytes_len_dma_addr) { 1551 memcpy(state->digest_bytes_len, in, HASH_LEN_SIZE);
1794 dma_sync_single_for_cpu(dev, state->digest_bytes_len_dma_addr,
1795 HASH_LEN_SIZE, DMA_BIDIRECTIONAL);
1796 memcpy(state->digest_bytes_len, in, HASH_LEN_SIZE);
1797 }
1798 in += HASH_LEN_SIZE; 1552 in += HASH_LEN_SIZE;
1799 1553
1800 dma_sync_single_for_device(dev, state->digest_buff_dma_addr,
1801 ctx->inter_digestsize, DMA_BIDIRECTIONAL);
1802
1803 if (state->digest_bytes_len_dma_addr)
1804 dma_sync_single_for_device(dev,
1805 state->digest_bytes_len_dma_addr,
1806 HASH_LEN_SIZE, DMA_BIDIRECTIONAL);
1807
1808 state->buff_index = 0;
1809
1810 /* Sanity check the data as much as possible */ 1554 /* Sanity check the data as much as possible */
1811 memcpy(&tmp, in, sizeof(u32)); 1555 memcpy(&tmp, in, sizeof(u32));
1812 if (tmp > SSI_MAX_HASH_BLCK_SIZE) { 1556 if (tmp > CC_MAX_HASH_BLCK_SIZE)
1813 rc = -EINVAL; 1557 return -EINVAL;
1814 goto out;
1815 }
1816 in += sizeof(u32); 1558 in += sizeof(u32);
1817 1559
1818 state->buff0_cnt = tmp; 1560 state->buf_cnt[0] = tmp;
1819 memcpy(state->buff0, in, state->buff0_cnt); 1561 memcpy(state->buffers[0], in, tmp);
1820
1821out:
1822 return rc;
1823}
1824 1562
1825static int ssi_ahash_setkey(struct crypto_ahash *ahash, 1563 return 0;
1826 const u8 *key, unsigned int keylen)
1827{
1828 return ssi_hash_setkey((void *)ahash, key, keylen, false);
1829} 1564}
1830 1565
1831struct ssi_hash_template { 1566struct cc_hash_template {
1832 char name[CRYPTO_MAX_ALG_NAME]; 1567 char name[CRYPTO_MAX_ALG_NAME];
1833 char driver_name[CRYPTO_MAX_ALG_NAME]; 1568 char driver_name[CRYPTO_MAX_ALG_NAME];
1834 char mac_name[CRYPTO_MAX_ALG_NAME]; 1569 char mac_name[CRYPTO_MAX_ALG_NAME];
@@ -1839,14 +1574,14 @@ struct ssi_hash_template {
1839 int hash_mode; 1574 int hash_mode;
1840 int hw_mode; 1575 int hw_mode;
1841 int inter_digestsize; 1576 int inter_digestsize;
1842 struct ssi_drvdata *drvdata; 1577 struct cc_drvdata *drvdata;
1843}; 1578};
1844 1579
1845#define CC_STATE_SIZE(_x) \ 1580#define CC_STATE_SIZE(_x) \
1846 ((_x) + HASH_LEN_SIZE + SSI_MAX_HASH_BLCK_SIZE + (2 * sizeof(u32))) 1581 ((_x) + HASH_LEN_SIZE + CC_MAX_HASH_BLCK_SIZE + (2 * sizeof(u32)))
1847 1582
1848/* hash descriptors */ 1583/* hash descriptors */
1849static struct ssi_hash_template driver_hash[] = { 1584static struct cc_hash_template driver_hash[] = {
1850 //Asynchronize hash template 1585 //Asynchronize hash template
1851 { 1586 {
1852 .name = "sha1", 1587 .name = "sha1",
@@ -1856,14 +1591,14 @@ static struct ssi_hash_template driver_hash[] = {
1856 .blocksize = SHA1_BLOCK_SIZE, 1591 .blocksize = SHA1_BLOCK_SIZE,
1857 .synchronize = false, 1592 .synchronize = false,
1858 .template_ahash = { 1593 .template_ahash = {
1859 .init = ssi_ahash_init, 1594 .init = cc_hash_init,
1860 .update = ssi_ahash_update, 1595 .update = cc_hash_update,
1861 .final = ssi_ahash_final, 1596 .final = cc_hash_final,
1862 .finup = ssi_ahash_finup, 1597 .finup = cc_hash_finup,
1863 .digest = ssi_ahash_digest, 1598 .digest = cc_hash_digest,
1864 .export = ssi_ahash_export, 1599 .export = cc_hash_export,
1865 .import = ssi_ahash_import, 1600 .import = cc_hash_import,
1866 .setkey = ssi_ahash_setkey, 1601 .setkey = cc_hash_setkey,
1867 .halg = { 1602 .halg = {
1868 .digestsize = SHA1_DIGEST_SIZE, 1603 .digestsize = SHA1_DIGEST_SIZE,
1869 .statesize = CC_STATE_SIZE(SHA1_DIGEST_SIZE), 1604 .statesize = CC_STATE_SIZE(SHA1_DIGEST_SIZE),
@@ -1880,14 +1615,14 @@ static struct ssi_hash_template driver_hash[] = {
1880 .mac_driver_name = "hmac-sha256-dx", 1615 .mac_driver_name = "hmac-sha256-dx",
1881 .blocksize = SHA256_BLOCK_SIZE, 1616 .blocksize = SHA256_BLOCK_SIZE,
1882 .template_ahash = { 1617 .template_ahash = {
1883 .init = ssi_ahash_init, 1618 .init = cc_hash_init,
1884 .update = ssi_ahash_update, 1619 .update = cc_hash_update,
1885 .final = ssi_ahash_final, 1620 .final = cc_hash_final,
1886 .finup = ssi_ahash_finup, 1621 .finup = cc_hash_finup,
1887 .digest = ssi_ahash_digest, 1622 .digest = cc_hash_digest,
1888 .export = ssi_ahash_export, 1623 .export = cc_hash_export,
1889 .import = ssi_ahash_import, 1624 .import = cc_hash_import,
1890 .setkey = ssi_ahash_setkey, 1625 .setkey = cc_hash_setkey,
1891 .halg = { 1626 .halg = {
1892 .digestsize = SHA256_DIGEST_SIZE, 1627 .digestsize = SHA256_DIGEST_SIZE,
1893 .statesize = CC_STATE_SIZE(SHA256_DIGEST_SIZE) 1628 .statesize = CC_STATE_SIZE(SHA256_DIGEST_SIZE)
@@ -1904,14 +1639,14 @@ static struct ssi_hash_template driver_hash[] = {
1904 .mac_driver_name = "hmac-sha224-dx", 1639 .mac_driver_name = "hmac-sha224-dx",
1905 .blocksize = SHA224_BLOCK_SIZE, 1640 .blocksize = SHA224_BLOCK_SIZE,
1906 .template_ahash = { 1641 .template_ahash = {
1907 .init = ssi_ahash_init, 1642 .init = cc_hash_init,
1908 .update = ssi_ahash_update, 1643 .update = cc_hash_update,
1909 .final = ssi_ahash_final, 1644 .final = cc_hash_final,
1910 .finup = ssi_ahash_finup, 1645 .finup = cc_hash_finup,
1911 .digest = ssi_ahash_digest, 1646 .digest = cc_hash_digest,
1912 .export = ssi_ahash_export, 1647 .export = cc_hash_export,
1913 .import = ssi_ahash_import, 1648 .import = cc_hash_import,
1914 .setkey = ssi_ahash_setkey, 1649 .setkey = cc_hash_setkey,
1915 .halg = { 1650 .halg = {
1916 .digestsize = SHA224_DIGEST_SIZE, 1651 .digestsize = SHA224_DIGEST_SIZE,
1917 .statesize = CC_STATE_SIZE(SHA224_DIGEST_SIZE), 1652 .statesize = CC_STATE_SIZE(SHA224_DIGEST_SIZE),
@@ -1921,7 +1656,7 @@ static struct ssi_hash_template driver_hash[] = {
1921 .hw_mode = DRV_HASH_HW_SHA256, 1656 .hw_mode = DRV_HASH_HW_SHA256,
1922 .inter_digestsize = SHA256_DIGEST_SIZE, 1657 .inter_digestsize = SHA256_DIGEST_SIZE,
1923 }, 1658 },
1924#if (DX_DEV_SHA_MAX > 256) 1659#if (CC_DEV_SHA_MAX > 256)
1925 { 1660 {
1926 .name = "sha384", 1661 .name = "sha384",
1927 .driver_name = "sha384-dx", 1662 .driver_name = "sha384-dx",
@@ -1929,14 +1664,14 @@ static struct ssi_hash_template driver_hash[] = {
1929 .mac_driver_name = "hmac-sha384-dx", 1664 .mac_driver_name = "hmac-sha384-dx",
1930 .blocksize = SHA384_BLOCK_SIZE, 1665 .blocksize = SHA384_BLOCK_SIZE,
1931 .template_ahash = { 1666 .template_ahash = {
1932 .init = ssi_ahash_init, 1667 .init = cc_hash_init,
1933 .update = ssi_ahash_update, 1668 .update = cc_hash_update,
1934 .final = ssi_ahash_final, 1669 .final = cc_hash_final,
1935 .finup = ssi_ahash_finup, 1670 .finup = cc_hash_finup,
1936 .digest = ssi_ahash_digest, 1671 .digest = cc_hash_digest,
1937 .export = ssi_ahash_export, 1672 .export = cc_hash_export,
1938 .import = ssi_ahash_import, 1673 .import = cc_hash_import,
1939 .setkey = ssi_ahash_setkey, 1674 .setkey = cc_hash_setkey,
1940 .halg = { 1675 .halg = {
1941 .digestsize = SHA384_DIGEST_SIZE, 1676 .digestsize = SHA384_DIGEST_SIZE,
1942 .statesize = CC_STATE_SIZE(SHA384_DIGEST_SIZE), 1677 .statesize = CC_STATE_SIZE(SHA384_DIGEST_SIZE),
@@ -1953,14 +1688,14 @@ static struct ssi_hash_template driver_hash[] = {
1953 .mac_driver_name = "hmac-sha512-dx", 1688 .mac_driver_name = "hmac-sha512-dx",
1954 .blocksize = SHA512_BLOCK_SIZE, 1689 .blocksize = SHA512_BLOCK_SIZE,
1955 .template_ahash = { 1690 .template_ahash = {
1956 .init = ssi_ahash_init, 1691 .init = cc_hash_init,
1957 .update = ssi_ahash_update, 1692 .update = cc_hash_update,
1958 .final = ssi_ahash_final, 1693 .final = cc_hash_final,
1959 .finup = ssi_ahash_finup, 1694 .finup = cc_hash_finup,
1960 .digest = ssi_ahash_digest, 1695 .digest = cc_hash_digest,
1961 .export = ssi_ahash_export, 1696 .export = cc_hash_export,
1962 .import = ssi_ahash_import, 1697 .import = cc_hash_import,
1963 .setkey = ssi_ahash_setkey, 1698 .setkey = cc_hash_setkey,
1964 .halg = { 1699 .halg = {
1965 .digestsize = SHA512_DIGEST_SIZE, 1700 .digestsize = SHA512_DIGEST_SIZE,
1966 .statesize = CC_STATE_SIZE(SHA512_DIGEST_SIZE), 1701 .statesize = CC_STATE_SIZE(SHA512_DIGEST_SIZE),
@@ -1978,14 +1713,14 @@ static struct ssi_hash_template driver_hash[] = {
1978 .mac_driver_name = "hmac-md5-dx", 1713 .mac_driver_name = "hmac-md5-dx",
1979 .blocksize = MD5_HMAC_BLOCK_SIZE, 1714 .blocksize = MD5_HMAC_BLOCK_SIZE,
1980 .template_ahash = { 1715 .template_ahash = {
1981 .init = ssi_ahash_init, 1716 .init = cc_hash_init,
1982 .update = ssi_ahash_update, 1717 .update = cc_hash_update,
1983 .final = ssi_ahash_final, 1718 .final = cc_hash_final,
1984 .finup = ssi_ahash_finup, 1719 .finup = cc_hash_finup,
1985 .digest = ssi_ahash_digest, 1720 .digest = cc_hash_digest,
1986 .export = ssi_ahash_export, 1721 .export = cc_hash_export,
1987 .import = ssi_ahash_import, 1722 .import = cc_hash_import,
1988 .setkey = ssi_ahash_setkey, 1723 .setkey = cc_hash_setkey,
1989 .halg = { 1724 .halg = {
1990 .digestsize = MD5_DIGEST_SIZE, 1725 .digestsize = MD5_DIGEST_SIZE,
1991 .statesize = CC_STATE_SIZE(MD5_DIGEST_SIZE), 1726 .statesize = CC_STATE_SIZE(MD5_DIGEST_SIZE),
@@ -2000,14 +1735,14 @@ static struct ssi_hash_template driver_hash[] = {
2000 .mac_driver_name = "xcbc-aes-dx", 1735 .mac_driver_name = "xcbc-aes-dx",
2001 .blocksize = AES_BLOCK_SIZE, 1736 .blocksize = AES_BLOCK_SIZE,
2002 .template_ahash = { 1737 .template_ahash = {
2003 .init = ssi_ahash_init, 1738 .init = cc_hash_init,
2004 .update = ssi_mac_update, 1739 .update = cc_mac_update,
2005 .final = ssi_mac_final, 1740 .final = cc_mac_final,
2006 .finup = ssi_mac_finup, 1741 .finup = cc_mac_finup,
2007 .digest = ssi_mac_digest, 1742 .digest = cc_mac_digest,
2008 .setkey = ssi_xcbc_setkey, 1743 .setkey = cc_xcbc_setkey,
2009 .export = ssi_ahash_export, 1744 .export = cc_hash_export,
2010 .import = ssi_ahash_import, 1745 .import = cc_hash_import,
2011 .halg = { 1746 .halg = {
2012 .digestsize = AES_BLOCK_SIZE, 1747 .digestsize = AES_BLOCK_SIZE,
2013 .statesize = CC_STATE_SIZE(AES_BLOCK_SIZE), 1748 .statesize = CC_STATE_SIZE(AES_BLOCK_SIZE),
@@ -2017,20 +1752,19 @@ static struct ssi_hash_template driver_hash[] = {
2017 .hw_mode = DRV_CIPHER_XCBC_MAC, 1752 .hw_mode = DRV_CIPHER_XCBC_MAC,
2018 .inter_digestsize = AES_BLOCK_SIZE, 1753 .inter_digestsize = AES_BLOCK_SIZE,
2019 }, 1754 },
2020#if SSI_CC_HAS_CMAC
2021 { 1755 {
2022 .mac_name = "cmac(aes)", 1756 .mac_name = "cmac(aes)",
2023 .mac_driver_name = "cmac-aes-dx", 1757 .mac_driver_name = "cmac-aes-dx",
2024 .blocksize = AES_BLOCK_SIZE, 1758 .blocksize = AES_BLOCK_SIZE,
2025 .template_ahash = { 1759 .template_ahash = {
2026 .init = ssi_ahash_init, 1760 .init = cc_hash_init,
2027 .update = ssi_mac_update, 1761 .update = cc_mac_update,
2028 .final = ssi_mac_final, 1762 .final = cc_mac_final,
2029 .finup = ssi_mac_finup, 1763 .finup = cc_mac_finup,
2030 .digest = ssi_mac_digest, 1764 .digest = cc_mac_digest,
2031 .setkey = ssi_cmac_setkey, 1765 .setkey = cc_cmac_setkey,
2032 .export = ssi_ahash_export, 1766 .export = cc_hash_export,
2033 .import = ssi_ahash_import, 1767 .import = cc_hash_import,
2034 .halg = { 1768 .halg = {
2035 .digestsize = AES_BLOCK_SIZE, 1769 .digestsize = AES_BLOCK_SIZE,
2036 .statesize = CC_STATE_SIZE(AES_BLOCK_SIZE), 1770 .statesize = CC_STATE_SIZE(AES_BLOCK_SIZE),
@@ -2040,15 +1774,12 @@ static struct ssi_hash_template driver_hash[] = {
2040 .hw_mode = DRV_CIPHER_CMAC, 1774 .hw_mode = DRV_CIPHER_CMAC,
2041 .inter_digestsize = AES_BLOCK_SIZE, 1775 .inter_digestsize = AES_BLOCK_SIZE,
2042 }, 1776 },
2043#endif
2044
2045}; 1777};
2046 1778
2047static struct ssi_hash_alg * 1779static struct cc_hash_alg *cc_alloc_hash_alg(struct cc_hash_template *template,
2048ssi_hash_create_alg(struct ssi_hash_template *template, struct device *dev, 1780 struct device *dev, bool keyed)
2049 bool keyed)
2050{ 1781{
2051 struct ssi_hash_alg *t_crypto_alg; 1782 struct cc_hash_alg *t_crypto_alg;
2052 struct crypto_alg *alg; 1783 struct crypto_alg *alg;
2053 struct ahash_alg *halg; 1784 struct ahash_alg *halg;
2054 1785
@@ -2056,7 +1787,6 @@ ssi_hash_create_alg(struct ssi_hash_template *template, struct device *dev,
2056 if (!t_crypto_alg) 1787 if (!t_crypto_alg)
2057 return ERR_PTR(-ENOMEM); 1788 return ERR_PTR(-ENOMEM);
2058 1789
2059
2060 t_crypto_alg->ahash_alg = template->template_ahash; 1790 t_crypto_alg->ahash_alg = template->template_ahash;
2061 halg = &t_crypto_alg->ahash_alg; 1791 halg = &t_crypto_alg->ahash_alg;
2062 alg = &halg->halg.base; 1792 alg = &halg->halg.base;
@@ -2074,13 +1804,13 @@ ssi_hash_create_alg(struct ssi_hash_template *template, struct device *dev,
2074 template->driver_name); 1804 template->driver_name);
2075 } 1805 }
2076 alg->cra_module = THIS_MODULE; 1806 alg->cra_module = THIS_MODULE;
2077 alg->cra_ctxsize = sizeof(struct ssi_hash_ctx); 1807 alg->cra_ctxsize = sizeof(struct cc_hash_ctx);
2078 alg->cra_priority = SSI_CRA_PRIO; 1808 alg->cra_priority = CC_CRA_PRIO;
2079 alg->cra_blocksize = template->blocksize; 1809 alg->cra_blocksize = template->blocksize;
2080 alg->cra_alignmask = 0; 1810 alg->cra_alignmask = 0;
2081 alg->cra_exit = ssi_hash_cra_exit; 1811 alg->cra_exit = cc_cra_exit;
2082 1812
2083 alg->cra_init = ssi_ahash_cra_init; 1813 alg->cra_init = cc_cra_init;
2084 alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_TYPE_AHASH | 1814 alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_TYPE_AHASH |
2085 CRYPTO_ALG_KERN_DRIVER_ONLY; 1815 CRYPTO_ALG_KERN_DRIVER_ONLY;
2086 alg->cra_type = &crypto_ahash_type; 1816 alg->cra_type = &crypto_ahash_type;
@@ -2092,36 +1822,32 @@ ssi_hash_create_alg(struct ssi_hash_template *template, struct device *dev,
2092 return t_crypto_alg; 1822 return t_crypto_alg;
2093} 1823}
2094 1824
2095int ssi_hash_init_sram_digest_consts(struct ssi_drvdata *drvdata) 1825int cc_init_hash_sram(struct cc_drvdata *drvdata)
2096{ 1826{
2097 struct ssi_hash_handle *hash_handle = drvdata->hash_handle; 1827 struct cc_hash_handle *hash_handle = drvdata->hash_handle;
2098 ssi_sram_addr_t sram_buff_ofs = hash_handle->digest_len_sram_addr; 1828 cc_sram_addr_t sram_buff_ofs = hash_handle->digest_len_sram_addr;
2099 unsigned int larval_seq_len = 0; 1829 unsigned int larval_seq_len = 0;
2100 struct cc_hw_desc larval_seq[CC_DIGEST_SIZE_MAX / sizeof(u32)]; 1830 struct cc_hw_desc larval_seq[CC_DIGEST_SIZE_MAX / sizeof(u32)];
2101 struct device *dev = drvdata_to_dev(drvdata);
2102 int rc = 0; 1831 int rc = 0;
2103#if (DX_DEV_SHA_MAX > 256)
2104 int i;
2105#endif
2106 1832
2107 /* Copy-to-sram digest-len */ 1833 /* Copy-to-sram digest-len */
2108 ssi_sram_mgr_const2sram_desc(digest_len_init, sram_buff_ofs, 1834 cc_set_sram_desc(digest_len_init, sram_buff_ofs,
2109 ARRAY_SIZE(digest_len_init), 1835 ARRAY_SIZE(digest_len_init), larval_seq,
2110 larval_seq, &larval_seq_len); 1836 &larval_seq_len);
2111 rc = send_request_init(drvdata, larval_seq, larval_seq_len); 1837 rc = send_request_init(drvdata, larval_seq, larval_seq_len);
2112 if (unlikely(rc != 0)) 1838 if (rc)
2113 goto init_digest_const_err; 1839 goto init_digest_const_err;
2114 1840
2115 sram_buff_ofs += sizeof(digest_len_init); 1841 sram_buff_ofs += sizeof(digest_len_init);
2116 larval_seq_len = 0; 1842 larval_seq_len = 0;
2117 1843
2118#if (DX_DEV_SHA_MAX > 256) 1844#if (CC_DEV_SHA_MAX > 256)
2119 /* Copy-to-sram digest-len for sha384/512 */ 1845 /* Copy-to-sram digest-len for sha384/512 */
2120 ssi_sram_mgr_const2sram_desc(digest_len_sha512_init, sram_buff_ofs, 1846 cc_set_sram_desc(digest_len_sha512_init, sram_buff_ofs,
2121 ARRAY_SIZE(digest_len_sha512_init), 1847 ARRAY_SIZE(digest_len_sha512_init),
2122 larval_seq, &larval_seq_len); 1848 larval_seq, &larval_seq_len);
2123 rc = send_request_init(drvdata, larval_seq, larval_seq_len); 1849 rc = send_request_init(drvdata, larval_seq, larval_seq_len);
2124 if (unlikely(rc != 0)) 1850 if (rc)
2125 goto init_digest_const_err; 1851 goto init_digest_const_err;
2126 1852
2127 sram_buff_ofs += sizeof(digest_len_sha512_init); 1853 sram_buff_ofs += sizeof(digest_len_sha512_init);
@@ -2132,88 +1858,89 @@ int ssi_hash_init_sram_digest_consts(struct ssi_drvdata *drvdata)
2132 hash_handle->larval_digest_sram_addr = sram_buff_ofs; 1858 hash_handle->larval_digest_sram_addr = sram_buff_ofs;
2133 1859
2134 /* Copy-to-sram initial SHA* digests */ 1860 /* Copy-to-sram initial SHA* digests */
2135 ssi_sram_mgr_const2sram_desc(md5_init, sram_buff_ofs, 1861 cc_set_sram_desc(md5_init, sram_buff_ofs, ARRAY_SIZE(md5_init),
2136 ARRAY_SIZE(md5_init), larval_seq, 1862 larval_seq, &larval_seq_len);
2137 &larval_seq_len);
2138 rc = send_request_init(drvdata, larval_seq, larval_seq_len); 1863 rc = send_request_init(drvdata, larval_seq, larval_seq_len);
2139 if (unlikely(rc != 0)) 1864 if (rc)
2140 goto init_digest_const_err; 1865 goto init_digest_const_err;
2141 sram_buff_ofs += sizeof(md5_init); 1866 sram_buff_ofs += sizeof(md5_init);
2142 larval_seq_len = 0; 1867 larval_seq_len = 0;
2143 1868
2144 ssi_sram_mgr_const2sram_desc(sha1_init, sram_buff_ofs, 1869 cc_set_sram_desc(sha1_init, sram_buff_ofs,
2145 ARRAY_SIZE(sha1_init), larval_seq, 1870 ARRAY_SIZE(sha1_init), larval_seq,
2146 &larval_seq_len); 1871 &larval_seq_len);
2147 rc = send_request_init(drvdata, larval_seq, larval_seq_len); 1872 rc = send_request_init(drvdata, larval_seq, larval_seq_len);
2148 if (unlikely(rc != 0)) 1873 if (rc)
2149 goto init_digest_const_err; 1874 goto init_digest_const_err;
2150 sram_buff_ofs += sizeof(sha1_init); 1875 sram_buff_ofs += sizeof(sha1_init);
2151 larval_seq_len = 0; 1876 larval_seq_len = 0;
2152 1877
2153 ssi_sram_mgr_const2sram_desc(sha224_init, sram_buff_ofs, 1878 cc_set_sram_desc(sha224_init, sram_buff_ofs,
2154 ARRAY_SIZE(sha224_init), larval_seq, 1879 ARRAY_SIZE(sha224_init), larval_seq,
2155 &larval_seq_len); 1880 &larval_seq_len);
2156 rc = send_request_init(drvdata, larval_seq, larval_seq_len); 1881 rc = send_request_init(drvdata, larval_seq, larval_seq_len);
2157 if (unlikely(rc != 0)) 1882 if (rc)
2158 goto init_digest_const_err; 1883 goto init_digest_const_err;
2159 sram_buff_ofs += sizeof(sha224_init); 1884 sram_buff_ofs += sizeof(sha224_init);
2160 larval_seq_len = 0; 1885 larval_seq_len = 0;
2161 1886
2162 ssi_sram_mgr_const2sram_desc(sha256_init, sram_buff_ofs, 1887 cc_set_sram_desc(sha256_init, sram_buff_ofs,
2163 ARRAY_SIZE(sha256_init), larval_seq, 1888 ARRAY_SIZE(sha256_init), larval_seq,
2164 &larval_seq_len); 1889 &larval_seq_len);
2165 rc = send_request_init(drvdata, larval_seq, larval_seq_len); 1890 rc = send_request_init(drvdata, larval_seq, larval_seq_len);
2166 if (unlikely(rc != 0)) 1891 if (rc)
2167 goto init_digest_const_err; 1892 goto init_digest_const_err;
2168 sram_buff_ofs += sizeof(sha256_init); 1893 sram_buff_ofs += sizeof(sha256_init);
2169 larval_seq_len = 0; 1894 larval_seq_len = 0;
2170 1895
2171#if (DX_DEV_SHA_MAX > 256) 1896#if (CC_DEV_SHA_MAX > 256)
2172 /* We are forced to swap each double-word larval before copying to sram */ 1897 cc_set_sram_desc((u32 *)sha384_init, sram_buff_ofs,
2173 for (i = 0; i < ARRAY_SIZE(sha384_init); i++) { 1898 (ARRAY_SIZE(sha384_init) * 2), larval_seq,
2174 const u32 const0 = ((u32 *)((u64 *)&sha384_init[i]))[1]; 1899 &larval_seq_len);
2175 const u32 const1 = ((u32 *)((u64 *)&sha384_init[i]))[0];
2176
2177 ssi_sram_mgr_const2sram_desc(&const0, sram_buff_ofs, 1,
2178 larval_seq, &larval_seq_len);
2179 sram_buff_ofs += sizeof(u32);
2180 ssi_sram_mgr_const2sram_desc(&const1, sram_buff_ofs, 1,
2181 larval_seq, &larval_seq_len);
2182 sram_buff_ofs += sizeof(u32);
2183 }
2184 rc = send_request_init(drvdata, larval_seq, larval_seq_len); 1900 rc = send_request_init(drvdata, larval_seq, larval_seq_len);
2185 if (unlikely(rc != 0)) { 1901 if (rc)
2186 dev_err(dev, "send_request() failed (rc = %d)\n", rc);
2187 goto init_digest_const_err; 1902 goto init_digest_const_err;
2188 } 1903 sram_buff_ofs += sizeof(sha384_init);
2189 larval_seq_len = 0; 1904 larval_seq_len = 0;
2190 1905
2191 for (i = 0; i < ARRAY_SIZE(sha512_init); i++) { 1906 cc_set_sram_desc((u32 *)sha512_init, sram_buff_ofs,
2192 const u32 const0 = ((u32 *)((u64 *)&sha512_init[i]))[1]; 1907 (ARRAY_SIZE(sha512_init) * 2), larval_seq,
2193 const u32 const1 = ((u32 *)((u64 *)&sha512_init[i]))[0]; 1908 &larval_seq_len);
2194
2195 ssi_sram_mgr_const2sram_desc(&const0, sram_buff_ofs, 1,
2196 larval_seq, &larval_seq_len);
2197 sram_buff_ofs += sizeof(u32);
2198 ssi_sram_mgr_const2sram_desc(&const1, sram_buff_ofs, 1,
2199 larval_seq, &larval_seq_len);
2200 sram_buff_ofs += sizeof(u32);
2201 }
2202 rc = send_request_init(drvdata, larval_seq, larval_seq_len); 1909 rc = send_request_init(drvdata, larval_seq, larval_seq_len);
2203 if (unlikely(rc != 0)) { 1910 if (rc)
2204 dev_err(dev, "send_request() failed (rc = %d)\n", rc);
2205 goto init_digest_const_err; 1911 goto init_digest_const_err;
2206 }
2207#endif 1912#endif
2208 1913
2209init_digest_const_err: 1914init_digest_const_err:
2210 return rc; 1915 return rc;
2211} 1916}
2212 1917
2213int ssi_hash_alloc(struct ssi_drvdata *drvdata) 1918static void __init cc_swap_dwords(u32 *buf, unsigned long size)
2214{ 1919{
2215 struct ssi_hash_handle *hash_handle; 1920 int i;
2216 ssi_sram_addr_t sram_buff; 1921 u32 tmp;
1922
1923 for (i = 0; i < size; i += 2) {
1924 tmp = buf[i];
1925 buf[i] = buf[i + 1];
1926 buf[i + 1] = tmp;
1927 }
1928}
1929
1930/*
1931 * Due to the way the HW works we need to swap every
1932 * double word in the SHA384 and SHA512 larval hashes
1933 */
1934void __init cc_hash_global_init(void)
1935{
1936 cc_swap_dwords((u32 *)&sha384_init, (ARRAY_SIZE(sha384_init) * 2));
1937 cc_swap_dwords((u32 *)&sha512_init, (ARRAY_SIZE(sha512_init) * 2));
1938}
1939
1940int cc_hash_alloc(struct cc_drvdata *drvdata)
1941{
1942 struct cc_hash_handle *hash_handle;
1943 cc_sram_addr_t sram_buff;
2217 u32 sram_size_to_alloc; 1944 u32 sram_size_to_alloc;
2218 struct device *dev = drvdata_to_dev(drvdata); 1945 struct device *dev = drvdata_to_dev(drvdata);
2219 int rc = 0; 1946 int rc = 0;
@@ -2227,7 +1954,7 @@ int ssi_hash_alloc(struct ssi_drvdata *drvdata)
2227 drvdata->hash_handle = hash_handle; 1954 drvdata->hash_handle = hash_handle;
2228 1955
2229 sram_size_to_alloc = sizeof(digest_len_init) + 1956 sram_size_to_alloc = sizeof(digest_len_init) +
2230#if (DX_DEV_SHA_MAX > 256) 1957#if (CC_DEV_SHA_MAX > 256)
2231 sizeof(digest_len_sha512_init) + 1958 sizeof(digest_len_sha512_init) +
2232 sizeof(sha384_init) + 1959 sizeof(sha384_init) +
2233 sizeof(sha512_init) + 1960 sizeof(sha512_init) +
@@ -2237,7 +1964,7 @@ int ssi_hash_alloc(struct ssi_drvdata *drvdata)
2237 sizeof(sha224_init) + 1964 sizeof(sha224_init) +
2238 sizeof(sha256_init); 1965 sizeof(sha256_init);
2239 1966
2240 sram_buff = ssi_sram_mgr_alloc(drvdata, sram_size_to_alloc); 1967 sram_buff = cc_sram_alloc(drvdata, sram_size_to_alloc);
2241 if (sram_buff == NULL_SRAM_ADDR) { 1968 if (sram_buff == NULL_SRAM_ADDR) {
2242 dev_err(dev, "SRAM pool exhausted\n"); 1969 dev_err(dev, "SRAM pool exhausted\n");
2243 rc = -ENOMEM; 1970 rc = -ENOMEM;
@@ -2248,19 +1975,19 @@ int ssi_hash_alloc(struct ssi_drvdata *drvdata)
2248 hash_handle->digest_len_sram_addr = sram_buff; 1975 hash_handle->digest_len_sram_addr = sram_buff;
2249 1976
2250 /*must be set before the alg registration as it is being used there*/ 1977 /*must be set before the alg registration as it is being used there*/
2251 rc = ssi_hash_init_sram_digest_consts(drvdata); 1978 rc = cc_init_hash_sram(drvdata);
2252 if (unlikely(rc != 0)) { 1979 if (rc) {
2253 dev_err(dev, "Init digest CONST failed (rc=%d)\n", rc); 1980 dev_err(dev, "Init digest CONST failed (rc=%d)\n", rc);
2254 goto fail; 1981 goto fail;
2255 } 1982 }
2256 1983
2257 /* ahash registration */ 1984 /* ahash registration */
2258 for (alg = 0; alg < ARRAY_SIZE(driver_hash); alg++) { 1985 for (alg = 0; alg < ARRAY_SIZE(driver_hash); alg++) {
2259 struct ssi_hash_alg *t_alg; 1986 struct cc_hash_alg *t_alg;
2260 int hw_mode = driver_hash[alg].hw_mode; 1987 int hw_mode = driver_hash[alg].hw_mode;
2261 1988
2262 /* register hmac version */ 1989 /* register hmac version */
2263 t_alg = ssi_hash_create_alg(&driver_hash[alg], dev, true); 1990 t_alg = cc_alloc_hash_alg(&driver_hash[alg], dev, true);
2264 if (IS_ERR(t_alg)) { 1991 if (IS_ERR(t_alg)) {
2265 rc = PTR_ERR(t_alg); 1992 rc = PTR_ERR(t_alg);
2266 dev_err(dev, "%s alg allocation failed\n", 1993 dev_err(dev, "%s alg allocation failed\n",
@@ -2270,22 +1997,21 @@ int ssi_hash_alloc(struct ssi_drvdata *drvdata)
2270 t_alg->drvdata = drvdata; 1997 t_alg->drvdata = drvdata;
2271 1998
2272 rc = crypto_register_ahash(&t_alg->ahash_alg); 1999 rc = crypto_register_ahash(&t_alg->ahash_alg);
2273 if (unlikely(rc)) { 2000 if (rc) {
2274 dev_err(dev, "%s alg registration failed\n", 2001 dev_err(dev, "%s alg registration failed\n",
2275 driver_hash[alg].driver_name); 2002 driver_hash[alg].driver_name);
2276 kfree(t_alg); 2003 kfree(t_alg);
2277 goto fail; 2004 goto fail;
2278 } else { 2005 } else {
2279 list_add_tail(&t_alg->entry, 2006 list_add_tail(&t_alg->entry, &hash_handle->hash_list);
2280 &hash_handle->hash_list);
2281 } 2007 }
2282 2008
2283 if ((hw_mode == DRV_CIPHER_XCBC_MAC) || 2009 if (hw_mode == DRV_CIPHER_XCBC_MAC ||
2284 (hw_mode == DRV_CIPHER_CMAC)) 2010 hw_mode == DRV_CIPHER_CMAC)
2285 continue; 2011 continue;
2286 2012
2287 /* register hash version */ 2013 /* register hash version */
2288 t_alg = ssi_hash_create_alg(&driver_hash[alg], dev, false); 2014 t_alg = cc_alloc_hash_alg(&driver_hash[alg], dev, false);
2289 if (IS_ERR(t_alg)) { 2015 if (IS_ERR(t_alg)) {
2290 rc = PTR_ERR(t_alg); 2016 rc = PTR_ERR(t_alg);
2291 dev_err(dev, "%s alg allocation failed\n", 2017 dev_err(dev, "%s alg allocation failed\n",
@@ -2295,7 +2021,7 @@ int ssi_hash_alloc(struct ssi_drvdata *drvdata)
2295 t_alg->drvdata = drvdata; 2021 t_alg->drvdata = drvdata;
2296 2022
2297 rc = crypto_register_ahash(&t_alg->ahash_alg); 2023 rc = crypto_register_ahash(&t_alg->ahash_alg);
2298 if (unlikely(rc)) { 2024 if (rc) {
2299 dev_err(dev, "%s alg registration failed\n", 2025 dev_err(dev, "%s alg registration failed\n",
2300 driver_hash[alg].driver_name); 2026 driver_hash[alg].driver_name);
2301 kfree(t_alg); 2027 kfree(t_alg);
@@ -2313,13 +2039,14 @@ fail:
2313 return rc; 2039 return rc;
2314} 2040}
2315 2041
2316int ssi_hash_free(struct ssi_drvdata *drvdata) 2042int cc_hash_free(struct cc_drvdata *drvdata)
2317{ 2043{
2318 struct ssi_hash_alg *t_hash_alg, *hash_n; 2044 struct cc_hash_alg *t_hash_alg, *hash_n;
2319 struct ssi_hash_handle *hash_handle = drvdata->hash_handle; 2045 struct cc_hash_handle *hash_handle = drvdata->hash_handle;
2320 2046
2321 if (hash_handle) { 2047 if (hash_handle) {
2322 list_for_each_entry_safe(t_hash_alg, hash_n, &hash_handle->hash_list, entry) { 2048 list_for_each_entry_safe(t_hash_alg, hash_n,
2049 &hash_handle->hash_list, entry) {
2323 crypto_unregister_ahash(&t_hash_alg->ahash_alg); 2050 crypto_unregister_ahash(&t_hash_alg->ahash_alg);
2324 list_del(&t_hash_alg->entry); 2051 list_del(&t_hash_alg->entry);
2325 kfree(t_hash_alg); 2052 kfree(t_hash_alg);
@@ -2331,14 +2058,13 @@ int ssi_hash_free(struct ssi_drvdata *drvdata)
2331 return 0; 2058 return 0;
2332} 2059}
2333 2060
2334static void ssi_hash_create_xcbc_setup(struct ahash_request *areq, 2061static void cc_setup_xcbc(struct ahash_request *areq, struct cc_hw_desc desc[],
2335 struct cc_hw_desc desc[], 2062 unsigned int *seq_size)
2336 unsigned int *seq_size)
2337{ 2063{
2338 unsigned int idx = *seq_size; 2064 unsigned int idx = *seq_size;
2339 struct ahash_req_ctx *state = ahash_request_ctx(areq); 2065 struct ahash_req_ctx *state = ahash_request_ctx(areq);
2340 struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); 2066 struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
2341 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm); 2067 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
2342 2068
2343 /* Setup XCBC MAC K1 */ 2069 /* Setup XCBC MAC K1 */
2344 hw_desc_init(&desc[idx]); 2070 hw_desc_init(&desc[idx]);
@@ -2354,8 +2080,8 @@ static void ssi_hash_create_xcbc_setup(struct ahash_request *areq,
2354 2080
2355 /* Setup XCBC MAC K2 */ 2081 /* Setup XCBC MAC K2 */
2356 hw_desc_init(&desc[idx]); 2082 hw_desc_init(&desc[idx]);
2357 set_din_type(&desc[idx], DMA_DLLI, (ctx->opad_tmp_keys_dma_addr + 2083 set_din_type(&desc[idx], DMA_DLLI,
2358 XCBC_MAC_K2_OFFSET), 2084 (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K2_OFFSET),
2359 CC_AES_128_BIT_KEY_SIZE, NS_BIT); 2085 CC_AES_128_BIT_KEY_SIZE, NS_BIT);
2360 set_setup_mode(&desc[idx], SETUP_LOAD_STATE1); 2086 set_setup_mode(&desc[idx], SETUP_LOAD_STATE1);
2361 set_cipher_mode(&desc[idx], DRV_CIPHER_XCBC_MAC); 2087 set_cipher_mode(&desc[idx], DRV_CIPHER_XCBC_MAC);
@@ -2366,8 +2092,8 @@ static void ssi_hash_create_xcbc_setup(struct ahash_request *areq,
2366 2092
2367 /* Setup XCBC MAC K3 */ 2093 /* Setup XCBC MAC K3 */
2368 hw_desc_init(&desc[idx]); 2094 hw_desc_init(&desc[idx]);
2369 set_din_type(&desc[idx], DMA_DLLI, (ctx->opad_tmp_keys_dma_addr + 2095 set_din_type(&desc[idx], DMA_DLLI,
2370 XCBC_MAC_K3_OFFSET), 2096 (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K3_OFFSET),
2371 CC_AES_128_BIT_KEY_SIZE, NS_BIT); 2097 CC_AES_128_BIT_KEY_SIZE, NS_BIT);
2372 set_setup_mode(&desc[idx], SETUP_LOAD_STATE2); 2098 set_setup_mode(&desc[idx], SETUP_LOAD_STATE2);
2373 set_cipher_mode(&desc[idx], DRV_CIPHER_XCBC_MAC); 2099 set_cipher_mode(&desc[idx], DRV_CIPHER_XCBC_MAC);
@@ -2389,14 +2115,13 @@ static void ssi_hash_create_xcbc_setup(struct ahash_request *areq,
2389 *seq_size = idx; 2115 *seq_size = idx;
2390} 2116}
2391 2117
2392static void ssi_hash_create_cmac_setup(struct ahash_request *areq, 2118static void cc_setup_cmac(struct ahash_request *areq, struct cc_hw_desc desc[],
2393 struct cc_hw_desc desc[], 2119 unsigned int *seq_size)
2394 unsigned int *seq_size)
2395{ 2120{
2396 unsigned int idx = *seq_size; 2121 unsigned int idx = *seq_size;
2397 struct ahash_req_ctx *state = ahash_request_ctx(areq); 2122 struct ahash_req_ctx *state = ahash_request_ctx(areq);
2398 struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); 2123 struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
2399 struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm); 2124 struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
2400 2125
2401 /* Setup CMAC Key */ 2126 /* Setup CMAC Key */
2402 hw_desc_init(&desc[idx]); 2127 hw_desc_init(&desc[idx]);
@@ -2423,17 +2148,15 @@ static void ssi_hash_create_cmac_setup(struct ahash_request *areq,
2423 *seq_size = idx; 2148 *seq_size = idx;
2424} 2149}
2425 2150
2426static void ssi_hash_create_data_desc(struct ahash_req_ctx *areq_ctx, 2151static void cc_set_desc(struct ahash_req_ctx *areq_ctx,
2427 struct ssi_hash_ctx *ctx, 2152 struct cc_hash_ctx *ctx, unsigned int flow_mode,
2428 unsigned int flow_mode, 2153 struct cc_hw_desc desc[], bool is_not_last_data,
2429 struct cc_hw_desc desc[], 2154 unsigned int *seq_size)
2430 bool is_not_last_data,
2431 unsigned int *seq_size)
2432{ 2155{
2433 unsigned int idx = *seq_size; 2156 unsigned int idx = *seq_size;
2434 struct device *dev = drvdata_to_dev(ctx->drvdata); 2157 struct device *dev = drvdata_to_dev(ctx->drvdata);
2435 2158
2436 if (likely(areq_ctx->data_dma_buf_type == SSI_DMA_BUF_DLLI)) { 2159 if (areq_ctx->data_dma_buf_type == CC_DMA_BUF_DLLI) {
2437 hw_desc_init(&desc[idx]); 2160 hw_desc_init(&desc[idx]);
2438 set_din_type(&desc[idx], DMA_DLLI, 2161 set_din_type(&desc[idx], DMA_DLLI,
2439 sg_dma_address(areq_ctx->curr_sg), 2162 sg_dma_address(areq_ctx->curr_sg),
@@ -2441,7 +2164,7 @@ static void ssi_hash_create_data_desc(struct ahash_req_ctx *areq_ctx,
2441 set_flow_mode(&desc[idx], flow_mode); 2164 set_flow_mode(&desc[idx], flow_mode);
2442 idx++; 2165 idx++;
2443 } else { 2166 } else {
2444 if (areq_ctx->data_dma_buf_type == SSI_DMA_BUF_NULL) { 2167 if (areq_ctx->data_dma_buf_type == CC_DMA_BUF_NULL) {
2445 dev_dbg(dev, " NULL mode\n"); 2168 dev_dbg(dev, " NULL mode\n");
2446 /* nothing to build */ 2169 /* nothing to build */
2447 return; 2170 return;
@@ -2469,6 +2192,29 @@ static void ssi_hash_create_data_desc(struct ahash_req_ctx *areq_ctx,
2469 *seq_size = idx; 2192 *seq_size = idx;
2470} 2193}
2471 2194
2195static const void *cc_larval_digest(struct device *dev, u32 mode)
2196{
2197 switch (mode) {
2198 case DRV_HASH_MD5:
2199 return md5_init;
2200 case DRV_HASH_SHA1:
2201 return sha1_init;
2202 case DRV_HASH_SHA224:
2203 return sha224_init;
2204 case DRV_HASH_SHA256:
2205 return sha256_init;
2206#if (CC_DEV_SHA_MAX > 256)
2207 case DRV_HASH_SHA384:
2208 return sha384_init;
2209 case DRV_HASH_SHA512:
2210 return sha512_init;
2211#endif
2212 default:
2213 dev_err(dev, "Invalid hash mode (%d)\n", mode);
2214 return md5_init;
2215 }
2216}
2217
2472/*! 2218/*!
2473 * Gets the address of the initial digest in SRAM 2219 * Gets the address of the initial digest in SRAM
2474 * according to the given hash mode 2220 * according to the given hash mode
@@ -2476,12 +2222,12 @@ static void ssi_hash_create_data_desc(struct ahash_req_ctx *areq_ctx,
2476 * \param drvdata 2222 * \param drvdata
2477 * \param mode The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256 2223 * \param mode The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256
2478 * 2224 *
2479 * \return u32 The address of the inital digest in SRAM 2225 * \return u32 The address of the initial digest in SRAM
2480 */ 2226 */
2481ssi_sram_addr_t ssi_ahash_get_larval_digest_sram_addr(void *drvdata, u32 mode) 2227cc_sram_addr_t cc_larval_digest_addr(void *drvdata, u32 mode)
2482{ 2228{
2483 struct ssi_drvdata *_drvdata = (struct ssi_drvdata *)drvdata; 2229 struct cc_drvdata *_drvdata = (struct cc_drvdata *)drvdata;
2484 struct ssi_hash_handle *hash_handle = _drvdata->hash_handle; 2230 struct cc_hash_handle *hash_handle = _drvdata->hash_handle;
2485 struct device *dev = drvdata_to_dev(_drvdata); 2231 struct device *dev = drvdata_to_dev(_drvdata);
2486 2232
2487 switch (mode) { 2233 switch (mode) {
@@ -2501,7 +2247,7 @@ ssi_sram_addr_t ssi_ahash_get_larval_digest_sram_addr(void *drvdata, u32 mode)
2501 sizeof(md5_init) + 2247 sizeof(md5_init) +
2502 sizeof(sha1_init) + 2248 sizeof(sha1_init) +
2503 sizeof(sha224_init)); 2249 sizeof(sha224_init));
2504#if (DX_DEV_SHA_MAX > 256) 2250#if (CC_DEV_SHA_MAX > 256)
2505 case DRV_HASH_SHA384: 2251 case DRV_HASH_SHA384:
2506 return (hash_handle->larval_digest_sram_addr + 2252 return (hash_handle->larval_digest_sram_addr +
2507 sizeof(md5_init) + 2253 sizeof(md5_init) +
@@ -2524,12 +2270,12 @@ ssi_sram_addr_t ssi_ahash_get_larval_digest_sram_addr(void *drvdata, u32 mode)
2524 return hash_handle->larval_digest_sram_addr; 2270 return hash_handle->larval_digest_sram_addr;
2525} 2271}
2526 2272
2527ssi_sram_addr_t 2273cc_sram_addr_t
2528ssi_ahash_get_initial_digest_len_sram_addr(void *drvdata, u32 mode) 2274cc_digest_len_addr(void *drvdata, u32 mode)
2529{ 2275{
2530 struct ssi_drvdata *_drvdata = (struct ssi_drvdata *)drvdata; 2276 struct cc_drvdata *_drvdata = (struct cc_drvdata *)drvdata;
2531 struct ssi_hash_handle *hash_handle = _drvdata->hash_handle; 2277 struct cc_hash_handle *hash_handle = _drvdata->hash_handle;
2532 ssi_sram_addr_t digest_len_addr = hash_handle->digest_len_sram_addr; 2278 cc_sram_addr_t digest_len_addr = hash_handle->digest_len_sram_addr;
2533 2279
2534 switch (mode) { 2280 switch (mode) {
2535 case DRV_HASH_SHA1: 2281 case DRV_HASH_SHA1:
@@ -2537,7 +2283,7 @@ ssi_ahash_get_initial_digest_len_sram_addr(void *drvdata, u32 mode)
2537 case DRV_HASH_SHA256: 2283 case DRV_HASH_SHA256:
2538 case DRV_HASH_MD5: 2284 case DRV_HASH_MD5:
2539 return digest_len_addr; 2285 return digest_len_addr;
2540#if (DX_DEV_SHA_MAX > 256) 2286#if (CC_DEV_SHA_MAX > 256)
2541 case DRV_HASH_SHA384: 2287 case DRV_HASH_SHA384:
2542 case DRV_HASH_SHA512: 2288 case DRV_HASH_SHA512:
2543 return digest_len_addr + sizeof(digest_len_init); 2289 return digest_len_addr + sizeof(digest_len_init);
diff --git a/drivers/staging/ccree/cc_hash.h b/drivers/staging/ccree/cc_hash.h
new file mode 100644
index 000000000000..aa42b8f4348d
--- /dev/null
+++ b/drivers/staging/ccree/cc_hash.h
@@ -0,0 +1,114 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4/* \file cc_hash.h
5 * ARM CryptoCell Hash Crypto API
6 */
7
8#ifndef __CC_HASH_H__
9#define __CC_HASH_H__
10
11#include "cc_buffer_mgr.h"
12
13#define HMAC_IPAD_CONST 0x36363636
14#define HMAC_OPAD_CONST 0x5C5C5C5C
15#if (CC_DEV_SHA_MAX > 256)
16#define HASH_LEN_SIZE 16
17#define CC_MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
18#define CC_MAX_HASH_BLCK_SIZE SHA512_BLOCK_SIZE
19#else
20#define HASH_LEN_SIZE 8
21#define CC_MAX_HASH_DIGEST_SIZE SHA256_DIGEST_SIZE
22#define CC_MAX_HASH_BLCK_SIZE SHA256_BLOCK_SIZE
23#endif
24
25#define XCBC_MAC_K1_OFFSET 0
26#define XCBC_MAC_K2_OFFSET 16
27#define XCBC_MAC_K3_OFFSET 32
28
29#define CC_EXPORT_MAGIC 0xC2EE1070U
30
31/* this struct was taken from drivers/crypto/nx/nx-aes-xcbc.c and it is used
32 * for xcbc/cmac statesize
33 */
34struct aeshash_state {
35 u8 state[AES_BLOCK_SIZE];
36 unsigned int count;
37 u8 buffer[AES_BLOCK_SIZE];
38};
39
40/* ahash state */
41struct ahash_req_ctx {
42 u8 buffers[2][CC_MAX_HASH_BLCK_SIZE] ____cacheline_aligned;
43 u8 digest_result_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned;
44 u8 digest_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned;
45 u8 opad_digest_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned;
46 u8 digest_bytes_len[HASH_LEN_SIZE] ____cacheline_aligned;
47 struct async_gen_req_ctx gen_ctx ____cacheline_aligned;
48 enum cc_req_dma_buf_type data_dma_buf_type;
49 dma_addr_t opad_digest_dma_addr;
50 dma_addr_t digest_buff_dma_addr;
51 dma_addr_t digest_bytes_len_dma_addr;
52 dma_addr_t digest_result_dma_addr;
53 u32 buf_cnt[2];
54 u32 buff_index;
55 u32 xcbc_count; /* count xcbc update operatations */
56 struct scatterlist buff_sg[2];
57 struct scatterlist *curr_sg;
58 u32 in_nents;
59 u32 mlli_nents;
60 struct mlli_params mlli_params;
61};
62
63static inline u32 *cc_hash_buf_cnt(struct ahash_req_ctx *state)
64{
65 return &state->buf_cnt[state->buff_index];
66}
67
68static inline u8 *cc_hash_buf(struct ahash_req_ctx *state)
69{
70 return state->buffers[state->buff_index];
71}
72
73static inline u32 *cc_next_buf_cnt(struct ahash_req_ctx *state)
74{
75 return &state->buf_cnt[state->buff_index ^ 1];
76}
77
78static inline u8 *cc_next_buf(struct ahash_req_ctx *state)
79{
80 return state->buffers[state->buff_index ^ 1];
81}
82
83int cc_hash_alloc(struct cc_drvdata *drvdata);
84int cc_init_hash_sram(struct cc_drvdata *drvdata);
85int cc_hash_free(struct cc_drvdata *drvdata);
86
87/*!
88 * Gets the initial digest length
89 *
90 * \param drvdata
91 * \param mode The Hash mode. Supported modes:
92 * MD5/SHA1/SHA224/SHA256/SHA384/SHA512
93 *
94 * \return u32 returns the address of the initial digest length in SRAM
95 */
96cc_sram_addr_t
97cc_digest_len_addr(void *drvdata, u32 mode);
98
99/*!
100 * Gets the address of the initial digest in SRAM
101 * according to the given hash mode
102 *
103 * \param drvdata
104 * \param mode The Hash mode. Supported modes:
105 * MD5/SHA1/SHA224/SHA256/SHA384/SHA512
106 *
107 * \return u32 The address of the initial digest in SRAM
108 */
109cc_sram_addr_t cc_larval_digest_addr(void *drvdata, u32 mode);
110
111void cc_hash_global_init(void);
112
113#endif /*__CC_HASH_H__*/
114
diff --git a/drivers/staging/ccree/cc_host_regs.h b/drivers/staging/ccree/cc_host_regs.h
new file mode 100644
index 000000000000..69ef2fa0cb9b
--- /dev/null
+++ b/drivers/staging/ccree/cc_host_regs.h
@@ -0,0 +1,142 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4#ifndef __CC_HOST_H__
5#define __CC_HOST_H__
6
7// --------------------------------------
8// BLOCK: HOST_P
9// --------------------------------------
10#define CC_HOST_IRR_REG_OFFSET 0xA00UL
11#define CC_HOST_IRR_DSCRPTR_COMPLETION_LOW_INT_BIT_SHIFT 0x2UL
12#define CC_HOST_IRR_DSCRPTR_COMPLETION_LOW_INT_BIT_SIZE 0x1UL
13#define CC_HOST_IRR_AXI_ERR_INT_BIT_SHIFT 0x8UL
14#define CC_HOST_IRR_AXI_ERR_INT_BIT_SIZE 0x1UL
15#define CC_HOST_IRR_GPR0_BIT_SHIFT 0xBUL
16#define CC_HOST_IRR_GPR0_BIT_SIZE 0x1UL
17#define CC_HOST_IRR_DSCRPTR_WATERMARK_INT_BIT_SHIFT 0x13UL
18#define CC_HOST_IRR_DSCRPTR_WATERMARK_INT_BIT_SIZE 0x1UL
19#define CC_HOST_IRR_AXIM_COMP_INT_BIT_SHIFT 0x17UL
20#define CC_HOST_IRR_AXIM_COMP_INT_BIT_SIZE 0x1UL
21#define CC_HOST_IMR_REG_OFFSET 0xA04UL
22#define CC_HOST_IMR_NOT_USED_MASK_BIT_SHIFT 0x1UL
23#define CC_HOST_IMR_NOT_USED_MASK_BIT_SIZE 0x1UL
24#define CC_HOST_IMR_DSCRPTR_COMPLETION_MASK_BIT_SHIFT 0x2UL
25#define CC_HOST_IMR_DSCRPTR_COMPLETION_MASK_BIT_SIZE 0x1UL
26#define CC_HOST_IMR_AXI_ERR_MASK_BIT_SHIFT 0x8UL
27#define CC_HOST_IMR_AXI_ERR_MASK_BIT_SIZE 0x1UL
28#define CC_HOST_IMR_GPR0_BIT_SHIFT 0xBUL
29#define CC_HOST_IMR_GPR0_BIT_SIZE 0x1UL
30#define CC_HOST_IMR_DSCRPTR_WATERMARK_MASK0_BIT_SHIFT 0x13UL
31#define CC_HOST_IMR_DSCRPTR_WATERMARK_MASK0_BIT_SIZE 0x1UL
32#define CC_HOST_IMR_AXIM_COMP_INT_MASK_BIT_SHIFT 0x17UL
33#define CC_HOST_IMR_AXIM_COMP_INT_MASK_BIT_SIZE 0x1UL
34#define CC_HOST_ICR_REG_OFFSET 0xA08UL
35#define CC_HOST_ICR_DSCRPTR_COMPLETION_BIT_SHIFT 0x2UL
36#define CC_HOST_ICR_DSCRPTR_COMPLETION_BIT_SIZE 0x1UL
37#define CC_HOST_ICR_AXI_ERR_CLEAR_BIT_SHIFT 0x8UL
38#define CC_HOST_ICR_AXI_ERR_CLEAR_BIT_SIZE 0x1UL
39#define CC_HOST_ICR_GPR_INT_CLEAR_BIT_SHIFT 0xBUL
40#define CC_HOST_ICR_GPR_INT_CLEAR_BIT_SIZE 0x1UL
41#define CC_HOST_ICR_DSCRPTR_WATERMARK_QUEUE0_CLEAR_BIT_SHIFT 0x13UL
42#define CC_HOST_ICR_DSCRPTR_WATERMARK_QUEUE0_CLEAR_BIT_SIZE 0x1UL
43#define CC_HOST_ICR_AXIM_COMP_INT_CLEAR_BIT_SHIFT 0x17UL
44#define CC_HOST_ICR_AXIM_COMP_INT_CLEAR_BIT_SIZE 0x1UL
45#define CC_HOST_SIGNATURE_REG_OFFSET 0xA24UL
46#define CC_HOST_SIGNATURE_VALUE_BIT_SHIFT 0x0UL
47#define CC_HOST_SIGNATURE_VALUE_BIT_SIZE 0x20UL
48#define CC_HOST_BOOT_REG_OFFSET 0xA28UL
49#define CC_HOST_BOOT_SYNTHESIS_CONFIG_BIT_SHIFT 0x0UL
50#define CC_HOST_BOOT_SYNTHESIS_CONFIG_BIT_SIZE 0x1UL
51#define CC_HOST_BOOT_LARGE_RKEK_LOCAL_BIT_SHIFT 0x1UL
52#define CC_HOST_BOOT_LARGE_RKEK_LOCAL_BIT_SIZE 0x1UL
53#define CC_HOST_BOOT_HASH_IN_FUSES_LOCAL_BIT_SHIFT 0x2UL
54#define CC_HOST_BOOT_HASH_IN_FUSES_LOCAL_BIT_SIZE 0x1UL
55#define CC_HOST_BOOT_EXT_MEM_SECURED_LOCAL_BIT_SHIFT 0x3UL
56#define CC_HOST_BOOT_EXT_MEM_SECURED_LOCAL_BIT_SIZE 0x1UL
57#define CC_HOST_BOOT_RKEK_ECC_EXISTS_LOCAL_N_BIT_SHIFT 0x5UL
58#define CC_HOST_BOOT_RKEK_ECC_EXISTS_LOCAL_N_BIT_SIZE 0x1UL
59#define CC_HOST_BOOT_SRAM_SIZE_LOCAL_BIT_SHIFT 0x6UL
60#define CC_HOST_BOOT_SRAM_SIZE_LOCAL_BIT_SIZE 0x3UL
61#define CC_HOST_BOOT_DSCRPTR_EXISTS_LOCAL_BIT_SHIFT 0x9UL
62#define CC_HOST_BOOT_DSCRPTR_EXISTS_LOCAL_BIT_SIZE 0x1UL
63#define CC_HOST_BOOT_PAU_EXISTS_LOCAL_BIT_SHIFT 0xAUL
64#define CC_HOST_BOOT_PAU_EXISTS_LOCAL_BIT_SIZE 0x1UL
65#define CC_HOST_BOOT_RNG_EXISTS_LOCAL_BIT_SHIFT 0xBUL
66#define CC_HOST_BOOT_RNG_EXISTS_LOCAL_BIT_SIZE 0x1UL
67#define CC_HOST_BOOT_PKA_EXISTS_LOCAL_BIT_SHIFT 0xCUL
68#define CC_HOST_BOOT_PKA_EXISTS_LOCAL_BIT_SIZE 0x1UL
69#define CC_HOST_BOOT_RC4_EXISTS_LOCAL_BIT_SHIFT 0xDUL
70#define CC_HOST_BOOT_RC4_EXISTS_LOCAL_BIT_SIZE 0x1UL
71#define CC_HOST_BOOT_SHA_512_PRSNT_LOCAL_BIT_SHIFT 0xEUL
72#define CC_HOST_BOOT_SHA_512_PRSNT_LOCAL_BIT_SIZE 0x1UL
73#define CC_HOST_BOOT_SHA_256_PRSNT_LOCAL_BIT_SHIFT 0xFUL
74#define CC_HOST_BOOT_SHA_256_PRSNT_LOCAL_BIT_SIZE 0x1UL
75#define CC_HOST_BOOT_MD5_PRSNT_LOCAL_BIT_SHIFT 0x10UL
76#define CC_HOST_BOOT_MD5_PRSNT_LOCAL_BIT_SIZE 0x1UL
77#define CC_HOST_BOOT_HASH_EXISTS_LOCAL_BIT_SHIFT 0x11UL
78#define CC_HOST_BOOT_HASH_EXISTS_LOCAL_BIT_SIZE 0x1UL
79#define CC_HOST_BOOT_C2_EXISTS_LOCAL_BIT_SHIFT 0x12UL
80#define CC_HOST_BOOT_C2_EXISTS_LOCAL_BIT_SIZE 0x1UL
81#define CC_HOST_BOOT_DES_EXISTS_LOCAL_BIT_SHIFT 0x13UL
82#define CC_HOST_BOOT_DES_EXISTS_LOCAL_BIT_SIZE 0x1UL
83#define CC_HOST_BOOT_AES_XCBC_MAC_EXISTS_LOCAL_BIT_SHIFT 0x14UL
84#define CC_HOST_BOOT_AES_XCBC_MAC_EXISTS_LOCAL_BIT_SIZE 0x1UL
85#define CC_HOST_BOOT_AES_CMAC_EXISTS_LOCAL_BIT_SHIFT 0x15UL
86#define CC_HOST_BOOT_AES_CMAC_EXISTS_LOCAL_BIT_SIZE 0x1UL
87#define CC_HOST_BOOT_AES_CCM_EXISTS_LOCAL_BIT_SHIFT 0x16UL
88#define CC_HOST_BOOT_AES_CCM_EXISTS_LOCAL_BIT_SIZE 0x1UL
89#define CC_HOST_BOOT_AES_XEX_HW_T_CALC_LOCAL_BIT_SHIFT 0x17UL
90#define CC_HOST_BOOT_AES_XEX_HW_T_CALC_LOCAL_BIT_SIZE 0x1UL
91#define CC_HOST_BOOT_AES_XEX_EXISTS_LOCAL_BIT_SHIFT 0x18UL
92#define CC_HOST_BOOT_AES_XEX_EXISTS_LOCAL_BIT_SIZE 0x1UL
93#define CC_HOST_BOOT_CTR_EXISTS_LOCAL_BIT_SHIFT 0x19UL
94#define CC_HOST_BOOT_CTR_EXISTS_LOCAL_BIT_SIZE 0x1UL
95#define CC_HOST_BOOT_AES_DIN_BYTE_RESOLUTION_LOCAL_BIT_SHIFT 0x1AUL
96#define CC_HOST_BOOT_AES_DIN_BYTE_RESOLUTION_LOCAL_BIT_SIZE 0x1UL
97#define CC_HOST_BOOT_TUNNELING_ENB_LOCAL_BIT_SHIFT 0x1BUL
98#define CC_HOST_BOOT_TUNNELING_ENB_LOCAL_BIT_SIZE 0x1UL
99#define CC_HOST_BOOT_SUPPORT_256_192_KEY_LOCAL_BIT_SHIFT 0x1CUL
100#define CC_HOST_BOOT_SUPPORT_256_192_KEY_LOCAL_BIT_SIZE 0x1UL
101#define CC_HOST_BOOT_ONLY_ENCRYPT_LOCAL_BIT_SHIFT 0x1DUL
102#define CC_HOST_BOOT_ONLY_ENCRYPT_LOCAL_BIT_SIZE 0x1UL
103#define CC_HOST_BOOT_AES_EXISTS_LOCAL_BIT_SHIFT 0x1EUL
104#define CC_HOST_BOOT_AES_EXISTS_LOCAL_BIT_SIZE 0x1UL
105#define CC_HOST_VERSION_REG_OFFSET 0xA40UL
106#define CC_HOST_VERSION_VALUE_BIT_SHIFT 0x0UL
107#define CC_HOST_VERSION_VALUE_BIT_SIZE 0x20UL
108#define CC_HOST_KFDE0_VALID_REG_OFFSET 0xA60UL
109#define CC_HOST_KFDE0_VALID_VALUE_BIT_SHIFT 0x0UL
110#define CC_HOST_KFDE0_VALID_VALUE_BIT_SIZE 0x1UL
111#define CC_HOST_KFDE1_VALID_REG_OFFSET 0xA64UL
112#define CC_HOST_KFDE1_VALID_VALUE_BIT_SHIFT 0x0UL
113#define CC_HOST_KFDE1_VALID_VALUE_BIT_SIZE 0x1UL
114#define CC_HOST_KFDE2_VALID_REG_OFFSET 0xA68UL
115#define CC_HOST_KFDE2_VALID_VALUE_BIT_SHIFT 0x0UL
116#define CC_HOST_KFDE2_VALID_VALUE_BIT_SIZE 0x1UL
117#define CC_HOST_KFDE3_VALID_REG_OFFSET 0xA6CUL
118#define CC_HOST_KFDE3_VALID_VALUE_BIT_SHIFT 0x0UL
119#define CC_HOST_KFDE3_VALID_VALUE_BIT_SIZE 0x1UL
120#define CC_HOST_GPR0_REG_OFFSET 0xA70UL
121#define CC_HOST_GPR0_VALUE_BIT_SHIFT 0x0UL
122#define CC_HOST_GPR0_VALUE_BIT_SIZE 0x20UL
123#define CC_GPR_HOST_REG_OFFSET 0xA74UL
124#define CC_GPR_HOST_VALUE_BIT_SHIFT 0x0UL
125#define CC_GPR_HOST_VALUE_BIT_SIZE 0x20UL
126#define CC_HOST_POWER_DOWN_EN_REG_OFFSET 0xA78UL
127#define CC_HOST_POWER_DOWN_EN_VALUE_BIT_SHIFT 0x0UL
128#define CC_HOST_POWER_DOWN_EN_VALUE_BIT_SIZE 0x1UL
129// --------------------------------------
130// BLOCK: HOST_SRAM
131// --------------------------------------
132#define CC_SRAM_DATA_REG_OFFSET 0xF00UL
133#define CC_SRAM_DATA_VALUE_BIT_SHIFT 0x0UL
134#define CC_SRAM_DATA_VALUE_BIT_SIZE 0x20UL
135#define CC_SRAM_ADDR_REG_OFFSET 0xF04UL
136#define CC_SRAM_ADDR_VALUE_BIT_SHIFT 0x0UL
137#define CC_SRAM_ADDR_VALUE_BIT_SIZE 0xFUL
138#define CC_SRAM_DATA_READY_REG_OFFSET 0xF08UL
139#define CC_SRAM_DATA_READY_VALUE_BIT_SHIFT 0x0UL
140#define CC_SRAM_DATA_READY_VALUE_BIT_SIZE 0x1UL
141
142#endif //__CC_HOST_H__
diff --git a/drivers/staging/ccree/cc_hw_queue_defs.h b/drivers/staging/ccree/cc_hw_queue_defs.h
index 2ae0f655e7a0..a79f28cec5ae 100644
--- a/drivers/staging/ccree/cc_hw_queue_defs.h
+++ b/drivers/staging/ccree/cc_hw_queue_defs.h
@@ -1,25 +1,12 @@
1/* 1/* SPDX-License-Identifier: GPL-2.0 */
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17#ifndef __CC_HW_QUEUE_DEFS_H__ 4#ifndef __CC_HW_QUEUE_DEFS_H__
18#define __CC_HW_QUEUE_DEFS_H__ 5#define __CC_HW_QUEUE_DEFS_H__
19 6
20#include <linux/types.h> 7#include <linux/types.h>
21 8
22#include "dx_crys_kernel.h" 9#include "cc_kernel_regs.h"
23#include <linux/bitfield.h> 10#include <linux/bitfield.h>
24 11
25/****************************************************************************** 12/******************************************************************************
@@ -30,14 +17,12 @@
30/* Define max. available slots in HW queue */ 17/* Define max. available slots in HW queue */
31#define HW_QUEUE_SLOTS_MAX 15 18#define HW_QUEUE_SLOTS_MAX 15
32 19
33#define CC_REG_NAME(word, name) DX_DSCRPTR_QUEUE_WORD ## word ## _ ## name
34
35#define CC_REG_LOW(word, name) \ 20#define CC_REG_LOW(word, name) \
36 (DX_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SHIFT) 21 (CC_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SHIFT)
37 22
38#define CC_REG_HIGH(word, name) \ 23#define CC_REG_HIGH(word, name) \
39 (CC_REG_LOW(word, name) + \ 24 (CC_REG_LOW(word, name) + \
40 DX_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SIZE - 1) 25 CC_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SIZE - 1)
41 26
42#define CC_GENMASK(word, name) \ 27#define CC_GENMASK(word, name) \
43 GENMASK(CC_REG_HIGH(word, name), CC_REG_LOW(word, name)) 28 GENMASK(CC_REG_HIGH(word, name), CC_REG_LOW(word, name))
@@ -122,7 +107,6 @@ enum cc_flow_mode {
122 AES_to_AES_to_HASH_and_DOUT = 13, 107 AES_to_AES_to_HASH_and_DOUT = 13,
123 AES_to_AES_to_HASH = 14, 108 AES_to_AES_to_HASH = 14,
124 AES_to_HASH_and_AES = 15, 109 AES_to_HASH_and_AES = 15,
125 DIN_MULTI2_DOUT = 16,
126 DIN_AES_AESMAC = 17, 110 DIN_AES_AESMAC = 17,
127 HASH_to_DOUT = 18, 111 HASH_to_DOUT = 18,
128 /* setup flows */ 112 /* setup flows */
@@ -130,7 +114,6 @@ enum cc_flow_mode {
130 S_DIN_to_AES2 = 33, 114 S_DIN_to_AES2 = 33,
131 S_DIN_to_DES = 34, 115 S_DIN_to_DES = 34,
132 S_DIN_to_RC4 = 35, 116 S_DIN_to_RC4 = 35,
133 S_DIN_to_MULTI2 = 36,
134 S_DIN_to_HASH = 37, 117 S_DIN_to_HASH = 37,
135 S_AES_to_DOUT = 38, 118 S_AES_to_DOUT = 38,
136 S_AES2_to_DOUT = 39, 119 S_AES2_to_DOUT = 39,
@@ -203,6 +186,19 @@ enum cc_hw_des_key_size {
203 END_OF_DES_KEYS = S32_MAX, 186 END_OF_DES_KEYS = S32_MAX,
204}; 187};
205 188
189enum cc_hash_conf_pad {
190 HASH_PADDING_DISABLED = 0,
191 HASH_PADDING_ENABLED = 1,
192 HASH_DIGEST_RESULT_LITTLE_ENDIAN = 2,
193 HASH_CONFIG1_PADDING_RESERVE32 = S32_MAX,
194};
195
196enum cc_hash_cipher_pad {
197 DO_NOT_PAD = 0,
198 DO_PAD = 1,
199 HASH_CIPHER_DO_PADDING_RESERVE32 = S32_MAX,
200};
201
206/*****************************/ 202/*****************************/
207/* Descriptor packing macros */ 203/* Descriptor packing macros */
208/*****************************/ 204/*****************************/
diff --git a/drivers/staging/ccree/ssi_ivgen.c b/drivers/staging/ccree/cc_ivgen.c
index 3f082f41ae8f..c47f419b277b 100644
--- a/drivers/staging/ccree/ssi_ivgen.c
+++ b/drivers/staging/ccree/cc_ivgen.c
@@ -1,38 +1,23 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17#include <linux/platform_device.h>
18#include <crypto/ctr.h> 4#include <crypto/ctr.h>
19#include "ssi_config.h" 5#include "cc_driver.h"
20#include "ssi_driver.h" 6#include "cc_ivgen.h"
21#include "ssi_ivgen.h" 7#include "cc_request_mgr.h"
22#include "ssi_request_mgr.h" 8#include "cc_sram_mgr.h"
23#include "ssi_sram_mgr.h" 9#include "cc_buffer_mgr.h"
24#include "ssi_buffer_mgr.h"
25 10
26/* The max. size of pool *MUST* be <= SRAM total size */ 11/* The max. size of pool *MUST* be <= SRAM total size */
27#define SSI_IVPOOL_SIZE 1024 12#define CC_IVPOOL_SIZE 1024
28/* The first 32B fraction of pool are dedicated to the 13/* The first 32B fraction of pool are dedicated to the
29 * next encryption "key" & "IV" for pool regeneration 14 * next encryption "key" & "IV" for pool regeneration
30 */ 15 */
31#define SSI_IVPOOL_META_SIZE (CC_AES_IV_SIZE + AES_KEYSIZE_128) 16#define CC_IVPOOL_META_SIZE (CC_AES_IV_SIZE + AES_KEYSIZE_128)
32#define SSI_IVPOOL_GEN_SEQ_LEN 4 17#define CC_IVPOOL_GEN_SEQ_LEN 4
33 18
34/** 19/**
35 * struct ssi_ivgen_ctx -IV pool generation context 20 * struct cc_ivgen_ctx -IV pool generation context
36 * @pool: the start address of the iv-pool resides in internal RAM 21 * @pool: the start address of the iv-pool resides in internal RAM
37 * @ctr_key_dma: address of pool's encryption key material in internal RAM 22 * @ctr_key_dma: address of pool's encryption key material in internal RAM
38 * @ctr_iv_dma: address of pool's counter iv in internal RAM 23 * @ctr_iv_dma: address of pool's counter iv in internal RAM
@@ -40,31 +25,29 @@
40 * @pool_meta: virt. address of the initial enc. key/IV 25 * @pool_meta: virt. address of the initial enc. key/IV
41 * @pool_meta_dma: phys. address of the initial enc. key/IV 26 * @pool_meta_dma: phys. address of the initial enc. key/IV
42 */ 27 */
43struct ssi_ivgen_ctx { 28struct cc_ivgen_ctx {
44 ssi_sram_addr_t pool; 29 cc_sram_addr_t pool;
45 ssi_sram_addr_t ctr_key; 30 cc_sram_addr_t ctr_key;
46 ssi_sram_addr_t ctr_iv; 31 cc_sram_addr_t ctr_iv;
47 u32 next_iv_ofs; 32 u32 next_iv_ofs;
48 u8 *pool_meta; 33 u8 *pool_meta;
49 dma_addr_t pool_meta_dma; 34 dma_addr_t pool_meta_dma;
50}; 35};
51 36
52/*! 37/*!
53 * Generates SSI_IVPOOL_SIZE of random bytes by 38 * Generates CC_IVPOOL_SIZE of random bytes by
54 * encrypting 0's using AES128-CTR. 39 * encrypting 0's using AES128-CTR.
55 * 40 *
56 * \param ivgen iv-pool context 41 * \param ivgen iv-pool context
57 * \param iv_seq IN/OUT array to the descriptors sequence 42 * \param iv_seq IN/OUT array to the descriptors sequence
58 * \param iv_seq_len IN/OUT pointer to the sequence length 43 * \param iv_seq_len IN/OUT pointer to the sequence length
59 */ 44 */
60static int ssi_ivgen_generate_pool( 45static int cc_gen_iv_pool(struct cc_ivgen_ctx *ivgen_ctx,
61 struct ssi_ivgen_ctx *ivgen_ctx, 46 struct cc_hw_desc iv_seq[], unsigned int *iv_seq_len)
62 struct cc_hw_desc iv_seq[],
63 unsigned int *iv_seq_len)
64{ 47{
65 unsigned int idx = *iv_seq_len; 48 unsigned int idx = *iv_seq_len;
66 49
67 if ((*iv_seq_len + SSI_IVPOOL_GEN_SEQ_LEN) > SSI_IVPOOL_SEQ_LEN) { 50 if ((*iv_seq_len + CC_IVPOOL_GEN_SEQ_LEN) > CC_IVPOOL_SEQ_LEN) {
68 /* The sequence will be longer than allowed */ 51 /* The sequence will be longer than allowed */
69 return -EINVAL; 52 return -EINVAL;
70 } 53 }
@@ -97,15 +80,15 @@ static int ssi_ivgen_generate_pool(
97 80
98 /* Generate IV pool */ 81 /* Generate IV pool */
99 hw_desc_init(&iv_seq[idx]); 82 hw_desc_init(&iv_seq[idx]);
100 set_din_const(&iv_seq[idx], 0, SSI_IVPOOL_SIZE); 83 set_din_const(&iv_seq[idx], 0, CC_IVPOOL_SIZE);
101 set_dout_sram(&iv_seq[idx], ivgen_ctx->pool, SSI_IVPOOL_SIZE); 84 set_dout_sram(&iv_seq[idx], ivgen_ctx->pool, CC_IVPOOL_SIZE);
102 set_flow_mode(&iv_seq[idx], DIN_AES_DOUT); 85 set_flow_mode(&iv_seq[idx], DIN_AES_DOUT);
103 idx++; 86 idx++;
104 87
105 *iv_seq_len = idx; /* Update sequence length */ 88 *iv_seq_len = idx; /* Update sequence length */
106 89
107 /* queue ordering assures pool readiness */ 90 /* queue ordering assures pool readiness */
108 ivgen_ctx->next_iv_ofs = SSI_IVPOOL_META_SIZE; 91 ivgen_ctx->next_iv_ofs = CC_IVPOOL_META_SIZE;
109 92
110 return 0; 93 return 0;
111} 94}
@@ -118,15 +101,15 @@ static int ssi_ivgen_generate_pool(
118 * 101 *
119 * \return int Zero for success, negative value otherwise. 102 * \return int Zero for success, negative value otherwise.
120 */ 103 */
121int ssi_ivgen_init_sram_pool(struct ssi_drvdata *drvdata) 104int cc_init_iv_sram(struct cc_drvdata *drvdata)
122{ 105{
123 struct ssi_ivgen_ctx *ivgen_ctx = drvdata->ivgen_handle; 106 struct cc_ivgen_ctx *ivgen_ctx = drvdata->ivgen_handle;
124 struct cc_hw_desc iv_seq[SSI_IVPOOL_SEQ_LEN]; 107 struct cc_hw_desc iv_seq[CC_IVPOOL_SEQ_LEN];
125 unsigned int iv_seq_len = 0; 108 unsigned int iv_seq_len = 0;
126 int rc; 109 int rc;
127 110
128 /* Generate initial enc. key/iv */ 111 /* Generate initial enc. key/iv */
129 get_random_bytes(ivgen_ctx->pool_meta, SSI_IVPOOL_META_SIZE); 112 get_random_bytes(ivgen_ctx->pool_meta, CC_IVPOOL_META_SIZE);
130 113
131 /* The first 32B reserved for the enc. Key/IV */ 114 /* The first 32B reserved for the enc. Key/IV */
132 ivgen_ctx->ctr_key = ivgen_ctx->pool; 115 ivgen_ctx->ctr_key = ivgen_ctx->pool;
@@ -135,15 +118,15 @@ int ssi_ivgen_init_sram_pool(struct ssi_drvdata *drvdata)
135 /* Copy initial enc. key and IV to SRAM at a single descriptor */ 118 /* Copy initial enc. key and IV to SRAM at a single descriptor */
136 hw_desc_init(&iv_seq[iv_seq_len]); 119 hw_desc_init(&iv_seq[iv_seq_len]);
137 set_din_type(&iv_seq[iv_seq_len], DMA_DLLI, ivgen_ctx->pool_meta_dma, 120 set_din_type(&iv_seq[iv_seq_len], DMA_DLLI, ivgen_ctx->pool_meta_dma,
138 SSI_IVPOOL_META_SIZE, NS_BIT); 121 CC_IVPOOL_META_SIZE, NS_BIT);
139 set_dout_sram(&iv_seq[iv_seq_len], ivgen_ctx->pool, 122 set_dout_sram(&iv_seq[iv_seq_len], ivgen_ctx->pool,
140 SSI_IVPOOL_META_SIZE); 123 CC_IVPOOL_META_SIZE);
141 set_flow_mode(&iv_seq[iv_seq_len], BYPASS); 124 set_flow_mode(&iv_seq[iv_seq_len], BYPASS);
142 iv_seq_len++; 125 iv_seq_len++;
143 126
144 /* Generate initial pool */ 127 /* Generate initial pool */
145 rc = ssi_ivgen_generate_pool(ivgen_ctx, iv_seq, &iv_seq_len); 128 rc = cc_gen_iv_pool(ivgen_ctx, iv_seq, &iv_seq_len);
146 if (unlikely(rc != 0)) 129 if (rc)
147 return rc; 130 return rc;
148 131
149 /* Fire-and-forget */ 132 /* Fire-and-forget */
@@ -155,17 +138,17 @@ int ssi_ivgen_init_sram_pool(struct ssi_drvdata *drvdata)
155 * 138 *
156 * \param drvdata 139 * \param drvdata
157 */ 140 */
158void ssi_ivgen_fini(struct ssi_drvdata *drvdata) 141void cc_ivgen_fini(struct cc_drvdata *drvdata)
159{ 142{
160 struct ssi_ivgen_ctx *ivgen_ctx = drvdata->ivgen_handle; 143 struct cc_ivgen_ctx *ivgen_ctx = drvdata->ivgen_handle;
161 struct device *device = &drvdata->plat_dev->dev; 144 struct device *device = &drvdata->plat_dev->dev;
162 145
163 if (!ivgen_ctx) 146 if (!ivgen_ctx)
164 return; 147 return;
165 148
166 if (ivgen_ctx->pool_meta) { 149 if (ivgen_ctx->pool_meta) {
167 memset(ivgen_ctx->pool_meta, 0, SSI_IVPOOL_META_SIZE); 150 memset(ivgen_ctx->pool_meta, 0, CC_IVPOOL_META_SIZE);
168 dma_free_coherent(device, SSI_IVPOOL_META_SIZE, 151 dma_free_coherent(device, CC_IVPOOL_META_SIZE,
169 ivgen_ctx->pool_meta, 152 ivgen_ctx->pool_meta,
170 ivgen_ctx->pool_meta_dma); 153 ivgen_ctx->pool_meta_dma);
171 } 154 }
@@ -184,42 +167,41 @@ void ssi_ivgen_fini(struct ssi_drvdata *drvdata)
184 * 167 *
185 * \return int Zero for success, negative value otherwise. 168 * \return int Zero for success, negative value otherwise.
186 */ 169 */
187int ssi_ivgen_init(struct ssi_drvdata *drvdata) 170int cc_ivgen_init(struct cc_drvdata *drvdata)
188{ 171{
189 struct ssi_ivgen_ctx *ivgen_ctx; 172 struct cc_ivgen_ctx *ivgen_ctx;
190 struct device *device = &drvdata->plat_dev->dev; 173 struct device *device = &drvdata->plat_dev->dev;
191 int rc; 174 int rc;
192 175
193 /* Allocate "this" context */ 176 /* Allocate "this" context */
194 drvdata->ivgen_handle = kzalloc(sizeof(*drvdata->ivgen_handle), 177 ivgen_ctx = kzalloc(sizeof(*ivgen_ctx), GFP_KERNEL);
195 GFP_KERNEL); 178 if (!ivgen_ctx)
196 if (!drvdata->ivgen_handle)
197 return -ENOMEM; 179 return -ENOMEM;
198 180
199 ivgen_ctx = drvdata->ivgen_handle; 181 drvdata->ivgen_handle = ivgen_ctx;
200 182
201 /* Allocate pool's header for intial enc. key/IV */ 183 /* Allocate pool's header for initial enc. key/IV */
202 ivgen_ctx->pool_meta = dma_alloc_coherent(device, SSI_IVPOOL_META_SIZE, 184 ivgen_ctx->pool_meta = dma_alloc_coherent(device, CC_IVPOOL_META_SIZE,
203 &ivgen_ctx->pool_meta_dma, 185 &ivgen_ctx->pool_meta_dma,
204 GFP_KERNEL); 186 GFP_KERNEL);
205 if (!ivgen_ctx->pool_meta) { 187 if (!ivgen_ctx->pool_meta) {
206 dev_err(device, "Not enough memory to allocate DMA of pool_meta (%u B)\n", 188 dev_err(device, "Not enough memory to allocate DMA of pool_meta (%u B)\n",
207 SSI_IVPOOL_META_SIZE); 189 CC_IVPOOL_META_SIZE);
208 rc = -ENOMEM; 190 rc = -ENOMEM;
209 goto out; 191 goto out;
210 } 192 }
211 /* Allocate IV pool in SRAM */ 193 /* Allocate IV pool in SRAM */
212 ivgen_ctx->pool = ssi_sram_mgr_alloc(drvdata, SSI_IVPOOL_SIZE); 194 ivgen_ctx->pool = cc_sram_alloc(drvdata, CC_IVPOOL_SIZE);
213 if (ivgen_ctx->pool == NULL_SRAM_ADDR) { 195 if (ivgen_ctx->pool == NULL_SRAM_ADDR) {
214 dev_err(device, "SRAM pool exhausted\n"); 196 dev_err(device, "SRAM pool exhausted\n");
215 rc = -ENOMEM; 197 rc = -ENOMEM;
216 goto out; 198 goto out;
217 } 199 }
218 200
219 return ssi_ivgen_init_sram_pool(drvdata); 201 return cc_init_iv_sram(drvdata);
220 202
221out: 203out:
222 ssi_ivgen_fini(drvdata); 204 cc_ivgen_fini(drvdata);
223 return rc; 205 return rc;
224} 206}
225 207
@@ -228,37 +210,36 @@ out:
228 * 210 *
229 * \param drvdata Driver private context 211 * \param drvdata Driver private context
230 * \param iv_out_dma Array of physical IV out addresses 212 * \param iv_out_dma Array of physical IV out addresses
231 * \param iv_out_dma_len Length of iv_out_dma array (additional elements of iv_out_dma array are ignore) 213 * \param iv_out_dma_len Length of iv_out_dma array (additional elements
214 * of iv_out_dma array are ignore)
232 * \param iv_out_size May be 8 or 16 bytes long 215 * \param iv_out_size May be 8 or 16 bytes long
233 * \param iv_seq IN/OUT array to the descriptors sequence 216 * \param iv_seq IN/OUT array to the descriptors sequence
234 * \param iv_seq_len IN/OUT pointer to the sequence length 217 * \param iv_seq_len IN/OUT pointer to the sequence length
235 * 218 *
236 * \return int Zero for success, negative value otherwise. 219 * \return int Zero for success, negative value otherwise.
237 */ 220 */
238int ssi_ivgen_getiv( 221int cc_get_iv(struct cc_drvdata *drvdata, dma_addr_t iv_out_dma[],
239 struct ssi_drvdata *drvdata, 222 unsigned int iv_out_dma_len, unsigned int iv_out_size,
240 dma_addr_t iv_out_dma[], 223 struct cc_hw_desc iv_seq[], unsigned int *iv_seq_len)
241 unsigned int iv_out_dma_len,
242 unsigned int iv_out_size,
243 struct cc_hw_desc iv_seq[],
244 unsigned int *iv_seq_len)
245{ 224{
246 struct ssi_ivgen_ctx *ivgen_ctx = drvdata->ivgen_handle; 225 struct cc_ivgen_ctx *ivgen_ctx = drvdata->ivgen_handle;
247 unsigned int idx = *iv_seq_len; 226 unsigned int idx = *iv_seq_len;
248 struct device *dev = drvdata_to_dev(drvdata); 227 struct device *dev = drvdata_to_dev(drvdata);
249 unsigned int t; 228 unsigned int t;
250 229
251 if ((iv_out_size != CC_AES_IV_SIZE) && 230 if (iv_out_size != CC_AES_IV_SIZE &&
252 (iv_out_size != CTR_RFC3686_IV_SIZE)) { 231 iv_out_size != CTR_RFC3686_IV_SIZE) {
253 return -EINVAL; 232 return -EINVAL;
254 } 233 }
255 if ((iv_out_dma_len + 1) > SSI_IVPOOL_SEQ_LEN) { 234 if ((iv_out_dma_len + 1) > CC_IVPOOL_SEQ_LEN) {
256 /* The sequence will be longer than allowed */ 235 /* The sequence will be longer than allowed */
257 return -EINVAL; 236 return -EINVAL;
258 } 237 }
259 238
260 //check that number of generated IV is limited to max dma address iv buffer size 239 /* check that number of generated IV is limited to max dma address
261 if (iv_out_dma_len > SSI_MAX_IVGEN_DMA_ADDRESSES) { 240 * iv buffer size
241 */
242 if (iv_out_dma_len > CC_MAX_IVGEN_DMA_ADDRESSES) {
262 /* The sequence will be longer than allowed */ 243 /* The sequence will be longer than allowed */
263 return -EINVAL; 244 return -EINVAL;
264 } 245 }
@@ -288,10 +269,10 @@ int ssi_ivgen_getiv(
288 /* Update iv index */ 269 /* Update iv index */
289 ivgen_ctx->next_iv_ofs += iv_out_size; 270 ivgen_ctx->next_iv_ofs += iv_out_size;
290 271
291 if ((SSI_IVPOOL_SIZE - ivgen_ctx->next_iv_ofs) < CC_AES_IV_SIZE) { 272 if ((CC_IVPOOL_SIZE - ivgen_ctx->next_iv_ofs) < CC_AES_IV_SIZE) {
292 dev_dbg(dev, "Pool exhausted, regenerating iv-pool\n"); 273 dev_dbg(dev, "Pool exhausted, regenerating iv-pool\n");
293 /* pool is drained -regenerate it! */ 274 /* pool is drained -regenerate it! */
294 return ssi_ivgen_generate_pool(ivgen_ctx, iv_seq, iv_seq_len); 275 return cc_gen_iv_pool(ivgen_ctx, iv_seq, iv_seq_len);
295 } 276 }
296 277
297 return 0; 278 return 0;
diff --git a/drivers/staging/ccree/cc_ivgen.h b/drivers/staging/ccree/cc_ivgen.h
new file mode 100644
index 000000000000..b6ac16903dda
--- /dev/null
+++ b/drivers/staging/ccree/cc_ivgen.h
@@ -0,0 +1,55 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4#ifndef __CC_IVGEN_H__
5#define __CC_IVGEN_H__
6
7#include "cc_hw_queue_defs.h"
8
9#define CC_IVPOOL_SEQ_LEN 8
10
11/*!
12 * Allocates iv-pool and maps resources.
13 * This function generates the first IV pool.
14 *
15 * \param drvdata Driver's private context
16 *
17 * \return int Zero for success, negative value otherwise.
18 */
19int cc_ivgen_init(struct cc_drvdata *drvdata);
20
21/*!
22 * Free iv-pool and ivgen context.
23 *
24 * \param drvdata
25 */
26void cc_ivgen_fini(struct cc_drvdata *drvdata);
27
28/*!
29 * Generates the initial pool in SRAM.
30 * This function should be invoked when resuming DX driver.
31 *
32 * \param drvdata
33 *
34 * \return int Zero for success, negative value otherwise.
35 */
36int cc_init_iv_sram(struct cc_drvdata *drvdata);
37
38/*!
39 * Acquires 16 Bytes IV from the iv-pool
40 *
41 * \param drvdata Driver private context
42 * \param iv_out_dma Array of physical IV out addresses
43 * \param iv_out_dma_len Length of iv_out_dma array (additional elements of
44 * iv_out_dma array are ignore)
45 * \param iv_out_size May be 8 or 16 bytes long
46 * \param iv_seq IN/OUT array to the descriptors sequence
47 * \param iv_seq_len IN/OUT pointer to the sequence length
48 *
49 * \return int Zero for success, negative value otherwise.
50 */
51int cc_get_iv(struct cc_drvdata *drvdata, dma_addr_t iv_out_dma[],
52 unsigned int iv_out_dma_len, unsigned int iv_out_size,
53 struct cc_hw_desc iv_seq[], unsigned int *iv_seq_len);
54
55#endif /*__CC_IVGEN_H__*/
diff --git a/drivers/staging/ccree/cc_kernel_regs.h b/drivers/staging/ccree/cc_kernel_regs.h
new file mode 100644
index 000000000000..fa994406d610
--- /dev/null
+++ b/drivers/staging/ccree/cc_kernel_regs.h
@@ -0,0 +1,167 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4#ifndef __CC_CRYS_KERNEL_H__
5#define __CC_CRYS_KERNEL_H__
6
7// --------------------------------------
8// BLOCK: DSCRPTR
9// --------------------------------------
10#define CC_DSCRPTR_COMPLETION_COUNTER_REG_OFFSET 0xE00UL
11#define CC_DSCRPTR_COMPLETION_COUNTER_COMPLETION_COUNTER_BIT_SHIFT 0x0UL
12#define CC_DSCRPTR_COMPLETION_COUNTER_COMPLETION_COUNTER_BIT_SIZE 0x6UL
13#define CC_DSCRPTR_COMPLETION_COUNTER_OVERFLOW_COUNTER_BIT_SHIFT 0x6UL
14#define CC_DSCRPTR_COMPLETION_COUNTER_OVERFLOW_COUNTER_BIT_SIZE 0x1UL
15#define CC_DSCRPTR_SW_RESET_REG_OFFSET 0xE40UL
16#define CC_DSCRPTR_SW_RESET_VALUE_BIT_SHIFT 0x0UL
17#define CC_DSCRPTR_SW_RESET_VALUE_BIT_SIZE 0x1UL
18#define CC_DSCRPTR_QUEUE_SRAM_SIZE_REG_OFFSET 0xE60UL
19#define CC_DSCRPTR_QUEUE_SRAM_SIZE_NUM_OF_DSCRPTR_BIT_SHIFT 0x0UL
20#define CC_DSCRPTR_QUEUE_SRAM_SIZE_NUM_OF_DSCRPTR_BIT_SIZE 0xAUL
21#define CC_DSCRPTR_QUEUE_SRAM_SIZE_DSCRPTR_SRAM_SIZE_BIT_SHIFT 0xAUL
22#define CC_DSCRPTR_QUEUE_SRAM_SIZE_DSCRPTR_SRAM_SIZE_BIT_SIZE 0xCUL
23#define CC_DSCRPTR_QUEUE_SRAM_SIZE_SRAM_SIZE_BIT_SHIFT 0x16UL
24#define CC_DSCRPTR_QUEUE_SRAM_SIZE_SRAM_SIZE_BIT_SIZE 0x3UL
25#define CC_DSCRPTR_SINGLE_ADDR_EN_REG_OFFSET 0xE64UL
26#define CC_DSCRPTR_SINGLE_ADDR_EN_VALUE_BIT_SHIFT 0x0UL
27#define CC_DSCRPTR_SINGLE_ADDR_EN_VALUE_BIT_SIZE 0x1UL
28#define CC_DSCRPTR_MEASURE_CNTR_REG_OFFSET 0xE68UL
29#define CC_DSCRPTR_MEASURE_CNTR_VALUE_BIT_SHIFT 0x0UL
30#define CC_DSCRPTR_MEASURE_CNTR_VALUE_BIT_SIZE 0x20UL
31#define CC_DSCRPTR_QUEUE_WORD0_REG_OFFSET 0xE80UL
32#define CC_DSCRPTR_QUEUE_WORD0_VALUE_BIT_SHIFT 0x0UL
33#define CC_DSCRPTR_QUEUE_WORD0_VALUE_BIT_SIZE 0x20UL
34#define CC_DSCRPTR_QUEUE_WORD1_REG_OFFSET 0xE84UL
35#define CC_DSCRPTR_QUEUE_WORD1_DIN_DMA_MODE_BIT_SHIFT 0x0UL
36#define CC_DSCRPTR_QUEUE_WORD1_DIN_DMA_MODE_BIT_SIZE 0x2UL
37#define CC_DSCRPTR_QUEUE_WORD1_DIN_SIZE_BIT_SHIFT 0x2UL
38#define CC_DSCRPTR_QUEUE_WORD1_DIN_SIZE_BIT_SIZE 0x18UL
39#define CC_DSCRPTR_QUEUE_WORD1_NS_BIT_BIT_SHIFT 0x1AUL
40#define CC_DSCRPTR_QUEUE_WORD1_NS_BIT_BIT_SIZE 0x1UL
41#define CC_DSCRPTR_QUEUE_WORD1_DIN_CONST_VALUE_BIT_SHIFT 0x1BUL
42#define CC_DSCRPTR_QUEUE_WORD1_DIN_CONST_VALUE_BIT_SIZE 0x1UL
43#define CC_DSCRPTR_QUEUE_WORD1_NOT_LAST_BIT_SHIFT 0x1CUL
44#define CC_DSCRPTR_QUEUE_WORD1_NOT_LAST_BIT_SIZE 0x1UL
45#define CC_DSCRPTR_QUEUE_WORD1_LOCK_QUEUE_BIT_SHIFT 0x1DUL
46#define CC_DSCRPTR_QUEUE_WORD1_LOCK_QUEUE_BIT_SIZE 0x1UL
47#define CC_DSCRPTR_QUEUE_WORD1_NOT_USED_BIT_SHIFT 0x1EUL
48#define CC_DSCRPTR_QUEUE_WORD1_NOT_USED_BIT_SIZE 0x2UL
49#define CC_DSCRPTR_QUEUE_WORD2_REG_OFFSET 0xE88UL
50#define CC_DSCRPTR_QUEUE_WORD2_VALUE_BIT_SHIFT 0x0UL
51#define CC_DSCRPTR_QUEUE_WORD2_VALUE_BIT_SIZE 0x20UL
52#define CC_DSCRPTR_QUEUE_WORD3_REG_OFFSET 0xE8CUL
53#define CC_DSCRPTR_QUEUE_WORD3_DOUT_DMA_MODE_BIT_SHIFT 0x0UL
54#define CC_DSCRPTR_QUEUE_WORD3_DOUT_DMA_MODE_BIT_SIZE 0x2UL
55#define CC_DSCRPTR_QUEUE_WORD3_DOUT_SIZE_BIT_SHIFT 0x2UL
56#define CC_DSCRPTR_QUEUE_WORD3_DOUT_SIZE_BIT_SIZE 0x18UL
57#define CC_DSCRPTR_QUEUE_WORD3_NS_BIT_BIT_SHIFT 0x1AUL
58#define CC_DSCRPTR_QUEUE_WORD3_NS_BIT_BIT_SIZE 0x1UL
59#define CC_DSCRPTR_QUEUE_WORD3_DOUT_LAST_IND_BIT_SHIFT 0x1BUL
60#define CC_DSCRPTR_QUEUE_WORD3_DOUT_LAST_IND_BIT_SIZE 0x1UL
61#define CC_DSCRPTR_QUEUE_WORD3_HASH_XOR_BIT_BIT_SHIFT 0x1DUL
62#define CC_DSCRPTR_QUEUE_WORD3_HASH_XOR_BIT_BIT_SIZE 0x1UL
63#define CC_DSCRPTR_QUEUE_WORD3_NOT_USED_BIT_SHIFT 0x1EUL
64#define CC_DSCRPTR_QUEUE_WORD3_NOT_USED_BIT_SIZE 0x1UL
65#define CC_DSCRPTR_QUEUE_WORD3_QUEUE_LAST_IND_BIT_SHIFT 0x1FUL
66#define CC_DSCRPTR_QUEUE_WORD3_QUEUE_LAST_IND_BIT_SIZE 0x1UL
67#define CC_DSCRPTR_QUEUE_WORD4_REG_OFFSET 0xE90UL
68#define CC_DSCRPTR_QUEUE_WORD4_DATA_FLOW_MODE_BIT_SHIFT 0x0UL
69#define CC_DSCRPTR_QUEUE_WORD4_DATA_FLOW_MODE_BIT_SIZE 0x6UL
70#define CC_DSCRPTR_QUEUE_WORD4_AES_SEL_N_HASH_BIT_SHIFT 0x6UL
71#define CC_DSCRPTR_QUEUE_WORD4_AES_SEL_N_HASH_BIT_SIZE 0x1UL
72#define CC_DSCRPTR_QUEUE_WORD4_AES_XOR_CRYPTO_KEY_BIT_SHIFT 0x7UL
73#define CC_DSCRPTR_QUEUE_WORD4_AES_XOR_CRYPTO_KEY_BIT_SIZE 0x1UL
74#define CC_DSCRPTR_QUEUE_WORD4_ACK_NEEDED_BIT_SHIFT 0x8UL
75#define CC_DSCRPTR_QUEUE_WORD4_ACK_NEEDED_BIT_SIZE 0x2UL
76#define CC_DSCRPTR_QUEUE_WORD4_CIPHER_MODE_BIT_SHIFT 0xAUL
77#define CC_DSCRPTR_QUEUE_WORD4_CIPHER_MODE_BIT_SIZE 0x4UL
78#define CC_DSCRPTR_QUEUE_WORD4_CMAC_SIZE0_BIT_SHIFT 0xEUL
79#define CC_DSCRPTR_QUEUE_WORD4_CMAC_SIZE0_BIT_SIZE 0x1UL
80#define CC_DSCRPTR_QUEUE_WORD4_CIPHER_DO_BIT_SHIFT 0xFUL
81#define CC_DSCRPTR_QUEUE_WORD4_CIPHER_DO_BIT_SIZE 0x2UL
82#define CC_DSCRPTR_QUEUE_WORD4_CIPHER_CONF0_BIT_SHIFT 0x11UL
83#define CC_DSCRPTR_QUEUE_WORD4_CIPHER_CONF0_BIT_SIZE 0x2UL
84#define CC_DSCRPTR_QUEUE_WORD4_CIPHER_CONF1_BIT_SHIFT 0x13UL
85#define CC_DSCRPTR_QUEUE_WORD4_CIPHER_CONF1_BIT_SIZE 0x1UL
86#define CC_DSCRPTR_QUEUE_WORD4_CIPHER_CONF2_BIT_SHIFT 0x14UL
87#define CC_DSCRPTR_QUEUE_WORD4_CIPHER_CONF2_BIT_SIZE 0x2UL
88#define CC_DSCRPTR_QUEUE_WORD4_KEY_SIZE_BIT_SHIFT 0x16UL
89#define CC_DSCRPTR_QUEUE_WORD4_KEY_SIZE_BIT_SIZE 0x2UL
90#define CC_DSCRPTR_QUEUE_WORD4_SETUP_OPERATION_BIT_SHIFT 0x18UL
91#define CC_DSCRPTR_QUEUE_WORD4_SETUP_OPERATION_BIT_SIZE 0x4UL
92#define CC_DSCRPTR_QUEUE_WORD4_DIN_SRAM_ENDIANNESS_BIT_SHIFT 0x1CUL
93#define CC_DSCRPTR_QUEUE_WORD4_DIN_SRAM_ENDIANNESS_BIT_SIZE 0x1UL
94#define CC_DSCRPTR_QUEUE_WORD4_DOUT_SRAM_ENDIANNESS_BIT_SHIFT 0x1DUL
95#define CC_DSCRPTR_QUEUE_WORD4_DOUT_SRAM_ENDIANNESS_BIT_SIZE 0x1UL
96#define CC_DSCRPTR_QUEUE_WORD4_WORD_SWAP_BIT_SHIFT 0x1EUL
97#define CC_DSCRPTR_QUEUE_WORD4_WORD_SWAP_BIT_SIZE 0x1UL
98#define CC_DSCRPTR_QUEUE_WORD4_BYTES_SWAP_BIT_SHIFT 0x1FUL
99#define CC_DSCRPTR_QUEUE_WORD4_BYTES_SWAP_BIT_SIZE 0x1UL
100#define CC_DSCRPTR_QUEUE_WORD5_REG_OFFSET 0xE94UL
101#define CC_DSCRPTR_QUEUE_WORD5_DIN_ADDR_HIGH_BIT_SHIFT 0x0UL
102#define CC_DSCRPTR_QUEUE_WORD5_DIN_ADDR_HIGH_BIT_SIZE 0x10UL
103#define CC_DSCRPTR_QUEUE_WORD5_DOUT_ADDR_HIGH_BIT_SHIFT 0x10UL
104#define CC_DSCRPTR_QUEUE_WORD5_DOUT_ADDR_HIGH_BIT_SIZE 0x10UL
105#define CC_DSCRPTR_QUEUE_WATERMARK_REG_OFFSET 0xE98UL
106#define CC_DSCRPTR_QUEUE_WATERMARK_VALUE_BIT_SHIFT 0x0UL
107#define CC_DSCRPTR_QUEUE_WATERMARK_VALUE_BIT_SIZE 0xAUL
108#define CC_DSCRPTR_QUEUE_CONTENT_REG_OFFSET 0xE9CUL
109#define CC_DSCRPTR_QUEUE_CONTENT_VALUE_BIT_SHIFT 0x0UL
110#define CC_DSCRPTR_QUEUE_CONTENT_VALUE_BIT_SIZE 0xAUL
111// --------------------------------------
112// BLOCK: AXI_P
113// --------------------------------------
114#define CC_AXIM_MON_INFLIGHT_REG_OFFSET 0xB00UL
115#define CC_AXIM_MON_INFLIGHT_VALUE_BIT_SHIFT 0x0UL
116#define CC_AXIM_MON_INFLIGHT_VALUE_BIT_SIZE 0x8UL
117#define CC_AXIM_MON_INFLIGHTLAST_REG_OFFSET 0xB40UL
118#define CC_AXIM_MON_INFLIGHTLAST_VALUE_BIT_SHIFT 0x0UL
119#define CC_AXIM_MON_INFLIGHTLAST_VALUE_BIT_SIZE 0x8UL
120#define CC_AXIM_MON_COMP_REG_OFFSET 0xB80UL
121#define CC_AXIM_MON_COMP_VALUE_BIT_SHIFT 0x0UL
122#define CC_AXIM_MON_COMP_VALUE_BIT_SIZE 0x10UL
123#define CC_AXIM_MON_ERR_REG_OFFSET 0xBC4UL
124#define CC_AXIM_MON_ERR_BRESP_BIT_SHIFT 0x0UL
125#define CC_AXIM_MON_ERR_BRESP_BIT_SIZE 0x2UL
126#define CC_AXIM_MON_ERR_BID_BIT_SHIFT 0x2UL
127#define CC_AXIM_MON_ERR_BID_BIT_SIZE 0x4UL
128#define CC_AXIM_MON_ERR_RRESP_BIT_SHIFT 0x10UL
129#define CC_AXIM_MON_ERR_RRESP_BIT_SIZE 0x2UL
130#define CC_AXIM_MON_ERR_RID_BIT_SHIFT 0x12UL
131#define CC_AXIM_MON_ERR_RID_BIT_SIZE 0x4UL
132#define CC_AXIM_CFG_REG_OFFSET 0xBE8UL
133#define CC_AXIM_CFG_BRESPMASK_BIT_SHIFT 0x4UL
134#define CC_AXIM_CFG_BRESPMASK_BIT_SIZE 0x1UL
135#define CC_AXIM_CFG_RRESPMASK_BIT_SHIFT 0x5UL
136#define CC_AXIM_CFG_RRESPMASK_BIT_SIZE 0x1UL
137#define CC_AXIM_CFG_INFLTMASK_BIT_SHIFT 0x6UL
138#define CC_AXIM_CFG_INFLTMASK_BIT_SIZE 0x1UL
139#define CC_AXIM_CFG_COMPMASK_BIT_SHIFT 0x7UL
140#define CC_AXIM_CFG_COMPMASK_BIT_SIZE 0x1UL
141#define CC_AXIM_ACE_CONST_REG_OFFSET 0xBECUL
142#define CC_AXIM_ACE_CONST_ARDOMAIN_BIT_SHIFT 0x0UL
143#define CC_AXIM_ACE_CONST_ARDOMAIN_BIT_SIZE 0x2UL
144#define CC_AXIM_ACE_CONST_AWDOMAIN_BIT_SHIFT 0x2UL
145#define CC_AXIM_ACE_CONST_AWDOMAIN_BIT_SIZE 0x2UL
146#define CC_AXIM_ACE_CONST_ARBAR_BIT_SHIFT 0x4UL
147#define CC_AXIM_ACE_CONST_ARBAR_BIT_SIZE 0x2UL
148#define CC_AXIM_ACE_CONST_AWBAR_BIT_SHIFT 0x6UL
149#define CC_AXIM_ACE_CONST_AWBAR_BIT_SIZE 0x2UL
150#define CC_AXIM_ACE_CONST_ARSNOOP_BIT_SHIFT 0x8UL
151#define CC_AXIM_ACE_CONST_ARSNOOP_BIT_SIZE 0x4UL
152#define CC_AXIM_ACE_CONST_AWSNOOP_NOT_ALIGNED_BIT_SHIFT 0xCUL
153#define CC_AXIM_ACE_CONST_AWSNOOP_NOT_ALIGNED_BIT_SIZE 0x3UL
154#define CC_AXIM_ACE_CONST_AWSNOOP_ALIGNED_BIT_SHIFT 0xFUL
155#define CC_AXIM_ACE_CONST_AWSNOOP_ALIGNED_BIT_SIZE 0x3UL
156#define CC_AXIM_ACE_CONST_AWADDR_NOT_MASKED_BIT_SHIFT 0x12UL
157#define CC_AXIM_ACE_CONST_AWADDR_NOT_MASKED_BIT_SIZE 0x7UL
158#define CC_AXIM_ACE_CONST_AWLEN_VAL_BIT_SHIFT 0x19UL
159#define CC_AXIM_ACE_CONST_AWLEN_VAL_BIT_SIZE 0x4UL
160#define CC_AXIM_CACHE_PARAMS_REG_OFFSET 0xBF0UL
161#define CC_AXIM_CACHE_PARAMS_AWCACHE_LAST_BIT_SHIFT 0x0UL
162#define CC_AXIM_CACHE_PARAMS_AWCACHE_LAST_BIT_SIZE 0x4UL
163#define CC_AXIM_CACHE_PARAMS_AWCACHE_BIT_SHIFT 0x4UL
164#define CC_AXIM_CACHE_PARAMS_AWCACHE_BIT_SIZE 0x4UL
165#define CC_AXIM_CACHE_PARAMS_ARCACHE_BIT_SHIFT 0x8UL
166#define CC_AXIM_CACHE_PARAMS_ARCACHE_BIT_SIZE 0x4UL
167#endif // __CC_CRYS_KERNEL_H__
diff --git a/drivers/staging/ccree/cc_lli_defs.h b/drivers/staging/ccree/cc_lli_defs.h
index a9c417b07b04..64b15ac9f1d3 100644
--- a/drivers/staging/ccree/cc_lli_defs.h
+++ b/drivers/staging/ccree/cc_lli_defs.h
@@ -1,18 +1,5 @@
1/* 1/* SPDX-License-Identifier: GPL-2.0 */
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17#ifndef _CC_LLI_DEFS_H_ 4#ifndef _CC_LLI_DEFS_H_
18#define _CC_LLI_DEFS_H_ 5#define _CC_LLI_DEFS_H_
@@ -20,7 +7,7 @@
20#include <linux/types.h> 7#include <linux/types.h>
21 8
22/* Max DLLI size 9/* Max DLLI size
23 * AKA DX_DSCRPTR_QUEUE_WORD1_DIN_SIZE_BIT_SIZE 10 * AKA CC_DSCRPTR_QUEUE_WORD1_DIN_SIZE_BIT_SIZE
24 */ 11 */
25#define DLLI_SIZE_BIT_SIZE 0x18 12#define DLLI_SIZE_BIT_SIZE 0x18
26 13
diff --git a/drivers/staging/ccree/cc_pm.c b/drivers/staging/ccree/cc_pm.c
new file mode 100644
index 000000000000..d990f472e89f
--- /dev/null
+++ b/drivers/staging/ccree/cc_pm.c
@@ -0,0 +1,122 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4#include <linux/kernel.h>
5#include <linux/interrupt.h>
6#include <linux/pm_runtime.h>
7#include "cc_driver.h"
8#include "cc_buffer_mgr.h"
9#include "cc_request_mgr.h"
10#include "cc_sram_mgr.h"
11#include "cc_ivgen.h"
12#include "cc_hash.h"
13#include "cc_pm.h"
14
15#define POWER_DOWN_ENABLE 0x01
16#define POWER_DOWN_DISABLE 0x00
17
18const struct dev_pm_ops ccree_pm = {
19 SET_RUNTIME_PM_OPS(cc_pm_suspend, cc_pm_resume, NULL)
20};
21
22int cc_pm_suspend(struct device *dev)
23{
24 struct cc_drvdata *drvdata = dev_get_drvdata(dev);
25 int rc;
26
27 dev_dbg(dev, "set HOST_POWER_DOWN_EN\n");
28 cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_ENABLE);
29 rc = cc_suspend_req_queue(drvdata);
30 if (rc) {
31 dev_err(dev, "cc_suspend_req_queue (%x)\n", rc);
32 return rc;
33 }
34 fini_cc_regs(drvdata);
35 cc_clk_off(drvdata);
36 return 0;
37}
38
39int cc_pm_resume(struct device *dev)
40{
41 int rc;
42 struct cc_drvdata *drvdata = dev_get_drvdata(dev);
43
44 dev_dbg(dev, "unset HOST_POWER_DOWN_EN\n");
45 cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE);
46
47 rc = cc_clk_on(drvdata);
48 if (rc) {
49 dev_err(dev, "failed getting clock back on. We're toast.\n");
50 return rc;
51 }
52
53 rc = init_cc_regs(drvdata, false);
54 if (rc) {
55 dev_err(dev, "init_cc_regs (%x)\n", rc);
56 return rc;
57 }
58
59 rc = cc_resume_req_queue(drvdata);
60 if (rc) {
61 dev_err(dev, "cc_resume_req_queue (%x)\n", rc);
62 return rc;
63 }
64
65 /* must be after the queue resuming as it uses the HW queue*/
66 cc_init_hash_sram(drvdata);
67
68 cc_init_iv_sram(drvdata);
69 return 0;
70}
71
72int cc_pm_get(struct device *dev)
73{
74 int rc = 0;
75 struct cc_drvdata *drvdata = dev_get_drvdata(dev);
76
77 if (cc_req_queue_suspended(drvdata))
78 rc = pm_runtime_get_sync(dev);
79 else
80 pm_runtime_get_noresume(dev);
81
82 return rc;
83}
84
85int cc_pm_put_suspend(struct device *dev)
86{
87 int rc = 0;
88 struct cc_drvdata *drvdata = dev_get_drvdata(dev);
89
90 if (!cc_req_queue_suspended(drvdata)) {
91 pm_runtime_mark_last_busy(dev);
92 rc = pm_runtime_put_autosuspend(dev);
93 } else {
94 /* Something wrong happens*/
95 dev_err(dev, "request to suspend already suspended queue");
96 rc = -EBUSY;
97 }
98 return rc;
99}
100
101int cc_pm_init(struct cc_drvdata *drvdata)
102{
103 int rc = 0;
104 struct device *dev = drvdata_to_dev(drvdata);
105
106 /* must be before the enabling to avoid resdundent suspending */
107 pm_runtime_set_autosuspend_delay(dev, CC_SUSPEND_TIMEOUT);
108 pm_runtime_use_autosuspend(dev);
109 /* activate the PM module */
110 rc = pm_runtime_set_active(dev);
111 if (rc)
112 return rc;
113 /* enable the PM module*/
114 pm_runtime_enable(dev);
115
116 return rc;
117}
118
119void cc_pm_fini(struct cc_drvdata *drvdata)
120{
121 pm_runtime_disable(drvdata_to_dev(drvdata));
122}
diff --git a/drivers/staging/ccree/cc_pm.h b/drivers/staging/ccree/cc_pm.h
new file mode 100644
index 000000000000..aac8190fea38
--- /dev/null
+++ b/drivers/staging/ccree/cc_pm.h
@@ -0,0 +1,57 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4/* \file cc_pm.h
5 */
6
7#ifndef __CC_POWER_MGR_H__
8#define __CC_POWER_MGR_H__
9
10#include "cc_driver.h"
11
12#define CC_SUSPEND_TIMEOUT 3000
13
14#if defined(CONFIG_PM)
15
16extern const struct dev_pm_ops ccree_pm;
17
18int cc_pm_init(struct cc_drvdata *drvdata);
19void cc_pm_fini(struct cc_drvdata *drvdata);
20int cc_pm_suspend(struct device *dev);
21int cc_pm_resume(struct device *dev);
22int cc_pm_get(struct device *dev);
23int cc_pm_put_suspend(struct device *dev);
24
25#else
26
27static inline int cc_pm_init(struct cc_drvdata *drvdata)
28{
29 return 0;
30}
31
32static inline void cc_pm_fini(struct cc_drvdata *drvdata) {}
33
34static inline int cc_pm_suspend(struct device *dev)
35{
36 return 0;
37}
38
39static inline int cc_pm_resume(struct device *dev)
40{
41 return 0;
42}
43
44static inline int cc_pm_get(struct device *dev)
45{
46 return 0;
47}
48
49static inline int cc_pm_put_suspend(struct device *dev)
50{
51 return 0;
52}
53
54#endif
55
56#endif /*__POWER_MGR_H__*/
57
diff --git a/drivers/staging/ccree/cc_request_mgr.c b/drivers/staging/ccree/cc_request_mgr.c
new file mode 100644
index 000000000000..8a7f83407410
--- /dev/null
+++ b/drivers/staging/ccree/cc_request_mgr.c
@@ -0,0 +1,713 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4#include <linux/kernel.h>
5#include "cc_driver.h"
6#include "cc_buffer_mgr.h"
7#include "cc_request_mgr.h"
8#include "cc_ivgen.h"
9#include "cc_pm.h"
10
11#define CC_MAX_POLL_ITER 10
12/* The highest descriptor count in used */
13#define CC_MAX_DESC_SEQ_LEN 23
14
15struct cc_req_mgr_handle {
16 /* Request manager resources */
17 unsigned int hw_queue_size; /* HW capability */
18 unsigned int min_free_hw_slots;
19 unsigned int max_used_sw_slots;
20 struct cc_crypto_req req_queue[MAX_REQUEST_QUEUE_SIZE];
21 u32 req_queue_head;
22 u32 req_queue_tail;
23 u32 axi_completed;
24 u32 q_free_slots;
25 /* This lock protects access to HW register
26 * that must be single request at a time
27 */
28 spinlock_t hw_lock;
29 struct cc_hw_desc compl_desc;
30 u8 *dummy_comp_buff;
31 dma_addr_t dummy_comp_buff_dma;
32
33 /* backlog queue */
34 struct list_head backlog;
35 unsigned int bl_len;
36 spinlock_t bl_lock; /* protect backlog queue */
37
38#ifdef COMP_IN_WQ
39 struct workqueue_struct *workq;
40 struct delayed_work compwork;
41#else
42 struct tasklet_struct comptask;
43#endif
44 bool is_runtime_suspended;
45};
46
47struct cc_bl_item {
48 struct cc_crypto_req creq;
49 struct cc_hw_desc desc[CC_MAX_DESC_SEQ_LEN];
50 unsigned int len;
51 struct list_head list;
52 bool notif;
53};
54
55static void comp_handler(unsigned long devarg);
56#ifdef COMP_IN_WQ
57static void comp_work_handler(struct work_struct *work);
58#endif
59
60void cc_req_mgr_fini(struct cc_drvdata *drvdata)
61{
62 struct cc_req_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
63 struct device *dev = drvdata_to_dev(drvdata);
64
65 if (!req_mgr_h)
66 return; /* Not allocated */
67
68 if (req_mgr_h->dummy_comp_buff_dma) {
69 dma_free_coherent(dev, sizeof(u32), req_mgr_h->dummy_comp_buff,
70 req_mgr_h->dummy_comp_buff_dma);
71 }
72
73 dev_dbg(dev, "max_used_hw_slots=%d\n", (req_mgr_h->hw_queue_size -
74 req_mgr_h->min_free_hw_slots));
75 dev_dbg(dev, "max_used_sw_slots=%d\n", req_mgr_h->max_used_sw_slots);
76
77#ifdef COMP_IN_WQ
78 flush_workqueue(req_mgr_h->workq);
79 destroy_workqueue(req_mgr_h->workq);
80#else
81 /* Kill tasklet */
82 tasklet_kill(&req_mgr_h->comptask);
83#endif
84 memset(req_mgr_h, 0, sizeof(struct cc_req_mgr_handle));
85 kfree(req_mgr_h);
86 drvdata->request_mgr_handle = NULL;
87}
88
89int cc_req_mgr_init(struct cc_drvdata *drvdata)
90{
91 struct cc_req_mgr_handle *req_mgr_h;
92 struct device *dev = drvdata_to_dev(drvdata);
93 int rc = 0;
94
95 req_mgr_h = kzalloc(sizeof(*req_mgr_h), GFP_KERNEL);
96 if (!req_mgr_h) {
97 rc = -ENOMEM;
98 goto req_mgr_init_err;
99 }
100
101 drvdata->request_mgr_handle = req_mgr_h;
102
103 spin_lock_init(&req_mgr_h->hw_lock);
104 spin_lock_init(&req_mgr_h->bl_lock);
105 INIT_LIST_HEAD(&req_mgr_h->backlog);
106
107#ifdef COMP_IN_WQ
108 dev_dbg(dev, "Initializing completion workqueue\n");
109 req_mgr_h->workq = create_singlethread_workqueue("arm_cc7x_wq");
110 if (!req_mgr_h->workq) {
111 dev_err(dev, "Failed creating work queue\n");
112 rc = -ENOMEM;
113 goto req_mgr_init_err;
114 }
115 INIT_DELAYED_WORK(&req_mgr_h->compwork, comp_work_handler);
116#else
117 dev_dbg(dev, "Initializing completion tasklet\n");
118 tasklet_init(&req_mgr_h->comptask, comp_handler,
119 (unsigned long)drvdata);
120#endif
121 req_mgr_h->hw_queue_size = cc_ioread(drvdata,
122 CC_REG(DSCRPTR_QUEUE_SRAM_SIZE));
123 dev_dbg(dev, "hw_queue_size=0x%08X\n", req_mgr_h->hw_queue_size);
124 if (req_mgr_h->hw_queue_size < MIN_HW_QUEUE_SIZE) {
125 dev_err(dev, "Invalid HW queue size = %u (Min. required is %u)\n",
126 req_mgr_h->hw_queue_size, MIN_HW_QUEUE_SIZE);
127 rc = -ENOMEM;
128 goto req_mgr_init_err;
129 }
130 req_mgr_h->min_free_hw_slots = req_mgr_h->hw_queue_size;
131 req_mgr_h->max_used_sw_slots = 0;
132
133 /* Allocate DMA word for "dummy" completion descriptor use */
134 req_mgr_h->dummy_comp_buff =
135 dma_alloc_coherent(dev, sizeof(u32),
136 &req_mgr_h->dummy_comp_buff_dma,
137 GFP_KERNEL);
138 if (!req_mgr_h->dummy_comp_buff) {
139 dev_err(dev, "Not enough memory to allocate DMA (%zu) dropped buffer\n",
140 sizeof(u32));
141 rc = -ENOMEM;
142 goto req_mgr_init_err;
143 }
144
145 /* Init. "dummy" completion descriptor */
146 hw_desc_init(&req_mgr_h->compl_desc);
147 set_din_const(&req_mgr_h->compl_desc, 0, sizeof(u32));
148 set_dout_dlli(&req_mgr_h->compl_desc, req_mgr_h->dummy_comp_buff_dma,
149 sizeof(u32), NS_BIT, 1);
150 set_flow_mode(&req_mgr_h->compl_desc, BYPASS);
151 set_queue_last_ind(&req_mgr_h->compl_desc);
152
153 return 0;
154
155req_mgr_init_err:
156 cc_req_mgr_fini(drvdata);
157 return rc;
158}
159
160static void enqueue_seq(struct cc_drvdata *drvdata, struct cc_hw_desc seq[],
161 unsigned int seq_len)
162{
163 int i, w;
164 void __iomem *reg = drvdata->cc_base + CC_REG(DSCRPTR_QUEUE_WORD0);
165 struct device *dev = drvdata_to_dev(drvdata);
166
167 /*
168 * We do indeed write all 6 command words to the same
169 * register. The HW supports this.
170 */
171
172 for (i = 0; i < seq_len; i++) {
173 for (w = 0; w <= 5; w++)
174 writel_relaxed(seq[i].word[w], reg);
175
176 if (cc_dump_desc)
177 dev_dbg(dev, "desc[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
178 i, seq[i].word[0], seq[i].word[1],
179 seq[i].word[2], seq[i].word[3],
180 seq[i].word[4], seq[i].word[5]);
181 }
182}
183
184/*!
185 * Completion will take place if and only if user requested completion
186 * by cc_send_sync_request().
187 *
188 * \param dev
189 * \param dx_compl_h The completion event to signal
190 */
191static void request_mgr_complete(struct device *dev, void *dx_compl_h,
192 int dummy)
193{
194 struct completion *this_compl = dx_compl_h;
195
196 complete(this_compl);
197}
198
199static int cc_queues_status(struct cc_drvdata *drvdata,
200 struct cc_req_mgr_handle *req_mgr_h,
201 unsigned int total_seq_len)
202{
203 unsigned long poll_queue;
204 struct device *dev = drvdata_to_dev(drvdata);
205
206 /* SW queue is checked only once as it will not
207 * be chaned during the poll because the spinlock_bh
208 * is held by the thread
209 */
210 if (((req_mgr_h->req_queue_head + 1) & (MAX_REQUEST_QUEUE_SIZE - 1)) ==
211 req_mgr_h->req_queue_tail) {
212 dev_err(dev, "SW FIFO is full. req_queue_head=%d sw_fifo_len=%d\n",
213 req_mgr_h->req_queue_head, MAX_REQUEST_QUEUE_SIZE);
214 return -ENOSPC;
215 }
216
217 if (req_mgr_h->q_free_slots >= total_seq_len)
218 return 0;
219
220 /* Wait for space in HW queue. Poll constant num of iterations. */
221 for (poll_queue = 0; poll_queue < CC_MAX_POLL_ITER ; poll_queue++) {
222 req_mgr_h->q_free_slots =
223 cc_ioread(drvdata, CC_REG(DSCRPTR_QUEUE_CONTENT));
224 if (req_mgr_h->q_free_slots < req_mgr_h->min_free_hw_slots)
225 req_mgr_h->min_free_hw_slots = req_mgr_h->q_free_slots;
226
227 if (req_mgr_h->q_free_slots >= total_seq_len) {
228 /* If there is enough place return */
229 return 0;
230 }
231
232 dev_dbg(dev, "HW FIFO is full. q_free_slots=%d total_seq_len=%d\n",
233 req_mgr_h->q_free_slots, total_seq_len);
234 }
235 /* No room in the HW queue try again later */
236 dev_dbg(dev, "HW FIFO full, timeout. req_queue_head=%d sw_fifo_len=%d q_free_slots=%d total_seq_len=%d\n",
237 req_mgr_h->req_queue_head, MAX_REQUEST_QUEUE_SIZE,
238 req_mgr_h->q_free_slots, total_seq_len);
239 return -ENOSPC;
240}
241
242/*!
243 * Enqueue caller request to crypto hardware.
244 * Need to be called with HW lock held and PM running
245 *
246 * \param drvdata
247 * \param cc_req The request to enqueue
248 * \param desc The crypto sequence
249 * \param len The crypto sequence length
250 * \param add_comp If "true": add an artificial dout DMA to mark completion
251 *
252 * \return int Returns -EINPROGRESS or error code
253 */
254static int cc_do_send_request(struct cc_drvdata *drvdata,
255 struct cc_crypto_req *cc_req,
256 struct cc_hw_desc *desc, unsigned int len,
257 bool add_comp, bool ivgen)
258{
259 struct cc_req_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
260 unsigned int used_sw_slots;
261 unsigned int iv_seq_len = 0;
262 unsigned int total_seq_len = len; /*initial sequence length*/
263 struct cc_hw_desc iv_seq[CC_IVPOOL_SEQ_LEN];
264 struct device *dev = drvdata_to_dev(drvdata);
265 int rc;
266
267 if (ivgen) {
268 dev_dbg(dev, "Acquire IV from pool into %d DMA addresses %pad, %pad, %pad, IV-size=%u\n",
269 cc_req->ivgen_dma_addr_len,
270 &cc_req->ivgen_dma_addr[0],
271 &cc_req->ivgen_dma_addr[1],
272 &cc_req->ivgen_dma_addr[2],
273 cc_req->ivgen_size);
274
275 /* Acquire IV from pool */
276 rc = cc_get_iv(drvdata, cc_req->ivgen_dma_addr,
277 cc_req->ivgen_dma_addr_len,
278 cc_req->ivgen_size, iv_seq, &iv_seq_len);
279
280 if (rc) {
281 dev_err(dev, "Failed to generate IV (rc=%d)\n", rc);
282 return rc;
283 }
284
285 total_seq_len += iv_seq_len;
286 }
287
288 used_sw_slots = ((req_mgr_h->req_queue_head -
289 req_mgr_h->req_queue_tail) &
290 (MAX_REQUEST_QUEUE_SIZE - 1));
291 if (used_sw_slots > req_mgr_h->max_used_sw_slots)
292 req_mgr_h->max_used_sw_slots = used_sw_slots;
293
294 /* Enqueue request - must be locked with HW lock*/
295 req_mgr_h->req_queue[req_mgr_h->req_queue_head] = *cc_req;
296 req_mgr_h->req_queue_head = (req_mgr_h->req_queue_head + 1) &
297 (MAX_REQUEST_QUEUE_SIZE - 1);
298 /* TODO: Use circ_buf.h ? */
299
300 dev_dbg(dev, "Enqueue request head=%u\n", req_mgr_h->req_queue_head);
301
302 /*
303 * We are about to push command to the HW via the command registers
304 * that may refernece hsot memory. We need to issue a memory barrier
305 * to make sure there are no outstnading memory writes
306 */
307 wmb();
308
309 /* STAT_PHASE_4: Push sequence */
310 if (ivgen)
311 enqueue_seq(drvdata, iv_seq, iv_seq_len);
312
313 enqueue_seq(drvdata, desc, len);
314
315 if (add_comp) {
316 enqueue_seq(drvdata, &req_mgr_h->compl_desc, 1);
317 total_seq_len++;
318 }
319
320 if (req_mgr_h->q_free_slots < total_seq_len) {
321 /* This situation should never occur. Maybe indicating problem
322 * with resuming power. Set the free slot count to 0 and hope
323 * for the best.
324 */
325 dev_err(dev, "HW free slot count mismatch.");
326 req_mgr_h->q_free_slots = 0;
327 } else {
328 /* Update the free slots in HW queue */
329 req_mgr_h->q_free_slots -= total_seq_len;
330 }
331
332 /* Operation still in process */
333 return -EINPROGRESS;
334}
335
336static void cc_enqueue_backlog(struct cc_drvdata *drvdata,
337 struct cc_bl_item *bli)
338{
339 struct cc_req_mgr_handle *mgr = drvdata->request_mgr_handle;
340
341 spin_lock_bh(&mgr->bl_lock);
342 list_add_tail(&bli->list, &mgr->backlog);
343 ++mgr->bl_len;
344 spin_unlock_bh(&mgr->bl_lock);
345 tasklet_schedule(&mgr->comptask);
346}
347
348static void cc_proc_backlog(struct cc_drvdata *drvdata)
349{
350 struct cc_req_mgr_handle *mgr = drvdata->request_mgr_handle;
351 struct cc_bl_item *bli;
352 struct cc_crypto_req *creq;
353 struct crypto_async_request *req;
354 bool ivgen;
355 unsigned int total_len;
356 struct device *dev = drvdata_to_dev(drvdata);
357 int rc;
358
359 spin_lock(&mgr->bl_lock);
360
361 while (mgr->bl_len) {
362 bli = list_first_entry(&mgr->backlog, struct cc_bl_item, list);
363 spin_unlock(&mgr->bl_lock);
364
365 creq = &bli->creq;
366 req = (struct crypto_async_request *)creq->user_arg;
367
368 /*
369 * Notify the request we're moving out of the backlog
370 * but only if we haven't done so already.
371 */
372 if (!bli->notif) {
373 req->complete(req, -EINPROGRESS);
374 bli->notif = true;
375 }
376
377 ivgen = !!creq->ivgen_dma_addr_len;
378 total_len = bli->len + (ivgen ? CC_IVPOOL_SEQ_LEN : 0);
379
380 spin_lock(&mgr->hw_lock);
381
382 rc = cc_queues_status(drvdata, mgr, total_len);
383 if (rc) {
384 /*
385 * There is still not room in the FIFO for
386 * this request. Bail out. We'll return here
387 * on the next completion irq.
388 */
389 spin_unlock(&mgr->hw_lock);
390 return;
391 }
392
393 rc = cc_do_send_request(drvdata, &bli->creq, bli->desc,
394 bli->len, false, ivgen);
395
396 spin_unlock(&mgr->hw_lock);
397
398 if (rc != -EINPROGRESS) {
399 cc_pm_put_suspend(dev);
400 creq->user_cb(dev, req, rc);
401 }
402
403 /* Remove ourselves from the backlog list */
404 spin_lock(&mgr->bl_lock);
405 list_del(&bli->list);
406 --mgr->bl_len;
407 }
408
409 spin_unlock(&mgr->bl_lock);
410}
411
412int cc_send_request(struct cc_drvdata *drvdata, struct cc_crypto_req *cc_req,
413 struct cc_hw_desc *desc, unsigned int len,
414 struct crypto_async_request *req)
415{
416 int rc;
417 struct cc_req_mgr_handle *mgr = drvdata->request_mgr_handle;
418 bool ivgen = !!cc_req->ivgen_dma_addr_len;
419 unsigned int total_len = len + (ivgen ? CC_IVPOOL_SEQ_LEN : 0);
420 struct device *dev = drvdata_to_dev(drvdata);
421 bool backlog_ok = req->flags & CRYPTO_TFM_REQ_MAY_BACKLOG;
422 gfp_t flags = cc_gfp_flags(req);
423 struct cc_bl_item *bli;
424
425 rc = cc_pm_get(dev);
426 if (rc) {
427 dev_err(dev, "ssi_power_mgr_runtime_get returned %x\n", rc);
428 return rc;
429 }
430
431 spin_lock_bh(&mgr->hw_lock);
432 rc = cc_queues_status(drvdata, mgr, total_len);
433
434#ifdef CC_DEBUG_FORCE_BACKLOG
435 if (backlog_ok)
436 rc = -ENOSPC;
437#endif /* CC_DEBUG_FORCE_BACKLOG */
438
439 if (rc == -ENOSPC && backlog_ok) {
440 spin_unlock_bh(&mgr->hw_lock);
441
442 bli = kmalloc(sizeof(*bli), flags);
443 if (!bli) {
444 cc_pm_put_suspend(dev);
445 return -ENOMEM;
446 }
447
448 memcpy(&bli->creq, cc_req, sizeof(*cc_req));
449 memcpy(&bli->desc, desc, len * sizeof(*desc));
450 bli->len = len;
451 bli->notif = false;
452 cc_enqueue_backlog(drvdata, bli);
453 return -EBUSY;
454 }
455
456 if (!rc)
457 rc = cc_do_send_request(drvdata, cc_req, desc, len, false,
458 ivgen);
459
460 spin_unlock_bh(&mgr->hw_lock);
461 return rc;
462}
463
464int cc_send_sync_request(struct cc_drvdata *drvdata,
465 struct cc_crypto_req *cc_req, struct cc_hw_desc *desc,
466 unsigned int len)
467{
468 int rc;
469 struct device *dev = drvdata_to_dev(drvdata);
470 struct cc_req_mgr_handle *mgr = drvdata->request_mgr_handle;
471
472 init_completion(&cc_req->seq_compl);
473 cc_req->user_cb = request_mgr_complete;
474 cc_req->user_arg = &cc_req->seq_compl;
475
476 rc = cc_pm_get(dev);
477 if (rc) {
478 dev_err(dev, "ssi_power_mgr_runtime_get returned %x\n", rc);
479 return rc;
480 }
481
482 while (true) {
483 spin_lock_bh(&mgr->hw_lock);
484 rc = cc_queues_status(drvdata, mgr, len + 1);
485
486 if (!rc)
487 break;
488
489 spin_unlock_bh(&mgr->hw_lock);
490 if (rc != -EAGAIN) {
491 cc_pm_put_suspend(dev);
492 return rc;
493 }
494 wait_for_completion_interruptible(&drvdata->hw_queue_avail);
495 reinit_completion(&drvdata->hw_queue_avail);
496 }
497
498 rc = cc_do_send_request(drvdata, cc_req, desc, len, true, false);
499 spin_unlock_bh(&mgr->hw_lock);
500
501 if (rc != -EINPROGRESS) {
502 cc_pm_put_suspend(dev);
503 return rc;
504 }
505
506 wait_for_completion(&cc_req->seq_compl);
507 return 0;
508}
509
510/*!
511 * Enqueue caller request to crypto hardware during init process.
512 * assume this function is not called in middle of a flow,
513 * since we set QUEUE_LAST_IND flag in the last descriptor.
514 *
515 * \param drvdata
516 * \param desc The crypto sequence
517 * \param len The crypto sequence length
518 *
519 * \return int Returns "0" upon success
520 */
521int send_request_init(struct cc_drvdata *drvdata, struct cc_hw_desc *desc,
522 unsigned int len)
523{
524 struct cc_req_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
525 unsigned int total_seq_len = len; /*initial sequence length*/
526 int rc = 0;
527
528 /* Wait for space in HW and SW FIFO. Poll for as much as FIFO_TIMEOUT.
529 */
530 rc = cc_queues_status(drvdata, req_mgr_h, total_seq_len);
531 if (rc)
532 return rc;
533
534 set_queue_last_ind(&desc[(len - 1)]);
535
536 /*
537 * We are about to push command to the HW via the command registers
538 * that may refernece hsot memory. We need to issue a memory barrier
539 * to make sure there are no outstnading memory writes
540 */
541 wmb();
542 enqueue_seq(drvdata, desc, len);
543
544 /* Update the free slots in HW queue */
545 req_mgr_h->q_free_slots =
546 cc_ioread(drvdata, CC_REG(DSCRPTR_QUEUE_CONTENT));
547
548 return 0;
549}
550
551void complete_request(struct cc_drvdata *drvdata)
552{
553 struct cc_req_mgr_handle *request_mgr_handle =
554 drvdata->request_mgr_handle;
555
556 complete(&drvdata->hw_queue_avail);
557#ifdef COMP_IN_WQ
558 queue_delayed_work(request_mgr_handle->workq,
559 &request_mgr_handle->compwork, 0);
560#else
561 tasklet_schedule(&request_mgr_handle->comptask);
562#endif
563}
564
565#ifdef COMP_IN_WQ
566static void comp_work_handler(struct work_struct *work)
567{
568 struct cc_drvdata *drvdata =
569 container_of(work, struct cc_drvdata, compwork.work);
570
571 comp_handler((unsigned long)drvdata);
572}
573#endif
574
575static void proc_completions(struct cc_drvdata *drvdata)
576{
577 struct cc_crypto_req *cc_req;
578 struct device *dev = drvdata_to_dev(drvdata);
579 struct cc_req_mgr_handle *request_mgr_handle =
580 drvdata->request_mgr_handle;
581 unsigned int *tail = &request_mgr_handle->req_queue_tail;
582 unsigned int *head = &request_mgr_handle->req_queue_head;
583
584 while (request_mgr_handle->axi_completed) {
585 request_mgr_handle->axi_completed--;
586
587 /* Dequeue request */
588 if (*head == *tail) {
589 /* We are supposed to handle a completion but our
590 * queue is empty. This is not normal. Return and
591 * hope for the best.
592 */
593 dev_err(dev, "Request queue is empty head == tail %u\n",
594 *head);
595 break;
596 }
597
598 cc_req = &request_mgr_handle->req_queue[*tail];
599
600 if (cc_req->user_cb)
601 cc_req->user_cb(dev, cc_req->user_arg, 0);
602 *tail = (*tail + 1) & (MAX_REQUEST_QUEUE_SIZE - 1);
603 dev_dbg(dev, "Dequeue request tail=%u\n", *tail);
604 dev_dbg(dev, "Request completed. axi_completed=%d\n",
605 request_mgr_handle->axi_completed);
606 cc_pm_put_suspend(dev);
607 }
608}
609
610static inline u32 cc_axi_comp_count(struct cc_drvdata *drvdata)
611{
612 return FIELD_GET(AXIM_MON_COMP_VALUE,
613 cc_ioread(drvdata, CC_REG(AXIM_MON_COMP)));
614}
615
616/* Deferred service handler, run as interrupt-fired tasklet */
617static void comp_handler(unsigned long devarg)
618{
619 struct cc_drvdata *drvdata = (struct cc_drvdata *)devarg;
620 struct cc_req_mgr_handle *request_mgr_handle =
621 drvdata->request_mgr_handle;
622
623 u32 irq;
624
625 irq = (drvdata->irq & CC_COMP_IRQ_MASK);
626
627 if (irq & CC_COMP_IRQ_MASK) {
628 /* To avoid the interrupt from firing as we unmask it,
629 * we clear it now
630 */
631 cc_iowrite(drvdata, CC_REG(HOST_ICR), CC_COMP_IRQ_MASK);
632
633 /* Avoid race with above clear: Test completion counter
634 * once more
635 */
636 request_mgr_handle->axi_completed +=
637 cc_axi_comp_count(drvdata);
638
639 while (request_mgr_handle->axi_completed) {
640 do {
641 proc_completions(drvdata);
642 /* At this point (after proc_completions()),
643 * request_mgr_handle->axi_completed is 0.
644 */
645 request_mgr_handle->axi_completed =
646 cc_axi_comp_count(drvdata);
647 } while (request_mgr_handle->axi_completed > 0);
648
649 cc_iowrite(drvdata, CC_REG(HOST_ICR),
650 CC_COMP_IRQ_MASK);
651
652 request_mgr_handle->axi_completed +=
653 cc_axi_comp_count(drvdata);
654 }
655 }
656 /* after verifing that there is nothing to do,
657 * unmask AXI completion interrupt
658 */
659 cc_iowrite(drvdata, CC_REG(HOST_IMR),
660 cc_ioread(drvdata, CC_REG(HOST_IMR)) & ~irq);
661
662 cc_proc_backlog(drvdata);
663}
664
665/*
666 * resume the queue configuration - no need to take the lock as this happens
667 * inside the spin lock protection
668 */
669#if defined(CONFIG_PM)
670int cc_resume_req_queue(struct cc_drvdata *drvdata)
671{
672 struct cc_req_mgr_handle *request_mgr_handle =
673 drvdata->request_mgr_handle;
674
675 spin_lock_bh(&request_mgr_handle->hw_lock);
676 request_mgr_handle->is_runtime_suspended = false;
677 spin_unlock_bh(&request_mgr_handle->hw_lock);
678
679 return 0;
680}
681
682/*
683 * suspend the queue configuration. Since it is used for the runtime suspend
684 * only verify that the queue can be suspended.
685 */
686int cc_suspend_req_queue(struct cc_drvdata *drvdata)
687{
688 struct cc_req_mgr_handle *request_mgr_handle =
689 drvdata->request_mgr_handle;
690
691 /* lock the send_request */
692 spin_lock_bh(&request_mgr_handle->hw_lock);
693 if (request_mgr_handle->req_queue_head !=
694 request_mgr_handle->req_queue_tail) {
695 spin_unlock_bh(&request_mgr_handle->hw_lock);
696 return -EBUSY;
697 }
698 request_mgr_handle->is_runtime_suspended = true;
699 spin_unlock_bh(&request_mgr_handle->hw_lock);
700
701 return 0;
702}
703
704bool cc_req_queue_suspended(struct cc_drvdata *drvdata)
705{
706 struct cc_req_mgr_handle *request_mgr_handle =
707 drvdata->request_mgr_handle;
708
709 return request_mgr_handle->is_runtime_suspended;
710}
711
712#endif
713
diff --git a/drivers/staging/ccree/cc_request_mgr.h b/drivers/staging/ccree/cc_request_mgr.h
new file mode 100644
index 000000000000..573cb97af085
--- /dev/null
+++ b/drivers/staging/ccree/cc_request_mgr.h
@@ -0,0 +1,51 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4/* \file cc_request_mgr.h
5 * Request Manager
6 */
7
8#ifndef __REQUEST_MGR_H__
9#define __REQUEST_MGR_H__
10
11#include "cc_hw_queue_defs.h"
12
13int cc_req_mgr_init(struct cc_drvdata *drvdata);
14
15/*!
16 * Enqueue caller request to crypto hardware.
17 *
18 * \param drvdata
19 * \param cc_req The request to enqueue
20 * \param desc The crypto sequence
21 * \param len The crypto sequence length
22 * \param is_dout If "true": completion is handled by the caller
23 * If "false": this function adds a dummy descriptor completion
24 * and waits upon completion signal.
25 *
26 * \return int Returns -EINPROGRESS or error
27 */
28int cc_send_request(struct cc_drvdata *drvdata, struct cc_crypto_req *cc_req,
29 struct cc_hw_desc *desc, unsigned int len,
30 struct crypto_async_request *req);
31
32int cc_send_sync_request(struct cc_drvdata *drvdata,
33 struct cc_crypto_req *cc_req, struct cc_hw_desc *desc,
34 unsigned int len);
35
36int send_request_init(struct cc_drvdata *drvdata, struct cc_hw_desc *desc,
37 unsigned int len);
38
39void complete_request(struct cc_drvdata *drvdata);
40
41void cc_req_mgr_fini(struct cc_drvdata *drvdata);
42
43#if defined(CONFIG_PM)
44int cc_resume_req_queue(struct cc_drvdata *drvdata);
45
46int cc_suspend_req_queue(struct cc_drvdata *drvdata);
47
48bool cc_req_queue_suspended(struct cc_drvdata *drvdata);
49#endif
50
51#endif /*__REQUEST_MGR_H__*/
diff --git a/drivers/staging/ccree/ssi_sram_mgr.c b/drivers/staging/ccree/cc_sram_mgr.c
index 07260d168c91..d1f8a9cc1c0f 100644
--- a/drivers/staging/ccree/ssi_sram_mgr.c
+++ b/drivers/staging/ccree/cc_sram_mgr.c
@@ -1,62 +1,47 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates. 2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16 3
17#include "ssi_driver.h" 4#include "cc_driver.h"
18#include "ssi_sram_mgr.h" 5#include "cc_sram_mgr.h"
19 6
20/** 7/**
21 * struct ssi_sram_mgr_ctx -Internal RAM context manager 8 * struct cc_sram_ctx -Internal RAM context manager
22 * @sram_free_offset: the offset to the non-allocated area 9 * @sram_free_offset: the offset to the non-allocated area
23 */ 10 */
24struct ssi_sram_mgr_ctx { 11struct cc_sram_ctx {
25 ssi_sram_addr_t sram_free_offset; 12 cc_sram_addr_t sram_free_offset;
26}; 13};
27 14
28/** 15/**
29 * ssi_sram_mgr_fini() - Cleanup SRAM pool. 16 * cc_sram_mgr_fini() - Cleanup SRAM pool.
30 * 17 *
31 * @drvdata: Associated device driver context 18 * @drvdata: Associated device driver context
32 */ 19 */
33void ssi_sram_mgr_fini(struct ssi_drvdata *drvdata) 20void cc_sram_mgr_fini(struct cc_drvdata *drvdata)
34{ 21{
35 struct ssi_sram_mgr_ctx *smgr_ctx = drvdata->sram_mgr_handle;
36
37 /* Free "this" context */ 22 /* Free "this" context */
38 if (smgr_ctx) { 23 kfree(drvdata->sram_mgr_handle);
39 memset(smgr_ctx, 0, sizeof(struct ssi_sram_mgr_ctx));
40 kfree(smgr_ctx);
41 }
42} 24}
43 25
44/** 26/**
45 * ssi_sram_mgr_init() - Initializes SRAM pool. 27 * cc_sram_mgr_init() - Initializes SRAM pool.
46 * The pool starts right at the beginning of SRAM. 28 * The pool starts right at the beginning of SRAM.
47 * Returns zero for success, negative value otherwise. 29 * Returns zero for success, negative value otherwise.
48 * 30 *
49 * @drvdata: Associated device driver context 31 * @drvdata: Associated device driver context
50 */ 32 */
51int ssi_sram_mgr_init(struct ssi_drvdata *drvdata) 33int cc_sram_mgr_init(struct cc_drvdata *drvdata)
52{ 34{
35 struct cc_sram_ctx *ctx;
36
53 /* Allocate "this" context */ 37 /* Allocate "this" context */
54 drvdata->sram_mgr_handle = kzalloc(sizeof(struct ssi_sram_mgr_ctx), 38 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
55 GFP_KERNEL);
56 39
57 if (!drvdata->sram_mgr_handle) 40 if (!ctx)
58 return -ENOMEM; 41 return -ENOMEM;
59 42
43 drvdata->sram_mgr_handle = ctx;
44
60 return 0; 45 return 0;
61} 46}
62 47
@@ -69,18 +54,18 @@ int ssi_sram_mgr_init(struct ssi_drvdata *drvdata)
69 * \param drvdata 54 * \param drvdata
70 * \param size The requested bytes to allocate 55 * \param size The requested bytes to allocate
71 */ 56 */
72ssi_sram_addr_t ssi_sram_mgr_alloc(struct ssi_drvdata *drvdata, u32 size) 57cc_sram_addr_t cc_sram_alloc(struct cc_drvdata *drvdata, u32 size)
73{ 58{
74 struct ssi_sram_mgr_ctx *smgr_ctx = drvdata->sram_mgr_handle; 59 struct cc_sram_ctx *smgr_ctx = drvdata->sram_mgr_handle;
75 struct device *dev = drvdata_to_dev(drvdata); 60 struct device *dev = drvdata_to_dev(drvdata);
76 ssi_sram_addr_t p; 61 cc_sram_addr_t p;
77 62
78 if (unlikely((size & 0x3) != 0)) { 63 if ((size & 0x3)) {
79 dev_err(dev, "Requested buffer size (%u) is not multiple of 4", 64 dev_err(dev, "Requested buffer size (%u) is not multiple of 4",
80 size); 65 size);
81 return NULL_SRAM_ADDR; 66 return NULL_SRAM_ADDR;
82 } 67 }
83 if (unlikely(size > (SSI_CC_SRAM_SIZE - smgr_ctx->sram_free_offset))) { 68 if (size > (CC_CC_SRAM_SIZE - smgr_ctx->sram_free_offset)) {
84 dev_err(dev, "Not enough space to allocate %u B (at offset %llu)\n", 69 dev_err(dev, "Not enough space to allocate %u B (at offset %llu)\n",
85 size, smgr_ctx->sram_free_offset); 70 size, smgr_ctx->sram_free_offset);
86 return NULL_SRAM_ADDR; 71 return NULL_SRAM_ADDR;
@@ -93,7 +78,7 @@ ssi_sram_addr_t ssi_sram_mgr_alloc(struct ssi_drvdata *drvdata, u32 size)
93} 78}
94 79
95/** 80/**
96 * ssi_sram_mgr_const2sram_desc() - Create const descriptors sequence to 81 * cc_set_sram_desc() - Create const descriptors sequence to
97 * set values in given array into SRAM. 82 * set values in given array into SRAM.
98 * Note: each const value can't exceed word size. 83 * Note: each const value can't exceed word size.
99 * 84 *
@@ -103,10 +88,9 @@ ssi_sram_addr_t ssi_sram_mgr_alloc(struct ssi_drvdata *drvdata, u32 size)
103 * @seq: A pointer to the given IN/OUT descriptor sequence 88 * @seq: A pointer to the given IN/OUT descriptor sequence
104 * @seq_len: A pointer to the given IN/OUT sequence length 89 * @seq_len: A pointer to the given IN/OUT sequence length
105 */ 90 */
106void ssi_sram_mgr_const2sram_desc( 91void cc_set_sram_desc(const u32 *src, cc_sram_addr_t dst,
107 const u32 *src, ssi_sram_addr_t dst, 92 unsigned int nelement, struct cc_hw_desc *seq,
108 unsigned int nelement, 93 unsigned int *seq_len)
109 struct cc_hw_desc *seq, unsigned int *seq_len)
110{ 94{
111 u32 i; 95 u32 i;
112 unsigned int idx = *seq_len; 96 unsigned int idx = *seq_len;
diff --git a/drivers/staging/ccree/cc_sram_mgr.h b/drivers/staging/ccree/cc_sram_mgr.h
new file mode 100644
index 000000000000..d48649fb3323
--- /dev/null
+++ b/drivers/staging/ccree/cc_sram_mgr.h
@@ -0,0 +1,65 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
3
4#ifndef __CC_SRAM_MGR_H__
5#define __CC_SRAM_MGR_H__
6
7#ifndef CC_CC_SRAM_SIZE
8#define CC_CC_SRAM_SIZE 4096
9#endif
10
11struct cc_drvdata;
12
13/**
14 * Address (offset) within CC internal SRAM
15 */
16
17typedef u64 cc_sram_addr_t;
18
19#define NULL_SRAM_ADDR ((cc_sram_addr_t)-1)
20
21/*!
22 * Initializes SRAM pool.
23 * The first X bytes of SRAM are reserved for ROM usage, hence, pool
24 * starts right after X bytes.
25 *
26 * \param drvdata
27 *
28 * \return int Zero for success, negative value otherwise.
29 */
30int cc_sram_mgr_init(struct cc_drvdata *drvdata);
31
32/*!
33 * Uninits SRAM pool.
34 *
35 * \param drvdata
36 */
37void cc_sram_mgr_fini(struct cc_drvdata *drvdata);
38
39/*!
40 * Allocated buffer from SRAM pool.
41 * Note: Caller is responsible to free the LAST allocated buffer.
42 * This function does not taking care of any fragmentation may occur
43 * by the order of calls to alloc/free.
44 *
45 * \param drvdata
46 * \param size The requested bytes to allocate
47 */
48cc_sram_addr_t cc_sram_alloc(struct cc_drvdata *drvdata, u32 size);
49
50/**
51 * cc_set_sram_desc() - Create const descriptors sequence to
52 * set values in given array into SRAM.
53 * Note: each const value can't exceed word size.
54 *
55 * @src: A pointer to array of words to set as consts.
56 * @dst: The target SRAM buffer to set into
57 * @nelements: The number of words in "src" array
58 * @seq: A pointer to the given IN/OUT descriptor sequence
59 * @seq_len: A pointer to the given IN/OUT sequence length
60 */
61void cc_set_sram_desc(const u32 *src, cc_sram_addr_t dst,
62 unsigned int nelement, struct cc_hw_desc *seq,
63 unsigned int *seq_len);
64
65#endif /*__CC_SRAM_MGR_H__*/
diff --git a/drivers/staging/ccree/dx_crys_kernel.h b/drivers/staging/ccree/dx_crys_kernel.h
deleted file mode 100644
index 219603030344..000000000000
--- a/drivers/staging/ccree/dx_crys_kernel.h
+++ /dev/null
@@ -1,180 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __DX_CRYS_KERNEL_H__
18#define __DX_CRYS_KERNEL_H__
19
20// --------------------------------------
21// BLOCK: DSCRPTR
22// --------------------------------------
23#define DX_DSCRPTR_COMPLETION_COUNTER_REG_OFFSET 0xE00UL
24#define DX_DSCRPTR_COMPLETION_COUNTER_COMPLETION_COUNTER_BIT_SHIFT 0x0UL
25#define DX_DSCRPTR_COMPLETION_COUNTER_COMPLETION_COUNTER_BIT_SIZE 0x6UL
26#define DX_DSCRPTR_COMPLETION_COUNTER_OVERFLOW_COUNTER_BIT_SHIFT 0x6UL
27#define DX_DSCRPTR_COMPLETION_COUNTER_OVERFLOW_COUNTER_BIT_SIZE 0x1UL
28#define DX_DSCRPTR_SW_RESET_REG_OFFSET 0xE40UL
29#define DX_DSCRPTR_SW_RESET_VALUE_BIT_SHIFT 0x0UL
30#define DX_DSCRPTR_SW_RESET_VALUE_BIT_SIZE 0x1UL
31#define DX_DSCRPTR_QUEUE_SRAM_SIZE_REG_OFFSET 0xE60UL
32#define DX_DSCRPTR_QUEUE_SRAM_SIZE_NUM_OF_DSCRPTR_BIT_SHIFT 0x0UL
33#define DX_DSCRPTR_QUEUE_SRAM_SIZE_NUM_OF_DSCRPTR_BIT_SIZE 0xAUL
34#define DX_DSCRPTR_QUEUE_SRAM_SIZE_DSCRPTR_SRAM_SIZE_BIT_SHIFT 0xAUL
35#define DX_DSCRPTR_QUEUE_SRAM_SIZE_DSCRPTR_SRAM_SIZE_BIT_SIZE 0xCUL
36#define DX_DSCRPTR_QUEUE_SRAM_SIZE_SRAM_SIZE_BIT_SHIFT 0x16UL
37#define DX_DSCRPTR_QUEUE_SRAM_SIZE_SRAM_SIZE_BIT_SIZE 0x3UL
38#define DX_DSCRPTR_SINGLE_ADDR_EN_REG_OFFSET 0xE64UL
39#define DX_DSCRPTR_SINGLE_ADDR_EN_VALUE_BIT_SHIFT 0x0UL
40#define DX_DSCRPTR_SINGLE_ADDR_EN_VALUE_BIT_SIZE 0x1UL
41#define DX_DSCRPTR_MEASURE_CNTR_REG_OFFSET 0xE68UL
42#define DX_DSCRPTR_MEASURE_CNTR_VALUE_BIT_SHIFT 0x0UL
43#define DX_DSCRPTR_MEASURE_CNTR_VALUE_BIT_SIZE 0x20UL
44#define DX_DSCRPTR_QUEUE_WORD0_REG_OFFSET 0xE80UL
45#define DX_DSCRPTR_QUEUE_WORD0_VALUE_BIT_SHIFT 0x0UL
46#define DX_DSCRPTR_QUEUE_WORD0_VALUE_BIT_SIZE 0x20UL
47#define DX_DSCRPTR_QUEUE_WORD1_REG_OFFSET 0xE84UL
48#define DX_DSCRPTR_QUEUE_WORD1_DIN_DMA_MODE_BIT_SHIFT 0x0UL
49#define DX_DSCRPTR_QUEUE_WORD1_DIN_DMA_MODE_BIT_SIZE 0x2UL
50#define DX_DSCRPTR_QUEUE_WORD1_DIN_SIZE_BIT_SHIFT 0x2UL
51#define DX_DSCRPTR_QUEUE_WORD1_DIN_SIZE_BIT_SIZE 0x18UL
52#define DX_DSCRPTR_QUEUE_WORD1_NS_BIT_BIT_SHIFT 0x1AUL
53#define DX_DSCRPTR_QUEUE_WORD1_NS_BIT_BIT_SIZE 0x1UL
54#define DX_DSCRPTR_QUEUE_WORD1_DIN_CONST_VALUE_BIT_SHIFT 0x1BUL
55#define DX_DSCRPTR_QUEUE_WORD1_DIN_CONST_VALUE_BIT_SIZE 0x1UL
56#define DX_DSCRPTR_QUEUE_WORD1_NOT_LAST_BIT_SHIFT 0x1CUL
57#define DX_DSCRPTR_QUEUE_WORD1_NOT_LAST_BIT_SIZE 0x1UL
58#define DX_DSCRPTR_QUEUE_WORD1_LOCK_QUEUE_BIT_SHIFT 0x1DUL
59#define DX_DSCRPTR_QUEUE_WORD1_LOCK_QUEUE_BIT_SIZE 0x1UL
60#define DX_DSCRPTR_QUEUE_WORD1_NOT_USED_BIT_SHIFT 0x1EUL
61#define DX_DSCRPTR_QUEUE_WORD1_NOT_USED_BIT_SIZE 0x2UL
62#define DX_DSCRPTR_QUEUE_WORD2_REG_OFFSET 0xE88UL
63#define DX_DSCRPTR_QUEUE_WORD2_VALUE_BIT_SHIFT 0x0UL
64#define DX_DSCRPTR_QUEUE_WORD2_VALUE_BIT_SIZE 0x20UL
65#define DX_DSCRPTR_QUEUE_WORD3_REG_OFFSET 0xE8CUL
66#define DX_DSCRPTR_QUEUE_WORD3_DOUT_DMA_MODE_BIT_SHIFT 0x0UL
67#define DX_DSCRPTR_QUEUE_WORD3_DOUT_DMA_MODE_BIT_SIZE 0x2UL
68#define DX_DSCRPTR_QUEUE_WORD3_DOUT_SIZE_BIT_SHIFT 0x2UL
69#define DX_DSCRPTR_QUEUE_WORD3_DOUT_SIZE_BIT_SIZE 0x18UL
70#define DX_DSCRPTR_QUEUE_WORD3_NS_BIT_BIT_SHIFT 0x1AUL
71#define DX_DSCRPTR_QUEUE_WORD3_NS_BIT_BIT_SIZE 0x1UL
72#define DX_DSCRPTR_QUEUE_WORD3_DOUT_LAST_IND_BIT_SHIFT 0x1BUL
73#define DX_DSCRPTR_QUEUE_WORD3_DOUT_LAST_IND_BIT_SIZE 0x1UL
74#define DX_DSCRPTR_QUEUE_WORD3_HASH_XOR_BIT_BIT_SHIFT 0x1DUL
75#define DX_DSCRPTR_QUEUE_WORD3_HASH_XOR_BIT_BIT_SIZE 0x1UL
76#define DX_DSCRPTR_QUEUE_WORD3_NOT_USED_BIT_SHIFT 0x1EUL
77#define DX_DSCRPTR_QUEUE_WORD3_NOT_USED_BIT_SIZE 0x1UL
78#define DX_DSCRPTR_QUEUE_WORD3_QUEUE_LAST_IND_BIT_SHIFT 0x1FUL
79#define DX_DSCRPTR_QUEUE_WORD3_QUEUE_LAST_IND_BIT_SIZE 0x1UL
80#define DX_DSCRPTR_QUEUE_WORD4_REG_OFFSET 0xE90UL
81#define DX_DSCRPTR_QUEUE_WORD4_DATA_FLOW_MODE_BIT_SHIFT 0x0UL
82#define DX_DSCRPTR_QUEUE_WORD4_DATA_FLOW_MODE_BIT_SIZE 0x6UL
83#define DX_DSCRPTR_QUEUE_WORD4_AES_SEL_N_HASH_BIT_SHIFT 0x6UL
84#define DX_DSCRPTR_QUEUE_WORD4_AES_SEL_N_HASH_BIT_SIZE 0x1UL
85#define DX_DSCRPTR_QUEUE_WORD4_AES_XOR_CRYPTO_KEY_BIT_SHIFT 0x7UL
86#define DX_DSCRPTR_QUEUE_WORD4_AES_XOR_CRYPTO_KEY_BIT_SIZE 0x1UL
87#define DX_DSCRPTR_QUEUE_WORD4_ACK_NEEDED_BIT_SHIFT 0x8UL
88#define DX_DSCRPTR_QUEUE_WORD4_ACK_NEEDED_BIT_SIZE 0x2UL
89#define DX_DSCRPTR_QUEUE_WORD4_CIPHER_MODE_BIT_SHIFT 0xAUL
90#define DX_DSCRPTR_QUEUE_WORD4_CIPHER_MODE_BIT_SIZE 0x4UL
91#define DX_DSCRPTR_QUEUE_WORD4_CMAC_SIZE0_BIT_SHIFT 0xEUL
92#define DX_DSCRPTR_QUEUE_WORD4_CMAC_SIZE0_BIT_SIZE 0x1UL
93#define DX_DSCRPTR_QUEUE_WORD4_CIPHER_DO_BIT_SHIFT 0xFUL
94#define DX_DSCRPTR_QUEUE_WORD4_CIPHER_DO_BIT_SIZE 0x2UL
95#define DX_DSCRPTR_QUEUE_WORD4_CIPHER_CONF0_BIT_SHIFT 0x11UL
96#define DX_DSCRPTR_QUEUE_WORD4_CIPHER_CONF0_BIT_SIZE 0x2UL
97#define DX_DSCRPTR_QUEUE_WORD4_CIPHER_CONF1_BIT_SHIFT 0x13UL
98#define DX_DSCRPTR_QUEUE_WORD4_CIPHER_CONF1_BIT_SIZE 0x1UL
99#define DX_DSCRPTR_QUEUE_WORD4_CIPHER_CONF2_BIT_SHIFT 0x14UL
100#define DX_DSCRPTR_QUEUE_WORD4_CIPHER_CONF2_BIT_SIZE 0x2UL
101#define DX_DSCRPTR_QUEUE_WORD4_KEY_SIZE_BIT_SHIFT 0x16UL
102#define DX_DSCRPTR_QUEUE_WORD4_KEY_SIZE_BIT_SIZE 0x2UL
103#define DX_DSCRPTR_QUEUE_WORD4_SETUP_OPERATION_BIT_SHIFT 0x18UL
104#define DX_DSCRPTR_QUEUE_WORD4_SETUP_OPERATION_BIT_SIZE 0x4UL
105#define DX_DSCRPTR_QUEUE_WORD4_DIN_SRAM_ENDIANNESS_BIT_SHIFT 0x1CUL
106#define DX_DSCRPTR_QUEUE_WORD4_DIN_SRAM_ENDIANNESS_BIT_SIZE 0x1UL
107#define DX_DSCRPTR_QUEUE_WORD4_DOUT_SRAM_ENDIANNESS_BIT_SHIFT 0x1DUL
108#define DX_DSCRPTR_QUEUE_WORD4_DOUT_SRAM_ENDIANNESS_BIT_SIZE 0x1UL
109#define DX_DSCRPTR_QUEUE_WORD4_WORD_SWAP_BIT_SHIFT 0x1EUL
110#define DX_DSCRPTR_QUEUE_WORD4_WORD_SWAP_BIT_SIZE 0x1UL
111#define DX_DSCRPTR_QUEUE_WORD4_BYTES_SWAP_BIT_SHIFT 0x1FUL
112#define DX_DSCRPTR_QUEUE_WORD4_BYTES_SWAP_BIT_SIZE 0x1UL
113#define DX_DSCRPTR_QUEUE_WORD5_REG_OFFSET 0xE94UL
114#define DX_DSCRPTR_QUEUE_WORD5_DIN_ADDR_HIGH_BIT_SHIFT 0x0UL
115#define DX_DSCRPTR_QUEUE_WORD5_DIN_ADDR_HIGH_BIT_SIZE 0x10UL
116#define DX_DSCRPTR_QUEUE_WORD5_DOUT_ADDR_HIGH_BIT_SHIFT 0x10UL
117#define DX_DSCRPTR_QUEUE_WORD5_DOUT_ADDR_HIGH_BIT_SIZE 0x10UL
118#define DX_DSCRPTR_QUEUE_WATERMARK_REG_OFFSET 0xE98UL
119#define DX_DSCRPTR_QUEUE_WATERMARK_VALUE_BIT_SHIFT 0x0UL
120#define DX_DSCRPTR_QUEUE_WATERMARK_VALUE_BIT_SIZE 0xAUL
121#define DX_DSCRPTR_QUEUE_CONTENT_REG_OFFSET 0xE9CUL
122#define DX_DSCRPTR_QUEUE_CONTENT_VALUE_BIT_SHIFT 0x0UL
123#define DX_DSCRPTR_QUEUE_CONTENT_VALUE_BIT_SIZE 0xAUL
124// --------------------------------------
125// BLOCK: AXI_P
126// --------------------------------------
127#define DX_AXIM_MON_INFLIGHT_REG_OFFSET 0xB00UL
128#define DX_AXIM_MON_INFLIGHT_VALUE_BIT_SHIFT 0x0UL
129#define DX_AXIM_MON_INFLIGHT_VALUE_BIT_SIZE 0x8UL
130#define DX_AXIM_MON_INFLIGHTLAST_REG_OFFSET 0xB40UL
131#define DX_AXIM_MON_INFLIGHTLAST_VALUE_BIT_SHIFT 0x0UL
132#define DX_AXIM_MON_INFLIGHTLAST_VALUE_BIT_SIZE 0x8UL
133#define DX_AXIM_MON_COMP_REG_OFFSET 0xB80UL
134#define DX_AXIM_MON_COMP_VALUE_BIT_SHIFT 0x0UL
135#define DX_AXIM_MON_COMP_VALUE_BIT_SIZE 0x10UL
136#define DX_AXIM_MON_ERR_REG_OFFSET 0xBC4UL
137#define DX_AXIM_MON_ERR_BRESP_BIT_SHIFT 0x0UL
138#define DX_AXIM_MON_ERR_BRESP_BIT_SIZE 0x2UL
139#define DX_AXIM_MON_ERR_BID_BIT_SHIFT 0x2UL
140#define DX_AXIM_MON_ERR_BID_BIT_SIZE 0x4UL
141#define DX_AXIM_MON_ERR_RRESP_BIT_SHIFT 0x10UL
142#define DX_AXIM_MON_ERR_RRESP_BIT_SIZE 0x2UL
143#define DX_AXIM_MON_ERR_RID_BIT_SHIFT 0x12UL
144#define DX_AXIM_MON_ERR_RID_BIT_SIZE 0x4UL
145#define DX_AXIM_CFG_REG_OFFSET 0xBE8UL
146#define DX_AXIM_CFG_BRESPMASK_BIT_SHIFT 0x4UL
147#define DX_AXIM_CFG_BRESPMASK_BIT_SIZE 0x1UL
148#define DX_AXIM_CFG_RRESPMASK_BIT_SHIFT 0x5UL
149#define DX_AXIM_CFG_RRESPMASK_BIT_SIZE 0x1UL
150#define DX_AXIM_CFG_INFLTMASK_BIT_SHIFT 0x6UL
151#define DX_AXIM_CFG_INFLTMASK_BIT_SIZE 0x1UL
152#define DX_AXIM_CFG_COMPMASK_BIT_SHIFT 0x7UL
153#define DX_AXIM_CFG_COMPMASK_BIT_SIZE 0x1UL
154#define DX_AXIM_ACE_CONST_REG_OFFSET 0xBECUL
155#define DX_AXIM_ACE_CONST_ARDOMAIN_BIT_SHIFT 0x0UL
156#define DX_AXIM_ACE_CONST_ARDOMAIN_BIT_SIZE 0x2UL
157#define DX_AXIM_ACE_CONST_AWDOMAIN_BIT_SHIFT 0x2UL
158#define DX_AXIM_ACE_CONST_AWDOMAIN_BIT_SIZE 0x2UL
159#define DX_AXIM_ACE_CONST_ARBAR_BIT_SHIFT 0x4UL
160#define DX_AXIM_ACE_CONST_ARBAR_BIT_SIZE 0x2UL
161#define DX_AXIM_ACE_CONST_AWBAR_BIT_SHIFT 0x6UL
162#define DX_AXIM_ACE_CONST_AWBAR_BIT_SIZE 0x2UL
163#define DX_AXIM_ACE_CONST_ARSNOOP_BIT_SHIFT 0x8UL
164#define DX_AXIM_ACE_CONST_ARSNOOP_BIT_SIZE 0x4UL
165#define DX_AXIM_ACE_CONST_AWSNOOP_NOT_ALIGNED_BIT_SHIFT 0xCUL
166#define DX_AXIM_ACE_CONST_AWSNOOP_NOT_ALIGNED_BIT_SIZE 0x3UL
167#define DX_AXIM_ACE_CONST_AWSNOOP_ALIGNED_BIT_SHIFT 0xFUL
168#define DX_AXIM_ACE_CONST_AWSNOOP_ALIGNED_BIT_SIZE 0x3UL
169#define DX_AXIM_ACE_CONST_AWADDR_NOT_MASKED_BIT_SHIFT 0x12UL
170#define DX_AXIM_ACE_CONST_AWADDR_NOT_MASKED_BIT_SIZE 0x7UL
171#define DX_AXIM_ACE_CONST_AWLEN_VAL_BIT_SHIFT 0x19UL
172#define DX_AXIM_ACE_CONST_AWLEN_VAL_BIT_SIZE 0x4UL
173#define DX_AXIM_CACHE_PARAMS_REG_OFFSET 0xBF0UL
174#define DX_AXIM_CACHE_PARAMS_AWCACHE_LAST_BIT_SHIFT 0x0UL
175#define DX_AXIM_CACHE_PARAMS_AWCACHE_LAST_BIT_SIZE 0x4UL
176#define DX_AXIM_CACHE_PARAMS_AWCACHE_BIT_SHIFT 0x4UL
177#define DX_AXIM_CACHE_PARAMS_AWCACHE_BIT_SIZE 0x4UL
178#define DX_AXIM_CACHE_PARAMS_ARCACHE_BIT_SHIFT 0x8UL
179#define DX_AXIM_CACHE_PARAMS_ARCACHE_BIT_SIZE 0x4UL
180#endif // __DX_CRYS_KERNEL_H__
diff --git a/drivers/staging/ccree/dx_host.h b/drivers/staging/ccree/dx_host.h
deleted file mode 100644
index 863c2670d826..000000000000
--- a/drivers/staging/ccree/dx_host.h
+++ /dev/null
@@ -1,155 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __DX_HOST_H__
18#define __DX_HOST_H__
19
20// --------------------------------------
21// BLOCK: HOST_P
22// --------------------------------------
23#define DX_HOST_IRR_REG_OFFSET 0xA00UL
24#define DX_HOST_IRR_DSCRPTR_COMPLETION_LOW_INT_BIT_SHIFT 0x2UL
25#define DX_HOST_IRR_DSCRPTR_COMPLETION_LOW_INT_BIT_SIZE 0x1UL
26#define DX_HOST_IRR_AXI_ERR_INT_BIT_SHIFT 0x8UL
27#define DX_HOST_IRR_AXI_ERR_INT_BIT_SIZE 0x1UL
28#define DX_HOST_IRR_GPR0_BIT_SHIFT 0xBUL
29#define DX_HOST_IRR_GPR0_BIT_SIZE 0x1UL
30#define DX_HOST_IRR_DSCRPTR_WATERMARK_INT_BIT_SHIFT 0x13UL
31#define DX_HOST_IRR_DSCRPTR_WATERMARK_INT_BIT_SIZE 0x1UL
32#define DX_HOST_IRR_AXIM_COMP_INT_BIT_SHIFT 0x17UL
33#define DX_HOST_IRR_AXIM_COMP_INT_BIT_SIZE 0x1UL
34#define DX_HOST_IMR_REG_OFFSET 0xA04UL
35#define DX_HOST_IMR_NOT_USED_MASK_BIT_SHIFT 0x1UL
36#define DX_HOST_IMR_NOT_USED_MASK_BIT_SIZE 0x1UL
37#define DX_HOST_IMR_DSCRPTR_COMPLETION_MASK_BIT_SHIFT 0x2UL
38#define DX_HOST_IMR_DSCRPTR_COMPLETION_MASK_BIT_SIZE 0x1UL
39#define DX_HOST_IMR_AXI_ERR_MASK_BIT_SHIFT 0x8UL
40#define DX_HOST_IMR_AXI_ERR_MASK_BIT_SIZE 0x1UL
41#define DX_HOST_IMR_GPR0_BIT_SHIFT 0xBUL
42#define DX_HOST_IMR_GPR0_BIT_SIZE 0x1UL
43#define DX_HOST_IMR_DSCRPTR_WATERMARK_MASK0_BIT_SHIFT 0x13UL
44#define DX_HOST_IMR_DSCRPTR_WATERMARK_MASK0_BIT_SIZE 0x1UL
45#define DX_HOST_IMR_AXIM_COMP_INT_MASK_BIT_SHIFT 0x17UL
46#define DX_HOST_IMR_AXIM_COMP_INT_MASK_BIT_SIZE 0x1UL
47#define DX_HOST_ICR_REG_OFFSET 0xA08UL
48#define DX_HOST_ICR_DSCRPTR_COMPLETION_BIT_SHIFT 0x2UL
49#define DX_HOST_ICR_DSCRPTR_COMPLETION_BIT_SIZE 0x1UL
50#define DX_HOST_ICR_AXI_ERR_CLEAR_BIT_SHIFT 0x8UL
51#define DX_HOST_ICR_AXI_ERR_CLEAR_BIT_SIZE 0x1UL
52#define DX_HOST_ICR_GPR_INT_CLEAR_BIT_SHIFT 0xBUL
53#define DX_HOST_ICR_GPR_INT_CLEAR_BIT_SIZE 0x1UL
54#define DX_HOST_ICR_DSCRPTR_WATERMARK_QUEUE0_CLEAR_BIT_SHIFT 0x13UL
55#define DX_HOST_ICR_DSCRPTR_WATERMARK_QUEUE0_CLEAR_BIT_SIZE 0x1UL
56#define DX_HOST_ICR_AXIM_COMP_INT_CLEAR_BIT_SHIFT 0x17UL
57#define DX_HOST_ICR_AXIM_COMP_INT_CLEAR_BIT_SIZE 0x1UL
58#define DX_HOST_SIGNATURE_REG_OFFSET 0xA24UL
59#define DX_HOST_SIGNATURE_VALUE_BIT_SHIFT 0x0UL
60#define DX_HOST_SIGNATURE_VALUE_BIT_SIZE 0x20UL
61#define DX_HOST_BOOT_REG_OFFSET 0xA28UL
62#define DX_HOST_BOOT_SYNTHESIS_CONFIG_BIT_SHIFT 0x0UL
63#define DX_HOST_BOOT_SYNTHESIS_CONFIG_BIT_SIZE 0x1UL
64#define DX_HOST_BOOT_LARGE_RKEK_LOCAL_BIT_SHIFT 0x1UL
65#define DX_HOST_BOOT_LARGE_RKEK_LOCAL_BIT_SIZE 0x1UL
66#define DX_HOST_BOOT_HASH_IN_FUSES_LOCAL_BIT_SHIFT 0x2UL
67#define DX_HOST_BOOT_HASH_IN_FUSES_LOCAL_BIT_SIZE 0x1UL
68#define DX_HOST_BOOT_EXT_MEM_SECURED_LOCAL_BIT_SHIFT 0x3UL
69#define DX_HOST_BOOT_EXT_MEM_SECURED_LOCAL_BIT_SIZE 0x1UL
70#define DX_HOST_BOOT_RKEK_ECC_EXISTS_LOCAL_N_BIT_SHIFT 0x5UL
71#define DX_HOST_BOOT_RKEK_ECC_EXISTS_LOCAL_N_BIT_SIZE 0x1UL
72#define DX_HOST_BOOT_SRAM_SIZE_LOCAL_BIT_SHIFT 0x6UL
73#define DX_HOST_BOOT_SRAM_SIZE_LOCAL_BIT_SIZE 0x3UL
74#define DX_HOST_BOOT_DSCRPTR_EXISTS_LOCAL_BIT_SHIFT 0x9UL
75#define DX_HOST_BOOT_DSCRPTR_EXISTS_LOCAL_BIT_SIZE 0x1UL
76#define DX_HOST_BOOT_PAU_EXISTS_LOCAL_BIT_SHIFT 0xAUL
77#define DX_HOST_BOOT_PAU_EXISTS_LOCAL_BIT_SIZE 0x1UL
78#define DX_HOST_BOOT_RNG_EXISTS_LOCAL_BIT_SHIFT 0xBUL
79#define DX_HOST_BOOT_RNG_EXISTS_LOCAL_BIT_SIZE 0x1UL
80#define DX_HOST_BOOT_PKA_EXISTS_LOCAL_BIT_SHIFT 0xCUL
81#define DX_HOST_BOOT_PKA_EXISTS_LOCAL_BIT_SIZE 0x1UL
82#define DX_HOST_BOOT_RC4_EXISTS_LOCAL_BIT_SHIFT 0xDUL
83#define DX_HOST_BOOT_RC4_EXISTS_LOCAL_BIT_SIZE 0x1UL
84#define DX_HOST_BOOT_SHA_512_PRSNT_LOCAL_BIT_SHIFT 0xEUL
85#define DX_HOST_BOOT_SHA_512_PRSNT_LOCAL_BIT_SIZE 0x1UL
86#define DX_HOST_BOOT_SHA_256_PRSNT_LOCAL_BIT_SHIFT 0xFUL
87#define DX_HOST_BOOT_SHA_256_PRSNT_LOCAL_BIT_SIZE 0x1UL
88#define DX_HOST_BOOT_MD5_PRSNT_LOCAL_BIT_SHIFT 0x10UL
89#define DX_HOST_BOOT_MD5_PRSNT_LOCAL_BIT_SIZE 0x1UL
90#define DX_HOST_BOOT_HASH_EXISTS_LOCAL_BIT_SHIFT 0x11UL
91#define DX_HOST_BOOT_HASH_EXISTS_LOCAL_BIT_SIZE 0x1UL
92#define DX_HOST_BOOT_C2_EXISTS_LOCAL_BIT_SHIFT 0x12UL
93#define DX_HOST_BOOT_C2_EXISTS_LOCAL_BIT_SIZE 0x1UL
94#define DX_HOST_BOOT_DES_EXISTS_LOCAL_BIT_SHIFT 0x13UL
95#define DX_HOST_BOOT_DES_EXISTS_LOCAL_BIT_SIZE 0x1UL
96#define DX_HOST_BOOT_AES_XCBC_MAC_EXISTS_LOCAL_BIT_SHIFT 0x14UL
97#define DX_HOST_BOOT_AES_XCBC_MAC_EXISTS_LOCAL_BIT_SIZE 0x1UL
98#define DX_HOST_BOOT_AES_CMAC_EXISTS_LOCAL_BIT_SHIFT 0x15UL
99#define DX_HOST_BOOT_AES_CMAC_EXISTS_LOCAL_BIT_SIZE 0x1UL
100#define DX_HOST_BOOT_AES_CCM_EXISTS_LOCAL_BIT_SHIFT 0x16UL
101#define DX_HOST_BOOT_AES_CCM_EXISTS_LOCAL_BIT_SIZE 0x1UL
102#define DX_HOST_BOOT_AES_XEX_HW_T_CALC_LOCAL_BIT_SHIFT 0x17UL
103#define DX_HOST_BOOT_AES_XEX_HW_T_CALC_LOCAL_BIT_SIZE 0x1UL
104#define DX_HOST_BOOT_AES_XEX_EXISTS_LOCAL_BIT_SHIFT 0x18UL
105#define DX_HOST_BOOT_AES_XEX_EXISTS_LOCAL_BIT_SIZE 0x1UL
106#define DX_HOST_BOOT_CTR_EXISTS_LOCAL_BIT_SHIFT 0x19UL
107#define DX_HOST_BOOT_CTR_EXISTS_LOCAL_BIT_SIZE 0x1UL
108#define DX_HOST_BOOT_AES_DIN_BYTE_RESOLUTION_LOCAL_BIT_SHIFT 0x1AUL
109#define DX_HOST_BOOT_AES_DIN_BYTE_RESOLUTION_LOCAL_BIT_SIZE 0x1UL
110#define DX_HOST_BOOT_TUNNELING_ENB_LOCAL_BIT_SHIFT 0x1BUL
111#define DX_HOST_BOOT_TUNNELING_ENB_LOCAL_BIT_SIZE 0x1UL
112#define DX_HOST_BOOT_SUPPORT_256_192_KEY_LOCAL_BIT_SHIFT 0x1CUL
113#define DX_HOST_BOOT_SUPPORT_256_192_KEY_LOCAL_BIT_SIZE 0x1UL
114#define DX_HOST_BOOT_ONLY_ENCRYPT_LOCAL_BIT_SHIFT 0x1DUL
115#define DX_HOST_BOOT_ONLY_ENCRYPT_LOCAL_BIT_SIZE 0x1UL
116#define DX_HOST_BOOT_AES_EXISTS_LOCAL_BIT_SHIFT 0x1EUL
117#define DX_HOST_BOOT_AES_EXISTS_LOCAL_BIT_SIZE 0x1UL
118#define DX_HOST_VERSION_REG_OFFSET 0xA40UL
119#define DX_HOST_VERSION_VALUE_BIT_SHIFT 0x0UL
120#define DX_HOST_VERSION_VALUE_BIT_SIZE 0x20UL
121#define DX_HOST_KFDE0_VALID_REG_OFFSET 0xA60UL
122#define DX_HOST_KFDE0_VALID_VALUE_BIT_SHIFT 0x0UL
123#define DX_HOST_KFDE0_VALID_VALUE_BIT_SIZE 0x1UL
124#define DX_HOST_KFDE1_VALID_REG_OFFSET 0xA64UL
125#define DX_HOST_KFDE1_VALID_VALUE_BIT_SHIFT 0x0UL
126#define DX_HOST_KFDE1_VALID_VALUE_BIT_SIZE 0x1UL
127#define DX_HOST_KFDE2_VALID_REG_OFFSET 0xA68UL
128#define DX_HOST_KFDE2_VALID_VALUE_BIT_SHIFT 0x0UL
129#define DX_HOST_KFDE2_VALID_VALUE_BIT_SIZE 0x1UL
130#define DX_HOST_KFDE3_VALID_REG_OFFSET 0xA6CUL
131#define DX_HOST_KFDE3_VALID_VALUE_BIT_SHIFT 0x0UL
132#define DX_HOST_KFDE3_VALID_VALUE_BIT_SIZE 0x1UL
133#define DX_HOST_GPR0_REG_OFFSET 0xA70UL
134#define DX_HOST_GPR0_VALUE_BIT_SHIFT 0x0UL
135#define DX_HOST_GPR0_VALUE_BIT_SIZE 0x20UL
136#define DX_GPR_HOST_REG_OFFSET 0xA74UL
137#define DX_GPR_HOST_VALUE_BIT_SHIFT 0x0UL
138#define DX_GPR_HOST_VALUE_BIT_SIZE 0x20UL
139#define DX_HOST_POWER_DOWN_EN_REG_OFFSET 0xA78UL
140#define DX_HOST_POWER_DOWN_EN_VALUE_BIT_SHIFT 0x0UL
141#define DX_HOST_POWER_DOWN_EN_VALUE_BIT_SIZE 0x1UL
142// --------------------------------------
143// BLOCK: HOST_SRAM
144// --------------------------------------
145#define DX_SRAM_DATA_REG_OFFSET 0xF00UL
146#define DX_SRAM_DATA_VALUE_BIT_SHIFT 0x0UL
147#define DX_SRAM_DATA_VALUE_BIT_SIZE 0x20UL
148#define DX_SRAM_ADDR_REG_OFFSET 0xF04UL
149#define DX_SRAM_ADDR_VALUE_BIT_SHIFT 0x0UL
150#define DX_SRAM_ADDR_VALUE_BIT_SIZE 0xFUL
151#define DX_SRAM_DATA_READY_REG_OFFSET 0xF08UL
152#define DX_SRAM_DATA_READY_VALUE_BIT_SHIFT 0x0UL
153#define DX_SRAM_DATA_READY_VALUE_BIT_SIZE 0x1UL
154
155#endif //__DX_HOST_H__
diff --git a/drivers/staging/ccree/dx_reg_common.h b/drivers/staging/ccree/dx_reg_common.h
deleted file mode 100644
index d5132ffaf6e6..000000000000
--- a/drivers/staging/ccree/dx_reg_common.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __DX_REG_COMMON_H__
18#define __DX_REG_COMMON_H__
19
20#define DX_DEV_SIGNATURE 0xDCC71200UL
21
22#define CC_HW_VERSION 0xef840015UL
23
24#define DX_DEV_SHA_MAX 512
25
26#endif /*__DX_REG_COMMON_H__*/
diff --git a/drivers/staging/ccree/hash_defs.h b/drivers/staging/ccree/hash_defs.h
deleted file mode 100644
index f52656f5a3ea..000000000000
--- a/drivers/staging/ccree/hash_defs.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef _HASH_DEFS_H_
18#define _HASH_DEFS_H_
19
20#include "cc_crypto_ctx.h"
21
22enum cc_hash_conf_pad {
23 HASH_PADDING_DISABLED = 0,
24 HASH_PADDING_ENABLED = 1,
25 HASH_DIGEST_RESULT_LITTLE_ENDIAN = 2,
26 HASH_CONFIG1_PADDING_RESERVE32 = S32_MAX,
27};
28
29enum cc_hash_cipher_pad {
30 DO_NOT_PAD = 0,
31 DO_PAD = 1,
32 HASH_CIPHER_DO_PADDING_RESERVE32 = S32_MAX,
33};
34
35#endif /*_HASH_DEFS_H_*/
36
diff --git a/drivers/staging/ccree/ssi_buffer_mgr.h b/drivers/staging/ccree/ssi_buffer_mgr.h
deleted file mode 100644
index 1032f25edcab..000000000000
--- a/drivers/staging/ccree/ssi_buffer_mgr.h
+++ /dev/null
@@ -1,91 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17/* \file buffer_mgr.h
18 * Buffer Manager
19 */
20
21#ifndef __SSI_BUFFER_MGR_H__
22#define __SSI_BUFFER_MGR_H__
23
24#include <crypto/algapi.h>
25
26#include "ssi_config.h"
27#include "ssi_driver.h"
28
29enum ssi_req_dma_buf_type {
30 SSI_DMA_BUF_NULL = 0,
31 SSI_DMA_BUF_DLLI,
32 SSI_DMA_BUF_MLLI
33};
34
35enum ssi_sg_cpy_direct {
36 SSI_SG_TO_BUF = 0,
37 SSI_SG_FROM_BUF = 1
38};
39
40struct ssi_mlli {
41 ssi_sram_addr_t sram_addr;
42 unsigned int nents; //sg nents
43 unsigned int mlli_nents; //mlli nents might be different than the above
44};
45
46struct mlli_params {
47 struct dma_pool *curr_pool;
48 u8 *mlli_virt_addr;
49 dma_addr_t mlli_dma_addr;
50 u32 mlli_len;
51};
52
53int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata);
54
55int ssi_buffer_mgr_fini(struct ssi_drvdata *drvdata);
56
57int ssi_buffer_mgr_map_blkcipher_request(
58 struct ssi_drvdata *drvdata,
59 void *ctx,
60 unsigned int ivsize,
61 unsigned int nbytes,
62 void *info,
63 struct scatterlist *src,
64 struct scatterlist *dst);
65
66void ssi_buffer_mgr_unmap_blkcipher_request(
67 struct device *dev,
68 void *ctx,
69 unsigned int ivsize,
70 struct scatterlist *src,
71 struct scatterlist *dst);
72
73int ssi_buffer_mgr_map_aead_request(struct ssi_drvdata *drvdata, struct aead_request *req);
74
75void ssi_buffer_mgr_unmap_aead_request(struct device *dev, struct aead_request *req);
76
77int ssi_buffer_mgr_map_hash_request_final(struct ssi_drvdata *drvdata, void *ctx, struct scatterlist *src, unsigned int nbytes, bool do_update);
78
79int ssi_buffer_mgr_map_hash_request_update(struct ssi_drvdata *drvdata, void *ctx, struct scatterlist *src, unsigned int nbytes, unsigned int block_size);
80
81void ssi_buffer_mgr_unmap_hash_request(struct device *dev, void *ctx, struct scatterlist *src, bool do_revert);
82
83void ssi_buffer_mgr_copy_scatterlist_portion(struct device *dev, u8 *dest,
84 struct scatterlist *sg,
85 u32 to_skip, u32 end,
86 enum ssi_sg_cpy_direct direct);
87
88void ssi_buffer_mgr_zero_sgl(struct scatterlist *sgl, u32 data_len);
89
90#endif /*__BUFFER_MGR_H__*/
91
diff --git a/drivers/staging/ccree/ssi_cipher.h b/drivers/staging/ccree/ssi_cipher.h
deleted file mode 100644
index 25e6335c0d94..000000000000
--- a/drivers/staging/ccree/ssi_cipher.h
+++ /dev/null
@@ -1,84 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17/* \file ssi_cipher.h
18 * ARM CryptoCell Cipher Crypto API
19 */
20
21#ifndef __SSI_CIPHER_H__
22#define __SSI_CIPHER_H__
23
24#include <linux/kernel.h>
25#include <crypto/algapi.h>
26#include "ssi_driver.h"
27#include "ssi_buffer_mgr.h"
28
29/* Crypto cipher flags */
30#define CC_CRYPTO_CIPHER_KEY_KFDE0 BIT(0)
31#define CC_CRYPTO_CIPHER_KEY_KFDE1 BIT(1)
32#define CC_CRYPTO_CIPHER_KEY_KFDE2 BIT(2)
33#define CC_CRYPTO_CIPHER_KEY_KFDE3 BIT(3)
34#define CC_CRYPTO_CIPHER_DU_SIZE_512B BIT(4)
35
36#define CC_CRYPTO_CIPHER_KEY_KFDE_MASK (CC_CRYPTO_CIPHER_KEY_KFDE0 | CC_CRYPTO_CIPHER_KEY_KFDE1 | CC_CRYPTO_CIPHER_KEY_KFDE2 | CC_CRYPTO_CIPHER_KEY_KFDE3)
37
38struct blkcipher_req_ctx {
39 struct async_gen_req_ctx gen_ctx;
40 enum ssi_req_dma_buf_type dma_buf_type;
41 u32 in_nents;
42 u32 in_mlli_nents;
43 u32 out_nents;
44 u32 out_mlli_nents;
45 u8 *backup_info; /*store iv for generated IV flow*/
46 u8 *iv;
47 bool is_giv;
48 struct mlli_params mlli_params;
49};
50
51int ssi_ablkcipher_alloc(struct ssi_drvdata *drvdata);
52
53int ssi_ablkcipher_free(struct ssi_drvdata *drvdata);
54
55#ifndef CRYPTO_ALG_BULK_MASK
56
57#define CRYPTO_ALG_BULK_DU_512 0x00002000
58#define CRYPTO_ALG_BULK_DU_4096 0x00004000
59#define CRYPTO_ALG_BULK_MASK (CRYPTO_ALG_BULK_DU_512 |\
60 CRYPTO_ALG_BULK_DU_4096)
61#endif /* CRYPTO_ALG_BULK_MASK */
62
63#ifdef CRYPTO_TFM_REQ_HW_KEY
64
65static inline bool ssi_is_hw_key(struct crypto_tfm *tfm)
66{
67 return (crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_HW_KEY);
68}
69
70#else
71
72struct arm_hw_key_info {
73 int hw_key1;
74 int hw_key2;
75};
76
77static inline bool ssi_is_hw_key(struct crypto_tfm *tfm)
78{
79 return false;
80}
81
82#endif /* CRYPTO_TFM_REQ_HW_KEY */
83
84#endif /*__SSI_CIPHER_H__*/
diff --git a/drivers/staging/ccree/ssi_config.h b/drivers/staging/ccree/ssi_config.h
deleted file mode 100644
index ff7597c2d77e..000000000000
--- a/drivers/staging/ccree/ssi_config.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17/* \file ssi_config.h
18 * Definitions for ARM CryptoCell Linux Crypto Driver
19 */
20
21#ifndef __SSI_CONFIG_H__
22#define __SSI_CONFIG_H__
23
24#include <linux/version.h>
25
26//#define FLUSH_CACHE_ALL
27//#define COMPLETION_DELAY
28//#define DX_DUMP_DESCS
29// #define DX_DUMP_BYTES
30// #define CC_DEBUG
31#define ENABLE_CC_SYSFS /* Enable sysfs interface for debugging REE driver */
32//#define DX_IRQ_DELAY 100000
33#define DMA_BIT_MASK_LEN 48 /* was 32 bit, but for juno's sake it was enlarged to 48 bit */
34
35#endif /*__DX_CONFIG_H__*/
36
diff --git a/drivers/staging/ccree/ssi_driver.h b/drivers/staging/ccree/ssi_driver.h
deleted file mode 100644
index 94c755cafb47..000000000000
--- a/drivers/staging/ccree/ssi_driver.h
+++ /dev/null
@@ -1,206 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17/* \file ssi_driver.h
18 * ARM CryptoCell Linux Crypto Driver
19 */
20
21#ifndef __SSI_DRIVER_H__
22#define __SSI_DRIVER_H__
23
24#include "ssi_config.h"
25#ifdef COMP_IN_WQ
26#include <linux/workqueue.h>
27#else
28#include <linux/interrupt.h>
29#endif
30#include <linux/dma-mapping.h>
31#include <crypto/algapi.h>
32#include <crypto/internal/skcipher.h>
33#include <crypto/aes.h>
34#include <crypto/sha.h>
35#include <crypto/aead.h>
36#include <crypto/authenc.h>
37#include <crypto/hash.h>
38#include <linux/version.h>
39#include <linux/clk.h>
40#include <linux/platform_device.h>
41
42/* Registers definitions from shared/hw/ree_include */
43#include "dx_host.h"
44#include "dx_reg_common.h"
45#define CC_SUPPORT_SHA DX_DEV_SHA_MAX
46#include "cc_crypto_ctx.h"
47#include "ssi_sysfs.h"
48#include "hash_defs.h"
49#include "cc_hw_queue_defs.h"
50#include "ssi_sram_mgr.h"
51
52#define DRV_MODULE_VERSION "3.0"
53
54#define SSI_DEV_NAME_STR "cc715ree"
55#define CC_COHERENT_CACHE_PARAMS 0xEEE
56
57#define SSI_CC_HAS_AES_CCM 1
58#define SSI_CC_HAS_AES_GCM 1
59#define SSI_CC_HAS_AES_XTS 1
60#define SSI_CC_HAS_AES_ESSIV 1
61#define SSI_CC_HAS_AES_BITLOCKER 1
62#define SSI_CC_HAS_AES_CTS 1
63#define SSI_CC_HAS_MULTI2 0
64#define SSI_CC_HAS_CMAC 1
65
66#define SSI_AXI_IRQ_MASK ((1 << DX_AXIM_CFG_BRESPMASK_BIT_SHIFT) | (1 << DX_AXIM_CFG_RRESPMASK_BIT_SHIFT) | \
67 (1 << DX_AXIM_CFG_INFLTMASK_BIT_SHIFT) | (1 << DX_AXIM_CFG_COMPMASK_BIT_SHIFT))
68
69#define SSI_AXI_ERR_IRQ_MASK BIT(DX_HOST_IRR_AXI_ERR_INT_BIT_SHIFT)
70
71#define SSI_COMP_IRQ_MASK BIT(DX_HOST_IRR_AXIM_COMP_INT_BIT_SHIFT)
72
73#define AXIM_MON_COMP_VALUE GENMASK(DX_AXIM_MON_COMP_VALUE_BIT_SIZE + \
74 DX_AXIM_MON_COMP_VALUE_BIT_SHIFT, \
75 DX_AXIM_MON_COMP_VALUE_BIT_SHIFT)
76
77/* Register name mangling macro */
78#define CC_REG(reg_name) DX_ ## reg_name ## _REG_OFFSET
79
80/* TEE FIPS status interrupt */
81#define SSI_GPR0_IRQ_MASK BIT(DX_HOST_IRR_GPR0_BIT_SHIFT)
82
83#define SSI_CRA_PRIO 3000
84
85#define MIN_HW_QUEUE_SIZE 50 /* Minimum size required for proper function */
86
87#define MAX_REQUEST_QUEUE_SIZE 4096
88#define MAX_MLLI_BUFF_SIZE 2080
89#define MAX_ICV_NENTS_SUPPORTED 2
90
91/* Definitions for HW descriptors DIN/DOUT fields */
92#define NS_BIT 1
93#define AXI_ID 0
94/* AXI_ID is not actually the AXI ID of the transaction but the value of AXI_ID
95 * field in the HW descriptor. The DMA engine +8 that value.
96 */
97
98#define MIN(a, b) (((a) < (b)) ? (a) : (b))
99#define MAX(a, b) (((a) > (b)) ? (a) : (b))
100
101#define SSI_MAX_IVGEN_DMA_ADDRESSES 3
102struct ssi_crypto_req {
103 void (*user_cb)(struct device *dev, void *req, void __iomem *cc_base);
104 void *user_arg;
105 dma_addr_t ivgen_dma_addr[SSI_MAX_IVGEN_DMA_ADDRESSES];
106 /* For the first 'ivgen_dma_addr_len' addresses of this array,
107 * generated IV would be placed in it by send_request().
108 * Same generated IV for all addresses!
109 */
110 unsigned int ivgen_dma_addr_len; /* Amount of 'ivgen_dma_addr' elements to be filled. */
111 unsigned int ivgen_size; /* The generated IV size required, 8/16 B allowed. */
112 struct completion seq_compl; /* request completion */
113};
114
115/**
116 * struct ssi_drvdata - driver private data context
117 * @cc_base: virt address of the CC registers
118 * @irq: device IRQ number
119 * @irq_mask: Interrupt mask shadow (1 for masked interrupts)
120 * @fw_ver: SeP loaded firmware version
121 */
122struct ssi_drvdata {
123 void __iomem *cc_base;
124 int irq;
125 u32 irq_mask;
126 u32 fw_ver;
127 /* Calibration time of start/stop
128 * monitor descriptors
129 */
130 u32 monitor_null_cycles;
131 struct platform_device *plat_dev;
132 ssi_sram_addr_t mlli_sram_addr;
133 void *buff_mgr_handle;
134 void *hash_handle;
135 void *aead_handle;
136 void *blkcipher_handle;
137 void *request_mgr_handle;
138 void *fips_handle;
139 void *ivgen_handle;
140 void *sram_mgr_handle;
141 struct clk *clk;
142 bool coherent;
143};
144
145struct ssi_crypto_alg {
146 struct list_head entry;
147 int cipher_mode;
148 int flow_mode; /* Note: currently, refers to the cipher mode only. */
149 int auth_mode;
150 struct ssi_drvdata *drvdata;
151 struct crypto_alg crypto_alg;
152 struct aead_alg aead_alg;
153};
154
155struct ssi_alg_template {
156 char name[CRYPTO_MAX_ALG_NAME];
157 char driver_name[CRYPTO_MAX_ALG_NAME];
158 unsigned int blocksize;
159 u32 type;
160 union {
161 struct ablkcipher_alg ablkcipher;
162 struct aead_alg aead;
163 struct blkcipher_alg blkcipher;
164 struct cipher_alg cipher;
165 struct compress_alg compress;
166 } template_u;
167 int cipher_mode;
168 int flow_mode; /* Note: currently, refers to the cipher mode only. */
169 int auth_mode;
170 struct ssi_drvdata *drvdata;
171};
172
173struct async_gen_req_ctx {
174 dma_addr_t iv_dma_addr;
175 enum drv_crypto_direction op_type;
176};
177
178static inline struct device *drvdata_to_dev(struct ssi_drvdata *drvdata)
179{
180 return &drvdata->plat_dev->dev;
181}
182
183#ifdef DX_DUMP_BYTES
184void dump_byte_array(const char *name, const u8 *the_array, unsigned long size);
185#else
186static inline void dump_byte_array(const char *name, const u8 *the_array,
187 unsigned long size) {};
188#endif
189
190int init_cc_regs(struct ssi_drvdata *drvdata, bool is_probe);
191void fini_cc_regs(struct ssi_drvdata *drvdata);
192int cc_clk_on(struct ssi_drvdata *drvdata);
193void cc_clk_off(struct ssi_drvdata *drvdata);
194
195static inline void cc_iowrite(struct ssi_drvdata *drvdata, u32 reg, u32 val)
196{
197 iowrite32(val, (drvdata->cc_base + reg));
198}
199
200static inline u32 cc_ioread(struct ssi_drvdata *drvdata, u32 reg)
201{
202 return ioread32(drvdata->cc_base + reg);
203}
204
205#endif /*__SSI_DRIVER_H__*/
206
diff --git a/drivers/staging/ccree/ssi_fips.h b/drivers/staging/ccree/ssi_fips.h
deleted file mode 100644
index 63bcca7f3af9..000000000000
--- a/drivers/staging/ccree/ssi_fips.h
+++ /dev/null
@@ -1,49 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __SSI_FIPS_H__
18#define __SSI_FIPS_H__
19
20#ifdef CONFIG_CRYPTO_FIPS
21
22enum cc_fips_status {
23 CC_FIPS_SYNC_MODULE_OK = 0x0,
24 CC_FIPS_SYNC_MODULE_ERROR = 0x1,
25 CC_FIPS_SYNC_REE_STATUS = 0x4,
26 CC_FIPS_SYNC_TEE_STATUS = 0x8,
27 CC_FIPS_SYNC_STATUS_RESERVE32B = S32_MAX
28};
29
30int ssi_fips_init(struct ssi_drvdata *p_drvdata);
31void ssi_fips_fini(struct ssi_drvdata *drvdata);
32void fips_handler(struct ssi_drvdata *drvdata);
33void cc_set_ree_fips_status(struct ssi_drvdata *drvdata, bool ok);
34
35#else /* CONFIG_CRYPTO_FIPS */
36
37static inline int ssi_fips_init(struct ssi_drvdata *p_drvdata)
38{
39 return 0;
40}
41
42static inline void ssi_fips_fini(struct ssi_drvdata *drvdata) {}
43static inline void cc_set_ree_fips_status(struct ssi_drvdata *drvdata, bool ok) {}
44static inline void fips_handler(struct ssi_drvdata *drvdata) {}
45
46#endif /* CONFIG_CRYPTO_FIPS */
47
48#endif /*__SSI_FIPS_H__*/
49
diff --git a/drivers/staging/ccree/ssi_hash.h b/drivers/staging/ccree/ssi_hash.h
deleted file mode 100644
index 2400e389d65a..000000000000
--- a/drivers/staging/ccree/ssi_hash.h
+++ /dev/null
@@ -1,103 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17/* \file ssi_hash.h
18 * ARM CryptoCell Hash Crypto API
19 */
20
21#ifndef __SSI_HASH_H__
22#define __SSI_HASH_H__
23
24#include "ssi_buffer_mgr.h"
25
26#define HMAC_IPAD_CONST 0x36363636
27#define HMAC_OPAD_CONST 0x5C5C5C5C
28#if (DX_DEV_SHA_MAX > 256)
29#define HASH_LEN_SIZE 16
30#define SSI_MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
31#define SSI_MAX_HASH_BLCK_SIZE SHA512_BLOCK_SIZE
32#else
33#define HASH_LEN_SIZE 8
34#define SSI_MAX_HASH_DIGEST_SIZE SHA256_DIGEST_SIZE
35#define SSI_MAX_HASH_BLCK_SIZE SHA256_BLOCK_SIZE
36#endif
37
38#define XCBC_MAC_K1_OFFSET 0
39#define XCBC_MAC_K2_OFFSET 16
40#define XCBC_MAC_K3_OFFSET 32
41
42#define CC_EXPORT_MAGIC 0xC2EE1070U
43
44// this struct was taken from drivers/crypto/nx/nx-aes-xcbc.c and it is used for xcbc/cmac statesize
45struct aeshash_state {
46 u8 state[AES_BLOCK_SIZE];
47 unsigned int count;
48 u8 buffer[AES_BLOCK_SIZE];
49};
50
51/* ahash state */
52struct ahash_req_ctx {
53 u8 *buff0;
54 u8 *buff1;
55 u8 *digest_result_buff;
56 struct async_gen_req_ctx gen_ctx;
57 enum ssi_req_dma_buf_type data_dma_buf_type;
58 u8 *digest_buff;
59 u8 *opad_digest_buff;
60 u8 *digest_bytes_len;
61 dma_addr_t opad_digest_dma_addr;
62 dma_addr_t digest_buff_dma_addr;
63 dma_addr_t digest_bytes_len_dma_addr;
64 dma_addr_t digest_result_dma_addr;
65 u32 buff0_cnt;
66 u32 buff1_cnt;
67 u32 buff_index;
68 u32 xcbc_count; /* count xcbc update operatations */
69 struct scatterlist buff_sg[2];
70 struct scatterlist *curr_sg;
71 u32 in_nents;
72 u32 mlli_nents;
73 struct mlli_params mlli_params;
74};
75
76int ssi_hash_alloc(struct ssi_drvdata *drvdata);
77int ssi_hash_init_sram_digest_consts(struct ssi_drvdata *drvdata);
78int ssi_hash_free(struct ssi_drvdata *drvdata);
79
80/*!
81 * Gets the initial digest length
82 *
83 * \param drvdata
84 * \param mode The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256/SHA384/SHA512
85 *
86 * \return u32 returns the address of the initial digest length in SRAM
87 */
88ssi_sram_addr_t
89ssi_ahash_get_initial_digest_len_sram_addr(void *drvdata, u32 mode);
90
91/*!
92 * Gets the address of the initial digest in SRAM
93 * according to the given hash mode
94 *
95 * \param drvdata
96 * \param mode The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256/SHA384/SHA512
97 *
98 * \return u32 The address of the inital digest in SRAM
99 */
100ssi_sram_addr_t ssi_ahash_get_larval_digest_sram_addr(void *drvdata, u32 mode);
101
102#endif /*__SSI_HASH_H__*/
103
diff --git a/drivers/staging/ccree/ssi_ivgen.h b/drivers/staging/ccree/ssi_ivgen.h
deleted file mode 100644
index 961aea411cb3..000000000000
--- a/drivers/staging/ccree/ssi_ivgen.h
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __SSI_IVGEN_H__
18#define __SSI_IVGEN_H__
19
20#include "cc_hw_queue_defs.h"
21
22#define SSI_IVPOOL_SEQ_LEN 8
23
24/*!
25 * Allocates iv-pool and maps resources.
26 * This function generates the first IV pool.
27 *
28 * \param drvdata Driver's private context
29 *
30 * \return int Zero for success, negative value otherwise.
31 */
32int ssi_ivgen_init(struct ssi_drvdata *drvdata);
33
34/*!
35 * Free iv-pool and ivgen context.
36 *
37 * \param drvdata
38 */
39void ssi_ivgen_fini(struct ssi_drvdata *drvdata);
40
41/*!
42 * Generates the initial pool in SRAM.
43 * This function should be invoked when resuming DX driver.
44 *
45 * \param drvdata
46 *
47 * \return int Zero for success, negative value otherwise.
48 */
49int ssi_ivgen_init_sram_pool(struct ssi_drvdata *drvdata);
50
51/*!
52 * Acquires 16 Bytes IV from the iv-pool
53 *
54 * \param drvdata Driver private context
55 * \param iv_out_dma Array of physical IV out addresses
56 * \param iv_out_dma_len Length of iv_out_dma array (additional elements of iv_out_dma array are ignore)
57 * \param iv_out_size May be 8 or 16 bytes long
58 * \param iv_seq IN/OUT array to the descriptors sequence
59 * \param iv_seq_len IN/OUT pointer to the sequence length
60 *
61 * \return int Zero for success, negative value otherwise.
62 */
63int ssi_ivgen_getiv(
64 struct ssi_drvdata *drvdata,
65 dma_addr_t iv_out_dma[],
66 unsigned int iv_out_dma_len,
67 unsigned int iv_out_size,
68 struct cc_hw_desc iv_seq[],
69 unsigned int *iv_seq_len);
70
71#endif /*__SSI_IVGEN_H__*/
diff --git a/drivers/staging/ccree/ssi_pm.c b/drivers/staging/ccree/ssi_pm.c
deleted file mode 100644
index 36a498098a70..000000000000
--- a/drivers/staging/ccree/ssi_pm.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "ssi_config.h"
18#include <linux/kernel.h>
19#include <linux/platform_device.h>
20#include <linux/interrupt.h>
21#include <crypto/ctr.h>
22#include <linux/pm_runtime.h>
23#include "ssi_driver.h"
24#include "ssi_buffer_mgr.h"
25#include "ssi_request_mgr.h"
26#include "ssi_sram_mgr.h"
27#include "ssi_sysfs.h"
28#include "ssi_ivgen.h"
29#include "ssi_hash.h"
30#include "ssi_pm.h"
31
32#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
33
34#define POWER_DOWN_ENABLE 0x01
35#define POWER_DOWN_DISABLE 0x00
36
37int ssi_power_mgr_runtime_suspend(struct device *dev)
38{
39 struct ssi_drvdata *drvdata =
40 (struct ssi_drvdata *)dev_get_drvdata(dev);
41 int rc;
42
43 dev_dbg(dev, "set HOST_POWER_DOWN_EN\n");
44 cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_ENABLE);
45 rc = ssi_request_mgr_runtime_suspend_queue(drvdata);
46 if (rc != 0) {
47 dev_err(dev, "ssi_request_mgr_runtime_suspend_queue (%x)\n",
48 rc);
49 return rc;
50 }
51 fini_cc_regs(drvdata);
52 cc_clk_off(drvdata);
53 return 0;
54}
55
56int ssi_power_mgr_runtime_resume(struct device *dev)
57{
58 int rc;
59 struct ssi_drvdata *drvdata =
60 (struct ssi_drvdata *)dev_get_drvdata(dev);
61
62 dev_dbg(dev, "unset HOST_POWER_DOWN_EN\n");
63 cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE);
64
65 rc = cc_clk_on(drvdata);
66 if (rc) {
67 dev_err(dev, "failed getting clock back on. We're toast.\n");
68 return rc;
69 }
70
71 rc = init_cc_regs(drvdata, false);
72 if (rc != 0) {
73 dev_err(dev, "init_cc_regs (%x)\n", rc);
74 return rc;
75 }
76
77 rc = ssi_request_mgr_runtime_resume_queue(drvdata);
78 if (rc != 0) {
79 dev_err(dev, "ssi_request_mgr_runtime_resume_queue (%x)\n", rc);
80 return rc;
81 }
82
83 /* must be after the queue resuming as it uses the HW queue*/
84 ssi_hash_init_sram_digest_consts(drvdata);
85
86 ssi_ivgen_init_sram_pool(drvdata);
87 return 0;
88}
89
90int ssi_power_mgr_runtime_get(struct device *dev)
91{
92 int rc = 0;
93
94 if (ssi_request_mgr_is_queue_runtime_suspend(
95 (struct ssi_drvdata *)dev_get_drvdata(dev))) {
96 rc = pm_runtime_get_sync(dev);
97 } else {
98 pm_runtime_get_noresume(dev);
99 }
100 return rc;
101}
102
103int ssi_power_mgr_runtime_put_suspend(struct device *dev)
104{
105 int rc = 0;
106
107 if (!ssi_request_mgr_is_queue_runtime_suspend(
108 (struct ssi_drvdata *)dev_get_drvdata(dev))) {
109 pm_runtime_mark_last_busy(dev);
110 rc = pm_runtime_put_autosuspend(dev);
111 } else {
112 /* Something wrong happens*/
113 dev_err(dev, "request to suspend already suspended queue");
114 rc = -EBUSY;
115 }
116 return rc;
117}
118
119#endif
120
121int ssi_power_mgr_init(struct ssi_drvdata *drvdata)
122{
123 int rc = 0;
124#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
125 struct device *dev = drvdata_to_dev(drvdata);
126
127 /* must be before the enabling to avoid resdundent suspending */
128 pm_runtime_set_autosuspend_delay(dev, SSI_SUSPEND_TIMEOUT);
129 pm_runtime_use_autosuspend(dev);
130 /* activate the PM module */
131 rc = pm_runtime_set_active(dev);
132 if (rc != 0)
133 return rc;
134 /* enable the PM module*/
135 pm_runtime_enable(dev);
136#endif
137 return rc;
138}
139
140void ssi_power_mgr_fini(struct ssi_drvdata *drvdata)
141{
142#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
143 pm_runtime_disable(drvdata_to_dev(drvdata));
144#endif
145}
diff --git a/drivers/staging/ccree/ssi_pm.h b/drivers/staging/ccree/ssi_pm.h
deleted file mode 100644
index 63673f60d2d8..000000000000
--- a/drivers/staging/ccree/ssi_pm.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17/* \file ssi_pm.h
18 */
19
20#ifndef __SSI_POWER_MGR_H__
21#define __SSI_POWER_MGR_H__
22
23#include "ssi_config.h"
24#include "ssi_driver.h"
25
26#define SSI_SUSPEND_TIMEOUT 3000
27
28int ssi_power_mgr_init(struct ssi_drvdata *drvdata);
29
30void ssi_power_mgr_fini(struct ssi_drvdata *drvdata);
31
32#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
33int ssi_power_mgr_runtime_suspend(struct device *dev);
34
35int ssi_power_mgr_runtime_resume(struct device *dev);
36
37int ssi_power_mgr_runtime_get(struct device *dev);
38
39int ssi_power_mgr_runtime_put_suspend(struct device *dev);
40#endif
41
42#endif /*__POWER_MGR_H__*/
43
diff --git a/drivers/staging/ccree/ssi_request_mgr.c b/drivers/staging/ccree/ssi_request_mgr.c
deleted file mode 100644
index a8a7dc672d4c..000000000000
--- a/drivers/staging/ccree/ssi_request_mgr.c
+++ /dev/null
@@ -1,610 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "ssi_config.h"
18#include <linux/kernel.h>
19#include <linux/platform_device.h>
20#include <linux/interrupt.h>
21#include <linux/delay.h>
22#include <crypto/ctr.h>
23#ifdef FLUSH_CACHE_ALL
24#include <asm/cacheflush.h>
25#endif
26#include <linux/pm_runtime.h>
27#include "ssi_driver.h"
28#include "ssi_buffer_mgr.h"
29#include "ssi_request_mgr.h"
30#include "ssi_sysfs.h"
31#include "ssi_ivgen.h"
32#include "ssi_pm.h"
33
34#define SSI_MAX_POLL_ITER 10
35
36struct ssi_request_mgr_handle {
37 /* Request manager resources */
38 unsigned int hw_queue_size; /* HW capability */
39 unsigned int min_free_hw_slots;
40 unsigned int max_used_sw_slots;
41 struct ssi_crypto_req req_queue[MAX_REQUEST_QUEUE_SIZE];
42 u32 req_queue_head;
43 u32 req_queue_tail;
44 u32 axi_completed;
45 u32 q_free_slots;
46 spinlock_t hw_lock;
47 struct cc_hw_desc compl_desc;
48 u8 *dummy_comp_buff;
49 dma_addr_t dummy_comp_buff_dma;
50 struct cc_hw_desc monitor_desc;
51
52#ifdef COMP_IN_WQ
53 struct workqueue_struct *workq;
54 struct delayed_work compwork;
55#else
56 struct tasklet_struct comptask;
57#endif
58#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
59 bool is_runtime_suspended;
60#endif
61};
62
63static void comp_handler(unsigned long devarg);
64#ifdef COMP_IN_WQ
65static void comp_work_handler(struct work_struct *work);
66#endif
67
68void request_mgr_fini(struct ssi_drvdata *drvdata)
69{
70 struct ssi_request_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
71 struct device *dev = drvdata_to_dev(drvdata);
72
73 if (!req_mgr_h)
74 return; /* Not allocated */
75
76 if (req_mgr_h->dummy_comp_buff_dma != 0) {
77 dma_free_coherent(dev, sizeof(u32), req_mgr_h->dummy_comp_buff,
78 req_mgr_h->dummy_comp_buff_dma);
79 }
80
81 dev_dbg(dev, "max_used_hw_slots=%d\n", (req_mgr_h->hw_queue_size -
82 req_mgr_h->min_free_hw_slots));
83 dev_dbg(dev, "max_used_sw_slots=%d\n", req_mgr_h->max_used_sw_slots);
84
85#ifdef COMP_IN_WQ
86 flush_workqueue(req_mgr_h->workq);
87 destroy_workqueue(req_mgr_h->workq);
88#else
89 /* Kill tasklet */
90 tasklet_kill(&req_mgr_h->comptask);
91#endif
92 memset(req_mgr_h, 0, sizeof(struct ssi_request_mgr_handle));
93 kfree(req_mgr_h);
94 drvdata->request_mgr_handle = NULL;
95}
96
97int request_mgr_init(struct ssi_drvdata *drvdata)
98{
99 struct ssi_request_mgr_handle *req_mgr_h;
100 struct device *dev = drvdata_to_dev(drvdata);
101 int rc = 0;
102
103 req_mgr_h = kzalloc(sizeof(*req_mgr_h), GFP_KERNEL);
104 if (!req_mgr_h) {
105 rc = -ENOMEM;
106 goto req_mgr_init_err;
107 }
108
109 drvdata->request_mgr_handle = req_mgr_h;
110
111 spin_lock_init(&req_mgr_h->hw_lock);
112#ifdef COMP_IN_WQ
113 dev_dbg(dev, "Initializing completion workqueue\n");
114 req_mgr_h->workq = create_singlethread_workqueue("arm_cc7x_wq");
115 if (unlikely(!req_mgr_h->workq)) {
116 dev_err(dev, "Failed creating work queue\n");
117 rc = -ENOMEM;
118 goto req_mgr_init_err;
119 }
120 INIT_DELAYED_WORK(&req_mgr_h->compwork, comp_work_handler);
121#else
122 dev_dbg(dev, "Initializing completion tasklet\n");
123 tasklet_init(&req_mgr_h->comptask, comp_handler, (unsigned long)drvdata);
124#endif
125 req_mgr_h->hw_queue_size = cc_ioread(drvdata,
126 CC_REG(DSCRPTR_QUEUE_SRAM_SIZE));
127 dev_dbg(dev, "hw_queue_size=0x%08X\n", req_mgr_h->hw_queue_size);
128 if (req_mgr_h->hw_queue_size < MIN_HW_QUEUE_SIZE) {
129 dev_err(dev, "Invalid HW queue size = %u (Min. required is %u)\n",
130 req_mgr_h->hw_queue_size, MIN_HW_QUEUE_SIZE);
131 rc = -ENOMEM;
132 goto req_mgr_init_err;
133 }
134 req_mgr_h->min_free_hw_slots = req_mgr_h->hw_queue_size;
135 req_mgr_h->max_used_sw_slots = 0;
136
137 /* Allocate DMA word for "dummy" completion descriptor use */
138 req_mgr_h->dummy_comp_buff = dma_alloc_coherent(dev, sizeof(u32),
139 &req_mgr_h->dummy_comp_buff_dma,
140 GFP_KERNEL);
141 if (!req_mgr_h->dummy_comp_buff) {
142 dev_err(dev, "Not enough memory to allocate DMA (%zu) dropped buffer\n",
143 sizeof(u32));
144 rc = -ENOMEM;
145 goto req_mgr_init_err;
146 }
147
148 /* Init. "dummy" completion descriptor */
149 hw_desc_init(&req_mgr_h->compl_desc);
150 set_din_const(&req_mgr_h->compl_desc, 0, sizeof(u32));
151 set_dout_dlli(&req_mgr_h->compl_desc, req_mgr_h->dummy_comp_buff_dma,
152 sizeof(u32), NS_BIT, 1);
153 set_flow_mode(&req_mgr_h->compl_desc, BYPASS);
154 set_queue_last_ind(&req_mgr_h->compl_desc);
155
156 return 0;
157
158req_mgr_init_err:
159 request_mgr_fini(drvdata);
160 return rc;
161}
162
163static inline void enqueue_seq(
164 void __iomem *cc_base,
165 struct cc_hw_desc seq[], unsigned int seq_len)
166{
167 int i;
168
169 for (i = 0; i < seq_len; i++) {
170 writel_relaxed(seq[i].word[0], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0)));
171 writel_relaxed(seq[i].word[1], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0)));
172 writel_relaxed(seq[i].word[2], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0)));
173 writel_relaxed(seq[i].word[3], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0)));
174 writel_relaxed(seq[i].word[4], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0)));
175 wmb();
176 writel_relaxed(seq[i].word[5], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0)));
177#ifdef DX_DUMP_DESCS
178 dev_dbg(dev, "desc[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
179 i, seq[i].word[0], seq[i].word[1], seq[i].word[2],
180 seq[i].word[3], seq[i].word[4], seq[i].word[5]);
181#endif
182 }
183}
184
185/*!
186 * Completion will take place if and only if user requested completion
187 * by setting "is_dout = 0" in send_request().
188 *
189 * \param dev
190 * \param dx_compl_h The completion event to signal
191 */
192static void request_mgr_complete(struct device *dev, void *dx_compl_h, void __iomem *cc_base)
193{
194 struct completion *this_compl = dx_compl_h;
195
196 complete(this_compl);
197}
198
199static inline int request_mgr_queues_status_check(
200 struct ssi_drvdata *drvdata,
201 struct ssi_request_mgr_handle *req_mgr_h,
202 unsigned int total_seq_len)
203{
204 unsigned long poll_queue;
205 struct device *dev = drvdata_to_dev(drvdata);
206
207 /* SW queue is checked only once as it will not
208 * be chaned during the poll becasue the spinlock_bh
209 * is held by the thread
210 */
211 if (unlikely(((req_mgr_h->req_queue_head + 1) &
212 (MAX_REQUEST_QUEUE_SIZE - 1)) ==
213 req_mgr_h->req_queue_tail)) {
214 dev_err(dev, "SW FIFO is full. req_queue_head=%d sw_fifo_len=%d\n",
215 req_mgr_h->req_queue_head, MAX_REQUEST_QUEUE_SIZE);
216 return -EBUSY;
217 }
218
219 if ((likely(req_mgr_h->q_free_slots >= total_seq_len)))
220 return 0;
221
222 /* Wait for space in HW queue. Poll constant num of iterations. */
223 for (poll_queue = 0; poll_queue < SSI_MAX_POLL_ITER ; poll_queue++) {
224 req_mgr_h->q_free_slots =
225 cc_ioread(drvdata, CC_REG(DSCRPTR_QUEUE_CONTENT));
226 if (unlikely(req_mgr_h->q_free_slots <
227 req_mgr_h->min_free_hw_slots)) {
228 req_mgr_h->min_free_hw_slots = req_mgr_h->q_free_slots;
229 }
230
231 if (likely(req_mgr_h->q_free_slots >= total_seq_len)) {
232 /* If there is enough place return */
233 return 0;
234 }
235
236 dev_dbg(dev, "HW FIFO is full. q_free_slots=%d total_seq_len=%d\n",
237 req_mgr_h->q_free_slots, total_seq_len);
238 }
239 /* No room in the HW queue try again later */
240 dev_dbg(dev, "HW FIFO full, timeout. req_queue_head=%d sw_fifo_len=%d q_free_slots=%d total_seq_len=%d\n",
241 req_mgr_h->req_queue_head, MAX_REQUEST_QUEUE_SIZE,
242 req_mgr_h->q_free_slots, total_seq_len);
243 return -EAGAIN;
244}
245
246/*!
247 * Enqueue caller request to crypto hardware.
248 *
249 * \param drvdata
250 * \param ssi_req The request to enqueue
251 * \param desc The crypto sequence
252 * \param len The crypto sequence length
253 * \param is_dout If "true": completion is handled by the caller
254 * If "false": this function adds a dummy descriptor completion
255 * and waits upon completion signal.
256 *
257 * \return int Returns -EINPROGRESS if "is_dout=true"; "0" if "is_dout=false"
258 */
259int send_request(
260 struct ssi_drvdata *drvdata, struct ssi_crypto_req *ssi_req,
261 struct cc_hw_desc *desc, unsigned int len, bool is_dout)
262{
263 void __iomem *cc_base = drvdata->cc_base;
264 struct ssi_request_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
265 unsigned int used_sw_slots;
266 unsigned int iv_seq_len = 0;
267 unsigned int total_seq_len = len; /*initial sequence length*/
268 struct cc_hw_desc iv_seq[SSI_IVPOOL_SEQ_LEN];
269 struct device *dev = drvdata_to_dev(drvdata);
270 int rc;
271 unsigned int max_required_seq_len = (total_seq_len +
272 ((ssi_req->ivgen_dma_addr_len == 0) ? 0 :
273 SSI_IVPOOL_SEQ_LEN) +
274 (!is_dout ? 1 : 0));
275
276#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
277 rc = ssi_power_mgr_runtime_get(dev);
278 if (rc != 0) {
279 dev_err(dev, "ssi_power_mgr_runtime_get returned %x\n", rc);
280 return rc;
281 }
282#endif
283
284 do {
285 spin_lock_bh(&req_mgr_h->hw_lock);
286
287 /* Check if there is enough place in the SW/HW queues
288 * in case iv gen add the max size and in case of no dout add 1
289 * for the internal completion descriptor
290 */
291 rc = request_mgr_queues_status_check(drvdata, req_mgr_h,
292 max_required_seq_len);
293 if (likely(rc == 0))
294 /* There is enough place in the queue */
295 break;
296 /* something wrong release the spinlock*/
297 spin_unlock_bh(&req_mgr_h->hw_lock);
298
299 if (rc != -EAGAIN) {
300 /* Any error other than HW queue full
301 * (SW queue is full)
302 */
303#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
304 ssi_power_mgr_runtime_put_suspend(dev);
305#endif
306 return rc;
307 }
308
309 /* HW queue is full - short sleep */
310 msleep(1);
311 } while (1);
312
313 /* Additional completion descriptor is needed incase caller did not
314 * enabled any DLLI/MLLI DOUT bit in the given sequence
315 */
316 if (!is_dout) {
317 init_completion(&ssi_req->seq_compl);
318 ssi_req->user_cb = request_mgr_complete;
319 ssi_req->user_arg = &ssi_req->seq_compl;
320 total_seq_len++;
321 }
322
323 if (ssi_req->ivgen_dma_addr_len > 0) {
324 dev_dbg(dev, "Acquire IV from pool into %d DMA addresses %pad, %pad, %pad, IV-size=%u\n",
325 ssi_req->ivgen_dma_addr_len,
326 &ssi_req->ivgen_dma_addr[0],
327 &ssi_req->ivgen_dma_addr[1],
328 &ssi_req->ivgen_dma_addr[2],
329 ssi_req->ivgen_size);
330
331 /* Acquire IV from pool */
332 rc = ssi_ivgen_getiv(drvdata, ssi_req->ivgen_dma_addr,
333 ssi_req->ivgen_dma_addr_len,
334 ssi_req->ivgen_size, iv_seq, &iv_seq_len);
335
336 if (unlikely(rc != 0)) {
337 dev_err(dev, "Failed to generate IV (rc=%d)\n", rc);
338 spin_unlock_bh(&req_mgr_h->hw_lock);
339#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
340 ssi_power_mgr_runtime_put_suspend(dev);
341#endif
342 return rc;
343 }
344
345 total_seq_len += iv_seq_len;
346 }
347
348 used_sw_slots = ((req_mgr_h->req_queue_head - req_mgr_h->req_queue_tail) & (MAX_REQUEST_QUEUE_SIZE - 1));
349 if (unlikely(used_sw_slots > req_mgr_h->max_used_sw_slots))
350 req_mgr_h->max_used_sw_slots = used_sw_slots;
351
352 /* Enqueue request - must be locked with HW lock*/
353 req_mgr_h->req_queue[req_mgr_h->req_queue_head] = *ssi_req;
354 req_mgr_h->req_queue_head = (req_mgr_h->req_queue_head + 1) & (MAX_REQUEST_QUEUE_SIZE - 1);
355 /* TODO: Use circ_buf.h ? */
356
357 dev_dbg(dev, "Enqueue request head=%u\n", req_mgr_h->req_queue_head);
358
359#ifdef FLUSH_CACHE_ALL
360 flush_cache_all();
361#endif
362
363 /* STAT_PHASE_4: Push sequence */
364 enqueue_seq(cc_base, iv_seq, iv_seq_len);
365 enqueue_seq(cc_base, desc, len);
366 enqueue_seq(cc_base, &req_mgr_h->compl_desc, (is_dout ? 0 : 1));
367
368 if (unlikely(req_mgr_h->q_free_slots < total_seq_len)) {
369 /* This situation should never occur. Maybe indicating problem
370 * with resuming power. Set the free slot count to 0 and hope
371 * for the best.
372 */
373 dev_err(dev, "HW free slot count mismatch.");
374 req_mgr_h->q_free_slots = 0;
375 } else {
376 /* Update the free slots in HW queue */
377 req_mgr_h->q_free_slots -= total_seq_len;
378 }
379
380 spin_unlock_bh(&req_mgr_h->hw_lock);
381
382 if (!is_dout) {
383 /* Wait upon sequence completion.
384 * Return "0" -Operation done successfully.
385 */
386 wait_for_completion(&ssi_req->seq_compl);
387 return 0;
388 }
389 /* Operation still in process */
390 return -EINPROGRESS;
391}
392
393/*!
394 * Enqueue caller request to crypto hardware during init process.
395 * assume this function is not called in middle of a flow,
396 * since we set QUEUE_LAST_IND flag in the last descriptor.
397 *
398 * \param drvdata
399 * \param desc The crypto sequence
400 * \param len The crypto sequence length
401 *
402 * \return int Returns "0" upon success
403 */
404int send_request_init(
405 struct ssi_drvdata *drvdata, struct cc_hw_desc *desc, unsigned int len)
406{
407 void __iomem *cc_base = drvdata->cc_base;
408 struct ssi_request_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
409 unsigned int total_seq_len = len; /*initial sequence length*/
410 int rc = 0;
411
412 /* Wait for space in HW and SW FIFO. Poll for as much as FIFO_TIMEOUT. */
413 rc = request_mgr_queues_status_check(drvdata, req_mgr_h,
414 total_seq_len);
415 if (unlikely(rc != 0))
416 return rc;
417
418 set_queue_last_ind(&desc[(len - 1)]);
419
420 enqueue_seq(cc_base, desc, len);
421
422 /* Update the free slots in HW queue */
423 req_mgr_h->q_free_slots =
424 cc_ioread(drvdata, CC_REG(DSCRPTR_QUEUE_CONTENT));
425
426 return 0;
427}
428
429void complete_request(struct ssi_drvdata *drvdata)
430{
431 struct ssi_request_mgr_handle *request_mgr_handle =
432 drvdata->request_mgr_handle;
433#ifdef COMP_IN_WQ
434 queue_delayed_work(request_mgr_handle->workq, &request_mgr_handle->compwork, 0);
435#else
436 tasklet_schedule(&request_mgr_handle->comptask);
437#endif
438}
439
440#ifdef COMP_IN_WQ
441static void comp_work_handler(struct work_struct *work)
442{
443 struct ssi_drvdata *drvdata =
444 container_of(work, struct ssi_drvdata, compwork.work);
445
446 comp_handler((unsigned long)drvdata);
447}
448#endif
449
450static void proc_completions(struct ssi_drvdata *drvdata)
451{
452 struct ssi_crypto_req *ssi_req;
453 struct device *dev = drvdata_to_dev(drvdata);
454 struct ssi_request_mgr_handle *request_mgr_handle =
455 drvdata->request_mgr_handle;
456#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
457 int rc = 0;
458#endif
459
460 while (request_mgr_handle->axi_completed) {
461 request_mgr_handle->axi_completed--;
462
463 /* Dequeue request */
464 if (unlikely(request_mgr_handle->req_queue_head == request_mgr_handle->req_queue_tail)) {
465 /* We are supposed to handle a completion but our
466 * queue is empty. This is not normal. Return and
467 * hope for the best.
468 */
469 dev_err(dev, "Request queue is empty head == tail %u\n",
470 request_mgr_handle->req_queue_head);
471 break;
472 }
473
474 ssi_req = &request_mgr_handle->req_queue[request_mgr_handle->req_queue_tail];
475
476#ifdef FLUSH_CACHE_ALL
477 flush_cache_all();
478#endif
479
480#ifdef COMPLETION_DELAY
481 /* Delay */
482 {
483 u32 axi_err;
484 int i;
485
486 dev_info(dev, "Delay\n");
487 for (i = 0; i < 1000000; i++)
488 axi_err = cc_ioread(drvdata,
489 CC_REG(AXIM_MON_ERR));
490 }
491#endif /* COMPLETION_DELAY */
492
493 if (likely(ssi_req->user_cb))
494 ssi_req->user_cb(dev, ssi_req->user_arg,
495 drvdata->cc_base);
496 request_mgr_handle->req_queue_tail = (request_mgr_handle->req_queue_tail + 1) & (MAX_REQUEST_QUEUE_SIZE - 1);
497 dev_dbg(dev, "Dequeue request tail=%u\n",
498 request_mgr_handle->req_queue_tail);
499 dev_dbg(dev, "Request completed. axi_completed=%d\n",
500 request_mgr_handle->axi_completed);
501#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
502 rc = ssi_power_mgr_runtime_put_suspend(dev);
503 if (rc != 0)
504 dev_err(dev, "Failed to set runtime suspension %d\n",
505 rc);
506#endif
507 }
508}
509
510static inline u32 cc_axi_comp_count(struct ssi_drvdata *drvdata)
511{
512 return FIELD_GET(AXIM_MON_COMP_VALUE,
513 cc_ioread(drvdata, CC_REG(AXIM_MON_COMP)));
514}
515
516/* Deferred service handler, run as interrupt-fired tasklet */
517static void comp_handler(unsigned long devarg)
518{
519 struct ssi_drvdata *drvdata = (struct ssi_drvdata *)devarg;
520 struct ssi_request_mgr_handle *request_mgr_handle =
521 drvdata->request_mgr_handle;
522
523 u32 irq;
524
525 irq = (drvdata->irq & SSI_COMP_IRQ_MASK);
526
527 if (irq & SSI_COMP_IRQ_MASK) {
528 /* To avoid the interrupt from firing as we unmask it,
529 * we clear it now
530 */
531 cc_iowrite(drvdata, CC_REG(HOST_ICR), SSI_COMP_IRQ_MASK);
532
533 /* Avoid race with above clear: Test completion counter
534 * once more
535 */
536 request_mgr_handle->axi_completed +=
537 cc_axi_comp_count(drvdata);
538
539 while (request_mgr_handle->axi_completed) {
540 do {
541 proc_completions(drvdata);
542 /* At this point (after proc_completions()),
543 * request_mgr_handle->axi_completed is 0.
544 */
545 request_mgr_handle->axi_completed =
546 cc_axi_comp_count(drvdata);
547 } while (request_mgr_handle->axi_completed > 0);
548
549 cc_iowrite(drvdata, CC_REG(HOST_ICR),
550 SSI_COMP_IRQ_MASK);
551
552 request_mgr_handle->axi_completed +=
553 cc_axi_comp_count(drvdata);
554 }
555 }
556 /* after verifing that there is nothing to do,
557 * unmask AXI completion interrupt
558 */
559 cc_iowrite(drvdata, CC_REG(HOST_IMR),
560 cc_ioread(drvdata, CC_REG(HOST_IMR)) & ~irq);
561}
562
563/*
564 * resume the queue configuration - no need to take the lock as this happens inside
565 * the spin lock protection
566 */
567#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
568int ssi_request_mgr_runtime_resume_queue(struct ssi_drvdata *drvdata)
569{
570 struct ssi_request_mgr_handle *request_mgr_handle = drvdata->request_mgr_handle;
571
572 spin_lock_bh(&request_mgr_handle->hw_lock);
573 request_mgr_handle->is_runtime_suspended = false;
574 spin_unlock_bh(&request_mgr_handle->hw_lock);
575
576 return 0;
577}
578
579/*
580 * suspend the queue configuration. Since it is used for the runtime suspend
581 * only verify that the queue can be suspended.
582 */
583int ssi_request_mgr_runtime_suspend_queue(struct ssi_drvdata *drvdata)
584{
585 struct ssi_request_mgr_handle *request_mgr_handle =
586 drvdata->request_mgr_handle;
587
588 /* lock the send_request */
589 spin_lock_bh(&request_mgr_handle->hw_lock);
590 if (request_mgr_handle->req_queue_head !=
591 request_mgr_handle->req_queue_tail) {
592 spin_unlock_bh(&request_mgr_handle->hw_lock);
593 return -EBUSY;
594 }
595 request_mgr_handle->is_runtime_suspended = true;
596 spin_unlock_bh(&request_mgr_handle->hw_lock);
597
598 return 0;
599}
600
601bool ssi_request_mgr_is_queue_runtime_suspend(struct ssi_drvdata *drvdata)
602{
603 struct ssi_request_mgr_handle *request_mgr_handle =
604 drvdata->request_mgr_handle;
605
606 return request_mgr_handle->is_runtime_suspended;
607}
608
609#endif
610
diff --git a/drivers/staging/ccree/ssi_request_mgr.h b/drivers/staging/ccree/ssi_request_mgr.h
deleted file mode 100644
index bdbbf89e5367..000000000000
--- a/drivers/staging/ccree/ssi_request_mgr.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17/* \file request_mgr.h
18 * Request Manager
19 */
20
21#ifndef __REQUEST_MGR_H__
22#define __REQUEST_MGR_H__
23
24#include "cc_hw_queue_defs.h"
25
26int request_mgr_init(struct ssi_drvdata *drvdata);
27
28/*!
29 * Enqueue caller request to crypto hardware.
30 *
31 * \param drvdata
32 * \param ssi_req The request to enqueue
33 * \param desc The crypto sequence
34 * \param len The crypto sequence length
35 * \param is_dout If "true": completion is handled by the caller
36 * If "false": this function adds a dummy descriptor completion
37 * and waits upon completion signal.
38 *
39 * \return int Returns -EINPROGRESS if "is_dout=ture"; "0" if "is_dout=false"
40 */
41int send_request(
42 struct ssi_drvdata *drvdata, struct ssi_crypto_req *ssi_req,
43 struct cc_hw_desc *desc, unsigned int len, bool is_dout);
44
45int send_request_init(
46 struct ssi_drvdata *drvdata, struct cc_hw_desc *desc, unsigned int len);
47
48void complete_request(struct ssi_drvdata *drvdata);
49
50void request_mgr_fini(struct ssi_drvdata *drvdata);
51
52#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
53int ssi_request_mgr_runtime_resume_queue(struct ssi_drvdata *drvdata);
54
55int ssi_request_mgr_runtime_suspend_queue(struct ssi_drvdata *drvdata);
56
57bool ssi_request_mgr_is_queue_runtime_suspend(struct ssi_drvdata *drvdata);
58#endif
59
60#endif /*__REQUEST_MGR_H__*/
diff --git a/drivers/staging/ccree/ssi_sram_mgr.h b/drivers/staging/ccree/ssi_sram_mgr.h
deleted file mode 100644
index 9ba1d59a0bae..000000000000
--- a/drivers/staging/ccree/ssi_sram_mgr.h
+++ /dev/null
@@ -1,79 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __SSI_SRAM_MGR_H__
18#define __SSI_SRAM_MGR_H__
19
20#ifndef SSI_CC_SRAM_SIZE
21#define SSI_CC_SRAM_SIZE 4096
22#endif
23
24struct ssi_drvdata;
25
26/**
27 * Address (offset) within CC internal SRAM
28 */
29
30typedef u64 ssi_sram_addr_t;
31
32#define NULL_SRAM_ADDR ((ssi_sram_addr_t)-1)
33
34/*!
35 * Initializes SRAM pool.
36 * The first X bytes of SRAM are reserved for ROM usage, hence, pool
37 * starts right after X bytes.
38 *
39 * \param drvdata
40 *
41 * \return int Zero for success, negative value otherwise.
42 */
43int ssi_sram_mgr_init(struct ssi_drvdata *drvdata);
44
45/*!
46 * Uninits SRAM pool.
47 *
48 * \param drvdata
49 */
50void ssi_sram_mgr_fini(struct ssi_drvdata *drvdata);
51
52/*!
53 * Allocated buffer from SRAM pool.
54 * Note: Caller is responsible to free the LAST allocated buffer.
55 * This function does not taking care of any fragmentation may occur
56 * by the order of calls to alloc/free.
57 *
58 * \param drvdata
59 * \param size The requested bytes to allocate
60 */
61ssi_sram_addr_t ssi_sram_mgr_alloc(struct ssi_drvdata *drvdata, u32 size);
62
63/**
64 * ssi_sram_mgr_const2sram_desc() - Create const descriptors sequence to
65 * set values in given array into SRAM.
66 * Note: each const value can't exceed word size.
67 *
68 * @src: A pointer to array of words to set as consts.
69 * @dst: The target SRAM buffer to set into
70 * @nelements: The number of words in "src" array
71 * @seq: A pointer to the given IN/OUT descriptor sequence
72 * @seq_len: A pointer to the given IN/OUT sequence length
73 */
74void ssi_sram_mgr_const2sram_desc(
75 const u32 *src, ssi_sram_addr_t dst,
76 unsigned int nelement,
77 struct cc_hw_desc *seq, unsigned int *seq_len);
78
79#endif /*__SSI_SRAM_MGR_H__*/
diff --git a/drivers/staging/ccree/ssi_sysfs.c b/drivers/staging/ccree/ssi_sysfs.c
deleted file mode 100644
index 5d39f15cdb59..000000000000
--- a/drivers/staging/ccree/ssi_sysfs.c
+++ /dev/null
@@ -1,172 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/kernel.h>
18#include "ssi_config.h"
19#include "ssi_driver.h"
20#include "cc_crypto_ctx.h"
21#include "ssi_sysfs.h"
22
23#ifdef ENABLE_CC_SYSFS
24
25static struct ssi_drvdata *sys_get_drvdata(void);
26
27static ssize_t ssi_sys_regdump_show(struct kobject *kobj,
28 struct kobj_attribute *attr, char *buf)
29{
30 struct ssi_drvdata *drvdata = sys_get_drvdata();
31 u32 register_value;
32 int offset = 0;
33
34 register_value = cc_ioread(drvdata, CC_REG(HOST_SIGNATURE));
35 offset += scnprintf(buf + offset, PAGE_SIZE - offset, "%s \t(0x%lX)\t 0x%08X\n", "HOST_SIGNATURE ", DX_HOST_SIGNATURE_REG_OFFSET, register_value);
36 register_value = cc_ioread(drvdata, CC_REG(HOST_IRR));
37 offset += scnprintf(buf + offset, PAGE_SIZE - offset, "%s \t(0x%lX)\t 0x%08X\n", "HOST_IRR ", DX_HOST_IRR_REG_OFFSET, register_value);
38 register_value = cc_ioread(drvdata, CC_REG(HOST_POWER_DOWN_EN));
39 offset += scnprintf(buf + offset, PAGE_SIZE - offset, "%s \t(0x%lX)\t 0x%08X\n", "HOST_POWER_DOWN_EN ", DX_HOST_POWER_DOWN_EN_REG_OFFSET, register_value);
40 register_value = cc_ioread(drvdata, CC_REG(AXIM_MON_ERR));
41 offset += scnprintf(buf + offset, PAGE_SIZE - offset, "%s \t(0x%lX)\t 0x%08X\n", "AXIM_MON_ERR ", DX_AXIM_MON_ERR_REG_OFFSET, register_value);
42 register_value = cc_ioread(drvdata, CC_REG(DSCRPTR_QUEUE_CONTENT));
43 offset += scnprintf(buf + offset, PAGE_SIZE - offset, "%s \t(0x%lX)\t 0x%08X\n", "DSCRPTR_QUEUE_CONTENT", DX_DSCRPTR_QUEUE_CONTENT_REG_OFFSET, register_value);
44 return offset;
45}
46
47static ssize_t ssi_sys_help_show(struct kobject *kobj,
48 struct kobj_attribute *attr, char *buf)
49{
50 char *help_str[] = {
51 "cat reg_dump ", "Print several of CC register values",
52 };
53 int i = 0, offset = 0;
54
55 offset += scnprintf(buf + offset, PAGE_SIZE - offset, "Usage:\n");
56 for (i = 0; i < ARRAY_SIZE(help_str); i += 2)
57 offset += scnprintf(buf + offset, PAGE_SIZE - offset, "%s\t\t%s\n", help_str[i], help_str[i + 1]);
58
59 return offset;
60}
61
62/********************************************************
63 * SYSFS objects *
64 ********************************************************/
65/*
66 * Structure used to create a directory
67 * and its attributes in sysfs.
68 */
69struct sys_dir {
70 struct kobject *sys_dir_kobj;
71 struct attribute_group sys_dir_attr_group;
72 struct attribute **sys_dir_attr_list;
73 u32 num_of_attrs;
74 struct ssi_drvdata *drvdata; /* Associated driver context */
75};
76
77/* top level directory structures */
78static struct sys_dir sys_top_dir;
79
80/* TOP LEVEL ATTRIBUTES */
81static struct kobj_attribute ssi_sys_top_level_attrs[] = {
82 __ATTR(dump_regs, 0444, ssi_sys_regdump_show, NULL),
83 __ATTR(help, 0444, ssi_sys_help_show, NULL),
84#if defined CC_CYCLE_COUNT
85 __ATTR(stats_host, 0664, ssi_sys_stat_host_db_show, ssi_sys_stats_host_db_clear),
86 __ATTR(stats_cc, 0664, ssi_sys_stat_cc_db_show, ssi_sys_stats_cc_db_clear),
87#endif
88
89};
90
91static struct ssi_drvdata *sys_get_drvdata(void)
92{
93 /* TODO: supporting multiple SeP devices would require avoiding
94 * global "top_dir" and finding associated "top_dir" by traversing
95 * up the tree to the kobject which matches one of the top_dir's
96 */
97 return sys_top_dir.drvdata;
98}
99
100static int sys_init_dir(struct sys_dir *sys_dir, struct ssi_drvdata *drvdata,
101 struct kobject *parent_dir_kobj, const char *dir_name,
102 struct kobj_attribute *attrs, u32 num_of_attrs)
103{
104 int i;
105
106 memset(sys_dir, 0, sizeof(struct sys_dir));
107
108 sys_dir->drvdata = drvdata;
109
110 /* initialize directory kobject */
111 sys_dir->sys_dir_kobj =
112 kobject_create_and_add(dir_name, parent_dir_kobj);
113
114 if (!(sys_dir->sys_dir_kobj))
115 return -ENOMEM;
116 /* allocate memory for directory's attributes list */
117 sys_dir->sys_dir_attr_list =
118 kcalloc(num_of_attrs + 1, sizeof(struct attribute *),
119 GFP_KERNEL);
120
121 if (!(sys_dir->sys_dir_attr_list)) {
122 kobject_put(sys_dir->sys_dir_kobj);
123 return -ENOMEM;
124 }
125
126 sys_dir->num_of_attrs = num_of_attrs;
127
128 /* initialize attributes list */
129 for (i = 0; i < num_of_attrs; ++i)
130 sys_dir->sys_dir_attr_list[i] = &attrs[i].attr;
131
132 /* last list entry should be NULL */
133 sys_dir->sys_dir_attr_list[num_of_attrs] = NULL;
134
135 sys_dir->sys_dir_attr_group.attrs = sys_dir->sys_dir_attr_list;
136
137 return sysfs_create_group(sys_dir->sys_dir_kobj,
138 &sys_dir->sys_dir_attr_group);
139}
140
141static void sys_free_dir(struct sys_dir *sys_dir)
142{
143 if (!sys_dir)
144 return;
145
146 kfree(sys_dir->sys_dir_attr_list);
147
148 if (sys_dir->sys_dir_kobj)
149 kobject_put(sys_dir->sys_dir_kobj);
150}
151
152int ssi_sysfs_init(struct kobject *sys_dev_obj, struct ssi_drvdata *drvdata)
153{
154 int retval;
155 struct device *dev = drvdata_to_dev(drvdata);
156
157 dev_info(dev, "setup sysfs under %s\n", sys_dev_obj->name);
158
159 /* Initialize top directory */
160 retval = sys_init_dir(&sys_top_dir, drvdata, sys_dev_obj, "cc_info",
161 ssi_sys_top_level_attrs,
162 ARRAY_SIZE(ssi_sys_top_level_attrs));
163 return retval;
164}
165
166void ssi_sysfs_fini(void)
167{
168 sys_free_dir(&sys_top_dir);
169}
170
171#endif /*ENABLE_CC_SYSFS*/
172
diff --git a/drivers/staging/ccree/ssi_sysfs.h b/drivers/staging/ccree/ssi_sysfs.h
deleted file mode 100644
index 44ae3d4c40b3..000000000000
--- a/drivers/staging/ccree/ssi_sysfs.h
+++ /dev/null
@@ -1,55 +0,0 @@
1/*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17/* \file ssi_sysfs.h
18 * ARM CryptoCell sysfs APIs
19 */
20
21#ifndef __SSI_SYSFS_H__
22#define __SSI_SYSFS_H__
23
24#include <asm/timex.h>
25
26/* forward declaration */
27struct ssi_drvdata;
28
29enum stat_phase {
30 STAT_PHASE_0 = 0,
31 STAT_PHASE_1,
32 STAT_PHASE_2,
33 STAT_PHASE_3,
34 STAT_PHASE_4,
35 STAT_PHASE_5,
36 STAT_PHASE_6,
37 MAX_STAT_PHASES,
38};
39
40enum stat_op {
41 STAT_OP_TYPE_NULL = 0,
42 STAT_OP_TYPE_ENCODE,
43 STAT_OP_TYPE_DECODE,
44 STAT_OP_TYPE_SETKEY,
45 STAT_OP_TYPE_GENERIC,
46 MAX_STAT_OP_TYPES,
47};
48
49int ssi_sysfs_init(struct kobject *sys_dev_obj, struct ssi_drvdata *drvdata);
50void ssi_sysfs_fini(void);
51void update_host_stat(unsigned int op_type, unsigned int phase, cycles_t result);
52void update_cc_stat(unsigned int op_type, unsigned int phase, unsigned int elapsed_cycles);
53void display_all_stat_db(void);
54
55#endif /*__SSI_SYSFS_H__*/
diff --git a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
index bf3fe7c61be5..cae7e6e695b0 100644
--- a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
+++ b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
@@ -1,21 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Xilinx 'Clocking Wizard' driver 3 * Xilinx 'Clocking Wizard' driver
3 * 4 *
4 * Copyright (C) 2013 - 2014 Xilinx 5 * Copyright (C) 2013 - 2014 Xilinx
5 * 6 *
6 * Sören Brinkmann <soren.brinkmann@xilinx.com> 7 * Sören Brinkmann <soren.brinkmann@xilinx.com>
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 v2 as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */ 8 */
20 9
21#include <linux/platform_device.h> 10#include <linux/platform_device.h>
diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h
index a1c1081906c5..c0bc413f7fe0 100644
--- a/drivers/staging/comedi/comedi.h
+++ b/drivers/staging/comedi/comedi.h
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: LGPL-2.0+
1/* 2/*
2 * comedi.h 3 * comedi.h
3 * header file for COMEDI user API 4 * header file for COMEDI user API
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1998-2001 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1998-2001 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#ifndef _COMEDI_H 10#ifndef _COMEDI_H
diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c
index b455ff6714eb..f693c2c0bec3 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_buf.c 3 * comedi_buf.c
3 * 4 *
4 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
6 * Copyright (C) 2002 Frank Mori Hess <fmhess@users.sourceforge.net> 7 * Copyright (C) 2002 Frank Mori Hess <fmhess@users.sourceforge.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/vmalloc.h> 10#include <linux/vmalloc.h>
diff --git a/drivers/staging/comedi/comedi_compat32.c b/drivers/staging/comedi/comedi_compat32.c
index f356386d833a..97fb9388bc22 100644
--- a/drivers/staging/comedi/comedi_compat32.c
+++ b/drivers/staging/comedi/comedi_compat32.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/comedi_compat32.c 3 * comedi/comedi_compat32.c
3 * 32-bit ioctl compatibility for 64-bit comedi kernel module. 4 * 32-bit ioctl compatibility for 64-bit comedi kernel module.
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 1997-2007 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 1997-2007 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22#include <linux/uaccess.h> 13#include <linux/uaccess.h>
diff --git a/drivers/staging/comedi/comedi_compat32.h b/drivers/staging/comedi/comedi_compat32.h
index 0127c1f98bbf..3980e6e1bd0d 100644
--- a/drivers/staging/comedi/comedi_compat32.h
+++ b/drivers/staging/comedi/comedi_compat32.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/comedi_compat32.h 3 * comedi/comedi_compat32.h
3 * 32-bit ioctl compatibility for 64-bit comedi kernel module. 4 * 32-bit ioctl compatibility for 64-bit comedi kernel module.
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 1997-2007 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 1997-2007 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22#ifndef _COMEDI_COMPAT32_H 13#ifndef _COMEDI_COMPAT32_H
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 491b54d986eb..ef733847eebe 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/comedi_fops.c 3 * comedi/comedi_fops.c
3 * comedi kernel module 4 * comedi kernel module
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
diff --git a/drivers/staging/comedi/comedi_pci.c b/drivers/staging/comedi/comedi_pci.c
index 51e023a1c0ee..126048b03f43 100644
--- a/drivers/staging/comedi/comedi_pci.c
+++ b/drivers/staging/comedi/comedi_pci.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_pci.c 3 * comedi_pci.c
3 * Comedi PCI driver specific functions. 4 * Comedi PCI driver specific functions.
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/module.h> 10#include <linux/module.h>
diff --git a/drivers/staging/comedi/comedi_pci.h b/drivers/staging/comedi/comedi_pci.h
index 7dfd892c74b0..647a72441b8a 100644
--- a/drivers/staging/comedi/comedi_pci.h
+++ b/drivers/staging/comedi/comedi_pci.h
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_pci.h 3 * comedi_pci.h
3 * header file for Comedi PCI drivers 4 * header file for Comedi PCI drivers
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#ifndef _COMEDI_PCI_H 10#ifndef _COMEDI_PCI_H
diff --git a/drivers/staging/comedi/comedi_pcmcia.c b/drivers/staging/comedi/comedi_pcmcia.c
index cd4742851c08..e16f35eae343 100644
--- a/drivers/staging/comedi/comedi_pcmcia.c
+++ b/drivers/staging/comedi/comedi_pcmcia.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_pcmcia.c 3 * comedi_pcmcia.c
3 * Comedi PCMCIA driver specific functions. 4 * Comedi PCMCIA driver specific functions.
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/module.h> 10#include <linux/module.h>
diff --git a/drivers/staging/comedi/comedi_pcmcia.h b/drivers/staging/comedi/comedi_pcmcia.h
index 9e45c7c93278..c7d37b38e730 100644
--- a/drivers/staging/comedi/comedi_pcmcia.h
+++ b/drivers/staging/comedi/comedi_pcmcia.h
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_pcmcia.h 3 * comedi_pcmcia.h
3 * header file for Comedi PCMCIA drivers 4 * header file for Comedi PCMCIA drivers
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#ifndef _COMEDI_PCMCIA_H 10#ifndef _COMEDI_PCMCIA_H
diff --git a/drivers/staging/comedi/comedi_usb.c b/drivers/staging/comedi/comedi_usb.c
index 9c946d40b894..c632c2bae722 100644
--- a/drivers/staging/comedi/comedi_usb.c
+++ b/drivers/staging/comedi/comedi_usb.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_usb.c 3 * comedi_usb.c
3 * Comedi USB driver specific functions. 4 * Comedi USB driver specific functions.
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/module.h> 10#include <linux/module.h>
diff --git a/drivers/staging/comedi/comedi_usb.h b/drivers/staging/comedi/comedi_usb.h
index 132154ec792f..50287de7a239 100644
--- a/drivers/staging/comedi/comedi_usb.h
+++ b/drivers/staging/comedi/comedi_usb.h
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_usb.h 3 * comedi_usb.h
3 * header file for USB Comedi drivers 4 * header file for USB Comedi drivers
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#ifndef _COMEDI_USB_H 10#ifndef _COMEDI_USB_H
diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
index 1bb9986f865e..f3474a4ba69e 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedidev.h 3 * comedidev.h
3 * header file for kernel-only structures, variables, and constants 4 * header file for kernel-only structures, variables, and constants
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#ifndef _COMEDIDEV_H 10#ifndef _COMEDIDEV_H
@@ -186,23 +177,27 @@ struct comedi_subdevice {
186 177
187 unsigned int *chanlist; /* driver-owned chanlist (not used) */ 178 unsigned int *chanlist; /* driver-owned chanlist (not used) */
188 179
189 int (*insn_read)(struct comedi_device *, struct comedi_subdevice *, 180 int (*insn_read)(struct comedi_device *dev, struct comedi_subdevice *s,
190 struct comedi_insn *, unsigned int *); 181 struct comedi_insn *insn, unsigned int *data);
191 int (*insn_write)(struct comedi_device *, struct comedi_subdevice *, 182 int (*insn_write)(struct comedi_device *dev, struct comedi_subdevice *s,
192 struct comedi_insn *, unsigned int *); 183 struct comedi_insn *insn, unsigned int *data);
193 int (*insn_bits)(struct comedi_device *, struct comedi_subdevice *, 184 int (*insn_bits)(struct comedi_device *dev, struct comedi_subdevice *s,
194 struct comedi_insn *, unsigned int *); 185 struct comedi_insn *insn, unsigned int *data);
195 int (*insn_config)(struct comedi_device *, struct comedi_subdevice *, 186 int (*insn_config)(struct comedi_device *dev,
196 struct comedi_insn *, unsigned int *); 187 struct comedi_subdevice *s,
197 188 struct comedi_insn *insn,
198 int (*do_cmd)(struct comedi_device *, struct comedi_subdevice *); 189 unsigned int *data);
199 int (*do_cmdtest)(struct comedi_device *, struct comedi_subdevice *, 190
200 struct comedi_cmd *); 191 int (*do_cmd)(struct comedi_device *dev, struct comedi_subdevice *s);
201 int (*poll)(struct comedi_device *, struct comedi_subdevice *); 192 int (*do_cmdtest)(struct comedi_device *dev,
202 int (*cancel)(struct comedi_device *, struct comedi_subdevice *); 193 struct comedi_subdevice *s,
194 struct comedi_cmd *cmd);
195 int (*poll)(struct comedi_device *dev, struct comedi_subdevice *s);
196 int (*cancel)(struct comedi_device *dev, struct comedi_subdevice *s);
203 197
204 /* called when the buffer changes */ 198 /* called when the buffer changes */
205 int (*buf_change)(struct comedi_device *, struct comedi_subdevice *); 199 int (*buf_change)(struct comedi_device *dev,
200 struct comedi_subdevice *s);
206 201
207 void (*munge)(struct comedi_device *dev, struct comedi_subdevice *s, 202 void (*munge)(struct comedi_device *dev, struct comedi_subdevice *s,
208 void *data, unsigned int num_bytes, 203 void *data, unsigned int num_bytes,
@@ -445,9 +440,9 @@ struct comedi_driver {
445 /* public: */ 440 /* public: */
446 const char *driver_name; 441 const char *driver_name;
447 struct module *module; 442 struct module *module;
448 int (*attach)(struct comedi_device *, struct comedi_devconfig *); 443 int (*attach)(struct comedi_device *dev, struct comedi_devconfig *it);
449 void (*detach)(struct comedi_device *); 444 void (*detach)(struct comedi_device *dev);
450 int (*auto_attach)(struct comedi_device *, unsigned long); 445 int (*auto_attach)(struct comedi_device *dev, unsigned long context);
451 unsigned int num_names; 446 unsigned int num_names;
452 const char *const *board_name; 447 const char *const *board_name;
453 int offset; 448 int offset;
diff --git a/drivers/staging/comedi/comedilib.h b/drivers/staging/comedi/comedilib.h
index f9b56396e161..e98cb9752dbc 100644
--- a/drivers/staging/comedi/comedilib.h
+++ b/drivers/staging/comedi/comedilib.h
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedilib.h 3 * comedilib.h
3 * Header file for kcomedilib 4 * Header file for kcomedilib
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1998-2001 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1998-2001 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#ifndef _LINUX_COMEDILIB_H 10#ifndef _LINUX_COMEDILIB_H
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 0b43db6371c6..e618a87521a3 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * module/drivers.c 3 * module/drivers.c
3 * functions for manipulating drivers 4 * functions for manipulating drivers
@@ -5,16 +6,6 @@
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 * Copyright (C) 2002 Frank Mori Hess <fmhess@users.sourceforge.net> 8 * Copyright (C) 2002 Frank Mori Hess <fmhess@users.sourceforge.net>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20#include <linux/device.h> 11#include <linux/device.h>
diff --git a/drivers/staging/comedi/drivers/8255.c b/drivers/staging/comedi/drivers/8255.c
index b79d3764a8a0..3d6105b5a11b 100644
--- a/drivers/staging/comedi/drivers/8255.c
+++ b/drivers/staging/comedi/drivers/8255.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/8255.c 3 * comedi/drivers/8255.c
3 * Driver for 8255 4 * Driver for 8255
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/8255.h b/drivers/staging/comedi/drivers/8255.h
index 55a67af5152d..6cd1339ab83e 100644
--- a/drivers/staging/comedi/drivers/8255.h
+++ b/drivers/staging/comedi/drivers/8255.h
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * module/8255.h 3 * module/8255.h
3 * Header file for 8255 4 * Header file for 8255
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#ifndef _8255_H 10#ifndef _8255_H
diff --git a/drivers/staging/comedi/drivers/8255_pci.c b/drivers/staging/comedi/drivers/8255_pci.c
index 38c05d1ec647..9ed05f962fdb 100644
--- a/drivers/staging/comedi/drivers/8255_pci.c
+++ b/drivers/staging/comedi/drivers/8255_pci.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * COMEDI driver for generic PCI based 8255 digital i/o boards 3 * COMEDI driver for generic PCI based 8255 digital i/o boards
3 * Copyright (C) 2012 H Hartley Sweeten <hsweeten@visionengravers.com> 4 * Copyright (C) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
@@ -9,16 +10,6 @@
9 * 10 *
10 * COMEDI - Linux Control and Measurement Device Interface 11 * COMEDI - Linux Control and Measurement Device Interface
11 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 12 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 */ 13 */
23 14
24/* 15/*
diff --git a/drivers/staging/comedi/drivers/addi_apci_1032.c b/drivers/staging/comedi/drivers/addi_apci_1032.c
index ccd1a91290bf..560649be9d13 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1032.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1032.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * addi_apci_1032.c 3 * addi_apci_1032.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. 4 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
@@ -10,16 +11,6 @@
10 * Fax: +49(0)7223/9493-92 11 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com 12 * http://www.addi-data.com
12 * info@addi-data.com 13 * info@addi-data.com
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 */ 14 */
24 15
25/* 16/*
diff --git a/drivers/staging/comedi/drivers/addi_apci_1500.c b/drivers/staging/comedi/drivers/addi_apci_1500.c
index 63991c49ff23..45ad4ba92f94 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1500.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1500.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * addi_apci_1500.c 3 * addi_apci_1500.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. 4 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
@@ -9,16 +10,6 @@
9 * Fax: +49(0)7223/9493-92 10 * Fax: +49(0)7223/9493-92
10 * http://www.addi-data.com 11 * http://www.addi-data.com
11 * info@addi-data.com 12 * info@addi-data.com
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 * more details.
22 */ 13 */
23 14
24#include <linux/module.h> 15#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/addi_apci_1516.c b/drivers/staging/comedi/drivers/addi_apci_1516.c
index f1f8b1c422a7..6c8213ee1a74 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1516.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1516.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * addi_apci_1516.c 3 * addi_apci_1516.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. 4 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
@@ -10,16 +11,6 @@
10 * Fax: +49(0)7223/9493-92 11 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com 12 * http://www.addi-data.com
12 * info@addi-data.com 13 * info@addi-data.com
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 */ 14 */
24 15
25#include <linux/module.h> 16#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/addi_apci_1564.c b/drivers/staging/comedi/drivers/addi_apci_1564.c
index 9bfb79c2e5c8..10501fe6bb25 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1564.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1564.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * addi_apci_1564.c 3 * addi_apci_1564.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. 4 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
@@ -9,16 +10,6 @@
9 * Fax: +49(0)7223/9493-92 10 * Fax: +49(0)7223/9493-92
10 * http://www.addi-data.com 11 * http://www.addi-data.com
11 * info@addi-data.com 12 * info@addi-data.com
12 *
13 * This program is free software; you can redistribute it and/or modify it under
14 * the terms of the GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the License, or (at your option) any later
16 * version.
17 *
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * details.
22 */ 13 */
23 14
24/* 15/*
diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c
index c63133a12a4e..050d0b4b3209 100644
--- a/drivers/staging/comedi/drivers/addi_apci_16xx.c
+++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * addi_apci_16xx.c 3 * addi_apci_16xx.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. 4 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
@@ -10,16 +11,6 @@
10 * Fax: +49(0)7223/9493-92 11 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com 12 * http://www.addi-data.com
12 * info@addi-data.com 13 * info@addi-data.com
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 */ 14 */
24 15
25#include <linux/module.h> 16#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c
index 50f9eb25d7cb..a122f3f3f5ec 100644
--- a/drivers/staging/comedi/drivers/addi_apci_2032.c
+++ b/drivers/staging/comedi/drivers/addi_apci_2032.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * addi_apci_2032.c 3 * addi_apci_2032.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. 4 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
@@ -10,16 +11,6 @@
10 * Fax: +49(0)7223/9493-92 11 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com 12 * http://www.addi-data.com
12 * info@addi-data.com 13 * info@addi-data.com
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 */ 14 */
24 15
25#include <linux/module.h> 16#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c
index 2b382a52d80d..140d1514a106 100644
--- a/drivers/staging/comedi/drivers/addi_apci_2200.c
+++ b/drivers/staging/comedi/drivers/addi_apci_2200.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * addi_apci_2200.c 3 * addi_apci_2200.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. 4 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
@@ -10,16 +11,6 @@
10 * Fax: +49(0)7223/9493-92 11 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com 12 * http://www.addi-data.com
12 * info@addi-data.com 13 * info@addi-data.com
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 */ 14 */
24 15
25#include <linux/module.h> 16#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/addi_apci_3120.c b/drivers/staging/comedi/drivers/addi_apci_3120.c
index 3630d75e36e8..d2810fdd5e63 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3120.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3120.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * addi_apci_3120.c 3 * addi_apci_3120.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. 4 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
@@ -9,16 +10,6 @@
9 * Fax: +49(0)7223/9493-92 10 * Fax: +49(0)7223/9493-92
10 * http://www.addi-data.com 11 * http://www.addi-data.com
11 * info@addi-data.com 12 * info@addi-data.com
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 * more details.
22 */ 13 */
23 14
24#include <linux/module.h> 15#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c
index 1fdc0f8d7e1a..a38267928e5e 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3501.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3501.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * addi_apci_3501.c 3 * addi_apci_3501.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. 4 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
@@ -10,16 +11,6 @@
10 * Fax: +49(0)7223/9493-92 11 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com 12 * http://www.addi-data.com
12 * info@addi-data.com 13 * info@addi-data.com
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 */ 14 */
24 15
25/* 16/*
diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
index be1f6133ff1c..55784f24e2a7 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * addi_apci_3xxx.c 3 * addi_apci_3xxx.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. 4 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
@@ -10,16 +11,6 @@
10 * Fax: +49(0)7223/9493-92 11 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com 12 * http://www.addi-data.com
12 * info@addi-data.com 13 * info@addi-data.com
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 */ 14 */
24 15
25#include <linux/module.h> 16#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/addi_watchdog.c b/drivers/staging/comedi/drivers/addi_watchdog.c
index 9d9853fe54a0..69b323fb869f 100644
--- a/drivers/staging/comedi/drivers/addi_watchdog.c
+++ b/drivers/staging/comedi/drivers/addi_watchdog.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * COMEDI driver for the watchdog subdevice found on some addi-data boards 3 * COMEDI driver for the watchdog subdevice found on some addi-data boards
3 * Copyright (c) 2013 H Hartley Sweeten <hsweeten@visionengravers.com> 4 * Copyright (c) 2013 H Hartley Sweeten <hsweeten@visionengravers.com>
@@ -6,16 +7,6 @@
6 * 7 *
7 * COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 9 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21#include <linux/module.h> 12#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c b/drivers/staging/comedi/drivers/adl_pci6208.c
index ad7e7c4a5232..d39b4eabce8d 100644
--- a/drivers/staging/comedi/drivers/adl_pci6208.c
+++ b/drivers/staging/comedi/drivers/adl_pci6208.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * adl_pci6208.c 3 * adl_pci6208.c
3 * Comedi driver for ADLink 6208 series cards 4 * Comedi driver for ADLink 6208 series cards
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/adl_pci7x3x.c b/drivers/staging/comedi/drivers/adl_pci7x3x.c
index b0fc027cf485..d0081897fe47 100644
--- a/drivers/staging/comedi/drivers/adl_pci7x3x.c
+++ b/drivers/staging/comedi/drivers/adl_pci7x3x.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * COMEDI driver for the ADLINK PCI-723x/743x series boards. 3 * COMEDI driver for the ADLINK PCI-723x/743x series boards.
3 * Copyright (C) 2012 H Hartley Sweeten <hsweeten@visionengravers.com> 4 * Copyright (C) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
@@ -9,16 +10,6 @@
9 * 10 *
10 * COMEDI - Linux Control and Measurement Device Interface 11 * COMEDI - Linux Control and Measurement Device Interface
11 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 12 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 */ 13 */
23 14
24/* 15/*
diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c b/drivers/staging/comedi/drivers/adl_pci8164.c
index da901c8dec0e..3022793b1bc5 100644
--- a/drivers/staging/comedi/drivers/adl_pci8164.c
+++ b/drivers/staging/comedi/drivers/adl_pci8164.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/adl_pci8164.c 3 * comedi/drivers/adl_pci8164.c
3 * 4 *
4 * Hardware comedi driver for PCI-8164 Adlink card 5 * Hardware comedi driver for PCI-8164 Adlink card
5 * Copyright (C) 2004 Michel Lachine <mike@mikelachaine.ca> 6 * Copyright (C) 2004 Michel Lachine <mike@mikelachaine.ca>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18/* 9/*
diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c
index 01d2ee931b28..f4dba6271d0d 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * adl_pci9111.c 3 * adl_pci9111.c
3 * Hardware driver for PCI9111 ADLink cards: PCI-9111HR 4 * Hardware driver for PCI9111 ADLink cards: PCI-9111HR
4 * Copyright (C) 2002-2005 Emmanuel Pacaud <emmanuel.pacaud@univ-poitiers.fr> 5 * Copyright (C) 2002-2005 Emmanuel Pacaud <emmanuel.pacaud@univ-poitiers.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17/* 8/*
diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c
index 1cc9b7ef1ff9..2528ca0ede6d 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * comedi/drivers/adl_pci9118.c 3 * comedi/drivers/adl_pci9118.c
3 * 4 *
diff --git a/drivers/staging/comedi/drivers/adq12b.c b/drivers/staging/comedi/drivers/adq12b.c
index 315050454c26..5d431573bcca 100644
--- a/drivers/staging/comedi/drivers/adq12b.c
+++ b/drivers/staging/comedi/drivers/adq12b.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * adq12b.c 3 * adq12b.c
3 * Driver for MicroAxial ADQ12-B data acquisition and control card 4 * Driver for MicroAxial ADQ12-B data acquisition and control card
@@ -9,16 +10,6 @@
9 * 10 *
10 * COMEDI - Linux Control and Measurement Device Interface 11 * COMEDI - Linux Control and Measurement Device Interface
11 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 12 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 */ 13 */
23 14
24/* 15/*
diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c
index 2c1b6de30da8..6a93b04f1fdf 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * adv_pci1710.c 3 * adv_pci1710.c
3 * Comedi driver for Advantech PCI-1710 series boards 4 * Comedi driver for Advantech PCI-1710 series boards
diff --git a/drivers/staging/comedi/drivers/adv_pci1720.c b/drivers/staging/comedi/drivers/adv_pci1720.c
index 4830a1c93d15..2fcd7e8e7d85 100644
--- a/drivers/staging/comedi/drivers/adv_pci1720.c
+++ b/drivers/staging/comedi/drivers/adv_pci1720.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * COMEDI driver for Advantech PCI-1720U 3 * COMEDI driver for Advantech PCI-1720U
3 * Copyright (c) 2015 H Hartley Sweeten <hsweeten@visionengravers.com> 4 * Copyright (c) 2015 H Hartley Sweeten <hsweeten@visionengravers.com>
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c b/drivers/staging/comedi/drivers/adv_pci1723.c
index f82afd947310..771d61f87427 100644
--- a/drivers/staging/comedi/drivers/adv_pci1723.c
+++ b/drivers/staging/comedi/drivers/adv_pci1723.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * adv_pci1723.c 3 * adv_pci1723.c
3 * Comedi driver for the Advantech PCI-1723 card. 4 * Comedi driver for the Advantech PCI-1723 card.
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/adv_pci1724.c b/drivers/staging/comedi/drivers/adv_pci1724.c
index bf6a8f10118c..e8ab573c839f 100644
--- a/drivers/staging/comedi/drivers/adv_pci1724.c
+++ b/drivers/staging/comedi/drivers/adv_pci1724.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * adv_pci1724.c 3 * adv_pci1724.c
3 * Comedi driver for the Advantech PCI-1724U card. 4 * Comedi driver for the Advantech PCI-1724U card.
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
diff --git a/drivers/staging/comedi/drivers/adv_pci1760.c b/drivers/staging/comedi/drivers/adv_pci1760.c
index 9f525ff7290c..f460f21efb90 100644
--- a/drivers/staging/comedi/drivers/adv_pci1760.c
+++ b/drivers/staging/comedi/drivers/adv_pci1760.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * COMEDI driver for the Advantech PCI-1760 3 * COMEDI driver for the Advantech PCI-1760
3 * Copyright (C) 2015 H Hartley Sweeten <hsweeten@visionengravers.com> 4 * Copyright (C) 2015 H Hartley Sweeten <hsweeten@visionengravers.com>
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
@@ -69,7 +60,7 @@
69#define PCI1760_CMD_SET_DO 0x01 /* Set output state */ 60#define PCI1760_CMD_SET_DO 0x01 /* Set output state */
70#define PCI1760_CMD_GET_DO 0x02 /* Read output status */ 61#define PCI1760_CMD_GET_DO 0x02 /* Read output status */
71#define PCI1760_CMD_GET_STATUS 0x03 /* Read current status */ 62#define PCI1760_CMD_GET_STATUS 0x03 /* Read current status */
72#define PCI1760_CMD_GET_FW_VER 0x0e /* Read firware version */ 63#define PCI1760_CMD_GET_FW_VER 0x0e /* Read firmware version */
73#define PCI1760_CMD_GET_HW_VER 0x0f /* Read hardware version */ 64#define PCI1760_CMD_GET_HW_VER 0x0f /* Read hardware version */
74#define PCI1760_CMD_SET_PWM_HI(x) (0x10 + (x) * 2) /* Set "hi" period */ 65#define PCI1760_CMD_SET_PWM_HI(x) (0x10 + (x) * 2) /* Set "hi" period */
75#define PCI1760_CMD_SET_PWM_LO(x) (0x11 + (x) * 2) /* Set "lo" period */ 66#define PCI1760_CMD_SET_PWM_LO(x) (0x11 + (x) * 2) /* Set "lo" period */
diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c b/drivers/staging/comedi/drivers/adv_pci_dio.c
index a8186687ca2c..5fef2aef7e03 100644
--- a/drivers/staging/comedi/drivers/adv_pci_dio.c
+++ b/drivers/staging/comedi/drivers/adv_pci_dio.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * comedi/drivers/adv_pci_dio.c 3 * comedi/drivers/adv_pci_dio.c
3 * 4 *
diff --git a/drivers/staging/comedi/drivers/aio_aio12_8.c b/drivers/staging/comedi/drivers/aio_aio12_8.c
index 43a0ce5721d3..f4beda1ed640 100644
--- a/drivers/staging/comedi/drivers/aio_aio12_8.c
+++ b/drivers/staging/comedi/drivers/aio_aio12_8.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * aio_aio12_8.c 3 * aio_aio12_8.c
3 * Driver for Access I/O Products PC-104 AIO12-8 Analog I/O Board 4 * Driver for Access I/O Products PC-104 AIO12-8 Analog I/O Board
4 * Copyright (C) 2006 C&C Technologies, Inc. 5 * Copyright (C) 2006 C&C Technologies, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17/* 8/*
diff --git a/drivers/staging/comedi/drivers/aio_iiro_16.c b/drivers/staging/comedi/drivers/aio_iiro_16.c
index 35b2f98f0de9..41c9c56816ef 100644
--- a/drivers/staging/comedi/drivers/aio_iiro_16.c
+++ b/drivers/staging/comedi/drivers/aio_iiro_16.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * aio_iiro_16.c 3 * aio_iiro_16.c
3 * Comedi driver for Access I/O Products 104-IIRO-16 board 4 * Comedi driver for Access I/O Products 104-IIRO-16 board
4 * Copyright (C) 2006 C&C Technologies, Inc. 5 * Copyright (C) 2006 C&C Technologies, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17/* 8/*
diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c b/drivers/staging/comedi/drivers/amplc_dio200.c
index f5cfa71a90c6..26e63d64ffc6 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/amplc_dio200.c 3 * comedi/drivers/amplc_dio200.c
3 * 4 *
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
diff --git a/drivers/staging/comedi/drivers/amplc_dio200.h b/drivers/staging/comedi/drivers/amplc_dio200.h
index 53fb86d59fc3..88c1d1063d5d 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200.h
+++ b/drivers/staging/comedi/drivers/amplc_dio200.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/amplc_dio.h 3 * comedi/drivers/amplc_dio.h
3 * 4 *
@@ -8,16 +9,6 @@
8 * 9 *
9 * COMEDI - Linux Control and Measurement Device Interface 10 * COMEDI - Linux Control and Measurement Device Interface
10 * Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org> 11 * Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
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 */ 12 */
22 13
23#ifndef AMPLC_DIO200_H_INCLUDED 14#ifndef AMPLC_DIO200_H_INCLUDED
diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c
index f6e4e984235d..82bd41d92509 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200_common.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200_common.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/amplc_dio200_common.c 3 * comedi/drivers/amplc_dio200_common.c
3 * 4 *
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22#include <linux/module.h> 13#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/amplc_dio200_pci.c b/drivers/staging/comedi/drivers/amplc_dio200_pci.c
index 2598e6e7d47d..30d239731e0b 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200_pci.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200_pci.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* comedi/drivers/amplc_dio200_pci.c 2/* comedi/drivers/amplc_dio200_pci.c
2 * 3 *
3 * Driver for Amplicon PCI215, PCI272, PCIe215, PCIe236, PCIe296. 4 * Driver for Amplicon PCI215, PCI272, PCIe215, PCIe236, PCIe296.
@@ -6,16 +7,6 @@
6 * 7 *
7 * COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org> 9 * Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21/* 12/*
diff --git a/drivers/staging/comedi/drivers/amplc_pc236.c b/drivers/staging/comedi/drivers/amplc_pc236.c
index 875cc19cb969..b7dd15f5ec63 100644
--- a/drivers/staging/comedi/drivers/amplc_pc236.c
+++ b/drivers/staging/comedi/drivers/amplc_pc236.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/amplc_pc236.c 3 * comedi/drivers/amplc_pc236.c
3 * Driver for Amplicon PC36AT DIO boards. 4 * Driver for Amplicon PC36AT DIO boards.
@@ -6,16 +7,6 @@
6 * 7 *
7 * COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 9 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20/* 11/*
21 * Driver: amplc_pc236 12 * Driver: amplc_pc236
diff --git a/drivers/staging/comedi/drivers/amplc_pc236.h b/drivers/staging/comedi/drivers/amplc_pc236.h
index 91d6d9c065b5..4b67090aab54 100644
--- a/drivers/staging/comedi/drivers/amplc_pc236.h
+++ b/drivers/staging/comedi/drivers/amplc_pc236.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/amplc_pc236.h 3 * comedi/drivers/amplc_pc236.h
3 * Header for "amplc_pc236", "amplc_pci236" and "amplc_pc236_common". 4 * Header for "amplc_pc236", "amplc_pci236" and "amplc_pc236_common".
@@ -6,16 +7,6 @@
6 * 7 *
7 * COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 9 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21#ifndef AMPLC_PC236_H_INCLUDED 12#ifndef AMPLC_PC236_H_INCLUDED
diff --git a/drivers/staging/comedi/drivers/amplc_pc236_common.c b/drivers/staging/comedi/drivers/amplc_pc236_common.c
index 0c02d3245679..01b90e4eca8a 100644
--- a/drivers/staging/comedi/drivers/amplc_pc236_common.c
+++ b/drivers/staging/comedi/drivers/amplc_pc236_common.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/amplc_pc236_common.c 3 * comedi/drivers/amplc_pc236_common.c
3 * Common support code for "amplc_pc236" and "amplc_pci236". 4 * Common support code for "amplc_pc236" and "amplc_pci236".
@@ -6,16 +7,6 @@
6 * 7 *
7 * COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 9 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21#include <linux/module.h> 12#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/amplc_pc263.c b/drivers/staging/comedi/drivers/amplc_pc263.c
index 58b0b6b1a693..84c989f12faf 100644
--- a/drivers/staging/comedi/drivers/amplc_pc263.c
+++ b/drivers/staging/comedi/drivers/amplc_pc263.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Driver for Amplicon PC263 relay board. 3 * Driver for Amplicon PC263 relay board.
3 * 4 *
@@ -5,16 +6,6 @@
5 * 6 *
6 * COMEDI - Linux Control and Measurement Device Interface 7 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20/* 11/*
diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c
index 4e554944bc71..657b736ef46d 100644
--- a/drivers/staging/comedi/drivers/amplc_pci224.c
+++ b/drivers/staging/comedi/drivers/amplc_pci224.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/amplc_pci224.c 3 * comedi/drivers/amplc_pci224.c
3 * Driver for Amplicon PCI224 and PCI234 AO boards. 4 * Driver for Amplicon PCI224 and PCI234 AO boards.
@@ -6,16 +7,6 @@
6 * 7 *
7 * COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org> 9 * Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21/* 12/*
diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c
index 48c7890c3007..15fc7f19051a 100644
--- a/drivers/staging/comedi/drivers/amplc_pci230.c
+++ b/drivers/staging/comedi/drivers/amplc_pci230.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/amplc_pci230.c 3 * comedi/drivers/amplc_pci230.c
3 * Driver for Amplicon PCI230 and PCI260 Multifunction I/O boards. 4 * Driver for Amplicon PCI230 and PCI260 Multifunction I/O boards.
@@ -6,16 +7,6 @@
6 * 7 *
7 * COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 9 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21/* 12/*
diff --git a/drivers/staging/comedi/drivers/amplc_pci236.c b/drivers/staging/comedi/drivers/amplc_pci236.c
index 31cc38b4bcad..86ea876a11be 100644
--- a/drivers/staging/comedi/drivers/amplc_pci236.c
+++ b/drivers/staging/comedi/drivers/amplc_pci236.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/amplc_pci236.c 3 * comedi/drivers/amplc_pci236.c
3 * Driver for Amplicon PCI236 DIO boards. 4 * Driver for Amplicon PCI236 DIO boards.
@@ -6,16 +7,6 @@
6 * 7 *
7 * COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 9 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20/* 11/*
21 * Driver: amplc_pci236 12 * Driver: amplc_pci236
diff --git a/drivers/staging/comedi/drivers/amplc_pci263.c b/drivers/staging/comedi/drivers/amplc_pci263.c
index 8d4069bc5716..c3efe14020a8 100644
--- a/drivers/staging/comedi/drivers/amplc_pci263.c
+++ b/drivers/staging/comedi/drivers/amplc_pci263.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Driver for Amplicon PCI263 relay board. 3 * Driver for Amplicon PCI263 relay board.
3 * 4 *
@@ -5,16 +6,6 @@
5 * 6 *
6 * COMEDI - Linux Control and Measurement Device Interface 7 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20/* 11/*
diff --git a/drivers/staging/comedi/drivers/c6xdigio.c b/drivers/staging/comedi/drivers/c6xdigio.c
index 8ee732571588..41cc784320a9 100644
--- a/drivers/staging/comedi/drivers/c6xdigio.c
+++ b/drivers/staging/comedi/drivers/c6xdigio.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * c6xdigio.c 3 * c6xdigio.c
3 * Hardware driver for Mechatronic Systems Inc. C6x_DIGIO DSP daughter card. 4 * Hardware driver for Mechatronic Systems Inc. C6x_DIGIO DSP daughter card.
@@ -5,16 +6,6 @@
5 * 6 *
6 * COMEDI - Linux Control and Measurement Device Interface 7 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 1999 Dan Block 8 * Copyright (C) 1999 Dan Block
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20/* 11/*
diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c
index 78d098f9e1f2..a5d171e71c33 100644
--- a/drivers/staging/comedi/drivers/cb_das16_cs.c
+++ b/drivers/staging/comedi/drivers/cb_das16_cs.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * cb_das16_cs.c 3 * cb_das16_cs.c
3 * Driver for Computer Boards PC-CARD DAS16/16. 4 * Driver for Computer Boards PC-CARD DAS16/16.
@@ -5,16 +6,6 @@
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000, 2001, 2002 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000, 2001, 2002 David A. Schleef <ds@schleef.org>
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * PCMCIA support code for this driver is adapted from the dummy_cs.c 9 * PCMCIA support code for this driver is adapted from the dummy_cs.c
19 * driver of the Linux PCMCIA Card Services package. 10 * driver of the Linux PCMCIA Card Services package.
20 * 11 *
diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c
index 3cd008acb657..8429d57087fd 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * cb_pcidas.c 3 * cb_pcidas.c
3 * Developed by Ivan Martinez and Frank Mori Hess, with valuable help from 4 * Developed by Ivan Martinez and Frank Mori Hess, with valuable help from
@@ -8,16 +9,6 @@
8 * 9 *
9 * COMEDI - Linux Control and Measurement Device Interface 10 * COMEDI - Linux Control and Measurement Device Interface
10 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org> 11 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
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 */ 12 */
22 13
23/* 14/*
diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c
index b761f000c1dc..b657beedd5ff 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/cb_pcidas64.c 3 * comedi/drivers/cb_pcidas64.c
3 * This is a driver for the ComputerBoards/MeasurementComputing PCI-DAS 4 * This is a driver for the ComputerBoards/MeasurementComputing PCI-DAS
@@ -18,16 +19,6 @@
18 * 19 *
19 * COMEDI - Linux Control and Measurement Device Interface 20 * COMEDI - Linux Control and Measurement Device Interface
20 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org> 21 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
21 *
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 */ 22 */
32 23
33/* 24/*
diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c b/drivers/staging/comedi/drivers/cb_pcidda.c
index 987414741605..807a31e75883 100644
--- a/drivers/staging/comedi/drivers/cb_pcidda.c
+++ b/drivers/staging/comedi/drivers/cb_pcidda.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/cb_pcidda.c 3 * comedi/drivers/cb_pcidda.c
3 * Driver for the ComputerBoards / MeasurementComputing PCI-DDA series. 4 * Driver for the ComputerBoards / MeasurementComputing PCI-DDA series.
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 47e38398921e..4e72a0778086 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/cb_pcimdas.c 3 * comedi/drivers/cb_pcimdas.c
3 * Comedi driver for Computer Boards PCIM-DAS1602/16 and PCIe-DAS1602/16 4 * Comedi driver for Computer Boards PCIM-DAS1602/16 and PCIe-DAS1602/16
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/cb_pcimdda.c b/drivers/staging/comedi/drivers/cb_pcimdda.c
index 84ef45457c60..b33203f6a990 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdda.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdda.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/cb_pcimdda.c 3 * comedi/drivers/cb_pcimdda.c
3 * Computer Boards PCIM-DDA06-16 Comedi driver 4 * Computer Boards PCIM-DDA06-16 Comedi driver
@@ -5,16 +6,6 @@
5 * 6 *
6 * COMEDI - Linux Control and Measurement Device Interface 7 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19/* 10/*
20 * Driver: cb_pcimdda 11 * Driver: cb_pcimdda
diff --git a/drivers/staging/comedi/drivers/comedi_8254.c b/drivers/staging/comedi/drivers/comedi_8254.c
index 0d5d56b61f60..d1d509e9add9 100644
--- a/drivers/staging/comedi/drivers/comedi_8254.c
+++ b/drivers/staging/comedi/drivers/comedi_8254.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_8254.c 3 * comedi_8254.c
3 * Generic 8254 timer/counter support 4 * Generic 8254 timer/counter support
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
diff --git a/drivers/staging/comedi/drivers/comedi_8254.h b/drivers/staging/comedi/drivers/comedi_8254.h
index 326bd44b063e..7faa2185282e 100644
--- a/drivers/staging/comedi/drivers/comedi_8254.h
+++ b/drivers/staging/comedi/drivers/comedi_8254.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_8254.h 3 * comedi_8254.h
3 * Generic 8254 timer/counter support 4 * Generic 8254 timer/counter support
@@ -5,16 +6,6 @@
5 * 6 *
6 * COMEDI - Linux Control and Measurement Device Interface 7 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20#ifndef _COMEDI_8254_H 11#ifndef _COMEDI_8254_H
diff --git a/drivers/staging/comedi/drivers/comedi_8255.c b/drivers/staging/comedi/drivers/comedi_8255.c
index b2441efc61cc..62baa0d79302 100644
--- a/drivers/staging/comedi/drivers/comedi_8255.c
+++ b/drivers/staging/comedi/drivers/comedi_8255.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_8255.c 3 * comedi_8255.c
3 * Generic 8255 digital I/O support 4 * Generic 8255 digital I/O support
@@ -6,16 +7,6 @@
6 * 7 *
7 * COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 9 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21/* 12/*
diff --git a/drivers/staging/comedi/drivers/comedi_bond.c b/drivers/staging/comedi/drivers/comedi_bond.c
index 64a5ea3810d4..4392b5927a99 100644
--- a/drivers/staging/comedi/drivers/comedi_bond.c
+++ b/drivers/staging/comedi/drivers/comedi_bond.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_bond.c 3 * comedi_bond.c
3 * A Comedi driver to 'bond' or merge multiple drivers and devices as one. 4 * A Comedi driver to 'bond' or merge multiple drivers and devices as one.
@@ -5,16 +6,6 @@
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 * Copyright (C) 2005 Calin A. Culianu <calin@ajvar.org> 8 * Copyright (C) 2005 Calin A. Culianu <calin@ajvar.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20/* 11/*
diff --git a/drivers/staging/comedi/drivers/comedi_isadma.c b/drivers/staging/comedi/drivers/comedi_isadma.c
index 68ef9b1750be..b77dc8d5d3ff 100644
--- a/drivers/staging/comedi/drivers/comedi_isadma.c
+++ b/drivers/staging/comedi/drivers/comedi_isadma.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * COMEDI ISA DMA support functions 3 * COMEDI ISA DMA support functions
3 * Copyright (c) 2014 H Hartley Sweeten <hsweeten@visionengravers.com> 4 * Copyright (c) 2014 H Hartley Sweeten <hsweeten@visionengravers.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 */ 5 */
15 6
16#include <linux/module.h> 7#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/comedi_isadma.h b/drivers/staging/comedi/drivers/comedi_isadma.h
index a193d3e8d185..ccef7c9c0a4d 100644
--- a/drivers/staging/comedi/drivers/comedi_isadma.h
+++ b/drivers/staging/comedi/drivers/comedi_isadma.h
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * COMEDI ISA DMA support functions 3 * COMEDI ISA DMA support functions
3 * Copyright (c) 2014 H Hartley Sweeten <hsweeten@visionengravers.com> 4 * Copyright (c) 2014 H Hartley Sweeten <hsweeten@visionengravers.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 */ 5 */
15 6
16#ifndef _COMEDI_ISADMA_H 7#ifndef _COMEDI_ISADMA_H
diff --git a/drivers/staging/comedi/drivers/comedi_parport.c b/drivers/staging/comedi/drivers/comedi_parport.c
index 1bf8ddc6f07c..efaa57372aeb 100644
--- a/drivers/staging/comedi/drivers/comedi_parport.c
+++ b/drivers/staging/comedi/drivers/comedi_parport.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi_parport.c 3 * comedi_parport.c
3 * Comedi driver for standard parallel port 4 * Comedi driver for standard parallel port
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 1998,2001 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 1998,2001 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
index c7e8194984e5..d437af721bd8 100644
--- a/drivers/staging/comedi/drivers/comedi_test.c
+++ b/drivers/staging/comedi/drivers/comedi_test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/comedi_test.c 3 * comedi/drivers/comedi_test.c
3 * 4 *
@@ -11,16 +12,6 @@
11 * 12 *
12 * COMEDI - Linux Control and Measurement Device Interface 13 * COMEDI - Linux Control and Measurement Device Interface
13 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 14 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 */ 15 */
25 16
26/* 17/*
diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c b/drivers/staging/comedi/drivers/contec_pci_dio.c
index 5f848396c2f7..49be795b4971 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/contec_pci_dio.c 3 * comedi/drivers/contec_pci_dio.c
3 * 4 *
4 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18/* 9/*
diff --git a/drivers/staging/comedi/drivers/dac02.c b/drivers/staging/comedi/drivers/dac02.c
index a562df498b01..5ef8114c2c85 100644
--- a/drivers/staging/comedi/drivers/dac02.c
+++ b/drivers/staging/comedi/drivers/dac02.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * dac02.c 3 * dac02.c
3 * Comedi driver for DAC02 compatible boards 4 * Comedi driver for DAC02 compatible boards
@@ -9,16 +10,6 @@
9 * 10 *
10 * COMEDI - Linux Control and Measurement Device Interface 11 * COMEDI - Linux Control and Measurement Device Interface
11 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 12 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 */ 13 */
23 14
24/* 15/*
diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c
index 32dd8a857b6b..03f98b0287c8 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/daqboard2000.c 3 * comedi/drivers/daqboard2000.c
3 * hardware driver for IOtech DAQboard/2000 4 * hardware driver for IOtech DAQboard/2000
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se> 7 * Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18/* 9/*
19 * Driver: daqboard2000 10 * Driver: daqboard2000
diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c
index 3d8fc6ad44df..327ecf9aea30 100644
--- a/drivers/staging/comedi/drivers/das08.c
+++ b/drivers/staging/comedi/drivers/das08.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/das08.c 3 * comedi/drivers/das08.c
3 * comedi module for common DAS08 support (used by ISA/PCI/PCMCIA drivers) 4 * comedi module for common DAS08 support (used by ISA/PCI/PCMCIA drivers)
@@ -6,16 +7,6 @@
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 * Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net> 8 * Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net>
8 * Copyright (C) 2004 Salvador E. Tropea <set@users.sf.net> <set@ieee.org> 9 * Copyright (C) 2004 Salvador E. Tropea <set@users.sf.net> <set@ieee.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21#include <linux/module.h> 12#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/das08.h b/drivers/staging/comedi/drivers/das08.h
index d27044cb7158..235d32f7c817 100644
--- a/drivers/staging/comedi/drivers/das08.h
+++ b/drivers/staging/comedi/drivers/das08.h
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * das08.h 3 * das08.h
3 * 4 *
4 * Header for common DAS08 support (used by ISA/PCI/PCMCIA drivers) 5 * Header for common DAS08 support (used by ISA/PCI/PCMCIA drivers)
5 * 6 *
6 * Copyright (C) 2003 Frank Mori Hess <fmhess@users.sourceforge.net> 7 * Copyright (C) 2003 Frank Mori Hess <fmhess@users.sourceforge.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#ifndef _DAS08_H 10#ifndef _DAS08_H
diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c
index 317a9b5e4a3b..223479f9ea3c 100644
--- a/drivers/staging/comedi/drivers/das08_cs.c
+++ b/drivers/staging/comedi/drivers/das08_cs.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for DAS008 PCMCIA boards 3 * Comedi driver for DAS008 PCMCIA boards
3 * 4 *
@@ -5,16 +6,6 @@
5 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
6 * Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net> 7 * Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net>
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * PCMCIA support code for this driver is adapted from the dummy_cs.c 9 * PCMCIA support code for this driver is adapted from the dummy_cs.c
19 * driver of the Linux PCMCIA Card Services package. 10 * driver of the Linux PCMCIA Card Services package.
20 * 11 *
diff --git a/drivers/staging/comedi/drivers/das08_isa.c b/drivers/staging/comedi/drivers/das08_isa.c
index cdefc99b6db3..b22a45bd21d1 100644
--- a/drivers/staging/comedi/drivers/das08_isa.c
+++ b/drivers/staging/comedi/drivers/das08_isa.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * das08_isa.c 3 * das08_isa.c
3 * comedi driver for DAS08 ISA/PC-104 boards 4 * comedi driver for DAS08 ISA/PC-104 boards
@@ -6,16 +7,6 @@
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 * Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net> 8 * Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net>
8 * Copyright (C) 2004 Salvador E. Tropea <set@users.sf.net> <set@ieee.org> 9 * Copyright (C) 2004 Salvador E. Tropea <set@users.sf.net> <set@ieee.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21/* 12/*
diff --git a/drivers/staging/comedi/drivers/das08_pci.c b/drivers/staging/comedi/drivers/das08_pci.c
index d8d27fa44491..7856fc13466a 100644
--- a/drivers/staging/comedi/drivers/das08_pci.c
+++ b/drivers/staging/comedi/drivers/das08_pci.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * das08_pci.c 3 * das08_pci.c
3 * comedi driver for DAS08 PCI boards 4 * comedi driver for DAS08 PCI boards
@@ -6,16 +7,6 @@
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 * Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net> 8 * Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net>
8 * Copyright (C) 2004 Salvador E. Tropea <set@users.sf.net> <set@ieee.org> 9 * Copyright (C) 2004 Salvador E. Tropea <set@users.sf.net> <set@ieee.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21/* 12/*
diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c
index ddd4aeab6365..74ff204b585d 100644
--- a/drivers/staging/comedi/drivers/das16.c
+++ b/drivers/staging/comedi/drivers/das16.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * das16.c 3 * das16.c
3 * DAS16 driver 4 * DAS16 driver
@@ -6,16 +7,6 @@
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 * Copyright (C) 2000 Chris R. Baugher <baugher@enteract.com> 8 * Copyright (C) 2000 Chris R. Baugher <baugher@enteract.com>
8 * Copyright (C) 2001,2002 Frank Mori Hess <fmhess@users.sourceforge.net> 9 * Copyright (C) 2001,2002 Frank Mori Hess <fmhess@users.sourceforge.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21/* 12/*
diff --git a/drivers/staging/comedi/drivers/das16m1.c b/drivers/staging/comedi/drivers/das16m1.c
index bb8d6ec0632e..72f8ed2c5008 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for CIO-DAS16/M1 3 * Comedi driver for CIO-DAS16/M1
3 * Author: Frank Mori Hess, based on code from the das16 driver. 4 * Author: Frank Mori Hess, based on code from the das16 driver.
@@ -5,16 +6,6 @@
5 * 6 *
6 * COMEDI - Linux Control and Measurement Device Interface 7 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20/* 11/*
diff --git a/drivers/staging/comedi/drivers/das1800.c b/drivers/staging/comedi/drivers/das1800.c
index e0a34c2687a8..f16aa7e9f4f3 100644
--- a/drivers/staging/comedi/drivers/das1800.c
+++ b/drivers/staging/comedi/drivers/das1800.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for Keithley DAS-1700/DAS-1800 series boards 3 * Comedi driver for Keithley DAS-1700/DAS-1800 series boards
3 * Copyright (C) 2000 Frank Mori Hess <fmhess@users.sourceforge.net> 4 * Copyright (C) 2000 Frank Mori Hess <fmhess@users.sourceforge.net>
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/das6402.c b/drivers/staging/comedi/drivers/das6402.c
index 0fdf5e02182f..f99211ec46de 100644
--- a/drivers/staging/comedi/drivers/das6402.c
+++ b/drivers/staging/comedi/drivers/das6402.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * das6402.c 3 * das6402.c
3 * Comedi driver for DAS6402 compatible boards 4 * Comedi driver for DAS6402 compatible boards
@@ -5,16 +6,6 @@
5 * 6 *
6 * Rewrite of an experimental driver by: 7 * Rewrite of an experimental driver by:
7 * Copyright (C) 1999 Oystein Svendsen <svendsen@pvv.org> 8 * Copyright (C) 1999 Oystein Svendsen <svendsen@pvv.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20/* 11/*
diff --git a/drivers/staging/comedi/drivers/das800.c b/drivers/staging/comedi/drivers/das800.c
index fd4cb4911671..8cf09ef3012f 100644
--- a/drivers/staging/comedi/drivers/das800.c
+++ b/drivers/staging/comedi/drivers/das800.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/das800.c 3 * comedi/drivers/das800.c
3 * Driver for Keitley das800 series boards and compatibles 4 * Driver for Keitley das800 series boards and compatibles
@@ -5,16 +6,6 @@
5 * 6 *
6 * COMEDI - Linux Control and Measurement Device Interface 7 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19/* 10/*
20 * Driver: das800 11 * Driver: das800
diff --git a/drivers/staging/comedi/drivers/dmm32at.c b/drivers/staging/comedi/drivers/dmm32at.c
index 771cceb71069..75693cdde313 100644
--- a/drivers/staging/comedi/drivers/dmm32at.c
+++ b/drivers/staging/comedi/drivers/dmm32at.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * dmm32at.c 3 * dmm32at.c
3 * Diamond Systems Diamond-MM-32-AT Comedi driver 4 * Diamond Systems Diamond-MM-32-AT Comedi driver
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/dt2801.c b/drivers/staging/comedi/drivers/dt2801.c
index 30805797a957..a29880981d81 100644
--- a/drivers/staging/comedi/drivers/dt2801.c
+++ b/drivers/staging/comedi/drivers/dt2801.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * comedi/drivers/dt2801.c 3 * comedi/drivers/dt2801.c
3 * Device Driver for DataTranslation DT2801 4 * Device Driver for DataTranslation DT2801
diff --git a/drivers/staging/comedi/drivers/dt2811.c b/drivers/staging/comedi/drivers/dt2811.c
index fcd85475e429..05207a519755 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for Data Translation DT2811 3 * Comedi 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 * Copyright (C) David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18/* 9/*
@@ -316,7 +307,7 @@ static int dt2811_ai_cmd(struct comedi_device *dev,
316static unsigned int dt2811_ns_to_timer(unsigned int *nanosec, 307static unsigned int dt2811_ns_to_timer(unsigned int *nanosec,
317 unsigned int flags) 308 unsigned int flags)
318{ 309{
319 unsigned long long ns = *nanosec; 310 unsigned long long ns;
320 unsigned int ns_lo = COMEDI_MIN_SPEED; 311 unsigned int ns_lo = COMEDI_MIN_SPEED;
321 unsigned int ns_hi = 0; 312 unsigned int ns_hi = 0;
322 unsigned int divisor_hi = 0; 313 unsigned int divisor_hi = 0;
diff --git a/drivers/staging/comedi/drivers/dt2814.c b/drivers/staging/comedi/drivers/dt2814.c
index 09984a66dba3..d2c715737361 100644
--- a/drivers/staging/comedi/drivers/dt2814.c
+++ b/drivers/staging/comedi/drivers/dt2814.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/dt2814.c 3 * comedi/drivers/dt2814.c
3 * Hardware driver for Data Translation DT2814 4 * Hardware driver for Data Translation DT2814
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18/* 9/*
19 * Driver: dt2814 10 * Driver: dt2814
diff --git a/drivers/staging/comedi/drivers/dt2815.c b/drivers/staging/comedi/drivers/dt2815.c
index ce5571971194..83026ba63d1c 100644
--- a/drivers/staging/comedi/drivers/dt2815.c
+++ b/drivers/staging/comedi/drivers/dt2815.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/dt2815.c 3 * comedi/drivers/dt2815.c
3 * Hardware driver for Data Translation DT2815 4 * Hardware driver for Data Translation DT2815
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se> 7 * Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18/* 9/*
19 * Driver: dt2815 10 * Driver: dt2815
diff --git a/drivers/staging/comedi/drivers/dt2817.c b/drivers/staging/comedi/drivers/dt2817.c
index 39d2566e49bf..9babb2a5196a 100644
--- a/drivers/staging/comedi/drivers/dt2817.c
+++ b/drivers/staging/comedi/drivers/dt2817.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/dt2817.c 3 * comedi/drivers/dt2817.c
3 * Hardware driver for Data Translation DT2817 4 * Hardware driver for Data Translation DT2817
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18/* 9/*
19 * Driver: dt2817 10 * Driver: dt2817
diff --git a/drivers/staging/comedi/drivers/dt282x.c b/drivers/staging/comedi/drivers/dt282x.c
index 217a4b884689..3be927f1d3a9 100644
--- a/drivers/staging/comedi/drivers/dt282x.c
+++ b/drivers/staging/comedi/drivers/dt282x.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * dt282x.c 3 * dt282x.c
3 * Comedi driver for Data Translation DT2821 series 4 * Comedi driver for Data Translation DT2821 series
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c
index 19e0b7be8495..2edf3ee91300 100644
--- a/drivers/staging/comedi/drivers/dt3000.c
+++ b/drivers/staging/comedi/drivers/dt3000.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * dt3000.c 3 * dt3000.c
3 * Data Translation DT3000 series driver 4 * Data Translation DT3000 series driver
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1999 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1999 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c
index 7ebca862ecaa..75cc9e8e5b94 100644
--- a/drivers/staging/comedi/drivers/dt9812.c
+++ b/drivers/staging/comedi/drivers/dt9812.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/dt9812.c 3 * comedi/drivers/dt9812.c
3 * COMEDI driver for DataTranslation DT9812 USB module 4 * COMEDI driver for DataTranslation DT9812 USB module
@@ -5,16 +6,6 @@
5 * Copyright (C) 2005 Anders Blomdell <anders.blomdell@control.lth.se> 6 * Copyright (C) 2005 Anders Blomdell <anders.blomdell@control.lth.se>
6 * 7 *
7 * COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20/* 11/*
diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index bab7ac9e6237..e50536731d11 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/dyna_pci10xx.c 3 * comedi/drivers/dyna_pci10xx.c
3 * Copyright (C) 2011 Prashant Shah, pshah.mumbai@gmail.com 4 * Copyright (C) 2011 Prashant Shah, pshah.mumbai@gmail.com
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 */ 5 */
15 6
16/* 7/*
diff --git a/drivers/staging/comedi/drivers/fl512.c b/drivers/staging/comedi/drivers/fl512.c
index 0f278ffdad76..41c50c7a8f59 100644
--- a/drivers/staging/comedi/drivers/fl512.c
+++ b/drivers/staging/comedi/drivers/fl512.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * fl512.c 3 * fl512.c
3 * Anders Gnistrup <ex18@kalman.iau.dtu.dk> 4 * Anders Gnistrup <ex18@kalman.iau.dtu.dk>
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c b/drivers/staging/comedi/drivers/gsc_hpdi.c
index e5b948405fd9..4bdf44d82879 100644
--- a/drivers/staging/comedi/drivers/gsc_hpdi.c
+++ b/drivers/staging/comedi/drivers/gsc_hpdi.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * gsc_hpdi.c 3 * gsc_hpdi.c
3 * Comedi driver the General Standards Corporation 4 * Comedi driver the General Standards Corporation
@@ -8,16 +9,6 @@
8 * 9 *
9 * COMEDI - Linux Control and Measurement Device Interface 10 * COMEDI - Linux Control and Measurement Device Interface
10 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org> 11 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
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 */ 12 */
22 13
23/* 14/*
diff --git a/drivers/staging/comedi/drivers/icp_multi.c b/drivers/staging/comedi/drivers/icp_multi.c
index 28cf53e48b8d..b14aaed6b525 100644
--- a/drivers/staging/comedi/drivers/icp_multi.c
+++ b/drivers/staging/comedi/drivers/icp_multi.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * icp_multi.c 3 * icp_multi.c
3 * Comedi driver for Inova ICP_MULTI board 4 * Comedi driver for Inova ICP_MULTI board
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2002 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2002 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/ii_pci20kc.c b/drivers/staging/comedi/drivers/ii_pci20kc.c
index 77e1d891f232..3eaf7c59de75 100644
--- a/drivers/staging/comedi/drivers/ii_pci20kc.c
+++ b/drivers/staging/comedi/drivers/ii_pci20kc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * ii_pci20kc.c 3 * ii_pci20kc.c
3 * Driver for Intelligent Instruments PCI-20001C carrier board and modules. 4 * Driver for Intelligent Instruments PCI-20001C carrier board and modules.
diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c
index cbff3b41bb45..201f4f96c182 100644
--- a/drivers/staging/comedi/drivers/jr3_pci.c
+++ b/drivers/staging/comedi/drivers/jr3_pci.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/jr3_pci.c 3 * comedi/drivers/jr3_pci.c
3 * hardware driver for JR3/PCI force sensor board 4 * hardware driver for JR3/PCI force sensor board
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2007 Anders Blomdell <anders.blomdell@control.lth.se> 7 * Copyright (C) 2007 Anders Blomdell <anders.blomdell@control.lth.se>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18/* 9/*
19 * Driver: jr3_pci 10 * Driver: jr3_pci
diff --git a/drivers/staging/comedi/drivers/ke_counter.c b/drivers/staging/comedi/drivers/ke_counter.c
index 93198abf0ee5..e612cf605700 100644
--- a/drivers/staging/comedi/drivers/ke_counter.c
+++ b/drivers/staging/comedi/drivers/ke_counter.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * ke_counter.c 3 * ke_counter.c
3 * Comedi driver for Kolter-Electronic PCI Counter 1 Card 4 * Comedi driver for Kolter-Electronic PCI Counter 1 Card
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c
index 15a53204a36a..ee53571a8969 100644
--- a/drivers/staging/comedi/drivers/me4000.c
+++ b/drivers/staging/comedi/drivers/me4000.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * me4000.c 3 * me4000.c
3 * Source code for the Meilhaus ME-4000 board family. 4 * Source code for the Meilhaus ME-4000 board family.
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c
index c0b7a300e428..169742be17b8 100644
--- a/drivers/staging/comedi/drivers/me_daq.c
+++ b/drivers/staging/comedi/drivers/me_daq.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/me_daq.c 3 * comedi/drivers/me_daq.c
3 * Hardware driver for Meilhaus data acquisition cards: 4 * Hardware driver for Meilhaus data acquisition cards:
4 * ME-2000i, ME-2600i, ME-3000vm1 5 * ME-2000i, ME-2600i, ME-3000vm1
5 * 6 *
6 * Copyright (C) 2002 Michael Hillmann <hillmann@syscongroup.de> 7 * Copyright (C) 2002 Michael Hillmann <hillmann@syscongroup.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/mf6x4.c b/drivers/staging/comedi/drivers/mf6x4.c
index fbdf181d8ccc..ea430237efa7 100644
--- a/drivers/staging/comedi/drivers/mf6x4.c
+++ b/drivers/staging/comedi/drivers/mf6x4.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/mf6x4.c 3 * comedi/drivers/mf6x4.c
3 * Driver for Humusoft MF634 and MF624 Data acquisition cards 4 * Driver for Humusoft MF634 and MF624 Data acquisition cards
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18/* 9/*
19 * Driver: mf6x4 10 * Driver: mf6x4
diff --git a/drivers/staging/comedi/drivers/mite.c b/drivers/staging/comedi/drivers/mite.c
index 05126ba4ba51..61e03ad84123 100644
--- a/drivers/staging/comedi/drivers/mite.c
+++ b/drivers/staging/comedi/drivers/mite.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/mite.c 3 * comedi/drivers/mite.c
3 * Hardware driver for NI Mite PCI interface chip 4 * Hardware driver for NI Mite PCI interface chip
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2002 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2002 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/mite.h b/drivers/staging/comedi/drivers/mite.h
index 02a627d3969d..d5e27ac25df8 100644
--- a/drivers/staging/comedi/drivers/mite.h
+++ b/drivers/staging/comedi/drivers/mite.h
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * module/mite.h 3 * module/mite.h
3 * Hardware driver for NI Mite PCI interface chip 4 * Hardware driver for NI Mite PCI interface chip
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1999 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1999 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#ifndef _MITE_H_ 10#ifndef _MITE_H_
diff --git a/drivers/staging/comedi/drivers/mpc624.c b/drivers/staging/comedi/drivers/mpc624.c
index 9bda761433c2..bf3a3a08c7ab 100644
--- a/drivers/staging/comedi/drivers/mpc624.c
+++ b/drivers/staging/comedi/drivers/mpc624.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * mpc624.c 3 * mpc624.c
3 * Hardware driver for a Micro/sys inc. MPC-624 PC/104 board 4 * Hardware driver for a Micro/sys inc. MPC-624 PC/104 board
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/multiq3.c b/drivers/staging/comedi/drivers/multiq3.c
index b5a26f7b4332..c85c9ab3655f 100644
--- a/drivers/staging/comedi/drivers/multiq3.c
+++ b/drivers/staging/comedi/drivers/multiq3.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * multiq3.c 3 * multiq3.c
3 * Hardware driver for Quanser Consulting MultiQ-3 board 4 * Hardware driver for Quanser Consulting MultiQ-3 board
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se> 7 * Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c
index 84c62e256094..4d1eccb5041d 100644
--- a/drivers/staging/comedi/drivers/ni_6527.c
+++ b/drivers/staging/comedi/drivers/ni_6527.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * ni_6527.c 3 * ni_6527.c
3 * Comedi driver for National Instruments PCI-6527 4 * Comedi driver for National Instruments PCI-6527
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1999,2002,2003 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1999,2002,2003 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index 07f38e385469..996074e471d3 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * ni_65xx.c 3 * ni_65xx.c
3 * Comedi driver for National Instruments PCI-65xx static dio boards 4 * Comedi driver for National Instruments PCI-65xx static dio boards
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 1999,2002,2003 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 1999,2002,2003 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c
index 6aa755ad3953..e521ed9d0887 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1,15 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Hardware driver for NI 660x devices 3 * Hardware driver for NI 660x devices
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */ 4 */
14 5
15/* 6/*
diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c
index 1d3ff60efcb8..4e4ae31c8d0b 100644
--- a/drivers/staging/comedi/drivers/ni_670x.c
+++ b/drivers/staging/comedi/drivers/ni_670x.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for NI 670x devices 3 * Comedi driver for NI 670x devices
3 * 4 *
4 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18/* 9/*
diff --git a/drivers/staging/comedi/drivers/ni_at_a2150.c b/drivers/staging/comedi/drivers/ni_at_a2150.c
index c69cd676f357..76e8d047f71e 100644
--- a/drivers/staging/comedi/drivers/ni_at_a2150.c
+++ b/drivers/staging/comedi/drivers/ni_at_a2150.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for National Instruments AT-A2150 boards 3 * Comedi driver for National Instruments AT-A2150 boards
3 * Copyright (C) 2001, 2002 Frank Mori Hess <fmhess@users.sourceforge.net> 4 * Copyright (C) 2001, 2002 Frank Mori Hess <fmhess@users.sourceforge.net>
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/ni_at_ao.c b/drivers/staging/comedi/drivers/ni_at_ao.c
index 158fa29374fc..aad0b295ee2b 100644
--- a/drivers/staging/comedi/drivers/ni_at_ao.c
+++ b/drivers/staging/comedi/drivers/ni_at_ao.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * ni_at_ao.c 3 * ni_at_ao.c
3 * Driver for NI AT-AO-6/10 boards 4 * Driver for NI AT-AO-6/10 boards
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000,2002 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000,2002 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/ni_atmio.c b/drivers/staging/comedi/drivers/ni_atmio.c
index ae6ed96d7874..b9e9ab548c4b 100644
--- a/drivers/staging/comedi/drivers/ni_atmio.c
+++ b/drivers/staging/comedi/drivers/ni_atmio.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for NI AT-MIO E series cards 3 * Comedi driver for NI AT-MIO E series cards
3 * 4 *
4 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18/* 9/*
diff --git a/drivers/staging/comedi/drivers/ni_atmio16d.c b/drivers/staging/comedi/drivers/ni_atmio16d.c
index fb59b0ffbba6..68ad9676f962 100644
--- a/drivers/staging/comedi/drivers/ni_atmio16d.c
+++ b/drivers/staging/comedi/drivers/ni_atmio16d.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for National Instruments AT-MIO16D board 3 * Comedi driver for National Instruments AT-MIO16D board
3 * Copyright (C) 2000 Chris R. Baugher <baugher@enteract.com> 4 * Copyright (C) 2000 Chris R. Baugher <baugher@enteract.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 */ 5 */
15 6
16/* 7/*
diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c
index 8f6396edd21c..b9e525b9beb9 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/ni_daq_700.c 3 * comedi/drivers/ni_daq_700.c
3 * Driver for DAQCard-700 DIO/AI 4 * Driver for DAQCard-700 DIO/AI
@@ -5,16 +6,6 @@
5 * 6 *
6 * COMEDI - Linux Control and Measurement Device Interface 7 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 8 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20/* 11/*
diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c
index 733d3fbafa4d..44fb65afc218 100644
--- a/drivers/staging/comedi/drivers/ni_daq_dio24.c
+++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for National Instruments PCMCIA DAQ-Card DIO-24 3 * Comedi driver for National Instruments PCMCIA DAQ-Card DIO-24
3 * Copyright (C) 2002 Daniel Vecino Castel <dvecino@able.es> 4 * Copyright (C) 2002 Daniel Vecino Castel <dvecino@able.es>
@@ -7,16 +8,6 @@
7 * The initial developer of the pcmcia dummy_cs.c code is David A. Hinds 8 * The initial developer of the pcmcia dummy_cs.c code is David A. Hinds
8 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds 9 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
9 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. 10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c
index 51e5e942b442..c6cf37ccbc92 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.c
+++ b/drivers/staging/comedi/drivers/ni_labpc.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/ni_labpc.c 3 * comedi/drivers/ni_labpc.c
3 * Driver for National Instruments Lab-PC series boards and compatibles 4 * Driver for National Instruments Lab-PC series boards and compatibles
4 * Copyright (C) 2001-2003 Frank Mori Hess <fmhess@users.sourceforge.net> 5 * Copyright (C) 2001-2003 Frank Mori Hess <fmhess@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17/* 8/*
diff --git a/drivers/staging/comedi/drivers/ni_labpc.h b/drivers/staging/comedi/drivers/ni_labpc.h
index c2edadc7b3c6..f685047efb67 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Header for ni_labpc ISA/PCMCIA/PCI drivers 3 * Header for ni_labpc ISA/PCMCIA/PCI drivers
3 * 4 *
4 * Copyright (C) 2003 Frank Mori Hess <fmhess@users.sourceforge.net> 5 * Copyright (C) 2003 Frank Mori Hess <fmhess@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#ifndef _NI_LABPC_H 8#ifndef _NI_LABPC_H
diff --git a/drivers/staging/comedi/drivers/ni_labpc_common.c b/drivers/staging/comedi/drivers/ni_labpc_common.c
index b0dfb8eed16d..7fa2d39562db 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_common.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_common.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/ni_labpc_common.c 3 * comedi/drivers/ni_labpc_common.c
3 * 4 *
4 * Common support code for "ni_labpc", "ni_labpc_pci" and "ni_labpc_cs". 5 * Common support code for "ni_labpc", "ni_labpc_pci" and "ni_labpc_cs".
5 * 6 *
6 * Copyright (C) 2001-2003 Frank Mori Hess <fmhess@users.sourceforge.net> 7 * Copyright (C) 2001-2003 Frank Mori Hess <fmhess@users.sourceforge.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/module.h> 10#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c
index 3d4d0b9ad4e1..4f7e2fe21254 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_cs.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Driver for National Instruments daqcard-1200 boards 3 * Driver for National Instruments daqcard-1200 boards
3 * Copyright (C) 2001, 2002, 2003 Frank Mori Hess <fmhess@users.sourceforge.net> 4 * Copyright (C) 2001, 2002, 2003 Frank Mori Hess <fmhess@users.sourceforge.net>
@@ -7,16 +8,6 @@
7 * The initial developer of the pcmcia dummy_cs.c code is David A. Hinds 8 * The initial developer of the pcmcia dummy_cs.c code is David A. Hinds
8 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds 9 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
9 * are Copyright (C) 1999 David A. Hinds. 10 * are Copyright (C) 1999 David A. Hinds.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
diff --git a/drivers/staging/comedi/drivers/ni_labpc_isadma.c b/drivers/staging/comedi/drivers/ni_labpc_isadma.c
index 29dbdf5ec25d..5657736a9408 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_isadma.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_isadma.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/ni_labpc_isadma.c 3 * comedi/drivers/ni_labpc_isadma.c
3 * ISA DMA support for National Instruments Lab-PC series boards and 4 * ISA DMA support for National Instruments Lab-PC series boards and
@@ -5,16 +6,6 @@
5 * 6 *
6 * Extracted from ni_labpc.c: 7 * Extracted from ni_labpc.c:
7 * Copyright (C) 2001-2003 Frank Mori Hess <fmhess@users.sourceforge.net> 8 * Copyright (C) 2001-2003 Frank Mori Hess <fmhess@users.sourceforge.net>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20#include <linux/module.h> 11#include <linux/module.h>
diff --git a/drivers/staging/comedi/drivers/ni_labpc_pci.c b/drivers/staging/comedi/drivers/ni_labpc_pci.c
index cac089193121..d7d5a7973558 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_pci.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_pci.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/ni_labpc_pci.c 3 * comedi/drivers/ni_labpc_pci.c
3 * Driver for National Instruments Lab-PC PCI-1200 4 * Driver for National Instruments Lab-PC PCI-1200
4 * Copyright (C) 2001, 2002, 2003 Frank Mori Hess <fmhess@users.sourceforge.net> 5 * Copyright (C) 2001, 2002, 2003 Frank Mori Hess <fmhess@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17/* 8/*
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c
index 398347fedc47..5d610af6799f 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Hardware driver for DAQ-STC based boards 3 * Hardware driver for DAQ-STC based boards
3 * 4 *
4 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
6 * Copyright (C) 2002-2006 Frank Mori Hess <fmhess@users.sourceforge.net> 7 * Copyright (C) 2002-2006 Frank Mori Hess <fmhess@users.sourceforge.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c
index 21f823179356..4f37b4e58f09 100644
--- a/drivers/staging/comedi/drivers/ni_mio_cs.c
+++ b/drivers/staging/comedi/drivers/ni_mio_cs.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for NI PCMCIA MIO E series cards 3 * Comedi driver for NI PCMCIA MIO E series cards
3 * 4 *
4 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18/* 9/*
diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c
index b27345abebe1..6692af5ff79b 100644
--- a/drivers/staging/comedi/drivers/ni_pcidio.c
+++ b/drivers/staging/comedi/drivers/ni_pcidio.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for National Instruments PCI-DIO-32HS 3 * Comedi driver for National Instruments PCI-DIO-32HS
3 * 4 *
4 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1999,2002 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 1999,2002 David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18/* 9/*
diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c
index 3a96913c025e..f9e466d18b3f 100644
--- a/drivers/staging/comedi/drivers/ni_pcimio.c
+++ b/drivers/staging/comedi/drivers/ni_pcimio.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Comedi driver for NI PCI-MIO E series cards 3 * Comedi driver for NI PCI-MIO E series cards
3 * 4 *
4 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18/* 9/*
diff --git a/drivers/staging/comedi/drivers/ni_stc.h b/drivers/staging/comedi/drivers/ni_stc.h
index 61138e86a455..cb9d4c3a1926 100644
--- a/drivers/staging/comedi/drivers/ni_stc.h
+++ b/drivers/staging/comedi/drivers/ni_stc.h
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Register descriptions for NI DAQ-STC chip 3 * Register descriptions for NI DAQ-STC chip
3 * 4 *
4 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1998-9 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 1998-9 David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18/* 9/*
diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c
index 15cb4088467b..ef919b21b7d9 100644
--- a/drivers/staging/comedi/drivers/ni_tio.c
+++ b/drivers/staging/comedi/drivers/ni_tio.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Support for NI general purpose counters 3 * Support for NI general purpose counters
3 * 4 *
4 * Copyright (C) 2006 Frank Mori Hess <fmhess@users.sourceforge.net> 5 * Copyright (C) 2006 Frank Mori Hess <fmhess@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17/* 8/*
diff --git a/drivers/staging/comedi/drivers/ni_tio.h b/drivers/staging/comedi/drivers/ni_tio.h
index 2012033414d3..23221cead8ca 100644
--- a/drivers/staging/comedi/drivers/ni_tio.h
+++ b/drivers/staging/comedi/drivers/ni_tio.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Header file for NI general purpose counter support code (ni_tio.c) 3 * Header file for NI general purpose counter support code (ni_tio.c)
3 * 4 *
4 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#ifndef _COMEDI_NI_TIO_H 8#ifndef _COMEDI_NI_TIO_H
diff --git a/drivers/staging/comedi/drivers/ni_tio_internal.h b/drivers/staging/comedi/drivers/ni_tio_internal.h
index 4e024eb5656b..f4d99d78208a 100644
--- a/drivers/staging/comedi/drivers/ni_tio_internal.h
+++ b/drivers/staging/comedi/drivers/ni_tio_internal.h
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Header file for NI general purpose counter support code (ni_tio.c and 3 * Header file for NI general purpose counter support code (ni_tio.c and
3 * ni_tiocmd.c) 4 * ni_tiocmd.c)
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18#ifndef _COMEDI_NI_TIO_INTERNAL_H 9#ifndef _COMEDI_NI_TIO_INTERNAL_H
diff --git a/drivers/staging/comedi/drivers/ni_tiocmd.c b/drivers/staging/comedi/drivers/ni_tiocmd.c
index 9007c57544bf..050bee0b9515 100644
--- a/drivers/staging/comedi/drivers/ni_tiocmd.c
+++ b/drivers/staging/comedi/drivers/ni_tiocmd.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Command support for NI general purpose counters 3 * Command support for NI general purpose counters
3 * 4 *
4 * Copyright (C) 2006 Frank Mori Hess <fmhess@users.sourceforge.net> 5 * Copyright (C) 2006 Frank Mori Hess <fmhess@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17/* 8/*
diff --git a/drivers/staging/comedi/drivers/ni_usb6501.c b/drivers/staging/comedi/drivers/ni_usb6501.c
index 9a0a96329a55..808ed92ed66f 100644
--- a/drivers/staging/comedi/drivers/ni_usb6501.c
+++ b/drivers/staging/comedi/drivers/ni_usb6501.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/ni_usb6501.c 3 * comedi/drivers/ni_usb6501.c
3 * Comedi driver for National Instruments USB-6501 4 * Comedi driver for National Instruments USB-6501
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2014 Luca Ellero <luca.ellero@brickedbrain.com> 7 * Copyright (C) 2014 Luca Ellero <luca.ellero@brickedbrain.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/pcl711.c b/drivers/staging/comedi/drivers/pcl711.c
index 3774daa9d661..a5937206bf1c 100644
--- a/drivers/staging/comedi/drivers/pcl711.c
+++ b/drivers/staging/comedi/drivers/pcl711.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * pcl711.c 3 * pcl711.c
3 * Comedi driver for PC-LabCard PCL-711 and AdSys ACL-8112 and compatibles 4 * Comedi driver for PC-LabCard PCL-711 and AdSys ACL-8112 and compatibles
@@ -7,16 +8,6 @@
7 * 8 *
8 * COMEDI - Linux Control and Measurement Device Interface 9 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 10 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
diff --git a/drivers/staging/comedi/drivers/pcl724.c b/drivers/staging/comedi/drivers/pcl724.c
index 74b07e1744c7..9c174f1f2fcf 100644
--- a/drivers/staging/comedi/drivers/pcl724.c
+++ b/drivers/staging/comedi/drivers/pcl724.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * pcl724.c 3 * pcl724.c
3 * Comedi driver for 8255 based ISA and PC/104 DIO boards 4 * Comedi driver for 8255 based ISA and PC/104 DIO boards
diff --git a/drivers/staging/comedi/drivers/pcl726.c b/drivers/staging/comedi/drivers/pcl726.c
index 256850ccb6fa..0963d85873a9 100644
--- a/drivers/staging/comedi/drivers/pcl726.c
+++ b/drivers/staging/comedi/drivers/pcl726.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * pcl726.c 3 * pcl726.c
3 * Comedi driver for 6/12-Channel D/A Output and DIO cards 4 * Comedi driver for 6/12-Channel D/A Output and DIO cards
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/pcl730.c b/drivers/staging/comedi/drivers/pcl730.c
index ce958eef2a61..3d1e9150e5b5 100644
--- a/drivers/staging/comedi/drivers/pcl730.c
+++ b/drivers/staging/comedi/drivers/pcl730.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * comedi/drivers/pcl730.c 3 * comedi/drivers/pcl730.c
3 * Driver for Advantech PCL-730 and clones 4 * Driver for Advantech PCL-730 and clones
diff --git a/drivers/staging/comedi/drivers/pcl812.c b/drivers/staging/comedi/drivers/pcl812.c
index 9c75065dd26a..aefc1b849cf7 100644
--- a/drivers/staging/comedi/drivers/pcl812.c
+++ b/drivers/staging/comedi/drivers/pcl812.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * comedi/drivers/pcl812.c 3 * comedi/drivers/pcl812.c
3 * 4 *
diff --git a/drivers/staging/comedi/drivers/pcl816.c b/drivers/staging/comedi/drivers/pcl816.c
index c00a71f538ef..d722079f3327 100644
--- a/drivers/staging/comedi/drivers/pcl816.c
+++ b/drivers/staging/comedi/drivers/pcl816.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * pcl816.c 3 * pcl816.c
3 * Comedi driver for Advantech PCL-816 cards 4 * Comedi driver for Advantech PCL-816 cards
diff --git a/drivers/staging/comedi/drivers/pcl818.c b/drivers/staging/comedi/drivers/pcl818.c
index 5b5df0596ad9..eebb49751713 100644
--- a/drivers/staging/comedi/drivers/pcl818.c
+++ b/drivers/staging/comedi/drivers/pcl818.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * comedi/drivers/pcl818.c 3 * comedi/drivers/pcl818.c
3 * 4 *
diff --git a/drivers/staging/comedi/drivers/pcm3724.c b/drivers/staging/comedi/drivers/pcm3724.c
index 588ae5ecec66..5779e005c0cb 100644
--- a/drivers/staging/comedi/drivers/pcm3724.c
+++ b/drivers/staging/comedi/drivers/pcm3724.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * pcm3724.c 3 * pcm3724.c
3 * Comedi driver for Advantech PCM-3724 Digital I/O board 4 * Comedi driver for Advantech PCM-3724 Digital I/O board
diff --git a/drivers/staging/comedi/drivers/pcmad.c b/drivers/staging/comedi/drivers/pcmad.c
index 12f94fe82f5b..fe5449bb1716 100644
--- a/drivers/staging/comedi/drivers/pcmad.c
+++ b/drivers/staging/comedi/drivers/pcmad.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * pcmad.c 3 * pcmad.c
3 * Hardware driver for Winsystems PCM-A/D12 and PCM-A/D16 4 * Hardware driver for Winsystems PCM-A/D12 and PCM-A/D16
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000,2001 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000,2001 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/pcmda12.c b/drivers/staging/comedi/drivers/pcmda12.c
index d86c5e2cd0c7..33e463b193a1 100644
--- a/drivers/staging/comedi/drivers/pcmda12.c
+++ b/drivers/staging/comedi/drivers/pcmda12.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * pcmda12.c 3 * pcmda12.c
3 * Driver for Winsystems PC-104 based PCM-D/A-12 8-channel AO board. 4 * Driver for Winsystems PC-104 based PCM-D/A-12 8-channel AO board.
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2006 Calin A. Culianu <calin@ajvar.org> 7 * Copyright (C) 2006 Calin A. Culianu <calin@ajvar.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c
index 70ad497dd20b..72af1776f785 100644
--- a/drivers/staging/comedi/drivers/pcmmio.c
+++ b/drivers/staging/comedi/drivers/pcmmio.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * pcmmio.c 3 * pcmmio.c
3 * Driver for Winsystems PC-104 based multifunction IO board. 4 * Driver for Winsystems PC-104 based multifunction IO board.
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2007 Calin A. Culianu <calin@ajvar.org> 7 * Copyright (C) 2007 Calin A. Culianu <calin@ajvar.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c
index 8ad64f2625fe..743fb226e2e4 100644
--- a/drivers/staging/comedi/drivers/pcmuio.c
+++ b/drivers/staging/comedi/drivers/pcmuio.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * pcmuio.c 3 * pcmuio.c
3 * Comedi driver for Winsystems PC-104 based 48/96-channel DIO boards. 4 * Comedi driver for Winsystems PC-104 based 48/96-channel DIO boards.
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2006 Calin A. Culianu <calin@ajvar.org> 7 * Copyright (C) 2006 Calin A. Culianu <calin@ajvar.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/plx9052.h b/drivers/staging/comedi/drivers/plx9052.h
index 2892e6528967..7950d1f57db6 100644
--- a/drivers/staging/comedi/drivers/plx9052.h
+++ b/drivers/staging/comedi/drivers/plx9052.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Definitions for the PLX-9052 PCI interface chip 3 * Definitions for the PLX-9052 PCI interface chip
3 * 4 *
@@ -5,16 +6,6 @@
5 * 6 *
6 * COMEDI - Linux Control and Measurement Device Interface 7 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20#ifndef _PLX9052_H_ 11#ifndef _PLX9052_H_
diff --git a/drivers/staging/comedi/drivers/plx9080.h b/drivers/staging/comedi/drivers/plx9080.h
index e23e63a097b5..469a9573acdc 100644
--- a/drivers/staging/comedi/drivers/plx9080.h
+++ b/drivers/staging/comedi/drivers/plx9080.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * plx9080.h 3 * plx9080.h
3 * 4 *
@@ -9,11 +10,6 @@
9 * Written by Krzysztof Halasa <khc@rgstudio.com.pl> 10 * Written by Krzysztof Halasa <khc@rgstudio.com.pl>
10 * 11 *
11 * Portions (C) SBE Inc., used by permission. 12 * Portions (C) SBE Inc., used by permission.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 */ 13 */
18 14
19#ifndef __COMEDI_PLX9080_H 15#ifndef __COMEDI_PLX9080_H
diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c
index e00e9c6268ae..bb400e08f0bc 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/rtd520.c 3 * comedi/drivers/rtd520.c
3 * Comedi driver for Real Time Devices (RTD) PCI4520/DM7520 4 * Comedi driver for Real Time Devices (RTD) PCI4520/DM7520
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2001 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2001 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/rti800.c b/drivers/staging/comedi/drivers/rti800.c
index cd61d2645af4..f7c320c89ee6 100644
--- a/drivers/staging/comedi/drivers/rti800.c
+++ b/drivers/staging/comedi/drivers/rti800.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/rti800.c 3 * comedi/drivers/rti800.c
3 * Hardware driver for Analog Devices RTI-800/815 board 4 * Hardware driver for Analog Devices RTI-800/815 board
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/rti802.c b/drivers/staging/comedi/drivers/rti802.c
index 6db58fcfd496..c6cf92bfff73 100644
--- a/drivers/staging/comedi/drivers/rti802.c
+++ b/drivers/staging/comedi/drivers/rti802.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * rti802.c 3 * rti802.c
3 * Comedi driver for Analog Devices RTI-802 board 4 * Comedi driver for Analog Devices RTI-802 board
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se> 7 * Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/s526.c b/drivers/staging/comedi/drivers/s526.c
index e226275972c0..5d567ae78f28 100644
--- a/drivers/staging/comedi/drivers/s526.c
+++ b/drivers/staging/comedi/drivers/s526.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * s526.c 3 * s526.c
3 * Sensoray s526 Comedi driver 4 * Sensoray s526 Comedi driver
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
index c906c9a5d944..0b3cfe934e14 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/s626.c 3 * comedi/drivers/s626.c
3 * Sensoray s626 Comedi driver 4 * Sensoray s626 Comedi driver
@@ -7,16 +8,6 @@
7 * 8 *
8 * Based on Sensoray Model 626 Linux driver Version 0.2 9 * Based on Sensoray Model 626 Linux driver Version 0.2
9 * Copyright (C) 2002-2004 Sensoray Co., Inc. 10 * Copyright (C) 2002-2004 Sensoray Co., Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22/* 13/*
@@ -1385,8 +1376,7 @@ static void s626_reset_adc(struct comedi_device *dev, u8 *ppl)
1385 jmp_adrs = 1376 jmp_adrs =
1386 (u32)devpriv->rps_buf.physical_base + 1377 (u32)devpriv->rps_buf.physical_base +
1387 (u32)((unsigned long)rps - 1378 (u32)((unsigned long)rps -
1388 (unsigned long)devpriv-> 1379 (unsigned long)devpriv->rps_buf.logical_base);
1389 rps_buf.logical_base);
1390 for (i = 0; i < (10 * S626_RPSCLK_PER_US / 2); i++) { 1380 for (i = 0; i < (10 * S626_RPSCLK_PER_US / 2); i++) {
1391 jmp_adrs += 8; /* Repeat to implement time delay: */ 1381 jmp_adrs += 8; /* Repeat to implement time delay: */
1392 /* Jump to next RPS instruction. */ 1382 /* Jump to next RPS instruction. */
@@ -1903,9 +1893,9 @@ static int s626_ai_cmdtest(struct comedi_device *dev,
1903 1893
1904 if (cmd->scan_begin_src == TRIG_TIMER) { 1894 if (cmd->scan_begin_src == TRIG_TIMER) {
1905 arg = cmd->convert_arg * cmd->scan_end_arg; 1895 arg = cmd->convert_arg * cmd->scan_end_arg;
1906 err |= comedi_check_trigger_arg_min(&cmd-> 1896 err |= comedi_check_trigger_arg_min(
1907 scan_begin_arg, 1897 &cmd->scan_begin_arg,
1908 arg); 1898 arg);
1909 } 1899 }
1910 } 1900 }
1911 1901
diff --git a/drivers/staging/comedi/drivers/s626.h b/drivers/staging/comedi/drivers/s626.h
index 4cef45263267..4bdc4fba736f 100644
--- a/drivers/staging/comedi/drivers/s626.h
+++ b/drivers/staging/comedi/drivers/s626.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/drivers/s626.h 3 * comedi/drivers/s626.h
3 * Sensoray s626 Comedi driver, header file 4 * Sensoray s626 Comedi driver, header file
@@ -7,16 +8,6 @@
7 * 8 *
8 * Based on Sensoray Model 626 Linux driver Version 0.2 9 * Based on Sensoray Model 626 Linux driver Version 0.2
9 * Copyright (C) 2002-2004 Sensoray Co., Inc. 10 * Copyright (C) 2002-2004 Sensoray Co., Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22#ifndef S626_H_INCLUDED 13#ifndef S626_H_INCLUDED
diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c
index a557be8a5076..ab69eeb2c1f1 100644
--- a/drivers/staging/comedi/drivers/serial2002.c
+++ b/drivers/staging/comedi/drivers/serial2002.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * serial2002.c 3 * serial2002.c
3 * Comedi driver for serial connected hardware 4 * Comedi driver for serial connected hardware
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2002 Anders Blomdell <anders.blomdell@control.lth.se> 7 * Copyright (C) 2002 Anders Blomdell <anders.blomdell@control.lth.se>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19/* 10/*
@@ -107,6 +98,7 @@ static long serial2002_tty_ioctl(struct file *f, unsigned int op,
107static int serial2002_tty_write(struct file *f, unsigned char *buf, int count) 98static int serial2002_tty_write(struct file *f, unsigned char *buf, int count)
108{ 99{
109 loff_t pos = 0; 100 loff_t pos = 0;
101
110 return kernel_write(f, buf, count, &pos); 102 return kernel_write(f, buf, count, &pos);
111} 103}
112 104
diff --git a/drivers/staging/comedi/drivers/ssv_dnp.c b/drivers/staging/comedi/drivers/ssv_dnp.c
index f9f634fd53cf..0628060e42ca 100644
--- a/drivers/staging/comedi/drivers/ssv_dnp.c
+++ b/drivers/staging/comedi/drivers/ssv_dnp.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * ssv_dnp.c 3 * ssv_dnp.c
3 * generic comedi driver for SSV Embedded Systems' DIL/Net-PCs 4 * generic comedi driver for SSV Embedded Systems' DIL/Net-PCs
@@ -5,16 +6,6 @@
5 * 6 *
6 * COMEDI - Linux Control and Measurement Device Interface 7 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20/* 11/*
diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c
index f4f05d29d30d..de177418190f 100644
--- a/drivers/staging/comedi/drivers/usbdux.c
+++ b/drivers/staging/comedi/drivers/usbdux.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * usbdux.c 3 * usbdux.c
3 * Copyright (C) 2003-2014 Bernd Porr, mail@berndporr.me.uk 4 * Copyright (C) 2003-2014 Bernd Porr, mail@berndporr.me.uk
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 */ 5 */
15 6
16/* 7/*
@@ -809,7 +800,6 @@ static int usbdux_ao_insn_write(struct comedi_device *dev,
809{ 800{
810 struct usbdux_private *devpriv = dev->private; 801 struct usbdux_private *devpriv = dev->private;
811 unsigned int chan = CR_CHAN(insn->chanspec); 802 unsigned int chan = CR_CHAN(insn->chanspec);
812 unsigned int val = s->readback[chan];
813 __le16 *p = (__le16 *)&devpriv->dux_commands[2]; 803 __le16 *p = (__le16 *)&devpriv->dux_commands[2];
814 int ret = -EBUSY; 804 int ret = -EBUSY;
815 int i; 805 int i;
@@ -825,7 +815,7 @@ static int usbdux_ao_insn_write(struct comedi_device *dev,
825 devpriv->dux_commands[4] = chan << 6; 815 devpriv->dux_commands[4] = chan << 6;
826 816
827 for (i = 0; i < insn->n; i++) { 817 for (i = 0; i < insn->n; i++) {
828 val = data[i]; 818 unsigned int val = data[i];
829 819
830 /* one 16 bit value */ 820 /* one 16 bit value */
831 *p = cpu_to_le16(val); 821 *p = cpu_to_le16(val);
diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c
index 608403c7586b..e18c0723b760 100644
--- a/drivers/staging/comedi/drivers/usbduxfast.c
+++ b/drivers/staging/comedi/drivers/usbduxfast.c
@@ -1,15 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (C) 2004-2014 Bernd Porr, mail@berndporr.me.uk 3 * Copyright (C) 2004-2014 Bernd Porr, mail@berndporr.me.uk
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */ 4 */
14 5
15/* 6/*
diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c
index 456e9f13becb..af5605a875e2 100644
--- a/drivers/staging/comedi/drivers/usbduxsigma.c
+++ b/drivers/staging/comedi/drivers/usbduxsigma.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * usbduxsigma.c 3 * usbduxsigma.c
3 * Copyright (C) 2011-2015 Bernd Porr, mail@berndporr.me.uk 4 * Copyright (C) 2011-2015 Bernd Porr, mail@berndporr.me.uk
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 */ 5 */
15 6
16/* 7/*
diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c
index a004aed0147a..6234b649d887 100644
--- a/drivers/staging/comedi/drivers/vmk80xx.c
+++ b/drivers/staging/comedi/drivers/vmk80xx.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * vmk80xx.c 3 * vmk80xx.c
3 * Velleman USB Board Low-Level Driver 4 * Velleman USB Board Low-Level Driver
@@ -6,16 +7,6 @@
6 * 7 *
7 * COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 9 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21/* 12/*
diff --git a/drivers/staging/comedi/kcomedilib/kcomedilib_main.c b/drivers/staging/comedi/kcomedilib/kcomedilib_main.c
index 55d43c076b1c..df9bba1b69ed 100644
--- a/drivers/staging/comedi/kcomedilib/kcomedilib_main.c
+++ b/drivers/staging/comedi/kcomedilib/kcomedilib_main.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * kcomedilib/kcomedilib.c 3 * kcomedilib/kcomedilib.c
3 * a comedlib interface for kernel modules 4 * a comedlib interface for kernel modules
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/module.h> 10#include <linux/module.h>
diff --git a/drivers/staging/comedi/proc.c b/drivers/staging/comedi/proc.c
index 2644dd4d6143..50d38938ac6f 100644
--- a/drivers/staging/comedi/proc.c
+++ b/drivers/staging/comedi/proc.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * /proc interface for comedi 3 * /proc interface for comedi
3 * 4 *
4 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1998 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18/* 9/*
diff --git a/drivers/staging/comedi/range.c b/drivers/staging/comedi/range.c
index ce3a58a7a171..89d599877445 100644
--- a/drivers/staging/comedi/range.c
+++ b/drivers/staging/comedi/range.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * comedi/range.c 3 * comedi/range.c
3 * comedi routines for voltage ranges 4 * comedi routines for voltage ranges
4 * 5 *
5 * COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/uaccess.h> 10#include <linux/uaccess.h>
diff --git a/drivers/staging/dgnc/Makefile b/drivers/staging/dgnc/Makefile
index 40ff0d007695..49633042fcc9 100644
--- a/drivers/staging/dgnc/Makefile
+++ b/drivers/staging/dgnc/Makefile
@@ -1,5 +1,4 @@
1obj-$(CONFIG_DGNC) += dgnc.o 1obj-$(CONFIG_DGNC) += dgnc.o
2 2
3dgnc-objs := dgnc_cls.o dgnc_driver.o\ 3dgnc-objs := dgnc_cls.o dgnc_driver.o\
4 dgnc_mgmt.o dgnc_neo.o\ 4 dgnc_tty.o
5 dgnc_tty.o dgnc_utils.o
diff --git a/drivers/staging/dgnc/dgnc_cls.c b/drivers/staging/dgnc/dgnc_cls.c
index 9639035fddd1..7e6cbfe4e4ee 100644
--- a/drivers/staging/dgnc/dgnc_cls.c
+++ b/drivers/staging/dgnc/dgnc_cls.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright 2003 Digi International (www.digi.com) 3 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com> 4 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */ 5 */
15 6
16#include <linux/kernel.h> 7#include <linux/kernel.h>
@@ -397,7 +388,7 @@ static void cls_assert_modem_signals(struct channel_t *ch)
397 writeb(out, &ch->ch_cls_uart->mcr); 388 writeb(out, &ch->ch_cls_uart->mcr);
398 389
399 /* Give time for the UART to actually drop the signals */ 390 /* Give time for the UART to actually drop the signals */
400 udelay(10); 391 usleep_range(10, 20);
401} 392}
402 393
403static void cls_copy_data_from_queue_to_uart(struct channel_t *ch) 394static void cls_copy_data_from_queue_to_uart(struct channel_t *ch)
@@ -1123,30 +1114,6 @@ static void cls_send_immediate_char(struct channel_t *ch, unsigned char c)
1123 writeb(c, &ch->ch_cls_uart->txrx); 1114 writeb(c, &ch->ch_cls_uart->txrx);
1124} 1115}
1125 1116
1126static void cls_vpd(struct dgnc_board *brd)
1127{
1128 ulong vpdbase; /* Start of io base of the card */
1129 u8 __iomem *re_map_vpdbase;/* Remapped memory of the card */
1130 int i = 0;
1131
1132 vpdbase = pci_resource_start(brd->pdev, 3);
1133 if (!vpdbase)
1134 return;
1135
1136 re_map_vpdbase = ioremap(vpdbase, 0x400);
1137
1138 if (!re_map_vpdbase)
1139 return;
1140
1141 for (i = 0; i < 0x40; i++) {
1142 brd->vpd[i] = readb(re_map_vpdbase + i);
1143 pr_info("%x ", brd->vpd[i]);
1144 }
1145 pr_info("\n");
1146
1147 iounmap(re_map_vpdbase);
1148}
1149
1150struct board_ops dgnc_cls_ops = { 1117struct board_ops dgnc_cls_ops = {
1151 .tasklet = cls_tasklet, 1118 .tasklet = cls_tasklet,
1152 .intr = cls_intr, 1119 .intr = cls_intr,
@@ -1154,7 +1121,6 @@ struct board_ops dgnc_cls_ops = {
1154 .uart_off = cls_uart_off, 1121 .uart_off = cls_uart_off,
1155 .drain = cls_drain, 1122 .drain = cls_drain,
1156 .param = cls_param, 1123 .param = cls_param,
1157 .vpd = cls_vpd,
1158 .assert_modem_signals = cls_assert_modem_signals, 1124 .assert_modem_signals = cls_assert_modem_signals,
1159 .flush_uart_write = cls_flush_uart_write, 1125 .flush_uart_write = cls_flush_uart_write,
1160 .flush_uart_read = cls_flush_uart_read, 1126 .flush_uart_read = cls_flush_uart_read,
diff --git a/drivers/staging/dgnc/dgnc_cls.h b/drivers/staging/dgnc/dgnc_cls.h
index 9dfa9682a897..d31508542261 100644
--- a/drivers/staging/dgnc/dgnc_cls.h
+++ b/drivers/staging/dgnc/dgnc_cls.h
@@ -1,16 +1,7 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * Copyright 2003 Digi International (www.digi.com) 3 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com> 4 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */ 5 */
15 6
16#ifndef _DGNC_CLS_H 7#ifndef _DGNC_CLS_H
diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c
index d9bf5da1b8e5..5d8c2d995dcc 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright 2003 Digi International (www.digi.com) 3 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com> 4 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */ 5 */
15 6
16#include <linux/kernel.h> 7#include <linux/kernel.h>
@@ -19,37 +10,34 @@
19#include <linux/slab.h> 10#include <linux/slab.h>
20#include <linux/sched.h> 11#include <linux/sched.h>
21#include "dgnc_driver.h" 12#include "dgnc_driver.h"
22#include "dgnc_pci.h"
23#include "dgnc_mgmt.h"
24#include "dgnc_tty.h" 13#include "dgnc_tty.h"
25#include "dgnc_cls.h" 14#include "dgnc_cls.h"
26#include "dgnc_neo.h"
27 15
28MODULE_LICENSE("GPL"); 16MODULE_LICENSE("GPL");
29MODULE_AUTHOR("Digi International, http://www.digi.com"); 17MODULE_AUTHOR("Digi International, http://www.digi.com");
30MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line"); 18MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line");
31MODULE_SUPPORTED_DEVICE("dgnc"); 19MODULE_SUPPORTED_DEVICE("dgnc");
32 20
33static const struct file_operations dgnc_board_fops = { 21static unsigned int dgnc_num_boards;
34 .owner = THIS_MODULE,
35 .unlocked_ioctl = dgnc_mgmt_ioctl,
36 .open = dgnc_mgmt_open,
37 .release = dgnc_mgmt_close
38};
39
40uint dgnc_num_boards;
41struct dgnc_board *dgnc_board[MAXBOARDS]; 22struct dgnc_board *dgnc_board[MAXBOARDS];
42DEFINE_SPINLOCK(dgnc_global_lock); 23static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
43DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
44uint dgnc_major;
45int dgnc_poll_tick = 20; /* Poll interval - 20 ms */
46
47static struct class *dgnc_class;
48 24
25static int dgnc_poll_tick = 20; /* Poll interval - 20 ms */
49static ulong dgnc_poll_time; /* Time of next poll */ 26static ulong dgnc_poll_time; /* Time of next poll */
50static uint dgnc_poll_stop; /* Used to tell poller to stop */ 27static uint dgnc_poll_stop; /* Used to tell poller to stop */
51static struct timer_list dgnc_poll_timer; 28static struct timer_list dgnc_poll_timer;
52 29
30#define DIGI_VID 0x114F
31#define PCI_DEVICE_CLASSIC_4_DID 0x0028
32#define PCI_DEVICE_CLASSIC_8_DID 0x0029
33#define PCI_DEVICE_CLASSIC_4_422_DID 0x00D0
34#define PCI_DEVICE_CLASSIC_8_422_DID 0x00D1
35
36#define PCI_DEVICE_CLASSIC_4_PCI_NAME "ClassicBoard 4 PCI"
37#define PCI_DEVICE_CLASSIC_8_PCI_NAME "ClassicBoard 8 PCI"
38#define PCI_DEVICE_CLASSIC_4_422_PCI_NAME "ClassicBoard 4 422 PCI"
39#define PCI_DEVICE_CLASSIC_8_422_PCI_NAME "ClassicBoard 8 422 PCI"
40
53static const struct pci_device_id dgnc_pci_tbl[] = { 41static const struct pci_device_id dgnc_pci_tbl[] = {
54 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_DID), .driver_data = 0}, 42 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_DID), .driver_data = 0},
55 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID), .driver_data = 1}, 43 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID), .driver_data = 1},
@@ -70,19 +58,6 @@ static const struct board_id dgnc_ids[] = {
70 { PCI_DEVICE_CLASSIC_4_422_PCI_NAME, 4, 0 }, 58 { PCI_DEVICE_CLASSIC_4_422_PCI_NAME, 4, 0 },
71 { PCI_DEVICE_CLASSIC_8_PCI_NAME, 8, 0 }, 59 { PCI_DEVICE_CLASSIC_8_PCI_NAME, 8, 0 },
72 { PCI_DEVICE_CLASSIC_8_422_PCI_NAME, 8, 0 }, 60 { PCI_DEVICE_CLASSIC_8_422_PCI_NAME, 8, 0 },
73 { PCI_DEVICE_NEO_4_PCI_NAME, 4, 0 },
74 { PCI_DEVICE_NEO_8_PCI_NAME, 8, 0 },
75 { PCI_DEVICE_NEO_2DB9_PCI_NAME, 2, 0 },
76 { PCI_DEVICE_NEO_2DB9PRI_PCI_NAME, 2, 0 },
77 { PCI_DEVICE_NEO_2RJ45_PCI_NAME, 2, 0 },
78 { PCI_DEVICE_NEO_2RJ45PRI_PCI_NAME, 2, 0 },
79 { PCI_DEVICE_NEO_1_422_PCI_NAME, 1, 0 },
80 { PCI_DEVICE_NEO_1_422_485_PCI_NAME, 1, 0 },
81 { PCI_DEVICE_NEO_2_422_485_PCI_NAME, 2, 0 },
82 { PCI_DEVICE_NEO_EXPRESS_8_PCI_NAME, 8, 1 },
83 { PCI_DEVICE_NEO_EXPRESS_4_PCI_NAME, 4, 1 },
84 { PCI_DEVICE_NEO_EXPRESS_4RJ45_PCI_NAME, 4, 1 },
85 { PCI_DEVICE_NEO_EXPRESS_8RJ45_PCI_NAME, 8, 1 },
86 { NULL, 0, 0 } 61 { NULL, 0, 0 }
87}; 62};
88 63
@@ -101,7 +76,6 @@ static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id)
101{ 76{
102 struct dgnc_board *brd; 77 struct dgnc_board *brd;
103 unsigned int pci_irq; 78 unsigned int pci_irq;
104 int i = 0;
105 int rc = 0; 79 int rc = 0;
106 80
107 brd = kzalloc(sizeof(*brd), GFP_KERNEL); 81 brd = kzalloc(sizeof(*brd), GFP_KERNEL);
@@ -110,16 +84,10 @@ static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id)
110 84
111 /* store the info for the board we've found */ 85 /* store the info for the board we've found */
112 brd->boardnum = dgnc_num_boards; 86 brd->boardnum = dgnc_num_boards;
113 brd->vendor = dgnc_pci_tbl[id].vendor;
114 brd->device = dgnc_pci_tbl[id].device; 87 brd->device = dgnc_pci_tbl[id].device;
115 brd->pdev = pdev; 88 brd->pdev = pdev;
116 brd->pci_bus = pdev->bus->number;
117 brd->pci_slot = PCI_SLOT(pdev->devfn);
118 brd->name = dgnc_ids[id].name; 89 brd->name = dgnc_ids[id].name;
119 brd->maxports = dgnc_ids[id].maxports; 90 brd->maxports = dgnc_ids[id].maxports;
120 if (dgnc_ids[i].is_pci_express)
121 brd->bd_flags |= BD_IS_PCI_EXPRESS;
122 brd->dpastatus = BD_NOFEP;
123 init_waitqueue_head(&brd->state_wait); 91 init_waitqueue_head(&brd->state_wait);
124 92
125 spin_lock_init(&brd->bd_lock); 93 spin_lock_init(&brd->bd_lock);
@@ -127,11 +95,6 @@ static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id)
127 95
128 brd->state = BOARD_FOUND; 96 brd->state = BOARD_FOUND;
129 97
130 /* store which card & revision we have */
131 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
132 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
133 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
134
135 pci_irq = pdev->irq; 98 pci_irq = pdev->irq;
136 brd->irq = pci_irq; 99 brd->irq = pci_irq;
137 100
@@ -140,9 +103,6 @@ static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id)
140 case PCI_DEVICE_CLASSIC_8_DID: 103 case PCI_DEVICE_CLASSIC_8_DID:
141 case PCI_DEVICE_CLASSIC_4_422_DID: 104 case PCI_DEVICE_CLASSIC_4_422_DID:
142 case PCI_DEVICE_CLASSIC_8_422_DID: 105 case PCI_DEVICE_CLASSIC_8_422_DID:
143
144 brd->dpatype = T_CLASSIC | T_PCIBUS;
145
146 /* 106 /*
147 * For PCI ClassicBoards 107 * For PCI ClassicBoards
148 * PCI Local Address (i.e. "resource" number) space 108 * PCI Local Address (i.e. "resource" number) space
@@ -182,9 +142,6 @@ static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id)
182 if (rc < 0) 142 if (rc < 0)
183 goto failed; 143 goto failed;
184 144
185 /* Get and store the board VPD, if it exists */
186 brd->bd_ops->vpd(brd);
187
188 /* 145 /*
189 * Enable Local Interrupt 1 (0x1), 146 * Enable Local Interrupt 1 (0x1),
190 * Local Interrupt 1 Polarity Active high (0x2), 147 * Local Interrupt 1 Polarity Active high (0x2),
@@ -194,55 +151,6 @@ static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id)
194 151
195 break; 152 break;
196 153
197 case PCI_DEVICE_NEO_4_DID:
198 case PCI_DEVICE_NEO_8_DID:
199 case PCI_DEVICE_NEO_2DB9_DID:
200 case PCI_DEVICE_NEO_2DB9PRI_DID:
201 case PCI_DEVICE_NEO_2RJ45_DID:
202 case PCI_DEVICE_NEO_2RJ45PRI_DID:
203 case PCI_DEVICE_NEO_1_422_DID:
204 case PCI_DEVICE_NEO_1_422_485_DID:
205 case PCI_DEVICE_NEO_2_422_485_DID:
206 case PCI_DEVICE_NEO_EXPRESS_8_DID:
207 case PCI_DEVICE_NEO_EXPRESS_4_DID:
208 case PCI_DEVICE_NEO_EXPRESS_4RJ45_DID:
209 case PCI_DEVICE_NEO_EXPRESS_8RJ45_DID:
210
211 /*
212 * This chip is set up 100% when we get to it.
213 * No need to enable global interrupts or anything.
214 */
215 if (brd->bd_flags & BD_IS_PCI_EXPRESS)
216 brd->dpatype = T_NEO_EXPRESS | T_PCIBUS;
217 else
218 brd->dpatype = T_NEO | T_PCIBUS;
219
220 brd->membase = pci_resource_start(pdev, 0);
221 brd->membase_end = pci_resource_end(pdev, 0);
222
223 if (brd->membase & 1)
224 brd->membase &= ~3;
225 else
226 brd->membase &= ~15;
227
228 brd->bd_ops = &dgnc_neo_ops;
229
230 brd->bd_uart_offset = 0x200;
231 brd->bd_dividend = 921600;
232
233 rc = dgnc_do_remap(brd);
234
235 if (rc < 0)
236 goto failed;
237
238 /* Read and store the dvid after remapping */
239 brd->dvid = readb(brd->re_map_membase + 0x8D);
240
241 /* Get and store the board VPD, if it exists */
242 brd->bd_ops->vpd(brd);
243
244 break;
245
246 default: 154 default:
247 dev_err(&brd->pdev->dev, 155 dev_err(&brd->pdev->dev,
248 "Didn't find any compatible Neo/Classic PCI boards.\n"); 156 "Didn't find any compatible Neo/Classic PCI boards.\n");
@@ -273,7 +181,6 @@ static int dgnc_request_irq(struct dgnc_board *brd)
273 dev_err(&brd->pdev->dev, 181 dev_err(&brd->pdev->dev,
274 "Failed to hook IRQ %d\n", brd->irq); 182 "Failed to hook IRQ %d\n", brd->irq);
275 brd->state = BOARD_FAILED; 183 brd->state = BOARD_FAILED;
276 brd->dpastatus = BD_NOFEP;
277 return -ENODEV; 184 return -ENODEV;
278 } 185 }
279 } 186 }
@@ -364,7 +271,6 @@ static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
364 } 271 }
365 272
366 brd->state = BOARD_READY; 273 brd->state = BOARD_READY;
367 brd->dpastatus = BD_RUNNING;
368 274
369 dgnc_board[dgnc_num_boards++] = brd; 275 dgnc_board[dgnc_num_boards++] = brd;
370 276
@@ -388,32 +294,7 @@ static struct pci_driver dgnc_driver = {
388 294
389static int dgnc_start(void) 295static int dgnc_start(void)
390{ 296{
391 int rc = 0;
392 unsigned long flags; 297 unsigned long flags;
393 struct device *dev;
394
395 rc = register_chrdev(0, "dgnc", &dgnc_board_fops);
396 if (rc < 0) {
397 pr_err(DRVSTR ": Can't register dgnc driver device (%d)\n", rc);
398 return rc;
399 }
400 dgnc_major = rc;
401
402 dgnc_class = class_create(THIS_MODULE, "dgnc_mgmt");
403 if (IS_ERR(dgnc_class)) {
404 rc = PTR_ERR(dgnc_class);
405 pr_err(DRVSTR ": Can't create dgnc_mgmt class (%d)\n", rc);
406 goto failed_class;
407 }
408
409 dev = device_create(dgnc_class, NULL,
410 MKDEV(dgnc_major, 0),
411 NULL, "dgnc_mgmt");
412 if (IS_ERR(dev)) {
413 rc = PTR_ERR(dev);
414 pr_err(DRVSTR ": Can't create device (%d)\n", rc);
415 goto failed_device;
416 }
417 298
418 /* Start the poller */ 299 /* Start the poller */
419 spin_lock_irqsave(&dgnc_poll_lock, flags); 300 spin_lock_irqsave(&dgnc_poll_lock, flags);
@@ -425,13 +306,6 @@ static int dgnc_start(void)
425 add_timer(&dgnc_poll_timer); 306 add_timer(&dgnc_poll_timer);
426 307
427 return 0; 308 return 0;
428
429failed_device:
430 class_destroy(dgnc_class);
431failed_class:
432 unregister_chrdev(dgnc_major, "dgnc");
433
434 return rc;
435} 309}
436 310
437/* Free all the memory associated with a board */ 311/* Free all the memory associated with a board */
@@ -495,10 +369,6 @@ static void cleanup(void)
495 /* Turn off poller right away. */ 369 /* Turn off poller right away. */
496 del_timer_sync(&dgnc_poll_timer); 370 del_timer_sync(&dgnc_poll_timer);
497 371
498 device_destroy(dgnc_class, MKDEV(dgnc_major, 0));
499 class_destroy(dgnc_class);
500 unregister_chrdev(dgnc_major, "dgnc");
501
502 for (i = 0; i < dgnc_num_boards; ++i) { 372 for (i = 0; i < dgnc_num_boards; ++i) {
503 dgnc_cleanup_tty(dgnc_board[i]); 373 dgnc_cleanup_tty(dgnc_board[i]);
504 dgnc_cleanup_board(dgnc_board[i]); 374 dgnc_cleanup_board(dgnc_board[i]);
diff --git a/drivers/staging/dgnc/dgnc_driver.h b/drivers/staging/dgnc/dgnc_driver.h
index efdb11a5e27f..b4d9f714c60a 100644
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ b/drivers/staging/dgnc/dgnc_driver.h
@@ -1,16 +1,7 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * Copyright 2003 Digi International (www.digi.com) 3 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com> 4 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */ 5 */
15 6
16#ifndef _DGNC_DRIVER_H 7#ifndef _DGNC_DRIVER_H
@@ -82,42 +73,27 @@ struct board_ops {
82 void (*uart_off)(struct channel_t *ch); 73 void (*uart_off)(struct channel_t *ch);
83 int (*drain)(struct tty_struct *tty, uint seconds); 74 int (*drain)(struct tty_struct *tty, uint seconds);
84 void (*param)(struct tty_struct *tty); 75 void (*param)(struct tty_struct *tty);
85 void (*vpd)(struct dgnc_board *brd);
86 void (*assert_modem_signals)(struct channel_t *ch); 76 void (*assert_modem_signals)(struct channel_t *ch);
87 void (*flush_uart_write)(struct channel_t *ch); 77 void (*flush_uart_write)(struct channel_t *ch);
88 void (*flush_uart_read)(struct channel_t *ch); 78 void (*flush_uart_read)(struct channel_t *ch);
89 void (*disable_receiver)(struct channel_t *ch); 79 void (*disable_receiver)(struct channel_t *ch);
90 void (*enable_receiver)(struct channel_t *ch); 80 void (*enable_receiver)(struct channel_t *ch);
91 void (*send_break)(struct channel_t *ch, int); 81 void (*send_break)(struct channel_t *ch, int msec);
92 void (*send_start_character)(struct channel_t *ch); 82 void (*send_start_character)(struct channel_t *ch);
93 void (*send_stop_character)(struct channel_t *ch); 83 void (*send_stop_character)(struct channel_t *ch);
94 void (*copy_data_from_queue_to_uart)(struct channel_t *ch); 84 void (*copy_data_from_queue_to_uart)(struct channel_t *ch);
95 uint (*get_uart_bytes_left)(struct channel_t *ch); 85 uint (*get_uart_bytes_left)(struct channel_t *ch);
96 void (*send_immediate_char)(struct channel_t *ch, unsigned char); 86 void (*send_immediate_char)(struct channel_t *ch, unsigned char c);
97}; 87};
98 88
99/* Device flag definitions for bd_flags. */
100
101#define BD_IS_PCI_EXPRESS 0x0001 /* Is a PCI Express board */
102
103/** 89/**
104 * struct dgnc_board - Per board information. 90 * struct dgnc_board - Per board information.
105 * @boardnum: Board number (0 - 32). 91 * @boardnum: Board number (0 - 32).
106 * 92 *
107 * @name: Product name. 93 * @name: Product name.
108 * @pdev: Pointer to the pci_dev structure. 94 * @pdev: Pointer to the pci_dev structure.
109 * @bd_flags: Board flags.
110 * @vendor: PCI vendor ID.
111 * @device: PCI device ID. 95 * @device: PCI device ID.
112 * @subvendor: PCI subsystem vendor ID.
113 * @subdevice: PCI subsystem device ID.
114 * @rev: PCI revision ID.
115 * @pci_bus: PCI bus value.
116 * @pci_slot: PCI slot value.
117 * @maxports: Maximum ports this board can handle. 96 * @maxports: Maximum ports this board can handle.
118 * @dvid: Board specific device ID.
119 * @vpd: VPD of this board, if found.
120 * @serial_num: Serial number of this board, if found in VPD.
121 * @bd_lock: Used to protect board. 97 * @bd_lock: Used to protect board.
122 * @bd_intr_lock: Protect poller tasklet and interrupt routine from each other. 98 * @bd_intr_lock: Protect poller tasklet and interrupt routine from each other.
123 * @state: State of the card. 99 * @state: State of the card.
@@ -135,8 +111,6 @@ struct board_ops {
135 * @serial_name: Serial driver name. 111 * @serial_name: Serial driver name.
136 * @print_dirver: Pointer to the print driver. 112 * @print_dirver: Pointer to the print driver.
137 * @print_name: Print driver name. 113 * @print_name: Print driver name.
138 * @dpatype: Board type as defined by DPA.
139 * @dpastatus: Board status as defined by DPA.
140 * @bd_dividend: Board/UART's specific dividend. 114 * @bd_dividend: Board/UART's specific dividend.
141 * @bd_ops: Pointer to board operations structure. 115 * @bd_ops: Pointer to board operations structure.
142 */ 116 */
@@ -144,18 +118,8 @@ struct dgnc_board {
144 int boardnum; 118 int boardnum;
145 char *name; 119 char *name;
146 struct pci_dev *pdev; 120 struct pci_dev *pdev;
147 unsigned long bd_flags;
148 u16 vendor;
149 u16 device; 121 u16 device;
150 u16 subvendor;
151 u16 subdevice;
152 unsigned char rev;
153 uint pci_bus;
154 uint pci_slot;
155 uint maxports; 122 uint maxports;
156 unsigned char dvid;
157 unsigned char vpd[128];
158 unsigned char serial_num[20];
159 123
160 /* used to protect the board */ 124 /* used to protect the board */
161 spinlock_t bd_lock; 125 spinlock_t bd_lock;
@@ -189,9 +153,6 @@ struct dgnc_board {
189 struct tty_driver *print_driver; 153 struct tty_driver *print_driver;
190 char print_name[200]; 154 char print_name[200];
191 155
192 u16 dpatype;
193 u16 dpastatus;
194
195 uint bd_dividend; 156 uint bd_dividend;
196 157
197 struct board_ops *bd_ops; 158 struct board_ops *bd_ops;
@@ -285,7 +246,6 @@ struct un_t {
285 * @ch_wopen: Waiting for open process count. 246 * @ch_wopen: Waiting for open process count.
286 * @ch_mostat: FEP output modem status. 247 * @ch_mostat: FEP output modem status.
287 * @ch_mistat: FEP input modem status. 248 * @ch_mistat: FEP input modem status.
288 * @chc_neo_uart: Pointer to the mapped neo UART struct
289 * @ch_cls_uart: Pointer to the mapped cls UART struct 249 * @ch_cls_uart: Pointer to the mapped cls UART struct
290 * @ch_cached_lsr: Cached value of the LSR register. 250 * @ch_cached_lsr: Cached value of the LSR register.
291 * @ch_rqueue: Read queue buffer, malloc'ed. 251 * @ch_rqueue: Read queue buffer, malloc'ed.
@@ -344,7 +304,6 @@ struct channel_t {
344 unsigned char ch_mostat; 304 unsigned char ch_mostat;
345 unsigned char ch_mistat; 305 unsigned char ch_mistat;
346 306
347 struct neo_uart_struct __iomem *ch_neo_uart;
348 struct cls_uart_struct __iomem *ch_cls_uart; 307 struct cls_uart_struct __iomem *ch_cls_uart;
349 308
350 unsigned char ch_cached_lsr; 309 unsigned char ch_cached_lsr;
@@ -381,11 +340,6 @@ struct channel_t {
381 ulong ch_xoff_sends; 340 ulong ch_xoff_sends;
382}; 341};
383 342
384extern uint dgnc_major; /* Our driver/mgmt major */
385extern int dgnc_poll_tick; /* Poll interval - 20 ms */
386extern spinlock_t dgnc_global_lock; /* Driver global spinlock */
387extern spinlock_t dgnc_poll_lock; /* Poll scheduling lock */
388extern uint dgnc_num_boards; /* Total number of boards */
389extern struct dgnc_board *dgnc_board[MAXBOARDS];/* Array of boards */ 343extern struct dgnc_board *dgnc_board[MAXBOARDS];/* Array of boards */
390 344
391#endif /* _DGNC_DRIVER_H */ 345#endif /* _DGNC_DRIVER_H */
diff --git a/drivers/staging/dgnc/dgnc_mgmt.c b/drivers/staging/dgnc/dgnc_mgmt.c
deleted file mode 100644
index 3ca473b47daf..000000000000
--- a/drivers/staging/dgnc/dgnc_mgmt.c
+++ /dev/null
@@ -1,248 +0,0 @@
1/*
2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */
15
16/*
17 * This file implements the mgmt functionality for the
18 * Neo and ClassicBoard based product lines.
19 */
20
21#include <linux/kernel.h>
22#include <linux/ctype.h>
23#include <linux/sched.h>
24#include <linux/interrupt.h>
25#include <linux/serial_reg.h>
26#include <linux/termios.h>
27#include <linux/uaccess.h>
28
29#include "dgnc_driver.h"
30#include "dgnc_pci.h"
31#include "dgnc_mgmt.h"
32
33/* Our "in use" variables, to enforce 1 open only */
34static int dgnc_mgmt_in_use[MAXMGMTDEVICES];
35
36/**
37 * dgnc_mgmt_open() - Open the mgmt/downld/dpa device.
38 */
39int dgnc_mgmt_open(struct inode *inode, struct file *file)
40{
41 unsigned long flags;
42 unsigned int minor = iminor(inode);
43 int rc = 0;
44
45 spin_lock_irqsave(&dgnc_global_lock, flags);
46
47 if (minor >= MAXMGMTDEVICES) {
48 rc = -ENXIO;
49 goto out;
50 }
51 /* Only allow 1 open at a time on mgmt device */
52 if (dgnc_mgmt_in_use[minor]) {
53 rc = -EBUSY;
54 goto out;
55 }
56 dgnc_mgmt_in_use[minor]++;
57
58out:
59 spin_unlock_irqrestore(&dgnc_global_lock, flags);
60
61 return rc;
62}
63
64/**
65 * dgnc_mgmt_close() - Close the mgmt/dpa device
66 */
67int dgnc_mgmt_close(struct inode *inode, struct file *file)
68{
69 unsigned long flags;
70 unsigned int minor = iminor(inode);
71 int rc = 0;
72
73 spin_lock_irqsave(&dgnc_global_lock, flags);
74
75 if (minor >= MAXMGMTDEVICES) {
76 rc = -ENXIO;
77 goto out;
78 }
79 dgnc_mgmt_in_use[minor] = 0;
80
81out:
82 spin_unlock_irqrestore(&dgnc_global_lock, flags);
83
84 return rc;
85}
86
87/**
88 * dgnc_mgmt_ioctl() - Ioctl the mgmt/dpa device.
89 */
90long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
91{
92 unsigned long flags;
93 void __user *uarg = (void __user *)arg;
94
95 switch (cmd) {
96 case DIGI_GETDD:
97 {
98 /*
99 * This returns the total number of boards
100 * in the system, as well as driver version
101 * and has space for a reserved entry
102 */
103 struct digi_dinfo ddi;
104
105 spin_lock_irqsave(&dgnc_global_lock, flags);
106
107 memset(&ddi, 0, sizeof(ddi));
108 ddi.dinfo_nboards = dgnc_num_boards;
109 sprintf(ddi.dinfo_version, "%s", DG_PART);
110
111 spin_unlock_irqrestore(&dgnc_global_lock, flags);
112
113 if (copy_to_user(uarg, &ddi, sizeof(ddi)))
114 return -EFAULT;
115
116 break;
117 }
118
119 case DIGI_GETBD:
120 {
121 int brd;
122
123 struct digi_info di;
124
125 if (copy_from_user(&brd, uarg, sizeof(int)))
126 return -EFAULT;
127
128 if (brd < 0 || brd >= dgnc_num_boards)
129 return -ENODEV;
130
131 memset(&di, 0, sizeof(di));
132
133 di.info_bdnum = brd;
134
135 spin_lock_irqsave(&dgnc_board[brd]->bd_lock, flags);
136
137 di.info_bdtype = dgnc_board[brd]->dpatype;
138 di.info_bdstate = dgnc_board[brd]->dpastatus;
139 di.info_ioport = 0;
140 di.info_physaddr = (ulong)dgnc_board[brd]->membase;
141 di.info_physsize = (ulong)dgnc_board[brd]->membase
142 - dgnc_board[brd]->membase_end;
143 if (dgnc_board[brd]->state != BOARD_FAILED)
144 di.info_nports = dgnc_board[brd]->nasync;
145 else
146 di.info_nports = 0;
147
148 spin_unlock_irqrestore(&dgnc_board[brd]->bd_lock, flags);
149
150 if (copy_to_user(uarg, &di, sizeof(di)))
151 return -EFAULT;
152
153 break;
154 }
155
156 case DIGI_GET_NI_INFO:
157 {
158 struct channel_t *ch;
159 struct ni_info ni;
160 unsigned char mstat = 0;
161 uint board = 0;
162 uint channel = 0;
163
164 if (copy_from_user(&ni, uarg, sizeof(ni)))
165 return -EFAULT;
166
167 board = ni.board;
168 channel = ni.channel;
169
170 if (board >= dgnc_num_boards)
171 return -ENODEV;
172
173 if (channel >= dgnc_board[board]->nasync)
174 return -ENODEV;
175
176 ch = dgnc_board[board]->channels[channel];
177
178 if (!ch)
179 return -ENODEV;
180
181 memset(&ni, 0, sizeof(ni));
182 ni.board = board;
183 ni.channel = channel;
184
185 spin_lock_irqsave(&ch->ch_lock, flags);
186
187 mstat = ch->ch_mostat | ch->ch_mistat;
188
189 if (mstat & UART_MCR_DTR) {
190 ni.mstat |= TIOCM_DTR;
191 ni.dtr = TIOCM_DTR;
192 }
193 if (mstat & UART_MCR_RTS) {
194 ni.mstat |= TIOCM_RTS;
195 ni.rts = TIOCM_RTS;
196 }
197 if (mstat & UART_MSR_CTS) {
198 ni.mstat |= TIOCM_CTS;
199 ni.cts = TIOCM_CTS;
200 }
201 if (mstat & UART_MSR_RI) {
202 ni.mstat |= TIOCM_RI;
203 ni.ri = TIOCM_RI;
204 }
205 if (mstat & UART_MSR_DCD) {
206 ni.mstat |= TIOCM_CD;
207 ni.dcd = TIOCM_CD;
208 }
209 if (mstat & UART_MSR_DSR)
210 ni.mstat |= TIOCM_DSR;
211
212 ni.iflag = ch->ch_c_iflag;
213 ni.oflag = ch->ch_c_oflag;
214 ni.cflag = ch->ch_c_cflag;
215 ni.lflag = ch->ch_c_lflag;
216
217 if (ch->ch_digi.digi_flags & CTSPACE ||
218 ch->ch_c_cflag & CRTSCTS)
219 ni.hflow = 1;
220 else
221 ni.hflow = 0;
222
223 if ((ch->ch_flags & CH_STOPI) ||
224 (ch->ch_flags & CH_FORCED_STOPI))
225 ni.recv_stopped = 1;
226 else
227 ni.recv_stopped = 0;
228
229 if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_FORCED_STOP))
230 ni.xmit_stopped = 1;
231 else
232 ni.xmit_stopped = 0;
233
234 ni.curtx = ch->ch_txcount;
235 ni.currx = ch->ch_rxcount;
236
237 ni.baud = ch->ch_old_baud;
238
239 spin_unlock_irqrestore(&ch->ch_lock, flags);
240
241 if (copy_to_user(uarg, &ni, sizeof(ni)))
242 return -EFAULT;
243
244 break;
245 }
246 }
247 return 0;
248}
diff --git a/drivers/staging/dgnc/dgnc_mgmt.h b/drivers/staging/dgnc/dgnc_mgmt.h
deleted file mode 100644
index a7a5770d7630..000000000000
--- a/drivers/staging/dgnc/dgnc_mgmt.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/*
2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */
15
16#ifndef _DGNC_MGMT_H
17#define _DGNC_MGMT_H
18
19#define MAXMGMTDEVICES 8
20
21int dgnc_mgmt_open(struct inode *inode, struct file *file);
22int dgnc_mgmt_close(struct inode *inode, struct file *file);
23long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
24
25#endif /* _DGNC_MGMT_H */
26
diff --git a/drivers/staging/dgnc/dgnc_neo.c b/drivers/staging/dgnc/dgnc_neo.c
deleted file mode 100644
index 0ae229c3aaaa..000000000000
--- a/drivers/staging/dgnc/dgnc_neo.c
+++ /dev/null
@@ -1,1690 +0,0 @@
1/*
2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */
15
16#include <linux/kernel.h>
17#include <linux/sched.h>
18#include <linux/interrupt.h>
19#include <linux/delay.h>
20#include <linux/io.h>
21#include <linux/serial.h>
22#include <linux/serial_reg.h>
23
24#include "dgnc_driver.h"
25#include "dgnc_neo.h"
26#include "dgnc_tty.h"
27
28static inline void neo_parse_lsr(struct dgnc_board *brd, uint port);
29static inline void neo_parse_isr(struct dgnc_board *brd, uint port);
30static void neo_copy_data_from_uart_to_queue(struct channel_t *ch);
31static inline void neo_clear_break(struct channel_t *ch, int force);
32static inline void neo_set_cts_flow_control(struct channel_t *ch);
33static inline void neo_set_rts_flow_control(struct channel_t *ch);
34static inline void neo_set_ixon_flow_control(struct channel_t *ch);
35static inline void neo_set_ixoff_flow_control(struct channel_t *ch);
36static inline void neo_set_no_output_flow_control(struct channel_t *ch);
37static inline void neo_set_no_input_flow_control(struct channel_t *ch);
38static inline void neo_set_new_start_stop_chars(struct channel_t *ch);
39static void neo_parse_modem(struct channel_t *ch, unsigned char signals);
40static void neo_tasklet(unsigned long data);
41static void neo_vpd(struct dgnc_board *brd);
42static void neo_uart_init(struct channel_t *ch);
43static void neo_uart_off(struct channel_t *ch);
44static int neo_drain(struct tty_struct *tty, uint seconds);
45static void neo_param(struct tty_struct *tty);
46static void neo_assert_modem_signals(struct channel_t *ch);
47static void neo_flush_uart_write(struct channel_t *ch);
48static void neo_flush_uart_read(struct channel_t *ch);
49static void neo_disable_receiver(struct channel_t *ch);
50static void neo_enable_receiver(struct channel_t *ch);
51static void neo_send_break(struct channel_t *ch, int msecs);
52static void neo_send_start_character(struct channel_t *ch);
53static void neo_send_stop_character(struct channel_t *ch);
54static void neo_copy_data_from_queue_to_uart(struct channel_t *ch);
55static uint neo_get_uart_bytes_left(struct channel_t *ch);
56static void neo_send_immediate_char(struct channel_t *ch, unsigned char c);
57static irqreturn_t neo_intr(int irq, void *voidbrd);
58
59struct board_ops dgnc_neo_ops = {
60 .tasklet = neo_tasklet,
61 .intr = neo_intr,
62 .uart_init = neo_uart_init,
63 .uart_off = neo_uart_off,
64 .drain = neo_drain,
65 .param = neo_param,
66 .vpd = neo_vpd,
67 .assert_modem_signals = neo_assert_modem_signals,
68 .flush_uart_write = neo_flush_uart_write,
69 .flush_uart_read = neo_flush_uart_read,
70 .disable_receiver = neo_disable_receiver,
71 .enable_receiver = neo_enable_receiver,
72 .send_break = neo_send_break,
73 .send_start_character = neo_send_start_character,
74 .send_stop_character = neo_send_stop_character,
75 .copy_data_from_queue_to_uart = neo_copy_data_from_queue_to_uart,
76 .get_uart_bytes_left = neo_get_uart_bytes_left,
77 .send_immediate_char = neo_send_immediate_char
78};
79
80/*
81 * This function allows calls to ensure that all outstanding
82 * PCI writes have been completed, by doing a PCI read against
83 * a non-destructive, read-only location on the Neo card.
84 *
85 * In this case, we are reading the DVID (Read-only Device Identification)
86 * value of the Neo card.
87 */
88static inline void neo_pci_posting_flush(struct dgnc_board *bd)
89{
90 readb(bd->re_map_membase + 0x8D);
91}
92
93static inline void neo_set_cts_flow_control(struct channel_t *ch)
94{
95 unsigned char ier = readb(&ch->ch_neo_uart->ier);
96 unsigned char efr = readb(&ch->ch_neo_uart->efr);
97
98 /* Turn on auto CTS flow control */
99 ier |= UART_17158_IER_CTSDSR;
100 efr |= (UART_17158_EFR_ECB | UART_17158_EFR_CTSDSR);
101
102 /* Turn off auto Xon flow control */
103 efr &= ~UART_17158_EFR_IXON;
104
105 /*
106 * Why? Because Exar's spec says we have to zero it
107 * out before setting it
108 */
109 writeb(0, &ch->ch_neo_uart->efr);
110
111 /* Turn on UART enhanced bits */
112 writeb(efr, &ch->ch_neo_uart->efr);
113
114 /* Turn on table D, with 8 char hi/low watermarks */
115 writeb(UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY,
116 &ch->ch_neo_uart->fctr);
117
118 /* Feed the UART our trigger levels */
119 writeb(8, &ch->ch_neo_uart->tfifo);
120 ch->ch_t_tlevel = 8;
121
122 writeb(ier, &ch->ch_neo_uart->ier);
123
124 neo_pci_posting_flush(ch->ch_bd);
125}
126
127static inline void neo_set_rts_flow_control(struct channel_t *ch)
128{
129 unsigned char ier = readb(&ch->ch_neo_uart->ier);
130 unsigned char efr = readb(&ch->ch_neo_uart->efr);
131
132 /* Turn on auto RTS flow control */
133 ier |= UART_17158_IER_RTSDTR;
134 efr |= (UART_17158_EFR_ECB | UART_17158_EFR_RTSDTR);
135
136 /* Turn off auto Xoff flow control */
137 ier &= ~UART_17158_IER_XOFF;
138 efr &= ~UART_17158_EFR_IXOFF;
139
140 /*
141 * Why? Because Exar's spec says we have to zero it
142 * out before setting it
143 */
144 writeb(0, &ch->ch_neo_uart->efr);
145
146 /* Turn on UART enhanced bits */
147 writeb(efr, &ch->ch_neo_uart->efr);
148
149 writeb(UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY,
150 &ch->ch_neo_uart->fctr);
151 ch->ch_r_watermark = 4;
152
153 writeb(32, &ch->ch_neo_uart->rfifo);
154 ch->ch_r_tlevel = 32;
155
156 writeb(ier, &ch->ch_neo_uart->ier);
157
158 /*
159 * From the Neo UART spec sheet:
160 * The auto RTS/DTR function must be started by asserting
161 * RTS/DTR# output pin (MCR bit-0 or 1 to logic 1 after
162 * it is enabled.
163 */
164 ch->ch_mostat |= UART_MCR_RTS;
165
166 neo_pci_posting_flush(ch->ch_bd);
167}
168
169static inline void neo_set_ixon_flow_control(struct channel_t *ch)
170{
171 unsigned char ier = readb(&ch->ch_neo_uart->ier);
172 unsigned char efr = readb(&ch->ch_neo_uart->efr);
173
174 /* Turn off auto CTS flow control */
175 ier &= ~UART_17158_IER_CTSDSR;
176 efr &= ~UART_17158_EFR_CTSDSR;
177
178 /* Turn on auto Xon flow control */
179 efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXON);
180
181 /*
182 * Why? Because Exar's spec says we have to zero it
183 * out before setting it
184 */
185 writeb(0, &ch->ch_neo_uart->efr);
186
187 /* Turn on UART enhanced bits */
188 writeb(efr, &ch->ch_neo_uart->efr);
189
190 writeb(UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY,
191 &ch->ch_neo_uart->fctr);
192 ch->ch_r_watermark = 4;
193
194 writeb(32, &ch->ch_neo_uart->rfifo);
195 ch->ch_r_tlevel = 32;
196
197 /* Tell UART what start/stop chars it should be looking for */
198 writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
199 writeb(0, &ch->ch_neo_uart->xonchar2);
200
201 writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
202 writeb(0, &ch->ch_neo_uart->xoffchar2);
203
204 writeb(ier, &ch->ch_neo_uart->ier);
205
206 neo_pci_posting_flush(ch->ch_bd);
207}
208
209static inline void neo_set_ixoff_flow_control(struct channel_t *ch)
210{
211 unsigned char ier = readb(&ch->ch_neo_uart->ier);
212 unsigned char efr = readb(&ch->ch_neo_uart->efr);
213
214 /* Turn off auto RTS flow control */
215 ier &= ~UART_17158_IER_RTSDTR;
216 efr &= ~UART_17158_EFR_RTSDTR;
217
218 /* Turn on auto Xoff flow control */
219 ier |= UART_17158_IER_XOFF;
220 efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
221
222 /*
223 * Why? Because Exar's spec says we have to zero it
224 * out before setting it
225 */
226 writeb(0, &ch->ch_neo_uart->efr);
227
228 /* Turn on UART enhanced bits */
229 writeb(efr, &ch->ch_neo_uart->efr);
230
231 /* Turn on table D, with 8 char hi/low watermarks */
232 writeb(UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY,
233 &ch->ch_neo_uart->fctr);
234
235 writeb(8, &ch->ch_neo_uart->tfifo);
236 ch->ch_t_tlevel = 8;
237
238 /* Tell UART what start/stop chars it should be looking for */
239 writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
240 writeb(0, &ch->ch_neo_uart->xonchar2);
241
242 writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
243 writeb(0, &ch->ch_neo_uart->xoffchar2);
244
245 writeb(ier, &ch->ch_neo_uart->ier);
246
247 neo_pci_posting_flush(ch->ch_bd);
248}
249
250static inline void neo_set_no_input_flow_control(struct channel_t *ch)
251{
252 unsigned char ier = readb(&ch->ch_neo_uart->ier);
253 unsigned char efr = readb(&ch->ch_neo_uart->efr);
254
255 /* Turn off auto RTS flow control */
256 ier &= ~UART_17158_IER_RTSDTR;
257 efr &= ~UART_17158_EFR_RTSDTR;
258
259 /* Turn off auto Xoff flow control */
260 ier &= ~UART_17158_IER_XOFF;
261 if (ch->ch_c_iflag & IXON)
262 efr &= ~(UART_17158_EFR_IXOFF);
263 else
264 efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
265
266 /*
267 * Why? Because Exar's spec says we have to zero
268 * it out before setting it
269 */
270 writeb(0, &ch->ch_neo_uart->efr);
271
272 /* Turn on UART enhanced bits */
273 writeb(efr, &ch->ch_neo_uart->efr);
274
275 /* Turn on table D, with 8 char hi/low watermarks */
276 writeb(UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY,
277 &ch->ch_neo_uart->fctr);
278
279 ch->ch_r_watermark = 0;
280
281 writeb(16, &ch->ch_neo_uart->tfifo);
282 ch->ch_t_tlevel = 16;
283
284 writeb(16, &ch->ch_neo_uart->rfifo);
285 ch->ch_r_tlevel = 16;
286
287 writeb(ier, &ch->ch_neo_uart->ier);
288
289 neo_pci_posting_flush(ch->ch_bd);
290}
291
292static inline void neo_set_no_output_flow_control(struct channel_t *ch)
293{
294 unsigned char ier = readb(&ch->ch_neo_uart->ier);
295 unsigned char efr = readb(&ch->ch_neo_uart->efr);
296
297 /* Turn off auto CTS flow control */
298 ier &= ~UART_17158_IER_CTSDSR;
299 efr &= ~UART_17158_EFR_CTSDSR;
300
301 /* Turn off auto Xon flow control */
302 if (ch->ch_c_iflag & IXOFF)
303 efr &= ~UART_17158_EFR_IXON;
304 else
305 efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXON);
306
307 /*
308 * Why? Because Exar's spec says we have to zero it
309 * out before setting it
310 */
311 writeb(0, &ch->ch_neo_uart->efr);
312
313 /* Turn on UART enhanced bits */
314 writeb(efr, &ch->ch_neo_uart->efr);
315
316 /* Turn on table D, with 8 char hi/low watermarks */
317 writeb(UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY,
318 &ch->ch_neo_uart->fctr);
319
320 ch->ch_r_watermark = 0;
321
322 writeb(16, &ch->ch_neo_uart->tfifo);
323 ch->ch_t_tlevel = 16;
324
325 writeb(16, &ch->ch_neo_uart->rfifo);
326 ch->ch_r_tlevel = 16;
327
328 writeb(ier, &ch->ch_neo_uart->ier);
329
330 neo_pci_posting_flush(ch->ch_bd);
331}
332
333/* change UARTs start/stop chars */
334static inline void neo_set_new_start_stop_chars(struct channel_t *ch)
335{
336 /* if hardware flow control is set, then skip this whole thing */
337 if (ch->ch_digi.digi_flags & (CTSPACE | RTSPACE) ||
338 ch->ch_c_cflag & CRTSCTS)
339 return;
340
341 /* Tell UART what start/stop chars it should be looking for */
342 writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
343 writeb(0, &ch->ch_neo_uart->xonchar2);
344
345 writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
346 writeb(0, &ch->ch_neo_uart->xoffchar2);
347
348 neo_pci_posting_flush(ch->ch_bd);
349}
350
351/* No locks are assumed to be held when calling this function. */
352static inline void neo_clear_break(struct channel_t *ch, int force)
353{
354 unsigned long flags;
355
356 spin_lock_irqsave(&ch->ch_lock, flags);
357
358 if (!ch->ch_stop_sending_break) {
359 spin_unlock_irqrestore(&ch->ch_lock, flags);
360 return;
361 }
362
363 if (ch->ch_flags & CH_BREAK_SENDING) {
364 if (force ||
365 time_after_eq(jiffies, ch->ch_stop_sending_break)) {
366 unsigned char temp = readb(&ch->ch_neo_uart->lcr);
367
368 writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
369 neo_pci_posting_flush(ch->ch_bd);
370 ch->ch_flags &= ~(CH_BREAK_SENDING);
371 ch->ch_stop_sending_break = 0;
372 }
373 }
374 spin_unlock_irqrestore(&ch->ch_lock, flags);
375}
376
377/* Parse the ISR register. */
378static inline void neo_parse_isr(struct dgnc_board *brd, uint port)
379{
380 struct channel_t *ch;
381 unsigned char isr;
382 unsigned char cause;
383 unsigned long flags;
384
385 ch = brd->channels[port];
386 if (!ch)
387 return;
388
389 /* Here we try to figure out what caused the interrupt to happen */
390 while (1) {
391 isr = readb(&ch->ch_neo_uart->isr_fcr);
392
393 if (isr & UART_IIR_NO_INT)
394 break;
395
396 /*
397 * Yank off the upper 2 bits,
398 * which just show that the FIFO's are enabled.
399 */
400 isr &= ~(UART_17158_IIR_FIFO_ENABLED);
401
402 if (isr & (UART_17158_IIR_RDI_TIMEOUT | UART_IIR_RDI)) {
403 /* Read data from uart -> queue */
404 neo_copy_data_from_uart_to_queue(ch);
405 /*
406 * Call our tty layer to enforce queue
407 * flow control if needed.
408 */
409 spin_lock_irqsave(&ch->ch_lock, flags);
410 dgnc_check_queue_flow_control(ch);
411 spin_unlock_irqrestore(&ch->ch_lock, flags);
412 }
413
414 if (isr & UART_IIR_THRI) {
415 spin_lock_irqsave(&ch->ch_lock, flags);
416 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
417 spin_unlock_irqrestore(&ch->ch_lock, flags);
418 neo_copy_data_from_queue_to_uart(ch);
419 }
420
421 if (isr & UART_17158_IIR_XONXOFF) {
422 cause = readb(&ch->ch_neo_uart->xoffchar1);
423
424 /*
425 * Since the UART detected either an XON or
426 * XOFF match, we need to figure out which
427 * one it was, so we can suspend or resume data flow.
428 */
429 if (cause == UART_17158_XON_DETECT) {
430 /* resume output if stopped */
431 if (brd->channels[port]->ch_flags & CH_STOP) {
432 spin_lock_irqsave(&ch->ch_lock,
433 flags);
434 ch->ch_flags &= ~(CH_STOP);
435 spin_unlock_irqrestore(&ch->ch_lock,
436 flags);
437 }
438 } else if (cause == UART_17158_XOFF_DETECT) {
439 if (!(brd->channels[port]->ch_flags &
440 CH_STOP)) {
441 spin_lock_irqsave(&ch->ch_lock,
442 flags);
443 ch->ch_flags |= CH_STOP;
444 spin_unlock_irqrestore(&ch->ch_lock,
445 flags);
446 }
447 }
448 }
449
450 if (isr & UART_17158_IIR_HWFLOW_STATE_CHANGE) {
451 /*
452 * If we get here, this means the hardware is
453 * doing auto flow control. Check to see whether
454 * RTS/DTR or CTS/DSR caused this interrupt.
455 */
456 cause = readb(&ch->ch_neo_uart->mcr);
457 /* Which pin is doing auto flow? RTS or DTR? */
458 if ((cause & 0x4) == 0) {
459 if (cause & UART_MCR_RTS) {
460 spin_lock_irqsave(&ch->ch_lock,
461 flags);
462 ch->ch_mostat |= UART_MCR_RTS;
463 spin_unlock_irqrestore(&ch->ch_lock,
464 flags);
465 } else {
466 spin_lock_irqsave(&ch->ch_lock,
467 flags);
468 ch->ch_mostat &= ~(UART_MCR_RTS);
469 spin_unlock_irqrestore(&ch->ch_lock,
470 flags);
471 }
472 } else {
473 if (cause & UART_MCR_DTR) {
474 spin_lock_irqsave(&ch->ch_lock,
475 flags);
476 ch->ch_mostat |= UART_MCR_DTR;
477 spin_unlock_irqrestore(&ch->ch_lock,
478 flags);
479 } else {
480 spin_lock_irqsave(&ch->ch_lock,
481 flags);
482 ch->ch_mostat &= ~(UART_MCR_DTR);
483 spin_unlock_irqrestore(&ch->ch_lock,
484 flags);
485 }
486 }
487 }
488
489 neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
490 }
491}
492
493static inline void neo_parse_lsr(struct dgnc_board *brd, uint port)
494{
495 struct channel_t *ch;
496 int linestatus;
497 unsigned long flags;
498
499 if (!brd)
500 return;
501
502 if (port >= brd->maxports)
503 return;
504
505 ch = brd->channels[port];
506 if (!ch)
507 return;
508
509 linestatus = readb(&ch->ch_neo_uart->lsr);
510
511 ch->ch_cached_lsr |= linestatus;
512
513 if (ch->ch_cached_lsr & UART_LSR_DR) {
514 neo_copy_data_from_uart_to_queue(ch);
515 spin_lock_irqsave(&ch->ch_lock, flags);
516 dgnc_check_queue_flow_control(ch);
517 spin_unlock_irqrestore(&ch->ch_lock, flags);
518 }
519
520 /*
521 * The next 3 tests should *NOT* happen, as the above test
522 * should encapsulate all 3... At least, thats what Exar says.
523 */
524
525 if (linestatus & UART_LSR_PE)
526 ch->ch_err_parity++;
527
528 if (linestatus & UART_LSR_FE)
529 ch->ch_err_frame++;
530
531 if (linestatus & UART_LSR_BI)
532 ch->ch_err_break++;
533
534 if (linestatus & UART_LSR_OE) {
535 /*
536 * Rx Oruns. Exar says that an orun will NOT corrupt
537 * the FIFO. It will just replace the holding register
538 * with this new data byte. So basically just ignore this.
539 * Probably we should eventually have an orun stat in our
540 * driver...
541 */
542 ch->ch_err_overrun++;
543 }
544
545 if (linestatus & UART_LSR_THRE) {
546 spin_lock_irqsave(&ch->ch_lock, flags);
547 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
548 spin_unlock_irqrestore(&ch->ch_lock, flags);
549
550 neo_copy_data_from_queue_to_uart(ch);
551 } else if (linestatus & UART_17158_TX_AND_FIFO_CLR) {
552 spin_lock_irqsave(&ch->ch_lock, flags);
553 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
554 spin_unlock_irqrestore(&ch->ch_lock, flags);
555
556 neo_copy_data_from_queue_to_uart(ch);
557 }
558}
559
560/* Send any/all changes to the line to the UART. */
561static void neo_param(struct tty_struct *tty)
562{
563 unsigned char lcr = 0;
564 unsigned char uart_lcr = 0;
565 unsigned char ier = 0;
566 unsigned char uart_ier = 0;
567 uint baud = 9600;
568 int quot = 0;
569 struct dgnc_board *bd;
570 struct channel_t *ch;
571 struct un_t *un;
572
573 if (!tty)
574 return;
575
576 un = (struct un_t *)tty->driver_data;
577 if (!un)
578 return;
579
580 ch = un->un_ch;
581 if (!ch)
582 return;
583
584 bd = ch->ch_bd;
585 if (!bd)
586 return;
587
588 /* If baud rate is zero, flush queues, and set mval to drop DTR. */
589 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
590 ch->ch_r_head = 0;
591 ch->ch_r_tail = 0;
592 ch->ch_e_head = 0;
593 ch->ch_e_tail = 0;
594 ch->ch_w_head = 0;
595 ch->ch_w_tail = 0;
596
597 neo_flush_uart_write(ch);
598 neo_flush_uart_read(ch);
599
600 /* The baudrate is B0 so all modem lines are to be dropped. */
601 ch->ch_flags |= (CH_BAUD0);
602 ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
603 neo_assert_modem_signals(ch);
604 ch->ch_old_baud = 0;
605 return;
606
607 } else if (ch->ch_custom_speed) {
608 baud = ch->ch_custom_speed;
609 /* Handle transition from B0 */
610 if (ch->ch_flags & CH_BAUD0) {
611 ch->ch_flags &= ~(CH_BAUD0);
612
613 /*
614 * Bring back up RTS and DTR...
615 * Also handle RTS or DTR toggle if set.
616 */
617 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
618 ch->ch_mostat |= (UART_MCR_RTS);
619 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
620 ch->ch_mostat |= (UART_MCR_DTR);
621 }
622 } else {
623 int iindex = 0;
624 int jindex = 0;
625
626 ulong bauds[4][16] = {
627 { /* slowbaud */
628 0, 50, 75, 110,
629 134, 150, 200, 300,
630 600, 1200, 1800, 2400,
631 4800, 9600, 19200, 38400 },
632 { /* slowbaud & CBAUDEX */
633 0, 57600, 115200, 230400,
634 460800, 150, 200, 921600,
635 600, 1200, 1800, 2400,
636 4800, 9600, 19200, 38400 },
637 { /* fastbaud */
638 0, 57600, 76800, 115200,
639 131657, 153600, 230400, 460800,
640 921600, 1200, 1800, 2400,
641 4800, 9600, 19200, 38400 },
642 { /* fastbaud & CBAUDEX */
643 0, 57600, 115200, 230400,
644 460800, 150, 200, 921600,
645 600, 1200, 1800, 2400,
646 4800, 9600, 19200, 38400 }
647 };
648
649 /*
650 * Only use the TXPrint baud rate if the terminal unit
651 * is NOT open
652 */
653 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
654 (un->un_type == DGNC_PRINT))
655 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
656 else
657 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
658
659 if (ch->ch_c_cflag & CBAUDEX)
660 iindex = 1;
661
662 if (ch->ch_digi.digi_flags & DIGI_FAST)
663 iindex += 2;
664
665 jindex = baud;
666
667 if ((iindex >= 0) && (iindex < 4) &&
668 (jindex >= 0) && (jindex < 16))
669 baud = bauds[iindex][jindex];
670 else
671 baud = 0;
672
673 if (baud == 0)
674 baud = 9600;
675
676 /* Handle transition from B0 */
677 if (ch->ch_flags & CH_BAUD0) {
678 ch->ch_flags &= ~(CH_BAUD0);
679
680 /*
681 * Bring back up RTS and DTR...
682 * Also handle RTS or DTR toggle if set.
683 */
684 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
685 ch->ch_mostat |= (UART_MCR_RTS);
686 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
687 ch->ch_mostat |= (UART_MCR_DTR);
688 }
689 }
690
691 if (ch->ch_c_cflag & PARENB)
692 lcr |= UART_LCR_PARITY;
693
694 if (!(ch->ch_c_cflag & PARODD))
695 lcr |= UART_LCR_EPAR;
696
697#ifdef CMSPAR
698 if (ch->ch_c_cflag & CMSPAR)
699 lcr |= UART_LCR_SPAR;
700#endif
701
702 if (ch->ch_c_cflag & CSTOPB)
703 lcr |= UART_LCR_STOP;
704
705 switch (ch->ch_c_cflag & CSIZE) {
706 case CS5:
707 lcr |= UART_LCR_WLEN5;
708 break;
709 case CS6:
710 lcr |= UART_LCR_WLEN6;
711 break;
712 case CS7:
713 lcr |= UART_LCR_WLEN7;
714 break;
715 case CS8:
716 default:
717 lcr |= UART_LCR_WLEN8;
718 break;
719 }
720
721 uart_ier = readb(&ch->ch_neo_uart->ier);
722 ier = uart_ier;
723
724 uart_lcr = readb(&ch->ch_neo_uart->lcr);
725
726 if (baud == 0)
727 baud = 9600;
728
729 quot = ch->ch_bd->bd_dividend / baud;
730
731 if (quot != 0 && ch->ch_old_baud != baud) {
732 ch->ch_old_baud = baud;
733 writeb(UART_LCR_DLAB, &ch->ch_neo_uart->lcr);
734 writeb((quot & 0xff), &ch->ch_neo_uart->txrx);
735 writeb((quot >> 8), &ch->ch_neo_uart->ier);
736 writeb(lcr, &ch->ch_neo_uart->lcr);
737 }
738
739 if (uart_lcr != lcr)
740 writeb(lcr, &ch->ch_neo_uart->lcr);
741
742 if (ch->ch_c_cflag & CREAD)
743 ier |= (UART_IER_RDI | UART_IER_RLSI);
744 else
745 ier &= ~(UART_IER_RDI | UART_IER_RLSI);
746
747 /*
748 * Have the UART interrupt on modem signal changes ONLY when
749 * we are in hardware flow control mode, or CLOCAL/FORCEDCD is not set.
750 */
751 if ((ch->ch_digi.digi_flags & CTSPACE) ||
752 (ch->ch_digi.digi_flags & RTSPACE) ||
753 (ch->ch_c_cflag & CRTSCTS) ||
754 !(ch->ch_digi.digi_flags & DIGI_FORCEDCD) ||
755 !(ch->ch_c_cflag & CLOCAL))
756 ier |= UART_IER_MSI;
757 else
758 ier &= ~UART_IER_MSI;
759
760 ier |= UART_IER_THRI;
761
762 if (ier != uart_ier)
763 writeb(ier, &ch->ch_neo_uart->ier);
764
765 neo_set_new_start_stop_chars(ch);
766
767 if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) {
768 neo_set_cts_flow_control(ch);
769 } else if (ch->ch_c_iflag & IXON) {
770 if ((ch->ch_startc == _POSIX_VDISABLE) ||
771 (ch->ch_stopc == _POSIX_VDISABLE))
772 neo_set_no_output_flow_control(ch);
773 else
774 neo_set_ixon_flow_control(ch);
775 } else {
776 neo_set_no_output_flow_control(ch);
777 }
778
779 if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) {
780 neo_set_rts_flow_control(ch);
781 } else if (ch->ch_c_iflag & IXOFF) {
782 if ((ch->ch_startc == _POSIX_VDISABLE) ||
783 (ch->ch_stopc == _POSIX_VDISABLE))
784 neo_set_no_input_flow_control(ch);
785 else
786 neo_set_ixoff_flow_control(ch);
787 } else {
788 neo_set_no_input_flow_control(ch);
789 }
790
791 /*
792 * Adjust the RX FIFO Trigger level if baud is less than 9600.
793 * Not exactly elegant, but this is needed because of the Exar chip's
794 * delay on firing off the RX FIFO interrupt on slower baud rates.
795 */
796 if (baud < 9600) {
797 writeb(1, &ch->ch_neo_uart->rfifo);
798 ch->ch_r_tlevel = 1;
799 }
800
801 neo_assert_modem_signals(ch);
802
803 neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
804}
805
806/* Board poller function. */
807static void neo_tasklet(unsigned long data)
808{
809 struct dgnc_board *bd = (struct dgnc_board *)data;
810 struct channel_t *ch;
811 unsigned long flags;
812 int i;
813 int state = 0;
814 int ports = 0;
815
816 if (!bd)
817 return;
818
819 spin_lock_irqsave(&bd->bd_lock, flags);
820 state = bd->state;
821 ports = bd->nasync;
822 spin_unlock_irqrestore(&bd->bd_lock, flags);
823
824 /*
825 * Do NOT allow the interrupt routine to read the intr registers
826 * Until we release this lock.
827 */
828 spin_lock_irqsave(&bd->bd_intr_lock, flags);
829
830 if ((state == BOARD_READY) && (ports > 0)) {
831 for (i = 0; i < ports; i++) {
832 ch = bd->channels[i];
833 if (!ch)
834 continue;
835
836 /*
837 * NOTE: Remember you CANNOT hold any channel
838 * locks when calling the input routine.
839 *
840 * During input processing, its possible we
841 * will call the Linux ld, which might in turn,
842 * do a callback right back into us, resulting
843 * in us trying to grab the channel lock twice!
844 */
845 dgnc_input(ch);
846
847 /*
848 * Channel lock is grabbed and then released
849 * inside both of these routines, but neither
850 * call anything else that could call back into us.
851 */
852 neo_copy_data_from_queue_to_uart(ch);
853 dgnc_wakeup_writes(ch);
854
855 dgnc_carrier(ch);
856
857 /*
858 * Check to see if we need to turn off a sending break.
859 * The timing check is done inside clear_break()
860 */
861 if (ch->ch_stop_sending_break)
862 neo_clear_break(ch, 0);
863 }
864 }
865
866 spin_unlock_irqrestore(&bd->bd_intr_lock, flags);
867}
868
869/* Neo specific interrupt handler. */
870static irqreturn_t neo_intr(int irq, void *voidbrd)
871{
872 struct dgnc_board *brd = voidbrd;
873 struct channel_t *ch;
874 int port = 0;
875 int type;
876 u32 uart_poll;
877 unsigned long flags;
878 unsigned long flags2;
879
880 if (!brd)
881 return IRQ_NONE;
882
883 /* Lock out the slow poller from running on this board. */
884 spin_lock_irqsave(&brd->bd_intr_lock, flags);
885
886 /*
887 * Read in "extended" IRQ information from the 32bit Neo register.
888 * Bits 0-7: What port triggered the interrupt.
889 * Bits 8-31: Each 3bits indicate what type of interrupt occurred.
890 */
891 uart_poll = readl(brd->re_map_membase + UART_17158_POLL_ADDR_OFFSET);
892
893 /*
894 * If 0, no interrupts pending.
895 * This can happen if the IRQ is shared among a couple Neo/Classic
896 * boards.
897 */
898 if (!uart_poll) {
899 spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
900 return IRQ_NONE;
901 }
902
903 while ((uart_poll & 0xff) != 0) {
904 type = uart_poll >> (8 + (port * 3));
905 type &= 0x7;
906
907 uart_poll &= ~(0x01 << port);
908
909 switch (type) {
910 case UART_17158_RXRDY_TIMEOUT:
911 /*
912 * RXRDY Time-out is cleared by reading data in the
913 * RX FIFO until it falls below the trigger level.
914 */
915
916 if (port >= brd->nasync)
917 break;
918
919 ch = brd->channels[port];
920 neo_copy_data_from_uart_to_queue(ch);
921
922 /*
923 * Call our tty layer to enforce queue flow control if
924 * needed.
925 */
926 spin_lock_irqsave(&ch->ch_lock, flags2);
927 dgnc_check_queue_flow_control(ch);
928 spin_unlock_irqrestore(&ch->ch_lock, flags2);
929
930 break;
931
932 case UART_17158_RX_LINE_STATUS:
933
934 /* RXRDY and RX LINE Status (logic OR of LSR[4:1]) */
935
936 neo_parse_lsr(brd, port);
937 break;
938
939 case UART_17158_TXRDY:
940 /*
941 * TXRDY interrupt clears after reading ISR register
942 * for the UART channel.
943 */
944
945 /*
946 * Yes, this is odd...
947 * Why would I check EVERY possibility of type of
948 * interrupt, when we know its TXRDY???
949 * Becuz for some reason, even tho we got triggered for
950 * TXRDY, it seems to be occasionally wrong. Instead of
951 * TX, which it should be, I was getting things like
952 * RXDY too. Weird.
953 */
954 neo_parse_isr(brd, port);
955 break;
956
957 case UART_17158_MSR:
958 /* MSR or flow control was seen. */
959 neo_parse_isr(brd, port);
960 break;
961
962 default:
963 break;
964 }
965
966 port++;
967 }
968
969 tasklet_schedule(&brd->helper_tasklet);
970
971 spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
972
973 return IRQ_HANDLED;
974}
975
976/*
977 * Neo specific way of turning off the receiver.
978 * Used as a way to enforce queue flow control when in
979 * hardware flow control mode.
980 */
981static void neo_disable_receiver(struct channel_t *ch)
982{
983 unsigned char tmp = readb(&ch->ch_neo_uart->ier);
984
985 tmp &= ~(UART_IER_RDI);
986 writeb(tmp, &ch->ch_neo_uart->ier);
987 neo_pci_posting_flush(ch->ch_bd);
988}
989
990/*
991 * Neo specific way of turning on the receiver.
992 * Used as a way to un-enforce queue flow control when in
993 * hardware flow control mode.
994 */
995static void neo_enable_receiver(struct channel_t *ch)
996{
997 unsigned char tmp = readb(&ch->ch_neo_uart->ier);
998
999 tmp |= (UART_IER_RDI);
1000 writeb(tmp, &ch->ch_neo_uart->ier);
1001 neo_pci_posting_flush(ch->ch_bd);
1002}
1003
1004static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
1005{
1006 int qleft = 0;
1007 unsigned char linestatus = 0;
1008 unsigned char error_mask = 0;
1009 int n = 0;
1010 int total = 0;
1011 ushort head;
1012 ushort tail;
1013 unsigned long flags;
1014
1015 if (!ch)
1016 return;
1017
1018 spin_lock_irqsave(&ch->ch_lock, flags);
1019
1020 head = ch->ch_r_head & RQUEUEMASK;
1021 tail = ch->ch_r_tail & RQUEUEMASK;
1022
1023 linestatus = ch->ch_cached_lsr;
1024 ch->ch_cached_lsr = 0;
1025
1026 qleft = tail - head - 1;
1027 if (qleft < 0)
1028 qleft += RQUEUEMASK + 1;
1029
1030 if (!(ch->ch_flags & CH_FIFO_ENABLED)) {
1031 /* force the FIFO copy to NOT be run */
1032 total = 0;
1033 } else {
1034 total = readb(&ch->ch_neo_uart->rfifo);
1035
1036 /*
1037 * EXAR chip bug - RX FIFO COUNT - Fudge factor.
1038 *
1039 * This resolves a problem/bug with the Exar chip that sometimes
1040 * returns a bogus value in the rfifo register.
1041 * The count can be any where from 0-3 bytes "off".
1042 * Bizarre, but true.
1043 */
1044 if ((ch->ch_bd->dvid & 0xf0) >= UART_XR17E158_DVID)
1045 total -= 1;
1046 else
1047 total -= 3;
1048 }
1049
1050 total = min(total, qleft);
1051
1052 while (total > 0) {
1053 linestatus = readb(&ch->ch_neo_uart->lsr);
1054
1055 if (linestatus & UART_17158_RX_FIFO_DATA_ERROR)
1056 break;
1057
1058 /* Make sure we don't go over the end of our queue */
1059 n = min(((uint)total), (RQUEUESIZE - (uint)head));
1060
1061 /*
1062 * Cut down n even further if needed, this is to fix
1063 * a problem with memcpy_fromio() with the Neo on the
1064 * IBM pSeries platform.
1065 * 15 bytes max appears to be the magic number.
1066 */
1067 n = min_t(uint, n, 12);
1068
1069 /*
1070 * Since we are grabbing the linestatus register, which
1071 * will reset some bits after our read, we need to ensure
1072 * we don't miss our TX FIFO emptys.
1073 */
1074 if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR))
1075 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1076
1077 linestatus = 0;
1078
1079 memcpy_fromio(ch->ch_rqueue + head,
1080 &ch->ch_neo_uart->txrxburst, n);
1081
1082 /*
1083 * Since RX_FIFO_DATA_ERROR was 0, we are guaranteed
1084 * that all the data currently in the FIFO is free of
1085 * breaks and parity/frame/orun errors.
1086 */
1087 memset(ch->ch_equeue + head, 0, n);
1088
1089 head = (head + n) & RQUEUEMASK;
1090 total -= n;
1091 qleft -= n;
1092 ch->ch_rxcount += n;
1093 }
1094
1095 /*
1096 * Create a mask to determine whether we should
1097 * insert the character (if any) into our queue.
1098 */
1099 if (ch->ch_c_iflag & IGNBRK)
1100 error_mask |= UART_LSR_BI;
1101
1102 /*
1103 * Now cleanup any leftover bytes still in the UART.
1104 * Also deal with any possible queue overflow here as well.
1105 */
1106 while (1) {
1107 /*
1108 * Its possible we have a linestatus from the loop above
1109 * this, so we "OR" on any extra bits.
1110 */
1111 linestatus |= readb(&ch->ch_neo_uart->lsr);
1112
1113 /*
1114 * If the chip tells us there is no more data pending to
1115 * be read, we can then leave.
1116 * But before we do, cache the linestatus, just in case.
1117 */
1118 if (!(linestatus & UART_LSR_DR)) {
1119 ch->ch_cached_lsr = linestatus;
1120 break;
1121 }
1122
1123 /* No need to store this bit */
1124 linestatus &= ~UART_LSR_DR;
1125
1126 /*
1127 * Since we are grabbing the linestatus register, which
1128 * will reset some bits after our read, we need to ensure
1129 * we don't miss our TX FIFO emptys.
1130 */
1131 if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR)) {
1132 linestatus &= ~(UART_LSR_THRE |
1133 UART_17158_TX_AND_FIFO_CLR);
1134 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1135 }
1136
1137 if (linestatus & error_mask) {
1138 unsigned char discard;
1139
1140 linestatus = 0;
1141 memcpy_fromio(&discard, &ch->ch_neo_uart->txrxburst, 1);
1142 continue;
1143 }
1144
1145 /*
1146 * If our queue is full, we have no choice but to drop
1147 * some data. The assumption is that HWFLOW or SWFLOW
1148 * should have stopped things way way before we got to
1149 * this point.
1150 */
1151 while (qleft < 1) {
1152 tail = (tail + 1) & RQUEUEMASK;
1153 ch->ch_r_tail = tail;
1154 ch->ch_err_overrun++;
1155 qleft++;
1156 }
1157
1158 memcpy_fromio(ch->ch_rqueue + head,
1159 &ch->ch_neo_uart->txrxburst, 1);
1160 ch->ch_equeue[head] = (unsigned char)linestatus;
1161
1162 linestatus = 0;
1163
1164 head = (head + 1) & RQUEUEMASK;
1165
1166 qleft--;
1167 ch->ch_rxcount++;
1168 }
1169
1170 ch->ch_r_head = head & RQUEUEMASK;
1171 ch->ch_e_head = head & EQUEUEMASK;
1172
1173 spin_unlock_irqrestore(&ch->ch_lock, flags);
1174}
1175
1176/*
1177 * This function basically goes to sleep for secs, or until
1178 * it gets signalled that the port has fully drained.
1179 */
1180static int neo_drain(struct tty_struct *tty, uint seconds)
1181{
1182 unsigned long flags;
1183 struct channel_t *ch;
1184 struct un_t *un;
1185
1186 if (!tty)
1187 return -ENXIO;
1188
1189 un = (struct un_t *)tty->driver_data;
1190 if (!un)
1191 return -ENXIO;
1192
1193 ch = un->un_ch;
1194 if (!ch)
1195 return -ENXIO;
1196
1197 spin_lock_irqsave(&ch->ch_lock, flags);
1198 un->un_flags |= UN_EMPTY;
1199 spin_unlock_irqrestore(&ch->ch_lock, flags);
1200
1201 /* If returned value is non-zero, user ctrl-c'ed us */
1202 return wait_event_interruptible_timeout(un->un_flags_wait,
1203 ((un->un_flags & UN_EMPTY) == 0),
1204 msecs_to_jiffies(seconds * 1000));
1205}
1206
1207/*
1208 * Flush the WRITE FIFO on the Neo.
1209 * Channel lock MUST be held before calling this function!
1210 */
1211static void neo_flush_uart_write(struct channel_t *ch)
1212{
1213 unsigned char tmp = 0;
1214 int i = 0;
1215
1216 if (!ch)
1217 return;
1218
1219 writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT),
1220 &ch->ch_neo_uart->isr_fcr);
1221 neo_pci_posting_flush(ch->ch_bd);
1222
1223 for (i = 0; i < 10; i++) {
1224 /*
1225 * Check to see if the UART completely flushed the FIFO
1226 * FIFO.
1227 */
1228 tmp = readb(&ch->ch_neo_uart->isr_fcr);
1229 if (tmp & 4)
1230 udelay(10);
1231 else
1232 break;
1233 }
1234
1235 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1236}
1237
1238/*
1239 * Flush the READ FIFO on the Neo.
1240 * Channel lock MUST be held before calling this function!
1241 */
1242static void neo_flush_uart_read(struct channel_t *ch)
1243{
1244 unsigned char tmp = 0;
1245 int i = 0;
1246
1247 if (!ch)
1248 return;
1249
1250 writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR,
1251 &ch->ch_neo_uart->isr_fcr);
1252 neo_pci_posting_flush(ch->ch_bd);
1253
1254 for (i = 0; i < 10; i++) {
1255 /*
1256 * Check to see if the UART feels it completely flushed the
1257 * FIFO.
1258 */
1259 tmp = readb(&ch->ch_neo_uart->isr_fcr);
1260 if (tmp & 2)
1261 udelay(10);
1262 else
1263 break;
1264 }
1265}
1266
1267static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
1268{
1269 ushort head;
1270 ushort tail;
1271 int n;
1272 int s;
1273 int qlen;
1274 uint len_written = 0;
1275 unsigned long flags;
1276
1277 if (!ch)
1278 return;
1279
1280 spin_lock_irqsave(&ch->ch_lock, flags);
1281
1282 if (ch->ch_w_tail == ch->ch_w_head)
1283 goto exit_unlock;
1284
1285 /* If port is "stopped", don't send any data to the UART */
1286 if ((ch->ch_flags & CH_FORCED_STOP) ||
1287 (ch->ch_flags & CH_BREAK_SENDING))
1288 goto exit_unlock;
1289
1290 if (!(ch->ch_flags & CH_FIFO_ENABLED)) {
1291 /* Send data directly to txrx register */
1292 unsigned char lsrbits = readb(&ch->ch_neo_uart->lsr);
1293
1294 ch->ch_cached_lsr |= lsrbits;
1295 if (ch->ch_cached_lsr & UART_LSR_THRE) {
1296 ch->ch_cached_lsr &= ~(UART_LSR_THRE);
1297
1298 /*
1299 * If RTS Toggle mode is on, turn on RTS now if not
1300 * already set, and make sure we get an event when the
1301 * data transfer has completed.
1302 */
1303 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
1304 if (!(ch->ch_mostat & UART_MCR_RTS)) {
1305 ch->ch_mostat |= (UART_MCR_RTS);
1306 neo_assert_modem_signals(ch);
1307 }
1308 ch->ch_tun.un_flags |= (UN_EMPTY);
1309 }
1310 /*
1311 * If DTR Toggle mode is on, turn on DTR now if not
1312 * already set, and make sure we get an event when the
1313 * data transfer has completed.
1314 */
1315 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
1316 if (!(ch->ch_mostat & UART_MCR_DTR)) {
1317 ch->ch_mostat |= (UART_MCR_DTR);
1318 neo_assert_modem_signals(ch);
1319 }
1320 ch->ch_tun.un_flags |= (UN_EMPTY);
1321 }
1322
1323 writeb(ch->ch_wqueue[ch->ch_w_tail],
1324 &ch->ch_neo_uart->txrx);
1325 ch->ch_w_tail++;
1326 ch->ch_w_tail &= WQUEUEMASK;
1327 ch->ch_txcount++;
1328 }
1329
1330 goto exit_unlock;
1331 }
1332
1333 /* We have to do it this way, because of the EXAR TXFIFO count bug. */
1334
1335 if ((ch->ch_bd->dvid & 0xf0) < UART_XR17E158_DVID) {
1336 if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
1337 goto exit_unlock;
1338
1339 len_written = 0;
1340
1341 n = readb(&ch->ch_neo_uart->tfifo);
1342
1343 if ((unsigned int)n > ch->ch_t_tlevel)
1344 goto exit_unlock;
1345
1346 n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel;
1347 } else {
1348 n = UART_17158_TX_FIFOSIZE - readb(&ch->ch_neo_uart->tfifo);
1349 }
1350
1351 head = ch->ch_w_head & WQUEUEMASK;
1352 tail = ch->ch_w_tail & WQUEUEMASK;
1353 qlen = (head - tail) & WQUEUEMASK;
1354
1355 n = min(n, qlen);
1356
1357 while (n > 0) {
1358 s = ((head >= tail) ? head : WQUEUESIZE) - tail;
1359 s = min(s, n);
1360
1361 if (s <= 0)
1362 break;
1363
1364 /*
1365 * If RTS Toggle mode is on, turn on RTS now if not already set,
1366 * and make sure we get an event when the data transfer has
1367 * completed.
1368 */
1369 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
1370 if (!(ch->ch_mostat & UART_MCR_RTS)) {
1371 ch->ch_mostat |= (UART_MCR_RTS);
1372 neo_assert_modem_signals(ch);
1373 }
1374 ch->ch_tun.un_flags |= (UN_EMPTY);
1375 }
1376
1377 /*
1378 * If DTR Toggle mode is on, turn on DTR now if not already set,
1379 * and make sure we get an event when the data transfer has
1380 * completed.
1381 */
1382 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
1383 if (!(ch->ch_mostat & UART_MCR_DTR)) {
1384 ch->ch_mostat |= (UART_MCR_DTR);
1385 neo_assert_modem_signals(ch);
1386 }
1387 ch->ch_tun.un_flags |= (UN_EMPTY);
1388 }
1389
1390 memcpy_toio(&ch->ch_neo_uart->txrxburst,
1391 ch->ch_wqueue + tail, s);
1392
1393 tail = (tail + s) & WQUEUEMASK;
1394 n -= s;
1395 ch->ch_txcount += s;
1396 len_written += s;
1397 }
1398
1399 ch->ch_w_tail = tail & WQUEUEMASK;
1400
1401 if (len_written > 0) {
1402 neo_pci_posting_flush(ch->ch_bd);
1403 ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1404 }
1405
1406exit_unlock:
1407 spin_unlock_irqrestore(&ch->ch_lock, flags);
1408}
1409
1410static void neo_parse_modem(struct channel_t *ch, unsigned char signals)
1411{
1412 unsigned char msignals = signals;
1413
1414 if (!ch)
1415 return;
1416
1417 /*
1418 * Do altpin switching. Altpin switches DCD and DSR.
1419 * This prolly breaks DSRPACE, so we should be more clever here.
1420 */
1421 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1422 unsigned char mswap = msignals;
1423
1424 if (mswap & UART_MSR_DDCD) {
1425 msignals &= ~UART_MSR_DDCD;
1426 msignals |= UART_MSR_DDSR;
1427 }
1428 if (mswap & UART_MSR_DDSR) {
1429 msignals &= ~UART_MSR_DDSR;
1430 msignals |= UART_MSR_DDCD;
1431 }
1432 if (mswap & UART_MSR_DCD) {
1433 msignals &= ~UART_MSR_DCD;
1434 msignals |= UART_MSR_DSR;
1435 }
1436 if (mswap & UART_MSR_DSR) {
1437 msignals &= ~UART_MSR_DSR;
1438 msignals |= UART_MSR_DCD;
1439 }
1440 }
1441
1442 /* Scrub off lower bits. They signify delta's */
1443 msignals &= 0xf0;
1444
1445 if (msignals & UART_MSR_DCD)
1446 ch->ch_mistat |= UART_MSR_DCD;
1447 else
1448 ch->ch_mistat &= ~UART_MSR_DCD;
1449
1450 if (msignals & UART_MSR_DSR)
1451 ch->ch_mistat |= UART_MSR_DSR;
1452 else
1453 ch->ch_mistat &= ~UART_MSR_DSR;
1454
1455 if (msignals & UART_MSR_RI)
1456 ch->ch_mistat |= UART_MSR_RI;
1457 else
1458 ch->ch_mistat &= ~UART_MSR_RI;
1459
1460 if (msignals & UART_MSR_CTS)
1461 ch->ch_mistat |= UART_MSR_CTS;
1462 else
1463 ch->ch_mistat &= ~UART_MSR_CTS;
1464}
1465
1466/* Make the UART raise any of the output signals we want up */
1467static void neo_assert_modem_signals(struct channel_t *ch)
1468{
1469 unsigned char out;
1470
1471 if (!ch)
1472 return;
1473
1474 out = ch->ch_mostat;
1475
1476 if (ch->ch_flags & CH_LOOPBACK)
1477 out |= UART_MCR_LOOP;
1478
1479 writeb(out, &ch->ch_neo_uart->mcr);
1480 neo_pci_posting_flush(ch->ch_bd);
1481
1482 /* Give time for the UART to actually raise/drop the signals */
1483 udelay(10);
1484}
1485
1486static void neo_send_start_character(struct channel_t *ch)
1487{
1488 if (!ch)
1489 return;
1490
1491 if (ch->ch_startc != _POSIX_VDISABLE) {
1492 ch->ch_xon_sends++;
1493 writeb(ch->ch_startc, &ch->ch_neo_uart->txrx);
1494 neo_pci_posting_flush(ch->ch_bd);
1495 udelay(10);
1496 }
1497}
1498
1499static void neo_send_stop_character(struct channel_t *ch)
1500{
1501 if (!ch)
1502 return;
1503
1504 if (ch->ch_stopc != _POSIX_VDISABLE) {
1505 ch->ch_xoff_sends++;
1506 writeb(ch->ch_stopc, &ch->ch_neo_uart->txrx);
1507 neo_pci_posting_flush(ch->ch_bd);
1508 udelay(10);
1509 }
1510}
1511
1512/* neo_uart_init */
1513
1514static void neo_uart_init(struct channel_t *ch)
1515{
1516 writeb(0, &ch->ch_neo_uart->ier);
1517 writeb(0, &ch->ch_neo_uart->efr);
1518 writeb(UART_EFR_ECB, &ch->ch_neo_uart->efr);
1519
1520 /* Clear out UART and FIFO */
1521 readb(&ch->ch_neo_uart->txrx);
1522 writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
1523 &ch->ch_neo_uart->isr_fcr);
1524 readb(&ch->ch_neo_uart->lsr);
1525 readb(&ch->ch_neo_uart->msr);
1526
1527 ch->ch_flags |= CH_FIFO_ENABLED;
1528
1529 /* Assert any signals we want up */
1530 writeb(ch->ch_mostat, &ch->ch_neo_uart->mcr);
1531 neo_pci_posting_flush(ch->ch_bd);
1532}
1533
1534/* Make the UART completely turn off. */
1535static void neo_uart_off(struct channel_t *ch)
1536{
1537 /* Turn off UART enhanced bits */
1538 writeb(0, &ch->ch_neo_uart->efr);
1539
1540 /* Stop all interrupts from occurring. */
1541 writeb(0, &ch->ch_neo_uart->ier);
1542 neo_pci_posting_flush(ch->ch_bd);
1543}
1544
1545static uint neo_get_uart_bytes_left(struct channel_t *ch)
1546{
1547 unsigned char left = 0;
1548 unsigned char lsr = readb(&ch->ch_neo_uart->lsr);
1549
1550 /* We must cache the LSR as some of the bits get reset once read... */
1551 ch->ch_cached_lsr |= lsr;
1552
1553 /* Determine whether the Transmitter is empty or not */
1554 if (!(lsr & UART_LSR_TEMT)) {
1555 if (ch->ch_flags & CH_TX_FIFO_EMPTY)
1556 tasklet_schedule(&ch->ch_bd->helper_tasklet);
1557 left = 1;
1558 } else {
1559 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1560 left = 0;
1561 }
1562
1563 return left;
1564}
1565
1566/* Channel lock MUST be held by the calling function! */
1567static void neo_send_break(struct channel_t *ch, int msecs)
1568{
1569 /* If we receive a time of 0, this means turn off the break. */
1570
1571 if (msecs == 0) {
1572 if (ch->ch_flags & CH_BREAK_SENDING) {
1573 unsigned char temp = readb(&ch->ch_neo_uart->lcr);
1574
1575 writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
1576 neo_pci_posting_flush(ch->ch_bd);
1577 ch->ch_flags &= ~(CH_BREAK_SENDING);
1578 ch->ch_stop_sending_break = 0;
1579 }
1580 return;
1581 }
1582
1583 /*
1584 * Set the time we should stop sending the break.
1585 * If we are already sending a break, toss away the existing
1586 * time to stop, and use this new value instead.
1587 */
1588 ch->ch_stop_sending_break = jiffies + dgnc_jiffies_from_ms(msecs);
1589
1590 /* Tell the UART to start sending the break */
1591 if (!(ch->ch_flags & CH_BREAK_SENDING)) {
1592 unsigned char temp = readb(&ch->ch_neo_uart->lcr);
1593
1594 writeb((temp | UART_LCR_SBC), &ch->ch_neo_uart->lcr);
1595 neo_pci_posting_flush(ch->ch_bd);
1596 ch->ch_flags |= (CH_BREAK_SENDING);
1597 }
1598}
1599
1600/*
1601 * Sends a specific character as soon as possible to the UART,
1602 * jumping over any bytes that might be in the write queue.
1603 *
1604 * The channel lock MUST be held by the calling function.
1605 */
1606static void neo_send_immediate_char(struct channel_t *ch, unsigned char c)
1607{
1608 if (!ch)
1609 return;
1610
1611 writeb(c, &ch->ch_neo_uart->txrx);
1612 neo_pci_posting_flush(ch->ch_bd);
1613}
1614
1615static unsigned int neo_read_eeprom(unsigned char __iomem *base,
1616 unsigned int address)
1617{
1618 unsigned int enable;
1619 unsigned int bits;
1620 unsigned int databit;
1621 unsigned int val;
1622
1623 /* enable chip select */
1624 writeb(NEO_EECS, base + NEO_EEREG);
1625 /* READ */
1626 enable = address | 0x180;
1627
1628 for (bits = 9; bits--; ) {
1629 databit = (enable & (1 << bits)) ? NEO_EEDI : 0;
1630 /* Set read address */
1631 writeb(databit | NEO_EECS, base + NEO_EEREG);
1632 writeb(databit | NEO_EECS | NEO_EECK, base + NEO_EEREG);
1633 }
1634
1635 val = 0;
1636
1637 for (bits = 17; bits--; ) {
1638 /* clock to EEPROM */
1639 writeb(NEO_EECS, base + NEO_EEREG);
1640 writeb(NEO_EECS | NEO_EECK, base + NEO_EEREG);
1641 val <<= 1;
1642 /* read EEPROM */
1643 if (readb(base + NEO_EEREG) & NEO_EEDO)
1644 val |= 1;
1645 }
1646
1647 /* clock falling edge */
1648 writeb(NEO_EECS, base + NEO_EEREG);
1649
1650 /* drop chip select */
1651 writeb(0x00, base + NEO_EEREG);
1652
1653 return val;
1654}
1655
1656static void neo_vpd(struct dgnc_board *brd)
1657{
1658 unsigned int i = 0;
1659 unsigned int a;
1660
1661 if (!brd)
1662 return;
1663
1664 if (!brd->re_map_membase)
1665 return;
1666
1667 /* Store the VPD into our buffer */
1668 for (i = 0; i < NEO_VPD_IMAGESIZE; i++) {
1669 a = neo_read_eeprom(brd->re_map_membase, i);
1670 brd->vpd[i * 2] = a & 0xff;
1671 brd->vpd[(i * 2) + 1] = (a >> 8) & 0xff;
1672 }
1673
1674 /*
1675 * brd->vpd has different name tags by below index.
1676 * 0x08 : long resource name tag
1677 * 0x10 : long resource name tage (PCI-66 files)
1678 * 0x7F : small resource end tag
1679 */
1680 if (((brd->vpd[0x08] != 0x82) &&
1681 (brd->vpd[0x10] != 0x82)) ||
1682 (brd->vpd[0x7F] != 0x78)) {
1683 memset(brd->vpd, '\0', NEO_VPD_IMAGESIZE);
1684 } else {
1685 /* Search for the serial number */
1686 for (i = 0; i < NEO_VPD_IMAGEBYTES - 3; i++)
1687 if (brd->vpd[i] == 'S' && brd->vpd[i + 1] == 'N')
1688 strncpy(brd->serial_num, &brd->vpd[i + 3], 9);
1689 }
1690}
diff --git a/drivers/staging/dgnc/dgnc_neo.h b/drivers/staging/dgnc/dgnc_neo.h
deleted file mode 100644
index c30a2c2b5eea..000000000000
--- a/drivers/staging/dgnc/dgnc_neo.h
+++ /dev/null
@@ -1,175 +0,0 @@
1/*
2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */
15
16#ifndef _DGNC_NEO_H
17#define _DGNC_NEO_H
18
19#include "dgnc_driver.h"
20
21/**
22 * struct neo_uart_struct - Per channel/port NEO UART structure
23 *
24 * key - W = read write
25 * - R = read only
26 * - U = unused
27 *
28 * @txrx: (RW) Holding Register.
29 * @ier: (RW) Interrupt Enable Register.
30 * @isr_fcr: (RW) Interrupt Status Reg/Fifo Control Register.
31 * @lcr: (RW) Line Control Register.
32 * @mcr: (RW) Modem Control Register.
33 * @lsr: (RW) Line Status Register.
34 * @msr: (RW) Modem Status Register.
35 * @spr: (RW) Scratch Pad Register.
36 * @fctr: (RW) Feature Control Register.
37 * @efr: (RW) Enhanced Function Register.
38 * @tfifo: (RW) Transmit FIFO Register.
39 * @rfifo: (RW) Receive FIFO Register.
40 * @xoffchar1: (RW) XOff Character 1 Register.
41 * @xoffchar2: (RW) XOff Character 2 Register.
42 * @xonchar1: (RW) Xon Character 1 Register.
43 * @xonchar2: (RW) XOn Character 2 Register.
44 * @reserved1: (U) Reserved by Exar.
45 * @txrxburst: (RW) 64 bytes of RX/TX FIFO Data.
46 * @reserved2: (U) Reserved by Exar.
47 * @rxburst_with_errors: (R) bytes of RX FIFO Data + LSR.
48 */
49struct neo_uart_struct {
50 u8 txrx;
51 u8 ier;
52 u8 isr_fcr;
53
54 u8 lcr;
55 u8 mcr;
56 u8 lsr;
57 u8 msr;
58 u8 spr;
59 u8 fctr;
60 u8 efr;
61 u8 tfifo;
62 u8 rfifo;
63 u8 xoffchar1;
64 u8 xoffchar2;
65 u8 xonchar1;
66 u8 xonchar2;
67
68 u8 reserved1[0x2ff - 0x200];
69 u8 txrxburst[64];
70 u8 reserved2[0x37f - 0x340];
71 u8 rxburst_with_errors[64];
72};
73
74/* Where to read the extended interrupt register (32bits instead of 8bits) */
75#define UART_17158_POLL_ADDR_OFFSET 0x80
76
77/* These are the current dvid's of the Neo boards */
78#define UART_XR17C158_DVID 0x20
79#define UART_XR17D158_DVID 0x20
80#define UART_XR17E158_DVID 0x40
81
82#define NEO_EECK 0x10 /* Clock */
83#define NEO_EECS 0x20 /* Chip Select */
84#define NEO_EEDI 0x40 /* Data In is an Output Pin */
85#define NEO_EEDO 0x80 /* Data Out is an Input Pin */
86#define NEO_EEREG 0x8E /* offset to EEPROM control reg */
87
88#define NEO_VPD_IMAGESIZE 0x40 /* size of image to read from EEPROM in words */
89#define NEO_VPD_IMAGEBYTES (NEO_VPD_IMAGESIZE * 2)
90
91/*
92 * These are the redefinitions for the FCTR on the XR17C158, since
93 * Exar made them different than their earlier design. (XR16C854)
94 */
95
96/* These are only applicable when table D is selected */
97#define UART_17158_FCTR_RTS_NODELAY 0x00
98#define UART_17158_FCTR_RTS_4DELAY 0x01
99#define UART_17158_FCTR_RTS_6DELAY 0x02
100#define UART_17158_FCTR_RTS_8DELAY 0x03
101#define UART_17158_FCTR_RTS_12DELAY 0x12
102#define UART_17158_FCTR_RTS_16DELAY 0x05
103#define UART_17158_FCTR_RTS_20DELAY 0x13
104#define UART_17158_FCTR_RTS_24DELAY 0x06
105#define UART_17158_FCTR_RTS_28DELAY 0x14
106#define UART_17158_FCTR_RTS_32DELAY 0x07
107#define UART_17158_FCTR_RTS_36DELAY 0x16
108#define UART_17158_FCTR_RTS_40DELAY 0x08
109#define UART_17158_FCTR_RTS_44DELAY 0x09
110#define UART_17158_FCTR_RTS_48DELAY 0x10
111#define UART_17158_FCTR_RTS_52DELAY 0x11
112
113#define UART_17158_FCTR_RTS_IRDA 0x10
114#define UART_17158_FCTR_RS485 0x20
115#define UART_17158_FCTR_TRGA 0x00
116#define UART_17158_FCTR_TRGB 0x40
117#define UART_17158_FCTR_TRGC 0x80
118#define UART_17158_FCTR_TRGD 0xC0
119
120/* 17158 trigger table selects.. */
121#define UART_17158_FCTR_BIT6 0x40
122#define UART_17158_FCTR_BIT7 0x80
123
124/* 17158 TX/RX memmapped buffer offsets */
125#define UART_17158_RX_FIFOSIZE 64
126#define UART_17158_TX_FIFOSIZE 64
127
128/* 17158 Extended IIR's */
129#define UART_17158_IIR_RDI_TIMEOUT 0x0C /* Receiver data TIMEOUT */
130#define UART_17158_IIR_XONXOFF 0x10 /* Received an XON/XOFF char */
131#define UART_17158_IIR_HWFLOW_STATE_CHANGE 0x20 /* CTS/DSR or RTS/DTR
132 * state change
133 */
134#define UART_17158_IIR_FIFO_ENABLED 0xC0 /* 16550 FIFOs are Enabled */
135
136/*
137 * These are the extended interrupts that get sent
138 * back to us from the UART's 32bit interrupt register
139 */
140#define UART_17158_RX_LINE_STATUS 0x1 /* RX Ready */
141#define UART_17158_RXRDY_TIMEOUT 0x2 /* RX Ready Timeout */
142#define UART_17158_TXRDY 0x3 /* TX Ready */
143#define UART_17158_MSR 0x4 /* Modem State Change */
144#define UART_17158_TX_AND_FIFO_CLR 0x40 /* Transmitter Holding
145 * Reg Empty
146 */
147#define UART_17158_RX_FIFO_DATA_ERROR 0x80 /* UART detected an RX FIFO
148 * Data error
149 */
150
151/*
152 * These are the EXTENDED definitions for the 17C158's Interrupt
153 * Enable Register.
154 */
155#define UART_17158_EFR_ECB 0x10 /* Enhanced control bit */
156#define UART_17158_EFR_IXON 0x2 /* Receiver compares Xon1/Xoff1 */
157#define UART_17158_EFR_IXOFF 0x8 /* Transmit Xon1/Xoff1 */
158#define UART_17158_EFR_RTSDTR 0x40 /* Auto RTS/DTR Flow Control Enable */
159#define UART_17158_EFR_CTSDSR 0x80 /* Auto CTS/DSR Flow Control Enable */
160
161#define UART_17158_XOFF_DETECT 0x1 /* Indicates whether chip saw an
162 * incoming XOFF char
163 */
164#define UART_17158_XON_DETECT 0x2 /* Indicates whether chip saw an
165 * incoming XON char
166 */
167
168#define UART_17158_IER_RSVD1 0x10 /* Reserved by Exar */
169#define UART_17158_IER_XOFF 0x20 /* Xoff Interrupt Enable */
170#define UART_17158_IER_RTSDTR 0x40 /* Output Interrupt Enable */
171#define UART_17158_IER_CTSDSR 0x80 /* Input Interrupt Enable */
172
173extern struct board_ops dgnc_neo_ops;
174
175#endif /* _DGNC_NEO_H */
diff --git a/drivers/staging/dgnc/dgnc_pci.h b/drivers/staging/dgnc/dgnc_pci.h
deleted file mode 100644
index 59845916d90c..000000000000
--- a/drivers/staging/dgnc/dgnc_pci.h
+++ /dev/null
@@ -1,69 +0,0 @@
1/*
2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */
15
16#ifndef _DGNC_PCI_H
17#define _DGNC_PCI_H
18
19/* Maximum number of PCI boards */
20#define PCIMAX 32
21
22#define DIGI_VID 0x114F
23
24#define PCI_DEVICE_CLASSIC_4_DID 0x0028
25#define PCI_DEVICE_CLASSIC_8_DID 0x0029
26#define PCI_DEVICE_CLASSIC_4_422_DID 0x00D0
27#define PCI_DEVICE_CLASSIC_8_422_DID 0x00D1
28#define PCI_DEVICE_NEO_4_DID 0x00B0
29#define PCI_DEVICE_NEO_8_DID 0x00B1
30#define PCI_DEVICE_NEO_2DB9_DID 0x00C8
31#define PCI_DEVICE_NEO_2DB9PRI_DID 0x00C9
32#define PCI_DEVICE_NEO_2RJ45_DID 0x00CA
33#define PCI_DEVICE_NEO_2RJ45PRI_DID 0x00CB
34#define PCI_DEVICE_NEO_1_422_DID 0x00CC
35#define PCI_DEVICE_NEO_1_422_485_DID 0x00CD
36#define PCI_DEVICE_NEO_2_422_485_DID 0x00CE
37#define PCI_DEVICE_NEO_EXPRESS_8_DID 0x00F0
38#define PCI_DEVICE_NEO_EXPRESS_4_DID 0x00F1
39#define PCI_DEVICE_NEO_EXPRESS_4RJ45_DID 0x00F2
40#define PCI_DEVICE_NEO_EXPRESS_8RJ45_DID 0x00F3
41#define PCI_DEVICE_NEO_EXPRESS_4_IBM_DID 0x00F4
42
43#define PCI_DEVICE_CLASSIC_4_PCI_NAME "ClassicBoard 4 PCI"
44#define PCI_DEVICE_CLASSIC_8_PCI_NAME "ClassicBoard 8 PCI"
45#define PCI_DEVICE_CLASSIC_4_422_PCI_NAME "ClassicBoard 4 422 PCI"
46#define PCI_DEVICE_CLASSIC_8_422_PCI_NAME "ClassicBoard 8 422 PCI"
47#define PCI_DEVICE_NEO_4_PCI_NAME "Neo 4 PCI"
48#define PCI_DEVICE_NEO_8_PCI_NAME "Neo 8 PCI"
49#define PCI_DEVICE_NEO_2DB9_PCI_NAME "Neo 2 - DB9 Universal PCI"
50#define PCI_DEVICE_NEO_2DB9PRI_PCI_NAME "Neo 2 - DB9 Universal PCI - Powered Ring Indicator"
51#define PCI_DEVICE_NEO_2RJ45_PCI_NAME "Neo 2 - RJ45 Universal PCI"
52#define PCI_DEVICE_NEO_2RJ45PRI_PCI_NAME "Neo 2 - RJ45 Universal PCI - Powered Ring Indicator"
53#define PCI_DEVICE_NEO_1_422_PCI_NAME "Neo 1 422 PCI"
54#define PCI_DEVICE_NEO_1_422_485_PCI_NAME "Neo 1 422/485 PCI"
55#define PCI_DEVICE_NEO_2_422_485_PCI_NAME "Neo 2 422/485 PCI"
56
57#define PCI_DEVICE_NEO_EXPRESS_8_PCI_NAME "Neo 8 PCI Express"
58#define PCI_DEVICE_NEO_EXPRESS_4_PCI_NAME "Neo 4 PCI Express"
59#define PCI_DEVICE_NEO_EXPRESS_4RJ45_PCI_NAME "Neo 4 PCI Express RJ45"
60#define PCI_DEVICE_NEO_EXPRESS_8RJ45_PCI_NAME "Neo 8 PCI Express RJ45"
61#define PCI_DEVICE_NEO_EXPRESS_4_IBM_PCI_NAME "Neo 4 PCI Express IBM"
62
63/* Size of memory and I/O for PCI (4 K) */
64#define PCI_RAM_SIZE 0x1000
65
66/* Size of memory (2MB) */
67#define PCI_MEM_SIZE 0x1000
68
69#endif /* _DGNC_PCI_H */
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index d3736daf8cf2..9f9b9a5b4b27 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright 2003 Digi International (www.digi.com) 3 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com> 4 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */ 5 */
15 6
16/* 7/*
@@ -33,9 +24,7 @@
33#include <linux/pci.h> 24#include <linux/pci.h>
34#include "dgnc_driver.h" 25#include "dgnc_driver.h"
35#include "dgnc_tty.h" 26#include "dgnc_tty.h"
36#include "dgnc_neo.h"
37#include "dgnc_cls.h" 27#include "dgnc_cls.h"
38#include "dgnc_utils.h"
39 28
40/* Default transparent print information. */ 29/* Default transparent print information. */
41 30
@@ -240,10 +229,7 @@ int dgnc_tty_init(struct dgnc_board *brd)
240 ch->ch_pun.un_type = DGNC_PRINT; 229 ch->ch_pun.un_type = DGNC_PRINT;
241 ch->ch_pun.un_dev = i + 128; 230 ch->ch_pun.un_dev = i + 128;
242 231
243 if (brd->bd_uart_offset == 0x200) 232 ch->ch_cls_uart = vaddr + (brd->bd_uart_offset * i);
244 ch->ch_neo_uart = vaddr + (brd->bd_uart_offset * i);
245 else
246 ch->ch_cls_uart = vaddr + (brd->bd_uart_offset * i);
247 233
248 ch->ch_bd = brd; 234 ch->ch_bd = brd;
249 ch->ch_portnum = i; 235 ch->ch_portnum = i;
@@ -1238,7 +1224,7 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
1238 if (ch->ch_close_delay) { 1224 if (ch->ch_close_delay) {
1239 spin_unlock_irqrestore(&ch->ch_lock, 1225 spin_unlock_irqrestore(&ch->ch_lock,
1240 flags); 1226 flags);
1241 dgnc_ms_sleep(ch->ch_close_delay); 1227 msleep_interruptible(ch->ch_close_delay);
1242 spin_lock_irqsave(&ch->ch_lock, flags); 1228 spin_lock_irqsave(&ch->ch_lock, flags);
1243 } 1229 }
1244 } 1230 }
diff --git a/drivers/staging/dgnc/dgnc_tty.h b/drivers/staging/dgnc/dgnc_tty.h
index 6c58f1b3461a..00e31035b83d 100644
--- a/drivers/staging/dgnc/dgnc_tty.h
+++ b/drivers/staging/dgnc/dgnc_tty.h
@@ -1,16 +1,7 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * Copyright 2003 Digi International (www.digi.com) 3 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com> 4 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */ 5 */
15 6
16#ifndef _DGNC_TTY_H 7#ifndef _DGNC_TTY_H
diff --git a/drivers/staging/dgnc/dgnc_utils.c b/drivers/staging/dgnc/dgnc_utils.c
deleted file mode 100644
index 620f5741a1ed..000000000000
--- a/drivers/staging/dgnc/dgnc_utils.c
+++ /dev/null
@@ -1,17 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/tty.h>
3#include <linux/sched/signal.h>
4#include "dgnc_utils.h"
5
6/**
7 * dgnc_ms_sleep - Put the driver to sleep
8 * @ms - milliseconds to sleep
9 *
10 * Return: 0 if timed out, if interrupted by a signal return signal.
11 */
12int dgnc_ms_sleep(ulong ms)
13{
14 __set_current_state(TASK_INTERRUPTIBLE);
15 schedule_timeout((ms * HZ) / 1000);
16 return signal_pending(current);
17}
diff --git a/drivers/staging/dgnc/dgnc_utils.h b/drivers/staging/dgnc/dgnc_utils.h
deleted file mode 100644
index b30527f0889d..000000000000
--- a/drivers/staging/dgnc/dgnc_utils.h
+++ /dev/null
@@ -1,7 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _DGNC_UTILS_H
3#define _DGNC_UTILS_H
4
5int dgnc_ms_sleep(ulong ms);
6
7#endif /* _DGNC_UTILS_H */
diff --git a/drivers/staging/dgnc/digi.h b/drivers/staging/dgnc/digi.h
index 46b06b07bbf2..b414ee80db88 100644
--- a/drivers/staging/dgnc/digi.h
+++ b/drivers/staging/dgnc/digi.h
@@ -1,50 +1,16 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * Copyright 2003 Digi International (www.digi.com) 3 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com> 4 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 */ 5 */
15 6
16#ifndef _DIGI_H 7#ifndef _DIGI_H
17#define _DIGI_H 8#define _DIGI_H
18 9
19#ifndef TIOCM_LE
20#define TIOCM_LE 0x01 /* line enable */
21#define TIOCM_DTR 0x02 /* data terminal ready */
22#define TIOCM_RTS 0x04 /* request to send */
23#define TIOCM_ST 0x08 /* secondary transmit */
24#define TIOCM_SR 0x10 /* secondary receive */
25#define TIOCM_CTS 0x20 /* clear to send */
26#define TIOCM_CAR 0x40 /* carrier detect */
27#define TIOCM_RNG 0x80 /* ring indicator */
28#define TIOCM_DSR 0x100 /* data set ready */
29#define TIOCM_RI TIOCM_RNG /* ring (alternate) */
30#define TIOCM_CD TIOCM_CAR /* carrier detect (alt) */
31#endif
32
33#if !defined(TIOCMSET)
34#define TIOCMSET (('d' << 8) | 252) /* set modem ctrl state */
35#define TIOCMGET (('d' << 8) | 253) /* set modem ctrl state */
36#endif
37
38#if !defined(TIOCMBIC)
39#define TIOCMBIC (('d' << 8) | 254) /* set modem ctrl state */
40#define TIOCMBIS (('d' << 8) | 255) /* set modem ctrl state */
41#endif
42
43#define DIGI_GETA (('e' << 8) | 94) /* Read params */ 10#define DIGI_GETA (('e' << 8) | 94) /* Read params */
44#define DIGI_SETA (('e' << 8) | 95) /* Set params */ 11#define DIGI_SETA (('e' << 8) | 95) /* Set params */
45#define DIGI_SETAW (('e' << 8) | 96) /* Drain & set params */ 12#define DIGI_SETAW (('e' << 8) | 96) /* Drain & set params */
46#define DIGI_SETAF (('e' << 8) | 97) /* Drain, flush & set params */ 13#define DIGI_SETAF (('e' << 8) | 97) /* Drain, flush & set params */
47#define DIGI_GET_NI_INFO (('d' << 8) | 250) /* Non-intelligent state info */
48#define DIGI_LOOPBACK (('d' << 8) | 252) /* Enable/disable UART 14#define DIGI_LOOPBACK (('d' << 8) | 252) /* Enable/disable UART
49 * internal loopback 15 * internal loopback
50 */ 16 */
@@ -88,49 +54,6 @@ struct digi_t {
88}; 54};
89 55
90/** 56/**
91 * struct digi_dinfo - Driver status information.
92 * @dinfo_nboards: Number of boards configured.
93 * @dinfo_reserved: Not used, for future expansion.
94 * @dinfio_version: Driver version.
95 */
96struct digi_dinfo {
97 unsigned int dinfo_nboards;
98 char dinfo_reserved[12];
99 char dinfo_version[16];
100};
101
102#define DIGI_GETDD (('d' << 8) | 248) /* get driver info */
103
104/**
105 * struct digi_info - Ioctl commands for per board information.
106 *
107 * Physsize and memsize differ when board has "windowed" memory.
108 *
109 * @info_bdnum: Board number (0 based).
110 * @info_ioport: IO port address.
111 * @indo_physaddr: Memory address.
112 * @info_physize: Size of host memory window.
113 * @info_memsize: Amount of dual-port memory on board.
114 * @info_bdtype: Board type.
115 * @info_nports: Number of ports.
116 * @info_bdstate: Board state.
117 * @info_reserved: Not used, for future expansion.
118 */
119struct digi_info {
120 unsigned int info_bdnum;
121 unsigned int info_ioport;
122 unsigned int info_physaddr;
123 unsigned int info_physsize;
124 unsigned int info_memsize;
125 unsigned short info_bdtype;
126 unsigned short info_nports;
127 char info_bdstate;
128 char info_reserved[7];
129};
130
131#define DIGI_GETBD (('d' << 8) | 249) /* get board info */
132
133/**
134 * struct digi_getbuffer - Holds buffer use counts. 57 * struct digi_getbuffer - Holds buffer use counts.
135 */ 58 */
136struct digi_getbuffer { 59struct digi_getbuffer {
@@ -161,10 +84,6 @@ struct digi_getcounter {
161 unsigned long tbytes; 84 unsigned long tbytes;
162}; 85};
163 86
164/* Board State Definitions */
165#define BD_RUNNING 0x0
166#define BD_NOFEP 0x5
167
168#define DIGI_SETCUSTOMBAUD _IOW('e', 106, int) /* Set integer baud rate */ 87#define DIGI_SETCUSTOMBAUD _IOW('e', 106, int) /* Set integer baud rate */
169#define DIGI_GETCUSTOMBAUD _IOR('e', 107, int) /* Get integer baud rate */ 88#define DIGI_GETCUSTOMBAUD _IOR('e', 107, int) /* Get integer baud rate */
170 89
@@ -204,11 +123,6 @@ struct ni_info {
204 unsigned int baud; 123 unsigned int baud;
205}; 124};
206 125
207#define T_CLASSIC 0002
208#define T_PCIBUS 0400
209#define T_NEO_EXPRESS 0001
210#define T_NEO 0000
211
212#define TTY_FLIPBUF_SIZE 512 126#define TTY_FLIPBUF_SIZE 512
213 127
214#endif /* _DIGI_H */ 128#endif /* _DIGI_H */
diff --git a/drivers/staging/emxx_udc/emxx_udc.c b/drivers/staging/emxx_udc/emxx_udc.c
index bb010cb98a1c..7517001fb8f0 100644
--- a/drivers/staging/emxx_udc/emxx_udc.c
+++ b/drivers/staging/emxx_udc/emxx_udc.c
@@ -1,17 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * drivers/usb/gadget/emxx_udc.c 3 * drivers/usb/gadget/emxx_udc.c
3 * EMXX FCD (Function Controller Driver) for USB. 4 * EMXX FCD (Function Controller Driver) for USB.
4 * 5 *
5 * Copyright (C) 2010 Renesas Electronics Corporation 6 * Copyright (C) 2010 Renesas Electronics Corporation
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
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 7 */
16 8
17#include <linux/kernel.h> 9#include <linux/kernel.h>
diff --git a/drivers/staging/emxx_udc/emxx_udc.h b/drivers/staging/emxx_udc/emxx_udc.h
index 928d531a5115..8337e38c238a 100644
--- a/drivers/staging/emxx_udc/emxx_udc.h
+++ b/drivers/staging/emxx_udc/emxx_udc.h
@@ -1,16 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * EMXX FCD (Function Controller Driver) for USB. 3 * EMXX FCD (Function Controller Driver) for USB.
3 * 4 *
4 * Copyright (C) 2010 Renesas Electronics Corporation 5 * Copyright (C) 2010 Renesas Electronics Corporation
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
8 * as published by the Free Software Foundation.
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 */ 6 */
15 7
16#ifndef _LINUX_EMXX_H 8#ifndef _LINUX_EMXX_H
diff --git a/drivers/staging/fbtft/Kconfig b/drivers/staging/fbtft/Kconfig
index dba676761d72..84b2e7ebc024 100644
--- a/drivers/staging/fbtft/Kconfig
+++ b/drivers/staging/fbtft/Kconfig
@@ -135,12 +135,6 @@ config FB_TFT_SSD1306
135 help 135 help
136 Framebuffer support for SSD1306 136 Framebuffer support for SSD1306
137 137
138config FB_TFT_SSD1325
139 tristate "FB driver for the SSD1325 OLED Controller"
140 depends on FB_TFT
141 help
142 Framebuffer support for SSD1305
143
144config FB_TFT_SSD1331 138config FB_TFT_SSD1331
145 tristate "FB driver for the SSD1331 LCD Controller" 139 tristate "FB driver for the SSD1331 LCD Controller"
146 depends on FB_TFT 140 depends on FB_TFT
diff --git a/drivers/staging/fbtft/fb_agm1264k-fl.c b/drivers/staging/fbtft/fb_agm1264k-fl.c
index 456a8dd65caf..f6f30f5bf15a 100644
--- a/drivers/staging/fbtft/fb_agm1264k-fl.c
+++ b/drivers/staging/fbtft/fb_agm1264k-fl.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for Two KS0108 LCD controllers in AGM1264K-FL display 3 * FB driver for Two KS0108 LCD controllers in AGM1264K-FL display
3 * 4 *
4 * Copyright (C) 2014 ololoshka2871 5 * Copyright (C) 2014 ololoshka2871
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_bd663474.c b/drivers/staging/fbtft/fb_bd663474.c
index 6010e6cbbd72..a58c514f4721 100644
--- a/drivers/staging/fbtft/fb_bd663474.c
+++ b/drivers/staging/fbtft/fb_bd663474.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the uPD161704 LCD Controller 3 * FB driver for the uPD161704 LCD Controller
3 * 4 *
@@ -6,16 +7,6 @@
6 * Based on fb_ili9325.c by Noralf Tronnes 7 * Based on fb_ili9325.c by Noralf Tronnes
7 * Based on ili9325.c by Jeroen Domburg 8 * Based on ili9325.c by Jeroen Domburg
8 * Init code from UTFT library by Henning Karlsen 9 * Init code from UTFT library by Henning Karlsen
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21#include <linux/module.h> 12#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_hx8340bn.c b/drivers/staging/fbtft/fb_hx8340bn.c
index fbd5ef525243..d47dcf31fffb 100644
--- a/drivers/staging/fbtft/fb_hx8340bn.c
+++ b/drivers/staging/fbtft/fb_hx8340bn.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the HX8340BN LCD Controller 3 * FB driver for the HX8340BN LCD Controller
3 * 4 *
@@ -7,16 +8,6 @@
7 * This is done by transferring eight 9-bit words in 9 bytes. 8 * This is done by transferring eight 9-bit words in 9 bytes.
8 * 9 *
9 * Copyright (C) 2013 Noralf Tronnes 10 * Copyright (C) 2013 Noralf Tronnes
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */ 11 */
21 12
22#include <linux/module.h> 13#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_hx8347d.c b/drivers/staging/fbtft/fb_hx8347d.c
index bbf78f8644a8..0b605303813e 100644
--- a/drivers/staging/fbtft/fb_hx8347d.c
+++ b/drivers/staging/fbtft/fb_hx8347d.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the HX8347D LCD Controller 3 * FB driver for the HX8347D LCD Controller
3 * 4 *
4 * Copyright (C) 2013 Christian Vogelgsang 5 * Copyright (C) 2013 Christian Vogelgsang
5 * 6 *
6 * Based on driver code found here: https://github.com/watterott/r61505u-Adapter 7 * Based on driver code found here: https://github.com/watterott/r61505u-Adapter
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/module.h> 10#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_hx8353d.c b/drivers/staging/fbtft/fb_hx8353d.c
index 2c18051a44b3..3e73b69b6a27 100644
--- a/drivers/staging/fbtft/fb_hx8353d.c
+++ b/drivers/staging/fbtft/fb_hx8353d.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the HX8353D LCD Controller 3 * FB driver for the HX8353D LCD Controller
3 * 4 *
4 * Copyright (c) 2014 Petr Olivka 5 * Copyright (c) 2014 Petr Olivka
5 * Copyright (c) 2013 Noralf Tronnes 6 * Copyright (c) 2013 Noralf Tronnes
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18#include <linux/module.h> 9#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_hx8357d.c b/drivers/staging/fbtft/fb_hx8357d.c
index 32e6efe1d0a7..94a357e8fdf6 100644
--- a/drivers/staging/fbtft/fb_hx8357d.c
+++ b/drivers/staging/fbtft/fb_hx8357d.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the HX8357D LCD Controller 3 * FB driver for the HX8357D LCD Controller
3 * Copyright (C) 2015 Adafruit Industries 4 * Copyright (C) 2015 Adafruit Industries
@@ -6,16 +7,6 @@
6 * Copyright (C) 2013 Christian Vogelgsang 7 * Copyright (C) 2013 Christian Vogelgsang
7 * 8 *
8 * Based on driver code found here: https://github.com/watterott/r61505u-Adapter 9 * Based on driver code found here: https://github.com/watterott/r61505u-Adapter
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21#include <linux/module.h> 12#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_hx8357d.h b/drivers/staging/fbtft/fb_hx8357d.h
index e281921d4a97..6180b093f94f 100644
--- a/drivers/staging/fbtft/fb_hx8357d.h
+++ b/drivers/staging/fbtft/fb_hx8357d.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: MIT */
1/* 2/*
2 * This is our library for the Adafruit ILI9341 Breakout and Shield 3 * This is our library for the Adafruit ILI9341 Breakout and Shield
3 * ----> http://www.adafruit.com/products/1651 4 * ----> http://www.adafruit.com/products/1651
diff --git a/drivers/staging/fbtft/fb_ili9163.c b/drivers/staging/fbtft/fb_ili9163.c
index 045cadc3bc65..fd3dd671509f 100644
--- a/drivers/staging/fbtft/fb_ili9163.c
+++ b/drivers/staging/fbtft/fb_ili9163.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the ILI9163 LCD Controller 3 * FB driver for the ILI9163 LCD Controller
3 * 4 *
@@ -5,16 +6,6 @@
5 * 6 *
6 * Based on ili9325.c by Noralf Tronnes and 7 * Based on ili9325.c by Noralf Tronnes and
7 * .S.U.M.O.T.O.Y. by Max MC Costa (https://github.com/sumotoy/TFT_ILI9163C). 8 * .S.U.M.O.T.O.Y. by Max MC Costa (https://github.com/sumotoy/TFT_ILI9163C).
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20#include <linux/module.h> 11#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ili9320.c b/drivers/staging/fbtft/fb_ili9320.c
index 20ba86da028b..501eee7dce4c 100644
--- a/drivers/staging/fbtft/fb_ili9320.c
+++ b/drivers/staging/fbtft/fb_ili9320.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the ILI9320 LCD Controller 3 * FB driver for the ILI9320 LCD Controller
3 * 4 *
4 * Copyright (C) 2013 Noralf Tronnes 5 * Copyright (C) 2013 Noralf Tronnes
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ili9325.c b/drivers/staging/fbtft/fb_ili9325.c
index 7f9e9b25490e..d6b1d4be9ff4 100644
--- a/drivers/staging/fbtft/fb_ili9325.c
+++ b/drivers/staging/fbtft/fb_ili9325.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the ILI9325 LCD Controller 3 * FB driver for the ILI9325 LCD Controller
3 * 4 *
4 * Copyright (C) 2013 Noralf Tronnes 5 * Copyright (C) 2013 Noralf Tronnes
5 * 6 *
6 * Based on ili9325.c by Jeroen Domburg 7 * Based on ili9325.c by Jeroen Domburg
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/module.h> 10#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ili9340.c b/drivers/staging/fbtft/fb_ili9340.c
index 0711121c303c..430f21e50f4d 100644
--- a/drivers/staging/fbtft/fb_ili9340.c
+++ b/drivers/staging/fbtft/fb_ili9340.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the ILI9340 LCD Controller 3 * FB driver for the ILI9340 LCD Controller
3 * 4 *
4 * Copyright (C) 2013 Noralf Tronnes 5 * Copyright (C) 2013 Noralf Tronnes
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ili9341.c b/drivers/staging/fbtft/fb_ili9341.c
index 21a98e9e1a14..a10e8c9de438 100644
--- a/drivers/staging/fbtft/fb_ili9341.c
+++ b/drivers/staging/fbtft/fb_ili9341.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the ILI9341 LCD display controller 3 * FB driver for the ILI9341 LCD display controller
3 * 4 *
@@ -8,16 +9,6 @@
8 * 9 *
9 * Copyright (C) 2013 Christian Vogelgsang 10 * Copyright (C) 2013 Christian Vogelgsang
10 * Based on adafruit22fb.c by Noralf Tronnes 11 * Based on adafruit22fb.c by Noralf Tronnes
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
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 */ 12 */
22 13
23#include <linux/module.h> 14#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ili9481.c b/drivers/staging/fbtft/fb_ili9481.c
index 7f182a1c084c..19eba085ea53 100644
--- a/drivers/staging/fbtft/fb_ili9481.c
+++ b/drivers/staging/fbtft/fb_ili9481.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the ILI9481 LCD Controller 3 * FB driver for the ILI9481 LCD Controller
3 * 4 *
4 * Copyright (c) 2014 Petr Olivka 5 * Copyright (c) 2014 Petr Olivka
5 * Copyright (c) 2013 Noralf Tronnes 6 * Copyright (c) 2013 Noralf Tronnes
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18#include <linux/module.h> 9#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ili9486.c b/drivers/staging/fbtft/fb_ili9486.c
index ddd07a64c48a..66210a7137fc 100644
--- a/drivers/staging/fbtft/fb_ili9486.c
+++ b/drivers/staging/fbtft/fb_ili9486.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the ILI9486 LCD Controller 3 * FB driver for the ILI9486 LCD Controller
3 * 4 *
4 * Copyright (C) 2014 Noralf Tronnes 5 * Copyright (C) 2014 Noralf Tronnes
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_pcd8544.c b/drivers/staging/fbtft/fb_pcd8544.c
index 87f678a314cc..32172f8f79f0 100644
--- a/drivers/staging/fbtft/fb_pcd8544.c
+++ b/drivers/staging/fbtft/fb_pcd8544.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the PCD8544 LCD Controller 3 * FB driver for the PCD8544 LCD Controller
3 * 4 *
@@ -5,16 +6,6 @@
5 * Any pixel value except 0 turns the pixel on. 6 * Any pixel value except 0 turns the pixel on.
6 * 7 *
7 * Copyright (C) 2013 Noralf Tronnes 8 * Copyright (C) 2013 Noralf Tronnes
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20#include <linux/module.h> 11#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ra8875.c b/drivers/staging/fbtft/fb_ra8875.c
index 6d1cad85957b..5d3b76ca74d8 100644
--- a/drivers/staging/fbtft/fb_ra8875.c
+++ b/drivers/staging/fbtft/fb_ra8875.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FBTFT driver for the RA8875 LCD Controller 3 * FBTFT driver for the RA8875 LCD Controller
3 * Copyright by Pf@nne & NOTRO 4 * Copyright by Pf@nne & NOTRO
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 */ 5 */
15 6
16#include <linux/module.h> 7#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_s6d02a1.c b/drivers/staging/fbtft/fb_s6d02a1.c
index c12855bb6891..75295760f491 100644
--- a/drivers/staging/fbtft/fb_s6d02a1.c
+++ b/drivers/staging/fbtft/fb_s6d02a1.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the S6D02A1 LCD Controller 3 * FB driver for the S6D02A1 LCD Controller
3 * 4 *
4 * Based on fb_st7735r.c by Noralf Tronnes 5 * Based on fb_st7735r.c by Noralf Tronnes
5 * Init code from UTFT library by Henning Karlsen 6 * Init code from UTFT library by Henning Karlsen
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18#include <linux/module.h> 9#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_s6d1121.c b/drivers/staging/fbtft/fb_s6d1121.c
index 3b36ed50d491..b90244259d43 100644
--- a/drivers/staging/fbtft/fb_s6d1121.c
+++ b/drivers/staging/fbtft/fb_s6d1121.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the S6D1121 LCD Controller 3 * FB driver for the S6D1121 LCD Controller
3 * 4 *
@@ -6,16 +7,6 @@
6 * Based on fb_ili9325.c by Noralf Tronnes 7 * Based on fb_ili9325.c by Noralf Tronnes
7 * Based on ili9325.c by Jeroen Domburg 8 * Based on ili9325.c by Jeroen Domburg
8 * Init code from UTFT library by Henning Karlsen 9 * Init code from UTFT library by Henning Karlsen
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21#include <linux/module.h> 12#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_sh1106.c b/drivers/staging/fbtft/fb_sh1106.c
index 89c27a440305..3fc18c0a6f11 100644
--- a/drivers/staging/fbtft/fb_sh1106.c
+++ b/drivers/staging/fbtft/fb_sh1106.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the SH1106 OLED Controller 3 * FB driver for the SH1106 OLED Controller
3 * Based on the SSD1306 driver by Noralf Tronnes 4 * Based on the SSD1306 driver by Noralf Tronnes
4 * 5 *
5 * Copyright (C) 2017 Heiner Kallweit 6 * Copyright (C) 2017 Heiner Kallweit
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */ 7 */
17 8
18#include <linux/module.h> 9#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ssd1289.c b/drivers/staging/fbtft/fb_ssd1289.c
index 129e175fcd7e..cbf22e1f4b61 100644
--- a/drivers/staging/fbtft/fb_ssd1289.c
+++ b/drivers/staging/fbtft/fb_ssd1289.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the SSD1289 LCD Controller 3 * FB driver for the SSD1289 LCD Controller
3 * 4 *
4 * Copyright (C) 2013 Noralf Tronnes 5 * Copyright (C) 2013 Noralf Tronnes
5 * 6 *
6 * Init sequence taken from ITDB02_Graph16.cpp - (C)2010-2011 Henning Karlsen 7 * Init sequence taken from ITDB02_Graph16.cpp - (C)2010-2011 Henning Karlsen
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/module.h> 10#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ssd1305.c b/drivers/staging/fbtft/fb_ssd1305.c
index 33c03872ca84..3515888d94c9 100644
--- a/drivers/staging/fbtft/fb_ssd1305.c
+++ b/drivers/staging/fbtft/fb_ssd1305.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the SSD1305 OLED Controller 3 * FB driver for the SSD1305 OLED Controller
3 * 4 *
4 * based on SSD1306 driver by Noralf Tronnes 5 * based on SSD1306 driver by Noralf Tronnes
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ssd1306.c b/drivers/staging/fbtft/fb_ssd1306.c
index 96c58de85288..9276be499303 100644
--- a/drivers/staging/fbtft/fb_ssd1306.c
+++ b/drivers/staging/fbtft/fb_ssd1306.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the SSD1306 OLED Controller 3 * FB driver for the SSD1306 OLED Controller
3 * 4 *
4 * Copyright (C) 2013 Noralf Tronnes 5 * Copyright (C) 2013 Noralf Tronnes
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ssd1325.c b/drivers/staging/fbtft/fb_ssd1325.c
index b7e40c24f58e..1a469b3c92d4 100644
--- a/drivers/staging/fbtft/fb_ssd1325.c
+++ b/drivers/staging/fbtft/fb_ssd1325.c
@@ -1,15 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the SSD1325 OLED Controller 3 * FB driver for the SSD1325 OLED Controller
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */ 4 */
14 5
15#include <linux/module.h> 6#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_ssd1331.c b/drivers/staging/fbtft/fb_ssd1331.c
index e4a759b54ba0..383e197cf56a 100644
--- a/drivers/staging/fbtft/fb_ssd1331.c
+++ b/drivers/staging/fbtft/fb_ssd1331.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/module.h> 2#include <linux/module.h>
2#include <linux/kernel.h> 3#include <linux/kernel.h>
3#include <linux/init.h> 4#include <linux/init.h>
diff --git a/drivers/staging/fbtft/fb_ssd1351.c b/drivers/staging/fbtft/fb_ssd1351.c
index e62235d4d9e7..b8ef75f5e856 100644
--- a/drivers/staging/fbtft/fb_ssd1351.c
+++ b/drivers/staging/fbtft/fb_ssd1351.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/module.h> 2#include <linux/module.h>
2#include <linux/kernel.h> 3#include <linux/kernel.h>
3#include <linux/init.h> 4#include <linux/init.h>
diff --git a/drivers/staging/fbtft/fb_st7735r.c b/drivers/staging/fbtft/fb_st7735r.c
index d98522a39344..631208bd3a17 100644
--- a/drivers/staging/fbtft/fb_st7735r.c
+++ b/drivers/staging/fbtft/fb_st7735r.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the ST7735R LCD Controller 3 * FB driver for the ST7735R LCD Controller
3 * 4 *
4 * Copyright (C) 2013 Noralf Tronnes 5 * Copyright (C) 2013 Noralf Tronnes
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_st7789v.c b/drivers/staging/fbtft/fb_st7789v.c
index a5d7c87557f8..7d7573a7b615 100644
--- a/drivers/staging/fbtft/fb_st7789v.c
+++ b/drivers/staging/fbtft/fb_st7789v.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the ST7789V LCD Controller 3 * FB driver for the ST7789V LCD Controller
3 * 4 *
4 * Copyright (C) 2015 Dennis Menschel 5 * Copyright (C) 2015 Dennis Menschel
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/bitops.h> 8#include <linux/bitops.h>
diff --git a/drivers/staging/fbtft/fb_tinylcd.c b/drivers/staging/fbtft/fb_tinylcd.c
index 097e71cfef62..e463b0ddf16d 100644
--- a/drivers/staging/fbtft/fb_tinylcd.c
+++ b/drivers/staging/fbtft/fb_tinylcd.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Custom FB driver for tinylcd.com display 3 * Custom FB driver for tinylcd.com display
3 * 4 *
4 * Copyright (C) 2013 Noralf Tronnes 5 * Copyright (C) 2013 Noralf Tronnes
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_tls8204.c b/drivers/staging/fbtft/fb_tls8204.c
index 4302e822de3b..277b6ed9c725 100644
--- a/drivers/staging/fbtft/fb_tls8204.c
+++ b/drivers/staging/fbtft/fb_tls8204.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the TLS8204 LCD Controller 3 * FB driver for the TLS8204 LCD Controller
3 * 4 *
@@ -6,16 +7,6 @@
6 * 7 *
7 * Copyright (C) 2013 Noralf Tronnes 8 * Copyright (C) 2013 Noralf Tronnes
8 * Copyright (C) 2014 Michael Hope (adapted for the TLS8204) 9 * Copyright (C) 2014 Michael Hope (adapted for the TLS8204)
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21#include <linux/module.h> 12#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_uc1611.c b/drivers/staging/fbtft/fb_uc1611.c
index 8eb5e7f10fb5..4d65567eefe2 100644
--- a/drivers/staging/fbtft/fb_uc1611.c
+++ b/drivers/staging/fbtft/fb_uc1611.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the UltraChip UC1611 LCD controller 3 * FB driver for the UltraChip UC1611 LCD controller
3 * 4 *
4 * The display is 4-bit grayscale (16 shades) 240x160. 5 * The display is 4-bit grayscale (16 shades) 240x160.
5 * 6 *
6 * Copyright (C) 2015 Henri Chain 7 * Copyright (C) 2015 Henri Chain
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/module.h> 10#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_uc1701.c b/drivers/staging/fbtft/fb_uc1701.c
index 78899a172c7e..0a3531d6eb39 100644
--- a/drivers/staging/fbtft/fb_uc1701.c
+++ b/drivers/staging/fbtft/fb_uc1701.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the UC1701 LCD Controller 3 * FB driver for the UC1701 LCD Controller
3 * 4 *
@@ -5,16 +6,6 @@
5 * Any pixel value except 0 turns the pixel on. 6 * Any pixel value except 0 turns the pixel on.
6 * 7 *
7 * Copyright (C) 2014 Juergen Holzmann 8 * Copyright (C) 2014 Juergen Holzmann
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */ 9 */
19 10
20#include <linux/module.h> 11#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_upd161704.c b/drivers/staging/fbtft/fb_upd161704.c
index 970b8430eccf..acc425fdf34e 100644
--- a/drivers/staging/fbtft/fb_upd161704.c
+++ b/drivers/staging/fbtft/fb_upd161704.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the uPD161704 LCD Controller 3 * FB driver for the uPD161704 LCD Controller
3 * 4 *
@@ -6,16 +7,6 @@
6 * Based on fb_ili9325.c by Noralf Tronnes 7 * Based on fb_ili9325.c by Noralf Tronnes
7 * Based on ili9325.c by Jeroen Domburg 8 * Based on ili9325.c by Jeroen Domburg
8 * Init code from UTFT library by Henning Karlsen 9 * Init code from UTFT library by Henning Karlsen
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21#include <linux/module.h> 12#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fb_watterott.c b/drivers/staging/fbtft/fb_watterott.c
index 180e5be6fa4f..bfd1527f20f7 100644
--- a/drivers/staging/fbtft/fb_watterott.c
+++ b/drivers/staging/fbtft/fb_watterott.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FB driver for the Watterott LCD Controller 3 * FB driver for the Watterott LCD Controller
3 * 4 *
4 * Copyright (C) 2013 Noralf Tronnes 5 * Copyright (C) 2013 Noralf Tronnes
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
index 6d0363deba61..0e36b66ae5f7 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (C) 2013 Noralf Tronnes 3 * Copyright (C) 2013 Noralf Tronnes
3 * 4 *
4 * This driver is inspired by: 5 * This driver is inspired by:
5 * st7735fb.c, Copyright (C) 2011, Matt Porter 6 * st7735fb.c, Copyright (C) 2011, Matt Porter
6 * broadsheetfb.c, Copyright (C) 2008, Jaya Kumar 7 * broadsheetfb.c, Copyright (C) 2008, Jaya Kumar
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/module.h> 10#include <linux/module.h>
@@ -1367,20 +1358,18 @@ int fbtft_probe_common(struct fbtft_display *display,
1367 } 1358 }
1368 1359
1369 /* write register functions */ 1360 /* write register functions */
1370 if (display->regwidth == 8 && display->buswidth == 8) { 1361 if (display->regwidth == 8 && display->buswidth == 8)
1371 par->fbtftops.write_register = fbtft_write_reg8_bus8; 1362 par->fbtftops.write_register = fbtft_write_reg8_bus8;
1372 } else 1363 else if (display->regwidth == 8 && display->buswidth == 9 && par->spi)
1373 if (display->regwidth == 8 && display->buswidth == 9 && par->spi) {
1374 par->fbtftops.write_register = fbtft_write_reg8_bus9; 1364 par->fbtftops.write_register = fbtft_write_reg8_bus9;
1375 } else if (display->regwidth == 16 && display->buswidth == 8) { 1365 else if (display->regwidth == 16 && display->buswidth == 8)
1376 par->fbtftops.write_register = fbtft_write_reg16_bus8; 1366 par->fbtftops.write_register = fbtft_write_reg16_bus8;
1377 } else if (display->regwidth == 16 && display->buswidth == 16) { 1367 else if (display->regwidth == 16 && display->buswidth == 16)
1378 par->fbtftops.write_register = fbtft_write_reg16_bus16; 1368 par->fbtftops.write_register = fbtft_write_reg16_bus16;
1379 } else { 1369 else
1380 dev_warn(dev, 1370 dev_warn(dev,
1381 "no default functions for regwidth=%d and buswidth=%d\n", 1371 "no default functions for regwidth=%d and buswidth=%d\n",
1382 display->regwidth, display->buswidth); 1372 display->regwidth, display->buswidth);
1383 }
1384 1373
1385 /* write_vmem() functions */ 1374 /* write_vmem() functions */
1386 if (display->buswidth == 8) 1375 if (display->buswidth == 8)
diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h
index 488ab788138e..e19e64e0d094 100644
--- a/drivers/staging/fbtft/fbtft.h
+++ b/drivers/staging/fbtft/fbtft.h
@@ -1,16 +1,5 @@
1/* 1/* SPDX-License-Identifier: GPL-2.0+ */
2 * Copyright (C) 2013 Noralf Tronnes 2/* Copyright (C) 2013 Noralf Tronnes */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14 3
15#ifndef __LINUX_FBTFT_H 4#ifndef __LINUX_FBTFT_H
16#define __LINUX_FBTFT_H 5#define __LINUX_FBTFT_H
diff --git a/drivers/staging/fbtft/fbtft_device.c b/drivers/staging/fbtft/fbtft_device.c
index 0d974738c1c4..ec8477674b7d 100644
--- a/drivers/staging/fbtft/fbtft_device.c
+++ b/drivers/staging/fbtft/fbtft_device.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * 3 *
3 * Copyright (C) 2013, Noralf Tronnes 4 * Copyright (C) 2013, Noralf Tronnes
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 */ 5 */
15 6
16#define pr_fmt(fmt) "fbtft_device: " fmt 7#define pr_fmt(fmt) "fbtft_device: " fmt
diff --git a/drivers/staging/fbtft/flexfb.c b/drivers/staging/fbtft/flexfb.c
index 7134624a16c2..f676c9b853f1 100644
--- a/drivers/staging/fbtft/flexfb.c
+++ b/drivers/staging/fbtft/flexfb.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Generic FB driver for TFT LCD displays 3 * Generic FB driver for TFT LCD displays
3 * 4 *
4 * Copyright (C) 2013 Noralf Tronnes 5 * Copyright (C) 2013 Noralf Tronnes
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/fbtft/internal.h b/drivers/staging/fbtft/internal.h
index 25b9bf6f54bb..ae2ff4a4a472 100644
--- a/drivers/staging/fbtft/internal.h
+++ b/drivers/staging/fbtft/internal.h
@@ -1,17 +1,5 @@
1/* 1/* SPDX-License-Identifier: GPL-2.0+ */
2 * Copyright (C) 2013 Noralf Tronnes 2/* Copyright (C) 2013 Noralf Tronnes */
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15 3
16#ifndef __LINUX_FBTFT_INTERNAL_H 4#ifndef __LINUX_FBTFT_INTERNAL_H
17#define __LINUX_FBTFT_INTERNAL_H 5#define __LINUX_FBTFT_INTERNAL_H
diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
index 0d8ed002adcb..2817e67df3d5 100644
--- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
+++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
@@ -230,7 +230,8 @@ static struct sk_buff *build_frag_skb(struct dpaa2_eth_priv *priv,
230static void dpaa2_eth_rx(struct dpaa2_eth_priv *priv, 230static void dpaa2_eth_rx(struct dpaa2_eth_priv *priv,
231 struct dpaa2_eth_channel *ch, 231 struct dpaa2_eth_channel *ch,
232 const struct dpaa2_fd *fd, 232 const struct dpaa2_fd *fd,
233 struct napi_struct *napi) 233 struct napi_struct *napi,
234 u16 queue_id)
234{ 235{
235 dma_addr_t addr = dpaa2_fd_get_addr(fd); 236 dma_addr_t addr = dpaa2_fd_get_addr(fd);
236 u8 fd_format = dpaa2_fd_get_format(fd); 237 u8 fd_format = dpaa2_fd_get_format(fd);
@@ -249,7 +250,7 @@ static void dpaa2_eth_rx(struct dpaa2_eth_priv *priv,
249 vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr); 250 vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr);
250 dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE, DMA_FROM_DEVICE); 251 dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE, DMA_FROM_DEVICE);
251 252
252 fas = dpaa2_get_fas(vaddr); 253 fas = dpaa2_get_fas(vaddr, false);
253 prefetch(fas); 254 prefetch(fas);
254 buf_data = vaddr + dpaa2_fd_get_offset(fd); 255 buf_data = vaddr + dpaa2_fd_get_offset(fd);
255 prefetch(buf_data); 256 prefetch(buf_data);
@@ -281,6 +282,7 @@ static void dpaa2_eth_rx(struct dpaa2_eth_priv *priv,
281 } 282 }
282 283
283 skb->protocol = eth_type_trans(skb, priv->net_dev); 284 skb->protocol = eth_type_trans(skb, priv->net_dev);
285 skb_record_rx_queue(skb, queue_id);
284 286
285 percpu_stats->rx_packets++; 287 percpu_stats->rx_packets++;
286 percpu_stats->rx_bytes += dpaa2_fd_get_len(fd); 288 percpu_stats->rx_bytes += dpaa2_fd_get_len(fd);
@@ -325,7 +327,7 @@ static int consume_frames(struct dpaa2_eth_channel *ch)
325 fq = (struct dpaa2_eth_fq *)dpaa2_dq_fqd_ctx(dq); 327 fq = (struct dpaa2_eth_fq *)dpaa2_dq_fqd_ctx(dq);
326 fq->stats.frames++; 328 fq->stats.frames++;
327 329
328 fq->consume(priv, ch, fd, &ch->napi); 330 fq->consume(priv, ch, fd, &ch->napi, fq->flowid);
329 cleaned++; 331 cleaned++;
330 } while (!is_last); 332 } while (!is_last);
331 333
@@ -348,7 +350,6 @@ static int build_sg_fd(struct dpaa2_eth_priv *priv,
348 int num_sg; 350 int num_sg;
349 int num_dma_bufs; 351 int num_dma_bufs;
350 struct dpaa2_eth_swa *swa; 352 struct dpaa2_eth_swa *swa;
351 struct dpaa2_fas *fas;
352 353
353 /* Create and map scatterlist. 354 /* Create and map scatterlist.
354 * We don't advertise NETIF_F_FRAGLIST, so skb_to_sgvec() will not have 355 * We don't advertise NETIF_F_FRAGLIST, so skb_to_sgvec() will not have
@@ -379,15 +380,6 @@ static int build_sg_fd(struct dpaa2_eth_priv *priv,
379 goto sgt_buf_alloc_failed; 380 goto sgt_buf_alloc_failed;
380 } 381 }
381 sgt_buf = PTR_ALIGN(sgt_buf, DPAA2_ETH_TX_BUF_ALIGN); 382 sgt_buf = PTR_ALIGN(sgt_buf, DPAA2_ETH_TX_BUF_ALIGN);
382
383 /* PTA from egress side is passed as is to the confirmation side so
384 * we need to clear some fields here in order to find consistent values
385 * on TX confirmation. We are clearing FAS (Frame Annotation Status)
386 * field from the hardware annotation area
387 */
388 fas = dpaa2_get_fas(sgt_buf);
389 memset(fas, 0, DPAA2_FAS_SIZE);
390
391 sgt = (struct dpaa2_sg_entry *)(sgt_buf + priv->tx_data_offset); 383 sgt = (struct dpaa2_sg_entry *)(sgt_buf + priv->tx_data_offset);
392 384
393 /* Fill in the HW SGT structure. 385 /* Fill in the HW SGT structure.
@@ -424,8 +416,7 @@ static int build_sg_fd(struct dpaa2_eth_priv *priv,
424 dpaa2_fd_set_format(fd, dpaa2_fd_sg); 416 dpaa2_fd_set_format(fd, dpaa2_fd_sg);
425 dpaa2_fd_set_addr(fd, addr); 417 dpaa2_fd_set_addr(fd, addr);
426 dpaa2_fd_set_len(fd, skb->len); 418 dpaa2_fd_set_len(fd, skb->len);
427 dpaa2_fd_set_ctrl(fd, DPAA2_FD_CTRL_ASAL | DPAA2_FD_CTRL_PTA | 419 dpaa2_fd_set_ctrl(fd, DPAA2_FD_CTRL_PTA | DPAA2_FD_CTRL_PTV1);
428 DPAA2_FD_CTRL_PTV1);
429 420
430 return 0; 421 return 0;
431 422
@@ -444,22 +435,19 @@ static int build_single_fd(struct dpaa2_eth_priv *priv,
444 struct dpaa2_fd *fd) 435 struct dpaa2_fd *fd)
445{ 436{
446 struct device *dev = priv->net_dev->dev.parent; 437 struct device *dev = priv->net_dev->dev.parent;
447 u8 *buffer_start; 438 u8 *buffer_start, *aligned_start;
448 struct dpaa2_fas *fas;
449 struct sk_buff **skbh; 439 struct sk_buff **skbh;
450 dma_addr_t addr; 440 dma_addr_t addr;
451 441
452 buffer_start = PTR_ALIGN(skb->data - priv->tx_data_offset - 442 buffer_start = skb->data - dpaa2_eth_needed_headroom(priv, skb);
453 DPAA2_ETH_TX_BUF_ALIGN,
454 DPAA2_ETH_TX_BUF_ALIGN);
455 443
456 /* PTA from egress side is passed as is to the confirmation side so 444 /* If there's enough room to align the FD address, do it.
457 * we need to clear some fields here in order to find consistent values 445 * It will help hardware optimize accesses.
458 * on TX confirmation. We are clearing FAS (Frame Annotation Status)
459 * field from the hardware annotation area
460 */ 446 */
461 fas = dpaa2_get_fas(buffer_start); 447 aligned_start = PTR_ALIGN(buffer_start - DPAA2_ETH_TX_BUF_ALIGN,
462 memset(fas, 0, DPAA2_FAS_SIZE); 448 DPAA2_ETH_TX_BUF_ALIGN);
449 if (aligned_start >= skb->head)
450 buffer_start = aligned_start;
463 451
464 /* Store a backpointer to the skb at the beginning of the buffer 452 /* Store a backpointer to the skb at the beginning of the buffer
465 * (in the private data area) such that we can release it 453 * (in the private data area) such that we can release it
@@ -478,8 +466,7 @@ static int build_single_fd(struct dpaa2_eth_priv *priv,
478 dpaa2_fd_set_offset(fd, (u16)(skb->data - buffer_start)); 466 dpaa2_fd_set_offset(fd, (u16)(skb->data - buffer_start));
479 dpaa2_fd_set_len(fd, skb->len); 467 dpaa2_fd_set_len(fd, skb->len);
480 dpaa2_fd_set_format(fd, dpaa2_fd_single); 468 dpaa2_fd_set_format(fd, dpaa2_fd_single);
481 dpaa2_fd_set_ctrl(fd, DPAA2_FD_CTRL_ASAL | DPAA2_FD_CTRL_PTA | 469 dpaa2_fd_set_ctrl(fd, DPAA2_FD_CTRL_PTA | DPAA2_FD_CTRL_PTV1);
482 DPAA2_FD_CTRL_PTV1);
483 470
484 return 0; 471 return 0;
485} 472}
@@ -494,8 +481,7 @@ static int build_single_fd(struct dpaa2_eth_priv *priv,
494 * to be checked if we're on the confirmation path. 481 * to be checked if we're on the confirmation path.
495 */ 482 */
496static void free_tx_fd(const struct dpaa2_eth_priv *priv, 483static void free_tx_fd(const struct dpaa2_eth_priv *priv,
497 const struct dpaa2_fd *fd, 484 const struct dpaa2_fd *fd)
498 u32 *status)
499{ 485{
500 struct device *dev = priv->net_dev->dev.parent; 486 struct device *dev = priv->net_dev->dev.parent;
501 dma_addr_t fd_addr; 487 dma_addr_t fd_addr;
@@ -506,11 +492,9 @@ static void free_tx_fd(const struct dpaa2_eth_priv *priv,
506 int num_sg, num_dma_bufs; 492 int num_sg, num_dma_bufs;
507 struct dpaa2_eth_swa *swa; 493 struct dpaa2_eth_swa *swa;
508 u8 fd_format = dpaa2_fd_get_format(fd); 494 u8 fd_format = dpaa2_fd_get_format(fd);
509 struct dpaa2_fas *fas;
510 495
511 fd_addr = dpaa2_fd_get_addr(fd); 496 fd_addr = dpaa2_fd_get_addr(fd);
512 skbh = dpaa2_iova_to_virt(priv->iommu_domain, fd_addr); 497 skbh = dpaa2_iova_to_virt(priv->iommu_domain, fd_addr);
513 fas = dpaa2_get_fas(skbh);
514 498
515 if (fd_format == dpaa2_fd_single) { 499 if (fd_format == dpaa2_fd_single) {
516 skb = *skbh; 500 skb = *skbh;
@@ -537,19 +521,10 @@ static void free_tx_fd(const struct dpaa2_eth_priv *priv,
537 sizeof(struct dpaa2_sg_entry) * (1 + num_dma_bufs); 521 sizeof(struct dpaa2_sg_entry) * (1 + num_dma_bufs);
538 dma_unmap_single(dev, fd_addr, unmap_size, DMA_BIDIRECTIONAL); 522 dma_unmap_single(dev, fd_addr, unmap_size, DMA_BIDIRECTIONAL);
539 } else { 523 } else {
540 /* Unsupported format, mark it as errored and give up */ 524 netdev_dbg(priv->net_dev, "Invalid FD format\n");
541 if (status)
542 *status = ~0;
543 return; 525 return;
544 } 526 }
545 527
546 /* Read the status from the Frame Annotation after we unmap the first
547 * buffer but before we free it. The caller function is responsible
548 * for checking the status value.
549 */
550 if (status)
551 *status = le32_to_cpu(fas->status);
552
553 /* Free SGT buffer kmalloc'ed on tx */ 528 /* Free SGT buffer kmalloc'ed on tx */
554 if (fd_format != dpaa2_fd_single) 529 if (fd_format != dpaa2_fd_single)
555 kfree(skbh); 530 kfree(skbh);
@@ -566,19 +541,22 @@ static netdev_tx_t dpaa2_eth_tx(struct sk_buff *skb, struct net_device *net_dev)
566 struct dpaa2_eth_drv_stats *percpu_extras; 541 struct dpaa2_eth_drv_stats *percpu_extras;
567 struct dpaa2_eth_fq *fq; 542 struct dpaa2_eth_fq *fq;
568 u16 queue_mapping; 543 u16 queue_mapping;
544 unsigned int needed_headroom;
569 int err, i; 545 int err, i;
570 546
571 percpu_stats = this_cpu_ptr(priv->percpu_stats); 547 percpu_stats = this_cpu_ptr(priv->percpu_stats);
572 percpu_extras = this_cpu_ptr(priv->percpu_extras); 548 percpu_extras = this_cpu_ptr(priv->percpu_extras);
573 549
574 if (unlikely(skb_headroom(skb) < dpaa2_eth_needed_headroom(priv))) { 550 needed_headroom = dpaa2_eth_needed_headroom(priv, skb);
551 if (skb_headroom(skb) < needed_headroom) {
575 struct sk_buff *ns; 552 struct sk_buff *ns;
576 553
577 ns = skb_realloc_headroom(skb, dpaa2_eth_needed_headroom(priv)); 554 ns = skb_realloc_headroom(skb, needed_headroom);
578 if (unlikely(!ns)) { 555 if (unlikely(!ns)) {
579 percpu_stats->tx_dropped++; 556 percpu_stats->tx_dropped++;
580 goto err_alloc_headroom; 557 goto err_alloc_headroom;
581 } 558 }
559 percpu_extras->tx_reallocs++;
582 dev_kfree_skb(skb); 560 dev_kfree_skb(skb);
583 skb = ns; 561 skb = ns;
584 } 562 }
@@ -612,13 +590,15 @@ static netdev_tx_t dpaa2_eth_tx(struct sk_buff *skb, struct net_device *net_dev)
612 /* Tracing point */ 590 /* Tracing point */
613 trace_dpaa2_tx_fd(net_dev, &fd); 591 trace_dpaa2_tx_fd(net_dev, &fd);
614 592
615 /* TxConf FQ selection primarily based on cpu affinity; this is 593 /* TxConf FQ selection relies on queue id from the stack.
616 * non-migratable context, so it's safe to call smp_processor_id(). 594 * In case of a forwarded frame from another DPNI interface, we choose
595 * a queue affined to the same core that processed the Rx frame
617 */ 596 */
618 queue_mapping = smp_processor_id() % dpaa2_eth_queue_count(priv); 597 queue_mapping = skb_get_queue_mapping(skb);
619 fq = &priv->fq[queue_mapping]; 598 fq = &priv->fq[queue_mapping];
620 for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) { 599 for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) {
621 err = dpaa2_io_service_enqueue_qd(NULL, priv->tx_qdid, 0, 600 err = dpaa2_io_service_enqueue_qd(fq->channel->dpio,
601 priv->tx_qdid, 0,
622 fq->tx_qdbin, &fd); 602 fq->tx_qdbin, &fd);
623 if (err != -EBUSY) 603 if (err != -EBUSY)
624 break; 604 break;
@@ -627,7 +607,7 @@ static netdev_tx_t dpaa2_eth_tx(struct sk_buff *skb, struct net_device *net_dev)
627 if (unlikely(err < 0)) { 607 if (unlikely(err < 0)) {
628 percpu_stats->tx_errors++; 608 percpu_stats->tx_errors++;
629 /* Clean up everything, including freeing the skb */ 609 /* Clean up everything, including freeing the skb */
630 free_tx_fd(priv, &fd, NULL); 610 free_tx_fd(priv, &fd);
631 } else { 611 } else {
632 percpu_stats->tx_packets++; 612 percpu_stats->tx_packets++;
633 percpu_stats->tx_bytes += dpaa2_fd_get_len(&fd); 613 percpu_stats->tx_bytes += dpaa2_fd_get_len(&fd);
@@ -646,13 +626,12 @@ err_alloc_headroom:
646static void dpaa2_eth_tx_conf(struct dpaa2_eth_priv *priv, 626static void dpaa2_eth_tx_conf(struct dpaa2_eth_priv *priv,
647 struct dpaa2_eth_channel *ch, 627 struct dpaa2_eth_channel *ch,
648 const struct dpaa2_fd *fd, 628 const struct dpaa2_fd *fd,
649 struct napi_struct *napi __always_unused) 629 struct napi_struct *napi __always_unused,
630 u16 queue_id __always_unused)
650{ 631{
651 struct rtnl_link_stats64 *percpu_stats; 632 struct rtnl_link_stats64 *percpu_stats;
652 struct dpaa2_eth_drv_stats *percpu_extras; 633 struct dpaa2_eth_drv_stats *percpu_extras;
653 u32 status = 0;
654 u32 fd_errors; 634 u32 fd_errors;
655 bool has_fas_errors = false;
656 635
657 /* Tracing point */ 636 /* Tracing point */
658 trace_dpaa2_tx_conf_fd(priv->net_dev, fd); 637 trace_dpaa2_tx_conf_fd(priv->net_dev, fd);
@@ -663,29 +642,18 @@ static void dpaa2_eth_tx_conf(struct dpaa2_eth_priv *priv,
663 642
664 /* Check frame errors in the FD field */ 643 /* Check frame errors in the FD field */
665 fd_errors = dpaa2_fd_get_ctrl(fd) & DPAA2_FD_TX_ERR_MASK; 644 fd_errors = dpaa2_fd_get_ctrl(fd) & DPAA2_FD_TX_ERR_MASK;
666 if (unlikely(fd_errors)) { 645 free_tx_fd(priv, fd);
667 /* We only check error bits in the FAS field if corresponding
668 * FAERR bit is set in FD and the FAS field is marked as valid
669 */
670 has_fas_errors = (fd_errors & DPAA2_FD_CTRL_FAERR) &&
671 !!(dpaa2_fd_get_frc(fd) & DPAA2_FD_FRC_FASV);
672 if (net_ratelimit())
673 netdev_dbg(priv->net_dev, "TX frame FD error: 0x%08x\n",
674 fd_errors);
675 }
676
677 free_tx_fd(priv, fd, has_fas_errors ? &status : NULL);
678 646
679 if (likely(!fd_errors)) 647 if (likely(!fd_errors))
680 return; 648 return;
681 649
650 if (net_ratelimit())
651 netdev_dbg(priv->net_dev, "TX frame FD error: 0x%08x\n",
652 fd_errors);
653
682 percpu_stats = this_cpu_ptr(priv->percpu_stats); 654 percpu_stats = this_cpu_ptr(priv->percpu_stats);
683 /* Tx-conf logically pertains to the egress path. */ 655 /* Tx-conf logically pertains to the egress path. */
684 percpu_stats->tx_errors++; 656 percpu_stats->tx_errors++;
685
686 if (has_fas_errors && net_ratelimit())
687 netdev_dbg(priv->net_dev, "TX frame FAS error: 0x%08x\n",
688 status & DPAA2_FAS_TX_ERR_MASK);
689} 657}
690 658
691static int set_rx_csum(struct dpaa2_eth_priv *priv, bool enable) 659static int set_rx_csum(struct dpaa2_eth_priv *priv, bool enable)
@@ -752,7 +720,8 @@ static void free_bufs(struct dpaa2_eth_priv *priv, u64 *buf_array, int count)
752/* Perform a single release command to add buffers 720/* Perform a single release command to add buffers
753 * to the specified buffer pool 721 * to the specified buffer pool
754 */ 722 */
755static int add_bufs(struct dpaa2_eth_priv *priv, u16 bpid) 723static int add_bufs(struct dpaa2_eth_priv *priv,
724 struct dpaa2_eth_channel *ch, u16 bpid)
756{ 725{
757 struct device *dev = priv->net_dev->dev.parent; 726 struct device *dev = priv->net_dev->dev.parent;
758 u64 buf_array[DPAA2_ETH_BUFS_PER_CMD]; 727 u64 buf_array[DPAA2_ETH_BUFS_PER_CMD];
@@ -786,7 +755,7 @@ static int add_bufs(struct dpaa2_eth_priv *priv, u16 bpid)
786 755
787release_bufs: 756release_bufs:
788 /* In case the portal is busy, retry until successful */ 757 /* In case the portal is busy, retry until successful */
789 while ((err = dpaa2_io_service_release(NULL, bpid, 758 while ((err = dpaa2_io_service_release(ch->dpio, bpid,
790 buf_array, i)) == -EBUSY) 759 buf_array, i)) == -EBUSY)
791 cpu_relax(); 760 cpu_relax();
792 761
@@ -827,7 +796,7 @@ static int seed_pool(struct dpaa2_eth_priv *priv, u16 bpid)
827 for (j = 0; j < priv->num_channels; j++) { 796 for (j = 0; j < priv->num_channels; j++) {
828 for (i = 0; i < DPAA2_ETH_NUM_BUFS; 797 for (i = 0; i < DPAA2_ETH_NUM_BUFS;
829 i += DPAA2_ETH_BUFS_PER_CMD) { 798 i += DPAA2_ETH_BUFS_PER_CMD) {
830 new_count = add_bufs(priv, bpid); 799 new_count = add_bufs(priv, priv->channel[j], bpid);
831 priv->channel[j]->buf_count += new_count; 800 priv->channel[j]->buf_count += new_count;
832 801
833 if (new_count < DPAA2_ETH_BUFS_PER_CMD) { 802 if (new_count < DPAA2_ETH_BUFS_PER_CMD) {
@@ -885,7 +854,7 @@ static int refill_pool(struct dpaa2_eth_priv *priv,
885 return 0; 854 return 0;
886 855
887 do { 856 do {
888 new_count = add_bufs(priv, bpid); 857 new_count = add_bufs(priv, ch, bpid);
889 if (unlikely(!new_count)) { 858 if (unlikely(!new_count)) {
890 /* Out of memory; abort for now, we'll try later on */ 859 /* Out of memory; abort for now, we'll try later on */
891 break; 860 break;
@@ -906,7 +875,8 @@ static int pull_channel(struct dpaa2_eth_channel *ch)
906 875
907 /* Retry while portal is busy */ 876 /* Retry while portal is busy */
908 do { 877 do {
909 err = dpaa2_io_service_pull_channel(NULL, ch->ch_id, ch->store); 878 err = dpaa2_io_service_pull_channel(ch->dpio, ch->ch_id,
879 ch->store);
910 dequeues++; 880 dequeues++;
911 cpu_relax(); 881 cpu_relax();
912 } while (err == -EBUSY); 882 } while (err == -EBUSY);
@@ -956,7 +926,7 @@ static int dpaa2_eth_poll(struct napi_struct *napi, int budget)
956 if (cleaned < budget && napi_complete_done(napi, cleaned)) { 926 if (cleaned < budget && napi_complete_done(napi, cleaned)) {
957 /* Re-enable data available notifications */ 927 /* Re-enable data available notifications */
958 do { 928 do {
959 err = dpaa2_io_service_rearm(NULL, &ch->nctx); 929 err = dpaa2_io_service_rearm(ch->dpio, &ch->nctx);
960 cpu_relax(); 930 cpu_relax();
961 } while (err == -EBUSY); 931 } while (err == -EBUSY);
962 WARN_ONCE(err, "CDAN notifications rearm failed on core %d", 932 WARN_ONCE(err, "CDAN notifications rearm failed on core %d",
@@ -1564,7 +1534,8 @@ static int setup_dpio(struct dpaa2_eth_priv *priv)
1564 nctx->desired_cpu = i; 1534 nctx->desired_cpu = i;
1565 1535
1566 /* Register the new context */ 1536 /* Register the new context */
1567 err = dpaa2_io_service_register(NULL, nctx); 1537 channel->dpio = dpaa2_io_service_select(i);
1538 err = dpaa2_io_service_register(channel->dpio, nctx);
1568 if (err) { 1539 if (err) {
1569 dev_dbg(dev, "No affine DPIO for cpu %d\n", i); 1540 dev_dbg(dev, "No affine DPIO for cpu %d\n", i);
1570 /* If no affine DPIO for this core, there's probably 1541 /* If no affine DPIO for this core, there's probably
@@ -1604,7 +1575,7 @@ static int setup_dpio(struct dpaa2_eth_priv *priv)
1604 return 0; 1575 return 0;
1605 1576
1606err_set_cdan: 1577err_set_cdan:
1607 dpaa2_io_service_deregister(NULL, nctx); 1578 dpaa2_io_service_deregister(channel->dpio, nctx);
1608err_service_reg: 1579err_service_reg:
1609 free_channel(priv, channel); 1580 free_channel(priv, channel);
1610err_alloc_ch: 1581err_alloc_ch:
@@ -1627,7 +1598,7 @@ static void free_dpio(struct dpaa2_eth_priv *priv)
1627 /* deregister CDAN notifications and free channels */ 1598 /* deregister CDAN notifications and free channels */
1628 for (i = 0; i < priv->num_channels; i++) { 1599 for (i = 0; i < priv->num_channels; i++) {
1629 ch = priv->channel[i]; 1600 ch = priv->channel[i];
1630 dpaa2_io_service_deregister(NULL, &ch->nctx); 1601 dpaa2_io_service_deregister(ch->dpio, &ch->nctx);
1631 free_channel(priv, ch); 1602 free_channel(priv, ch);
1632 } 1603 }
1633} 1604}
@@ -1653,9 +1624,10 @@ static struct dpaa2_eth_channel *get_affine_channel(struct dpaa2_eth_priv *priv,
1653static void set_fq_affinity(struct dpaa2_eth_priv *priv) 1624static void set_fq_affinity(struct dpaa2_eth_priv *priv)
1654{ 1625{
1655 struct device *dev = priv->net_dev->dev.parent; 1626 struct device *dev = priv->net_dev->dev.parent;
1627 struct cpumask xps_mask;
1656 struct dpaa2_eth_fq *fq; 1628 struct dpaa2_eth_fq *fq;
1657 int rx_cpu, txc_cpu; 1629 int rx_cpu, txc_cpu;
1658 int i; 1630 int i, err;
1659 1631
1660 /* For each FQ, pick one channel/CPU to deliver frames to. 1632 /* For each FQ, pick one channel/CPU to deliver frames to.
1661 * This may well change at runtime, either through irqbalance or 1633 * This may well change at runtime, either through irqbalance or
@@ -1674,6 +1646,17 @@ static void set_fq_affinity(struct dpaa2_eth_priv *priv)
1674 break; 1646 break;
1675 case DPAA2_TX_CONF_FQ: 1647 case DPAA2_TX_CONF_FQ:
1676 fq->target_cpu = txc_cpu; 1648 fq->target_cpu = txc_cpu;
1649
1650 /* Tell the stack to affine to txc_cpu the Tx queue
1651 * associated with the confirmation one
1652 */
1653 cpumask_clear(&xps_mask);
1654 cpumask_set_cpu(txc_cpu, &xps_mask);
1655 err = netif_set_xps_queue(priv->net_dev, &xps_mask,
1656 fq->flowid);
1657 if (err)
1658 dev_err(dev, "Error setting XPS queue\n");
1659
1677 txc_cpu = cpumask_next(txc_cpu, &priv->dpio_cpumask); 1660 txc_cpu = cpumask_next(txc_cpu, &priv->dpio_cpumask);
1678 if (txc_cpu >= nr_cpu_ids) 1661 if (txc_cpu >= nr_cpu_ids)
1679 txc_cpu = cpumask_first(&priv->dpio_cpumask); 1662 txc_cpu = cpumask_first(&priv->dpio_cpumask);
@@ -1791,10 +1774,8 @@ static int set_buffer_layout(struct dpaa2_eth_priv *priv)
1791 priv->rx_buf_align = DPAA2_ETH_RX_BUF_ALIGN; 1774 priv->rx_buf_align = DPAA2_ETH_RX_BUF_ALIGN;
1792 1775
1793 /* tx buffer */ 1776 /* tx buffer */
1794 buf_layout.pass_frame_status = true;
1795 buf_layout.private_data_size = DPAA2_ETH_SWA_SIZE; 1777 buf_layout.private_data_size = DPAA2_ETH_SWA_SIZE;
1796 buf_layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS | 1778 buf_layout.options = DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
1797 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
1798 err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token, 1779 err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token,
1799 DPNI_QUEUE_TX, &buf_layout); 1780 DPNI_QUEUE_TX, &buf_layout);
1800 if (err) { 1781 if (err) {
@@ -1803,7 +1784,7 @@ static int set_buffer_layout(struct dpaa2_eth_priv *priv)
1803 } 1784 }
1804 1785
1805 /* tx-confirm buffer */ 1786 /* tx-confirm buffer */
1806 buf_layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS; 1787 buf_layout.options = 0;
1807 err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token, 1788 err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token,
1808 DPNI_QUEUE_TX_CONFIRM, &buf_layout); 1789 DPNI_QUEUE_TX_CONFIRM, &buf_layout);
1809 if (err) { 1790 if (err) {
@@ -1826,6 +1807,7 @@ static int set_buffer_layout(struct dpaa2_eth_priv *priv)
1826 priv->tx_data_offset); 1807 priv->tx_data_offset);
1827 1808
1828 /* rx buffer */ 1809 /* rx buffer */
1810 buf_layout.pass_frame_status = true;
1829 buf_layout.pass_parser_result = true; 1811 buf_layout.pass_parser_result = true;
1830 buf_layout.data_align = priv->rx_buf_align; 1812 buf_layout.data_align = priv->rx_buf_align;
1831 buf_layout.data_head_room = dpaa2_eth_rx_head_room(priv); 1813 buf_layout.data_head_room = dpaa2_eth_rx_head_room(priv);
@@ -2273,7 +2255,6 @@ static int netdev_init(struct net_device *net_dev)
2273{ 2255{
2274 struct device *dev = net_dev->dev.parent; 2256 struct device *dev = net_dev->dev.parent;
2275 struct dpaa2_eth_priv *priv = netdev_priv(net_dev); 2257 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
2276 u16 rx_headroom, req_headroom;
2277 u8 bcast_addr[ETH_ALEN]; 2258 u8 bcast_addr[ETH_ALEN];
2278 u8 num_queues; 2259 u8 num_queues;
2279 int err; 2260 int err;
@@ -2292,24 +2273,6 @@ static int netdev_init(struct net_device *net_dev)
2292 return err; 2273 return err;
2293 } 2274 }
2294 2275
2295 /* Reserve enough space to align buffer as per hardware requirement;
2296 * NOTE: priv->tx_data_offset MUST be initialized at this point.
2297 */
2298 net_dev->needed_headroom = dpaa2_eth_needed_headroom(priv);
2299
2300 /* If headroom guaranteed by hardware in the Rx frame buffer is
2301 * smaller than the Tx headroom required by the stack, issue a
2302 * one time warning. This will most likely mean skbs forwarded to
2303 * another DPAA2 network interface will get reallocated, with a
2304 * significant performance impact.
2305 */
2306 req_headroom = LL_RESERVED_SPACE(net_dev) - ETH_HLEN;
2307 rx_headroom = ALIGN(DPAA2_ETH_RX_HWA_SIZE +
2308 dpaa2_eth_rx_head_room(priv), priv->rx_buf_align);
2309 if (req_headroom > rx_headroom)
2310 dev_info_once(dev, "Required headroom (%d) greater than available (%d)\n",
2311 req_headroom, rx_headroom);
2312
2313 /* Set MTU limits */ 2276 /* Set MTU limits */
2314 net_dev->min_mtu = 68; 2277 net_dev->min_mtu = 68;
2315 net_dev->max_mtu = DPAA2_ETH_MAX_MTU; 2278 net_dev->max_mtu = DPAA2_ETH_MAX_MTU;
diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h
index 5b3ab9f62d5e..e577410fdf4f 100644
--- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h
+++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h
@@ -134,7 +134,6 @@ struct dpaa2_eth_swa {
134 DPAA2_FD_CTRL_FAERR) 134 DPAA2_FD_CTRL_FAERR)
135 135
136/* Annotation bits in FD CTRL */ 136/* Annotation bits in FD CTRL */
137#define DPAA2_FD_CTRL_ASAL 0x00010000 /* ASAL = 64 */
138#define DPAA2_FD_CTRL_PTA 0x00800000 137#define DPAA2_FD_CTRL_PTA 0x00800000
139#define DPAA2_FD_CTRL_PTV1 0x00400000 138#define DPAA2_FD_CTRL_PTV1 0x00400000
140 139
@@ -153,10 +152,15 @@ struct dpaa2_fas {
153#define DPAA2_FAS_SIZE (sizeof(struct dpaa2_fas)) 152#define DPAA2_FAS_SIZE (sizeof(struct dpaa2_fas))
154 153
155/* Accessors for the hardware annotation fields that we use */ 154/* Accessors for the hardware annotation fields that we use */
156#define dpaa2_get_hwa(buf_addr) \ 155static inline void *dpaa2_get_hwa(void *buf_addr, bool swa)
157 ((void *)(buf_addr) + DPAA2_ETH_SWA_SIZE) 156{
158#define dpaa2_get_fas(buf_addr) \ 157 return buf_addr + (swa ? DPAA2_ETH_SWA_SIZE : 0);
159 (struct dpaa2_fas *)(dpaa2_get_hwa(buf_addr) + DPAA2_FAS_OFFSET) 158}
159
160static inline struct dpaa2_fas *dpaa2_get_fas(void *buf_addr, bool swa)
161{
162 return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAS_OFFSET;
163}
160 164
161/* Error and status bits in the frame annotation status word */ 165/* Error and status bits in the frame annotation status word */
162/* Debug frame, otherwise supposed to be discarded */ 166/* Debug frame, otherwise supposed to be discarded */
@@ -203,11 +207,6 @@ struct dpaa2_fas {
203 DPAA2_FAS_BLE | \ 207 DPAA2_FAS_BLE | \
204 DPAA2_FAS_L3CE | \ 208 DPAA2_FAS_L3CE | \
205 DPAA2_FAS_L4CE) 209 DPAA2_FAS_L4CE)
206/* Tx errors */
207#define DPAA2_FAS_TX_ERR_MASK (DPAA2_FAS_KSE | \
208 DPAA2_FAS_EOFHE | \
209 DPAA2_FAS_MNLE | \
210 DPAA2_FAS_TIDE)
211 210
212/* Time in milliseconds between link state updates */ 211/* Time in milliseconds between link state updates */
213#define DPAA2_ETH_LINK_STATE_REFRESH 1000 212#define DPAA2_ETH_LINK_STATE_REFRESH 1000
@@ -226,6 +225,7 @@ struct dpaa2_eth_drv_stats {
226 __u64 tx_conf_bytes; 225 __u64 tx_conf_bytes;
227 __u64 tx_sg_frames; 226 __u64 tx_sg_frames;
228 __u64 tx_sg_bytes; 227 __u64 tx_sg_bytes;
228 __u64 tx_reallocs;
229 __u64 rx_sg_frames; 229 __u64 rx_sg_frames;
230 __u64 rx_sg_bytes; 230 __u64 rx_sg_bytes;
231 /* Enqueues retried due to portal busy */ 231 /* Enqueues retried due to portal busy */
@@ -276,7 +276,8 @@ struct dpaa2_eth_fq {
276 void (*consume)(struct dpaa2_eth_priv *, 276 void (*consume)(struct dpaa2_eth_priv *,
277 struct dpaa2_eth_channel *, 277 struct dpaa2_eth_channel *,
278 const struct dpaa2_fd *, 278 const struct dpaa2_fd *,
279 struct napi_struct *); 279 struct napi_struct *,
280 u16 queue_id);
280 struct dpaa2_eth_fq_stats stats; 281 struct dpaa2_eth_fq_stats stats;
281}; 282};
282 283
@@ -287,6 +288,7 @@ struct dpaa2_eth_channel {
287 int ch_id; 288 int ch_id;
288 int dpio_id; 289 int dpio_id;
289 struct napi_struct napi; 290 struct napi_struct napi;
291 struct dpaa2_io *dpio;
290 struct dpaa2_io_store *store; 292 struct dpaa2_io_store *store;
291 struct dpaa2_eth_priv *priv; 293 struct dpaa2_eth_priv *priv;
292 int buf_count; 294 int buf_count;
@@ -364,9 +366,13 @@ static inline unsigned int dpaa2_eth_buf_raw_size(struct dpaa2_eth_priv *priv)
364} 366}
365 367
366static inline 368static inline
367unsigned int dpaa2_eth_needed_headroom(struct dpaa2_eth_priv *priv) 369unsigned int dpaa2_eth_needed_headroom(struct dpaa2_eth_priv *priv,
370 struct sk_buff *skb)
368{ 371{
369 return priv->tx_data_offset + DPAA2_ETH_TX_BUF_ALIGN - HH_DATA_MOD; 372 if (skb_is_nonlinear(skb))
373 return 0;
374
375 return DPAA2_ETH_SWA_SIZE;
370} 376}
371 377
372/* Extra headroom space requested to hardware, in order to make sure there's 378/* Extra headroom space requested to hardware, in order to make sure there's
@@ -374,7 +380,8 @@ unsigned int dpaa2_eth_needed_headroom(struct dpaa2_eth_priv *priv)
374 */ 380 */
375static inline unsigned int dpaa2_eth_rx_head_room(struct dpaa2_eth_priv *priv) 381static inline unsigned int dpaa2_eth_rx_head_room(struct dpaa2_eth_priv *priv)
376{ 382{
377 return dpaa2_eth_needed_headroom(priv) - DPAA2_ETH_RX_HWA_SIZE; 383 return priv->tx_data_offset + DPAA2_ETH_TX_BUF_ALIGN -
384 DPAA2_ETH_RX_HWA_SIZE;
378} 385}
379 386
380static int dpaa2_eth_queue_count(struct dpaa2_eth_priv *priv) 387static int dpaa2_eth_queue_count(struct dpaa2_eth_priv *priv)
diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c
index ebe8fd6ccf2c..070a3f2a0523 100644
--- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c
+++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c
@@ -62,6 +62,7 @@ static char dpaa2_ethtool_extras[][ETH_GSTRING_LEN] = {
62 "[drv] tx conf bytes", 62 "[drv] tx conf bytes",
63 "[drv] tx sg frames", 63 "[drv] tx sg frames",
64 "[drv] tx sg bytes", 64 "[drv] tx sg bytes",
65 "[drv] tx realloc frames",
65 "[drv] rx sg frames", 66 "[drv] rx sg frames",
66 "[drv] rx sg bytes", 67 "[drv] rx sg bytes",
67 "[drv] enqueue portal busy", 68 "[drv] enqueue portal busy",
diff --git a/drivers/staging/fsl-mc/Kconfig b/drivers/staging/fsl-mc/Kconfig
index 32df07b15e09..3002229bec1b 100644
--- a/drivers/staging/fsl-mc/Kconfig
+++ b/drivers/staging/fsl-mc/Kconfig
@@ -1 +1,2 @@
1# SPDX-License-Identifier: GPL-2.0
1source "drivers/staging/fsl-mc/bus/Kconfig" 2source "drivers/staging/fsl-mc/bus/Kconfig"
diff --git a/drivers/staging/fsl-mc/Makefile b/drivers/staging/fsl-mc/Makefile
index 9c6a00128c65..14683889dabd 100644
--- a/drivers/staging/fsl-mc/Makefile
+++ b/drivers/staging/fsl-mc/Makefile
@@ -1,2 +1,3 @@
1# SPDX-License-Identifier: GPL-2.0
1# Freescale Management Complex (MC) bus drivers 2# Freescale Management Complex (MC) bus drivers
2obj-$(CONFIG_FSL_MC_BUS) += bus/ 3obj-$(CONFIG_FSL_MC_BUS) += bus/
diff --git a/drivers/staging/fsl-mc/README.txt b/drivers/staging/fsl-mc/README.txt
deleted file mode 100644
index 524eda1de04f..000000000000
--- a/drivers/staging/fsl-mc/README.txt
+++ /dev/null
@@ -1,386 +0,0 @@
1Copyright (C) 2015 Freescale Semiconductor Inc.
2
3DPAA2 (Data Path Acceleration Architecture Gen2)
4------------------------------------------------
5
6This document provides an overview of the Freescale DPAA2 architecture
7and how it is integrated into the Linux kernel.
8
9Contents summary
10 -DPAA2 overview
11 -Overview of DPAA2 objects
12 -DPAA2 Linux driver architecture overview
13 -bus driver
14 -DPRC driver
15 -allocator
16 -DPIO driver
17 -Ethernet
18 -MAC
19
20DPAA2 Overview
21--------------
22
23DPAA2 is a hardware architecture designed for high-speeed network
24packet processing. DPAA2 consists of sophisticated mechanisms for
25processing Ethernet packets, queue management, buffer management,
26autonomous L2 switching, virtual Ethernet bridging, and accelerator
27(e.g. crypto) sharing.
28
29A DPAA2 hardware component called the Management Complex (or MC) manages the
30DPAA2 hardware resources. The MC provides an object-based abstraction for
31software drivers to use the DPAA2 hardware.
32
33The MC uses DPAA2 hardware resources such as queues, buffer pools, and
34network ports to create functional objects/devices such as network
35interfaces, an L2 switch, or accelerator instances.
36
37The MC provides memory-mapped I/O command interfaces (MC portals)
38which DPAA2 software drivers use to operate on DPAA2 objects:
39
40The diagram below shows an overview of the DPAA2 resource management
41architecture:
42
43 +--------------------------------------+
44 | OS |
45 | DPAA2 drivers |
46 | | |
47 +-----------------------------|--------+
48 |
49 | (create,discover,connect
50 | config,use,destroy)
51 |
52 DPAA2 |
53 +------------------------| mc portal |-+
54 | | |
55 | +- - - - - - - - - - - - -V- - -+ |
56 | | | |
57 | | Management Complex (MC) | |
58 | | | |
59 | +- - - - - - - - - - - - - - - -+ |
60 | |
61 | Hardware Hardware |
62 | Resources Objects |
63 | --------- ------- |
64 | -queues -DPRC |
65 | -buffer pools -DPMCP |
66 | -Eth MACs/ports -DPIO |
67 | -network interface -DPNI |
68 | profiles -DPMAC |
69 | -queue portals -DPBP |
70 | -MC portals ... |
71 | ... |
72 | |
73 +--------------------------------------+
74
75The MC mediates operations such as create, discover,
76connect, configuration, and destroy. Fast-path operations
77on data, such as packet transmit/receive, are not mediated by
78the MC and are done directly using memory mapped regions in
79DPIO objects.
80
81Overview of DPAA2 Objects
82-------------------------
83The section provides a brief overview of some key DPAA2 objects.
84A simple scenario is described illustrating the objects involved
85in creating a network interfaces.
86
87-DPRC (Datapath Resource Container)
88
89 A DPRC is a container object that holds all the other
90 types of DPAA2 objects. In the example diagram below there
91 are 8 objects of 5 types (DPMCP, DPIO, DPBP, DPNI, and DPMAC)
92 in the container.
93
94 +---------------------------------------------------------+
95 | DPRC |
96 | |
97 | +-------+ +-------+ +-------+ +-------+ +-------+ |
98 | | DPMCP | | DPIO | | DPBP | | DPNI | | DPMAC | |
99 | +-------+ +-------+ +-------+ +---+---+ +---+---+ |
100 | | DPMCP | | DPIO | |
101 | +-------+ +-------+ |
102 | | DPMCP | |
103 | +-------+ |
104 | |
105 +---------------------------------------------------------+
106
107 From the point of view of an OS, a DPRC behaves similar to a plug and
108 play bus, like PCI. DPRC commands can be used to enumerate the contents
109 of the DPRC, discover the hardware objects present (including mappable
110 regions and interrupts).
111
112 DPRC.1 (bus)
113 |
114 +--+--------+-------+-------+-------+
115 | | | | |
116 DPMCP.1 DPIO.1 DPBP.1 DPNI.1 DPMAC.1
117 DPMCP.2 DPIO.2
118 DPMCP.3
119
120 Hardware objects can be created and destroyed dynamically, providing
121 the ability to hot plug/unplug objects in and out of the DPRC.
122
123 A DPRC has a mappable MMIO region (an MC portal) that can be used
124 to send MC commands. It has an interrupt for status events (like
125 hotplug).
126
127 All objects in a container share the same hardware "isolation context".
128 This means that with respect to an IOMMU the isolation granularity
129 is at the DPRC (container) level, not at the individual object
130 level.
131
132 DPRCs can be defined statically and populated with objects
133 via a config file passed to the MC when firmware starts
134 it.
135
136-DPAA2 Objects for an Ethernet Network Interface
137
138 A typical Ethernet NIC is monolithic-- the NIC device contains TX/RX
139 queuing mechanisms, configuration mechanisms, buffer management,
140 physical ports, and interrupts. DPAA2 uses a more granular approach
141 utilizing multiple hardware objects. Each object provides specialized
142 functions. Groups of these objects are used by software to provide
143 Ethernet network interface functionality. This approach provides
144 efficient use of finite hardware resources, flexibility, and
145 performance advantages.
146
147 The diagram below shows the objects needed for a simple
148 network interface configuration on a system with 2 CPUs.
149
150 +---+---+ +---+---+
151 CPU0 CPU1
152 +---+---+ +---+---+
153 | |
154 +---+---+ +---+---+
155 DPIO DPIO
156 +---+---+ +---+---+
157 \ /
158 \ /
159 \ /
160 +---+---+
161 DPNI --- DPBP,DPMCP
162 +---+---+
163 |
164 |
165 +---+---+
166 DPMAC
167 +---+---+
168 |
169 port/PHY
170
171 Below the objects are described. For each object a brief description
172 is provided along with a summary of the kinds of operations the object
173 supports and a summary of key resources of the object (MMIO regions
174 and IRQs).
175
176 -DPMAC (Datapath Ethernet MAC): represents an Ethernet MAC, a
177 hardware device that connects to an Ethernet PHY and allows
178 physical transmission and reception of Ethernet frames.
179 -MMIO regions: none
180 -IRQs: DPNI link change
181 -commands: set link up/down, link config, get stats,
182 IRQ config, enable, reset
183
184 -DPNI (Datapath Network Interface): contains TX/RX queues,
185 network interface configuration, and RX buffer pool configuration
186 mechanisms. The TX/RX queues are in memory and are identified by
187 queue number.
188 -MMIO regions: none
189 -IRQs: link state
190 -commands: port config, offload config, queue config,
191 parse/classify config, IRQ config, enable, reset
192
193 -DPIO (Datapath I/O): provides interfaces to enqueue and dequeue
194 packets and do hardware buffer pool management operations. The DPAA2
195 architecture separates the mechanism to access queues (the DPIO object)
196 from the queues themselves. The DPIO provides an MMIO interface to
197 enqueue/dequeue packets. To enqueue something a descriptor is written
198 to the DPIO MMIO region, which includes the target queue number.
199 There will typically be one DPIO assigned to each CPU. This allows all
200 CPUs to simultaneously perform enqueue/dequeued operations. DPIOs are
201 expected to be shared by different DPAA2 drivers.
202 -MMIO regions: queue operations, buffer management
203 -IRQs: data availability, congestion notification, buffer
204 pool depletion
205 -commands: IRQ config, enable, reset
206
207 -DPBP (Datapath Buffer Pool): represents a hardware buffer
208 pool.
209 -MMIO regions: none
210 -IRQs: none
211 -commands: enable, reset
212
213 -DPMCP (Datapath MC Portal): provides an MC command portal.
214 Used by drivers to send commands to the MC to manage
215 objects.
216 -MMIO regions: MC command portal
217 -IRQs: command completion
218 -commands: IRQ config, enable, reset
219
220 Object Connections
221 ------------------
222 Some objects have explicit relationships that must
223 be configured:
224
225 -DPNI <--> DPMAC
226 -DPNI <--> DPNI
227 -DPNI <--> L2-switch-port
228 A DPNI must be connected to something such as a DPMAC,
229 another DPNI, or L2 switch port. The DPNI connection
230 is made via a DPRC command.
231
232 +-------+ +-------+
233 | DPNI | | DPMAC |
234 +---+---+ +---+---+
235 | |
236 +==========+
237
238 -DPNI <--> DPBP
239 A network interface requires a 'buffer pool' (DPBP
240 object) which provides a list of pointers to memory
241 where received Ethernet data is to be copied. The
242 Ethernet driver configures the DPBPs associated with
243 the network interface.
244
245 Interrupts
246 ----------
247 All interrupts generated by DPAA2 objects are message
248 interrupts. At the hardware level message interrupts
249 generated by devices will normally have 3 components--
250 1) a non-spoofable 'device-id' expressed on the hardware
251 bus, 2) an address, 3) a data value.
252
253 In the case of DPAA2 devices/objects, all objects in the
254 same container/DPRC share the same 'device-id'.
255 For ARM-based SoC this is the same as the stream ID.
256
257
258DPAA2 Linux Driver Overview
259---------------------------
260
261This section provides an overview of the Linux kernel drivers for
262DPAA2-- 1) the bus driver and associated "DPAA2 infrastructure"
263drivers and 2) functional object drivers (such as Ethernet).
264
265As described previously, a DPRC is a container that holds the other
266types of DPAA2 objects. It is functionally similar to a plug-and-play
267bus controller.
268
269Each object in the DPRC is a Linux "device" and is bound to a driver.
270The diagram below shows the Linux drivers involved in a networking
271scenario and the objects bound to each driver. A brief description
272of each driver follows.
273
274 +------------+
275 | OS Network |
276 | Stack |
277 +------------+ +------------+
278 | Allocator |. . . . . . . | Ethernet |
279 |(DPMCP,DPBP)| | (DPNI) |
280 +-.----------+ +---+---+----+
281 . . ^ |
282 . . <data avail, | |<enqueue,
283 . . tx confirm> | | dequeue>
284 +-------------+ . | |
285 | DPRC driver | . +---+---V----+ +---------+
286 | (DPRC) | . . . . . .| DPIO driver| | MAC |
287 +----------+--+ | (DPIO) | | (DPMAC) |
288 | +------+-----+ +-----+---+
289 |<dev add/remove> | |
290 | | |
291 +----+--------------+ | +--+---+
292 | MC-bus driver | | | PHY |
293 | | | |driver|
294 | /soc/fsl-mc | | +--+---+
295 +-------------------+ | |
296 | |
297 ================================ HARDWARE =========|=================|======
298 DPIO |
299 | |
300 DPNI---DPBP |
301 | |
302 DPMAC |
303 | |
304 PHY ---------------+
305 ===================================================|========================
306
307A brief description of each driver is provided below.
308
309 MC-bus driver
310 -------------
311 The MC-bus driver is a platform driver and is probed from a
312 node in the device tree (compatible "fsl,qoriq-mc") passed in by boot
313 firmware. It is responsible for bootstrapping the DPAA2 kernel
314 infrastructure.
315 Key functions include:
316 -registering a new bus type named "fsl-mc" with the kernel,
317 and implementing bus call-backs (e.g. match/uevent/dev_groups)
318 -implementing APIs for DPAA2 driver registration and for device
319 add/remove
320 -creates an MSI IRQ domain
321 -doing a 'device add' to expose the 'root' DPRC, in turn triggering
322 a bind of the root DPRC to the DPRC driver
323 The binding for the MC-bus device-tree node can be consulted here:
324 Documentation/devicetree/bindings/misc/fsl,qoriq-mc.txt
325
326 DPRC driver
327 -----------
328 The DPRC driver is bound to DPRC objects and does runtime management
329 of a bus instance. It performs the initial bus scan of the DPRC
330 and handles interrupts for container events such as hot plug by
331 re-scanning the DPRC.
332
333 Allocator
334 ----------
335 Certain objects such as DPMCP and DPBP are generic and fungible,
336 and are intended to be used by other drivers. For example,
337 the DPAA2 Ethernet driver needs:
338 -DPMCPs to send MC commands, to configure network interfaces
339 -DPBPs for network buffer pools
340
341 The allocator driver registers for these allocatable object types
342 and those objects are bound to the allocator when the bus is probed.
343 The allocator maintains a pool of objects that are available for
344 allocation by other DPAA2 drivers.
345
346 DPIO driver
347 -----------
348 The DPIO driver is bound to DPIO objects and provides services that allow
349 other drivers such as the Ethernet driver to enqueue and dequeue data for
350 their respective objects.
351 Key services include:
352 -data availability notifications
353 -hardware queuing operations (enqueue and dequeue of data)
354 -hardware buffer pool management
355
356 To transmit a packet the Ethernet driver puts data on a queue and
357 invokes a DPIO API. For receive, the Ethernet driver registers
358 a data availability notification callback. To dequeue a packet
359 a DPIO API is used.
360
361 There is typically one DPIO object per physical CPU for optimum
362 performance, allowing different CPUs to simultaneously enqueue
363 and dequeue data.
364
365 The DPIO driver operates on behalf of all DPAA2 drivers
366 active in the kernel-- Ethernet, crypto, compression,
367 etc.
368
369 Ethernet
370 --------
371 The Ethernet driver is bound to a DPNI and implements the kernel
372 interfaces needed to connect the DPAA2 network interface to
373 the network stack.
374
375 Each DPNI corresponds to a Linux network interface.
376
377 MAC driver
378 ----------
379 An Ethernet PHY is an off-chip, board specific component and is managed
380 by the appropriate PHY driver via an mdio bus. The MAC driver
381 plays a role of being a proxy between the PHY driver and the
382 MC. It does this proxy via the MC commands to a DPMAC object.
383 If the PHY driver signals a link change, the MAC driver notifies
384 the MC via a DPMAC command. If a network interface is brought
385 up or down, the MC notifies the DPMAC driver via an interrupt and
386 the driver can take appropriate action.
diff --git a/drivers/staging/fsl-mc/bus/Kconfig b/drivers/staging/fsl-mc/bus/Kconfig
index 504c987447f2..1f9100049176 100644
--- a/drivers/staging/fsl-mc/bus/Kconfig
+++ b/drivers/staging/fsl-mc/bus/Kconfig
@@ -1,10 +1,9 @@
1# SPDX-License-Identifier: GPL-2.0
1# 2#
2# DPAA2 fsl-mc bus 3# DPAA2 fsl-mc bus
3# 4#
4# Copyright (C) 2014-2016 Freescale Semiconductor, Inc. 5# Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
5# 6#
6# This file is released under the GPLv2
7#
8 7
9config FSL_MC_BUS 8config FSL_MC_BUS
10 bool "QorIQ DPAA2 fsl-mc bus driver" 9 bool "QorIQ DPAA2 fsl-mc bus driver"
diff --git a/drivers/staging/fsl-mc/bus/Makefile b/drivers/staging/fsl-mc/bus/Makefile
index 6df407edfade..29059db95ecc 100644
--- a/drivers/staging/fsl-mc/bus/Makefile
+++ b/drivers/staging/fsl-mc/bus/Makefile
@@ -1,10 +1,9 @@
1# SPDX-License-Identifier: GPL-2.0
1# 2#
2# Freescale Management Complex (MC) bus drivers 3# Freescale Management Complex (MC) bus drivers
3# 4#
4# Copyright (C) 2014 Freescale Semiconductor, Inc. 5# Copyright (C) 2014 Freescale Semiconductor, Inc.
5# 6#
6# This file is released under the GPLv2
7#
8obj-$(CONFIG_FSL_MC_BUS) += mc-bus-driver.o 7obj-$(CONFIG_FSL_MC_BUS) += mc-bus-driver.o
9 8
10mc-bus-driver-objs := fsl-mc-bus.o \ 9mc-bus-driver-objs := fsl-mc-bus.o \
diff --git a/drivers/staging/fsl-mc/bus/dpbp-cmd.h b/drivers/staging/fsl-mc/bus/dpbp-cmd.h
index 5904836fd741..0b7f5c041f19 100644
--- a/drivers/staging/fsl-mc/bus/dpbp-cmd.h
+++ b/drivers/staging/fsl-mc/bus/dpbp-cmd.h
@@ -1,33 +1,7 @@
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
1/* 2/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 5 */
32#ifndef _FSL_DPBP_CMD_H 6#ifndef _FSL_DPBP_CMD_H
33#define _FSL_DPBP_CMD_H 7#define _FSL_DPBP_CMD_H
diff --git a/drivers/staging/fsl-mc/bus/dpbp.c b/drivers/staging/fsl-mc/bus/dpbp.c
index 363730a80cbb..a4df84668d5b 100644
--- a/drivers/staging/fsl-mc/bus/dpbp.c
+++ b/drivers/staging/fsl-mc/bus/dpbp.c
@@ -1,33 +1,7 @@
1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
1/* 2/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 5 */
32#include <linux/kernel.h> 6#include <linux/kernel.h>
33#include "../include/mc.h" 7#include "../include/mc.h"
@@ -77,7 +51,7 @@ int dpbp_open(struct fsl_mc_io *mc_io,
77 51
78 return err; 52 return err;
79} 53}
80EXPORT_SYMBOL(dpbp_open); 54EXPORT_SYMBOL_GPL(dpbp_open);
81 55
82/** 56/**
83 * dpbp_close() - Close the control session of the object 57 * dpbp_close() - Close the control session of the object
@@ -103,7 +77,7 @@ int dpbp_close(struct fsl_mc_io *mc_io,
103 /* send command to mc*/ 77 /* send command to mc*/
104 return mc_send_command(mc_io, &cmd); 78 return mc_send_command(mc_io, &cmd);
105} 79}
106EXPORT_SYMBOL(dpbp_close); 80EXPORT_SYMBOL_GPL(dpbp_close);
107 81
108/** 82/**
109 * dpbp_enable() - Enable the DPBP. 83 * dpbp_enable() - Enable the DPBP.
@@ -126,7 +100,7 @@ int dpbp_enable(struct fsl_mc_io *mc_io,
126 /* send command to mc*/ 100 /* send command to mc*/
127 return mc_send_command(mc_io, &cmd); 101 return mc_send_command(mc_io, &cmd);
128} 102}
129EXPORT_SYMBOL(dpbp_enable); 103EXPORT_SYMBOL_GPL(dpbp_enable);
130 104
131/** 105/**
132 * dpbp_disable() - Disable the DPBP. 106 * dpbp_disable() - Disable the DPBP.
@@ -149,7 +123,7 @@ int dpbp_disable(struct fsl_mc_io *mc_io,
149 /* send command to mc*/ 123 /* send command to mc*/
150 return mc_send_command(mc_io, &cmd); 124 return mc_send_command(mc_io, &cmd);
151} 125}
152EXPORT_SYMBOL(dpbp_disable); 126EXPORT_SYMBOL_GPL(dpbp_disable);
153 127
154/** 128/**
155 * dpbp_is_enabled() - Check if the DPBP is enabled. 129 * dpbp_is_enabled() - Check if the DPBP is enabled.
@@ -183,7 +157,7 @@ int dpbp_is_enabled(struct fsl_mc_io *mc_io,
183 157
184 return 0; 158 return 0;
185} 159}
186EXPORT_SYMBOL(dpbp_is_enabled); 160EXPORT_SYMBOL_GPL(dpbp_is_enabled);
187 161
188/** 162/**
189 * dpbp_reset() - Reset the DPBP, returns the object to initial state. 163 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
@@ -206,7 +180,7 @@ int dpbp_reset(struct fsl_mc_io *mc_io,
206 /* send command to mc*/ 180 /* send command to mc*/
207 return mc_send_command(mc_io, &cmd); 181 return mc_send_command(mc_io, &cmd);
208} 182}
209EXPORT_SYMBOL(dpbp_reset); 183EXPORT_SYMBOL_GPL(dpbp_reset);
210 184
211/** 185/**
212 * dpbp_get_attributes - Retrieve DPBP attributes. 186 * dpbp_get_attributes - Retrieve DPBP attributes.
@@ -243,7 +217,7 @@ int dpbp_get_attributes(struct fsl_mc_io *mc_io,
243 217
244 return 0; 218 return 0;
245} 219}
246EXPORT_SYMBOL(dpbp_get_attributes); 220EXPORT_SYMBOL_GPL(dpbp_get_attributes);
247 221
248/** 222/**
249 * dpbp_get_api_version - Get Data Path Buffer Pool API version 223 * dpbp_get_api_version - Get Data Path Buffer Pool API version
@@ -276,4 +250,4 @@ int dpbp_get_api_version(struct fsl_mc_io *mc_io,
276 250
277 return 0; 251 return 0;
278} 252}
279EXPORT_SYMBOL(dpbp_get_api_version); 253EXPORT_SYMBOL_GPL(dpbp_get_api_version);
diff --git a/drivers/staging/fsl-mc/bus/dpcon-cmd.h b/drivers/staging/fsl-mc/bus/dpcon-cmd.h
index 2bb66988ecf6..27fa09877970 100644
--- a/drivers/staging/fsl-mc/bus/dpcon-cmd.h
+++ b/drivers/staging/fsl-mc/bus/dpcon-cmd.h
@@ -1,33 +1,7 @@
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
1/* 2/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 5 */
32#ifndef _FSL_DPCON_CMD_H 6#ifndef _FSL_DPCON_CMD_H
33#define _FSL_DPCON_CMD_H 7#define _FSL_DPCON_CMD_H
@@ -45,13 +19,11 @@
45/* Command IDs */ 19/* Command IDs */
46#define DPCON_CMDID_CLOSE DPCON_CMD(0x800) 20#define DPCON_CMDID_CLOSE DPCON_CMD(0x800)
47#define DPCON_CMDID_OPEN DPCON_CMD(0x808) 21#define DPCON_CMDID_OPEN DPCON_CMD(0x808)
48#define DPCON_CMDID_GET_API_VERSION DPCON_CMD(0xa08)
49 22
50#define DPCON_CMDID_ENABLE DPCON_CMD(0x002) 23#define DPCON_CMDID_ENABLE DPCON_CMD(0x002)
51#define DPCON_CMDID_DISABLE DPCON_CMD(0x003) 24#define DPCON_CMDID_DISABLE DPCON_CMD(0x003)
52#define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004) 25#define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004)
53#define DPCON_CMDID_RESET DPCON_CMD(0x005) 26#define DPCON_CMDID_RESET DPCON_CMD(0x005)
54#define DPCON_CMDID_IS_ENABLED DPCON_CMD(0x006)
55 27
56#define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100) 28#define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100)
57 29
@@ -61,10 +33,6 @@ struct dpcon_cmd_open {
61 33
62#define DPCON_ENABLE 1 34#define DPCON_ENABLE 1
63 35
64struct dpcon_rsp_is_enabled {
65 u8 enabled;
66};
67
68struct dpcon_rsp_get_attr { 36struct dpcon_rsp_get_attr {
69 /* response word 0 */ 37 /* response word 0 */
70 __le32 id; 38 __le32 id;
diff --git a/drivers/staging/fsl-mc/bus/dpcon.c b/drivers/staging/fsl-mc/bus/dpcon.c
index ca1da85c6dda..8f84d7b5465c 100644
--- a/drivers/staging/fsl-mc/bus/dpcon.c
+++ b/drivers/staging/fsl-mc/bus/dpcon.c
@@ -1,33 +1,7 @@
1/* Copyright 2013-2016 Freescale Semiconductor Inc. 1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2/*
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
2 * 4 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5 * * Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * * Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 * * Neither the name of the above-listed copyright holders nor the
11 * names of any contributors may be used to endorse or promote products
12 * derived from this software without specific prior written permission.
13 *
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 5 */
32#include <linux/kernel.h> 6#include <linux/kernel.h>
33#include "../include/mc.h" 7#include "../include/mc.h"
@@ -78,7 +52,7 @@ int dpcon_open(struct fsl_mc_io *mc_io,
78 52
79 return 0; 53 return 0;
80} 54}
81EXPORT_SYMBOL(dpcon_open); 55EXPORT_SYMBOL_GPL(dpcon_open);
82 56
83/** 57/**
84 * dpcon_close() - Close the control session of the object 58 * dpcon_close() - Close the control session of the object
@@ -105,7 +79,7 @@ int dpcon_close(struct fsl_mc_io *mc_io,
105 /* send command to mc*/ 79 /* send command to mc*/
106 return mc_send_command(mc_io, &cmd); 80 return mc_send_command(mc_io, &cmd);
107} 81}
108EXPORT_SYMBOL(dpcon_close); 82EXPORT_SYMBOL_GPL(dpcon_close);
109 83
110/** 84/**
111 * dpcon_enable() - Enable the DPCON 85 * dpcon_enable() - Enable the DPCON
@@ -129,7 +103,7 @@ int dpcon_enable(struct fsl_mc_io *mc_io,
129 /* send command to mc*/ 103 /* send command to mc*/
130 return mc_send_command(mc_io, &cmd); 104 return mc_send_command(mc_io, &cmd);
131} 105}
132EXPORT_SYMBOL(dpcon_enable); 106EXPORT_SYMBOL_GPL(dpcon_enable);
133 107
134/** 108/**
135 * dpcon_disable() - Disable the DPCON 109 * dpcon_disable() - Disable the DPCON
@@ -153,43 +127,7 @@ int dpcon_disable(struct fsl_mc_io *mc_io,
153 /* send command to mc*/ 127 /* send command to mc*/
154 return mc_send_command(mc_io, &cmd); 128 return mc_send_command(mc_io, &cmd);
155} 129}
156EXPORT_SYMBOL(dpcon_disable); 130EXPORT_SYMBOL_GPL(dpcon_disable);
157
158/**
159 * dpcon_is_enabled() - Check if the DPCON is enabled.
160 * @mc_io: Pointer to MC portal's I/O object
161 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
162 * @token: Token of DPCON object
163 * @en: Returns '1' if object is enabled; '0' otherwise
164 *
165 * Return: '0' on Success; Error code otherwise.
166 */
167int dpcon_is_enabled(struct fsl_mc_io *mc_io,
168 u32 cmd_flags,
169 u16 token,
170 int *en)
171{
172 struct mc_command cmd = { 0 };
173 struct dpcon_rsp_is_enabled *dpcon_rsp;
174 int err;
175
176 /* prepare command */
177 cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
178 cmd_flags,
179 token);
180
181 /* send command to mc*/
182 err = mc_send_command(mc_io, &cmd);
183 if (err)
184 return err;
185
186 /* retrieve response parameters */
187 dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params;
188 *en = dpcon_rsp->enabled & DPCON_ENABLE;
189
190 return 0;
191}
192EXPORT_SYMBOL(dpcon_is_enabled);
193 131
194/** 132/**
195 * dpcon_reset() - Reset the DPCON, returns the object to initial state. 133 * dpcon_reset() - Reset the DPCON, returns the object to initial state.
@@ -212,7 +150,7 @@ int dpcon_reset(struct fsl_mc_io *mc_io,
212 /* send command to mc*/ 150 /* send command to mc*/
213 return mc_send_command(mc_io, &cmd); 151 return mc_send_command(mc_io, &cmd);
214} 152}
215EXPORT_SYMBOL(dpcon_reset); 153EXPORT_SYMBOL_GPL(dpcon_reset);
216 154
217/** 155/**
218 * dpcon_get_attributes() - Retrieve DPCON attributes. 156 * dpcon_get_attributes() - Retrieve DPCON attributes.
@@ -250,7 +188,7 @@ int dpcon_get_attributes(struct fsl_mc_io *mc_io,
250 188
251 return 0; 189 return 0;
252} 190}
253EXPORT_SYMBOL(dpcon_get_attributes); 191EXPORT_SYMBOL_GPL(dpcon_get_attributes);
254 192
255/** 193/**
256 * dpcon_set_notification() - Set DPCON notification destination 194 * dpcon_set_notification() - Set DPCON notification destination
@@ -281,37 +219,4 @@ int dpcon_set_notification(struct fsl_mc_io *mc_io,
281 /* send command to mc*/ 219 /* send command to mc*/
282 return mc_send_command(mc_io, &cmd); 220 return mc_send_command(mc_io, &cmd);
283} 221}
284EXPORT_SYMBOL(dpcon_set_notification); 222EXPORT_SYMBOL_GPL(dpcon_set_notification);
285
286/**
287 * dpcon_get_api_version - Get Data Path Concentrator API version
288 * @mc_io: Pointer to MC portal's DPCON object
289 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
290 * @major_ver: Major version of DPCON API
291 * @minor_ver: Minor version of DPCON API
292 *
293 * Return: '0' on Success; Error code otherwise
294 */
295int dpcon_get_api_version(struct fsl_mc_io *mc_io,
296 u32 cmd_flags,
297 u16 *major_ver,
298 u16 *minor_ver)
299{
300 struct mc_command cmd = { 0 };
301 int err;
302
303 /* prepare command */
304 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
305 cmd_flags, 0);
306
307 /* send command to mc */
308 err = mc_send_command(mc_io, &cmd);
309 if (err)
310 return err;
311
312 /* retrieve response parameters */
313 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
314
315 return 0;
316}
317EXPORT_SYMBOL(dpcon_get_api_version);
diff --git a/drivers/staging/fsl-mc/bus/dpio/Makefile b/drivers/staging/fsl-mc/bus/dpio/Makefile
index 837d3303e11d..53ba84d7b884 100644
--- a/drivers/staging/fsl-mc/bus/dpio/Makefile
+++ b/drivers/staging/fsl-mc/bus/dpio/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# 2#
2# QorIQ DPAA2 DPIO driver 3# QorIQ DPAA2 DPIO driver
3# 4#
diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-cmd.h b/drivers/staging/fsl-mc/bus/dpio/dpio-cmd.h
index b2dc6e766f09..ab8f82ee7ee5 100644
--- a/drivers/staging/fsl-mc/bus/dpio/dpio-cmd.h
+++ b/drivers/staging/fsl-mc/bus/dpio/dpio-cmd.h
@@ -1,34 +1,8 @@
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
1/* 2/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * Copyright 2016 NXP 4 * Copyright 2016 NXP
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the above-listed copyright holders nor the
13 * names of any contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 6 */
33#ifndef _FSL_DPIO_CMD_H 7#ifndef _FSL_DPIO_CMD_H
34#define _FSL_DPIO_CMD_H 8#define _FSL_DPIO_CMD_H
diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c
index e36da20a2796..b8479ef64c71 100644
--- a/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c
+++ b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c
@@ -1,33 +1,8 @@
1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
1/* 2/*
2 * Copyright 2014-2016 Freescale Semiconductor Inc. 3 * Copyright 2014-2016 Freescale Semiconductor Inc.
3 * Copyright NXP 2016 4 * Copyright NXP 2016
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Freescale Semiconductor nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 6 */
32 7
33#include <linux/types.h> 8#include <linux/types.h>
diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-service.c b/drivers/staging/fsl-mc/bus/dpio/dpio-service.c
index a609ec82daf3..d3c8462d43e8 100644
--- a/drivers/staging/fsl-mc/bus/dpio/dpio-service.c
+++ b/drivers/staging/fsl-mc/bus/dpio/dpio-service.c
@@ -1,33 +1,8 @@
1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
1/* 2/*
2 * Copyright 2014-2016 Freescale Semiconductor Inc. 3 * Copyright 2014-2016 Freescale Semiconductor Inc.
3 * Copyright 2016 NXP 4 * Copyright 2016 NXP
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Freescale Semiconductor nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 6 */
32#include <linux/types.h> 7#include <linux/types.h>
33#include "../../include/mc.h" 8#include "../../include/mc.h"
@@ -43,7 +18,6 @@
43#include "qbman-portal.h" 18#include "qbman-portal.h"
44 19
45struct dpaa2_io { 20struct dpaa2_io {
46 atomic_t refs;
47 struct dpaa2_io_desc dpio_desc; 21 struct dpaa2_io_desc dpio_desc;
48 struct qbman_swp_desc swp_desc; 22 struct qbman_swp_desc swp_desc;
49 struct qbman_swp *swp; 23 struct qbman_swp *swp;
@@ -105,6 +79,23 @@ static inline struct dpaa2_io *service_select(struct dpaa2_io *d)
105} 79}
106 80
107/** 81/**
82 * dpaa2_io_service_select() - return a dpaa2_io service affined to this cpu
83 * @cpu: the cpu id
84 *
85 * Return the affine dpaa2_io service, or NULL if there is no service affined
86 * to the specified cpu. If DPAA2_IO_ANY_CPU is used, return the next available
87 * service.
88 */
89struct dpaa2_io *dpaa2_io_service_select(int cpu)
90{
91 if (cpu == DPAA2_IO_ANY_CPU)
92 return service_select(NULL);
93
94 return service_select_by_cpu(NULL, cpu);
95}
96EXPORT_SYMBOL_GPL(dpaa2_io_service_select);
97
98/**
108 * dpaa2_io_create() - create a dpaa2_io object. 99 * dpaa2_io_create() - create a dpaa2_io object.
109 * @desc: the dpaa2_io descriptor 100 * @desc: the dpaa2_io descriptor
110 * 101 *
@@ -126,7 +117,6 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc)
126 return NULL; 117 return NULL;
127 } 118 }
128 119
129 atomic_set(&obj->refs, 1);
130 obj->dpio_desc = *desc; 120 obj->dpio_desc = *desc;
131 obj->swp_desc.cena_bar = obj->dpio_desc.regs_cena; 121 obj->swp_desc.cena_bar = obj->dpio_desc.regs_cena;
132 obj->swp_desc.cinh_bar = obj->dpio_desc.regs_cinh; 122 obj->swp_desc.cinh_bar = obj->dpio_desc.regs_cinh;
@@ -158,7 +148,6 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc)
158 148
159 return obj; 149 return obj;
160} 150}
161EXPORT_SYMBOL(dpaa2_io_create);
162 151
163/** 152/**
164 * dpaa2_io_down() - release the dpaa2_io object. 153 * dpaa2_io_down() - release the dpaa2_io object.
@@ -171,11 +160,8 @@ EXPORT_SYMBOL(dpaa2_io_create);
171 */ 160 */
172void dpaa2_io_down(struct dpaa2_io *d) 161void dpaa2_io_down(struct dpaa2_io *d)
173{ 162{
174 if (!atomic_dec_and_test(&d->refs))
175 return;
176 kfree(d); 163 kfree(d);
177} 164}
178EXPORT_SYMBOL(dpaa2_io_down);
179 165
180#define DPAA_POLL_MAX 32 166#define DPAA_POLL_MAX 32
181 167
@@ -222,7 +208,6 @@ done:
222 qbman_swp_interrupt_set_inhibit(swp, 0); 208 qbman_swp_interrupt_set_inhibit(swp, 0);
223 return IRQ_HANDLED; 209 return IRQ_HANDLED;
224} 210}
225EXPORT_SYMBOL(dpaa2_io_irq);
226 211
227/** 212/**
228 * dpaa2_io_service_register() - Prepare for servicing of FQDAN or CDAN 213 * dpaa2_io_service_register() - Prepare for servicing of FQDAN or CDAN
@@ -265,7 +250,7 @@ int dpaa2_io_service_register(struct dpaa2_io *d,
265 ctx->qman64); 250 ctx->qman64);
266 return 0; 251 return 0;
267} 252}
268EXPORT_SYMBOL(dpaa2_io_service_register); 253EXPORT_SYMBOL_GPL(dpaa2_io_service_register);
269 254
270/** 255/**
271 * dpaa2_io_service_deregister - The opposite of 'register'. 256 * dpaa2_io_service_deregister - The opposite of 'register'.
@@ -288,7 +273,7 @@ void dpaa2_io_service_deregister(struct dpaa2_io *service,
288 list_del(&ctx->node); 273 list_del(&ctx->node);
289 spin_unlock_irqrestore(&d->lock_notifications, irqflags); 274 spin_unlock_irqrestore(&d->lock_notifications, irqflags);
290} 275}
291EXPORT_SYMBOL(dpaa2_io_service_deregister); 276EXPORT_SYMBOL_GPL(dpaa2_io_service_deregister);
292 277
293/** 278/**
294 * dpaa2_io_service_rearm() - Rearm the notification for the given DPIO service. 279 * dpaa2_io_service_rearm() - Rearm the notification for the given DPIO service.
@@ -322,38 +307,7 @@ int dpaa2_io_service_rearm(struct dpaa2_io *d,
322 307
323 return err; 308 return err;
324} 309}
325EXPORT_SYMBOL(dpaa2_io_service_rearm); 310EXPORT_SYMBOL_GPL(dpaa2_io_service_rearm);
326
327/**
328 * dpaa2_io_service_pull_fq() - pull dequeue functions from a fq.
329 * @d: the given DPIO service.
330 * @fqid: the given frame queue id.
331 * @s: the dpaa2_io_store object for the result.
332 *
333 * Return 0 for success, or error code for failure.
334 */
335int dpaa2_io_service_pull_fq(struct dpaa2_io *d, u32 fqid,
336 struct dpaa2_io_store *s)
337{
338 struct qbman_pull_desc pd;
339 int err;
340
341 qbman_pull_desc_clear(&pd);
342 qbman_pull_desc_set_storage(&pd, s->vaddr, s->paddr, 1);
343 qbman_pull_desc_set_numframes(&pd, (u8)s->max);
344 qbman_pull_desc_set_fq(&pd, fqid);
345
346 d = service_select(d);
347 if (!d)
348 return -ENODEV;
349 s->swp = d->swp;
350 err = qbman_swp_pull(d->swp, &pd);
351 if (err)
352 s->swp = NULL;
353
354 return err;
355}
356EXPORT_SYMBOL(dpaa2_io_service_pull_fq);
357 311
358/** 312/**
359 * dpaa2_io_service_pull_channel() - pull dequeue functions from a channel. 313 * dpaa2_io_service_pull_channel() - pull dequeue functions from a channel.
@@ -385,34 +339,7 @@ int dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid,
385 339
386 return err; 340 return err;
387} 341}
388EXPORT_SYMBOL(dpaa2_io_service_pull_channel); 342EXPORT_SYMBOL_GPL(dpaa2_io_service_pull_channel);
389
390/**
391 * dpaa2_io_service_enqueue_fq() - Enqueue a frame to a frame queue.
392 * @d: the given DPIO service.
393 * @fqid: the given frame queue id.
394 * @fd: the frame descriptor which is enqueued.
395 *
396 * Return 0 for successful enqueue, -EBUSY if the enqueue ring is not ready,
397 * or -ENODEV if there is no dpio service.
398 */
399int dpaa2_io_service_enqueue_fq(struct dpaa2_io *d,
400 u32 fqid,
401 const struct dpaa2_fd *fd)
402{
403 struct qbman_eq_desc ed;
404
405 d = service_select(d);
406 if (!d)
407 return -ENODEV;
408
409 qbman_eq_desc_clear(&ed);
410 qbman_eq_desc_set_no_orp(&ed, 0);
411 qbman_eq_desc_set_fq(&ed, fqid);
412
413 return qbman_swp_enqueue(d->swp, &ed, fd);
414}
415EXPORT_SYMBOL(dpaa2_io_service_enqueue_fq);
416 343
417/** 344/**
418 * dpaa2_io_service_enqueue_qd() - Enqueue a frame to a QD. 345 * dpaa2_io_service_enqueue_qd() - Enqueue a frame to a QD.
@@ -441,7 +368,7 @@ int dpaa2_io_service_enqueue_qd(struct dpaa2_io *d,
441 368
442 return qbman_swp_enqueue(d->swp, &ed, fd); 369 return qbman_swp_enqueue(d->swp, &ed, fd);
443} 370}
444EXPORT_SYMBOL(dpaa2_io_service_enqueue_qd); 371EXPORT_SYMBOL_GPL(dpaa2_io_service_enqueue_qd);
445 372
446/** 373/**
447 * dpaa2_io_service_release() - Release buffers to a buffer pool. 374 * dpaa2_io_service_release() - Release buffers to a buffer pool.
@@ -468,7 +395,7 @@ int dpaa2_io_service_release(struct dpaa2_io *d,
468 395
469 return qbman_swp_release(d->swp, &rd, buffers, num_buffers); 396 return qbman_swp_release(d->swp, &rd, buffers, num_buffers);
470} 397}
471EXPORT_SYMBOL(dpaa2_io_service_release); 398EXPORT_SYMBOL_GPL(dpaa2_io_service_release);
472 399
473/** 400/**
474 * dpaa2_io_service_acquire() - Acquire buffers from a buffer pool. 401 * dpaa2_io_service_acquire() - Acquire buffers from a buffer pool.
@@ -499,7 +426,7 @@ int dpaa2_io_service_acquire(struct dpaa2_io *d,
499 426
500 return err; 427 return err;
501} 428}
502EXPORT_SYMBOL(dpaa2_io_service_acquire); 429EXPORT_SYMBOL_GPL(dpaa2_io_service_acquire);
503 430
504/* 431/*
505 * 'Stores' are reusable memory blocks for holding dequeue results, and to 432 * 'Stores' are reusable memory blocks for holding dequeue results, and to
@@ -553,7 +480,7 @@ struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
553 480
554 return ret; 481 return ret;
555} 482}
556EXPORT_SYMBOL(dpaa2_io_store_create); 483EXPORT_SYMBOL_GPL(dpaa2_io_store_create);
557 484
558/** 485/**
559 * dpaa2_io_store_destroy() - Frees the dma memory storage for dequeue 486 * dpaa2_io_store_destroy() - Frees the dma memory storage for dequeue
@@ -567,7 +494,7 @@ void dpaa2_io_store_destroy(struct dpaa2_io_store *s)
567 kfree(s->alloced_addr); 494 kfree(s->alloced_addr);
568 kfree(s); 495 kfree(s);
569} 496}
570EXPORT_SYMBOL(dpaa2_io_store_destroy); 497EXPORT_SYMBOL_GPL(dpaa2_io_store_destroy);
571 498
572/** 499/**
573 * dpaa2_io_store_next() - Determine when the next dequeue result is available. 500 * dpaa2_io_store_next() - Determine when the next dequeue result is available.
@@ -615,4 +542,4 @@ struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last)
615 542
616 return ret; 543 return ret;
617} 544}
618EXPORT_SYMBOL(dpaa2_io_store_next); 545EXPORT_SYMBOL_GPL(dpaa2_io_store_next);
diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio.c b/drivers/staging/fsl-mc/bus/dpio/dpio.c
index 00eb22186f42..20cdeae54a74 100644
--- a/drivers/staging/fsl-mc/bus/dpio/dpio.c
+++ b/drivers/staging/fsl-mc/bus/dpio/dpio.c
@@ -1,34 +1,8 @@
1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
1/* 2/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * Copyright 2016 NXP 4 * Copyright 2016 NXP
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the above-listed copyright holders nor the
13 * names of any contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 6 */
33#include <linux/kernel.h> 7#include <linux/kernel.h>
34#include "../../include/mc.h" 8#include "../../include/mc.h"
diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio.h b/drivers/staging/fsl-mc/bus/dpio/dpio.h
index ced1103d157c..49194c8e45f1 100644
--- a/drivers/staging/fsl-mc/bus/dpio/dpio.h
+++ b/drivers/staging/fsl-mc/bus/dpio/dpio.h
@@ -1,34 +1,8 @@
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
1/* 2/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * Copyright 2016 NXP 4 * Copyright 2016 NXP
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the above-listed copyright holders nor the
13 * names of any contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 6 */
33#ifndef __FSL_DPIO_H 7#ifndef __FSL_DPIO_H
34#define __FSL_DPIO_H 8#define __FSL_DPIO_H
diff --git a/drivers/staging/fsl-mc/bus/dpio/qbman-portal.c b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.c
index 163bdac6b051..376e9ed0297a 100644
--- a/drivers/staging/fsl-mc/bus/dpio/qbman-portal.c
+++ b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.c
@@ -1,33 +1,8 @@
1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
1/* 2/*
2 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc. 3 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
3 * Copyright 2016 NXP 4 * Copyright 2016 NXP
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Freescale Semiconductor nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 6 */
32 7
33#include <asm/cacheflush.h> 8#include <asm/cacheflush.h>
diff --git a/drivers/staging/fsl-mc/bus/dpio/qbman-portal.h b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.h
index 842855971f34..fb8b9d35a3eb 100644
--- a/drivers/staging/fsl-mc/bus/dpio/qbman-portal.h
+++ b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.h
@@ -1,33 +1,8 @@
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
1/* 2/*
2 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc. 3 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
3 * Copyright 2016 NXP 4 * Copyright 2016 NXP
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Freescale Semiconductor nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 6 */
32#ifndef __FSL_QBMAN_PORTAL_H 7#ifndef __FSL_QBMAN_PORTAL_H
33#define __FSL_QBMAN_PORTAL_H 8#define __FSL_QBMAN_PORTAL_H
diff --git a/drivers/staging/fsl-mc/bus/dpmcp-cmd.h b/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
deleted file mode 100644
index 861b2a708af8..000000000000
--- a/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
+++ /dev/null
@@ -1,56 +0,0 @@
1/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32#ifndef _FSL_DPMCP_CMD_H
33#define _FSL_DPMCP_CMD_H
34
35/* Minimal supported DPMCP Version */
36#define DPMCP_MIN_VER_MAJOR 3
37#define DPMCP_MIN_VER_MINOR 0
38
39/* Command versioning */
40#define DPMCP_CMD_BASE_VERSION 1
41#define DPMCP_CMD_ID_OFFSET 4
42
43#define DPMCP_CMD(id) (((id) << DPMCP_CMD_ID_OFFSET) | DPMCP_CMD_BASE_VERSION)
44
45/* Command IDs */
46#define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800)
47#define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b)
48#define DPMCP_CMDID_GET_API_VERSION DPMCP_CMD(0xa0b)
49
50#define DPMCP_CMDID_RESET DPMCP_CMD(0x005)
51
52struct dpmcp_cmd_open {
53 __le32 dpmcp_id;
54};
55
56#endif /* _FSL_DPMCP_CMD_H */
diff --git a/drivers/staging/fsl-mc/bus/dpmcp.c b/drivers/staging/fsl-mc/bus/dpmcp.c
index eea42f61af86..be07c77520af 100644
--- a/drivers/staging/fsl-mc/bus/dpmcp.c
+++ b/drivers/staging/fsl-mc/bus/dpmcp.c
@@ -1,39 +1,12 @@
1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
1/* 2/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 5 */
32#include <linux/kernel.h> 6#include <linux/kernel.h>
33#include "../include/mc.h" 7#include "../include/mc.h"
34 8
35#include "dpmcp.h" 9#include "fsl-mc-private.h"
36#include "dpmcp-cmd.h"
37 10
38/** 11/**
39 * dpmcp_open() - Open a control session for the specified object. 12 * dpmcp_open() - Open a control session for the specified object.
@@ -124,35 +97,3 @@ int dpmcp_reset(struct fsl_mc_io *mc_io,
124 /* send command to mc*/ 97 /* send command to mc*/
125 return mc_send_command(mc_io, &cmd); 98 return mc_send_command(mc_io, &cmd);
126} 99}
127
128/**
129 * dpmcp_get_api_version - Get Data Path Management Command Portal API version
130 * @mc_io: Pointer to Mc portal's I/O object
131 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
132 * @major_ver: Major version of Data Path Management Command Portal API
133 * @minor_ver: Minor version of Data Path Management Command Portal API
134 *
135 * Return: '0' on Success; Error code otherwise.
136 */
137int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
138 u32 cmd_flags,
139 u16 *major_ver,
140 u16 *minor_ver)
141{
142 struct mc_command cmd = { 0 };
143 int err;
144
145 /* prepare command */
146 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_API_VERSION,
147 cmd_flags, 0);
148
149 /* send command to mc */
150 err = mc_send_command(mc_io, &cmd);
151 if (err)
152 return err;
153
154 /* retrieve response parameters */
155 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
156
157 return 0;
158}
diff --git a/drivers/staging/fsl-mc/bus/dpmcp.h b/drivers/staging/fsl-mc/bus/dpmcp.h
deleted file mode 100644
index f616031e3e59..000000000000
--- a/drivers/staging/fsl-mc/bus/dpmcp.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32#ifndef __FSL_DPMCP_H
33#define __FSL_DPMCP_H
34
35/*
36 * Data Path Management Command Portal API
37 * Contains initialization APIs and runtime control APIs for DPMCP
38 */
39
40struct fsl_mc_io;
41
42int dpmcp_open(struct fsl_mc_io *mc_io,
43 u32 cmd_flags,
44 int dpmcp_id,
45 u16 *token);
46
47int dpmcp_close(struct fsl_mc_io *mc_io,
48 u32 cmd_flags,
49 u16 token);
50
51int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
52 u32 cmd_flags,
53 u16 *major_ver,
54 u16 *minor_ver);
55
56int dpmcp_reset(struct fsl_mc_io *mc_io,
57 u32 cmd_flags,
58 u16 token);
59
60#endif /* __FSL_DPMCP_H */
diff --git a/drivers/staging/fsl-mc/bus/dpmng-cmd.h b/drivers/staging/fsl-mc/bus/dpmng-cmd.h
deleted file mode 100644
index d1f04ac18b78..000000000000
--- a/drivers/staging/fsl-mc/bus/dpmng-cmd.h
+++ /dev/null
@@ -1,58 +0,0 @@
1/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/*
34 * dpmng-cmd.h
35 *
36 * defines portal commands
37 *
38 */
39
40#ifndef __FSL_DPMNG_CMD_H
41#define __FSL_DPMNG_CMD_H
42
43/* Command versioning */
44#define DPMNG_CMD_BASE_VERSION 1
45#define DPMNG_CMD_ID_OFFSET 4
46
47#define DPMNG_CMD(id) (((id) << DPMNG_CMD_ID_OFFSET) | DPMNG_CMD_BASE_VERSION)
48
49/* Command IDs */
50#define DPMNG_CMDID_GET_VERSION DPMNG_CMD(0x831)
51
52struct dpmng_rsp_get_version {
53 __le32 revision;
54 __le32 version_major;
55 __le32 version_minor;
56};
57
58#endif /* __FSL_DPMNG_CMD_H */
diff --git a/drivers/staging/fsl-mc/bus/dprc-cmd.h b/drivers/staging/fsl-mc/bus/dprc-cmd.h
deleted file mode 100644
index d9b2dcde468e..000000000000
--- a/drivers/staging/fsl-mc/bus/dprc-cmd.h
+++ /dev/null
@@ -1,451 +0,0 @@
1/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/*
34 * dprc-cmd.h
35 *
36 * defines dprc portal commands
37 *
38 */
39
40#ifndef _FSL_DPRC_CMD_H
41#define _FSL_DPRC_CMD_H
42
43/* Minimal supported DPRC Version */
44#define DPRC_MIN_VER_MAJOR 6
45#define DPRC_MIN_VER_MINOR 0
46
47/* Command versioning */
48#define DPRC_CMD_BASE_VERSION 1
49#define DPRC_CMD_ID_OFFSET 4
50
51#define DPRC_CMD(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
52
53/* Command IDs */
54#define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
55#define DPRC_CMDID_OPEN DPRC_CMD(0x805)
56#define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
57
58#define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
59
60#define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
61#define DPRC_CMDID_GET_IRQ DPRC_CMD(0x011)
62#define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
63#define DPRC_CMDID_GET_IRQ_ENABLE DPRC_CMD(0x013)
64#define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
65#define DPRC_CMDID_GET_IRQ_MASK DPRC_CMD(0x015)
66#define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
67#define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
68
69#define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
70#define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
71#define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
72#define DPRC_CMDID_GET_RES_COUNT DPRC_CMD(0x15B)
73#define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
74#define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
75#define DPRC_CMDID_GET_OBJ_IRQ DPRC_CMD(0x160)
76
77struct dprc_cmd_open {
78 __le32 container_id;
79};
80
81struct dprc_cmd_create_container {
82 /* cmd word 0 */
83 __le32 options;
84 __le16 icid;
85 __le16 pad0;
86 /* cmd word 1 */
87 __le32 pad1;
88 __le32 portal_id;
89 /* cmd words 2-3 */
90 u8 label[16];
91};
92
93struct dprc_rsp_create_container {
94 /* response word 0 */
95 __le64 pad0;
96 /* response word 1 */
97 __le32 child_container_id;
98 __le32 pad1;
99 /* response word 2 */
100 __le64 child_portal_addr;
101};
102
103struct dprc_cmd_destroy_container {
104 __le32 child_container_id;
105};
106
107struct dprc_cmd_reset_container {
108 __le32 child_container_id;
109};
110
111struct dprc_cmd_set_irq {
112 /* cmd word 0 */
113 __le32 irq_val;
114 u8 irq_index;
115 u8 pad[3];
116 /* cmd word 1 */
117 __le64 irq_addr;
118 /* cmd word 2 */
119 __le32 irq_num;
120};
121
122struct dprc_cmd_get_irq {
123 __le32 pad;
124 u8 irq_index;
125};
126
127struct dprc_rsp_get_irq {
128 /* response word 0 */
129 __le32 irq_val;
130 __le32 pad;
131 /* response word 1 */
132 __le64 irq_addr;
133 /* response word 2 */
134 __le32 irq_num;
135 __le32 type;
136};
137
138#define DPRC_ENABLE 0x1
139
140struct dprc_cmd_set_irq_enable {
141 u8 enable;
142 u8 pad[3];
143 u8 irq_index;
144};
145
146struct dprc_cmd_get_irq_enable {
147 __le32 pad;
148 u8 irq_index;
149};
150
151struct dprc_rsp_get_irq_enable {
152 u8 enabled;
153};
154
155struct dprc_cmd_set_irq_mask {
156 __le32 mask;
157 u8 irq_index;
158};
159
160struct dprc_cmd_get_irq_mask {
161 __le32 pad;
162 u8 irq_index;
163};
164
165struct dprc_rsp_get_irq_mask {
166 __le32 mask;
167};
168
169struct dprc_cmd_get_irq_status {
170 __le32 status;
171 u8 irq_index;
172};
173
174struct dprc_rsp_get_irq_status {
175 __le32 status;
176};
177
178struct dprc_cmd_clear_irq_status {
179 __le32 status;
180 u8 irq_index;
181};
182
183struct dprc_rsp_get_attributes {
184 /* response word 0 */
185 __le32 container_id;
186 __le16 icid;
187 __le16 pad;
188 /* response word 1 */
189 __le32 options;
190 __le32 portal_id;
191};
192
193struct dprc_cmd_set_res_quota {
194 /* cmd word 0 */
195 __le32 child_container_id;
196 __le16 quota;
197 __le16 pad;
198 /* cmd words 1-2 */
199 u8 type[16];
200};
201
202struct dprc_cmd_get_res_quota {
203 /* cmd word 0 */
204 __le32 child_container_id;
205 __le32 pad;
206 /* cmd word 1-2 */
207 u8 type[16];
208};
209
210struct dprc_rsp_get_res_quota {
211 __le32 pad;
212 __le16 quota;
213};
214
215struct dprc_cmd_assign {
216 /* cmd word 0 */
217 __le32 container_id;
218 __le32 options;
219 /* cmd word 1 */
220 __le32 num;
221 __le32 id_base_align;
222 /* cmd word 2-3 */
223 u8 type[16];
224};
225
226struct dprc_cmd_unassign {
227 /* cmd word 0 */
228 __le32 child_container_id;
229 __le32 options;
230 /* cmd word 1 */
231 __le32 num;
232 __le32 id_base_align;
233 /* cmd word 2-3 */
234 u8 type[16];
235};
236
237struct dprc_rsp_get_pool_count {
238 __le32 pool_count;
239};
240
241struct dprc_cmd_get_pool {
242 __le32 pool_index;
243};
244
245struct dprc_rsp_get_pool {
246 /* response word 0 */
247 __le64 pad;
248 /* response word 1-2 */
249 u8 type[16];
250};
251
252struct dprc_rsp_get_obj_count {
253 __le32 pad;
254 __le32 obj_count;
255};
256
257struct dprc_cmd_get_obj {
258 __le32 obj_index;
259};
260
261struct dprc_rsp_get_obj {
262 /* response word 0 */
263 __le32 pad0;
264 __le32 id;
265 /* response word 1 */
266 __le16 vendor;
267 u8 irq_count;
268 u8 region_count;
269 __le32 state;
270 /* response word 2 */
271 __le16 version_major;
272 __le16 version_minor;
273 __le16 flags;
274 __le16 pad1;
275 /* response word 3-4 */
276 u8 type[16];
277 /* response word 5-6 */
278 u8 label[16];
279};
280
281struct dprc_cmd_get_obj_desc {
282 /* cmd word 0 */
283 __le32 obj_id;
284 __le32 pad;
285 /* cmd word 1-2 */
286 u8 type[16];
287};
288
289struct dprc_rsp_get_obj_desc {
290 /* response word 0 */
291 __le32 pad0;
292 __le32 id;
293 /* response word 1 */
294 __le16 vendor;
295 u8 irq_count;
296 u8 region_count;
297 __le32 state;
298 /* response word 2 */
299 __le16 version_major;
300 __le16 version_minor;
301 __le16 flags;
302 __le16 pad1;
303 /* response word 3-4 */
304 u8 type[16];
305 /* response word 5-6 */
306 u8 label[16];
307};
308
309struct dprc_cmd_get_res_count {
310 /* cmd word 0 */
311 __le64 pad;
312 /* cmd word 1-2 */
313 u8 type[16];
314};
315
316struct dprc_rsp_get_res_count {
317 __le32 res_count;
318};
319
320struct dprc_cmd_get_res_ids {
321 /* cmd word 0 */
322 u8 pad0[5];
323 u8 iter_status;
324 __le16 pad1;
325 /* cmd word 1 */
326 __le32 base_id;
327 __le32 last_id;
328 /* cmd word 2-3 */
329 u8 type[16];
330};
331
332struct dprc_rsp_get_res_ids {
333 /* response word 0 */
334 u8 pad0[5];
335 u8 iter_status;
336 __le16 pad1;
337 /* response word 1 */
338 __le32 base_id;
339 __le32 last_id;
340};
341
342struct dprc_cmd_get_obj_region {
343 /* cmd word 0 */
344 __le32 obj_id;
345 __le16 pad0;
346 u8 region_index;
347 u8 pad1;
348 /* cmd word 1-2 */
349 __le64 pad2[2];
350 /* cmd word 3-4 */
351 u8 obj_type[16];
352};
353
354struct dprc_rsp_get_obj_region {
355 /* response word 0 */
356 __le64 pad;
357 /* response word 1 */
358 __le64 base_addr;
359 /* response word 2 */
360 __le32 size;
361};
362
363struct dprc_cmd_set_obj_label {
364 /* cmd word 0 */
365 __le32 obj_id;
366 __le32 pad;
367 /* cmd word 1-2 */
368 u8 label[16];
369 /* cmd word 3-4 */
370 u8 obj_type[16];
371};
372
373struct dprc_cmd_set_obj_irq {
374 /* cmd word 0 */
375 __le32 irq_val;
376 u8 irq_index;
377 u8 pad[3];
378 /* cmd word 1 */
379 __le64 irq_addr;
380 /* cmd word 2 */
381 __le32 irq_num;
382 __le32 obj_id;
383 /* cmd word 3-4 */
384 u8 obj_type[16];
385};
386
387struct dprc_cmd_get_obj_irq {
388 /* cmd word 0 */
389 __le32 obj_id;
390 u8 irq_index;
391 u8 pad[3];
392 /* cmd word 1-2 */
393 u8 obj_type[16];
394};
395
396struct dprc_rsp_get_obj_irq {
397 /* response word 0 */
398 __le32 irq_val;
399 __le32 pad;
400 /* response word 1 */
401 __le64 irq_addr;
402 /* response word 2 */
403 __le32 irq_num;
404 __le32 type;
405};
406
407struct dprc_cmd_connect {
408 /* cmd word 0 */
409 __le32 ep1_id;
410 __le32 ep1_interface_id;
411 /* cmd word 1 */
412 __le32 ep2_id;
413 __le32 ep2_interface_id;
414 /* cmd word 2-3 */
415 u8 ep1_type[16];
416 /* cmd word 4 */
417 __le32 max_rate;
418 __le32 committed_rate;
419 /* cmd word 5-6 */
420 u8 ep2_type[16];
421};
422
423struct dprc_cmd_disconnect {
424 /* cmd word 0 */
425 __le32 id;
426 __le32 interface_id;
427 /* cmd word 1-2 */
428 u8 type[16];
429};
430
431struct dprc_cmd_get_connection {
432 /* cmd word 0 */
433 __le32 ep1_id;
434 __le32 ep1_interface_id;
435 /* cmd word 1-2 */
436 u8 ep1_type[16];
437};
438
439struct dprc_rsp_get_connection {
440 /* response word 0-2 */
441 __le64 pad[3];
442 /* response word 3 */
443 __le32 ep2_id;
444 __le32 ep2_interface_id;
445 /* response word 4-5 */
446 u8 ep2_type[16];
447 /* response word 6 */
448 __le32 state;
449};
450
451#endif /* _FSL_DPRC_CMD_H */
diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c
index 06df528f4cfc..b09075731e62 100644
--- a/drivers/staging/fsl-mc/bus/dprc-driver.c
+++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
@@ -1,12 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Freescale data path resource container (DPRC) driver 3 * Freescale data path resource container (DPRC) driver
3 * 4 *
4 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc. 5 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
5 * Author: German Rivera <German.Rivera@freescale.com> 6 * Author: German Rivera <German.Rivera@freescale.com>
6 * 7 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */ 8 */
11 9
12#include <linux/module.h> 10#include <linux/module.h>
@@ -15,7 +13,6 @@
15#include <linux/msi.h> 13#include <linux/msi.h>
16#include "../include/mc.h" 14#include "../include/mc.h"
17 15
18#include "dprc-cmd.h"
19#include "fsl-mc-private.h" 16#include "fsl-mc-private.h"
20 17
21#define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc" 18#define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc"
@@ -39,8 +36,6 @@ static int __fsl_mc_device_remove_if_not_in_mc(struct device *dev, void *data)
39 struct fsl_mc_child_objs *objs; 36 struct fsl_mc_child_objs *objs;
40 struct fsl_mc_device *mc_dev; 37 struct fsl_mc_device *mc_dev;
41 38
42 WARN_ON(!dev);
43 WARN_ON(!data);
44 mc_dev = to_fsl_mc_device(dev); 39 mc_dev = to_fsl_mc_device(dev);
45 objs = data; 40 objs = data;
46 41
@@ -60,8 +55,6 @@ static int __fsl_mc_device_remove_if_not_in_mc(struct device *dev, void *data)
60 55
61static int __fsl_mc_device_remove(struct device *dev, void *data) 56static int __fsl_mc_device_remove(struct device *dev, void *data)
62{ 57{
63 WARN_ON(!dev);
64 WARN_ON(data);
65 fsl_mc_device_remove(to_fsl_mc_device(dev)); 58 fsl_mc_device_remove(to_fsl_mc_device(dev));
66 return 0; 59 return 0;
67} 60}
@@ -206,7 +199,8 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
206 * dprc_scan_objects - Discover objects in a DPRC 199 * dprc_scan_objects - Discover objects in a DPRC
207 * 200 *
208 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object 201 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
209 * @total_irq_count: total number of IRQs needed by objects in the DPRC. 202 * @total_irq_count: If argument is provided the function populates the
203 * total number of IRQs created by objects in the DPRC.
210 * 204 *
211 * Detects objects added and removed from a DPRC and synchronizes the 205 * Detects objects added and removed from a DPRC and synchronizes the
212 * state of the Linux bus driver, MC by adding and removing 206 * state of the Linux bus driver, MC by adding and removing
@@ -228,6 +222,7 @@ static int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
228 int error; 222 int error;
229 unsigned int irq_count = mc_bus_dev->obj_desc.irq_count; 223 unsigned int irq_count = mc_bus_dev->obj_desc.irq_count;
230 struct fsl_mc_obj_desc *child_obj_desc_array = NULL; 224 struct fsl_mc_obj_desc *child_obj_desc_array = NULL;
225 struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
231 226
232 error = dprc_get_obj_count(mc_bus_dev->mc_io, 227 error = dprc_get_obj_count(mc_bus_dev->mc_io,
233 0, 228 0,
@@ -297,7 +292,26 @@ static int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
297 } 292 }
298 } 293 }
299 294
300 *total_irq_count = irq_count; 295 /*
296 * Allocate IRQ's before binding the scanned devices with their
297 * respective drivers.
298 */
299 if (dev_get_msi_domain(&mc_bus_dev->dev) && !mc_bus->irq_resources) {
300 if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) {
301 dev_warn(&mc_bus_dev->dev,
302 "IRQs needed (%u) exceed IRQs preallocated (%u)\n",
303 irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
304 }
305
306 error = fsl_mc_populate_irq_pool(mc_bus,
307 FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
308 if (error < 0)
309 return error;
310 }
311
312 if (total_irq_count)
313 *total_irq_count = irq_count;
314
301 dprc_remove_devices(mc_bus_dev, child_obj_desc_array, 315 dprc_remove_devices(mc_bus_dev, child_obj_desc_array,
302 num_child_objects); 316 num_child_objects);
303 317
@@ -322,7 +336,6 @@ static int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
322static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev) 336static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
323{ 337{
324 int error; 338 int error;
325 unsigned int irq_count;
326 struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); 339 struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
327 340
328 fsl_mc_init_all_resource_pools(mc_bus_dev); 341 fsl_mc_init_all_resource_pools(mc_bus_dev);
@@ -331,29 +344,14 @@ static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
331 * Discover objects in the DPRC: 344 * Discover objects in the DPRC:
332 */ 345 */
333 mutex_lock(&mc_bus->scan_mutex); 346 mutex_lock(&mc_bus->scan_mutex);
334 error = dprc_scan_objects(mc_bus_dev, &irq_count); 347 error = dprc_scan_objects(mc_bus_dev, NULL);
335 mutex_unlock(&mc_bus->scan_mutex); 348 mutex_unlock(&mc_bus->scan_mutex);
336 if (error < 0) 349 if (error < 0) {
337 goto error; 350 fsl_mc_cleanup_all_resource_pools(mc_bus_dev);
338 351 return error;
339 if (dev_get_msi_domain(&mc_bus_dev->dev) && !mc_bus->irq_resources) {
340 if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) {
341 dev_warn(&mc_bus_dev->dev,
342 "IRQs needed (%u) exceed IRQs preallocated (%u)\n",
343 irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
344 }
345
346 error = fsl_mc_populate_irq_pool(
347 mc_bus,
348 FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
349 if (error < 0)
350 goto error;
351 } 352 }
352 353
353 return 0; 354 return 0;
354error:
355 fsl_mc_cleanup_all_resource_pools(mc_bus_dev);
356 return error;
357} 355}
358 356
359/** 357/**
@@ -386,11 +384,11 @@ static irqreturn_t dprc_irq0_handler_thread(int irq_num, void *arg)
386 dev_dbg(dev, "DPRC IRQ %d triggered on CPU %u\n", 384 dev_dbg(dev, "DPRC IRQ %d triggered on CPU %u\n",
387 irq_num, smp_processor_id()); 385 irq_num, smp_processor_id());
388 386
389 if (WARN_ON(!(mc_dev->flags & FSL_MC_IS_DPRC))) 387 if (!(mc_dev->flags & FSL_MC_IS_DPRC))
390 return IRQ_HANDLED; 388 return IRQ_HANDLED;
391 389
392 mutex_lock(&mc_bus->scan_mutex); 390 mutex_lock(&mc_bus->scan_mutex);
393 if (WARN_ON(!msi_desc || msi_desc->irq != (u32)irq_num)) 391 if (!msi_desc || msi_desc->irq != (u32)irq_num)
394 goto out; 392 goto out;
395 393
396 status = 0; 394 status = 0;
@@ -453,8 +451,6 @@ static int disable_dprc_irq(struct fsl_mc_device *mc_dev)
453 int error; 451 int error;
454 struct fsl_mc_io *mc_io = mc_dev->mc_io; 452 struct fsl_mc_io *mc_io = mc_dev->mc_io;
455 453
456 WARN_ON(mc_dev->obj_desc.irq_count != 1);
457
458 /* 454 /*
459 * Disable generation of interrupt, while we configure it: 455 * Disable generation of interrupt, while we configure it:
460 */ 456 */
@@ -496,8 +492,6 @@ static int register_dprc_irq_handler(struct fsl_mc_device *mc_dev)
496 int error; 492 int error;
497 struct fsl_mc_device_irq *irq = mc_dev->irqs[0]; 493 struct fsl_mc_device_irq *irq = mc_dev->irqs[0];
498 494
499 WARN_ON(mc_dev->obj_desc.irq_count != 1);
500
501 /* 495 /*
502 * NOTE: devm_request_threaded_irq() invokes the device-specific 496 * NOTE: devm_request_threaded_irq() invokes the device-specific
503 * function that programs the MSI physically in the device 497 * function that programs the MSI physically in the device
@@ -601,20 +595,20 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
601 bool msi_domain_set = false; 595 bool msi_domain_set = false;
602 u16 major_ver, minor_ver; 596 u16 major_ver, minor_ver;
603 597
604 if (WARN_ON(strcmp(mc_dev->obj_desc.type, "dprc") != 0)) 598 if (!is_fsl_mc_bus_dprc(mc_dev))
605 return -EINVAL; 599 return -EINVAL;
606 600
607 if (WARN_ON(dev_get_msi_domain(&mc_dev->dev))) 601 if (dev_get_msi_domain(&mc_dev->dev))
608 return -EINVAL; 602 return -EINVAL;
609 603
610 if (!mc_dev->mc_io) { 604 if (!mc_dev->mc_io) {
611 /* 605 /*
612 * This is a child DPRC: 606 * This is a child DPRC:
613 */ 607 */
614 if (WARN_ON(!dev_is_fsl_mc(parent_dev))) 608 if (!dev_is_fsl_mc(parent_dev))
615 return -EINVAL; 609 return -EINVAL;
616 610
617 if (WARN_ON(mc_dev->obj_desc.region_count == 0)) 611 if (mc_dev->obj_desc.region_count == 0)
618 return -EINVAL; 612 return -EINVAL;
619 613
620 region_size = resource_size(mc_dev->regions); 614 region_size = resource_size(mc_dev->regions);
@@ -642,7 +636,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
642 */ 636 */
643 struct irq_domain *mc_msi_domain; 637 struct irq_domain *mc_msi_domain;
644 638
645 if (WARN_ON(dev_is_fsl_mc(parent_dev))) 639 if (dev_is_fsl_mc(parent_dev))
646 return -EINVAL; 640 return -EINVAL;
647 641
648 error = fsl_mc_find_msi_domain(parent_dev, 642 error = fsl_mc_find_msi_domain(parent_dev,
@@ -753,12 +747,12 @@ static int dprc_remove(struct fsl_mc_device *mc_dev)
753 int error; 747 int error;
754 struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev); 748 struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
755 749
756 if (WARN_ON(strcmp(mc_dev->obj_desc.type, "dprc") != 0)) 750 if (!is_fsl_mc_bus_dprc(mc_dev))
757 return -EINVAL; 751 return -EINVAL;
758 if (WARN_ON(!mc_dev->mc_io)) 752 if (!mc_dev->mc_io)
759 return -EINVAL; 753 return -EINVAL;
760 754
761 if (WARN_ON(!mc_bus->irq_resources)) 755 if (!mc_bus->irq_resources)
762 return -EINVAL; 756 return -EINVAL;
763 757
764 if (dev_get_msi_domain(&mc_dev->dev)) 758 if (dev_get_msi_domain(&mc_dev->dev))
diff --git a/drivers/staging/fsl-mc/bus/dprc.c b/drivers/staging/fsl-mc/bus/dprc.c
index 6f6c65a42166..97f51726fa7e 100644
--- a/drivers/staging/fsl-mc/bus/dprc.c
+++ b/drivers/staging/fsl-mc/bus/dprc.c
@@ -1,39 +1,11 @@
1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
1/* 2/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 5 */
32#include <linux/kernel.h> 6#include <linux/kernel.h>
33#include "../include/mc.h" 7#include "../include/mc.h"
34#include "dprc.h" 8#include "fsl-mc-private.h"
35
36#include "dprc-cmd.h"
37 9
38/** 10/**
39 * dprc_open() - Open DPRC object for use 11 * dprc_open() - Open DPRC object for use
@@ -71,7 +43,7 @@ int dprc_open(struct fsl_mc_io *mc_io,
71 43
72 return 0; 44 return 0;
73} 45}
74EXPORT_SYMBOL(dprc_open); 46EXPORT_SYMBOL_GPL(dprc_open);
75 47
76/** 48/**
77 * dprc_close() - Close the control session of the object 49 * dprc_close() - Close the control session of the object
@@ -97,53 +69,7 @@ int dprc_close(struct fsl_mc_io *mc_io,
97 /* send command to mc*/ 69 /* send command to mc*/
98 return mc_send_command(mc_io, &cmd); 70 return mc_send_command(mc_io, &cmd);
99} 71}
100EXPORT_SYMBOL(dprc_close); 72EXPORT_SYMBOL_GPL(dprc_close);
101
102/**
103 * dprc_get_irq() - Get IRQ information from the DPRC.
104 * @mc_io: Pointer to MC portal's I/O object
105 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
106 * @token: Token of DPRC object
107 * @irq_index: The interrupt index to configure
108 * @type: Interrupt type: 0 represents message interrupt
109 * type (both irq_addr and irq_val are valid)
110 * @irq_cfg: IRQ attributes
111 *
112 * Return: '0' on Success; Error code otherwise.
113 */
114int dprc_get_irq(struct fsl_mc_io *mc_io,
115 u32 cmd_flags,
116 u16 token,
117 u8 irq_index,
118 int *type,
119 struct dprc_irq_cfg *irq_cfg)
120{
121 struct mc_command cmd = { 0 };
122 struct dprc_cmd_get_irq *cmd_params;
123 struct dprc_rsp_get_irq *rsp_params;
124 int err;
125
126 /* prepare command */
127 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ,
128 cmd_flags,
129 token);
130 cmd_params = (struct dprc_cmd_get_irq *)cmd.params;
131 cmd_params->irq_index = irq_index;
132
133 /* send command to mc*/
134 err = mc_send_command(mc_io, &cmd);
135 if (err)
136 return err;
137
138 /* retrieve response parameters */
139 rsp_params = (struct dprc_rsp_get_irq *)cmd.params;
140 irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
141 irq_cfg->paddr = le64_to_cpu(rsp_params->irq_addr);
142 irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
143 *type = le32_to_cpu(rsp_params->type);
144
145 return 0;
146}
147 73
148/** 74/**
149 * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt. 75 * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt.
@@ -179,45 +105,6 @@ int dprc_set_irq(struct fsl_mc_io *mc_io,
179} 105}
180 106
181/** 107/**
182 * dprc_get_irq_enable() - Get overall interrupt state.
183 * @mc_io: Pointer to MC portal's I/O object
184 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
185 * @token: Token of DPRC object
186 * @irq_index: The interrupt index to configure
187 * @en: Returned interrupt state - enable = 1, disable = 0
188 *
189 * Return: '0' on Success; Error code otherwise.
190 */
191int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
192 u32 cmd_flags,
193 u16 token,
194 u8 irq_index,
195 u8 *en)
196{
197 struct mc_command cmd = { 0 };
198 struct dprc_cmd_get_irq_enable *cmd_params;
199 struct dprc_rsp_get_irq_enable *rsp_params;
200 int err;
201
202 /* prepare command */
203 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_ENABLE,
204 cmd_flags, token);
205 cmd_params = (struct dprc_cmd_get_irq_enable *)cmd.params;
206 cmd_params->irq_index = irq_index;
207
208 /* send command to mc*/
209 err = mc_send_command(mc_io, &cmd);
210 if (err)
211 return err;
212
213 /* retrieve response parameters */
214 rsp_params = (struct dprc_rsp_get_irq_enable *)cmd.params;
215 *en = rsp_params->enabled & DPRC_ENABLE;
216
217 return 0;
218}
219
220/**
221 * dprc_set_irq_enable() - Set overall interrupt state. 108 * dprc_set_irq_enable() - Set overall interrupt state.
222 * @mc_io: Pointer to MC portal's I/O object 109 * @mc_io: Pointer to MC portal's I/O object
223 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 110 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
@@ -253,48 +140,6 @@ int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
253} 140}
254 141
255/** 142/**
256 * dprc_get_irq_mask() - Get interrupt mask.
257 * @mc_io: Pointer to MC portal's I/O object
258 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
259 * @token: Token of DPRC object
260 * @irq_index: The interrupt index to configure
261 * @mask: Returned event mask to trigger interrupt
262 *
263 * Every interrupt can have up to 32 causes and the interrupt model supports
264 * masking/unmasking each cause independently
265 *
266 * Return: '0' on Success; Error code otherwise.
267 */
268int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
269 u32 cmd_flags,
270 u16 token,
271 u8 irq_index,
272 u32 *mask)
273{
274 struct mc_command cmd = { 0 };
275 struct dprc_cmd_get_irq_mask *cmd_params;
276 struct dprc_rsp_get_irq_mask *rsp_params;
277 int err;
278
279 /* prepare command */
280 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_MASK,
281 cmd_flags, token);
282 cmd_params = (struct dprc_cmd_get_irq_mask *)cmd.params;
283 cmd_params->irq_index = irq_index;
284
285 /* send command to mc*/
286 err = mc_send_command(mc_io, &cmd);
287 if (err)
288 return err;
289
290 /* retrieve response parameters */
291 rsp_params = (struct dprc_rsp_get_irq_mask *)cmd.params;
292 *mask = le32_to_cpu(rsp_params->mask);
293
294 return 0;
295}
296
297/**
298 * dprc_set_irq_mask() - Set interrupt mask. 143 * dprc_set_irq_mask() - Set interrupt mask.
299 * @mc_io: Pointer to MC portal's I/O object 144 * @mc_io: Pointer to MC portal's I/O object
300 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 145 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
@@ -475,7 +320,7 @@ int dprc_get_obj_count(struct fsl_mc_io *mc_io,
475 320
476 return 0; 321 return 0;
477} 322}
478EXPORT_SYMBOL(dprc_get_obj_count); 323EXPORT_SYMBOL_GPL(dprc_get_obj_count);
479 324
480/** 325/**
481 * dprc_get_obj() - Get general information on an object 326 * dprc_get_obj() - Get general information on an object
@@ -531,7 +376,7 @@ int dprc_get_obj(struct fsl_mc_io *mc_io,
531 obj_desc->label[15] = '\0'; 376 obj_desc->label[15] = '\0';
532 return 0; 377 return 0;
533} 378}
534EXPORT_SYMBOL(dprc_get_obj); 379EXPORT_SYMBOL_GPL(dprc_get_obj);
535 380
536/** 381/**
537 * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt. 382 * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
@@ -572,104 +417,7 @@ int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
572 /* send command to mc*/ 417 /* send command to mc*/
573 return mc_send_command(mc_io, &cmd); 418 return mc_send_command(mc_io, &cmd);
574} 419}
575EXPORT_SYMBOL(dprc_set_obj_irq); 420EXPORT_SYMBOL_GPL(dprc_set_obj_irq);
576
577/**
578 * dprc_get_obj_irq() - Get IRQ information from object.
579 * @mc_io: Pointer to MC portal's I/O object
580 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
581 * @token: Token of DPRC object
582 * @obj_type: Type od the object to get its IRQ
583 * @obj_id: ID of the object to get its IRQ
584 * @irq_index: The interrupt index to configure
585 * @type: Interrupt type: 0 represents message interrupt
586 * type (both irq_addr and irq_val are valid)
587 * @irq_cfg: The returned IRQ attributes
588 *
589 * Return: '0' on Success; Error code otherwise.
590 */
591int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
592 u32 cmd_flags,
593 u16 token,
594 char *obj_type,
595 int obj_id,
596 u8 irq_index,
597 int *type,
598 struct dprc_irq_cfg *irq_cfg)
599{
600 struct mc_command cmd = { 0 };
601 struct dprc_cmd_get_obj_irq *cmd_params;
602 struct dprc_rsp_get_obj_irq *rsp_params;
603 int err;
604
605 /* prepare command */
606 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_IRQ,
607 cmd_flags,
608 token);
609 cmd_params = (struct dprc_cmd_get_obj_irq *)cmd.params;
610 cmd_params->obj_id = cpu_to_le32(obj_id);
611 cmd_params->irq_index = irq_index;
612 strncpy(cmd_params->obj_type, obj_type, 16);
613 cmd_params->obj_type[15] = '\0';
614
615 /* send command to mc*/
616 err = mc_send_command(mc_io, &cmd);
617 if (err)
618 return err;
619
620 /* retrieve response parameters */
621 rsp_params = (struct dprc_rsp_get_obj_irq *)cmd.params;
622 irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
623 irq_cfg->paddr = le64_to_cpu(rsp_params->irq_addr);
624 irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
625 *type = le32_to_cpu(rsp_params->type);
626
627 return 0;
628}
629EXPORT_SYMBOL(dprc_get_obj_irq);
630
631/**
632 * dprc_get_res_count() - Obtains the number of free resources that are assigned
633 * to this container, by pool type
634 * @mc_io: Pointer to MC portal's I/O object
635 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
636 * @token: Token of DPRC object
637 * @type: pool type
638 * @res_count: Returned number of free resources of the given
639 * resource type that are assigned to this DPRC
640 *
641 * Return: '0' on Success; Error code otherwise.
642 */
643int dprc_get_res_count(struct fsl_mc_io *mc_io,
644 u32 cmd_flags,
645 u16 token,
646 char *type,
647 int *res_count)
648{
649 struct mc_command cmd = { 0 };
650 struct dprc_cmd_get_res_count *cmd_params;
651 struct dprc_rsp_get_res_count *rsp_params;
652 int err;
653
654 /* prepare command */
655 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
656 cmd_flags, token);
657 cmd_params = (struct dprc_cmd_get_res_count *)cmd.params;
658 strncpy(cmd_params->type, type, 16);
659 cmd_params->type[15] = '\0';
660
661 /* send command to mc*/
662 err = mc_send_command(mc_io, &cmd);
663 if (err)
664 return err;
665
666 /* retrieve response parameters */
667 rsp_params = (struct dprc_rsp_get_res_count *)cmd.params;
668 *res_count = le32_to_cpu(rsp_params->res_count);
669
670 return 0;
671}
672EXPORT_SYMBOL(dprc_get_res_count);
673 421
674/** 422/**
675 * dprc_get_obj_region() - Get region information for a specified object. 423 * dprc_get_obj_region() - Get region information for a specified object.
@@ -717,7 +465,7 @@ int dprc_get_obj_region(struct fsl_mc_io *mc_io,
717 465
718 return 0; 466 return 0;
719} 467}
720EXPORT_SYMBOL(dprc_get_obj_region); 468EXPORT_SYMBOL_GPL(dprc_get_obj_region);
721 469
722/** 470/**
723 * dprc_get_api_version - Get Data Path Resource Container API version 471 * dprc_get_api_version - Get Data Path Resource Container API version
diff --git a/drivers/staging/fsl-mc/bus/dprc.h b/drivers/staging/fsl-mc/bus/dprc.h
deleted file mode 100644
index 21295e4feb04..000000000000
--- a/drivers/staging/fsl-mc/bus/dprc.h
+++ /dev/null
@@ -1,268 +0,0 @@
1/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33#ifndef _FSL_DPRC_H
34#define _FSL_DPRC_H
35
36/*
37 * Data Path Resource Container API
38 * Contains DPRC API for managing and querying DPAA resources
39 */
40
41struct fsl_mc_io;
42struct fsl_mc_obj_desc;
43
44int dprc_open(struct fsl_mc_io *mc_io,
45 u32 cmd_flags,
46 int container_id,
47 u16 *token);
48
49int dprc_close(struct fsl_mc_io *mc_io,
50 u32 cmd_flags,
51 u16 token);
52
53/* IRQ */
54
55/* IRQ index */
56#define DPRC_IRQ_INDEX 0
57
58/* Number of dprc's IRQs */
59#define DPRC_NUM_OF_IRQS 1
60
61/* DPRC IRQ events */
62
63/* IRQ event - Indicates that a new object added to the container */
64#define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001
65/* IRQ event - Indicates that an object was removed from the container */
66#define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002
67/* IRQ event - Indicates that resources added to the container */
68#define DPRC_IRQ_EVENT_RES_ADDED 0x00000004
69/* IRQ event - Indicates that resources removed from the container */
70#define DPRC_IRQ_EVENT_RES_REMOVED 0x00000008
71/*
72 * IRQ event - Indicates that one of the descendant containers that opened by
73 * this container is destroyed
74 */
75#define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
76
77/*
78 * IRQ event - Indicates that on one of the container's opened object is
79 * destroyed
80 */
81#define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
82
83/* Irq event - Indicates that object is created at the container */
84#define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040
85
86/**
87 * struct dprc_irq_cfg - IRQ configuration
88 * @paddr: Address that must be written to signal a message-based interrupt
89 * @val: Value to write into irq_addr address
90 * @irq_num: A user defined number associated with this IRQ
91 */
92struct dprc_irq_cfg {
93 phys_addr_t paddr;
94 u32 val;
95 int irq_num;
96};
97
98int dprc_set_irq(struct fsl_mc_io *mc_io,
99 u32 cmd_flags,
100 u16 token,
101 u8 irq_index,
102 struct dprc_irq_cfg *irq_cfg);
103
104int dprc_get_irq(struct fsl_mc_io *mc_io,
105 u32 cmd_flags,
106 u16 token,
107 u8 irq_index,
108 int *type,
109 struct dprc_irq_cfg *irq_cfg);
110
111int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
112 u32 cmd_flags,
113 u16 token,
114 u8 irq_index,
115 u8 en);
116
117int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
118 u32 cmd_flags,
119 u16 token,
120 u8 irq_index,
121 u8 *en);
122
123int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
124 u32 cmd_flags,
125 u16 token,
126 u8 irq_index,
127 u32 mask);
128
129int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
130 u32 cmd_flags,
131 u16 token,
132 u8 irq_index,
133 u32 *mask);
134
135int dprc_get_irq_status(struct fsl_mc_io *mc_io,
136 u32 cmd_flags,
137 u16 token,
138 u8 irq_index,
139 u32 *status);
140
141int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
142 u32 cmd_flags,
143 u16 token,
144 u8 irq_index,
145 u32 status);
146
147/**
148 * struct dprc_attributes - Container attributes
149 * @container_id: Container's ID
150 * @icid: Container's ICID
151 * @portal_id: Container's portal ID
152 * @options: Container's options as set at container's creation
153 */
154struct dprc_attributes {
155 int container_id;
156 u16 icid;
157 int portal_id;
158 u64 options;
159};
160
161int dprc_get_attributes(struct fsl_mc_io *mc_io,
162 u32 cmd_flags,
163 u16 token,
164 struct dprc_attributes *attributes);
165
166int dprc_get_obj_count(struct fsl_mc_io *mc_io,
167 u32 cmd_flags,
168 u16 token,
169 int *obj_count);
170
171int dprc_get_obj(struct fsl_mc_io *mc_io,
172 u32 cmd_flags,
173 u16 token,
174 int obj_index,
175 struct fsl_mc_obj_desc *obj_desc);
176
177int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
178 u32 cmd_flags,
179 u16 token,
180 char *obj_type,
181 int obj_id,
182 struct fsl_mc_obj_desc *obj_desc);
183
184int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
185 u32 cmd_flags,
186 u16 token,
187 char *obj_type,
188 int obj_id,
189 u8 irq_index,
190 struct dprc_irq_cfg *irq_cfg);
191
192int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
193 u32 cmd_flags,
194 u16 token,
195 char *obj_type,
196 int obj_id,
197 u8 irq_index,
198 int *type,
199 struct dprc_irq_cfg *irq_cfg);
200
201int dprc_get_res_count(struct fsl_mc_io *mc_io,
202 u32 cmd_flags,
203 u16 token,
204 char *type,
205 int *res_count);
206
207/**
208 * enum dprc_iter_status - Iteration status
209 * @DPRC_ITER_STATUS_FIRST: Perform first iteration
210 * @DPRC_ITER_STATUS_MORE: Indicates more/next iteration is needed
211 * @DPRC_ITER_STATUS_LAST: Indicates last iteration
212 */
213enum dprc_iter_status {
214 DPRC_ITER_STATUS_FIRST = 0,
215 DPRC_ITER_STATUS_MORE = 1,
216 DPRC_ITER_STATUS_LAST = 2
217};
218
219/* Region flags */
220/* Cacheable - Indicates that region should be mapped as cacheable */
221#define DPRC_REGION_CACHEABLE 0x00000001
222
223/**
224 * enum dprc_region_type - Region type
225 * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
226 * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
227 */
228enum dprc_region_type {
229 DPRC_REGION_TYPE_MC_PORTAL,
230 DPRC_REGION_TYPE_QBMAN_PORTAL
231};
232
233/**
234 * struct dprc_region_desc - Mappable region descriptor
235 * @base_offset: Region offset from region's base address.
236 * For DPMCP and DPRC objects, region base is offset from SoC MC portals
237 * base address; For DPIO, region base is offset from SoC QMan portals
238 * base address
239 * @size: Region size (in bytes)
240 * @flags: Region attributes
241 * @type: Portal region type
242 */
243struct dprc_region_desc {
244 u32 base_offset;
245 u32 size;
246 u32 flags;
247 enum dprc_region_type type;
248};
249
250int dprc_get_obj_region(struct fsl_mc_io *mc_io,
251 u32 cmd_flags,
252 u16 token,
253 char *obj_type,
254 int obj_id,
255 u8 region_index,
256 struct dprc_region_desc *region_desc);
257
258int dprc_get_api_version(struct fsl_mc_io *mc_io,
259 u32 cmd_flags,
260 u16 *major_ver,
261 u16 *minor_ver);
262
263int dprc_get_container_id(struct fsl_mc_io *mc_io,
264 u32 cmd_flags,
265 int *container_id);
266
267#endif /* _FSL_DPRC_H */
268
diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
index 8ea3920400a0..8f313a41240b 100644
--- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
+++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
@@ -1,11 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * fsl-mc object allocator driver 3 * fsl-mc object allocator driver
3 * 4 *
4 * Copyright (C) 2013-2016 Freescale Semiconductor, Inc. 5 * Copyright (C) 2013-2016 Freescale Semiconductor, Inc.
5 * 6 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */ 7 */
10 8
11#include <linux/module.h> 9#include <linux/module.h>
@@ -14,11 +12,11 @@
14 12
15#include "fsl-mc-private.h" 13#include "fsl-mc-private.h"
16 14
17static bool __must_check fsl_mc_is_allocatable(const char *obj_type) 15static bool __must_check fsl_mc_is_allocatable(struct fsl_mc_device *mc_dev)
18{ 16{
19 return strcmp(obj_type, "dpbp") == 0 || 17 return is_fsl_mc_bus_dpbp(mc_dev) ||
20 strcmp(obj_type, "dpmcp") == 0 || 18 is_fsl_mc_bus_dpmcp(mc_dev) ||
21 strcmp(obj_type, "dpcon") == 0; 19 is_fsl_mc_bus_dpcon(mc_dev);
22} 20}
23 21
24/** 22/**
@@ -41,25 +39,25 @@ static int __must_check fsl_mc_resource_pool_add_device(struct fsl_mc_bus
41 struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; 39 struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev;
42 int error = -EINVAL; 40 int error = -EINVAL;
43 41
44 if (WARN_ON(pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)) 42 if (pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)
45 goto out; 43 goto out;
46 if (WARN_ON(!fsl_mc_is_allocatable(mc_dev->obj_desc.type))) 44 if (!fsl_mc_is_allocatable(mc_dev))
47 goto out; 45 goto out;
48 if (WARN_ON(mc_dev->resource)) 46 if (mc_dev->resource)
49 goto out; 47 goto out;
50 48
51 res_pool = &mc_bus->resource_pools[pool_type]; 49 res_pool = &mc_bus->resource_pools[pool_type];
52 if (WARN_ON(res_pool->type != pool_type)) 50 if (res_pool->type != pool_type)
53 goto out; 51 goto out;
54 if (WARN_ON(res_pool->mc_bus != mc_bus)) 52 if (res_pool->mc_bus != mc_bus)
55 goto out; 53 goto out;
56 54
57 mutex_lock(&res_pool->mutex); 55 mutex_lock(&res_pool->mutex);
58 56
59 if (WARN_ON(res_pool->max_count < 0)) 57 if (res_pool->max_count < 0)
60 goto out_unlock; 58 goto out_unlock;
61 if (WARN_ON(res_pool->free_count < 0 || 59 if (res_pool->free_count < 0 ||
62 res_pool->free_count > res_pool->max_count)) 60 res_pool->free_count > res_pool->max_count)
63 goto out_unlock; 61 goto out_unlock;
64 62
65 resource = devm_kzalloc(&mc_bus_dev->dev, sizeof(*resource), 63 resource = devm_kzalloc(&mc_bus_dev->dev, sizeof(*resource),
@@ -105,25 +103,25 @@ static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
105 struct fsl_mc_resource *resource; 103 struct fsl_mc_resource *resource;
106 int error = -EINVAL; 104 int error = -EINVAL;
107 105
108 if (WARN_ON(!fsl_mc_is_allocatable(mc_dev->obj_desc.type))) 106 if (!fsl_mc_is_allocatable(mc_dev))
109 goto out; 107 goto out;
110 108
111 resource = mc_dev->resource; 109 resource = mc_dev->resource;
112 if (WARN_ON(!resource || resource->data != mc_dev)) 110 if (!resource || resource->data != mc_dev)
113 goto out; 111 goto out;
114 112
115 mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); 113 mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
116 mc_bus = to_fsl_mc_bus(mc_bus_dev); 114 mc_bus = to_fsl_mc_bus(mc_bus_dev);
117 res_pool = resource->parent_pool; 115 res_pool = resource->parent_pool;
118 if (WARN_ON(res_pool != &mc_bus->resource_pools[resource->type])) 116 if (res_pool != &mc_bus->resource_pools[resource->type])
119 goto out; 117 goto out;
120 118
121 mutex_lock(&res_pool->mutex); 119 mutex_lock(&res_pool->mutex);
122 120
123 if (WARN_ON(res_pool->max_count <= 0)) 121 if (res_pool->max_count <= 0)
124 goto out_unlock; 122 goto out_unlock;
125 if (WARN_ON(res_pool->free_count <= 0 || 123 if (res_pool->free_count <= 0 ||
126 res_pool->free_count > res_pool->max_count)) 124 res_pool->free_count > res_pool->max_count)
127 goto out_unlock; 125 goto out_unlock;
128 126
129 /* 127 /*
@@ -187,11 +185,11 @@ int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
187 FSL_MC_NUM_POOL_TYPES); 185 FSL_MC_NUM_POOL_TYPES);
188 186
189 *new_resource = NULL; 187 *new_resource = NULL;
190 if (WARN_ON(pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)) 188 if (pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)
191 goto out; 189 goto out;
192 190
193 res_pool = &mc_bus->resource_pools[pool_type]; 191 res_pool = &mc_bus->resource_pools[pool_type];
194 if (WARN_ON(res_pool->mc_bus != mc_bus)) 192 if (res_pool->mc_bus != mc_bus)
195 goto out; 193 goto out;
196 194
197 mutex_lock(&res_pool->mutex); 195 mutex_lock(&res_pool->mutex);
@@ -199,7 +197,6 @@ int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
199 struct fsl_mc_resource, node); 197 struct fsl_mc_resource, node);
200 198
201 if (!resource) { 199 if (!resource) {
202 WARN_ON(res_pool->free_count != 0);
203 error = -ENXIO; 200 error = -ENXIO;
204 dev_err(&mc_bus_dev->dev, 201 dev_err(&mc_bus_dev->dev,
205 "No more resources of type %s left\n", 202 "No more resources of type %s left\n",
@@ -207,12 +204,12 @@ int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
207 goto out_unlock; 204 goto out_unlock;
208 } 205 }
209 206
210 if (WARN_ON(resource->type != pool_type)) 207 if (resource->type != pool_type)
211 goto out_unlock; 208 goto out_unlock;
212 if (WARN_ON(resource->parent_pool != res_pool)) 209 if (resource->parent_pool != res_pool)
213 goto out_unlock; 210 goto out_unlock;
214 if (WARN_ON(res_pool->free_count <= 0 || 211 if (res_pool->free_count <= 0 ||
215 res_pool->free_count > res_pool->max_count)) 212 res_pool->free_count > res_pool->max_count)
216 goto out_unlock; 213 goto out_unlock;
217 214
218 list_del_init(&resource->node); 215 list_del_init(&resource->node);
@@ -232,15 +229,15 @@ void fsl_mc_resource_free(struct fsl_mc_resource *resource)
232 struct fsl_mc_resource_pool *res_pool; 229 struct fsl_mc_resource_pool *res_pool;
233 230
234 res_pool = resource->parent_pool; 231 res_pool = resource->parent_pool;
235 if (WARN_ON(resource->type != res_pool->type)) 232 if (resource->type != res_pool->type)
236 return; 233 return;
237 234
238 mutex_lock(&res_pool->mutex); 235 mutex_lock(&res_pool->mutex);
239 if (WARN_ON(res_pool->free_count < 0 || 236 if (res_pool->free_count < 0 ||
240 res_pool->free_count >= res_pool->max_count)) 237 res_pool->free_count >= res_pool->max_count)
241 goto out_unlock; 238 goto out_unlock;
242 239
243 if (WARN_ON(!list_empty(&resource->node))) 240 if (!list_empty(&resource->node))
244 goto out_unlock; 241 goto out_unlock;
245 242
246 list_add_tail(&resource->node, &res_pool->free_list); 243 list_add_tail(&resource->node, &res_pool->free_list);
@@ -279,13 +276,13 @@ int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
279 struct fsl_mc_resource *resource = NULL; 276 struct fsl_mc_resource *resource = NULL;
280 277
281 *new_mc_adev = NULL; 278 *new_mc_adev = NULL;
282 if (WARN_ON(mc_dev->flags & FSL_MC_IS_DPRC)) 279 if (mc_dev->flags & FSL_MC_IS_DPRC)
283 goto error; 280 goto error;
284 281
285 if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent))) 282 if (!dev_is_fsl_mc(mc_dev->dev.parent))
286 goto error; 283 goto error;
287 284
288 if (WARN_ON(pool_type == FSL_MC_POOL_DPMCP)) 285 if (pool_type == FSL_MC_POOL_DPMCP)
289 goto error; 286 goto error;
290 287
291 mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); 288 mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
@@ -295,7 +292,7 @@ int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
295 goto error; 292 goto error;
296 293
297 mc_adev = resource->data; 294 mc_adev = resource->data;
298 if (WARN_ON(!mc_adev)) 295 if (!mc_adev)
299 goto error; 296 goto error;
300 297
301 *new_mc_adev = mc_adev; 298 *new_mc_adev = mc_adev;
@@ -318,9 +315,9 @@ void fsl_mc_object_free(struct fsl_mc_device *mc_adev)
318 struct fsl_mc_resource *resource; 315 struct fsl_mc_resource *resource;
319 316
320 resource = mc_adev->resource; 317 resource = mc_adev->resource;
321 if (WARN_ON(resource->type == FSL_MC_POOL_DPMCP)) 318 if (resource->type == FSL_MC_POOL_DPMCP)
322 return; 319 return;
323 if (WARN_ON(resource->data != mc_adev)) 320 if (resource->data != mc_adev)
324 return; 321 return;
325 322
326 fsl_mc_resource_free(resource); 323 fsl_mc_resource_free(resource);
@@ -349,8 +346,8 @@ int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
349 struct fsl_mc_resource_pool *res_pool = 346 struct fsl_mc_resource_pool *res_pool =
350 &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; 347 &mc_bus->resource_pools[FSL_MC_POOL_IRQ];
351 348
352 if (WARN_ON(irq_count == 0 || 349 if (irq_count == 0 ||
353 irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS)) 350 irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS)
354 return -EINVAL; 351 return -EINVAL;
355 352
356 error = fsl_mc_msi_domain_alloc_irqs(&mc_bus_dev->dev, irq_count); 353 error = fsl_mc_msi_domain_alloc_irqs(&mc_bus_dev->dev, irq_count);
@@ -406,13 +403,13 @@ void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus)
406 struct fsl_mc_resource_pool *res_pool = 403 struct fsl_mc_resource_pool *res_pool =
407 &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; 404 &mc_bus->resource_pools[FSL_MC_POOL_IRQ];
408 405
409 if (WARN_ON(!mc_bus->irq_resources)) 406 if (!mc_bus->irq_resources)
410 return; 407 return;
411 408
412 if (WARN_ON(res_pool->max_count == 0)) 409 if (res_pool->max_count == 0)
413 return; 410 return;
414 411
415 if (WARN_ON(res_pool->free_count != res_pool->max_count)) 412 if (res_pool->free_count != res_pool->max_count)
416 return; 413 return;
417 414
418 INIT_LIST_HEAD(&res_pool->free_list); 415 INIT_LIST_HEAD(&res_pool->free_list);
@@ -436,19 +433,19 @@ int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev)
436 struct fsl_mc_bus *mc_bus; 433 struct fsl_mc_bus *mc_bus;
437 struct fsl_mc_resource_pool *res_pool; 434 struct fsl_mc_resource_pool *res_pool;
438 435
439 if (WARN_ON(mc_dev->irqs)) 436 if (mc_dev->irqs)
440 return -EINVAL; 437 return -EINVAL;
441 438
442 irq_count = mc_dev->obj_desc.irq_count; 439 irq_count = mc_dev->obj_desc.irq_count;
443 if (WARN_ON(irq_count == 0)) 440 if (irq_count == 0)
444 return -EINVAL; 441 return -EINVAL;
445 442
446 if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) 443 if (is_fsl_mc_bus_dprc(mc_dev))
447 mc_bus = to_fsl_mc_bus(mc_dev); 444 mc_bus = to_fsl_mc_bus(mc_dev);
448 else 445 else
449 mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent)); 446 mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent));
450 447
451 if (WARN_ON(!mc_bus->irq_resources)) 448 if (!mc_bus->irq_resources)
452 return -EINVAL; 449 return -EINVAL;
453 450
454 res_pool = &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; 451 res_pool = &mc_bus->resource_pools[FSL_MC_POOL_IRQ];
@@ -474,7 +471,6 @@ int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev)
474 irqs[i] = to_fsl_mc_irq(resource); 471 irqs[i] = to_fsl_mc_irq(resource);
475 res_allocated_count++; 472 res_allocated_count++;
476 473
477 WARN_ON(irqs[i]->mc_dev);
478 irqs[i]->mc_dev = mc_dev; 474 irqs[i]->mc_dev = mc_dev;
479 irqs[i]->dev_irq_index = i; 475 irqs[i]->dev_irq_index = i;
480 } 476 }
@@ -502,21 +498,20 @@ void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev)
502 struct fsl_mc_bus *mc_bus; 498 struct fsl_mc_bus *mc_bus;
503 struct fsl_mc_device_irq **irqs = mc_dev->irqs; 499 struct fsl_mc_device_irq **irqs = mc_dev->irqs;
504 500
505 if (WARN_ON(!irqs)) 501 if (!irqs)
506 return; 502 return;
507 503
508 irq_count = mc_dev->obj_desc.irq_count; 504 irq_count = mc_dev->obj_desc.irq_count;
509 505
510 if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) 506 if (is_fsl_mc_bus_dprc(mc_dev))
511 mc_bus = to_fsl_mc_bus(mc_dev); 507 mc_bus = to_fsl_mc_bus(mc_dev);
512 else 508 else
513 mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent)); 509 mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent));
514 510
515 if (WARN_ON(!mc_bus->irq_resources)) 511 if (!mc_bus->irq_resources)
516 return; 512 return;
517 513
518 for (i = 0; i < irq_count; i++) { 514 for (i = 0; i < irq_count; i++) {
519 WARN_ON(!irqs[i]->mc_dev);
520 irqs[i]->mc_dev = NULL; 515 irqs[i]->mc_dev = NULL;
521 fsl_mc_resource_free(&irqs[i]->resource); 516 fsl_mc_resource_free(&irqs[i]->resource);
522 } 517 }
@@ -553,17 +548,10 @@ static void fsl_mc_cleanup_resource_pool(struct fsl_mc_device *mc_bus_dev,
553 &mc_bus->resource_pools[pool_type]; 548 &mc_bus->resource_pools[pool_type];
554 int free_count = 0; 549 int free_count = 0;
555 550
556 WARN_ON(res_pool->type != pool_type);
557 WARN_ON(res_pool->free_count != res_pool->max_count);
558
559 list_for_each_entry_safe(resource, next, &res_pool->free_list, node) { 551 list_for_each_entry_safe(resource, next, &res_pool->free_list, node) {
560 free_count++; 552 free_count++;
561 WARN_ON(resource->type != res_pool->type);
562 WARN_ON(resource->parent_pool != res_pool);
563 devm_kfree(&mc_bus_dev->dev, resource); 553 devm_kfree(&mc_bus_dev->dev, resource);
564 } 554 }
565
566 WARN_ON(free_count != res_pool->free_count);
567} 555}
568 556
569void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev) 557void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev)
@@ -585,11 +573,11 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev)
585 struct fsl_mc_bus *mc_bus; 573 struct fsl_mc_bus *mc_bus;
586 int error; 574 int error;
587 575
588 if (WARN_ON(!fsl_mc_is_allocatable(mc_dev->obj_desc.type))) 576 if (!fsl_mc_is_allocatable(mc_dev))
589 return -EINVAL; 577 return -EINVAL;
590 578
591 mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); 579 mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
592 if (WARN_ON(!dev_is_fsl_mc(&mc_bus_dev->dev))) 580 if (!dev_is_fsl_mc(&mc_bus_dev->dev))
593 return -EINVAL; 581 return -EINVAL;
594 582
595 mc_bus = to_fsl_mc_bus(mc_bus_dev); 583 mc_bus = to_fsl_mc_bus(mc_bus_dev);
@@ -614,7 +602,7 @@ static int fsl_mc_allocator_remove(struct fsl_mc_device *mc_dev)
614{ 602{
615 int error; 603 int error;
616 604
617 if (WARN_ON(!fsl_mc_is_allocatable(mc_dev->obj_desc.type))) 605 if (!fsl_mc_is_allocatable(mc_dev))
618 return -EINVAL; 606 return -EINVAL;
619 607
620 if (mc_dev->resource) { 608 if (mc_dev->resource) {
@@ -658,8 +646,3 @@ int __init fsl_mc_allocator_driver_init(void)
658{ 646{
659 return fsl_mc_driver_register(&fsl_mc_allocator_driver); 647 return fsl_mc_driver_register(&fsl_mc_allocator_driver);
660} 648}
661
662void fsl_mc_allocator_driver_exit(void)
663{
664 fsl_mc_driver_unregister(&fsl_mc_allocator_driver);
665}
diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
index 409f2b9e70ff..1b333c43aae9 100644
--- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
@@ -1,12 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Freescale Management Complex (MC) bus driver 3 * Freescale Management Complex (MC) bus driver
3 * 4 *
4 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc. 5 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
5 * Author: German Rivera <German.Rivera@freescale.com> 6 * Author: German Rivera <German.Rivera@freescale.com>
6 * 7 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */ 8 */
11 9
12#define pr_fmt(fmt) "fsl-mc: " fmt 10#define pr_fmt(fmt) "fsl-mc: " fmt
@@ -22,8 +20,6 @@
22#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
23 21
24#include "fsl-mc-private.h" 22#include "fsl-mc-private.h"
25#include "dprc-cmd.h"
26#include "dpmng-cmd.h"
27 23
28/** 24/**
29 * Default DMA mask for devices on a fsl-mc bus 25 * Default DMA mask for devices on a fsl-mc bus
@@ -156,22 +152,80 @@ struct bus_type fsl_mc_bus_type = {
156}; 152};
157EXPORT_SYMBOL_GPL(fsl_mc_bus_type); 153EXPORT_SYMBOL_GPL(fsl_mc_bus_type);
158 154
155struct device_type fsl_mc_bus_dprc_type = {
156 .name = "fsl_mc_bus_dprc"
157};
158
159struct device_type fsl_mc_bus_dpni_type = {
160 .name = "fsl_mc_bus_dpni"
161};
162
163struct device_type fsl_mc_bus_dpio_type = {
164 .name = "fsl_mc_bus_dpio"
165};
166
167struct device_type fsl_mc_bus_dpsw_type = {
168 .name = "fsl_mc_bus_dpsw"
169};
170
171struct device_type fsl_mc_bus_dpbp_type = {
172 .name = "fsl_mc_bus_dpbp"
173};
174
175struct device_type fsl_mc_bus_dpcon_type = {
176 .name = "fsl_mc_bus_dpcon"
177};
178
179struct device_type fsl_mc_bus_dpmcp_type = {
180 .name = "fsl_mc_bus_dpmcp"
181};
182
183struct device_type fsl_mc_bus_dpmac_type = {
184 .name = "fsl_mc_bus_dpmac"
185};
186
187struct device_type fsl_mc_bus_dprtc_type = {
188 .name = "fsl_mc_bus_dprtc"
189};
190
191static struct device_type *fsl_mc_get_device_type(const char *type)
192{
193 static const struct {
194 struct device_type *dev_type;
195 const char *type;
196 } dev_types[] = {
197 { &fsl_mc_bus_dprc_type, "dprc" },
198 { &fsl_mc_bus_dpni_type, "dpni" },
199 { &fsl_mc_bus_dpio_type, "dpio" },
200 { &fsl_mc_bus_dpsw_type, "dpsw" },
201 { &fsl_mc_bus_dpbp_type, "dpbp" },
202 { &fsl_mc_bus_dpcon_type, "dpcon" },
203 { &fsl_mc_bus_dpmcp_type, "dpmcp" },
204 { &fsl_mc_bus_dpmac_type, "dpmac" },
205 { &fsl_mc_bus_dprtc_type, "dprtc" },
206 { NULL, NULL }
207 };
208 int i;
209
210 for (i = 0; dev_types[i].dev_type; i++)
211 if (!strcmp(dev_types[i].type, type))
212 return dev_types[i].dev_type;
213
214 return NULL;
215}
216
159static int fsl_mc_driver_probe(struct device *dev) 217static int fsl_mc_driver_probe(struct device *dev)
160{ 218{
161 struct fsl_mc_driver *mc_drv; 219 struct fsl_mc_driver *mc_drv;
162 struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); 220 struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
163 int error; 221 int error;
164 222
165 if (WARN_ON(!dev->driver))
166 return -EINVAL;
167
168 mc_drv = to_fsl_mc_driver(dev->driver); 223 mc_drv = to_fsl_mc_driver(dev->driver);
169 if (WARN_ON(!mc_drv->probe))
170 return -EINVAL;
171 224
172 error = mc_drv->probe(mc_dev); 225 error = mc_drv->probe(mc_dev);
173 if (error < 0) { 226 if (error < 0) {
174 dev_err(dev, "%s failed: %d\n", __func__, error); 227 if (error != -EPROBE_DEFER)
228 dev_err(dev, "%s failed: %d\n", __func__, error);
175 return error; 229 return error;
176 } 230 }
177 231
@@ -184,9 +238,6 @@ static int fsl_mc_driver_remove(struct device *dev)
184 struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); 238 struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
185 int error; 239 int error;
186 240
187 if (WARN_ON(!dev->driver))
188 return -EINVAL;
189
190 error = mc_drv->remove(mc_dev); 241 error = mc_drv->remove(mc_dev);
191 if (error < 0) { 242 if (error < 0) {
192 dev_err(dev, "%s failed: %d\n", __func__, error); 243 dev_err(dev, "%s failed: %d\n", __func__, error);
@@ -292,9 +343,9 @@ static int mc_get_version(struct fsl_mc_io *mc_io,
292static void fsl_mc_get_root_dprc(struct device *dev, 343static void fsl_mc_get_root_dprc(struct device *dev,
293 struct device **root_dprc_dev) 344 struct device **root_dprc_dev)
294{ 345{
295 if (WARN_ON(!dev)) { 346 if (!dev) {
296 *root_dprc_dev = NULL; 347 *root_dprc_dev = NULL;
297 } else if (WARN_ON(!dev_is_fsl_mc(dev))) { 348 } else if (!dev_is_fsl_mc(dev)) {
298 *root_dprc_dev = NULL; 349 *root_dprc_dev = NULL;
299 } else { 350 } else {
300 *root_dprc_dev = dev; 351 *root_dprc_dev = dev;
@@ -352,8 +403,6 @@ static int translate_mc_addr(struct fsl_mc_device *mc_dev,
352 struct fsl_mc *mc; 403 struct fsl_mc *mc;
353 404
354 fsl_mc_get_root_dprc(&mc_dev->dev, &root_dprc_dev); 405 fsl_mc_get_root_dprc(&mc_dev->dev, &root_dprc_dev);
355 if (WARN_ON(!root_dprc_dev))
356 return -EINVAL;
357 mc = dev_get_drvdata(root_dprc_dev->parent); 406 mc = dev_get_drvdata(root_dprc_dev->parent);
358 407
359 if (mc->num_translation_ranges == 0) { 408 if (mc->num_translation_ranges == 0) {
@@ -390,10 +439,10 @@ static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev,
390 struct device *parent_dev = mc_dev->dev.parent; 439 struct device *parent_dev = mc_dev->dev.parent;
391 enum dprc_region_type mc_region_type; 440 enum dprc_region_type mc_region_type;
392 441
393 if (strcmp(obj_desc->type, "dprc") == 0 || 442 if (is_fsl_mc_bus_dprc(mc_dev) ||
394 strcmp(obj_desc->type, "dpmcp") == 0) { 443 is_fsl_mc_bus_dpmcp(mc_dev)) {
395 mc_region_type = DPRC_REGION_TYPE_MC_PORTAL; 444 mc_region_type = DPRC_REGION_TYPE_MC_PORTAL;
396 } else if (strcmp(obj_desc->type, "dpio") == 0) { 445 } else if (is_fsl_mc_bus_dpio(mc_dev)) {
397 mc_region_type = DPRC_REGION_TYPE_QBMAN_PORTAL; 446 mc_region_type = DPRC_REGION_TYPE_QBMAN_PORTAL;
398 } else { 447 } else {
399 /* 448 /*
@@ -401,7 +450,6 @@ static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev,
401 * type, as this object type is not supposed to have MMIO 450 * type, as this object type is not supposed to have MMIO
402 * regions 451 * regions
403 */ 452 */
404 WARN_ON(true);
405 return -EINVAL; 453 return -EINVAL;
406 } 454 }
407 455
@@ -424,7 +472,6 @@ static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev,
424 goto error_cleanup_regions; 472 goto error_cleanup_regions;
425 } 473 }
426 474
427 WARN_ON(region_desc.size == 0);
428 error = translate_mc_addr(mc_dev, mc_region_type, 475 error = translate_mc_addr(mc_dev, mc_region_type,
429 region_desc.base_offset, 476 region_desc.base_offset,
430 &regions[i].start); 477 &regions[i].start);
@@ -470,7 +517,7 @@ static void fsl_mc_device_release(struct device *dev)
470 517
471 kfree(mc_dev->regions); 518 kfree(mc_dev->regions);
472 519
473 if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) 520 if (is_fsl_mc_bus_dprc(mc_dev))
474 kfree(to_fsl_mc_bus(mc_dev)); 521 kfree(to_fsl_mc_bus(mc_dev));
475 else 522 else
476 kfree(mc_dev); 523 kfree(mc_dev);
@@ -518,6 +565,12 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
518 mc_dev->dev.parent = parent_dev; 565 mc_dev->dev.parent = parent_dev;
519 mc_dev->dev.bus = &fsl_mc_bus_type; 566 mc_dev->dev.bus = &fsl_mc_bus_type;
520 mc_dev->dev.release = fsl_mc_device_release; 567 mc_dev->dev.release = fsl_mc_device_release;
568 mc_dev->dev.type = fsl_mc_get_device_type(obj_desc->type);
569 if (!mc_dev->dev.type) {
570 error = -ENODEV;
571 dev_err(parent_dev, "unknown device type %s\n", obj_desc->type);
572 goto error_cleanup_dev;
573 }
521 dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id); 574 dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id);
522 575
523 if (strcmp(obj_desc->type, "dprc") == 0) { 576 if (strcmp(obj_desc->type, "dprc") == 0) {
@@ -544,7 +597,7 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
544 /* 597 /*
545 * device being added is the root DPRC device 598 * device being added is the root DPRC device
546 */ 599 */
547 if (WARN_ON(!mc_io)) { 600 if (!mc_io) {
548 error = -EINVAL; 601 error = -EINVAL;
549 goto error_cleanup_dev; 602 goto error_cleanup_dev;
550 } 603 }
@@ -826,7 +879,7 @@ static int fsl_mc_bus_remove(struct platform_device *pdev)
826{ 879{
827 struct fsl_mc *mc = platform_get_drvdata(pdev); 880 struct fsl_mc *mc = platform_get_drvdata(pdev);
828 881
829 if (WARN_ON(!fsl_mc_is_root_dprc(&mc->root_mc_bus_dev->dev))) 882 if (!fsl_mc_is_root_dprc(&mc->root_mc_bus_dev->dev))
830 return -EINVAL; 883 return -EINVAL;
831 884
832 fsl_mc_device_remove(mc->root_mc_bus_dev); 885 fsl_mc_device_remove(mc->root_mc_bus_dev);
@@ -878,15 +931,8 @@ static int __init fsl_mc_bus_driver_init(void)
878 if (error < 0) 931 if (error < 0)
879 goto error_cleanup_dprc_driver; 932 goto error_cleanup_dprc_driver;
880 933
881 error = its_fsl_mc_msi_init();
882 if (error < 0)
883 goto error_cleanup_mc_allocator;
884
885 return 0; 934 return 0;
886 935
887error_cleanup_mc_allocator:
888 fsl_mc_allocator_driver_exit();
889
890error_cleanup_dprc_driver: 936error_cleanup_dprc_driver:
891 dprc_driver_exit(); 937 dprc_driver_exit();
892 938
diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
index f74a6f1764bb..971ad87c584c 100644
--- a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
+++ b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
@@ -1,12 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Freescale Management Complex (MC) bus driver MSI support 3 * Freescale Management Complex (MC) bus driver MSI support
3 * 4 *
4 * Copyright (C) 2015-2016 Freescale Semiconductor, Inc. 5 * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
5 * Author: German Rivera <German.Rivera@freescale.com> 6 * Author: German Rivera <German.Rivera@freescale.com>
6 * 7 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */ 8 */
11 9
12#include <linux/of_device.h> 10#include <linux/of_device.h>
@@ -47,7 +45,7 @@ static void fsl_mc_msi_update_dom_ops(struct msi_domain_info *info)
47{ 45{
48 struct msi_domain_ops *ops = info->ops; 46 struct msi_domain_ops *ops = info->ops;
49 47
50 if (WARN_ON(!ops)) 48 if (!ops)
51 return; 49 return;
52 50
53 /* 51 /*
@@ -73,7 +71,7 @@ static void __fsl_mc_msi_write_msg(struct fsl_mc_device *mc_bus_dev,
73 if (msi_desc->msg.address_lo == 0x0 && msi_desc->msg.address_hi == 0x0) 71 if (msi_desc->msg.address_lo == 0x0 && msi_desc->msg.address_hi == 0x0)
74 return; 72 return;
75 73
76 if (WARN_ON(!owner_mc_dev)) 74 if (!owner_mc_dev)
77 return; 75 return;
78 76
79 irq_cfg.paddr = ((u64)msi_desc->msg.address_hi << 32) | 77 irq_cfg.paddr = ((u64)msi_desc->msg.address_hi << 32) |
@@ -124,7 +122,6 @@ static void fsl_mc_msi_write_msg(struct irq_data *irq_data,
124 struct fsl_mc_device_irq *mc_dev_irq = 122 struct fsl_mc_device_irq *mc_dev_irq =
125 &mc_bus->irq_resources[msi_desc->fsl_mc.msi_index]; 123 &mc_bus->irq_resources[msi_desc->fsl_mc.msi_index];
126 124
127 WARN_ON(mc_dev_irq->msi_desc != msi_desc);
128 msi_desc->msg = *msg; 125 msi_desc->msg = *msg;
129 126
130 /* 127 /*
@@ -137,7 +134,7 @@ static void fsl_mc_msi_update_chip_ops(struct msi_domain_info *info)
137{ 134{
138 struct irq_chip *chip = info->chip; 135 struct irq_chip *chip = info->chip;
139 136
140 if (WARN_ON(!chip)) 137 if (!chip)
141 return; 138 return;
142 139
143 /* 140 /*
@@ -239,7 +236,7 @@ int fsl_mc_msi_domain_alloc_irqs(struct device *dev,
239 struct irq_domain *msi_domain; 236 struct irq_domain *msi_domain;
240 int error; 237 int error;
241 238
242 if (WARN_ON(!list_empty(dev_to_msi_list(dev)))) 239 if (!list_empty(dev_to_msi_list(dev)))
243 return -EINVAL; 240 return -EINVAL;
244 241
245 error = fsl_mc_msi_alloc_descs(dev, irq_count); 242 error = fsl_mc_msi_alloc_descs(dev, irq_count);
@@ -247,7 +244,7 @@ int fsl_mc_msi_domain_alloc_irqs(struct device *dev,
247 return error; 244 return error;
248 245
249 msi_domain = dev_get_msi_domain(dev); 246 msi_domain = dev_get_msi_domain(dev);
250 if (WARN_ON(!msi_domain)) { 247 if (!msi_domain) {
251 error = -EINVAL; 248 error = -EINVAL;
252 goto cleanup_msi_descs; 249 goto cleanup_msi_descs;
253 } 250 }
@@ -275,12 +272,12 @@ void fsl_mc_msi_domain_free_irqs(struct device *dev)
275 struct irq_domain *msi_domain; 272 struct irq_domain *msi_domain;
276 273
277 msi_domain = dev_get_msi_domain(dev); 274 msi_domain = dev_get_msi_domain(dev);
278 if (WARN_ON(!msi_domain)) 275 if (!msi_domain)
279 return; 276 return;
280 277
281 msi_domain_free_irqs(msi_domain, dev); 278 msi_domain_free_irqs(msi_domain, dev);
282 279
283 if (WARN_ON(list_empty(dev_to_msi_list(dev)))) 280 if (list_empty(dev_to_msi_list(dev)))
284 return; 281 return;
285 282
286 fsl_mc_msi_free_descs(dev); 283 fsl_mc_msi_free_descs(dev);
diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-private.h b/drivers/staging/fsl-mc/bus/fsl-mc-private.h
index 62d398947605..83b89d6241f2 100644
--- a/drivers/staging/fsl-mc/bus/fsl-mc-private.h
+++ b/drivers/staging/fsl-mc/bus/fsl-mc-private.h
@@ -1,19 +1,384 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Freescale Management Complex (MC) bus private declarations 3 * Freescale Management Complex (MC) bus private declarations
3 * 4 *
4 * Copyright (C) 2016 Freescale Semiconductor, Inc. 5 * Copyright (C) 2016 Freescale Semiconductor, Inc.
5 * 6 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */ 7 */
10#ifndef _FSL_MC_PRIVATE_H_ 8#ifndef _FSL_MC_PRIVATE_H_
11#define _FSL_MC_PRIVATE_H_ 9#define _FSL_MC_PRIVATE_H_
12 10
13#include "../include/mc.h" 11#include "../include/mc.h"
14#include "dprc.h"
15#include <linux/mutex.h> 12#include <linux/mutex.h>
16 13
14/*
15 * Data Path Management Complex (DPMNG) General API
16 */
17
18/* DPMNG command versioning */
19#define DPMNG_CMD_BASE_VERSION 1
20#define DPMNG_CMD_ID_OFFSET 4
21
22#define DPMNG_CMD(id) (((id) << DPMNG_CMD_ID_OFFSET) | DPMNG_CMD_BASE_VERSION)
23
24/* DPMNG command IDs */
25#define DPMNG_CMDID_GET_VERSION DPMNG_CMD(0x831)
26
27struct dpmng_rsp_get_version {
28 __le32 revision;
29 __le32 version_major;
30 __le32 version_minor;
31};
32
33/*
34 * Data Path Management Command Portal (DPMCP) API
35 */
36
37/* Minimal supported DPMCP Version */
38#define DPMCP_MIN_VER_MAJOR 3
39#define DPMCP_MIN_VER_MINOR 0
40
41/* DPMCP command versioning */
42#define DPMCP_CMD_BASE_VERSION 1
43#define DPMCP_CMD_ID_OFFSET 4
44
45#define DPMCP_CMD(id) (((id) << DPMCP_CMD_ID_OFFSET) | DPMCP_CMD_BASE_VERSION)
46
47/* DPMCP command IDs */
48#define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800)
49#define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b)
50#define DPMCP_CMDID_RESET DPMCP_CMD(0x005)
51
52struct dpmcp_cmd_open {
53 __le32 dpmcp_id;
54};
55
56/*
57 * Initialization and runtime control APIs for DPMCP
58 */
59int dpmcp_open(struct fsl_mc_io *mc_io,
60 u32 cmd_flags,
61 int dpmcp_id,
62 u16 *token);
63
64int dpmcp_close(struct fsl_mc_io *mc_io,
65 u32 cmd_flags,
66 u16 token);
67
68int dpmcp_reset(struct fsl_mc_io *mc_io,
69 u32 cmd_flags,
70 u16 token);
71
72/*
73 * Data Path Resource Container (DPRC) API
74 */
75
76/* Minimal supported DPRC Version */
77#define DPRC_MIN_VER_MAJOR 6
78#define DPRC_MIN_VER_MINOR 0
79
80/* DPRC command versioning */
81#define DPRC_CMD_BASE_VERSION 1
82#define DPRC_CMD_ID_OFFSET 4
83
84#define DPRC_CMD(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
85
86/* DPRC command IDs */
87#define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
88#define DPRC_CMDID_OPEN DPRC_CMD(0x805)
89#define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
90
91#define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
92
93#define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
94#define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
95#define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
96#define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
97#define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
98
99#define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
100#define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
101#define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
102#define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
103#define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
104
105struct dprc_cmd_open {
106 __le32 container_id;
107};
108
109struct dprc_cmd_set_irq {
110 /* cmd word 0 */
111 __le32 irq_val;
112 u8 irq_index;
113 u8 pad[3];
114 /* cmd word 1 */
115 __le64 irq_addr;
116 /* cmd word 2 */
117 __le32 irq_num;
118};
119
120#define DPRC_ENABLE 0x1
121
122struct dprc_cmd_set_irq_enable {
123 u8 enable;
124 u8 pad[3];
125 u8 irq_index;
126};
127
128struct dprc_cmd_set_irq_mask {
129 __le32 mask;
130 u8 irq_index;
131};
132
133struct dprc_cmd_get_irq_status {
134 __le32 status;
135 u8 irq_index;
136};
137
138struct dprc_rsp_get_irq_status {
139 __le32 status;
140};
141
142struct dprc_cmd_clear_irq_status {
143 __le32 status;
144 u8 irq_index;
145};
146
147struct dprc_rsp_get_attributes {
148 /* response word 0 */
149 __le32 container_id;
150 __le16 icid;
151 __le16 pad;
152 /* response word 1 */
153 __le32 options;
154 __le32 portal_id;
155};
156
157struct dprc_rsp_get_obj_count {
158 __le32 pad;
159 __le32 obj_count;
160};
161
162struct dprc_cmd_get_obj {
163 __le32 obj_index;
164};
165
166struct dprc_rsp_get_obj {
167 /* response word 0 */
168 __le32 pad0;
169 __le32 id;
170 /* response word 1 */
171 __le16 vendor;
172 u8 irq_count;
173 u8 region_count;
174 __le32 state;
175 /* response word 2 */
176 __le16 version_major;
177 __le16 version_minor;
178 __le16 flags;
179 __le16 pad1;
180 /* response word 3-4 */
181 u8 type[16];
182 /* response word 5-6 */
183 u8 label[16];
184};
185
186struct dprc_cmd_get_obj_region {
187 /* cmd word 0 */
188 __le32 obj_id;
189 __le16 pad0;
190 u8 region_index;
191 u8 pad1;
192 /* cmd word 1-2 */
193 __le64 pad2[2];
194 /* cmd word 3-4 */
195 u8 obj_type[16];
196};
197
198struct dprc_rsp_get_obj_region {
199 /* response word 0 */
200 __le64 pad;
201 /* response word 1 */
202 __le64 base_addr;
203 /* response word 2 */
204 __le32 size;
205};
206
207struct dprc_cmd_set_obj_irq {
208 /* cmd word 0 */
209 __le32 irq_val;
210 u8 irq_index;
211 u8 pad[3];
212 /* cmd word 1 */
213 __le64 irq_addr;
214 /* cmd word 2 */
215 __le32 irq_num;
216 __le32 obj_id;
217 /* cmd word 3-4 */
218 u8 obj_type[16];
219};
220
221/*
222 * DPRC API for managing and querying DPAA resources
223 */
224int dprc_open(struct fsl_mc_io *mc_io,
225 u32 cmd_flags,
226 int container_id,
227 u16 *token);
228
229int dprc_close(struct fsl_mc_io *mc_io,
230 u32 cmd_flags,
231 u16 token);
232
233/* DPRC IRQ events */
234
235/* IRQ event - Indicates that a new object added to the container */
236#define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001
237/* IRQ event - Indicates that an object was removed from the container */
238#define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002
239/*
240 * IRQ event - Indicates that one of the descendant containers that opened by
241 * this container is destroyed
242 */
243#define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
244
245/*
246 * IRQ event - Indicates that on one of the container's opened object is
247 * destroyed
248 */
249#define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
250
251/* Irq event - Indicates that object is created at the container */
252#define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040
253
254/**
255 * struct dprc_irq_cfg - IRQ configuration
256 * @paddr: Address that must be written to signal a message-based interrupt
257 * @val: Value to write into irq_addr address
258 * @irq_num: A user defined number associated with this IRQ
259 */
260struct dprc_irq_cfg {
261 phys_addr_t paddr;
262 u32 val;
263 int irq_num;
264};
265
266int dprc_set_irq(struct fsl_mc_io *mc_io,
267 u32 cmd_flags,
268 u16 token,
269 u8 irq_index,
270 struct dprc_irq_cfg *irq_cfg);
271
272int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
273 u32 cmd_flags,
274 u16 token,
275 u8 irq_index,
276 u8 en);
277
278int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
279 u32 cmd_flags,
280 u16 token,
281 u8 irq_index,
282 u32 mask);
283
284int dprc_get_irq_status(struct fsl_mc_io *mc_io,
285 u32 cmd_flags,
286 u16 token,
287 u8 irq_index,
288 u32 *status);
289
290int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
291 u32 cmd_flags,
292 u16 token,
293 u8 irq_index,
294 u32 status);
295
296/**
297 * struct dprc_attributes - Container attributes
298 * @container_id: Container's ID
299 * @icid: Container's ICID
300 * @portal_id: Container's portal ID
301 * @options: Container's options as set at container's creation
302 */
303struct dprc_attributes {
304 int container_id;
305 u16 icid;
306 int portal_id;
307 u64 options;
308};
309
310int dprc_get_attributes(struct fsl_mc_io *mc_io,
311 u32 cmd_flags,
312 u16 token,
313 struct dprc_attributes *attributes);
314
315int dprc_get_obj_count(struct fsl_mc_io *mc_io,
316 u32 cmd_flags,
317 u16 token,
318 int *obj_count);
319
320int dprc_get_obj(struct fsl_mc_io *mc_io,
321 u32 cmd_flags,
322 u16 token,
323 int obj_index,
324 struct fsl_mc_obj_desc *obj_desc);
325
326int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
327 u32 cmd_flags,
328 u16 token,
329 char *obj_type,
330 int obj_id,
331 u8 irq_index,
332 struct dprc_irq_cfg *irq_cfg);
333
334/* Region flags */
335/* Cacheable - Indicates that region should be mapped as cacheable */
336#define DPRC_REGION_CACHEABLE 0x00000001
337
338/**
339 * enum dprc_region_type - Region type
340 * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
341 * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
342 */
343enum dprc_region_type {
344 DPRC_REGION_TYPE_MC_PORTAL,
345 DPRC_REGION_TYPE_QBMAN_PORTAL
346};
347
348/**
349 * struct dprc_region_desc - Mappable region descriptor
350 * @base_offset: Region offset from region's base address.
351 * For DPMCP and DPRC objects, region base is offset from SoC MC portals
352 * base address; For DPIO, region base is offset from SoC QMan portals
353 * base address
354 * @size: Region size (in bytes)
355 * @flags: Region attributes
356 * @type: Portal region type
357 */
358struct dprc_region_desc {
359 u32 base_offset;
360 u32 size;
361 u32 flags;
362 enum dprc_region_type type;
363};
364
365int dprc_get_obj_region(struct fsl_mc_io *mc_io,
366 u32 cmd_flags,
367 u16 token,
368 char *obj_type,
369 int obj_id,
370 u8 region_index,
371 struct dprc_region_desc *region_desc);
372
373int dprc_get_api_version(struct fsl_mc_io *mc_io,
374 u32 cmd_flags,
375 u16 *major_ver,
376 u16 *minor_ver);
377
378int dprc_get_container_id(struct fsl_mc_io *mc_io,
379 u32 cmd_flags,
380 int *container_id);
381
17/** 382/**
18 * Maximum number of total IRQs that can be pre-allocated for an MC bus' 383 * Maximum number of total IRQs that can be pre-allocated for an MC bus'
19 * IRQ pool 384 * IRQ pool
@@ -73,8 +438,6 @@ void dprc_driver_exit(void);
73 438
74int __init fsl_mc_allocator_driver_init(void); 439int __init fsl_mc_allocator_driver_init(void);
75 440
76void fsl_mc_allocator_driver_exit(void);
77
78void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev); 441void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
79 442
80void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev); 443void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
@@ -91,10 +454,6 @@ int fsl_mc_msi_domain_alloc_irqs(struct device *dev,
91 454
92void fsl_mc_msi_domain_free_irqs(struct device *dev); 455void fsl_mc_msi_domain_free_irqs(struct device *dev);
93 456
94int __init its_fsl_mc_msi_init(void);
95
96void its_fsl_mc_msi_cleanup(void);
97
98int fsl_mc_find_msi_domain(struct device *mc_platform_dev, 457int fsl_mc_find_msi_domain(struct device *mc_platform_dev,
99 struct irq_domain **mc_msi_domain); 458 struct irq_domain **mc_msi_domain);
100 459
diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
index 123e4af58408..5064d5ddf581 100644
--- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
+++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
@@ -1,12 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Freescale Management Complex (MC) bus driver MSI support 3 * Freescale Management Complex (MC) bus driver MSI support
3 * 4 *
4 * Copyright (C) 2015-2016 Freescale Semiconductor, Inc. 5 * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
5 * Author: German Rivera <German.Rivera@freescale.com> 6 * Author: German Rivera <German.Rivera@freescale.com>
6 * 7 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */ 8 */
11 9
12#include <linux/of_device.h> 10#include <linux/of_device.h>
@@ -15,7 +13,7 @@
15#include <linux/msi.h> 13#include <linux/msi.h>
16#include <linux/of.h> 14#include <linux/of.h>
17#include <linux/of_irq.h> 15#include <linux/of_irq.h>
18#include "fsl-mc-private.h" 16#include "../include/mc.h"
19 17
20static struct irq_chip its_msi_irq_chip = { 18static struct irq_chip its_msi_irq_chip = {
21 .name = "ITS-fMSI", 19 .name = "ITS-fMSI",
@@ -32,11 +30,11 @@ static int its_fsl_mc_msi_prepare(struct irq_domain *msi_domain,
32 struct fsl_mc_device *mc_bus_dev; 30 struct fsl_mc_device *mc_bus_dev;
33 struct msi_domain_info *msi_info; 31 struct msi_domain_info *msi_info;
34 32
35 if (WARN_ON(!dev_is_fsl_mc(dev))) 33 if (!dev_is_fsl_mc(dev))
36 return -EINVAL; 34 return -EINVAL;
37 35
38 mc_bus_dev = to_fsl_mc_device(dev); 36 mc_bus_dev = to_fsl_mc_device(dev);
39 if (WARN_ON(!(mc_bus_dev->flags & FSL_MC_IS_DPRC))) 37 if (!(mc_bus_dev->flags & FSL_MC_IS_DPRC))
40 return -EINVAL; 38 return -EINVAL;
41 39
42 /* 40 /*
@@ -67,7 +65,7 @@ static const struct of_device_id its_device_id[] = {
67 {}, 65 {},
68}; 66};
69 67
70int __init its_fsl_mc_msi_init(void) 68static int __init its_fsl_mc_msi_init(void)
71{ 69{
72 struct device_node *np; 70 struct device_node *np;
73 struct irq_domain *parent; 71 struct irq_domain *parent;
@@ -93,30 +91,10 @@ int __init its_fsl_mc_msi_init(void)
93 continue; 91 continue;
94 } 92 }
95 93
96 WARN_ON(mc_msi_domain->host_data !=
97 &its_fsl_mc_msi_domain_info);
98
99 pr_info("fsl-mc MSI: %pOF domain created\n", np); 94 pr_info("fsl-mc MSI: %pOF domain created\n", np);
100 } 95 }
101 96
102 return 0; 97 return 0;
103} 98}
104 99
105void its_fsl_mc_msi_cleanup(void) 100early_initcall(its_fsl_mc_msi_init);
106{
107 struct device_node *np;
108
109 for (np = of_find_matching_node(NULL, its_device_id); np;
110 np = of_find_matching_node(np, its_device_id)) {
111 struct irq_domain *mc_msi_domain = irq_find_matching_host(
112 np,
113 DOMAIN_BUS_FSL_MC_MSI);
114
115 if (!of_property_read_bool(np, "msi-controller"))
116 continue;
117
118 if (mc_msi_domain &&
119 mc_msi_domain->host_data == &its_fsl_mc_msi_domain_info)
120 irq_domain_remove(mc_msi_domain);
121 }
122}
diff --git a/drivers/staging/fsl-mc/bus/mc-io.c b/drivers/staging/fsl-mc/bus/mc-io.c
index f65c23ce83f1..7e6fb360ef12 100644
--- a/drivers/staging/fsl-mc/bus/mc-io.c
+++ b/drivers/staging/fsl-mc/bus/mc-io.c
@@ -1,54 +1,23 @@
1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
1/* 2/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 5 */
32 6
33#include <linux/io.h> 7#include <linux/io.h>
34#include "../include/mc.h" 8#include "../include/mc.h"
35 9
36#include "fsl-mc-private.h" 10#include "fsl-mc-private.h"
37#include "dpmcp.h"
38#include "dpmcp-cmd.h"
39 11
40static int fsl_mc_io_set_dpmcp(struct fsl_mc_io *mc_io, 12static int fsl_mc_io_set_dpmcp(struct fsl_mc_io *mc_io,
41 struct fsl_mc_device *dpmcp_dev) 13 struct fsl_mc_device *dpmcp_dev)
42{ 14{
43 int error; 15 int error;
44 16
45 if (WARN_ON(!dpmcp_dev)) 17 if (mc_io->dpmcp_dev)
46 return -EINVAL;
47
48 if (WARN_ON(mc_io->dpmcp_dev))
49 return -EINVAL; 18 return -EINVAL;
50 19
51 if (WARN_ON(dpmcp_dev->mc_io)) 20 if (dpmcp_dev->mc_io)
52 return -EINVAL; 21 return -EINVAL;
53 22
54 error = dpmcp_open(mc_io, 23 error = dpmcp_open(mc_io,
@@ -68,12 +37,6 @@ static void fsl_mc_io_unset_dpmcp(struct fsl_mc_io *mc_io)
68 int error; 37 int error;
69 struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev; 38 struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev;
70 39
71 if (WARN_ON(!dpmcp_dev))
72 return;
73
74 if (WARN_ON(dpmcp_dev->mc_io != mc_io))
75 return;
76
77 error = dpmcp_close(mc_io, 40 error = dpmcp_close(mc_io,
78 0, 41 0,
79 dpmcp_dev->mc_handle); 42 dpmcp_dev->mc_handle);
@@ -210,7 +173,7 @@ int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
210 if (mc_dev->flags & FSL_MC_IS_DPRC) { 173 if (mc_dev->flags & FSL_MC_IS_DPRC) {
211 mc_bus_dev = mc_dev; 174 mc_bus_dev = mc_dev;
212 } else { 175 } else {
213 if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent))) 176 if (!dev_is_fsl_mc(mc_dev->dev.parent))
214 return error; 177 return error;
215 178
216 mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); 179 mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
@@ -224,8 +187,6 @@ int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
224 187
225 error = -EINVAL; 188 error = -EINVAL;
226 dpmcp_dev = resource->data; 189 dpmcp_dev = resource->data;
227 if (WARN_ON(!dpmcp_dev))
228 goto error_cleanup_resource;
229 190
230 if (dpmcp_dev->obj_desc.ver_major < DPMCP_MIN_VER_MAJOR || 191 if (dpmcp_dev->obj_desc.ver_major < DPMCP_MIN_VER_MAJOR ||
231 (dpmcp_dev->obj_desc.ver_major == DPMCP_MIN_VER_MAJOR && 192 (dpmcp_dev->obj_desc.ver_major == DPMCP_MIN_VER_MAJOR &&
@@ -238,15 +199,9 @@ int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
238 goto error_cleanup_resource; 199 goto error_cleanup_resource;
239 } 200 }
240 201
241 if (WARN_ON(dpmcp_dev->obj_desc.region_count == 0))
242 goto error_cleanup_resource;
243
244 mc_portal_phys_addr = dpmcp_dev->regions[0].start; 202 mc_portal_phys_addr = dpmcp_dev->regions[0].start;
245 mc_portal_size = resource_size(dpmcp_dev->regions); 203 mc_portal_size = resource_size(dpmcp_dev->regions);
246 204
247 if (WARN_ON(mc_portal_size != mc_bus_dev->mc_io->portal_size))
248 goto error_cleanup_resource;
249
250 error = fsl_create_mc_io(&mc_bus_dev->dev, 205 error = fsl_create_mc_io(&mc_bus_dev->dev,
251 mc_portal_phys_addr, 206 mc_portal_phys_addr,
252 mc_portal_size, dpmcp_dev, 207 mc_portal_size, dpmcp_dev,
@@ -279,14 +234,12 @@ void fsl_mc_portal_free(struct fsl_mc_io *mc_io)
279 * to have a DPMCP object associated with. 234 * to have a DPMCP object associated with.
280 */ 235 */
281 dpmcp_dev = mc_io->dpmcp_dev; 236 dpmcp_dev = mc_io->dpmcp_dev;
282 if (WARN_ON(!dpmcp_dev))
283 return;
284 237
285 resource = dpmcp_dev->resource; 238 resource = dpmcp_dev->resource;
286 if (WARN_ON(!resource || resource->type != FSL_MC_POOL_DPMCP)) 239 if (!resource || resource->type != FSL_MC_POOL_DPMCP)
287 return; 240 return;
288 241
289 if (WARN_ON(resource->data != dpmcp_dev)) 242 if (resource->data != dpmcp_dev)
290 return; 243 return;
291 244
292 fsl_destroy_mc_io(mc_io); 245 fsl_destroy_mc_io(mc_io);
@@ -304,9 +257,6 @@ int fsl_mc_portal_reset(struct fsl_mc_io *mc_io)
304 int error; 257 int error;
305 struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev; 258 struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev;
306 259
307 if (WARN_ON(!dpmcp_dev))
308 return -EINVAL;
309
310 error = dpmcp_reset(mc_io, 0, dpmcp_dev->mc_handle); 260 error = dpmcp_reset(mc_io, 0, dpmcp_dev->mc_handle);
311 if (error < 0) { 261 if (error < 0) {
312 dev_err(&dpmcp_dev->dev, "dpmcp_reset() failed: %d\n", error); 262 dev_err(&dpmcp_dev->dev, "dpmcp_reset() failed: %d\n", error);
diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c b/drivers/staging/fsl-mc/bus/mc-sys.c
index 7ce105bd3977..f09d75d9a976 100644
--- a/drivers/staging/fsl-mc/bus/mc-sys.c
+++ b/drivers/staging/fsl-mc/bus/mc-sys.c
@@ -1,35 +1,9 @@
1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
1/* 2/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * 4 *
4 * I/O services to send MC commands to the MC hardware 5 * I/O services to send MC commands to the MC hardware
5 * 6 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the above-listed copyright holders nor the
14 * names of any contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * ALTERNATIVELY, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") as published by the Free Software
19 * Foundation, either version 2 of that License or (at your option) any
20 * later version.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */ 7 */
34 8
35#include <linux/delay.h> 9#include <linux/delay.h>
@@ -40,7 +14,7 @@
40#include <linux/io-64-nonatomic-hi-lo.h> 14#include <linux/io-64-nonatomic-hi-lo.h>
41#include "../include/mc.h" 15#include "../include/mc.h"
42 16
43#include "dpmcp.h" 17#include "fsl-mc-private.h"
44 18
45/** 19/**
46 * Timeout in milliseconds to wait for the completion of an MC command 20 * Timeout in milliseconds to wait for the completion of an MC command
@@ -85,7 +59,7 @@ static int mc_status_to_error(enum mc_cmd_status status)
85 [MC_CMD_STATUS_INVALID_STATE] = -ENODEV, 59 [MC_CMD_STATUS_INVALID_STATE] = -ENODEV,
86 }; 60 };
87 61
88 if (WARN_ON((u32)status >= ARRAY_SIZE(mc_status_to_error_map))) 62 if ((u32)status >= ARRAY_SIZE(mc_status_to_error_map))
89 return -EINVAL; 63 return -EINVAL;
90 64
91 return mc_status_to_error_map[status]; 65 return mc_status_to_error_map[status];
@@ -273,8 +247,7 @@ int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
273 enum mc_cmd_status status; 247 enum mc_cmd_status status;
274 unsigned long irq_flags = 0; 248 unsigned long irq_flags = 0;
275 249
276 if (WARN_ON(in_irq() && 250 if (in_irq() && !(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL))
277 !(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)))
278 return -EINVAL; 251 return -EINVAL;
279 252
280 if (mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL) 253 if (mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)
@@ -320,4 +293,4 @@ common_exit:
320 293
321 return error; 294 return error;
322} 295}
323EXPORT_SYMBOL(mc_send_command); 296EXPORT_SYMBOL_GPL(mc_send_command);
diff --git a/drivers/staging/fsl-mc/include/dpaa2-fd.h b/drivers/staging/fsl-mc/include/dpaa2-fd.h
index cf7857f00a5c..3e022001f0b1 100644
--- a/drivers/staging/fsl-mc/include/dpaa2-fd.h
+++ b/drivers/staging/fsl-mc/include/dpaa2-fd.h
@@ -1,33 +1,8 @@
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
1/* 2/*
2 * Copyright 2014-2016 Freescale Semiconductor Inc. 3 * Copyright 2014-2016 Freescale Semiconductor Inc.
3 * Copyright 2016 NXP 4 * Copyright 2016 NXP
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Freescale Semiconductor nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 6 */
32#ifndef __FSL_DPAA2_FD_H 7#ifndef __FSL_DPAA2_FD_H
33#define __FSL_DPAA2_FD_H 8#define __FSL_DPAA2_FD_H
diff --git a/drivers/staging/fsl-mc/include/dpaa2-global.h b/drivers/staging/fsl-mc/include/dpaa2-global.h
index 0326447fde4e..9bc0713346a8 100644
--- a/drivers/staging/fsl-mc/include/dpaa2-global.h
+++ b/drivers/staging/fsl-mc/include/dpaa2-global.h
@@ -1,33 +1,8 @@
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
1/* 2/*
2 * Copyright 2014-2016 Freescale Semiconductor Inc. 3 * Copyright 2014-2016 Freescale Semiconductor Inc.
3 * Copyright 2016 NXP 4 * Copyright 2016 NXP
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Freescale Semiconductor nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 6 */
32#ifndef __FSL_DPAA2_GLOBAL_H 7#ifndef __FSL_DPAA2_GLOBAL_H
33#define __FSL_DPAA2_GLOBAL_H 8#define __FSL_DPAA2_GLOBAL_H
diff --git a/drivers/staging/fsl-mc/include/dpaa2-io.h b/drivers/staging/fsl-mc/include/dpaa2-io.h
index afc2d060d077..9cb1eec87a9c 100644
--- a/drivers/staging/fsl-mc/include/dpaa2-io.h
+++ b/drivers/staging/fsl-mc/include/dpaa2-io.h
@@ -1,33 +1,8 @@
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
1/* 2/*
2 * Copyright 2014-2016 Freescale Semiconductor Inc. 3 * Copyright 2014-2016 Freescale Semiconductor Inc.
3 * Copyright NXP 4 * Copyright NXP
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Freescale Semiconductor nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 6 */
32#ifndef __FSL_DPAA2_IO_H 7#ifndef __FSL_DPAA2_IO_H
33#define __FSL_DPAA2_IO_H 8#define __FSL_DPAA2_IO_H
@@ -88,6 +63,8 @@ void dpaa2_io_down(struct dpaa2_io *d);
88 63
89irqreturn_t dpaa2_io_irq(struct dpaa2_io *obj); 64irqreturn_t dpaa2_io_irq(struct dpaa2_io *obj);
90 65
66struct dpaa2_io *dpaa2_io_service_select(int cpu);
67
91/** 68/**
92 * struct dpaa2_io_notification_ctx - The DPIO notification context structure 69 * struct dpaa2_io_notification_ctx - The DPIO notification context structure
93 * @cb: The callback to be invoked when the notification arrives 70 * @cb: The callback to be invoked when the notification arrives
@@ -120,13 +97,9 @@ void dpaa2_io_service_deregister(struct dpaa2_io *service,
120int dpaa2_io_service_rearm(struct dpaa2_io *service, 97int dpaa2_io_service_rearm(struct dpaa2_io *service,
121 struct dpaa2_io_notification_ctx *ctx); 98 struct dpaa2_io_notification_ctx *ctx);
122 99
123int dpaa2_io_service_pull_fq(struct dpaa2_io *d, u32 fqid,
124 struct dpaa2_io_store *s);
125int dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid, 100int dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid,
126 struct dpaa2_io_store *s); 101 struct dpaa2_io_store *s);
127 102
128int dpaa2_io_service_enqueue_fq(struct dpaa2_io *d, u32 fqid,
129 const struct dpaa2_fd *fd);
130int dpaa2_io_service_enqueue_qd(struct dpaa2_io *d, u32 qdid, u8 prio, 103int dpaa2_io_service_enqueue_qd(struct dpaa2_io *d, u32 qdid, u8 prio,
131 u16 qdbin, const struct dpaa2_fd *fd); 104 u16 qdbin, const struct dpaa2_fd *fd);
132int dpaa2_io_service_release(struct dpaa2_io *d, u32 bpid, 105int dpaa2_io_service_release(struct dpaa2_io *d, u32 bpid,
diff --git a/drivers/staging/fsl-mc/include/dpbp.h b/drivers/staging/fsl-mc/include/dpbp.h
index e9e04ccea82b..4a1809604319 100644
--- a/drivers/staging/fsl-mc/include/dpbp.h
+++ b/drivers/staging/fsl-mc/include/dpbp.h
@@ -1,34 +1,7 @@
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
1/* 2/*
2 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 5 */
33#ifndef __FSL_DPBP_H 6#ifndef __FSL_DPBP_H
34#define __FSL_DPBP_H 7#define __FSL_DPBP_H
diff --git a/drivers/staging/fsl-mc/include/dpcon.h b/drivers/staging/fsl-mc/include/dpcon.h
index efa23906b364..062e90ad929b 100644
--- a/drivers/staging/fsl-mc/include/dpcon.h
+++ b/drivers/staging/fsl-mc/include/dpcon.h
@@ -1,33 +1,7 @@
1/* Copyright 2013-2016 Freescale Semiconductor Inc. 1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2/*
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
2 * 4 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5 * * Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * * Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 * * Neither the name of the above-listed copyright holders nor the
11 * names of any contributors may be used to endorse or promote products
12 * derived from this software without specific prior written permission.
13 *
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 5 */
32#ifndef __FSL_DPCON_H 6#ifndef __FSL_DPCON_H
33#define __FSL_DPCON_H 7#define __FSL_DPCON_H
@@ -62,11 +36,6 @@ int dpcon_disable(struct fsl_mc_io *mc_io,
62 u32 cmd_flags, 36 u32 cmd_flags,
63 u16 token); 37 u16 token);
64 38
65int dpcon_is_enabled(struct fsl_mc_io *mc_io,
66 u32 cmd_flags,
67 u16 token,
68 int *en);
69
70int dpcon_reset(struct fsl_mc_io *mc_io, 39int dpcon_reset(struct fsl_mc_io *mc_io,
71 u32 cmd_flags, 40 u32 cmd_flags,
72 u16 token); 41 u16 token);
@@ -107,9 +76,4 @@ int dpcon_set_notification(struct fsl_mc_io *mc_io,
107 u16 token, 76 u16 token,
108 struct dpcon_notification_cfg *cfg); 77 struct dpcon_notification_cfg *cfg);
109 78
110int dpcon_get_api_version(struct fsl_mc_io *mc_io,
111 u32 cmd_flags,
112 u16 *major_ver,
113 u16 *minor_ver);
114
115#endif /* __FSL_DPCON_H */ 79#endif /* __FSL_DPCON_H */
diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h
index aafe63a21f49..765ba41f5987 100644
--- a/drivers/staging/fsl-mc/include/mc.h
+++ b/drivers/staging/fsl-mc/include/mc.h
@@ -1,12 +1,10 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Freescale Management Complex (MC) bus public interface 3 * Freescale Management Complex (MC) bus public interface
3 * 4 *
4 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc. 5 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
5 * Author: German Rivera <German.Rivera@freescale.com> 6 * Author: German Rivera <German.Rivera@freescale.com>
6 * 7 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */ 8 */
11#ifndef _FSL_MC_H_ 9#ifndef _FSL_MC_H_
12#define _FSL_MC_H_ 10#define _FSL_MC_H_
@@ -325,7 +323,7 @@ static inline void mc_cmd_read_api_version(struct mc_command *cmd,
325struct fsl_mc_io { 323struct fsl_mc_io {
326 struct device *dev; 324 struct device *dev;
327 u16 flags; 325 u16 flags;
328 u16 portal_size; 326 u32 portal_size;
329 phys_addr_t portal_phys_addr; 327 phys_addr_t portal_phys_addr;
330 void __iomem *portal_virt_addr; 328 void __iomem *portal_virt_addr;
331 struct fsl_mc_device *dpmcp_dev; 329 struct fsl_mc_device *dpmcp_dev;
@@ -398,4 +396,59 @@ void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
398 396
399extern struct bus_type fsl_mc_bus_type; 397extern struct bus_type fsl_mc_bus_type;
400 398
399extern struct device_type fsl_mc_bus_dprc_type;
400extern struct device_type fsl_mc_bus_dpni_type;
401extern struct device_type fsl_mc_bus_dpio_type;
402extern struct device_type fsl_mc_bus_dpsw_type;
403extern struct device_type fsl_mc_bus_dpbp_type;
404extern struct device_type fsl_mc_bus_dpcon_type;
405extern struct device_type fsl_mc_bus_dpmcp_type;
406extern struct device_type fsl_mc_bus_dpmac_type;
407extern struct device_type fsl_mc_bus_dprtc_type;
408
409static inline bool is_fsl_mc_bus_dprc(const struct fsl_mc_device *mc_dev)
410{
411 return mc_dev->dev.type == &fsl_mc_bus_dprc_type;
412}
413
414static inline bool is_fsl_mc_bus_dpni(const struct fsl_mc_device *mc_dev)
415{
416 return mc_dev->dev.type == &fsl_mc_bus_dpni_type;
417}
418
419static inline bool is_fsl_mc_bus_dpio(const struct fsl_mc_device *mc_dev)
420{
421 return mc_dev->dev.type == &fsl_mc_bus_dpio_type;
422}
423
424static inline bool is_fsl_mc_bus_dpsw(const struct fsl_mc_device *mc_dev)
425{
426 return mc_dev->dev.type == &fsl_mc_bus_dpsw_type;
427}
428
429static inline bool is_fsl_mc_bus_dpbp(const struct fsl_mc_device *mc_dev)
430{
431 return mc_dev->dev.type == &fsl_mc_bus_dpbp_type;
432}
433
434static inline bool is_fsl_mc_bus_dpcon(const struct fsl_mc_device *mc_dev)
435{
436 return mc_dev->dev.type == &fsl_mc_bus_dpcon_type;
437}
438
439static inline bool is_fsl_mc_bus_dpmcp(const struct fsl_mc_device *mc_dev)
440{
441 return mc_dev->dev.type == &fsl_mc_bus_dpmcp_type;
442}
443
444static inline bool is_fsl_mc_bus_dpmac(const struct fsl_mc_device *mc_dev)
445{
446 return mc_dev->dev.type == &fsl_mc_bus_dpmac_type;
447}
448
449static inline bool is_fsl_mc_bus_dprtc(const struct fsl_mc_device *mc_dev)
450{
451 return mc_dev->dev.type == &fsl_mc_bus_dprtc_type;
452}
453
401#endif /* _FSL_MC_H_ */ 454#endif /* _FSL_MC_H_ */
diff --git a/drivers/staging/fsl-mc/overview.rst b/drivers/staging/fsl-mc/overview.rst
new file mode 100644
index 000000000000..79fede4447d6
--- /dev/null
+++ b/drivers/staging/fsl-mc/overview.rst
@@ -0,0 +1,404 @@
1.. include:: <isonum.txt>
2
3DPAA2 (Data Path Acceleration Architecture Gen2) Overview
4=========================================================
5
6:Copyright: |copy| 2015 Freescale Semiconductor Inc.
7:Copyright: |copy| 2018 NXP
8
9This document provides an overview of the Freescale DPAA2 architecture
10and how it is integrated into the Linux kernel.
11
12Introduction
13============
14
15DPAA2 is a hardware architecture designed for high-speeed network
16packet processing. DPAA2 consists of sophisticated mechanisms for
17processing Ethernet packets, queue management, buffer management,
18autonomous L2 switching, virtual Ethernet bridging, and accelerator
19(e.g. crypto) sharing.
20
21A DPAA2 hardware component called the Management Complex (or MC) manages the
22DPAA2 hardware resources. The MC provides an object-based abstraction for
23software drivers to use the DPAA2 hardware.
24The MC uses DPAA2 hardware resources such as queues, buffer pools, and
25network ports to create functional objects/devices such as network
26interfaces, an L2 switch, or accelerator instances.
27The MC provides memory-mapped I/O command interfaces (MC portals)
28which DPAA2 software drivers use to operate on DPAA2 objects.
29
30The diagram below shows an overview of the DPAA2 resource management
31architecture::
32
33 +--------------------------------------+
34 | OS |
35 | DPAA2 drivers |
36 | | |
37 +-----------------------------|--------+
38 |
39 | (create,discover,connect
40 | config,use,destroy)
41 |
42 DPAA2 |
43 +------------------------| mc portal |-+
44 | | |
45 | +- - - - - - - - - - - - -V- - -+ |
46 | | | |
47 | | Management Complex (MC) | |
48 | | | |
49 | +- - - - - - - - - - - - - - - -+ |
50 | |
51 | Hardware Hardware |
52 | Resources Objects |
53 | --------- ------- |
54 | -queues -DPRC |
55 | -buffer pools -DPMCP |
56 | -Eth MACs/ports -DPIO |
57 | -network interface -DPNI |
58 | profiles -DPMAC |
59 | -queue portals -DPBP |
60 | -MC portals ... |
61 | ... |
62 | |
63 +--------------------------------------+
64
65
66The MC mediates operations such as create, discover,
67connect, configuration, and destroy. Fast-path operations
68on data, such as packet transmit/receive, are not mediated by
69the MC and are done directly using memory mapped regions in
70DPIO objects.
71
72Overview of DPAA2 Objects
73=========================
74
75The section provides a brief overview of some key DPAA2 objects.
76A simple scenario is described illustrating the objects involved
77in creating a network interfaces.
78
79DPRC (Datapath Resource Container)
80----------------------------------
81
82A DPRC is a container object that holds all the other
83types of DPAA2 objects. In the example diagram below there
84are 8 objects of 5 types (DPMCP, DPIO, DPBP, DPNI, and DPMAC)
85in the container.
86
87::
88
89 +---------------------------------------------------------+
90 | DPRC |
91 | |
92 | +-------+ +-------+ +-------+ +-------+ +-------+ |
93 | | DPMCP | | DPIO | | DPBP | | DPNI | | DPMAC | |
94 | +-------+ +-------+ +-------+ +---+---+ +---+---+ |
95 | | DPMCP | | DPIO | |
96 | +-------+ +-------+ |
97 | | DPMCP | |
98 | +-------+ |
99 | |
100 +---------------------------------------------------------+
101
102From the point of view of an OS, a DPRC behaves similar to a plug and
103play bus, like PCI. DPRC commands can be used to enumerate the contents
104of the DPRC, discover the hardware objects present (including mappable
105regions and interrupts).
106
107::
108
109 DPRC.1 (bus)
110 |
111 +--+--------+-------+-------+-------+
112 | | | | |
113 DPMCP.1 DPIO.1 DPBP.1 DPNI.1 DPMAC.1
114 DPMCP.2 DPIO.2
115 DPMCP.3
116
117Hardware objects can be created and destroyed dynamically, providing
118the ability to hot plug/unplug objects in and out of the DPRC.
119
120A DPRC has a mappable MMIO region (an MC portal) that can be used
121to send MC commands. It has an interrupt for status events (like
122hotplug).
123All objects in a container share the same hardware "isolation context".
124This means that with respect to an IOMMU the isolation granularity
125is at the DPRC (container) level, not at the individual object
126level.
127
128DPRCs can be defined statically and populated with objects
129via a config file passed to the MC when firmware starts it.
130
131DPAA2 Objects for an Ethernet Network Interface
132-----------------------------------------------
133
134A typical Ethernet NIC is monolithic-- the NIC device contains TX/RX
135queuing mechanisms, configuration mechanisms, buffer management,
136physical ports, and interrupts. DPAA2 uses a more granular approach
137utilizing multiple hardware objects. Each object provides specialized
138functions. Groups of these objects are used by software to provide
139Ethernet network interface functionality. This approach provides
140efficient use of finite hardware resources, flexibility, and
141performance advantages.
142
143The diagram below shows the objects needed for a simple
144network interface configuration on a system with 2 CPUs.
145
146::
147
148 +---+---+ +---+---+
149 CPU0 CPU1
150 +---+---+ +---+---+
151 | |
152 +---+---+ +---+---+
153 DPIO DPIO
154 +---+---+ +---+---+
155 \ /
156 \ /
157 \ /
158 +---+---+
159 DPNI --- DPBP,DPMCP
160 +---+---+
161 |
162 |
163 +---+---+
164 DPMAC
165 +---+---+
166 |
167 port/PHY
168
169Below the objects are described. For each object a brief description
170is provided along with a summary of the kinds of operations the object
171supports and a summary of key resources of the object (MMIO regions
172and IRQs).
173
174DPMAC (Datapath Ethernet MAC)
175~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
176Represents an Ethernet MAC, a hardware device that connects to an Ethernet
177PHY and allows physical transmission and reception of Ethernet frames.
178
179- MMIO regions: none
180- IRQs: DPNI link change
181- commands: set link up/down, link config, get stats,
182 IRQ config, enable, reset
183
184DPNI (Datapath Network Interface)
185Contains TX/RX queues, network interface configuration, and RX buffer pool
186configuration mechanisms. The TX/RX queues are in memory and are identified
187by queue number.
188
189- MMIO regions: none
190- IRQs: link state
191- commands: port config, offload config, queue config,
192 parse/classify config, IRQ config, enable, reset
193
194DPIO (Datapath I/O)
195~~~~~~~~~~~~~~~~~~~
196Provides interfaces to enqueue and dequeue
197packets and do hardware buffer pool management operations. The DPAA2
198architecture separates the mechanism to access queues (the DPIO object)
199from the queues themselves. The DPIO provides an MMIO interface to
200enqueue/dequeue packets. To enqueue something a descriptor is written
201to the DPIO MMIO region, which includes the target queue number.
202There will typically be one DPIO assigned to each CPU. This allows all
203CPUs to simultaneously perform enqueue/dequeued operations. DPIOs are
204expected to be shared by different DPAA2 drivers.
205
206- MMIO regions: queue operations, buffer management
207- IRQs: data availability, congestion notification, buffer
208 pool depletion
209- commands: IRQ config, enable, reset
210
211DPBP (Datapath Buffer Pool)
212~~~~~~~~~~~~~~~~~~~~~~~~~~~
213Represents a hardware buffer pool.
214
215- MMIO regions: none
216- IRQs: none
217- commands: enable, reset
218
219DPMCP (Datapath MC Portal)
220~~~~~~~~~~~~~~~~~~~~~~~~~~
221Provides an MC command portal.
222Used by drivers to send commands to the MC to manage
223objects.
224
225- MMIO regions: MC command portal
226- IRQs: command completion
227- commands: IRQ config, enable, reset
228
229Object Connections
230==================
231Some objects have explicit relationships that must
232be configured:
233
234- DPNI <--> DPMAC
235- DPNI <--> DPNI
236- DPNI <--> L2-switch-port
237
238 A DPNI must be connected to something such as a DPMAC,
239 another DPNI, or L2 switch port. The DPNI connection
240 is made via a DPRC command.
241
242::
243
244 +-------+ +-------+
245 | DPNI | | DPMAC |
246 +---+---+ +---+---+
247 | |
248 +==========+
249
250- DPNI <--> DPBP
251
252 A network interface requires a 'buffer pool' (DPBP
253 object) which provides a list of pointers to memory
254 where received Ethernet data is to be copied. The
255 Ethernet driver configures the DPBPs associated with
256 the network interface.
257
258Interrupts
259==========
260All interrupts generated by DPAA2 objects are message
261interrupts. At the hardware level message interrupts
262generated by devices will normally have 3 components--
2631) a non-spoofable 'device-id' expressed on the hardware
264bus, 2) an address, 3) a data value.
265
266In the case of DPAA2 devices/objects, all objects in the
267same container/DPRC share the same 'device-id'.
268For ARM-based SoC this is the same as the stream ID.
269
270
271DPAA2 Linux Drivers Overview
272============================
273
274This section provides an overview of the Linux kernel drivers for
275DPAA2-- 1) the bus driver and associated "DPAA2 infrastructure"
276drivers and 2) functional object drivers (such as Ethernet).
277
278As described previously, a DPRC is a container that holds the other
279types of DPAA2 objects. It is functionally similar to a plug-and-play
280bus controller.
281Each object in the DPRC is a Linux "device" and is bound to a driver.
282The diagram below shows the Linux drivers involved in a networking
283scenario and the objects bound to each driver. A brief description
284of each driver follows.
285
286::
287
288 +------------+
289 | OS Network |
290 | Stack |
291 +------------+ +------------+
292 | Allocator |. . . . . . . | Ethernet |
293 |(DPMCP,DPBP)| | (DPNI) |
294 +-.----------+ +---+---+----+
295 . . ^ |
296 . . <data avail, | | <enqueue,
297 . . tx confirm> | | dequeue>
298 +-------------+ . | |
299 | DPRC driver | . +---+---V----+ +---------+
300 | (DPRC) | . . . . . .| DPIO driver| | MAC |
301 +----------+--+ | (DPIO) | | (DPMAC) |
302 | +------+-----+ +-----+---+
303 |<dev add/remove> | |
304 | | |
305 +--------+----------+ | +--+---+
306 | MC-bus driver | | | PHY |
307 | | | |driver|
308 | /bus/fsl-mc | | +--+---+
309 +-------------------+ | |
310 | |
311 ========================= HARDWARE =========|=================|======
312 DPIO |
313 | |
314 DPNI---DPBP |
315 | |
316 DPMAC |
317 | |
318 PHY ---------------+
319 ============================================|========================
320
321A brief description of each driver is provided below.
322
323MC-bus driver
324-------------
325The MC-bus driver is a platform driver and is probed from a
326node in the device tree (compatible "fsl,qoriq-mc") passed in by boot
327firmware. It is responsible for bootstrapping the DPAA2 kernel
328infrastructure.
329Key functions include:
330
331- registering a new bus type named "fsl-mc" with the kernel,
332 and implementing bus call-backs (e.g. match/uevent/dev_groups)
333- implementing APIs for DPAA2 driver registration and for device
334 add/remove
335- creates an MSI IRQ domain
336- doing a 'device add' to expose the 'root' DPRC, in turn triggering
337 a bind of the root DPRC to the DPRC driver
338
339The binding for the MC-bus device-tree node can be consulted at
340*Documentation/devicetree/bindings/misc/fsl,qoriq-mc.txt*.
341The sysfs bind/unbind interfaces for the MC-bus can be consulted at
342*Documentation/ABI/testing/sysfs-bus-fsl-mc*.
343
344DPRC driver
345-----------
346The DPRC driver is bound to DPRC objects and does runtime management
347of a bus instance. It performs the initial bus scan of the DPRC
348and handles interrupts for container events such as hot plug by
349re-scanning the DPRC.
350
351Allocator
352---------
353Certain objects such as DPMCP and DPBP are generic and fungible,
354and are intended to be used by other drivers. For example,
355the DPAA2 Ethernet driver needs:
356
357- DPMCPs to send MC commands, to configure network interfaces
358- DPBPs for network buffer pools
359
360The allocator driver registers for these allocatable object types
361and those objects are bound to the allocator when the bus is probed.
362The allocator maintains a pool of objects that are available for
363allocation by other DPAA2 drivers.
364
365DPIO driver
366-----------
367The DPIO driver is bound to DPIO objects and provides services that allow
368other drivers such as the Ethernet driver to enqueue and dequeue data for
369their respective objects.
370Key services include:
371
372- data availability notifications
373- hardware queuing operations (enqueue and dequeue of data)
374- hardware buffer pool management
375
376To transmit a packet the Ethernet driver puts data on a queue and
377invokes a DPIO API. For receive, the Ethernet driver registers
378a data availability notification callback. To dequeue a packet
379a DPIO API is used.
380There is typically one DPIO object per physical CPU for optimum
381performance, allowing different CPUs to simultaneously enqueue
382and dequeue data.
383
384The DPIO driver operates on behalf of all DPAA2 drivers
385active in the kernel-- Ethernet, crypto, compression,
386etc.
387
388Ethernet driver
389---------------
390The Ethernet driver is bound to a DPNI and implements the kernel
391interfaces needed to connect the DPAA2 network interface to
392the network stack.
393Each DPNI corresponds to a Linux network interface.
394
395MAC driver
396----------
397An Ethernet PHY is an off-chip, board specific component and is managed
398by the appropriate PHY driver via an mdio bus. The MAC driver
399plays a role of being a proxy between the PHY driver and the
400MC. It does this proxy via the MC commands to a DPMAC object.
401If the PHY driver signals a link change, the MAC driver notifies
402the MC via a DPMAC command. If a network interface is brought
403up or down, the MC notifies the DPMAC driver via an interrupt and
404the driver can take appropriate action.
diff --git a/drivers/staging/fwserial/dma_fifo.c b/drivers/staging/fwserial/dma_fifo.c
index 8b23a553fd4a..5dcbab6fd622 100644
--- a/drivers/staging/fwserial/dma_fifo.c
+++ b/drivers/staging/fwserial/dma_fifo.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * DMA-able FIFO implementation 3 * DMA-able FIFO implementation
3 * 4 *
4 * Copyright (C) 2012 Peter Hurley <peter@hurleysoftware.com> 5 * Copyright (C) 2012 Peter Hurley <peter@hurleysoftware.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#include <linux/kernel.h> 8#include <linux/kernel.h>
diff --git a/drivers/staging/fwserial/dma_fifo.h b/drivers/staging/fwserial/dma_fifo.h
index 37a91c6a1709..c46a06336975 100644
--- a/drivers/staging/fwserial/dma_fifo.h
+++ b/drivers/staging/fwserial/dma_fifo.h
@@ -1,17 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * DMA-able FIFO interface 3 * DMA-able FIFO interface
3 * 4 *
4 * Copyright (C) 2012 Peter Hurley <peter@hurleysoftware.com> 5 * Copyright (C) 2012 Peter Hurley <peter@hurleysoftware.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#ifndef _DMA_FIFO_H_ 8#ifndef _DMA_FIFO_H_
diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
index bba7e9c888b3..1993b03a6f2d 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * FireWire Serial driver 3 * FireWire Serial driver
3 * 4 *
4 * Copyright (C) 2012 Peter Hurley <peter@hurleysoftware.com> 5 * Copyright (C) 2012 Peter Hurley <peter@hurleysoftware.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16 7
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
diff --git a/drivers/staging/greybus/arche-apb-ctrl.c b/drivers/staging/greybus/arche-apb-ctrl.c
index b0c66112eb18..cc8d6fc831b4 100644
--- a/drivers/staging/greybus/arche-apb-ctrl.c
+++ b/drivers/staging/greybus/arche-apb-ctrl.c
@@ -72,14 +72,14 @@ static int coldboot_seq(struct platform_device *pdev)
72 int ret; 72 int ret;
73 73
74 if (apb->init_disabled || 74 if (apb->init_disabled ||
75 apb->state == ARCHE_PLATFORM_STATE_ACTIVE) 75 apb->state == ARCHE_PLATFORM_STATE_ACTIVE)
76 return 0; 76 return 0;
77 77
78 /* Hold APB in reset state */ 78 /* Hold APB in reset state */
79 assert_reset(apb->resetn_gpio); 79 assert_reset(apb->resetn_gpio);
80 80
81 if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && 81 if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING &&
82 gpio_is_valid(apb->spi_en_gpio)) 82 gpio_is_valid(apb->spi_en_gpio))
83 devm_gpio_free(dev, apb->spi_en_gpio); 83 devm_gpio_free(dev, apb->spi_en_gpio);
84 84
85 /* Enable power to APB */ 85 /* Enable power to APB */
@@ -122,7 +122,7 @@ static int fw_flashing_seq(struct platform_device *pdev)
122 int ret; 122 int ret;
123 123
124 if (apb->init_disabled || 124 if (apb->init_disabled ||
125 apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING) 125 apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING)
126 return 0; 126 return 0;
127 127
128 ret = regulator_enable(apb->vcore); 128 ret = regulator_enable(apb->vcore);
@@ -146,7 +146,7 @@ static int fw_flashing_seq(struct platform_device *pdev)
146 flags = GPIOF_OUT_INIT_LOW; 146 flags = GPIOF_OUT_INIT_LOW;
147 147
148 ret = devm_gpio_request_one(dev, apb->spi_en_gpio, 148 ret = devm_gpio_request_one(dev, apb->spi_en_gpio,
149 flags, "apb_spi_en"); 149 flags, "apb_spi_en");
150 if (ret) { 150 if (ret) {
151 dev_err(dev, "Failed requesting SPI bus en gpio %d\n", 151 dev_err(dev, "Failed requesting SPI bus en gpio %d\n",
152 apb->spi_en_gpio); 152 apb->spi_en_gpio);
@@ -174,11 +174,11 @@ static int standby_boot_seq(struct platform_device *pdev)
174 * then we do not want to change the state 174 * then we do not want to change the state
175 */ 175 */
176 if (apb->state == ARCHE_PLATFORM_STATE_STANDBY || 176 if (apb->state == ARCHE_PLATFORM_STATE_STANDBY ||
177 apb->state == ARCHE_PLATFORM_STATE_OFF) 177 apb->state == ARCHE_PLATFORM_STATE_OFF)
178 return 0; 178 return 0;
179 179
180 if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && 180 if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING &&
181 gpio_is_valid(apb->spi_en_gpio)) 181 gpio_is_valid(apb->spi_en_gpio))
182 devm_gpio_free(dev, apb->spi_en_gpio); 182 devm_gpio_free(dev, apb->spi_en_gpio);
183 183
184 /* 184 /*
@@ -203,7 +203,7 @@ static void poweroff_seq(struct platform_device *pdev)
203 return; 203 return;
204 204
205 if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && 205 if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING &&
206 gpio_is_valid(apb->spi_en_gpio)) 206 gpio_is_valid(apb->spi_en_gpio))
207 devm_gpio_free(dev, apb->spi_en_gpio); 207 devm_gpio_free(dev, apb->spi_en_gpio);
208 208
209 /* disable the clock */ 209 /* disable the clock */
@@ -251,7 +251,8 @@ void apb_ctrl_poweroff(struct device *dev)
251} 251}
252 252
253static ssize_t state_store(struct device *dev, 253static ssize_t state_store(struct device *dev,
254 struct device_attribute *attr, const char *buf, size_t count) 254 struct device_attribute *attr,
255 const char *buf, size_t count)
255{ 256{
256 struct platform_device *pdev = to_platform_device(dev); 257 struct platform_device *pdev = to_platform_device(dev);
257 struct arche_apb_ctrl_drvdata *apb = platform_get_drvdata(pdev); 258 struct arche_apb_ctrl_drvdata *apb = platform_get_drvdata(pdev);
@@ -297,7 +298,7 @@ static ssize_t state_store(struct device *dev,
297} 298}
298 299
299static ssize_t state_show(struct device *dev, 300static ssize_t state_show(struct device *dev,
300 struct device_attribute *attr, char *buf) 301 struct device_attribute *attr, char *buf)
301{ 302{
302 struct arche_apb_ctrl_drvdata *apb = dev_get_drvdata(dev); 303 struct arche_apb_ctrl_drvdata *apb = dev_get_drvdata(dev);
303 304
@@ -319,7 +320,7 @@ static ssize_t state_show(struct device *dev,
319static DEVICE_ATTR_RW(state); 320static DEVICE_ATTR_RW(state);
320 321
321static int apb_ctrl_get_devtree_data(struct platform_device *pdev, 322static int apb_ctrl_get_devtree_data(struct platform_device *pdev,
322 struct arche_apb_ctrl_drvdata *apb) 323 struct arche_apb_ctrl_drvdata *apb)
323{ 324{
324 struct device *dev = &pdev->dev; 325 struct device *dev = &pdev->dev;
325 struct device_node *np = dev->of_node; 326 struct device_node *np = dev->of_node;
@@ -331,10 +332,10 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev,
331 return apb->resetn_gpio; 332 return apb->resetn_gpio;
332 } 333 }
333 ret = devm_gpio_request_one(dev, apb->resetn_gpio, 334 ret = devm_gpio_request_one(dev, apb->resetn_gpio,
334 GPIOF_OUT_INIT_LOW, "apb-reset"); 335 GPIOF_OUT_INIT_LOW, "apb-reset");
335 if (ret) { 336 if (ret) {
336 dev_err(dev, "Failed requesting reset gpio %d\n", 337 dev_err(dev, "Failed requesting reset gpio %d\n",
337 apb->resetn_gpio); 338 apb->resetn_gpio);
338 return ret; 339 return ret;
339 } 340 }
340 341
@@ -344,10 +345,10 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev,
344 return apb->boot_ret_gpio; 345 return apb->boot_ret_gpio;
345 } 346 }
346 ret = devm_gpio_request_one(dev, apb->boot_ret_gpio, 347 ret = devm_gpio_request_one(dev, apb->boot_ret_gpio,
347 GPIOF_OUT_INIT_LOW, "boot retention"); 348 GPIOF_OUT_INIT_LOW, "boot retention");
348 if (ret) { 349 if (ret) {
349 dev_err(dev, "Failed requesting bootret gpio %d\n", 350 dev_err(dev, "Failed requesting bootret gpio %d\n",
350 apb->boot_ret_gpio); 351 apb->boot_ret_gpio);
351 return ret; 352 return ret;
352 } 353 }
353 354
@@ -358,10 +359,10 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev,
358 return apb->pwroff_gpio; 359 return apb->pwroff_gpio;
359 } 360 }
360 ret = devm_gpio_request_one(dev, apb->pwroff_gpio, 361 ret = devm_gpio_request_one(dev, apb->pwroff_gpio,
361 GPIOF_IN, "pwroff_n"); 362 GPIOF_IN, "pwroff_n");
362 if (ret) { 363 if (ret) {
363 dev_err(dev, "Failed requesting pwroff_n gpio %d\n", 364 dev_err(dev, "Failed requesting pwroff_n gpio %d\n",
364 apb->pwroff_gpio); 365 apb->pwroff_gpio);
365 return ret; 366 return ret;
366 } 367 }
367 368
@@ -371,10 +372,10 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev,
371 dev_warn(dev, "failed to get clock en gpio\n"); 372 dev_warn(dev, "failed to get clock en gpio\n");
372 } else if (gpio_is_valid(apb->clk_en_gpio)) { 373 } else if (gpio_is_valid(apb->clk_en_gpio)) {
373 ret = devm_gpio_request_one(dev, apb->clk_en_gpio, 374 ret = devm_gpio_request_one(dev, apb->clk_en_gpio,
374 GPIOF_OUT_INIT_LOW, "apb_clk_en"); 375 GPIOF_OUT_INIT_LOW, "apb_clk_en");
375 if (ret) { 376 if (ret) {
376 dev_warn(dev, "Failed requesting APB clock en gpio %d\n", 377 dev_warn(dev, "Failed requesting APB clock en gpio %d\n",
377 apb->clk_en_gpio); 378 apb->clk_en_gpio);
378 return ret; 379 return ret;
379 } 380 }
380 } 381 }
@@ -407,7 +408,7 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev,
407 apb->spi_en_gpio = of_get_named_gpio(np, "spi-en-gpio", 0); 408 apb->spi_en_gpio = of_get_named_gpio(np, "spi-en-gpio", 0);
408 if (apb->spi_en_gpio >= 0) { 409 if (apb->spi_en_gpio >= 0) {
409 if (of_property_read_bool(pdev->dev.of_node, 410 if (of_property_read_bool(pdev->dev.of_node,
410 "spi-en-active-high")) 411 "spi-en-active-high"))
411 apb->spi_en_polarity_high = true; 412 apb->spi_en_polarity_high = true;
412 } 413 }
413 414
diff --git a/drivers/staging/greybus/arche-platform.c b/drivers/staging/greybus/arche-platform.c
index ace4eb365c0e..83254a72a7bb 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -233,7 +233,7 @@ arche_platform_coldboot_seq(struct arche_platform_drvdata *arche_pdata)
233 ret = clk_prepare_enable(arche_pdata->svc_ref_clk); 233 ret = clk_prepare_enable(arche_pdata->svc_ref_clk);
234 if (ret) { 234 if (ret) {
235 dev_err(arche_pdata->dev, "failed to enable svc_ref_clk: %d\n", 235 dev_err(arche_pdata->dev, "failed to enable svc_ref_clk: %d\n",
236 ret); 236 ret);
237 return ret; 237 return ret;
238 } 238 }
239 239
@@ -269,7 +269,7 @@ arche_platform_fw_flashing_seq(struct arche_platform_drvdata *arche_pdata)
269 ret = clk_prepare_enable(arche_pdata->svc_ref_clk); 269 ret = clk_prepare_enable(arche_pdata->svc_ref_clk);
270 if (ret) { 270 if (ret) {
271 dev_err(arche_pdata->dev, "failed to enable svc_ref_clk: %d\n", 271 dev_err(arche_pdata->dev, "failed to enable svc_ref_clk: %d\n",
272 ret); 272 ret);
273 return ret; 273 return ret;
274 } 274 }
275 275
@@ -312,7 +312,8 @@ arche_platform_poweroff_seq(struct arche_platform_drvdata *arche_pdata)
312} 312}
313 313
314static ssize_t state_store(struct device *dev, 314static ssize_t state_store(struct device *dev,
315 struct device_attribute *attr, const char *buf, size_t count) 315 struct device_attribute *attr,
316 const char *buf, size_t count)
316{ 317{
317 struct platform_device *pdev = to_platform_device(dev); 318 struct platform_device *pdev = to_platform_device(dev);
318 struct arche_platform_drvdata *arche_pdata = platform_get_drvdata(pdev); 319 struct arche_platform_drvdata *arche_pdata = platform_get_drvdata(pdev);
@@ -376,7 +377,7 @@ exit:
376} 377}
377 378
378static ssize_t state_show(struct device *dev, 379static ssize_t state_show(struct device *dev,
379 struct device_attribute *attr, char *buf) 380 struct device_attribute *attr, char *buf)
380{ 381{
381 struct arche_platform_drvdata *arche_pdata = dev_get_drvdata(dev); 382 struct arche_platform_drvdata *arche_pdata = dev_get_drvdata(dev);
382 383
@@ -443,7 +444,7 @@ static int arche_platform_probe(struct platform_device *pdev)
443 444
444 /* setup svc reset gpio */ 445 /* setup svc reset gpio */
445 arche_pdata->is_reset_act_hi = of_property_read_bool(np, 446 arche_pdata->is_reset_act_hi = of_property_read_bool(np,
446 "svc,reset-active-high"); 447 "svc,reset-active-high");
447 arche_pdata->svc_reset_gpio = of_get_named_gpio(np, 448 arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
448 "svc,reset-gpio", 449 "svc,reset-gpio",
449 0); 450 0);
@@ -457,7 +458,7 @@ static int arche_platform_probe(struct platform_device *pdev)
457 return ret; 458 return ret;
458 } 459 }
459 ret = gpio_direction_output(arche_pdata->svc_reset_gpio, 460 ret = gpio_direction_output(arche_pdata->svc_reset_gpio,
460 arche_pdata->is_reset_act_hi); 461 arche_pdata->is_reset_act_hi);
461 if (ret) { 462 if (ret) {
462 dev_err(dev, "failed to set svc-reset gpio dir:%d\n", ret); 463 dev_err(dev, "failed to set svc-reset gpio dir:%d\n", ret);
463 return ret; 464 return ret;
@@ -465,7 +466,8 @@ static int arche_platform_probe(struct platform_device *pdev)
465 arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_OFF); 466 arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_OFF);
466 467
467 arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np, 468 arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np,
468 "svc,sysboot-gpio", 0); 469 "svc,sysboot-gpio",
470 0);
469 if (arche_pdata->svc_sysboot_gpio < 0) { 471 if (arche_pdata->svc_sysboot_gpio < 0) {
470 dev_err(dev, "failed to get sysboot gpio\n"); 472 dev_err(dev, "failed to get sysboot gpio\n");
471 return arche_pdata->svc_sysboot_gpio; 473 return arche_pdata->svc_sysboot_gpio;
@@ -483,7 +485,8 @@ static int arche_platform_probe(struct platform_device *pdev)
483 485
484 /* setup the clock request gpio first */ 486 /* setup the clock request gpio first */
485 arche_pdata->svc_refclk_req = of_get_named_gpio(np, 487 arche_pdata->svc_refclk_req = of_get_named_gpio(np,
486 "svc,refclk-req-gpio", 0); 488 "svc,refclk-req-gpio",
489 0);
487 if (arche_pdata->svc_refclk_req < 0) { 490 if (arche_pdata->svc_refclk_req < 0) {
488 dev_err(dev, "failed to get svc clock-req gpio\n"); 491 dev_err(dev, "failed to get svc clock-req gpio\n");
489 return arche_pdata->svc_refclk_req; 492 return arche_pdata->svc_refclk_req;
@@ -525,7 +528,7 @@ static int arche_platform_probe(struct platform_device *pdev)
525 "wake detect"); 528 "wake detect");
526 if (ret) { 529 if (ret) {
527 dev_err(dev, "Failed requesting wake_detect gpio %d\n", 530 dev_err(dev, "Failed requesting wake_detect gpio %d\n",
528 arche_pdata->wake_detect_gpio); 531 arche_pdata->wake_detect_gpio);
529 return ret; 532 return ret;
530 } 533 }
531 534
diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c
index fdb9e83cc34b..35acd55ca5ab 100644
--- a/drivers/staging/greybus/audio_codec.c
+++ b/drivers/staging/greybus/audio_codec.c
@@ -47,7 +47,7 @@ static int gbaudio_module_enable_tx(struct gbaudio_codec_info *codec,
47 int module_state, ret = 0; 47 int module_state, ret = 0;
48 u16 data_cport, i2s_port, cportid; 48 u16 data_cport, i2s_port, cportid;
49 u8 sig_bits, channels; 49 u8 sig_bits, channels;
50 uint32_t format, rate; 50 u32 format, rate;
51 struct gbaudio_data_connection *data; 51 struct gbaudio_data_connection *data;
52 struct gbaudio_stream_params *params; 52 struct gbaudio_stream_params *params;
53 53
@@ -182,7 +182,7 @@ static int gbaudio_module_enable_rx(struct gbaudio_codec_info *codec,
182 int module_state, ret = 0; 182 int module_state, ret = 0;
183 u16 data_cport, i2s_port, cportid; 183 u16 data_cport, i2s_port, cportid;
184 u8 sig_bits, channels; 184 u8 sig_bits, channels;
185 uint32_t format, rate; 185 u32 format, rate;
186 struct gbaudio_data_connection *data; 186 struct gbaudio_data_connection *data;
187 struct gbaudio_stream_params *params; 187 struct gbaudio_stream_params *params;
188 188
@@ -319,7 +319,7 @@ int gbaudio_module_update(struct gbaudio_codec_info *codec,
319 char intf_name[NAME_SIZE], dir[NAME_SIZE]; 319 char intf_name[NAME_SIZE], dir[NAME_SIZE];
320 320
321 dev_dbg(module->dev, "%s:Module update %s sequence\n", w->name, 321 dev_dbg(module->dev, "%s:Module update %s sequence\n", w->name,
322 enable ? "Enable":"Disable"); 322 enable ? "Enable" : "Disable");
323 323
324 if ((w->id != snd_soc_dapm_aif_in) && (w->id != snd_soc_dapm_aif_out)) { 324 if ((w->id != snd_soc_dapm_aif_in) && (w->id != snd_soc_dapm_aif_out)) {
325 dev_dbg(codec->dev, "No action required for %s\n", w->name); 325 dev_dbg(codec->dev, "No action required for %s\n", w->name);
@@ -412,7 +412,7 @@ static int gbcodec_hw_params(struct snd_pcm_substream *substream,
412{ 412{
413 int ret; 413 int ret;
414 u8 sig_bits, channels; 414 u8 sig_bits, channels;
415 uint32_t format, rate; 415 u32 format, rate;
416 struct gbaudio_module_info *module; 416 struct gbaudio_module_info *module;
417 struct gbaudio_data_connection *data; 417 struct gbaudio_data_connection *data;
418 struct gb_bundle *bundle; 418 struct gb_bundle *bundle;
@@ -567,7 +567,7 @@ static int gbcodec_prepare(struct snd_pcm_substream *substream,
567 if (ret) { 567 if (ret) {
568 mutex_unlock(&codec->lock); 568 mutex_unlock(&codec->lock);
569 dev_err_ratelimited(dai->dev, "set_data_size failed:%d\n", 569 dev_err_ratelimited(dai->dev, "set_data_size failed:%d\n",
570 ret); 570 ret);
571 return ret; 571 return ret;
572 } 572 }
573 573
@@ -587,9 +587,8 @@ static int gbcodec_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
587 struct gbaudio_codec_info *codec = dev_get_drvdata(dai->dev); 587 struct gbaudio_codec_info *codec = dev_get_drvdata(dai->dev);
588 struct gbaudio_stream_params *params; 588 struct gbaudio_stream_params *params;
589 589
590
591 dev_dbg(dai->dev, "Mute:%d, Direction:%s\n", mute, 590 dev_dbg(dai->dev, "Mute:%d, Direction:%s\n", mute,
592 stream ? "CAPTURE":"PLAYBACK"); 591 stream ? "CAPTURE" : "PLAYBACK");
593 592
594 mutex_lock(&codec->lock); 593 mutex_lock(&codec->lock);
595 594
@@ -827,7 +826,7 @@ int gbaudio_register_module(struct gbaudio_module_info *module)
827 module->num_dapm_widgets); 826 module->num_dapm_widgets);
828 if (module->controls) 827 if (module->controls)
829 snd_soc_add_codec_controls(codec, module->controls, 828 snd_soc_add_codec_controls(codec, module->controls,
830 module->num_controls); 829 module->num_controls);
831 if (module->dapm_routes) 830 if (module->dapm_routes)
832 snd_soc_dapm_add_routes(&codec->dapm, module->dapm_routes, 831 snd_soc_dapm_add_routes(&codec->dapm, module->dapm_routes,
833 module->num_dapm_routes); 832 module->num_dapm_routes);
@@ -842,8 +841,8 @@ int gbaudio_register_module(struct gbaudio_module_info *module)
842 * from codec->jack_list 841 * from codec->jack_list
843 */ 842 */
844 list_for_each_entry(jack, &codec->jack_list, list) { 843 list_for_each_entry(jack, &codec->jack_list, list) {
845 if ((jack == &module->headset_jack) 844 if ((jack == &module->headset_jack) ||
846 || (jack == &module->button_jack)) 845 (jack == &module->button_jack))
847 snd_device_register(codec->card->snd_card, 846 snd_device_register(codec->card->snd_card,
848 jack->jack); 847 jack->jack);
849 } 848 }
@@ -907,7 +906,6 @@ static void gbaudio_codec_clean_data_rx(struct gbaudio_data_connection *data)
907 data->state[1] = GBAUDIO_CODEC_SHUTDOWN; 906 data->state[1] = GBAUDIO_CODEC_SHUTDOWN;
908} 907}
909 908
910
911static void gbaudio_codec_cleanup(struct gbaudio_module_info *module) 909static void gbaudio_codec_cleanup(struct gbaudio_module_info *module)
912{ 910{
913 struct gbaudio_data_connection *data; 911 struct gbaudio_data_connection *data;
@@ -923,7 +921,6 @@ static void gbaudio_codec_cleanup(struct gbaudio_module_info *module)
923 921
924 if (cap_state > GBAUDIO_CODEC_SHUTDOWN) 922 if (cap_state > GBAUDIO_CODEC_SHUTDOWN)
925 gbaudio_codec_clean_data_rx(data); 923 gbaudio_codec_clean_data_rx(data);
926
927 } 924 }
928} 925}
929 926
@@ -972,7 +969,7 @@ void gbaudio_unregister_module(struct gbaudio_module_info *module)
972 dev_dbg(codec->dev, "Removing %d controls\n", 969 dev_dbg(codec->dev, "Removing %d controls\n",
973 module->num_controls); 970 module->num_controls);
974 snd_soc_remove_codec_controls(codec, module->controls, 971 snd_soc_remove_codec_controls(codec, module->controls,
975 module->num_controls); 972 module->num_controls);
976 } 973 }
977 if (module->dapm_widgets) { 974 if (module->dapm_widgets) {
978 dev_dbg(codec->dev, "Removing %d widgets\n", 975 dev_dbg(codec->dev, "Removing %d widgets\n",
diff --git a/drivers/staging/greybus/audio_codec.h b/drivers/staging/greybus/audio_codec.h
index 161b37c8ef17..a1d5440552d4 100644
--- a/drivers/staging/greybus/audio_codec.h
+++ b/drivers/staging/greybus/audio_codec.h
@@ -53,7 +53,7 @@ enum gbaudio_codec_state {
53struct gbaudio_stream_params { 53struct gbaudio_stream_params {
54 int state; 54 int state;
55 u8 sig_bits, channels; 55 u8 sig_bits, channels;
56 uint32_t format, rate; 56 u32 format, rate;
57}; 57};
58 58
59struct gbaudio_codec_dai { 59struct gbaudio_codec_dai {
@@ -159,7 +159,7 @@ struct gbaudio_module_info {
159}; 159};
160 160
161int gbaudio_tplg_parse_data(struct gbaudio_module_info *module, 161int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
162 struct gb_audio_topology *tplg_data); 162 struct gb_audio_topology *tplg_data);
163void gbaudio_tplg_release(struct gbaudio_module_info *module); 163void gbaudio_tplg_release(struct gbaudio_module_info *module);
164 164
165int gbaudio_module_update(struct gbaudio_codec_info *codec, 165int gbaudio_module_update(struct gbaudio_codec_info *codec,
@@ -183,12 +183,12 @@ extern int gb_audio_gb_enable_widget(struct gb_connection *connection,
183extern int gb_audio_gb_disable_widget(struct gb_connection *connection, 183extern int gb_audio_gb_disable_widget(struct gb_connection *connection,
184 u8 widget_id); 184 u8 widget_id);
185extern int gb_audio_gb_get_pcm(struct gb_connection *connection, 185extern int gb_audio_gb_get_pcm(struct gb_connection *connection,
186 u16 data_cport, uint32_t *format, 186 u16 data_cport, u32 *format,
187 uint32_t *rate, u8 *channels, 187 u32 *rate, u8 *channels,
188 u8 *sig_bits); 188 u8 *sig_bits);
189extern int gb_audio_gb_set_pcm(struct gb_connection *connection, 189extern int gb_audio_gb_set_pcm(struct gb_connection *connection,
190 u16 data_cport, uint32_t format, 190 u16 data_cport, u32 format,
191 uint32_t rate, u8 channels, 191 u32 rate, u8 channels,
192 u8 sig_bits); 192 u8 sig_bits);
193extern int gb_audio_gb_set_tx_data_size(struct gb_connection *connection, 193extern int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
194 u16 data_cport, u16 size); 194 u16 data_cport, u16 size);
diff --git a/drivers/staging/greybus/authentication.c b/drivers/staging/greybus/authentication.c
index 16cc65e1472b..a5d7c53df987 100644
--- a/drivers/staging/greybus/authentication.c
+++ b/drivers/staging/greybus/authentication.c
@@ -202,7 +202,7 @@ static int cap_release(struct inode *inode, struct file *file)
202} 202}
203 203
204static int cap_ioctl(struct gb_cap *cap, unsigned int cmd, 204static int cap_ioctl(struct gb_cap *cap, unsigned int cmd,
205 void __user *buf) 205 void __user *buf)
206{ 206{
207 struct cap_ioc_get_endpoint_uid endpoint_uid; 207 struct cap_ioc_get_endpoint_uid endpoint_uid;
208 struct cap_ioc_get_ims_certificate *ims_cert; 208 struct cap_ioc_get_ims_certificate *ims_cert;
diff --git a/drivers/staging/greybus/camera.c b/drivers/staging/greybus/camera.c
index f13f16b63d7e..07ebfb88db9b 100644
--- a/drivers/staging/greybus/camera.c
+++ b/drivers/staging/greybus/camera.c
@@ -918,7 +918,7 @@ static ssize_t gb_camera_debugfs_configure_streams(struct gb_camera *gcam,
918 918
919 /* Retrieve number of streams to configure */ 919 /* Retrieve number of streams to configure */
920 token = strsep(&buf, ";"); 920 token = strsep(&buf, ";");
921 if (token == NULL) 921 if (!token)
922 return -EINVAL; 922 return -EINVAL;
923 923
924 ret = kstrtouint(token, 10, &nstreams); 924 ret = kstrtouint(token, 10, &nstreams);
@@ -929,7 +929,7 @@ static ssize_t gb_camera_debugfs_configure_streams(struct gb_camera *gcam,
929 return -EINVAL; 929 return -EINVAL;
930 930
931 token = strsep(&buf, ";"); 931 token = strsep(&buf, ";");
932 if (token == NULL) 932 if (!token)
933 return -EINVAL; 933 return -EINVAL;
934 934
935 ret = kstrtouint(token, 10, &flags); 935 ret = kstrtouint(token, 10, &flags);
@@ -946,7 +946,7 @@ static ssize_t gb_camera_debugfs_configure_streams(struct gb_camera *gcam,
946 946
947 /* width */ 947 /* width */
948 token = strsep(&buf, ";"); 948 token = strsep(&buf, ";");
949 if (token == NULL) { 949 if (!token) {
950 ret = -EINVAL; 950 ret = -EINVAL;
951 goto done; 951 goto done;
952 } 952 }
@@ -956,7 +956,7 @@ static ssize_t gb_camera_debugfs_configure_streams(struct gb_camera *gcam,
956 956
957 /* height */ 957 /* height */
958 token = strsep(&buf, ";"); 958 token = strsep(&buf, ";");
959 if (token == NULL) 959 if (!token)
960 goto done; 960 goto done;
961 961
962 ret = kstrtouint(token, 10, &stream->height); 962 ret = kstrtouint(token, 10, &stream->height);
@@ -965,7 +965,7 @@ static ssize_t gb_camera_debugfs_configure_streams(struct gb_camera *gcam,
965 965
966 /* Image format code */ 966 /* Image format code */
967 token = strsep(&buf, ";"); 967 token = strsep(&buf, ";");
968 if (token == NULL) 968 if (!token)
969 goto done; 969 goto done;
970 970
971 ret = kstrtouint(token, 16, &stream->format); 971 ret = kstrtouint(token, 16, &stream->format);
@@ -1009,7 +1009,7 @@ static ssize_t gb_camera_debugfs_capture(struct gb_camera *gcam,
1009 1009
1010 /* Request id */ 1010 /* Request id */
1011 token = strsep(&buf, ";"); 1011 token = strsep(&buf, ";");
1012 if (token == NULL) 1012 if (!token)
1013 return -EINVAL; 1013 return -EINVAL;
1014 ret = kstrtouint(token, 10, &request_id); 1014 ret = kstrtouint(token, 10, &request_id);
1015 if (ret < 0) 1015 if (ret < 0)
@@ -1017,7 +1017,7 @@ static ssize_t gb_camera_debugfs_capture(struct gb_camera *gcam,
1017 1017
1018 /* Stream mask */ 1018 /* Stream mask */
1019 token = strsep(&buf, ";"); 1019 token = strsep(&buf, ";");
1020 if (token == NULL) 1020 if (!token)
1021 return -EINVAL; 1021 return -EINVAL;
1022 ret = kstrtouint(token, 16, &streams_mask); 1022 ret = kstrtouint(token, 16, &streams_mask);
1023 if (ret < 0) 1023 if (ret < 0)
@@ -1025,7 +1025,7 @@ static ssize_t gb_camera_debugfs_capture(struct gb_camera *gcam,
1025 1025
1026 /* number of frames */ 1026 /* number of frames */
1027 token = strsep(&buf, ";"); 1027 token = strsep(&buf, ";");
1028 if (token == NULL) 1028 if (!token)
1029 return -EINVAL; 1029 return -EINVAL;
1030 ret = kstrtouint(token, 10, &num_frames); 1030 ret = kstrtouint(token, 10, &num_frames);
1031 if (ret < 0) 1031 if (ret < 0)
diff --git a/drivers/staging/gs_fpgaboot/io.h b/drivers/staging/gs_fpgaboot/io.h
index 5e839b1fc884..bc5d99cbda8f 100644
--- a/drivers/staging/gs_fpgaboot/io.h
+++ b/drivers/staging/gs_fpgaboot/io.h
@@ -7,12 +7,7 @@
7 * This program is distributed in the hope that it will be useful, 7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 *
11 * GNU General Public License for more details. 10 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 */ 11 */
17 12
18#define GPDIR 0 13#define GPDIR 0
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index cadfb96734ed..f01595593ce2 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -271,7 +271,7 @@ static int ad7192_setup(struct ad7192_state *st,
271 if (pdata->sinc3_en) 271 if (pdata->sinc3_en)
272 st->mode |= AD7192_MODE_SINC3; 272 st->mode |= AD7192_MODE_SINC3;
273 273
274 if (pdata->refin2_en && (st->devid != ID_AD7195)) 274 if (pdata->refin2_en && st->devid != ID_AD7195)
275 st->conf |= AD7192_CONF_REFSEL; 275 st->conf |= AD7192_CONF_REFSEL;
276 276
277 if (pdata->chop_en) { 277 if (pdata->chop_en) {
diff --git a/drivers/staging/iio/cdc/ad7152.c b/drivers/staging/iio/cdc/ad7152.c
index 61377ca444de..19dc896603a1 100644
--- a/drivers/staging/iio/cdc/ad7152.c
+++ b/drivers/staging/iio/cdc/ad7152.c
@@ -47,7 +47,7 @@
47#define AD7152_STATUS_PWDN BIT(7) 47#define AD7152_STATUS_PWDN BIT(7)
48 48
49/* Setup Register Bit Designations (AD7152_REG_CHx_SETUP) */ 49/* Setup Register Bit Designations (AD7152_REG_CHx_SETUP) */
50#define AD7152_SETUP_CAPDIFF (1 << 5) 50#define AD7152_SETUP_CAPDIFF BIT(5)
51#define AD7152_SETUP_RANGE_2pF (0 << 6) 51#define AD7152_SETUP_RANGE_2pF (0 << 6)
52#define AD7152_SETUP_RANGE_0_5pF (1 << 6) 52#define AD7152_SETUP_RANGE_0_5pF (1 << 6)
53#define AD7152_SETUP_RANGE_1pF (2 << 6) 53#define AD7152_SETUP_RANGE_1pF (2 << 6)
@@ -55,8 +55,8 @@
55#define AD7152_SETUP_RANGE(x) ((x) << 6) 55#define AD7152_SETUP_RANGE(x) ((x) << 6)
56 56
57/* Config Register Bit Designations (AD7152_REG_CFG) */ 57/* Config Register Bit Designations (AD7152_REG_CFG) */
58#define AD7152_CONF_CH2EN (1 << 3) 58#define AD7152_CONF_CH2EN BIT(3)
59#define AD7152_CONF_CH1EN (1 << 4) 59#define AD7152_CONF_CH1EN BIT(4)
60#define AD7152_CONF_MODE_IDLE (0 << 0) 60#define AD7152_CONF_MODE_IDLE (0 << 0)
61#define AD7152_CONF_MODE_CONT_CONV (1 << 0) 61#define AD7152_CONF_MODE_CONT_CONV (1 << 0)
62#define AD7152_CONF_MODE_SINGLE_CONV (2 << 0) 62#define AD7152_CONF_MODE_SINGLE_CONV (2 << 0)
@@ -64,7 +64,7 @@
64#define AD7152_CONF_MODE_GAIN_CAL (6 << 0) 64#define AD7152_CONF_MODE_GAIN_CAL (6 << 0)
65 65
66/* Capdac Register Bit Designations (AD7152_REG_CAPDAC_XXX) */ 66/* Capdac Register Bit Designations (AD7152_REG_CAPDAC_XXX) */
67#define AD7152_CAPDAC_DACEN (1 << 7) 67#define AD7152_CAPDAC_DACEN BIT(7)
68#define AD7152_CAPDAC_DACP(x) ((x) & 0x1F) 68#define AD7152_CAPDAC_DACP(x) ((x) & 0x1F)
69 69
70/* CFG2 Register Bit Designations (AD7152_REG_CFG2) */ 70/* CFG2 Register Bit Designations (AD7152_REG_CFG2) */
@@ -118,22 +118,23 @@ static inline ssize_t ad7152_start_calib(struct device *dev,
118 118
119 mutex_lock(&chip->state_lock); 119 mutex_lock(&chip->state_lock);
120 ret = i2c_smbus_write_byte_data(chip->client, AD7152_REG_CFG, regval); 120 ret = i2c_smbus_write_byte_data(chip->client, AD7152_REG_CFG, regval);
121 if (ret < 0) { 121 if (ret < 0)
122 mutex_unlock(&chip->state_lock); 122 goto unlock;
123 return ret;
124 }
125 123
126 do { 124 do {
127 mdelay(20); 125 mdelay(20);
128 ret = i2c_smbus_read_byte_data(chip->client, AD7152_REG_CFG); 126 ret = i2c_smbus_read_byte_data(chip->client, AD7152_REG_CFG);
129 if (ret < 0) { 127 if (ret < 0)
130 mutex_unlock(&chip->state_lock); 128 goto unlock;
131 return ret; 129
132 }
133 } while ((ret == regval) && timeout--); 130 } while ((ret == regval) && timeout--);
134 131
135 mutex_unlock(&chip->state_lock); 132 mutex_unlock(&chip->state_lock);
136 return len; 133 return len;
134
135unlock:
136 mutex_unlock(&chip->state_lock);
137 return ret;
137} 138}
138 139
139static ssize_t ad7152_start_offset_calib(struct device *dev, 140static ssize_t ad7152_start_offset_calib(struct device *dev,
diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c
index a124853a05f0..c4a864725376 100644
--- a/drivers/staging/iio/cdc/ad7746.c
+++ b/drivers/staging/iio/cdc/ad7746.c
@@ -302,23 +302,24 @@ static inline ssize_t ad7746_start_calib(struct device *dev,
302 mutex_lock(&chip->lock); 302 mutex_lock(&chip->lock);
303 regval |= chip->config; 303 regval |= chip->config;
304 ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG, regval); 304 ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG, regval);
305 if (ret < 0) { 305 if (ret < 0)
306 mutex_unlock(&chip->lock); 306 goto unlock;
307 return ret;
308 }
309 307
310 do { 308 do {
311 msleep(20); 309 msleep(20);
312 ret = i2c_smbus_read_byte_data(chip->client, AD7746_REG_CFG); 310 ret = i2c_smbus_read_byte_data(chip->client, AD7746_REG_CFG);
313 if (ret < 0) { 311 if (ret < 0)
314 mutex_unlock(&chip->lock); 312 goto unlock;
315 return ret; 313
316 }
317 } while ((ret == regval) && timeout--); 314 } while ((ret == regval) && timeout--);
318 315
319 mutex_unlock(&chip->lock); 316 mutex_unlock(&chip->lock);
320 317
321 return len; 318 return len;
319
320unlock:
321 mutex_unlock(&chip->lock);
322 return ret;
322} 323}
323 324
324static ssize_t ad7746_start_offset_calib(struct device *dev, 325static ssize_t ad7746_start_offset_calib(struct device *dev,
diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index 42ed9c015aaf..126e11530ce0 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -1441,7 +1441,8 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
1441 1441
1442static struct attribute *tsl2x7x_ALS_device_attrs[] = { 1442static struct attribute *tsl2x7x_ALS_device_attrs[] = {
1443 &dev_attr_in_illuminance0_calibscale_available.attr, 1443 &dev_attr_in_illuminance0_calibscale_available.attr,
1444 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr, 1444 &iio_const_attr_in_illuminance0_integration_time_available
1445 .dev_attr.attr,
1445 &dev_attr_in_illuminance0_target_input.attr, 1446 &dev_attr_in_illuminance0_target_input.attr,
1446 &dev_attr_in_illuminance0_calibrate.attr, 1447 &dev_attr_in_illuminance0_calibrate.attr,
1447 &dev_attr_in_illuminance0_lux_table.attr, 1448 &dev_attr_in_illuminance0_lux_table.attr,
@@ -1455,7 +1456,8 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = {
1455 1456
1456static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = { 1457static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
1457 &dev_attr_in_illuminance0_calibscale_available.attr, 1458 &dev_attr_in_illuminance0_calibscale_available.attr,
1458 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr, 1459 &iio_const_attr_in_illuminance0_integration_time_available
1460 .dev_attr.attr,
1459 &dev_attr_in_illuminance0_target_input.attr, 1461 &dev_attr_in_illuminance0_target_input.attr,
1460 &dev_attr_in_illuminance0_calibrate.attr, 1462 &dev_attr_in_illuminance0_calibrate.attr,
1461 &dev_attr_in_illuminance0_lux_table.attr, 1463 &dev_attr_in_illuminance0_lux_table.attr,
@@ -1471,7 +1473,8 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
1471 1473
1472static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = { 1474static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
1473 &dev_attr_in_illuminance0_calibscale_available.attr, 1475 &dev_attr_in_illuminance0_calibscale_available.attr,
1474 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr, 1476 &iio_const_attr_in_illuminance0_integration_time_available
1477 .dev_attr.attr,
1475 &dev_attr_in_illuminance0_target_input.attr, 1478 &dev_attr_in_illuminance0_target_input.attr,
1476 &dev_attr_in_illuminance0_calibrate.attr, 1479 &dev_attr_in_illuminance0_calibrate.attr,
1477 &dev_attr_in_illuminance0_lux_table.attr, 1480 &dev_attr_in_illuminance0_lux_table.attr,
diff --git a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
index d80dcf82eba9..71f11d7472c0 100644
--- a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
+++ b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
@@ -78,9 +78,9 @@ static int iio_bfin_tmr_set_state(struct iio_trigger *trig, bool state)
78 return 0; 78 return 0;
79} 79}
80 80
81static ssize_t iio_bfin_tmr_frequency_store(struct device *dev, 81static ssize_t frequency_store(struct device *dev,
82 struct device_attribute *attr, 82 struct device_attribute *attr,
83 const char *buf, size_t count) 83 const char *buf, size_t count)
84{ 84{
85 struct iio_trigger *trig = to_iio_trigger(dev); 85 struct iio_trigger *trig = to_iio_trigger(dev);
86 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig); 86 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig);
@@ -116,9 +116,9 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
116 return count; 116 return count;
117} 117}
118 118
119static ssize_t iio_bfin_tmr_frequency_show(struct device *dev, 119static ssize_t frequency_show(struct device *dev,
120 struct device_attribute *attr, 120 struct device_attribute *attr,
121 char *buf) 121 char *buf)
122{ 122{
123 struct iio_trigger *trig = to_iio_trigger(dev); 123 struct iio_trigger *trig = to_iio_trigger(dev);
124 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig); 124 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig);
@@ -133,8 +133,7 @@ static ssize_t iio_bfin_tmr_frequency_show(struct device *dev,
133 return sprintf(buf, "%lu\n", val); 133 return sprintf(buf, "%lu\n", val);
134} 134}
135 135
136static DEVICE_ATTR(frequency, 0644, iio_bfin_tmr_frequency_show, 136static DEVICE_ATTR_RW(frequency);
137 iio_bfin_tmr_frequency_store);
138 137
139static struct attribute *iio_bfin_tmr_trigger_attrs[] = { 138static struct attribute *iio_bfin_tmr_trigger_attrs[] = {
140 &dev_attr_frequency.attr, 139 &dev_attr_frequency.attr,
@@ -187,9 +186,9 @@ static int iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
187 return -ENOMEM; 186 return -ENOMEM;
188 187
189 st->irq = platform_get_irq(pdev, 0); 188 st->irq = platform_get_irq(pdev, 0);
190 if (!st->irq) { 189 if (st->irq < 0) {
191 dev_err(&pdev->dev, "No IRQs specified"); 190 dev_err(&pdev->dev, "No IRQs specified");
192 return -ENODEV; 191 return st->irq;
193 } 192 }
194 193
195 ret = iio_bfin_tmr_get_number(st->irq); 194 ret = iio_bfin_tmr_get_number(st->irq);
diff --git a/net/ipx/Kconfig b/drivers/staging/ipx/Kconfig
index e9ad0062fbb6..cdff083d0ee6 100644
--- a/net/ipx/Kconfig
+++ b/drivers/staging/ipx/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4config IPX 4config IPX
5 tristate "The IPX protocol" 5 tristate "The IPX protocol"
6 depends on NET
6 select LLC 7 select LLC
7 ---help--- 8 ---help---
8 This is support for the Novell networking protocol, IPX, commonly 9 This is support for the Novell networking protocol, IPX, commonly
diff --git a/net/ipx/Makefile b/drivers/staging/ipx/Makefile
index 440fafa9fd07..440fafa9fd07 100644
--- a/net/ipx/Makefile
+++ b/drivers/staging/ipx/Makefile
diff --git a/drivers/staging/ipx/TODO b/drivers/staging/ipx/TODO
new file mode 100644
index 000000000000..80db5d968264
--- /dev/null
+++ b/drivers/staging/ipx/TODO
@@ -0,0 +1,4 @@
1The ipx code will be removed soon from the kernel tree as it is old and
2obsolete and broken.
3
4Don't worry about fixing up anything here, it's not needed.
diff --git a/net/ipx/af_ipx.c b/drivers/staging/ipx/af_ipx.c
index d21a9d128d3e..d21a9d128d3e 100644
--- a/net/ipx/af_ipx.c
+++ b/drivers/staging/ipx/af_ipx.c
diff --git a/net/ipx/ipx_proc.c b/drivers/staging/ipx/ipx_proc.c
index b9232e4e2ed4..b9232e4e2ed4 100644
--- a/net/ipx/ipx_proc.c
+++ b/drivers/staging/ipx/ipx_proc.c
diff --git a/net/ipx/ipx_route.c b/drivers/staging/ipx/ipx_route.c
index 3cf93aa9f284..3cf93aa9f284 100644
--- a/net/ipx/ipx_route.c
+++ b/drivers/staging/ipx/ipx_route.c
diff --git a/net/ipx/pe2.c b/drivers/staging/ipx/pe2.c
index ba7d4214bbff..ba7d4214bbff 100644
--- a/net/ipx/pe2.c
+++ b/drivers/staging/ipx/pe2.c
diff --git a/net/ipx/sysctl_net_ipx.c b/drivers/staging/ipx/sysctl_net_ipx.c
index c3eef457db88..c3eef457db88 100644
--- a/net/ipx/sysctl_net_ipx.c
+++ b/drivers/staging/ipx/sysctl_net_ipx.c
diff --git a/drivers/staging/irda/drivers/pxaficp_ir.c b/drivers/staging/irda/drivers/pxaficp_ir.c
index 1dba16bc7f8d..2ea00a6531f9 100644
--- a/drivers/staging/irda/drivers/pxaficp_ir.c
+++ b/drivers/staging/irda/drivers/pxaficp_ir.c
@@ -12,7 +12,6 @@
12 * Infra-red driver (SIR/FIR) for the PXA2xx embedded microprocessor 12 * Infra-red driver (SIR/FIR) for the PXA2xx embedded microprocessor
13 * 13 *
14 */ 14 */
15#include <linux/dma-mapping.h>
16#include <linux/interrupt.h> 15#include <linux/interrupt.h>
17#include <linux/module.h> 16#include <linux/module.h>
18#include <linux/netdevice.h> 17#include <linux/netdevice.h>
diff --git a/drivers/staging/irda/net/irlmp.c b/drivers/staging/irda/net/irlmp.c
index 34355061ab0b..7af618fb66c0 100644
--- a/drivers/staging/irda/net/irlmp.c
+++ b/drivers/staging/irda/net/irlmp.c
@@ -1668,7 +1668,7 @@ static int irlmp_slsap_inuse(__u8 slsap_sel)
1668 IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, 1668 IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC,
1669 goto errlsap;); 1669 goto errlsap;);
1670 1670
1671 if ((self->slsap_sel == slsap_sel)) { 1671 if (self->slsap_sel == slsap_sel) {
1672 pr_debug("Source LSAP selector=%02x in use\n", 1672 pr_debug("Source LSAP selector=%02x in use\n",
1673 self->slsap_sel); 1673 self->slsap_sel);
1674 goto errlsap; 1674 goto errlsap;
@@ -1693,7 +1693,7 @@ static int irlmp_slsap_inuse(__u8 slsap_sel)
1693 self = (struct lsap_cb *) hashbin_get_first(irlmp->unconnected_lsaps); 1693 self = (struct lsap_cb *) hashbin_get_first(irlmp->unconnected_lsaps);
1694 while (self != NULL) { 1694 while (self != NULL) {
1695 IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, goto erruncon;); 1695 IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, goto erruncon;);
1696 if ((self->slsap_sel == slsap_sel)) { 1696 if (self->slsap_sel == slsap_sel) {
1697 pr_debug("Source LSAP selector=%02x in use (unconnected)\n", 1697 pr_debug("Source LSAP selector=%02x in use (unconnected)\n",
1698 self->slsap_sel); 1698 self->slsap_sel);
1699 goto erruncon; 1699 goto erruncon;
diff --git a/drivers/staging/ks7010/ks_wlan_net.c b/drivers/staging/ks7010/ks_wlan_net.c
index 880085e2f24a..e48c55769c94 100644
--- a/drivers/staging/ks7010/ks_wlan_net.c
+++ b/drivers/staging/ks7010/ks_wlan_net.c
@@ -2990,7 +2990,7 @@ int ks_wlan_net_stop(struct net_device *dev)
2990/** 2990/**
2991 * is_connect_status() - return true if status is 'connected' 2991 * is_connect_status() - return true if status is 'connected'
2992 * @status: high bit is used as FORCE_DISCONNECT, low bits used for 2992 * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2993 * connect status. 2993 * connect status.
2994 */ 2994 */
2995bool is_connect_status(u32 status) 2995bool is_connect_status(u32 status)
2996{ 2996{
@@ -3000,7 +3000,7 @@ bool is_connect_status(u32 status)
3000/** 3000/**
3001 * is_disconnect_status() - return true if status is 'disconnected' 3001 * is_disconnect_status() - return true if status is 'disconnected'
3002 * @status: high bit is used as FORCE_DISCONNECT, low bits used for 3002 * @status: high bit is used as FORCE_DISCONNECT, low bits used for
3003 * disconnect status. 3003 * disconnect status.
3004 */ 3004 */
3005bool is_disconnect_status(u32 status) 3005bool is_disconnect_status(u32 status)
3006{ 3006{
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
index 6ad8867e5451..ca3472cc952f 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
@@ -45,7 +45,6 @@
45#include <linux/libcfs/libcfs_prim.h> 45#include <linux/libcfs/libcfs_prim.h>
46#include <linux/libcfs/libcfs_time.h> 46#include <linux/libcfs/libcfs_time.h>
47#include <linux/libcfs/libcfs_string.h> 47#include <linux/libcfs/libcfs_string.h>
48#include <linux/libcfs/libcfs_workitem.h>
49#include <linux/libcfs/libcfs_hash.h> 48#include <linux/libcfs/libcfs_hash.h>
50#include <linux/libcfs/libcfs_fail.h> 49#include <linux/libcfs/libcfs_fail.h>
51#include <linux/libcfs/curproc.h> 50#include <linux/libcfs/curproc.h>
@@ -74,16 +73,6 @@ sigset_t cfs_block_sigsinv(unsigned long sigs);
74void cfs_restore_sigs(sigset_t sigset); 73void cfs_restore_sigs(sigset_t sigset);
75void cfs_clear_sigpending(void); 74void cfs_clear_sigpending(void);
76 75
77/*
78 * Random number handling
79 */
80
81/* returns a random 32-bit integer */
82unsigned int cfs_rand(void);
83/* seed the generator */
84void cfs_srand(unsigned int seed1, unsigned int seed2);
85void cfs_get_random_bytes(void *buf, int size);
86
87struct libcfs_ioctl_handler { 76struct libcfs_ioctl_handler {
88 struct list_head item; 77 struct list_head item;
89 int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr); 78 int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
@@ -126,7 +115,7 @@ extern struct miscdevice libcfs_dev;
126 */ 115 */
127extern char lnet_debug_log_upcall[1024]; 116extern char lnet_debug_log_upcall[1024];
128 117
129extern struct cfs_wi_sched *cfs_sched_rehash; 118extern struct workqueue_struct *cfs_rehash_wq;
130 119
131struct lnet_debugfs_symlink_def { 120struct lnet_debugfs_symlink_def {
132 char *name; 121 char *name;
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h
index 6d132f941281..61bce77fddd6 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h
@@ -79,7 +79,7 @@
79/** 79/**
80 * return cpumask of CPU partition \a cpt 80 * return cpumask of CPU partition \a cpt
81 */ 81 */
82cpumask_t *cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt); 82cpumask_var_t *cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt);
83/** 83/**
84 * print string information of cpt-table 84 * print string information of cpt-table
85 */ 85 */
@@ -96,7 +96,7 @@ struct cfs_cpt_table {
96 u64 ctb_version; 96 u64 ctb_version;
97}; 97};
98 98
99static inline cpumask_t * 99static inline cpumask_var_t *
100cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt) 100cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt)
101{ 101{
102 return NULL; 102 return NULL;
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h
index 5a27220cc608..0506f1d45757 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h
@@ -248,7 +248,7 @@ struct cfs_hash {
248 /** # of iterators (caller of cfs_hash_for_each_*) */ 248 /** # of iterators (caller of cfs_hash_for_each_*) */
249 u32 hs_iterators; 249 u32 hs_iterators;
250 /** rehash workitem */ 250 /** rehash workitem */
251 struct cfs_workitem hs_rehash_wi; 251 struct work_struct hs_rehash_work;
252 /** refcount on this hash table */ 252 /** refcount on this hash table */
253 atomic_t hs_refcount; 253 atomic_t hs_refcount;
254 /** rehash buckets-table */ 254 /** rehash buckets-table */
@@ -265,7 +265,7 @@ struct cfs_hash {
265 /** bits when we found the max depth */ 265 /** bits when we found the max depth */
266 unsigned int hs_dep_bits; 266 unsigned int hs_dep_bits;
267 /** workitem to output max depth */ 267 /** workitem to output max depth */
268 struct cfs_workitem hs_dep_wi; 268 struct work_struct hs_dep_work;
269#endif 269#endif
270 /** name of htable */ 270 /** name of htable */
271 char hs_name[0]; 271 char hs_name[0];
@@ -738,7 +738,7 @@ u64 cfs_hash_size_get(struct cfs_hash *hs);
738 */ 738 */
739void cfs_hash_rehash_cancel_locked(struct cfs_hash *hs); 739void cfs_hash_rehash_cancel_locked(struct cfs_hash *hs);
740void cfs_hash_rehash_cancel(struct cfs_hash *hs); 740void cfs_hash_rehash_cancel(struct cfs_hash *hs);
741int cfs_hash_rehash(struct cfs_hash *hs, int do_rehash); 741void cfs_hash_rehash(struct cfs_hash *hs, int do_rehash);
742void cfs_hash_rehash_key(struct cfs_hash *hs, const void *old_key, 742void cfs_hash_rehash_key(struct cfs_hash *hs, const void *old_key,
743 void *new_key, struct hlist_node *hnode); 743 void *new_key, struct hlist_node *hnode);
744 744
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
index 2f4ff595fac9..491d5971d199 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
@@ -43,13 +43,6 @@
43# define DEBUG_SUBSYSTEM S_UNDEFINED 43# define DEBUG_SUBSYSTEM S_UNDEFINED
44#endif 44#endif
45 45
46/*
47 * When this is on, LASSERT macro includes check for assignment used instead
48 * of equality check, but doesn't have unlikely(). Turn this on from time to
49 * time to make test-builds. This shouldn't be on for production release.
50 */
51#define LASSERT_CHECKED (0)
52
53#define LASSERTF(cond, fmt, ...) \ 46#define LASSERTF(cond, fmt, ...) \
54do { \ 47do { \
55 if (unlikely(!(cond))) { \ 48 if (unlikely(!(cond))) { \
@@ -74,8 +67,6 @@ do { \
74# define LINVRNT(exp) ((void)sizeof !!(exp)) 67# define LINVRNT(exp) ((void)sizeof !!(exp))
75#endif 68#endif
76 69
77#define KLASSERT(e) LASSERT(e)
78
79void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *msg); 70void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *msg);
80 71
81#define LBUG() \ 72#define LBUG() \
@@ -84,74 +75,24 @@ do { \
84 lbug_with_loc(&msgdata); \ 75 lbug_with_loc(&msgdata); \
85} while (0) 76} while (0)
86 77
87#ifndef LIBCFS_VMALLOC_SIZE 78/*
88#define LIBCFS_VMALLOC_SIZE (2 << PAGE_SHIFT) /* 2 pages */ 79 * Use #define rather than inline, as lnet_cpt_table() might
89#endif 80 * not be defined yet
90
91#define LIBCFS_ALLOC_PRE(size, mask) \
92 LASSERT(!in_interrupt() || ((size) <= LIBCFS_VMALLOC_SIZE && \
93 !gfpflags_allow_blocking(mask)))
94
95#define LIBCFS_ALLOC_POST(ptr, size) \
96do { \
97 if (unlikely(!(ptr))) { \
98 CERROR("LNET: out of memory at %s:%d (tried to alloc '" \
99 #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size)); \
100 } else { \
101 memset((ptr), 0, (size)); \
102 } \
103} while (0)
104
105/**
106 * allocate memory with GFP flags @mask
107 */
108#define LIBCFS_ALLOC_GFP(ptr, size, mask) \
109do { \
110 LIBCFS_ALLOC_PRE((size), (mask)); \
111 (ptr) = (size) <= LIBCFS_VMALLOC_SIZE ? \
112 kmalloc((size), (mask)) : vmalloc(size); \
113 LIBCFS_ALLOC_POST((ptr), (size)); \
114} while (0)
115
116/**
117 * default allocator
118 */
119#define LIBCFS_ALLOC(ptr, size) \
120 LIBCFS_ALLOC_GFP(ptr, size, GFP_NOFS)
121
122/**
123 * non-sleeping allocator
124 */ 81 */
125#define LIBCFS_ALLOC_ATOMIC(ptr, size) \ 82#define kmalloc_cpt(size, flags, cpt) \
126 LIBCFS_ALLOC_GFP(ptr, size, GFP_ATOMIC) 83 kmalloc_node(size, flags, cfs_cpt_spread_node(lnet_cpt_table(), cpt))
127 84
128/** 85#define kzalloc_cpt(size, flags, cpt) \
129 * allocate memory for specified CPU partition 86 kmalloc_node(size, flags | __GFP_ZERO, \
130 * \a cptab != NULL, \a cpt is CPU partition id of \a cptab 87 cfs_cpt_spread_node(lnet_cpt_table(), cpt))
131 * \a cptab == NULL, \a cpt is HW NUMA node id
132 */
133#define LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, mask) \
134do { \
135 LIBCFS_ALLOC_PRE((size), (mask)); \
136 (ptr) = (size) <= LIBCFS_VMALLOC_SIZE ? \
137 kmalloc_node((size), (mask), cfs_cpt_spread_node(cptab, cpt)) :\
138 vmalloc_node(size, cfs_cpt_spread_node(cptab, cpt)); \
139 LIBCFS_ALLOC_POST((ptr), (size)); \
140} while (0)
141 88
142/** default numa allocator */ 89#define kvmalloc_cpt(size, flags, cpt) \
143#define LIBCFS_CPT_ALLOC(ptr, cptab, cpt, size) \ 90 kvmalloc_node(size, flags, \
144 LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, GFP_NOFS) 91 cfs_cpt_spread_node(lnet_cpt_table(), cpt))
145 92
146#define LIBCFS_FREE(ptr, size) \ 93#define kvzalloc_cpt(size, flags, cpt) \
147do { \ 94 kvmalloc_node(size, flags | __GFP_ZERO, \
148 if (unlikely(!(ptr))) { \ 95 cfs_cpt_spread_node(lnet_cpt_table(), cpt))
149 CERROR("LIBCFS: free NULL '" #ptr "' (%d bytes) at " \
150 "%s:%d\n", (int)(size), __FILE__, __LINE__); \
151 break; \
152 } \
153 kvfree(ptr); \
154} while (0)
155 96
156/******************************************************************************/ 97/******************************************************************************/
157 98
@@ -242,59 +183,18 @@ do { \
242#define LASSERT_ATOMIC_ZERO(a) LASSERT_ATOMIC_EQ(a, 0) 183#define LASSERT_ATOMIC_ZERO(a) LASSERT_ATOMIC_EQ(a, 0)
243#define LASSERT_ATOMIC_POS(a) LASSERT_ATOMIC_GT(a, 0) 184#define LASSERT_ATOMIC_POS(a) LASSERT_ATOMIC_GT(a, 0)
244 185
245#define CFS_ALLOC_PTR(ptr) LIBCFS_ALLOC(ptr, sizeof(*(ptr)))
246#define CFS_FREE_PTR(ptr) LIBCFS_FREE(ptr, sizeof(*(ptr)))
247
248/* max value for numeric network address */
249#define MAX_NUMERIC_VALUE 0xffffffff
250
251/* implication */ 186/* implication */
252#define ergo(a, b) (!(a) || (b)) 187#define ergo(a, b) (!(a) || (b))
253/* logical equivalence */ 188/* logical equivalence */
254#define equi(a, b) (!!(a) == !!(b)) 189#define equi(a, b) (!!(a) == !!(b))
255 190
256/* --------------------------------------------------------------------
257 * Light-weight trace
258 * Support for temporary event tracing with minimal Heisenberg effect.
259 * --------------------------------------------------------------------
260 */
261
262#define MKSTR(ptr) ((ptr)) ? (ptr) : ""
263
264static inline size_t cfs_size_round4(int val)
265{
266 return (val + 3) & (~0x3);
267}
268
269#ifndef HAVE_CFS_SIZE_ROUND 191#ifndef HAVE_CFS_SIZE_ROUND
270static inline size_t cfs_size_round(int val) 192static inline size_t cfs_size_round(int val)
271{ 193{
272 return (val + 7) & (~0x7); 194 return round_up(val, 8);
273} 195}
274 196
275#define HAVE_CFS_SIZE_ROUND 197#define HAVE_CFS_SIZE_ROUND
276#endif 198#endif
277 199
278static inline size_t cfs_size_round16(int val)
279{
280 return (val + 0xf) & (~0xf);
281}
282
283static inline size_t cfs_size_round32(int val)
284{
285 return (val + 0x1f) & (~0x1f);
286}
287
288static inline size_t cfs_size_round0(int val)
289{
290 if (!val)
291 return 0;
292 return (val + 1 + 7) & (~0x7);
293}
294
295static inline size_t cfs_round_strlen(char *fset)
296{
297 return cfs_size_round((int)strlen(fset) + 1);
298}
299
300#endif 200#endif
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
index 1191764c431a..66463477074a 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
@@ -73,7 +73,6 @@ struct cfs_expr_list {
73 struct list_head el_exprs; 73 struct list_head el_exprs;
74}; 74};
75 75
76char *cfs_trimwhite(char *str);
77int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res); 76int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res);
78int cfs_str2num_check(char *str, int nob, unsigned int *num, 77int cfs_str2num_check(char *str, int nob, unsigned int *num,
79 unsigned int min, unsigned int max); 78 unsigned int min, unsigned int max);
@@ -86,11 +85,11 @@ static inline void
86cfs_expr_list_values_free(u32 *values, int num) 85cfs_expr_list_values_free(u32 *values, int num)
87{ 86{
88 /* 87 /*
89 * This array is allocated by LIBCFS_ALLOC(), so it shouldn't be freed 88 * This array is allocated by kvalloc(), so it shouldn't be freed
90 * by OBD_FREE() if it's called by module other than libcfs & LNet, 89 * by OBD_FREE() if it's called by module other than libcfs & LNet,
91 * otherwise we will see fake memory leak 90 * otherwise we will see fake memory leak
92 */ 91 */
93 LIBCFS_FREE(values, num * sizeof(values[0])); 92 kvfree(values);
94} 93}
95 94
96void cfs_expr_list_free(struct cfs_expr_list *expr_list); 95void cfs_expr_list_free(struct cfs_expr_list *expr_list);
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h
deleted file mode 100644
index fc780f608e57..000000000000
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h
+++ /dev/null
@@ -1,107 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * GPL HEADER START
4 *
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 only,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License version 2 for more details (a copy is included
15 * in the LICENSE file that accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License
18 * version 2 along with this program; If not, see
19 * http://www.gnu.org/licenses/gpl-2.0.html
20 *
21 * GPL HEADER END
22 */
23/*
24 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25 * Use is subject to license terms.
26 *
27 * Copyright (c) 2012, Intel Corporation.
28 */
29/*
30 * This file is part of Lustre, http://www.lustre.org/
31 * Lustre is a trademark of Sun Microsystems, Inc.
32 *
33 * libcfs/include/libcfs/libcfs_workitem.h
34 *
35 * Author: Isaac Huang <he.h.huang@oracle.com>
36 * Liang Zhen <zhen.liang@sun.com>
37 *
38 * A workitems is deferred work with these semantics:
39 * - a workitem always runs in thread context.
40 * - a workitem can be concurrent with other workitems but is strictly
41 * serialized with respect to itself.
42 * - no CPU affinity, a workitem does not necessarily run on the same CPU
43 * that schedules it. However, this might change in the future.
44 * - if a workitem is scheduled again before it has a chance to run, it
45 * runs only once.
46 * - if a workitem is scheduled while it runs, it runs again after it
47 * completes; this ensures that events occurring while other events are
48 * being processed receive due attention. This behavior also allows a
49 * workitem to reschedule itself.
50 *
51 * Usage notes:
52 * - a workitem can sleep but it should be aware of how that sleep might
53 * affect others.
54 * - a workitem runs inside a kernel thread so there's no user space to access.
55 * - do not use a workitem if the scheduling latency can't be tolerated.
56 *
57 * When wi_action returns non-zero, it means the workitem has either been
58 * freed or reused and workitem scheduler won't touch it any more.
59 */
60
61#ifndef __LIBCFS_WORKITEM_H__
62#define __LIBCFS_WORKITEM_H__
63
64struct cfs_wi_sched;
65
66void cfs_wi_sched_destroy(struct cfs_wi_sched *sched);
67int cfs_wi_sched_create(char *name, struct cfs_cpt_table *cptab, int cpt,
68 int nthrs, struct cfs_wi_sched **sched_pp);
69
70struct cfs_workitem;
71
72typedef int (*cfs_wi_action_t) (struct cfs_workitem *);
73struct cfs_workitem {
74 /** chain on runq or rerunq */
75 struct list_head wi_list;
76 /** working function */
77 cfs_wi_action_t wi_action;
78 /** arg for working function */
79 void *wi_data;
80 /** in running */
81 unsigned short wi_running:1;
82 /** scheduled */
83 unsigned short wi_scheduled:1;
84};
85
86static inline void
87cfs_wi_init(struct cfs_workitem *wi, void *data, cfs_wi_action_t action)
88{
89 INIT_LIST_HEAD(&wi->wi_list);
90
91 wi->wi_running = 0;
92 wi->wi_scheduled = 0;
93 wi->wi_data = data;
94 wi->wi_action = action;
95}
96
97void cfs_wi_schedule(struct cfs_wi_sched *sched, struct cfs_workitem *wi);
98int cfs_wi_deschedule(struct cfs_wi_sched *sched, struct cfs_workitem *wi);
99void cfs_wi_exit(struct cfs_wi_sched *sched, struct cfs_workitem *wi);
100
101int cfs_wi_startup(void);
102void cfs_wi_shutdown(void);
103
104/** # workitem scheduler loops before reschedule */
105#define CFS_WI_RESCHED 128
106
107#endif /* __LIBCFS_WORKITEM_H__ */
diff --git a/drivers/staging/lustre/include/linux/libcfs/linux/linux-cpu.h b/drivers/staging/lustre/include/linux/libcfs/linux/linux-cpu.h
index 854c84358ab4..6035376f2830 100644
--- a/drivers/staging/lustre/include/linux/libcfs/linux/linux-cpu.h
+++ b/drivers/staging/lustre/include/linux/libcfs/linux/linux-cpu.h
@@ -49,7 +49,7 @@
49/** virtual processing unit */ 49/** virtual processing unit */
50struct cfs_cpu_partition { 50struct cfs_cpu_partition {
51 /* CPUs mask for this partition */ 51 /* CPUs mask for this partition */
52 cpumask_t *cpt_cpumask; 52 cpumask_var_t cpt_cpumask;
53 /* nodes mask for this partition */ 53 /* nodes mask for this partition */
54 nodemask_t *cpt_nodemask; 54 nodemask_t *cpt_nodemask;
55 /* spread rotor for NUMA allocator */ 55 /* spread rotor for NUMA allocator */
@@ -69,7 +69,7 @@ struct cfs_cpt_table {
69 /* shadow HW CPU to CPU partition ID */ 69 /* shadow HW CPU to CPU partition ID */
70 int *ctb_cpu2cpt; 70 int *ctb_cpu2cpt;
71 /* all cpus in this partition table */ 71 /* all cpus in this partition table */
72 cpumask_t *ctb_cpumask; 72 cpumask_var_t ctb_cpumask;
73 /* all nodes in this partition table */ 73 /* all nodes in this partition table */
74 nodemask_t *ctb_nodemask; 74 nodemask_t *ctb_nodemask;
75}; 75};
diff --git a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h
index c1626726fa05..df4c72507a15 100644
--- a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h
+++ b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h
@@ -181,21 +181,6 @@ lnet_net_lock_current(void)
181 181
182#define MAX_PORTALS 64 182#define MAX_PORTALS 64
183 183
184static inline struct lnet_eq *
185lnet_eq_alloc(void)
186{
187 struct lnet_eq *eq;
188
189 LIBCFS_ALLOC(eq, sizeof(*eq));
190 return eq;
191}
192
193static inline void
194lnet_eq_free(struct lnet_eq *eq)
195{
196 LIBCFS_FREE(eq, sizeof(*eq));
197}
198
199static inline struct lnet_libmd * 184static inline struct lnet_libmd *
200lnet_md_alloc(struct lnet_md *umd) 185lnet_md_alloc(struct lnet_md *umd)
201{ 186{
@@ -211,7 +196,7 @@ lnet_md_alloc(struct lnet_md *umd)
211 size = offsetof(struct lnet_libmd, md_iov.iov[niov]); 196 size = offsetof(struct lnet_libmd, md_iov.iov[niov]);
212 } 197 }
213 198
214 LIBCFS_ALLOC(md, size); 199 md = kzalloc(size, GFP_NOFS);
215 200
216 if (md) { 201 if (md) {
217 /* Set here in case of early free */ 202 /* Set here in case of early free */
@@ -223,52 +208,6 @@ lnet_md_alloc(struct lnet_md *umd)
223 return md; 208 return md;
224} 209}
225 210
226static inline void
227lnet_md_free(struct lnet_libmd *md)
228{
229 unsigned int size;
230
231 if (md->md_options & LNET_MD_KIOV)
232 size = offsetof(struct lnet_libmd, md_iov.kiov[md->md_niov]);
233 else
234 size = offsetof(struct lnet_libmd, md_iov.iov[md->md_niov]);
235
236 LIBCFS_FREE(md, size);
237}
238
239static inline struct lnet_me *
240lnet_me_alloc(void)
241{
242 struct lnet_me *me;
243
244 LIBCFS_ALLOC(me, sizeof(*me));
245 return me;
246}
247
248static inline void
249lnet_me_free(struct lnet_me *me)
250{
251 LIBCFS_FREE(me, sizeof(*me));
252}
253
254static inline struct lnet_msg *
255lnet_msg_alloc(void)
256{
257 struct lnet_msg *msg;
258
259 LIBCFS_ALLOC(msg, sizeof(*msg));
260
261 /* no need to zero, LIBCFS_ALLOC does for us */
262 return msg;
263}
264
265static inline void
266lnet_msg_free(struct lnet_msg *msg)
267{
268 LASSERT(!msg->msg_onactivelist);
269 LIBCFS_FREE(msg, sizeof(*msg));
270}
271
272struct lnet_libhandle *lnet_res_lh_lookup(struct lnet_res_container *rec, 211struct lnet_libhandle *lnet_res_lh_lookup(struct lnet_res_container *rec,
273 __u64 cookie); 212 __u64 cookie);
274void lnet_res_lh_initialize(struct lnet_res_container *rec, 213void lnet_res_lh_initialize(struct lnet_res_container *rec,
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
index 8024843521ab..ec84edfda271 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
@@ -325,7 +325,7 @@ int kiblnd_create_peer(struct lnet_ni *ni, struct kib_peer **peerp,
325 LASSERT(net); 325 LASSERT(net);
326 LASSERT(nid != LNET_NID_ANY); 326 LASSERT(nid != LNET_NID_ANY);
327 327
328 LIBCFS_CPT_ALLOC(peer, lnet_cpt_table(), cpt, sizeof(*peer)); 328 peer = kzalloc_cpt(sizeof(*peer), GFP_NOFS, cpt);
329 if (!peer) { 329 if (!peer) {
330 CERROR("Cannot allocate peer\n"); 330 CERROR("Cannot allocate peer\n");
331 return -ENOMEM; 331 return -ENOMEM;
@@ -367,7 +367,7 @@ void kiblnd_destroy_peer(struct kib_peer *peer)
367 LASSERT(kiblnd_peer_idle(peer)); 367 LASSERT(kiblnd_peer_idle(peer));
368 LASSERT(list_empty(&peer->ibp_tx_queue)); 368 LASSERT(list_empty(&peer->ibp_tx_queue));
369 369
370 LIBCFS_FREE(peer, sizeof(*peer)); 370 kfree(peer);
371 371
372 /* 372 /*
373 * NB a peer's connections keep a reference on their peer until 373 * NB a peer's connections keep a reference on their peer until
@@ -596,7 +596,7 @@ static void kiblnd_setup_mtu_locked(struct rdma_cm_id *cmid)
596 596
597static int kiblnd_get_completion_vector(struct kib_conn *conn, int cpt) 597static int kiblnd_get_completion_vector(struct kib_conn *conn, int cpt)
598{ 598{
599 cpumask_t *mask; 599 cpumask_var_t *mask;
600 int vectors; 600 int vectors;
601 int off; 601 int off;
602 int i; 602 int i;
@@ -611,8 +611,8 @@ static int kiblnd_get_completion_vector(struct kib_conn *conn, int cpt)
611 return 0; 611 return 0;
612 612
613 /* hash NID to CPU id in this partition... */ 613 /* hash NID to CPU id in this partition... */
614 off = do_div(nid, cpumask_weight(mask)); 614 off = do_div(nid, cpumask_weight(*mask));
615 for_each_cpu(i, mask) { 615 for_each_cpu(i, *mask) {
616 if (!off--) 616 if (!off--)
617 return i % vectors; 617 return i % vectors;
618 } 618 }
@@ -656,15 +656,14 @@ struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cm
656 656
657 LASSERT(sched->ibs_nthreads > 0); 657 LASSERT(sched->ibs_nthreads > 0);
658 658
659 LIBCFS_CPT_ALLOC(init_qp_attr, lnet_cpt_table(), cpt, 659 init_qp_attr = kzalloc_cpt(sizeof(*init_qp_attr), GFP_NOFS, cpt);
660 sizeof(*init_qp_attr));
661 if (!init_qp_attr) { 660 if (!init_qp_attr) {
662 CERROR("Can't allocate qp_attr for %s\n", 661 CERROR("Can't allocate qp_attr for %s\n",
663 libcfs_nid2str(peer->ibp_nid)); 662 libcfs_nid2str(peer->ibp_nid));
664 goto failed_0; 663 goto failed_0;
665 } 664 }
666 665
667 LIBCFS_CPT_ALLOC(conn, lnet_cpt_table(), cpt, sizeof(*conn)); 666 conn = kzalloc_cpt(sizeof(*conn), GFP_NOFS, cpt);
668 if (!conn) { 667 if (!conn) {
669 CERROR("Can't allocate connection for %s\n", 668 CERROR("Can't allocate connection for %s\n",
670 libcfs_nid2str(peer->ibp_nid)); 669 libcfs_nid2str(peer->ibp_nid));
@@ -687,8 +686,7 @@ struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cm
687 INIT_LIST_HEAD(&conn->ibc_active_txs); 686 INIT_LIST_HEAD(&conn->ibc_active_txs);
688 spin_lock_init(&conn->ibc_lock); 687 spin_lock_init(&conn->ibc_lock);
689 688
690 LIBCFS_CPT_ALLOC(conn->ibc_connvars, lnet_cpt_table(), cpt, 689 conn->ibc_connvars = kzalloc_cpt(sizeof(*conn->ibc_connvars), GFP_NOFS, cpt);
691 sizeof(*conn->ibc_connvars));
692 if (!conn->ibc_connvars) { 690 if (!conn->ibc_connvars) {
693 CERROR("Can't allocate in-progress connection state\n"); 691 CERROR("Can't allocate in-progress connection state\n");
694 goto failed_2; 692 goto failed_2;
@@ -722,8 +720,8 @@ struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cm
722 720
723 write_unlock_irqrestore(glock, flags); 721 write_unlock_irqrestore(glock, flags);
724 722
725 LIBCFS_CPT_ALLOC(conn->ibc_rxs, lnet_cpt_table(), cpt, 723 conn->ibc_rxs = kzalloc_cpt(IBLND_RX_MSGS(conn) * sizeof(struct kib_rx),
726 IBLND_RX_MSGS(conn) * sizeof(struct kib_rx)); 724 GFP_NOFS, cpt);
727 if (!conn->ibc_rxs) { 725 if (!conn->ibc_rxs) {
728 CERROR("Cannot allocate RX buffers\n"); 726 CERROR("Cannot allocate RX buffers\n");
729 goto failed_2; 727 goto failed_2;
@@ -776,7 +774,7 @@ struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cm
776 goto failed_2; 774 goto failed_2;
777 } 775 }
778 776
779 LIBCFS_FREE(init_qp_attr, sizeof(*init_qp_attr)); 777 kfree(init_qp_attr);
780 778
781 /* 1 ref for caller and each rxmsg */ 779 /* 1 ref for caller and each rxmsg */
782 atomic_set(&conn->ibc_refcount, 1 + IBLND_RX_MSGS(conn)); 780 atomic_set(&conn->ibc_refcount, 1 + IBLND_RX_MSGS(conn));
@@ -826,14 +824,15 @@ struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cm
826 return conn; 824 return conn;
827 825
828 failed_2: 826 failed_2:
829 kiblnd_destroy_conn(conn, true); 827 kiblnd_destroy_conn(conn);
828 kfree(conn);
830 failed_1: 829 failed_1:
831 LIBCFS_FREE(init_qp_attr, sizeof(*init_qp_attr)); 830 kfree(init_qp_attr);
832 failed_0: 831 failed_0:
833 return NULL; 832 return NULL;
834} 833}
835 834
836void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) 835void kiblnd_destroy_conn(struct kib_conn *conn)
837{ 836{
838 struct rdma_cm_id *cmid = conn->ibc_cmid; 837 struct rdma_cm_id *cmid = conn->ibc_cmid;
839 struct kib_peer *peer = conn->ibc_peer; 838 struct kib_peer *peer = conn->ibc_peer;
@@ -877,13 +876,8 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn)
877 if (conn->ibc_rx_pages) 876 if (conn->ibc_rx_pages)
878 kiblnd_unmap_rx_descs(conn); 877 kiblnd_unmap_rx_descs(conn);
879 878
880 if (conn->ibc_rxs) { 879 kfree(conn->ibc_rxs);
881 LIBCFS_FREE(conn->ibc_rxs, 880 kfree(conn->ibc_connvars);
882 IBLND_RX_MSGS(conn) * sizeof(struct kib_rx));
883 }
884
885 if (conn->ibc_connvars)
886 LIBCFS_FREE(conn->ibc_connvars, sizeof(*conn->ibc_connvars));
887 881
888 if (conn->ibc_hdev) 882 if (conn->ibc_hdev)
889 kiblnd_hdev_decref(conn->ibc_hdev); 883 kiblnd_hdev_decref(conn->ibc_hdev);
@@ -896,8 +890,6 @@ void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn)
896 rdma_destroy_id(cmid); 890 rdma_destroy_id(cmid);
897 atomic_dec(&net->ibn_nconns); 891 atomic_dec(&net->ibn_nconns);
898 } 892 }
899
900 LIBCFS_FREE(conn, sizeof(*conn));
901} 893}
902 894
903int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why) 895int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why)
@@ -1089,7 +1081,7 @@ static void kiblnd_free_pages(struct kib_pages *p)
1089 __free_page(p->ibp_pages[i]); 1081 __free_page(p->ibp_pages[i]);
1090 } 1082 }
1091 1083
1092 LIBCFS_FREE(p, offsetof(struct kib_pages, ibp_pages[npages])); 1084 kfree(p);
1093} 1085}
1094 1086
1095int kiblnd_alloc_pages(struct kib_pages **pp, int cpt, int npages) 1087int kiblnd_alloc_pages(struct kib_pages **pp, int cpt, int npages)
@@ -1097,14 +1089,13 @@ int kiblnd_alloc_pages(struct kib_pages **pp, int cpt, int npages)
1097 struct kib_pages *p; 1089 struct kib_pages *p;
1098 int i; 1090 int i;
1099 1091
1100 LIBCFS_CPT_ALLOC(p, lnet_cpt_table(), cpt, 1092 p = kzalloc_cpt(offsetof(struct kib_pages, ibp_pages[npages]),
1101 offsetof(struct kib_pages, ibp_pages[npages])); 1093 GFP_NOFS, cpt);
1102 if (!p) { 1094 if (!p) {
1103 CERROR("Can't allocate descriptor for %d pages\n", npages); 1095 CERROR("Can't allocate descriptor for %d pages\n", npages);
1104 return -ENOMEM; 1096 return -ENOMEM;
1105 } 1097 }
1106 1098
1107 memset(p, 0, offsetof(struct kib_pages, ibp_pages[npages]));
1108 p->ibp_npages = npages; 1099 p->ibp_npages = npages;
1109 1100
1110 for (i = 0; i < npages; i++) { 1101 for (i = 0; i < npages; i++) {
@@ -1299,7 +1290,7 @@ static void kiblnd_destroy_fmr_pool(struct kib_fmr_pool *fpo)
1299 frd_list) { 1290 frd_list) {
1300 list_del(&frd->frd_list); 1291 list_del(&frd->frd_list);
1301 ib_dereg_mr(frd->frd_mr); 1292 ib_dereg_mr(frd->frd_mr);
1302 LIBCFS_FREE(frd, sizeof(*frd)); 1293 kfree(frd);
1303 i++; 1294 i++;
1304 } 1295 }
1305 if (i < fpo->fast_reg.fpo_pool_size) 1296 if (i < fpo->fast_reg.fpo_pool_size)
@@ -1310,7 +1301,7 @@ static void kiblnd_destroy_fmr_pool(struct kib_fmr_pool *fpo)
1310 if (fpo->fpo_hdev) 1301 if (fpo->fpo_hdev)
1311 kiblnd_hdev_decref(fpo->fpo_hdev); 1302 kiblnd_hdev_decref(fpo->fpo_hdev);
1312 1303
1313 LIBCFS_FREE(fpo, sizeof(*fpo)); 1304 kfree(fpo);
1314} 1305}
1315 1306
1316static void kiblnd_destroy_fmr_pool_list(struct list_head *head) 1307static void kiblnd_destroy_fmr_pool_list(struct list_head *head)
@@ -1376,8 +1367,7 @@ static int kiblnd_alloc_freg_pool(struct kib_fmr_poolset *fps, struct kib_fmr_po
1376 INIT_LIST_HEAD(&fpo->fast_reg.fpo_pool_list); 1367 INIT_LIST_HEAD(&fpo->fast_reg.fpo_pool_list);
1377 fpo->fast_reg.fpo_pool_size = 0; 1368 fpo->fast_reg.fpo_pool_size = 0;
1378 for (i = 0; i < fps->fps_pool_size; i++) { 1369 for (i = 0; i < fps->fps_pool_size; i++) {
1379 LIBCFS_CPT_ALLOC(frd, lnet_cpt_table(), fps->fps_cpt, 1370 frd = kzalloc_cpt(sizeof(*frd), GFP_NOFS, fps->fps_cpt);
1380 sizeof(*frd));
1381 if (!frd) { 1371 if (!frd) {
1382 CERROR("Failed to allocate a new fast_reg descriptor\n"); 1372 CERROR("Failed to allocate a new fast_reg descriptor\n");
1383 rc = -ENOMEM; 1373 rc = -ENOMEM;
@@ -1405,14 +1395,14 @@ static int kiblnd_alloc_freg_pool(struct kib_fmr_poolset *fps, struct kib_fmr_po
1405out_middle: 1395out_middle:
1406 if (frd->frd_mr) 1396 if (frd->frd_mr)
1407 ib_dereg_mr(frd->frd_mr); 1397 ib_dereg_mr(frd->frd_mr);
1408 LIBCFS_FREE(frd, sizeof(*frd)); 1398 kfree(frd);
1409 1399
1410out: 1400out:
1411 list_for_each_entry_safe(frd, tmp, &fpo->fast_reg.fpo_pool_list, 1401 list_for_each_entry_safe(frd, tmp, &fpo->fast_reg.fpo_pool_list,
1412 frd_list) { 1402 frd_list) {
1413 list_del(&frd->frd_list); 1403 list_del(&frd->frd_list);
1414 ib_dereg_mr(frd->frd_mr); 1404 ib_dereg_mr(frd->frd_mr);
1415 LIBCFS_FREE(frd, sizeof(*frd)); 1405 kfree(frd);
1416 } 1406 }
1417 1407
1418 return rc; 1408 return rc;
@@ -1426,7 +1416,7 @@ static int kiblnd_create_fmr_pool(struct kib_fmr_poolset *fps,
1426 struct kib_fmr_pool *fpo; 1416 struct kib_fmr_pool *fpo;
1427 int rc; 1417 int rc;
1428 1418
1429 LIBCFS_CPT_ALLOC(fpo, lnet_cpt_table(), fps->fps_cpt, sizeof(*fpo)); 1419 fpo = kzalloc_cpt(sizeof(*fpo), GFP_NOFS, fps->fps_cpt);
1430 if (!fpo) 1420 if (!fpo)
1431 return -ENOMEM; 1421 return -ENOMEM;
1432 1422
@@ -1464,7 +1454,7 @@ static int kiblnd_create_fmr_pool(struct kib_fmr_poolset *fps,
1464 1454
1465out_fpo: 1455out_fpo:
1466 kiblnd_hdev_decref(fpo->fpo_hdev); 1456 kiblnd_hdev_decref(fpo->fpo_hdev);
1467 LIBCFS_FREE(fpo, sizeof(*fpo)); 1457 kfree(fpo);
1468 return rc; 1458 return rc;
1469} 1459}
1470 1460
@@ -1985,33 +1975,17 @@ static void kiblnd_destroy_tx_pool(struct kib_pool *pool)
1985 struct kib_tx *tx = &tpo->tpo_tx_descs[i]; 1975 struct kib_tx *tx = &tpo->tpo_tx_descs[i];
1986 1976
1987 list_del(&tx->tx_list); 1977 list_del(&tx->tx_list);
1988 if (tx->tx_pages) 1978 kfree(tx->tx_pages);
1989 LIBCFS_FREE(tx->tx_pages, 1979 kfree(tx->tx_frags);
1990 LNET_MAX_IOV * 1980 kfree(tx->tx_wrq);
1991 sizeof(*tx->tx_pages)); 1981 kfree(tx->tx_sge);
1992 if (tx->tx_frags) 1982 kfree(tx->tx_rd);
1993 LIBCFS_FREE(tx->tx_frags, 1983 }
1994 (1 + IBLND_MAX_RDMA_FRAGS) * 1984
1995 sizeof(*tx->tx_frags)); 1985 kfree(tpo->tpo_tx_descs);
1996 if (tx->tx_wrq)
1997 LIBCFS_FREE(tx->tx_wrq,
1998 (1 + IBLND_MAX_RDMA_FRAGS) *
1999 sizeof(*tx->tx_wrq));
2000 if (tx->tx_sge)
2001 LIBCFS_FREE(tx->tx_sge,
2002 (1 + IBLND_MAX_RDMA_FRAGS) *
2003 sizeof(*tx->tx_sge));
2004 if (tx->tx_rd)
2005 LIBCFS_FREE(tx->tx_rd,
2006 offsetof(struct kib_rdma_desc,
2007 rd_frags[IBLND_MAX_RDMA_FRAGS]));
2008 }
2009
2010 LIBCFS_FREE(tpo->tpo_tx_descs,
2011 pool->po_size * sizeof(struct kib_tx));
2012out: 1986out:
2013 kiblnd_fini_pool(pool); 1987 kiblnd_fini_pool(pool);
2014 LIBCFS_FREE(tpo, sizeof(*tpo)); 1988 kfree(tpo);
2015} 1989}
2016 1990
2017static int kiblnd_tx_pool_size(int ncpts) 1991static int kiblnd_tx_pool_size(int ncpts)
@@ -2029,7 +2003,7 @@ static int kiblnd_create_tx_pool(struct kib_poolset *ps, int size,
2029 struct kib_pool *pool; 2003 struct kib_pool *pool;
2030 struct kib_tx_pool *tpo; 2004 struct kib_tx_pool *tpo;
2031 2005
2032 LIBCFS_CPT_ALLOC(tpo, lnet_cpt_table(), ps->ps_cpt, sizeof(*tpo)); 2006 tpo = kzalloc_cpt(sizeof(*tpo), GFP_NOFS, ps->ps_cpt);
2033 if (!tpo) { 2007 if (!tpo) {
2034 CERROR("Failed to allocate TX pool\n"); 2008 CERROR("Failed to allocate TX pool\n");
2035 return -ENOMEM; 2009 return -ENOMEM;
@@ -2043,12 +2017,12 @@ static int kiblnd_create_tx_pool(struct kib_poolset *ps, int size,
2043 npg = DIV_ROUND_UP(size * IBLND_MSG_SIZE, PAGE_SIZE); 2017 npg = DIV_ROUND_UP(size * IBLND_MSG_SIZE, PAGE_SIZE);
2044 if (kiblnd_alloc_pages(&tpo->tpo_tx_pages, ps->ps_cpt, npg)) { 2018 if (kiblnd_alloc_pages(&tpo->tpo_tx_pages, ps->ps_cpt, npg)) {
2045 CERROR("Can't allocate tx pages: %d\n", npg); 2019 CERROR("Can't allocate tx pages: %d\n", npg);
2046 LIBCFS_FREE(tpo, sizeof(*tpo)); 2020 kfree(tpo);
2047 return -ENOMEM; 2021 return -ENOMEM;
2048 } 2022 }
2049 2023
2050 LIBCFS_CPT_ALLOC(tpo->tpo_tx_descs, lnet_cpt_table(), ps->ps_cpt, 2024 tpo->tpo_tx_descs = kzalloc_cpt(size * sizeof(struct kib_tx),
2051 size * sizeof(struct kib_tx)); 2025 GFP_NOFS, ps->ps_cpt);
2052 if (!tpo->tpo_tx_descs) { 2026 if (!tpo->tpo_tx_descs) {
2053 CERROR("Can't allocate %d tx descriptors\n", size); 2027 CERROR("Can't allocate %d tx descriptors\n", size);
2054 ps->ps_pool_destroy(pool); 2028 ps->ps_pool_destroy(pool);
@@ -2062,36 +2036,35 @@ static int kiblnd_create_tx_pool(struct kib_poolset *ps, int size,
2062 2036
2063 tx->tx_pool = tpo; 2037 tx->tx_pool = tpo;
2064 if (ps->ps_net->ibn_fmr_ps) { 2038 if (ps->ps_net->ibn_fmr_ps) {
2065 LIBCFS_CPT_ALLOC(tx->tx_pages, 2039 tx->tx_pages = kzalloc_cpt(LNET_MAX_IOV * sizeof(*tx->tx_pages),
2066 lnet_cpt_table(), ps->ps_cpt, 2040 GFP_NOFS, ps->ps_cpt);
2067 LNET_MAX_IOV * sizeof(*tx->tx_pages));
2068 if (!tx->tx_pages) 2041 if (!tx->tx_pages)
2069 break; 2042 break;
2070 } 2043 }
2071 2044
2072 LIBCFS_CPT_ALLOC(tx->tx_frags, lnet_cpt_table(), ps->ps_cpt, 2045 tx->tx_frags = kzalloc_cpt((1 + IBLND_MAX_RDMA_FRAGS) *
2073 (1 + IBLND_MAX_RDMA_FRAGS) * 2046 sizeof(*tx->tx_frags),
2074 sizeof(*tx->tx_frags)); 2047 GFP_NOFS, ps->ps_cpt);
2075 if (!tx->tx_frags) 2048 if (!tx->tx_frags)
2076 break; 2049 break;
2077 2050
2078 sg_init_table(tx->tx_frags, IBLND_MAX_RDMA_FRAGS + 1); 2051 sg_init_table(tx->tx_frags, IBLND_MAX_RDMA_FRAGS + 1);
2079 2052
2080 LIBCFS_CPT_ALLOC(tx->tx_wrq, lnet_cpt_table(), ps->ps_cpt, 2053 tx->tx_wrq = kzalloc_cpt((1 + IBLND_MAX_RDMA_FRAGS) *
2081 (1 + IBLND_MAX_RDMA_FRAGS) * 2054 sizeof(*tx->tx_wrq),
2082 sizeof(*tx->tx_wrq)); 2055 GFP_NOFS, ps->ps_cpt);
2083 if (!tx->tx_wrq) 2056 if (!tx->tx_wrq)
2084 break; 2057 break;
2085 2058
2086 LIBCFS_CPT_ALLOC(tx->tx_sge, lnet_cpt_table(), ps->ps_cpt, 2059 tx->tx_sge = kzalloc_cpt((1 + IBLND_MAX_RDMA_FRAGS) *
2087 (1 + IBLND_MAX_RDMA_FRAGS) * 2060 sizeof(*tx->tx_sge),
2088 sizeof(*tx->tx_sge)); 2061 GFP_NOFS, ps->ps_cpt);
2089 if (!tx->tx_sge) 2062 if (!tx->tx_sge)
2090 break; 2063 break;
2091 2064
2092 LIBCFS_CPT_ALLOC(tx->tx_rd, lnet_cpt_table(), ps->ps_cpt, 2065 tx->tx_rd = kzalloc_cpt(offsetof(struct kib_rdma_desc,
2093 offsetof(struct kib_rdma_desc, 2066 rd_frags[IBLND_MAX_RDMA_FRAGS]),
2094 rd_frags[IBLND_MAX_RDMA_FRAGS])); 2067 GFP_NOFS, ps->ps_cpt);
2095 if (!tx->tx_rd) 2068 if (!tx->tx_rd)
2096 break; 2069 break;
2097 } 2070 }
@@ -2263,7 +2236,7 @@ void kiblnd_hdev_destroy(struct kib_hca_dev *hdev)
2263 if (hdev->ibh_cmid) 2236 if (hdev->ibh_cmid)
2264 rdma_destroy_id(hdev->ibh_cmid); 2237 rdma_destroy_id(hdev->ibh_cmid);
2265 2238
2266 LIBCFS_FREE(hdev, sizeof(*hdev)); 2239 kfree(hdev);
2267} 2240}
2268 2241
2269/* DUMMY */ 2242/* DUMMY */
@@ -2392,7 +2365,7 @@ int kiblnd_dev_failover(struct kib_dev *dev)
2392 goto out; 2365 goto out;
2393 } 2366 }
2394 2367
2395 LIBCFS_ALLOC(hdev, sizeof(*hdev)); 2368 hdev = kzalloc(sizeof(*hdev), GFP_NOFS);
2396 if (!hdev) { 2369 if (!hdev) {
2397 CERROR("Failed to allocate kib_hca_dev\n"); 2370 CERROR("Failed to allocate kib_hca_dev\n");
2398 rdma_destroy_id(cmid); 2371 rdma_destroy_id(cmid);
@@ -2471,7 +2444,7 @@ void kiblnd_destroy_dev(struct kib_dev *dev)
2471 if (dev->ibd_hdev) 2444 if (dev->ibd_hdev)
2472 kiblnd_hdev_decref(dev->ibd_hdev); 2445 kiblnd_hdev_decref(dev->ibd_hdev);
2473 2446
2474 LIBCFS_FREE(dev, sizeof(*dev)); 2447 kfree(dev);
2475} 2448}
2476 2449
2477static struct kib_dev *kiblnd_create_dev(char *ifname) 2450static struct kib_dev *kiblnd_create_dev(char *ifname)
@@ -2495,7 +2468,7 @@ static struct kib_dev *kiblnd_create_dev(char *ifname)
2495 return NULL; 2468 return NULL;
2496 } 2469 }
2497 2470
2498 LIBCFS_ALLOC(dev, sizeof(*dev)); 2471 dev = kzalloc(sizeof(*dev), GFP_NOFS);
2499 if (!dev) 2472 if (!dev)
2500 return NULL; 2473 return NULL;
2501 2474
@@ -2517,7 +2490,7 @@ static struct kib_dev *kiblnd_create_dev(char *ifname)
2517 rc = kiblnd_dev_failover(dev); 2490 rc = kiblnd_dev_failover(dev);
2518 if (rc) { 2491 if (rc) {
2519 CERROR("Can't initialize device: %d\n", rc); 2492 CERROR("Can't initialize device: %d\n", rc);
2520 LIBCFS_FREE(dev, sizeof(*dev)); 2493 kfree(dev);
2521 return NULL; 2494 return NULL;
2522 } 2495 }
2523 2496
@@ -2577,11 +2550,7 @@ static void kiblnd_base_shutdown(void)
2577 break; 2550 break;
2578 } 2551 }
2579 2552
2580 if (kiblnd_data.kib_peers) { 2553 kvfree(kiblnd_data.kib_peers);
2581 LIBCFS_FREE(kiblnd_data.kib_peers,
2582 sizeof(struct list_head) *
2583 kiblnd_data.kib_peer_hash_size);
2584 }
2585 2554
2586 if (kiblnd_data.kib_scheds) 2555 if (kiblnd_data.kib_scheds)
2587 cfs_percpt_free(kiblnd_data.kib_scheds); 2556 cfs_percpt_free(kiblnd_data.kib_scheds);
@@ -2648,7 +2617,7 @@ static void kiblnd_shutdown(struct lnet_ni *ni)
2648 net->ibn_init = IBLND_INIT_NOTHING; 2617 net->ibn_init = IBLND_INIT_NOTHING;
2649 ni->ni_data = NULL; 2618 ni->ni_data = NULL;
2650 2619
2651 LIBCFS_FREE(net, sizeof(*net)); 2620 kfree(net);
2652 2621
2653out: 2622out:
2654 if (list_empty(&kiblnd_data.kib_devs)) 2623 if (list_empty(&kiblnd_data.kib_devs))
@@ -2673,8 +2642,9 @@ static int kiblnd_base_startup(void)
2673 INIT_LIST_HEAD(&kiblnd_data.kib_failed_devs); 2642 INIT_LIST_HEAD(&kiblnd_data.kib_failed_devs);
2674 2643
2675 kiblnd_data.kib_peer_hash_size = IBLND_PEER_HASH_SIZE; 2644 kiblnd_data.kib_peer_hash_size = IBLND_PEER_HASH_SIZE;
2676 LIBCFS_ALLOC(kiblnd_data.kib_peers, 2645 kiblnd_data.kib_peers = kvmalloc_array(kiblnd_data.kib_peer_hash_size,
2677 sizeof(struct list_head) * kiblnd_data.kib_peer_hash_size); 2646 sizeof(struct list_head),
2647 GFP_KERNEL);
2678 if (!kiblnd_data.kib_peers) 2648 if (!kiblnd_data.kib_peers)
2679 goto failed; 2649 goto failed;
2680 for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) 2650 for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++)
@@ -2865,7 +2835,7 @@ static int kiblnd_startup(struct lnet_ni *ni)
2865 return rc; 2835 return rc;
2866 } 2836 }
2867 2837
2868 LIBCFS_ALLOC(net, sizeof(*net)); 2838 net = kzalloc(sizeof(*net), GFP_NOFS);
2869 ni->ni_data = net; 2839 ni->ni_data = net;
2870 if (!net) 2840 if (!net)
2871 goto net_failed; 2841 goto net_failed;
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
index 171eced213f8..b18911d09e9a 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
@@ -1016,7 +1016,7 @@ int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why);
1016struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, 1016struct kib_conn *kiblnd_create_conn(struct kib_peer *peer,
1017 struct rdma_cm_id *cmid, 1017 struct rdma_cm_id *cmid,
1018 int state, int version); 1018 int state, int version);
1019void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn); 1019void kiblnd_destroy_conn(struct kib_conn *conn);
1020void kiblnd_close_conn(struct kib_conn *conn, int error); 1020void kiblnd_close_conn(struct kib_conn *conn, int error);
1021void kiblnd_close_conn_locked(struct kib_conn *conn, int error); 1021void kiblnd_close_conn_locked(struct kib_conn *conn, int error);
1022 1022
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
index 40e3af5d8b04..b3e7f28eb978 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
@@ -2124,7 +2124,7 @@ kiblnd_connreq_done(struct kib_conn *conn, int status)
2124 (conn->ibc_state == IBLND_CONN_PASSIVE_WAIT && 2124 (conn->ibc_state == IBLND_CONN_PASSIVE_WAIT &&
2125 peer->ibp_accepting > 0)); 2125 peer->ibp_accepting > 0));
2126 2126
2127 LIBCFS_FREE(conn->ibc_connvars, sizeof(*conn->ibc_connvars)); 2127 kfree(conn->ibc_connvars);
2128 conn->ibc_connvars = NULL; 2128 conn->ibc_connvars = NULL;
2129 2129
2130 if (status) { 2130 if (status) {
@@ -3314,11 +3314,13 @@ kiblnd_connd(void *arg)
3314 spin_unlock_irqrestore(lock, flags); 3314 spin_unlock_irqrestore(lock, flags);
3315 dropped_lock = 1; 3315 dropped_lock = 1;
3316 3316
3317 kiblnd_destroy_conn(conn, !peer); 3317 kiblnd_destroy_conn(conn);
3318 3318
3319 spin_lock_irqsave(lock, flags); 3319 spin_lock_irqsave(lock, flags);
3320 if (!peer) 3320 if (!peer) {
3321 kfree(conn);
3321 continue; 3322 continue;
3323 }
3322 3324
3323 conn->ibc_peer = peer; 3325 conn->ibc_peer = peer;
3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) 3326 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE)
@@ -3363,7 +3365,7 @@ kiblnd_connd(void *arg)
3363 3365
3364 reconn += kiblnd_reconnect_peer(conn->ibc_peer); 3366 reconn += kiblnd_reconnect_peer(conn->ibc_peer);
3365 kiblnd_peer_decref(conn->ibc_peer); 3367 kiblnd_peer_decref(conn->ibc_peer);
3366 LIBCFS_FREE(conn, sizeof(*conn)); 3368 kfree(conn);
3367 3369
3368 spin_lock_irqsave(lock, flags); 3370 spin_lock_irqsave(lock, flags);
3369 } 3371 }
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
index a71b765215ad..b9235400bf1d 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
@@ -181,8 +181,8 @@ int kiblnd_tunables_setup(struct lnet_ni *ni)
181 * defaulted 181 * defaulted
182 */ 182 */
183 if (!ni->ni_lnd_tunables) { 183 if (!ni->ni_lnd_tunables) {
184 LIBCFS_ALLOC(ni->ni_lnd_tunables, 184 ni->ni_lnd_tunables = kzalloc(sizeof(*ni->ni_lnd_tunables),
185 sizeof(*ni->ni_lnd_tunables)); 185 GFP_NOFS);
186 if (!ni->ni_lnd_tunables) 186 if (!ni->ni_lnd_tunables)
187 return -ENOMEM; 187 return -ENOMEM;
188 188
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
index 8267119ccc8e..ff292216290d 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
@@ -66,7 +66,7 @@ ksocknal_create_route(__u32 ipaddr, int port)
66{ 66{
67 struct ksock_route *route; 67 struct ksock_route *route;
68 68
69 LIBCFS_ALLOC(route, sizeof(*route)); 69 route = kzalloc(sizeof(*route), GFP_NOFS);
70 if (!route) 70 if (!route)
71 return NULL; 71 return NULL;
72 72
@@ -93,7 +93,7 @@ ksocknal_destroy_route(struct ksock_route *route)
93 if (route->ksnr_peer) 93 if (route->ksnr_peer)
94 ksocknal_peer_decref(route->ksnr_peer); 94 ksocknal_peer_decref(route->ksnr_peer);
95 95
96 LIBCFS_FREE(route, sizeof(*route)); 96 kfree(route);
97} 97}
98 98
99static int 99static int
@@ -108,7 +108,7 @@ ksocknal_create_peer(struct ksock_peer **peerp, struct lnet_ni *ni,
108 LASSERT(id.pid != LNET_PID_ANY); 108 LASSERT(id.pid != LNET_PID_ANY);
109 LASSERT(!in_interrupt()); 109 LASSERT(!in_interrupt());
110 110
111 LIBCFS_CPT_ALLOC(peer, lnet_cpt_table(), cpt, sizeof(*peer)); 111 peer = kzalloc_cpt(sizeof(*peer), GFP_NOFS, cpt);
112 if (!peer) 112 if (!peer)
113 return -ENOMEM; 113 return -ENOMEM;
114 114
@@ -132,7 +132,7 @@ ksocknal_create_peer(struct ksock_peer **peerp, struct lnet_ni *ni,
132 if (net->ksnn_shutdown) { 132 if (net->ksnn_shutdown) {
133 spin_unlock_bh(&net->ksnn_lock); 133 spin_unlock_bh(&net->ksnn_lock);
134 134
135 LIBCFS_FREE(peer, sizeof(*peer)); 135 kfree(peer);
136 CERROR("Can't create peer: network shutdown\n"); 136 CERROR("Can't create peer: network shutdown\n");
137 return -ESHUTDOWN; 137 return -ESHUTDOWN;
138 } 138 }
@@ -160,7 +160,7 @@ ksocknal_destroy_peer(struct ksock_peer *peer)
160 LASSERT(list_empty(&peer->ksnp_tx_queue)); 160 LASSERT(list_empty(&peer->ksnp_tx_queue));
161 LASSERT(list_empty(&peer->ksnp_zc_req_list)); 161 LASSERT(list_empty(&peer->ksnp_zc_req_list));
162 162
163 LIBCFS_FREE(peer, sizeof(*peer)); 163 kfree(peer);
164 164
165 /* 165 /*
166 * NB a peer's connections and routes keep a reference on their peer 166 * NB a peer's connections and routes keep a reference on their peer
@@ -985,7 +985,7 @@ ksocknal_accept(struct lnet_ni *ni, struct socket *sock)
985 rc = lnet_sock_getaddr(sock, 1, &peer_ip, &peer_port); 985 rc = lnet_sock_getaddr(sock, 1, &peer_ip, &peer_port);
986 LASSERT(!rc); /* we succeeded before */ 986 LASSERT(!rc); /* we succeeded before */
987 987
988 LIBCFS_ALLOC(cr, sizeof(*cr)); 988 cr = kzalloc(sizeof(*cr), GFP_NOFS);
989 if (!cr) { 989 if (!cr) {
990 LCONSOLE_ERROR_MSG(0x12f, "Dropping connection request from %pI4h: memory exhausted\n", 990 LCONSOLE_ERROR_MSG(0x12f, "Dropping connection request from %pI4h: memory exhausted\n",
991 &peer_ip); 991 &peer_ip);
@@ -1043,7 +1043,7 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route,
1043 1043
1044 LASSERT(active == (type != SOCKLND_CONN_NONE)); 1044 LASSERT(active == (type != SOCKLND_CONN_NONE));
1045 1045
1046 LIBCFS_ALLOC(conn, sizeof(*conn)); 1046 conn = kzalloc(sizeof(*conn), GFP_NOFS);
1047 if (!conn) { 1047 if (!conn) {
1048 rc = -ENOMEM; 1048 rc = -ENOMEM;
1049 goto failed_0; 1049 goto failed_0;
@@ -1070,8 +1070,9 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route,
1070 conn->ksnc_tx_carrier = NULL; 1070 conn->ksnc_tx_carrier = NULL;
1071 atomic_set(&conn->ksnc_tx_nob, 0); 1071 atomic_set(&conn->ksnc_tx_nob, 0);
1072 1072
1073 LIBCFS_ALLOC(hello, offsetof(struct ksock_hello_msg, 1073 hello = kvzalloc(offsetof(struct ksock_hello_msg,
1074 kshm_ips[LNET_MAX_INTERFACES])); 1074 kshm_ips[LNET_MAX_INTERFACES]),
1075 GFP_KERNEL);
1075 if (!hello) { 1076 if (!hello) {
1076 rc = -ENOMEM; 1077 rc = -ENOMEM;
1077 goto failed_1; 1078 goto failed_1;
@@ -1334,8 +1335,7 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route,
1334 rc = ksocknal_send_hello(ni, conn, peerid.nid, hello); 1335 rc = ksocknal_send_hello(ni, conn, peerid.nid, hello);
1335 } 1336 }
1336 1337
1337 LIBCFS_FREE(hello, offsetof(struct ksock_hello_msg, 1338 kvfree(hello);
1338 kshm_ips[LNET_MAX_INTERFACES]));
1339 1339
1340 /* 1340 /*
1341 * setup the socket AFTER I've received hello (it disables 1341 * setup the socket AFTER I've received hello (it disables
@@ -1415,11 +1415,9 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route,
1415 ksocknal_peer_decref(peer); 1415 ksocknal_peer_decref(peer);
1416 1416
1417failed_1: 1417failed_1:
1418 if (hello) 1418 kvfree(hello);
1419 LIBCFS_FREE(hello, offsetof(struct ksock_hello_msg,
1420 kshm_ips[LNET_MAX_INTERFACES]));
1421 1419
1422 LIBCFS_FREE(conn, sizeof(*conn)); 1420 kfree(conn);
1423 1421
1424failed_0: 1422failed_0:
1425 sock_release(sock); 1423 sock_release(sock);
@@ -1716,7 +1714,7 @@ ksocknal_destroy_conn(struct ksock_conn *conn)
1716 1714
1717 ksocknal_peer_decref(conn->ksnc_peer); 1715 ksocknal_peer_decref(conn->ksnc_peer);
1718 1716
1719 LIBCFS_FREE(conn, sizeof(*conn)); 1717 kfree(conn);
1720} 1718}
1721 1719
1722int 1720int
@@ -2259,19 +2257,12 @@ ksocknal_free_buffers(void)
2259 struct ksock_sched_info *info; 2257 struct ksock_sched_info *info;
2260 int i; 2258 int i;
2261 2259
2262 cfs_percpt_for_each(info, i, ksocknal_data.ksnd_sched_info) { 2260 cfs_percpt_for_each(info, i, ksocknal_data.ksnd_sched_info)
2263 if (info->ksi_scheds) { 2261 kfree(info->ksi_scheds);
2264 LIBCFS_FREE(info->ksi_scheds,
2265 info->ksi_nthreads_max *
2266 sizeof(info->ksi_scheds[0]));
2267 }
2268 }
2269 cfs_percpt_free(ksocknal_data.ksnd_sched_info); 2262 cfs_percpt_free(ksocknal_data.ksnd_sched_info);
2270 } 2263 }
2271 2264
2272 LIBCFS_FREE(ksocknal_data.ksnd_peers, 2265 kvfree(ksocknal_data.ksnd_peers);
2273 sizeof(struct list_head) *
2274 ksocknal_data.ksnd_peer_hash_size);
2275 2266
2276 spin_lock(&ksocknal_data.ksnd_tx_lock); 2267 spin_lock(&ksocknal_data.ksnd_tx_lock);
2277 2268
@@ -2286,7 +2277,7 @@ ksocknal_free_buffers(void)
2286 2277
2287 list_for_each_entry_safe(tx, temp, &zlist, tx_list) { 2278 list_for_each_entry_safe(tx, temp, &zlist, tx_list) {
2288 list_del(&tx->tx_list); 2279 list_del(&tx->tx_list);
2289 LIBCFS_FREE(tx, tx->tx_desc_size); 2280 kfree(tx);
2290 } 2281 }
2291 } else { 2282 } else {
2292 spin_unlock(&ksocknal_data.ksnd_tx_lock); 2283 spin_unlock(&ksocknal_data.ksnd_tx_lock);
@@ -2401,9 +2392,9 @@ ksocknal_base_startup(void)
2401 memset(&ksocknal_data, 0, sizeof(ksocknal_data)); /* zero pointers */ 2392 memset(&ksocknal_data, 0, sizeof(ksocknal_data)); /* zero pointers */
2402 2393
2403 ksocknal_data.ksnd_peer_hash_size = SOCKNAL_PEER_HASH_SIZE; 2394 ksocknal_data.ksnd_peer_hash_size = SOCKNAL_PEER_HASH_SIZE;
2404 LIBCFS_ALLOC(ksocknal_data.ksnd_peers, 2395 ksocknal_data.ksnd_peers = kvmalloc_array(ksocknal_data.ksnd_peer_hash_size,
2405 sizeof(struct list_head) * 2396 sizeof(struct list_head),
2406 ksocknal_data.ksnd_peer_hash_size); 2397 GFP_KERNEL);
2407 if (!ksocknal_data.ksnd_peers) 2398 if (!ksocknal_data.ksnd_peers)
2408 return -ENOMEM; 2399 return -ENOMEM;
2409 2400
@@ -2456,8 +2447,8 @@ ksocknal_base_startup(void)
2456 info->ksi_nthreads_max = nthrs; 2447 info->ksi_nthreads_max = nthrs;
2457 info->ksi_cpt = i; 2448 info->ksi_cpt = i;
2458 2449
2459 LIBCFS_CPT_ALLOC(info->ksi_scheds, lnet_cpt_table(), i, 2450 info->ksi_scheds = kzalloc_cpt(info->ksi_nthreads_max * sizeof(*sched),
2460 info->ksi_nthreads_max * sizeof(*sched)); 2451 GFP_NOFS, i);
2461 if (!info->ksi_scheds) 2452 if (!info->ksi_scheds)
2462 goto failed; 2453 goto failed;
2463 2454
@@ -2622,7 +2613,7 @@ ksocknal_shutdown(struct lnet_ni *ni)
2622 } 2613 }
2623 2614
2624 list_del(&net->ksnn_list); 2615 list_del(&net->ksnn_list);
2625 LIBCFS_FREE(net, sizeof(*net)); 2616 kfree(net);
2626 2617
2627 ksocknal_data.ksnd_nnets--; 2618 ksocknal_data.ksnd_nnets--;
2628 if (!ksocknal_data.ksnd_nnets) 2619 if (!ksocknal_data.ksnd_nnets)
@@ -2815,7 +2806,7 @@ ksocknal_startup(struct lnet_ni *ni)
2815 return rc; 2806 return rc;
2816 } 2807 }
2817 2808
2818 LIBCFS_ALLOC(net, sizeof(*net)); 2809 net = kzalloc(sizeof(*net), GFP_NOFS);
2819 if (!net) 2810 if (!net)
2820 goto fail_0; 2811 goto fail_0;
2821 2812
@@ -2877,7 +2868,7 @@ ksocknal_startup(struct lnet_ni *ni)
2877 return 0; 2868 return 0;
2878 2869
2879 fail_1: 2870 fail_1:
2880 LIBCFS_FREE(net, sizeof(*net)); 2871 kfree(net);
2881 fail_0: 2872 fail_0:
2882 if (!ksocknal_data.ksnd_nnets) 2873 if (!ksocknal_data.ksnd_nnets)
2883 ksocknal_base_shutdown(); 2874 ksocknal_base_shutdown();
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
index 27c56d5ae4e5..11fd3a36424f 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
@@ -46,7 +46,7 @@ ksocknal_alloc_tx(int type, int size)
46 } 46 }
47 47
48 if (!tx) 48 if (!tx)
49 LIBCFS_ALLOC(tx, size); 49 tx = kzalloc(size, GFP_NOFS);
50 50
51 if (!tx) 51 if (!tx)
52 return NULL; 52 return NULL;
@@ -102,7 +102,7 @@ ksocknal_free_tx(struct ksock_tx *tx)
102 102
103 spin_unlock(&ksocknal_data.ksnd_tx_lock); 103 spin_unlock(&ksocknal_data.ksnd_tx_lock);
104 } else { 104 } else {
105 LIBCFS_FREE(tx, tx->tx_desc_size); 105 kfree(tx);
106 } 106 }
107} 107}
108 108
@@ -2117,7 +2117,7 @@ ksocknal_connd(void *arg)
2117 ksocknal_create_conn(cr->ksncr_ni, NULL, 2117 ksocknal_create_conn(cr->ksncr_ni, NULL,
2118 cr->ksncr_sock, SOCKLND_CONN_NONE); 2118 cr->ksncr_sock, SOCKLND_CONN_NONE);
2119 lnet_ni_decref(cr->ksncr_ni); 2119 lnet_ni_decref(cr->ksncr_ni);
2120 LIBCFS_FREE(cr, sizeof(*cr)); 2120 kfree(cr);
2121 2121
2122 spin_lock_bh(connd_lock); 2122 spin_lock_bh(connd_lock);
2123 } 2123 }
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
index d827f770e831..05982dac781c 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
@@ -467,7 +467,7 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello)
467 467
468 BUILD_BUG_ON(sizeof(struct lnet_magicversion) != offsetof(struct lnet_hdr, src_nid)); 468 BUILD_BUG_ON(sizeof(struct lnet_magicversion) != offsetof(struct lnet_hdr, src_nid));
469 469
470 LIBCFS_ALLOC(hdr, sizeof(*hdr)); 470 hdr = kzalloc(sizeof(*hdr), GFP_NOFS);
471 if (!hdr) { 471 if (!hdr) {
472 CERROR("Can't allocate struct lnet_hdr\n"); 472 CERROR("Can't allocate struct lnet_hdr\n");
473 return -ENOMEM; 473 return -ENOMEM;
@@ -526,7 +526,7 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello)
526 &conn->ksnc_ipaddr, conn->ksnc_port); 526 &conn->ksnc_ipaddr, conn->ksnc_port);
527 } 527 }
528out: 528out:
529 LIBCFS_FREE(hdr, sizeof(*hdr)); 529 kfree(hdr);
530 530
531 return rc; 531 return rc;
532} 532}
@@ -582,7 +582,7 @@ ksocknal_recv_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello,
582 int rc; 582 int rc;
583 int i; 583 int i;
584 584
585 LIBCFS_ALLOC(hdr, sizeof(*hdr)); 585 hdr = kzalloc(sizeof(*hdr), GFP_NOFS);
586 if (!hdr) { 586 if (!hdr) {
587 CERROR("Can't allocate struct lnet_hdr\n"); 587 CERROR("Can't allocate struct lnet_hdr\n");
588 return -ENOMEM; 588 return -ENOMEM;
@@ -644,7 +644,7 @@ ksocknal_recv_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello,
644 } 644 }
645 } 645 }
646out: 646out:
647 LIBCFS_FREE(hdr, sizeof(*hdr)); 647 kfree(hdr);
648 648
649 return rc; 649 return rc;
650} 650}
diff --git a/drivers/staging/lustre/lnet/libcfs/Makefile b/drivers/staging/lustre/lnet/libcfs/Makefile
index 1607570ef8de..730f2c675047 100644
--- a/drivers/staging/lustre/lnet/libcfs/Makefile
+++ b/drivers/staging/lustre/lnet/libcfs/Makefile
@@ -15,7 +15,7 @@ libcfs-linux-objs += linux-mem.o
15libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs)) 15libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs))
16 16
17libcfs-all-objs := debug.o fail.o module.o tracefile.o \ 17libcfs-all-objs := debug.o fail.o module.o tracefile.o \
18 libcfs_string.o hash.o prng.o workitem.o \ 18 libcfs_string.o hash.o \
19 libcfs_cpu.o libcfs_mem.o libcfs_lock.o 19 libcfs_cpu.o libcfs_mem.o libcfs_lock.o
20 20
21libcfs-objs := $(libcfs-linux-objs) $(libcfs-all-objs) 21libcfs-objs := $(libcfs-linux-objs) $(libcfs-all-objs)
diff --git a/drivers/staging/lustre/lnet/libcfs/fail.c b/drivers/staging/lustre/lnet/libcfs/fail.c
index 5d501beeb622..39439b303d65 100644
--- a/drivers/staging/lustre/lnet/libcfs/fail.c
+++ b/drivers/staging/lustre/lnet/libcfs/fail.c
@@ -61,7 +61,7 @@ int __cfs_fail_check_set(u32 id, u32 value, int set)
61 61
62 /* Fail 1/cfs_fail_val times */ 62 /* Fail 1/cfs_fail_val times */
63 if (cfs_fail_loc & CFS_FAIL_RAND) { 63 if (cfs_fail_loc & CFS_FAIL_RAND) {
64 if (cfs_fail_val < 2 || cfs_rand() % cfs_fail_val > 0) 64 if (cfs_fail_val < 2 || prandom_u32_max(cfs_fail_val) > 0)
65 return 0; 65 return 0;
66 } 66 }
67 67
diff --git a/drivers/staging/lustre/lnet/libcfs/hash.c b/drivers/staging/lustre/lnet/libcfs/hash.c
index f4f67d2b301e..f7b3c9306456 100644
--- a/drivers/staging/lustre/lnet/libcfs/hash.c
+++ b/drivers/staging/lustre/lnet/libcfs/hash.c
@@ -114,7 +114,7 @@ module_param(warn_on_depth, uint, 0644);
114MODULE_PARM_DESC(warn_on_depth, "warning when hash depth is high."); 114MODULE_PARM_DESC(warn_on_depth, "warning when hash depth is high.");
115#endif 115#endif
116 116
117struct cfs_wi_sched *cfs_sched_rehash; 117struct workqueue_struct *cfs_rehash_wq;
118 118
119static inline void 119static inline void
120cfs_hash_nl_lock(union cfs_hash_lock *lock, int exclusive) {} 120cfs_hash_nl_lock(union cfs_hash_lock *lock, int exclusive) {}
@@ -519,7 +519,7 @@ cfs_hash_bd_dep_record(struct cfs_hash *hs, struct cfs_hash_bd *bd, int dep_cur)
519 hs->hs_dep_bits = hs->hs_cur_bits; 519 hs->hs_dep_bits = hs->hs_cur_bits;
520 spin_unlock(&hs->hs_dep_lock); 520 spin_unlock(&hs->hs_dep_lock);
521 521
522 cfs_wi_schedule(cfs_sched_rehash, &hs->hs_dep_wi); 522 queue_work(cfs_rehash_wq, &hs->hs_dep_work);
523# endif 523# endif
524} 524}
525 525
@@ -864,12 +864,10 @@ cfs_hash_buckets_free(struct cfs_hash_bucket **buckets,
864{ 864{
865 int i; 865 int i;
866 866
867 for (i = prev_size; i < size; i++) { 867 for (i = prev_size; i < size; i++)
868 if (buckets[i]) 868 kfree(buckets[i]);
869 LIBCFS_FREE(buckets[i], bkt_size);
870 }
871 869
872 LIBCFS_FREE(buckets, sizeof(buckets[0]) * size); 870 kvfree(buckets);
873} 871}
874 872
875/* 873/*
@@ -889,7 +887,7 @@ cfs_hash_buckets_realloc(struct cfs_hash *hs, struct cfs_hash_bucket **old_bkts,
889 if (old_bkts && old_size == new_size) 887 if (old_bkts && old_size == new_size)
890 return old_bkts; 888 return old_bkts;
891 889
892 LIBCFS_ALLOC(new_bkts, sizeof(new_bkts[0]) * new_size); 890 new_bkts = kvmalloc_array(new_size, sizeof(new_bkts[0]), GFP_KERNEL);
893 if (!new_bkts) 891 if (!new_bkts)
894 return NULL; 892 return NULL;
895 893
@@ -902,7 +900,7 @@ cfs_hash_buckets_realloc(struct cfs_hash *hs, struct cfs_hash_bucket **old_bkts,
902 struct hlist_head *hhead; 900 struct hlist_head *hhead;
903 struct cfs_hash_bd bd; 901 struct cfs_hash_bd bd;
904 902
905 LIBCFS_ALLOC(new_bkts[i], cfs_hash_bkt_size(hs)); 903 new_bkts[i] = kzalloc(cfs_hash_bkt_size(hs), GFP_KERNEL);
906 if (!new_bkts[i]) { 904 if (!new_bkts[i]) {
907 cfs_hash_buckets_free(new_bkts, cfs_hash_bkt_size(hs), 905 cfs_hash_buckets_free(new_bkts, cfs_hash_bkt_size(hs),
908 old_size, new_size); 906 old_size, new_size);
@@ -939,12 +937,12 @@ cfs_hash_buckets_realloc(struct cfs_hash *hs, struct cfs_hash_bucket **old_bkts,
939 * @flags - CFS_HASH_REHASH enable synamic hash resizing 937 * @flags - CFS_HASH_REHASH enable synamic hash resizing
940 * - CFS_HASH_SORT enable chained hash sort 938 * - CFS_HASH_SORT enable chained hash sort
941 */ 939 */
942static int cfs_hash_rehash_worker(struct cfs_workitem *wi); 940static void cfs_hash_rehash_worker(struct work_struct *work);
943 941
944#if CFS_HASH_DEBUG_LEVEL >= CFS_HASH_DEBUG_1 942#if CFS_HASH_DEBUG_LEVEL >= CFS_HASH_DEBUG_1
945static int cfs_hash_dep_print(struct cfs_workitem *wi) 943static void cfs_hash_dep_print(struct work_struct *work)
946{ 944{
947 struct cfs_hash *hs = container_of(wi, struct cfs_hash, hs_dep_wi); 945 struct cfs_hash *hs = container_of(work, struct cfs_hash, hs_dep_work);
948 int dep; 946 int dep;
949 int bkt; 947 int bkt;
950 int off; 948 int off;
@@ -968,21 +966,12 @@ static int cfs_hash_dep_print(struct cfs_workitem *wi)
968static void cfs_hash_depth_wi_init(struct cfs_hash *hs) 966static void cfs_hash_depth_wi_init(struct cfs_hash *hs)
969{ 967{
970 spin_lock_init(&hs->hs_dep_lock); 968 spin_lock_init(&hs->hs_dep_lock);
971 cfs_wi_init(&hs->hs_dep_wi, hs, cfs_hash_dep_print); 969 INIT_WORK(&hs->hs_dep_work, cfs_hash_dep_print);
972} 970}
973 971
974static void cfs_hash_depth_wi_cancel(struct cfs_hash *hs) 972static void cfs_hash_depth_wi_cancel(struct cfs_hash *hs)
975{ 973{
976 if (cfs_wi_deschedule(cfs_sched_rehash, &hs->hs_dep_wi)) 974 cancel_work_sync(&hs->hs_dep_work);
977 return;
978
979 spin_lock(&hs->hs_dep_lock);
980 while (hs->hs_dep_bits) {
981 spin_unlock(&hs->hs_dep_lock);
982 cond_resched();
983 spin_lock(&hs->hs_dep_lock);
984 }
985 spin_unlock(&hs->hs_dep_lock);
986} 975}
987 976
988#else /* CFS_HASH_DEBUG_LEVEL < CFS_HASH_DEBUG_1 */ 977#else /* CFS_HASH_DEBUG_LEVEL < CFS_HASH_DEBUG_1 */
@@ -1023,7 +1012,7 @@ cfs_hash_create(char *name, unsigned int cur_bits, unsigned int max_bits,
1023 1012
1024 len = !(flags & CFS_HASH_BIGNAME) ? 1013 len = !(flags & CFS_HASH_BIGNAME) ?
1025 CFS_HASH_NAME_LEN : CFS_HASH_BIGNAME_LEN; 1014 CFS_HASH_NAME_LEN : CFS_HASH_BIGNAME_LEN;
1026 LIBCFS_ALLOC(hs, offsetof(struct cfs_hash, hs_name[len])); 1015 hs = kzalloc(offsetof(struct cfs_hash, hs_name[len]), GFP_KERNEL);
1027 if (!hs) 1016 if (!hs)
1028 return NULL; 1017 return NULL;
1029 1018
@@ -1044,7 +1033,7 @@ cfs_hash_create(char *name, unsigned int cur_bits, unsigned int max_bits,
1044 hs->hs_ops = ops; 1033 hs->hs_ops = ops;
1045 hs->hs_extra_bytes = extra_bytes; 1034 hs->hs_extra_bytes = extra_bytes;
1046 hs->hs_rehash_bits = 0; 1035 hs->hs_rehash_bits = 0;
1047 cfs_wi_init(&hs->hs_rehash_wi, hs, cfs_hash_rehash_worker); 1036 INIT_WORK(&hs->hs_rehash_work, cfs_hash_rehash_worker);
1048 cfs_hash_depth_wi_init(hs); 1037 cfs_hash_depth_wi_init(hs);
1049 1038
1050 if (cfs_hash_with_rehash(hs)) 1039 if (cfs_hash_with_rehash(hs))
@@ -1055,7 +1044,7 @@ cfs_hash_create(char *name, unsigned int cur_bits, unsigned int max_bits,
1055 if (hs->hs_buckets) 1044 if (hs->hs_buckets)
1056 return hs; 1045 return hs;
1057 1046
1058 LIBCFS_FREE(hs, offsetof(struct cfs_hash, hs_name[len])); 1047 kfree(hs);
1059 return NULL; 1048 return NULL;
1060} 1049}
1061EXPORT_SYMBOL(cfs_hash_create); 1050EXPORT_SYMBOL(cfs_hash_create);
@@ -1118,7 +1107,7 @@ cfs_hash_destroy(struct cfs_hash *hs)
1118 0, CFS_HASH_NBKT(hs)); 1107 0, CFS_HASH_NBKT(hs));
1119 i = cfs_hash_with_bigname(hs) ? 1108 i = cfs_hash_with_bigname(hs) ?
1120 CFS_HASH_BIGNAME_LEN : CFS_HASH_NAME_LEN; 1109 CFS_HASH_BIGNAME_LEN : CFS_HASH_NAME_LEN;
1121 LIBCFS_FREE(hs, offsetof(struct cfs_hash, hs_name[i])); 1110 kfree(hs);
1122} 1111}
1123 1112
1124struct cfs_hash *cfs_hash_getref(struct cfs_hash *hs) 1113struct cfs_hash *cfs_hash_getref(struct cfs_hash *hs)
@@ -1364,6 +1353,7 @@ cfs_hash_for_each_enter(struct cfs_hash *hs)
1364 1353
1365 cfs_hash_lock(hs, 1); 1354 cfs_hash_lock(hs, 1);
1366 hs->hs_iterators++; 1355 hs->hs_iterators++;
1356 cfs_hash_unlock(hs, 1);
1367 1357
1368 /* NB: iteration is mostly called by service thread, 1358 /* NB: iteration is mostly called by service thread,
1369 * we tend to cancel pending rehash-request, instead of 1359 * we tend to cancel pending rehash-request, instead of
@@ -1371,8 +1361,7 @@ cfs_hash_for_each_enter(struct cfs_hash *hs)
1371 * after iteration 1361 * after iteration
1372 */ 1362 */
1373 if (cfs_hash_is_rehashing(hs)) 1363 if (cfs_hash_is_rehashing(hs))
1374 cfs_hash_rehash_cancel_locked(hs); 1364 cfs_hash_rehash_cancel(hs);
1375 cfs_hash_unlock(hs, 1);
1376} 1365}
1377 1366
1378static void 1367static void
@@ -1774,42 +1763,13 @@ EXPORT_SYMBOL(cfs_hash_for_each_key);
1774 * theta thresholds for @hs are tunable via cfs_hash_set_theta(). 1763 * theta thresholds for @hs are tunable via cfs_hash_set_theta().
1775 */ 1764 */
1776void 1765void
1777cfs_hash_rehash_cancel_locked(struct cfs_hash *hs)
1778{
1779 int i;
1780
1781 /* need hold cfs_hash_lock(hs, 1) */
1782 LASSERT(cfs_hash_with_rehash(hs) &&
1783 !cfs_hash_with_no_lock(hs));
1784
1785 if (!cfs_hash_is_rehashing(hs))
1786 return;
1787
1788 if (cfs_wi_deschedule(cfs_sched_rehash, &hs->hs_rehash_wi)) {
1789 hs->hs_rehash_bits = 0;
1790 return;
1791 }
1792
1793 for (i = 2; cfs_hash_is_rehashing(hs); i++) {
1794 cfs_hash_unlock(hs, 1);
1795 /* raise console warning while waiting too long */
1796 CDEBUG(is_power_of_2(i >> 3) ? D_WARNING : D_INFO,
1797 "hash %s is still rehashing, rescheded %d\n",
1798 hs->hs_name, i - 1);
1799 cond_resched();
1800 cfs_hash_lock(hs, 1);
1801 }
1802}
1803
1804void
1805cfs_hash_rehash_cancel(struct cfs_hash *hs) 1766cfs_hash_rehash_cancel(struct cfs_hash *hs)
1806{ 1767{
1807 cfs_hash_lock(hs, 1); 1768 LASSERT(cfs_hash_with_rehash(hs));
1808 cfs_hash_rehash_cancel_locked(hs); 1769 cancel_work_sync(&hs->hs_rehash_work);
1809 cfs_hash_unlock(hs, 1);
1810} 1770}
1811 1771
1812int 1772void
1813cfs_hash_rehash(struct cfs_hash *hs, int do_rehash) 1773cfs_hash_rehash(struct cfs_hash *hs, int do_rehash)
1814{ 1774{
1815 int rc; 1775 int rc;
@@ -1821,21 +1781,21 @@ cfs_hash_rehash(struct cfs_hash *hs, int do_rehash)
1821 rc = cfs_hash_rehash_bits(hs); 1781 rc = cfs_hash_rehash_bits(hs);
1822 if (rc <= 0) { 1782 if (rc <= 0) {
1823 cfs_hash_unlock(hs, 1); 1783 cfs_hash_unlock(hs, 1);
1824 return rc; 1784 return;
1825 } 1785 }
1826 1786
1827 hs->hs_rehash_bits = rc; 1787 hs->hs_rehash_bits = rc;
1828 if (!do_rehash) { 1788 if (!do_rehash) {
1829 /* launch and return */ 1789 /* launch and return */
1830 cfs_wi_schedule(cfs_sched_rehash, &hs->hs_rehash_wi); 1790 queue_work(cfs_rehash_wq, &hs->hs_rehash_work);
1831 cfs_hash_unlock(hs, 1); 1791 cfs_hash_unlock(hs, 1);
1832 return 0; 1792 return;
1833 } 1793 }
1834 1794
1835 /* rehash right now */ 1795 /* rehash right now */
1836 cfs_hash_unlock(hs, 1); 1796 cfs_hash_unlock(hs, 1);
1837 1797
1838 return cfs_hash_rehash_worker(&hs->hs_rehash_wi); 1798 cfs_hash_rehash_worker(&hs->hs_rehash_work);
1839} 1799}
1840 1800
1841static int 1801static int
@@ -1869,10 +1829,10 @@ cfs_hash_rehash_bd(struct cfs_hash *hs, struct cfs_hash_bd *old)
1869 return c; 1829 return c;
1870} 1830}
1871 1831
1872static int 1832static void
1873cfs_hash_rehash_worker(struct cfs_workitem *wi) 1833cfs_hash_rehash_worker(struct work_struct *work)
1874{ 1834{
1875 struct cfs_hash *hs = container_of(wi, struct cfs_hash, hs_rehash_wi); 1835 struct cfs_hash *hs = container_of(work, struct cfs_hash, hs_rehash_work);
1876 struct cfs_hash_bucket **bkts; 1836 struct cfs_hash_bucket **bkts;
1877 struct cfs_hash_bd bd; 1837 struct cfs_hash_bd bd;
1878 unsigned int old_size; 1838 unsigned int old_size;
@@ -1956,8 +1916,6 @@ cfs_hash_rehash_worker(struct cfs_workitem *wi)
1956 hs->hs_cur_bits = hs->hs_rehash_bits; 1916 hs->hs_cur_bits = hs->hs_rehash_bits;
1957out: 1917out:
1958 hs->hs_rehash_bits = 0; 1918 hs->hs_rehash_bits = 0;
1959 if (rc == -ESRCH) /* never be scheduled again */
1960 cfs_wi_exit(cfs_sched_rehash, wi);
1961 bsize = cfs_hash_bkt_size(hs); 1919 bsize = cfs_hash_bkt_size(hs);
1962 cfs_hash_unlock(hs, 1); 1920 cfs_hash_unlock(hs, 1);
1963 /* can't refer to @hs anymore because it could be destroyed */ 1921 /* can't refer to @hs anymore because it could be destroyed */
@@ -1965,8 +1923,6 @@ out:
1965 cfs_hash_buckets_free(bkts, bsize, new_size, old_size); 1923 cfs_hash_buckets_free(bkts, bsize, new_size, old_size);
1966 if (rc) 1924 if (rc)
1967 CDEBUG(D_INFO, "early quit of rehashing: %d\n", rc); 1925 CDEBUG(D_INFO, "early quit of rehashing: %d\n", rc);
1968 /* return 1 only if cfs_wi_exit is called */
1969 return rc == -ESRCH;
1970} 1926}
1971 1927
1972/** 1928/**
diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c b/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c
index e3a4c67a66b5..76291a350406 100644
--- a/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c
+++ b/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c
@@ -51,7 +51,7 @@ cfs_cpt_table_alloc(unsigned int ncpt)
51 return NULL; 51 return NULL;
52 } 52 }
53 53
54 LIBCFS_ALLOC(cptab, sizeof(*cptab)); 54 cptab = kzalloc(sizeof(*cptab), GFP_NOFS);
55 if (cptab) { 55 if (cptab) {
56 cptab->ctb_version = CFS_CPU_VERSION_MAGIC; 56 cptab->ctb_version = CFS_CPU_VERSION_MAGIC;
57 node_set(0, cptab->ctb_nodemask); 57 node_set(0, cptab->ctb_nodemask);
@@ -67,7 +67,7 @@ cfs_cpt_table_free(struct cfs_cpt_table *cptab)
67{ 67{
68 LASSERT(cptab->ctb_version == CFS_CPU_VERSION_MAGIC); 68 LASSERT(cptab->ctb_version == CFS_CPU_VERSION_MAGIC);
69 69
70 LIBCFS_FREE(cptab, sizeof(*cptab)); 70 kfree(cptab);
71} 71}
72EXPORT_SYMBOL(cfs_cpt_table_free); 72EXPORT_SYMBOL(cfs_cpt_table_free);
73 73
@@ -113,7 +113,7 @@ cfs_cpt_nodemask(struct cfs_cpt_table *cptab, int cpt)
113{ 113{
114 return &cptab->ctb_nodemask; 114 return &cptab->ctb_nodemask;
115} 115}
116EXPORT_SYMBOL(cfs_cpt_cpumask); 116EXPORT_SYMBOL(cfs_cpt_nodemask);
117 117
118int 118int
119cfs_cpt_set_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu) 119cfs_cpt_set_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c b/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c
index f6a0040f4ab1..670ad5a34224 100644
--- a/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c
+++ b/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c
@@ -38,7 +38,7 @@ cfs_percpt_lock_free(struct cfs_percpt_lock *pcl)
38 LASSERT(!pcl->pcl_locked); 38 LASSERT(!pcl->pcl_locked);
39 39
40 cfs_percpt_free(pcl->pcl_locks); 40 cfs_percpt_free(pcl->pcl_locks);
41 LIBCFS_FREE(pcl, sizeof(*pcl)); 41 kfree(pcl);
42} 42}
43EXPORT_SYMBOL(cfs_percpt_lock_free); 43EXPORT_SYMBOL(cfs_percpt_lock_free);
44 44
@@ -58,14 +58,14 @@ cfs_percpt_lock_create(struct cfs_cpt_table *cptab,
58 int i; 58 int i;
59 59
60 /* NB: cptab can be NULL, pcl will be for HW CPUs on that case */ 60 /* NB: cptab can be NULL, pcl will be for HW CPUs on that case */
61 LIBCFS_ALLOC(pcl, sizeof(*pcl)); 61 pcl = kzalloc(sizeof(*pcl), GFP_NOFS);
62 if (!pcl) 62 if (!pcl)
63 return NULL; 63 return NULL;
64 64
65 pcl->pcl_cptab = cptab; 65 pcl->pcl_cptab = cptab;
66 pcl->pcl_locks = cfs_percpt_alloc(cptab, sizeof(*lock)); 66 pcl->pcl_locks = cfs_percpt_alloc(cptab, sizeof(*lock));
67 if (!pcl->pcl_locks) { 67 if (!pcl->pcl_locks) {
68 LIBCFS_FREE(pcl, sizeof(*pcl)); 68 kfree(pcl);
69 return NULL; 69 return NULL;
70 } 70 }
71 71
diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c
index df93d8f77ea2..7faed94994ea 100644
--- a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c
+++ b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c
@@ -49,13 +49,10 @@ cfs_percpt_free(void *vars)
49 49
50 arr = container_of(vars, struct cfs_var_array, va_ptrs[0]); 50 arr = container_of(vars, struct cfs_var_array, va_ptrs[0]);
51 51
52 for (i = 0; i < arr->va_count; i++) { 52 for (i = 0; i < arr->va_count; i++)
53 if (arr->va_ptrs[i]) 53 kfree(arr->va_ptrs[i]);
54 LIBCFS_FREE(arr->va_ptrs[i], arr->va_size);
55 }
56 54
57 LIBCFS_FREE(arr, offsetof(struct cfs_var_array, 55 kvfree(arr);
58 va_ptrs[arr->va_count]));
59} 56}
60EXPORT_SYMBOL(cfs_percpt_free); 57EXPORT_SYMBOL(cfs_percpt_free);
61 58
@@ -79,7 +76,8 @@ cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size)
79 76
80 count = cfs_cpt_number(cptab); 77 count = cfs_cpt_number(cptab);
81 78
82 LIBCFS_ALLOC(arr, offsetof(struct cfs_var_array, va_ptrs[count])); 79 arr = kvzalloc(offsetof(struct cfs_var_array, va_ptrs[count]),
80 GFP_KERNEL);
83 if (!arr) 81 if (!arr)
84 return NULL; 82 return NULL;
85 83
@@ -89,7 +87,8 @@ cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size)
89 arr->va_cptab = cptab; 87 arr->va_cptab = cptab;
90 88
91 for (i = 0; i < count; i++) { 89 for (i = 0; i < count; i++) {
92 LIBCFS_CPT_ALLOC(arr->va_ptrs[i], cptab, i, size); 90 arr->va_ptrs[i] = kzalloc_node(size, GFP_KERNEL,
91 cfs_cpt_spread_node(cptab, i));
93 if (!arr->va_ptrs[i]) { 92 if (!arr->va_ptrs[i]) {
94 cfs_percpt_free((void *)&arr->va_ptrs[0]); 93 cfs_percpt_free((void *)&arr->va_ptrs[0]);
95 return NULL; 94 return NULL;
@@ -130,10 +129,9 @@ cfs_array_free(void *vars)
130 if (!arr->va_ptrs[i]) 129 if (!arr->va_ptrs[i])
131 continue; 130 continue;
132 131
133 LIBCFS_FREE(arr->va_ptrs[i], arr->va_size); 132 kvfree(arr->va_ptrs[i]);
134 } 133 }
135 LIBCFS_FREE(arr, offsetof(struct cfs_var_array, 134 kvfree(arr);
136 va_ptrs[arr->va_count]));
137} 135}
138EXPORT_SYMBOL(cfs_array_free); 136EXPORT_SYMBOL(cfs_array_free);
139 137
@@ -148,7 +146,7 @@ cfs_array_alloc(int count, unsigned int size)
148 struct cfs_var_array *arr; 146 struct cfs_var_array *arr;
149 int i; 147 int i;
150 148
151 LIBCFS_ALLOC(arr, offsetof(struct cfs_var_array, va_ptrs[count])); 149 arr = kvmalloc(offsetof(struct cfs_var_array, va_ptrs[count]), GFP_KERNEL);
152 if (!arr) 150 if (!arr)
153 return NULL; 151 return NULL;
154 152
@@ -156,7 +154,7 @@ cfs_array_alloc(int count, unsigned int size)
156 arr->va_size = size; 154 arr->va_size = size;
157 155
158 for (i = 0; i < count; i++) { 156 for (i = 0; i < count; i++) {
159 LIBCFS_ALLOC(arr->va_ptrs[i], size); 157 arr->va_ptrs[i] = kvzalloc(size, GFP_KERNEL);
160 158
161 if (!arr->va_ptrs[i]) { 159 if (!arr->va_ptrs[i]) {
162 cfs_array_free((void *)&arr->va_ptrs[0]); 160 cfs_array_free((void *)&arr->va_ptrs[0]);
diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_string.c b/drivers/staging/lustre/lnet/libcfs/libcfs_string.c
index bcac5074bf80..442889a3d729 100644
--- a/drivers/staging/lustre/lnet/libcfs/libcfs_string.c
+++ b/drivers/staging/lustre/lnet/libcfs/libcfs_string.c
@@ -137,26 +137,6 @@ out:
137} 137}
138EXPORT_SYMBOL(cfs_firststr); 138EXPORT_SYMBOL(cfs_firststr);
139 139
140char *
141cfs_trimwhite(char *str)
142{
143 char *end;
144
145 while (isspace(*str))
146 str++;
147
148 end = str + strlen(str);
149 while (end > str) {
150 if (!isspace(end[-1]))
151 break;
152 end--;
153 }
154
155 *end = 0;
156 return str;
157}
158EXPORT_SYMBOL(cfs_trimwhite);
159
160/** 140/**
161 * Extracts tokens from strings. 141 * Extracts tokens from strings.
162 * 142 *
@@ -280,7 +260,7 @@ cfs_range_expr_parse(struct cfs_lstr *src, unsigned int min, unsigned int max,
280 struct cfs_range_expr *re; 260 struct cfs_range_expr *re;
281 struct cfs_lstr tok; 261 struct cfs_lstr tok;
282 262
283 LIBCFS_ALLOC(re, sizeof(*re)); 263 re = kzalloc(sizeof(*re), GFP_NOFS);
284 if (!re) 264 if (!re)
285 return -ENOMEM; 265 return -ENOMEM;
286 266
@@ -333,7 +313,7 @@ cfs_range_expr_parse(struct cfs_lstr *src, unsigned int min, unsigned int max,
333 return 0; 313 return 0;
334 314
335 failed: 315 failed:
336 LIBCFS_FREE(re, sizeof(*re)); 316 kfree(re);
337 return -EINVAL; 317 return -EINVAL;
338} 318}
339 319
@@ -457,7 +437,7 @@ cfs_expr_list_values(struct cfs_expr_list *expr_list, int max, u32 **valpp)
457 return -EINVAL; 437 return -EINVAL;
458 } 438 }
459 439
460 LIBCFS_ALLOC(val, sizeof(val[0]) * count); 440 val = kvmalloc_array(count, sizeof(val[0]), GFP_KERNEL | __GFP_ZERO);
461 if (!val) 441 if (!val)
462 return -ENOMEM; 442 return -ENOMEM;
463 443
@@ -488,10 +468,10 @@ cfs_expr_list_free(struct cfs_expr_list *expr_list)
488 expr = list_entry(expr_list->el_exprs.next, 468 expr = list_entry(expr_list->el_exprs.next,
489 struct cfs_range_expr, re_link); 469 struct cfs_range_expr, re_link);
490 list_del(&expr->re_link); 470 list_del(&expr->re_link);
491 LIBCFS_FREE(expr, sizeof(*expr)); 471 kfree(expr);
492 } 472 }
493 473
494 LIBCFS_FREE(expr_list, sizeof(*expr_list)); 474 kfree(expr_list);
495} 475}
496EXPORT_SYMBOL(cfs_expr_list_free); 476EXPORT_SYMBOL(cfs_expr_list_free);
497 477
@@ -510,7 +490,7 @@ cfs_expr_list_parse(char *str, int len, unsigned int min, unsigned int max,
510 struct cfs_lstr src; 490 struct cfs_lstr src;
511 int rc; 491 int rc;
512 492
513 LIBCFS_ALLOC(expr_list, sizeof(*expr_list)); 493 expr_list = kzalloc(sizeof(*expr_list), GFP_NOFS);
514 if (!expr_list) 494 if (!expr_list)
515 return -ENOMEM; 495 return -ENOMEM;
516 496
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c
index 51823ce71773..c07165e0ad95 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c
@@ -72,7 +72,7 @@ struct cfs_cpt_data {
72 /* mutex to protect cpt_cpumask */ 72 /* mutex to protect cpt_cpumask */
73 struct mutex cpt_mutex; 73 struct mutex cpt_mutex;
74 /* scratch buffer for set/unset_node */ 74 /* scratch buffer for set/unset_node */
75 cpumask_t *cpt_cpumask; 75 cpumask_var_t cpt_cpumask;
76}; 76};
77 77
78static struct cfs_cpt_data cpt_data; 78static struct cfs_cpt_data cpt_data;
@@ -93,35 +93,21 @@ cfs_cpt_table_free(struct cfs_cpt_table *cptab)
93{ 93{
94 int i; 94 int i;
95 95
96 if (cptab->ctb_cpu2cpt) { 96 kvfree(cptab->ctb_cpu2cpt);
97 LIBCFS_FREE(cptab->ctb_cpu2cpt,
98 num_possible_cpus() *
99 sizeof(cptab->ctb_cpu2cpt[0]));
100 }
101 97
102 for (i = 0; cptab->ctb_parts && i < cptab->ctb_nparts; i++) { 98 for (i = 0; cptab->ctb_parts && i < cptab->ctb_nparts; i++) {
103 struct cfs_cpu_partition *part = &cptab->ctb_parts[i]; 99 struct cfs_cpu_partition *part = &cptab->ctb_parts[i];
104 100
105 if (part->cpt_nodemask) { 101 kfree(part->cpt_nodemask);
106 LIBCFS_FREE(part->cpt_nodemask, 102 free_cpumask_var(part->cpt_cpumask);
107 sizeof(*part->cpt_nodemask));
108 }
109
110 if (part->cpt_cpumask)
111 LIBCFS_FREE(part->cpt_cpumask, cpumask_size());
112 } 103 }
113 104
114 if (cptab->ctb_parts) { 105 kvfree(cptab->ctb_parts);
115 LIBCFS_FREE(cptab->ctb_parts,
116 cptab->ctb_nparts * sizeof(cptab->ctb_parts[0]));
117 }
118 106
119 if (cptab->ctb_nodemask) 107 kfree(cptab->ctb_nodemask);
120 LIBCFS_FREE(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask)); 108 free_cpumask_var(cptab->ctb_cpumask);
121 if (cptab->ctb_cpumask)
122 LIBCFS_FREE(cptab->ctb_cpumask, cpumask_size());
123 109
124 LIBCFS_FREE(cptab, sizeof(*cptab)); 110 kfree(cptab);
125} 111}
126EXPORT_SYMBOL(cfs_cpt_table_free); 112EXPORT_SYMBOL(cfs_cpt_table_free);
127 113
@@ -131,36 +117,39 @@ cfs_cpt_table_alloc(unsigned int ncpt)
131 struct cfs_cpt_table *cptab; 117 struct cfs_cpt_table *cptab;
132 int i; 118 int i;
133 119
134 LIBCFS_ALLOC(cptab, sizeof(*cptab)); 120 cptab = kzalloc(sizeof(*cptab), GFP_NOFS);
135 if (!cptab) 121 if (!cptab)
136 return NULL; 122 return NULL;
137 123
138 cptab->ctb_nparts = ncpt; 124 cptab->ctb_nparts = ncpt;
139 125
140 LIBCFS_ALLOC(cptab->ctb_cpumask, cpumask_size()); 126 cptab->ctb_nodemask = kzalloc(sizeof(*cptab->ctb_nodemask),
141 LIBCFS_ALLOC(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask)); 127 GFP_NOFS);
142 128 if (!zalloc_cpumask_var(&cptab->ctb_cpumask, GFP_NOFS) ||
143 if (!cptab->ctb_cpumask || !cptab->ctb_nodemask) 129 !cptab->ctb_nodemask)
144 goto failed; 130 goto failed;
145 131
146 LIBCFS_ALLOC(cptab->ctb_cpu2cpt, 132 cptab->ctb_cpu2cpt = kvmalloc_array(num_possible_cpus(),
147 num_possible_cpus() * sizeof(cptab->ctb_cpu2cpt[0])); 133 sizeof(cptab->ctb_cpu2cpt[0]),
134 GFP_KERNEL);
148 if (!cptab->ctb_cpu2cpt) 135 if (!cptab->ctb_cpu2cpt)
149 goto failed; 136 goto failed;
150 137
151 memset(cptab->ctb_cpu2cpt, -1, 138 memset(cptab->ctb_cpu2cpt, -1,
152 num_possible_cpus() * sizeof(cptab->ctb_cpu2cpt[0])); 139 num_possible_cpus() * sizeof(cptab->ctb_cpu2cpt[0]));
153 140
154 LIBCFS_ALLOC(cptab->ctb_parts, ncpt * sizeof(cptab->ctb_parts[0])); 141 cptab->ctb_parts = kvmalloc_array(ncpt, sizeof(cptab->ctb_parts[0]),
142 GFP_KERNEL);
155 if (!cptab->ctb_parts) 143 if (!cptab->ctb_parts)
156 goto failed; 144 goto failed;
157 145
158 for (i = 0; i < ncpt; i++) { 146 for (i = 0; i < ncpt; i++) {
159 struct cfs_cpu_partition *part = &cptab->ctb_parts[i]; 147 struct cfs_cpu_partition *part = &cptab->ctb_parts[i];
160 148
161 LIBCFS_ALLOC(part->cpt_cpumask, cpumask_size()); 149 part->cpt_nodemask = kzalloc(sizeof(*part->cpt_nodemask),
162 LIBCFS_ALLOC(part->cpt_nodemask, sizeof(*part->cpt_nodemask)); 150 GFP_NOFS);
163 if (!part->cpt_cpumask || !part->cpt_nodemask) 151 if (!zalloc_cpumask_var(&part->cpt_cpumask, GFP_NOFS) ||
152 !part->cpt_nodemask)
164 goto failed; 153 goto failed;
165 } 154 }
166 155
@@ -251,13 +240,13 @@ cfs_cpt_online(struct cfs_cpt_table *cptab, int cpt)
251} 240}
252EXPORT_SYMBOL(cfs_cpt_online); 241EXPORT_SYMBOL(cfs_cpt_online);
253 242
254cpumask_t * 243cpumask_var_t *
255cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt) 244cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt)
256{ 245{
257 LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts)); 246 LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts));
258 247
259 return cpt == CFS_CPT_ANY ? 248 return cpt == CFS_CPT_ANY ?
260 cptab->ctb_cpumask : cptab->ctb_parts[cpt].cpt_cpumask; 249 &cptab->ctb_cpumask : &cptab->ctb_parts[cpt].cpt_cpumask;
261} 250}
262EXPORT_SYMBOL(cfs_cpt_cpumask); 251EXPORT_SYMBOL(cfs_cpt_cpumask);
263 252
@@ -405,7 +394,6 @@ EXPORT_SYMBOL(cfs_cpt_unset_cpumask);
405int 394int
406cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node) 395cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node)
407{ 396{
408 cpumask_t *mask;
409 int rc; 397 int rc;
410 398
411 if (node < 0 || node >= MAX_NUMNODES) { 399 if (node < 0 || node >= MAX_NUMNODES) {
@@ -416,10 +404,9 @@ cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node)
416 404
417 mutex_lock(&cpt_data.cpt_mutex); 405 mutex_lock(&cpt_data.cpt_mutex);
418 406
419 mask = cpt_data.cpt_cpumask; 407 cfs_node_to_cpumask(node, cpt_data.cpt_cpumask);
420 cfs_node_to_cpumask(node, mask);
421 408
422 rc = cfs_cpt_set_cpumask(cptab, cpt, mask); 409 rc = cfs_cpt_set_cpumask(cptab, cpt, cpt_data.cpt_cpumask);
423 410
424 mutex_unlock(&cpt_data.cpt_mutex); 411 mutex_unlock(&cpt_data.cpt_mutex);
425 412
@@ -430,8 +417,6 @@ EXPORT_SYMBOL(cfs_cpt_set_node);
430void 417void
431cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node) 418cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node)
432{ 419{
433 cpumask_t *mask;
434
435 if (node < 0 || node >= MAX_NUMNODES) { 420 if (node < 0 || node >= MAX_NUMNODES) {
436 CDEBUG(D_INFO, 421 CDEBUG(D_INFO,
437 "Invalid NUMA id %d for CPU partition %d\n", node, cpt); 422 "Invalid NUMA id %d for CPU partition %d\n", node, cpt);
@@ -440,10 +425,9 @@ cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node)
440 425
441 mutex_lock(&cpt_data.cpt_mutex); 426 mutex_lock(&cpt_data.cpt_mutex);
442 427
443 mask = cpt_data.cpt_cpumask; 428 cfs_node_to_cpumask(node, cpt_data.cpt_cpumask);
444 cfs_node_to_cpumask(node, mask);
445 429
446 cfs_cpt_unset_cpumask(cptab, cpt, mask); 430 cfs_cpt_unset_cpumask(cptab, cpt, cpt_data.cpt_cpumask);
447 431
448 mutex_unlock(&cpt_data.cpt_mutex); 432 mutex_unlock(&cpt_data.cpt_mutex);
449} 433}
@@ -529,19 +513,20 @@ EXPORT_SYMBOL(cfs_cpt_spread_node);
529int 513int
530cfs_cpt_current(struct cfs_cpt_table *cptab, int remap) 514cfs_cpt_current(struct cfs_cpt_table *cptab, int remap)
531{ 515{
532 int cpu = smp_processor_id(); 516 int cpu;
533 int cpt = cptab->ctb_cpu2cpt[cpu]; 517 int cpt;
534 518
535 if (cpt < 0) { 519 preempt_disable();
536 if (!remap) 520 cpu = smp_processor_id();
537 return cpt; 521 cpt = cptab->ctb_cpu2cpt[cpu];
538 522
523 if (cpt < 0 && remap) {
539 /* don't return negative value for safety of upper layer, 524 /* don't return negative value for safety of upper layer,
540 * instead we shadow the unknown cpu to a valid partition ID 525 * instead we shadow the unknown cpu to a valid partition ID
541 */ 526 */
542 cpt = cpu % cptab->ctb_nparts; 527 cpt = cpu % cptab->ctb_nparts;
543 } 528 }
544 529 preempt_enable();
545 return cpt; 530 return cpt;
546} 531}
547EXPORT_SYMBOL(cfs_cpt_current); 532EXPORT_SYMBOL(cfs_cpt_current);
@@ -558,7 +543,7 @@ EXPORT_SYMBOL(cfs_cpt_of_cpu);
558int 543int
559cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt) 544cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt)
560{ 545{
561 cpumask_t *cpumask; 546 cpumask_var_t *cpumask;
562 nodemask_t *nodemask; 547 nodemask_t *nodemask;
563 int rc; 548 int rc;
564 int i; 549 int i;
@@ -566,24 +551,24 @@ cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt)
566 LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts)); 551 LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts));
567 552
568 if (cpt == CFS_CPT_ANY) { 553 if (cpt == CFS_CPT_ANY) {
569 cpumask = cptab->ctb_cpumask; 554 cpumask = &cptab->ctb_cpumask;
570 nodemask = cptab->ctb_nodemask; 555 nodemask = cptab->ctb_nodemask;
571 } else { 556 } else {
572 cpumask = cptab->ctb_parts[cpt].cpt_cpumask; 557 cpumask = &cptab->ctb_parts[cpt].cpt_cpumask;
573 nodemask = cptab->ctb_parts[cpt].cpt_nodemask; 558 nodemask = cptab->ctb_parts[cpt].cpt_nodemask;
574 } 559 }
575 560
576 if (cpumask_any_and(cpumask, cpu_online_mask) >= nr_cpu_ids) { 561 if (cpumask_any_and(*cpumask, cpu_online_mask) >= nr_cpu_ids) {
577 CERROR("No online CPU found in CPU partition %d, did someone do CPU hotplug on system? You might need to reload Lustre modules to keep system working well.\n", 562 CERROR("No online CPU found in CPU partition %d, did someone do CPU hotplug on system? You might need to reload Lustre modules to keep system working well.\n",
578 cpt); 563 cpt);
579 return -EINVAL; 564 return -EINVAL;
580 } 565 }
581 566
582 for_each_online_cpu(i) { 567 for_each_online_cpu(i) {
583 if (cpumask_test_cpu(i, cpumask)) 568 if (cpumask_test_cpu(i, *cpumask))
584 continue; 569 continue;
585 570
586 rc = set_cpus_allowed_ptr(current, cpumask); 571 rc = set_cpus_allowed_ptr(current, *cpumask);
587 set_mems_allowed(*nodemask); 572 set_mems_allowed(*nodemask);
588 if (!rc) 573 if (!rc)
589 schedule(); /* switch to allowed CPU */ 574 schedule(); /* switch to allowed CPU */
@@ -604,8 +589,8 @@ static int
604cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt, 589cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt,
605 cpumask_t *node, int number) 590 cpumask_t *node, int number)
606{ 591{
607 cpumask_t *socket = NULL; 592 cpumask_var_t socket;
608 cpumask_t *core = NULL; 593 cpumask_var_t core;
609 int rc = 0; 594 int rc = 0;
610 int cpu; 595 int cpu;
611 596
@@ -623,13 +608,17 @@ cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt,
623 return 0; 608 return 0;
624 } 609 }
625 610
626 /* allocate scratch buffer */ 611 /*
627 LIBCFS_ALLOC(socket, cpumask_size()); 612 * Allocate scratch buffers
628 LIBCFS_ALLOC(core, cpumask_size()); 613 * As we cannot initialize a cpumask_var_t, we need
629 if (!socket || !core) { 614 * to alloc both before we can risk trying to free either
615 */
616 if (!zalloc_cpumask_var(&socket, GFP_NOFS))
630 rc = -ENOMEM; 617 rc = -ENOMEM;
618 if (!zalloc_cpumask_var(&core, GFP_NOFS))
619 rc = -ENOMEM;
620 if (rc)
631 goto out; 621 goto out;
632 }
633 622
634 while (!cpumask_empty(node)) { 623 while (!cpumask_empty(node)) {
635 cpu = cpumask_first(node); 624 cpu = cpumask_first(node);
@@ -667,10 +656,8 @@ cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt,
667 } 656 }
668 657
669out: 658out:
670 if (socket) 659 free_cpumask_var(socket);
671 LIBCFS_FREE(socket, cpumask_size()); 660 free_cpumask_var(core);
672 if (core)
673 LIBCFS_FREE(core, cpumask_size());
674 return rc; 661 return rc;
675} 662}
676 663
@@ -723,7 +710,7 @@ static struct cfs_cpt_table *
723cfs_cpt_table_create(int ncpt) 710cfs_cpt_table_create(int ncpt)
724{ 711{
725 struct cfs_cpt_table *cptab = NULL; 712 struct cfs_cpt_table *cptab = NULL;
726 cpumask_t *mask = NULL; 713 cpumask_var_t mask;
727 int cpt = 0; 714 int cpt = 0;
728 int num; 715 int num;
729 int rc; 716 int rc;
@@ -756,8 +743,7 @@ cfs_cpt_table_create(int ncpt)
756 goto failed; 743 goto failed;
757 } 744 }
758 745
759 LIBCFS_ALLOC(mask, cpumask_size()); 746 if (!zalloc_cpumask_var(&mask, GFP_NOFS)){
760 if (!mask) {
761 CERROR("Failed to allocate scratch cpumask\n"); 747 CERROR("Failed to allocate scratch cpumask\n");
762 goto failed; 748 goto failed;
763 } 749 }
@@ -784,7 +770,7 @@ cfs_cpt_table_create(int ncpt)
784 770
785 rc = cfs_cpt_choose_ncpus(cptab, cpt, mask, n); 771 rc = cfs_cpt_choose_ncpus(cptab, cpt, mask, n);
786 if (rc < 0) 772 if (rc < 0)
787 goto failed; 773 goto failed_mask;
788 774
789 LASSERT(num >= cpumask_weight(part->cpt_cpumask)); 775 LASSERT(num >= cpumask_weight(part->cpt_cpumask));
790 if (num == cpumask_weight(part->cpt_cpumask)) 776 if (num == cpumask_weight(part->cpt_cpumask))
@@ -797,20 +783,19 @@ cfs_cpt_table_create(int ncpt)
797 CERROR("Expect %d(%d) CPU partitions but got %d(%d), CPU hotplug/unplug while setting?\n", 783 CERROR("Expect %d(%d) CPU partitions but got %d(%d), CPU hotplug/unplug while setting?\n",
798 cptab->ctb_nparts, num, cpt, 784 cptab->ctb_nparts, num, cpt,
799 cpumask_weight(cptab->ctb_parts[ncpt - 1].cpt_cpumask)); 785 cpumask_weight(cptab->ctb_parts[ncpt - 1].cpt_cpumask));
800 goto failed; 786 goto failed_mask;
801 } 787 }
802 788
803 LIBCFS_FREE(mask, cpumask_size()); 789 free_cpumask_var(mask);
804 790
805 return cptab; 791 return cptab;
806 792
793 failed_mask:
794 free_cpumask_var(mask);
807 failed: 795 failed:
808 CERROR("Failed to setup CPU-partition-table with %d CPU-partitions, online HW nodes: %d, HW cpus: %d.\n", 796 CERROR("Failed to setup CPU-partition-table with %d CPU-partitions, online HW nodes: %d, HW cpus: %d.\n",
809 ncpt, num_online_nodes(), num_online_cpus()); 797 ncpt, num_online_nodes(), num_online_cpus());
810 798
811 if (mask)
812 LIBCFS_FREE(mask, cpumask_size());
813
814 if (cptab) 799 if (cptab)
815 cfs_cpt_table_free(cptab); 800 cfs_cpt_table_free(cptab);
816 801
@@ -830,7 +815,7 @@ cfs_cpt_table_create_pattern(char *pattern)
830 int c; 815 int c;
831 int i; 816 int i;
832 817
833 str = cfs_trimwhite(pattern); 818 str = strim(pattern);
834 if (*str == 'n' || *str == 'N') { 819 if (*str == 'n' || *str == 'N') {
835 pattern = str + 1; 820 pattern = str + 1;
836 if (*pattern != '\0') { 821 if (*pattern != '\0') {
@@ -882,7 +867,7 @@ cfs_cpt_table_create_pattern(char *pattern)
882 867
883 high = node ? MAX_NUMNODES - 1 : nr_cpu_ids - 1; 868 high = node ? MAX_NUMNODES - 1 : nr_cpu_ids - 1;
884 869
885 for (str = cfs_trimwhite(pattern), c = 0;; c++) { 870 for (str = strim(pattern), c = 0;; c++) {
886 struct cfs_range_expr *range; 871 struct cfs_range_expr *range;
887 struct cfs_expr_list *el; 872 struct cfs_expr_list *el;
888 char *bracket = strchr(str, '['); 873 char *bracket = strchr(str, '[');
@@ -917,7 +902,7 @@ cfs_cpt_table_create_pattern(char *pattern)
917 goto failed; 902 goto failed;
918 } 903 }
919 904
920 str = cfs_trimwhite(str + n); 905 str = strim(str + n);
921 if (str != bracket) { 906 if (str != bracket) {
922 CERROR("Invalid pattern %s\n", str); 907 CERROR("Invalid pattern %s\n", str);
923 goto failed; 908 goto failed;
@@ -957,7 +942,7 @@ cfs_cpt_table_create_pattern(char *pattern)
957 goto failed; 942 goto failed;
958 } 943 }
959 944
960 str = cfs_trimwhite(bracket + 1); 945 str = strim(bracket + 1);
961 } 946 }
962 947
963 return cptab; 948 return cptab;
@@ -1013,8 +998,7 @@ cfs_cpu_fini(void)
1013 cpuhp_remove_state_nocalls(lustre_cpu_online); 998 cpuhp_remove_state_nocalls(lustre_cpu_online);
1014 cpuhp_remove_state_nocalls(CPUHP_LUSTRE_CFS_DEAD); 999 cpuhp_remove_state_nocalls(CPUHP_LUSTRE_CFS_DEAD);
1015#endif 1000#endif
1016 if (cpt_data.cpt_cpumask) 1001 free_cpumask_var(cpt_data.cpt_cpumask);
1017 LIBCFS_FREE(cpt_data.cpt_cpumask, cpumask_size());
1018} 1002}
1019 1003
1020int 1004int
@@ -1026,8 +1010,7 @@ cfs_cpu_init(void)
1026 1010
1027 memset(&cpt_data, 0, sizeof(cpt_data)); 1011 memset(&cpt_data, 0, sizeof(cpt_data));
1028 1012
1029 LIBCFS_ALLOC(cpt_data.cpt_cpumask, cpumask_size()); 1013 if (!zalloc_cpumask_var(&cpt_data.cpt_cpumask, GFP_NOFS)) {
1030 if (!cpt_data.cpt_cpumask) {
1031 CERROR("Failed to allocate scratch buffer\n"); 1014 CERROR("Failed to allocate scratch buffer\n");
1032 return -1; 1015 return -1;
1033 } 1016 }
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index b5746230ab31..ddf625669bff 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -146,7 +146,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
146 return -EINVAL; 146 return -EINVAL;
147 } 147 }
148 148
149 LIBCFS_ALLOC(*hdr_pp, hdr.ioc_len); 149 *hdr_pp = kvmalloc(hdr.ioc_len, GFP_KERNEL);
150 if (!*hdr_pp) 150 if (!*hdr_pp)
151 return -ENOMEM; 151 return -ENOMEM;
152 152
@@ -164,7 +164,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
164 return 0; 164 return 0;
165 165
166free: 166free:
167 LIBCFS_FREE(*hdr_pp, hdr.ioc_len); 167 kvfree(*hdr_pp);
168 return err; 168 return err;
169} 169}
170 170
diff --git a/drivers/staging/lustre/lnet/libcfs/module.c b/drivers/staging/lustre/lnet/libcfs/module.c
index 4ead55920e79..a03f924f1d7c 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -156,7 +156,7 @@ int libcfs_ioctl(unsigned long cmd, void __user *uparam)
156 break; } 156 break; }
157 } 157 }
158out: 158out:
159 LIBCFS_FREE(hdr, hdr->ioc_len); 159 kvfree(hdr);
160 return err; 160 return err;
161} 161}
162 162
@@ -302,7 +302,7 @@ static int __proc_cpt_table(void *data, int write,
302 LASSERT(cfs_cpt_table); 302 LASSERT(cfs_cpt_table);
303 303
304 while (1) { 304 while (1) {
305 LIBCFS_ALLOC(buf, len); 305 buf = kzalloc(len, GFP_KERNEL);
306 if (!buf) 306 if (!buf)
307 return -ENOMEM; 307 return -ENOMEM;
308 308
@@ -311,7 +311,7 @@ static int __proc_cpt_table(void *data, int write,
311 break; 311 break;
312 312
313 if (rc == -EFBIG) { 313 if (rc == -EFBIG) {
314 LIBCFS_FREE(buf, len); 314 kfree(buf);
315 len <<= 1; 315 len <<= 1;
316 continue; 316 continue;
317 } 317 }
@@ -325,8 +325,7 @@ static int __proc_cpt_table(void *data, int write,
325 325
326 rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL); 326 rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL);
327 out: 327 out:
328 if (buf) 328 kfree(buf);
329 LIBCFS_FREE(buf, len);
330 return rc; 329 return rc;
331} 330}
332 331
@@ -548,33 +547,23 @@ static int libcfs_init(void)
548 goto cleanup_cpu; 547 goto cleanup_cpu;
549 } 548 }
550 549
551 rc = cfs_wi_startup(); 550 cfs_rehash_wq = alloc_workqueue("cfs_rh", WQ_SYSFS, 4);
552 if (rc) { 551 if (!cfs_rehash_wq) {
553 CERROR("initialize workitem: error %d\n", rc); 552 CERROR("Failed to start rehash workqueue.\n");
554 goto cleanup_deregister; 553 rc = -ENOMEM;
555 }
556
557 /* max to 4 threads, should be enough for rehash */
558 rc = min(cfs_cpt_weight(cfs_cpt_table, CFS_CPT_ANY), 4);
559 rc = cfs_wi_sched_create("cfs_rh", cfs_cpt_table, CFS_CPT_ANY,
560 rc, &cfs_sched_rehash);
561 if (rc) {
562 CERROR("Startup workitem scheduler: error: %d\n", rc);
563 goto cleanup_deregister; 554 goto cleanup_deregister;
564 } 555 }
565 556
566 rc = cfs_crypto_register(); 557 rc = cfs_crypto_register();
567 if (rc) { 558 if (rc) {
568 CERROR("cfs_crypto_register: error %d\n", rc); 559 CERROR("cfs_crypto_register: error %d\n", rc);
569 goto cleanup_wi; 560 goto cleanup_deregister;
570 } 561 }
571 562
572 lustre_insert_debugfs(lnet_table, lnet_debugfs_symlinks); 563 lustre_insert_debugfs(lnet_table, lnet_debugfs_symlinks);
573 564
574 CDEBUG(D_OTHER, "portals setup OK\n"); 565 CDEBUG(D_OTHER, "portals setup OK\n");
575 return 0; 566 return 0;
576 cleanup_wi:
577 cfs_wi_shutdown();
578 cleanup_deregister: 567 cleanup_deregister:
579 misc_deregister(&libcfs_dev); 568 misc_deregister(&libcfs_dev);
580cleanup_cpu: 569cleanup_cpu:
@@ -590,13 +579,12 @@ static void libcfs_exit(void)
590 579
591 lustre_remove_debugfs(); 580 lustre_remove_debugfs();
592 581
593 if (cfs_sched_rehash) { 582 if (cfs_rehash_wq) {
594 cfs_wi_sched_destroy(cfs_sched_rehash); 583 destroy_workqueue(cfs_rehash_wq);
595 cfs_sched_rehash = NULL; 584 cfs_rehash_wq = NULL;
596 } 585 }
597 586
598 cfs_crypto_unregister(); 587 cfs_crypto_unregister();
599 cfs_wi_shutdown();
600 588
601 misc_deregister(&libcfs_dev); 589 misc_deregister(&libcfs_dev);
602 590
diff --git a/drivers/staging/lustre/lnet/libcfs/prng.c b/drivers/staging/lustre/lnet/libcfs/prng.c
deleted file mode 100644
index f47cf67a92e3..000000000000
--- a/drivers/staging/lustre/lnet/libcfs/prng.c
+++ /dev/null
@@ -1,137 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * GPL HEADER START
4 *
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 only,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License version 2 for more details (a copy is included
15 * in the LICENSE file that accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License
18 * version 2 along with this program; If not, see
19 * http://www.gnu.org/licenses/gpl-2.0.html
20 *
21 * GPL HEADER END
22 */
23/*
24 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
25 * Use is subject to license terms.
26 */
27/*
28 * This file is part of Lustre, http://www.lustre.org/
29 * Lustre is a trademark of Sun Microsystems, Inc.
30 *
31 * libcfs/libcfs/prng.c
32 *
33 * concatenation of following two 16-bit multiply with carry generators
34 * x(n)=a*x(n-1)+carry mod 2^16 and y(n)=b*y(n-1)+carry mod 2^16,
35 * number and carry packed within the same 32 bit integer.
36 * algorithm recommended by Marsaglia
37 */
38
39#include <linux/libcfs/libcfs.h>
40
41/*
42 * From: George Marsaglia <geo@stat.fsu.edu>
43 * Newsgroups: sci.math
44 * Subject: Re: A RANDOM NUMBER GENERATOR FOR C
45 * Date: Tue, 30 Sep 1997 05:29:35 -0700
46 *
47 * You may replace the two constants 36969 and 18000 by any
48 * pair of distinct constants from this list:
49 * 18000 18030 18273 18513 18879 19074 19098 19164 19215 19584
50 * 19599 19950 20088 20508 20544 20664 20814 20970 21153 21243
51 * 21423 21723 21954 22125 22188 22293 22860 22938 22965 22974
52 * 23109 23124 23163 23208 23508 23520 23553 23658 23865 24114
53 * 24219 24660 24699 24864 24948 25023 25308 25443 26004 26088
54 * 26154 26550 26679 26838 27183 27258 27753 27795 27810 27834
55 * 27960 28320 28380 28689 28710 28794 28854 28959 28980 29013
56 * 29379 29889 30135 30345 30459 30714 30903 30963 31059 31083
57 * (or any other 16-bit constants k for which both k*2^16-1
58 * and k*2^15-1 are prime)
59 */
60
61#define RANDOM_CONST_A 18030
62#define RANDOM_CONST_B 29013
63
64static unsigned int seed_x = 521288629;
65static unsigned int seed_y = 362436069;
66
67/**
68 * cfs_rand - creates new seeds
69 *
70 * First it creates new seeds from the previous seeds. Then it generates a
71 * new pseudo random number for use.
72 *
73 * Returns a pseudo-random 32-bit integer
74 */
75unsigned int cfs_rand(void)
76{
77 seed_x = RANDOM_CONST_A * (seed_x & 65535) + (seed_x >> 16);
78 seed_y = RANDOM_CONST_B * (seed_y & 65535) + (seed_y >> 16);
79
80 return ((seed_x << 16) + (seed_y & 65535));
81}
82EXPORT_SYMBOL(cfs_rand);
83
84/**
85 * cfs_srand - sets the initial seed
86 * @seed1 : (seed_x) should have the most entropy in the low bits of the word
87 * @seed2 : (seed_y) should have the most entropy in the high bits of the word
88 *
89 * Replaces the original seeds with new values. Used to generate a new pseudo
90 * random numbers.
91 */
92void cfs_srand(unsigned int seed1, unsigned int seed2)
93{
94 if (seed1)
95 seed_x = seed1; /* use default seeds if parameter is 0 */
96 if (seed2)
97 seed_y = seed2;
98}
99EXPORT_SYMBOL(cfs_srand);
100
101/**
102 * cfs_get_random_bytes - generate a bunch of random numbers
103 * @buf : buffer to fill with random numbers
104 * @size: size of passed in buffer
105 *
106 * Fills a buffer with random bytes
107 */
108void cfs_get_random_bytes(void *buf, int size)
109{
110 int *p = buf;
111 int rem, tmp;
112
113 LASSERT(size >= 0);
114
115 rem = min((int)((unsigned long)buf & (sizeof(int) - 1)), size);
116 if (rem) {
117 get_random_bytes(&tmp, sizeof(tmp));
118 tmp ^= cfs_rand();
119 memcpy(buf, &tmp, rem);
120 p = buf + rem;
121 size -= rem;
122 }
123
124 while (size >= sizeof(int)) {
125 get_random_bytes(&tmp, sizeof(tmp));
126 *p = cfs_rand() ^ tmp;
127 size -= sizeof(int);
128 p++;
129 }
130 buf = p;
131 if (size) {
132 get_random_bytes(&tmp, sizeof(tmp));
133 tmp ^= cfs_rand();
134 memcpy(buf, &tmp, size);
135 }
136}
137EXPORT_SYMBOL(cfs_get_random_bytes);
diff --git a/drivers/staging/lustre/lnet/libcfs/tracefile.c b/drivers/staging/lustre/lnet/libcfs/tracefile.c
index da2844f37edf..57913aae1d88 100644
--- a/drivers/staging/lustre/lnet/libcfs/tracefile.c
+++ b/drivers/staging/lustre/lnet/libcfs/tracefile.c
@@ -785,7 +785,7 @@ int cfs_trace_copyin_string(char *knl_buffer, int knl_buffer_nob,
785 return -EFAULT; 785 return -EFAULT;
786 786
787 nob = strnlen(knl_buffer, usr_buffer_nob); 787 nob = strnlen(knl_buffer, usr_buffer_nob);
788 while (nob-- >= 0) /* strip trailing whitespace */ 788 while (--nob >= 0) /* strip trailing whitespace */
789 if (!isspace(knl_buffer[nob])) 789 if (!isspace(knl_buffer[nob]))
790 break; 790 break;
791 791
diff --git a/drivers/staging/lustre/lnet/libcfs/workitem.c b/drivers/staging/lustre/lnet/libcfs/workitem.c
deleted file mode 100644
index 6a05d9bab8dc..000000000000
--- a/drivers/staging/lustre/lnet/libcfs/workitem.c
+++ /dev/null
@@ -1,466 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * GPL HEADER START
4 *
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 only,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License version 2 for more details (a copy is included
15 * in the LICENSE file that accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License
18 * version 2 along with this program; If not, see
19 * http://www.gnu.org/licenses/gpl-2.0.html
20 *
21 * GPL HEADER END
22 */
23/*
24 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
25 * Use is subject to license terms.
26 *
27 * Copyright (c) 2011, 2012, Intel Corporation.
28 */
29/*
30 * This file is part of Lustre, http://www.lustre.org/
31 * Lustre is a trademark of Sun Microsystems, Inc.
32 *
33 * libcfs/libcfs/workitem.c
34 *
35 * Author: Isaac Huang <isaac@clusterfs.com>
36 * Liang Zhen <zhen.liang@sun.com>
37 */
38
39#define DEBUG_SUBSYSTEM S_LNET
40
41#include <linux/libcfs/libcfs.h>
42
43#define CFS_WS_NAME_LEN 16
44
45struct cfs_wi_sched {
46 /* chain on global list */
47 struct list_head ws_list;
48 /** serialised workitems */
49 spinlock_t ws_lock;
50 /** where schedulers sleep */
51 wait_queue_head_t ws_waitq;
52 /** concurrent workitems */
53 struct list_head ws_runq;
54 /**
55 * rescheduled running-workitems, a workitem can be rescheduled
56 * while running in wi_action(), but we don't to execute it again
57 * unless it returns from wi_action(), so we put it on ws_rerunq
58 * while rescheduling, and move it to runq after it returns
59 * from wi_action()
60 */
61 struct list_head ws_rerunq;
62 /** CPT-table for this scheduler */
63 struct cfs_cpt_table *ws_cptab;
64 /** CPT id for affinity */
65 int ws_cpt;
66 /** number of scheduled workitems */
67 int ws_nscheduled;
68 /** started scheduler thread, protected by cfs_wi_data::wi_glock */
69 unsigned int ws_nthreads:30;
70 /** shutting down, protected by cfs_wi_data::wi_glock */
71 unsigned int ws_stopping:1;
72 /** serialize starting thread, protected by cfs_wi_data::wi_glock */
73 unsigned int ws_starting:1;
74 /** scheduler name */
75 char ws_name[CFS_WS_NAME_LEN];
76};
77
78static struct cfs_workitem_data {
79 /** serialize */
80 spinlock_t wi_glock;
81 /** list of all schedulers */
82 struct list_head wi_scheds;
83 /** WI module is initialized */
84 int wi_init;
85 /** shutting down the whole WI module */
86 int wi_stopping;
87} cfs_wi_data;
88
89static inline int
90cfs_wi_sched_cansleep(struct cfs_wi_sched *sched)
91{
92 spin_lock(&sched->ws_lock);
93 if (sched->ws_stopping) {
94 spin_unlock(&sched->ws_lock);
95 return 0;
96 }
97
98 if (!list_empty(&sched->ws_runq)) {
99 spin_unlock(&sched->ws_lock);
100 return 0;
101 }
102 spin_unlock(&sched->ws_lock);
103 return 1;
104}
105
106/* XXX:
107 * 0. it only works when called from wi->wi_action.
108 * 1. when it returns no one shall try to schedule the workitem.
109 */
110void
111cfs_wi_exit(struct cfs_wi_sched *sched, struct cfs_workitem *wi)
112{
113 LASSERT(!in_interrupt()); /* because we use plain spinlock */
114 LASSERT(!sched->ws_stopping);
115
116 spin_lock(&sched->ws_lock);
117
118 LASSERT(wi->wi_running);
119 if (wi->wi_scheduled) { /* cancel pending schedules */
120 LASSERT(!list_empty(&wi->wi_list));
121 list_del_init(&wi->wi_list);
122
123 LASSERT(sched->ws_nscheduled > 0);
124 sched->ws_nscheduled--;
125 }
126
127 LASSERT(list_empty(&wi->wi_list));
128
129 wi->wi_scheduled = 1; /* LBUG future schedule attempts */
130 spin_unlock(&sched->ws_lock);
131}
132EXPORT_SYMBOL(cfs_wi_exit);
133
134/**
135 * cancel schedule request of workitem \a wi
136 */
137int
138cfs_wi_deschedule(struct cfs_wi_sched *sched, struct cfs_workitem *wi)
139{
140 int rc;
141
142 LASSERT(!in_interrupt()); /* because we use plain spinlock */
143 LASSERT(!sched->ws_stopping);
144
145 /*
146 * return 0 if it's running already, otherwise return 1, which
147 * means the workitem will not be scheduled and will not have
148 * any race with wi_action.
149 */
150 spin_lock(&sched->ws_lock);
151
152 rc = !(wi->wi_running);
153
154 if (wi->wi_scheduled) { /* cancel pending schedules */
155 LASSERT(!list_empty(&wi->wi_list));
156 list_del_init(&wi->wi_list);
157
158 LASSERT(sched->ws_nscheduled > 0);
159 sched->ws_nscheduled--;
160
161 wi->wi_scheduled = 0;
162 }
163
164 LASSERT(list_empty(&wi->wi_list));
165
166 spin_unlock(&sched->ws_lock);
167 return rc;
168}
169EXPORT_SYMBOL(cfs_wi_deschedule);
170
171/*
172 * Workitem scheduled with (serial == 1) is strictly serialised not only with
173 * itself, but also with others scheduled this way.
174 *
175 * Now there's only one static serialised queue, but in the future more might
176 * be added, and even dynamic creation of serialised queues might be supported.
177 */
178void
179cfs_wi_schedule(struct cfs_wi_sched *sched, struct cfs_workitem *wi)
180{
181 LASSERT(!in_interrupt()); /* because we use plain spinlock */
182 LASSERT(!sched->ws_stopping);
183
184 spin_lock(&sched->ws_lock);
185
186 if (!wi->wi_scheduled) {
187 LASSERT(list_empty(&wi->wi_list));
188
189 wi->wi_scheduled = 1;
190 sched->ws_nscheduled++;
191 if (!wi->wi_running) {
192 list_add_tail(&wi->wi_list, &sched->ws_runq);
193 wake_up(&sched->ws_waitq);
194 } else {
195 list_add(&wi->wi_list, &sched->ws_rerunq);
196 }
197 }
198
199 LASSERT(!list_empty(&wi->wi_list));
200 spin_unlock(&sched->ws_lock);
201}
202EXPORT_SYMBOL(cfs_wi_schedule);
203
204static int cfs_wi_scheduler(void *arg)
205{
206 struct cfs_wi_sched *sched = (struct cfs_wi_sched *)arg;
207
208 cfs_block_allsigs();
209
210 /* CPT affinity scheduler? */
211 if (sched->ws_cptab)
212 if (cfs_cpt_bind(sched->ws_cptab, sched->ws_cpt))
213 CWARN("Unable to bind %s on CPU partition %d\n",
214 sched->ws_name, sched->ws_cpt);
215
216 spin_lock(&cfs_wi_data.wi_glock);
217
218 LASSERT(sched->ws_starting == 1);
219 sched->ws_starting--;
220 sched->ws_nthreads++;
221
222 spin_unlock(&cfs_wi_data.wi_glock);
223
224 spin_lock(&sched->ws_lock);
225
226 while (!sched->ws_stopping) {
227 int nloops = 0;
228 int rc;
229 struct cfs_workitem *wi;
230
231 while (!list_empty(&sched->ws_runq) &&
232 nloops < CFS_WI_RESCHED) {
233 wi = list_entry(sched->ws_runq.next,
234 struct cfs_workitem, wi_list);
235 LASSERT(wi->wi_scheduled && !wi->wi_running);
236
237 list_del_init(&wi->wi_list);
238
239 LASSERT(sched->ws_nscheduled > 0);
240 sched->ws_nscheduled--;
241
242 wi->wi_running = 1;
243 wi->wi_scheduled = 0;
244
245 spin_unlock(&sched->ws_lock);
246 nloops++;
247
248 rc = (*wi->wi_action)(wi);
249
250 spin_lock(&sched->ws_lock);
251 if (rc) /* WI should be dead, even be freed! */
252 continue;
253
254 wi->wi_running = 0;
255 if (list_empty(&wi->wi_list))
256 continue;
257
258 LASSERT(wi->wi_scheduled);
259 /* wi is rescheduled, should be on rerunq now, we
260 * move it to runq so it can run action now
261 */
262 list_move_tail(&wi->wi_list, &sched->ws_runq);
263 }
264
265 if (!list_empty(&sched->ws_runq)) {
266 spin_unlock(&sched->ws_lock);
267 /* don't sleep because some workitems still
268 * expect me to come back soon
269 */
270 cond_resched();
271 spin_lock(&sched->ws_lock);
272 continue;
273 }
274
275 spin_unlock(&sched->ws_lock);
276 rc = wait_event_interruptible_exclusive(sched->ws_waitq,
277 !cfs_wi_sched_cansleep(sched));
278 spin_lock(&sched->ws_lock);
279 }
280
281 spin_unlock(&sched->ws_lock);
282
283 spin_lock(&cfs_wi_data.wi_glock);
284 sched->ws_nthreads--;
285 spin_unlock(&cfs_wi_data.wi_glock);
286
287 return 0;
288}
289
290void
291cfs_wi_sched_destroy(struct cfs_wi_sched *sched)
292{
293 int i;
294
295 LASSERT(cfs_wi_data.wi_init);
296 LASSERT(!cfs_wi_data.wi_stopping);
297
298 spin_lock(&cfs_wi_data.wi_glock);
299 if (sched->ws_stopping) {
300 CDEBUG(D_INFO, "%s is in progress of stopping\n",
301 sched->ws_name);
302 spin_unlock(&cfs_wi_data.wi_glock);
303 return;
304 }
305
306 LASSERT(!list_empty(&sched->ws_list));
307 sched->ws_stopping = 1;
308
309 spin_unlock(&cfs_wi_data.wi_glock);
310
311 i = 2;
312 wake_up_all(&sched->ws_waitq);
313
314 spin_lock(&cfs_wi_data.wi_glock);
315 while (sched->ws_nthreads > 0) {
316 CDEBUG(is_power_of_2(++i) ? D_WARNING : D_NET,
317 "waiting for %d threads of WI sched[%s] to terminate\n",
318 sched->ws_nthreads, sched->ws_name);
319
320 spin_unlock(&cfs_wi_data.wi_glock);
321 set_current_state(TASK_UNINTERRUPTIBLE);
322 schedule_timeout(cfs_time_seconds(1) / 20);
323 spin_lock(&cfs_wi_data.wi_glock);
324 }
325
326 list_del(&sched->ws_list);
327
328 spin_unlock(&cfs_wi_data.wi_glock);
329 LASSERT(!sched->ws_nscheduled);
330
331 LIBCFS_FREE(sched, sizeof(*sched));
332}
333EXPORT_SYMBOL(cfs_wi_sched_destroy);
334
335int
336cfs_wi_sched_create(char *name, struct cfs_cpt_table *cptab,
337 int cpt, int nthrs, struct cfs_wi_sched **sched_pp)
338{
339 struct cfs_wi_sched *sched;
340 int rc;
341
342 LASSERT(cfs_wi_data.wi_init);
343 LASSERT(!cfs_wi_data.wi_stopping);
344 LASSERT(!cptab || cpt == CFS_CPT_ANY ||
345 (cpt >= 0 && cpt < cfs_cpt_number(cptab)));
346
347 LIBCFS_ALLOC(sched, sizeof(*sched));
348 if (!sched)
349 return -ENOMEM;
350
351 if (strlen(name) > sizeof(sched->ws_name) - 1) {
352 LIBCFS_FREE(sched, sizeof(*sched));
353 return -E2BIG;
354 }
355 strncpy(sched->ws_name, name, sizeof(sched->ws_name));
356
357 sched->ws_cptab = cptab;
358 sched->ws_cpt = cpt;
359
360 spin_lock_init(&sched->ws_lock);
361 init_waitqueue_head(&sched->ws_waitq);
362 INIT_LIST_HEAD(&sched->ws_runq);
363 INIT_LIST_HEAD(&sched->ws_rerunq);
364 INIT_LIST_HEAD(&sched->ws_list);
365
366 rc = 0;
367 while (nthrs > 0) {
368 char name[16];
369 struct task_struct *task;
370
371 spin_lock(&cfs_wi_data.wi_glock);
372 while (sched->ws_starting > 0) {
373 spin_unlock(&cfs_wi_data.wi_glock);
374 schedule();
375 spin_lock(&cfs_wi_data.wi_glock);
376 }
377
378 sched->ws_starting++;
379 spin_unlock(&cfs_wi_data.wi_glock);
380
381 if (sched->ws_cptab && sched->ws_cpt >= 0) {
382 snprintf(name, sizeof(name), "%s_%02d_%02u",
383 sched->ws_name, sched->ws_cpt,
384 sched->ws_nthreads);
385 } else {
386 snprintf(name, sizeof(name), "%s_%02u",
387 sched->ws_name, sched->ws_nthreads);
388 }
389
390 task = kthread_run(cfs_wi_scheduler, sched, "%s", name);
391 if (!IS_ERR(task)) {
392 nthrs--;
393 continue;
394 }
395 rc = PTR_ERR(task);
396
397 CERROR("Failed to create thread for WI scheduler %s: %d\n",
398 name, rc);
399
400 spin_lock(&cfs_wi_data.wi_glock);
401
402 /* make up for cfs_wi_sched_destroy */
403 list_add(&sched->ws_list, &cfs_wi_data.wi_scheds);
404 sched->ws_starting--;
405
406 spin_unlock(&cfs_wi_data.wi_glock);
407
408 cfs_wi_sched_destroy(sched);
409 return rc;
410 }
411 spin_lock(&cfs_wi_data.wi_glock);
412 list_add(&sched->ws_list, &cfs_wi_data.wi_scheds);
413 spin_unlock(&cfs_wi_data.wi_glock);
414
415 *sched_pp = sched;
416 return 0;
417}
418EXPORT_SYMBOL(cfs_wi_sched_create);
419
420int
421cfs_wi_startup(void)
422{
423 memset(&cfs_wi_data, 0, sizeof(cfs_wi_data));
424
425 spin_lock_init(&cfs_wi_data.wi_glock);
426 INIT_LIST_HEAD(&cfs_wi_data.wi_scheds);
427 cfs_wi_data.wi_init = 1;
428
429 return 0;
430}
431
432void
433cfs_wi_shutdown(void)
434{
435 struct cfs_wi_sched *sched;
436 struct cfs_wi_sched *temp;
437
438 spin_lock(&cfs_wi_data.wi_glock);
439 cfs_wi_data.wi_stopping = 1;
440 spin_unlock(&cfs_wi_data.wi_glock);
441
442 /* nobody should contend on this list */
443 list_for_each_entry(sched, &cfs_wi_data.wi_scheds, ws_list) {
444 sched->ws_stopping = 1;
445 wake_up_all(&sched->ws_waitq);
446 }
447
448 list_for_each_entry(sched, &cfs_wi_data.wi_scheds, ws_list) {
449 spin_lock(&cfs_wi_data.wi_glock);
450
451 while (sched->ws_nthreads) {
452 spin_unlock(&cfs_wi_data.wi_glock);
453 set_current_state(TASK_UNINTERRUPTIBLE);
454 schedule_timeout(cfs_time_seconds(1) / 20);
455 spin_lock(&cfs_wi_data.wi_glock);
456 }
457 spin_unlock(&cfs_wi_data.wi_glock);
458 }
459 list_for_each_entry_safe(sched, temp, &cfs_wi_data.wi_scheds, ws_list) {
460 list_del(&sched->ws_list);
461 LIBCFS_FREE(sched, sizeof(*sched));
462 }
463
464 cfs_wi_data.wi_stopping = 0;
465 cfs_wi_data.wi_init = 0;
466}
diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c
index 7caff290c146..2c7abad57104 100644
--- a/drivers/staging/lustre/lnet/lnet/api-ni.c
+++ b/drivers/staging/lustre/lnet/lnet/api-ni.c
@@ -108,7 +108,8 @@ lnet_create_remote_nets_table(void)
108 108
109 LASSERT(!the_lnet.ln_remote_nets_hash); 109 LASSERT(!the_lnet.ln_remote_nets_hash);
110 LASSERT(the_lnet.ln_remote_nets_hbits > 0); 110 LASSERT(the_lnet.ln_remote_nets_hbits > 0);
111 LIBCFS_ALLOC(hash, LNET_REMOTE_NETS_HASH_SIZE * sizeof(*hash)); 111 hash = kvmalloc_array(LNET_REMOTE_NETS_HASH_SIZE, sizeof(*hash),
112 GFP_KERNEL);
112 if (!hash) { 113 if (!hash) {
113 CERROR("Failed to create remote nets hash table\n"); 114 CERROR("Failed to create remote nets hash table\n");
114 return -ENOMEM; 115 return -ENOMEM;
@@ -131,9 +132,7 @@ lnet_destroy_remote_nets_table(void)
131 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) 132 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
132 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i])); 133 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
133 134
134 LIBCFS_FREE(the_lnet.ln_remote_nets_hash, 135 kvfree(the_lnet.ln_remote_nets_hash);
135 LNET_REMOTE_NETS_HASH_SIZE *
136 sizeof(the_lnet.ln_remote_nets_hash[0]));
137 the_lnet.ln_remote_nets_hash = NULL; 136 the_lnet.ln_remote_nets_hash = NULL;
138} 137}
139 138
@@ -384,10 +383,10 @@ lnet_res_container_cleanup(struct lnet_res_container *rec)
384 383
385 list_del_init(e); 384 list_del_init(e);
386 if (rec->rec_type == LNET_COOKIE_TYPE_EQ) { 385 if (rec->rec_type == LNET_COOKIE_TYPE_EQ) {
387 lnet_eq_free(list_entry(e, struct lnet_eq, eq_list)); 386 kfree(list_entry(e, struct lnet_eq, eq_list));
388 387
389 } else if (rec->rec_type == LNET_COOKIE_TYPE_MD) { 388 } else if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
390 lnet_md_free(list_entry(e, struct lnet_libmd, md_list)); 389 kfree(list_entry(e, struct lnet_libmd, md_list));
391 390
392 } else { /* NB: Active MEs should be attached on portals */ 391 } else { /* NB: Active MEs should be attached on portals */
393 LBUG(); 392 LBUG();
@@ -405,11 +404,8 @@ lnet_res_container_cleanup(struct lnet_res_container *rec)
405 count, lnet_res_type2str(rec->rec_type)); 404 count, lnet_res_type2str(rec->rec_type));
406 } 405 }
407 406
408 if (rec->rec_lh_hash) { 407 kfree(rec->rec_lh_hash);
409 LIBCFS_FREE(rec->rec_lh_hash, 408 rec->rec_lh_hash = NULL;
410 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
411 rec->rec_lh_hash = NULL;
412 }
413 409
414 rec->rec_type = 0; /* mark it as finalized */ 410 rec->rec_type = 0; /* mark it as finalized */
415} 411}
@@ -427,8 +423,8 @@ lnet_res_container_setup(struct lnet_res_container *rec, int cpt, int type)
427 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type; 423 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type;
428 424
429 /* Arbitrary choice of hash table size */ 425 /* Arbitrary choice of hash table size */
430 LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt, 426 rec->rec_lh_hash = kvmalloc_cpt(LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]),
431 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0])); 427 GFP_KERNEL, cpt);
432 if (!rec->rec_lh_hash) { 428 if (!rec->rec_lh_hash) {
433 rc = -ENOMEM; 429 rc = -ENOMEM;
434 goto out; 430 goto out;
@@ -831,7 +827,7 @@ lnet_ping_info_create(int num_ni)
831 unsigned int infosz; 827 unsigned int infosz;
832 828
833 infosz = offsetof(struct lnet_ping_info, pi_ni[num_ni]); 829 infosz = offsetof(struct lnet_ping_info, pi_ni[num_ni]);
834 LIBCFS_ALLOC(ping_info, infosz); 830 ping_info = kvzalloc(infosz, GFP_KERNEL);
835 if (!ping_info) { 831 if (!ping_info) {
836 CERROR("Can't allocate ping info[%d]\n", num_ni); 832 CERROR("Can't allocate ping info[%d]\n", num_ni);
837 return NULL; 833 return NULL;
@@ -864,9 +860,7 @@ lnet_get_ni_count(void)
864static inline void 860static inline void
865lnet_ping_info_free(struct lnet_ping_info *pinfo) 861lnet_ping_info_free(struct lnet_ping_info *pinfo)
866{ 862{
867 LIBCFS_FREE(pinfo, 863 kvfree(pinfo);
868 offsetof(struct lnet_ping_info,
869 pi_ni[pinfo->pi_nnis]));
870} 864}
871 865
872static void 866static void
@@ -1280,8 +1274,8 @@ lnet_startup_lndni(struct lnet_ni *ni, struct lnet_ioctl_config_data *conf)
1280 lnd_tunables = (struct lnet_ioctl_config_lnd_tunables *)conf->cfg_bulk; 1274 lnd_tunables = (struct lnet_ioctl_config_lnd_tunables *)conf->cfg_bulk;
1281 1275
1282 if (lnd_tunables) { 1276 if (lnd_tunables) {
1283 LIBCFS_ALLOC(ni->ni_lnd_tunables, 1277 ni->ni_lnd_tunables = kzalloc(sizeof(*ni->ni_lnd_tunables),
1284 sizeof(*ni->ni_lnd_tunables)); 1278 GFP_NOFS);
1285 if (!ni->ni_lnd_tunables) { 1279 if (!ni->ni_lnd_tunables) {
1286 mutex_unlock(&the_lnet.ln_lnd_mutex); 1280 mutex_unlock(&the_lnet.ln_lnd_mutex);
1287 rc = -ENOMEM; 1281 rc = -ENOMEM;
@@ -2160,7 +2154,7 @@ static int lnet_ping(struct lnet_process_id id, int timeout_ms,
2160 if (id.pid == LNET_PID_ANY) 2154 if (id.pid == LNET_PID_ANY)
2161 id.pid = LNET_PID_LUSTRE; 2155 id.pid = LNET_PID_LUSTRE;
2162 2156
2163 LIBCFS_ALLOC(info, infosz); 2157 info = kzalloc(infosz, GFP_KERNEL);
2164 if (!info) 2158 if (!info)
2165 return -ENOMEM; 2159 return -ENOMEM;
2166 2160
@@ -2310,6 +2304,6 @@ static int lnet_ping(struct lnet_process_id id, int timeout_ms,
2310 LASSERT(!rc2); 2304 LASSERT(!rc2);
2311 2305
2312 out_0: 2306 out_0:
2313 LIBCFS_FREE(info, infosz); 2307 kfree(info);
2314 return rc; 2308 return rc;
2315} 2309}
diff --git a/drivers/staging/lustre/lnet/lnet/config.c b/drivers/staging/lustre/lnet/lnet/config.c
index 0cf0f4f99435..0aea268a4f1c 100644
--- a/drivers/staging/lustre/lnet/lnet/config.c
+++ b/drivers/staging/lustre/lnet/lnet/config.c
@@ -106,19 +106,16 @@ lnet_ni_free(struct lnet_ni *ni)
106 if (ni->ni_cpts) 106 if (ni->ni_cpts)
107 cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts); 107 cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
108 108
109 if (ni->ni_lnd_tunables) 109 kfree(ni->ni_lnd_tunables);
110 LIBCFS_FREE(ni->ni_lnd_tunables, sizeof(*ni->ni_lnd_tunables));
111 110
112 for (i = 0; i < LNET_MAX_INTERFACES && ni->ni_interfaces[i]; i++) { 111 for (i = 0; i < LNET_MAX_INTERFACES && ni->ni_interfaces[i]; i++)
113 LIBCFS_FREE(ni->ni_interfaces[i], 112 kfree(ni->ni_interfaces[i]);
114 strlen(ni->ni_interfaces[i]) + 1);
115 }
116 113
117 /* release reference to net namespace */ 114 /* release reference to net namespace */
118 if (ni->ni_net_ns) 115 if (ni->ni_net_ns)
119 put_net(ni->ni_net_ns); 116 put_net(ni->ni_net_ns);
120 117
121 LIBCFS_FREE(ni, sizeof(*ni)); 118 kfree(ni);
122} 119}
123 120
124struct lnet_ni * 121struct lnet_ni *
@@ -135,7 +132,7 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
135 return NULL; 132 return NULL;
136 } 133 }
137 134
138 LIBCFS_ALLOC(ni, sizeof(*ni)); 135 ni = kzalloc(sizeof(*ni), GFP_NOFS);
139 if (!ni) { 136 if (!ni) {
140 CERROR("Out of memory creating network %s\n", 137 CERROR("Out of memory creating network %s\n",
141 libcfs_net2str(net)); 138 libcfs_net2str(net));
@@ -170,7 +167,7 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
170 167
171 LASSERT(rc <= LNET_CPT_NUMBER); 168 LASSERT(rc <= LNET_CPT_NUMBER);
172 if (rc == LNET_CPT_NUMBER) { 169 if (rc == LNET_CPT_NUMBER) {
173 LIBCFS_FREE(ni->ni_cpts, rc * sizeof(ni->ni_cpts[0])); 170 cfs_expr_list_values_free(ni->ni_cpts, LNET_CPT_NUMBER);
174 ni->ni_cpts = NULL; 171 ni->ni_cpts = NULL;
175 } 172 }
176 173
@@ -198,7 +195,6 @@ int
198lnet_parse_networks(struct list_head *nilist, char *networks) 195lnet_parse_networks(struct list_head *nilist, char *networks)
199{ 196{
200 struct cfs_expr_list *el = NULL; 197 struct cfs_expr_list *el = NULL;
201 int tokensize;
202 char *tokens; 198 char *tokens;
203 char *str; 199 char *str;
204 char *tmp; 200 char *tmp;
@@ -219,15 +215,12 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
219 return -EINVAL; 215 return -EINVAL;
220 } 216 }
221 217
222 tokensize = strlen(networks) + 1; 218 tokens = kstrdup(networks, GFP_KERNEL);
223
224 LIBCFS_ALLOC(tokens, tokensize);
225 if (!tokens) { 219 if (!tokens) {
226 CERROR("Can't allocate net tokens\n"); 220 CERROR("Can't allocate net tokens\n");
227 return -ENOMEM; 221 return -ENOMEM;
228 } 222 }
229 223
230 memcpy(tokens, networks, tokensize);
231 tmp = tokens; 224 tmp = tokens;
232 str = tokens; 225 str = tokens;
233 226
@@ -275,7 +268,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
275 268
276 if (comma) 269 if (comma)
277 *comma++ = 0; 270 *comma++ = 0;
278 net = libcfs_str2net(cfs_trimwhite(str)); 271 net = libcfs_str2net(strim(str));
279 272
280 if (net == LNET_NIDNET(LNET_NID_ANY)) { 273 if (net == LNET_NIDNET(LNET_NID_ANY)) {
281 LCONSOLE_ERROR_MSG(0x113, 274 LCONSOLE_ERROR_MSG(0x113,
@@ -298,7 +291,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
298 } 291 }
299 292
300 *bracket = 0; 293 *bracket = 0;
301 net = libcfs_str2net(cfs_trimwhite(str)); 294 net = libcfs_str2net(strim(str));
302 if (net == LNET_NIDNET(LNET_NID_ANY)) { 295 if (net == LNET_NIDNET(LNET_NID_ANY)) {
303 tmp = str; 296 tmp = str;
304 goto failed_syntax; 297 goto failed_syntax;
@@ -328,7 +321,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
328 if (comma) 321 if (comma)
329 *comma++ = 0; 322 *comma++ = 0;
330 323
331 iface = cfs_trimwhite(iface); 324 iface = strim(iface);
332 if (!*iface) { 325 if (!*iface) {
333 tmp = iface; 326 tmp = iface;
334 goto failed_syntax; 327 goto failed_syntax;
@@ -349,14 +342,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
349 * The newly allocated ni_interfaces[] can be 342 * The newly allocated ni_interfaces[] can be
350 * freed when freeing the NI 343 * freed when freeing the NI
351 */ 344 */
352 LIBCFS_ALLOC(ni->ni_interfaces[niface], 345 ni->ni_interfaces[niface] = kstrdup(iface, GFP_KERNEL);
353 strlen(iface) + 1);
354 if (!ni->ni_interfaces[niface]) { 346 if (!ni->ni_interfaces[niface]) {
355 CERROR("Can't allocate net interface name\n"); 347 CERROR("Can't allocate net interface name\n");
356 goto failed; 348 goto failed;
357 } 349 }
358 strncpy(ni->ni_interfaces[niface], iface,
359 strlen(iface));
360 niface++; 350 niface++;
361 iface = comma; 351 iface = comma;
362 } while (iface); 352 } while (iface);
@@ -365,7 +355,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
365 comma = strchr(bracket + 1, ','); 355 comma = strchr(bracket + 1, ',');
366 if (comma) { 356 if (comma) {
367 *comma = 0; 357 *comma = 0;
368 str = cfs_trimwhite(str); 358 str = strim(str);
369 if (*str) { 359 if (*str) {
370 tmp = str; 360 tmp = str;
371 goto failed_syntax; 361 goto failed_syntax;
@@ -374,7 +364,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
374 continue; 364 continue;
375 } 365 }
376 366
377 str = cfs_trimwhite(str); 367 str = strim(str);
378 if (*str) { 368 if (*str) {
379 tmp = str; 369 tmp = str;
380 goto failed_syntax; 370 goto failed_syntax;
@@ -384,7 +374,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
384 list_for_each(temp_node, nilist) 374 list_for_each(temp_node, nilist)
385 nnets++; 375 nnets++;
386 376
387 LIBCFS_FREE(tokens, tokensize); 377 kfree(tokens);
388 return nnets; 378 return nnets;
389 379
390 failed_syntax: 380 failed_syntax:
@@ -400,7 +390,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
400 if (el) 390 if (el)
401 cfs_expr_list_free(el); 391 cfs_expr_list_free(el);
402 392
403 LIBCFS_FREE(tokens, tokensize); 393 kfree(tokens);
404 394
405 return -EINVAL; 395 return -EINVAL;
406} 396}
@@ -424,7 +414,7 @@ lnet_new_text_buf(int str_len)
424 return NULL; 414 return NULL;
425 } 415 }
426 416
427 LIBCFS_ALLOC(ltb, nob); 417 ltb = kzalloc(nob, GFP_KERNEL);
428 if (!ltb) 418 if (!ltb)
429 return NULL; 419 return NULL;
430 420
@@ -438,7 +428,7 @@ static void
438lnet_free_text_buf(struct lnet_text_buf *ltb) 428lnet_free_text_buf(struct lnet_text_buf *ltb)
439{ 429{
440 lnet_tbnob -= ltb->ltb_size; 430 lnet_tbnob -= ltb->ltb_size;
441 LIBCFS_FREE(ltb, ltb->ltb_size); 431 kfree(ltb);
442} 432}
443 433
444static void 434static void
@@ -1156,7 +1146,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp)
1156 if (nif <= 0) 1146 if (nif <= 0)
1157 return nif; 1147 return nif;
1158 1148
1159 LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs)); 1149 ipaddrs = kcalloc(nif, sizeof(*ipaddrs), GFP_KERNEL);
1160 if (!ipaddrs) { 1150 if (!ipaddrs) {
1161 CERROR("Can't allocate ipaddrs[%d]\n", nif); 1151 CERROR("Can't allocate ipaddrs[%d]\n", nif);
1162 lnet_ipif_free_enumeration(ifnames, nif); 1152 lnet_ipif_free_enumeration(ifnames, nif);
@@ -1189,7 +1179,8 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp)
1189 *ipaddrsp = ipaddrs; 1179 *ipaddrsp = ipaddrs;
1190 } else { 1180 } else {
1191 if (nip > 0) { 1181 if (nip > 0) {
1192 LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2)); 1182 ipaddrs2 = kcalloc(nip, sizeof(*ipaddrs2),
1183 GFP_KERNEL);
1193 if (!ipaddrs2) { 1184 if (!ipaddrs2) {
1194 CERROR("Can't allocate ipaddrs[%d]\n", nip); 1185 CERROR("Can't allocate ipaddrs[%d]\n", nip);
1195 nip = -ENOMEM; 1186 nip = -ENOMEM;
@@ -1200,7 +1191,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp)
1200 rc = nip; 1191 rc = nip;
1201 } 1192 }
1202 } 1193 }
1203 LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); 1194 kfree(ipaddrs);
1204 } 1195 }
1205 return nip; 1196 return nip;
1206} 1197}
@@ -1226,7 +1217,7 @@ lnet_parse_ip2nets(char **networksp, char *ip2nets)
1226 } 1217 }
1227 1218
1228 rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip); 1219 rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
1229 LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); 1220 kfree(ipaddrs);
1230 1221
1231 if (rc < 0) { 1222 if (rc < 0) {
1232 LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc); 1223 LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc);
diff --git a/drivers/staging/lustre/lnet/lnet/lib-eq.c b/drivers/staging/lustre/lnet/lnet/lib-eq.c
index daf744277003..a173b69e2f92 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-eq.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-eq.c
@@ -90,12 +90,13 @@ LNetEQAlloc(unsigned int count, lnet_eq_handler_t callback,
90 if (!count && callback == LNET_EQ_HANDLER_NONE) 90 if (!count && callback == LNET_EQ_HANDLER_NONE)
91 return -EINVAL; 91 return -EINVAL;
92 92
93 eq = lnet_eq_alloc(); 93 eq = kzalloc(sizeof(*eq), GFP_NOFS);
94 if (!eq) 94 if (!eq)
95 return -ENOMEM; 95 return -ENOMEM;
96 96
97 if (count) { 97 if (count) {
98 LIBCFS_ALLOC(eq->eq_events, count * sizeof(struct lnet_event)); 98 eq->eq_events = kvmalloc_array(count, sizeof(struct lnet_event),
99 GFP_KERNEL | __GFP_ZERO);
99 if (!eq->eq_events) 100 if (!eq->eq_events)
100 goto failed; 101 goto failed;
101 /* 102 /*
@@ -132,13 +133,12 @@ LNetEQAlloc(unsigned int count, lnet_eq_handler_t callback,
132 return 0; 133 return 0;
133 134
134failed: 135failed:
135 if (eq->eq_events) 136 kvfree(eq->eq_events);
136 LIBCFS_FREE(eq->eq_events, count * sizeof(struct lnet_event));
137 137
138 if (eq->eq_refs) 138 if (eq->eq_refs)
139 cfs_percpt_free(eq->eq_refs); 139 cfs_percpt_free(eq->eq_refs);
140 140
141 lnet_eq_free(eq); 141 kfree(eq);
142 return -ENOMEM; 142 return -ENOMEM;
143} 143}
144EXPORT_SYMBOL(LNetEQAlloc); 144EXPORT_SYMBOL(LNetEQAlloc);
@@ -197,13 +197,12 @@ LNetEQFree(struct lnet_handle_eq eqh)
197 197
198 lnet_res_lh_invalidate(&eq->eq_lh); 198 lnet_res_lh_invalidate(&eq->eq_lh);
199 list_del(&eq->eq_list); 199 list_del(&eq->eq_list);
200 lnet_eq_free(eq); 200 kfree(eq);
201 out: 201 out:
202 lnet_eq_wait_unlock(); 202 lnet_eq_wait_unlock();
203 lnet_res_unlock(LNET_LOCK_EX); 203 lnet_res_unlock(LNET_LOCK_EX);
204 204
205 if (events) 205 kvfree(events);
206 LIBCFS_FREE(events, size * sizeof(struct lnet_event));
207 if (refs) 206 if (refs)
208 cfs_percpt_free(refs); 207 cfs_percpt_free(refs);
209 208
diff --git a/drivers/staging/lustre/lnet/lnet/lib-md.c b/drivers/staging/lustre/lnet/lnet/lib-md.c
index ac5b9593d597..8a22514aaf71 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-md.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-md.c
@@ -81,7 +81,7 @@ lnet_md_unlink(struct lnet_libmd *md)
81 81
82 LASSERT(!list_empty(&md->md_list)); 82 LASSERT(!list_empty(&md->md_list));
83 list_del_init(&md->md_list); 83 list_del_init(&md->md_list);
84 lnet_md_free(md); 84 kfree(md);
85} 85}
86 86
87static int 87static int
@@ -173,7 +173,7 @@ lnet_md_link(struct lnet_libmd *md, struct lnet_handle_eq eq_handle, int cpt)
173 /* 173 /*
174 * NB we are passed an allocated, but inactive md. 174 * NB we are passed an allocated, but inactive md.
175 * if we return success, caller may lnet_md_unlink() it. 175 * if we return success, caller may lnet_md_unlink() it.
176 * otherwise caller may only lnet_md_free() it. 176 * otherwise caller may only kfree() it.
177 */ 177 */
178 /* 178 /*
179 * This implementation doesn't know how to create START events or 179 * This implementation doesn't know how to create START events or
@@ -329,7 +329,7 @@ LNetMDAttach(struct lnet_handle_me meh, struct lnet_md umd,
329out_unlock: 329out_unlock:
330 lnet_res_unlock(cpt); 330 lnet_res_unlock(cpt);
331out_free: 331out_free:
332 lnet_md_free(md); 332 kfree(md);
333 return rc; 333 return rc;
334} 334}
335EXPORT_SYMBOL(LNetMDAttach); 335EXPORT_SYMBOL(LNetMDAttach);
@@ -390,7 +390,7 @@ LNetMDBind(struct lnet_md umd, enum lnet_unlink unlink,
390out_unlock: 390out_unlock:
391 lnet_res_unlock(cpt); 391 lnet_res_unlock(cpt);
392out_free: 392out_free:
393 lnet_md_free(md); 393 kfree(md);
394 394
395 return rc; 395 return rc;
396} 396}
diff --git a/drivers/staging/lustre/lnet/lnet/lib-me.c b/drivers/staging/lustre/lnet/lnet/lib-me.c
index dd5d3cf6d3e2..672e37bdd045 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-me.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-me.c
@@ -90,7 +90,7 @@ LNetMEAttach(unsigned int portal,
90 if (!mtable) /* can't match portal type */ 90 if (!mtable) /* can't match portal type */
91 return -EPERM; 91 return -EPERM;
92 92
93 me = lnet_me_alloc(); 93 me = kzalloc(sizeof(*me), GFP_NOFS);
94 if (!me) 94 if (!me)
95 return -ENOMEM; 95 return -ENOMEM;
96 96
@@ -157,7 +157,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,
157 if (pos == LNET_INS_LOCAL) 157 if (pos == LNET_INS_LOCAL)
158 return -EPERM; 158 return -EPERM;
159 159
160 new_me = lnet_me_alloc(); 160 new_me = kzalloc(sizeof(*new_me), GFP_NOFS);
161 if (!new_me) 161 if (!new_me)
162 return -ENOMEM; 162 return -ENOMEM;
163 163
@@ -167,7 +167,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,
167 167
168 current_me = lnet_handle2me(&current_meh); 168 current_me = lnet_handle2me(&current_meh);
169 if (!current_me) { 169 if (!current_me) {
170 lnet_me_free(new_me); 170 kfree(new_me);
171 171
172 lnet_res_unlock(cpt); 172 lnet_res_unlock(cpt);
173 return -ENOENT; 173 return -ENOENT;
@@ -178,7 +178,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,
178 ptl = the_lnet.ln_portals[current_me->me_portal]; 178 ptl = the_lnet.ln_portals[current_me->me_portal];
179 if (lnet_ptl_is_unique(ptl)) { 179 if (lnet_ptl_is_unique(ptl)) {
180 /* nosense to insertion on unique portal */ 180 /* nosense to insertion on unique portal */
181 lnet_me_free(new_me); 181 kfree(new_me);
182 lnet_res_unlock(cpt); 182 lnet_res_unlock(cpt);
183 return -EPERM; 183 return -EPERM;
184 } 184 }
@@ -270,5 +270,5 @@ lnet_me_unlink(struct lnet_me *me)
270 } 270 }
271 271
272 lnet_res_lh_invalidate(&me->me_lh); 272 lnet_res_lh_invalidate(&me->me_lh);
273 lnet_me_free(me); 273 kfree(me);
274} 274}
diff --git a/drivers/staging/lustre/lnet/lnet/lib-move.c b/drivers/staging/lustre/lnet/lnet/lib-move.c
index 68d16ffec980..c673037dbce4 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-move.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-move.c
@@ -57,7 +57,7 @@ lnet_fail_nid(lnet_nid_t nid, unsigned int threshold)
57 /* NB: use lnet_net_lock(0) to serialize operations on test peers */ 57 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
58 if (threshold) { 58 if (threshold) {
59 /* Adding a new entry */ 59 /* Adding a new entry */
60 LIBCFS_ALLOC(tp, sizeof(*tp)); 60 tp = kzalloc(sizeof(*tp), GFP_NOFS);
61 if (!tp) 61 if (!tp)
62 return -ENOMEM; 62 return -ENOMEM;
63 63
@@ -90,7 +90,7 @@ lnet_fail_nid(lnet_nid_t nid, unsigned int threshold)
90 90
91 list_for_each_entry_safe(tp, temp, &cull, tp_list) { 91 list_for_each_entry_safe(tp, temp, &cull, tp_list) {
92 list_del(&tp->tp_list); 92 list_del(&tp->tp_list);
93 LIBCFS_FREE(tp, sizeof(*tp)); 93 kfree(tp);
94 } 94 }
95 return 0; 95 return 0;
96} 96}
@@ -149,7 +149,7 @@ fail_peer(lnet_nid_t nid, int outgoing)
149 list_for_each_entry_safe(tp, temp, &cull, tp_list) { 149 list_for_each_entry_safe(tp, temp, &cull, tp_list) {
150 list_del(&tp->tp_list); 150 list_del(&tp->tp_list);
151 151
152 LIBCFS_FREE(tp, sizeof(*tp)); 152 kfree(tp);
153 } 153 }
154 154
155 return fail; 155 return fail;
@@ -1769,7 +1769,7 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
1769 goto drop; 1769 goto drop;
1770 } 1770 }
1771 1771
1772 msg = lnet_msg_alloc(); 1772 msg = kzalloc(sizeof(*msg), GFP_NOFS);
1773 if (!msg) { 1773 if (!msg) {
1774 CERROR("%s, src %s: Dropping %s (out of memory)\n", 1774 CERROR("%s, src %s: Dropping %s (out of memory)\n",
1775 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid), 1775 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
@@ -1777,7 +1777,7 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
1777 goto drop; 1777 goto drop;
1778 } 1778 }
1779 1779
1780 /* msg zeroed in lnet_msg_alloc; 1780 /* msg zeroed by kzalloc()
1781 * i.e. flags all clear, pointers NULL etc 1781 * i.e. flags all clear, pointers NULL etc
1782 */ 1782 */
1783 msg->msg_type = type; 1783 msg->msg_type = type;
@@ -1812,7 +1812,7 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
1812 CERROR("%s, src %s: Dropping %s (error %d looking up sender)\n", 1812 CERROR("%s, src %s: Dropping %s (error %d looking up sender)\n",
1813 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid), 1813 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1814 lnet_msgtyp2str(type), rc); 1814 lnet_msgtyp2str(type), rc);
1815 lnet_msg_free(msg); 1815 kfree(msg);
1816 if (rc == -ESHUTDOWN) 1816 if (rc == -ESHUTDOWN)
1817 /* We are shutting down. Don't do anything more */ 1817 /* We are shutting down. Don't do anything more */
1818 return 0; 1818 return 0;
@@ -2010,7 +2010,7 @@ LNetPut(lnet_nid_t self, struct lnet_handle_md mdh, enum lnet_ack_req ack,
2010 return -EIO; 2010 return -EIO;
2011 } 2011 }
2012 2012
2013 msg = lnet_msg_alloc(); 2013 msg = kzalloc(sizeof(*msg), GFP_NOFS);
2014 if (!msg) { 2014 if (!msg) {
2015 CERROR("Dropping PUT to %s: ENOMEM on struct lnet_msg\n", 2015 CERROR("Dropping PUT to %s: ENOMEM on struct lnet_msg\n",
2016 libcfs_id2str(target)); 2016 libcfs_id2str(target));
@@ -2031,7 +2031,7 @@ LNetPut(lnet_nid_t self, struct lnet_handle_md mdh, enum lnet_ack_req ack,
2031 md->md_me->me_portal); 2031 md->md_me->me_portal);
2032 lnet_res_unlock(cpt); 2032 lnet_res_unlock(cpt);
2033 2033
2034 lnet_msg_free(msg); 2034 kfree(msg);
2035 return -ENOENT; 2035 return -ENOENT;
2036 } 2036 }
2037 2037
@@ -2086,7 +2086,7 @@ lnet_create_reply_msg(struct lnet_ni *ni, struct lnet_msg *getmsg)
2086 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when 2086 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
2087 * lnet_finalize() is called on it, so the LND must call this first 2087 * lnet_finalize() is called on it, so the LND must call this first
2088 */ 2088 */
2089 struct lnet_msg *msg = lnet_msg_alloc(); 2089 struct lnet_msg *msg = kzalloc(sizeof(*msg), GFP_NOFS);
2090 struct lnet_libmd *getmd = getmsg->msg_md; 2090 struct lnet_libmd *getmd = getmsg->msg_md;
2091 struct lnet_process_id peer_id = getmsg->msg_target; 2091 struct lnet_process_id peer_id = getmsg->msg_target;
2092 int cpt; 2092 int cpt;
@@ -2146,8 +2146,7 @@ lnet_create_reply_msg(struct lnet_ni *ni, struct lnet_msg *getmsg)
2146 the_lnet.ln_counters[cpt]->drop_length += getmd->md_length; 2146 the_lnet.ln_counters[cpt]->drop_length += getmd->md_length;
2147 lnet_net_unlock(cpt); 2147 lnet_net_unlock(cpt);
2148 2148
2149 if (msg) 2149 kfree(msg);
2150 lnet_msg_free(msg);
2151 2150
2152 return NULL; 2151 return NULL;
2153} 2152}
@@ -2215,7 +2214,7 @@ LNetGet(lnet_nid_t self, struct lnet_handle_md mdh,
2215 return -EIO; 2214 return -EIO;
2216 } 2215 }
2217 2216
2218 msg = lnet_msg_alloc(); 2217 msg = kzalloc(sizeof(*msg), GFP_NOFS);
2219 if (!msg) { 2218 if (!msg) {
2220 CERROR("Dropping GET to %s: ENOMEM on struct lnet_msg\n", 2219 CERROR("Dropping GET to %s: ENOMEM on struct lnet_msg\n",
2221 libcfs_id2str(target)); 2220 libcfs_id2str(target));
@@ -2236,7 +2235,7 @@ LNetGet(lnet_nid_t self, struct lnet_handle_md mdh,
2236 2235
2237 lnet_res_unlock(cpt); 2236 lnet_res_unlock(cpt);
2238 2237
2239 lnet_msg_free(msg); 2238 kfree(msg);
2240 return -ENOENT; 2239 return -ENOENT;
2241 } 2240 }
2242 2241
diff --git a/drivers/staging/lustre/lnet/lnet/lib-msg.c b/drivers/staging/lustre/lnet/lnet/lib-msg.c
index c72ef05b2420..0091273c04b9 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-msg.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-msg.c
@@ -433,7 +433,7 @@ lnet_complete_msg_locked(struct lnet_msg *msg, int cpt)
433 } 433 }
434 434
435 lnet_msg_decommit(msg, cpt, status); 435 lnet_msg_decommit(msg, cpt, status);
436 lnet_msg_free(msg); 436 kfree(msg);
437 return 0; 437 return 0;
438} 438}
439 439
@@ -466,7 +466,7 @@ lnet_finalize(struct lnet_ni *ni, struct lnet_msg *msg, int status)
466 if (!msg->msg_tx_committed && !msg->msg_rx_committed) { 466 if (!msg->msg_tx_committed && !msg->msg_rx_committed) {
467 /* not committed to network yet */ 467 /* not committed to network yet */
468 LASSERT(!msg->msg_onactivelist); 468 LASSERT(!msg->msg_onactivelist);
469 lnet_msg_free(msg); 469 kfree(msg);
470 return; 470 return;
471 } 471 }
472 472
@@ -546,19 +546,15 @@ lnet_msg_container_cleanup(struct lnet_msg_container *container)
546 LASSERT(msg->msg_onactivelist); 546 LASSERT(msg->msg_onactivelist);
547 msg->msg_onactivelist = 0; 547 msg->msg_onactivelist = 0;
548 list_del(&msg->msg_activelist); 548 list_del(&msg->msg_activelist);
549 lnet_msg_free(msg); 549 kfree(msg);
550 count++; 550 count++;
551 } 551 }
552 552
553 if (count > 0) 553 if (count > 0)
554 CERROR("%d active msg on exit\n", count); 554 CERROR("%d active msg on exit\n", count);
555 555
556 if (container->msc_finalizers) { 556 kvfree(container->msc_finalizers);
557 LIBCFS_FREE(container->msc_finalizers, 557 container->msc_finalizers = NULL;
558 container->msc_nfinalizers *
559 sizeof(*container->msc_finalizers));
560 container->msc_finalizers = NULL;
561 }
562 container->msc_init = 0; 558 container->msc_init = 0;
563} 559}
564 560
@@ -573,9 +569,9 @@ lnet_msg_container_setup(struct lnet_msg_container *container, int cpt)
573 /* number of CPUs */ 569 /* number of CPUs */
574 container->msc_nfinalizers = cfs_cpt_weight(lnet_cpt_table(), cpt); 570 container->msc_nfinalizers = cfs_cpt_weight(lnet_cpt_table(), cpt);
575 571
576 LIBCFS_CPT_ALLOC(container->msc_finalizers, lnet_cpt_table(), cpt, 572 container->msc_finalizers = kvzalloc_cpt(container->msc_nfinalizers *
577 container->msc_nfinalizers * 573 sizeof(*container->msc_finalizers),
578 sizeof(*container->msc_finalizers)); 574 GFP_KERNEL, cpt);
579 575
580 if (!container->msc_finalizers) { 576 if (!container->msc_finalizers) {
581 CERROR("Failed to allocate message finalizers\n"); 577 CERROR("Failed to allocate message finalizers\n");
diff --git a/drivers/staging/lustre/lnet/lnet/lib-ptl.c b/drivers/staging/lustre/lnet/lnet/lib-ptl.c
index 8ae93bf6fd1b..471f2f6c86f4 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-ptl.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-ptl.c
@@ -771,11 +771,11 @@ lnet_ptl_cleanup(struct lnet_portal *ptl)
771 struct lnet_me, me_list); 771 struct lnet_me, me_list);
772 CERROR("Active ME %p on exit\n", me); 772 CERROR("Active ME %p on exit\n", me);
773 list_del(&me->me_list); 773 list_del(&me->me_list);
774 lnet_me_free(me); 774 kfree(me);
775 } 775 }
776 } 776 }
777 /* the extra entry is for MEs with ignore bits */ 777 /* the extra entry is for MEs with ignore bits */
778 LIBCFS_FREE(mhash, sizeof(*mhash) * (LNET_MT_HASH_SIZE + 1)); 778 kvfree(mhash);
779 } 779 }
780 780
781 cfs_percpt_free(ptl->ptl_mtables); 781 cfs_percpt_free(ptl->ptl_mtables);
@@ -803,8 +803,8 @@ lnet_ptl_setup(struct lnet_portal *ptl, int index)
803 spin_lock_init(&ptl->ptl_lock); 803 spin_lock_init(&ptl->ptl_lock);
804 cfs_percpt_for_each(mtable, i, ptl->ptl_mtables) { 804 cfs_percpt_for_each(mtable, i, ptl->ptl_mtables) {
805 /* the extra entry is for MEs with ignore bits */ 805 /* the extra entry is for MEs with ignore bits */
806 LIBCFS_CPT_ALLOC(mhash, lnet_cpt_table(), i, 806 mhash = kvzalloc_cpt(sizeof(*mhash) * (LNET_MT_HASH_SIZE + 1),
807 sizeof(*mhash) * (LNET_MT_HASH_SIZE + 1)); 807 GFP_KERNEL, i);
808 if (!mhash) { 808 if (!mhash) {
809 CERROR("Failed to create match hash for portal %d\n", 809 CERROR("Failed to create match hash for portal %d\n",
810 index); 810 index);
diff --git a/drivers/staging/lustre/lnet/lnet/lib-socket.c b/drivers/staging/lustre/lnet/lnet/lib-socket.c
index ed46aaca0ba3..ce93806eefca 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-socket.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-socket.c
@@ -170,7 +170,7 @@ lnet_ipif_enumerate(char ***namesp)
170 nalloc); 170 nalloc);
171 } 171 }
172 172
173 LIBCFS_ALLOC(ifr, nalloc * sizeof(*ifr)); 173 ifr = kzalloc(nalloc * sizeof(*ifr), GFP_KERNEL);
174 if (!ifr) { 174 if (!ifr) {
175 CERROR("ENOMEM enumerating up to %d interfaces\n", 175 CERROR("ENOMEM enumerating up to %d interfaces\n",
176 nalloc); 176 nalloc);
@@ -195,14 +195,14 @@ lnet_ipif_enumerate(char ***namesp)
195 if (nfound < nalloc || toobig) 195 if (nfound < nalloc || toobig)
196 break; 196 break;
197 197
198 LIBCFS_FREE(ifr, nalloc * sizeof(*ifr)); 198 kfree(ifr);
199 nalloc *= 2; 199 nalloc *= 2;
200 } 200 }
201 201
202 if (!nfound) 202 if (!nfound)
203 goto out1; 203 goto out1;
204 204
205 LIBCFS_ALLOC(names, nfound * sizeof(*names)); 205 names = kzalloc(nfound * sizeof(*names), GFP_KERNEL);
206 if (!names) { 206 if (!names) {
207 rc = -ENOMEM; 207 rc = -ENOMEM;
208 goto out1; 208 goto out1;
@@ -218,7 +218,7 @@ lnet_ipif_enumerate(char ***namesp)
218 goto out2; 218 goto out2;
219 } 219 }
220 220
221 LIBCFS_ALLOC(names[i], IFNAMSIZ); 221 names[i] = kmalloc(IFNAMSIZ, GFP_KERNEL);
222 if (!names[i]) { 222 if (!names[i]) {
223 rc = -ENOMEM; 223 rc = -ENOMEM;
224 goto out2; 224 goto out2;
@@ -235,7 +235,7 @@ out2:
235 if (rc < 0) 235 if (rc < 0)
236 lnet_ipif_free_enumeration(names, nfound); 236 lnet_ipif_free_enumeration(names, nfound);
237out1: 237out1:
238 LIBCFS_FREE(ifr, nalloc * sizeof(*ifr)); 238 kfree(ifr);
239out0: 239out0:
240 return rc; 240 return rc;
241} 241}
@@ -249,9 +249,9 @@ lnet_ipif_free_enumeration(char **names, int n)
249 LASSERT(n > 0); 249 LASSERT(n > 0);
250 250
251 for (i = 0; i < n && names[i]; i++) 251 for (i = 0; i < n && names[i]; i++)
252 LIBCFS_FREE(names[i], IFNAMSIZ); 252 kfree(names[i]);
253 253
254 LIBCFS_FREE(names, n * sizeof(*names)); 254 kfree(names);
255} 255}
256EXPORT_SYMBOL(lnet_ipif_free_enumeration); 256EXPORT_SYMBOL(lnet_ipif_free_enumeration);
257 257
diff --git a/drivers/staging/lustre/lnet/lnet/net_fault.c b/drivers/staging/lustre/lnet/lnet/net_fault.c
index 5a5d1811ffbe..e3468cef273b 100644
--- a/drivers/staging/lustre/lnet/lnet/net_fault.c
+++ b/drivers/staging/lustre/lnet/lnet/net_fault.c
@@ -161,7 +161,7 @@ lnet_drop_rule_add(struct lnet_fault_attr *attr)
161 if (lnet_fault_attr_validate(attr)) 161 if (lnet_fault_attr_validate(attr))
162 return -EINVAL; 162 return -EINVAL;
163 163
164 CFS_ALLOC_PTR(rule); 164 rule = kzalloc(sizeof(*rule), GFP_NOFS);
165 if (!rule) 165 if (!rule)
166 return -ENOMEM; 166 return -ENOMEM;
167 167
@@ -170,10 +170,10 @@ lnet_drop_rule_add(struct lnet_fault_attr *attr)
170 rule->dr_attr = *attr; 170 rule->dr_attr = *attr;
171 if (attr->u.drop.da_interval) { 171 if (attr->u.drop.da_interval) {
172 rule->dr_time_base = cfs_time_shift(attr->u.drop.da_interval); 172 rule->dr_time_base = cfs_time_shift(attr->u.drop.da_interval);
173 rule->dr_drop_time = cfs_time_shift(cfs_rand() % 173 rule->dr_drop_time = cfs_time_shift(
174 attr->u.drop.da_interval); 174 prandom_u32_max(attr->u.drop.da_interval));
175 } else { 175 } else {
176 rule->dr_drop_at = cfs_rand() % attr->u.drop.da_rate; 176 rule->dr_drop_at = prandom_u32_max(attr->u.drop.da_rate);
177 } 177 }
178 178
179 lnet_net_lock(LNET_LOCK_EX); 179 lnet_net_lock(LNET_LOCK_EX);
@@ -223,7 +223,7 @@ lnet_drop_rule_del(lnet_nid_t src, lnet_nid_t dst)
223 rule->dr_attr.u.drop.da_interval); 223 rule->dr_attr.u.drop.da_interval);
224 224
225 list_del(&rule->dr_link); 225 list_del(&rule->dr_link);
226 CFS_FREE_PTR(rule); 226 kfree(rule);
227 n++; 227 n++;
228 } 228 }
229 229
@@ -277,10 +277,10 @@ lnet_drop_rule_reset(void)
277 277
278 memset(&rule->dr_stat, 0, sizeof(rule->dr_stat)); 278 memset(&rule->dr_stat, 0, sizeof(rule->dr_stat));
279 if (attr->u.drop.da_rate) { 279 if (attr->u.drop.da_rate) {
280 rule->dr_drop_at = cfs_rand() % attr->u.drop.da_rate; 280 rule->dr_drop_at = prandom_u32_max(attr->u.drop.da_rate);
281 } else { 281 } else {
282 rule->dr_drop_time = cfs_time_shift(cfs_rand() % 282 rule->dr_drop_time = cfs_time_shift(
283 attr->u.drop.da_interval); 283 prandom_u32_max(attr->u.drop.da_interval));
284 rule->dr_time_base = cfs_time_shift(attr->u.drop.da_interval); 284 rule->dr_time_base = cfs_time_shift(attr->u.drop.da_interval);
285 } 285 }
286 spin_unlock(&rule->dr_lock); 286 spin_unlock(&rule->dr_lock);
@@ -315,8 +315,8 @@ drop_rule_match(struct lnet_drop_rule *rule, lnet_nid_t src,
315 rule->dr_time_base = now; 315 rule->dr_time_base = now;
316 316
317 rule->dr_drop_time = rule->dr_time_base + 317 rule->dr_drop_time = rule->dr_time_base +
318 cfs_time_seconds(cfs_rand() % 318 cfs_time_seconds(
319 attr->u.drop.da_interval); 319 prandom_u32_max(attr->u.drop.da_interval));
320 rule->dr_time_base += cfs_time_seconds(attr->u.drop.da_interval); 320 rule->dr_time_base += cfs_time_seconds(attr->u.drop.da_interval);
321 321
322 CDEBUG(D_NET, "Drop Rule %s->%s: next drop : %lu\n", 322 CDEBUG(D_NET, "Drop Rule %s->%s: next drop : %lu\n",
@@ -330,7 +330,7 @@ drop_rule_match(struct lnet_drop_rule *rule, lnet_nid_t src,
330 330
331 if (!do_div(rule->dr_stat.fs_count, attr->u.drop.da_rate)) { 331 if (!do_div(rule->dr_stat.fs_count, attr->u.drop.da_rate)) {
332 rule->dr_drop_at = rule->dr_stat.fs_count + 332 rule->dr_drop_at = rule->dr_stat.fs_count +
333 cfs_rand() % attr->u.drop.da_rate; 333 prandom_u32_max(attr->u.drop.da_rate);
334 CDEBUG(D_NET, "Drop Rule %s->%s: next drop: %lu\n", 334 CDEBUG(D_NET, "Drop Rule %s->%s: next drop: %lu\n",
335 libcfs_nid2str(attr->fa_src), 335 libcfs_nid2str(attr->fa_src),
336 libcfs_nid2str(attr->fa_dst), rule->dr_drop_at); 336 libcfs_nid2str(attr->fa_dst), rule->dr_drop_at);
@@ -452,7 +452,7 @@ delay_rule_decref(struct lnet_delay_rule *rule)
452 LASSERT(list_empty(&rule->dl_msg_list)); 452 LASSERT(list_empty(&rule->dl_msg_list));
453 LASSERT(list_empty(&rule->dl_link)); 453 LASSERT(list_empty(&rule->dl_link));
454 454
455 CFS_FREE_PTR(rule); 455 kfree(rule);
456 } 456 }
457} 457}
458 458
@@ -483,8 +483,9 @@ delay_rule_match(struct lnet_delay_rule *rule, lnet_nid_t src,
483 rule->dl_time_base = now; 483 rule->dl_time_base = now;
484 484
485 rule->dl_delay_time = rule->dl_time_base + 485 rule->dl_delay_time = rule->dl_time_base +
486 cfs_time_seconds(cfs_rand() % 486 cfs_time_seconds(
487 attr->u.delay.la_interval); 487 prandom_u32_max(
488 attr->u.delay.la_interval));
488 rule->dl_time_base += cfs_time_seconds(attr->u.delay.la_interval); 489 rule->dl_time_base += cfs_time_seconds(attr->u.delay.la_interval);
489 490
490 CDEBUG(D_NET, "Delay Rule %s->%s: next delay : %lu\n", 491 CDEBUG(D_NET, "Delay Rule %s->%s: next delay : %lu\n",
@@ -498,7 +499,7 @@ delay_rule_match(struct lnet_delay_rule *rule, lnet_nid_t src,
498 /* generate the next random rate sequence */ 499 /* generate the next random rate sequence */
499 if (!do_div(rule->dl_stat.fs_count, attr->u.delay.la_rate)) { 500 if (!do_div(rule->dl_stat.fs_count, attr->u.delay.la_rate)) {
500 rule->dl_delay_at = rule->dl_stat.fs_count + 501 rule->dl_delay_at = rule->dl_stat.fs_count +
501 cfs_rand() % attr->u.delay.la_rate; 502 prandom_u32_max(attr->u.delay.la_rate);
502 CDEBUG(D_NET, "Delay Rule %s->%s: next delay: %lu\n", 503 CDEBUG(D_NET, "Delay Rule %s->%s: next delay: %lu\n",
503 libcfs_nid2str(attr->fa_src), 504 libcfs_nid2str(attr->fa_src),
504 libcfs_nid2str(attr->fa_dst), rule->dl_delay_at); 505 libcfs_nid2str(attr->fa_dst), rule->dl_delay_at);
@@ -738,7 +739,7 @@ lnet_delay_rule_add(struct lnet_fault_attr *attr)
738 if (lnet_fault_attr_validate(attr)) 739 if (lnet_fault_attr_validate(attr))
739 return -EINVAL; 740 return -EINVAL;
740 741
741 CFS_ALLOC_PTR(rule); 742 rule = kzalloc(sizeof(*rule), GFP_NOFS);
742 if (!rule) 743 if (!rule)
743 return -ENOMEM; 744 return -ENOMEM;
744 745
@@ -771,10 +772,10 @@ lnet_delay_rule_add(struct lnet_fault_attr *attr)
771 rule->dl_attr = *attr; 772 rule->dl_attr = *attr;
772 if (attr->u.delay.la_interval) { 773 if (attr->u.delay.la_interval) {
773 rule->dl_time_base = cfs_time_shift(attr->u.delay.la_interval); 774 rule->dl_time_base = cfs_time_shift(attr->u.delay.la_interval);
774 rule->dl_delay_time = cfs_time_shift(cfs_rand() % 775 rule->dl_delay_time = cfs_time_shift(
775 attr->u.delay.la_interval); 776 prandom_u32_max(attr->u.delay.la_interval));
776 } else { 777 } else {
777 rule->dl_delay_at = cfs_rand() % attr->u.delay.la_rate; 778 rule->dl_delay_at = prandom_u32_max(attr->u.delay.la_rate);
778 } 779 }
779 780
780 rule->dl_msg_send = -1; 781 rule->dl_msg_send = -1;
@@ -792,7 +793,7 @@ lnet_delay_rule_add(struct lnet_fault_attr *attr)
792 return 0; 793 return 0;
793failed: 794failed:
794 mutex_unlock(&delay_dd.dd_mutex); 795 mutex_unlock(&delay_dd.dd_mutex);
795 CFS_FREE_PTR(rule); 796 kfree(rule);
796 return rc; 797 return rc;
797} 798}
798 799
@@ -920,10 +921,11 @@ lnet_delay_rule_reset(void)
920 921
921 memset(&rule->dl_stat, 0, sizeof(rule->dl_stat)); 922 memset(&rule->dl_stat, 0, sizeof(rule->dl_stat));
922 if (attr->u.delay.la_rate) { 923 if (attr->u.delay.la_rate) {
923 rule->dl_delay_at = cfs_rand() % attr->u.delay.la_rate; 924 rule->dl_delay_at = prandom_u32_max(attr->u.delay.la_rate);
924 } else { 925 } else {
925 rule->dl_delay_time = cfs_time_shift(cfs_rand() % 926 rule->dl_delay_time =
926 attr->u.delay.la_interval); 927 cfs_time_shift(prandom_u32_max(
928 attr->u.delay.la_interval));
927 rule->dl_time_base = cfs_time_shift(attr->u.delay.la_interval); 929 rule->dl_time_base = cfs_time_shift(attr->u.delay.la_interval);
928 } 930 }
929 spin_unlock(&rule->dl_lock); 931 spin_unlock(&rule->dl_lock);
diff --git a/drivers/staging/lustre/lnet/lnet/nidstrings.c b/drivers/staging/lustre/lnet/lnet/nidstrings.c
index 05b120c2d45a..3aba1421c741 100644
--- a/drivers/staging/lustre/lnet/lnet/nidstrings.c
+++ b/drivers/staging/lustre/lnet/lnet/nidstrings.c
@@ -166,7 +166,7 @@ parse_addrange(const struct cfs_lstr *src, struct nidrange *nidrange)
166 return 0; 166 return 0;
167 } 167 }
168 168
169 LIBCFS_ALLOC(addrrange, sizeof(struct addrrange)); 169 addrrange = kzalloc(sizeof(struct addrrange), GFP_NOFS);
170 if (!addrrange) 170 if (!addrrange)
171 return -ENOMEM; 171 return -ENOMEM;
172 list_add_tail(&addrrange->ar_link, &nidrange->nr_addrranges); 172 list_add_tail(&addrrange->ar_link, &nidrange->nr_addrranges);
@@ -225,7 +225,7 @@ add_nidrange(const struct cfs_lstr *src,
225 return nr; 225 return nr;
226 } 226 }
227 227
228 LIBCFS_ALLOC(nr, sizeof(struct nidrange)); 228 nr = kzalloc(sizeof(struct nidrange), GFP_NOFS);
229 if (!nr) 229 if (!nr)
230 return NULL; 230 return NULL;
231 list_add_tail(&nr->nr_link, nidlist); 231 list_add_tail(&nr->nr_link, nidlist);
@@ -286,7 +286,7 @@ free_addrranges(struct list_head *list)
286 286
287 cfs_expr_list_free_list(&ar->ar_numaddr_ranges); 287 cfs_expr_list_free_list(&ar->ar_numaddr_ranges);
288 list_del(&ar->ar_link); 288 list_del(&ar->ar_link);
289 LIBCFS_FREE(ar, sizeof(struct addrrange)); 289 kfree(ar);
290 } 290 }
291} 291}
292 292
@@ -308,7 +308,7 @@ cfs_free_nidlist(struct list_head *list)
308 nr = list_entry(pos, struct nidrange, nr_link); 308 nr = list_entry(pos, struct nidrange, nr_link);
309 free_addrranges(&nr->nr_addrranges); 309 free_addrranges(&nr->nr_addrranges);
310 list_del(pos); 310 list_del(pos);
311 LIBCFS_FREE(nr, sizeof(struct nidrange)); 311 kfree(nr);
312 } 312 }
313} 313}
314EXPORT_SYMBOL(cfs_free_nidlist); 314EXPORT_SYMBOL(cfs_free_nidlist);
diff --git a/drivers/staging/lustre/lnet/lnet/peer.c b/drivers/staging/lustre/lnet/lnet/peer.c
index 5e94ad349454..3e157c10fec4 100644
--- a/drivers/staging/lustre/lnet/lnet/peer.c
+++ b/drivers/staging/lustre/lnet/lnet/peer.c
@@ -56,8 +56,8 @@ lnet_peer_tables_create(void)
56 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) { 56 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
57 INIT_LIST_HEAD(&ptable->pt_deathrow); 57 INIT_LIST_HEAD(&ptable->pt_deathrow);
58 58
59 LIBCFS_CPT_ALLOC(hash, lnet_cpt_table(), i, 59 hash = kvmalloc_cpt(LNET_PEER_HASH_SIZE * sizeof(*hash),
60 LNET_PEER_HASH_SIZE * sizeof(*hash)); 60 GFP_KERNEL, i);
61 if (!hash) { 61 if (!hash) {
62 CERROR("Failed to create peer hash table\n"); 62 CERROR("Failed to create peer hash table\n");
63 lnet_peer_tables_destroy(); 63 lnet_peer_tables_destroy();
@@ -94,7 +94,7 @@ lnet_peer_tables_destroy(void)
94 for (j = 0; j < LNET_PEER_HASH_SIZE; j++) 94 for (j = 0; j < LNET_PEER_HASH_SIZE; j++)
95 LASSERT(list_empty(&hash[j])); 95 LASSERT(list_empty(&hash[j]));
96 96
97 LIBCFS_FREE(hash, LNET_PEER_HASH_SIZE * sizeof(*hash)); 97 kvfree(hash);
98 } 98 }
99 99
100 cfs_percpt_free(the_lnet.ln_peer_tables); 100 cfs_percpt_free(the_lnet.ln_peer_tables);
@@ -212,7 +212,7 @@ lnet_peer_tables_cleanup(struct lnet_ni *ni)
212 212
213 list_for_each_entry_safe(lp, temp, &deathrow, lp_hashlist) { 213 list_for_each_entry_safe(lp, temp, &deathrow, lp_hashlist) {
214 list_del(&lp->lp_hashlist); 214 list_del(&lp->lp_hashlist);
215 LIBCFS_FREE(lp, sizeof(*lp)); 215 kfree(lp);
216 } 216 }
217} 217}
218 218
@@ -297,7 +297,7 @@ lnet_nid2peer_locked(struct lnet_peer **lpp, lnet_nid_t nid, int cpt)
297 if (lp) 297 if (lp)
298 memset(lp, 0, sizeof(*lp)); 298 memset(lp, 0, sizeof(*lp));
299 else 299 else
300 LIBCFS_CPT_ALLOC(lp, lnet_cpt_table(), cpt2, sizeof(*lp)); 300 lp = kzalloc_cpt(sizeof(*lp), GFP_NOFS, cpt2);
301 301
302 if (!lp) { 302 if (!lp) {
303 rc = -ENOMEM; 303 rc = -ENOMEM;
diff --git a/drivers/staging/lustre/lnet/lnet/router.c b/drivers/staging/lustre/lnet/lnet/router.c
index 88283ca3f860..6504761ca598 100644
--- a/drivers/staging/lustre/lnet/lnet/router.c
+++ b/drivers/staging/lustre/lnet/lnet/router.c
@@ -238,28 +238,25 @@ lnet_find_net_locked(__u32 net)
238static void lnet_shuffle_seed(void) 238static void lnet_shuffle_seed(void)
239{ 239{
240 static int seeded; 240 static int seeded;
241 __u32 lnd_type, seed[2];
242 struct timespec64 ts;
243 struct lnet_ni *ni; 241 struct lnet_ni *ni;
244 242
245 if (seeded) 243 if (seeded)
246 return; 244 return;
247 245
248 cfs_get_random_bytes(seed, sizeof(seed));
249
250 /* 246 /*
251 * Nodes with small feet have little entropy 247 * Nodes with small feet have little entropy
252 * the NID for this node gives the most entropy in the low bits 248 * the NID for this node gives the most entropy in the low bits
253 */ 249 */
254 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) { 250 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
255 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid)); 251 __u32 lnd_type, seed;
256 252
257 if (lnd_type != LOLND) 253 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
258 seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type); 254 if (lnd_type != LOLND) {
255 seed = (LNET_NIDADDR(ni->ni_nid) | lnd_type);
256 add_device_randomness(&seed, sizeof(seed));
257 }
259 } 258 }
260 259
261 ktime_get_ts64(&ts);
262 cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]);
263 seeded = 1; 260 seeded = 1;
264} 261}
265 262
@@ -277,8 +274,8 @@ lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route)
277 len++; 274 len++;
278 } 275 }
279 276
280 /* len+1 positions to add a new entry, also prevents division by 0 */ 277 /* len+1 positions to add a new entry */
281 offset = cfs_rand() % (len + 1); 278 offset = prandom_u32_max(len + 1);
282 list_for_each(e, &rnet->lrn_routes) { 279 list_for_each(e, &rnet->lrn_routes) {
283 if (!offset) 280 if (!offset)
284 break; 281 break;
@@ -318,15 +315,13 @@ lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
318 return -EEXIST; 315 return -EEXIST;
319 316
320 /* Assume net, route, all new */ 317 /* Assume net, route, all new */
321 LIBCFS_ALLOC(route, sizeof(*route)); 318 route = kzalloc(sizeof(*route), GFP_NOFS);
322 LIBCFS_ALLOC(rnet, sizeof(*rnet)); 319 rnet = kzalloc(sizeof(*rnet), GFP_NOFS);
323 if (!route || !rnet) { 320 if (!route || !rnet) {
324 CERROR("Out of memory creating route %s %d %s\n", 321 CERROR("Out of memory creating route %s %d %s\n",
325 libcfs_net2str(net), hops, libcfs_nid2str(gateway)); 322 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
326 if (route) 323 kfree(route);
327 LIBCFS_FREE(route, sizeof(*route)); 324 kfree(rnet);
328 if (rnet)
329 LIBCFS_FREE(rnet, sizeof(*rnet));
330 return -ENOMEM; 325 return -ENOMEM;
331 } 326 }
332 327
@@ -342,8 +337,8 @@ lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
342 if (rc) { 337 if (rc) {
343 lnet_net_unlock(LNET_LOCK_EX); 338 lnet_net_unlock(LNET_LOCK_EX);
344 339
345 LIBCFS_FREE(route, sizeof(*route)); 340 kfree(route);
346 LIBCFS_FREE(rnet, sizeof(*rnet)); 341 kfree(rnet);
347 342
348 if (rc == -EHOSTUNREACH) /* gateway is not on a local net */ 343 if (rc == -EHOSTUNREACH) /* gateway is not on a local net */
349 return rc; /* ignore the route entry */ 344 return rc; /* ignore the route entry */
@@ -398,11 +393,11 @@ lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
398 393
399 if (!add_route) { 394 if (!add_route) {
400 rc = -EEXIST; 395 rc = -EEXIST;
401 LIBCFS_FREE(route, sizeof(*route)); 396 kfree(route);
402 } 397 }
403 398
404 if (rnet != rnet2) 399 if (rnet != rnet2)
405 LIBCFS_FREE(rnet, sizeof(*rnet)); 400 kfree(rnet);
406 401
407 /* indicate to startup the router checker if configured */ 402 /* indicate to startup the router checker if configured */
408 wake_up(&the_lnet.ln_rc_waitq); 403 wake_up(&the_lnet.ln_rc_waitq);
@@ -520,10 +515,8 @@ lnet_del_route(__u32 net, lnet_nid_t gw_nid)
520 515
521 lnet_net_unlock(LNET_LOCK_EX); 516 lnet_net_unlock(LNET_LOCK_EX);
522 517
523 LIBCFS_FREE(route, sizeof(*route)); 518 kfree(route);
524 519 kfree(rnet);
525 if (rnet)
526 LIBCFS_FREE(rnet, sizeof(*rnet));
527 520
528 rc = 0; 521 rc = 0;
529 lnet_net_lock(LNET_LOCK_EX); 522 lnet_net_lock(LNET_LOCK_EX);
@@ -891,10 +884,9 @@ lnet_destroy_rc_data(struct lnet_rc_data *rcd)
891 lnet_net_unlock(cpt); 884 lnet_net_unlock(cpt);
892 } 885 }
893 886
894 if (rcd->rcd_pinginfo) 887 kfree(rcd->rcd_pinginfo);
895 LIBCFS_FREE(rcd->rcd_pinginfo, LNET_PINGINFO_SIZE);
896 888
897 LIBCFS_FREE(rcd, sizeof(*rcd)); 889 kfree(rcd);
898} 890}
899 891
900static struct lnet_rc_data * 892static struct lnet_rc_data *
@@ -908,14 +900,14 @@ lnet_create_rc_data_locked(struct lnet_peer *gateway)
908 900
909 lnet_net_unlock(gateway->lp_cpt); 901 lnet_net_unlock(gateway->lp_cpt);
910 902
911 LIBCFS_ALLOC(rcd, sizeof(*rcd)); 903 rcd = kzalloc(sizeof(*rcd), GFP_NOFS);
912 if (!rcd) 904 if (!rcd)
913 goto out; 905 goto out;
914 906
915 LNetInvalidateMDHandle(&rcd->rcd_mdh); 907 LNetInvalidateMDHandle(&rcd->rcd_mdh);
916 INIT_LIST_HEAD(&rcd->rcd_list); 908 INIT_LIST_HEAD(&rcd->rcd_list);
917 909
918 LIBCFS_ALLOC(pi, LNET_PINGINFO_SIZE); 910 pi = kzalloc(LNET_PINGINFO_SIZE, GFP_NOFS);
919 if (!pi) 911 if (!pi)
920 goto out; 912 goto out;
921 913
@@ -1304,12 +1296,10 @@ rescan:
1304void 1296void
1305lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages) 1297lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages)
1306{ 1298{
1307 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1308
1309 while (--npages >= 0) 1299 while (--npages >= 0)
1310 __free_page(rb->rb_kiov[npages].bv_page); 1300 __free_page(rb->rb_kiov[npages].bv_page);
1311 1301
1312 LIBCFS_FREE(rb, sz); 1302 kfree(rb);
1313} 1303}
1314 1304
1315static struct lnet_rtrbuf * 1305static struct lnet_rtrbuf *
@@ -1321,7 +1311,7 @@ lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1321 struct lnet_rtrbuf *rb; 1311 struct lnet_rtrbuf *rb;
1322 int i; 1312 int i;
1323 1313
1324 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz); 1314 rb = kzalloc_cpt(sz, GFP_NOFS, cpt);
1325 if (!rb) 1315 if (!rb)
1326 return NULL; 1316 return NULL;
1327 1317
@@ -1335,7 +1325,7 @@ lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1335 while (--i >= 0) 1325 while (--i >= 0)
1336 __free_page(rb->rb_kiov[i].bv_page); 1326 __free_page(rb->rb_kiov[i].bv_page);
1337 1327
1338 LIBCFS_FREE(rb, sz); 1328 kfree(rb);
1339 return NULL; 1329 return NULL;
1340 } 1330 }
1341 1331
diff --git a/drivers/staging/lustre/lnet/lnet/router_proc.c b/drivers/staging/lustre/lnet/lnet/router_proc.c
index d32d653edcb0..1a71ffebc889 100644
--- a/drivers/staging/lustre/lnet/lnet/router_proc.c
+++ b/drivers/staging/lustre/lnet/lnet/router_proc.c
@@ -91,13 +91,13 @@ static int __proc_lnet_stats(void *data, int write,
91 91
92 /* read */ 92 /* read */
93 93
94 LIBCFS_ALLOC(ctrs, sizeof(*ctrs)); 94 ctrs = kzalloc(sizeof(*ctrs), GFP_NOFS);
95 if (!ctrs) 95 if (!ctrs)
96 return -ENOMEM; 96 return -ENOMEM;
97 97
98 LIBCFS_ALLOC(tmpstr, tmpsiz); 98 tmpstr = kmalloc(tmpsiz, GFP_KERNEL);
99 if (!tmpstr) { 99 if (!tmpstr) {
100 LIBCFS_FREE(ctrs, sizeof(*ctrs)); 100 kfree(ctrs);
101 return -ENOMEM; 101 return -ENOMEM;
102 } 102 }
103 103
@@ -118,8 +118,8 @@ static int __proc_lnet_stats(void *data, int write,
118 rc = cfs_trace_copyout_string(buffer, nob, 118 rc = cfs_trace_copyout_string(buffer, nob,
119 tmpstr + pos, "\n"); 119 tmpstr + pos, "\n");
120 120
121 LIBCFS_FREE(tmpstr, tmpsiz); 121 kfree(tmpstr);
122 LIBCFS_FREE(ctrs, sizeof(*ctrs)); 122 kfree(ctrs);
123 return rc; 123 return rc;
124} 124}
125 125
@@ -151,7 +151,7 @@ static int proc_lnet_routes(struct ctl_table *table, int write,
151 if (!*lenp) 151 if (!*lenp)
152 return 0; 152 return 0;
153 153
154 LIBCFS_ALLOC(tmpstr, tmpsiz); 154 tmpstr = kmalloc(tmpsiz, GFP_KERNEL);
155 if (!tmpstr) 155 if (!tmpstr)
156 return -ENOMEM; 156 return -ENOMEM;
157 157
@@ -183,7 +183,7 @@ static int proc_lnet_routes(struct ctl_table *table, int write,
183 183
184 if (ver != LNET_PROC_VERSION(the_lnet.ln_remote_nets_version)) { 184 if (ver != LNET_PROC_VERSION(the_lnet.ln_remote_nets_version)) {
185 lnet_net_unlock(0); 185 lnet_net_unlock(0);
186 LIBCFS_FREE(tmpstr, tmpsiz); 186 kfree(tmpstr);
187 return -ESTALE; 187 return -ESTALE;
188 } 188 }
189 189
@@ -248,7 +248,7 @@ static int proc_lnet_routes(struct ctl_table *table, int write,
248 } 248 }
249 } 249 }
250 250
251 LIBCFS_FREE(tmpstr, tmpsiz); 251 kfree(tmpstr);
252 252
253 if (!rc) 253 if (!rc)
254 *lenp = len; 254 *lenp = len;
@@ -275,7 +275,7 @@ static int proc_lnet_routers(struct ctl_table *table, int write,
275 if (!*lenp) 275 if (!*lenp)
276 return 0; 276 return 0;
277 277
278 LIBCFS_ALLOC(tmpstr, tmpsiz); 278 tmpstr = kmalloc(tmpsiz, GFP_KERNEL);
279 if (!tmpstr) 279 if (!tmpstr)
280 return -ENOMEM; 280 return -ENOMEM;
281 281
@@ -303,7 +303,7 @@ static int proc_lnet_routers(struct ctl_table *table, int write,
303 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) { 303 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) {
304 lnet_net_unlock(0); 304 lnet_net_unlock(0);
305 305
306 LIBCFS_FREE(tmpstr, tmpsiz); 306 kfree(tmpstr);
307 return -ESTALE; 307 return -ESTALE;
308 } 308 }
309 309
@@ -385,7 +385,7 @@ static int proc_lnet_routers(struct ctl_table *table, int write,
385 } 385 }
386 } 386 }
387 387
388 LIBCFS_FREE(tmpstr, tmpsiz); 388 kfree(tmpstr);
389 389
390 if (!rc) 390 if (!rc)
391 *lenp = len; 391 *lenp = len;
@@ -418,7 +418,7 @@ static int proc_lnet_peers(struct ctl_table *table, int write,
418 return 0; 418 return 0;
419 } 419 }
420 420
421 LIBCFS_ALLOC(tmpstr, tmpsiz); 421 tmpstr = kmalloc(tmpsiz, GFP_KERNEL);
422 if (!tmpstr) 422 if (!tmpstr)
423 return -ENOMEM; 423 return -ENOMEM;
424 424
@@ -448,7 +448,7 @@ static int proc_lnet_peers(struct ctl_table *table, int write,
448 448
449 if (ver != LNET_PROC_VERSION(ptable->pt_version)) { 449 if (ver != LNET_PROC_VERSION(ptable->pt_version)) {
450 lnet_net_unlock(cpt); 450 lnet_net_unlock(cpt);
451 LIBCFS_FREE(tmpstr, tmpsiz); 451 kfree(tmpstr);
452 return -ESTALE; 452 return -ESTALE;
453 } 453 }
454 454
@@ -556,7 +556,7 @@ static int proc_lnet_peers(struct ctl_table *table, int write,
556 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff); 556 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff);
557 } 557 }
558 558
559 LIBCFS_FREE(tmpstr, tmpsiz); 559 kfree(tmpstr);
560 560
561 if (!rc) 561 if (!rc)
562 *lenp = len; 562 *lenp = len;
@@ -579,7 +579,7 @@ static int __proc_lnet_buffers(void *data, int write,
579 579
580 /* (4 %d) * 4 * LNET_CPT_NUMBER */ 580 /* (4 %d) * 4 * LNET_CPT_NUMBER */
581 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER; 581 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER;
582 LIBCFS_ALLOC(tmpstr, tmpsiz); 582 tmpstr = kvmalloc(tmpsiz, GFP_KERNEL);
583 if (!tmpstr) 583 if (!tmpstr)
584 return -ENOMEM; 584 return -ENOMEM;
585 585
@@ -618,7 +618,7 @@ static int __proc_lnet_buffers(void *data, int write,
618 rc = cfs_trace_copyout_string(buffer, nob, 618 rc = cfs_trace_copyout_string(buffer, nob,
619 tmpstr + pos, NULL); 619 tmpstr + pos, NULL);
620 620
621 LIBCFS_FREE(tmpstr, tmpsiz); 621 kvfree(tmpstr);
622 return rc; 622 return rc;
623} 623}
624 624
@@ -643,7 +643,7 @@ static int proc_lnet_nis(struct ctl_table *table, int write,
643 if (!*lenp) 643 if (!*lenp)
644 return 0; 644 return 0;
645 645
646 LIBCFS_ALLOC(tmpstr, tmpsiz); 646 tmpstr = kvmalloc(tmpsiz, GFP_KERNEL);
647 if (!tmpstr) 647 if (!tmpstr)
648 return -ENOMEM; 648 return -ENOMEM;
649 649
@@ -744,7 +744,7 @@ static int proc_lnet_nis(struct ctl_table *table, int write,
744 *ppos += 1; 744 *ppos += 1;
745 } 745 }
746 746
747 LIBCFS_FREE(tmpstr, tmpsiz); 747 kvfree(tmpstr);
748 748
749 if (!rc) 749 if (!rc)
750 *lenp = len; 750 *lenp = len;
@@ -795,7 +795,7 @@ static int __proc_lnet_portal_rotor(void *data, int write,
795 int rc; 795 int rc;
796 int i; 796 int i;
797 797
798 LIBCFS_ALLOC(buf, buf_len); 798 buf = kmalloc(buf_len, GFP_KERNEL);
799 if (!buf) 799 if (!buf)
800 return -ENOMEM; 800 return -ENOMEM;
801 801
@@ -829,7 +829,7 @@ static int __proc_lnet_portal_rotor(void *data, int write,
829 if (rc < 0) 829 if (rc < 0)
830 goto out; 830 goto out;
831 831
832 tmp = cfs_trimwhite(buf); 832 tmp = strim(buf);
833 833
834 rc = -EINVAL; 834 rc = -EINVAL;
835 lnet_res_lock(0); 835 lnet_res_lock(0);
@@ -843,7 +843,7 @@ static int __proc_lnet_portal_rotor(void *data, int write,
843 } 843 }
844 lnet_res_unlock(0); 844 lnet_res_unlock(0);
845out: 845out:
846 LIBCFS_FREE(buf, buf_len); 846 kfree(buf);
847 return rc; 847 return rc;
848} 848}
849 849
diff --git a/drivers/staging/lustre/lnet/selftest/conctl.c b/drivers/staging/lustre/lnet/selftest/conctl.c
index 082c0afacf23..34ba440b3c02 100644
--- a/drivers/staging/lustre/lnet/selftest/conctl.c
+++ b/drivers/staging/lustre/lnet/selftest/conctl.c
@@ -45,7 +45,7 @@
45static int 45static int
46lst_session_new_ioctl(struct lstio_session_new_args *args) 46lst_session_new_ioctl(struct lstio_session_new_args *args)
47{ 47{
48 char *name; 48 char name[LST_NAME_SIZE + 1];
49 int rc; 49 int rc;
50 50
51 if (!args->lstio_ses_idp || /* address for output sid */ 51 if (!args->lstio_ses_idp || /* address for output sid */
@@ -55,13 +55,8 @@ lst_session_new_ioctl(struct lstio_session_new_args *args)
55 args->lstio_ses_nmlen > LST_NAME_SIZE) 55 args->lstio_ses_nmlen > LST_NAME_SIZE)
56 return -EINVAL; 56 return -EINVAL;
57 57
58 LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1);
59 if (!name)
60 return -ENOMEM;
61
62 if (copy_from_user(name, args->lstio_ses_namep, 58 if (copy_from_user(name, args->lstio_ses_namep,
63 args->lstio_ses_nmlen)) { 59 args->lstio_ses_nmlen)) {
64 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
65 return -EFAULT; 60 return -EFAULT;
66 } 61 }
67 62
@@ -74,7 +69,6 @@ lst_session_new_ioctl(struct lstio_session_new_args *args)
74 args->lstio_ses_force, 69 args->lstio_ses_force,
75 args->lstio_ses_idp); 70 args->lstio_ses_idp);
76 71
77 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
78 return rc; 72 return rc;
79} 73}
80 74
@@ -112,7 +106,7 @@ lst_session_info_ioctl(struct lstio_session_info_args *args)
112static int 106static int
113lst_debug_ioctl(struct lstio_debug_args *args) 107lst_debug_ioctl(struct lstio_debug_args *args)
114{ 108{
115 char *name = NULL; 109 char name[LST_NAME_SIZE + 1];
116 int client = 1; 110 int client = 1;
117 int rc; 111 int rc;
118 112
@@ -128,16 +122,10 @@ lst_debug_ioctl(struct lstio_debug_args *args)
128 return -EINVAL; 122 return -EINVAL;
129 123
130 if (args->lstio_dbg_namep) { 124 if (args->lstio_dbg_namep) {
131 LIBCFS_ALLOC(name, args->lstio_dbg_nmlen + 1);
132 if (!name)
133 return -ENOMEM;
134 125
135 if (copy_from_user(name, args->lstio_dbg_namep, 126 if (copy_from_user(name, args->lstio_dbg_namep,
136 args->lstio_dbg_nmlen)) { 127 args->lstio_dbg_nmlen))
137 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
138
139 return -EFAULT; 128 return -EFAULT;
140 }
141 129
142 name[args->lstio_dbg_nmlen] = 0; 130 name[args->lstio_dbg_nmlen] = 0;
143 } 131 }
@@ -154,7 +142,7 @@ lst_debug_ioctl(struct lstio_debug_args *args)
154 client = 0; 142 client = 0;
155 /* fall through */ 143 /* fall through */
156 case LST_OPC_BATCHCLI: 144 case LST_OPC_BATCHCLI:
157 if (!name) 145 if (!args->lstio_dbg_namep)
158 goto out; 146 goto out;
159 147
160 rc = lstcon_batch_debug(args->lstio_dbg_timeout, 148 rc = lstcon_batch_debug(args->lstio_dbg_timeout,
@@ -162,7 +150,7 @@ lst_debug_ioctl(struct lstio_debug_args *args)
162 break; 150 break;
163 151
164 case LST_OPC_GROUP: 152 case LST_OPC_GROUP:
165 if (!name) 153 if (!args->lstio_dbg_namep)
166 goto out; 154 goto out;
167 155
168 rc = lstcon_group_debug(args->lstio_dbg_timeout, 156 rc = lstcon_group_debug(args->lstio_dbg_timeout,
@@ -185,16 +173,13 @@ lst_debug_ioctl(struct lstio_debug_args *args)
185 } 173 }
186 174
187out: 175out:
188 if (name)
189 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
190
191 return rc; 176 return rc;
192} 177}
193 178
194static int 179static int
195lst_group_add_ioctl(struct lstio_group_add_args *args) 180lst_group_add_ioctl(struct lstio_group_add_args *args)
196{ 181{
197 char *name; 182 char name[LST_NAME_SIZE + 1];
198 int rc; 183 int rc;
199 184
200 if (args->lstio_grp_key != console_session.ses_key) 185 if (args->lstio_grp_key != console_session.ses_key)
@@ -205,22 +190,14 @@ lst_group_add_ioctl(struct lstio_group_add_args *args)
205 args->lstio_grp_nmlen > LST_NAME_SIZE) 190 args->lstio_grp_nmlen > LST_NAME_SIZE)
206 return -EINVAL; 191 return -EINVAL;
207 192
208 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
209 if (!name)
210 return -ENOMEM;
211
212 if (copy_from_user(name, args->lstio_grp_namep, 193 if (copy_from_user(name, args->lstio_grp_namep,
213 args->lstio_grp_nmlen)) { 194 args->lstio_grp_nmlen))
214 LIBCFS_FREE(name, args->lstio_grp_nmlen);
215 return -EFAULT; 195 return -EFAULT;
216 }
217 196
218 name[args->lstio_grp_nmlen] = 0; 197 name[args->lstio_grp_nmlen] = 0;
219 198
220 rc = lstcon_group_add(name); 199 rc = lstcon_group_add(name);
221 200
222 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
223
224 return rc; 201 return rc;
225} 202}
226 203
@@ -228,7 +205,7 @@ static int
228lst_group_del_ioctl(struct lstio_group_del_args *args) 205lst_group_del_ioctl(struct lstio_group_del_args *args)
229{ 206{
230 int rc; 207 int rc;
231 char *name; 208 char name[LST_NAME_SIZE + 1];
232 209
233 if (args->lstio_grp_key != console_session.ses_key) 210 if (args->lstio_grp_key != console_session.ses_key)
234 return -EACCES; 211 return -EACCES;
@@ -238,22 +215,14 @@ lst_group_del_ioctl(struct lstio_group_del_args *args)
238 args->lstio_grp_nmlen > LST_NAME_SIZE) 215 args->lstio_grp_nmlen > LST_NAME_SIZE)
239 return -EINVAL; 216 return -EINVAL;
240 217
241 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
242 if (!name)
243 return -ENOMEM;
244
245 if (copy_from_user(name, args->lstio_grp_namep, 218 if (copy_from_user(name, args->lstio_grp_namep,
246 args->lstio_grp_nmlen)) { 219 args->lstio_grp_nmlen))
247 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
248 return -EFAULT; 220 return -EFAULT;
249 }
250 221
251 name[args->lstio_grp_nmlen] = 0; 222 name[args->lstio_grp_nmlen] = 0;
252 223
253 rc = lstcon_group_del(name); 224 rc = lstcon_group_del(name);
254 225
255 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
256
257 return rc; 226 return rc;
258} 227}
259 228
@@ -261,7 +230,7 @@ static int
261lst_group_update_ioctl(struct lstio_group_update_args *args) 230lst_group_update_ioctl(struct lstio_group_update_args *args)
262{ 231{
263 int rc; 232 int rc;
264 char *name; 233 char name[LST_NAME_SIZE + 1];
265 234
266 if (args->lstio_grp_key != console_session.ses_key) 235 if (args->lstio_grp_key != console_session.ses_key)
267 return -EACCES; 236 return -EACCES;
@@ -272,15 +241,9 @@ lst_group_update_ioctl(struct lstio_group_update_args *args)
272 args->lstio_grp_nmlen > LST_NAME_SIZE) 241 args->lstio_grp_nmlen > LST_NAME_SIZE)
273 return -EINVAL; 242 return -EINVAL;
274 243
275 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
276 if (!name)
277 return -ENOMEM;
278
279 if (copy_from_user(name, args->lstio_grp_namep, 244 if (copy_from_user(name, args->lstio_grp_namep,
280 args->lstio_grp_nmlen)) { 245 args->lstio_grp_nmlen))
281 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
282 return -EFAULT; 246 return -EFAULT;
283 }
284 247
285 name[args->lstio_grp_nmlen] = 0; 248 name[args->lstio_grp_nmlen] = 0;
286 249
@@ -309,8 +272,6 @@ lst_group_update_ioctl(struct lstio_group_update_args *args)
309 break; 272 break;
310 } 273 }
311 274
312 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
313
314 return rc; 275 return rc;
315} 276}
316 277
@@ -319,7 +280,7 @@ lst_nodes_add_ioctl(struct lstio_group_nodes_args *args)
319{ 280{
320 unsigned int feats; 281 unsigned int feats;
321 int rc; 282 int rc;
322 char *name; 283 char name[LST_NAME_SIZE + 1];
323 284
324 if (args->lstio_grp_key != console_session.ses_key) 285 if (args->lstio_grp_key != console_session.ses_key)
325 return -EACCES; 286 return -EACCES;
@@ -333,16 +294,9 @@ lst_nodes_add_ioctl(struct lstio_group_nodes_args *args)
333 args->lstio_grp_nmlen > LST_NAME_SIZE) 294 args->lstio_grp_nmlen > LST_NAME_SIZE)
334 return -EINVAL; 295 return -EINVAL;
335 296
336 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
337 if (!name)
338 return -ENOMEM;
339
340 if (copy_from_user(name, args->lstio_grp_namep, 297 if (copy_from_user(name, args->lstio_grp_namep,
341 args->lstio_grp_nmlen)) { 298 args->lstio_grp_nmlen))
342 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
343
344 return -EFAULT; 299 return -EFAULT;
345 }
346 300
347 name[args->lstio_grp_nmlen] = 0; 301 name[args->lstio_grp_nmlen] = 0;
348 302
@@ -350,7 +304,6 @@ lst_nodes_add_ioctl(struct lstio_group_nodes_args *args)
350 args->lstio_grp_idsp, &feats, 304 args->lstio_grp_idsp, &feats,
351 args->lstio_grp_resultp); 305 args->lstio_grp_resultp);
352 306
353 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
354 if (!rc && 307 if (!rc &&
355 copy_to_user(args->lstio_grp_featp, &feats, sizeof(feats))) { 308 copy_to_user(args->lstio_grp_featp, &feats, sizeof(feats))) {
356 return -EINVAL; 309 return -EINVAL;
@@ -379,7 +332,7 @@ lst_group_list_ioctl(struct lstio_group_list_args *args)
379static int 332static int
380lst_group_info_ioctl(struct lstio_group_info_args *args) 333lst_group_info_ioctl(struct lstio_group_info_args *args)
381{ 334{
382 char *name; 335 char name[LST_NAME_SIZE + 1];
383 int ndent; 336 int ndent;
384 int index; 337 int index;
385 int rc; 338 int rc;
@@ -411,23 +364,15 @@ lst_group_info_ioctl(struct lstio_group_info_args *args)
411 return -EINVAL; 364 return -EINVAL;
412 } 365 }
413 366
414 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
415 if (!name)
416 return -ENOMEM;
417
418 if (copy_from_user(name, args->lstio_grp_namep, 367 if (copy_from_user(name, args->lstio_grp_namep,
419 args->lstio_grp_nmlen)) { 368 args->lstio_grp_nmlen))
420 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
421 return -EFAULT; 369 return -EFAULT;
422 }
423 370
424 name[args->lstio_grp_nmlen] = 0; 371 name[args->lstio_grp_nmlen] = 0;
425 372
426 rc = lstcon_group_info(name, args->lstio_grp_entp, 373 rc = lstcon_group_info(name, args->lstio_grp_entp,
427 &index, &ndent, args->lstio_grp_dentsp); 374 &index, &ndent, args->lstio_grp_dentsp);
428 375
429 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
430
431 if (rc) 376 if (rc)
432 return rc; 377 return rc;
433 378
@@ -443,7 +388,7 @@ static int
443lst_batch_add_ioctl(struct lstio_batch_add_args *args) 388lst_batch_add_ioctl(struct lstio_batch_add_args *args)
444{ 389{
445 int rc; 390 int rc;
446 char *name; 391 char name[LST_NAME_SIZE + 1];
447 392
448 if (args->lstio_bat_key != console_session.ses_key) 393 if (args->lstio_bat_key != console_session.ses_key)
449 return -EACCES; 394 return -EACCES;
@@ -453,22 +398,14 @@ lst_batch_add_ioctl(struct lstio_batch_add_args *args)
453 args->lstio_bat_nmlen > LST_NAME_SIZE) 398 args->lstio_bat_nmlen > LST_NAME_SIZE)
454 return -EINVAL; 399 return -EINVAL;
455 400
456 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
457 if (!name)
458 return -ENOMEM;
459
460 if (copy_from_user(name, args->lstio_bat_namep, 401 if (copy_from_user(name, args->lstio_bat_namep,
461 args->lstio_bat_nmlen)) { 402 args->lstio_bat_nmlen))
462 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
463 return -EFAULT; 403 return -EFAULT;
464 }
465 404
466 name[args->lstio_bat_nmlen] = 0; 405 name[args->lstio_bat_nmlen] = 0;
467 406
468 rc = lstcon_batch_add(name); 407 rc = lstcon_batch_add(name);
469 408
470 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
471
472 return rc; 409 return rc;
473} 410}
474 411
@@ -476,7 +413,7 @@ static int
476lst_batch_run_ioctl(struct lstio_batch_run_args *args) 413lst_batch_run_ioctl(struct lstio_batch_run_args *args)
477{ 414{
478 int rc; 415 int rc;
479 char *name; 416 char name[LST_NAME_SIZE + 1];
480 417
481 if (args->lstio_bat_key != console_session.ses_key) 418 if (args->lstio_bat_key != console_session.ses_key)
482 return -EACCES; 419 return -EACCES;
@@ -486,23 +423,15 @@ lst_batch_run_ioctl(struct lstio_batch_run_args *args)
486 args->lstio_bat_nmlen > LST_NAME_SIZE) 423 args->lstio_bat_nmlen > LST_NAME_SIZE)
487 return -EINVAL; 424 return -EINVAL;
488 425
489 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
490 if (!name)
491 return -ENOMEM;
492
493 if (copy_from_user(name, args->lstio_bat_namep, 426 if (copy_from_user(name, args->lstio_bat_namep,
494 args->lstio_bat_nmlen)) { 427 args->lstio_bat_nmlen))
495 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
496 return -EFAULT; 428 return -EFAULT;
497 }
498 429
499 name[args->lstio_bat_nmlen] = 0; 430 name[args->lstio_bat_nmlen] = 0;
500 431
501 rc = lstcon_batch_run(name, args->lstio_bat_timeout, 432 rc = lstcon_batch_run(name, args->lstio_bat_timeout,
502 args->lstio_bat_resultp); 433 args->lstio_bat_resultp);
503 434
504 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
505
506 return rc; 435 return rc;
507} 436}
508 437
@@ -510,7 +439,7 @@ static int
510lst_batch_stop_ioctl(struct lstio_batch_stop_args *args) 439lst_batch_stop_ioctl(struct lstio_batch_stop_args *args)
511{ 440{
512 int rc; 441 int rc;
513 char *name; 442 char name[LST_NAME_SIZE + 1];
514 443
515 if (args->lstio_bat_key != console_session.ses_key) 444 if (args->lstio_bat_key != console_session.ses_key)
516 return -EACCES; 445 return -EACCES;
@@ -521,30 +450,22 @@ lst_batch_stop_ioctl(struct lstio_batch_stop_args *args)
521 args->lstio_bat_nmlen > LST_NAME_SIZE) 450 args->lstio_bat_nmlen > LST_NAME_SIZE)
522 return -EINVAL; 451 return -EINVAL;
523 452
524 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
525 if (!name)
526 return -ENOMEM;
527
528 if (copy_from_user(name, args->lstio_bat_namep, 453 if (copy_from_user(name, args->lstio_bat_namep,
529 args->lstio_bat_nmlen)) { 454 args->lstio_bat_nmlen))
530 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
531 return -EFAULT; 455 return -EFAULT;
532 }
533 456
534 name[args->lstio_bat_nmlen] = 0; 457 name[args->lstio_bat_nmlen] = 0;
535 458
536 rc = lstcon_batch_stop(name, args->lstio_bat_force, 459 rc = lstcon_batch_stop(name, args->lstio_bat_force,
537 args->lstio_bat_resultp); 460 args->lstio_bat_resultp);
538 461
539 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
540
541 return rc; 462 return rc;
542} 463}
543 464
544static int 465static int
545lst_batch_query_ioctl(struct lstio_batch_query_args *args) 466lst_batch_query_ioctl(struct lstio_batch_query_args *args)
546{ 467{
547 char *name; 468 char name[LST_NAME_SIZE + 1];
548 int rc; 469 int rc;
549 470
550 if (args->lstio_bat_key != console_session.ses_key) 471 if (args->lstio_bat_key != console_session.ses_key)
@@ -559,15 +480,9 @@ lst_batch_query_ioctl(struct lstio_batch_query_args *args)
559 if (args->lstio_bat_testidx < 0) 480 if (args->lstio_bat_testidx < 0)
560 return -EINVAL; 481 return -EINVAL;
561 482
562 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
563 if (!name)
564 return -ENOMEM;
565
566 if (copy_from_user(name, args->lstio_bat_namep, 483 if (copy_from_user(name, args->lstio_bat_namep,
567 args->lstio_bat_nmlen)) { 484 args->lstio_bat_nmlen))
568 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
569 return -EFAULT; 485 return -EFAULT;
570 }
571 486
572 name[args->lstio_bat_nmlen] = 0; 487 name[args->lstio_bat_nmlen] = 0;
573 488
@@ -577,8 +492,6 @@ lst_batch_query_ioctl(struct lstio_batch_query_args *args)
577 args->lstio_bat_timeout, 492 args->lstio_bat_timeout,
578 args->lstio_bat_resultp); 493 args->lstio_bat_resultp);
579 494
580 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
581
582 return rc; 495 return rc;
583} 496}
584 497
@@ -602,7 +515,7 @@ lst_batch_list_ioctl(struct lstio_batch_list_args *args)
602static int 515static int
603lst_batch_info_ioctl(struct lstio_batch_info_args *args) 516lst_batch_info_ioctl(struct lstio_batch_info_args *args)
604{ 517{
605 char *name; 518 char name[LST_NAME_SIZE + 1];
606 int rc; 519 int rc;
607 int index; 520 int index;
608 int ndent; 521 int ndent;
@@ -634,15 +547,9 @@ lst_batch_info_ioctl(struct lstio_batch_info_args *args)
634 return -EINVAL; 547 return -EINVAL;
635 } 548 }
636 549
637 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
638 if (!name)
639 return -ENOMEM;
640
641 if (copy_from_user(name, args->lstio_bat_namep, 550 if (copy_from_user(name, args->lstio_bat_namep,
642 args->lstio_bat_nmlen)) { 551 args->lstio_bat_nmlen))
643 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
644 return -EFAULT; 552 return -EFAULT;
645 }
646 553
647 name[args->lstio_bat_nmlen] = 0; 554 name[args->lstio_bat_nmlen] = 0;
648 555
@@ -650,8 +557,6 @@ lst_batch_info_ioctl(struct lstio_batch_info_args *args)
650 args->lstio_bat_server, args->lstio_bat_testidx, 557 args->lstio_bat_server, args->lstio_bat_testidx,
651 &index, &ndent, args->lstio_bat_dentsp); 558 &index, &ndent, args->lstio_bat_dentsp);
652 559
653 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
654
655 if (rc) 560 if (rc)
656 return rc; 561 return rc;
657 562
@@ -667,7 +572,7 @@ static int
667lst_stat_query_ioctl(struct lstio_stat_args *args) 572lst_stat_query_ioctl(struct lstio_stat_args *args)
668{ 573{
669 int rc; 574 int rc;
670 char *name = NULL; 575 char name[LST_NAME_SIZE + 1];
671 576
672 /* TODO: not finished */ 577 /* TODO: not finished */
673 if (args->lstio_sta_key != console_session.ses_key) 578 if (args->lstio_sta_key != console_session.ses_key)
@@ -689,10 +594,6 @@ lst_stat_query_ioctl(struct lstio_stat_args *args)
689 args->lstio_sta_nmlen > LST_NAME_SIZE) 594 args->lstio_sta_nmlen > LST_NAME_SIZE)
690 return -EINVAL; 595 return -EINVAL;
691 596
692 LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
693 if (!name)
694 return -ENOMEM;
695
696 rc = copy_from_user(name, args->lstio_sta_namep, 597 rc = copy_from_user(name, args->lstio_sta_namep,
697 args->lstio_sta_nmlen); 598 args->lstio_sta_nmlen);
698 if (!rc) 599 if (!rc)
@@ -704,16 +605,14 @@ lst_stat_query_ioctl(struct lstio_stat_args *args)
704 rc = -EINVAL; 605 rc = -EINVAL;
705 } 606 }
706 607
707 if (name)
708 LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
709 return rc; 608 return rc;
710} 609}
711 610
712static int lst_test_add_ioctl(struct lstio_test_args *args) 611static int lst_test_add_ioctl(struct lstio_test_args *args)
713{ 612{
714 char *batch_name; 613 char batch_name[LST_NAME_SIZE + 1];
715 char *src_name = NULL; 614 char src_name[LST_NAME_SIZE + 1];
716 char *dst_name = NULL; 615 char dst_name[LST_NAME_SIZE + 1];
717 void *param = NULL; 616 void *param = NULL;
718 int ret = 0; 617 int ret = 0;
719 int rc = -ENOMEM; 618 int rc = -ENOMEM;
@@ -748,20 +647,8 @@ static int lst_test_add_ioctl(struct lstio_test_args *args)
748 if (!args->lstio_tes_param && args->lstio_tes_param_len) 647 if (!args->lstio_tes_param && args->lstio_tes_param_len)
749 return -EINVAL; 648 return -EINVAL;
750 649
751 LIBCFS_ALLOC(batch_name, args->lstio_tes_bat_nmlen + 1);
752 if (!batch_name)
753 return rc;
754
755 LIBCFS_ALLOC(src_name, args->lstio_tes_sgrp_nmlen + 1);
756 if (!src_name)
757 goto out;
758
759 LIBCFS_ALLOC(dst_name, args->lstio_tes_dgrp_nmlen + 1);
760 if (!dst_name)
761 goto out;
762
763 if (args->lstio_tes_param) { 650 if (args->lstio_tes_param) {
764 LIBCFS_ALLOC(param, args->lstio_tes_param_len); 651 param = kmalloc(args->lstio_tes_param_len, GFP_KERNEL);
765 if (!param) 652 if (!param)
766 goto out; 653 goto out;
767 if (copy_from_user(param, args->lstio_tes_param, 654 if (copy_from_user(param, args->lstio_tes_param,
@@ -791,17 +678,7 @@ static int lst_test_add_ioctl(struct lstio_test_args *args)
791 rc = (copy_to_user(args->lstio_tes_retp, &ret, 678 rc = (copy_to_user(args->lstio_tes_retp, &ret,
792 sizeof(ret))) ? -EFAULT : 0; 679 sizeof(ret))) ? -EFAULT : 0;
793out: 680out:
794 if (batch_name) 681 kfree(param);
795 LIBCFS_FREE(batch_name, args->lstio_tes_bat_nmlen + 1);
796
797 if (src_name)
798 LIBCFS_FREE(src_name, args->lstio_tes_sgrp_nmlen + 1);
799
800 if (dst_name)
801 LIBCFS_FREE(dst_name, args->lstio_tes_dgrp_nmlen + 1);
802
803 if (param)
804 LIBCFS_FREE(param, args->lstio_tes_param_len);
805 682
806 return rc; 683 return rc;
807} 684}
@@ -824,13 +701,13 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
824 if (data->ioc_plen1 > PAGE_SIZE) 701 if (data->ioc_plen1 > PAGE_SIZE)
825 return -EINVAL; 702 return -EINVAL;
826 703
827 LIBCFS_ALLOC(buf, data->ioc_plen1); 704 buf = kmalloc(data->ioc_plen1, GFP_KERNEL);
828 if (!buf) 705 if (!buf)
829 return -ENOMEM; 706 return -ENOMEM;
830 707
831 /* copy in parameter */ 708 /* copy in parameter */
832 if (copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) { 709 if (copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) {
833 LIBCFS_FREE(buf, data->ioc_plen1); 710 kfree(buf);
834 return -EFAULT; 711 return -EFAULT;
835 } 712 }
836 713
@@ -920,7 +797,7 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
920out: 797out:
921 mutex_unlock(&console_session.ses_mutex); 798 mutex_unlock(&console_session.ses_mutex);
922 799
923 LIBCFS_FREE(buf, data->ioc_plen1); 800 kfree(buf);
924 801
925 return rc; 802 return rc;
926} 803}
diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.c b/drivers/staging/lustre/lnet/selftest/conrpc.c
index 6a0f770e0e24..7aa515c34594 100644
--- a/drivers/staging/lustre/lnet/selftest/conrpc.c
+++ b/drivers/staging/lustre/lnet/selftest/conrpc.c
@@ -129,7 +129,7 @@ lstcon_rpc_prep(struct lstcon_node *nd, int service, unsigned int feats,
129 spin_unlock(&console_session.ses_rpc_lock); 129 spin_unlock(&console_session.ses_rpc_lock);
130 130
131 if (!crpc) { 131 if (!crpc) {
132 LIBCFS_ALLOC(crpc, sizeof(*crpc)); 132 crpc = kzalloc(sizeof(*crpc), GFP_NOFS);
133 if (!crpc) 133 if (!crpc)
134 return -ENOMEM; 134 return -ENOMEM;
135 } 135 }
@@ -140,7 +140,7 @@ lstcon_rpc_prep(struct lstcon_node *nd, int service, unsigned int feats,
140 return 0; 140 return 0;
141 } 141 }
142 142
143 LIBCFS_FREE(crpc, sizeof(*crpc)); 143 kfree(crpc);
144 144
145 return rc; 145 return rc;
146} 146}
@@ -250,7 +250,7 @@ lstcon_rpc_trans_prep(struct list_head *translist, int transop,
250 } 250 }
251 251
252 /* create a trans group */ 252 /* create a trans group */
253 LIBCFS_ALLOC(trans, sizeof(*trans)); 253 trans = kzalloc(sizeof(*trans), GFP_NOFS);
254 if (!trans) 254 if (!trans)
255 return -ENOMEM; 255 return -ENOMEM;
256 256
@@ -585,7 +585,7 @@ lstcon_rpc_trans_destroy(struct lstcon_rpc_trans *trans)
585 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n", 585 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
586 lstcon_rpc_trans_name(trans->tas_opc), count); 586 lstcon_rpc_trans_name(trans->tas_opc), count);
587 587
588 LIBCFS_FREE(trans, sizeof(*trans)); 588 kfree(trans);
589} 589}
590 590
591int 591int
@@ -1369,7 +1369,7 @@ lstcon_rpc_cleanup_wait(void)
1369 1369
1370 list_for_each_entry_safe(crpc, temp, &zlist, crp_link) { 1370 list_for_each_entry_safe(crpc, temp, &zlist, crp_link) {
1371 list_del(&crpc->crp_link); 1371 list_del(&crpc->crp_link);
1372 LIBCFS_FREE(crpc, sizeof(struct lstcon_rpc)); 1372 kfree(crpc);
1373 } 1373 }
1374} 1374}
1375 1375
diff --git a/drivers/staging/lustre/lnet/selftest/console.c b/drivers/staging/lustre/lnet/selftest/console.c
index a2662638d599..1acd5cb324b1 100644
--- a/drivers/staging/lustre/lnet/selftest/console.c
+++ b/drivers/staging/lustre/lnet/selftest/console.c
@@ -88,7 +88,7 @@ lstcon_node_find(struct lnet_process_id id, struct lstcon_node **ndpp,
88 if (!create) 88 if (!create)
89 return -ENOENT; 89 return -ENOENT;
90 90
91 LIBCFS_ALLOC(*ndpp, sizeof(**ndpp) + sizeof(*ndl)); 91 *ndpp = kzalloc(sizeof(**ndpp) + sizeof(*ndl), GFP_KERNEL);
92 if (!*ndpp) 92 if (!*ndpp)
93 return -ENOMEM; 93 return -ENOMEM;
94 94
@@ -133,7 +133,7 @@ lstcon_node_put(struct lstcon_node *nd)
133 list_del(&ndl->ndl_link); 133 list_del(&ndl->ndl_link);
134 list_del(&ndl->ndl_hlink); 134 list_del(&ndl->ndl_hlink);
135 135
136 LIBCFS_FREE(nd, sizeof(*nd) + sizeof(*ndl)); 136 kfree(nd);
137} 137}
138 138
139static int 139static int
@@ -166,7 +166,7 @@ lstcon_ndlink_find(struct list_head *hash, struct lnet_process_id id,
166 if (rc) 166 if (rc)
167 return rc; 167 return rc;
168 168
169 LIBCFS_ALLOC(ndl, sizeof(struct lstcon_ndlink)); 169 ndl = kzalloc(sizeof(struct lstcon_ndlink), GFP_NOFS);
170 if (!ndl) { 170 if (!ndl) {
171 lstcon_node_put(nd); 171 lstcon_node_put(nd);
172 return -ENOMEM; 172 return -ENOMEM;
@@ -190,7 +190,7 @@ lstcon_ndlink_release(struct lstcon_ndlink *ndl)
190 list_del(&ndl->ndl_hlink); /* delete from hash */ 190 list_del(&ndl->ndl_hlink); /* delete from hash */
191 lstcon_node_put(ndl->ndl_node); 191 lstcon_node_put(ndl->ndl_node);
192 192
193 LIBCFS_FREE(ndl, sizeof(*ndl)); 193 kfree(ndl);
194} 194}
195 195
196static int 196static int
@@ -199,16 +199,16 @@ lstcon_group_alloc(char *name, struct lstcon_group **grpp)
199 struct lstcon_group *grp; 199 struct lstcon_group *grp;
200 int i; 200 int i;
201 201
202 LIBCFS_ALLOC(grp, offsetof(struct lstcon_group, 202 grp = kmalloc(offsetof(struct lstcon_group,
203 grp_ndl_hash[LST_NODE_HASHSIZE])); 203 grp_ndl_hash[LST_NODE_HASHSIZE]),
204 GFP_KERNEL);
204 if (!grp) 205 if (!grp)
205 return -ENOMEM; 206 return -ENOMEM;
206 207
207 grp->grp_ref = 1; 208 grp->grp_ref = 1;
208 if (name) { 209 if (name) {
209 if (strlen(name) > sizeof(grp->grp_name) - 1) { 210 if (strlen(name) > sizeof(grp->grp_name) - 1) {
210 LIBCFS_FREE(grp, offsetof(struct lstcon_group, 211 kfree(grp);
211 grp_ndl_hash[LST_NODE_HASHSIZE]));
212 return -E2BIG; 212 return -E2BIG;
213 } 213 }
214 strncpy(grp->grp_name, name, sizeof(grp->grp_name)); 214 strncpy(grp->grp_name, name, sizeof(grp->grp_name));
@@ -263,8 +263,7 @@ lstcon_group_decref(struct lstcon_group *grp)
263 for (i = 0; i < LST_NODE_HASHSIZE; i++) 263 for (i = 0; i < LST_NODE_HASHSIZE; i++)
264 LASSERT(list_empty(&grp->grp_ndl_hash[i])); 264 LASSERT(list_empty(&grp->grp_ndl_hash[i]));
265 265
266 LIBCFS_FREE(grp, offsetof(struct lstcon_group, 266 kfree(grp);
267 grp_ndl_hash[LST_NODE_HASHSIZE]));
268} 267}
269 268
270static int 269static int
@@ -807,7 +806,7 @@ lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gents_p,
807 } 806 }
808 807
809 /* non-verbose query */ 808 /* non-verbose query */
810 LIBCFS_ALLOC(gentp, sizeof(struct lstcon_ndlist_ent)); 809 gentp = kzalloc(sizeof(struct lstcon_ndlist_ent), GFP_NOFS);
811 if (!gentp) { 810 if (!gentp) {
812 CERROR("Can't allocate ndlist_ent\n"); 811 CERROR("Can't allocate ndlist_ent\n");
813 lstcon_group_decref(grp); 812 lstcon_group_decref(grp);
@@ -821,7 +820,7 @@ lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gents_p,
821 rc = copy_to_user(gents_p, gentp, 820 rc = copy_to_user(gents_p, gentp,
822 sizeof(struct lstcon_ndlist_ent)) ? -EFAULT : 0; 821 sizeof(struct lstcon_ndlist_ent)) ? -EFAULT : 0;
823 822
824 LIBCFS_FREE(gentp, sizeof(struct lstcon_ndlist_ent)); 823 kfree(gentp);
825 824
826 lstcon_group_decref(grp); 825 lstcon_group_decref(grp);
827 826
@@ -856,35 +855,35 @@ lstcon_batch_add(char *name)
856 return rc; 855 return rc;
857 } 856 }
858 857
859 LIBCFS_ALLOC(bat, sizeof(struct lstcon_batch)); 858 bat = kzalloc(sizeof(struct lstcon_batch), GFP_NOFS);
860 if (!bat) { 859 if (!bat) {
861 CERROR("Can't allocate descriptor for batch %s\n", name); 860 CERROR("Can't allocate descriptor for batch %s\n", name);
862 return -ENOMEM; 861 return -ENOMEM;
863 } 862 }
864 863
865 LIBCFS_ALLOC(bat->bat_cli_hash, 864 bat->bat_cli_hash = kmalloc(sizeof(struct list_head) * LST_NODE_HASHSIZE,
866 sizeof(struct list_head) * LST_NODE_HASHSIZE); 865 GFP_KERNEL);
867 if (!bat->bat_cli_hash) { 866 if (!bat->bat_cli_hash) {
868 CERROR("Can't allocate hash for batch %s\n", name); 867 CERROR("Can't allocate hash for batch %s\n", name);
869 LIBCFS_FREE(bat, sizeof(struct lstcon_batch)); 868 kfree(bat);
870 869
871 return -ENOMEM; 870 return -ENOMEM;
872 } 871 }
873 872
874 LIBCFS_ALLOC(bat->bat_srv_hash, 873 bat->bat_srv_hash = kmalloc(sizeof(struct list_head) * LST_NODE_HASHSIZE,
875 sizeof(struct list_head) * LST_NODE_HASHSIZE); 874 GFP_KERNEL);
876 if (!bat->bat_srv_hash) { 875 if (!bat->bat_srv_hash) {
877 CERROR("Can't allocate hash for batch %s\n", name); 876 CERROR("Can't allocate hash for batch %s\n", name);
878 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE); 877 kfree(bat->bat_cli_hash);
879 LIBCFS_FREE(bat, sizeof(struct lstcon_batch)); 878 kfree(bat);
880 879
881 return -ENOMEM; 880 return -ENOMEM;
882 } 881 }
883 882
884 if (strlen(name) > sizeof(bat->bat_name) - 1) { 883 if (strlen(name) > sizeof(bat->bat_name) - 1) {
885 LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE); 884 kfree(bat->bat_srv_hash);
886 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE); 885 kfree(bat->bat_cli_hash);
887 LIBCFS_FREE(bat, sizeof(struct lstcon_batch)); 886 kfree(bat);
888 return -E2BIG; 887 return -E2BIG;
889 } 888 }
890 strncpy(bat->bat_name, name, sizeof(bat->bat_name)); 889 strncpy(bat->bat_name, name, sizeof(bat->bat_name));
@@ -971,7 +970,7 @@ lstcon_batch_info(char *name, struct lstcon_test_batch_ent __user *ent_up,
971 } 970 }
972 971
973 /* non-verbose query */ 972 /* non-verbose query */
974 LIBCFS_ALLOC(entp, sizeof(struct lstcon_test_batch_ent)); 973 entp = kzalloc(sizeof(struct lstcon_test_batch_ent), GFP_NOFS);
975 if (!entp) 974 if (!entp)
976 return -ENOMEM; 975 return -ENOMEM;
977 976
@@ -993,7 +992,7 @@ lstcon_batch_info(char *name, struct lstcon_test_batch_ent __user *ent_up,
993 rc = copy_to_user(ent_up, entp, 992 rc = copy_to_user(ent_up, entp,
994 sizeof(struct lstcon_test_batch_ent)) ? -EFAULT : 0; 993 sizeof(struct lstcon_test_batch_ent)) ? -EFAULT : 0;
995 994
996 LIBCFS_FREE(entp, sizeof(struct lstcon_test_batch_ent)); 995 kfree(entp);
997 996
998 return rc; 997 return rc;
999} 998}
@@ -1107,8 +1106,7 @@ lstcon_batch_destroy(struct lstcon_batch *bat)
1107 lstcon_group_decref(test->tes_src_grp); 1106 lstcon_group_decref(test->tes_src_grp);
1108 lstcon_group_decref(test->tes_dst_grp); 1107 lstcon_group_decref(test->tes_dst_grp);
1109 1108
1110 LIBCFS_FREE(test, offsetof(struct lstcon_test, 1109 kfree(test);
1111 tes_param[test->tes_paramlen]));
1112 } 1110 }
1113 1111
1114 LASSERT(list_empty(&bat->bat_trans_list)); 1112 LASSERT(list_empty(&bat->bat_trans_list));
@@ -1134,11 +1132,9 @@ lstcon_batch_destroy(struct lstcon_batch *bat)
1134 LASSERT(list_empty(&bat->bat_srv_hash[i])); 1132 LASSERT(list_empty(&bat->bat_srv_hash[i]));
1135 } 1133 }
1136 1134
1137 LIBCFS_FREE(bat->bat_cli_hash, 1135 kfree(bat->bat_cli_hash);
1138 sizeof(struct list_head) * LST_NODE_HASHSIZE); 1136 kfree(bat->bat_srv_hash);
1139 LIBCFS_FREE(bat->bat_srv_hash, 1137 kfree(bat);
1140 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1141 LIBCFS_FREE(bat, sizeof(struct lstcon_batch));
1142} 1138}
1143 1139
1144static int 1140static int
@@ -1311,7 +1307,8 @@ lstcon_test_add(char *batch_name, int type, int loop,
1311 if (dst_grp->grp_userland) 1307 if (dst_grp->grp_userland)
1312 *retp = 1; 1308 *retp = 1;
1313 1309
1314 LIBCFS_ALLOC(test, offsetof(struct lstcon_test, tes_param[paramlen])); 1310 test = kzalloc(offsetof(struct lstcon_test, tes_param[paramlen]),
1311 GFP_KERNEL);
1315 if (!test) { 1312 if (!test) {
1316 CERROR("Can't allocate test descriptor\n"); 1313 CERROR("Can't allocate test descriptor\n");
1317 rc = -ENOMEM; 1314 rc = -ENOMEM;
@@ -1357,8 +1354,7 @@ lstcon_test_add(char *batch_name, int type, int loop,
1357 /* hold groups so nobody can change them */ 1354 /* hold groups so nobody can change them */
1358 return rc; 1355 return rc;
1359out: 1356out:
1360 if (test) 1357 kfree(test);
1361 LIBCFS_FREE(test, offsetof(struct lstcon_test, tes_param[paramlen]));
1362 1358
1363 if (dst_grp) 1359 if (dst_grp)
1364 lstcon_group_decref(dst_grp); 1360 lstcon_group_decref(dst_grp);
@@ -1790,7 +1786,7 @@ lstcon_session_info(struct lst_sid __user *sid_up, int __user *key_up,
1790 if (console_session.ses_state != LST_SESSION_ACTIVE) 1786 if (console_session.ses_state != LST_SESSION_ACTIVE)
1791 return -ESRCH; 1787 return -ESRCH;
1792 1788
1793 LIBCFS_ALLOC(entp, sizeof(*entp)); 1789 entp = kzalloc(sizeof(*entp), GFP_NOFS);
1794 if (!entp) 1790 if (!entp)
1795 return -ENOMEM; 1791 return -ENOMEM;
1796 1792
@@ -1807,7 +1803,7 @@ lstcon_session_info(struct lst_sid __user *sid_up, int __user *key_up,
1807 copy_to_user(name_up, console_session.ses_name, len)) 1803 copy_to_user(name_up, console_session.ses_name, len))
1808 rc = -EFAULT; 1804 rc = -EFAULT;
1809 1805
1810 LIBCFS_FREE(entp, sizeof(*entp)); 1806 kfree(entp);
1811 1807
1812 return rc; 1808 return rc;
1813} 1809}
@@ -2027,8 +2023,8 @@ lstcon_console_init(void)
2027 INIT_LIST_HEAD(&console_session.ses_bat_list); 2023 INIT_LIST_HEAD(&console_session.ses_bat_list);
2028 INIT_LIST_HEAD(&console_session.ses_trans_list); 2024 INIT_LIST_HEAD(&console_session.ses_trans_list);
2029 2025
2030 LIBCFS_ALLOC(console_session.ses_ndl_hash, 2026 console_session.ses_ndl_hash =
2031 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE); 2027 kmalloc(sizeof(struct list_head) * LST_GLOBAL_HASHSIZE, GFP_KERNEL);
2032 if (!console_session.ses_ndl_hash) 2028 if (!console_session.ses_ndl_hash)
2033 return -ENOMEM; 2029 return -ENOMEM;
2034 2030
@@ -2041,8 +2037,7 @@ lstcon_console_init(void)
2041 rc = srpc_add_service(&lstcon_acceptor_service); 2037 rc = srpc_add_service(&lstcon_acceptor_service);
2042 LASSERT(rc != -EBUSY); 2038 LASSERT(rc != -EBUSY);
2043 if (rc) { 2039 if (rc) {
2044 LIBCFS_FREE(console_session.ses_ndl_hash, 2040 kfree(console_session.ses_ndl_hash);
2045 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2046 return rc; 2041 return rc;
2047 } 2042 }
2048 2043
@@ -2064,8 +2059,7 @@ out:
2064 srpc_shutdown_service(&lstcon_acceptor_service); 2059 srpc_shutdown_service(&lstcon_acceptor_service);
2065 srpc_remove_service(&lstcon_acceptor_service); 2060 srpc_remove_service(&lstcon_acceptor_service);
2066 2061
2067 LIBCFS_FREE(console_session.ses_ndl_hash, 2062 kfree(console_session.ses_ndl_hash);
2068 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2069 2063
2070 srpc_wait_service_shutdown(&lstcon_acceptor_service); 2064 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2071 2065
@@ -2099,8 +2093,7 @@ lstcon_console_fini(void)
2099 for (i = 0; i < LST_NODE_HASHSIZE; i++) 2093 for (i = 0; i < LST_NODE_HASHSIZE; i++)
2100 LASSERT(list_empty(&console_session.ses_ndl_hash[i])); 2094 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
2101 2095
2102 LIBCFS_FREE(console_session.ses_ndl_hash, 2096 kfree(console_session.ses_ndl_hash);
2103 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2104 2097
2105 srpc_wait_service_shutdown(&lstcon_acceptor_service); 2098 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2106 2099
diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
index fe889607ff3f..c7697f66f663 100644
--- a/drivers/staging/lustre/lnet/selftest/framework.c
+++ b/drivers/staging/lustre/lnet/selftest/framework.c
@@ -143,7 +143,7 @@ sfw_register_test(struct srpc_service *service,
143 return -EEXIST; 143 return -EEXIST;
144 } 144 }
145 145
146 LIBCFS_ALLOC(tsc, sizeof(struct sfw_test_case)); 146 tsc = kzalloc(sizeof(struct sfw_test_case), GFP_NOFS);
147 if (!tsc) 147 if (!tsc)
148 return -ENOMEM; 148 return -ENOMEM;
149 149
@@ -344,7 +344,7 @@ sfw_bid2batch(struct lst_bid bid)
344 if (bat) 344 if (bat)
345 return bat; 345 return bat;
346 346
347 LIBCFS_ALLOC(bat, sizeof(struct sfw_batch)); 347 bat = kzalloc(sizeof(struct sfw_batch), GFP_NOFS);
348 if (!bat) 348 if (!bat)
349 return NULL; 349 return NULL;
350 350
@@ -447,7 +447,7 @@ sfw_make_session(struct srpc_mksn_reqst *request, struct srpc_mksn_reply *reply)
447 } 447 }
448 448
449 /* brand new or create by force */ 449 /* brand new or create by force */
450 LIBCFS_ALLOC(sn, sizeof(struct sfw_session)); 450 sn = kzalloc(sizeof(struct sfw_session), GFP_NOFS);
451 if (!sn) { 451 if (!sn) {
452 CERROR("dropping RPC mksn under memory pressure\n"); 452 CERROR("dropping RPC mksn under memory pressure\n");
453 return -ENOMEM; 453 return -ENOMEM;
@@ -632,19 +632,19 @@ sfw_destroy_test_instance(struct sfw_test_instance *tsi)
632 tsu = list_entry(tsi->tsi_units.next, 632 tsu = list_entry(tsi->tsi_units.next,
633 struct sfw_test_unit, tsu_list); 633 struct sfw_test_unit, tsu_list);
634 list_del(&tsu->tsu_list); 634 list_del(&tsu->tsu_list);
635 LIBCFS_FREE(tsu, sizeof(*tsu)); 635 kfree(tsu);
636 } 636 }
637 637
638 while (!list_empty(&tsi->tsi_free_rpcs)) { 638 while (!list_empty(&tsi->tsi_free_rpcs)) {
639 rpc = list_entry(tsi->tsi_free_rpcs.next, 639 rpc = list_entry(tsi->tsi_free_rpcs.next,
640 struct srpc_client_rpc, crpc_list); 640 struct srpc_client_rpc, crpc_list);
641 list_del(&rpc->crpc_list); 641 list_del(&rpc->crpc_list);
642 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc)); 642 kfree(rpc);
643 } 643 }
644 644
645clean: 645clean:
646 sfw_unload_test(tsi); 646 sfw_unload_test(tsi);
647 LIBCFS_FREE(tsi, sizeof(*tsi)); 647 kfree(tsi);
648} 648}
649 649
650static void 650static void
@@ -662,7 +662,7 @@ sfw_destroy_batch(struct sfw_batch *tsb)
662 sfw_destroy_test_instance(tsi); 662 sfw_destroy_test_instance(tsi);
663 } 663 }
664 664
665 LIBCFS_FREE(tsb, sizeof(struct sfw_batch)); 665 kfree(tsb);
666} 666}
667 667
668void 668void
@@ -680,7 +680,7 @@ sfw_destroy_session(struct sfw_session *sn)
680 sfw_destroy_batch(batch); 680 sfw_destroy_batch(batch);
681 } 681 }
682 682
683 LIBCFS_FREE(sn, sizeof(*sn)); 683 kfree(sn);
684 atomic_dec(&sfw_data.fw_nzombies); 684 atomic_dec(&sfw_data.fw_nzombies);
685} 685}
686 686
@@ -740,7 +740,7 @@ sfw_add_test_instance(struct sfw_batch *tsb, struct srpc_server_rpc *rpc)
740 int i; 740 int i;
741 int rc; 741 int rc;
742 742
743 LIBCFS_ALLOC(tsi, sizeof(*tsi)); 743 tsi = kzalloc(sizeof(*tsi), GFP_NOFS);
744 if (!tsi) { 744 if (!tsi) {
745 CERROR("Can't allocate test instance for batch: %llu\n", 745 CERROR("Can't allocate test instance for batch: %llu\n",
746 tsb->bat_id.bat_id); 746 tsb->bat_id.bat_id);
@@ -763,7 +763,7 @@ sfw_add_test_instance(struct sfw_batch *tsb, struct srpc_server_rpc *rpc)
763 763
764 rc = sfw_load_test(tsi); 764 rc = sfw_load_test(tsi);
765 if (rc) { 765 if (rc) {
766 LIBCFS_FREE(tsi, sizeof(*tsi)); 766 kfree(tsi);
767 return rc; 767 return rc;
768 } 768 }
769 769
@@ -795,7 +795,7 @@ sfw_add_test_instance(struct sfw_batch *tsb, struct srpc_server_rpc *rpc)
795 sfw_unpack_id(id); 795 sfw_unpack_id(id);
796 796
797 for (j = 0; j < tsi->tsi_concur; j++) { 797 for (j = 0; j < tsi->tsi_concur; j++) {
798 LIBCFS_ALLOC(tsu, sizeof(struct sfw_test_unit)); 798 tsu = kzalloc(sizeof(struct sfw_test_unit), GFP_NOFS);
799 if (!tsu) { 799 if (!tsu) {
800 rc = -ENOMEM; 800 rc = -ENOMEM;
801 CERROR("Can't allocate tsu for %d\n", 801 CERROR("Can't allocate tsu for %d\n",
@@ -941,15 +941,13 @@ sfw_create_test_rpc(struct sfw_test_unit *tsu, struct lnet_process_id peer,
941 return 0; 941 return 0;
942} 942}
943 943
944static int 944static void
945sfw_run_test(struct swi_workitem *wi) 945sfw_run_test(struct swi_workitem *wi)
946{ 946{
947 struct sfw_test_unit *tsu = wi->swi_workitem.wi_data; 947 struct sfw_test_unit *tsu = container_of(wi, struct sfw_test_unit, tsu_worker);
948 struct sfw_test_instance *tsi = tsu->tsu_instance; 948 struct sfw_test_instance *tsi = tsu->tsu_instance;
949 struct srpc_client_rpc *rpc = NULL; 949 struct srpc_client_rpc *rpc = NULL;
950 950
951 LASSERT(wi == &tsu->tsu_worker);
952
953 if (tsi->tsi_ops->tso_prep_rpc(tsu, tsu->tsu_dest, &rpc)) { 951 if (tsi->tsi_ops->tso_prep_rpc(tsu, tsu->tsu_dest, &rpc)) {
954 LASSERT(!rpc); 952 LASSERT(!rpc);
955 goto test_done; 953 goto test_done;
@@ -975,7 +973,7 @@ sfw_run_test(struct swi_workitem *wi)
975 rpc->crpc_timeout = rpc_timeout; 973 rpc->crpc_timeout = rpc_timeout;
976 srpc_post_rpc(rpc); 974 srpc_post_rpc(rpc);
977 spin_unlock(&rpc->crpc_lock); 975 spin_unlock(&rpc->crpc_lock);
978 return 0; 976 return;
979 977
980test_done: 978test_done:
981 /* 979 /*
@@ -985,9 +983,7 @@ test_done:
985 * - my batch is still active; no one can run it again now. 983 * - my batch is still active; no one can run it again now.
986 * Cancel pending schedules and prevent future schedule attempts: 984 * Cancel pending schedules and prevent future schedule attempts:
987 */ 985 */
988 swi_exit_workitem(wi);
989 sfw_test_unit_done(tsu); 986 sfw_test_unit_done(tsu);
990 return 1;
991} 987}
992 988
993static int 989static int
@@ -1016,8 +1012,8 @@ sfw_run_batch(struct sfw_batch *tsb)
1016 atomic_inc(&tsi->tsi_nactive); 1012 atomic_inc(&tsi->tsi_nactive);
1017 tsu->tsu_loop = tsi->tsi_loop; 1013 tsu->tsu_loop = tsi->tsi_loop;
1018 wi = &tsu->tsu_worker; 1014 wi = &tsu->tsu_worker;
1019 swi_init_workitem(wi, tsu, sfw_run_test, 1015 swi_init_workitem(wi, sfw_run_test,
1020 lst_sched_test[lnet_cpt_of_nid(tsu->tsu_dest.nid)]); 1016 lst_test_wq[lnet_cpt_of_nid(tsu->tsu_dest.nid)]);
1021 swi_schedule_workitem(wi); 1017 swi_schedule_workitem(wi);
1022 } 1018 }
1023 } 1019 }
@@ -1767,7 +1763,7 @@ sfw_shutdown(void)
1767 struct srpc_client_rpc, crpc_list); 1763 struct srpc_client_rpc, crpc_list);
1768 list_del(&rpc->crpc_list); 1764 list_del(&rpc->crpc_list);
1769 1765
1770 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc)); 1766 kfree(rpc);
1771 } 1767 }
1772 1768
1773 for (i = 0; ; i++) { 1769 for (i = 0; ; i++) {
@@ -1785,6 +1781,6 @@ sfw_shutdown(void)
1785 srpc_wait_service_shutdown(tsc->tsc_srv_service); 1781 srpc_wait_service_shutdown(tsc->tsc_srv_service);
1786 1782
1787 list_del(&tsc->tsc_list); 1783 list_del(&tsc->tsc_list);
1788 LIBCFS_FREE(tsc, sizeof(*tsc)); 1784 kfree(tsc);
1789 } 1785 }
1790} 1786}
diff --git a/drivers/staging/lustre/lnet/selftest/module.c b/drivers/staging/lustre/lnet/selftest/module.c
index 1d44d912f014..7359aa56d9b3 100644
--- a/drivers/staging/lustre/lnet/selftest/module.c
+++ b/drivers/staging/lustre/lnet/selftest/module.c
@@ -47,8 +47,8 @@ enum {
47 47
48static int lst_init_step = LST_INIT_NONE; 48static int lst_init_step = LST_INIT_NONE;
49 49
50struct cfs_wi_sched *lst_sched_serial; 50struct workqueue_struct *lst_serial_wq;
51struct cfs_wi_sched **lst_sched_test; 51struct workqueue_struct **lst_test_wq;
52 52
53static void 53static void
54lnet_selftest_exit(void) 54lnet_selftest_exit(void)
@@ -68,18 +68,16 @@ lnet_selftest_exit(void)
68 case LST_INIT_WI_TEST: 68 case LST_INIT_WI_TEST:
69 for (i = 0; 69 for (i = 0;
70 i < cfs_cpt_number(lnet_cpt_table()); i++) { 70 i < cfs_cpt_number(lnet_cpt_table()); i++) {
71 if (!lst_sched_test[i]) 71 if (!lst_test_wq[i])
72 continue; 72 continue;
73 cfs_wi_sched_destroy(lst_sched_test[i]); 73 destroy_workqueue(lst_test_wq[i]);
74 } 74 }
75 LIBCFS_FREE(lst_sched_test, 75 kvfree(lst_test_wq);
76 sizeof(lst_sched_test[0]) * 76 lst_test_wq = NULL;
77 cfs_cpt_number(lnet_cpt_table()));
78 lst_sched_test = NULL;
79 /* fall through */ 77 /* fall through */
80 case LST_INIT_WI_SERIAL: 78 case LST_INIT_WI_SERIAL:
81 cfs_wi_sched_destroy(lst_sched_serial); 79 destroy_workqueue(lst_serial_wq);
82 lst_sched_serial = NULL; 80 lst_serial_wq = NULL;
83 case LST_INIT_NONE: 81 case LST_INIT_NONE:
84 break; 82 break;
85 default: 83 default:
@@ -91,35 +89,45 @@ static int
91lnet_selftest_init(void) 89lnet_selftest_init(void)
92{ 90{
93 int nscheds; 91 int nscheds;
94 int rc; 92 int rc = -ENOMEM;
95 int i; 93 int i;
96 94
97 rc = cfs_wi_sched_create("lst_s", lnet_cpt_table(), CFS_CPT_ANY, 95 lst_serial_wq = alloc_ordered_workqueue("lst_s", 0);
98 1, &lst_sched_serial); 96 if (!lst_serial_wq) {
99 if (rc) {
100 CERROR("Failed to create serial WI scheduler for LST\n"); 97 CERROR("Failed to create serial WI scheduler for LST\n");
101 return rc; 98 return -ENOMEM;
102 } 99 }
103 lst_init_step = LST_INIT_WI_SERIAL; 100 lst_init_step = LST_INIT_WI_SERIAL;
104 101
105 nscheds = cfs_cpt_number(lnet_cpt_table()); 102 nscheds = cfs_cpt_number(lnet_cpt_table());
106 LIBCFS_ALLOC(lst_sched_test, sizeof(lst_sched_test[0]) * nscheds); 103 lst_test_wq = kvmalloc_array(nscheds, sizeof(lst_test_wq[0]),
107 if (!lst_sched_test) 104 GFP_KERNEL | __GFP_ZERO);
105 if (!lst_test_wq) {
106 rc = -ENOMEM;
108 goto error; 107 goto error;
108 }
109 109
110 lst_init_step = LST_INIT_WI_TEST; 110 lst_init_step = LST_INIT_WI_TEST;
111 for (i = 0; i < nscheds; i++) { 111 for (i = 0; i < nscheds; i++) {
112 int nthrs = cfs_cpt_weight(lnet_cpt_table(), i); 112 int nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
113 struct workqueue_attrs attrs = {0};
114 cpumask_var_t *mask = cfs_cpt_cpumask(lnet_cpt_table(), i);
113 115
114 /* reserve at least one CPU for LND */ 116 /* reserve at least one CPU for LND */
115 nthrs = max(nthrs - 1, 1); 117 nthrs = max(nthrs - 1, 1);
116 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i, 118 lst_test_wq[i] = alloc_workqueue("lst_t", WQ_UNBOUND, nthrs);
117 nthrs, &lst_sched_test[i]); 119 if (!lst_test_wq[i]) {
118 if (rc) {
119 CWARN("Failed to create CPU partition affinity WI scheduler %d for LST\n", 120 CWARN("Failed to create CPU partition affinity WI scheduler %d for LST\n",
120 i); 121 i);
122 rc = -ENOMEM;
121 goto error; 123 goto error;
122 } 124 }
125
126 if (mask && alloc_cpumask_var(&attrs.cpumask, GFP_KERNEL)) {
127 cpumask_copy(attrs.cpumask, *mask);
128 apply_workqueue_attrs(lst_test_wq[i], &attrs);
129 free_cpumask_var(attrs.cpumask);
130 }
123 } 131 }
124 132
125 rc = srpc_startup(); 133 rc = srpc_startup();
diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c
index ab7e8a8e58b8..f8198ad1046e 100644
--- a/drivers/staging/lustre/lnet/selftest/rpc.c
+++ b/drivers/staging/lustre/lnet/selftest/rpc.c
@@ -68,7 +68,7 @@ srpc_serv_portal(int svc_id)
68} 68}
69 69
70/* forward ref's */ 70/* forward ref's */
71int srpc_handle_rpc(struct swi_workitem *wi); 71void srpc_handle_rpc(struct swi_workitem *wi);
72 72
73void srpc_get_counters(struct srpc_counters *cnt) 73void srpc_get_counters(struct srpc_counters *cnt)
74{ 74{
@@ -113,7 +113,7 @@ srpc_free_bulk(struct srpc_bulk *bk)
113 __free_page(pg); 113 __free_page(pg);
114 } 114 }
115 115
116 LIBCFS_FREE(bk, offsetof(struct srpc_bulk, bk_iovs[bk->bk_niov])); 116 kfree(bk);
117} 117}
118 118
119struct srpc_bulk * 119struct srpc_bulk *
@@ -125,8 +125,8 @@ srpc_alloc_bulk(int cpt, unsigned int bulk_off, unsigned int bulk_npg,
125 125
126 LASSERT(bulk_npg > 0 && bulk_npg <= LNET_MAX_IOV); 126 LASSERT(bulk_npg > 0 && bulk_npg <= LNET_MAX_IOV);
127 127
128 LIBCFS_CPT_ALLOC(bk, lnet_cpt_table(), cpt, 128 bk = kzalloc_cpt(offsetof(struct srpc_bulk, bk_iovs[bulk_npg]),
129 offsetof(struct srpc_bulk, bk_iovs[bulk_npg])); 129 GFP_KERNEL, cpt);
130 if (!bk) { 130 if (!bk) {
131 CERROR("Can't allocate descriptor for %d pages\n", bulk_npg); 131 CERROR("Can't allocate descriptor for %d pages\n", bulk_npg);
132 return NULL; 132 return NULL;
@@ -176,9 +176,9 @@ srpc_init_server_rpc(struct srpc_server_rpc *rpc,
176 struct srpc_buffer *buffer) 176 struct srpc_buffer *buffer)
177{ 177{
178 memset(rpc, 0, sizeof(*rpc)); 178 memset(rpc, 0, sizeof(*rpc));
179 swi_init_workitem(&rpc->srpc_wi, rpc, srpc_handle_rpc, 179 swi_init_workitem(&rpc->srpc_wi, srpc_handle_rpc,
180 srpc_serv_is_framework(scd->scd_svc) ? 180 srpc_serv_is_framework(scd->scd_svc) ?
181 lst_sched_serial : lst_sched_test[scd->scd_cpt]); 181 lst_serial_wq : lst_test_wq[scd->scd_cpt]);
182 182
183 rpc->srpc_ev.ev_fired = 1; /* no event expected now */ 183 rpc->srpc_ev.ev_fired = 1; /* no event expected now */
184 184
@@ -214,7 +214,7 @@ srpc_service_fini(struct srpc_service *svc)
214 buf = list_entry(q->next, struct srpc_buffer, 214 buf = list_entry(q->next, struct srpc_buffer,
215 buf_list); 215 buf_list);
216 list_del(&buf->buf_list); 216 list_del(&buf->buf_list);
217 LIBCFS_FREE(buf, sizeof(*buf)); 217 kfree(buf);
218 } 218 }
219 } 219 }
220 220
@@ -225,7 +225,7 @@ srpc_service_fini(struct srpc_service *svc)
225 struct srpc_server_rpc, 225 struct srpc_server_rpc,
226 srpc_list); 226 srpc_list);
227 list_del(&rpc->srpc_list); 227 list_del(&rpc->srpc_list);
228 LIBCFS_FREE(rpc, sizeof(*rpc)); 228 kfree(rpc);
229 } 229 }
230 } 230 }
231 231
@@ -242,7 +242,7 @@ srpc_service_nrpcs(struct srpc_service *svc)
242 max(nrpcs, SFW_FRWK_WI_MIN) : max(nrpcs, SFW_TEST_WI_MIN); 242 max(nrpcs, SFW_FRWK_WI_MIN) : max(nrpcs, SFW_TEST_WI_MIN);
243} 243}
244 244
245int srpc_add_buffer(struct swi_workitem *wi); 245void srpc_add_buffer(struct swi_workitem *wi);
246 246
247static int 247static int
248srpc_service_init(struct srpc_service *svc) 248srpc_service_init(struct srpc_service *svc)
@@ -277,11 +277,11 @@ srpc_service_init(struct srpc_service *svc)
277 scd->scd_ev.ev_type = SRPC_REQUEST_RCVD; 277 scd->scd_ev.ev_type = SRPC_REQUEST_RCVD;
278 278
279 /* 279 /*
280 * NB: don't use lst_sched_serial for adding buffer, 280 * NB: don't use lst_serial_wq for adding buffer,
281 * see details in srpc_service_add_buffers() 281 * see details in srpc_service_add_buffers()
282 */ 282 */
283 swi_init_workitem(&scd->scd_buf_wi, scd, 283 swi_init_workitem(&scd->scd_buf_wi,
284 srpc_add_buffer, lst_sched_test[i]); 284 srpc_add_buffer, lst_test_wq[i]);
285 285
286 if (i && srpc_serv_is_framework(svc)) { 286 if (i && srpc_serv_is_framework(svc)) {
287 /* 287 /*
@@ -294,8 +294,7 @@ srpc_service_init(struct srpc_service *svc)
294 } 294 }
295 295
296 for (j = 0; j < nrpcs; j++) { 296 for (j = 0; j < nrpcs; j++) {
297 LIBCFS_CPT_ALLOC(rpc, lnet_cpt_table(), 297 rpc = kzalloc_cpt(sizeof(*rpc), GFP_NOFS, i);
298 i, sizeof(*rpc));
299 if (!rpc) { 298 if (!rpc) {
300 srpc_service_fini(svc); 299 srpc_service_fini(svc);
301 return -ENOMEM; 300 return -ENOMEM;
@@ -508,16 +507,16 @@ __must_hold(&scd->scd_lock)
508 list_del(&buf->buf_list); 507 list_del(&buf->buf_list);
509 spin_unlock(&scd->scd_lock); 508 spin_unlock(&scd->scd_lock);
510 509
511 LIBCFS_FREE(buf, sizeof(*buf)); 510 kfree(buf);
512 511
513 spin_lock(&scd->scd_lock); 512 spin_lock(&scd->scd_lock);
514 return rc; 513 return rc;
515} 514}
516 515
517int 516void
518srpc_add_buffer(struct swi_workitem *wi) 517srpc_add_buffer(struct swi_workitem *wi)
519{ 518{
520 struct srpc_service_cd *scd = wi->swi_workitem.wi_data; 519 struct srpc_service_cd *scd = container_of(wi, struct srpc_service_cd, scd_buf_wi);
521 struct srpc_buffer *buf; 520 struct srpc_buffer *buf;
522 int rc = 0; 521 int rc = 0;
523 522
@@ -535,7 +534,7 @@ srpc_add_buffer(struct swi_workitem *wi)
535 534
536 spin_unlock(&scd->scd_lock); 535 spin_unlock(&scd->scd_lock);
537 536
538 LIBCFS_ALLOC(buf, sizeof(*buf)); 537 buf = kzalloc(sizeof(*buf), GFP_NOFS);
539 if (!buf) { 538 if (!buf) {
540 CERROR("Failed to add new buf to service: %s\n", 539 CERROR("Failed to add new buf to service: %s\n",
541 scd->scd_svc->sv_name); 540 scd->scd_svc->sv_name);
@@ -547,7 +546,7 @@ srpc_add_buffer(struct swi_workitem *wi)
547 spin_lock(&scd->scd_lock); 546 spin_lock(&scd->scd_lock);
548 if (scd->scd_svc->sv_shuttingdown) { 547 if (scd->scd_svc->sv_shuttingdown) {
549 spin_unlock(&scd->scd_lock); 548 spin_unlock(&scd->scd_lock);
550 LIBCFS_FREE(buf, sizeof(*buf)); 549 kfree(buf);
551 550
552 spin_lock(&scd->scd_lock); 551 spin_lock(&scd->scd_lock);
553 rc = -ESHUTDOWN; 552 rc = -ESHUTDOWN;
@@ -573,7 +572,6 @@ srpc_add_buffer(struct swi_workitem *wi)
573 } 572 }
574 573
575 spin_unlock(&scd->scd_lock); 574 spin_unlock(&scd->scd_lock);
576 return 0;
577} 575}
578 576
579int 577int
@@ -605,15 +603,15 @@ srpc_service_add_buffers(struct srpc_service *sv, int nbuffer)
605 spin_lock(&scd->scd_lock); 603 spin_lock(&scd->scd_lock);
606 /* 604 /*
607 * NB: srpc_service_add_buffers() can be called inside 605 * NB: srpc_service_add_buffers() can be called inside
608 * thread context of lst_sched_serial, and we don't normally 606 * thread context of lst_serial_wq, and we don't normally
609 * allow to sleep inside thread context of WI scheduler 607 * allow to sleep inside thread context of WI scheduler
610 * because it will block current scheduler thread from doing 608 * because it will block current scheduler thread from doing
611 * anything else, even worse, it could deadlock if it's 609 * anything else, even worse, it could deadlock if it's
612 * waiting on result from another WI of the same scheduler. 610 * waiting on result from another WI of the same scheduler.
613 * However, it's safe at here because scd_buf_wi is scheduled 611 * However, it's safe at here because scd_buf_wi is scheduled
614 * by thread in a different WI scheduler (lst_sched_test), 612 * by thread in a different WI scheduler (lst_test_wq),
615 * so we don't have any risk of deadlock, though this could 613 * so we don't have any risk of deadlock, though this could
616 * block all WIs pending on lst_sched_serial for a moment 614 * block all WIs pending on lst_serial_wq for a moment
617 * which is not good but not fatal. 615 * which is not good but not fatal.
618 */ 616 */
619 lst_wait_until(scd->scd_buf_err || 617 lst_wait_until(scd->scd_buf_err ||
@@ -660,11 +658,9 @@ srpc_finish_service(struct srpc_service *sv)
660 LASSERT(sv->sv_shuttingdown); /* srpc_shutdown_service called */ 658 LASSERT(sv->sv_shuttingdown); /* srpc_shutdown_service called */
661 659
662 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) { 660 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
661 swi_cancel_workitem(&scd->scd_buf_wi);
662
663 spin_lock(&scd->scd_lock); 663 spin_lock(&scd->scd_lock);
664 if (!swi_deschedule_workitem(&scd->scd_buf_wi)) {
665 spin_unlock(&scd->scd_lock);
666 return 0;
667 }
668 664
669 if (scd->scd_buf_nposted > 0) { 665 if (scd->scd_buf_nposted > 0) {
670 CDEBUG(D_NET, "waiting for %d posted buffers to unlink\n", 666 CDEBUG(D_NET, "waiting for %d posted buffers to unlink\n",
@@ -680,11 +676,9 @@ srpc_finish_service(struct srpc_service *sv)
680 676
681 rpc = list_entry(scd->scd_rpc_active.next, 677 rpc = list_entry(scd->scd_rpc_active.next,
682 struct srpc_server_rpc, srpc_list); 678 struct srpc_server_rpc, srpc_list);
683 CNETERR("Active RPC %p on shutdown: sv %s, peer %s, wi %s scheduled %d running %d, ev fired %d type %d status %d lnet %d\n", 679 CNETERR("Active RPC %p on shutdown: sv %s, peer %s, wi %s, ev fired %d type %d status %d lnet %d\n",
684 rpc, sv->sv_name, libcfs_id2str(rpc->srpc_peer), 680 rpc, sv->sv_name, libcfs_id2str(rpc->srpc_peer),
685 swi_state2str(rpc->srpc_wi.swi_state), 681 swi_state2str(rpc->srpc_wi.swi_state),
686 rpc->srpc_wi.swi_workitem.wi_scheduled,
687 rpc->srpc_wi.swi_workitem.wi_running,
688 rpc->srpc_ev.ev_fired, rpc->srpc_ev.ev_type, 682 rpc->srpc_ev.ev_fired, rpc->srpc_ev.ev_type,
689 rpc->srpc_ev.ev_status, rpc->srpc_ev.ev_lnet); 683 rpc->srpc_ev.ev_status, rpc->srpc_ev.ev_lnet);
690 spin_unlock(&scd->scd_lock); 684 spin_unlock(&scd->scd_lock);
@@ -725,7 +719,7 @@ __must_hold(&scd->scd_lock)
725 } 719 }
726 720
727 spin_unlock(&scd->scd_lock); 721 spin_unlock(&scd->scd_lock);
728 LIBCFS_FREE(buf, sizeof(*buf)); 722 kfree(buf);
729 spin_lock(&scd->scd_lock); 723 spin_lock(&scd->scd_lock);
730} 724}
731 725
@@ -947,7 +941,6 @@ srpc_server_rpc_done(struct srpc_server_rpc *rpc, int status)
947 * Cancel pending schedules and prevent future schedule attempts: 941 * Cancel pending schedules and prevent future schedule attempts:
948 */ 942 */
949 LASSERT(rpc->srpc_ev.ev_fired); 943 LASSERT(rpc->srpc_ev.ev_fired);
950 swi_exit_workitem(&rpc->srpc_wi);
951 944
952 if (!sv->sv_shuttingdown && !list_empty(&scd->scd_buf_blocked)) { 945 if (!sv->sv_shuttingdown && !list_empty(&scd->scd_buf_blocked)) {
953 buffer = list_entry(scd->scd_buf_blocked.next, 946 buffer = list_entry(scd->scd_buf_blocked.next,
@@ -965,10 +958,10 @@ srpc_server_rpc_done(struct srpc_server_rpc *rpc, int status)
965} 958}
966 959
967/* handles an incoming RPC */ 960/* handles an incoming RPC */
968int 961void
969srpc_handle_rpc(struct swi_workitem *wi) 962srpc_handle_rpc(struct swi_workitem *wi)
970{ 963{
971 struct srpc_server_rpc *rpc = wi->swi_workitem.wi_data; 964 struct srpc_server_rpc *rpc = container_of(wi, struct srpc_server_rpc, srpc_wi);
972 struct srpc_service_cd *scd = rpc->srpc_scd; 965 struct srpc_service_cd *scd = rpc->srpc_scd;
973 struct srpc_service *sv = scd->scd_svc; 966 struct srpc_service *sv = scd->scd_svc;
974 struct srpc_event *ev = &rpc->srpc_ev; 967 struct srpc_event *ev = &rpc->srpc_ev;
@@ -987,9 +980,8 @@ srpc_handle_rpc(struct swi_workitem *wi)
987 980
988 if (ev->ev_fired) { /* no more event, OK to finish */ 981 if (ev->ev_fired) { /* no more event, OK to finish */
989 srpc_server_rpc_done(rpc, -ESHUTDOWN); 982 srpc_server_rpc_done(rpc, -ESHUTDOWN);
990 return 1;
991 } 983 }
992 return 0; 984 return;
993 } 985 }
994 986
995 spin_unlock(&scd->scd_lock); 987 spin_unlock(&scd->scd_lock);
@@ -1007,7 +999,7 @@ srpc_handle_rpc(struct swi_workitem *wi)
1007 if (!msg->msg_magic) { 999 if (!msg->msg_magic) {
1008 /* moaned already in srpc_lnet_ev_handler */ 1000 /* moaned already in srpc_lnet_ev_handler */
1009 srpc_server_rpc_done(rpc, EBADMSG); 1001 srpc_server_rpc_done(rpc, EBADMSG);
1010 return 1; 1002 return;
1011 } 1003 }
1012 1004
1013 srpc_unpack_msg_hdr(msg); 1005 srpc_unpack_msg_hdr(msg);
@@ -1023,7 +1015,7 @@ srpc_handle_rpc(struct swi_workitem *wi)
1023 LASSERT(!reply->status || !rpc->srpc_bulk); 1015 LASSERT(!reply->status || !rpc->srpc_bulk);
1024 if (rc) { 1016 if (rc) {
1025 srpc_server_rpc_done(rpc, rc); 1017 srpc_server_rpc_done(rpc, rc);
1026 return 1; 1018 return;
1027 } 1019 }
1028 } 1020 }
1029 1021
@@ -1032,7 +1024,7 @@ srpc_handle_rpc(struct swi_workitem *wi)
1032 if (rpc->srpc_bulk) { 1024 if (rpc->srpc_bulk) {
1033 rc = srpc_do_bulk(rpc); 1025 rc = srpc_do_bulk(rpc);
1034 if (!rc) 1026 if (!rc)
1035 return 0; /* wait for bulk */ 1027 return; /* wait for bulk */
1036 1028
1037 LASSERT(ev->ev_fired); 1029 LASSERT(ev->ev_fired);
1038 ev->ev_status = rc; 1030 ev->ev_status = rc;
@@ -1050,16 +1042,16 @@ srpc_handle_rpc(struct swi_workitem *wi)
1050 1042
1051 if (rc) { 1043 if (rc) {
1052 srpc_server_rpc_done(rpc, rc); 1044 srpc_server_rpc_done(rpc, rc);
1053 return 1; 1045 return;
1054 } 1046 }
1055 } 1047 }
1056 1048
1057 wi->swi_state = SWI_STATE_REPLY_SUBMITTED; 1049 wi->swi_state = SWI_STATE_REPLY_SUBMITTED;
1058 rc = srpc_send_reply(rpc); 1050 rc = srpc_send_reply(rpc);
1059 if (!rc) 1051 if (!rc)
1060 return 0; /* wait for reply */ 1052 return; /* wait for reply */
1061 srpc_server_rpc_done(rpc, rc); 1053 srpc_server_rpc_done(rpc, rc);
1062 return 1; 1054 return;
1063 1055
1064 case SWI_STATE_REPLY_SUBMITTED: 1056 case SWI_STATE_REPLY_SUBMITTED:
1065 if (!ev->ev_fired) { 1057 if (!ev->ev_fired) {
@@ -1072,10 +1064,8 @@ srpc_handle_rpc(struct swi_workitem *wi)
1072 1064
1073 wi->swi_state = SWI_STATE_DONE; 1065 wi->swi_state = SWI_STATE_DONE;
1074 srpc_server_rpc_done(rpc, ev->ev_status); 1066 srpc_server_rpc_done(rpc, ev->ev_status);
1075 return 1; 1067 return;
1076 } 1068 }
1077
1078 return 0;
1079} 1069}
1080 1070
1081static void 1071static void
@@ -1170,7 +1160,6 @@ srpc_client_rpc_done(struct srpc_client_rpc *rpc, int status)
1170 * Cancel pending schedules and prevent future schedule attempts: 1160 * Cancel pending schedules and prevent future schedule attempts:
1171 */ 1161 */
1172 LASSERT(!srpc_event_pending(rpc)); 1162 LASSERT(!srpc_event_pending(rpc));
1173 swi_exit_workitem(wi);
1174 1163
1175 spin_unlock(&rpc->crpc_lock); 1164 spin_unlock(&rpc->crpc_lock);
1176 1165
@@ -1178,7 +1167,7 @@ srpc_client_rpc_done(struct srpc_client_rpc *rpc, int status)
1178} 1167}
1179 1168
1180/* sends an outgoing RPC */ 1169/* sends an outgoing RPC */
1181int 1170void
1182srpc_send_rpc(struct swi_workitem *wi) 1171srpc_send_rpc(struct swi_workitem *wi)
1183{ 1172{
1184 int rc = 0; 1173 int rc = 0;
@@ -1188,7 +1177,7 @@ srpc_send_rpc(struct swi_workitem *wi)
1188 1177
1189 LASSERT(wi); 1178 LASSERT(wi);
1190 1179
1191 rpc = wi->swi_workitem.wi_data; 1180 rpc = container_of(wi, struct srpc_client_rpc, crpc_wi);
1192 1181
1193 LASSERT(rpc); 1182 LASSERT(rpc);
1194 LASSERT(wi == &rpc->crpc_wi); 1183 LASSERT(wi == &rpc->crpc_wi);
@@ -1214,7 +1203,7 @@ srpc_send_rpc(struct swi_workitem *wi)
1214 rc = srpc_prepare_reply(rpc); 1203 rc = srpc_prepare_reply(rpc);
1215 if (rc) { 1204 if (rc) {
1216 srpc_client_rpc_done(rpc, rc); 1205 srpc_client_rpc_done(rpc, rc);
1217 return 1; 1206 return;
1218 } 1207 }
1219 1208
1220 rc = srpc_prepare_bulk(rpc); 1209 rc = srpc_prepare_bulk(rpc);
@@ -1291,7 +1280,7 @@ srpc_send_rpc(struct swi_workitem *wi)
1291 1280
1292 wi->swi_state = SWI_STATE_DONE; 1281 wi->swi_state = SWI_STATE_DONE;
1293 srpc_client_rpc_done(rpc, rc); 1282 srpc_client_rpc_done(rpc, rc);
1294 return 1; 1283 return;
1295 } 1284 }
1296 1285
1297 if (rc) { 1286 if (rc) {
@@ -1308,10 +1297,9 @@ abort:
1308 1297
1309 if (!srpc_event_pending(rpc)) { 1298 if (!srpc_event_pending(rpc)) {
1310 srpc_client_rpc_done(rpc, -EINTR); 1299 srpc_client_rpc_done(rpc, -EINTR);
1311 return 1; 1300 return;
1312 } 1301 }
1313 } 1302 }
1314 return 0;
1315} 1303}
1316 1304
1317struct srpc_client_rpc * 1305struct srpc_client_rpc *
@@ -1322,8 +1310,8 @@ srpc_create_client_rpc(struct lnet_process_id peer, int service,
1322{ 1310{
1323 struct srpc_client_rpc *rpc; 1311 struct srpc_client_rpc *rpc;
1324 1312
1325 LIBCFS_ALLOC(rpc, offsetof(struct srpc_client_rpc, 1313 rpc = kzalloc(offsetof(struct srpc_client_rpc,
1326 crpc_bulk.bk_iovs[nbulkiov])); 1314 crpc_bulk.bk_iovs[nbulkiov]), GFP_KERNEL);
1327 if (!rpc) 1315 if (!rpc)
1328 return NULL; 1316 return NULL;
1329 1317
diff --git a/drivers/staging/lustre/lnet/selftest/selftest.h b/drivers/staging/lustre/lnet/selftest/selftest.h
index 8c10f0f149d5..ad04534f000c 100644
--- a/drivers/staging/lustre/lnet/selftest/selftest.h
+++ b/drivers/staging/lustre/lnet/selftest/selftest.h
@@ -169,11 +169,11 @@ struct srpc_buffer {
169}; 169};
170 170
171struct swi_workitem; 171struct swi_workitem;
172typedef int (*swi_action_t) (struct swi_workitem *); 172typedef void (*swi_action_t) (struct swi_workitem *);
173 173
174struct swi_workitem { 174struct swi_workitem {
175 struct cfs_wi_sched *swi_sched; 175 struct workqueue_struct *swi_wq;
176 struct cfs_workitem swi_workitem; 176 struct work_struct swi_work;
177 swi_action_t swi_action; 177 swi_action_t swi_action;
178 int swi_state; 178 int swi_state;
179}; 179};
@@ -444,7 +444,7 @@ void srpc_free_bulk(struct srpc_bulk *bk);
444struct srpc_bulk *srpc_alloc_bulk(int cpt, unsigned int off, 444struct srpc_bulk *srpc_alloc_bulk(int cpt, unsigned int off,
445 unsigned int bulk_npg, unsigned int bulk_len, 445 unsigned int bulk_npg, unsigned int bulk_len,
446 int sink); 446 int sink);
447int srpc_send_rpc(struct swi_workitem *wi); 447void srpc_send_rpc(struct swi_workitem *wi);
448int srpc_send_reply(struct srpc_server_rpc *rpc); 448int srpc_send_reply(struct srpc_server_rpc *rpc);
449int srpc_add_service(struct srpc_service *sv); 449int srpc_add_service(struct srpc_service *sv);
450int srpc_remove_service(struct srpc_service *sv); 450int srpc_remove_service(struct srpc_service *sv);
@@ -456,8 +456,8 @@ void srpc_service_remove_buffers(struct srpc_service *sv, int nbuffer);
456void srpc_get_counters(struct srpc_counters *cnt); 456void srpc_get_counters(struct srpc_counters *cnt);
457void srpc_set_counters(const struct srpc_counters *cnt); 457void srpc_set_counters(const struct srpc_counters *cnt);
458 458
459extern struct cfs_wi_sched *lst_sched_serial; 459extern struct workqueue_struct *lst_serial_wq;
460extern struct cfs_wi_sched **lst_sched_test; 460extern struct workqueue_struct **lst_test_wq;
461 461
462static inline int 462static inline int
463srpc_serv_is_framework(struct srpc_service *svc) 463srpc_serv_is_framework(struct srpc_service *svc)
@@ -465,42 +465,36 @@ srpc_serv_is_framework(struct srpc_service *svc)
465 return svc->sv_id < SRPC_FRAMEWORK_SERVICE_MAX_ID; 465 return svc->sv_id < SRPC_FRAMEWORK_SERVICE_MAX_ID;
466} 466}
467 467
468static inline int 468static void
469swi_wi_action(struct cfs_workitem *wi) 469swi_wi_action(struct work_struct *wi)
470{ 470{
471 struct swi_workitem *swi; 471 struct swi_workitem *swi;
472 472
473 swi = container_of(wi, struct swi_workitem, swi_workitem); 473 swi = container_of(wi, struct swi_workitem, swi_work);
474 474
475 return swi->swi_action(swi); 475 swi->swi_action(swi);
476} 476}
477 477
478static inline void 478static inline void
479swi_init_workitem(struct swi_workitem *swi, void *data, 479swi_init_workitem(struct swi_workitem *swi,
480 swi_action_t action, struct cfs_wi_sched *sched) 480 swi_action_t action, struct workqueue_struct *wq)
481{ 481{
482 swi->swi_sched = sched; 482 swi->swi_wq = wq;
483 swi->swi_action = action; 483 swi->swi_action = action;
484 swi->swi_state = SWI_STATE_NEWBORN; 484 swi->swi_state = SWI_STATE_NEWBORN;
485 cfs_wi_init(&swi->swi_workitem, data, swi_wi_action); 485 INIT_WORK(&swi->swi_work, swi_wi_action);
486} 486}
487 487
488static inline void 488static inline void
489swi_schedule_workitem(struct swi_workitem *wi) 489swi_schedule_workitem(struct swi_workitem *wi)
490{ 490{
491 cfs_wi_schedule(wi->swi_sched, &wi->swi_workitem); 491 queue_work(wi->swi_wq, &wi->swi_work);
492}
493
494static inline void
495swi_exit_workitem(struct swi_workitem *swi)
496{
497 cfs_wi_exit(swi->swi_sched, &swi->swi_workitem);
498} 492}
499 493
500static inline int 494static inline int
501swi_deschedule_workitem(struct swi_workitem *swi) 495swi_cancel_workitem(struct swi_workitem *swi)
502{ 496{
503 return cfs_wi_deschedule(swi->swi_sched, &swi->swi_workitem); 497 return cancel_work_sync(&swi->swi_work);
504} 498}
505 499
506int sfw_startup(void); 500int sfw_startup(void);
@@ -516,7 +510,7 @@ srpc_destroy_client_rpc(struct srpc_client_rpc *rpc)
516 LASSERT(!atomic_read(&rpc->crpc_refcount)); 510 LASSERT(!atomic_read(&rpc->crpc_refcount));
517 511
518 if (!rpc->crpc_fini) 512 if (!rpc->crpc_fini)
519 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc)); 513 kfree(rpc);
520 else 514 else
521 (*rpc->crpc_fini)(rpc); 515 (*rpc->crpc_fini)(rpc);
522} 516}
@@ -533,8 +527,8 @@ srpc_init_client_rpc(struct srpc_client_rpc *rpc, struct lnet_process_id peer,
533 crpc_bulk.bk_iovs[nbulkiov])); 527 crpc_bulk.bk_iovs[nbulkiov]));
534 528
535 INIT_LIST_HEAD(&rpc->crpc_list); 529 INIT_LIST_HEAD(&rpc->crpc_list);
536 swi_init_workitem(&rpc->crpc_wi, rpc, srpc_send_rpc, 530 swi_init_workitem(&rpc->crpc_wi, srpc_send_rpc,
537 lst_sched_test[lnet_cpt_of_nid(peer.nid)]); 531 lst_test_wq[lnet_cpt_of_nid(peer.nid)]);
538 spin_lock_init(&rpc->crpc_lock); 532 spin_lock_init(&rpc->crpc_lock);
539 atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */ 533 atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */
540 534
diff --git a/drivers/staging/lustre/lustre/fld/fld_cache.c b/drivers/staging/lustre/lustre/fld/fld_cache.c
index 7d6a7106c0a5..ecf8b9e1ed5c 100644
--- a/drivers/staging/lustre/lustre/fld/fld_cache.c
+++ b/drivers/staging/lustre/lustre/fld/fld_cache.c
@@ -213,19 +213,18 @@ static inline void fld_cache_entry_add(struct fld_cache *cache,
213 */ 213 */
214static int fld_cache_shrink(struct fld_cache *cache) 214static int fld_cache_shrink(struct fld_cache *cache)
215{ 215{
216 struct fld_cache_entry *flde;
217 struct list_head *curr;
218 int num = 0; 216 int num = 0;
219 217
220 if (cache->fci_cache_count < cache->fci_cache_size) 218 if (cache->fci_cache_count < cache->fci_cache_size)
221 return 0; 219 return 0;
222 220
223 curr = cache->fci_lru.prev;
224
225 while (cache->fci_cache_count + cache->fci_threshold > 221 while (cache->fci_cache_count + cache->fci_threshold >
226 cache->fci_cache_size && curr != &cache->fci_lru) { 222 cache->fci_cache_size &&
227 flde = list_entry(curr, struct fld_cache_entry, fce_lru); 223 !list_empty(&cache->fci_lru)) {
228 curr = curr->prev; 224 struct fld_cache_entry *flde =
225 list_last_entry(&cache->fci_lru,
226 struct fld_cache_entry, fce_lru);
227
229 fld_cache_entry_delete(cache, flde); 228 fld_cache_entry_delete(cache, flde);
230 num++; 229 num++;
231 } 230 }
diff --git a/drivers/staging/lustre/lustre/include/lustre_disk.h b/drivers/staging/lustre/lustre/include/lustre_disk.h
index 8f1a22527006..100e993ab00b 100644
--- a/drivers/staging/lustre/lustre/include/lustre_disk.h
+++ b/drivers/staging/lustre/lustre/include/lustre_disk.h
@@ -141,9 +141,9 @@ struct lustre_sb_info {
141/* obd_mount.c */ 141/* obd_mount.c */
142 142
143int lustre_start_mgc(struct super_block *sb); 143int lustre_start_mgc(struct super_block *sb);
144void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb, 144void lustre_register_super_ops(struct module *mod,
145 struct vfsmount *mnt)); 145 int (*cfs)(struct super_block *sb),
146void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb)); 146 void (*ksc)(struct super_block *sb));
147int lustre_common_put_super(struct super_block *sb); 147int lustre_common_put_super(struct super_block *sb);
148 148
149int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id, int type); 149int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id, int type);
diff --git a/drivers/staging/lustre/lustre/include/lustre_sec.h b/drivers/staging/lustre/lustre/include/lustre_sec.h
index a40f706a53a1..64b6fd4fed8f 100644
--- a/drivers/staging/lustre/lustre/include/lustre_sec.h
+++ b/drivers/staging/lustre/lustre/include/lustre_sec.h
@@ -341,8 +341,8 @@ void sptlrpc_conf_client_adapt(struct obd_device *obd);
341#define SPTLRPC_MAX_PAYLOAD (1024) 341#define SPTLRPC_MAX_PAYLOAD (1024)
342 342
343struct vfs_cred { 343struct vfs_cred {
344 uint32_t vc_uid; 344 u32 vc_uid;
345 uint32_t vc_gid; 345 u32 vc_gid;
346}; 346};
347 347
348struct ptlrpc_ctx_ops { 348struct ptlrpc_ctx_ops {
diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h
index 67c535c5aa98..531e8ddfa9e5 100644
--- a/drivers/staging/lustre/lustre/include/obd_class.h
+++ b/drivers/staging/lustre/lustre/include/obd_class.h
@@ -40,22 +40,19 @@
40#include <lustre_lib.h> 40#include <lustre_lib.h>
41#include <lprocfs_status.h> 41#include <lprocfs_status.h>
42 42
43#define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay 43/* requests should be send without delay and resends for avoid deadlocks */
44 * and resends for avoid deadlocks 44#define OBD_STATFS_NODELAY 0x0001
45 */ 45/* the statfs callback should not update obd_osfs_age */
46#define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update 46#define OBD_STATFS_FROM_CACHE 0x0002
47 * obd_osfs_age 47/* the statfs is only for retrieving information from MDT0 */
48 */ 48#define OBD_STATFS_FOR_MDT0 0x0004
49#define OBD_STATFS_FOR_MDT0 0x0004 /* The statfs is only for retrieving
50 * information from MDT0.
51 */
52 49
53/* OBD Device Declarations */ 50/* OBD Device Declarations */
54extern struct obd_device *obd_devs[MAX_OBD_DEVICES]; 51extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
55extern rwlock_t obd_dev_lock; 52extern rwlock_t obd_dev_lock;
56 53
57/* OBD Operations Declarations */ 54/* OBD Operations Declarations */
58struct obd_device *class_exp2obd(struct obd_export *); 55struct obd_device *class_exp2obd(struct obd_export *exp);
59int class_handle_ioctl(unsigned int cmd, unsigned long arg); 56int class_handle_ioctl(unsigned int cmd, unsigned long arg);
60int lustre_get_jobid(char *jobid); 57int lustre_get_jobid(char *jobid);
61 58
@@ -63,10 +60,10 @@ struct lu_device_type;
63 60
64/* genops.c */ 61/* genops.c */
65extern struct list_head obd_types; 62extern struct list_head obd_types;
66struct obd_export *class_conn2export(struct lustre_handle *); 63struct obd_export *class_conn2export(struct lustre_handle *conn);
67int class_register_type(struct obd_ops *, struct md_ops *, 64int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
68 const char *nm, struct lu_device_type *ldt); 65 const char *name, struct lu_device_type *ldt);
69int class_unregister_type(const char *nm); 66int class_unregister_type(const char *name);
70 67
71struct obd_device *class_newdev(const char *type_name, const char *name); 68struct obd_device *class_newdev(const char *type_name, const char *name);
72void class_release_dev(struct obd_device *obd); 69void class_release_dev(struct obd_device *obd);
@@ -137,7 +134,7 @@ int class_config_llog_handler(const struct lu_env *env,
137 struct llog_rec_hdr *rec, void *data); 134 struct llog_rec_hdr *rec, void *data);
138int class_add_uuid(const char *uuid, __u64 nid); 135int class_add_uuid(const char *uuid, __u64 nid);
139 136
140/*obdecho*/ 137/* obdecho */
141void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars); 138void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
142 139
143#define CFG_F_START 0x01 /* Set when we start updating from a log */ 140#define CFG_F_START 0x01 /* Set when we start updating from a log */
@@ -148,13 +145,13 @@ void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
148 145
149/* Passed as data param to class_config_parse_llog */ 146/* Passed as data param to class_config_parse_llog */
150struct config_llog_instance { 147struct config_llog_instance {
151 char *cfg_obdname; 148 char *cfg_obdname;
152 void *cfg_instance; 149 void *cfg_instance;
153 struct super_block *cfg_sb; 150 struct super_block *cfg_sb;
154 struct obd_uuid cfg_uuid; 151 struct obd_uuid cfg_uuid;
155 llog_cb_t cfg_callback; 152 llog_cb_t cfg_callback;
156 int cfg_last_idx; /* for partial llog processing */ 153 int cfg_last_idx; /* for partial llog processing */
157 int cfg_flags; 154 int cfg_flags;
158}; 155};
159 156
160int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt, 157int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
@@ -172,30 +169,31 @@ enum {
172 169
173/* list of active configuration logs */ 170/* list of active configuration logs */
174struct config_llog_data { 171struct config_llog_data {
175 struct ldlm_res_id cld_resid; 172 struct ldlm_res_id cld_resid;
176 struct config_llog_instance cld_cfg; 173 struct config_llog_instance cld_cfg;
177 struct list_head cld_list_chain; 174 struct list_head cld_list_chain;
178 atomic_t cld_refcount; 175 atomic_t cld_refcount;
179 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */ 176 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
180 struct config_llog_data *cld_params; /* common parameters log */ 177 struct config_llog_data *cld_params; /* common parameters log */
181 struct config_llog_data *cld_recover;/* imperative recover log */ 178 struct config_llog_data *cld_recover;/* imperative recover log */
182 struct obd_export *cld_mgcexp; 179 struct obd_export *cld_mgcexp;
183 struct mutex cld_lock; 180 struct mutex cld_lock;
184 int cld_type; 181 int cld_type;
185 unsigned int cld_stopping:1, /* we were told to stop 182 unsigned int cld_stopping:1, /*
186 * watching 183 * we were told to stop
187 */ 184 * watching
188 cld_lostlock:1; /* lock not requeued */ 185 */
189 char cld_logname[0]; 186 cld_lostlock:1; /* lock not requeued */
187 char cld_logname[0];
190}; 188};
191 189
192struct lustre_profile { 190struct lustre_profile {
193 struct list_head lp_list; 191 struct list_head lp_list;
194 char *lp_profile; 192 char *lp_profile;
195 char *lp_dt; 193 char *lp_dt;
196 char *lp_md; 194 char *lp_md;
197 int lp_refs; 195 int lp_refs;
198 bool lp_list_deleted; 196 bool lp_list_deleted;
199}; 197};
200 198
201struct lustre_profile *class_get_profile(const char *prof); 199struct lustre_profile *class_get_profile(const char *prof);
@@ -205,9 +203,11 @@ void class_del_profiles(void);
205 203
206#if LUSTRE_TRACKS_LOCK_EXP_REFS 204#if LUSTRE_TRACKS_LOCK_EXP_REFS
207 205
208void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *); 206void __class_export_add_lock_ref(struct obd_export *exp,
209void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *); 207 struct ldlm_lock *lock);
210extern void (*class_export_dump_hook)(struct obd_export *); 208void __class_export_del_lock_ref(struct obd_export *exp,
209 struct ldlm_lock *lock);
210extern void (*class_export_dump_hook)(struct obd_export *exp);
211 211
212#else 212#else
213 213
@@ -223,8 +223,8 @@ struct obd_export *class_new_export(struct obd_device *obddev,
223 struct obd_uuid *cluuid); 223 struct obd_uuid *cluuid);
224void class_unlink_export(struct obd_export *exp); 224void class_unlink_export(struct obd_export *exp);
225 225
226struct obd_import *class_import_get(struct obd_import *); 226struct obd_import *class_import_get(struct obd_import *imp);
227void class_import_put(struct obd_import *); 227void class_import_put(struct obd_import *imp);
228struct obd_import *class_new_import(struct obd_device *obd); 228struct obd_import *class_new_import(struct obd_device *obd);
229void class_destroy_import(struct obd_import *exp); 229void class_destroy_import(struct obd_import *exp);
230 230
@@ -299,7 +299,8 @@ void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
299#define MDP(dev, op) (dev)->obd_type->typ_md_ops->op 299#define MDP(dev, op) (dev)->obd_type->typ_md_ops->op
300#define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op 300#define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
301 301
302/* Ensure obd_setup: used for cleanup which must be called 302/*
303 * Ensure obd_setup: used for cleanup which must be called
303 * while obd is stopping 304 * while obd is stopping
304 */ 305 */
305static inline int obd_check_dev(struct obd_device *obd) 306static inline int obd_check_dev(struct obd_device *obd)
@@ -326,108 +327,116 @@ static inline int obd_check_dev_active(struct obd_device *obd)
326 return rc; 327 return rc;
327} 328}
328 329
329#define OBD_COUNTER_OFFSET(op) \ 330#define OBD_COUNTER_OFFSET(op) \
330 ((offsetof(struct obd_ops, op) - \ 331 ((offsetof(struct obd_ops, op) - \
331 offsetof(struct obd_ops, iocontrol)) \ 332 offsetof(struct obd_ops, iocontrol)) \
332 / sizeof(((struct obd_ops *)(0))->iocontrol)) 333 / sizeof(((struct obd_ops *)(0))->iocontrol))
333
334#define OBD_COUNTER_INCREMENT(obdx, op) \
335 if ((obdx)->obd_stats) { \
336 unsigned int coffset; \
337 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
338 OBD_COUNTER_OFFSET(op); \
339 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
340 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
341 }
342 334
343#define EXP_COUNTER_INCREMENT(export, op) \ 335#define OBD_COUNTER_INCREMENT(obdx, op) \
344 if ((export)->exp_obd->obd_stats) { \ 336do { \
337 if ((obdx)->obd_stats) { \
345 unsigned int coffset; \ 338 unsigned int coffset; \
339 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
340 OBD_COUNTER_OFFSET(op); \
341 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
342 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
343 } \
344} while (0)
345
346#define EXP_COUNTER_INCREMENT(export, op) \
347do { \
348 if ((export)->exp_obd->obd_stats) { \
349 unsigned int coffset; \
346 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \ 350 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
347 OBD_COUNTER_OFFSET(op); \ 351 OBD_COUNTER_OFFSET(op); \
348 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \ 352 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
349 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \ 353 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
350 } 354 } \
355} while (0)
351 356
352#define MD_COUNTER_OFFSET(op) \ 357#define MD_COUNTER_OFFSET(op) \
353 ((offsetof(struct md_ops, op) - \ 358 ((offsetof(struct md_ops, op) - \
354 offsetof(struct md_ops, getstatus)) \ 359 offsetof(struct md_ops, getstatus)) \
355 / sizeof(((struct md_ops *)(0))->getstatus)) 360 / sizeof(((struct md_ops *)(0))->getstatus))
356 361
357#define MD_COUNTER_INCREMENT(obdx, op) \ 362#define MD_COUNTER_INCREMENT(obdx, op) \
358 if ((obd)->md_stats) { \ 363do { \
359 unsigned int coffset; \ 364 if ((obd)->md_stats) { \
365 unsigned int coffset; \
360 coffset = (unsigned int)((obdx)->md_cntr_base) + \ 366 coffset = (unsigned int)((obdx)->md_cntr_base) + \
361 MD_COUNTER_OFFSET(op); \ 367 MD_COUNTER_OFFSET(op); \
362 LASSERT(coffset < (obdx)->md_stats->ls_num); \ 368 LASSERT(coffset < (obdx)->md_stats->ls_num); \
363 lprocfs_counter_incr((obdx)->md_stats, coffset); \ 369 lprocfs_counter_incr((obdx)->md_stats, coffset); \
364 } 370 } \
371} while (0)
365 372
366#define EXP_MD_COUNTER_INCREMENT(export, op) \ 373#define EXP_MD_COUNTER_INCREMENT(export, op) \
367 if ((export)->exp_obd->obd_stats) { \ 374do { \
368 unsigned int coffset; \ 375 if ((export)->exp_obd->obd_stats) { \
369 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \ 376 unsigned int coffset; \
370 MD_COUNTER_OFFSET(op); \ 377 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
371 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \ 378 MD_COUNTER_OFFSET(op); \
372 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \ 379 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
373 if ((export)->exp_md_stats) \ 380 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
374 lprocfs_counter_incr( \ 381 if ((export)->exp_md_stats) \
382 lprocfs_counter_incr( \
375 (export)->exp_md_stats, coffset); \ 383 (export)->exp_md_stats, coffset); \
376 } 384 } \
385} while (0)
377 386
378#define EXP_CHECK_MD_OP(exp, op) \ 387#define EXP_CHECK_MD_OP(exp, op) \
379do { \ 388do { \
380 if (!(exp)) { \ 389 if (!(exp)) { \
381 CERROR("obd_" #op ": NULL export\n"); \ 390 CERROR("obd_" #op ": NULL export\n"); \
382 return -ENODEV; \ 391 return -ENODEV; \
383 } \ 392 } \
384 if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \ 393 if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \
385 CERROR("obd_" #op ": cleaned up obd\n"); \ 394 CERROR("obd_" #op ": cleaned up obd\n"); \
386 return -EOPNOTSUPP; \ 395 return -EOPNOTSUPP; \
387 } \ 396 } \
388 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \ 397 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
389 CERROR("obd_" #op ": dev %s/%d no operation\n", \ 398 CERROR("obd_" #op ": dev %s/%d no operation\n", \
390 (exp)->exp_obd->obd_name, \ 399 (exp)->exp_obd->obd_name, \
391 (exp)->exp_obd->obd_minor); \ 400 (exp)->exp_obd->obd_minor); \
392 return -EOPNOTSUPP; \ 401 return -EOPNOTSUPP; \
393 } \ 402 } \
394} while (0) 403} while (0)
395 404
396#define OBD_CHECK_DT_OP(obd, op, err) \ 405#define OBD_CHECK_DT_OP(obd, op, err) \
397do { \ 406do { \
398 if (!OBT(obd) || !OBP((obd), op)) { \ 407 if (!OBT(obd) || !OBP((obd), op)) { \
399 if (err) \ 408 if (err) \
400 CERROR("obd_" #op ": dev %d no operation\n", \ 409 CERROR("obd_" #op ": dev %d no operation\n", \
401 obd->obd_minor); \ 410 obd->obd_minor); \
402 return err; \ 411 return err; \
403 } \ 412 } \
404} while (0) 413} while (0)
405 414
406#define EXP_CHECK_DT_OP(exp, op) \ 415#define EXP_CHECK_DT_OP(exp, op) \
407do { \ 416do { \
408 if (!(exp)) { \ 417 if (!(exp)) { \
409 CERROR("obd_" #op ": NULL export\n"); \ 418 CERROR("obd_" #op ": NULL export\n"); \
410 return -ENODEV; \ 419 return -ENODEV; \
411 } \ 420 } \
412 if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \ 421 if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \
413 CERROR("obd_" #op ": cleaned up obd\n"); \ 422 CERROR("obd_" #op ": cleaned up obd\n"); \
414 return -EOPNOTSUPP; \ 423 return -EOPNOTSUPP; \
415 } \ 424 } \
416 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \ 425 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
417 CERROR("obd_" #op ": dev %d no operation\n", \ 426 CERROR("obd_" #op ": dev %d no operation\n", \
418 (exp)->exp_obd->obd_minor); \ 427 (exp)->exp_obd->obd_minor); \
419 return -EOPNOTSUPP; \ 428 return -EOPNOTSUPP; \
420 } \ 429 } \
421} while (0) 430} while (0)
422 431
423#define CTXT_CHECK_OP(ctxt, op, err) \ 432#define CTXT_CHECK_OP(ctxt, op, err) \
424do { \ 433do { \
425 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \ 434 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
426 if (err) \ 435 if (err) \
427 CERROR("lop_" #op ": dev %d no operation\n", \ 436 CERROR("lop_" #op ": dev %d no operation\n", \
428 ctxt->loc_obd->obd_minor); \ 437 ctxt->loc_obd->obd_minor); \
429 return err; \ 438 return err; \
430 } \ 439 } \
431} while (0) 440} while (0)
432 441
433static inline int class_devno_max(void) 442static inline int class_devno_max(void)
@@ -481,14 +490,11 @@ static inline int obd_set_info_async(const struct lu_env *env,
481 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations. 490 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
482 */ 491 */
483 492
484#define DECLARE_LU_VARS(ldt, d) \
485 struct lu_device_type *ldt; \
486 struct lu_device *d
487
488static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg) 493static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
489{ 494{
490 int rc; 495 int rc;
491 DECLARE_LU_VARS(ldt, d); 496 struct lu_device_type *ldt;
497 struct lu_device *d;
492 498
493 ldt = obd->obd_type->typ_lu; 499 ldt = obd->obd_type->typ_lu;
494 if (ldt) { 500 if (ldt) {
@@ -526,7 +532,8 @@ static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
526static inline int obd_precleanup(struct obd_device *obd) 532static inline int obd_precleanup(struct obd_device *obd)
527{ 533{
528 int rc; 534 int rc;
529 DECLARE_LU_VARS(ldt, d); 535 struct lu_device_type *ldt;
536 struct lu_device *d;
530 537
531 rc = obd_check_dev(obd); 538 rc = obd_check_dev(obd);
532 if (rc) 539 if (rc)
@@ -552,7 +559,8 @@ static inline int obd_precleanup(struct obd_device *obd)
552static inline int obd_cleanup(struct obd_device *obd) 559static inline int obd_cleanup(struct obd_device *obd)
553{ 560{
554 int rc; 561 int rc;
555 DECLARE_LU_VARS(ldt, d); 562 struct lu_device_type *ldt;
563 struct lu_device *d;
556 564
557 rc = obd_check_dev(obd); 565 rc = obd_check_dev(obd);
558 if (rc) 566 if (rc)
@@ -579,7 +587,8 @@ static inline int obd_cleanup(struct obd_device *obd)
579 587
580static inline void obd_cleanup_client_import(struct obd_device *obd) 588static inline void obd_cleanup_client_import(struct obd_device *obd)
581{ 589{
582 /* If we set up but never connected, the 590 /*
591 * If we set up but never connected, the
583 * client import will not have been cleaned. 592 * client import will not have been cleaned.
584 */ 593 */
585 down_write(&obd->u.cli.cl_sem); 594 down_write(&obd->u.cli.cl_sem);
@@ -600,7 +609,8 @@ static inline int
600obd_process_config(struct obd_device *obd, int datalen, void *data) 609obd_process_config(struct obd_device *obd, int datalen, void *data)
601{ 610{
602 int rc; 611 int rc;
603 DECLARE_LU_VARS(ldt, d); 612 struct lu_device_type *ldt;
613 struct lu_device *d;
604 614
605 rc = obd_check_dev(obd); 615 rc = obd_check_dev(obd);
606 if (rc) 616 if (rc)
@@ -717,7 +727,8 @@ static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
717 return uuid; 727 return uuid;
718} 728}
719 729
720/** Create a new /a exp on device /a obd for the uuid /a cluuid 730/*
731 * Create a new /a exp on device /a obd for the uuid /a cluuid
721 * @param exp New export handle 732 * @param exp New export handle
722 * @param d Connect data, supported flags are set, flags also understood 733 * @param d Connect data, supported flags are set, flags also understood
723 * by obd are returned. 734 * by obd are returned.
@@ -729,7 +740,8 @@ static inline int obd_connect(const struct lu_env *env,
729 void *localdata) 740 void *localdata)
730{ 741{
731 int rc; 742 int rc;
732 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition 743 __u64 ocf = data ? data->ocd_connect_flags : 0; /*
744 * for post-condition
733 * check 745 * check
734 */ 746 */
735 747
@@ -838,7 +850,9 @@ static inline int obd_pool_del(struct obd_device *obd, char *poolname)
838 return rc; 850 return rc;
839} 851}
840 852
841static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname) 853static inline int obd_pool_add(struct obd_device *obd,
854 char *poolname,
855 char *ostname)
842{ 856{
843 int rc; 857 int rc;
844 858
@@ -849,7 +863,9 @@ static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ost
849 return rc; 863 return rc;
850} 864}
851 865
852static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname) 866static inline int obd_pool_rem(struct obd_device *obd,
867 char *poolname,
868 char *ostname)
853{ 869{
854 int rc; 870 int rc;
855 871
@@ -894,7 +910,8 @@ static inline int obd_destroy_export(struct obd_export *exp)
894 return 0; 910 return 0;
895} 911}
896 912
897/* @max_age is the oldest time in jiffies that we accept using a cached data. 913/*
914 * @max_age is the oldest time in jiffies that we accept using a cached data.
898 * If the cache is older than @max_age we will get a new value from the 915 * If the cache is older than @max_age we will get a new value from the
899 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. 916 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness.
900 */ 917 */
@@ -955,7 +972,8 @@ static inline int obd_statfs_rqset(struct obd_export *exp,
955 return rc; 972 return rc;
956} 973}
957 974
958/* @max_age is the oldest time in jiffies that we accept using a cached data. 975/*
976 * @max_age is the oldest time in jiffies that we accept using a cached data.
959 * If the cache is older than @max_age we will get a new value from the 977 * If the cache is older than @max_age we will get a new value from the
960 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. 978 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness.
961 */ 979 */
@@ -983,7 +1001,8 @@ static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
983 spin_unlock(&obd->obd_osfs_lock); 1001 spin_unlock(&obd->obd_osfs_lock);
984 } 1002 }
985 } else { 1003 } else {
986 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n", 1004 CDEBUG(D_SUPER,
1005 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
987 obd->obd_name, &obd->obd_osfs, 1006 obd->obd_name, &obd->obd_osfs,
988 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks, 1007 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
989 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files); 1008 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
@@ -1118,7 +1137,8 @@ static inline int obd_quotactl(struct obd_export *exp,
1118static inline int obd_health_check(const struct lu_env *env, 1137static inline int obd_health_check(const struct lu_env *env,
1119 struct obd_device *obd) 1138 struct obd_device *obd)
1120{ 1139{
1121 /* returns: 0 on healthy 1140 /*
1141 * returns: 0 on healthy
1122 * >0 on unhealthy + reason code/flag 1142 * >0 on unhealthy + reason code/flag
1123 * however the only supported reason == 1 right now 1143 * however the only supported reason == 1 right now
1124 * We'll need to define some better reasons 1144 * We'll need to define some better reasons
@@ -1491,7 +1511,8 @@ static inline int md_get_fid_from_lsm(struct obd_export *exp,
1491 return rc; 1511 return rc;
1492} 1512}
1493 1513
1494/* Unpack an MD struct from disk to in-memory format. 1514/*
1515 * Unpack an MD struct from disk to in-memory format.
1495 * Returns +ve size of unpacked MD (0 for free), or -ve error. 1516 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1496 * 1517 *
1497 * If *plsm != NULL and lmm == NULL then *lsm will be freed. 1518 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
@@ -1523,11 +1544,12 @@ struct lwp_register_item {
1523 struct obd_export **lri_exp; 1544 struct obd_export **lri_exp;
1524 register_lwp_cb lri_cb_func; 1545 register_lwp_cb lri_cb_func;
1525 void *lri_cb_data; 1546 void *lri_cb_data;
1526 struct list_head lri_list; 1547 struct list_head lri_list;
1527 char lri_name[MTI_NAME_MAXLEN]; 1548 char lri_name[MTI_NAME_MAXLEN];
1528}; 1549};
1529 1550
1530/* I'm as embarrassed about this as you are. 1551/*
1552 * I'm as embarrassed about this as you are.
1531 * 1553 *
1532 * <shaver> // XXX do not look into _superhack with remaining eye 1554 * <shaver> // XXX do not look into _superhack with remaining eye
1533 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV 1555 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV
@@ -1562,7 +1584,8 @@ int class_procfs_init(void);
1562int class_procfs_clean(void); 1584int class_procfs_clean(void);
1563 1585
1564/* prng.c */ 1586/* prng.c */
1565#define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t)) 1587#define ll_generate_random_uuid(uuid_out) \
1588 get_random_bytes(uuid_out, sizeof(class_uuid_t))
1566 1589
1567/* statfs_pack.c */ 1590/* statfs_pack.c */
1568struct kstatfs; 1591struct kstatfs;
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
index fac9d19d50b6..11b11b5f3216 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
@@ -64,7 +64,6 @@
64__u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 old_kms) 64__u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 old_kms)
65{ 65{
66 struct ldlm_resource *res = lock->l_resource; 66 struct ldlm_resource *res = lock->l_resource;
67 struct list_head *tmp;
68 struct ldlm_lock *lck; 67 struct ldlm_lock *lck;
69 __u64 kms = 0; 68 __u64 kms = 0;
70 69
@@ -74,8 +73,7 @@ __u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 old_kms)
74 */ 73 */
75 ldlm_set_kms_ignore(lock); 74 ldlm_set_kms_ignore(lock);
76 75
77 list_for_each(tmp, &res->lr_granted) { 76 list_for_each_entry(lck, &res->lr_granted, l_res_link) {
78 lck = list_entry(tmp, struct ldlm_lock, l_res_link);
79 77
80 if (ldlm_is_kms_ignore(lck)) 78 if (ldlm_is_kms_ignore(lck))
81 continue; 79 continue;
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index 7cb61e2e7d3b..7cbc6a06afec 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -886,17 +886,15 @@ static void search_granted_lock(struct list_head *queue,
886 struct ldlm_lock *req, 886 struct ldlm_lock *req,
887 struct sl_insert_point *prev) 887 struct sl_insert_point *prev)
888{ 888{
889 struct list_head *tmp;
890 struct ldlm_lock *lock, *mode_end, *policy_end; 889 struct ldlm_lock *lock, *mode_end, *policy_end;
891 890
892 list_for_each(tmp, queue) { 891 list_for_each_entry(lock, queue, l_res_link) {
893 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
894 892
895 mode_end = list_prev_entry(lock, l_sl_mode); 893 mode_end = list_prev_entry(lock, l_sl_mode);
896 894
897 if (lock->l_req_mode != req->l_req_mode) { 895 if (lock->l_req_mode != req->l_req_mode) {
898 /* jump to last lock of mode group */ 896 /* jump to last lock of mode group */
899 tmp = &mode_end->l_res_link; 897 lock = mode_end;
900 continue; 898 continue;
901 } 899 }
902 900
@@ -933,9 +931,7 @@ static void search_granted_lock(struct list_head *queue,
933 break; 931 break;
934 932
935 /* go to next policy group within mode group */ 933 /* go to next policy group within mode group */
936 tmp = policy_end->l_res_link.next; 934 lock = list_next_entry(policy_end, l_res_link);
937 lock = list_entry(tmp, struct ldlm_lock,
938 l_res_link);
939 } /* loop over policy groups within the mode group */ 935 } /* loop over policy groups within the mode group */
940 936
941 /* insert point is last lock of the mode group, 937 /* insert point is last lock of the mode group,
@@ -1687,7 +1683,7 @@ ldlm_work_bl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
1687 if (list_empty(arg->list)) 1683 if (list_empty(arg->list))
1688 return -ENOENT; 1684 return -ENOENT;
1689 1685
1690 lock = list_entry(arg->list->next, struct ldlm_lock, l_bl_ast); 1686 lock = list_first_entry(arg->list, struct ldlm_lock, l_bl_ast);
1691 1687
1692 /* nobody should touch l_bl_ast */ 1688 /* nobody should touch l_bl_ast */
1693 lock_res_and_lock(lock); 1689 lock_res_and_lock(lock);
@@ -1723,7 +1719,7 @@ ldlm_work_cp_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
1723 if (list_empty(arg->list)) 1719 if (list_empty(arg->list))
1724 return -ENOENT; 1720 return -ENOENT;
1725 1721
1726 lock = list_entry(arg->list->next, struct ldlm_lock, l_cp_ast); 1722 lock = list_first_entry(arg->list, struct ldlm_lock, l_cp_ast);
1727 1723
1728 /* It's possible to receive a completion AST before we've set 1724 /* It's possible to receive a completion AST before we've set
1729 * the l_completion_ast pointer: either because the AST arrived 1725 * the l_completion_ast pointer: either because the AST arrived
@@ -1769,7 +1765,7 @@ ldlm_work_revoke_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
1769 if (list_empty(arg->list)) 1765 if (list_empty(arg->list))
1770 return -ENOENT; 1766 return -ENOENT;
1771 1767
1772 lock = list_entry(arg->list->next, struct ldlm_lock, l_rk_ast); 1768 lock = list_first_entry(arg->list, struct ldlm_lock, l_rk_ast);
1773 list_del_init(&lock->l_rk_ast); 1769 list_del_init(&lock->l_rk_ast);
1774 1770
1775 /* the desc just pretend to exclusive */ 1771 /* the desc just pretend to exclusive */
@@ -1796,7 +1792,7 @@ static int ldlm_work_gl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
1796 if (list_empty(arg->list)) 1792 if (list_empty(arg->list))
1797 return -ENOENT; 1793 return -ENOENT;
1798 1794
1799 gl_work = list_entry(arg->list->next, struct ldlm_glimpse_work, 1795 gl_work = list_first_entry(arg->list, struct ldlm_glimpse_work,
1800 gl_list); 1796 gl_list);
1801 list_del_init(&gl_work->gl_list); 1797 list_del_init(&gl_work->gl_list);
1802 1798
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
index 2d5a2c932ddc..5f6e7c933b81 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
@@ -696,13 +696,13 @@ static int ldlm_bl_get_work(struct ldlm_bl_pool *blp,
696 /* process a request from the blp_list at least every blp_num_threads */ 696 /* process a request from the blp_list at least every blp_num_threads */
697 if (!list_empty(&blp->blp_list) && 697 if (!list_empty(&blp->blp_list) &&
698 (list_empty(&blp->blp_prio_list) || num_bl == 0)) 698 (list_empty(&blp->blp_prio_list) || num_bl == 0))
699 blwi = list_entry(blp->blp_list.next, 699 blwi = list_first_entry(&blp->blp_list,
700 struct ldlm_bl_work_item, blwi_entry); 700 struct ldlm_bl_work_item, blwi_entry);
701 else 701 else
702 if (!list_empty(&blp->blp_prio_list)) 702 if (!list_empty(&blp->blp_prio_list))
703 blwi = list_entry(blp->blp_prio_list.next, 703 blwi = list_first_entry(&blp->blp_prio_list,
704 struct ldlm_bl_work_item, 704 struct ldlm_bl_work_item,
705 blwi_entry); 705 blwi_entry);
706 706
707 if (blwi) { 707 if (blwi) {
708 if (++num_bl >= num_th) 708 if (++num_bl >= num_th)
@@ -1093,8 +1093,10 @@ static int ldlm_cleanup(void)
1093 kset_unregister(ldlm_ns_kset); 1093 kset_unregister(ldlm_ns_kset);
1094 if (ldlm_svc_kset) 1094 if (ldlm_svc_kset)
1095 kset_unregister(ldlm_svc_kset); 1095 kset_unregister(ldlm_svc_kset);
1096 if (ldlm_kobj) 1096 if (ldlm_kobj) {
1097 sysfs_remove_group(ldlm_kobj, &ldlm_attr_group);
1097 kobject_put(ldlm_kobj); 1098 kobject_put(ldlm_kobj);
1099 }
1098 1100
1099 ldlm_debugfs_cleanup(); 1101 ldlm_debugfs_cleanup();
1100 1102
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
index da65d00a7811..8563bd32befa 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
@@ -1086,8 +1086,12 @@ int ldlm_pools_init(void)
1086 int rc; 1086 int rc;
1087 1087
1088 rc = ldlm_pools_thread_start(); 1088 rc = ldlm_pools_thread_start();
1089 if (rc == 0) 1089 if (rc)
1090 register_shrinker(&ldlm_pools_cli_shrinker); 1090 return rc;
1091
1092 rc = register_shrinker(&ldlm_pools_cli_shrinker);
1093 if (rc)
1094 ldlm_pools_thread_stop();
1091 1095
1092 return rc; 1096 return rc;
1093} 1097}
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
index 02ea14c9b089..6aa37463db46 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
@@ -1656,7 +1656,7 @@ int ldlm_cli_cancel_list(struct list_head *cancels, int count,
1656 */ 1656 */
1657 while (count > 0) { 1657 while (count > 0) {
1658 LASSERT(!list_empty(cancels)); 1658 LASSERT(!list_empty(cancels));
1659 lock = list_entry(cancels->next, struct ldlm_lock, l_bl_ast); 1659 lock = list_first_entry(cancels, struct ldlm_lock, l_bl_ast);
1660 LASSERT(lock->l_conn_export); 1660 LASSERT(lock->l_conn_export);
1661 1661
1662 if (exp_connect_cancelset(lock->l_conn_export)) { 1662 if (exp_connect_cancelset(lock->l_conn_export)) {
@@ -1780,7 +1780,7 @@ EXPORT_SYMBOL(ldlm_cli_cancel_unused);
1780static int ldlm_resource_foreach(struct ldlm_resource *res, 1780static int ldlm_resource_foreach(struct ldlm_resource *res,
1781 ldlm_iterator_t iter, void *closure) 1781 ldlm_iterator_t iter, void *closure)
1782{ 1782{
1783 struct list_head *tmp, *next; 1783 struct ldlm_lock *tmp;
1784 struct ldlm_lock *lock; 1784 struct ldlm_lock *lock;
1785 int rc = LDLM_ITER_CONTINUE; 1785 int rc = LDLM_ITER_CONTINUE;
1786 1786
@@ -1788,18 +1788,14 @@ static int ldlm_resource_foreach(struct ldlm_resource *res,
1788 return LDLM_ITER_CONTINUE; 1788 return LDLM_ITER_CONTINUE;
1789 1789
1790 lock_res(res); 1790 lock_res(res);
1791 list_for_each_safe(tmp, next, &res->lr_granted) { 1791 list_for_each_entry_safe(lock, tmp, &res->lr_granted, l_res_link) {
1792 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
1793
1794 if (iter(lock, closure) == LDLM_ITER_STOP) { 1792 if (iter(lock, closure) == LDLM_ITER_STOP) {
1795 rc = LDLM_ITER_STOP; 1793 rc = LDLM_ITER_STOP;
1796 goto out; 1794 goto out;
1797 } 1795 }
1798 } 1796 }
1799 1797
1800 list_for_each_safe(tmp, next, &res->lr_waiting) { 1798 list_for_each_entry_safe(lock, tmp, &res->lr_waiting, l_res_link) {
1801 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
1802
1803 if (iter(lock, closure) == LDLM_ITER_STOP) { 1799 if (iter(lock, closure) == LDLM_ITER_STOP) {
1804 rc = LDLM_ITER_STOP; 1800 rc = LDLM_ITER_STOP;
1805 goto out; 1801 goto out;
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
index 2689ffdf10e3..9958533cc227 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
@@ -752,24 +752,22 @@ extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
752static void cleanup_resource(struct ldlm_resource *res, struct list_head *q, 752static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
753 __u64 flags) 753 __u64 flags)
754{ 754{
755 struct list_head *tmp;
756 int rc = 0; 755 int rc = 0;
757 bool local_only = !!(flags & LDLM_FL_LOCAL_ONLY); 756 bool local_only = !!(flags & LDLM_FL_LOCAL_ONLY);
758 757
759 do { 758 do {
760 struct ldlm_lock *lock = NULL; 759 struct ldlm_lock *lock = NULL, *tmp;
761 struct lustre_handle lockh; 760 struct lustre_handle lockh;
762 761
763 /* First, we look for non-cleaned-yet lock 762 /* First, we look for non-cleaned-yet lock
764 * all cleaned locks are marked by CLEANED flag. 763 * all cleaned locks are marked by CLEANED flag.
765 */ 764 */
766 lock_res(res); 765 lock_res(res);
767 list_for_each(tmp, q) { 766 list_for_each_entry(tmp, q, l_res_link) {
768 lock = list_entry(tmp, struct ldlm_lock, l_res_link); 767 if (ldlm_is_cleaned(tmp))
769 if (ldlm_is_cleaned(lock)) {
770 lock = NULL;
771 continue; 768 continue;
772 } 769
770 lock = tmp;
773 LDLM_LOCK_GET(lock); 771 LDLM_LOCK_GET(lock);
774 ldlm_set_cleaned(lock); 772 ldlm_set_cleaned(lock);
775 break; 773 break;
@@ -1283,19 +1281,15 @@ void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc)
1283 */ 1281 */
1284void ldlm_dump_all_namespaces(enum ldlm_side client, int level) 1282void ldlm_dump_all_namespaces(enum ldlm_side client, int level)
1285{ 1283{
1286 struct list_head *tmp; 1284 struct ldlm_namespace *ns;
1287 1285
1288 if (!((libcfs_debug | D_ERROR) & level)) 1286 if (!((libcfs_debug | D_ERROR) & level))
1289 return; 1287 return;
1290 1288
1291 mutex_lock(ldlm_namespace_lock(client)); 1289 mutex_lock(ldlm_namespace_lock(client));
1292 1290
1293 list_for_each(tmp, ldlm_namespace_list(client)) { 1291 list_for_each_entry(ns, ldlm_namespace_list(client), ns_list_chain)
1294 struct ldlm_namespace *ns;
1295
1296 ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain);
1297 ldlm_namespace_dump(level, ns); 1292 ldlm_namespace_dump(level, ns);
1298 }
1299 1293
1300 mutex_unlock(ldlm_namespace_lock(client)); 1294 mutex_unlock(ldlm_namespace_lock(client));
1301} 1295}
diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
index 6f59045be0f9..99b0b77c75f5 100644
--- a/drivers/staging/lustre/lustre/llite/dir.c
+++ b/drivers/staging/lustre/lustre/llite/dir.c
@@ -1337,9 +1337,9 @@ finish_req:
1337 cmd == LL_IOC_MDC_GETINFO)) { 1337 cmd == LL_IOC_MDC_GETINFO)) {
1338 rc = 0; 1338 rc = 0;
1339 goto skip_lmm; 1339 goto skip_lmm;
1340 } else {
1341 goto out_req;
1342 } 1340 }
1341
1342 goto out_req;
1343 } 1343 }
1344 1344
1345 if (cmd == IOC_MDC_GETFILESTRIPE || 1345 if (cmd == IOC_MDC_GETFILESTRIPE ||
diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h
index 0d62fcf016dc..f68c2e88f12b 100644
--- a/drivers/staging/lustre/lustre/llite/llite_internal.h
+++ b/drivers/staging/lustre/lustre/llite/llite_internal.h
@@ -792,7 +792,7 @@ int ll_revalidate_it_finish(struct ptlrpc_request *request,
792extern struct super_operations lustre_super_operations; 792extern struct super_operations lustre_super_operations;
793 793
794void ll_lli_init(struct ll_inode_info *lli); 794void ll_lli_init(struct ll_inode_info *lli);
795int ll_fill_super(struct super_block *sb, struct vfsmount *mnt); 795int ll_fill_super(struct super_block *sb);
796void ll_put_super(struct super_block *sb); 796void ll_put_super(struct super_block *sb);
797void ll_kill_super(struct super_block *sb); 797void ll_kill_super(struct super_block *sb);
798struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock); 798struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock);
diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c
index 8666f1e81ade..6735a6f006d2 100644
--- a/drivers/staging/lustre/lustre/llite/llite_lib.c
+++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
@@ -146,8 +146,7 @@ static void ll_free_sbi(struct super_block *sb)
146 kfree(sbi); 146 kfree(sbi);
147} 147}
148 148
149static int client_common_fill_super(struct super_block *sb, char *md, char *dt, 149static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
150 struct vfsmount *mnt)
151{ 150{
152 struct inode *root = NULL; 151 struct inode *root = NULL;
153 struct ll_sb_info *sbi = ll_s2sbi(sb); 152 struct ll_sb_info *sbi = ll_s2sbi(sb);
@@ -236,7 +235,9 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
236 "An MDT (md %s) is performing recovery, of which this client is not a part. Please wait for recovery to complete, abort, or time out.\n", 235 "An MDT (md %s) is performing recovery, of which this client is not a part. Please wait for recovery to complete, abort, or time out.\n",
237 md); 236 md);
238 goto out; 237 goto out;
239 } else if (err) { 238 }
239
240 if (err) {
240 CERROR("cannot connect to %s: rc = %d\n", md, err); 241 CERROR("cannot connect to %s: rc = %d\n", md, err);
241 goto out; 242 goto out;
242 } 243 }
@@ -865,7 +866,7 @@ void ll_lli_init(struct ll_inode_info *lli)
865 mutex_init(&lli->lli_layout_mutex); 866 mutex_init(&lli->lli_layout_mutex);
866} 867}
867 868
868int ll_fill_super(struct super_block *sb, struct vfsmount *mnt) 869int ll_fill_super(struct super_block *sb)
869{ 870{
870 struct lustre_profile *lprof = NULL; 871 struct lustre_profile *lprof = NULL;
871 struct lustre_sb_info *lsi = s2lsi(sb); 872 struct lustre_sb_info *lsi = s2lsi(sb);
@@ -942,7 +943,7 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
942 } 943 }
943 944
944 /* connections, registrations, sb setup */ 945 /* connections, registrations, sb setup */
945 err = client_common_fill_super(sb, md, dt, mnt); 946 err = client_common_fill_super(sb, md, dt);
946 if (!err) 947 if (!err)
947 sbi->ll_client_common_fill_super_succeeded = 1; 948 sbi->ll_client_common_fill_super_succeeded = 1;
948 949
diff --git a/drivers/staging/lustre/lustre/llite/super25.c b/drivers/staging/lustre/lustre/llite/super25.c
index 0bda111a096e..9b0bb3541a84 100644
--- a/drivers/staging/lustre/lustre/llite/super25.c
+++ b/drivers/staging/lustre/lustre/llite/super25.c
@@ -86,8 +86,7 @@ MODULE_ALIAS_FS("lustre");
86static int __init lustre_init(void) 86static int __init lustre_init(void)
87{ 87{
88 struct lnet_process_id lnet_id; 88 struct lnet_process_id lnet_id;
89 struct timespec64 ts; 89 int i, rc;
90 int i, rc, seed[2];
91 90
92 BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) != 91 BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) !=
93 LUSTRE_VOLATILE_HDR_LEN + 1); 92 LUSTRE_VOLATILE_HDR_LEN + 1);
@@ -126,22 +125,20 @@ static int __init lustre_init(void)
126 goto out_debugfs; 125 goto out_debugfs;
127 } 126 }
128 127
129 cfs_get_random_bytes(seed, sizeof(seed));
130
131 /* Nodes with small feet have little entropy. The NID for this 128 /* Nodes with small feet have little entropy. The NID for this
132 * node gives the most entropy in the low bits 129 * node gives the most entropy in the low bits
133 */ 130 */
134 for (i = 0;; i++) { 131 for (i = 0;; i++) {
132 u32 seed;
133
135 if (LNetGetId(i, &lnet_id) == -ENOENT) 134 if (LNetGetId(i, &lnet_id) == -ENOENT)
136 break; 135 break;
137 136 if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) {
138 if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) 137 seed = LNET_NIDADDR(lnet_id.nid);
139 seed[0] ^= LNET_NIDADDR(lnet_id.nid); 138 add_device_randomness(&seed, sizeof(seed));
139 }
140 } 140 }
141 141
142 ktime_get_ts64(&ts);
143 cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]);
144
145 rc = vvp_global_init(); 142 rc = vvp_global_init();
146 if (rc != 0) 143 if (rc != 0)
147 goto out_sysfs; 144 goto out_sysfs;
@@ -159,8 +156,7 @@ static int __init lustre_init(void)
159 if (rc != 0) 156 if (rc != 0)
160 goto out_inode_fini_env; 157 goto out_inode_fini_env;
161 158
162 lustre_register_client_fill_super(ll_fill_super); 159 lustre_register_super_ops(THIS_MODULE, ll_fill_super, ll_kill_super);
163 lustre_register_kill_super_cb(ll_kill_super);
164 lustre_register_client_process_config(ll_process_config); 160 lustre_register_client_process_config(ll_process_config);
165 161
166 return 0; 162 return 0;
@@ -181,8 +177,7 @@ out_cache:
181 177
182static void __exit lustre_exit(void) 178static void __exit lustre_exit(void)
183{ 179{
184 lustre_register_client_fill_super(NULL); 180 lustre_register_super_ops(NULL, NULL, NULL);
185 lustre_register_kill_super_cb(NULL);
186 lustre_register_client_process_config(NULL); 181 lustre_register_client_process_config(NULL);
187 182
188 debugfs_remove(llite_root); 183 debugfs_remove(llite_root);
diff --git a/drivers/staging/lustre/lustre/llite/vvp_dev.c b/drivers/staging/lustre/lustre/llite/vvp_dev.c
index 8ccc8b799c02..987c03b058e6 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_dev.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_dev.c
@@ -384,7 +384,7 @@ int cl_sb_fini(struct super_block *sb)
384struct vvp_pgcache_id { 384struct vvp_pgcache_id {
385 unsigned int vpi_bucket; 385 unsigned int vpi_bucket;
386 unsigned int vpi_depth; 386 unsigned int vpi_depth;
387 uint32_t vpi_index; 387 u32 vpi_index;
388 388
389 unsigned int vpi_curdep; 389 unsigned int vpi_curdep;
390 struct lu_object_header *vpi_obj; 390 struct lu_object_header *vpi_obj;
diff --git a/drivers/staging/lustre/lustre/llite/vvp_io.c b/drivers/staging/lustre/lustre/llite/vvp_io.c
index bfae98e82d6f..e7a4778e02e4 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_io.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_io.c
@@ -699,7 +699,7 @@ static int vvp_io_read_start(const struct lu_env *env,
699 result = vvp_prep_size(env, obj, io, pos, tot, &exceed); 699 result = vvp_prep_size(env, obj, io, pos, tot, &exceed);
700 if (result != 0) 700 if (result != 0)
701 return result; 701 return result;
702 else if (exceed != 0) 702 if (exceed != 0)
703 goto out; 703 goto out;
704 704
705 LU_OBJECT_HEADER(D_INODE, env, &obj->co_lu, 705 LU_OBJECT_HEADER(D_INODE, env, &obj->co_lu,
diff --git a/drivers/staging/lustre/lustre/lov/lov_internal.h b/drivers/staging/lustre/lustre/lov/lov_internal.h
index ae28ddf80d9b..a56d71c2dda2 100644
--- a/drivers/staging/lustre/lustre/lov/lov_internal.h
+++ b/drivers/staging/lustre/lustre/lov/lov_internal.h
@@ -115,19 +115,19 @@ static inline const struct lsm_operations *lsm_op_find(int magic)
115 */ 115 */
116#if BITS_PER_LONG == 64 116#if BITS_PER_LONG == 64
117# define lov_do_div64(n, base) ({ \ 117# define lov_do_div64(n, base) ({ \
118 uint64_t __base = (base); \ 118 u64 __base = (base); \
119 uint64_t __rem; \ 119 u64 __rem; \
120 __rem = ((uint64_t)(n)) % __base; \ 120 __rem = ((u64)(n)) % __base; \
121 (n) = ((uint64_t)(n)) / __base; \ 121 (n) = ((u64)(n)) / __base; \
122 __rem; \ 122 __rem; \
123}) 123})
124#elif BITS_PER_LONG == 32 124#elif BITS_PER_LONG == 32
125# define lov_do_div64(n, base) ({ \ 125# define lov_do_div64(n, base) ({ \
126 uint64_t __rem; \ 126 u64 __rem; \
127 if ((sizeof(base) > 4) && (((base) & 0xffffffff00000000ULL) != 0)) { \ 127 if ((sizeof(base) > 4) && (((base) & 0xffffffff00000000ULL) != 0)) { \
128 int __remainder; \ 128 int __remainder; \
129 LASSERTF(!((base) & (LOV_MIN_STRIPE_SIZE - 1)), "64 bit lov " \ 129 LASSERTF(!((base) & (LOV_MIN_STRIPE_SIZE - 1)), "64 bit lov " \
130 "division %llu / %llu\n", (n), (uint64_t)(base)); \ 130 "division %llu / %llu\n", (n), (u64)(base)); \
131 __remainder = (n) & (LOV_MIN_STRIPE_SIZE - 1); \ 131 __remainder = (n) & (LOV_MIN_STRIPE_SIZE - 1); \
132 (n) >>= LOV_MIN_STRIPE_BITS; \ 132 (n) >>= LOV_MIN_STRIPE_BITS; \
133 __rem = do_div(n, (base) >> LOV_MIN_STRIPE_BITS); \ 133 __rem = do_div(n, (base) >> LOV_MIN_STRIPE_BITS); \
diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
index 7ce01026a409..ec70c12e5b40 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -828,11 +828,9 @@ out:
828static int lov_cleanup(struct obd_device *obd) 828static int lov_cleanup(struct obd_device *obd)
829{ 829{
830 struct lov_obd *lov = &obd->u.lov; 830 struct lov_obd *lov = &obd->u.lov;
831 struct list_head *pos, *tmp; 831 struct pool_desc *pool, *tmp;
832 struct pool_desc *pool;
833 832
834 list_for_each_safe(pos, tmp, &lov->lov_pool_list) { 833 list_for_each_entry_safe(pool, tmp, &lov->lov_pool_list, pool_list) {
835 pool = list_entry(pos, struct pool_desc, pool_list);
836 /* free pool structs */ 834 /* free pool structs */
837 CDEBUG(D_INFO, "delete pool %p\n", pool); 835 CDEBUG(D_INFO, "delete pool %p\n", pool);
838 /* In the function below, .hs_keycmp resolves to 836 /* In the function below, .hs_keycmp resolves to
diff --git a/drivers/staging/lustre/lustre/lov/lov_object.c b/drivers/staging/lustre/lustre/lov/lov_object.c
index 105b707eed14..897cf2cd4a24 100644
--- a/drivers/staging/lustre/lustre/lov/lov_object.c
+++ b/drivers/staging/lustre/lustre/lov/lov_object.c
@@ -1335,7 +1335,7 @@ static int lov_object_fiemap(const struct lu_env *env, struct cl_object *obj,
1335 int rc = 0; 1335 int rc = 0;
1336 int cur_stripe; 1336 int cur_stripe;
1337 int stripe_count; 1337 int stripe_count;
1338 struct fiemap_state fs = { 0 }; 1338 struct fiemap_state fs = { NULL };
1339 1339
1340 lsm = lov_lsm_addref(cl2lov(obj)); 1340 lsm = lov_lsm_addref(cl2lov(obj));
1341 if (!lsm) 1341 if (!lsm)
diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c
index 3bdf48e4edb4..cfa1d7f92b0f 100644
--- a/drivers/staging/lustre/lustre/lov/lov_request.c
+++ b/drivers/staging/lustre/lustre/lov/lov_request.c
@@ -49,15 +49,13 @@ static void lov_init_set(struct lov_request_set *set)
49 49
50static void lov_finish_set(struct lov_request_set *set) 50static void lov_finish_set(struct lov_request_set *set)
51{ 51{
52 struct list_head *pos, *n; 52 struct lov_request *req;
53 53
54 LASSERT(set); 54 LASSERT(set);
55 list_for_each_safe(pos, n, &set->set_list) { 55 while ((req = list_first_entry_or_null(&set->set_list,
56 struct lov_request *req = list_entry(pos, 56 struct lov_request,
57 struct lov_request, 57 rq_link)) != NULL) {
58 rq_link);
59 list_del_init(&req->rq_link); 58 list_del_init(&req->rq_link);
60
61 kfree(req->rq_oi.oi_osfs); 59 kfree(req->rq_oi.oi_osfs);
62 kfree(req); 60 kfree(req);
63 } 61 }
diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c
index 77fa8fea0249..79ff85feab64 100644
--- a/drivers/staging/lustre/lustre/mgc/mgc_request.c
+++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c
@@ -523,7 +523,7 @@ static void do_requeue(struct config_llog_data *cld)
523 * in order to not flood the MGS. 523 * in order to not flood the MGS.
524 */ 524 */
525#define MGC_TIMEOUT_MIN_SECONDS 5 525#define MGC_TIMEOUT_MIN_SECONDS 5
526#define MGC_TIMEOUT_RAND_CENTISEC 0x1ff /* ~500 */ 526#define MGC_TIMEOUT_RAND_CENTISEC 500
527 527
528static int mgc_requeue_thread(void *data) 528static int mgc_requeue_thread(void *data)
529{ 529{
@@ -537,7 +537,7 @@ static int mgc_requeue_thread(void *data)
537 while (!(rq_state & RQ_STOP)) { 537 while (!(rq_state & RQ_STOP)) {
538 struct l_wait_info lwi; 538 struct l_wait_info lwi;
539 struct config_llog_data *cld, *cld_prev; 539 struct config_llog_data *cld, *cld_prev;
540 int rand = cfs_rand() & MGC_TIMEOUT_RAND_CENTISEC; 540 int rand = prandom_u32_max(MGC_TIMEOUT_RAND_CENTISEC);
541 int to; 541 int to;
542 542
543 /* Any new or requeued lostlocks will change the state */ 543 /* Any new or requeued lostlocks will change the state */
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_lock.c b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
index d415f8396038..3b683b774fef 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_lock.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
@@ -79,13 +79,12 @@ EXPORT_SYMBOL(cl_lock_slice_add);
79 79
80void cl_lock_fini(const struct lu_env *env, struct cl_lock *lock) 80void cl_lock_fini(const struct lu_env *env, struct cl_lock *lock)
81{ 81{
82 struct cl_lock_slice *slice;
82 cl_lock_trace(D_DLMTRACE, env, "destroy lock", lock); 83 cl_lock_trace(D_DLMTRACE, env, "destroy lock", lock);
83 84
84 while (!list_empty(&lock->cll_layers)) { 85 while ((slice = list_first_entry_or_null(&lock->cll_layers,
85 struct cl_lock_slice *slice; 86 struct cl_lock_slice,
86 87 cls_linkage)) != NULL) {
87 slice = list_entry(lock->cll_layers.next,
88 struct cl_lock_slice, cls_linkage);
89 list_del_init(lock->cll_layers.next); 88 list_del_init(lock->cll_layers.next);
90 slice->cls_ops->clo_fini(env, slice); 89 slice->cls_ops->clo_fini(env, slice);
91 } 90 }
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c
index fdd27ce46fda..7b18d775b001 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c
@@ -510,13 +510,13 @@ locks: ...... ...... ...... ...... ...... [...... ...... ...... ...... ......]
510 */ 510 */
511 lu_site_stats_print(&site->cs_lu, m); 511 lu_site_stats_print(&site->cs_lu, m);
512 cache_stats_print(&site->cs_pages, m, 1); 512 cache_stats_print(&site->cs_pages, m, 1);
513 seq_printf(m, " ["); 513 seq_puts(m, " [");
514 for (i = 0; i < ARRAY_SIZE(site->cs_pages_state); ++i) 514 for (i = 0; i < ARRAY_SIZE(site->cs_pages_state); ++i)
515 seq_printf(m, "%s: %u ", pstate[i], 515 seq_printf(m, "%s: %u ", pstate[i],
516 atomic_read(&site->cs_pages_state[i])); 516 atomic_read(&site->cs_pages_state[i]));
517 seq_printf(m, "]\n"); 517 seq_puts(m, "]\n");
518 cache_stats_print(&cl_env_stats, m, 0); 518 cache_stats_print(&cl_env_stats, m, 0);
519 seq_printf(m, "\n"); 519 seq_puts(m, "\n");
520 return 0; 520 return 0;
521} 521}
522EXPORT_SYMBOL(cl_site_stats_print); 522EXPORT_SYMBOL(cl_site_stats_print);
@@ -1017,7 +1017,7 @@ int cl_global_init(void)
1017{ 1017{
1018 int result; 1018 int result;
1019 1019
1020 cl_envs = kzalloc(sizeof(*cl_envs) * num_possible_cpus(), GFP_KERNEL); 1020 cl_envs = kcalloc(num_possible_cpus(), sizeof(*cl_envs), GFP_KERNEL);
1021 if (!cl_envs) { 1021 if (!cl_envs) {
1022 result = -ENOMEM; 1022 result = -ENOMEM;
1023 goto out; 1023 goto out;
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_page.c b/drivers/staging/lustre/lustre/obdclass/cl_page.c
index 7f65439f9b95..d3b25667bc3a 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_page.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_page.c
@@ -202,7 +202,7 @@ struct cl_page *cl_page_find(const struct lu_env *env,
202 * vmpage lock is used to protect the child/parent 202 * vmpage lock is used to protect the child/parent
203 * relationship 203 * relationship
204 */ 204 */
205 KLASSERT(PageLocked(vmpage)); 205 LASSERT(PageLocked(vmpage));
206 /* 206 /*
207 * cl_vmpage_page() can be called here without any locks as 207 * cl_vmpage_page() can be called here without any locks as
208 * 208 *
@@ -340,7 +340,7 @@ struct cl_page *cl_vmpage_page(struct page *vmpage, struct cl_object *obj)
340{ 340{
341 struct cl_page *page; 341 struct cl_page *page;
342 342
343 KLASSERT(PageLocked(vmpage)); 343 LASSERT(PageLocked(vmpage));
344 344
345 /* 345 /*
346 * NOTE: absence of races and liveness of data are guaranteed by page 346 * NOTE: absence of races and liveness of data are guaranteed by page
diff --git a/drivers/staging/lustre/lustre/obdclass/class_obd.c b/drivers/staging/lustre/lustre/obdclass/class_obd.c
index 2985bca4dc4c..3e24b76f6301 100644
--- a/drivers/staging/lustre/lustre/obdclass/class_obd.c
+++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c
@@ -377,7 +377,8 @@ static int obd_init_checks(void)
377 char buf[64]; 377 char buf[64];
378 int len, ret = 0; 378 int len, ret = 0;
379 379
380 CDEBUG(D_INFO, "LPU64=%s, LPD64=%s, LPX64=%s\n", "%llu", "%lld", "%#llx"); 380 CDEBUG(D_INFO, "LPU64=%s, LPD64=%s, LPX64=%s\n", "%llu", "%lld",
381 "%#llx");
381 382
382 CDEBUG(D_INFO, "OBD_OBJECT_EOF = %#llx\n", (__u64)OBD_OBJECT_EOF); 383 CDEBUG(D_INFO, "OBD_OBJECT_EOF = %#llx\n", (__u64)OBD_OBJECT_EOF);
383 384
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
index fc59f29a4290..57951237def2 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
@@ -501,6 +501,7 @@ int class_procfs_init(void)
501 rc = debugfs_lustre_root ? PTR_ERR(debugfs_lustre_root) 501 rc = debugfs_lustre_root ? PTR_ERR(debugfs_lustre_root)
502 : -ENOMEM; 502 : -ENOMEM;
503 debugfs_lustre_root = NULL; 503 debugfs_lustre_root = NULL;
504 sysfs_remove_group(lustre_kobj, &lustre_attr_group);
504 kobject_put(lustre_kobj); 505 kobject_put(lustre_kobj);
505 goto out; 506 goto out;
506 } 507 }
@@ -509,6 +510,7 @@ int class_procfs_init(void)
509 &obd_device_list_fops); 510 &obd_device_list_fops);
510 if (IS_ERR_OR_NULL(file)) { 511 if (IS_ERR_OR_NULL(file)) {
511 rc = file ? PTR_ERR(file) : -ENOMEM; 512 rc = file ? PTR_ERR(file) : -ENOMEM;
513 sysfs_remove_group(lustre_kobj, &lustre_attr_group);
512 kobject_put(lustre_kobj); 514 kobject_put(lustre_kobj);
513 goto out; 515 goto out;
514 } 516 }
@@ -522,6 +524,7 @@ int class_procfs_clean(void)
522 524
523 debugfs_lustre_root = NULL; 525 debugfs_lustre_root = NULL;
524 526
527 sysfs_remove_group(lustre_kobj, &lustre_attr_group);
525 kobject_put(lustre_kobj); 528 kobject_put(lustre_kobj);
526 529
527 return 0; 530 return 0;
diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 05d71f568837..e1f4ef2bddd4 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -1093,7 +1093,7 @@ int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1093 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0); 1093 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1094 1094
1095 percpusize = lprocfs_stats_counter_size(stats); 1095 percpusize = lprocfs_stats_counter_size(stats);
1096 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize); 1096 stats->ls_percpu[cpuid] = kzalloc(percpusize, GFP_ATOMIC);
1097 if (stats->ls_percpu[cpuid]) { 1097 if (stats->ls_percpu[cpuid]) {
1098 rc = 0; 1098 rc = 0;
1099 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) { 1099 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
@@ -1137,7 +1137,8 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1137 num_entry = num_possible_cpus(); 1137 num_entry = num_possible_cpus();
1138 1138
1139 /* alloc percpu pointers for all possible cpu slots */ 1139 /* alloc percpu pointers for all possible cpu slots */
1140 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry])); 1140 stats = kvzalloc(offsetof(typeof(*stats), ls_percpu[num_entry]),
1141 GFP_KERNEL);
1141 if (!stats) 1142 if (!stats)
1142 return NULL; 1143 return NULL;
1143 1144
@@ -1146,15 +1147,16 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1146 spin_lock_init(&stats->ls_lock); 1147 spin_lock_init(&stats->ls_lock);
1147 1148
1148 /* alloc num of counter headers */ 1149 /* alloc num of counter headers */
1149 LIBCFS_ALLOC(stats->ls_cnt_header, 1150 stats->ls_cnt_header = kvmalloc_array(stats->ls_num,
1150 stats->ls_num * sizeof(struct lprocfs_counter_header)); 1151 sizeof(struct lprocfs_counter_header),
1152 GFP_KERNEL | __GFP_ZERO);
1151 if (!stats->ls_cnt_header) 1153 if (!stats->ls_cnt_header)
1152 goto fail; 1154 goto fail;
1153 1155
1154 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) { 1156 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1155 /* contains only one set counters */ 1157 /* contains only one set counters */
1156 percpusize = lprocfs_stats_counter_size(stats); 1158 percpusize = lprocfs_stats_counter_size(stats);
1157 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize); 1159 stats->ls_percpu[0] = kzalloc(percpusize, GFP_ATOMIC);
1158 if (!stats->ls_percpu[0]) 1160 if (!stats->ls_percpu[0])
1159 goto fail; 1161 goto fail;
1160 stats->ls_biggest_alloc_num = 1; 1162 stats->ls_biggest_alloc_num = 1;
@@ -1191,12 +1193,9 @@ void lprocfs_free_stats(struct lprocfs_stats **statsh)
1191 1193
1192 percpusize = lprocfs_stats_counter_size(stats); 1194 percpusize = lprocfs_stats_counter_size(stats);
1193 for (i = 0; i < num_entry; i++) 1195 for (i = 0; i < num_entry; i++)
1194 if (stats->ls_percpu[i]) 1196 kfree(stats->ls_percpu[i]);
1195 LIBCFS_FREE(stats->ls_percpu[i], percpusize); 1197 kvfree(stats->ls_cnt_header);
1196 if (stats->ls_cnt_header) 1198 kvfree(stats);
1197 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1198 sizeof(struct lprocfs_counter_header));
1199 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1200} 1199}
1201EXPORT_SYMBOL(lprocfs_free_stats); 1200EXPORT_SYMBOL(lprocfs_free_stats);
1202 1201
diff --git a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c
index b938a3f9d50a..2719abbff85f 100644
--- a/drivers/staging/lustre/lustre/obdclass/lu_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c
@@ -1932,8 +1932,10 @@ int lu_global_init(void)
1932 1932
1933 LU_CONTEXT_KEY_INIT(&lu_global_key); 1933 LU_CONTEXT_KEY_INIT(&lu_global_key);
1934 result = lu_context_key_register(&lu_global_key); 1934 result = lu_context_key_register(&lu_global_key);
1935 if (result != 0) 1935 if (result != 0) {
1936 lu_ref_global_fini();
1936 return result; 1937 return result;
1938 }
1937 1939
1938 /* 1940 /*
1939 * At this level, we don't know what tags are needed, so allocate them 1941 * At this level, we don't know what tags are needed, so allocate them
@@ -1943,17 +1945,31 @@ int lu_global_init(void)
1943 down_write(&lu_sites_guard); 1945 down_write(&lu_sites_guard);
1944 result = lu_env_init(&lu_shrink_env, LCT_SHRINKER); 1946 result = lu_env_init(&lu_shrink_env, LCT_SHRINKER);
1945 up_write(&lu_sites_guard); 1947 up_write(&lu_sites_guard);
1946 if (result != 0) 1948 if (result != 0) {
1949 lu_context_key_degister(&lu_global_key);
1950 lu_ref_global_fini();
1947 return result; 1951 return result;
1952 }
1948 1953
1949 /* 1954 /*
1950 * seeks estimation: 3 seeks to read a record from oi, one to read 1955 * seeks estimation: 3 seeks to read a record from oi, one to read
1951 * inode, one for ea. Unfortunately setting this high value results in 1956 * inode, one for ea. Unfortunately setting this high value results in
1952 * lu_object/inode cache consuming all the memory. 1957 * lu_object/inode cache consuming all the memory.
1953 */ 1958 */
1954 register_shrinker(&lu_site_shrinker); 1959 result = register_shrinker(&lu_site_shrinker);
1960 if (result != 0) {
1961 /* Order explained in lu_global_fini(). */
1962 lu_context_key_degister(&lu_global_key);
1955 1963
1956 return result; 1964 down_write(&lu_sites_guard);
1965 lu_env_fini(&lu_shrink_env);
1966 up_write(&lu_sites_guard);
1967
1968 lu_ref_global_fini();
1969 return result;
1970 }
1971
1972 return 0;
1957} 1973}
1958 1974
1959/** 1975/**
diff --git a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
index 71329adc0318..2d6da2431a09 100644
--- a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
+++ b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
@@ -181,8 +181,6 @@ EXPORT_SYMBOL(class_handle_free_cb);
181int class_handle_init(void) 181int class_handle_init(void)
182{ 182{
183 struct handle_bucket *bucket; 183 struct handle_bucket *bucket;
184 struct timespec64 ts;
185 int seed[2];
186 184
187 LASSERT(!handle_hash); 185 LASSERT(!handle_hash);
188 186
@@ -198,12 +196,7 @@ int class_handle_init(void)
198 spin_lock_init(&bucket->lock); 196 spin_lock_init(&bucket->lock);
199 } 197 }
200 198
201 /** bug 21430: add randomness to the initial base */ 199 get_random_bytes(&handle_base, sizeof(handle_base));
202 cfs_get_random_bytes(seed, sizeof(seed));
203 ktime_get_ts64(&ts);
204 cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]);
205
206 cfs_get_random_bytes(&handle_base, sizeof(handle_base));
207 LASSERT(handle_base != 0ULL); 200 LASSERT(handle_base != 0ULL);
208 201
209 return 0; 202 return 0;
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c
index c0e192ae22a9..997c0f9aafb5 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_config.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c
@@ -236,7 +236,7 @@ static int class_attach(struct lustre_cfg *lcfg)
236 uuid = lustre_cfg_string(lcfg, 2); 236 uuid = lustre_cfg_string(lcfg, 2);
237 237
238 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n", 238 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
239 MKSTR(typename), MKSTR(name), MKSTR(uuid)); 239 typename, name, uuid);
240 240
241 obd = class_newdev(typename, name); 241 obd = class_newdev(typename, name);
242 if (IS_ERR(obd)) { 242 if (IS_ERR(obd)) {
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
index 2a79a223b98a..acc1ea773c9c 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
@@ -49,9 +49,9 @@
49#include <lustre_disk.h> 49#include <lustre_disk.h>
50#include <uapi/linux/lustre/lustre_param.h> 50#include <uapi/linux/lustre/lustre_param.h>
51 51
52static int (*client_fill_super)(struct super_block *sb, 52static DEFINE_SPINLOCK(client_lock);
53 struct vfsmount *mnt); 53static struct module *client_mod;
54 54static int (*client_fill_super)(struct super_block *sb);
55static void (*kill_super_cb)(struct super_block *sb); 55static void (*kill_super_cb)(struct super_block *sb);
56 56
57/**************** config llog ********************/ 57/**************** config llog ********************/
@@ -1107,20 +1107,14 @@ invalid:
1107 return -EINVAL; 1107 return -EINVAL;
1108} 1108}
1109 1109
1110struct lustre_mount_data2 {
1111 void *lmd2_data;
1112 struct vfsmount *lmd2_mnt;
1113};
1114
1115/** This is the entry point for the mount call into Lustre. 1110/** This is the entry point for the mount call into Lustre.
1116 * This is called when a server or client is mounted, 1111 * This is called when a server or client is mounted,
1117 * and this is where we start setting things up. 1112 * and this is where we start setting things up.
1118 * @param data Mount options (e.g. -o flock,abort_recov) 1113 * @param data Mount options (e.g. -o flock,abort_recov)
1119 */ 1114 */
1120static int lustre_fill_super(struct super_block *sb, void *data, int silent) 1115static int lustre_fill_super(struct super_block *sb, void *lmd2_data, int silent)
1121{ 1116{
1122 struct lustre_mount_data *lmd; 1117 struct lustre_mount_data *lmd;
1123 struct lustre_mount_data2 *lmd2 = data;
1124 struct lustre_sb_info *lsi; 1118 struct lustre_sb_info *lsi;
1125 int rc; 1119 int rc;
1126 1120
@@ -1143,17 +1137,22 @@ static int lustre_fill_super(struct super_block *sb, void *data, int silent)
1143 obd_zombie_barrier(); 1137 obd_zombie_barrier();
1144 1138
1145 /* Figure out the lmd from the mount options */ 1139 /* Figure out the lmd from the mount options */
1146 if (lmd_parse((lmd2->lmd2_data), lmd)) { 1140 if (lmd_parse(lmd2_data, lmd)) {
1147 lustre_put_lsi(sb); 1141 lustre_put_lsi(sb);
1148 rc = -EINVAL; 1142 rc = -EINVAL;
1149 goto out; 1143 goto out;
1150 } 1144 }
1151 1145
1152 if (lmd_is_client(lmd)) { 1146 if (lmd_is_client(lmd)) {
1147 bool have_client = false;
1153 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile); 1148 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1154 if (!client_fill_super) 1149 if (!client_fill_super)
1155 request_module("lustre"); 1150 request_module("lustre");
1156 if (!client_fill_super) { 1151 spin_lock(&client_lock);
1152 if (client_fill_super && try_module_get(client_mod))
1153 have_client = true;
1154 spin_unlock(&client_lock);
1155 if (!have_client) {
1157 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for client mount! Is the 'lustre' module loaded?\n"); 1156 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for client mount! Is the 'lustre' module loaded?\n");
1158 lustre_put_lsi(sb); 1157 lustre_put_lsi(sb);
1159 rc = -ENODEV; 1158 rc = -ENODEV;
@@ -1165,8 +1164,10 @@ static int lustre_fill_super(struct super_block *sb, void *data, int silent)
1165 } 1164 }
1166 /* Connect and start */ 1165 /* Connect and start */
1167 /* (should always be ll_fill_super) */ 1166 /* (should always be ll_fill_super) */
1168 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt); 1167 rc = (*client_fill_super)(sb);
1169 /* c_f_s will call lustre_common_put_super on failure */ 1168 /* c_f_s will call lustre_common_put_super on failure, otherwise
1169 * c_f_s will have taken another reference to the module */
1170 module_put(client_mod);
1170 } 1171 }
1171 } else { 1172 } else {
1172 CERROR("This is client-side-only module, cannot handle server mount.\n"); 1173 CERROR("This is client-side-only module, cannot handle server mount.\n");
@@ -1192,29 +1193,23 @@ out:
1192/* We can't call ll_fill_super by name because it lives in a module that 1193/* We can't call ll_fill_super by name because it lives in a module that
1193 * must be loaded after this one. 1194 * must be loaded after this one.
1194 */ 1195 */
1195void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb, 1196void lustre_register_super_ops(struct module *mod,
1196 struct vfsmount *mnt)) 1197 int (*cfs)(struct super_block *sb),
1198 void (*ksc)(struct super_block *sb))
1197{ 1199{
1200 spin_lock(&client_lock);
1201 client_mod = mod;
1198 client_fill_super = cfs; 1202 client_fill_super = cfs;
1203 kill_super_cb = ksc;
1204 spin_unlock(&client_lock);
1199} 1205}
1200EXPORT_SYMBOL(lustre_register_client_fill_super); 1206EXPORT_SYMBOL(lustre_register_super_ops);
1201
1202void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1203{
1204 kill_super_cb = cfs;
1205}
1206EXPORT_SYMBOL(lustre_register_kill_super_cb);
1207 1207
1208/***************** FS registration ******************/ 1208/***************** FS registration ******************/
1209static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags, 1209static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1210 const char *devname, void *data) 1210 const char *devname, void *data)
1211{ 1211{
1212 struct lustre_mount_data2 lmd2 = { 1212 return mount_nodev(fs_type, flags, data, lustre_fill_super);
1213 .lmd2_data = data,
1214 .lmd2_mnt = NULL
1215 };
1216
1217 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1218} 1213}
1219 1214
1220static void lustre_kill_super(struct super_block *sb) 1215static void lustre_kill_super(struct super_block *sb)
@@ -1230,11 +1225,11 @@ static void lustre_kill_super(struct super_block *sb)
1230/** Register the "lustre" fs type 1225/** Register the "lustre" fs type
1231 */ 1226 */
1232static struct file_system_type lustre_fs_type = { 1227static struct file_system_type lustre_fs_type = {
1233 .owner = THIS_MODULE, 1228 .owner = THIS_MODULE,
1234 .name = "lustre", 1229 .name = "lustre",
1235 .mount = lustre_mount, 1230 .mount = lustre_mount,
1236 .kill_sb = lustre_kill_super, 1231 .kill_sb = lustre_kill_super,
1237 .fs_flags = FS_REQUIRES_DEV | FS_RENAME_DOES_D_MOVE, 1232 .fs_flags = FS_RENAME_DOES_D_MOVE,
1238}; 1233};
1239MODULE_ALIAS_FS("lustre"); 1234MODULE_ALIAS_FS("lustre");
1240 1235
diff --git a/drivers/staging/lustre/lustre/osc/osc_internal.h b/drivers/staging/lustre/lustre/osc/osc_internal.h
index feda61bcdb9b..32db150fd42e 100644
--- a/drivers/staging/lustre/lustre/osc/osc_internal.h
+++ b/drivers/staging/lustre/lustre/osc/osc_internal.h
@@ -168,9 +168,9 @@ struct osc_device {
168 168
169 /* Write stats is actually protected by client_obd's lock. */ 169 /* Write stats is actually protected by client_obd's lock. */
170 struct osc_stats { 170 struct osc_stats {
171 uint64_t os_lockless_writes; /* by bytes */ 171 u64 os_lockless_writes; /* by bytes */
172 uint64_t os_lockless_reads; /* by bytes */ 172 u64 os_lockless_reads; /* by bytes */
173 uint64_t os_lockless_truncates; /* by times */ 173 u64 os_lockless_truncates; /* by times */
174 } od_stats; 174 } od_stats;
175 175
176 /* configuration item(s) */ 176 /* configuration item(s) */
diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index 53eda4c99142..45b1ebf33363 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -2844,7 +2844,9 @@ static int __init osc_init(void)
2844 if (rc) 2844 if (rc)
2845 goto out_kmem; 2845 goto out_kmem;
2846 2846
2847 register_shrinker(&osc_cache_shrinker); 2847 rc = register_shrinker(&osc_cache_shrinker);
2848 if (rc)
2849 goto out_type;
2848 2850
2849 /* This is obviously too much memory, only prevent overflow here */ 2851 /* This is obviously too much memory, only prevent overflow here */
2850 if (osc_reqpool_mem_max >= 1 << 12 || osc_reqpool_mem_max == 0) { 2852 if (osc_reqpool_mem_max >= 1 << 12 || osc_reqpool_mem_max == 0) {
diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c
index 2a9f2f2ebaa8..bac4b2304bad 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/client.c
@@ -3067,7 +3067,7 @@ void ptlrpc_init_xid(void)
3067 3067
3068 spin_lock_init(&ptlrpc_last_xid_lock); 3068 spin_lock_init(&ptlrpc_last_xid_lock);
3069 if (now < YEAR_2004) { 3069 if (now < YEAR_2004) {
3070 cfs_get_random_bytes(&ptlrpc_last_xid, sizeof(ptlrpc_last_xid)); 3070 get_random_bytes(&ptlrpc_last_xid, sizeof(ptlrpc_last_xid));
3071 ptlrpc_last_xid >>= 2; 3071 ptlrpc_last_xid >>= 2;
3072 ptlrpc_last_xid |= (1ULL << 61); 3072 ptlrpc_last_xid |= (1ULL << 61);
3073 } else { 3073 } else {
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
index 77a3721beaee..134ee727e8b7 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
@@ -396,6 +396,8 @@ static struct shrinker pools_shrinker = {
396 396
397int sptlrpc_enc_pool_init(void) 397int sptlrpc_enc_pool_init(void)
398{ 398{
399 int rc;
400
399 /* 401 /*
400 * maximum capacity is 1/8 of total physical memory. 402 * maximum capacity is 1/8 of total physical memory.
401 * is the 1/8 a good number? 403 * is the 1/8 a good number?
@@ -432,9 +434,11 @@ int sptlrpc_enc_pool_init(void)
432 if (!page_pools.epp_pools) 434 if (!page_pools.epp_pools)
433 return -ENOMEM; 435 return -ENOMEM;
434 436
435 register_shrinker(&pools_shrinker); 437 rc = register_shrinker(&pools_shrinker);
438 if (rc)
439 enc_pools_free();
436 440
437 return 0; 441 return rc;
438} 442}
439 443
440void sptlrpc_enc_pool_fini(void) 444void sptlrpc_enc_pool_fini(void)
diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index bb1d6dafca83..26994b429cf2 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -207,13 +207,9 @@ static irqreturn_t csi_idmac_eof_interrupt(int irq, void *dev_id)
207 goto unlock; 207 goto unlock;
208 } 208 }
209 209
210 if (priv->fim) { 210 if (priv->fim)
211 struct timespec cur_ts;
212
213 ktime_get_ts(&cur_ts);
214 /* call frame interval monitor */ 211 /* call frame interval monitor */
215 imx_media_fim_eof_monitor(priv->fim, &cur_ts); 212 imx_media_fim_eof_monitor(priv->fim, ktime_get());
216 }
217 213
218 csi_vb2_buf_done(priv); 214 csi_vb2_buf_done(priv);
219 215
diff --git a/drivers/staging/media/imx/imx-media-fim.c b/drivers/staging/media/imx/imx-media-fim.c
index 47275ef803f3..6df189135db8 100644
--- a/drivers/staging/media/imx/imx-media-fim.c
+++ b/drivers/staging/media/imx/imx-media-fim.c
@@ -66,7 +66,7 @@ struct imx_media_fim {
66 int icap_flags; 66 int icap_flags;
67 67
68 int counter; 68 int counter;
69 struct timespec last_ts; 69 ktime_t last_ts;
70 unsigned long sum; /* usec */ 70 unsigned long sum; /* usec */
71 unsigned long nominal; /* usec */ 71 unsigned long nominal; /* usec */
72 72
@@ -147,22 +147,26 @@ static void send_fim_event(struct imx_media_fim *fim, unsigned long error)
147 * (presumably random) interrupt latency. 147 * (presumably random) interrupt latency.
148 */ 148 */
149static void frame_interval_monitor(struct imx_media_fim *fim, 149static void frame_interval_monitor(struct imx_media_fim *fim,
150 struct timespec *ts) 150 ktime_t timestamp)
151{ 151{
152 unsigned long interval, error, error_avg; 152 long long interval, error;
153 unsigned long error_avg;
153 bool send_event = false; 154 bool send_event = false;
154 struct timespec diff;
155 155
156 if (!fim->enabled || ++fim->counter <= 0) 156 if (!fim->enabled || ++fim->counter <= 0)
157 goto out_update_ts; 157 goto out_update_ts;
158 158
159 diff = timespec_sub(*ts, fim->last_ts); 159 /* max error is less than l00µs, so use 32-bit division or fail */
160 interval = diff.tv_sec * 1000 * 1000 + diff.tv_nsec / 1000; 160 interval = ktime_to_ns(ktime_sub(timestamp, fim->last_ts));
161 error = abs(interval - fim->nominal); 161 error = abs(interval - NSEC_PER_USEC * (u64)fim->nominal);
162 if (error > U32_MAX)
163 error = U32_MAX;
164 else
165 error = abs((u32)error / NSEC_PER_USEC);
162 166
163 if (fim->tolerance_max && error >= fim->tolerance_max) { 167 if (fim->tolerance_max && error >= fim->tolerance_max) {
164 dev_dbg(fim->sd->dev, 168 dev_dbg(fim->sd->dev,
165 "FIM: %lu ignored, out of tolerance bounds\n", 169 "FIM: %llu ignored, out of tolerance bounds\n",
166 error); 170 error);
167 fim->counter--; 171 fim->counter--;
168 goto out_update_ts; 172 goto out_update_ts;
@@ -184,7 +188,7 @@ static void frame_interval_monitor(struct imx_media_fim *fim,
184 } 188 }
185 189
186out_update_ts: 190out_update_ts:
187 fim->last_ts = *ts; 191 fim->last_ts = timestamp;
188 if (send_event) 192 if (send_event)
189 send_fim_event(fim, error_avg); 193 send_fim_event(fim, error_avg);
190} 194}
@@ -195,14 +199,14 @@ out_update_ts:
195 * to interrupt latency. 199 * to interrupt latency.
196 */ 200 */
197static void fim_input_capture_handler(int channel, void *dev_id, 201static void fim_input_capture_handler(int channel, void *dev_id,
198 struct timespec *ts) 202 ktime_t timestamp)
199{ 203{
200 struct imx_media_fim *fim = dev_id; 204 struct imx_media_fim *fim = dev_id;
201 unsigned long flags; 205 unsigned long flags;
202 206
203 spin_lock_irqsave(&fim->lock, flags); 207 spin_lock_irqsave(&fim->lock, flags);
204 208
205 frame_interval_monitor(fim, ts); 209 frame_interval_monitor(fim, timestamp);
206 210
207 if (!completion_done(&fim->icap_first_event)) 211 if (!completion_done(&fim->icap_first_event))
208 complete(&fim->icap_first_event); 212 complete(&fim->icap_first_event);
@@ -405,14 +409,14 @@ err_free:
405 * the frame_interval_monitor() is called by the input capture event 409 * the frame_interval_monitor() is called by the input capture event
406 * callback handler in that case. 410 * callback handler in that case.
407 */ 411 */
408void imx_media_fim_eof_monitor(struct imx_media_fim *fim, struct timespec *ts) 412void imx_media_fim_eof_monitor(struct imx_media_fim *fim, ktime_t timestamp)
409{ 413{
410 unsigned long flags; 414 unsigned long flags;
411 415
412 spin_lock_irqsave(&fim->lock, flags); 416 spin_lock_irqsave(&fim->lock, flags);
413 417
414 if (!icap_enabled(fim)) 418 if (!icap_enabled(fim))
415 frame_interval_monitor(fim, ts); 419 frame_interval_monitor(fim, timestamp);
416 420
417 spin_unlock_irqrestore(&fim->lock, flags); 421 spin_unlock_irqrestore(&fim->lock, flags);
418} 422}
diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h
index d409170632bd..ac3ab115394f 100644
--- a/drivers/staging/media/imx/imx-media.h
+++ b/drivers/staging/media/imx/imx-media.h
@@ -280,7 +280,7 @@ int imx_media_pipeline_set_stream(struct imx_media_dev *imxmd,
280 280
281/* imx-media-fim.c */ 281/* imx-media-fim.c */
282struct imx_media_fim; 282struct imx_media_fim;
283void imx_media_fim_eof_monitor(struct imx_media_fim *fim, struct timespec *ts); 283void imx_media_fim_eof_monitor(struct imx_media_fim *fim, ktime_t timestamp);
284int imx_media_fim_set_stream(struct imx_media_fim *fim, 284int imx_media_fim_set_stream(struct imx_media_fim *fim,
285 const struct v4l2_fract *frame_interval, 285 const struct v4l2_fract *frame_interval,
286 bool on); 286 bool on);
diff --git a/drivers/staging/most/Documentation/ABI/sysfs-bus-most.txt b/drivers/staging/most/Documentation/ABI/sysfs-bus-most.txt
new file mode 100644
index 000000000000..d8fa841e3742
--- /dev/null
+++ b/drivers/staging/most/Documentation/ABI/sysfs-bus-most.txt
@@ -0,0 +1,313 @@
1What: /sys/bus/most/devices/.../description
2Date: March 2017
3KernelVersion: 4.15
4Contact: Christian Gromm <christian.gromm@microchip.com>
5Description:
6 Provides information about the interface type and the physical
7 location of the device. Hardware attached via USB, for instance,
8 might return <usb_device 1-1.1:1.0>
9Users:
10
11What: /sys/bus/most/devices/.../interface
12Date: March 2017
13KernelVersion: 4.15
14Contact: Christian Gromm <christian.gromm@microchip.com>
15Description:
16 Indicates the type of peripheral interface the device uses.
17Users:
18
19What: /sys/bus/most/devices/.../dci
20Date: June 2016
21KernelVersion: 4.15
22Contact: Christian Gromm <christian.gromm@microchip.com>
23Description:
24 If the network interface controller is attached via USB, a dci
25 directory is created that allows applications to read and
26 write the controller's DCI registers.
27Users:
28
29What: /sys/bus/most/devices/.../dci/arb_address
30Date: June 2016
31KernelVersion: 4.15
32Contact: Christian Gromm <christian.gromm@microchip.com>
33Description:
34 This is used to set an arbitrary DCI register address an
35 application wants to read from or write to.
36Users:
37
38What: /sys/bus/most/devices/.../dci/arb_value
39Date: June 2016
40KernelVersion: 4.15
41Contact: Christian Gromm <christian.gromm@microchip.com>
42Description:
43 This is used to read and write the DCI register whose address
44 is stored in arb_address.
45Users:
46
47What: /sys/bus/most/devices/.../dci/mep_eui48_hi
48Date: June 2016
49KernelVersion: 4.15
50Contact: Christian Gromm <christian.gromm@microchip.com>
51Description:
52 This is used to check and configure the MAC address.
53Users:
54
55What: /sys/bus/most/devices/.../dci/mep_eui48_lo
56Date: June 2016
57KernelVersion: 4.15
58Contact: Christian Gromm <christian.gromm@microchip.com>
59Description:
60 This is used to check and configure the MAC address.
61Users:
62
63What: /sys/bus/most/devices/.../dci/mep_eui48_mi
64Date: June 2016
65KernelVersion: 4.15
66Contact: Christian Gromm <christian.gromm@microchip.com>
67Description:
68 This is used to check and configure the MAC address.
69Users:
70
71What: /sys/bus/most/devices/.../dci/mep_filter
72Date: June 2016
73KernelVersion: 4.15
74Contact: Christian Gromm <christian.gromm@microchip.com>
75Description:
76 This is used to check and configure the MEP filter address.
77Users:
78
79What: /sys/bus/most/devices/.../dci/mep_hash0
80Date: June 2016
81KernelVersion: 4.15
82Contact: Christian Gromm <christian.gromm@microchip.com>
83Description:
84 This is used to check and configure the MEP hash table.
85Users:
86
87What: /sys/bus/most/devices/.../dci/mep_hash1
88Date: June 2016
89KernelVersion: 4.15
90Contact: Christian Gromm <christian.gromm@microchip.com>
91Description:
92 This is used to check and configure the MEP hash table.
93Users:
94
95What: /sys/bus/most/devices/.../dci/mep_hash2
96Date: June 2016
97KernelVersion: 4.15
98Contact: Christian Gromm <christian.gromm@microchip.com>
99Description:
100 This is used to check and configure the MEP hash table.
101Users:
102
103What: /sys/bus/most/devices/.../dci/mep_hash3
104Date: June 2016
105KernelVersion: 4.15
106Contact: Christian Gromm <christian.gromm@microchip.com>
107Description:
108 This is used to check and configure the MEP hash table.
109Users:
110
111What: /sys/bus/most/devices/.../dci/ni_state
112Date: June 2016
113KernelVersion: 4.15
114Contact: Christian Gromm <christian.gromm@microchip.com>
115Description:
116 Indicates the current network interface state.
117Users:
118
119What: /sys/bus/most/devices/.../dci/node_address
120Date: June 2016
121KernelVersion: 4.15
122Contact: Christian Gromm <christian.gromm@microchip.com>
123Description:
124 Indicates the current node address.
125Users:
126
127What: /sys/bus/most/devices/.../dci/node_position
128Date: June 2016
129KernelVersion: 4.15
130Contact: Christian Gromm <christian.gromm@microchip.com>
131Description:
132 Indicates the current node position.
133Users:
134
135What: /sys/bus/most/devices/.../dci/packet_bandwidth
136Date: June 2016
137KernelVersion: 4.15
138Contact: Christian Gromm <christian.gromm@microchip.com>
139Description:
140 Indicates the configured packet bandwidth.
141Users:
142
143What: /sys/bus/most/devices/.../dci/sync_ep
144Date: June 2016
145KernelVersion: 4.15
146Contact: Christian Gromm <christian.gromm@microchip.com>
147Description:
148 Triggers the controller's synchronization process for a certain
149 endpoint.
150Users:
151
152What: /sys/bus/most/devices/.../<channel>/
153Date: March 2017
154KernelVersion: 4.15
155Contact: Christian Gromm <christian.gromm@microchip.com>
156Description:
157 For every channel of the device a directory is created, whose
158 name is dictated by the HDM. This enables an application to
159 collect information about the channel's capabilities and
160 configure it.
161Users:
162
163What: /sys/bus/most/devices/.../<channel>/available_datatypes
164Date: March 2017
165KernelVersion: 4.15
166Contact: Christian Gromm <christian.gromm@microchip.com>
167Description:
168 Indicates the data types the current channel can transport.
169Users:
170
171What: /sys/bus/most/devices/.../<channel>/available_directions
172Date: March 2017
173KernelVersion: 4.15
174Contact: Christian Gromm <christian.gromm@microchip.com>
175Description:
176 Indicates the directions the current channel is capable of.
177Users:
178
179What: /sys/bus/most/devices/.../<channel>/number_of_packet_buffers
180Date: March 2017
181KernelVersion: 4.15
182Contact: Christian Gromm <christian.gromm@microchip.com>
183Description:
184 Indicates the number of packet buffers the current channel can
185 handle.
186Users:
187
188What: /sys/bus/most/devices/.../<channel>/number_of_stream_buffers
189Date: March 2017
190KernelVersion: 4.15
191Contact: Christian Gromm <christian.gromm@microchip.com>
192Description:
193 Indicates the number of streaming buffers the current channel can
194 handle.
195Users:
196
197What: /sys/bus/most/devices/.../<channel>/size_of_packet_buffer
198Date: March 2017
199KernelVersion: 4.15
200Contact: Christian Gromm <christian.gromm@microchip.com>
201Description:
202 Indicates the size of a packet buffer the current channel can
203 handle.
204Users:
205
206What: /sys/bus/most/devices/.../<channel>/size_of_stream_buffer
207Date: March 2017
208KernelVersion: 4.15
209Contact: Christian Gromm <christian.gromm@microchip.com>
210Description:
211 Indicates the size of a streaming buffer the current channel can
212 handle.
213Users:
214
215What: /sys/bus/most/devices/.../<channel>/set_number_of_buffers
216Date: March 2017
217KernelVersion: 4.15
218Contact: Christian Gromm <christian.gromm@microchip.com>
219Description:
220 This is to configure the number of buffers of the current channel.
221Users:
222
223What: /sys/bus/most/devices/.../<channel>/set_buffer_size
224Date: March 2017
225KernelVersion: 4.15
226Contact: Christian Gromm <christian.gromm@microchip.com>
227Description:
228 This is to configure the size of a buffer of the current channel.
229Users:
230
231What: /sys/bus/most/devices/.../<channel>/set_direction
232Date: March 2017
233KernelVersion: 4.15
234Contact: Christian Gromm <christian.gromm@microchip.com>
235Description:
236 This is to configure the direction of the current channel.
237 The following strings will be accepted:
238 'dir_tx',
239 'dir_rx'
240Users:
241
242What: /sys/bus/most/devices/.../<channel>/set_datatype
243Date: March 2017
244KernelVersion: 4.15
245Contact: Christian Gromm <christian.gromm@microchip.com>
246Description:
247 This is to configure the data type of the current channel.
248 The following strings will be accepted:
249 'control',
250 'async',
251 'sync',
252 'isoc_avp'
253Users:
254
255What: /sys/bus/most/devices/.../<channel>/set_subbuffer_size
256Date: March 2017
257KernelVersion: 4.15
258Contact: Christian Gromm <christian.gromm@microchip.com>
259Description:
260 This is to configure the subbuffer size of the current channel.
261Users:
262
263What: /sys/bus/most/devices/.../<channel>/set_packets_per_xact
264Date: March 2017
265KernelVersion: 4.15
266Contact: Christian Gromm <christian.gromm@microchip.com>
267Description:
268 This is to configure the number of packets per transaction of
269 the current channel. This is only needed network interface
270 controller is attached via USB.
271Users:
272
273What: /sys/bus/most/devices/.../<channel>/channel_starving
274Date: March 2017
275KernelVersion: 4.15
276Contact: Christian Gromm <christian.gromm@microchip.com>
277Description:
278 Indicates whether current channel ran out of buffers.
279Users:
280
281What: /sys/bus/most/drivers/mostcore/add_link
282Date: March 2017
283KernelVersion: 4.15
284Contact: Christian Gromm <christian.gromm@microchip.com>
285Description:
286 This is used to link a channel to a component of the
287 mostcore. A link created by writing to this file is
288 referred to as pipe.
289Users:
290
291What: /sys/bus/most/drivers/mostcore/remove_link
292Date: March 2017
293KernelVersion: 4.15
294Contact: Christian Gromm <christian.gromm@microchip.com>
295Description:
296 This is used to unlink a channel from a component.
297Users:
298
299What: /sys/bus/most/drivers/mostcore/components
300Date: March 2017
301KernelVersion: 4.15
302Contact: Christian Gromm <christian.gromm@microchip.com>
303Description:
304 This is used to retrieve a list of registered components.
305Users:
306
307What: /sys/bus/most/drivers/mostcore/links
308Date: March 2017
309KernelVersion: 4.15
310Contact: Christian Gromm <christian.gromm@microchip.com>
311Description:
312 This is used to retrieve a list of established links.
313Users:
diff --git a/drivers/staging/most/Documentation/driver_usage.txt b/drivers/staging/most/Documentation/driver_usage.txt
index a4dc0c348fbc..bb9b4e870199 100644
--- a/drivers/staging/most/Documentation/driver_usage.txt
+++ b/drivers/staging/most/Documentation/driver_usage.txt
@@ -23,20 +23,29 @@ audio/video streaming. Therefore, the driver perfectly fits to the mission
23of Automotive Grade Linux to create open source software solutions for 23of Automotive Grade Linux to create open source software solutions for
24automotive applications. 24automotive applications.
25 25
26The driver consists basically of three layers. The hardware layer, the 26The MOST driver uses module stacking to divide the associated modules into
27core layer and the application layer. The core layer consists of the core 27three layers. From bottom up these layers are: the adapter layer, the core
28module only. This module handles the communication flow through all three 28layer and the application layer. The core layer implements the MOST
29layers, the configuration of the driver, the configuration interface 29subsystem and consists basically of the module core.c and its API. It
30representation in sysfs, and the buffer management. 30registers the MOST bus with the kernel's device model, handles the data
31For each of the other two layers a selection of modules is provided. These 31routing through all three layers, the configuration of the driver, the
32modules can arbitrarily be combined to meet the needs of the desired 32representation of the configuration interface in sysfs and the buffer
33system architecture. A module of the hardware layer is referred to as an 33management.
34HDM (hardware dependent module). Each module of this layer handles exactly 34
35one of the peripheral interfaces of a network interface controller (e.g. 35For each of the other two layers a set of modules is provided. Those can be
36USB, MediaLB, I2C). A module of the application layer is referred to as an 36arbitrarily combined with the core to meet the connectivity of the desired
37AIM (application interfacing module). The modules of this layer give access 37system architecture.
38to MOST via one the following ways: character devices, ALSA, Networking or 38
39V4L2. 39A module of the adapter layer is basically a device driver for a different
40subsystem. It is registered with the core to connect the MOST subsystem to
41the attached network interface controller hardware. Hence, a given module
42of this layer is designed to handle exactly one of the peripheral
43interfaces (e.g. USB, MediaLB, I2C) the hardware provides.
44
45A module of the application layer is referred to as a core comoponent,
46which kind of extends the core by providing connectivity to the user space.
47Applications, then, can access a MOST network via character devices, an
48ALSA soundcard, a Network adapter or a V4L2 capture device.
40 49
41To physically access MOST, an Intelligent Network Interface Controller 50To physically access MOST, an Intelligent Network Interface Controller
42(INIC) is needed. For more information on available controllers visit: 51(INIC) is needed. For more information on available controllers visit:
@@ -44,15 +53,14 @@ www.microchip.com
44 53
45 54
46 55
47 Section 1.1 Hardware Layer 56 Section 1.1 Adapter Layer
48 57
49The hardware layer contains so called hardware dependent modules (HDM). For each 58The adapter layer contains a pool of device drivers. For each peripheral
50peripheral interface the hardware supports the driver has a suitable module 59interface the hardware supports there is one suitable module that handles
51that handles the interface. 60the interface. Adapter drivers encapsulate the peripheral interface
52 61specific knowledge of the MOST driver stack and provide an easy way of
53The HDMs encapsulate the peripheral interface specific knowledge of the driver 62extending the number of supported interfaces. Currently the following
54and provides an easy way of extending the number of supported interfaces. 63interfaces are available:
55Currently the following HDMs are available:
56 64
57 1) MediaLB (DIM2) 65 1) MediaLB (DIM2)
58 Host wants to communicate with hardware via MediaLB. 66 Host wants to communicate with hardware via MediaLB.
@@ -63,26 +71,34 @@ Currently the following HDMs are available:
63 3) USB 71 3) USB
64 Host wants to communicate with the hardware via USB. 72 Host wants to communicate with the hardware via USB.
65 73
74Once an adapter driver recognizes a MOST device being attached, it
75registers it with the core, which, in turn, assigns the necessary members
76of the embedded struct device (e.g. the bus this device belongs to and
77attribute groups) and registers it with the kernel's device model.
66 78
67 Section 1.2 Core Layer
68
69The core layer contains the mostcore module only, which processes the driver
70configuration via sysfs, buffer management and data forwarding.
71 79
80 Section 1.2 Core Layer
72 81
82This layer implements the MOST subsystem. It contains the core module and
83the header file most.h that exposes the API of the core. When inserted in
84the kernel, it registers the MOST bus_type with the kernel's device model
85and registers itself as a device driver for this bus. Besides these meta
86tasks the core populates the configuration directory for a registered MOST
87device (represented by struct most_interface) in sysfs and processes the
88configuration of the device's interface. The core layer also handles the
89buffer management and the data/message routing.
73 90
74 Section 1.2 Application Layer
75 91
76The application layer contains so called application interfacing modules (AIM). 92 Section 1.3 Application Layer
77Depending on how the driver should interface to the application, one or more
78suitable modules can be selected.
79 93
80The AIMs encapsulate the application interface specific knowledge of the driver 94This layer contains a pool of device drivers that are components of the
81and provides access to user space or other kernel subsystems. 95core designed to make up the userspace experience of the MOST driver stack.
82Currently the following AIMs are available 96Depending on how an application is meant to interface the driver, one or
97more modules of this pool can be registered with the core. Currently the
98following components are available
83 99
84 1) Character Device 100 1) Character Device
85 Applications can access the driver by means of character devices. 101 Userspace can access the driver by means of character devices.
86 102
87 2) Networking 103 2) Networking
88 Standard networking applications (e.g. iperf) can by used to access 104 Standard networking applications (e.g. iperf) can by used to access
@@ -97,84 +113,86 @@ Currently the following AIMs are available
97 used to access the driver via the ALSA subsystem. 113 used to access the driver via the ALSA subsystem.
98 114
99 115
116 Section 2 Usage of the MOST Driver
100 117
101 Section 2 Configuration 118 Section 2.1 Configuration
102 119
103See ABI/sysfs-class-most.txt 120See ABI/sysfs-bus-most.txt
104 121
105 122
123 Section 2.2 Routing Channels
106 124
107 Section 3 USB Padding 125To connect a configured channel to a certain core component and make it
126accessible for user space applications, the driver attribute 'add_link' is
127used. The configuration string passed to it has the following format:
108 128
109When transceiving synchronous or isochronous data, the number of packets per USB 129 "device_name:channel_name:component_name:link_name[.param]"
110transaction and the sub-buffer size need to be configured. These values
111are needed for the driver to process buffer padding, as expected by hardware,
112which is for performance optimization purposes of the USB transmission.
113 130
114When transmitting synchronous data the allocated channel width needs to be 131It is the concatenation of up to four substrings separated by a colon. The
115written to 'set_subbuffer_size'. Additionally, the number of MOST frames that 132substrings contain the names of the MOST interface, the channel, the
116should travel to the host within one USB transaction need to be written to 133component driver and a custom name with which the link is going to be
117'packets_per_xact'. 134referenced with. Since some components need additional information, the
135link name can be extended with a component-specific parameter (separated by
136a dot). In case the character device component is loaded, the handle would
137also appear as a device node in the /dev directory.
118 138
119Internally the synchronous threshold is calculated as follows: 139Cdev component example:
140 $ echo "mdev0:ep_81:cdev:my_rx_channel" >$(DRV_DIR)/add_link
120 141
121 frame_size = set_subbuffer_size * packets_per_xact
122 142
123In case 'packets_per_xact' is set to 0xFF the maximum number of packets, 143Sound component example:
124allocated within one MOST frame, is calculated that fit into _one_ 512 byte
125USB full packet.
126 144
127 frame_size = floor(MTU_USB / bandwidth_sync) * bandwidth_sync 145The sound component needs an additional parameter to determine the audio
146resolution that is going to be used. The following formats are available:
128 147
129This frame_size is the number of synchronous data within an USB transaction, 148 - "1x8" (Mono)
130which renders MTU_USB - frame_size bytes for padding. 149 - "2x16" (16-bit stereo)
150 - "2x24" (24-bit stereo)
151 - "2x32" (32-bit stereo)
152 - "6x16" (16-bit surround 5.1)
131 153
132When transmitting isochronous AVP data the desired packet size needs to be 154 $ echo "mdev0:ep_81:sound:most51_playback.6x16" >$(DRV_DIR)/add_link
133written to 'set_subbuffer_size' and hardware will always expect two isochronous
134packets within one USB transaction. This renders
135 155
136 MTU_USB - (2 * set_subbuffer_size)
137 156
138bytes for padding.
139
140Note that at least 2 times set_subbuffer_size bytes for isochronous data or
141set_subbuffer_size times packts_per_xact bytes for synchronous data need to be
142put in the transmission buffer and passed to the driver.
143 157
144Since HDMs are allowed to change a chosen configuration to best fit its 158 Section 2.3 USB Padding
145constraints, it is recommended to always double check the configuration and read
146back the previously written files.
147 159
160When transceiving synchronous or isochronous data, the number of packets
161per USB transaction and the sub-buffer size need to be configured. These
162values are needed for the driver to process buffer padding, as expected by
163hardware, which is for performance optimization purposes of the USB
164transmission.
148 165
166When transmitting synchronous data the allocated channel width needs to be
167written to 'set_subbuffer_size'. Additionally, the number of MOST frames
168that should travel to the host within one USB transaction need to be
169written to 'packets_per_xact'.
149 170
150 Section 4 Routing Channels 171The driver, then, calculates the synchronous threshold as follows:
151 172
152To connect a channel that has been configured as outlined above to an AIM and 173 frame_size = set_subbuffer_size * packets_per_xact
153make it accessible to user space applications, the attribute file 'add_link' is
154used. To actually bind a channel to the AIM a string needs to be written to the
155file that complies with the following syntax:
156 174
157 "most_device:channel_name:link_name[.param]" 175In case 'packets_per_xact' is set to 0xFF the maximum number of packets,
176allocated within one MOST frame, is calculated that fit into _one_ 512 byte
177USB full packet.
158 178
159The example above links the channel "channel_name" of the device "most_device" 179 frame_size = floor(MTU_USB / bandwidth_sync) * bandwidth_sync
160to the AIM. In case the AIM interfaces the VFS this would also create a device
161node "link_name" in the /dev directory. The parameter "param" is an AIM dependent
162string, which can be omitted in case the used AIM does not make any use of it.
163 180
164Cdev AIM example: 181This frame_size is the number of synchronous data within an USB
165 $ echo "mdev0:ep_81:my_rx_channel" >add_link 182transaction, which renders MTU_USB - frame_size bytes for padding.
166 $ echo "mdev0:ep_81" >add_link
167 183
184When transmitting isochronous AVP data the desired packet size needs to be
185written to 'set_subbuffer_size' and hardware will always expect two
186isochronous packets within one USB transaction. This renders
168 187
169Sound/ALSA AIM example: 188 MTU_USB - (2 * set_subbuffer_size)
170 189
171The sound/ALSA AIM needs an additional parameter to determine the audio resolution 190bytes for padding.
172that is going to be used. The following strings can be used:
173 191
174 - "1x8" (Mono) 192Note that at least (2 * set_subbuffer_size) bytes for isochronous data or
175 - "2x16" (16-bit stereo) 193(set_subbuffer_size * packts_per_xact) bytes for synchronous data need to
176 - "2x24" (24-bit stereo) 194be put in the transmission buffer and passed to the driver.
177 - "2x32" (32-bit stereo)
178 195
179 $ echo "mdev0:ep_81:audio_rx.2x16" >add_link 196Since adapter drivers are allowed to change a chosen configuration to best
180 $ echo "mdev0:ep_81" >add_link 197fit its constraints, it is recommended to always double check the
198configuration and read back the previously written files.
diff --git a/drivers/staging/most/Kconfig b/drivers/staging/most/Kconfig
index 0b9b9b539f70..20047abbe560 100644
--- a/drivers/staging/most/Kconfig
+++ b/drivers/staging/most/Kconfig
@@ -1,10 +1,15 @@
1menuconfig MOST 1menuconfig MOST
2 tristate "MOST driver" 2 tristate "MOST support"
3 depends on HAS_DMA 3 depends on HAS_DMA
4 select MOSTCORE
5 default n 4 default n
6 ---help--- 5 ---help---
7 This option allows you to enable support for MOST Network transceivers. 6 Say Y here if you want to enable MOST support.
7 This driver needs at least one additional component to enable the
8 desired access from userspace (e.g. character devices) and one that
9 matches the network controller's hardware interface (e.g. USB).
10
11 To compile this driver as a module, choose M here: the
12 module will be called most_core.
8 13
9 If in doubt, say N here. 14 If in doubt, say N here.
10 15
@@ -12,20 +17,18 @@ menuconfig MOST
12 17
13if MOST 18if MOST
14 19
15source "drivers/staging/most/mostcore/Kconfig" 20source "drivers/staging/most/cdev/Kconfig"
16
17source "drivers/staging/most/aim-cdev/Kconfig"
18 21
19source "drivers/staging/most/aim-network/Kconfig" 22source "drivers/staging/most/net/Kconfig"
20 23
21source "drivers/staging/most/aim-sound/Kconfig" 24source "drivers/staging/most/sound/Kconfig"
22 25
23source "drivers/staging/most/aim-v4l2/Kconfig" 26source "drivers/staging/most/video/Kconfig"
24 27
25source "drivers/staging/most/hdm-dim2/Kconfig" 28source "drivers/staging/most/dim2/Kconfig"
26 29
27source "drivers/staging/most/hdm-i2c/Kconfig" 30source "drivers/staging/most/i2c/Kconfig"
28 31
29source "drivers/staging/most/hdm-usb/Kconfig" 32source "drivers/staging/most/usb/Kconfig"
30 33
31endif 34endif
diff --git a/drivers/staging/most/Makefile b/drivers/staging/most/Makefile
index f5bbb9deaab5..f8bcf488ecf2 100644
--- a/drivers/staging/most/Makefile
+++ b/drivers/staging/most/Makefile
@@ -1,9 +1,12 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2obj-$(CONFIG_MOSTCORE) += mostcore/ 2obj-$(CONFIG_MOST) += most_core.o
3obj-$(CONFIG_AIM_CDEV) += aim-cdev/ 3most_core-y := core.o
4obj-$(CONFIG_AIM_NETWORK) += aim-network/ 4ccflags-y += -Idrivers/staging/
5obj-$(CONFIG_AIM_SOUND) += aim-sound/ 5
6obj-$(CONFIG_AIM_V4L2) += aim-v4l2/ 6obj-$(CONFIG_MOST_CDEV) += cdev/
7obj-$(CONFIG_HDM_DIM2) += hdm-dim2/ 7obj-$(CONFIG_MOST_NET) += net/
8obj-$(CONFIG_HDM_I2C) += hdm-i2c/ 8obj-$(CONFIG_MOST_SOUND) += sound/
9obj-$(CONFIG_HDM_USB) += hdm-usb/ 9obj-$(CONFIG_MOST_VIDEO) += video/
10obj-$(CONFIG_MOST_DIM2) += dim2/
11obj-$(CONFIG_MOST_I2C) += i2c/
12obj-$(CONFIG_MOST_USB) += usb/
diff --git a/drivers/staging/most/aim-cdev/Makefile b/drivers/staging/most/aim-cdev/Makefile
deleted file mode 100644
index 0bcc6c637b75..000000000000
--- a/drivers/staging/most/aim-cdev/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
1obj-$(CONFIG_AIM_CDEV) += aim_cdev.o
2
3aim_cdev-objs := cdev.o
4ccflags-y += -Idrivers/staging/most/mostcore/ \ No newline at end of file
diff --git a/drivers/staging/most/aim-network/Makefile b/drivers/staging/most/aim-network/Makefile
deleted file mode 100644
index 840c1dd94873..000000000000
--- a/drivers/staging/most/aim-network/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
1obj-$(CONFIG_AIM_NETWORK) += aim_network.o
2
3aim_network-objs := networking.o
4ccflags-y += -Idrivers/staging/most/mostcore/
diff --git a/drivers/staging/most/aim-sound/Makefile b/drivers/staging/most/aim-sound/Makefile
deleted file mode 100644
index beba9586fd28..000000000000
--- a/drivers/staging/most/aim-sound/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
1obj-$(CONFIG_AIM_SOUND) += aim_sound.o
2
3aim_sound-objs := sound.o
4ccflags-y += -Idrivers/staging/most/mostcore/
diff --git a/drivers/staging/most/aim-v4l2/Makefile b/drivers/staging/most/aim-v4l2/Makefile
deleted file mode 100644
index 69a7524b466c..000000000000
--- a/drivers/staging/most/aim-v4l2/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
1obj-$(CONFIG_AIM_V4L2) += aim_v4l2.o
2
3aim_v4l2-objs := video.o
4
5ccflags-y += -Idrivers/staging/most/mostcore/
diff --git a/drivers/staging/most/aim-cdev/Kconfig b/drivers/staging/most/cdev/Kconfig
index 3c59f1bac127..2b04e26bcbea 100644
--- a/drivers/staging/most/aim-cdev/Kconfig
+++ b/drivers/staging/most/cdev/Kconfig
@@ -2,11 +2,11 @@
2# MOST Cdev configuration 2# MOST Cdev configuration
3# 3#
4 4
5config AIM_CDEV 5config MOST_CDEV
6 tristate "Cdev AIM" 6 tristate "Cdev"
7 7
8 ---help--- 8 ---help---
9 Say Y here if you want to commumicate via character devices. 9 Say Y here if you want to commumicate via character devices.
10 10
11 To compile this driver as a module, choose M here: the 11 To compile this driver as a module, choose M here: the
12 module will be called aim_cdev. \ No newline at end of file 12 module will be called most_cdev.
diff --git a/drivers/staging/most/cdev/Makefile b/drivers/staging/most/cdev/Makefile
new file mode 100644
index 000000000000..afb9870eb50f
--- /dev/null
+++ b/drivers/staging/most/cdev/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_MOST_CDEV) += most_cdev.o
2
3most_cdev-objs := cdev.o
4ccflags-y += -Idrivers/staging/
diff --git a/drivers/staging/most/aim-cdev/cdev.c b/drivers/staging/most/cdev/cdev.c
index 69f530972273..c183489c4a1c 100644
--- a/drivers/staging/most/aim-cdev/cdev.c
+++ b/drivers/staging/most/cdev/cdev.c
@@ -1,14 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * cdev.c - Application interfacing module for character devices 3 * cdev.c - Character device component for Mostcore
3 * 4 *
4 * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG 5 * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG
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 * This file is licensed under GPLv2.
12 */ 6 */
13 7
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -22,15 +16,17 @@
22#include <linux/kfifo.h> 16#include <linux/kfifo.h>
23#include <linux/uaccess.h> 17#include <linux/uaccess.h>
24#include <linux/idr.h> 18#include <linux/idr.h>
25#include "mostcore.h" 19#include "most/core.h"
26 20
27static dev_t aim_devno; 21static struct cdev_component {
28static struct class *aim_class; 22 dev_t devno;
29static struct ida minor_id; 23 struct ida minor_id;
30static unsigned int major; 24 unsigned int major;
31static struct most_aim cdev_aim; 25 struct class *class;
26 struct core_component cc;
27} comp;
32 28
33struct aim_channel { 29struct comp_channel {
34 wait_queue_head_t wq; 30 wait_queue_head_t wq;
35 spinlock_t unlink; /* synchronization lock to unlink channels */ 31 spinlock_t unlink; /* synchronization lock to unlink channels */
36 struct cdev cdev; 32 struct cdev cdev;
@@ -46,28 +42,28 @@ struct aim_channel {
46 struct list_head list; 42 struct list_head list;
47}; 43};
48 44
49#define to_channel(d) container_of(d, struct aim_channel, cdev) 45#define to_channel(d) container_of(d, struct comp_channel, cdev)
50static struct list_head channel_list; 46static struct list_head channel_list;
51static spinlock_t ch_list_lock; 47static spinlock_t ch_list_lock;
52 48
53static inline bool ch_has_mbo(struct aim_channel *c) 49static inline bool ch_has_mbo(struct comp_channel *c)
54{ 50{
55 return channel_has_mbo(c->iface, c->channel_id, &cdev_aim) > 0; 51 return channel_has_mbo(c->iface, c->channel_id, &comp.cc) > 0;
56} 52}
57 53
58static inline bool ch_get_mbo(struct aim_channel *c, struct mbo **mbo) 54static inline bool ch_get_mbo(struct comp_channel *c, struct mbo **mbo)
59{ 55{
60 if (!kfifo_peek(&c->fifo, mbo)) { 56 if (!kfifo_peek(&c->fifo, mbo)) {
61 *mbo = most_get_mbo(c->iface, c->channel_id, &cdev_aim); 57 *mbo = most_get_mbo(c->iface, c->channel_id, &comp.cc);
62 if (*mbo) 58 if (*mbo)
63 kfifo_in(&c->fifo, mbo, 1); 59 kfifo_in(&c->fifo, mbo, 1);
64 } 60 }
65 return *mbo; 61 return *mbo;
66} 62}
67 63
68static struct aim_channel *get_channel(struct most_interface *iface, int id) 64static struct comp_channel *get_channel(struct most_interface *iface, int id)
69{ 65{
70 struct aim_channel *c, *tmp; 66 struct comp_channel *c, *tmp;
71 unsigned long flags; 67 unsigned long flags;
72 int found_channel = 0; 68 int found_channel = 0;
73 69
@@ -84,44 +80,44 @@ static struct aim_channel *get_channel(struct most_interface *iface, int id)
84 return c; 80 return c;
85} 81}
86 82
87static void stop_channel(struct aim_channel *c) 83static void stop_channel(struct comp_channel *c)
88{ 84{
89 struct mbo *mbo; 85 struct mbo *mbo;
90 86
91 while (kfifo_out((struct kfifo *)&c->fifo, &mbo, 1)) 87 while (kfifo_out((struct kfifo *)&c->fifo, &mbo, 1))
92 most_put_mbo(mbo); 88 most_put_mbo(mbo);
93 most_stop_channel(c->iface, c->channel_id, &cdev_aim); 89 most_stop_channel(c->iface, c->channel_id, &comp.cc);
94} 90}
95 91
96static void destroy_cdev(struct aim_channel *c) 92static void destroy_cdev(struct comp_channel *c)
97{ 93{
98 unsigned long flags; 94 unsigned long flags;
99 95
100 device_destroy(aim_class, c->devno); 96 device_destroy(comp.class, c->devno);
101 cdev_del(&c->cdev); 97 cdev_del(&c->cdev);
102 spin_lock_irqsave(&ch_list_lock, flags); 98 spin_lock_irqsave(&ch_list_lock, flags);
103 list_del(&c->list); 99 list_del(&c->list);
104 spin_unlock_irqrestore(&ch_list_lock, flags); 100 spin_unlock_irqrestore(&ch_list_lock, flags);
105} 101}
106 102
107static void destroy_channel(struct aim_channel *c) 103static void destroy_channel(struct comp_channel *c)
108{ 104{
109 ida_simple_remove(&minor_id, MINOR(c->devno)); 105 ida_simple_remove(&comp.minor_id, MINOR(c->devno));
110 kfifo_free(&c->fifo); 106 kfifo_free(&c->fifo);
111 kfree(c); 107 kfree(c);
112} 108}
113 109
114/** 110/**
115 * aim_open - implements the syscall to open the device 111 * comp_open - implements the syscall to open the device
116 * @inode: inode pointer 112 * @inode: inode pointer
117 * @filp: file pointer 113 * @filp: file pointer
118 * 114 *
119 * This stores the channel pointer in the private data field of 115 * This stores the channel pointer in the private data field of
120 * the file structure and activates the channel within the core. 116 * the file structure and activates the channel within the core.
121 */ 117 */
122static int aim_open(struct inode *inode, struct file *filp) 118static int comp_open(struct inode *inode, struct file *filp)
123{ 119{
124 struct aim_channel *c; 120 struct comp_channel *c;
125 int ret; 121 int ret;
126 122
127 c = to_channel(inode->i_cdev); 123 c = to_channel(inode->i_cdev);
@@ -149,7 +145,7 @@ static int aim_open(struct inode *inode, struct file *filp)
149 } 145 }
150 146
151 c->mbo_offs = 0; 147 c->mbo_offs = 0;
152 ret = most_start_channel(c->iface, c->channel_id, &cdev_aim); 148 ret = most_start_channel(c->iface, c->channel_id, &comp.cc);
153 if (!ret) 149 if (!ret)
154 c->access_ref = 1; 150 c->access_ref = 1;
155 mutex_unlock(&c->io_mutex); 151 mutex_unlock(&c->io_mutex);
@@ -157,15 +153,15 @@ static int aim_open(struct inode *inode, struct file *filp)
157} 153}
158 154
159/** 155/**
160 * aim_close - implements the syscall to close the device 156 * comp_close - implements the syscall to close the device
161 * @inode: inode pointer 157 * @inode: inode pointer
162 * @filp: file pointer 158 * @filp: file pointer
163 * 159 *
164 * This stops the channel within the core. 160 * This stops the channel within the core.
165 */ 161 */
166static int aim_close(struct inode *inode, struct file *filp) 162static int comp_close(struct inode *inode, struct file *filp)
167{ 163{
168 struct aim_channel *c = to_channel(inode->i_cdev); 164 struct comp_channel *c = to_channel(inode->i_cdev);
169 165
170 mutex_lock(&c->io_mutex); 166 mutex_lock(&c->io_mutex);
171 spin_lock(&c->unlink); 167 spin_lock(&c->unlink);
@@ -182,19 +178,19 @@ static int aim_close(struct inode *inode, struct file *filp)
182} 178}
183 179
184/** 180/**
185 * aim_write - implements the syscall to write to the device 181 * comp_write - implements the syscall to write to the device
186 * @filp: file pointer 182 * @filp: file pointer
187 * @buf: pointer to user buffer 183 * @buf: pointer to user buffer
188 * @count: number of bytes to write 184 * @count: number of bytes to write
189 * @offset: offset from where to start writing 185 * @offset: offset from where to start writing
190 */ 186 */
191static ssize_t aim_write(struct file *filp, const char __user *buf, 187static ssize_t comp_write(struct file *filp, const char __user *buf,
192 size_t count, loff_t *offset) 188 size_t count, loff_t *offset)
193{ 189{
194 int ret; 190 int ret;
195 size_t to_copy, left; 191 size_t to_copy, left;
196 struct mbo *mbo = NULL; 192 struct mbo *mbo = NULL;
197 struct aim_channel *c = filp->private_data; 193 struct comp_channel *c = filp->private_data;
198 194
199 mutex_lock(&c->io_mutex); 195 mutex_lock(&c->io_mutex);
200 while (c->dev && !ch_get_mbo(c, &mbo)) { 196 while (c->dev && !ch_get_mbo(c, &mbo)) {
@@ -236,18 +232,18 @@ unlock:
236} 232}
237 233
238/** 234/**
239 * aim_read - implements the syscall to read from the device 235 * comp_read - implements the syscall to read from the device
240 * @filp: file pointer 236 * @filp: file pointer
241 * @buf: pointer to user buffer 237 * @buf: pointer to user buffer
242 * @count: number of bytes to read 238 * @count: number of bytes to read
243 * @offset: offset from where to start reading 239 * @offset: offset from where to start reading
244 */ 240 */
245static ssize_t 241static ssize_t
246aim_read(struct file *filp, char __user *buf, size_t count, loff_t *offset) 242comp_read(struct file *filp, char __user *buf, size_t count, loff_t *offset)
247{ 243{
248 size_t to_copy, not_copied, copied; 244 size_t to_copy, not_copied, copied;
249 struct mbo *mbo; 245 struct mbo *mbo;
250 struct aim_channel *c = filp->private_data; 246 struct comp_channel *c = filp->private_data;
251 247
252 mutex_lock(&c->io_mutex); 248 mutex_lock(&c->io_mutex);
253 while (c->dev && !kfifo_peek(&c->fifo, &mbo)) { 249 while (c->dev && !kfifo_peek(&c->fifo, &mbo)) {
@@ -287,9 +283,9 @@ aim_read(struct file *filp, char __user *buf, size_t count, loff_t *offset)
287 return copied; 283 return copied;
288} 284}
289 285
290static __poll_t aim_poll(struct file *filp, poll_table *wait) 286static __poll_t comp_poll(struct file *filp, poll_table *wait)
291{ 287{
292 struct aim_channel *c = filp->private_data; 288 struct comp_channel *c = filp->private_data;
293 __poll_t mask = 0; 289 __poll_t mask = 0;
294 290
295 poll_wait(filp, &c->wq, wait); 291 poll_wait(filp, &c->wq, wait);
@@ -309,24 +305,24 @@ static __poll_t aim_poll(struct file *filp, poll_table *wait)
309 */ 305 */
310static const struct file_operations channel_fops = { 306static const struct file_operations channel_fops = {
311 .owner = THIS_MODULE, 307 .owner = THIS_MODULE,
312 .read = aim_read, 308 .read = comp_read,
313 .write = aim_write, 309 .write = comp_write,
314 .open = aim_open, 310 .open = comp_open,
315 .release = aim_close, 311 .release = comp_close,
316 .poll = aim_poll, 312 .poll = comp_poll,
317}; 313};
318 314
319/** 315/**
320 * aim_disconnect_channel - disconnect a channel 316 * comp_disconnect_channel - disconnect a channel
321 * @iface: pointer to interface instance 317 * @iface: pointer to interface instance
322 * @channel_id: channel index 318 * @channel_id: channel index
323 * 319 *
324 * This frees allocated memory and removes the cdev that represents this 320 * This frees allocated memory and removes the cdev that represents this
325 * channel in user space. 321 * channel in user space.
326 */ 322 */
327static int aim_disconnect_channel(struct most_interface *iface, int channel_id) 323static int comp_disconnect_channel(struct most_interface *iface, int channel_id)
328{ 324{
329 struct aim_channel *c; 325 struct comp_channel *c;
330 326
331 if (!iface) { 327 if (!iface) {
332 pr_info("Bad interface pointer\n"); 328 pr_info("Bad interface pointer\n");
@@ -354,15 +350,15 @@ static int aim_disconnect_channel(struct most_interface *iface, int channel_id)
354} 350}
355 351
356/** 352/**
357 * aim_rx_completion - completion handler for rx channels 353 * comp_rx_completion - completion handler for rx channels
358 * @mbo: pointer to buffer object that has completed 354 * @mbo: pointer to buffer object that has completed
359 * 355 *
360 * This searches for the channel linked to this MBO and stores it in the local 356 * This searches for the channel linked to this MBO and stores it in the local
361 * fifo buffer. 357 * fifo buffer.
362 */ 358 */
363static int aim_rx_completion(struct mbo *mbo) 359static int comp_rx_completion(struct mbo *mbo)
364{ 360{
365 struct aim_channel *c; 361 struct comp_channel *c;
366 362
367 if (!mbo) 363 if (!mbo)
368 return -EINVAL; 364 return -EINVAL;
@@ -387,15 +383,15 @@ static int aim_rx_completion(struct mbo *mbo)
387} 383}
388 384
389/** 385/**
390 * aim_tx_completion - completion handler for tx channels 386 * comp_tx_completion - completion handler for tx channels
391 * @iface: pointer to interface instance 387 * @iface: pointer to interface instance
392 * @channel_id: channel index/ID 388 * @channel_id: channel index/ID
393 * 389 *
394 * This wakes sleeping processes in the wait-queue. 390 * This wakes sleeping processes in the wait-queue.
395 */ 391 */
396static int aim_tx_completion(struct most_interface *iface, int channel_id) 392static int comp_tx_completion(struct most_interface *iface, int channel_id)
397{ 393{
398 struct aim_channel *c; 394 struct comp_channel *c;
399 395
400 if (!iface) { 396 if (!iface) {
401 pr_info("Bad interface pointer\n"); 397 pr_info("Bad interface pointer\n");
@@ -414,35 +410,33 @@ static int aim_tx_completion(struct most_interface *iface, int channel_id)
414} 410}
415 411
416/** 412/**
417 * aim_probe - probe function of the driver module 413 * comp_probe - probe function of the driver module
418 * @iface: pointer to interface instance 414 * @iface: pointer to interface instance
419 * @channel_id: channel index/ID 415 * @channel_id: channel index/ID
420 * @cfg: pointer to actual channel configuration 416 * @cfg: pointer to actual channel configuration
421 * @parent: pointer to kobject (needed for sysfs hook-up)
422 * @name: name of the device to be created 417 * @name: name of the device to be created
423 * 418 *
424 * This allocates achannel object and creates the device node in /dev 419 * This allocates achannel object and creates the device node in /dev
425 * 420 *
426 * Returns 0 on success or error code otherwise. 421 * Returns 0 on success or error code otherwise.
427 */ 422 */
428static int aim_probe(struct most_interface *iface, int channel_id, 423static int comp_probe(struct most_interface *iface, int channel_id,
429 struct most_channel_config *cfg, 424 struct most_channel_config *cfg, char *name)
430 struct kobject *parent, char *name)
431{ 425{
432 struct aim_channel *c; 426 struct comp_channel *c;
433 unsigned long cl_flags; 427 unsigned long cl_flags;
434 int retval; 428 int retval;
435 int current_minor; 429 int current_minor;
436 430
437 if ((!iface) || (!cfg) || (!parent) || (!name)) { 431 if ((!iface) || (!cfg) || (!name)) {
438 pr_info("Probing AIM with bad arguments"); 432 pr_info("Probing component with bad arguments");
439 return -EINVAL; 433 return -EINVAL;
440 } 434 }
441 c = get_channel(iface, channel_id); 435 c = get_channel(iface, channel_id);
442 if (c) 436 if (c)
443 return -EEXIST; 437 return -EEXIST;
444 438
445 current_minor = ida_simple_get(&minor_id, 0, 0, GFP_KERNEL); 439 current_minor = ida_simple_get(&comp.minor_id, 0, 0, GFP_KERNEL);
446 if (current_minor < 0) 440 if (current_minor < 0)
447 return current_minor; 441 return current_minor;
448 442
@@ -452,7 +446,7 @@ static int aim_probe(struct most_interface *iface, int channel_id,
452 goto error_alloc_channel; 446 goto error_alloc_channel;
453 } 447 }
454 448
455 c->devno = MKDEV(major, current_minor); 449 c->devno = MKDEV(comp.major, current_minor);
456 cdev_init(&c->cdev, &channel_fops); 450 cdev_init(&c->cdev, &channel_fops);
457 c->cdev.owner = THIS_MODULE; 451 c->cdev.owner = THIS_MODULE;
458 cdev_add(&c->cdev, c->devno, 1); 452 cdev_add(&c->cdev, c->devno, 1);
@@ -472,11 +466,7 @@ static int aim_probe(struct most_interface *iface, int channel_id,
472 spin_lock_irqsave(&ch_list_lock, cl_flags); 466 spin_lock_irqsave(&ch_list_lock, cl_flags);
473 list_add_tail(&c->list, &channel_list); 467 list_add_tail(&c->list, &channel_list);
474 spin_unlock_irqrestore(&ch_list_lock, cl_flags); 468 spin_unlock_irqrestore(&ch_list_lock, cl_flags);
475 c->dev = device_create(aim_class, 469 c->dev = device_create(comp.class, NULL, c->devno, NULL, "%s", name);
476 NULL,
477 c->devno,
478 NULL,
479 "%s", name);
480 470
481 if (IS_ERR(c->dev)) { 471 if (IS_ERR(c->dev)) {
482 retval = PTR_ERR(c->dev); 472 retval = PTR_ERR(c->dev);
@@ -493,16 +483,18 @@ error_alloc_kfifo:
493 cdev_del(&c->cdev); 483 cdev_del(&c->cdev);
494 kfree(c); 484 kfree(c);
495error_alloc_channel: 485error_alloc_channel:
496 ida_simple_remove(&minor_id, current_minor); 486 ida_simple_remove(&comp.minor_id, current_minor);
497 return retval; 487 return retval;
498} 488}
499 489
500static struct most_aim cdev_aim = { 490static struct cdev_component comp = {
501 .name = "cdev", 491 .cc = {
502 .probe_channel = aim_probe, 492 .name = "cdev",
503 .disconnect_channel = aim_disconnect_channel, 493 .probe_channel = comp_probe,
504 .rx_completion = aim_rx_completion, 494 .disconnect_channel = comp_disconnect_channel,
505 .tx_completion = aim_tx_completion, 495 .rx_completion = comp_rx_completion,
496 .tx_completion = comp_tx_completion,
497 },
506}; 498};
507 499
508static int __init mod_init(void) 500static int __init mod_init(void)
@@ -511,54 +503,52 @@ static int __init mod_init(void)
511 503
512 pr_info("init()\n"); 504 pr_info("init()\n");
513 505
506 comp.class = class_create(THIS_MODULE, "most_cdev");
507 if (IS_ERR(comp.class)) {
508 pr_info("No udev support.\n");
509 return PTR_ERR(comp.class);
510 }
511
514 INIT_LIST_HEAD(&channel_list); 512 INIT_LIST_HEAD(&channel_list);
515 spin_lock_init(&ch_list_lock); 513 spin_lock_init(&ch_list_lock);
516 ida_init(&minor_id); 514 ida_init(&comp.minor_id);
517 515
518 err = alloc_chrdev_region(&aim_devno, 0, 50, "cdev"); 516 err = alloc_chrdev_region(&comp.devno, 0, 50, "cdev");
519 if (err < 0) 517 if (err < 0)
520 goto dest_ida; 518 goto dest_ida;
521 major = MAJOR(aim_devno); 519 comp.major = MAJOR(comp.devno);
522 520 err = most_register_component(&comp.cc);
523 aim_class = class_create(THIS_MODULE, "most_cdev_aim");
524 if (IS_ERR(aim_class)) {
525 pr_err("no udev support\n");
526 err = PTR_ERR(aim_class);
527 goto free_cdev;
528 }
529 err = most_register_aim(&cdev_aim);
530 if (err) 521 if (err)
531 goto dest_class; 522 goto free_cdev;
532 return 0; 523 return 0;
533 524
534dest_class:
535 class_destroy(aim_class);
536free_cdev: 525free_cdev:
537 unregister_chrdev_region(aim_devno, 1); 526 unregister_chrdev_region(comp.devno, 1);
538dest_ida: 527dest_ida:
539 ida_destroy(&minor_id); 528 ida_destroy(&comp.minor_id);
529 class_destroy(comp.class);
540 return err; 530 return err;
541} 531}
542 532
543static void __exit mod_exit(void) 533static void __exit mod_exit(void)
544{ 534{
545 struct aim_channel *c, *tmp; 535 struct comp_channel *c, *tmp;
546 536
547 pr_info("exit module\n"); 537 pr_info("exit module\n");
548 538
549 most_deregister_aim(&cdev_aim); 539 most_deregister_component(&comp.cc);
550 540
551 list_for_each_entry_safe(c, tmp, &channel_list, list) { 541 list_for_each_entry_safe(c, tmp, &channel_list, list) {
552 destroy_cdev(c); 542 destroy_cdev(c);
553 destroy_channel(c); 543 destroy_channel(c);
554 } 544 }
555 class_destroy(aim_class); 545 unregister_chrdev_region(comp.devno, 1);
556 unregister_chrdev_region(aim_devno, 1); 546 ida_destroy(&comp.minor_id);
557 ida_destroy(&minor_id); 547 class_destroy(comp.class);
558} 548}
559 549
560module_init(mod_init); 550module_init(mod_init);
561module_exit(mod_exit); 551module_exit(mod_exit);
562MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>"); 552MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>");
563MODULE_LICENSE("GPL"); 553MODULE_LICENSE("GPL");
564MODULE_DESCRIPTION("character device AIM for mostcore"); 554MODULE_DESCRIPTION("character device component for mostcore");
diff --git a/drivers/staging/most/core.c b/drivers/staging/most/core.c
new file mode 100644
index 000000000000..3dda8d81bf0b
--- /dev/null
+++ b/drivers/staging/most/core.c
@@ -0,0 +1,1603 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * core.c - Implementation of core module of MOST Linux driver stack
4 *
5 * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG
6 */
7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9#include <linux/module.h>
10#include <linux/fs.h>
11#include <linux/slab.h>
12#include <linux/init.h>
13#include <linux/device.h>
14#include <linux/list.h>
15#include <linux/poll.h>
16#include <linux/wait.h>
17#include <linux/kobject.h>
18#include <linux/mutex.h>
19#include <linux/completion.h>
20#include <linux/sysfs.h>
21#include <linux/kthread.h>
22#include <linux/dma-mapping.h>
23#include <linux/idr.h>
24#include <most/core.h>
25
26#define MAX_CHANNELS 64
27#define STRING_SIZE 80
28
29static struct ida mdev_id;
30static int dummy_num_buffers;
31
32static struct mostcore {
33 struct device dev;
34 struct device_driver drv;
35 struct bus_type bus;
36 struct list_head comp_list;
37} mc;
38
39#define to_driver(d) container_of(d, struct mostcore, drv)
40
41struct pipe {
42 struct core_component *comp;
43 int refs;
44 int num_buffers;
45};
46
47struct most_channel {
48 struct device dev;
49 struct completion cleanup;
50 atomic_t mbo_ref;
51 atomic_t mbo_nq_level;
52 u16 channel_id;
53 char name[STRING_SIZE];
54 bool is_poisoned;
55 struct mutex start_mutex;
56 struct mutex nq_mutex; /* nq thread synchronization */
57 int is_starving;
58 struct most_interface *iface;
59 struct most_channel_config cfg;
60 bool keep_mbo;
61 bool enqueue_halt;
62 struct list_head fifo;
63 spinlock_t fifo_lock;
64 struct list_head halt_fifo;
65 struct list_head list;
66 struct pipe pipe0;
67 struct pipe pipe1;
68 struct list_head trash_fifo;
69 struct task_struct *hdm_enqueue_task;
70 wait_queue_head_t hdm_fifo_wq;
71
72};
73
74#define to_channel(d) container_of(d, struct most_channel, dev)
75
76struct interface_private {
77 int dev_id;
78 char name[STRING_SIZE];
79 struct most_channel *channel[MAX_CHANNELS];
80 struct list_head channel_list;
81};
82
83static const struct {
84 int most_ch_data_type;
85 const char *name;
86} ch_data_type[] = {
87 { MOST_CH_CONTROL, "control\n" },
88 { MOST_CH_ASYNC, "async\n" },
89 { MOST_CH_SYNC, "sync\n" },
90 { MOST_CH_ISOC, "isoc\n"},
91 { MOST_CH_ISOC, "isoc_avp\n"},
92};
93
94/**
95 * list_pop_mbo - retrieves the first MBO of the list and removes it
96 * @ptr: the list head to grab the MBO from.
97 */
98#define list_pop_mbo(ptr) \
99({ \
100 struct mbo *_mbo = list_first_entry(ptr, struct mbo, list); \
101 list_del(&_mbo->list); \
102 _mbo; \
103})
104
105/**
106 * most_free_mbo_coherent - free an MBO and its coherent buffer
107 * @mbo: most buffer
108 */
109static void most_free_mbo_coherent(struct mbo *mbo)
110{
111 struct most_channel *c = mbo->context;
112 u16 const coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len;
113
114 dma_free_coherent(NULL, coherent_buf_size, mbo->virt_address,
115 mbo->bus_address);
116 kfree(mbo);
117 if (atomic_sub_and_test(1, &c->mbo_ref))
118 complete(&c->cleanup);
119}
120
121/**
122 * flush_channel_fifos - clear the channel fifos
123 * @c: pointer to channel object
124 */
125static void flush_channel_fifos(struct most_channel *c)
126{
127 unsigned long flags, hf_flags;
128 struct mbo *mbo, *tmp;
129
130 if (list_empty(&c->fifo) && list_empty(&c->halt_fifo))
131 return;
132
133 spin_lock_irqsave(&c->fifo_lock, flags);
134 list_for_each_entry_safe(mbo, tmp, &c->fifo, list) {
135 list_del(&mbo->list);
136 spin_unlock_irqrestore(&c->fifo_lock, flags);
137 most_free_mbo_coherent(mbo);
138 spin_lock_irqsave(&c->fifo_lock, flags);
139 }
140 spin_unlock_irqrestore(&c->fifo_lock, flags);
141
142 spin_lock_irqsave(&c->fifo_lock, hf_flags);
143 list_for_each_entry_safe(mbo, tmp, &c->halt_fifo, list) {
144 list_del(&mbo->list);
145 spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
146 most_free_mbo_coherent(mbo);
147 spin_lock_irqsave(&c->fifo_lock, hf_flags);
148 }
149 spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
150
151 if (unlikely((!list_empty(&c->fifo) || !list_empty(&c->halt_fifo))))
152 pr_info("WARN: fifo | trash fifo not empty\n");
153}
154
155/**
156 * flush_trash_fifo - clear the trash fifo
157 * @c: pointer to channel object
158 */
159static int flush_trash_fifo(struct most_channel *c)
160{
161 struct mbo *mbo, *tmp;
162 unsigned long flags;
163
164 spin_lock_irqsave(&c->fifo_lock, flags);
165 list_for_each_entry_safe(mbo, tmp, &c->trash_fifo, list) {
166 list_del(&mbo->list);
167 spin_unlock_irqrestore(&c->fifo_lock, flags);
168 most_free_mbo_coherent(mbo);
169 spin_lock_irqsave(&c->fifo_lock, flags);
170 }
171 spin_unlock_irqrestore(&c->fifo_lock, flags);
172 return 0;
173}
174
175static ssize_t available_directions_show(struct device *dev,
176 struct device_attribute *attr,
177 char *buf)
178{
179 struct most_channel *c = to_channel(dev);
180 unsigned int i = c->channel_id;
181
182 strcpy(buf, "");
183 if (c->iface->channel_vector[i].direction & MOST_CH_RX)
184 strcat(buf, "rx ");
185 if (c->iface->channel_vector[i].direction & MOST_CH_TX)
186 strcat(buf, "tx ");
187 strcat(buf, "\n");
188 return strlen(buf);
189}
190
191static ssize_t available_datatypes_show(struct device *dev,
192 struct device_attribute *attr,
193 char *buf)
194{
195 struct most_channel *c = to_channel(dev);
196 unsigned int i = c->channel_id;
197
198 strcpy(buf, "");
199 if (c->iface->channel_vector[i].data_type & MOST_CH_CONTROL)
200 strcat(buf, "control ");
201 if (c->iface->channel_vector[i].data_type & MOST_CH_ASYNC)
202 strcat(buf, "async ");
203 if (c->iface->channel_vector[i].data_type & MOST_CH_SYNC)
204 strcat(buf, "sync ");
205 if (c->iface->channel_vector[i].data_type & MOST_CH_ISOC)
206 strcat(buf, "isoc ");
207 strcat(buf, "\n");
208 return strlen(buf);
209}
210
211static ssize_t number_of_packet_buffers_show(struct device *dev,
212 struct device_attribute *attr,
213 char *buf)
214{
215 struct most_channel *c = to_channel(dev);
216 unsigned int i = c->channel_id;
217
218 return snprintf(buf, PAGE_SIZE, "%d\n",
219 c->iface->channel_vector[i].num_buffers_packet);
220}
221
222static ssize_t number_of_stream_buffers_show(struct device *dev,
223 struct device_attribute *attr,
224 char *buf)
225{
226 struct most_channel *c = to_channel(dev);
227 unsigned int i = c->channel_id;
228
229 return snprintf(buf, PAGE_SIZE, "%d\n",
230 c->iface->channel_vector[i].num_buffers_streaming);
231}
232
233static ssize_t size_of_packet_buffer_show(struct device *dev,
234 struct device_attribute *attr,
235 char *buf)
236{
237 struct most_channel *c = to_channel(dev);
238 unsigned int i = c->channel_id;
239
240 return snprintf(buf, PAGE_SIZE, "%d\n",
241 c->iface->channel_vector[i].buffer_size_packet);
242}
243
244static ssize_t size_of_stream_buffer_show(struct device *dev,
245 struct device_attribute *attr,
246 char *buf)
247{
248 struct most_channel *c = to_channel(dev);
249 unsigned int i = c->channel_id;
250
251 return snprintf(buf, PAGE_SIZE, "%d\n",
252 c->iface->channel_vector[i].buffer_size_streaming);
253}
254
255static ssize_t channel_starving_show(struct device *dev,
256 struct device_attribute *attr,
257 char *buf)
258{
259 struct most_channel *c = to_channel(dev);
260
261 return snprintf(buf, PAGE_SIZE, "%d\n", c->is_starving);
262}
263
264static ssize_t set_number_of_buffers_show(struct device *dev,
265 struct device_attribute *attr,
266 char *buf)
267{
268 struct most_channel *c = to_channel(dev);
269
270 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.num_buffers);
271}
272
273static ssize_t set_number_of_buffers_store(struct device *dev,
274 struct device_attribute *attr,
275 const char *buf,
276 size_t count)
277{
278 struct most_channel *c = to_channel(dev);
279 int ret = kstrtou16(buf, 0, &c->cfg.num_buffers);
280
281 if (ret)
282 return ret;
283 return count;
284}
285
286static ssize_t set_buffer_size_show(struct device *dev,
287 struct device_attribute *attr,
288 char *buf)
289{
290 struct most_channel *c = to_channel(dev);
291
292 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.buffer_size);
293}
294
295static ssize_t set_buffer_size_store(struct device *dev,
296 struct device_attribute *attr,
297 const char *buf,
298 size_t count)
299{
300 struct most_channel *c = to_channel(dev);
301 int ret = kstrtou16(buf, 0, &c->cfg.buffer_size);
302
303 if (ret)
304 return ret;
305 return count;
306}
307
308static ssize_t set_direction_show(struct device *dev,
309 struct device_attribute *attr,
310 char *buf)
311{
312 struct most_channel *c = to_channel(dev);
313
314 if (c->cfg.direction & MOST_CH_TX)
315 return snprintf(buf, PAGE_SIZE, "tx\n");
316 else if (c->cfg.direction & MOST_CH_RX)
317 return snprintf(buf, PAGE_SIZE, "rx\n");
318 return snprintf(buf, PAGE_SIZE, "unconfigured\n");
319}
320
321static ssize_t set_direction_store(struct device *dev,
322 struct device_attribute *attr,
323 const char *buf,
324 size_t count)
325{
326 struct most_channel *c = to_channel(dev);
327
328 if (!strcmp(buf, "dir_rx\n")) {
329 c->cfg.direction = MOST_CH_RX;
330 } else if (!strcmp(buf, "rx\n")) {
331 c->cfg.direction = MOST_CH_RX;
332 } else if (!strcmp(buf, "dir_tx\n")) {
333 c->cfg.direction = MOST_CH_TX;
334 } else if (!strcmp(buf, "tx\n")) {
335 c->cfg.direction = MOST_CH_TX;
336 } else {
337 pr_info("WARN: invalid attribute settings\n");
338 return -EINVAL;
339 }
340 return count;
341}
342
343static ssize_t set_datatype_show(struct device *dev,
344 struct device_attribute *attr,
345 char *buf)
346{
347 int i;
348 struct most_channel *c = to_channel(dev);
349
350 for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
351 if (c->cfg.data_type & ch_data_type[i].most_ch_data_type)
352 return snprintf(buf, PAGE_SIZE, ch_data_type[i].name);
353 }
354 return snprintf(buf, PAGE_SIZE, "unconfigured\n");
355}
356
357static ssize_t set_datatype_store(struct device *dev,
358 struct device_attribute *attr,
359 const char *buf,
360 size_t count)
361{
362 int i;
363 struct most_channel *c = to_channel(dev);
364
365 for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
366 if (!strcmp(buf, ch_data_type[i].name)) {
367 c->cfg.data_type = ch_data_type[i].most_ch_data_type;
368 break;
369 }
370 }
371
372 if (i == ARRAY_SIZE(ch_data_type)) {
373 pr_info("WARN: invalid attribute settings\n");
374 return -EINVAL;
375 }
376 return count;
377}
378
379static ssize_t set_subbuffer_size_show(struct device *dev,
380 struct device_attribute *attr,
381 char *buf)
382{
383 struct most_channel *c = to_channel(dev);
384
385 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.subbuffer_size);
386}
387
388static ssize_t set_subbuffer_size_store(struct device *dev,
389 struct device_attribute *attr,
390 const char *buf,
391 size_t count)
392{
393 struct most_channel *c = to_channel(dev);
394 int ret = kstrtou16(buf, 0, &c->cfg.subbuffer_size);
395
396 if (ret)
397 return ret;
398 return count;
399}
400
401static ssize_t set_packets_per_xact_show(struct device *dev,
402 struct device_attribute *attr,
403 char *buf)
404{
405 struct most_channel *c = to_channel(dev);
406
407 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.packets_per_xact);
408}
409
410static ssize_t set_packets_per_xact_store(struct device *dev,
411 struct device_attribute *attr,
412 const char *buf,
413 size_t count)
414{
415 struct most_channel *c = to_channel(dev);
416 int ret = kstrtou16(buf, 0, &c->cfg.packets_per_xact);
417
418 if (ret)
419 return ret;
420 return count;
421}
422
423#define DEV_ATTR(_name) (&dev_attr_##_name.attr)
424
425static DEVICE_ATTR_RO(available_directions);
426static DEVICE_ATTR_RO(available_datatypes);
427static DEVICE_ATTR_RO(number_of_packet_buffers);
428static DEVICE_ATTR_RO(number_of_stream_buffers);
429static DEVICE_ATTR_RO(size_of_stream_buffer);
430static DEVICE_ATTR_RO(size_of_packet_buffer);
431static DEVICE_ATTR_RO(channel_starving);
432static DEVICE_ATTR_RW(set_buffer_size);
433static DEVICE_ATTR_RW(set_number_of_buffers);
434static DEVICE_ATTR_RW(set_direction);
435static DEVICE_ATTR_RW(set_datatype);
436static DEVICE_ATTR_RW(set_subbuffer_size);
437static DEVICE_ATTR_RW(set_packets_per_xact);
438
439static struct attribute *channel_attrs[] = {
440 DEV_ATTR(available_directions),
441 DEV_ATTR(available_datatypes),
442 DEV_ATTR(number_of_packet_buffers),
443 DEV_ATTR(number_of_stream_buffers),
444 DEV_ATTR(size_of_stream_buffer),
445 DEV_ATTR(size_of_packet_buffer),
446 DEV_ATTR(channel_starving),
447 DEV_ATTR(set_buffer_size),
448 DEV_ATTR(set_number_of_buffers),
449 DEV_ATTR(set_direction),
450 DEV_ATTR(set_datatype),
451 DEV_ATTR(set_subbuffer_size),
452 DEV_ATTR(set_packets_per_xact),
453 NULL,
454};
455
456static struct attribute_group channel_attr_group = {
457 .attrs = channel_attrs,
458};
459
460static const struct attribute_group *channel_attr_groups[] = {
461 &channel_attr_group,
462 NULL,
463};
464
465static ssize_t description_show(struct device *dev,
466 struct device_attribute *attr,
467 char *buf)
468{
469 struct most_interface *iface = to_most_interface(dev);
470
471 return snprintf(buf, PAGE_SIZE, "%s\n", iface->description);
472}
473
474static ssize_t interface_show(struct device *dev,
475 struct device_attribute *attr,
476 char *buf)
477{
478 struct most_interface *iface = to_most_interface(dev);
479
480 switch (iface->interface) {
481 case ITYPE_LOOPBACK:
482 return snprintf(buf, PAGE_SIZE, "loopback\n");
483 case ITYPE_I2C:
484 return snprintf(buf, PAGE_SIZE, "i2c\n");
485 case ITYPE_I2S:
486 return snprintf(buf, PAGE_SIZE, "i2s\n");
487 case ITYPE_TSI:
488 return snprintf(buf, PAGE_SIZE, "tsi\n");
489 case ITYPE_HBI:
490 return snprintf(buf, PAGE_SIZE, "hbi\n");
491 case ITYPE_MEDIALB_DIM:
492 return snprintf(buf, PAGE_SIZE, "mlb_dim\n");
493 case ITYPE_MEDIALB_DIM2:
494 return snprintf(buf, PAGE_SIZE, "mlb_dim2\n");
495 case ITYPE_USB:
496 return snprintf(buf, PAGE_SIZE, "usb\n");
497 case ITYPE_PCIE:
498 return snprintf(buf, PAGE_SIZE, "pcie\n");
499 }
500 return snprintf(buf, PAGE_SIZE, "unknown\n");
501}
502
503static DEVICE_ATTR_RO(description);
504static DEVICE_ATTR_RO(interface);
505
506static struct attribute *interface_attrs[] = {
507 DEV_ATTR(description),
508 DEV_ATTR(interface),
509 NULL,
510};
511
512static struct attribute_group interface_attr_group = {
513 .attrs = interface_attrs,
514};
515
516static const struct attribute_group *interface_attr_groups[] = {
517 &interface_attr_group,
518 NULL,
519};
520
521static struct core_component *match_component(char *name)
522{
523 struct core_component *comp;
524
525 list_for_each_entry(comp, &mc.comp_list, list) {
526 if (!strcmp(comp->name, name))
527 return comp;
528 }
529 return NULL;
530}
531
532struct show_links_data {
533 int offs;
534 char *buf;
535};
536
537static int print_links(struct device *dev, void *data)
538{
539 struct show_links_data *d = data;
540 int offs = d->offs;
541 char *buf = d->buf;
542 struct most_channel *c;
543 struct most_interface *iface = to_most_interface(dev);
544
545 list_for_each_entry(c, &iface->p->channel_list, list) {
546 if (c->pipe0.comp) {
547 offs += snprintf(buf + offs,
548 PAGE_SIZE - offs,
549 "%s:%s:%s\n",
550 c->pipe0.comp->name,
551 dev_name(&iface->dev),
552 dev_name(&c->dev));
553 }
554 if (c->pipe1.comp) {
555 offs += snprintf(buf + offs,
556 PAGE_SIZE - offs,
557 "%s:%s:%s\n",
558 c->pipe1.comp->name,
559 dev_name(&iface->dev),
560 dev_name(&c->dev));
561 }
562 }
563 d->offs = offs;
564 return 0;
565}
566
567static ssize_t links_show(struct device_driver *drv, char *buf)
568{
569 struct show_links_data d = { .buf = buf };
570
571 bus_for_each_dev(&mc.bus, NULL, &d, print_links);
572 return d.offs;
573}
574
575static ssize_t components_show(struct device_driver *drv, char *buf)
576{
577 struct core_component *comp;
578 int offs = 0;
579
580 list_for_each_entry(comp, &mc.comp_list, list) {
581 offs += snprintf(buf + offs, PAGE_SIZE - offs, "%s\n",
582 comp->name);
583 }
584 return offs;
585}
586/**
587 * split_string - parses buf and extracts ':' separated substrings.
588 *
589 * @buf: complete string from attribute 'add_channel'
590 * @a: storage for 1st substring (=interface name)
591 * @b: storage for 2nd substring (=channel name)
592 * @c: storage for 3rd substring (=component name)
593 * @d: storage optional 4th substring (=user defined name)
594 *
595 * Examples:
596 *
597 * Input: "mdev0:ch6:cdev:my_channel\n" or
598 * "mdev0:ch6:cdev:my_channel"
599 *
600 * Output: *a -> "mdev0", *b -> "ch6", *c -> "cdev" *d -> "my_channel"
601 *
602 * Input: "mdev1:ep81:cdev\n"
603 * Output: *a -> "mdev1", *b -> "ep81", *c -> "cdev" *d -> ""
604 *
605 * Input: "mdev1:ep81"
606 * Output: *a -> "mdev1", *b -> "ep81", *c -> "cdev" *d == NULL
607 */
608static int split_string(char *buf, char **a, char **b, char **c, char **d)
609{
610 *a = strsep(&buf, ":");
611 if (!*a)
612 return -EIO;
613
614 *b = strsep(&buf, ":\n");
615 if (!*b)
616 return -EIO;
617
618 *c = strsep(&buf, ":\n");
619 if (!*c)
620 return -EIO;
621
622 if (d)
623 *d = strsep(&buf, ":\n");
624
625 return 0;
626}
627
628static int match_bus_dev(struct device *dev, void *data)
629{
630 char *mdev_name = data;
631
632 return !strcmp(dev_name(dev), mdev_name);
633}
634
635/**
636 * get_channel - get pointer to channel
637 * @mdev: name of the device interface
638 * @mdev_ch: name of channel
639 */
640static struct most_channel *get_channel(char *mdev, char *mdev_ch)
641{
642 struct device *dev = NULL;
643 struct most_interface *iface;
644 struct most_channel *c, *tmp;
645
646 dev = bus_find_device(&mc.bus, NULL, mdev, match_bus_dev);
647 if (!dev)
648 return NULL;
649 iface = to_most_interface(dev);
650 list_for_each_entry_safe(c, tmp, &iface->p->channel_list, list) {
651 if (!strcmp(dev_name(&c->dev), mdev_ch))
652 return c;
653 }
654 return NULL;
655}
656
657static
658inline int link_channel_to_component(struct most_channel *c,
659 struct core_component *comp,
660 char *comp_param)
661{
662 int ret;
663 struct core_component **comp_ptr;
664
665 if (!c->pipe0.comp)
666 comp_ptr = &c->pipe0.comp;
667 else if (!c->pipe1.comp)
668 comp_ptr = &c->pipe1.comp;
669 else
670 return -ENOSPC;
671
672 *comp_ptr = comp;
673 ret = comp->probe_channel(c->iface, c->channel_id, &c->cfg, comp_param);
674 if (ret) {
675 *comp_ptr = NULL;
676 return ret;
677 }
678 return 0;
679}
680
681/**
682 * add_link_store - store function for add_link attribute
683 * @drv: device driver
684 * @buf: buffer
685 * @len: buffer length
686 *
687 * This parses the string given by buf and splits it into
688 * four substrings. Note: last substring is optional. In case a cdev
689 * component is loaded the optional 4th substring will make up the name of
690 * device node in the /dev directory. If omitted, the device node will
691 * inherit the channel's name within sysfs.
692 *
693 * Searches for (device, channel) pair and probes the component
694 *
695 * Example:
696 * (1) echo "mdev0:ch6:cdev:my_rxchannel" >add_link
697 * (2) echo "mdev1:ep81:cdev" >add_link
698 *
699 * (1) would create the device node /dev/my_rxchannel
700 * (2) would create the device node /dev/mdev1-ep81
701 */
702static ssize_t add_link_store(struct device_driver *drv,
703 const char *buf,
704 size_t len)
705{
706 struct most_channel *c;
707 struct core_component *comp;
708 char buffer[STRING_SIZE];
709 char *mdev;
710 char *mdev_ch;
711 char *comp_name;
712 char *comp_param;
713 char devnod_buf[STRING_SIZE];
714 int ret;
715 size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
716
717 strlcpy(buffer, buf, max_len);
718 ret = split_string(buffer, &mdev, &mdev_ch, &comp_name, &comp_param);
719 if (ret)
720 return ret;
721 comp = match_component(comp_name);
722 if (!comp)
723 return -ENODEV;
724 if (!comp_param || *comp_param == 0) {
725 snprintf(devnod_buf, sizeof(devnod_buf), "%s-%s", mdev,
726 mdev_ch);
727 comp_param = devnod_buf;
728 }
729
730 c = get_channel(mdev, mdev_ch);
731 if (!c)
732 return -ENODEV;
733
734 ret = link_channel_to_component(c, comp, comp_param);
735 if (ret)
736 return ret;
737 return len;
738}
739
740/**
741 * remove_link_store - store function for remove_link attribute
742 * @drv: device driver
743 * @buf: buffer
744 * @len: buffer length
745 *
746 * Example:
747 * echo "mdev0:ep81" >remove_link
748 */
749static ssize_t remove_link_store(struct device_driver *drv,
750 const char *buf,
751 size_t len)
752{
753 struct most_channel *c;
754 struct core_component *comp;
755 char buffer[STRING_SIZE];
756 char *mdev;
757 char *mdev_ch;
758 char *comp_name;
759 int ret;
760 size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
761
762 strlcpy(buffer, buf, max_len);
763 ret = split_string(buffer, &mdev, &mdev_ch, &comp_name, NULL);
764 if (ret)
765 return ret;
766 comp = match_component(comp_name);
767 if (!comp)
768 return -ENODEV;
769 c = get_channel(mdev, mdev_ch);
770 if (!c)
771 return -ENODEV;
772
773 if (comp->disconnect_channel(c->iface, c->channel_id))
774 return -EIO;
775 if (c->pipe0.comp == comp)
776 c->pipe0.comp = NULL;
777 if (c->pipe1.comp == comp)
778 c->pipe1.comp = NULL;
779 return len;
780}
781
782#define DRV_ATTR(_name) (&driver_attr_##_name.attr)
783
784static DRIVER_ATTR_RO(links);
785static DRIVER_ATTR_RO(components);
786static DRIVER_ATTR_WO(add_link);
787static DRIVER_ATTR_WO(remove_link);
788
789static struct attribute *mc_attrs[] = {
790 DRV_ATTR(links),
791 DRV_ATTR(components),
792 DRV_ATTR(add_link),
793 DRV_ATTR(remove_link),
794 NULL,
795};
796
797static struct attribute_group mc_attr_group = {
798 .attrs = mc_attrs,
799};
800
801static const struct attribute_group *mc_attr_groups[] = {
802 &mc_attr_group,
803 NULL,
804};
805
806static int most_match(struct device *dev, struct device_driver *drv)
807{
808 if (!strcmp(dev_name(dev), "most"))
809 return 0;
810 else
811 return 1;
812}
813
814static inline void trash_mbo(struct mbo *mbo)
815{
816 unsigned long flags;
817 struct most_channel *c = mbo->context;
818
819 spin_lock_irqsave(&c->fifo_lock, flags);
820 list_add(&mbo->list, &c->trash_fifo);
821 spin_unlock_irqrestore(&c->fifo_lock, flags);
822}
823
824static bool hdm_mbo_ready(struct most_channel *c)
825{
826 bool empty;
827
828 if (c->enqueue_halt)
829 return false;
830
831 spin_lock_irq(&c->fifo_lock);
832 empty = list_empty(&c->halt_fifo);
833 spin_unlock_irq(&c->fifo_lock);
834
835 return !empty;
836}
837
838static void nq_hdm_mbo(struct mbo *mbo)
839{
840 unsigned long flags;
841 struct most_channel *c = mbo->context;
842
843 spin_lock_irqsave(&c->fifo_lock, flags);
844 list_add_tail(&mbo->list, &c->halt_fifo);
845 spin_unlock_irqrestore(&c->fifo_lock, flags);
846 wake_up_interruptible(&c->hdm_fifo_wq);
847}
848
849static int hdm_enqueue_thread(void *data)
850{
851 struct most_channel *c = data;
852 struct mbo *mbo;
853 int ret;
854 typeof(c->iface->enqueue) enqueue = c->iface->enqueue;
855
856 while (likely(!kthread_should_stop())) {
857 wait_event_interruptible(c->hdm_fifo_wq,
858 hdm_mbo_ready(c) ||
859 kthread_should_stop());
860
861 mutex_lock(&c->nq_mutex);
862 spin_lock_irq(&c->fifo_lock);
863 if (unlikely(c->enqueue_halt || list_empty(&c->halt_fifo))) {
864 spin_unlock_irq(&c->fifo_lock);
865 mutex_unlock(&c->nq_mutex);
866 continue;
867 }
868
869 mbo = list_pop_mbo(&c->halt_fifo);
870 spin_unlock_irq(&c->fifo_lock);
871
872 if (c->cfg.direction == MOST_CH_RX)
873 mbo->buffer_length = c->cfg.buffer_size;
874
875 ret = enqueue(mbo->ifp, mbo->hdm_channel_id, mbo);
876 mutex_unlock(&c->nq_mutex);
877
878 if (unlikely(ret)) {
879 pr_err("hdm enqueue failed\n");
880 nq_hdm_mbo(mbo);
881 c->hdm_enqueue_task = NULL;
882 return 0;
883 }
884 }
885
886 return 0;
887}
888
889static int run_enqueue_thread(struct most_channel *c, int channel_id)
890{
891 struct task_struct *task =
892 kthread_run(hdm_enqueue_thread, c, "hdm_fifo_%d",
893 channel_id);
894
895 if (IS_ERR(task))
896 return PTR_ERR(task);
897
898 c->hdm_enqueue_task = task;
899 return 0;
900}
901
902/**
903 * arm_mbo - recycle MBO for further usage
904 * @mbo: most buffer
905 *
906 * This puts an MBO back to the list to have it ready for up coming
907 * tx transactions.
908 *
909 * In case the MBO belongs to a channel that recently has been
910 * poisoned, the MBO is scheduled to be trashed.
911 * Calls the completion handler of an attached component.
912 */
913static void arm_mbo(struct mbo *mbo)
914{
915 unsigned long flags;
916 struct most_channel *c;
917
918 BUG_ON((!mbo) || (!mbo->context));
919 c = mbo->context;
920
921 if (c->is_poisoned) {
922 trash_mbo(mbo);
923 return;
924 }
925
926 spin_lock_irqsave(&c->fifo_lock, flags);
927 ++*mbo->num_buffers_ptr;
928 list_add_tail(&mbo->list, &c->fifo);
929 spin_unlock_irqrestore(&c->fifo_lock, flags);
930
931 if (c->pipe0.refs && c->pipe0.comp->tx_completion)
932 c->pipe0.comp->tx_completion(c->iface, c->channel_id);
933
934 if (c->pipe1.refs && c->pipe1.comp->tx_completion)
935 c->pipe1.comp->tx_completion(c->iface, c->channel_id);
936}
937
938/**
939 * arm_mbo_chain - helper function that arms an MBO chain for the HDM
940 * @c: pointer to interface channel
941 * @dir: direction of the channel
942 * @compl: pointer to completion function
943 *
944 * This allocates buffer objects including the containing DMA coherent
945 * buffer and puts them in the fifo.
946 * Buffers of Rx channels are put in the kthread fifo, hence immediately
947 * submitted to the HDM.
948 *
949 * Returns the number of allocated and enqueued MBOs.
950 */
951static int arm_mbo_chain(struct most_channel *c, int dir,
952 void (*compl)(struct mbo *))
953{
954 unsigned int i;
955 int retval;
956 struct mbo *mbo;
957 u32 coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len;
958
959 atomic_set(&c->mbo_nq_level, 0);
960
961 for (i = 0; i < c->cfg.num_buffers; i++) {
962 mbo = kzalloc(sizeof(*mbo), GFP_KERNEL);
963 if (!mbo) {
964 retval = i;
965 goto _exit;
966 }
967 mbo->context = c;
968 mbo->ifp = c->iface;
969 mbo->hdm_channel_id = c->channel_id;
970 mbo->virt_address = dma_alloc_coherent(NULL,
971 coherent_buf_size,
972 &mbo->bus_address,
973 GFP_KERNEL);
974 if (!mbo->virt_address) {
975 pr_info("WARN: No DMA coherent buffer.\n");
976 retval = i;
977 goto _error1;
978 }
979 mbo->complete = compl;
980 mbo->num_buffers_ptr = &dummy_num_buffers;
981 if (dir == MOST_CH_RX) {
982 nq_hdm_mbo(mbo);
983 atomic_inc(&c->mbo_nq_level);
984 } else {
985 arm_mbo(mbo);
986 }
987 }
988 return i;
989
990_error1:
991 kfree(mbo);
992_exit:
993 return retval;
994}
995
996/**
997 * most_submit_mbo - submits an MBO to fifo
998 * @mbo: most buffer
999 */
1000void most_submit_mbo(struct mbo *mbo)
1001{
1002 if (WARN_ONCE(!mbo || !mbo->context,
1003 "bad mbo or missing channel reference\n"))
1004 return;
1005
1006 nq_hdm_mbo(mbo);
1007}
1008EXPORT_SYMBOL_GPL(most_submit_mbo);
1009
1010/**
1011 * most_write_completion - write completion handler
1012 * @mbo: most buffer
1013 *
1014 * This recycles the MBO for further usage. In case the channel has been
1015 * poisoned, the MBO is scheduled to be trashed.
1016 */
1017static void most_write_completion(struct mbo *mbo)
1018{
1019 struct most_channel *c;
1020
1021 BUG_ON((!mbo) || (!mbo->context));
1022
1023 c = mbo->context;
1024 if (mbo->status == MBO_E_INVAL)
1025 pr_info("WARN: Tx MBO status: invalid\n");
1026 if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE)))
1027 trash_mbo(mbo);
1028 else
1029 arm_mbo(mbo);
1030}
1031
1032int channel_has_mbo(struct most_interface *iface, int id,
1033 struct core_component *comp)
1034{
1035 struct most_channel *c = iface->p->channel[id];
1036 unsigned long flags;
1037 int empty;
1038
1039 if (unlikely(!c))
1040 return -EINVAL;
1041
1042 if (c->pipe0.refs && c->pipe1.refs &&
1043 ((comp == c->pipe0.comp && c->pipe0.num_buffers <= 0) ||
1044 (comp == c->pipe1.comp && c->pipe1.num_buffers <= 0)))
1045 return 0;
1046
1047 spin_lock_irqsave(&c->fifo_lock, flags);
1048 empty = list_empty(&c->fifo);
1049 spin_unlock_irqrestore(&c->fifo_lock, flags);
1050 return !empty;
1051}
1052EXPORT_SYMBOL_GPL(channel_has_mbo);
1053
1054/**
1055 * most_get_mbo - get pointer to an MBO of pool
1056 * @iface: pointer to interface instance
1057 * @id: channel ID
1058 * @comp: driver component
1059 *
1060 * This attempts to get a free buffer out of the channel fifo.
1061 * Returns a pointer to MBO on success or NULL otherwise.
1062 */
1063struct mbo *most_get_mbo(struct most_interface *iface, int id,
1064 struct core_component *comp)
1065{
1066 struct mbo *mbo;
1067 struct most_channel *c;
1068 unsigned long flags;
1069 int *num_buffers_ptr;
1070
1071 c = iface->p->channel[id];
1072 if (unlikely(!c))
1073 return NULL;
1074
1075 if (c->pipe0.refs && c->pipe1.refs &&
1076 ((comp == c->pipe0.comp && c->pipe0.num_buffers <= 0) ||
1077 (comp == c->pipe1.comp && c->pipe1.num_buffers <= 0)))
1078 return NULL;
1079
1080 if (comp == c->pipe0.comp)
1081 num_buffers_ptr = &c->pipe0.num_buffers;
1082 else if (comp == c->pipe1.comp)
1083 num_buffers_ptr = &c->pipe1.num_buffers;
1084 else
1085 num_buffers_ptr = &dummy_num_buffers;
1086
1087 spin_lock_irqsave(&c->fifo_lock, flags);
1088 if (list_empty(&c->fifo)) {
1089 spin_unlock_irqrestore(&c->fifo_lock, flags);
1090 return NULL;
1091 }
1092 mbo = list_pop_mbo(&c->fifo);
1093 --*num_buffers_ptr;
1094 spin_unlock_irqrestore(&c->fifo_lock, flags);
1095
1096 mbo->num_buffers_ptr = num_buffers_ptr;
1097 mbo->buffer_length = c->cfg.buffer_size;
1098 return mbo;
1099}
1100EXPORT_SYMBOL_GPL(most_get_mbo);
1101
1102/**
1103 * most_put_mbo - return buffer to pool
1104 * @mbo: most buffer
1105 */
1106void most_put_mbo(struct mbo *mbo)
1107{
1108 struct most_channel *c = mbo->context;
1109
1110 if (c->cfg.direction == MOST_CH_TX) {
1111 arm_mbo(mbo);
1112 return;
1113 }
1114 nq_hdm_mbo(mbo);
1115 atomic_inc(&c->mbo_nq_level);
1116}
1117EXPORT_SYMBOL_GPL(most_put_mbo);
1118
1119/**
1120 * most_read_completion - read completion handler
1121 * @mbo: most buffer
1122 *
1123 * This function is called by the HDM when data has been received from the
1124 * hardware and copied to the buffer of the MBO.
1125 *
1126 * In case the channel has been poisoned it puts the buffer in the trash queue.
1127 * Otherwise, it passes the buffer to an component for further processing.
1128 */
1129static void most_read_completion(struct mbo *mbo)
1130{
1131 struct most_channel *c = mbo->context;
1132
1133 if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE))) {
1134 trash_mbo(mbo);
1135 return;
1136 }
1137
1138 if (mbo->status == MBO_E_INVAL) {
1139 nq_hdm_mbo(mbo);
1140 atomic_inc(&c->mbo_nq_level);
1141 return;
1142 }
1143
1144 if (atomic_sub_and_test(1, &c->mbo_nq_level))
1145 c->is_starving = 1;
1146
1147 if (c->pipe0.refs && c->pipe0.comp->rx_completion &&
1148 c->pipe0.comp->rx_completion(mbo) == 0)
1149 return;
1150
1151 if (c->pipe1.refs && c->pipe1.comp->rx_completion &&
1152 c->pipe1.comp->rx_completion(mbo) == 0)
1153 return;
1154
1155 most_put_mbo(mbo);
1156}
1157
1158/**
1159 * most_start_channel - prepares a channel for communication
1160 * @iface: pointer to interface instance
1161 * @id: channel ID
1162 * @comp: driver component
1163 *
1164 * This prepares the channel for usage. Cross-checks whether the
1165 * channel's been properly configured.
1166 *
1167 * Returns 0 on success or error code otherwise.
1168 */
1169int most_start_channel(struct most_interface *iface, int id,
1170 struct core_component *comp)
1171{
1172 int num_buffer;
1173 int ret;
1174 struct most_channel *c = iface->p->channel[id];
1175
1176 if (unlikely(!c))
1177 return -EINVAL;
1178
1179 mutex_lock(&c->start_mutex);
1180 if (c->pipe0.refs + c->pipe1.refs > 0)
1181 goto out; /* already started by another component */
1182
1183 if (!try_module_get(iface->mod)) {
1184 pr_info("failed to acquire HDM lock\n");
1185 mutex_unlock(&c->start_mutex);
1186 return -ENOLCK;
1187 }
1188
1189 c->cfg.extra_len = 0;
1190 if (c->iface->configure(c->iface, c->channel_id, &c->cfg)) {
1191 pr_info("channel configuration failed. Go check settings...\n");
1192 ret = -EINVAL;
1193 goto error;
1194 }
1195
1196 init_waitqueue_head(&c->hdm_fifo_wq);
1197
1198 if (c->cfg.direction == MOST_CH_RX)
1199 num_buffer = arm_mbo_chain(c, c->cfg.direction,
1200 most_read_completion);
1201 else
1202 num_buffer = arm_mbo_chain(c, c->cfg.direction,
1203 most_write_completion);
1204 if (unlikely(!num_buffer)) {
1205 pr_info("failed to allocate memory\n");
1206 ret = -ENOMEM;
1207 goto error;
1208 }
1209
1210 ret = run_enqueue_thread(c, id);
1211 if (ret)
1212 goto error;
1213
1214 c->is_starving = 0;
1215 c->pipe0.num_buffers = c->cfg.num_buffers / 2;
1216 c->pipe1.num_buffers = c->cfg.num_buffers - c->pipe0.num_buffers;
1217 atomic_set(&c->mbo_ref, num_buffer);
1218
1219out:
1220 if (comp == c->pipe0.comp)
1221 c->pipe0.refs++;
1222 if (comp == c->pipe1.comp)
1223 c->pipe1.refs++;
1224 mutex_unlock(&c->start_mutex);
1225 return 0;
1226
1227error:
1228 module_put(iface->mod);
1229 mutex_unlock(&c->start_mutex);
1230 return ret;
1231}
1232EXPORT_SYMBOL_GPL(most_start_channel);
1233
1234/**
1235 * most_stop_channel - stops a running channel
1236 * @iface: pointer to interface instance
1237 * @id: channel ID
1238 * @comp: driver component
1239 */
1240int most_stop_channel(struct most_interface *iface, int id,
1241 struct core_component *comp)
1242{
1243 struct most_channel *c;
1244
1245 if (unlikely((!iface) || (id >= iface->num_channels) || (id < 0))) {
1246 pr_err("Bad interface or index out of range\n");
1247 return -EINVAL;
1248 }
1249 c = iface->p->channel[id];
1250 if (unlikely(!c))
1251 return -EINVAL;
1252
1253 mutex_lock(&c->start_mutex);
1254 if (c->pipe0.refs + c->pipe1.refs >= 2)
1255 goto out;
1256
1257 if (c->hdm_enqueue_task)
1258 kthread_stop(c->hdm_enqueue_task);
1259 c->hdm_enqueue_task = NULL;
1260
1261 if (iface->mod)
1262 module_put(iface->mod);
1263
1264 c->is_poisoned = true;
1265 if (c->iface->poison_channel(c->iface, c->channel_id)) {
1266 pr_err("Cannot stop channel %d of mdev %s\n", c->channel_id,
1267 c->iface->description);
1268 mutex_unlock(&c->start_mutex);
1269 return -EAGAIN;
1270 }
1271 flush_trash_fifo(c);
1272 flush_channel_fifos(c);
1273
1274#ifdef CMPL_INTERRUPTIBLE
1275 if (wait_for_completion_interruptible(&c->cleanup)) {
1276 pr_info("Interrupted while clean up ch %d\n", c->channel_id);
1277 mutex_unlock(&c->start_mutex);
1278 return -EINTR;
1279 }
1280#else
1281 wait_for_completion(&c->cleanup);
1282#endif
1283 c->is_poisoned = false;
1284
1285out:
1286 if (comp == c->pipe0.comp)
1287 c->pipe0.refs--;
1288 if (comp == c->pipe1.comp)
1289 c->pipe1.refs--;
1290 mutex_unlock(&c->start_mutex);
1291 return 0;
1292}
1293EXPORT_SYMBOL_GPL(most_stop_channel);
1294
1295/**
1296 * most_register_component - registers a driver component with the core
1297 * @comp: driver component
1298 */
1299int most_register_component(struct core_component *comp)
1300{
1301 if (!comp) {
1302 pr_err("Bad component\n");
1303 return -EINVAL;
1304 }
1305 list_add_tail(&comp->list, &mc.comp_list);
1306 pr_info("registered new core component %s\n", comp->name);
1307 return 0;
1308}
1309EXPORT_SYMBOL_GPL(most_register_component);
1310
1311static int disconnect_channels(struct device *dev, void *data)
1312{
1313 struct most_interface *iface;
1314 struct most_channel *c, *tmp;
1315 struct core_component *comp = data;
1316
1317 iface = to_most_interface(dev);
1318 list_for_each_entry_safe(c, tmp, &iface->p->channel_list, list) {
1319 if (c->pipe0.comp == comp || c->pipe1.comp == comp)
1320 comp->disconnect_channel(c->iface, c->channel_id);
1321 if (c->pipe0.comp == comp)
1322 c->pipe0.comp = NULL;
1323 if (c->pipe1.comp == comp)
1324 c->pipe1.comp = NULL;
1325 }
1326 return 0;
1327}
1328
1329/**
1330 * most_deregister_component - deregisters a driver component with the core
1331 * @comp: driver component
1332 */
1333int most_deregister_component(struct core_component *comp)
1334{
1335 if (!comp) {
1336 pr_err("Bad component\n");
1337 return -EINVAL;
1338 }
1339
1340 bus_for_each_dev(&mc.bus, NULL, comp, disconnect_channels);
1341 list_del(&comp->list);
1342 pr_info("deregistering component %s\n", comp->name);
1343 return 0;
1344}
1345EXPORT_SYMBOL_GPL(most_deregister_component);
1346
1347static void release_interface(struct device *dev)
1348{
1349 pr_info("releasing interface dev %s...\n", dev_name(dev));
1350}
1351
1352static void release_channel(struct device *dev)
1353{
1354 pr_info("releasing channel dev %s...\n", dev_name(dev));
1355}
1356
1357/**
1358 * most_register_interface - registers an interface with core
1359 * @iface: device interface
1360 *
1361 * Allocates and initializes a new interface instance and all of its channels.
1362 * Returns a pointer to kobject or an error pointer.
1363 */
1364int most_register_interface(struct most_interface *iface)
1365{
1366 unsigned int i;
1367 int id;
1368 struct most_channel *c;
1369
1370 if (!iface || !iface->enqueue || !iface->configure ||
1371 !iface->poison_channel || (iface->num_channels > MAX_CHANNELS)) {
1372 pr_err("Bad interface or channel overflow\n");
1373 return -EINVAL;
1374 }
1375
1376 id = ida_simple_get(&mdev_id, 0, 0, GFP_KERNEL);
1377 if (id < 0) {
1378 pr_info("Failed to alloc mdev ID\n");
1379 return id;
1380 }
1381
1382 iface->p = kzalloc(sizeof(*iface->p), GFP_KERNEL);
1383 if (!iface->p) {
1384 pr_info("Failed to allocate interface instance\n");
1385 ida_simple_remove(&mdev_id, id);
1386 return -ENOMEM;
1387 }
1388
1389 INIT_LIST_HEAD(&iface->p->channel_list);
1390 iface->p->dev_id = id;
1391 snprintf(iface->p->name, STRING_SIZE, "mdev%d", id);
1392 iface->dev.init_name = iface->p->name;
1393 iface->dev.bus = &mc.bus;
1394 iface->dev.parent = &mc.dev;
1395 iface->dev.groups = interface_attr_groups;
1396 iface->dev.release = release_interface;
1397 if (device_register(&iface->dev)) {
1398 pr_err("registering iface->dev failed\n");
1399 kfree(iface->p);
1400 ida_simple_remove(&mdev_id, id);
1401 return -ENOMEM;
1402 }
1403
1404 for (i = 0; i < iface->num_channels; i++) {
1405 const char *name_suffix = iface->channel_vector[i].name_suffix;
1406
1407 c = kzalloc(sizeof(*c), GFP_KERNEL);
1408 if (!c)
1409 goto free_instance;
1410 if (!name_suffix)
1411 snprintf(c->name, STRING_SIZE, "ch%d", i);
1412 else
1413 snprintf(c->name, STRING_SIZE, "%s", name_suffix);
1414 c->dev.init_name = c->name;
1415 c->dev.parent = &iface->dev;
1416 c->dev.groups = channel_attr_groups;
1417 c->dev.release = release_channel;
1418 if (device_register(&c->dev)) {
1419 pr_err("registering c->dev failed\n");
1420 goto free_instance_nodev;
1421 }
1422 iface->p->channel[i] = c;
1423 c->is_starving = 0;
1424 c->iface = iface;
1425 c->channel_id = i;
1426 c->keep_mbo = false;
1427 c->enqueue_halt = false;
1428 c->is_poisoned = false;
1429 c->cfg.direction = 0;
1430 c->cfg.data_type = 0;
1431 c->cfg.num_buffers = 0;
1432 c->cfg.buffer_size = 0;
1433 c->cfg.subbuffer_size = 0;
1434 c->cfg.packets_per_xact = 0;
1435 spin_lock_init(&c->fifo_lock);
1436 INIT_LIST_HEAD(&c->fifo);
1437 INIT_LIST_HEAD(&c->trash_fifo);
1438 INIT_LIST_HEAD(&c->halt_fifo);
1439 init_completion(&c->cleanup);
1440 atomic_set(&c->mbo_ref, 0);
1441 mutex_init(&c->start_mutex);
1442 mutex_init(&c->nq_mutex);
1443 list_add_tail(&c->list, &iface->p->channel_list);
1444 }
1445 pr_info("registered new device mdev%d (%s)\n",
1446 id, iface->description);
1447 return 0;
1448
1449free_instance_nodev:
1450 kfree(c);
1451
1452free_instance:
1453 while (i > 0) {
1454 c = iface->p->channel[--i];
1455 device_unregister(&c->dev);
1456 kfree(c);
1457 }
1458 kfree(iface->p);
1459 device_unregister(&iface->dev);
1460 ida_simple_remove(&mdev_id, id);
1461 return -ENOMEM;
1462}
1463EXPORT_SYMBOL_GPL(most_register_interface);
1464
1465/**
1466 * most_deregister_interface - deregisters an interface with core
1467 * @iface: device interface
1468 *
1469 * Before removing an interface instance from the list, all running
1470 * channels are stopped and poisoned.
1471 */
1472void most_deregister_interface(struct most_interface *iface)
1473{
1474 int i;
1475 struct most_channel *c;
1476
1477 pr_info("deregistering device %s (%s)\n", dev_name(&iface->dev), iface->description);
1478 for (i = 0; i < iface->num_channels; i++) {
1479 c = iface->p->channel[i];
1480 if (c->pipe0.comp)
1481 c->pipe0.comp->disconnect_channel(c->iface,
1482 c->channel_id);
1483 if (c->pipe1.comp)
1484 c->pipe1.comp->disconnect_channel(c->iface,
1485 c->channel_id);
1486 c->pipe0.comp = NULL;
1487 c->pipe1.comp = NULL;
1488 list_del(&c->list);
1489 device_unregister(&c->dev);
1490 kfree(c);
1491 }
1492
1493 ida_simple_remove(&mdev_id, iface->p->dev_id);
1494 kfree(iface->p);
1495 device_unregister(&iface->dev);
1496}
1497EXPORT_SYMBOL_GPL(most_deregister_interface);
1498
1499/**
1500 * most_stop_enqueue - prevents core from enqueueing MBOs
1501 * @iface: pointer to interface
1502 * @id: channel id
1503 *
1504 * This is called by an HDM that _cannot_ attend to its duties and
1505 * is imminent to get run over by the core. The core is not going to
1506 * enqueue any further packets unless the flagging HDM calls
1507 * most_resume enqueue().
1508 */
1509void most_stop_enqueue(struct most_interface *iface, int id)
1510{
1511 struct most_channel *c = iface->p->channel[id];
1512
1513 if (!c)
1514 return;
1515
1516 mutex_lock(&c->nq_mutex);
1517 c->enqueue_halt = true;
1518 mutex_unlock(&c->nq_mutex);
1519}
1520EXPORT_SYMBOL_GPL(most_stop_enqueue);
1521
1522/**
1523 * most_resume_enqueue - allow core to enqueue MBOs again
1524 * @iface: pointer to interface
1525 * @id: channel id
1526 *
1527 * This clears the enqueue halt flag and enqueues all MBOs currently
1528 * sitting in the wait fifo.
1529 */
1530void most_resume_enqueue(struct most_interface *iface, int id)
1531{
1532 struct most_channel *c = iface->p->channel[id];
1533
1534 if (!c)
1535 return;
1536
1537 mutex_lock(&c->nq_mutex);
1538 c->enqueue_halt = false;
1539 mutex_unlock(&c->nq_mutex);
1540
1541 wake_up_interruptible(&c->hdm_fifo_wq);
1542}
1543EXPORT_SYMBOL_GPL(most_resume_enqueue);
1544
1545static void release_most_sub(struct device *dev)
1546{
1547 pr_info("releasing most_subsystem\n");
1548}
1549
1550static int __init most_init(void)
1551{
1552 int err;
1553
1554 pr_info("init()\n");
1555 INIT_LIST_HEAD(&mc.comp_list);
1556 ida_init(&mdev_id);
1557
1558 mc.bus.name = "most",
1559 mc.bus.match = most_match,
1560 mc.drv.name = "most_core",
1561 mc.drv.bus = &mc.bus,
1562 mc.drv.groups = mc_attr_groups;
1563
1564 err = bus_register(&mc.bus);
1565 if (err) {
1566 pr_info("Cannot register most bus\n");
1567 return err;
1568 }
1569 err = driver_register(&mc.drv);
1570 if (err) {
1571 pr_info("Cannot register core driver\n");
1572 goto exit_bus;
1573 }
1574 mc.dev.init_name = "most_bus";
1575 mc.dev.release = release_most_sub;
1576 if (device_register(&mc.dev)) {
1577 err = -ENOMEM;
1578 goto exit_driver;
1579 }
1580
1581 return 0;
1582
1583exit_driver:
1584 driver_unregister(&mc.drv);
1585exit_bus:
1586 bus_unregister(&mc.bus);
1587 return err;
1588}
1589
1590static void __exit most_exit(void)
1591{
1592 pr_info("exit core module\n");
1593 device_unregister(&mc.dev);
1594 driver_unregister(&mc.drv);
1595 bus_unregister(&mc.bus);
1596 ida_destroy(&mdev_id);
1597}
1598
1599module_init(most_init);
1600module_exit(most_exit);
1601MODULE_LICENSE("GPL");
1602MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>");
1603MODULE_DESCRIPTION("Core module of stacked MOST Linux driver");
diff --git a/drivers/staging/most/mostcore/mostcore.h b/drivers/staging/most/core.h
index 915e5159d1eb..74a29163b68a 100644
--- a/drivers/staging/most/mostcore/mostcore.h
+++ b/drivers/staging/most/core.h
@@ -1,31 +1,18 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * mostcore.h - Interface between MostCore, 3 * most.h - API for component and adapter drivers
3 * Hardware Dependent Module (HDM) and Application Interface Module (AIM).
4 * 4 *
5 * Copyright (C) 2013-2015, Microchip Technology Germany II GmbH & Co. KG 5 * Copyright (C) 2013-2015, Microchip Technology Germany II GmbH & Co. KG
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * This file is licensed under GPLv2.
13 */
14
15/*
16 * Authors:
17 * Andrey Shvetsov <andrey.shvetsov@k2l.de>
18 * Christian Gromm <christian.gromm@microchip.com>
19 * Sebastian Graf
20 */ 6 */
21 7
22#ifndef __MOST_CORE_H__ 8#ifndef __MOST_CORE_H__
23#define __MOST_CORE_H__ 9#define __MOST_CORE_H__
24 10
25#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/device.h>
26 13
27struct kobject;
28struct module; 14struct module;
15struct interface_private;
29 16
30/** 17/**
31 * Interface type 18 * Interface type
@@ -79,22 +66,22 @@ enum mbo_status_flags {
79 * The value is bitwise OR-combination of the values from the 66 * The value is bitwise OR-combination of the values from the
80 * enumeration most_channel_data_type. Zero is allowed value and means 67 * enumeration most_channel_data_type. Zero is allowed value and means
81 * "channel may not be used". 68 * "channel may not be used".
82 * @num_buffer_packet: Maximum number of buffers supported by this channel 69 * @num_buffers_packet: Maximum number of buffers supported by this channel
83 * for packet data types (Async,Control,QoS) 70 * for packet data types (Async,Control,QoS)
84 * @buffer_size_packet: Maximum buffer size supported by this channel 71 * @buffer_size_packet: Maximum buffer size supported by this channel
85 * for packet data types (Async,Control,QoS) 72 * for packet data types (Async,Control,QoS)
86 * @num_buffer_streaming: Maximum number of buffers supported by this channel 73 * @num_buffers_streaming: Maximum number of buffers supported by this channel
87 * for streaming data types (Sync,AV Packetized) 74 * for streaming data types (Sync,AV Packetized)
88 * @buffer_size_streaming: Maximum buffer size supported by this channel 75 * @buffer_size_streaming: Maximum buffer size supported by this channel
89 * for streaming data types (Sync,AV Packetized) 76 * for streaming data types (Sync,AV Packetized)
90 * @name_suffix: Optional suffix providean by an HDM that is attached to the 77 * @name_suffix: Optional suffix providean by an HDM that is attached to the
91 * regular channel name. 78 * regular channel name.
92 * 79 *
93 * Describes the capabilities of a MostCore channel like supported Data Types 80 * Describes the capabilities of a MOST channel like supported Data Types
94 * and directions. This information is provided by an HDM for the MostCore. 81 * and directions. This information is provided by an HDM for the MostCore.
95 * 82 *
96 * The Core creates read only sysfs attribute files in 83 * The Core creates read only sysfs attribute files in
97 * /sys/devices/virtual/most/mostcore/devices/mdev-#/mdev#-ch#/ with the 84 * /sys/devices/most/mdev#/<channel>/ with the
98 * following attributes: 85 * following attributes:
99 * -available_directions 86 * -available_directions
100 * -available_datatypes 87 * -available_datatypes
@@ -129,7 +116,7 @@ struct most_channel_capability {
129 * @packets_per_xact: number of MOST frames that are packet inside one USB 116 * @packets_per_xact: number of MOST frames that are packet inside one USB
130 * packet. This is USB specific 117 * packet. This is USB specific
131 * 118 *
132 * Describes the configuration for a MostCore channel. This information is 119 * Describes the configuration for a MOST channel. This information is
133 * provided from the MostCore to a HDM (like the Medusa PCIe Interface) as a 120 * provided from the MostCore to a HDM (like the Medusa PCIe Interface) as a
134 * parameter of the "configure" function call. 121 * parameter of the "configure" function call.
135 */ 122 */
@@ -153,6 +140,7 @@ struct most_channel_config {
153 * 140 *
154 * @list: list head for use by the mbo's current owner 141 * @list: list head for use by the mbo's current owner
155 * @ifp: (in) associated interface instance 142 * @ifp: (in) associated interface instance
143 * @num_buffers_ptr: amount of pool buffers
156 * @hdm_channel_id: (in) HDM channel instance 144 * @hdm_channel_id: (in) HDM channel instance
157 * @virt_address: (in) kernel virtual address of the buffer 145 * @virt_address: (in) kernel virtual address of the buffer
158 * @bus_address: (in) bus address of the buffer 146 * @bus_address: (in) bus address of the buffer
@@ -161,15 +149,15 @@ struct most_channel_config {
161 * @status: (out) transfer status 149 * @status: (out) transfer status
162 * @complete: (in) completion routine 150 * @complete: (in) completion routine
163 * 151 *
164 * The MostCore allocates and initializes the MBO. 152 * The core allocates and initializes the MBO.
165 * 153 *
166 * The HDM receives MBO for transfer from MostCore with the call to enqueue(). 154 * The HDM receives MBO for transfer from the core with the call to enqueue().
167 * The HDM copies the data to- or from the buffer depending on configured 155 * The HDM copies the data to- or from the buffer depending on configured
168 * channel direction, set "processed_length" and "status" and completes 156 * channel direction, set "processed_length" and "status" and completes
169 * the transfer procedure by calling the completion routine. 157 * the transfer procedure by calling the completion routine.
170 * 158 *
171 * At the end the MostCore deallocates the MBO or recycles it for further 159 * Finally, the MBO is being deallocated or recycled for further
172 * transfers for the same or different HDM. 160 * transfers of the same or a different HDM.
173 * 161 *
174 * Directions of usage: 162 * Directions of usage:
175 * The core driver should never access any MBO fields (even if marked 163 * The core driver should never access any MBO fields (even if marked
@@ -202,10 +190,12 @@ struct mbo {
202/** 190/**
203 * Interface instance description. 191 * Interface instance description.
204 * 192 *
205 * Describes one instance of an interface like Medusa PCIe or Vantage USB. 193 * Describes an interface of a MOST device the core driver is bound to.
206 * This structure is allocated and initialized in the HDM. MostCore may not 194 * This structure is allocated and initialized in the HDM. MostCore may not
207 * modify this structure. 195 * modify this structure.
208 * 196 *
197 * @dev: the actual device
198 * @mod: module
209 * @interface Interface type. \sa most_interface_type. 199 * @interface Interface type. \sa most_interface_type.
210 * @description PRELIMINARY. 200 * @description PRELIMINARY.
211 * Unique description of the device instance from point of view of the 201 * Unique description of the device instance from point of view of the
@@ -238,10 +228,11 @@ struct mbo {
238 * @priv Private field used by mostcore to store context information. 228 * @priv Private field used by mostcore to store context information.
239 */ 229 */
240struct most_interface { 230struct most_interface {
231 struct device dev;
241 struct module *mod; 232 struct module *mod;
242 enum most_interface_type interface; 233 enum most_interface_type interface;
243 const char *description; 234 const char *description;
244 int num_channels; 235 unsigned int num_channels;
245 struct most_channel_capability *channel_vector; 236 struct most_channel_capability *channel_vector;
246 int (*configure)(struct most_interface *iface, int channel_idx, 237 int (*configure)(struct most_interface *iface, int channel_idx,
247 struct most_channel_config *channel_config); 238 struct most_channel_config *channel_config);
@@ -253,27 +244,29 @@ struct most_interface {
253 unsigned char link_stat, 244 unsigned char link_stat,
254 unsigned char *mac_addr)); 245 unsigned char *mac_addr));
255 void *priv; 246 void *priv;
247 struct interface_private *p;
256}; 248};
257 249
250#define to_most_interface(d) container_of(d, struct most_interface, dev)
251
258/** 252/**
259 * struct most_aim - identifies MOST device driver to mostcore 253 * struct core_component - identifies a loadable component for the mostcore
260 * @name: Driver name 254 * @list: list_head
255 * @name: component name
261 * @probe_channel: function for core to notify driver about channel connection 256 * @probe_channel: function for core to notify driver about channel connection
262 * @disconnect_channel: callback function to disconnect a certain channel 257 * @disconnect_channel: callback function to disconnect a certain channel
263 * @rx_completion: completion handler for received packets 258 * @rx_completion: completion handler for received packets
264 * @tx_completion: completion handler for transmitted packets 259 * @tx_completion: completion handler for transmitted packets
265 * @context: context pointer to be used by mostcore
266 */ 260 */
267struct most_aim { 261struct core_component {
262 struct list_head list;
268 const char *name; 263 const char *name;
269 int (*probe_channel)(struct most_interface *iface, int channel_idx, 264 int (*probe_channel)(struct most_interface *iface, int channel_idx,
270 struct most_channel_config *cfg, 265 struct most_channel_config *cfg, char *name);
271 struct kobject *parent, char *name);
272 int (*disconnect_channel)(struct most_interface *iface, 266 int (*disconnect_channel)(struct most_interface *iface,
273 int channel_idx); 267 int channel_idx);
274 int (*rx_completion)(struct mbo *mbo); 268 int (*rx_completion)(struct mbo *mbo);
275 int (*tx_completion)(struct most_interface *iface, int channel_idx); 269 int (*tx_completion)(struct most_interface *iface, int channel_idx);
276 void *context;
277}; 270};
278 271
279/** 272/**
@@ -285,7 +278,7 @@ struct most_aim {
285 * Note: HDM has to ensure that any reference held on the kobj is 278 * Note: HDM has to ensure that any reference held on the kobj is
286 * released before deregistering the interface. 279 * released before deregistering the interface.
287 */ 280 */
288struct kobject *most_register_interface(struct most_interface *iface); 281int most_register_interface(struct most_interface *iface);
289 282
290/** 283/**
291 * Deregisters instance of the interface. 284 * Deregisters instance of the interface.
@@ -310,16 +303,16 @@ void most_stop_enqueue(struct most_interface *iface, int channel_idx);
310 * in wait fifo. 303 * in wait fifo.
311 */ 304 */
312void most_resume_enqueue(struct most_interface *iface, int channel_idx); 305void most_resume_enqueue(struct most_interface *iface, int channel_idx);
313int most_register_aim(struct most_aim *aim); 306int most_register_component(struct core_component *comp);
314int most_deregister_aim(struct most_aim *aim); 307int most_deregister_component(struct core_component *comp);
315struct mbo *most_get_mbo(struct most_interface *iface, int channel_idx, 308struct mbo *most_get_mbo(struct most_interface *iface, int channel_idx,
316 struct most_aim *); 309 struct core_component *comp);
317void most_put_mbo(struct mbo *mbo); 310void most_put_mbo(struct mbo *mbo);
318int channel_has_mbo(struct most_interface *iface, int channel_idx, 311int channel_has_mbo(struct most_interface *iface, int channel_idx,
319 struct most_aim *aim); 312 struct core_component *comp);
320int most_start_channel(struct most_interface *iface, int channel_idx, 313int most_start_channel(struct most_interface *iface, int channel_idx,
321 struct most_aim *); 314 struct core_component *comp);
322int most_stop_channel(struct most_interface *iface, int channel_idx, 315int most_stop_channel(struct most_interface *iface, int channel_idx,
323 struct most_aim *); 316 struct core_component *comp);
324 317
325#endif /* MOST_CORE_H_ */ 318#endif /* MOST_CORE_H_ */
diff --git a/drivers/staging/most/hdm-dim2/Kconfig b/drivers/staging/most/dim2/Kconfig
index 663bfebff674..e39c4e525cac 100644
--- a/drivers/staging/most/hdm-dim2/Kconfig
+++ b/drivers/staging/most/dim2/Kconfig
@@ -2,8 +2,8 @@
2# MediaLB configuration 2# MediaLB configuration
3# 3#
4 4
5config HDM_DIM2 5config MOST_DIM2
6 tristate "DIM2 HDM" 6 tristate "DIM2"
7 depends on HAS_IOMEM 7 depends on HAS_IOMEM
8 8
9 ---help--- 9 ---help---
@@ -13,4 +13,4 @@ config HDM_DIM2
13 maintainer of this driver. 13 maintainer of this driver.
14 14
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 hdm_dim2. 16 module will be called most_dim2.
diff --git a/drivers/staging/most/dim2/Makefile b/drivers/staging/most/dim2/Makefile
new file mode 100644
index 000000000000..66676f5907ee
--- /dev/null
+++ b/drivers/staging/most/dim2/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_MOST_DIM2) += most_dim2.o
2
3most_dim2-objs := dim2.o hal.o sysfs.o
4ccflags-y += -Idrivers/staging/
diff --git a/drivers/staging/most/hdm-dim2/dim2_hdm.c b/drivers/staging/most/dim2/dim2.c
index df7021c522b3..f9bc7dea75b8 100644
--- a/drivers/staging/most/hdm-dim2/dim2_hdm.c
+++ b/drivers/staging/most/dim2/dim2.c
@@ -1,14 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * dim2_hdm.c - MediaLB DIM2 Hardware Dependent Module 3 * dim2.c - MediaLB DIM2 Hardware Dependent Module
3 * 4 *
4 * Copyright (C) 2015-2016, Microchip Technology Germany II GmbH & Co. KG 5 * Copyright (C) 2015-2016, Microchip Technology Germany II GmbH & Co. KG
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 * This file is licensed under GPLv2.
12 */ 6 */
13 7
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -25,11 +19,11 @@
25#include <linux/sched.h> 19#include <linux/sched.h>
26#include <linux/kthread.h> 20#include <linux/kthread.h>
27 21
28#include <mostcore.h> 22#include "most/core.h"
29#include "dim2_hal.h" 23#include "hal.h"
30#include "dim2_hdm.h" 24#include "dim2.h"
31#include "dim2_errors.h" 25#include "errors.h"
32#include "dim2_sysfs.h" 26#include "sysfs.h"
33 27
34#define DMA_CHANNELS (32 - 1) /* channel 0 is a system channel */ 28#define DMA_CHANNELS (32 - 1) /* channel 0 is a system channel */
35 29
@@ -93,6 +87,7 @@ struct hdm_channel {
93 * @atx_idx: index of async tx channel 87 * @atx_idx: index of async tx channel
94 */ 88 */
95struct dim2_hdm { 89struct dim2_hdm {
90 struct device dev;
96 struct hdm_channel hch[DMA_CHANNELS]; 91 struct hdm_channel hch[DMA_CHANNELS];
97 struct most_channel_capability capabilities[DMA_CHANNELS]; 92 struct most_channel_capability capabilities[DMA_CHANNELS];
98 struct most_interface most_iface; 93 struct most_interface most_iface;
@@ -106,8 +101,8 @@ struct dim2_hdm {
106 unsigned char link_state; 101 unsigned char link_state;
107 int atx_idx; 102 int atx_idx;
108 struct medialb_bus bus; 103 struct medialb_bus bus;
109 void (*on_netinfo)(struct most_interface *, 104 void (*on_netinfo)(struct most_interface *most_iface,
110 unsigned char, unsigned char *); 105 unsigned char link_state, unsigned char *addrs);
111}; 106};
112 107
113#define iface_to_hdm(iface) container_of(iface, struct dim2_hdm, most_iface) 108#define iface_to_hdm(iface) container_of(iface, struct dim2_hdm, most_iface)
@@ -156,7 +151,7 @@ void dimcb_io_write(u32 __iomem *ptr32, u32 value)
156 */ 151 */
157void dimcb_on_error(u8 error_id, const char *error_message) 152void dimcb_on_error(u8 error_id, const char *error_message)
158{ 153{
159 pr_err("dimcb_on_error: error_id - %d, error_message - %s\n", error_id, 154 pr_err("%s: error_id - %d, error_message - %s\n", __func__, error_id,
160 error_message); 155 error_message);
161} 156}
162 157
@@ -744,7 +739,6 @@ static int dim2_probe(struct platform_device *pdev)
744 struct dim2_hdm *dev; 739 struct dim2_hdm *dev;
745 struct resource *res; 740 struct resource *res;
746 int ret, i; 741 int ret, i;
747 struct kobject *kobj;
748 int irq; 742 int irq;
749 743
750 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); 744 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
@@ -832,17 +826,20 @@ static int dim2_probe(struct platform_device *pdev)
832 dev->most_iface.enqueue = enqueue; 826 dev->most_iface.enqueue = enqueue;
833 dev->most_iface.poison_channel = poison_channel; 827 dev->most_iface.poison_channel = poison_channel;
834 dev->most_iface.request_netinfo = request_netinfo; 828 dev->most_iface.request_netinfo = request_netinfo;
829 dev->dev.init_name = "dim2_state";
830 dev->dev.parent = &dev->most_iface.dev;
835 831
836 kobj = most_register_interface(&dev->most_iface); 832 ret = most_register_interface(&dev->most_iface);
837 if (IS_ERR(kobj)) { 833 if (ret) {
838 ret = PTR_ERR(kobj);
839 dev_err(&pdev->dev, "failed to register MOST interface\n"); 834 dev_err(&pdev->dev, "failed to register MOST interface\n");
840 goto err_stop_thread; 835 goto err_stop_thread;
841 } 836 }
842 837
843 ret = dim2_sysfs_probe(&dev->bus, kobj); 838 ret = dim2_sysfs_probe(&dev->dev);
844 if (ret) 839 if (ret) {
840 dev_err(&pdev->dev, "failed to create sysfs attribute\n");
845 goto err_unreg_iface; 841 goto err_unreg_iface;
842 }
846 843
847 ret = startup_dim(pdev); 844 ret = startup_dim(pdev);
848 if (ret) { 845 if (ret) {
@@ -853,7 +850,7 @@ static int dim2_probe(struct platform_device *pdev)
853 return 0; 850 return 0;
854 851
855err_destroy_bus: 852err_destroy_bus:
856 dim2_sysfs_destroy(&dev->bus); 853 dim2_sysfs_destroy(&dev->dev);
857err_unreg_iface: 854err_unreg_iface:
858 most_deregister_interface(&dev->most_iface); 855 most_deregister_interface(&dev->most_iface);
859err_stop_thread: 856err_stop_thread:
@@ -881,7 +878,7 @@ static int dim2_remove(struct platform_device *pdev)
881 if (pdata && pdata->destroy) 878 if (pdata && pdata->destroy)
882 pdata->destroy(pdata); 879 pdata->destroy(pdata);
883 880
884 dim2_sysfs_destroy(&dev->bus); 881 dim2_sysfs_destroy(&dev->dev);
885 most_deregister_interface(&dev->most_iface); 882 most_deregister_interface(&dev->most_iface);
886 kthread_stop(dev->netinfo_task); 883 kthread_stop(dev->netinfo_task);
887 884
diff --git a/drivers/staging/most/hdm-dim2/dim2_hdm.h b/drivers/staging/most/dim2/dim2.h
index 4050e7c764ed..6a9fc51a2eb4 100644
--- a/drivers/staging/most/hdm-dim2/dim2_hdm.h
+++ b/drivers/staging/most/dim2/dim2.h
@@ -1,14 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * dim2_hdm.h - MediaLB DIM2 HDM Header 3 * dim2.h - MediaLB DIM2 HDM Header
3 * 4 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG 5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
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 * This file is licensed under GPLv2.
12 */ 6 */
13 7
14#ifndef DIM2_HDM_H 8#ifndef DIM2_HDM_H
diff --git a/drivers/staging/most/hdm-dim2/dim2_errors.h b/drivers/staging/most/dim2/errors.h
index 66343ba426c1..3487510fbd2f 100644
--- a/drivers/staging/most/hdm-dim2/dim2_errors.h
+++ b/drivers/staging/most/dim2/errors.h
@@ -1,15 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * dim2_errors.h - Definitions of errors for DIM2 HAL API 3 * errors.h - Definitions of errors for DIM2 HAL API
3 * (MediaLB, Device Interface Macro IP, OS62420) 4 * (MediaLB, Device Interface Macro IP, OS62420)
4 * 5 *
5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG 6 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * This file is licensed under GPLv2.
13 */ 7 */
14 8
15#ifndef _MOST_DIM_ERRORS_H 9#ifndef _MOST_DIM_ERRORS_H
diff --git a/drivers/staging/most/hdm-dim2/dim2_hal.c b/drivers/staging/most/dim2/hal.c
index 91484643d289..17c04e1c5e62 100644
--- a/drivers/staging/most/hdm-dim2/dim2_hal.c
+++ b/drivers/staging/most/dim2/hal.c
@@ -1,22 +1,16 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * dim2_hal.c - DIM2 HAL implementation 3 * hal.c - DIM2 HAL implementation
3 * (MediaLB, Device Interface Macro IP, OS62420) 4 * (MediaLB, Device Interface Macro IP, OS62420)
4 * 5 *
5 * Copyright (C) 2015-2016, Microchip Technology Germany II GmbH & Co. KG 6 * Copyright (C) 2015-2016, Microchip Technology Germany II GmbH & Co. KG
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * This file is licensed under GPLv2.
13 */ 7 */
14 8
15/* Author: Andrey Shvetsov <andrey.shvetsov@k2l.de> */ 9/* Author: Andrey Shvetsov <andrey.shvetsov@k2l.de> */
16 10
17#include "dim2_hal.h" 11#include "hal.h"
18#include "dim2_errors.h" 12#include "errors.h"
19#include "dim2_reg.h" 13#include "reg.h"
20#include <linux/stddef.h> 14#include <linux/stddef.h>
21#include <linux/kernel.h> 15#include <linux/kernel.h>
22 16
diff --git a/drivers/staging/most/hdm-dim2/dim2_hal.h b/drivers/staging/most/dim2/hal.h
index 6df6ea5f7da4..e04a5350f134 100644
--- a/drivers/staging/most/hdm-dim2/dim2_hal.h
+++ b/drivers/staging/most/dim2/hal.h
@@ -1,22 +1,16 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * dim2_hal.h - DIM2 HAL interface 3 * hal.h - DIM2 HAL interface
3 * (MediaLB, Device Interface Macro IP, OS62420) 4 * (MediaLB, Device Interface Macro IP, OS62420)
4 * 5 *
5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG 6 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * This file is licensed under GPLv2.
13 */ 7 */
14 8
15#ifndef _DIM2_HAL_H 9#ifndef _DIM2_HAL_H
16#define _DIM2_HAL_H 10#define _DIM2_HAL_H
17 11
18#include <linux/types.h> 12#include <linux/types.h>
19#include "dim2_reg.h" 13#include "reg.h"
20 14
21/* 15/*
22 * The values below are specified in the hardware specification. 16 * The values below are specified in the hardware specification.
diff --git a/drivers/staging/most/hdm-dim2/dim2_reg.h b/drivers/staging/most/dim2/reg.h
index f7d9fbcd29f2..69cbf78239f1 100644
--- a/drivers/staging/most/hdm-dim2/dim2_reg.h
+++ b/drivers/staging/most/dim2/reg.h
@@ -1,15 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * dim2_reg.h - Definitions for registers of DIM2 3 * reg.h - Definitions for registers of DIM2
3 * (MediaLB, Device Interface Macro IP, OS62420) 4 * (MediaLB, Device Interface Macro IP, OS62420)
4 * 5 *
5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG 6 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * This file is licensed under GPLv2.
13 */ 7 */
14 8
15#ifndef DIM2_OS62420_H 9#ifndef DIM2_OS62420_H
diff --git a/drivers/staging/most/dim2/sysfs.c b/drivers/staging/most/dim2/sysfs.c
new file mode 100644
index 000000000000..c85b2cdcdca3
--- /dev/null
+++ b/drivers/staging/most/dim2/sysfs.c
@@ -0,0 +1,49 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * sysfs.c - MediaLB sysfs information
4 *
5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 */
7
8/* Author: Andrey Shvetsov <andrey.shvetsov@k2l.de> */
9
10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
12#include <linux/kernel.h>
13#include "sysfs.h"
14#include <linux/device.h>
15
16static ssize_t state_show(struct device *dev, struct device_attribute *attr,
17 char *buf)
18{
19 bool state = dim2_sysfs_get_state_cb();
20
21 return sprintf(buf, "%s\n", state ? "locked" : "");
22}
23
24static DEVICE_ATTR_RO(state);
25
26static struct attribute *dev_attrs[] = {
27 &dev_attr_state.attr,
28 NULL,
29};
30
31static struct attribute_group dev_attr_group = {
32 .attrs = dev_attrs,
33};
34
35static const struct attribute_group *dev_attr_groups[] = {
36 &dev_attr_group,
37 NULL,
38};
39
40int dim2_sysfs_probe(struct device *dev)
41{
42 dev->groups = dev_attr_groups;
43 return device_register(dev);
44}
45
46void dim2_sysfs_destroy(struct device *dev)
47{
48 device_unregister(dev);
49}
diff --git a/drivers/staging/most/dim2/sysfs.h b/drivers/staging/most/dim2/sysfs.h
new file mode 100644
index 000000000000..33756a3bffe2
--- /dev/null
+++ b/drivers/staging/most/dim2/sysfs.h
@@ -0,0 +1,30 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * sysfs.h - MediaLB sysfs information
4 *
5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 */
7
8/* Author: Andrey Shvetsov <andrey.shvetsov@k2l.de> */
9
10#ifndef DIM2_SYSFS_H
11#define DIM2_SYSFS_H
12
13#include <linux/kobject.h>
14
15struct medialb_bus {
16 struct kobject kobj_group;
17};
18
19struct device;
20
21int dim2_sysfs_probe(struct device *dev);
22void dim2_sysfs_destroy(struct device *dev);
23
24/*
25 * callback,
26 * must deliver MediaLB state as true if locked or false if unlocked
27 */
28bool dim2_sysfs_get_state_cb(void);
29
30#endif /* DIM2_SYSFS_H */
diff --git a/drivers/staging/most/hdm-dim2/Makefile b/drivers/staging/most/hdm-dim2/Makefile
deleted file mode 100644
index 6bbee879a8ea..000000000000
--- a/drivers/staging/most/hdm-dim2/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
1obj-$(CONFIG_HDM_DIM2) += hdm_dim2.o
2
3hdm_dim2-objs := dim2_hdm.o dim2_hal.o dim2_sysfs.o
4ccflags-y += -Idrivers/staging/most/mostcore/
5ccflags-y += -Idrivers/staging/most/aim-network/
diff --git a/drivers/staging/most/hdm-dim2/dim2_sysfs.c b/drivers/staging/most/hdm-dim2/dim2_sysfs.c
deleted file mode 100644
index d8b22f91d2c3..000000000000
--- a/drivers/staging/most/hdm-dim2/dim2_sysfs.c
+++ /dev/null
@@ -1,115 +0,0 @@
1/*
2 * dim2_sysfs.c - MediaLB sysfs information
3 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
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 * This file is licensed under GPLv2.
12 */
13
14/* Author: Andrey Shvetsov <andrey.shvetsov@k2l.de> */
15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18#include <linux/kernel.h>
19#include "dim2_sysfs.h"
20
21struct bus_attr {
22 struct attribute attr;
23 ssize_t (*show)(struct medialb_bus *bus, char *buf);
24 ssize_t (*store)(struct medialb_bus *bus, const char *buf,
25 size_t count);
26};
27
28static ssize_t state_show(struct medialb_bus *bus, char *buf)
29{
30 bool state = dim2_sysfs_get_state_cb();
31
32 return sprintf(buf, "%s\n", state ? "locked" : "");
33}
34
35static struct bus_attr state_attr = __ATTR_RO(state);
36
37static struct attribute *bus_default_attrs[] = {
38 &state_attr.attr,
39 NULL,
40};
41
42static const struct attribute_group bus_attr_group = {
43 .attrs = bus_default_attrs,
44};
45
46static void bus_kobj_release(struct kobject *kobj)
47{
48}
49
50static ssize_t bus_kobj_attr_show(struct kobject *kobj, struct attribute *attr,
51 char *buf)
52{
53 struct medialb_bus *bus =
54 container_of(kobj, struct medialb_bus, kobj_group);
55 struct bus_attr *xattr = container_of(attr, struct bus_attr, attr);
56
57 if (!xattr->show)
58 return -EIO;
59
60 return xattr->show(bus, buf);
61}
62
63static ssize_t bus_kobj_attr_store(struct kobject *kobj, struct attribute *attr,
64 const char *buf, size_t count)
65{
66 struct medialb_bus *bus =
67 container_of(kobj, struct medialb_bus, kobj_group);
68 struct bus_attr *xattr = container_of(attr, struct bus_attr, attr);
69
70 if (!xattr->store)
71 return -EIO;
72
73 return xattr->store(bus, buf, count);
74}
75
76static struct sysfs_ops const bus_kobj_sysfs_ops = {
77 .show = bus_kobj_attr_show,
78 .store = bus_kobj_attr_store,
79};
80
81static struct kobj_type bus_ktype = {
82 .release = bus_kobj_release,
83 .sysfs_ops = &bus_kobj_sysfs_ops,
84};
85
86int dim2_sysfs_probe(struct medialb_bus *bus, struct kobject *parent_kobj)
87{
88 int err;
89
90 kobject_init(&bus->kobj_group, &bus_ktype);
91 err = kobject_add(&bus->kobj_group, parent_kobj, "bus");
92 if (err) {
93 pr_err("kobject_add() failed: %d\n", err);
94 goto err_kobject_add;
95 }
96
97 err = sysfs_create_group(&bus->kobj_group, &bus_attr_group);
98 if (err) {
99 pr_err("sysfs_create_group() failed: %d\n", err);
100 goto err_create_group;
101 }
102
103 return 0;
104
105err_create_group:
106 kobject_put(&bus->kobj_group);
107
108err_kobject_add:
109 return err;
110}
111
112void dim2_sysfs_destroy(struct medialb_bus *bus)
113{
114 kobject_put(&bus->kobj_group);
115}
diff --git a/drivers/staging/most/hdm-dim2/dim2_sysfs.h b/drivers/staging/most/hdm-dim2/dim2_sysfs.h
deleted file mode 100644
index b71dd027ebc7..000000000000
--- a/drivers/staging/most/hdm-dim2/dim2_sysfs.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * dim2_sysfs.h - MediaLB sysfs information
3 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
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 * This file is licensed under GPLv2.
12 */
13
14/* Author: Andrey Shvetsov <andrey.shvetsov@k2l.de> */
15
16#ifndef DIM2_SYSFS_H
17#define DIM2_SYSFS_H
18
19#include <linux/kobject.h>
20
21struct medialb_bus {
22 struct kobject kobj_group;
23};
24
25struct dim2_hdm;
26
27int dim2_sysfs_probe(struct medialb_bus *bus, struct kobject *parent_kobj);
28void dim2_sysfs_destroy(struct medialb_bus *bus);
29
30/*
31 * callback,
32 * must deliver MediaLB state as true if locked or false if unlocked
33 */
34bool dim2_sysfs_get_state_cb(void);
35
36#endif /* DIM2_SYSFS_H */
diff --git a/drivers/staging/most/hdm-i2c/Makefile b/drivers/staging/most/hdm-i2c/Makefile
deleted file mode 100644
index 03a4a59b1f9f..000000000000
--- a/drivers/staging/most/hdm-i2c/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1obj-$(CONFIG_HDM_I2C) += hdm_i2c.o
2
3ccflags-y += -Idrivers/staging/most/mostcore/
diff --git a/drivers/staging/most/hdm-usb/Makefile b/drivers/staging/most/hdm-usb/Makefile
deleted file mode 100644
index 6bbacb41e94b..000000000000
--- a/drivers/staging/most/hdm-usb/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
1obj-$(CONFIG_HDM_USB) += hdm_usb.o
2
3ccflags-y += -Idrivers/staging/most/mostcore/
4ccflags-y += -Idrivers/staging/most/aim-network/
diff --git a/drivers/staging/most/hdm-i2c/Kconfig b/drivers/staging/most/i2c/Kconfig
index 6fd7983668ad..79d0ff27f56d 100644
--- a/drivers/staging/most/hdm-i2c/Kconfig
+++ b/drivers/staging/most/i2c/Kconfig
@@ -2,11 +2,11 @@
2# MOST I2C configuration 2# MOST I2C configuration
3# 3#
4 4
5config HDM_I2C 5config MOST_I2C
6 tristate "I2C HDM" 6 tristate "I2C"
7 depends on I2C 7 depends on I2C
8 ---help--- 8 ---help---
9 Say Y here if you want to connect via I2C to network tranceiver. 9 Say Y here if you want to connect via I2C to network tranceiver.
10 10
11 To compile this driver as a module, choose M here: the 11 To compile this driver as a module, choose M here: the
12 module will be called hdm_i2c. 12 module will be called most_i2c.
diff --git a/drivers/staging/most/i2c/Makefile b/drivers/staging/most/i2c/Makefile
new file mode 100644
index 000000000000..a7d094c1e1c2
--- /dev/null
+++ b/drivers/staging/most/i2c/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_MOST_I2C) += most_i2c.o
2
3most_i2c-objs := i2c.o
4ccflags-y += -Idrivers/staging/
diff --git a/drivers/staging/most/hdm-i2c/hdm_i2c.c b/drivers/staging/most/i2c/i2c.c
index 2b4de404e46a..141239fc9f51 100644
--- a/drivers/staging/most/hdm-i2c/hdm_i2c.c
+++ b/drivers/staging/most/i2c/i2c.c
@@ -1,14 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * hdm_i2c.c - Hardware Dependent Module for I2C Interface 3 * i2c.c - Hardware Dependent Module for I2C Interface
3 * 4 *
4 * Copyright (C) 2013-2015, Microchip Technology Germany II GmbH & Co. KG 5 * Copyright (C) 2013-2015, Microchip Technology Germany II GmbH & Co. KG
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 * This file is licensed under GPLv2.
12 */ 6 */
13 7
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -21,7 +15,7 @@
21#include <linux/interrupt.h> 15#include <linux/interrupt.h>
22#include <linux/err.h> 16#include <linux/err.h>
23 17
24#include <mostcore.h> 18#include "most/core.h"
25 19
26enum { CH_RX, CH_TX, NUM_CHANNELS }; 20enum { CH_RX, CH_TX, NUM_CHANNELS };
27 21
@@ -309,7 +303,6 @@ static int i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
309{ 303{
310 struct hdm_i2c *dev; 304 struct hdm_i2c *dev;
311 int ret, i; 305 int ret, i;
312 struct kobject *kobj;
313 306
314 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 307 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
315 if (!dev) 308 if (!dev)
@@ -347,11 +340,11 @@ static int i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
347 dev->client = client; 340 dev->client = client;
348 i2c_set_clientdata(client, dev); 341 i2c_set_clientdata(client, dev);
349 342
350 kobj = most_register_interface(&dev->most_iface); 343 ret = most_register_interface(&dev->most_iface);
351 if (IS_ERR(kobj)) { 344 if (ret) {
352 pr_err("Failed to register i2c as a MOST interface\n"); 345 pr_err("Failed to register i2c as a MOST interface\n");
353 kfree(dev); 346 kfree(dev);
354 return PTR_ERR(kobj); 347 return ret;
355 } 348 }
356 349
357 dev->polling_mode = polling_req || client->irq <= 0; 350 dev->polling_mode = polling_req || client->irq <= 0;
diff --git a/drivers/staging/most/mostcore/Kconfig b/drivers/staging/most/mostcore/Kconfig
deleted file mode 100644
index 47172546d728..000000000000
--- a/drivers/staging/most/mostcore/Kconfig
+++ /dev/null
@@ -1,14 +0,0 @@
1#
2# MOSTCore configuration
3#
4
5config MOSTCORE
6 tristate "MOST Core"
7 depends on HAS_DMA
8
9 ---help---
10 Say Y here if you want to enable MOST support.
11 This device driver needs at least an additional AIM and HDM to work.
12
13 To compile this driver as a module, choose M here: the
14 module will be called mostcore.
diff --git a/drivers/staging/most/mostcore/Makefile b/drivers/staging/most/mostcore/Makefile
deleted file mode 100644
index a078f01cf7c2..000000000000
--- a/drivers/staging/most/mostcore/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1obj-$(CONFIG_MOSTCORE) += mostcore.o
2
3mostcore-objs := core.o
diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c
deleted file mode 100644
index 069269db394c..000000000000
--- a/drivers/staging/most/mostcore/core.c
+++ /dev/null
@@ -1,1949 +0,0 @@
1/*
2 * core.c - Implementation of core module of MOST Linux driver stack
3 *
4 * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG
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 * This file is licensed under GPLv2.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#include <linux/module.h>
16#include <linux/fs.h>
17#include <linux/slab.h>
18#include <linux/init.h>
19#include <linux/device.h>
20#include <linux/list.h>
21#include <linux/poll.h>
22#include <linux/wait.h>
23#include <linux/kobject.h>
24#include <linux/mutex.h>
25#include <linux/completion.h>
26#include <linux/sysfs.h>
27#include <linux/kthread.h>
28#include <linux/dma-mapping.h>
29#include <linux/idr.h>
30#include "mostcore.h"
31
32#define MAX_CHANNELS 64
33#define STRING_SIZE 80
34
35static struct class *most_class;
36static struct device *core_dev;
37static struct ida mdev_id;
38static int dummy_num_buffers;
39
40struct most_c_aim_obj {
41 struct most_aim *ptr;
42 int refs;
43 int num_buffers;
44};
45
46struct most_c_obj {
47 struct kobject kobj;
48 struct completion cleanup;
49 atomic_t mbo_ref;
50 atomic_t mbo_nq_level;
51 u16 channel_id;
52 bool is_poisoned;
53 struct mutex start_mutex;
54 struct mutex nq_mutex; /* nq thread synchronization */
55 int is_starving;
56 struct most_interface *iface;
57 struct most_inst_obj *inst;
58 struct most_channel_config cfg;
59 bool keep_mbo;
60 bool enqueue_halt;
61 struct list_head fifo;
62 spinlock_t fifo_lock;
63 struct list_head halt_fifo;
64 struct list_head list;
65 struct most_c_aim_obj aim0;
66 struct most_c_aim_obj aim1;
67 struct list_head trash_fifo;
68 struct task_struct *hdm_enqueue_task;
69 wait_queue_head_t hdm_fifo_wq;
70};
71
72#define to_c_obj(d) container_of(d, struct most_c_obj, kobj)
73
74struct most_inst_obj {
75 int dev_id;
76 struct most_interface *iface;
77 struct list_head channel_list;
78 struct most_c_obj *channel[MAX_CHANNELS];
79 struct kobject kobj;
80 struct list_head list;
81};
82
83static const struct {
84 int most_ch_data_type;
85 const char *name;
86} ch_data_type[] = {
87 { MOST_CH_CONTROL, "control\n" },
88 { MOST_CH_ASYNC, "async\n" },
89 { MOST_CH_SYNC, "sync\n" },
90 { MOST_CH_ISOC, "isoc\n"},
91 { MOST_CH_ISOC, "isoc_avp\n"},
92};
93
94#define to_inst_obj(d) container_of(d, struct most_inst_obj, kobj)
95
96/**
97 * list_pop_mbo - retrieves the first MBO of the list and removes it
98 * @ptr: the list head to grab the MBO from.
99 */
100#define list_pop_mbo(ptr) \
101({ \
102 struct mbo *_mbo = list_first_entry(ptr, struct mbo, list); \
103 list_del(&_mbo->list); \
104 _mbo; \
105})
106
107/* ___ ___
108 * ___C H A N N E L___
109 */
110
111/**
112 * struct most_c_attr - to access the attributes of a channel object
113 * @attr: attributes of a channel
114 * @show: pointer to the show function
115 * @store: pointer to the store function
116 */
117struct most_c_attr {
118 struct attribute attr;
119 ssize_t (*show)(struct most_c_obj *d,
120 struct most_c_attr *attr,
121 char *buf);
122 ssize_t (*store)(struct most_c_obj *d,
123 struct most_c_attr *attr,
124 const char *buf,
125 size_t count);
126};
127
128#define to_channel_attr(a) container_of(a, struct most_c_attr, attr)
129
130/**
131 * channel_attr_show - show function of channel object
132 * @kobj: pointer to its kobject
133 * @attr: pointer to its attributes
134 * @buf: buffer
135 */
136static ssize_t channel_attr_show(struct kobject *kobj, struct attribute *attr,
137 char *buf)
138{
139 struct most_c_attr *channel_attr = to_channel_attr(attr);
140 struct most_c_obj *c_obj = to_c_obj(kobj);
141
142 if (!channel_attr->show)
143 return -EIO;
144
145 return channel_attr->show(c_obj, channel_attr, buf);
146}
147
148/**
149 * channel_attr_store - store function of channel object
150 * @kobj: pointer to its kobject
151 * @attr: pointer to its attributes
152 * @buf: buffer
153 * @len: length of buffer
154 */
155static ssize_t channel_attr_store(struct kobject *kobj,
156 struct attribute *attr,
157 const char *buf,
158 size_t len)
159{
160 struct most_c_attr *channel_attr = to_channel_attr(attr);
161 struct most_c_obj *c_obj = to_c_obj(kobj);
162
163 if (!channel_attr->store)
164 return -EIO;
165 return channel_attr->store(c_obj, channel_attr, buf, len);
166}
167
168static const struct sysfs_ops most_channel_sysfs_ops = {
169 .show = channel_attr_show,
170 .store = channel_attr_store,
171};
172
173/**
174 * most_free_mbo_coherent - free an MBO and its coherent buffer
175 * @mbo: buffer to be released
176 *
177 */
178static void most_free_mbo_coherent(struct mbo *mbo)
179{
180 struct most_c_obj *c = mbo->context;
181 u16 const coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len;
182
183 dma_free_coherent(NULL, coherent_buf_size, mbo->virt_address,
184 mbo->bus_address);
185 kfree(mbo);
186 if (atomic_sub_and_test(1, &c->mbo_ref))
187 complete(&c->cleanup);
188}
189
190/**
191 * flush_channel_fifos - clear the channel fifos
192 * @c: pointer to channel object
193 */
194static void flush_channel_fifos(struct most_c_obj *c)
195{
196 unsigned long flags, hf_flags;
197 struct mbo *mbo, *tmp;
198
199 if (list_empty(&c->fifo) && list_empty(&c->halt_fifo))
200 return;
201
202 spin_lock_irqsave(&c->fifo_lock, flags);
203 list_for_each_entry_safe(mbo, tmp, &c->fifo, list) {
204 list_del(&mbo->list);
205 spin_unlock_irqrestore(&c->fifo_lock, flags);
206 most_free_mbo_coherent(mbo);
207 spin_lock_irqsave(&c->fifo_lock, flags);
208 }
209 spin_unlock_irqrestore(&c->fifo_lock, flags);
210
211 spin_lock_irqsave(&c->fifo_lock, hf_flags);
212 list_for_each_entry_safe(mbo, tmp, &c->halt_fifo, list) {
213 list_del(&mbo->list);
214 spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
215 most_free_mbo_coherent(mbo);
216 spin_lock_irqsave(&c->fifo_lock, hf_flags);
217 }
218 spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
219
220 if (unlikely((!list_empty(&c->fifo) || !list_empty(&c->halt_fifo))))
221 pr_info("WARN: fifo | trash fifo not empty\n");
222}
223
224/**
225 * flush_trash_fifo - clear the trash fifo
226 * @c: pointer to channel object
227 */
228static int flush_trash_fifo(struct most_c_obj *c)
229{
230 struct mbo *mbo, *tmp;
231 unsigned long flags;
232
233 spin_lock_irqsave(&c->fifo_lock, flags);
234 list_for_each_entry_safe(mbo, tmp, &c->trash_fifo, list) {
235 list_del(&mbo->list);
236 spin_unlock_irqrestore(&c->fifo_lock, flags);
237 most_free_mbo_coherent(mbo);
238 spin_lock_irqsave(&c->fifo_lock, flags);
239 }
240 spin_unlock_irqrestore(&c->fifo_lock, flags);
241 return 0;
242}
243
244/**
245 * most_channel_release - release function of channel object
246 * @kobj: pointer to channel's kobject
247 */
248static void most_channel_release(struct kobject *kobj)
249{
250 struct most_c_obj *c = to_c_obj(kobj);
251
252 kfree(c);
253}
254
255static ssize_t available_directions_show(struct most_c_obj *c,
256 struct most_c_attr *attr,
257 char *buf)
258{
259 unsigned int i = c->channel_id;
260
261 strcpy(buf, "");
262 if (c->iface->channel_vector[i].direction & MOST_CH_RX)
263 strcat(buf, "rx ");
264 if (c->iface->channel_vector[i].direction & MOST_CH_TX)
265 strcat(buf, "tx ");
266 strcat(buf, "\n");
267 return strlen(buf);
268}
269
270static ssize_t available_datatypes_show(struct most_c_obj *c,
271 struct most_c_attr *attr,
272 char *buf)
273{
274 unsigned int i = c->channel_id;
275
276 strcpy(buf, "");
277 if (c->iface->channel_vector[i].data_type & MOST_CH_CONTROL)
278 strcat(buf, "control ");
279 if (c->iface->channel_vector[i].data_type & MOST_CH_ASYNC)
280 strcat(buf, "async ");
281 if (c->iface->channel_vector[i].data_type & MOST_CH_SYNC)
282 strcat(buf, "sync ");
283 if (c->iface->channel_vector[i].data_type & MOST_CH_ISOC)
284 strcat(buf, "isoc ");
285 strcat(buf, "\n");
286 return strlen(buf);
287}
288
289static ssize_t number_of_packet_buffers_show(struct most_c_obj *c,
290 struct most_c_attr *attr,
291 char *buf)
292{
293 unsigned int i = c->channel_id;
294
295 return snprintf(buf, PAGE_SIZE, "%d\n",
296 c->iface->channel_vector[i].num_buffers_packet);
297}
298
299static ssize_t number_of_stream_buffers_show(struct most_c_obj *c,
300 struct most_c_attr *attr,
301 char *buf)
302{
303 unsigned int i = c->channel_id;
304
305 return snprintf(buf, PAGE_SIZE, "%d\n",
306 c->iface->channel_vector[i].num_buffers_streaming);
307}
308
309static ssize_t size_of_packet_buffer_show(struct most_c_obj *c,
310 struct most_c_attr *attr,
311 char *buf)
312{
313 unsigned int i = c->channel_id;
314
315 return snprintf(buf, PAGE_SIZE, "%d\n",
316 c->iface->channel_vector[i].buffer_size_packet);
317}
318
319static ssize_t size_of_stream_buffer_show(struct most_c_obj *c,
320 struct most_c_attr *attr,
321 char *buf)
322{
323 unsigned int i = c->channel_id;
324
325 return snprintf(buf, PAGE_SIZE, "%d\n",
326 c->iface->channel_vector[i].buffer_size_streaming);
327}
328
329static ssize_t channel_starving_show(struct most_c_obj *c,
330 struct most_c_attr *attr,
331 char *buf)
332{
333 return snprintf(buf, PAGE_SIZE, "%d\n", c->is_starving);
334}
335
336static ssize_t set_number_of_buffers_show(struct most_c_obj *c,
337 struct most_c_attr *attr,
338 char *buf)
339{
340 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.num_buffers);
341}
342
343static ssize_t set_number_of_buffers_store(struct most_c_obj *c,
344 struct most_c_attr *attr,
345 const char *buf,
346 size_t count)
347{
348 int ret = kstrtou16(buf, 0, &c->cfg.num_buffers);
349
350 if (ret)
351 return ret;
352 return count;
353}
354
355static ssize_t set_buffer_size_show(struct most_c_obj *c,
356 struct most_c_attr *attr,
357 char *buf)
358{
359 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.buffer_size);
360}
361
362static ssize_t set_buffer_size_store(struct most_c_obj *c,
363 struct most_c_attr *attr,
364 const char *buf,
365 size_t count)
366{
367 int ret = kstrtou16(buf, 0, &c->cfg.buffer_size);
368
369 if (ret)
370 return ret;
371 return count;
372}
373
374static ssize_t set_direction_show(struct most_c_obj *c,
375 struct most_c_attr *attr,
376 char *buf)
377{
378 if (c->cfg.direction & MOST_CH_TX)
379 return snprintf(buf, PAGE_SIZE, "tx\n");
380 else if (c->cfg.direction & MOST_CH_RX)
381 return snprintf(buf, PAGE_SIZE, "rx\n");
382 return snprintf(buf, PAGE_SIZE, "unconfigured\n");
383}
384
385static ssize_t set_direction_store(struct most_c_obj *c,
386 struct most_c_attr *attr,
387 const char *buf,
388 size_t count)
389{
390 if (!strcmp(buf, "dir_rx\n")) {
391 c->cfg.direction = MOST_CH_RX;
392 } else if (!strcmp(buf, "rx\n")) {
393 c->cfg.direction = MOST_CH_RX;
394 } else if (!strcmp(buf, "dir_tx\n")) {
395 c->cfg.direction = MOST_CH_TX;
396 } else if (!strcmp(buf, "tx\n")) {
397 c->cfg.direction = MOST_CH_TX;
398 } else {
399 pr_info("WARN: invalid attribute settings\n");
400 return -EINVAL;
401 }
402 return count;
403}
404
405static ssize_t set_datatype_show(struct most_c_obj *c,
406 struct most_c_attr *attr,
407 char *buf)
408{
409 int i;
410
411 for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
412 if (c->cfg.data_type & ch_data_type[i].most_ch_data_type)
413 return snprintf(buf, PAGE_SIZE, ch_data_type[i].name);
414 }
415 return snprintf(buf, PAGE_SIZE, "unconfigured\n");
416}
417
418static ssize_t set_datatype_store(struct most_c_obj *c,
419 struct most_c_attr *attr,
420 const char *buf,
421 size_t count)
422{
423 int i;
424
425 for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
426 if (!strcmp(buf, ch_data_type[i].name)) {
427 c->cfg.data_type = ch_data_type[i].most_ch_data_type;
428 break;
429 }
430 }
431
432 if (i == ARRAY_SIZE(ch_data_type)) {
433 pr_info("WARN: invalid attribute settings\n");
434 return -EINVAL;
435 }
436 return count;
437}
438
439static ssize_t set_subbuffer_size_show(struct most_c_obj *c,
440 struct most_c_attr *attr,
441 char *buf)
442{
443 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.subbuffer_size);
444}
445
446static ssize_t set_subbuffer_size_store(struct most_c_obj *c,
447 struct most_c_attr *attr,
448 const char *buf,
449 size_t count)
450{
451 int ret = kstrtou16(buf, 0, &c->cfg.subbuffer_size);
452
453 if (ret)
454 return ret;
455 return count;
456}
457
458static ssize_t set_packets_per_xact_show(struct most_c_obj *c,
459 struct most_c_attr *attr,
460 char *buf)
461{
462 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.packets_per_xact);
463}
464
465static ssize_t set_packets_per_xact_store(struct most_c_obj *c,
466 struct most_c_attr *attr,
467 const char *buf,
468 size_t count)
469{
470 int ret = kstrtou16(buf, 0, &c->cfg.packets_per_xact);
471
472 if (ret)
473 return ret;
474 return count;
475}
476
477static struct most_c_attr most_c_attrs[] = {
478 __ATTR_RO(available_directions),
479 __ATTR_RO(available_datatypes),
480 __ATTR_RO(number_of_packet_buffers),
481 __ATTR_RO(number_of_stream_buffers),
482 __ATTR_RO(size_of_stream_buffer),
483 __ATTR_RO(size_of_packet_buffer),
484 __ATTR_RO(channel_starving),
485 __ATTR_RW(set_buffer_size),
486 __ATTR_RW(set_number_of_buffers),
487 __ATTR_RW(set_direction),
488 __ATTR_RW(set_datatype),
489 __ATTR_RW(set_subbuffer_size),
490 __ATTR_RW(set_packets_per_xact),
491};
492
493/**
494 * most_channel_def_attrs - array of default attributes of channel object
495 */
496static struct attribute *most_channel_def_attrs[] = {
497 &most_c_attrs[0].attr,
498 &most_c_attrs[1].attr,
499 &most_c_attrs[2].attr,
500 &most_c_attrs[3].attr,
501 &most_c_attrs[4].attr,
502 &most_c_attrs[5].attr,
503 &most_c_attrs[6].attr,
504 &most_c_attrs[7].attr,
505 &most_c_attrs[8].attr,
506 &most_c_attrs[9].attr,
507 &most_c_attrs[10].attr,
508 &most_c_attrs[11].attr,
509 &most_c_attrs[12].attr,
510 NULL,
511};
512
513static struct kobj_type most_channel_ktype = {
514 .sysfs_ops = &most_channel_sysfs_ops,
515 .release = most_channel_release,
516 .default_attrs = most_channel_def_attrs,
517};
518
519static struct kset *most_channel_kset;
520
521/**
522 * create_most_c_obj - allocates a channel object
523 * @name: name of the channel object
524 * @parent: parent kobject
525 *
526 * This create a channel object and registers it with sysfs.
527 * Returns a pointer to the object or NULL when something went wrong.
528 */
529static struct most_c_obj *
530create_most_c_obj(const char *name, struct kobject *parent)
531{
532 struct most_c_obj *c;
533 int retval;
534
535 c = kzalloc(sizeof(*c), GFP_KERNEL);
536 if (!c)
537 return NULL;
538 c->kobj.kset = most_channel_kset;
539 retval = kobject_init_and_add(&c->kobj, &most_channel_ktype, parent,
540 "%s", name);
541 if (retval) {
542 kobject_put(&c->kobj);
543 return NULL;
544 }
545 kobject_uevent(&c->kobj, KOBJ_ADD);
546 return c;
547}
548
549/* ___ ___
550 * ___I N S T A N C E___
551 */
552
553static struct list_head instance_list;
554
555/**
556 * struct most_inst_attribute - to access the attributes of instance object
557 * @attr: attributes of an instance
558 * @show: pointer to the show function
559 * @store: pointer to the store function
560 */
561struct most_inst_attribute {
562 struct attribute attr;
563 ssize_t (*show)(struct most_inst_obj *d,
564 struct most_inst_attribute *attr,
565 char *buf);
566 ssize_t (*store)(struct most_inst_obj *d,
567 struct most_inst_attribute *attr,
568 const char *buf,
569 size_t count);
570};
571
572#define to_instance_attr(a) \
573 container_of(a, struct most_inst_attribute, attr)
574
575/**
576 * instance_attr_show - show function for an instance object
577 * @kobj: pointer to kobject
578 * @attr: pointer to attribute struct
579 * @buf: buffer
580 */
581static ssize_t instance_attr_show(struct kobject *kobj,
582 struct attribute *attr,
583 char *buf)
584{
585 struct most_inst_attribute *instance_attr;
586 struct most_inst_obj *instance_obj;
587
588 instance_attr = to_instance_attr(attr);
589 instance_obj = to_inst_obj(kobj);
590
591 if (!instance_attr->show)
592 return -EIO;
593
594 return instance_attr->show(instance_obj, instance_attr, buf);
595}
596
597/**
598 * instance_attr_store - store function for an instance object
599 * @kobj: pointer to kobject
600 * @attr: pointer to attribute struct
601 * @buf: buffer
602 * @len: length of buffer
603 */
604static ssize_t instance_attr_store(struct kobject *kobj,
605 struct attribute *attr,
606 const char *buf,
607 size_t len)
608{
609 struct most_inst_attribute *instance_attr;
610 struct most_inst_obj *instance_obj;
611
612 instance_attr = to_instance_attr(attr);
613 instance_obj = to_inst_obj(kobj);
614
615 if (!instance_attr->store)
616 return -EIO;
617
618 return instance_attr->store(instance_obj, instance_attr, buf, len);
619}
620
621static const struct sysfs_ops most_inst_sysfs_ops = {
622 .show = instance_attr_show,
623 .store = instance_attr_store,
624};
625
626/**
627 * most_inst_release - release function for instance object
628 * @kobj: pointer to instance's kobject
629 *
630 * This frees the allocated memory for the instance object
631 */
632static void most_inst_release(struct kobject *kobj)
633{
634 struct most_inst_obj *inst = to_inst_obj(kobj);
635
636 kfree(inst);
637}
638
639static ssize_t description_show(struct most_inst_obj *instance_obj,
640 struct most_inst_attribute *attr,
641 char *buf)
642{
643 return snprintf(buf, PAGE_SIZE, "%s\n",
644 instance_obj->iface->description);
645}
646
647static ssize_t interface_show(struct most_inst_obj *instance_obj,
648 struct most_inst_attribute *attr,
649 char *buf)
650{
651 switch (instance_obj->iface->interface) {
652 case ITYPE_LOOPBACK:
653 return snprintf(buf, PAGE_SIZE, "loopback\n");
654 case ITYPE_I2C:
655 return snprintf(buf, PAGE_SIZE, "i2c\n");
656 case ITYPE_I2S:
657 return snprintf(buf, PAGE_SIZE, "i2s\n");
658 case ITYPE_TSI:
659 return snprintf(buf, PAGE_SIZE, "tsi\n");
660 case ITYPE_HBI:
661 return snprintf(buf, PAGE_SIZE, "hbi\n");
662 case ITYPE_MEDIALB_DIM:
663 return snprintf(buf, PAGE_SIZE, "mlb_dim\n");
664 case ITYPE_MEDIALB_DIM2:
665 return snprintf(buf, PAGE_SIZE, "mlb_dim2\n");
666 case ITYPE_USB:
667 return snprintf(buf, PAGE_SIZE, "usb\n");
668 case ITYPE_PCIE:
669 return snprintf(buf, PAGE_SIZE, "pcie\n");
670 }
671 return snprintf(buf, PAGE_SIZE, "unknown\n");
672}
673
674static struct most_inst_attribute most_inst_attr_description =
675 __ATTR_RO(description);
676
677static struct most_inst_attribute most_inst_attr_interface =
678 __ATTR_RO(interface);
679
680static struct attribute *most_inst_def_attrs[] = {
681 &most_inst_attr_description.attr,
682 &most_inst_attr_interface.attr,
683 NULL,
684};
685
686static struct kobj_type most_inst_ktype = {
687 .sysfs_ops = &most_inst_sysfs_ops,
688 .release = most_inst_release,
689 .default_attrs = most_inst_def_attrs,
690};
691
692static struct kset *most_inst_kset;
693
694/**
695 * create_most_inst_obj - creates an instance object
696 * @name: name of the object to be created
697 *
698 * This allocates memory for an instance structure, assigns the proper kset
699 * and registers it with sysfs.
700 *
701 * Returns a pointer to the instance object or NULL when something went wrong.
702 */
703static struct most_inst_obj *create_most_inst_obj(const char *name)
704{
705 struct most_inst_obj *inst;
706 int retval;
707
708 inst = kzalloc(sizeof(*inst), GFP_KERNEL);
709 if (!inst)
710 return NULL;
711 inst->kobj.kset = most_inst_kset;
712 retval = kobject_init_and_add(&inst->kobj, &most_inst_ktype, NULL,
713 "%s", name);
714 if (retval) {
715 kobject_put(&inst->kobj);
716 return NULL;
717 }
718 kobject_uevent(&inst->kobj, KOBJ_ADD);
719 return inst;
720}
721
722/**
723 * destroy_most_inst_obj - MOST instance release function
724 * @inst: pointer to the instance object
725 *
726 * This decrements the reference counter of the instance object.
727 * If the reference count turns zero, its release function is called
728 */
729static void destroy_most_inst_obj(struct most_inst_obj *inst)
730{
731 struct most_c_obj *c, *tmp;
732
733 list_for_each_entry_safe(c, tmp, &inst->channel_list, list) {
734 flush_trash_fifo(c);
735 flush_channel_fifos(c);
736 kobject_put(&c->kobj);
737 }
738 kobject_put(&inst->kobj);
739}
740
741/* ___ ___
742 * ___A I M___
743 */
744struct most_aim_obj {
745 struct kobject kobj;
746 struct list_head list;
747 struct most_aim *driver;
748};
749
750#define to_aim_obj(d) container_of(d, struct most_aim_obj, kobj)
751
752static struct list_head aim_list;
753
754/**
755 * struct most_aim_attribute - to access the attributes of AIM object
756 * @attr: attributes of an AIM
757 * @show: pointer to the show function
758 * @store: pointer to the store function
759 */
760struct most_aim_attribute {
761 struct attribute attr;
762 ssize_t (*show)(struct most_aim_obj *d,
763 struct most_aim_attribute *attr,
764 char *buf);
765 ssize_t (*store)(struct most_aim_obj *d,
766 struct most_aim_attribute *attr,
767 const char *buf,
768 size_t count);
769};
770
771#define to_aim_attr(a) container_of(a, struct most_aim_attribute, attr)
772
773/**
774 * aim_attr_show - show function of an AIM object
775 * @kobj: pointer to kobject
776 * @attr: pointer to attribute struct
777 * @buf: buffer
778 */
779static ssize_t aim_attr_show(struct kobject *kobj,
780 struct attribute *attr,
781 char *buf)
782{
783 struct most_aim_attribute *aim_attr;
784 struct most_aim_obj *aim_obj;
785
786 aim_attr = to_aim_attr(attr);
787 aim_obj = to_aim_obj(kobj);
788
789 if (!aim_attr->show)
790 return -EIO;
791
792 return aim_attr->show(aim_obj, aim_attr, buf);
793}
794
795/**
796 * aim_attr_store - store function of an AIM object
797 * @kobj: pointer to kobject
798 * @attr: pointer to attribute struct
799 * @buf: buffer
800 * @len: length of buffer
801 */
802static ssize_t aim_attr_store(struct kobject *kobj,
803 struct attribute *attr,
804 const char *buf,
805 size_t len)
806{
807 struct most_aim_attribute *aim_attr;
808 struct most_aim_obj *aim_obj;
809
810 aim_attr = to_aim_attr(attr);
811 aim_obj = to_aim_obj(kobj);
812
813 if (!aim_attr->store)
814 return -EIO;
815 return aim_attr->store(aim_obj, aim_attr, buf, len);
816}
817
818static const struct sysfs_ops most_aim_sysfs_ops = {
819 .show = aim_attr_show,
820 .store = aim_attr_store,
821};
822
823/**
824 * most_aim_release - AIM release function
825 * @kobj: pointer to AIM's kobject
826 */
827static void most_aim_release(struct kobject *kobj)
828{
829 struct most_aim_obj *aim_obj = to_aim_obj(kobj);
830
831 kfree(aim_obj);
832}
833
834static ssize_t links_show(struct most_aim_obj *aim_obj,
835 struct most_aim_attribute *attr,
836 char *buf)
837{
838 struct most_c_obj *c;
839 struct most_inst_obj *i;
840 int offs = 0;
841
842 list_for_each_entry(i, &instance_list, list) {
843 list_for_each_entry(c, &i->channel_list, list) {
844 if (c->aim0.ptr == aim_obj->driver ||
845 c->aim1.ptr == aim_obj->driver) {
846 offs += snprintf(buf + offs, PAGE_SIZE - offs,
847 "%s:%s\n",
848 kobject_name(&i->kobj),
849 kobject_name(&c->kobj));
850 }
851 }
852 }
853
854 return offs;
855}
856
857/**
858 * split_string - parses and changes string in the buffer buf and
859 * splits it into two mandatory and one optional substrings.
860 *
861 * @buf: complete string from attribute 'add_channel'
862 * @a: address of pointer to 1st substring (=instance name)
863 * @b: address of pointer to 2nd substring (=channel name)
864 * @c: optional address of pointer to 3rd substring (=user defined name)
865 *
866 * Examples:
867 *
868 * Input: "mdev0:ch6:my_channel\n" or
869 * "mdev0:ch6:my_channel"
870 *
871 * Output: *a -> "mdev0", *b -> "ch6", *c -> "my_channel"
872 *
873 * Input: "mdev1:ep81\n"
874 * Output: *a -> "mdev1", *b -> "ep81", *c -> ""
875 *
876 * Input: "mdev1:ep81"
877 * Output: *a -> "mdev1", *b -> "ep81", *c == NULL
878 */
879static int split_string(char *buf, char **a, char **b, char **c)
880{
881 *a = strsep(&buf, ":");
882 if (!*a)
883 return -EIO;
884
885 *b = strsep(&buf, ":\n");
886 if (!*b)
887 return -EIO;
888
889 if (c)
890 *c = strsep(&buf, ":\n");
891
892 return 0;
893}
894
895/**
896 * get_channel_by_name - get pointer to channel object
897 * @mdev: name of the device instance
898 * @mdev_ch: name of the respective channel
899 *
900 * This retrieves the pointer to a channel object.
901 */
902static struct
903most_c_obj *get_channel_by_name(char *mdev, char *mdev_ch)
904{
905 struct most_c_obj *c, *tmp;
906 struct most_inst_obj *i, *i_tmp;
907 int found = 0;
908
909 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
910 if (!strcmp(kobject_name(&i->kobj), mdev)) {
911 found++;
912 break;
913 }
914 }
915 if (unlikely(!found))
916 return ERR_PTR(-EIO);
917
918 list_for_each_entry_safe(c, tmp, &i->channel_list, list) {
919 if (!strcmp(kobject_name(&c->kobj), mdev_ch)) {
920 found++;
921 break;
922 }
923 }
924 if (unlikely(found < 2))
925 return ERR_PTR(-EIO);
926 return c;
927}
928
929/**
930 * add_link_store - store() function for add_link attribute
931 * @aim_obj: pointer to AIM object
932 * @attr: its attributes
933 * @buf: buffer
934 * @len: buffer length
935 *
936 * This parses the string given by buf and splits it into
937 * three substrings. Note: third substring is optional. In case a cdev
938 * AIM is loaded the optional 3rd substring will make up the name of
939 * device node in the /dev directory. If omitted, the device node will
940 * inherit the channel's name within sysfs.
941 *
942 * Searches for a pair of device and channel and probes the AIM
943 *
944 * Example:
945 * (1) echo "mdev0:ch6:my_rxchannel" >add_link
946 * (2) echo "mdev1:ep81" >add_link
947 *
948 * (1) would create the device node /dev/my_rxchannel
949 * (2) would create the device node /dev/mdev1-ep81
950 */
951static ssize_t add_link_store(struct most_aim_obj *aim_obj,
952 struct most_aim_attribute *attr,
953 const char *buf,
954 size_t len)
955{
956 struct most_c_obj *c;
957 struct most_aim **aim_ptr;
958 char buffer[STRING_SIZE];
959 char *mdev;
960 char *mdev_ch;
961 char *mdev_devnod;
962 char devnod_buf[STRING_SIZE];
963 int ret;
964 size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
965
966 strlcpy(buffer, buf, max_len);
967
968 ret = split_string(buffer, &mdev, &mdev_ch, &mdev_devnod);
969 if (ret)
970 return ret;
971
972 if (!mdev_devnod || *mdev_devnod == 0) {
973 snprintf(devnod_buf, sizeof(devnod_buf), "%s-%s", mdev,
974 mdev_ch);
975 mdev_devnod = devnod_buf;
976 }
977
978 c = get_channel_by_name(mdev, mdev_ch);
979 if (IS_ERR(c))
980 return -ENODEV;
981
982 if (!c->aim0.ptr)
983 aim_ptr = &c->aim0.ptr;
984 else if (!c->aim1.ptr)
985 aim_ptr = &c->aim1.ptr;
986 else
987 return -ENOSPC;
988
989 *aim_ptr = aim_obj->driver;
990 ret = aim_obj->driver->probe_channel(c->iface, c->channel_id,
991 &c->cfg, &c->kobj, mdev_devnod);
992 if (ret) {
993 *aim_ptr = NULL;
994 return ret;
995 }
996
997 return len;
998}
999
1000/**
1001 * remove_link_store - store function for remove_link attribute
1002 * @aim_obj: pointer to AIM object
1003 * @attr: its attributes
1004 * @buf: buffer
1005 * @len: buffer length
1006 *
1007 * Example:
1008 * echo "mdev0:ep81" >remove_link
1009 */
1010static ssize_t remove_link_store(struct most_aim_obj *aim_obj,
1011 struct most_aim_attribute *attr,
1012 const char *buf,
1013 size_t len)
1014{
1015 struct most_c_obj *c;
1016 char buffer[STRING_SIZE];
1017 char *mdev;
1018 char *mdev_ch;
1019 int ret;
1020 size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
1021
1022 strlcpy(buffer, buf, max_len);
1023 ret = split_string(buffer, &mdev, &mdev_ch, NULL);
1024 if (ret)
1025 return ret;
1026
1027 c = get_channel_by_name(mdev, mdev_ch);
1028 if (IS_ERR(c))
1029 return -ENODEV;
1030
1031 if (aim_obj->driver->disconnect_channel(c->iface, c->channel_id))
1032 return -EIO;
1033 if (c->aim0.ptr == aim_obj->driver)
1034 c->aim0.ptr = NULL;
1035 if (c->aim1.ptr == aim_obj->driver)
1036 c->aim1.ptr = NULL;
1037 return len;
1038}
1039
1040static struct most_aim_attribute most_aim_attrs[] = {
1041 __ATTR_RO(links),
1042 __ATTR_WO(add_link),
1043 __ATTR_WO(remove_link),
1044};
1045
1046static struct attribute *most_aim_def_attrs[] = {
1047 &most_aim_attrs[0].attr,
1048 &most_aim_attrs[1].attr,
1049 &most_aim_attrs[2].attr,
1050 NULL,
1051};
1052
1053static struct kobj_type most_aim_ktype = {
1054 .sysfs_ops = &most_aim_sysfs_ops,
1055 .release = most_aim_release,
1056 .default_attrs = most_aim_def_attrs,
1057};
1058
1059static struct kset *most_aim_kset;
1060
1061/**
1062 * create_most_aim_obj - creates an AIM object
1063 * @name: name of the AIM
1064 *
1065 * This creates an AIM object assigns the proper kset and registers
1066 * it with sysfs.
1067 * Returns a pointer to the object or NULL if something went wrong.
1068 */
1069static struct most_aim_obj *create_most_aim_obj(const char *name)
1070{
1071 struct most_aim_obj *most_aim;
1072 int retval;
1073
1074 most_aim = kzalloc(sizeof(*most_aim), GFP_KERNEL);
1075 if (!most_aim)
1076 return NULL;
1077 most_aim->kobj.kset = most_aim_kset;
1078 retval = kobject_init_and_add(&most_aim->kobj, &most_aim_ktype,
1079 NULL, "%s", name);
1080 if (retval) {
1081 kobject_put(&most_aim->kobj);
1082 return NULL;
1083 }
1084 kobject_uevent(&most_aim->kobj, KOBJ_ADD);
1085 return most_aim;
1086}
1087
1088/**
1089 * destroy_most_aim_obj - AIM release function
1090 * @p: pointer to AIM object
1091 *
1092 * This decrements the reference counter of the AIM object. If the
1093 * reference count turns zero, its release function will be called.
1094 */
1095static void destroy_most_aim_obj(struct most_aim_obj *p)
1096{
1097 kobject_put(&p->kobj);
1098}
1099
1100/* ___ ___
1101 * ___C O R E___
1102 */
1103
1104/**
1105 * Instantiation of the MOST bus
1106 */
1107static struct bus_type most_bus = {
1108 .name = "most",
1109};
1110
1111/**
1112 * Instantiation of the core driver
1113 */
1114static struct device_driver mostcore = {
1115 .name = "mostcore",
1116 .bus = &most_bus,
1117};
1118
1119static inline void trash_mbo(struct mbo *mbo)
1120{
1121 unsigned long flags;
1122 struct most_c_obj *c = mbo->context;
1123
1124 spin_lock_irqsave(&c->fifo_lock, flags);
1125 list_add(&mbo->list, &c->trash_fifo);
1126 spin_unlock_irqrestore(&c->fifo_lock, flags);
1127}
1128
1129static bool hdm_mbo_ready(struct most_c_obj *c)
1130{
1131 bool empty;
1132
1133 if (c->enqueue_halt)
1134 return false;
1135
1136 spin_lock_irq(&c->fifo_lock);
1137 empty = list_empty(&c->halt_fifo);
1138 spin_unlock_irq(&c->fifo_lock);
1139
1140 return !empty;
1141}
1142
1143static void nq_hdm_mbo(struct mbo *mbo)
1144{
1145 unsigned long flags;
1146 struct most_c_obj *c = mbo->context;
1147
1148 spin_lock_irqsave(&c->fifo_lock, flags);
1149 list_add_tail(&mbo->list, &c->halt_fifo);
1150 spin_unlock_irqrestore(&c->fifo_lock, flags);
1151 wake_up_interruptible(&c->hdm_fifo_wq);
1152}
1153
1154static int hdm_enqueue_thread(void *data)
1155{
1156 struct most_c_obj *c = data;
1157 struct mbo *mbo;
1158 int ret;
1159 typeof(c->iface->enqueue) enqueue = c->iface->enqueue;
1160
1161 while (likely(!kthread_should_stop())) {
1162 wait_event_interruptible(c->hdm_fifo_wq,
1163 hdm_mbo_ready(c) ||
1164 kthread_should_stop());
1165
1166 mutex_lock(&c->nq_mutex);
1167 spin_lock_irq(&c->fifo_lock);
1168 if (unlikely(c->enqueue_halt || list_empty(&c->halt_fifo))) {
1169 spin_unlock_irq(&c->fifo_lock);
1170 mutex_unlock(&c->nq_mutex);
1171 continue;
1172 }
1173
1174 mbo = list_pop_mbo(&c->halt_fifo);
1175 spin_unlock_irq(&c->fifo_lock);
1176
1177 if (c->cfg.direction == MOST_CH_RX)
1178 mbo->buffer_length = c->cfg.buffer_size;
1179
1180 ret = enqueue(mbo->ifp, mbo->hdm_channel_id, mbo);
1181 mutex_unlock(&c->nq_mutex);
1182
1183 if (unlikely(ret)) {
1184 pr_err("hdm enqueue failed\n");
1185 nq_hdm_mbo(mbo);
1186 c->hdm_enqueue_task = NULL;
1187 return 0;
1188 }
1189 }
1190
1191 return 0;
1192}
1193
1194static int run_enqueue_thread(struct most_c_obj *c, int channel_id)
1195{
1196 struct task_struct *task =
1197 kthread_run(hdm_enqueue_thread, c, "hdm_fifo_%d",
1198 channel_id);
1199
1200 if (IS_ERR(task))
1201 return PTR_ERR(task);
1202
1203 c->hdm_enqueue_task = task;
1204 return 0;
1205}
1206
1207/**
1208 * arm_mbo - recycle MBO for further usage
1209 * @mbo: buffer object
1210 *
1211 * This puts an MBO back to the list to have it ready for up coming
1212 * tx transactions.
1213 *
1214 * In case the MBO belongs to a channel that recently has been
1215 * poisoned, the MBO is scheduled to be trashed.
1216 * Calls the completion handler of an attached AIM.
1217 */
1218static void arm_mbo(struct mbo *mbo)
1219{
1220 unsigned long flags;
1221 struct most_c_obj *c;
1222
1223 BUG_ON((!mbo) || (!mbo->context));
1224 c = mbo->context;
1225
1226 if (c->is_poisoned) {
1227 trash_mbo(mbo);
1228 return;
1229 }
1230
1231 spin_lock_irqsave(&c->fifo_lock, flags);
1232 ++*mbo->num_buffers_ptr;
1233 list_add_tail(&mbo->list, &c->fifo);
1234 spin_unlock_irqrestore(&c->fifo_lock, flags);
1235
1236 if (c->aim0.refs && c->aim0.ptr->tx_completion)
1237 c->aim0.ptr->tx_completion(c->iface, c->channel_id);
1238
1239 if (c->aim1.refs && c->aim1.ptr->tx_completion)
1240 c->aim1.ptr->tx_completion(c->iface, c->channel_id);
1241}
1242
1243/**
1244 * arm_mbo_chain - helper function that arms an MBO chain for the HDM
1245 * @c: pointer to interface channel
1246 * @dir: direction of the channel
1247 * @compl: pointer to completion function
1248 *
1249 * This allocates buffer objects including the containing DMA coherent
1250 * buffer and puts them in the fifo.
1251 * Buffers of Rx channels are put in the kthread fifo, hence immediately
1252 * submitted to the HDM.
1253 *
1254 * Returns the number of allocated and enqueued MBOs.
1255 */
1256static int arm_mbo_chain(struct most_c_obj *c, int dir,
1257 void (*compl)(struct mbo *))
1258{
1259 unsigned int i;
1260 int retval;
1261 struct mbo *mbo;
1262 u32 coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len;
1263
1264 atomic_set(&c->mbo_nq_level, 0);
1265
1266 for (i = 0; i < c->cfg.num_buffers; i++) {
1267 mbo = kzalloc(sizeof(*mbo), GFP_KERNEL);
1268 if (!mbo) {
1269 retval = i;
1270 goto _exit;
1271 }
1272 mbo->context = c;
1273 mbo->ifp = c->iface;
1274 mbo->hdm_channel_id = c->channel_id;
1275 mbo->virt_address = dma_alloc_coherent(NULL,
1276 coherent_buf_size,
1277 &mbo->bus_address,
1278 GFP_KERNEL);
1279 if (!mbo->virt_address) {
1280 pr_info("WARN: No DMA coherent buffer.\n");
1281 retval = i;
1282 goto _error1;
1283 }
1284 mbo->complete = compl;
1285 mbo->num_buffers_ptr = &dummy_num_buffers;
1286 if (dir == MOST_CH_RX) {
1287 nq_hdm_mbo(mbo);
1288 atomic_inc(&c->mbo_nq_level);
1289 } else {
1290 arm_mbo(mbo);
1291 }
1292 }
1293 return i;
1294
1295_error1:
1296 kfree(mbo);
1297_exit:
1298 return retval;
1299}
1300
1301/**
1302 * most_submit_mbo - submits an MBO to fifo
1303 * @mbo: pointer to the MBO
1304 */
1305void most_submit_mbo(struct mbo *mbo)
1306{
1307 if (WARN_ONCE(!mbo || !mbo->context,
1308 "bad mbo or missing channel reference\n"))
1309 return;
1310
1311 nq_hdm_mbo(mbo);
1312}
1313EXPORT_SYMBOL_GPL(most_submit_mbo);
1314
1315/**
1316 * most_write_completion - write completion handler
1317 * @mbo: pointer to MBO
1318 *
1319 * This recycles the MBO for further usage. In case the channel has been
1320 * poisoned, the MBO is scheduled to be trashed.
1321 */
1322static void most_write_completion(struct mbo *mbo)
1323{
1324 struct most_c_obj *c;
1325
1326 BUG_ON((!mbo) || (!mbo->context));
1327
1328 c = mbo->context;
1329 if (mbo->status == MBO_E_INVAL)
1330 pr_info("WARN: Tx MBO status: invalid\n");
1331 if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE)))
1332 trash_mbo(mbo);
1333 else
1334 arm_mbo(mbo);
1335}
1336
1337/**
1338 * get_channel_by_iface - get pointer to channel object
1339 * @iface: pointer to interface instance
1340 * @id: channel ID
1341 *
1342 * This retrieves a pointer to a channel of the given interface and channel ID.
1343 */
1344static struct
1345most_c_obj *get_channel_by_iface(struct most_interface *iface, int id)
1346{
1347 struct most_inst_obj *i;
1348
1349 if (unlikely(!iface)) {
1350 pr_err("Bad interface\n");
1351 return NULL;
1352 }
1353 if (unlikely((id < 0) || (id >= iface->num_channels))) {
1354 pr_err("Channel index (%d) out of range\n", id);
1355 return NULL;
1356 }
1357 i = iface->priv;
1358 if (unlikely(!i)) {
1359 pr_err("interface is not registered\n");
1360 return NULL;
1361 }
1362 return i->channel[id];
1363}
1364
1365int channel_has_mbo(struct most_interface *iface, int id, struct most_aim *aim)
1366{
1367 struct most_c_obj *c = get_channel_by_iface(iface, id);
1368 unsigned long flags;
1369 int empty;
1370
1371 if (unlikely(!c))
1372 return -EINVAL;
1373
1374 if (c->aim0.refs && c->aim1.refs &&
1375 ((aim == c->aim0.ptr && c->aim0.num_buffers <= 0) ||
1376 (aim == c->aim1.ptr && c->aim1.num_buffers <= 0)))
1377 return 0;
1378
1379 spin_lock_irqsave(&c->fifo_lock, flags);
1380 empty = list_empty(&c->fifo);
1381 spin_unlock_irqrestore(&c->fifo_lock, flags);
1382 return !empty;
1383}
1384EXPORT_SYMBOL_GPL(channel_has_mbo);
1385
1386/**
1387 * most_get_mbo - get pointer to an MBO of pool
1388 * @iface: pointer to interface instance
1389 * @id: channel ID
1390 *
1391 * This attempts to get a free buffer out of the channel fifo.
1392 * Returns a pointer to MBO on success or NULL otherwise.
1393 */
1394struct mbo *most_get_mbo(struct most_interface *iface, int id,
1395 struct most_aim *aim)
1396{
1397 struct mbo *mbo;
1398 struct most_c_obj *c;
1399 unsigned long flags;
1400 int *num_buffers_ptr;
1401
1402 c = get_channel_by_iface(iface, id);
1403 if (unlikely(!c))
1404 return NULL;
1405
1406 if (c->aim0.refs && c->aim1.refs &&
1407 ((aim == c->aim0.ptr && c->aim0.num_buffers <= 0) ||
1408 (aim == c->aim1.ptr && c->aim1.num_buffers <= 0)))
1409 return NULL;
1410
1411 if (aim == c->aim0.ptr)
1412 num_buffers_ptr = &c->aim0.num_buffers;
1413 else if (aim == c->aim1.ptr)
1414 num_buffers_ptr = &c->aim1.num_buffers;
1415 else
1416 num_buffers_ptr = &dummy_num_buffers;
1417
1418 spin_lock_irqsave(&c->fifo_lock, flags);
1419 if (list_empty(&c->fifo)) {
1420 spin_unlock_irqrestore(&c->fifo_lock, flags);
1421 return NULL;
1422 }
1423 mbo = list_pop_mbo(&c->fifo);
1424 --*num_buffers_ptr;
1425 spin_unlock_irqrestore(&c->fifo_lock, flags);
1426
1427 mbo->num_buffers_ptr = num_buffers_ptr;
1428 mbo->buffer_length = c->cfg.buffer_size;
1429 return mbo;
1430}
1431EXPORT_SYMBOL_GPL(most_get_mbo);
1432
1433/**
1434 * most_put_mbo - return buffer to pool
1435 * @mbo: buffer object
1436 */
1437void most_put_mbo(struct mbo *mbo)
1438{
1439 struct most_c_obj *c = mbo->context;
1440
1441 if (c->cfg.direction == MOST_CH_TX) {
1442 arm_mbo(mbo);
1443 return;
1444 }
1445 nq_hdm_mbo(mbo);
1446 atomic_inc(&c->mbo_nq_level);
1447}
1448EXPORT_SYMBOL_GPL(most_put_mbo);
1449
1450/**
1451 * most_read_completion - read completion handler
1452 * @mbo: pointer to MBO
1453 *
1454 * This function is called by the HDM when data has been received from the
1455 * hardware and copied to the buffer of the MBO.
1456 *
1457 * In case the channel has been poisoned it puts the buffer in the trash queue.
1458 * Otherwise, it passes the buffer to an AIM for further processing.
1459 */
1460static void most_read_completion(struct mbo *mbo)
1461{
1462 struct most_c_obj *c = mbo->context;
1463
1464 if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE))) {
1465 trash_mbo(mbo);
1466 return;
1467 }
1468
1469 if (mbo->status == MBO_E_INVAL) {
1470 nq_hdm_mbo(mbo);
1471 atomic_inc(&c->mbo_nq_level);
1472 return;
1473 }
1474
1475 if (atomic_sub_and_test(1, &c->mbo_nq_level))
1476 c->is_starving = 1;
1477
1478 if (c->aim0.refs && c->aim0.ptr->rx_completion &&
1479 c->aim0.ptr->rx_completion(mbo) == 0)
1480 return;
1481
1482 if (c->aim1.refs && c->aim1.ptr->rx_completion &&
1483 c->aim1.ptr->rx_completion(mbo) == 0)
1484 return;
1485
1486 most_put_mbo(mbo);
1487}
1488
1489/**
1490 * most_start_channel - prepares a channel for communication
1491 * @iface: pointer to interface instance
1492 * @id: channel ID
1493 *
1494 * This prepares the channel for usage. Cross-checks whether the
1495 * channel's been properly configured.
1496 *
1497 * Returns 0 on success or error code otherwise.
1498 */
1499int most_start_channel(struct most_interface *iface, int id,
1500 struct most_aim *aim)
1501{
1502 int num_buffer;
1503 int ret;
1504 struct most_c_obj *c = get_channel_by_iface(iface, id);
1505
1506 if (unlikely(!c))
1507 return -EINVAL;
1508
1509 mutex_lock(&c->start_mutex);
1510 if (c->aim0.refs + c->aim1.refs > 0)
1511 goto out; /* already started by other aim */
1512
1513 if (!try_module_get(iface->mod)) {
1514 pr_info("failed to acquire HDM lock\n");
1515 mutex_unlock(&c->start_mutex);
1516 return -ENOLCK;
1517 }
1518
1519 c->cfg.extra_len = 0;
1520 if (c->iface->configure(c->iface, c->channel_id, &c->cfg)) {
1521 pr_info("channel configuration failed. Go check settings...\n");
1522 ret = -EINVAL;
1523 goto error;
1524 }
1525
1526 init_waitqueue_head(&c->hdm_fifo_wq);
1527
1528 if (c->cfg.direction == MOST_CH_RX)
1529 num_buffer = arm_mbo_chain(c, c->cfg.direction,
1530 most_read_completion);
1531 else
1532 num_buffer = arm_mbo_chain(c, c->cfg.direction,
1533 most_write_completion);
1534 if (unlikely(!num_buffer)) {
1535 pr_info("failed to allocate memory\n");
1536 ret = -ENOMEM;
1537 goto error;
1538 }
1539
1540 ret = run_enqueue_thread(c, id);
1541 if (ret)
1542 goto error;
1543
1544 c->is_starving = 0;
1545 c->aim0.num_buffers = c->cfg.num_buffers / 2;
1546 c->aim1.num_buffers = c->cfg.num_buffers - c->aim0.num_buffers;
1547 atomic_set(&c->mbo_ref, num_buffer);
1548
1549out:
1550 if (aim == c->aim0.ptr)
1551 c->aim0.refs++;
1552 if (aim == c->aim1.ptr)
1553 c->aim1.refs++;
1554 mutex_unlock(&c->start_mutex);
1555 return 0;
1556
1557error:
1558 module_put(iface->mod);
1559 mutex_unlock(&c->start_mutex);
1560 return ret;
1561}
1562EXPORT_SYMBOL_GPL(most_start_channel);
1563
1564/**
1565 * most_stop_channel - stops a running channel
1566 * @iface: pointer to interface instance
1567 * @id: channel ID
1568 */
1569int most_stop_channel(struct most_interface *iface, int id,
1570 struct most_aim *aim)
1571{
1572 struct most_c_obj *c;
1573
1574 if (unlikely((!iface) || (id >= iface->num_channels) || (id < 0))) {
1575 pr_err("Bad interface or index out of range\n");
1576 return -EINVAL;
1577 }
1578 c = get_channel_by_iface(iface, id);
1579 if (unlikely(!c))
1580 return -EINVAL;
1581
1582 mutex_lock(&c->start_mutex);
1583 if (c->aim0.refs + c->aim1.refs >= 2)
1584 goto out;
1585
1586 if (c->hdm_enqueue_task)
1587 kthread_stop(c->hdm_enqueue_task);
1588 c->hdm_enqueue_task = NULL;
1589
1590 if (iface->mod)
1591 module_put(iface->mod);
1592
1593 c->is_poisoned = true;
1594 if (c->iface->poison_channel(c->iface, c->channel_id)) {
1595 pr_err("Cannot stop channel %d of mdev %s\n", c->channel_id,
1596 c->iface->description);
1597 mutex_unlock(&c->start_mutex);
1598 return -EAGAIN;
1599 }
1600 flush_trash_fifo(c);
1601 flush_channel_fifos(c);
1602
1603#ifdef CMPL_INTERRUPTIBLE
1604 if (wait_for_completion_interruptible(&c->cleanup)) {
1605 pr_info("Interrupted while clean up ch %d\n", c->channel_id);
1606 mutex_unlock(&c->start_mutex);
1607 return -EINTR;
1608 }
1609#else
1610 wait_for_completion(&c->cleanup);
1611#endif
1612 c->is_poisoned = false;
1613
1614out:
1615 if (aim == c->aim0.ptr)
1616 c->aim0.refs--;
1617 if (aim == c->aim1.ptr)
1618 c->aim1.refs--;
1619 mutex_unlock(&c->start_mutex);
1620 return 0;
1621}
1622EXPORT_SYMBOL_GPL(most_stop_channel);
1623
1624/**
1625 * most_register_aim - registers an AIM (driver) with the core
1626 * @aim: instance of AIM to be registered
1627 */
1628int most_register_aim(struct most_aim *aim)
1629{
1630 struct most_aim_obj *aim_obj;
1631
1632 if (!aim) {
1633 pr_err("Bad driver\n");
1634 return -EINVAL;
1635 }
1636 aim_obj = create_most_aim_obj(aim->name);
1637 if (!aim_obj) {
1638 pr_info("failed to alloc driver object\n");
1639 return -ENOMEM;
1640 }
1641 aim_obj->driver = aim;
1642 aim->context = aim_obj;
1643 pr_info("registered new application interfacing module %s\n",
1644 aim->name);
1645 list_add_tail(&aim_obj->list, &aim_list);
1646 return 0;
1647}
1648EXPORT_SYMBOL_GPL(most_register_aim);
1649
1650/**
1651 * most_deregister_aim - deregisters an AIM (driver) with the core
1652 * @aim: AIM to be removed
1653 */
1654int most_deregister_aim(struct most_aim *aim)
1655{
1656 struct most_aim_obj *aim_obj;
1657 struct most_c_obj *c, *tmp;
1658 struct most_inst_obj *i, *i_tmp;
1659
1660 if (!aim) {
1661 pr_err("Bad driver\n");
1662 return -EINVAL;
1663 }
1664
1665 aim_obj = aim->context;
1666 if (!aim_obj) {
1667 pr_info("driver not registered.\n");
1668 return -EINVAL;
1669 }
1670 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
1671 list_for_each_entry_safe(c, tmp, &i->channel_list, list) {
1672 if (c->aim0.ptr == aim || c->aim1.ptr == aim)
1673 aim->disconnect_channel(
1674 c->iface, c->channel_id);
1675 if (c->aim0.ptr == aim)
1676 c->aim0.ptr = NULL;
1677 if (c->aim1.ptr == aim)
1678 c->aim1.ptr = NULL;
1679 }
1680 }
1681 list_del(&aim_obj->list);
1682 destroy_most_aim_obj(aim_obj);
1683 pr_info("deregistering application interfacing module %s\n", aim->name);
1684 return 0;
1685}
1686EXPORT_SYMBOL_GPL(most_deregister_aim);
1687
1688/**
1689 * most_register_interface - registers an interface with core
1690 * @iface: pointer to the instance of the interface description.
1691 *
1692 * Allocates and initializes a new interface instance and all of its channels.
1693 * Returns a pointer to kobject or an error pointer.
1694 */
1695struct kobject *most_register_interface(struct most_interface *iface)
1696{
1697 unsigned int i;
1698 int id;
1699 char name[STRING_SIZE];
1700 char channel_name[STRING_SIZE];
1701 struct most_c_obj *c;
1702 struct most_inst_obj *inst;
1703
1704 if (!iface || !iface->enqueue || !iface->configure ||
1705 !iface->poison_channel || (iface->num_channels > MAX_CHANNELS)) {
1706 pr_err("Bad interface or channel overflow\n");
1707 return ERR_PTR(-EINVAL);
1708 }
1709
1710 id = ida_simple_get(&mdev_id, 0, 0, GFP_KERNEL);
1711 if (id < 0) {
1712 pr_info("Failed to alloc mdev ID\n");
1713 return ERR_PTR(id);
1714 }
1715 snprintf(name, STRING_SIZE, "mdev%d", id);
1716
1717 inst = create_most_inst_obj(name);
1718 if (!inst) {
1719 pr_info("Failed to allocate interface instance\n");
1720 ida_simple_remove(&mdev_id, id);
1721 return ERR_PTR(-ENOMEM);
1722 }
1723
1724 iface->priv = inst;
1725 INIT_LIST_HEAD(&inst->channel_list);
1726 inst->iface = iface;
1727 inst->dev_id = id;
1728 list_add_tail(&inst->list, &instance_list);
1729
1730 for (i = 0; i < iface->num_channels; i++) {
1731 const char *name_suffix = iface->channel_vector[i].name_suffix;
1732
1733 if (!name_suffix)
1734 snprintf(channel_name, STRING_SIZE, "ch%d", i);
1735 else
1736 snprintf(channel_name, STRING_SIZE, "%s", name_suffix);
1737
1738 /* this increments the reference count of this instance */
1739 c = create_most_c_obj(channel_name, &inst->kobj);
1740 if (!c)
1741 goto free_instance;
1742 inst->channel[i] = c;
1743 c->is_starving = 0;
1744 c->iface = iface;
1745 c->inst = inst;
1746 c->channel_id = i;
1747 c->keep_mbo = false;
1748 c->enqueue_halt = false;
1749 c->is_poisoned = false;
1750 c->cfg.direction = 0;
1751 c->cfg.data_type = 0;
1752 c->cfg.num_buffers = 0;
1753 c->cfg.buffer_size = 0;
1754 c->cfg.subbuffer_size = 0;
1755 c->cfg.packets_per_xact = 0;
1756 spin_lock_init(&c->fifo_lock);
1757 INIT_LIST_HEAD(&c->fifo);
1758 INIT_LIST_HEAD(&c->trash_fifo);
1759 INIT_LIST_HEAD(&c->halt_fifo);
1760 init_completion(&c->cleanup);
1761 atomic_set(&c->mbo_ref, 0);
1762 mutex_init(&c->start_mutex);
1763 mutex_init(&c->nq_mutex);
1764 list_add_tail(&c->list, &inst->channel_list);
1765 }
1766 pr_info("registered new MOST device mdev%d (%s)\n",
1767 inst->dev_id, iface->description);
1768 return &inst->kobj;
1769
1770free_instance:
1771 pr_info("Failed allocate channel(s)\n");
1772 list_del(&inst->list);
1773 ida_simple_remove(&mdev_id, id);
1774 destroy_most_inst_obj(inst);
1775 return ERR_PTR(-ENOMEM);
1776}
1777EXPORT_SYMBOL_GPL(most_register_interface);
1778
1779/**
1780 * most_deregister_interface - deregisters an interface with core
1781 * @iface: pointer to the interface instance description.
1782 *
1783 * Before removing an interface instance from the list, all running
1784 * channels are stopped and poisoned.
1785 */
1786void most_deregister_interface(struct most_interface *iface)
1787{
1788 struct most_inst_obj *i = iface->priv;
1789 struct most_c_obj *c;
1790
1791 if (unlikely(!i)) {
1792 pr_info("Bad Interface\n");
1793 return;
1794 }
1795 pr_info("deregistering MOST device %s (%s)\n", i->kobj.name,
1796 iface->description);
1797
1798 list_for_each_entry(c, &i->channel_list, list) {
1799 if (c->aim0.ptr)
1800 c->aim0.ptr->disconnect_channel(c->iface,
1801 c->channel_id);
1802 if (c->aim1.ptr)
1803 c->aim1.ptr->disconnect_channel(c->iface,
1804 c->channel_id);
1805 c->aim0.ptr = NULL;
1806 c->aim1.ptr = NULL;
1807 }
1808
1809 ida_simple_remove(&mdev_id, i->dev_id);
1810 list_del(&i->list);
1811 destroy_most_inst_obj(i);
1812}
1813EXPORT_SYMBOL_GPL(most_deregister_interface);
1814
1815/**
1816 * most_stop_enqueue - prevents core from enqueueing MBOs
1817 * @iface: pointer to interface
1818 * @id: channel id
1819 *
1820 * This is called by an HDM that _cannot_ attend to its duties and
1821 * is imminent to get run over by the core. The core is not going to
1822 * enqueue any further packets unless the flagging HDM calls
1823 * most_resume enqueue().
1824 */
1825void most_stop_enqueue(struct most_interface *iface, int id)
1826{
1827 struct most_c_obj *c = get_channel_by_iface(iface, id);
1828
1829 if (!c)
1830 return;
1831
1832 mutex_lock(&c->nq_mutex);
1833 c->enqueue_halt = true;
1834 mutex_unlock(&c->nq_mutex);
1835}
1836EXPORT_SYMBOL_GPL(most_stop_enqueue);
1837
1838/**
1839 * most_resume_enqueue - allow core to enqueue MBOs again
1840 * @iface: pointer to interface
1841 * @id: channel id
1842 *
1843 * This clears the enqueue halt flag and enqueues all MBOs currently
1844 * sitting in the wait fifo.
1845 */
1846void most_resume_enqueue(struct most_interface *iface, int id)
1847{
1848 struct most_c_obj *c = get_channel_by_iface(iface, id);
1849
1850 if (!c)
1851 return;
1852
1853 mutex_lock(&c->nq_mutex);
1854 c->enqueue_halt = false;
1855 mutex_unlock(&c->nq_mutex);
1856
1857 wake_up_interruptible(&c->hdm_fifo_wq);
1858}
1859EXPORT_SYMBOL_GPL(most_resume_enqueue);
1860
1861static int __init most_init(void)
1862{
1863 int err;
1864
1865 pr_info("init()\n");
1866 INIT_LIST_HEAD(&instance_list);
1867 INIT_LIST_HEAD(&aim_list);
1868 ida_init(&mdev_id);
1869
1870 err = bus_register(&most_bus);
1871 if (err) {
1872 pr_info("Cannot register most bus\n");
1873 return err;
1874 }
1875
1876 most_class = class_create(THIS_MODULE, "most");
1877 if (IS_ERR(most_class)) {
1878 pr_info("No udev support.\n");
1879 err = PTR_ERR(most_class);
1880 goto exit_bus;
1881 }
1882
1883 err = driver_register(&mostcore);
1884 if (err) {
1885 pr_info("Cannot register core driver\n");
1886 goto exit_class;
1887 }
1888
1889 core_dev = device_create(most_class, NULL, 0, NULL, "mostcore");
1890 if (IS_ERR(core_dev)) {
1891 err = PTR_ERR(core_dev);
1892 goto exit_driver;
1893 }
1894
1895 most_aim_kset = kset_create_and_add("aims", NULL, &core_dev->kobj);
1896 if (!most_aim_kset) {
1897 err = -ENOMEM;
1898 goto exit_class_container;
1899 }
1900
1901 most_inst_kset = kset_create_and_add("devices", NULL, &core_dev->kobj);
1902 if (!most_inst_kset) {
1903 err = -ENOMEM;
1904 goto exit_driver_kset;
1905 }
1906
1907 return 0;
1908
1909exit_driver_kset:
1910 kset_unregister(most_aim_kset);
1911exit_class_container:
1912 device_destroy(most_class, 0);
1913exit_driver:
1914 driver_unregister(&mostcore);
1915exit_class:
1916 class_destroy(most_class);
1917exit_bus:
1918 bus_unregister(&most_bus);
1919 return err;
1920}
1921
1922static void __exit most_exit(void)
1923{
1924 struct most_inst_obj *i, *i_tmp;
1925 struct most_aim_obj *d, *d_tmp;
1926
1927 pr_info("exit core module\n");
1928 list_for_each_entry_safe(d, d_tmp, &aim_list, list) {
1929 destroy_most_aim_obj(d);
1930 }
1931
1932 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
1933 list_del(&i->list);
1934 destroy_most_inst_obj(i);
1935 }
1936 kset_unregister(most_inst_kset);
1937 kset_unregister(most_aim_kset);
1938 device_destroy(most_class, 0);
1939 driver_unregister(&mostcore);
1940 class_destroy(most_class);
1941 bus_unregister(&most_bus);
1942 ida_destroy(&mdev_id);
1943}
1944
1945module_init(most_init);
1946module_exit(most_exit);
1947MODULE_LICENSE("GPL");
1948MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>");
1949MODULE_DESCRIPTION("Core module of stacked MOST Linux driver");
diff --git a/drivers/staging/most/aim-network/Kconfig b/drivers/staging/most/net/Kconfig
index 4c66b24cf73c..795330ba94ef 100644
--- a/drivers/staging/most/aim-network/Kconfig
+++ b/drivers/staging/most/net/Kconfig
@@ -2,12 +2,12 @@
2# MOST Networking configuration 2# MOST Networking configuration
3# 3#
4 4
5config AIM_NETWORK 5config MOST_NET
6 tristate "Networking AIM" 6 tristate "Net"
7 depends on NET 7 depends on NET
8 8
9 ---help--- 9 ---help---
10 Say Y here if you want to commumicate via a networking device. 10 Say Y here if you want to commumicate via a networking device.
11 11
12 To compile this driver as a module, choose M here: the 12 To compile this driver as a module, choose M here: the
13 module will be called aim_network. 13 module will be called most_net.
diff --git a/drivers/staging/most/net/Makefile b/drivers/staging/most/net/Makefile
new file mode 100644
index 000000000000..54500aa77be8
--- /dev/null
+++ b/drivers/staging/most/net/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_MOST_NET) += most_net.o
2
3most_net-objs := net.o
4ccflags-y += -Idrivers/staging/
diff --git a/drivers/staging/most/aim-network/networking.c b/drivers/staging/most/net/net.c
index 936f013c350e..30d816b7e165 100644
--- a/drivers/staging/most/aim-network/networking.c
+++ b/drivers/staging/most/net/net.c
@@ -1,14 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Networking AIM - Networking Application Interface Module for MostCore 3 * net.c - Networking component for Mostcore
3 * 4 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG 5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
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 * This file is licensed under GPLv2.
12 */ 6 */
13 7
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -21,7 +15,7 @@
21#include <linux/list.h> 15#include <linux/list.h>
22#include <linux/wait.h> 16#include <linux/wait.h>
23#include <linux/kobject.h> 17#include <linux/kobject.h>
24#include "mostcore.h" 18#include "most/core.h"
25 19
26#define MEP_HDR_LEN 8 20#define MEP_HDR_LEN 8
27#define MDP_HDR_LEN 16 21#define MDP_HDR_LEN 16
@@ -52,10 +46,12 @@
52 ((len) > MEP_HDR_LEN && \ 46 ((len) > MEP_HDR_LEN && \
53 EXTRACT_BIT_SET(PMS_FIFONO, (buf)[3]) == PMS_FIFONO_MEP) 47 EXTRACT_BIT_SET(PMS_FIFONO, (buf)[3]) == PMS_FIFONO_MEP)
54 48
55#define PMS_IS_MAMAC(buf, len) \ 49static inline bool pms_is_mamac(char *buf, u32 len)
56 ((len) > MDP_HDR_LEN && \ 50{
57 EXTRACT_BIT_SET(PMS_FIFONO, (buf)[3]) == PMS_FIFONO_MDP && \ 51 return (len > MDP_HDR_LEN &&
58 EXTRACT_BIT_SET(PMS_TELID, (buf)[14]) == PMS_TELID_UNSEGM_MAMAC) 52 EXTRACT_BIT_SET(PMS_FIFONO, buf[3]) == PMS_FIFONO_MDP &&
53 EXTRACT_BIT_SET(PMS_TELID, buf[14]) == PMS_TELID_UNSEGM_MAMAC);
54}
59 55
60struct net_dev_channel { 56struct net_dev_channel {
61 bool linked; 57 bool linked;
@@ -74,7 +70,7 @@ struct net_dev_context {
74static struct list_head net_devices = LIST_HEAD_INIT(net_devices); 70static struct list_head net_devices = LIST_HEAD_INIT(net_devices);
75static struct mutex probe_disc_mt; /* ch->linked = true, most_nd_open */ 71static struct mutex probe_disc_mt; /* ch->linked = true, most_nd_open */
76static struct spinlock list_lock; /* list_head, ch->linked = false, dev_hold */ 72static struct spinlock list_lock; /* list_head, ch->linked = false, dev_hold */
77static struct most_aim aim; 73static struct core_component comp;
78 74
79static int skb_to_mamac(const struct sk_buff *skb, struct mbo *mbo) 75static int skb_to_mamac(const struct sk_buff *skb, struct mbo *mbo)
80{ 76{
@@ -184,15 +180,15 @@ static int most_nd_open(struct net_device *dev)
184 180
185 mutex_lock(&probe_disc_mt); 181 mutex_lock(&probe_disc_mt);
186 182
187 if (most_start_channel(nd->iface, nd->rx.ch_id, &aim)) { 183 if (most_start_channel(nd->iface, nd->rx.ch_id, &comp)) {
188 netdev_err(dev, "most_start_channel() failed\n"); 184 netdev_err(dev, "most_start_channel() failed\n");
189 ret = -EBUSY; 185 ret = -EBUSY;
190 goto unlock; 186 goto unlock;
191 } 187 }
192 188
193 if (most_start_channel(nd->iface, nd->tx.ch_id, &aim)) { 189 if (most_start_channel(nd->iface, nd->tx.ch_id, &comp)) {
194 netdev_err(dev, "most_start_channel() failed\n"); 190 netdev_err(dev, "most_start_channel() failed\n");
195 most_stop_channel(nd->iface, nd->rx.ch_id, &aim); 191 most_stop_channel(nd->iface, nd->rx.ch_id, &comp);
196 ret = -EBUSY; 192 ret = -EBUSY;
197 goto unlock; 193 goto unlock;
198 } 194 }
@@ -218,8 +214,8 @@ static int most_nd_stop(struct net_device *dev)
218 netif_stop_queue(dev); 214 netif_stop_queue(dev);
219 if (nd->iface->request_netinfo) 215 if (nd->iface->request_netinfo)
220 nd->iface->request_netinfo(nd->iface, nd->tx.ch_id, NULL); 216 nd->iface->request_netinfo(nd->iface, nd->tx.ch_id, NULL);
221 most_stop_channel(nd->iface, nd->rx.ch_id, &aim); 217 most_stop_channel(nd->iface, nd->rx.ch_id, &comp);
222 most_stop_channel(nd->iface, nd->tx.ch_id, &aim); 218 most_stop_channel(nd->iface, nd->tx.ch_id, &comp);
223 219
224 return 0; 220 return 0;
225} 221}
@@ -231,7 +227,7 @@ static netdev_tx_t most_nd_start_xmit(struct sk_buff *skb,
231 struct mbo *mbo; 227 struct mbo *mbo;
232 int ret; 228 int ret;
233 229
234 mbo = most_get_mbo(nd->iface, nd->tx.ch_id, &aim); 230 mbo = most_get_mbo(nd->iface, nd->tx.ch_id, &comp);
235 231
236 if (!mbo) { 232 if (!mbo) {
237 netif_stop_queue(dev); 233 netif_stop_queue(dev);
@@ -296,9 +292,8 @@ static struct net_dev_context *get_net_dev_hold(struct most_interface *iface)
296 return nd; 292 return nd;
297} 293}
298 294
299static int aim_probe_channel(struct most_interface *iface, int channel_idx, 295static int comp_probe_channel(struct most_interface *iface, int channel_idx,
300 struct most_channel_config *ccfg, 296 struct most_channel_config *ccfg, char *name)
301 struct kobject *parent, char *name)
302{ 297{
303 struct net_dev_context *nd; 298 struct net_dev_context *nd;
304 struct net_dev_channel *ch; 299 struct net_dev_channel *ch;
@@ -353,8 +348,8 @@ unlock:
353 return ret; 348 return ret;
354} 349}
355 350
356static int aim_disconnect_channel(struct most_interface *iface, 351static int comp_disconnect_channel(struct most_interface *iface,
357 int channel_idx) 352 int channel_idx)
358{ 353{
359 struct net_dev_context *nd; 354 struct net_dev_context *nd;
360 struct net_dev_channel *ch; 355 struct net_dev_channel *ch;
@@ -400,8 +395,8 @@ unlock:
400 return ret; 395 return ret;
401} 396}
402 397
403static int aim_resume_tx_channel(struct most_interface *iface, 398static int comp_resume_tx_channel(struct most_interface *iface,
404 int channel_idx) 399 int channel_idx)
405{ 400{
406 struct net_dev_context *nd; 401 struct net_dev_context *nd;
407 402
@@ -419,7 +414,7 @@ put_nd:
419 return 0; 414 return 0;
420} 415}
421 416
422static int aim_rx_data(struct mbo *mbo) 417static int comp_rx_data(struct mbo *mbo)
423{ 418{
424 const u32 zero = 0; 419 const u32 zero = 0;
425 struct net_dev_context *nd; 420 struct net_dev_context *nd;
@@ -442,7 +437,7 @@ static int aim_rx_data(struct mbo *mbo)
442 dev = nd->dev; 437 dev = nd->dev;
443 438
444 if (nd->is_mamac) { 439 if (nd->is_mamac) {
445 if (!PMS_IS_MAMAC(buf, len)) { 440 if (!pms_is_mamac(buf, len)) {
446 ret = -EIO; 441 ret = -EIO;
447 goto put_nd; 442 goto put_nd;
448 } 443 }
@@ -501,24 +496,24 @@ put_nd:
501 return ret; 496 return ret;
502} 497}
503 498
504static struct most_aim aim = { 499static struct core_component comp = {
505 .name = "networking", 500 .name = "net",
506 .probe_channel = aim_probe_channel, 501 .probe_channel = comp_probe_channel,
507 .disconnect_channel = aim_disconnect_channel, 502 .disconnect_channel = comp_disconnect_channel,
508 .tx_completion = aim_resume_tx_channel, 503 .tx_completion = comp_resume_tx_channel,
509 .rx_completion = aim_rx_data, 504 .rx_completion = comp_rx_data,
510}; 505};
511 506
512static int __init most_net_init(void) 507static int __init most_net_init(void)
513{ 508{
514 spin_lock_init(&list_lock); 509 spin_lock_init(&list_lock);
515 mutex_init(&probe_disc_mt); 510 mutex_init(&probe_disc_mt);
516 return most_register_aim(&aim); 511 return most_register_component(&comp);
517} 512}
518 513
519static void __exit most_net_exit(void) 514static void __exit most_net_exit(void)
520{ 515{
521 most_deregister_aim(&aim); 516 most_deregister_component(&comp);
522} 517}
523 518
524/** 519/**
@@ -564,4 +559,4 @@ module_init(most_net_init);
564module_exit(most_net_exit); 559module_exit(most_net_exit);
565MODULE_LICENSE("GPL"); 560MODULE_LICENSE("GPL");
566MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>"); 561MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
567MODULE_DESCRIPTION("Networking Application Interface Module for MostCore"); 562MODULE_DESCRIPTION("Networking Component Module for Mostcore");
diff --git a/drivers/staging/most/aim-sound/Kconfig b/drivers/staging/most/sound/Kconfig
index 3194c219ff14..115262a58a42 100644
--- a/drivers/staging/most/aim-sound/Kconfig
+++ b/drivers/staging/most/sound/Kconfig
@@ -2,12 +2,12 @@
2# MOST ALSA configuration 2# MOST ALSA configuration
3# 3#
4 4
5config AIM_SOUND 5config MOST_SOUND
6 tristate "ALSA AIM" 6 tristate "Sound"
7 depends on SND 7 depends on SND
8 select SND_PCM 8 select SND_PCM
9 ---help--- 9 ---help---
10 Say Y here if you want to commumicate via ALSA/sound devices. 10 Say Y here if you want to commumicate via ALSA/sound devices.
11 11
12 To compile this driver as a module, choose M here: the 12 To compile this driver as a module, choose M here: the
13 module will be called aim_sound. 13 module will be called most_sound.
diff --git a/drivers/staging/most/sound/Makefile b/drivers/staging/most/sound/Makefile
new file mode 100644
index 000000000000..eee8774e38cb
--- /dev/null
+++ b/drivers/staging/most/sound/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_MOST_SOUND) += most_sound.o
2
3most_sound-objs := sound.o
4ccflags-y += -Idrivers/staging/
diff --git a/drivers/staging/most/aim-sound/sound.c b/drivers/staging/most/sound/sound.c
index ea1366a44008..83cec21c85b8 100644
--- a/drivers/staging/most/aim-sound/sound.c
+++ b/drivers/staging/most/sound/sound.c
@@ -1,14 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * sound.c - Audio Application Interface Module for Mostcore 3 * sound.c - Sound component for Mostcore
3 * 4 *
4 * Copyright (C) 2015 Microchip Technology Germany II GmbH & Co. KG 5 * Copyright (C) 2015 Microchip Technology Germany II GmbH & Co. KG
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 * This file is licensed under GPLv2.
12 */ 6 */
13 7
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -22,12 +16,12 @@
22#include <sound/pcm_params.h> 16#include <sound/pcm_params.h>
23#include <linux/sched.h> 17#include <linux/sched.h>
24#include <linux/kthread.h> 18#include <linux/kthread.h>
25#include <mostcore.h> 19#include <most/core.h>
26 20
27#define DRIVER_NAME "sound" 21#define DRIVER_NAME "sound"
28 22
29static struct list_head dev_list; 23static struct list_head dev_list;
30static struct most_aim audio_aim; 24static struct core_component comp;
31 25
32/** 26/**
33 * struct channel - private structure to keep channel specific data 27 * struct channel - private structure to keep channel specific data
@@ -240,7 +234,7 @@ static int playback_thread(void *data)
240 kthread_should_stop() || 234 kthread_should_stop() ||
241 (channel->is_stream_running && 235 (channel->is_stream_running &&
242 (mbo = most_get_mbo(channel->iface, channel->id, 236 (mbo = most_get_mbo(channel->iface, channel->id,
243 &audio_aim)))); 237 &comp))));
244 if (!mbo) 238 if (!mbo)
245 continue; 239 continue;
246 240
@@ -283,7 +277,7 @@ static int pcm_open(struct snd_pcm_substream *substream)
283 } 277 }
284 } 278 }
285 279
286 if (most_start_channel(channel->iface, channel->id, &audio_aim)) { 280 if (most_start_channel(channel->iface, channel->id, &comp)) {
287 pr_err("most_start_channel() failed!\n"); 281 pr_err("most_start_channel() failed!\n");
288 if (cfg->direction == MOST_CH_TX) 282 if (cfg->direction == MOST_CH_TX)
289 kthread_stop(channel->playback_task); 283 kthread_stop(channel->playback_task);
@@ -310,7 +304,7 @@ static int pcm_close(struct snd_pcm_substream *substream)
310 304
311 if (channel->cfg->direction == MOST_CH_TX) 305 if (channel->cfg->direction == MOST_CH_TX)
312 kthread_stop(channel->playback_task); 306 kthread_stop(channel->playback_task);
313 most_stop_channel(channel->iface, channel->id, &audio_aim); 307 most_stop_channel(channel->iface, channel->id, &comp);
314 308
315 return 0; 309 return 0;
316} 310}
@@ -545,7 +539,6 @@ error:
545 * @iface: pointer to interface instance 539 * @iface: pointer to interface instance
546 * @channel_id: channel index/ID 540 * @channel_id: channel index/ID
547 * @cfg: pointer to actual channel configuration 541 * @cfg: pointer to actual channel configuration
548 * @parent: pointer to kobject (needed for sysfs hook-up)
549 * @arg_list: string that provides the name of the device to be created in /dev 542 * @arg_list: string that provides the name of the device to be created in /dev
550 * plus the desired audio resolution 543 * plus the desired audio resolution
551 * 544 *
@@ -555,7 +548,7 @@ error:
555 */ 548 */
556static int audio_probe_channel(struct most_interface *iface, int channel_id, 549static int audio_probe_channel(struct most_interface *iface, int channel_id,
557 struct most_channel_config *cfg, 550 struct most_channel_config *cfg,
558 struct kobject *parent, char *arg_list) 551 char *arg_list)
559{ 552{
560 struct channel *channel; 553 struct channel *channel;
561 struct snd_card *card; 554 struct snd_card *card;
@@ -724,9 +717,9 @@ static int audio_tx_completion(struct most_interface *iface, int channel_id)
724} 717}
725 718
726/** 719/**
727 * Initialization of the struct most_aim 720 * Initialization of the struct core_component
728 */ 721 */
729static struct most_aim audio_aim = { 722static struct core_component comp = {
730 .name = DRIVER_NAME, 723 .name = DRIVER_NAME,
731 .probe_channel = audio_probe_channel, 724 .probe_channel = audio_probe_channel,
732 .disconnect_channel = audio_disconnect_channel, 725 .disconnect_channel = audio_disconnect_channel,
@@ -740,7 +733,7 @@ static int __init audio_init(void)
740 733
741 INIT_LIST_HEAD(&dev_list); 734 INIT_LIST_HEAD(&dev_list);
742 735
743 return most_register_aim(&audio_aim); 736 return most_register_component(&comp);
744} 737}
745 738
746static void __exit audio_exit(void) 739static void __exit audio_exit(void)
@@ -754,7 +747,7 @@ static void __exit audio_exit(void)
754 snd_card_free(channel->card); 747 snd_card_free(channel->card);
755 } 748 }
756 749
757 most_deregister_aim(&audio_aim); 750 most_deregister_component(&comp);
758} 751}
759 752
760module_init(audio_init); 753module_init(audio_init);
@@ -762,4 +755,4 @@ module_exit(audio_exit);
762 755
763MODULE_LICENSE("GPL"); 756MODULE_LICENSE("GPL");
764MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>"); 757MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>");
765MODULE_DESCRIPTION("Audio Application Interface Module for MostCore"); 758MODULE_DESCRIPTION("Sound Component Module for Mostcore");
diff --git a/drivers/staging/most/hdm-usb/Kconfig b/drivers/staging/most/usb/Kconfig
index 487f1f34776c..ebbdb573a9a6 100644
--- a/drivers/staging/most/hdm-usb/Kconfig
+++ b/drivers/staging/most/usb/Kconfig
@@ -2,13 +2,12 @@
2# MOST USB configuration 2# MOST USB configuration
3# 3#
4 4
5config HDM_USB 5config MOST_USB
6 tristate "USB HDM" 6 tristate "USB"
7 depends on USB && NET 7 depends on USB && NET
8
9 ---help--- 8 ---help---
10 Say Y here if you want to connect via USB to network tranceiver. 9 Say Y here if you want to connect via USB to network tranceiver.
11 This device driver depends on the networking AIM. 10 This device driver depends on the networking AIM.
12 11
13 To compile this driver as a module, choose M here: the 12 To compile this driver as a module, choose M here: the
14 module will be called hdm_usb. 13 module will be called most_usb.
diff --git a/drivers/staging/most/usb/Makefile b/drivers/staging/most/usb/Makefile
new file mode 100644
index 000000000000..18d28cba4fbf
--- /dev/null
+++ b/drivers/staging/most/usb/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_MOST_USB) += most_usb.o
2
3most_usb-objs := usb.o
4ccflags-y += -Idrivers/staging/
diff --git a/drivers/staging/most/hdm-usb/hdm_usb.c b/drivers/staging/most/usb/usb.c
index 667dacac81f0..31f184cfcd69 100644
--- a/drivers/staging/most/hdm-usb/hdm_usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -1,14 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * hdm_usb.c - Hardware dependent module for USB 3 * usb.c - Hardware dependent module for USB
3 * 4 *
4 * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG 5 * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG
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 * This file is licensed under GPLv2.
12 */ 6 */
13 7
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -29,7 +23,7 @@
29#include <linux/dma-mapping.h> 23#include <linux/dma-mapping.h>
30#include <linux/etherdevice.h> 24#include <linux/etherdevice.h>
31#include <linux/uaccess.h> 25#include <linux/uaccess.h>
32#include "mostcore.h" 26#include "most/core.h"
33 27
34#define USB_MTU 512 28#define USB_MTU 512
35#define NO_ISOCHRONOUS_URB 0 29#define NO_ISOCHRONOUS_URB 0
@@ -70,12 +64,12 @@
70 * @reg_addr: register address for arbitrary DCI access 64 * @reg_addr: register address for arbitrary DCI access
71 */ 65 */
72struct most_dci_obj { 66struct most_dci_obj {
73 struct kobject kobj; 67 struct device dev;
74 struct usb_device *usb_device; 68 struct usb_device *usb_device;
75 u16 reg_addr; 69 u16 reg_addr;
76}; 70};
77 71
78#define to_dci_obj(p) container_of(p, struct most_dci_obj, kobj) 72#define to_dci_obj(p) container_of(p, struct most_dci_obj, dev)
79 73
80struct most_dev; 74struct most_dev;
81 75
@@ -90,7 +84,6 @@ struct clear_hold_work {
90 84
91/** 85/**
92 * struct most_dev - holds all usb interface specific stuff 86 * struct most_dev - holds all usb interface specific stuff
93 * @parent: parent object in sysfs
94 * @usb_device: pointer to usb device 87 * @usb_device: pointer to usb device
95 * @iface: hardware interface 88 * @iface: hardware interface
96 * @cap: channel capabilities 89 * @cap: channel capabilities
@@ -108,7 +101,6 @@ struct clear_hold_work {
108 * @poll_work_obj: work for polling link status 101 * @poll_work_obj: work for polling link status
109 */ 102 */
110struct most_dev { 103struct most_dev {
111 struct kobject *parent;
112 struct usb_device *usb_device; 104 struct usb_device *usb_device;
113 struct most_interface iface; 105 struct most_interface iface;
114 struct most_channel_capability *cap; 106 struct most_channel_capability *cap;
@@ -125,8 +117,8 @@ struct most_dev {
125 struct mutex io_mutex; 117 struct mutex io_mutex;
126 struct timer_list link_stat_timer; 118 struct timer_list link_stat_timer;
127 struct work_struct poll_work_obj; 119 struct work_struct poll_work_obj;
128 void (*on_netinfo)(struct most_interface *, unsigned char, 120 void (*on_netinfo)(struct most_interface *most_iface,
129 unsigned char *); 121 unsigned char link_state, unsigned char *addrs);
130}; 122};
131 123
132#define to_mdev(d) container_of(d, struct most_dev, iface) 124#define to_mdev(d) container_of(d, struct most_dev, iface)
@@ -817,6 +809,21 @@ static void wq_clear_halt(struct work_struct *wq_obj)
817 if (usb_clear_halt(mdev->usb_device, pipe)) 809 if (usb_clear_halt(mdev->usb_device, pipe))
818 dev_warn(&mdev->usb_device->dev, "Failed to reset endpoint.\n"); 810 dev_warn(&mdev->usb_device->dev, "Failed to reset endpoint.\n");
819 811
812 /* If the functional Stall condition has been set on an
813 * asynchronous rx channel, we need to clear the tx channel
814 * too, since the hardware runs its clean-up sequence on both
815 * channels, as they are physically one on the network.
816 *
817 * The USB interface that exposes the asynchronous channels
818 * contains always two endpoints, and two only.
819 */
820 if (mdev->conf[channel].data_type == MOST_CH_ASYNC &&
821 mdev->conf[channel].direction == MOST_CH_RX) {
822 int peer = 1 - channel;
823 int snd_pipe = usb_sndbulkpipe(mdev->usb_device,
824 mdev->ep_address[peer]);
825 usb_clear_halt(mdev->usb_device, snd_pipe);
826 }
820 mdev->is_channel_healthy[channel] = true; 827 mdev->is_channel_healthy[channel] = true;
821 most_resume_enqueue(&mdev->iface, channel); 828 most_resume_enqueue(&mdev->iface, channel);
822 mutex_unlock(&mdev->io_mutex); 829 mutex_unlock(&mdev->io_mutex);
@@ -840,94 +847,6 @@ static const struct usb_device_id usbid[] = {
840 { } /* Terminating entry */ 847 { } /* Terminating entry */
841}; 848};
842 849
843#define MOST_DCI_RO_ATTR(_name) \
844 struct most_dci_attribute most_dci_attr_##_name = \
845 __ATTR(_name, 0444, show_value, NULL)
846
847#define MOST_DCI_ATTR(_name) \
848 struct most_dci_attribute most_dci_attr_##_name = \
849 __ATTR(_name, 0644, show_value, store_value)
850
851#define MOST_DCI_WO_ATTR(_name) \
852 struct most_dci_attribute most_dci_attr_##_name = \
853 __ATTR(_name, 0200, NULL, store_value)
854
855/**
856 * struct most_dci_attribute - to access the attributes of a dci object
857 * @attr: attributes of a dci object
858 * @show: pointer to the show function
859 * @store: pointer to the store function
860 */
861struct most_dci_attribute {
862 struct attribute attr;
863 ssize_t (*show)(struct most_dci_obj *d,
864 struct most_dci_attribute *attr,
865 char *buf);
866 ssize_t (*store)(struct most_dci_obj *d,
867 struct most_dci_attribute *attr,
868 const char *buf,
869 size_t count);
870};
871
872#define to_dci_attr(a) container_of(a, struct most_dci_attribute, attr)
873
874/**
875 * dci_attr_show - show function for dci object
876 * @kobj: pointer to kobject
877 * @attr: pointer to attribute struct
878 * @buf: buffer
879 */
880static ssize_t dci_attr_show(struct kobject *kobj, struct attribute *attr,
881 char *buf)
882{
883 struct most_dci_attribute *dci_attr = to_dci_attr(attr);
884 struct most_dci_obj *dci_obj = to_dci_obj(kobj);
885
886 if (!dci_attr->show)
887 return -EIO;
888
889 return dci_attr->show(dci_obj, dci_attr, buf);
890}
891
892/**
893 * dci_attr_store - store function for dci object
894 * @kobj: pointer to kobject
895 * @attr: pointer to attribute struct
896 * @buf: buffer
897 * @len: length of buffer
898 */
899static ssize_t dci_attr_store(struct kobject *kobj,
900 struct attribute *attr,
901 const char *buf,
902 size_t len)
903{
904 struct most_dci_attribute *dci_attr = to_dci_attr(attr);
905 struct most_dci_obj *dci_obj = to_dci_obj(kobj);
906
907 if (!dci_attr->store)
908 return -EIO;
909
910 return dci_attr->store(dci_obj, dci_attr, buf, len);
911}
912
913static const struct sysfs_ops most_dci_sysfs_ops = {
914 .show = dci_attr_show,
915 .store = dci_attr_store,
916};
917
918/**
919 * most_dci_release - release function for dci object
920 * @kobj: pointer to kobject
921 *
922 * This frees the memory allocated for the dci object
923 */
924static void most_dci_release(struct kobject *kobj)
925{
926 struct most_dci_obj *dci_obj = to_dci_obj(kobj);
927
928 kfree(dci_obj);
929}
930
931struct regs { 850struct regs {
932 const char *name; 851 const char *name;
933 u16 reg; 852 u16 reg;
@@ -968,10 +887,11 @@ static int get_stat_reg_addr(const struct regs *regs, int size,
968#define get_static_reg_addr(regs, name, reg_addr) \ 887#define get_static_reg_addr(regs, name, reg_addr) \
969 get_stat_reg_addr(regs, ARRAY_SIZE(regs), name, reg_addr) 888 get_stat_reg_addr(regs, ARRAY_SIZE(regs), name, reg_addr)
970 889
971static ssize_t show_value(struct most_dci_obj *dci_obj, 890static ssize_t value_show(struct device *dev, struct device_attribute *attr,
972 struct most_dci_attribute *attr, char *buf) 891 char *buf)
973{ 892{
974 const char *name = attr->attr.name; 893 const char *name = attr->attr.name;
894 struct most_dci_obj *dci_obj = to_dci_obj(dev);
975 u16 val; 895 u16 val;
976 u16 reg_addr; 896 u16 reg_addr;
977 int err; 897 int err;
@@ -992,13 +912,13 @@ static ssize_t show_value(struct most_dci_obj *dci_obj,
992 return snprintf(buf, PAGE_SIZE, "%04x\n", val); 912 return snprintf(buf, PAGE_SIZE, "%04x\n", val);
993} 913}
994 914
995static ssize_t store_value(struct most_dci_obj *dci_obj, 915static ssize_t value_store(struct device *dev, struct device_attribute *attr,
996 struct most_dci_attribute *attr,
997 const char *buf, size_t count) 916 const char *buf, size_t count)
998{ 917{
999 u16 val; 918 u16 val;
1000 u16 reg_addr; 919 u16 reg_addr;
1001 const char *name = attr->attr.name; 920 const char *name = attr->attr.name;
921 struct most_dci_obj *dci_obj = to_dci_obj(dev);
1002 struct usb_device *usb_dev = dci_obj->usb_device; 922 struct usb_device *usb_dev = dci_obj->usb_device;
1003 int err = kstrtou16(buf, 16, &val); 923 int err = kstrtou16(buf, 16, &val);
1004 924
@@ -1025,86 +945,49 @@ static ssize_t store_value(struct most_dci_obj *dci_obj,
1025 return count; 945 return count;
1026} 946}
1027 947
1028static MOST_DCI_RO_ATTR(ni_state); 948static DEVICE_ATTR(ni_state, 0444, value_show, NULL);
1029static MOST_DCI_RO_ATTR(packet_bandwidth); 949static DEVICE_ATTR(packet_bandwidth, 0444, value_show, NULL);
1030static MOST_DCI_RO_ATTR(node_address); 950static DEVICE_ATTR(node_address, 0444, value_show, NULL);
1031static MOST_DCI_RO_ATTR(node_position); 951static DEVICE_ATTR(node_position, 0444, value_show, NULL);
1032static MOST_DCI_WO_ATTR(sync_ep); 952static DEVICE_ATTR(sync_ep, 0200, NULL, value_store);
1033static MOST_DCI_ATTR(mep_filter); 953static DEVICE_ATTR(mep_filter, 0644, value_show, value_store);
1034static MOST_DCI_ATTR(mep_hash0); 954static DEVICE_ATTR(mep_hash0, 0644, value_show, value_store);
1035static MOST_DCI_ATTR(mep_hash1); 955static DEVICE_ATTR(mep_hash1, 0644, value_show, value_store);
1036static MOST_DCI_ATTR(mep_hash2); 956static DEVICE_ATTR(mep_hash2, 0644, value_show, value_store);
1037static MOST_DCI_ATTR(mep_hash3); 957static DEVICE_ATTR(mep_hash3, 0644, value_show, value_store);
1038static MOST_DCI_ATTR(mep_eui48_hi); 958static DEVICE_ATTR(mep_eui48_hi, 0644, value_show, value_store);
1039static MOST_DCI_ATTR(mep_eui48_mi); 959static DEVICE_ATTR(mep_eui48_mi, 0644, value_show, value_store);
1040static MOST_DCI_ATTR(mep_eui48_lo); 960static DEVICE_ATTR(mep_eui48_lo, 0644, value_show, value_store);
1041static MOST_DCI_ATTR(arb_address); 961static DEVICE_ATTR(arb_address, 0644, value_show, value_store);
1042static MOST_DCI_ATTR(arb_value); 962static DEVICE_ATTR(arb_value, 0644, value_show, value_store);
1043 963
1044/** 964static struct attribute *dci_attrs[] = {
1045 * most_dci_def_attrs - array of default attribute files of the dci object 965 &dev_attr_ni_state.attr,
1046 */ 966 &dev_attr_packet_bandwidth.attr,
1047static struct attribute *most_dci_def_attrs[] = { 967 &dev_attr_node_address.attr,
1048 &most_dci_attr_ni_state.attr, 968 &dev_attr_node_position.attr,
1049 &most_dci_attr_packet_bandwidth.attr, 969 &dev_attr_sync_ep.attr,
1050 &most_dci_attr_node_address.attr, 970 &dev_attr_mep_filter.attr,
1051 &most_dci_attr_node_position.attr, 971 &dev_attr_mep_hash0.attr,
1052 &most_dci_attr_sync_ep.attr, 972 &dev_attr_mep_hash1.attr,
1053 &most_dci_attr_mep_filter.attr, 973 &dev_attr_mep_hash2.attr,
1054 &most_dci_attr_mep_hash0.attr, 974 &dev_attr_mep_hash3.attr,
1055 &most_dci_attr_mep_hash1.attr, 975 &dev_attr_mep_eui48_hi.attr,
1056 &most_dci_attr_mep_hash2.attr, 976 &dev_attr_mep_eui48_mi.attr,
1057 &most_dci_attr_mep_hash3.attr, 977 &dev_attr_mep_eui48_lo.attr,
1058 &most_dci_attr_mep_eui48_hi.attr, 978 &dev_attr_arb_address.attr,
1059 &most_dci_attr_mep_eui48_mi.attr, 979 &dev_attr_arb_value.attr,
1060 &most_dci_attr_mep_eui48_lo.attr,
1061 &most_dci_attr_arb_address.attr,
1062 &most_dci_attr_arb_value.attr,
1063 NULL, 980 NULL,
1064}; 981};
1065 982
1066/** 983static struct attribute_group dci_attr_group = {
1067 * DCI ktype 984 .attrs = dci_attrs,
1068 */
1069static struct kobj_type most_dci_ktype = {
1070 .sysfs_ops = &most_dci_sysfs_ops,
1071 .release = most_dci_release,
1072 .default_attrs = most_dci_def_attrs,
1073}; 985};
1074 986
1075/** 987static const struct attribute_group *dci_attr_groups[] = {
1076 * create_most_dci_obj - allocates a dci object 988 &dci_attr_group,
1077 * @parent: parent kobject 989 NULL,
1078 * 990};
1079 * This creates a dci object and registers it with sysfs.
1080 * Returns a pointer to the object or NULL when something went wrong.
1081 */
1082static struct
1083most_dci_obj *create_most_dci_obj(struct kobject *parent)
1084{
1085 struct most_dci_obj *most_dci = kzalloc(sizeof(*most_dci), GFP_KERNEL);
1086 int retval;
1087
1088 if (!most_dci)
1089 return NULL;
1090
1091 retval = kobject_init_and_add(&most_dci->kobj, &most_dci_ktype, parent,
1092 "dci");
1093 if (retval) {
1094 kobject_put(&most_dci->kobj);
1095 return NULL;
1096 }
1097 return most_dci;
1098}
1099
1100/**
1101 * destroy_most_dci_obj - DCI object release function
1102 * @p: pointer to dci object
1103 */
1104static void destroy_most_dci_obj(struct most_dci_obj *p)
1105{
1106 kobject_put(&p->kobj);
1107}
1108 991
1109/** 992/**
1110 * hdm_probe - probe function of USB device driver 993 * hdm_probe - probe function of USB device driver
@@ -1168,8 +1051,6 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
1168 goto exit_free1; 1051 goto exit_free1;
1169 1052
1170 mdev->iface.channel_vector = mdev->cap; 1053 mdev->iface.channel_vector = mdev->cap;
1171 mdev->iface.priv = NULL;
1172
1173 mdev->ep_address = 1054 mdev->ep_address =
1174 kcalloc(num_endpoints, sizeof(*mdev->ep_address), GFP_KERNEL); 1055 kcalloc(num_endpoints, sizeof(*mdev->ep_address), GFP_KERNEL);
1175 if (!mdev->ep_address) 1056 if (!mdev->ep_address)
@@ -1217,20 +1098,15 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
1217 usb_dev->config->desc.bConfigurationValue, 1098 usb_dev->config->desc.bConfigurationValue,
1218 usb_iface_desc->desc.bInterfaceNumber); 1099 usb_iface_desc->desc.bInterfaceNumber);
1219 1100
1220 mdev->parent = most_register_interface(&mdev->iface); 1101 ret = most_register_interface(&mdev->iface);
1221 if (IS_ERR(mdev->parent)) { 1102 if (ret)
1222 ret = PTR_ERR(mdev->parent);
1223 goto exit_free4; 1103 goto exit_free4;
1224 }
1225 1104
1226 mutex_lock(&mdev->io_mutex); 1105 mutex_lock(&mdev->io_mutex);
1227 if (le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81118 || 1106 if (le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81118 ||
1228 le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81119 || 1107 le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81119 ||
1229 le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81210) { 1108 le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81210) {
1230 /* this increments the reference count of the instance 1109 mdev->dci = kzalloc(sizeof(*mdev->dci), GFP_KERNEL);
1231 * object of the core
1232 */
1233 mdev->dci = create_most_dci_obj(mdev->parent);
1234 if (!mdev->dci) { 1110 if (!mdev->dci) {
1235 mutex_unlock(&mdev->io_mutex); 1111 mutex_unlock(&mdev->io_mutex);
1236 most_deregister_interface(&mdev->iface); 1112 most_deregister_interface(&mdev->iface);
@@ -1238,12 +1114,21 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
1238 goto exit_free4; 1114 goto exit_free4;
1239 } 1115 }
1240 1116
1241 kobject_uevent(&mdev->dci->kobj, KOBJ_ADD); 1117 mdev->dci->dev.init_name = "dci";
1118 mdev->dci->dev.parent = &mdev->iface.dev;
1119 mdev->dci->dev.groups = dci_attr_groups;
1120 if (device_register(&mdev->dci->dev)) {
1121 mutex_unlock(&mdev->io_mutex);
1122 most_deregister_interface(&mdev->iface);
1123 ret = -ENOMEM;
1124 goto exit_free5;
1125 }
1242 mdev->dci->usb_device = mdev->usb_device; 1126 mdev->dci->usb_device = mdev->usb_device;
1243 } 1127 }
1244 mutex_unlock(&mdev->io_mutex); 1128 mutex_unlock(&mdev->io_mutex);
1245 return 0; 1129 return 0;
1246 1130exit_free5:
1131 kfree(mdev->dci);
1247exit_free4: 1132exit_free4:
1248 kfree(mdev->busy_urbs); 1133 kfree(mdev->busy_urbs);
1249exit_free3: 1134exit_free3:
@@ -1283,7 +1168,8 @@ static void hdm_disconnect(struct usb_interface *interface)
1283 del_timer_sync(&mdev->link_stat_timer); 1168 del_timer_sync(&mdev->link_stat_timer);
1284 cancel_work_sync(&mdev->poll_work_obj); 1169 cancel_work_sync(&mdev->poll_work_obj);
1285 1170
1286 destroy_most_dci_obj(mdev->dci); 1171 device_unregister(&mdev->dci->dev);
1172 kfree(mdev->dci);
1287 most_deregister_interface(&mdev->iface); 1173 most_deregister_interface(&mdev->iface);
1288 1174
1289 kfree(mdev->busy_urbs); 1175 kfree(mdev->busy_urbs);
diff --git a/drivers/staging/most/aim-v4l2/Kconfig b/drivers/staging/most/video/Kconfig
index d70eaaf0936c..ce6af4f951a6 100644
--- a/drivers/staging/most/aim-v4l2/Kconfig
+++ b/drivers/staging/most/video/Kconfig
@@ -2,11 +2,11 @@
2# MOST V4L2 configuration 2# MOST V4L2 configuration
3# 3#
4 4
5config AIM_V4L2 5config MOST_VIDEO
6 tristate "V4L2 AIM" 6 tristate "Video"
7 depends on VIDEO_V4L2 7 depends on VIDEO_V4L2
8 ---help--- 8 ---help---
9 Say Y here if you want to commumicate via Video 4 Linux. 9 Say Y here if you want to commumicate via Video 4 Linux.
10 10
11 To compile this driver as a module, choose M here: the 11 To compile this driver as a module, choose M here: the
12 module will be called aim_v4l2. \ No newline at end of file 12 module will be called most_video.
diff --git a/drivers/staging/most/video/Makefile b/drivers/staging/most/video/Makefile
new file mode 100644
index 000000000000..1c8e520e02a2
--- /dev/null
+++ b/drivers/staging/most/video/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_MOST_VIDEO) += most_video.o
2
3most_video-objs := video.o
4ccflags-y += -Idrivers/staging/
diff --git a/drivers/staging/most/aim-v4l2/video.c b/drivers/staging/most/video/video.c
index 7783bc2dd9f5..ef23e8524b1e 100644
--- a/drivers/staging/most/aim-v4l2/video.c
+++ b/drivers/staging/most/video/video.c
@@ -1,14 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * V4L2 AIM - V4L2 Application Interface Module for MostCore 3 * video.c - V4L2 component for Mostcore
3 * 4 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG 5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
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 * This file is licensed under GPLv2.
12 */ 6 */
13 7
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -27,11 +21,11 @@
27#include <media/v4l2-ctrls.h> 21#include <media/v4l2-ctrls.h>
28#include <media/v4l2-fh.h> 22#include <media/v4l2-fh.h>
29 23
30#include "mostcore.h" 24#include "most/core.h"
31 25
32#define V4L2_AIM_MAX_INPUT 1 26#define V4L2_CMP_MAX_INPUT 1
33 27
34static struct most_aim aim_info; 28static struct core_component comp;
35 29
36struct most_video_dev { 30struct most_video_dev {
37 struct most_interface *iface; 31 struct most_interface *iface;
@@ -52,7 +46,7 @@ struct most_video_dev {
52 wait_queue_head_t wait_data; 46 wait_queue_head_t wait_data;
53}; 47};
54 48
55struct aim_fh { 49struct comp_fh {
56 /* must be the first field of this struct! */ 50 /* must be the first field of this struct! */
57 struct v4l2_fh fh; 51 struct v4l2_fh fh;
58 struct most_video_dev *mdev; 52 struct most_video_dev *mdev;
@@ -72,14 +66,14 @@ static inline struct mbo *get_top_mbo(struct most_video_dev *mdev)
72 return list_first_entry(&mdev->pending_mbos, struct mbo, list); 66 return list_first_entry(&mdev->pending_mbos, struct mbo, list);
73} 67}
74 68
75static int aim_vdev_open(struct file *filp) 69static int comp_vdev_open(struct file *filp)
76{ 70{
77 int ret; 71 int ret;
78 struct video_device *vdev = video_devdata(filp); 72 struct video_device *vdev = video_devdata(filp);
79 struct most_video_dev *mdev = video_drvdata(filp); 73 struct most_video_dev *mdev = video_drvdata(filp);
80 struct aim_fh *fh; 74 struct comp_fh *fh;
81 75
82 v4l2_info(&mdev->v4l2_dev, "aim_vdev_open()\n"); 76 v4l2_info(&mdev->v4l2_dev, "comp_vdev_open()\n");
83 77
84 switch (vdev->vfl_type) { 78 switch (vdev->vfl_type) {
85 case VFL_TYPE_GRABBER: 79 case VFL_TYPE_GRABBER:
@@ -104,7 +98,7 @@ static int aim_vdev_open(struct file *filp)
104 98
105 v4l2_fh_add(&fh->fh); 99 v4l2_fh_add(&fh->fh);
106 100
107 ret = most_start_channel(mdev->iface, mdev->ch_idx, &aim_info); 101 ret = most_start_channel(mdev->iface, mdev->ch_idx, &comp);
108 if (ret) { 102 if (ret) {
109 v4l2_err(&mdev->v4l2_dev, "most_start_channel() failed\n"); 103 v4l2_err(&mdev->v4l2_dev, "most_start_channel() failed\n");
110 goto err_rm; 104 goto err_rm;
@@ -122,13 +116,13 @@ err_dec:
122 return ret; 116 return ret;
123} 117}
124 118
125static int aim_vdev_close(struct file *filp) 119static int comp_vdev_close(struct file *filp)
126{ 120{
127 struct aim_fh *fh = filp->private_data; 121 struct comp_fh *fh = filp->private_data;
128 struct most_video_dev *mdev = fh->mdev; 122 struct most_video_dev *mdev = fh->mdev;
129 struct mbo *mbo, *tmp; 123 struct mbo *mbo, *tmp;
130 124
131 v4l2_info(&mdev->v4l2_dev, "aim_vdev_close()\n"); 125 v4l2_info(&mdev->v4l2_dev, "comp_vdev_close()\n");
132 126
133 /* 127 /*
134 * We need to put MBOs back before we call most_stop_channel() 128 * We need to put MBOs back before we call most_stop_channel()
@@ -148,7 +142,7 @@ static int aim_vdev_close(struct file *filp)
148 spin_lock_irq(&mdev->list_lock); 142 spin_lock_irq(&mdev->list_lock);
149 } 143 }
150 spin_unlock_irq(&mdev->list_lock); 144 spin_unlock_irq(&mdev->list_lock);
151 most_stop_channel(mdev->iface, mdev->ch_idx, &aim_info); 145 most_stop_channel(mdev->iface, mdev->ch_idx, &comp);
152 mdev->mute = false; 146 mdev->mute = false;
153 147
154 v4l2_fh_del(&fh->fh); 148 v4l2_fh_del(&fh->fh);
@@ -159,10 +153,10 @@ static int aim_vdev_close(struct file *filp)
159 return 0; 153 return 0;
160} 154}
161 155
162static ssize_t aim_vdev_read(struct file *filp, char __user *buf, 156static ssize_t comp_vdev_read(struct file *filp, char __user *buf,
163 size_t count, loff_t *pos) 157 size_t count, loff_t *pos)
164{ 158{
165 struct aim_fh *fh = filp->private_data; 159 struct comp_fh *fh = filp->private_data;
166 struct most_video_dev *mdev = fh->mdev; 160 struct most_video_dev *mdev = fh->mdev;
167 int ret = 0; 161 int ret = 0;
168 162
@@ -209,9 +203,9 @@ static ssize_t aim_vdev_read(struct file *filp, char __user *buf,
209 return ret; 203 return ret;
210} 204}
211 205
212static __poll_t aim_vdev_poll(struct file *filp, poll_table *wait) 206static __poll_t comp_vdev_poll(struct file *filp, poll_table *wait)
213{ 207{
214 struct aim_fh *fh = filp->private_data; 208 struct comp_fh *fh = filp->private_data;
215 struct most_video_dev *mdev = fh->mdev; 209 struct most_video_dev *mdev = fh->mdev;
216 __poll_t mask = 0; 210 __poll_t mask = 0;
217 211
@@ -224,7 +218,7 @@ static __poll_t aim_vdev_poll(struct file *filp, poll_table *wait)
224 return mask; 218 return mask;
225} 219}
226 220
227static void aim_set_format_struct(struct v4l2_format *f) 221static void comp_set_format_struct(struct v4l2_format *f)
228{ 222{
229 f->fmt.pix.width = 8; 223 f->fmt.pix.width = 8;
230 f->fmt.pix.height = 8; 224 f->fmt.pix.height = 8;
@@ -236,8 +230,8 @@ static void aim_set_format_struct(struct v4l2_format *f)
236 f->fmt.pix.priv = 0; 230 f->fmt.pix.priv = 0;
237} 231}
238 232
239static int aim_set_format(struct most_video_dev *mdev, unsigned int cmd, 233static int comp_set_format(struct most_video_dev *mdev, unsigned int cmd,
240 struct v4l2_format *format) 234 struct v4l2_format *format)
241{ 235{
242 if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_MPEG) 236 if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_MPEG)
243 return -EINVAL; 237 return -EINVAL;
@@ -245,7 +239,7 @@ static int aim_set_format(struct most_video_dev *mdev, unsigned int cmd,
245 if (cmd == VIDIOC_TRY_FMT) 239 if (cmd == VIDIOC_TRY_FMT)
246 return 0; 240 return 0;
247 241
248 aim_set_format_struct(format); 242 comp_set_format_struct(format);
249 243
250 return 0; 244 return 0;
251} 245}
@@ -253,12 +247,12 @@ static int aim_set_format(struct most_video_dev *mdev, unsigned int cmd,
253static int vidioc_querycap(struct file *file, void *priv, 247static int vidioc_querycap(struct file *file, void *priv,
254 struct v4l2_capability *cap) 248 struct v4l2_capability *cap)
255{ 249{
256 struct aim_fh *fh = priv; 250 struct comp_fh *fh = priv;
257 struct most_video_dev *mdev = fh->mdev; 251 struct most_video_dev *mdev = fh->mdev;
258 252
259 v4l2_info(&mdev->v4l2_dev, "vidioc_querycap()\n"); 253 v4l2_info(&mdev->v4l2_dev, "vidioc_querycap()\n");
260 254
261 strlcpy(cap->driver, "v4l2_most_aim", sizeof(cap->driver)); 255 strlcpy(cap->driver, "v4l2_component", sizeof(cap->driver));
262 strlcpy(cap->card, "MOST", sizeof(cap->card)); 256 strlcpy(cap->card, "MOST", sizeof(cap->card));
263 snprintf(cap->bus_info, sizeof(cap->bus_info), 257 snprintf(cap->bus_info, sizeof(cap->bus_info),
264 "%s", mdev->iface->description); 258 "%s", mdev->iface->description);
@@ -273,7 +267,7 @@ static int vidioc_querycap(struct file *file, void *priv,
273static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 267static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
274 struct v4l2_fmtdesc *f) 268 struct v4l2_fmtdesc *f)
275{ 269{
276 struct aim_fh *fh = priv; 270 struct comp_fh *fh = priv;
277 struct most_video_dev *mdev = fh->mdev; 271 struct most_video_dev *mdev = fh->mdev;
278 272
279 v4l2_info(&mdev->v4l2_dev, "vidioc_enum_fmt_vid_cap() %d\n", f->index); 273 v4l2_info(&mdev->v4l2_dev, "vidioc_enum_fmt_vid_cap() %d\n", f->index);
@@ -292,36 +286,36 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
292static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, 286static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
293 struct v4l2_format *f) 287 struct v4l2_format *f)
294{ 288{
295 struct aim_fh *fh = priv; 289 struct comp_fh *fh = priv;
296 struct most_video_dev *mdev = fh->mdev; 290 struct most_video_dev *mdev = fh->mdev;
297 291
298 v4l2_info(&mdev->v4l2_dev, "vidioc_g_fmt_vid_cap()\n"); 292 v4l2_info(&mdev->v4l2_dev, "vidioc_g_fmt_vid_cap()\n");
299 293
300 aim_set_format_struct(f); 294 comp_set_format_struct(f);
301 return 0; 295 return 0;
302} 296}
303 297
304static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, 298static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
305 struct v4l2_format *f) 299 struct v4l2_format *f)
306{ 300{
307 struct aim_fh *fh = priv; 301 struct comp_fh *fh = priv;
308 struct most_video_dev *mdev = fh->mdev; 302 struct most_video_dev *mdev = fh->mdev;
309 303
310 return aim_set_format(mdev, VIDIOC_TRY_FMT, f); 304 return comp_set_format(mdev, VIDIOC_TRY_FMT, f);
311} 305}
312 306
313static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 307static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
314 struct v4l2_format *f) 308 struct v4l2_format *f)
315{ 309{
316 struct aim_fh *fh = priv; 310 struct comp_fh *fh = priv;
317 struct most_video_dev *mdev = fh->mdev; 311 struct most_video_dev *mdev = fh->mdev;
318 312
319 return aim_set_format(mdev, VIDIOC_S_FMT, f); 313 return comp_set_format(mdev, VIDIOC_S_FMT, f);
320} 314}
321 315
322static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm) 316static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
323{ 317{
324 struct aim_fh *fh = priv; 318 struct comp_fh *fh = priv;
325 struct most_video_dev *mdev = fh->mdev; 319 struct most_video_dev *mdev = fh->mdev;
326 320
327 v4l2_info(&mdev->v4l2_dev, "vidioc_g_std()\n"); 321 v4l2_info(&mdev->v4l2_dev, "vidioc_g_std()\n");
@@ -333,10 +327,10 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
333static int vidioc_enum_input(struct file *file, void *priv, 327static int vidioc_enum_input(struct file *file, void *priv,
334 struct v4l2_input *input) 328 struct v4l2_input *input)
335{ 329{
336 struct aim_fh *fh = priv; 330 struct comp_fh *fh = priv;
337 struct most_video_dev *mdev = fh->mdev; 331 struct most_video_dev *mdev = fh->mdev;
338 332
339 if (input->index >= V4L2_AIM_MAX_INPUT) 333 if (input->index >= V4L2_CMP_MAX_INPUT)
340 return -EINVAL; 334 return -EINVAL;
341 335
342 strcpy(input->name, "MOST Video"); 336 strcpy(input->name, "MOST Video");
@@ -350,7 +344,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
350 344
351static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) 345static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
352{ 346{
353 struct aim_fh *fh = priv; 347 struct comp_fh *fh = priv;
354 struct most_video_dev *mdev = fh->mdev; 348 struct most_video_dev *mdev = fh->mdev;
355 *i = mdev->ctrl_input; 349 *i = mdev->ctrl_input;
356 return 0; 350 return 0;
@@ -358,23 +352,23 @@ static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
358 352
359static int vidioc_s_input(struct file *file, void *priv, unsigned int index) 353static int vidioc_s_input(struct file *file, void *priv, unsigned int index)
360{ 354{
361 struct aim_fh *fh = priv; 355 struct comp_fh *fh = priv;
362 struct most_video_dev *mdev = fh->mdev; 356 struct most_video_dev *mdev = fh->mdev;
363 357
364 v4l2_info(&mdev->v4l2_dev, "vidioc_s_input(%d)\n", index); 358 v4l2_info(&mdev->v4l2_dev, "vidioc_s_input(%d)\n", index);
365 359
366 if (index >= V4L2_AIM_MAX_INPUT) 360 if (index >= V4L2_CMP_MAX_INPUT)
367 return -EINVAL; 361 return -EINVAL;
368 mdev->ctrl_input = index; 362 mdev->ctrl_input = index;
369 return 0; 363 return 0;
370} 364}
371 365
372static const struct v4l2_file_operations aim_fops = { 366static const struct v4l2_file_operations comp_fops = {
373 .owner = THIS_MODULE, 367 .owner = THIS_MODULE,
374 .open = aim_vdev_open, 368 .open = comp_vdev_open,
375 .release = aim_vdev_close, 369 .release = comp_vdev_close,
376 .read = aim_vdev_read, 370 .read = comp_vdev_read,
377 .poll = aim_vdev_poll, 371 .poll = comp_vdev_poll,
378 .unlocked_ioctl = video_ioctl2, 372 .unlocked_ioctl = video_ioctl2,
379}; 373};
380 374
@@ -390,8 +384,8 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
390 .vidioc_s_input = vidioc_s_input, 384 .vidioc_s_input = vidioc_s_input,
391}; 385};
392 386
393static const struct video_device aim_videodev_template = { 387static const struct video_device comp_videodev_template = {
394 .fops = &aim_fops, 388 .fops = &comp_fops,
395 .release = video_device_release, 389 .release = video_device_release,
396 .ioctl_ops = &video_ioctl_ops, 390 .ioctl_ops = &video_ioctl_ops,
397 .tvnorms = V4L2_STD_UNKNOWN, 391 .tvnorms = V4L2_STD_UNKNOWN,
@@ -399,7 +393,7 @@ static const struct video_device aim_videodev_template = {
399 393
400/**************************************************************************/ 394/**************************************************************************/
401 395
402static struct most_video_dev *get_aim_dev( 396static struct most_video_dev *get_comp_dev(
403 struct most_interface *iface, int channel_idx) 397 struct most_interface *iface, int channel_idx)
404{ 398{
405 struct most_video_dev *mdev; 399 struct most_video_dev *mdev;
@@ -416,11 +410,11 @@ static struct most_video_dev *get_aim_dev(
416 return NULL; 410 return NULL;
417} 411}
418 412
419static int aim_rx_data(struct mbo *mbo) 413static int comp_rx_data(struct mbo *mbo)
420{ 414{
421 unsigned long flags; 415 unsigned long flags;
422 struct most_video_dev *mdev = 416 struct most_video_dev *mdev =
423 get_aim_dev(mbo->ifp, mbo->hdm_channel_id); 417 get_comp_dev(mbo->ifp, mbo->hdm_channel_id);
424 418
425 if (!mdev) 419 if (!mdev)
426 return -EIO; 420 return -EIO;
@@ -437,11 +431,11 @@ static int aim_rx_data(struct mbo *mbo)
437 return 0; 431 return 0;
438} 432}
439 433
440static int aim_register_videodev(struct most_video_dev *mdev) 434static int comp_register_videodev(struct most_video_dev *mdev)
441{ 435{
442 int ret; 436 int ret;
443 437
444 v4l2_info(&mdev->v4l2_dev, "aim_register_videodev()\n"); 438 v4l2_info(&mdev->v4l2_dev, "comp_register_videodev()\n");
445 439
446 init_waitqueue_head(&mdev->wait_data); 440 init_waitqueue_head(&mdev->wait_data);
447 441
@@ -451,7 +445,7 @@ static int aim_register_videodev(struct most_video_dev *mdev)
451 return -ENOMEM; 445 return -ENOMEM;
452 446
453 /* Fill the video capture device struct */ 447 /* Fill the video capture device struct */
454 *mdev->vdev = aim_videodev_template; 448 *mdev->vdev = comp_videodev_template;
455 mdev->vdev->v4l2_dev = &mdev->v4l2_dev; 449 mdev->vdev->v4l2_dev = &mdev->v4l2_dev;
456 mdev->vdev->lock = &mdev->lock; 450 mdev->vdev->lock = &mdev->lock;
457 snprintf(mdev->vdev->name, sizeof(mdev->vdev->name), "MOST: %s", 451 snprintf(mdev->vdev->name, sizeof(mdev->vdev->name), "MOST: %s",
@@ -469,14 +463,14 @@ static int aim_register_videodev(struct most_video_dev *mdev)
469 return ret; 463 return ret;
470} 464}
471 465
472static void aim_unregister_videodev(struct most_video_dev *mdev) 466static void comp_unregister_videodev(struct most_video_dev *mdev)
473{ 467{
474 v4l2_info(&mdev->v4l2_dev, "aim_unregister_videodev()\n"); 468 v4l2_info(&mdev->v4l2_dev, "comp_unregister_videodev()\n");
475 469
476 video_unregister_device(mdev->vdev); 470 video_unregister_device(mdev->vdev);
477} 471}
478 472
479static void aim_v4l2_dev_release(struct v4l2_device *v4l2_dev) 473static void comp_v4l2_dev_release(struct v4l2_device *v4l2_dev)
480{ 474{
481 struct most_video_dev *mdev = 475 struct most_video_dev *mdev =
482 container_of(v4l2_dev, struct most_video_dev, v4l2_dev); 476 container_of(v4l2_dev, struct most_video_dev, v4l2_dev);
@@ -485,14 +479,13 @@ static void aim_v4l2_dev_release(struct v4l2_device *v4l2_dev)
485 kfree(mdev); 479 kfree(mdev);
486} 480}
487 481
488static int aim_probe_channel(struct most_interface *iface, int channel_idx, 482static int comp_probe_channel(struct most_interface *iface, int channel_idx,
489 struct most_channel_config *ccfg, 483 struct most_channel_config *ccfg, char *name)
490 struct kobject *parent, char *name)
491{ 484{
492 int ret; 485 int ret;
493 struct most_video_dev *mdev = get_aim_dev(iface, channel_idx); 486 struct most_video_dev *mdev = get_comp_dev(iface, channel_idx);
494 487
495 pr_info("aim_probe_channel(%s)\n", name); 488 pr_info("comp_probe_channel(%s)\n", name);
496 489
497 if (mdev) { 490 if (mdev) {
498 pr_err("channel already linked\n"); 491 pr_err("channel already linked\n");
@@ -520,7 +513,7 @@ static int aim_probe_channel(struct most_interface *iface, int channel_idx,
520 INIT_LIST_HEAD(&mdev->pending_mbos); 513 INIT_LIST_HEAD(&mdev->pending_mbos);
521 mdev->iface = iface; 514 mdev->iface = iface;
522 mdev->ch_idx = channel_idx; 515 mdev->ch_idx = channel_idx;
523 mdev->v4l2_dev.release = aim_v4l2_dev_release; 516 mdev->v4l2_dev.release = comp_v4l2_dev_release;
524 517
525 /* Create the v4l2_device */ 518 /* Create the v4l2_device */
526 strlcpy(mdev->v4l2_dev.name, name, sizeof(mdev->v4l2_dev.name)); 519 strlcpy(mdev->v4l2_dev.name, name, sizeof(mdev->v4l2_dev.name));
@@ -531,14 +524,14 @@ static int aim_probe_channel(struct most_interface *iface, int channel_idx,
531 return ret; 524 return ret;
532 } 525 }
533 526
534 ret = aim_register_videodev(mdev); 527 ret = comp_register_videodev(mdev);
535 if (ret) 528 if (ret)
536 goto err_unreg; 529 goto err_unreg;
537 530
538 spin_lock_irq(&list_lock); 531 spin_lock_irq(&list_lock);
539 list_add(&mdev->list, &video_devices); 532 list_add(&mdev->list, &video_devices);
540 spin_unlock_irq(&list_lock); 533 spin_unlock_irq(&list_lock);
541 v4l2_info(&mdev->v4l2_dev, "aim_probe_channel() done\n"); 534 v4l2_info(&mdev->v4l2_dev, "comp_probe_channel() done\n");
542 return 0; 535 return 0;
543 536
544err_unreg: 537err_unreg:
@@ -547,48 +540,48 @@ err_unreg:
547 return ret; 540 return ret;
548} 541}
549 542
550static int aim_disconnect_channel(struct most_interface *iface, 543static int comp_disconnect_channel(struct most_interface *iface,
551 int channel_idx) 544 int channel_idx)
552{ 545{
553 struct most_video_dev *mdev = get_aim_dev(iface, channel_idx); 546 struct most_video_dev *mdev = get_comp_dev(iface, channel_idx);
554 547
555 if (!mdev) { 548 if (!mdev) {
556 pr_err("no such channel is linked\n"); 549 pr_err("no such channel is linked\n");
557 return -ENOENT; 550 return -ENOENT;
558 } 551 }
559 552
560 v4l2_info(&mdev->v4l2_dev, "aim_disconnect_channel()\n"); 553 v4l2_info(&mdev->v4l2_dev, "comp_disconnect_channel()\n");
561 554
562 spin_lock_irq(&list_lock); 555 spin_lock_irq(&list_lock);
563 list_del(&mdev->list); 556 list_del(&mdev->list);
564 spin_unlock_irq(&list_lock); 557 spin_unlock_irq(&list_lock);
565 558
566 aim_unregister_videodev(mdev); 559 comp_unregister_videodev(mdev);
567 v4l2_device_disconnect(&mdev->v4l2_dev); 560 v4l2_device_disconnect(&mdev->v4l2_dev);
568 v4l2_device_put(&mdev->v4l2_dev); 561 v4l2_device_put(&mdev->v4l2_dev);
569 return 0; 562 return 0;
570} 563}
571 564
572static struct most_aim aim_info = { 565static struct core_component comp_info = {
573 .name = "v4l", 566 .name = "video",
574 .probe_channel = aim_probe_channel, 567 .probe_channel = comp_probe_channel,
575 .disconnect_channel = aim_disconnect_channel, 568 .disconnect_channel = comp_disconnect_channel,
576 .rx_completion = aim_rx_data, 569 .rx_completion = comp_rx_data,
577}; 570};
578 571
579static int __init aim_init(void) 572static int __init comp_init(void)
580{ 573{
581 spin_lock_init(&list_lock); 574 spin_lock_init(&list_lock);
582 return most_register_aim(&aim_info); 575 return most_register_component(&comp);
583} 576}
584 577
585static void __exit aim_exit(void) 578static void __exit comp_exit(void)
586{ 579{
587 struct most_video_dev *mdev, *tmp; 580 struct most_video_dev *mdev, *tmp;
588 581
589 /* 582 /*
590 * As the mostcore currently doesn't call disconnect_channel() 583 * As the mostcore currently doesn't call disconnect_channel()
591 * for linked channels while we call most_deregister_aim() 584 * for linked channels while we call most_deregister_component()
592 * we simulate this call here. 585 * we simulate this call here.
593 * This must be fixed in core. 586 * This must be fixed in core.
594 */ 587 */
@@ -597,20 +590,20 @@ static void __exit aim_exit(void)
597 list_del(&mdev->list); 590 list_del(&mdev->list);
598 spin_unlock_irq(&list_lock); 591 spin_unlock_irq(&list_lock);
599 592
600 aim_unregister_videodev(mdev); 593 comp_unregister_videodev(mdev);
601 v4l2_device_disconnect(&mdev->v4l2_dev); 594 v4l2_device_disconnect(&mdev->v4l2_dev);
602 v4l2_device_put(&mdev->v4l2_dev); 595 v4l2_device_put(&mdev->v4l2_dev);
603 spin_lock_irq(&list_lock); 596 spin_lock_irq(&list_lock);
604 } 597 }
605 spin_unlock_irq(&list_lock); 598 spin_unlock_irq(&list_lock);
606 599
607 most_deregister_aim(&aim_info); 600 most_deregister_component(&comp_info);
608 BUG_ON(!list_empty(&video_devices)); 601 BUG_ON(!list_empty(&video_devices));
609} 602}
610 603
611module_init(aim_init); 604module_init(comp_init);
612module_exit(aim_exit); 605module_exit(comp_exit);
613 606
614MODULE_DESCRIPTION("V4L2 Application Interface Module for MostCore"); 607MODULE_DESCRIPTION("V4L2 Component Module for Mostcore");
615MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>"); 608MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
616MODULE_LICENSE("GPL"); 609MODULE_LICENSE("GPL");
diff --git a/fs/ncpfs/Kconfig b/drivers/staging/ncpfs/Kconfig
index c931cf22a1f6..c931cf22a1f6 100644
--- a/fs/ncpfs/Kconfig
+++ b/drivers/staging/ncpfs/Kconfig
diff --git a/fs/ncpfs/Makefile b/drivers/staging/ncpfs/Makefile
index 66fe5f878817..66fe5f878817 100644
--- a/fs/ncpfs/Makefile
+++ b/drivers/staging/ncpfs/Makefile
diff --git a/drivers/staging/ncpfs/TODO b/drivers/staging/ncpfs/TODO
new file mode 100644
index 000000000000..9b6d38b7e248
--- /dev/null
+++ b/drivers/staging/ncpfs/TODO
@@ -0,0 +1,4 @@
1The ncpfs code will be removed soon from the kernel tree as it is old and
2obsolete and broken.
3
4Don't worry about fixing up anything here, it's not needed.
diff --git a/fs/ncpfs/dir.c b/drivers/staging/ncpfs/dir.c
index 0c57c5c5d40a..0c57c5c5d40a 100644
--- a/fs/ncpfs/dir.c
+++ b/drivers/staging/ncpfs/dir.c
diff --git a/fs/ncpfs/file.c b/drivers/staging/ncpfs/file.c
index 8f8cc0334ddd..8f8cc0334ddd 100644
--- a/fs/ncpfs/file.c
+++ b/drivers/staging/ncpfs/file.c
diff --git a/fs/ncpfs/getopt.c b/drivers/staging/ncpfs/getopt.c
index 5c941bef14c4..5c941bef14c4 100644
--- a/fs/ncpfs/getopt.c
+++ b/drivers/staging/ncpfs/getopt.c
diff --git a/fs/ncpfs/getopt.h b/drivers/staging/ncpfs/getopt.h
index 30f0da317670..30f0da317670 100644
--- a/fs/ncpfs/getopt.h
+++ b/drivers/staging/ncpfs/getopt.h
diff --git a/fs/ncpfs/inode.c b/drivers/staging/ncpfs/inode.c
index 41de88cdc053..bb411610a071 100644
--- a/fs/ncpfs/inode.c
+++ b/drivers/staging/ncpfs/inode.c
@@ -53,7 +53,8 @@ static struct kmem_cache * ncp_inode_cachep;
53static struct inode *ncp_alloc_inode(struct super_block *sb) 53static struct inode *ncp_alloc_inode(struct super_block *sb)
54{ 54{
55 struct ncp_inode_info *ei; 55 struct ncp_inode_info *ei;
56 ei = (struct ncp_inode_info *)kmem_cache_alloc(ncp_inode_cachep, GFP_KERNEL); 56
57 ei = kmem_cache_alloc(ncp_inode_cachep, GFP_KERNEL);
57 if (!ei) 58 if (!ei)
58 return NULL; 59 return NULL;
59 return &ei->vfs_inode; 60 return &ei->vfs_inode;
diff --git a/fs/ncpfs/ioctl.c b/drivers/staging/ncpfs/ioctl.c
index d378b98cd7b6..d378b98cd7b6 100644
--- a/fs/ncpfs/ioctl.c
+++ b/drivers/staging/ncpfs/ioctl.c
diff --git a/fs/ncpfs/mmap.c b/drivers/staging/ncpfs/mmap.c
index a5c5cf2ff007..a5c5cf2ff007 100644
--- a/fs/ncpfs/mmap.c
+++ b/drivers/staging/ncpfs/mmap.c
diff --git a/fs/ncpfs/ncp_fs.h b/drivers/staging/ncpfs/ncp_fs.h
index bdd262b6c198..bdd262b6c198 100644
--- a/fs/ncpfs/ncp_fs.h
+++ b/drivers/staging/ncpfs/ncp_fs.h
diff --git a/fs/ncpfs/ncp_fs_i.h b/drivers/staging/ncpfs/ncp_fs_i.h
index 3432bafb53a5..3432bafb53a5 100644
--- a/fs/ncpfs/ncp_fs_i.h
+++ b/drivers/staging/ncpfs/ncp_fs_i.h
diff --git a/fs/ncpfs/ncp_fs_sb.h b/drivers/staging/ncpfs/ncp_fs_sb.h
index f06cde4adf71..f06cde4adf71 100644
--- a/fs/ncpfs/ncp_fs_sb.h
+++ b/drivers/staging/ncpfs/ncp_fs_sb.h
diff --git a/fs/ncpfs/ncplib_kernel.c b/drivers/staging/ncpfs/ncplib_kernel.c
index 804adfebba2f..804adfebba2f 100644
--- a/fs/ncpfs/ncplib_kernel.c
+++ b/drivers/staging/ncpfs/ncplib_kernel.c
diff --git a/fs/ncpfs/ncplib_kernel.h b/drivers/staging/ncpfs/ncplib_kernel.h
index aaae8aa9bf7d..aaae8aa9bf7d 100644
--- a/fs/ncpfs/ncplib_kernel.h
+++ b/drivers/staging/ncpfs/ncplib_kernel.h
diff --git a/fs/ncpfs/ncpsign_kernel.c b/drivers/staging/ncpfs/ncpsign_kernel.c
index 8085b1a3ba47..8085b1a3ba47 100644
--- a/fs/ncpfs/ncpsign_kernel.c
+++ b/drivers/staging/ncpfs/ncpsign_kernel.c
diff --git a/fs/ncpfs/ncpsign_kernel.h b/drivers/staging/ncpfs/ncpsign_kernel.h
index 57ff0a0650b8..57ff0a0650b8 100644
--- a/fs/ncpfs/ncpsign_kernel.h
+++ b/drivers/staging/ncpfs/ncpsign_kernel.h
diff --git a/fs/ncpfs/sock.c b/drivers/staging/ncpfs/sock.c
index 4c13174d85b7..4c13174d85b7 100644
--- a/fs/ncpfs/sock.c
+++ b/drivers/staging/ncpfs/sock.c
diff --git a/fs/ncpfs/symlink.c b/drivers/staging/ncpfs/symlink.c
index b6e16da4837a..b6e16da4837a 100644
--- a/fs/ncpfs/symlink.c
+++ b/drivers/staging/ncpfs/symlink.c
diff --git a/drivers/staging/nvec/nvec-keytable.h b/drivers/staging/nvec/nvec-keytable.h
index 7008c96bdbbe..ac58e87e6a4e 100644
--- a/drivers/staging/nvec/nvec-keytable.h
+++ b/drivers/staging/nvec/nvec-keytable.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * drivers/input/keyboard/tegra-nvec.c 3 * drivers/input/keyboard/tegra-nvec.c
3 * 4 *
@@ -5,19 +6,6 @@
5 * embedded controller 6 * embedded controller
6 * 7 *
7 * Copyright (c) 2009, NVIDIA Corporation. 8 * Copyright (c) 2009, NVIDIA Corporation.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see http://www.gnu.org/licenses
21 */ 9 */
22 10
23static unsigned short code_tab_102us[] = { 11static unsigned short code_tab_102us[] = {
diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
index 4ff8f47385da..52054a528723 100644
--- a/drivers/staging/nvec/nvec.c
+++ b/drivers/staging/nvec/nvec.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * NVEC: NVIDIA compliant embedded controller interface 3 * NVEC: NVIDIA compliant embedded controller interface
3 * 4 *
@@ -7,11 +8,6 @@
7 * Ilya Petrov <ilya.muromec@gmail.com> 8 * Ilya Petrov <ilya.muromec@gmail.com>
8 * Marc Dietrich <marvin24@gmx.de> 9 * Marc Dietrich <marvin24@gmx.de>
9 * Julian Andres Klode <jak@jak-linux.org> 10 * Julian Andres Klode <jak@jak-linux.org>
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 *
15 */ 11 */
16 12
17#include <linux/kernel.h> 13#include <linux/kernel.h>
diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
index aa7c70ef94f5..25efcdfa4f20 100644
--- a/drivers/staging/nvec/nvec.h
+++ b/drivers/staging/nvec/nvec.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * NVEC: NVIDIA compliant embedded controller interface 3 * NVEC: NVIDIA compliant embedded controller interface
3 * 4 *
@@ -7,11 +8,6 @@
7 * Ilya Petrov <ilya.muromec@gmail.com> 8 * Ilya Petrov <ilya.muromec@gmail.com>
8 * Marc Dietrich <marvin24@gmx.de> 9 * Marc Dietrich <marvin24@gmx.de>
9 * Julian Andres Klode <jak@jak-linux.org> 10 * Julian Andres Klode <jak@jak-linux.org>
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 *
15 */ 11 */
16 12
17#ifndef __LINUX_MFD_NVEC 13#ifndef __LINUX_MFD_NVEC
diff --git a/drivers/staging/nvec/nvec_kbd.c b/drivers/staging/nvec/nvec_kbd.c
index a01f486621eb..01dbb66f7e9a 100644
--- a/drivers/staging/nvec/nvec_kbd.c
+++ b/drivers/staging/nvec/nvec_kbd.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * nvec_kbd: keyboard driver for a NVIDIA compliant embedded controller 3 * nvec_kbd: keyboard driver for a NVIDIA compliant embedded controller
3 * 4 *
@@ -5,11 +6,6 @@
5 * 6 *
6 * Authors: Pierre-Hugues Husson <phhusson@free.fr> 7 * Authors: Pierre-Hugues Husson <phhusson@free.fr>
7 * Marc Dietrich <marvin24@gmx.de> 8 * Marc Dietrich <marvin24@gmx.de>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 *
13 */ 9 */
14 10
15#include <linux/module.h> 11#include <linux/module.h>
diff --git a/drivers/staging/nvec/nvec_paz00.c b/drivers/staging/nvec/nvec_paz00.c
index 51dbeeb3320e..8b4da95081c8 100644
--- a/drivers/staging/nvec/nvec_paz00.c
+++ b/drivers/staging/nvec/nvec_paz00.c
@@ -1,14 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * nvec_paz00: OEM specific driver for Compal PAZ00 based devices 3 * nvec_paz00: OEM specific driver for Compal PAZ00 based devices
3 * 4 *
4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net> 5 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net>
5 * 6 *
6 * Authors: Ilya Petrov <ilya.muromec@gmail.com> 7 * Authors: Ilya Petrov <ilya.muromec@gmail.com>
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 *
12 */ 8 */
13 9
14#include <linux/module.h> 10#include <linux/module.h>
diff --git a/drivers/staging/nvec/nvec_power.c b/drivers/staging/nvec/nvec_power.c
index 3b144a9ea055..0e861c4bfcbf 100644
--- a/drivers/staging/nvec/nvec_power.c
+++ b/drivers/staging/nvec/nvec_power.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * nvec_power: power supply driver for a NVIDIA compliant embedded controller 3 * nvec_power: power supply driver for a NVIDIA compliant embedded controller
3 * 4 *
@@ -5,11 +6,6 @@
5 * 6 *
6 * Authors: Ilya Petrov <ilya.muromec@gmail.com> 7 * Authors: Ilya Petrov <ilya.muromec@gmail.com>
7 * Marc Dietrich <marvin24@gmx.de> 8 * Marc Dietrich <marvin24@gmx.de>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 *
13 */ 9 */
14 10
15#include <linux/module.h> 11#include <linux/module.h>
diff --git a/drivers/staging/nvec/nvec_ps2.c b/drivers/staging/nvec/nvec_ps2.c
index 3b7bce3ffd19..45db29262a9c 100644
--- a/drivers/staging/nvec/nvec_ps2.c
+++ b/drivers/staging/nvec/nvec_ps2.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * nvec_ps2: mouse driver for a NVIDIA compliant embedded controller 3 * nvec_ps2: mouse driver for a NVIDIA compliant embedded controller
3 * 4 *
@@ -6,11 +7,6 @@
6 * Authors: Pierre-Hugues Husson <phhusson@free.fr> 7 * Authors: Pierre-Hugues Husson <phhusson@free.fr>
7 * Ilya Petrov <ilya.muromec@gmail.com> 8 * Ilya Petrov <ilya.muromec@gmail.com>
8 * Marc Dietrich <marvin24@gmx.de> 9 * Marc Dietrich <marvin24@gmx.de>
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
13 *
14 */ 10 */
15 11
16#include <linux/module.h> 12#include <linux/module.h>
diff --git a/drivers/staging/octeon/Makefile b/drivers/staging/octeon/Makefile
index 8ca17210d917..3887cf5f1e84 100644
--- a/drivers/staging/octeon/Makefile
+++ b/drivers/staging/octeon/Makefile
@@ -1,6 +1,4 @@
1# This file is subject to the terms and conditions of the GNU General Public 1# SPDX-License-Identifier: GPL-2.0
2# License. See the file "COPYING" in the main directory of this archive
3# for more details.
4# 2#
5# Copyright (C) 2005-2009 Cavium Networks 3# Copyright (C) 2005-2009 Cavium Networks
6# 4#
diff --git a/drivers/staging/octeon/ethernet-defines.h b/drivers/staging/octeon/ethernet-defines.h
index 07bd2b87f6a0..1e114422993a 100644
--- a/drivers/staging/octeon/ethernet-defines.h
+++ b/drivers/staging/octeon/ethernet-defines.h
@@ -1,11 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2007 Cavium Networks 5 * Copyright (c) 2003-2007 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11/* 8/*
diff --git a/drivers/staging/octeon/ethernet-mdio.c b/drivers/staging/octeon/ethernet-mdio.c
index 691e4a51ace4..f67f95043887 100644
--- a/drivers/staging/octeon/ethernet-mdio.c
+++ b/drivers/staging/octeon/ethernet-mdio.c
@@ -1,11 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2007 Cavium Networks 5 * Copyright (c) 2003-2007 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11#include <linux/kernel.h> 8#include <linux/kernel.h>
diff --git a/drivers/staging/octeon/ethernet-mdio.h b/drivers/staging/octeon/ethernet-mdio.h
index 5ed8483fc24d..e3771d48c49b 100644
--- a/drivers/staging/octeon/ethernet-mdio.h
+++ b/drivers/staging/octeon/ethernet-mdio.h
@@ -1,11 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2007 Cavium Networks 5 * Copyright (c) 2003-2007 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/octeon/ethernet-mem.c b/drivers/staging/octeon/ethernet-mem.c
index d6172e4dace5..0d26c4a93ec1 100644
--- a/drivers/staging/octeon/ethernet-mem.c
+++ b/drivers/staging/octeon/ethernet-mem.c
@@ -1,11 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2010 Cavium Networks 5 * Copyright (c) 2003-2010 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11#include <linux/kernel.h> 8#include <linux/kernel.h>
diff --git a/drivers/staging/octeon/ethernet-mem.h b/drivers/staging/octeon/ethernet-mem.h
index 62d07c426f89..692dcdb7154d 100644
--- a/drivers/staging/octeon/ethernet-mem.h
+++ b/drivers/staging/octeon/ethernet-mem.h
@@ -1,11 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2007 Cavium Networks 5 * Copyright (c) 2003-2007 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11int cvm_oct_mem_fill_fpa(int pool, int size, int elements); 8int cvm_oct_mem_fill_fpa(int pool, int size, int elements);
diff --git a/drivers/staging/octeon/ethernet-rgmii.c b/drivers/staging/octeon/ethernet-rgmii.c
index 4e7304210bb9..c15376d33891 100644
--- a/drivers/staging/octeon/ethernet-rgmii.c
+++ b/drivers/staging/octeon/ethernet-rgmii.c
@@ -1,11 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2007 Cavium Networks 5 * Copyright (c) 2003-2007 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11#include <linux/kernel.h> 8#include <linux/kernel.h>
diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
index 1a44291318ee..5e271245273c 100644
--- a/drivers/staging/octeon/ethernet-rx.c
+++ b/drivers/staging/octeon/ethernet-rx.c
@@ -1,11 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2010 Cavium Networks 5 * Copyright (c) 2003-2010 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/octeon/ethernet-rx.h b/drivers/staging/octeon/ethernet-rx.h
index 315a63d7094f..096553d8fc99 100644
--- a/drivers/staging/octeon/ethernet-rx.h
+++ b/drivers/staging/octeon/ethernet-rx.h
@@ -1,11 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2007 Cavium Networks 5 * Copyright (c) 2003-2007 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11#include <asm/octeon/cvmx-fau.h> 8#include <asm/octeon/cvmx-fau.h>
diff --git a/drivers/staging/octeon/ethernet-sgmii.c b/drivers/staging/octeon/ethernet-sgmii.c
index 7424dc45ad39..a4a8f094e2b4 100644
--- a/drivers/staging/octeon/ethernet-sgmii.c
+++ b/drivers/staging/octeon/ethernet-sgmii.c
@@ -1,11 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2007 Cavium Networks 5 * Copyright (c) 2003-2007 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11#include <linux/phy.h> 8#include <linux/phy.h>
diff --git a/drivers/staging/octeon/ethernet-spi.c b/drivers/staging/octeon/ethernet-spi.c
index 063dcd07557b..01efdf2a2c20 100644
--- a/drivers/staging/octeon/ethernet-spi.c
+++ b/drivers/staging/octeon/ethernet-spi.c
@@ -1,11 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2007 Cavium Networks 5 * Copyright (c) 2003-2007 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11#include <linux/kernel.h> 8#include <linux/kernel.h>
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index 31f35025d19e..df3441b815bb 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -1,11 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2010 Cavium Networks 5 * Copyright (c) 2003-2010 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11#include <linux/module.h> 8#include <linux/module.h>
diff --git a/drivers/staging/octeon/ethernet-tx.h b/drivers/staging/octeon/ethernet-tx.h
index 84848e4c1664..78936e9b33b0 100644
--- a/drivers/staging/octeon/ethernet-tx.h
+++ b/drivers/staging/octeon/ethernet-tx.h
@@ -1,11 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2007 Cavium Networks 5 * Copyright (c) 2003-2007 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev); 8int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev);
diff --git a/drivers/staging/octeon/ethernet-util.h b/drivers/staging/octeon/ethernet-util.h
index cb5540dc0e9d..31a82873e15c 100644
--- a/drivers/staging/octeon/ethernet-util.h
+++ b/drivers/staging/octeon/ethernet-util.h
@@ -1,11 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2007 Cavium Networks 5 * Copyright (c) 2003-2007 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11#include <asm/octeon/cvmx-pip.h> 8#include <asm/octeon/cvmx-pip.h>
diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
index 429e24adfcf5..9b15c9ed844b 100644
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -1,11 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2007 Cavium Networks 5 * Copyright (c) 2003-2007 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11#include <linux/platform_device.h> 8#include <linux/platform_device.h>
diff --git a/drivers/staging/octeon/octeon-ethernet.h b/drivers/staging/octeon/octeon-ethernet.h
index 9c3f453adaa0..4a07e7f43d12 100644
--- a/drivers/staging/octeon/octeon-ethernet.h
+++ b/drivers/staging/octeon/octeon-ethernet.h
@@ -1,11 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This file is based on code from OCTEON SDK by Cavium Networks. 3 * This file is based on code from OCTEON SDK by Cavium Networks.
3 * 4 *
4 * Copyright (c) 2003-2010 Cavium Networks 5 * Copyright (c) 2003-2010 Cavium Networks
5 *
6 * This file 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 */ 6 */
10 7
11/* 8/*
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c
index 82bffd911435..2744c9f0920e 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon.c
@@ -393,7 +393,8 @@ static void dcon_set_source_sync(struct dcon_priv *dcon, int arg)
393} 393}
394 394
395static ssize_t dcon_mode_show(struct device *dev, 395static ssize_t dcon_mode_show(struct device *dev,
396 struct device_attribute *attr, char *buf) 396 struct device_attribute *attr,
397 char *buf)
397{ 398{
398 struct dcon_priv *dcon = dev_get_drvdata(dev); 399 struct dcon_priv *dcon = dev_get_drvdata(dev);
399 400
@@ -401,7 +402,8 @@ static ssize_t dcon_mode_show(struct device *dev,
401} 402}
402 403
403static ssize_t dcon_sleep_show(struct device *dev, 404static ssize_t dcon_sleep_show(struct device *dev,
404 struct device_attribute *attr, char *buf) 405 struct device_attribute *attr,
406 char *buf)
405{ 407{
406 struct dcon_priv *dcon = dev_get_drvdata(dev); 408 struct dcon_priv *dcon = dev_get_drvdata(dev);
407 409
@@ -409,7 +411,8 @@ static ssize_t dcon_sleep_show(struct device *dev,
409} 411}
410 412
411static ssize_t dcon_freeze_show(struct device *dev, 413static ssize_t dcon_freeze_show(struct device *dev,
412 struct device_attribute *attr, char *buf) 414 struct device_attribute *attr,
415 char *buf)
413{ 416{
414 struct dcon_priv *dcon = dev_get_drvdata(dev); 417 struct dcon_priv *dcon = dev_get_drvdata(dev);
415 418
@@ -417,7 +420,8 @@ static ssize_t dcon_freeze_show(struct device *dev,
417} 420}
418 421
419static ssize_t dcon_mono_show(struct device *dev, 422static ssize_t dcon_mono_show(struct device *dev,
420 struct device_attribute *attr, char *buf) 423 struct device_attribute *attr,
424 char *buf)
421{ 425{
422 struct dcon_priv *dcon = dev_get_drvdata(dev); 426 struct dcon_priv *dcon = dev_get_drvdata(dev);
423 427
@@ -425,13 +429,15 @@ static ssize_t dcon_mono_show(struct device *dev,
425} 429}
426 430
427static ssize_t dcon_resumeline_show(struct device *dev, 431static ssize_t dcon_resumeline_show(struct device *dev,
428 struct device_attribute *attr, char *buf) 432 struct device_attribute *attr,
433 char *buf)
429{ 434{
430 return sprintf(buf, "%d\n", resumeline); 435 return sprintf(buf, "%d\n", resumeline);
431} 436}
432 437
433static ssize_t dcon_mono_store(struct device *dev, 438static ssize_t dcon_mono_store(struct device *dev,
434 struct device_attribute *attr, const char *buf, size_t count) 439 struct device_attribute *attr,
440 const char *buf, size_t count)
435{ 441{
436 unsigned long enable_mono; 442 unsigned long enable_mono;
437 int rc; 443 int rc;
@@ -446,7 +452,8 @@ static ssize_t dcon_mono_store(struct device *dev,
446} 452}
447 453
448static ssize_t dcon_freeze_store(struct device *dev, 454static ssize_t dcon_freeze_store(struct device *dev,
449 struct device_attribute *attr, const char *buf, size_t count) 455 struct device_attribute *attr,
456 const char *buf, size_t count)
450{ 457{
451 struct dcon_priv *dcon = dev_get_drvdata(dev); 458 struct dcon_priv *dcon = dev_get_drvdata(dev);
452 unsigned long output; 459 unsigned long output;
@@ -474,7 +481,8 @@ static ssize_t dcon_freeze_store(struct device *dev,
474} 481}
475 482
476static ssize_t dcon_resumeline_store(struct device *dev, 483static ssize_t dcon_resumeline_store(struct device *dev,
477 struct device_attribute *attr, const char *buf, size_t count) 484 struct device_attribute *attr,
485 const char *buf, size_t count)
478{ 486{
479 unsigned short rl; 487 unsigned short rl;
480 int rc; 488 int rc;
@@ -490,7 +498,8 @@ static ssize_t dcon_resumeline_store(struct device *dev,
490} 498}
491 499
492static ssize_t dcon_sleep_store(struct device *dev, 500static ssize_t dcon_sleep_store(struct device *dev,
493 struct device_attribute *attr, const char *buf, size_t count) 501 struct device_attribute *attr,
502 const char *buf, size_t count)
494{ 503{
495 unsigned long output; 504 unsigned long output;
496 int ret; 505 int ret;
@@ -641,7 +650,8 @@ static int dcon_probe(struct i2c_client *client, const struct i2c_device_id *id)
641 /* Add the backlight device for the DCON */ 650 /* Add the backlight device for the DCON */
642 dcon_bl_props.brightness = dcon->bl_val; 651 dcon_bl_props.brightness = dcon->bl_val;
643 dcon->bl_dev = backlight_device_register("dcon-bl", &dcon_device->dev, 652 dcon->bl_dev = backlight_device_register("dcon-bl", &dcon_device->dev,
644 dcon, &dcon_bl_ops, &dcon_bl_props); 653 dcon, &dcon_bl_ops,
654 &dcon_bl_props);
645 if (IS_ERR(dcon->bl_dev)) { 655 if (IS_ERR(dcon->bl_dev)) {
646 dev_err(&client->dev, "cannot register backlight dev (%ld)\n", 656 dev_err(&client->dev, "cannot register backlight dev (%ld)\n",
647 PTR_ERR(dcon->bl_dev)); 657 PTR_ERR(dcon->bl_dev));
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.h b/drivers/staging/olpc_dcon/olpc_dcon.h
index 8fbde5d3b4a6..fa89bb97c7b0 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.h
+++ b/drivers/staging/olpc_dcon/olpc_dcon.h
@@ -10,18 +10,18 @@
10#define DCON_REG_ID 0 10#define DCON_REG_ID 0
11#define DCON_REG_MODE 1 11#define DCON_REG_MODE 1
12 12
13#define MODE_PASSTHRU (1<<0) 13#define MODE_PASSTHRU BIT(0)
14#define MODE_SLEEP (1<<1) 14#define MODE_SLEEP BIT(1)
15#define MODE_SLEEP_AUTO (1<<2) 15#define MODE_SLEEP_AUTO BIT(2)
16#define MODE_BL_ENABLE (1<<3) 16#define MODE_BL_ENABLE BIT(3)
17#define MODE_BLANK (1<<4) 17#define MODE_BLANK BIT(4)
18#define MODE_CSWIZZLE (1<<5) 18#define MODE_CSWIZZLE BIT(5)
19#define MODE_COL_AA (1<<6) 19#define MODE_COL_AA BIT(6)
20#define MODE_MONO_LUMA (1<<7) 20#define MODE_MONO_LUMA BIT(7)
21#define MODE_SCAN_INT (1<<8) 21#define MODE_SCAN_INT BIT(8)
22#define MODE_CLOCKDIV (1<<9) 22#define MODE_CLOCKDIV BIT(9)
23#define MODE_DEBUG (1<<14) 23#define MODE_DEBUG BIT(14)
24#define MODE_SELFTEST (1<<15) 24#define MODE_SELFTEST BIT(15)
25 25
26#define DCON_REG_HRES 0x2 26#define DCON_REG_HRES 0x2
27#define DCON_REG_HTOTAL 0x3 27#define DCON_REG_HTOTAL 0x3
@@ -36,11 +36,11 @@
36#define DCON_REG_MEM_OPT_B 0x42 36#define DCON_REG_MEM_OPT_B 0x42
37 37
38/* Load Delay Locked Loop (DLL) settings for clock delay */ 38/* Load Delay Locked Loop (DLL) settings for clock delay */
39#define MEM_DLL_CLOCK_DELAY (1<<0) 39#define MEM_DLL_CLOCK_DELAY BIT(0)
40/* Memory controller power down function */ 40/* Memory controller power down function */
41#define MEM_POWER_DOWN (1<<8) 41#define MEM_POWER_DOWN BIT(8)
42/* Memory controller software reset */ 42/* Memory controller software reset */
43#define MEM_SOFT_RESET (1<<0) 43#define MEM_SOFT_RESET BIT(0)
44 44
45/* Status values */ 45/* Status values */
46 46
diff --git a/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c b/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
index 0c5a10c69401..633c58ce24ee 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
@@ -69,7 +69,7 @@ static int dcon_init_xo_1(struct dcon_priv *dcon)
69 gpio_direction_input(OLPC_GPIO_DCON_IRQ); 69 gpio_direction_input(OLPC_GPIO_DCON_IRQ);
70 gpio_direction_input(OLPC_GPIO_DCON_BLANK); 70 gpio_direction_input(OLPC_GPIO_DCON_BLANK);
71 gpio_direction_output(OLPC_GPIO_DCON_LOAD, 71 gpio_direction_output(OLPC_GPIO_DCON_LOAD,
72 dcon->curr_src == DCON_SOURCE_CPU); 72 dcon->curr_src == DCON_SOURCE_CPU);
73 73
74 /* Set up the interrupt mappings */ 74 /* Set up the interrupt mappings */
75 75
diff --git a/drivers/staging/pi433/Documentation/devicetree/pi433-overlay.dts b/drivers/staging/pi433/Documentation/devicetree/pi433-overlay.dts
index 004b5027a934..61fad96818c2 100644
--- a/drivers/staging/pi433/Documentation/devicetree/pi433-overlay.dts
+++ b/drivers/staging/pi433/Documentation/devicetree/pi433-overlay.dts
@@ -3,22 +3,22 @@
3/plugin/; 3/plugin/;
4 4
5/ { 5/ {
6 compatible = "bcm,bcm2835", "bcm,bcm2708", "bcm,bcm2709"; 6 compatible = "bcm,bcm2835", "bcm,bcm2708", "bcm,bcm2709";
7 7
8 fragment@0 { 8 fragment@0 {
9 target = <&spi0>; 9 target = <&spi0>;
10 __overlay__ { 10 __overlay__ {
11 status = "okay"; 11 status = "okay";
12 12
13 spidev@0{ 13 spidev@0{
14 status = "disabled"; 14 status = "disabled";
15 }; 15 };
16 16
17 spidev@1{ 17 spidev@1{
18 status = "disabled"; 18 status = "disabled";
19 }; 19 };
20 }; 20 };
21 }; 21 };
22 22
23 fragment@1 { 23 fragment@1 {
24 target = <&gpio>; 24 target = <&gpio>;
diff --git a/drivers/staging/pi433/Documentation/pi433.txt b/drivers/staging/pi433/Documentation/pi433.txt
index 245fef33d688..7d9dc2244848 100644
--- a/drivers/staging/pi433/Documentation/pi433.txt
+++ b/drivers/staging/pi433/Documentation/pi433.txt
@@ -69,8 +69,8 @@ PI433_IOC_WR_TX_CFG - set the transmission parameters
69PI433_IOC_RD_RX_CFG - get the receiving parameters from the driver 69PI433_IOC_RD_RX_CFG - get the receiving parameters from the driver
70PI433_IOC_WR_RX_CFG - set the receiving parameters 70PI433_IOC_WR_RX_CFG - set the receiving parameters
71 71
72The tx configuration is transfered via struct pi433_tx_cfg, the parameterset for transmission. 72The tx configuration is transferred via struct pi433_tx_cfg, the parameterset for transmission.
73It is devided into two sections: rf parameters and packet format. 73It is divided into two sections: rf parameters and packet format.
74 74
75rf params: 75rf params:
76 frequency 76 frequency
@@ -110,9 +110,9 @@ rf params:
110 ramp12 - amp ramps up in 12us 110 ramp12 - amp ramps up in 12us
111 ramp10 - amp ramps up in 10us 111 ramp10 - amp ramps up in 10us
112 tx_start_condition 112 tx_start_condition
113 fifoLevel - transmission starts, if fifo is filled to 113 fifo_level - transmission starts, if fifo is filled to
114 threshold level 114 threshold level
115 fifoNotEmpty - transmission starts, as soon as there is one 115 fifo_not_empty - transmission starts, as soon as there is one
116 byte in internal fifo 116 byte in internal fifo
117 repetitions 117 repetitions
118 This gives the option, to send a telegram multiple times. Default: 1 118 This gives the option, to send a telegram multiple times. Default: 1
@@ -200,11 +200,11 @@ rf params:
200 sets the gain of the low noise amp 200 sets the gain of the low noise amp
201 automatic - lna gain is determined by an agc 201 automatic - lna gain is determined by an agc
202 max - lna gain is set to maximum 202 max - lna gain is set to maximum
203 maxMinus6 - lna gain is set to 6db below max 203 max_minus_6 - lna gain is set to 6db below max
204 maxMinus12 - lna gain is set to 12db below max 204 max_minus_12 - lna gain is set to 12db below max
205 maxMinus24 - lna gain is set to 24db below max 205 max_minus_24 - lna gain is set to 24db below max
206 maxMinus36 - lna gain is set to 36db below max 206 max_minus_36 - lna gain is set to 36db below max
207 maxMinus48 - lna gain is set to 48db below max 207 max_minus_48 - lna gain is set to 48db below max
208 bw_mantisse 208 bw_mantisse
209 sets the bandwidth of the channel filter - part one: mantisse. 209 sets the bandwidth of the channel filter - part one: mantisse.
210 mantisse16 - mantisse is set to 16 210 mantisse16 - mantisse is set to 16
diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
index 2a205c6173dc..edcd7e798f99 100644
--- a/drivers/staging/pi433/pi433_if.c
+++ b/drivers/staging/pi433/pi433_if.c
@@ -48,14 +48,13 @@
48#include <linux/wait.h> 48#include <linux/wait.h>
49#include <linux/spi/spi.h> 49#include <linux/spi/spi.h>
50#ifdef CONFIG_COMPAT 50#ifdef CONFIG_COMPAT
51#include <asm/compat.h> 51#include <linux/compat.h>
52#endif 52#endif
53 53
54#include "pi433_if.h" 54#include "pi433_if.h"
55#include "rf69.h" 55#include "rf69.h"
56 56
57 57#define N_PI433_MINORS BIT(MINORBITS) /*32*/ /* ... up to 256 */
58#define N_PI433_MINORS (1U << MINORBITS) /*32*/ /* ... up to 256 */
59#define MAX_MSG_SIZE 900 /* min: FIFO_SIZE! */ 58#define MAX_MSG_SIZE 900 /* min: FIFO_SIZE! */
60#define MSG_FIFO_SIZE 65536 /* 65536 = 2^16 */ 59#define MSG_FIFO_SIZE 65536 /* 65536 = 2^16 */
61#define NUM_DIO 2 60#define NUM_DIO 2
@@ -79,7 +78,7 @@ struct pi433_device {
79 struct device *dev; 78 struct device *dev;
80 struct cdev *cdev; 79 struct cdev *cdev;
81 struct spi_device *spi; 80 struct spi_device *spi;
82 unsigned users; 81 unsigned int users;
83 82
84 /* irq related values */ 83 /* irq related values */
85 struct gpio_desc *gpiod[NUM_DIO]; 84 struct gpio_desc *gpiod[NUM_DIO];
@@ -121,32 +120,20 @@ struct pi433_instance {
121 120
122/*-------------------------------------------------------------------------*/ 121/*-------------------------------------------------------------------------*/
123 122
124/* macro for checked access of registers of radio module */
125#define SET_CHECKED(retval) \
126 if (retval < 0) \
127 return retval;
128
129/*-------------------------------------------------------------------------*/
130
131/* GPIO interrupt handlers */ 123/* GPIO interrupt handlers */
132static irqreturn_t DIO0_irq_handler(int irq, void *dev_id) 124static irqreturn_t DIO0_irq_handler(int irq, void *dev_id)
133{ 125{
134 struct pi433_device *device = dev_id; 126 struct pi433_device *device = dev_id;
135 127
136 if (device->irq_state[DIO0] == DIO_PacketSent) 128 if (device->irq_state[DIO0] == DIO_PACKET_SENT) {
137 {
138 device->free_in_fifo = FIFO_SIZE; 129 device->free_in_fifo = FIFO_SIZE;
139 dev_dbg(device->dev, "DIO0 irq: Packet sent\n"); 130 dev_dbg(device->dev, "DIO0 irq: Packet sent\n");
140 wake_up_interruptible(&device->fifo_wait_queue); 131 wake_up_interruptible(&device->fifo_wait_queue);
141 } 132 } else if (device->irq_state[DIO0] == DIO_RSSI_DIO0) {
142 else if (device->irq_state[DIO0] == DIO_Rssi_DIO0)
143 {
144 dev_dbg(device->dev, "DIO0 irq: RSSI level over threshold\n"); 133 dev_dbg(device->dev, "DIO0 irq: RSSI level over threshold\n");
145 wake_up_interruptible(&device->rx_wait_queue); 134 wake_up_interruptible(&device->rx_wait_queue);
146 } 135 } else if (device->irq_state[DIO0] == DIO_PAYLOAD_READY) {
147 else if (device->irq_state[DIO0] == DIO_PayloadReady) 136 dev_dbg(device->dev, "DIO0 irq: Payload ready\n");
148 {
149 dev_dbg(device->dev, "DIO0 irq: PayloadReady\n");
150 device->free_in_fifo = 0; 137 device->free_in_fifo = 0;
151 wake_up_interruptible(&device->fifo_wait_queue); 138 wake_up_interruptible(&device->fifo_wait_queue);
152 } 139 }
@@ -158,14 +145,13 @@ static irqreturn_t DIO1_irq_handler(int irq, void *dev_id)
158{ 145{
159 struct pi433_device *device = dev_id; 146 struct pi433_device *device = dev_id;
160 147
161 if (device->irq_state[DIO1] == DIO_FifoNotEmpty_DIO1) 148 if (device->irq_state[DIO1] == DIO_FIFO_NOT_EMPTY_DIO1) {
162 {
163 device->free_in_fifo = FIFO_SIZE; 149 device->free_in_fifo = FIFO_SIZE;
164 } 150 } else if (device->irq_state[DIO1] == DIO_FIFO_LEVEL) {
165 else if (device->irq_state[DIO1] == DIO_FifoLevel) 151 if (device->rx_active)
166 { 152 device->free_in_fifo = FIFO_THRESHOLD - 1;
167 if (device->rx_active) device->free_in_fifo = FIFO_THRESHOLD - 1; 153 else
168 else device->free_in_fifo = FIFO_SIZE - FIFO_THRESHOLD - 1; 154 device->free_in_fifo = FIFO_SIZE - FIFO_THRESHOLD - 1;
169 } 155 }
170 dev_dbg(device->dev, 156 dev_dbg(device->dev,
171 "DIO1 irq: %d bytes free in fifo\n", device->free_in_fifo); 157 "DIO1 irq: %d bytes free in fifo\n", device->free_in_fifo);
@@ -183,30 +169,56 @@ rf69_set_rx_cfg(struct pi433_device *dev, struct pi433_rx_cfg *rx_cfg)
183 int payload_length; 169 int payload_length;
184 170
185 /* receiver config */ 171 /* receiver config */
186 SET_CHECKED(rf69_set_frequency (dev->spi, rx_cfg->frequency)); 172 ret = rf69_set_frequency(dev->spi, rx_cfg->frequency);
187 SET_CHECKED(rf69_set_bit_rate (dev->spi, rx_cfg->bit_rate)); 173 if (ret < 0)
188 SET_CHECKED(rf69_set_modulation (dev->spi, rx_cfg->modulation)); 174 return ret;
189 SET_CHECKED(rf69_set_antenna_impedance (dev->spi, rx_cfg->antenna_impedance)); 175 ret = rf69_set_bit_rate(dev->spi, rx_cfg->bit_rate);
190 SET_CHECKED(rf69_set_rssi_threshold (dev->spi, rx_cfg->rssi_threshold)); 176 if (ret < 0)
191 SET_CHECKED(rf69_set_ook_threshold_dec (dev->spi, rx_cfg->thresholdDecrement)); 177 return ret;
192 SET_CHECKED(rf69_set_bandwidth (dev->spi, rx_cfg->bw_mantisse, rx_cfg->bw_exponent)); 178 ret = rf69_set_modulation(dev->spi, rx_cfg->modulation);
193 SET_CHECKED(rf69_set_bandwidth_during_afc(dev->spi, rx_cfg->bw_mantisse, rx_cfg->bw_exponent)); 179 if (ret < 0)
194 SET_CHECKED(rf69_set_dagc (dev->spi, rx_cfg->dagc)); 180 return ret;
181 ret = rf69_set_antenna_impedance(dev->spi, rx_cfg->antenna_impedance);
182 if (ret < 0)
183 return ret;
184 ret = rf69_set_rssi_threshold(dev->spi, rx_cfg->rssi_threshold);
185 if (ret < 0)
186 return ret;
187 ret = rf69_set_ook_threshold_dec(dev->spi, rx_cfg->threshold_decrement);
188 if (ret < 0)
189 return ret;
190 ret = rf69_set_bandwidth(dev->spi, rx_cfg->bw_mantisse, rx_cfg->bw_exponent);
191 if (ret < 0)
192 return ret;
193 ret = rf69_set_bandwidth_during_afc(dev->spi, rx_cfg->bw_mantisse, rx_cfg->bw_exponent);
194 if (ret < 0)
195 return ret;
196 ret = rf69_set_dagc(dev->spi, rx_cfg->dagc);
197 if (ret < 0)
198 return ret;
195 199
196 dev->rx_bytes_to_drop = rx_cfg->bytes_to_drop; 200 dev->rx_bytes_to_drop = rx_cfg->bytes_to_drop;
197 201
198 /* packet config */ 202 /* packet config */
199 /* enable */ 203 /* enable */
200 SET_CHECKED(rf69_set_sync_enable(dev->spi, rx_cfg->enable_sync)); 204 if (rx_cfg->enable_sync == OPTION_ON) {
201 if (rx_cfg->enable_sync == optionOn) 205 ret = rf69_enable_sync(dev->spi);
202 { 206 if (ret < 0)
203 SET_CHECKED(rf69_set_fifo_fill_condition(dev->spi, afterSyncInterrupt)); 207 return ret;
204 } 208
205 else 209 ret = rf69_set_fifo_fill_condition(dev->spi, afterSyncInterrupt);
206 { 210 if (ret < 0)
207 SET_CHECKED(rf69_set_fifo_fill_condition(dev->spi, always)); 211 return ret;
212 } else {
213 ret = rf69_disable_sync(dev->spi);
214 if (ret < 0)
215 return ret;
216
217 ret = rf69_set_fifo_fill_condition(dev->spi, always);
218 if (ret < 0)
219 return ret;
208 } 220 }
209 if (rx_cfg->enable_length_byte == optionOn) { 221 if (rx_cfg->enable_length_byte == OPTION_ON) {
210 ret = rf69_set_packet_format(dev->spi, packetLengthVar); 222 ret = rf69_set_packet_format(dev->spi, packetLengthVar);
211 if (ret < 0) 223 if (ret < 0)
212 return ret; 224 return ret;
@@ -215,36 +227,56 @@ rf69_set_rx_cfg(struct pi433_device *dev, struct pi433_rx_cfg *rx_cfg)
215 if (ret < 0) 227 if (ret < 0)
216 return ret; 228 return ret;
217 } 229 }
218 SET_CHECKED(rf69_set_adressFiltering(dev->spi, rx_cfg->enable_address_filtering)); 230 ret = rf69_set_adressFiltering(dev->spi, rx_cfg->enable_address_filtering);
219 SET_CHECKED(rf69_set_crc_enable (dev->spi, rx_cfg->enable_crc)); 231 if (ret < 0)
232 return ret;
220 233
221 /* lengths */ 234 if (rx_cfg->enable_crc == OPTION_ON) {
222 SET_CHECKED(rf69_set_sync_size(dev->spi, rx_cfg->sync_length)); 235 ret = rf69_enable_crc(dev->spi);
223 if (rx_cfg->enable_length_byte == optionOn) 236 if (ret < 0)
224 { 237 return ret;
225 SET_CHECKED(rf69_set_payload_length(dev->spi, 0xff)); 238 } else {
239 ret = rf69_disable_crc(dev->spi);
240 if (ret < 0)
241 return ret;
226 } 242 }
227 else if (rx_cfg->fixed_message_length != 0) 243
228 { 244 /* lengths */
245 ret = rf69_set_sync_size(dev->spi, rx_cfg->sync_length);
246 if (ret < 0)
247 return ret;
248 if (rx_cfg->enable_length_byte == OPTION_ON) {
249 ret = rf69_set_payload_length(dev->spi, 0xff);
250 if (ret < 0)
251 return ret;
252 } else if (rx_cfg->fixed_message_length != 0) {
229 payload_length = rx_cfg->fixed_message_length; 253 payload_length = rx_cfg->fixed_message_length;
230 if (rx_cfg->enable_length_byte == optionOn) payload_length++; 254 if (rx_cfg->enable_length_byte == OPTION_ON)
231 if (rx_cfg->enable_address_filtering != filteringOff) payload_length++; 255 payload_length++;
232 SET_CHECKED(rf69_set_payload_length(dev->spi, payload_length)); 256 if (rx_cfg->enable_address_filtering != filteringOff)
233 } 257 payload_length++;
234 else 258 ret = rf69_set_payload_length(dev->spi, payload_length);
235 { 259 if (ret < 0)
236 SET_CHECKED(rf69_set_payload_length(dev->spi, 0)); 260 return ret;
261 } else {
262 ret = rf69_set_payload_length(dev->spi, 0);
263 if (ret < 0)
264 return ret;
237 } 265 }
238 266
239 /* values */ 267 /* values */
240 if (rx_cfg->enable_sync == optionOn) 268 if (rx_cfg->enable_sync == OPTION_ON) {
241 { 269 ret = rf69_set_sync_values(dev->spi, rx_cfg->sync_pattern);
242 SET_CHECKED(rf69_set_sync_values(dev->spi, rx_cfg->sync_pattern)); 270 if (ret < 0)
271 return ret;
243 } 272 }
244 if (rx_cfg->enable_address_filtering != filteringOff) 273 if (rx_cfg->enable_address_filtering != filteringOff) {
245 { 274 ret = rf69_set_node_address(dev->spi, rx_cfg->node_address);
246 SET_CHECKED(rf69_set_node_address (dev->spi, rx_cfg->node_address)); 275 if (ret < 0)
247 SET_CHECKED(rf69_set_broadcast_address(dev->spi, rx_cfg->broadcast_address)); 276 return ret;
277 ret = rf69_set_broadcast_address(dev->spi, rx_cfg->broadcast_address);
278 if (ret < 0)
279 return ret;
248 } 280 }
249 281
250 return 0; 282 return 0;
@@ -255,25 +287,50 @@ rf69_set_tx_cfg(struct pi433_device *dev, struct pi433_tx_cfg *tx_cfg)
255{ 287{
256 int ret; 288 int ret;
257 289
258 SET_CHECKED(rf69_set_frequency (dev->spi, tx_cfg->frequency)); 290 ret = rf69_set_frequency(dev->spi, tx_cfg->frequency);
259 SET_CHECKED(rf69_set_bit_rate (dev->spi, tx_cfg->bit_rate)); 291 if (ret < 0)
260 SET_CHECKED(rf69_set_modulation (dev->spi, tx_cfg->modulation)); 292 return ret;
261 SET_CHECKED(rf69_set_deviation (dev->spi, tx_cfg->dev_frequency)); 293 ret = rf69_set_bit_rate(dev->spi, tx_cfg->bit_rate);
262 SET_CHECKED(rf69_set_pa_ramp (dev->spi, tx_cfg->pa_ramp)); 294 if (ret < 0)
263 SET_CHECKED(rf69_set_modulation_shaping(dev->spi, tx_cfg->modShaping)); 295 return ret;
264 SET_CHECKED(rf69_set_tx_start_condition(dev->spi, tx_cfg->tx_start_condition)); 296 ret = rf69_set_modulation(dev->spi, tx_cfg->modulation);
297 if (ret < 0)
298 return ret;
299 ret = rf69_set_deviation(dev->spi, tx_cfg->dev_frequency);
300 if (ret < 0)
301 return ret;
302 ret = rf69_set_pa_ramp(dev->spi, tx_cfg->pa_ramp);
303 if (ret < 0)
304 return ret;
305 ret = rf69_set_modulation_shaping(dev->spi, tx_cfg->mod_shaping);
306 if (ret < 0)
307 return ret;
308 ret = rf69_set_tx_start_condition(dev->spi, tx_cfg->tx_start_condition);
309 if (ret < 0)
310 return ret;
265 311
266 /* packet format enable */ 312 /* packet format enable */
267 if (tx_cfg->enable_preamble == optionOn) 313 if (tx_cfg->enable_preamble == OPTION_ON) {
268 { 314 ret = rf69_set_preamble_length(dev->spi, tx_cfg->preamble_length);
269 SET_CHECKED(rf69_set_preamble_length(dev->spi, tx_cfg->preamble_length)); 315 if (ret < 0)
316 return ret;
317 } else {
318 ret = rf69_set_preamble_length(dev->spi, 0);
319 if (ret < 0)
320 return ret;
270 } 321 }
271 else 322
272 { 323 if (tx_cfg->enable_sync == OPTION_ON) {
273 SET_CHECKED(rf69_set_preamble_length(dev->spi, 0)); 324 ret = rf69_enable_sync(dev->spi);
325 if (ret < 0)
326 return ret;
327 } else {
328 ret = rf69_disable_sync(dev->spi);
329 if (ret < 0)
330 return ret;
274 } 331 }
275 SET_CHECKED(rf69_set_sync_enable (dev->spi, tx_cfg->enable_sync)); 332
276 if (tx_cfg->enable_length_byte == optionOn) { 333 if (tx_cfg->enable_length_byte == OPTION_ON) {
277 ret = rf69_set_packet_format(dev->spi, packetLengthVar); 334 ret = rf69_set_packet_format(dev->spi, packetLengthVar);
278 if (ret < 0) 335 if (ret < 0)
279 return ret; 336 return ret;
@@ -282,12 +339,25 @@ rf69_set_tx_cfg(struct pi433_device *dev, struct pi433_tx_cfg *tx_cfg)
282 if (ret < 0) 339 if (ret < 0)
283 return ret; 340 return ret;
284 } 341 }
285 SET_CHECKED(rf69_set_crc_enable (dev->spi, tx_cfg->enable_crc)); 342
343 if (tx_cfg->enable_crc == OPTION_ON) {
344 ret = rf69_enable_crc(dev->spi);
345 if (ret < 0)
346 return ret;
347 } else {
348 ret = rf69_disable_crc(dev->spi);
349 if (ret < 0)
350 return ret;
351 }
286 352
287 /* configure sync, if enabled */ 353 /* configure sync, if enabled */
288 if (tx_cfg->enable_sync == optionOn) { 354 if (tx_cfg->enable_sync == OPTION_ON) {
289 SET_CHECKED(rf69_set_sync_size(dev->spi, tx_cfg->sync_length)); 355 ret = rf69_set_sync_size(dev->spi, tx_cfg->sync_length);
290 SET_CHECKED(rf69_set_sync_values(dev->spi, tx_cfg->sync_pattern)); 356 if (ret < 0)
357 return ret;
358 ret = rf69_set_sync_values(dev->spi, tx_cfg->sync_pattern);
359 if (ret < 0)
360 return ret;
291 } 361 }
292 362
293 return 0; 363 return 0;
@@ -306,43 +376,51 @@ pi433_start_rx(struct pi433_device *dev)
306 376
307 /* setup for receiving */ 377 /* setup for receiving */
308 retval = rf69_set_rx_cfg(dev, &dev->rx_cfg); 378 retval = rf69_set_rx_cfg(dev, &dev->rx_cfg);
309 if (retval) return retval; 379 if (retval)
380 return retval;
310 381
311 /* setup rssi irq */ 382 /* setup rssi irq */
312 SET_CHECKED(rf69_set_dio_mapping(dev->spi, DIO0, DIO_Rssi_DIO0)); 383 retval = rf69_set_dio_mapping(dev->spi, DIO0, DIO_RSSI_DIO0);
313 dev->irq_state[DIO0] = DIO_Rssi_DIO0; 384 if (retval < 0)
385 return retval;
386 dev->irq_state[DIO0] = DIO_RSSI_DIO0;
314 irq_set_irq_type(dev->irq_num[DIO0], IRQ_TYPE_EDGE_RISING); 387 irq_set_irq_type(dev->irq_num[DIO0], IRQ_TYPE_EDGE_RISING);
315 388
316 /* setup fifo level interrupt */ 389 /* setup fifo level interrupt */
317 SET_CHECKED(rf69_set_fifo_threshold(dev->spi, FIFO_SIZE - FIFO_THRESHOLD)); 390 retval = rf69_set_fifo_threshold(dev->spi, FIFO_SIZE - FIFO_THRESHOLD);
318 SET_CHECKED(rf69_set_dio_mapping(dev->spi, DIO1, DIO_FifoLevel)); 391 if (retval < 0)
319 dev->irq_state[DIO1] = DIO_FifoLevel; 392 return retval;
393 retval = rf69_set_dio_mapping(dev->spi, DIO1, DIO_FIFO_LEVEL);
394 if (retval < 0)
395 return retval;
396 dev->irq_state[DIO1] = DIO_FIFO_LEVEL;
320 irq_set_irq_type(dev->irq_num[DIO1], IRQ_TYPE_EDGE_RISING); 397 irq_set_irq_type(dev->irq_num[DIO1], IRQ_TYPE_EDGE_RISING);
321 398
322 /* set module to receiving mode */ 399 /* set module to receiving mode */
323 SET_CHECKED(rf69_set_mode(dev->spi, receive)); 400 retval = rf69_set_mode(dev->spi, receive);
401 if (retval < 0)
402 return retval;
324 403
325 return 0; 404 return 0;
326} 405}
327 406
328
329/*-------------------------------------------------------------------------*/ 407/*-------------------------------------------------------------------------*/
330 408
331static int 409static int
332pi433_receive(void *data) 410pi433_receive(void *data)
333{ 411{
334 struct pi433_device *dev = data; 412 struct pi433_device *dev = data;
335 struct spi_device *spi = dev->spi; /* needed for SET_CHECKED */ 413 struct spi_device *spi = dev->spi;
336 int bytes_to_read, bytes_total; 414 int bytes_to_read, bytes_total;
337 int retval; 415 int retval;
338 416
339 dev->interrupt_rx_allowed = false; 417 dev->interrupt_rx_allowed = false;
340 418
341 /* wait for any tx to finish */ 419 /* wait for any tx to finish */
342 dev_dbg(dev->dev,"rx: going to wait for any tx to finish"); 420 dev_dbg(dev->dev, "rx: going to wait for any tx to finish");
343 retval = wait_event_interruptible(dev->rx_wait_queue, !dev->tx_active); 421 retval = wait_event_interruptible(dev->rx_wait_queue, !dev->tx_active);
344 if(retval) /* wait was interrupted */ 422 if (retval) {
345 { 423 /* wait was interrupted */
346 dev->interrupt_rx_allowed = true; 424 dev->interrupt_rx_allowed = true;
347 wake_up_interruptible(&dev->tx_wait_queue); 425 wake_up_interruptible(&dev->tx_wait_queue);
348 return retval; 426 return retval;
@@ -359,8 +437,7 @@ pi433_receive(void *data)
359 return retval; 437 return retval;
360 438
361 /* now check RSSI, if low wait for getting high (RSSI interrupt) */ 439 /* now check RSSI, if low wait for getting high (RSSI interrupt) */
362 while ( !rf69_get_flag(dev->spi, rssiExceededThreshold) ) 440 while (!rf69_get_flag(dev->spi, rssiExceededThreshold)) {
363 {
364 /* allow tx to interrupt us while waiting for high RSSI */ 441 /* allow tx to interrupt us while waiting for high RSSI */
365 dev->interrupt_rx_allowed = true; 442 dev->interrupt_rx_allowed = true;
366 wake_up_interruptible(&dev->tx_wait_queue); 443 wake_up_interruptible(&dev->tx_wait_queue);
@@ -368,43 +445,43 @@ pi433_receive(void *data)
368 /* wait for RSSI level to become high */ 445 /* wait for RSSI level to become high */
369 dev_dbg(dev->dev, "rx: going to wait for high RSSI level"); 446 dev_dbg(dev->dev, "rx: going to wait for high RSSI level");
370 retval = wait_event_interruptible(dev->rx_wait_queue, 447 retval = wait_event_interruptible(dev->rx_wait_queue,
371 rf69_get_flag(dev->spi, 448 rf69_get_flag(dev->spi,
372 rssiExceededThreshold)); 449 rssiExceededThreshold));
373 if (retval) goto abort; /* wait was interrupted */ 450 if (retval) /* wait was interrupted */
451 goto abort;
374 dev->interrupt_rx_allowed = false; 452 dev->interrupt_rx_allowed = false;
375 453
376 /* cross check for ongoing tx */ 454 /* cross check for ongoing tx */
377 if (!dev->tx_active) break; 455 if (!dev->tx_active)
456 break;
378 } 457 }
379 458
380 /* configure payload ready irq */ 459 /* configure payload ready irq */
381 SET_CHECKED(rf69_set_dio_mapping(spi, DIO0, DIO_PayloadReady)); 460 retval = rf69_set_dio_mapping(spi, DIO0, DIO_PAYLOAD_READY);
382 dev->irq_state[DIO0] = DIO_PayloadReady; 461 if (retval < 0)
462 goto abort;
463 dev->irq_state[DIO0] = DIO_PAYLOAD_READY;
383 irq_set_irq_type(dev->irq_num[DIO0], IRQ_TYPE_EDGE_RISING); 464 irq_set_irq_type(dev->irq_num[DIO0], IRQ_TYPE_EDGE_RISING);
384 465
385 /* fixed or unlimited length? */ 466 /* fixed or unlimited length? */
386 if (dev->rx_cfg.fixed_message_length != 0) 467 if (dev->rx_cfg.fixed_message_length != 0) {
387 { 468 if (dev->rx_cfg.fixed_message_length > dev->rx_buffer_size) {
388 if (dev->rx_cfg.fixed_message_length > dev->rx_buffer_size)
389 {
390 retval = -1; 469 retval = -1;
391 goto abort; 470 goto abort;
392 } 471 }
393 bytes_total = dev->rx_cfg.fixed_message_length; 472 bytes_total = dev->rx_cfg.fixed_message_length;
394 dev_dbg(dev->dev,"rx: msg len set to %d by fixed length", bytes_total); 473 dev_dbg(dev->dev, "rx: msg len set to %d by fixed length", bytes_total);
395 } 474 } else {
396 else
397 {
398 bytes_total = dev->rx_buffer_size; 475 bytes_total = dev->rx_buffer_size;
399 dev_dbg(dev->dev, "rx: msg len set to %d as requested by read", bytes_total); 476 dev_dbg(dev->dev, "rx: msg len set to %d as requested by read", bytes_total);
400 } 477 }
401 478
402 /* length byte enabled? */ 479 /* length byte enabled? */
403 if (dev->rx_cfg.enable_length_byte == optionOn) 480 if (dev->rx_cfg.enable_length_byte == OPTION_ON) {
404 {
405 retval = wait_event_interruptible(dev->fifo_wait_queue, 481 retval = wait_event_interruptible(dev->fifo_wait_queue,
406 dev->free_in_fifo < FIFO_SIZE); 482 dev->free_in_fifo < FIFO_SIZE);
407 if (retval) goto abort; /* wait was interrupted */ 483 if (retval) /* wait was interrupted */
484 goto abort;
408 485
409 rf69_read_fifo(spi, (u8 *)&bytes_total, 1); 486 rf69_read_fifo(spi, (u8 *)&bytes_total, 1);
410 if (bytes_total > dev->rx_buffer_size) { 487 if (bytes_total > dev->rx_buffer_size) {
@@ -416,15 +493,15 @@ pi433_receive(void *data)
416 } 493 }
417 494
418 /* address byte enabled? */ 495 /* address byte enabled? */
419 if (dev->rx_cfg.enable_address_filtering != filteringOff) 496 if (dev->rx_cfg.enable_address_filtering != filteringOff) {
420 {
421 u8 dummy; 497 u8 dummy;
422 498
423 bytes_total--; 499 bytes_total--;
424 500
425 retval = wait_event_interruptible(dev->fifo_wait_queue, 501 retval = wait_event_interruptible(dev->fifo_wait_queue,
426 dev->free_in_fifo < FIFO_SIZE); 502 dev->free_in_fifo < FIFO_SIZE);
427 if (retval) goto abort; /* wait was interrupted */ 503 if (retval) /* wait was interrupted */
504 goto abort;
428 505
429 rf69_read_fifo(spi, &dummy, 1); 506 rf69_read_fifo(spi, &dummy, 1);
430 dev->free_in_fifo++; 507 dev->free_in_fifo++;
@@ -432,13 +509,12 @@ pi433_receive(void *data)
432 } 509 }
433 510
434 /* get payload */ 511 /* get payload */
435 while (dev->rx_position < bytes_total) 512 while (dev->rx_position < bytes_total) {
436 { 513 if (!rf69_get_flag(dev->spi, payload_ready)) {
437 if ( !rf69_get_flag(dev->spi, payloadReady) )
438 {
439 retval = wait_event_interruptible(dev->fifo_wait_queue, 514 retval = wait_event_interruptible(dev->fifo_wait_queue,
440 dev->free_in_fifo < FIFO_SIZE); 515 dev->free_in_fifo < FIFO_SIZE);
441 if (retval) goto abort; /* wait was interrupted */ 516 if (retval) /* wait was interrupted */
517 goto abort;
442 } 518 }
443 519
444 /* need to drop bytes or acquire? */ 520 /* need to drop bytes or acquire? */
@@ -447,14 +523,15 @@ pi433_receive(void *data)
447 else 523 else
448 bytes_to_read = bytes_total - dev->rx_position; 524 bytes_to_read = bytes_total - dev->rx_position;
449 525
450
451 /* access the fifo */ 526 /* access the fifo */
452 if (bytes_to_read > FIFO_SIZE - dev->free_in_fifo) 527 if (bytes_to_read > FIFO_SIZE - dev->free_in_fifo)
453 bytes_to_read = FIFO_SIZE - dev->free_in_fifo; 528 bytes_to_read = FIFO_SIZE - dev->free_in_fifo;
454 retval = rf69_read_fifo(spi, 529 retval = rf69_read_fifo(spi,
455 &dev->rx_buffer[dev->rx_position], 530 &dev->rx_buffer[dev->rx_position],
456 bytes_to_read); 531 bytes_to_read);
457 if (retval) goto abort; /* read failed */ 532 if (retval) /* read failed */
533 goto abort;
534
458 dev->free_in_fifo += bytes_to_read; 535 dev->free_in_fifo += bytes_to_read;
459 536
460 /* adjust status vars */ 537 /* adjust status vars */
@@ -464,11 +541,11 @@ pi433_receive(void *data)
464 dev->rx_position += bytes_to_read; 541 dev->rx_position += bytes_to_read;
465 } 542 }
466 543
467
468 /* rx done, wait was interrupted or error occurred */ 544 /* rx done, wait was interrupted or error occurred */
469abort: 545abort:
470 dev->interrupt_rx_allowed = true; 546 dev->interrupt_rx_allowed = true;
471 SET_CHECKED(rf69_set_mode(dev->spi, standby)); 547 if (rf69_set_mode(dev->spi, standby))
548 pr_err("rf69_set_mode(): radio module failed to go standby\n");
472 wake_up_interruptible(&dev->tx_wait_queue); 549 wake_up_interruptible(&dev->tx_wait_queue);
473 550
474 if (retval) 551 if (retval)
@@ -481,22 +558,20 @@ static int
481pi433_tx_thread(void *data) 558pi433_tx_thread(void *data)
482{ 559{
483 struct pi433_device *device = data; 560 struct pi433_device *device = data;
484 struct spi_device *spi = device->spi; /* needed for SET_CHECKED */ 561 struct spi_device *spi = device->spi;
485 struct pi433_tx_cfg tx_cfg; 562 struct pi433_tx_cfg tx_cfg;
486 u8 *buffer = device->buffer;
487 size_t size; 563 size_t size;
488 bool rx_interrupted = false; 564 bool rx_interrupted = false;
489 int position, repetitions; 565 int position, repetitions;
490 int retval; 566 int retval;
491 567
492 while (1) 568 while (1) {
493 {
494 /* wait for fifo to be populated or for request to terminate*/ 569 /* wait for fifo to be populated or for request to terminate*/
495 dev_dbg(device->dev, "thread: going to wait for new messages"); 570 dev_dbg(device->dev, "thread: going to wait for new messages");
496 wait_event_interruptible(device->tx_wait_queue, 571 wait_event_interruptible(device->tx_wait_queue,
497 ( !kfifo_is_empty(&device->tx_fifo) || 572 (!kfifo_is_empty(&device->tx_fifo) ||
498 kthread_should_stop() )); 573 kthread_should_stop()));
499 if ( kthread_should_stop() ) 574 if (kthread_should_stop())
500 return 0; 575 return 0;
501 576
502 /* get data from fifo in the following order: 577 /* get data from fifo in the following order:
@@ -508,14 +583,14 @@ pi433_tx_thread(void *data)
508 583
509 retval = kfifo_out(&device->tx_fifo, &tx_cfg, sizeof(tx_cfg)); 584 retval = kfifo_out(&device->tx_fifo, &tx_cfg, sizeof(tx_cfg));
510 if (retval != sizeof(tx_cfg)) { 585 if (retval != sizeof(tx_cfg)) {
511 dev_dbg(device->dev, "reading tx_cfg from fifo failed: got %d byte(s), expected %d", retval, (unsigned int)sizeof(tx_cfg) ); 586 dev_dbg(device->dev, "reading tx_cfg from fifo failed: got %d byte(s), expected %d", retval, (unsigned int)sizeof(tx_cfg));
512 mutex_unlock(&device->tx_fifo_lock); 587 mutex_unlock(&device->tx_fifo_lock);
513 continue; 588 continue;
514 } 589 }
515 590
516 retval = kfifo_out(&device->tx_fifo, &size, sizeof(size_t)); 591 retval = kfifo_out(&device->tx_fifo, &size, sizeof(size_t));
517 if (retval != sizeof(size_t)) { 592 if (retval != sizeof(size_t)) {
518 dev_dbg(device->dev, "reading msg size from fifo failed: got %d, expected %d", retval, (unsigned int)sizeof(size_t) ); 593 dev_dbg(device->dev, "reading msg size from fifo failed: got %d, expected %d", retval, (unsigned int)sizeof(size_t));
519 mutex_unlock(&device->tx_fifo_lock); 594 mutex_unlock(&device->tx_fifo_lock);
520 continue; 595 continue;
521 } 596 }
@@ -525,27 +600,27 @@ pi433_tx_thread(void *data)
525 size = tx_cfg.fixed_message_length; 600 size = tx_cfg.fixed_message_length;
526 601
527 /* increase size, if len byte is requested */ 602 /* increase size, if len byte is requested */
528 if (tx_cfg.enable_length_byte == optionOn) 603 if (tx_cfg.enable_length_byte == OPTION_ON)
529 size++; 604 size++;
530 605
531 /* increase size, if adr byte is requested */ 606 /* increase size, if adr byte is requested */
532 if (tx_cfg.enable_address_byte == optionOn) 607 if (tx_cfg.enable_address_byte == OPTION_ON)
533 size++; 608 size++;
534 609
535 /* prime buffer */ 610 /* prime buffer */
536 memset(buffer, 0, size); 611 memset(device->buffer, 0, size);
537 position = 0; 612 position = 0;
538 613
539 /* add length byte, if requested */ 614 /* add length byte, if requested */
540 if (tx_cfg.enable_length_byte == optionOn) 615 if (tx_cfg.enable_length_byte == OPTION_ON)
541 buffer[position++] = size-1; /* according to spec length byte itself must be excluded from the length calculation */ 616 device->buffer[position++] = size - 1; /* according to spec length byte itself must be excluded from the length calculation */
542 617
543 /* add adr byte, if requested */ 618 /* add adr byte, if requested */
544 if (tx_cfg.enable_address_byte == optionOn) 619 if (tx_cfg.enable_address_byte == OPTION_ON)
545 buffer[position++] = tx_cfg.address_byte; 620 device->buffer[position++] = tx_cfg.address_byte;
546 621
547 /* finally get message data from fifo */ 622 /* finally get message data from fifo */
548 retval = kfifo_out(&device->tx_fifo, &buffer[position], sizeof(buffer)-position ); 623 retval = kfifo_out(&device->tx_fifo, &device->buffer[position], sizeof(device->buffer) - position);
549 dev_dbg(device->dev, "read %d message byte(s) from fifo queue.", retval); 624 dev_dbg(device->dev, "read %d message byte(s) from fifo queue.", retval);
550 mutex_unlock(&device->tx_fifo_lock); 625 mutex_unlock(&device->tx_fifo_lock);
551 626
@@ -557,7 +632,7 @@ pi433_tx_thread(void *data)
557 */ 632 */
558 wait_event_interruptible(device->tx_wait_queue, 633 wait_event_interruptible(device->tx_wait_queue,
559 !device->rx_active || 634 !device->rx_active ||
560 device->interrupt_rx_allowed == true); 635 device->interrupt_rx_allowed);
561 636
562 /* prevent race conditions 637 /* prevent race conditions
563 * irq will be reenabled after tx config is set 638 * irq will be reenabled after tx config is set
@@ -565,91 +640,107 @@ pi433_tx_thread(void *data)
565 disable_irq(device->irq_num[DIO0]); 640 disable_irq(device->irq_num[DIO0]);
566 device->tx_active = true; 641 device->tx_active = true;
567 642
568 if (device->rx_active && rx_interrupted == false) 643 if (device->rx_active && !rx_interrupted) {
569 {
570 /* rx is currently waiting for a telegram; 644 /* rx is currently waiting for a telegram;
571 * we need to set the radio module to standby 645 * we need to set the radio module to standby
572 */ 646 */
573 SET_CHECKED(rf69_set_mode(device->spi, standby)); 647 retval = rf69_set_mode(device->spi, standby);
648 if (retval < 0)
649 return retval;
574 rx_interrupted = true; 650 rx_interrupted = true;
575 } 651 }
576 652
577 /* clear fifo, set fifo threshold, set payload length */ 653 /* clear fifo, set fifo threshold, set payload length */
578 SET_CHECKED(rf69_set_mode(spi, standby)); /* this clears the fifo */ 654 retval = rf69_set_mode(spi, standby); /* this clears the fifo */
579 SET_CHECKED(rf69_set_fifo_threshold(spi, FIFO_THRESHOLD)); 655 if (retval < 0)
580 if (tx_cfg.enable_length_byte == optionOn) 656 return retval;
581 { 657 retval = rf69_set_fifo_threshold(spi, FIFO_THRESHOLD);
582 SET_CHECKED(rf69_set_payload_length(spi, size * tx_cfg.repetitions)); 658 if (retval < 0)
583 } 659 return retval;
584 else 660 if (tx_cfg.enable_length_byte == OPTION_ON) {
585 { 661 retval = rf69_set_payload_length(spi, size * tx_cfg.repetitions);
586 SET_CHECKED(rf69_set_payload_length(spi, 0)); 662 if (retval < 0)
663 return retval;
664 } else {
665 retval = rf69_set_payload_length(spi, 0);
666 if (retval < 0)
667 return retval;
587 } 668 }
588 669
589 /* configure the rf chip */ 670 /* configure the rf chip */
590 rf69_set_tx_cfg(device, &tx_cfg); 671 retval = rf69_set_tx_cfg(device, &tx_cfg);
672 if (retval < 0)
673 return retval;
591 674
592 /* enable fifo level interrupt */ 675 /* enable fifo level interrupt */
593 SET_CHECKED(rf69_set_dio_mapping(spi, DIO1, DIO_FifoLevel)); 676 retval = rf69_set_dio_mapping(spi, DIO1, DIO_FIFO_LEVEL);
594 device->irq_state[DIO1] = DIO_FifoLevel; 677 if (retval < 0)
678 return retval;
679 device->irq_state[DIO1] = DIO_FIFO_LEVEL;
595 irq_set_irq_type(device->irq_num[DIO1], IRQ_TYPE_EDGE_FALLING); 680 irq_set_irq_type(device->irq_num[DIO1], IRQ_TYPE_EDGE_FALLING);
596 681
597 /* enable packet sent interrupt */ 682 /* enable packet sent interrupt */
598 SET_CHECKED(rf69_set_dio_mapping(spi, DIO0, DIO_PacketSent)); 683 retval = rf69_set_dio_mapping(spi, DIO0, DIO_PACKET_SENT);
599 device->irq_state[DIO0] = DIO_PacketSent; 684 if (retval < 0)
685 return retval;
686 device->irq_state[DIO0] = DIO_PACKET_SENT;
600 irq_set_irq_type(device->irq_num[DIO0], IRQ_TYPE_EDGE_RISING); 687 irq_set_irq_type(device->irq_num[DIO0], IRQ_TYPE_EDGE_RISING);
601 enable_irq(device->irq_num[DIO0]); /* was disabled by rx active check */ 688 enable_irq(device->irq_num[DIO0]); /* was disabled by rx active check */
602 689
603 /* enable transmission */ 690 /* enable transmission */
604 SET_CHECKED(rf69_set_mode(spi, transmit)); 691 retval = rf69_set_mode(spi, transmit);
692 if (retval < 0)
693 return retval;
605 694
606 /* transfer this msg (and repetitions) to chip fifo */ 695 /* transfer this msg (and repetitions) to chip fifo */
607 device->free_in_fifo = FIFO_SIZE; 696 device->free_in_fifo = FIFO_SIZE;
608 position = 0; 697 position = 0;
609 repetitions = tx_cfg.repetitions; 698 repetitions = tx_cfg.repetitions;
610 while( (repetitions > 0) && (size > position) ) 699 while ((repetitions > 0) && (size > position)) {
611 { 700 if ((size - position) > device->free_in_fifo) {
612 if ( (size - position) > device->free_in_fifo) 701 /* msg to big for fifo - take a part */
613 { /* msg to big for fifo - take a part */
614 int temp = device->free_in_fifo; 702 int temp = device->free_in_fifo;
615 device->free_in_fifo = 0; 703 device->free_in_fifo = 0;
616 rf69_write_fifo(spi, 704 rf69_write_fifo(spi,
617 &buffer[position], 705 &device->buffer[position],
618 temp); 706 temp);
619 position +=temp; 707 position += temp;
620 } 708 } else {
621 else 709 /* msg fits into fifo - take all */
622 { /* msg fits into fifo - take all */
623 device->free_in_fifo -= size; 710 device->free_in_fifo -= size;
624 repetitions--; 711 repetitions--;
625 rf69_write_fifo(spi, 712 rf69_write_fifo(spi,
626 &buffer[position], 713 &device->buffer[position],
627 (size - position) ); 714 (size - position));
628 position = 0; /* reset for next repetition */ 715 position = 0; /* reset for next repetition */
629 } 716 }
630 717
631 retval = wait_event_interruptible(device->fifo_wait_queue, 718 retval = wait_event_interruptible(device->fifo_wait_queue,
632 device->free_in_fifo > 0); 719 device->free_in_fifo > 0);
633 if (retval) { printk("ABORT\n"); goto abort; } 720 if (retval) {
721 dev_dbg(device->dev, "ABORT\n");
722 goto abort;
723 }
634 } 724 }
635 725
636 /* we are done. Wait for packet to get sent */ 726 /* we are done. Wait for packet to get sent */
637 dev_dbg(device->dev, "thread: wait for packet to get sent/fifo to be empty"); 727 dev_dbg(device->dev, "thread: wait for packet to get sent/fifo to be empty");
638 wait_event_interruptible(device->fifo_wait_queue, 728 wait_event_interruptible(device->fifo_wait_queue,
639 device->free_in_fifo == FIFO_SIZE || 729 device->free_in_fifo == FIFO_SIZE ||
640 kthread_should_stop() ); 730 kthread_should_stop());
641 if ( kthread_should_stop() ) printk("ABORT\n"); 731 if (kthread_should_stop())
642 732 dev_dbg(device->dev, "ABORT\n");
643 733
644 /* STOP_TRANSMISSION */ 734 /* STOP_TRANSMISSION */
645 dev_dbg(device->dev, "thread: Packet sent. Set mode to stby."); 735 dev_dbg(device->dev, "thread: Packet sent. Set mode to stby.");
646 SET_CHECKED(rf69_set_mode(spi, standby)); 736 retval = rf69_set_mode(spi, standby);
737 if (retval < 0)
738 return retval;
647 739
648 /* everything sent? */ 740 /* everything sent? */
649 if (kfifo_is_empty(&device->tx_fifo)) { 741 if (kfifo_is_empty(&device->tx_fifo)) {
650abort: 742abort:
651 if (rx_interrupted) 743 if (rx_interrupted) {
652 {
653 rx_interrupted = false; 744 rx_interrupted = false;
654 pi433_start_rx(device); 745 pi433_start_rx(device);
655 } 746 }
@@ -678,16 +769,13 @@ pi433_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
678 769
679 /* just one read request at a time */ 770 /* just one read request at a time */
680 mutex_lock(&device->rx_lock); 771 mutex_lock(&device->rx_lock);
681 if (device->rx_active) 772 if (device->rx_active) {
682 {
683 mutex_unlock(&device->rx_lock); 773 mutex_unlock(&device->rx_lock);
684 return -EAGAIN; 774 return -EAGAIN;
685 } 775 }
686 else 776
687 { 777 device->rx_active = true;
688 device->rx_active = true; 778 mutex_unlock(&device->rx_lock);
689 mutex_unlock(&device->rx_lock);
690 }
691 779
692 /* start receiving */ 780 /* start receiving */
693 /* will block until something was received*/ 781 /* will block until something was received*/
@@ -709,14 +797,14 @@ pi433_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
709 return bytes_received; 797 return bytes_received;
710} 798}
711 799
712
713static ssize_t 800static ssize_t
714pi433_write(struct file *filp, const char __user *buf, 801pi433_write(struct file *filp, const char __user *buf,
715 size_t count, loff_t *f_pos) 802 size_t count, loff_t *f_pos)
716{ 803{
717 struct pi433_instance *instance; 804 struct pi433_instance *instance;
718 struct pi433_device *device; 805 struct pi433_device *device;
719 int copied, retval; 806 int retval;
807 unsigned int copied;
720 808
721 instance = filp->private_data; 809 instance = filp->private_data;
722 device = instance->device; 810 device = instance->device;
@@ -732,11 +820,11 @@ pi433_write(struct file *filp, const char __user *buf,
732 */ 820 */
733 mutex_lock(&device->tx_fifo_lock); 821 mutex_lock(&device->tx_fifo_lock);
734 retval = kfifo_in(&device->tx_fifo, &instance->tx_cfg, sizeof(instance->tx_cfg)); 822 retval = kfifo_in(&device->tx_fifo, &instance->tx_cfg, sizeof(instance->tx_cfg));
735 if ( retval != sizeof(instance->tx_cfg) ) 823 if (retval != sizeof(instance->tx_cfg))
736 goto abort; 824 goto abort;
737 825
738 retval = kfifo_in (&device->tx_fifo, &count, sizeof(size_t)); 826 retval = kfifo_in(&device->tx_fifo, &count, sizeof(size_t));
739 if ( retval != sizeof(size_t) ) 827 if (retval != sizeof(size_t))
740 goto abort; 828 goto abort;
741 829
742 retval = kfifo_from_user(&device->tx_fifo, buf, count, &copied); 830 retval = kfifo_from_user(&device->tx_fifo, buf, count, &copied);
@@ -749,7 +837,7 @@ pi433_write(struct file *filp, const char __user *buf,
749 wake_up_interruptible(&device->tx_wait_queue); 837 wake_up_interruptible(&device->tx_wait_queue);
750 dev_dbg(device->dev, "write: generated new msg with %d bytes.", copied); 838 dev_dbg(device->dev, "write: generated new msg with %d bytes.", copied);
751 839
752 return 0; 840 return copied;
753 841
754abort: 842abort:
755 dev_dbg(device->dev, "write to fifo failed: 0x%x", retval); 843 dev_dbg(device->dev, "write to fifo failed: 0x%x", retval);
@@ -758,7 +846,6 @@ abort:
758 return -EAGAIN; 846 return -EAGAIN;
759} 847}
760 848
761
762static long 849static long
763pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 850pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
764{ 851{
@@ -777,23 +864,23 @@ pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
777 instance = filp->private_data; 864 instance = filp->private_data;
778 device = instance->device; 865 device = instance->device;
779 866
780 if (device == NULL) 867 if (!device)
781 return -ESHUTDOWN; 868 return -ESHUTDOWN;
782 869
783 switch (cmd) { 870 switch (cmd) {
784 case PI433_IOC_RD_TX_CFG: 871 case PI433_IOC_RD_TX_CFG:
785 if (copy_to_user(argp, &instance->tx_cfg, 872 if (copy_to_user(argp, &instance->tx_cfg,
786 sizeof(struct pi433_tx_cfg))) 873 sizeof(struct pi433_tx_cfg)))
787 return -EFAULT; 874 return -EFAULT;
788 break; 875 break;
789 case PI433_IOC_WR_TX_CFG: 876 case PI433_IOC_WR_TX_CFG:
790 if (copy_from_user(&instance->tx_cfg, argp, 877 if (copy_from_user(&instance->tx_cfg, argp,
791 sizeof(struct pi433_tx_cfg))) 878 sizeof(struct pi433_tx_cfg)))
792 return -EFAULT; 879 return -EFAULT;
793 break; 880 break;
794 case PI433_IOC_RD_RX_CFG: 881 case PI433_IOC_RD_RX_CFG:
795 if (copy_to_user(argp, &device->rx_cfg, 882 if (copy_to_user(argp, &device->rx_cfg,
796 sizeof(struct pi433_rx_cfg))) 883 sizeof(struct pi433_rx_cfg)))
797 return -EFAULT; 884 return -EFAULT;
798 break; 885 break;
799 case PI433_IOC_WR_RX_CFG: 886 case PI433_IOC_WR_RX_CFG:
@@ -806,7 +893,7 @@ pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
806 } 893 }
807 894
808 if (copy_from_user(&device->rx_cfg, argp, 895 if (copy_from_user(&device->rx_cfg, argp,
809 sizeof(struct pi433_rx_cfg))) { 896 sizeof(struct pi433_rx_cfg))) {
810 mutex_unlock(&device->rx_lock); 897 mutex_unlock(&device->rx_lock);
811 return -EFAULT; 898 return -EFAULT;
812 } 899 }
@@ -847,10 +934,8 @@ static int pi433_open(struct inode *inode, struct file *filp)
847 934
848 if (!device->rx_buffer) { 935 if (!device->rx_buffer) {
849 device->rx_buffer = kmalloc(MAX_MSG_SIZE, GFP_KERNEL); 936 device->rx_buffer = kmalloc(MAX_MSG_SIZE, GFP_KERNEL);
850 if (!device->rx_buffer) { 937 if (!device->rx_buffer)
851 dev_dbg(device->dev, "open/ENOMEM\n");
852 return -ENOMEM; 938 return -ENOMEM;
853 }
854 } 939 }
855 940
856 device->users++; 941 device->users++;
@@ -889,19 +974,18 @@ static int pi433_release(struct inode *inode, struct file *filp)
889 if (!device->users) { 974 if (!device->users) {
890 kfree(device->rx_buffer); 975 kfree(device->rx_buffer);
891 device->rx_buffer = NULL; 976 device->rx_buffer = NULL;
892 if (device->spi == NULL) 977 if (!device->spi)
893 kfree(device); 978 kfree(device);
894 } 979 }
895 980
896 return 0; 981 return 0;
897} 982}
898 983
899
900/*-------------------------------------------------------------------------*/ 984/*-------------------------------------------------------------------------*/
901 985
902static int setup_GPIOs(struct pi433_device *device) 986static int setup_GPIOs(struct pi433_device *device)
903{ 987{
904 char name[5]; 988 char name[5];
905 int retval; 989 int retval;
906 int i; 990 int i;
907 const irq_handler_t DIO_irq_handler[NUM_DIO] = { 991 const irq_handler_t DIO_irq_handler[NUM_DIO] = {
@@ -909,8 +993,7 @@ static int setup_GPIOs(struct pi433_device *device)
909 DIO1_irq_handler 993 DIO1_irq_handler
910 }; 994 };
911 995
912 for (i=0; i<NUM_DIO; i++) 996 for (i = 0; i < NUM_DIO; i++) {
913 {
914 /* "construct" name and get the gpio descriptor */ 997 /* "construct" name and get the gpio descriptor */
915 snprintf(name, sizeof(name), "DIO%d", i); 998 snprintf(name, sizeof(name), "DIO%d", i);
916 device->gpiod[i] = gpiod_get(&device->spi->dev, name, 0 /*GPIOD_IN*/); 999 device->gpiod[i] = gpiod_get(&device->spi->dev, name, 0 /*GPIOD_IN*/);
@@ -923,24 +1006,21 @@ static int setup_GPIOs(struct pi433_device *device)
923 if (device->gpiod[i] == ERR_PTR(-EBUSY)) 1006 if (device->gpiod[i] == ERR_PTR(-EBUSY))
924 dev_dbg(&device->spi->dev, "%s is busy.", name); 1007 dev_dbg(&device->spi->dev, "%s is busy.", name);
925 1008
926 if ( IS_ERR(device->gpiod[i]) ) 1009 if (IS_ERR(device->gpiod[i])) {
927 {
928 retval = PTR_ERR(device->gpiod[i]); 1010 retval = PTR_ERR(device->gpiod[i]);
929 /* release already allocated gpios */ 1011 /* release already allocated gpios */
930 for (i--; i>=0; i--) 1012 for (i--; i >= 0; i--) {
931 {
932 free_irq(device->irq_num[i], device); 1013 free_irq(device->irq_num[i], device);
933 gpiod_put(device->gpiod[i]); 1014 gpiod_put(device->gpiod[i]);
934 } 1015 }
935 return retval; 1016 return retval;
936 } 1017 }
937 1018
938
939 /* configure the pin */ 1019 /* configure the pin */
940 gpiod_unexport(device->gpiod[i]); 1020 gpiod_unexport(device->gpiod[i]);
941 retval = gpiod_direction_input(device->gpiod[i]); 1021 retval = gpiod_direction_input(device->gpiod[i]);
942 if (retval) return retval; 1022 if (retval)
943 1023 return retval;
944 1024
945 /* configure irq */ 1025 /* configure irq */
946 device->irq_num[i] = gpiod_to_irq(device->gpiod[i]); 1026 device->irq_num[i] = gpiod_to_irq(device->gpiod[i]);
@@ -967,16 +1047,14 @@ static void free_GPIOs(struct pi433_device *device)
967{ 1047{
968 int i; 1048 int i;
969 1049
970 for (i=0; i<NUM_DIO; i++) 1050 for (i = 0; i < NUM_DIO; i++) {
971 {
972 /* check if gpiod is valid */ 1051 /* check if gpiod is valid */
973 if ( IS_ERR(device->gpiod[i]) ) 1052 if (IS_ERR(device->gpiod[i]))
974 continue; 1053 continue;
975 1054
976 free_irq(device->irq_num[i], device); 1055 free_irq(device->irq_num[i], device);
977 gpiod_put(device->gpiod[i]); 1056 gpiod_put(device->gpiod[i]);
978 } 1057 }
979 return;
980} 1058}
981 1059
982static int pi433_get_minor(struct pi433_device *device) 1060static int pi433_get_minor(struct pi433_device *device)
@@ -989,7 +1067,7 @@ static int pi433_get_minor(struct pi433_device *device)
989 device->minor = retval; 1067 device->minor = retval;
990 retval = 0; 1068 retval = 0;
991 } else if (retval == -ENOSPC) { 1069 } else if (retval == -ENOSPC) {
992 dev_err(device->dev, "too many pi433 devices\n"); 1070 dev_err(&device->spi->dev, "too many pi433 devices\n");
993 retval = -EINVAL; 1071 retval = -EINVAL;
994 } 1072 }
995 mutex_unlock(&minor_lock); 1073 mutex_unlock(&minor_lock);
@@ -1002,6 +1080,7 @@ static void pi433_free_minor(struct pi433_device *dev)
1002 idr_remove(&pi433_idr, dev->minor); 1080 idr_remove(&pi433_idr, dev->minor);
1003 mutex_unlock(&minor_lock); 1081 mutex_unlock(&minor_lock);
1004} 1082}
1083
1005/*-------------------------------------------------------------------------*/ 1084/*-------------------------------------------------------------------------*/
1006 1085
1007static const struct file_operations pi433_fops = { 1086static const struct file_operations pi433_fops = {
@@ -1032,17 +1111,14 @@ static int pi433_probe(struct spi_device *spi)
1032 /* spi->max_speed_hz = 10000000; 1MHz already set by device tree overlay */ 1111 /* spi->max_speed_hz = 10000000; 1MHz already set by device tree overlay */
1033 1112
1034 retval = spi_setup(spi); 1113 retval = spi_setup(spi);
1035 if (retval) 1114 if (retval) {
1036 {
1037 dev_dbg(&spi->dev, "configuration of SPI interface failed!\n"); 1115 dev_dbg(&spi->dev, "configuration of SPI interface failed!\n");
1038 return retval; 1116 return retval;
1039 } 1117 }
1040 else 1118
1041 { 1119 dev_dbg(&spi->dev,
1042 dev_dbg(&spi->dev, 1120 "spi interface setup: mode 0x%2x, %d bits per word, %dhz max speed",
1043 "spi interface setup: mode 0x%2x, %d bits per word, %dhz max speed", 1121 spi->mode, spi->bits_per_word, spi->max_speed_hz);
1044 spi->mode, spi->bits_per_word, spi->max_speed_hz);
1045 }
1046 1122
1047 /* Ping the chip by reading the version register */ 1123 /* Ping the chip by reading the version register */
1048 retval = spi_w8r8(spi, 0x10); 1124 retval = spi_w8r8(spi, 0x10);
@@ -1089,27 +1165,32 @@ static int pi433_probe(struct spi_device *spi)
1089 } 1165 }
1090 1166
1091 /* setup the radio module */ 1167 /* setup the radio module */
1092 SET_CHECKED(rf69_set_mode (spi, standby)); 1168 retval = rf69_set_mode(spi, standby);
1093 SET_CHECKED(rf69_set_data_mode (spi, packet)); 1169 if (retval < 0)
1094 SET_CHECKED(rf69_set_amplifier_0 (spi, optionOn)); 1170 goto minor_failed;
1095 SET_CHECKED(rf69_set_amplifier_1 (spi, optionOff)); 1171 retval = rf69_set_data_mode(spi, DATAMODUL_MODE_PACKET);
1096 SET_CHECKED(rf69_set_amplifier_2 (spi, optionOff)); 1172 if (retval < 0)
1097 SET_CHECKED(rf69_set_output_power_level (spi, 13)); 1173 goto minor_failed;
1098 SET_CHECKED(rf69_set_antenna_impedance (spi, fiftyOhm)); 1174 retval = rf69_enable_amplifier(spi, MASK_PALEVEL_PA0);
1099 1175 if (retval < 0)
1100 /* start tx thread */ 1176 goto minor_failed;
1101 device->tx_task_struct = kthread_run(pi433_tx_thread, 1177 retval = rf69_disable_amplifier(spi, MASK_PALEVEL_PA1);
1102 device, 1178 if (retval < 0)
1103 "pi433_tx_task"); 1179 goto minor_failed;
1104 if (IS_ERR(device->tx_task_struct)) { 1180 retval = rf69_disable_amplifier(spi, MASK_PALEVEL_PA2);
1105 dev_dbg(device->dev, "start of send thread failed"); 1181 if (retval < 0)
1106 goto send_thread_failed; 1182 goto minor_failed;
1107 } 1183 retval = rf69_set_output_power_level(spi, 13);
1184 if (retval < 0)
1185 goto minor_failed;
1186 retval = rf69_set_antenna_impedance(spi, fiftyOhm);
1187 if (retval < 0)
1188 goto minor_failed;
1108 1189
1109 /* determ minor number */ 1190 /* determ minor number */
1110 retval = pi433_get_minor(device); 1191 retval = pi433_get_minor(device);
1111 if (retval) { 1192 if (retval) {
1112 dev_dbg(device->dev, "get of minor number failed"); 1193 dev_dbg(&spi->dev, "get of minor number failed");
1113 goto minor_failed; 1194 goto minor_failed;
1114 } 1195 }
1115 1196
@@ -1119,19 +1200,29 @@ static int pi433_probe(struct spi_device *spi)
1119 &spi->dev, 1200 &spi->dev,
1120 device->devt, 1201 device->devt,
1121 device, 1202 device,
1122 "pi433"); 1203 "pi433.%d",
1204 device->minor);
1123 if (IS_ERR(device->dev)) { 1205 if (IS_ERR(device->dev)) {
1124 pr_err("pi433: device register failed\n"); 1206 pr_err("pi433: device register failed\n");
1125 retval = PTR_ERR(device->dev); 1207 retval = PTR_ERR(device->dev);
1126 goto device_create_failed; 1208 goto device_create_failed;
1127 } 1209 } else {
1128 else {
1129 dev_dbg(device->dev, 1210 dev_dbg(device->dev,
1130 "created device for major %d, minor %d\n", 1211 "created device for major %d, minor %d\n",
1131 MAJOR(pi433_dev), 1212 MAJOR(pi433_dev),
1132 device->minor); 1213 device->minor);
1133 } 1214 }
1134 1215
1216 /* start tx thread */
1217 device->tx_task_struct = kthread_run(pi433_tx_thread,
1218 device,
1219 "pi433.%d_tx_task",
1220 device->minor);
1221 if (IS_ERR(device->tx_task_struct)) {
1222 dev_dbg(device->dev, "start of send thread failed");
1223 goto send_thread_failed;
1224 }
1225
1135 /* create cdev */ 1226 /* create cdev */
1136 device->cdev = cdev_alloc(); 1227 device->cdev = cdev_alloc();
1137 device->cdev->owner = THIS_MODULE; 1228 device->cdev->owner = THIS_MODULE;
@@ -1148,12 +1239,12 @@ static int pi433_probe(struct spi_device *spi)
1148 return 0; 1239 return 0;
1149 1240
1150cdev_failed: 1241cdev_failed:
1242 kthread_stop(device->tx_task_struct);
1243send_thread_failed:
1151 device_destroy(pi433_class, device->devt); 1244 device_destroy(pi433_class, device->devt);
1152device_create_failed: 1245device_create_failed:
1153 pi433_free_minor(device); 1246 pi433_free_minor(device);
1154minor_failed: 1247minor_failed:
1155 kthread_stop(device->tx_task_struct);
1156send_thread_failed:
1157 free_GPIOs(device); 1248 free_GPIOs(device);
1158GPIO_failed: 1249GPIO_failed:
1159 kfree(device); 1250 kfree(device);
@@ -1230,14 +1321,16 @@ static int __init pi433_init(void)
1230 1321
1231 pi433_class = class_create(THIS_MODULE, "pi433"); 1322 pi433_class = class_create(THIS_MODULE, "pi433");
1232 if (IS_ERR(pi433_class)) { 1323 if (IS_ERR(pi433_class)) {
1233 unregister_chrdev(MAJOR(pi433_dev), pi433_spi_driver.driver.name); 1324 unregister_chrdev(MAJOR(pi433_dev),
1325 pi433_spi_driver.driver.name);
1234 return PTR_ERR(pi433_class); 1326 return PTR_ERR(pi433_class);
1235 } 1327 }
1236 1328
1237 status = spi_register_driver(&pi433_spi_driver); 1329 status = spi_register_driver(&pi433_spi_driver);
1238 if (status < 0) { 1330 if (status < 0) {
1239 class_destroy(pi433_class); 1331 class_destroy(pi433_class);
1240 unregister_chrdev(MAJOR(pi433_dev), pi433_spi_driver.driver.name); 1332 unregister_chrdev(MAJOR(pi433_dev),
1333 pi433_spi_driver.driver.name);
1241 } 1334 }
1242 1335
1243 return status; 1336 return status;
diff --git a/drivers/staging/pi433/pi433_if.h b/drivers/staging/pi433/pi433_if.h
index e6ed3cd9b2e2..7314f69af198 100644
--- a/drivers/staging/pi433/pi433_if.h
+++ b/drivers/staging/pi433/pi433_if.h
@@ -34,8 +34,10 @@
34 34
35/*---------------------------------------------------------------------------*/ 35/*---------------------------------------------------------------------------*/
36 36
37 37enum option_on_off {
38/*---------------------------------------------------------------------------*/ 38 OPTION_OFF,
39 OPTION_ON
40};
39 41
40/* IOCTL structs and commands */ 42/* IOCTL structs and commands */
41 43
@@ -57,14 +59,13 @@
57 * 59 *
58 * NOTE: struct layout is the same in 64bit and 32bit userspace. 60 * NOTE: struct layout is the same in 64bit and 32bit userspace.
59 */ 61 */
60#define PI433_TX_CFG_IOCTL_NR 0 62#define PI433_TX_CFG_IOCTL_NR 0
61struct pi433_tx_cfg 63struct pi433_tx_cfg {
62{
63 __u32 frequency; 64 __u32 frequency;
64 __u16 bit_rate; 65 __u16 bit_rate;
65 __u32 dev_frequency; 66 __u32 dev_frequency;
66 enum modulation modulation; 67 enum modulation modulation;
67 enum modShaping modShaping; 68 enum mod_shaping mod_shaping;
68 69
69 enum paRamp pa_ramp; 70 enum paRamp pa_ramp;
70 71
@@ -72,13 +73,12 @@ struct pi433_tx_cfg
72 73
73 __u16 repetitions; 74 __u16 repetitions;
74 75
75
76 /* packet format */ 76 /* packet format */
77 enum optionOnOff enable_preamble; 77 enum option_on_off enable_preamble;
78 enum optionOnOff enable_sync; 78 enum option_on_off enable_sync;
79 enum optionOnOff enable_length_byte; 79 enum option_on_off enable_length_byte;
80 enum optionOnOff enable_address_byte; 80 enum option_on_off enable_address_byte;
81 enum optionOnOff enable_crc; 81 enum option_on_off enable_crc;
82 82
83 __u16 preamble_length; 83 __u16 preamble_length;
84 __u8 sync_length; 84 __u8 sync_length;
@@ -88,7 +88,6 @@ struct pi433_tx_cfg
88 __u8 address_byte; 88 __u8 address_byte;
89}; 89};
90 90
91
92/** 91/**
93 * struct pi433_rx_config - describes the configuration of the radio module for sending 92 * struct pi433_rx_config - describes the configuration of the radio module for sending
94 * @frequency: 93 * @frequency:
@@ -107,7 +106,7 @@ struct pi433_tx_cfg
107 * 106 *
108 * NOTE: struct layout is the same in 64bit and 32bit userspace. 107 * NOTE: struct layout is the same in 64bit and 32bit userspace.
109 */ 108 */
110#define PI433_RX_CFG_IOCTL_NR 1 109#define PI433_RX_CFG_IOCTL_NR 1
111struct pi433_rx_cfg { 110struct pi433_rx_cfg {
112 __u32 frequency; 111 __u32 frequency;
113 __u16 bit_rate; 112 __u16 bit_rate;
@@ -116,20 +115,18 @@ struct pi433_rx_cfg {
116 enum modulation modulation; 115 enum modulation modulation;
117 116
118 __u8 rssi_threshold; 117 __u8 rssi_threshold;
119 enum thresholdDecrement thresholdDecrement; 118 enum thresholdDecrement threshold_decrement;
120 enum antennaImpedance antenna_impedance; 119 enum antennaImpedance antenna_impedance;
121 enum lnaGain lna_gain; 120 enum lnaGain lna_gain;
122 enum mantisse bw_mantisse; /* normal: 0x50 */ 121 enum mantisse bw_mantisse; /* normal: 0x50 */
123 __u8 bw_exponent; /* during AFC: 0x8b */ 122 __u8 bw_exponent; /* during AFC: 0x8b */
124 enum dagc dagc; 123 enum dagc dagc;
125 124
126
127
128 /* packet format */ 125 /* packet format */
129 enum optionOnOff enable_sync; 126 enum option_on_off enable_sync;
130 enum optionOnOff enable_length_byte; /* should be used in combination with sync, only */ 127 enum option_on_off enable_length_byte; /* should be used in combination with sync, only */
131 enum addressFiltering enable_address_filtering; /* operational with sync, only */ 128 enum addressFiltering enable_address_filtering; /* operational with sync, only */
132 enum optionOnOff enable_crc; /* only operational, if sync on and fixed length or length byte is used */ 129 enum option_on_off enable_crc; /* only operational, if sync on and fixed length or length byte is used */
133 130
134 __u8 sync_length; 131 __u8 sync_length;
135 __u8 fixed_message_length; 132 __u8 fixed_message_length;
@@ -140,7 +137,6 @@ struct pi433_rx_cfg {
140 __u8 broadcast_address; 137 __u8 broadcast_address;
141}; 138};
142 139
143
144#define PI433_IOC_MAGIC 'r' 140#define PI433_IOC_MAGIC 'r'
145 141
146#define PI433_IOC_RD_TX_CFG _IOR(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)]) 142#define PI433_IOC_RD_TX_CFG _IOR(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)])
diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index 12c9df9cddde..7ccdff6ae213 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -29,27 +29,98 @@
29#include "rf69_registers.h" 29#include "rf69_registers.h"
30 30
31#define F_OSC 32000000 /* in Hz */ 31#define F_OSC 32000000 /* in Hz */
32#define FIFO_SIZE 66 /* in byte */ 32#define FIFO_SIZE 66 /* in byte */
33 33
34/*-------------------------------------------------------------------------*/ 34/*-------------------------------------------------------------------------*/
35 35
36#define READ_REG(x) rf69_read_reg (spi, x) 36static u8 rf69_read_reg(struct spi_device *spi, u8 addr)
37#define WRITE_REG(x, y) rf69_write_reg(spi, x, y) 37{
38 int retval;
39
40 retval = spi_w8r8(spi, addr);
41
42#ifdef DEBUG_VALUES
43 if (retval < 0)
44 /* should never happen, since we already checked,
45 * that module is connected. Therefore no error
46 * handling, just an optional error message...
47 */
48 dev_dbg(&spi->dev, "read 0x%x FAILED\n", addr);
49 else
50 dev_dbg(&spi->dev, "read 0x%x from reg 0x%x\n", retval, addr);
51#endif
52
53 return retval;
54}
55
56static int rf69_write_reg(struct spi_device *spi, u8 addr, u8 value)
57{
58 int retval;
59 char buffer[2];
60
61 buffer[0] = addr | WRITE_BIT;
62 buffer[1] = value;
63
64 retval = spi_write(spi, &buffer, 2);
65
66#ifdef DEBUG_VALUES
67 if (retval < 0)
68 /* should never happen, since we already checked,
69 * that module is connected. Therefore no error
70 * handling, just an optional error message...
71 */
72 dev_dbg(&spi->dev, "write 0x%x to 0x%x FAILED\n", value, addr);
73 else
74 dev_dbg(&spi->dev, "wrote 0x%x to reg 0x%x\n", value, addr);
75#endif
76
77 return retval;
78}
38 79
39/*-------------------------------------------------------------------------*/ 80/*-------------------------------------------------------------------------*/
40 81
41int rf69_set_mode(struct spi_device *spi, enum mode mode) 82static int rf69_set_bit(struct spi_device *spi, u8 reg, u8 mask)
83{
84 u8 tmp;
85
86 tmp = rf69_read_reg(spi, reg);
87 tmp = tmp | mask;
88 return rf69_write_reg(spi, reg, tmp);
89}
90
91static int rf69_clear_bit(struct spi_device *spi, u8 reg, u8 mask)
42{ 92{
43 #ifdef DEBUG 93 u8 tmp;
44 dev_dbg(&spi->dev, "set: mode");
45 #endif
46 94
95 tmp = rf69_read_reg(spi, reg);
96 tmp = tmp & ~mask;
97 return rf69_write_reg(spi, reg, tmp);
98}
99
100static inline int rf69_read_mod_write(struct spi_device *spi, u8 reg, u8 mask, u8 value)
101{
102 u8 tmp;
103
104 tmp = rf69_read_reg(spi, reg);
105 tmp = (tmp & ~mask) | value;
106 return rf69_write_reg(spi, reg, tmp);
107}
108
109/*-------------------------------------------------------------------------*/
110
111int rf69_set_mode(struct spi_device *spi, enum mode mode)
112{
47 switch (mode) { 113 switch (mode) {
48 case transmit: return WRITE_REG(REG_OPMODE, (READ_REG(REG_OPMODE) & ~MASK_OPMODE_MODE) | OPMODE_MODE_TRANSMIT); 114 case transmit:
49 case receive: return WRITE_REG(REG_OPMODE, (READ_REG(REG_OPMODE) & ~MASK_OPMODE_MODE) | OPMODE_MODE_RECEIVE); 115 return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, OPMODE_MODE_TRANSMIT);
50 case synthesizer: return WRITE_REG(REG_OPMODE, (READ_REG(REG_OPMODE) & ~MASK_OPMODE_MODE) | OPMODE_MODE_SYNTHESIZER); 116 case receive:
51 case standby: return WRITE_REG(REG_OPMODE, (READ_REG(REG_OPMODE) & ~MASK_OPMODE_MODE) | OPMODE_MODE_STANDBY); 117 return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, OPMODE_MODE_RECEIVE);
52 case mode_sleep: return WRITE_REG(REG_OPMODE, (READ_REG(REG_OPMODE) & ~MASK_OPMODE_MODE) | OPMODE_MODE_SLEEP); 118 case synthesizer:
119 return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, OPMODE_MODE_SYNTHESIZER);
120 case standby:
121 return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, OPMODE_MODE_STANDBY);
122 case mode_sleep:
123 return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, OPMODE_MODE_SLEEP);
53 default: 124 default:
54 dev_dbg(&spi->dev, "set: illegal input param"); 125 dev_dbg(&spi->dev, "set: illegal input param");
55 return -EINVAL; 126 return -EINVAL;
@@ -58,82 +129,75 @@ int rf69_set_mode(struct spi_device *spi, enum mode mode)
58 // we are using packet mode, so this check is not really needed 129 // we are using packet mode, so this check is not really needed
59 // but waiting for mode ready is necessary when going from sleep because the FIFO may not be immediately available from previous mode 130 // but waiting for mode ready is necessary when going from sleep because the FIFO may not be immediately available from previous mode
60 //while (_mode == RF69_MODE_SLEEP && (READ_REG(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady 131 //while (_mode == RF69_MODE_SLEEP && (READ_REG(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady
61
62} 132}
63 133
64int rf69_set_data_mode(struct spi_device *spi, enum dataMode dataMode) 134int rf69_set_data_mode(struct spi_device *spi, u8 data_mode)
65{ 135{
66 #ifdef DEBUG 136 return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODE, data_mode);
67 dev_dbg(&spi->dev, "set: data mode");
68 #endif
69
70 switch (dataMode) {
71 case packet: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODE) | DATAMODUL_MODE_PACKET);
72 case continuous: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODE) | DATAMODUL_MODE_CONTINUOUS);
73 case continuousNoSync: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODE) | DATAMODUL_MODE_CONTINUOUS_NOSYNC);
74 default:
75 dev_dbg(&spi->dev, "set: illegal input param");
76 return -EINVAL;
77 }
78} 137}
79 138
80int rf69_set_modulation(struct spi_device *spi, enum modulation modulation) 139int rf69_set_modulation(struct spi_device *spi, enum modulation modulation)
81{ 140{
82 #ifdef DEBUG
83 dev_dbg(&spi->dev, "set: modulation");
84 #endif
85
86 switch (modulation) { 141 switch (modulation) {
87 case OOK: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODULATION_TYPE) | DATAMODUL_MODULATION_TYPE_OOK); 142 case OOK:
88 case FSK: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODULATION_TYPE) | DATAMODUL_MODULATION_TYPE_FSK); 143 return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_TYPE, DATAMODUL_MODULATION_TYPE_OOK);
144 case FSK:
145 return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_TYPE, DATAMODUL_MODULATION_TYPE_FSK);
89 default: 146 default:
90 dev_dbg(&spi->dev, "set: illegal input param"); 147 dev_dbg(&spi->dev, "set: illegal input param");
91 return -EINVAL; 148 return -EINVAL;
92 } 149 }
93} 150}
94 151
95enum modulation rf69_get_modulation(struct spi_device *spi) 152static enum modulation rf69_get_modulation(struct spi_device *spi)
96{ 153{
97 u8 currentValue; 154 u8 currentValue;
98 155
99 #ifdef DEBUG 156 currentValue = rf69_read_reg(spi, REG_DATAMODUL);
100 dev_dbg(&spi->dev, "get: mode");
101 #endif
102
103 currentValue = READ_REG(REG_DATAMODUL);
104 157
105 switch (currentValue & MASK_DATAMODUL_MODULATION_TYPE) { 158 switch (currentValue & MASK_DATAMODUL_MODULATION_TYPE) {
106 case DATAMODUL_MODULATION_TYPE_OOK: return OOK; 159 case DATAMODUL_MODULATION_TYPE_OOK:
107 case DATAMODUL_MODULATION_TYPE_FSK: return FSK; 160 return OOK;
108 default: return undefined; 161 case DATAMODUL_MODULATION_TYPE_FSK:
162 return FSK;
163 default:
164 return UNDEF;
109 } 165 }
110} 166}
111 167
112int rf69_set_modulation_shaping(struct spi_device *spi, enum modShaping modShaping) 168int rf69_set_modulation_shaping(struct spi_device *spi,
169 enum mod_shaping mod_shaping)
113{ 170{
114 #ifdef DEBUG 171 switch (rf69_get_modulation(spi)) {
115 dev_dbg(&spi->dev, "set: mod shaping"); 172 case FSK:
116 #endif 173 switch (mod_shaping) {
117 174 case SHAPING_OFF:
118 if (rf69_get_modulation(spi) == FSK) { 175 return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_NONE);
119 switch (modShaping) { 176 case SHAPING_1_0:
120 case shapingOff: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODULATION_SHAPE) | DATAMODUL_MODULATION_SHAPE_NONE); 177 return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_1_0);
121 case shaping1_0: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODULATION_SHAPE) | DATAMODUL_MODULATION_SHAPE_1_0); 178 case SHAPING_0_5:
122 case shaping0_5: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODULATION_SHAPE) | DATAMODUL_MODULATION_SHAPE_0_3); 179 return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_0_5);
123 case shaping0_3: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODULATION_SHAPE) | DATAMODUL_MODULATION_SHAPE_0_5); 180 case SHAPING_0_3:
181 return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_0_3);
124 default: 182 default:
125 dev_dbg(&spi->dev, "set: illegal input param"); 183 dev_dbg(&spi->dev, "set: illegal input param");
126 return -EINVAL; 184 return -EINVAL;
127 } 185 }
128 } else { 186 case OOK:
129 switch (modShaping) { 187 switch (mod_shaping) {
130 case shapingOff: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODULATION_SHAPE) | DATAMODUL_MODULATION_SHAPE_NONE); 188 case SHAPING_OFF:
131 case shapingBR: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODULATION_SHAPE) | DATAMODUL_MODULATION_SHAPE_BR); 189 return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_NONE);
132 case shaping2BR: return WRITE_REG(REG_DATAMODUL, (READ_REG(REG_DATAMODUL) & ~MASK_DATAMODUL_MODULATION_SHAPE) | DATAMODUL_MODULATION_SHAPE_2BR); 190 case SHAPING_BR:
191 return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_BR);
192 case SHAPING_2BR:
193 return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_2BR);
133 default: 194 default:
134 dev_dbg(&spi->dev, "set: illegal input param"); 195 dev_dbg(&spi->dev, "set: illegal input param");
135 return -EINVAL; 196 return -EINVAL;
136 } 197 }
198 default:
199 dev_dbg(&spi->dev, "set: modulation undefined");
200 return -EINVAL;
137 } 201 }
138} 202}
139 203
@@ -145,10 +209,6 @@ int rf69_set_bit_rate(struct spi_device *spi, u16 bitRate)
145 u8 msb; 209 u8 msb;
146 u8 lsb; 210 u8 lsb;
147 211
148 #ifdef DEBUG
149 dev_dbg(&spi->dev, "set: bit rate");
150 #endif
151
152 // check input value 212 // check input value
153 bitRate_min = F_OSC / 8388608; // 8388608 = 2^23; 213 bitRate_min = F_OSC / 8388608; // 8388608 = 2^23;
154 if (bitRate < bitRate_min) { 214 if (bitRate < bitRate_min) {
@@ -159,15 +219,14 @@ int rf69_set_bit_rate(struct spi_device *spi, u16 bitRate)
159 // calculate reg settings 219 // calculate reg settings
160 bitRate_reg = (F_OSC / bitRate); 220 bitRate_reg = (F_OSC / bitRate);
161 221
162 msb = (bitRate_reg&0xff00) >> 8; 222 msb = (bitRate_reg & 0xff00) >> 8;
163 lsb = (bitRate_reg&0xff); 223 lsb = (bitRate_reg & 0xff);
164 224
165 // transmit to RF 69 225 // transmit to RF 69
166 retval = WRITE_REG(REG_BITRATE_MSB, msb); 226 retval = rf69_write_reg(spi, REG_BITRATE_MSB, msb);
167 if (retval) 227 if (retval)
168 return retval; 228 return retval;
169 229 retval = rf69_write_reg(spi, REG_BITRATE_LSB, lsb);
170 retval = WRITE_REG(REG_BITRATE_LSB, lsb);
171 if (retval) 230 if (retval)
172 return retval; 231 return retval;
173 232
@@ -177,18 +236,14 @@ int rf69_set_bit_rate(struct spi_device *spi, u16 bitRate)
177int rf69_set_deviation(struct spi_device *spi, u32 deviation) 236int rf69_set_deviation(struct spi_device *spi, u32 deviation)
178{ 237{
179 int retval; 238 int retval;
180// u32 f_max; TODO: Abhängigkeit von Bitrate beachten!!
181 u64 f_reg; 239 u64 f_reg;
182 u64 f_step; 240 u64 f_step;
183 u8 msb; 241 u8 msb;
184 u8 lsb; 242 u8 lsb;
185 u64 factor = 1000000; // to improve precision of calculation 243 u64 factor = 1000000; // to improve precision of calculation
186 244
187 #ifdef DEBUG 245 // TODO: Dependency to bitrate
188 dev_dbg(&spi->dev, "set: deviation"); 246 if (deviation < 600 || deviation > 500000) {
189 #endif
190
191 if (deviation < 600 || deviation > 500000) { //TODO: Abhängigkeit von Bitrate beachten!!
192 dev_dbg(&spi->dev, "set_deviation: illegal input param"); 247 dev_dbg(&spi->dev, "set_deviation: illegal input param");
193 return -EINVAL; 248 return -EINVAL;
194 } 249 }
@@ -201,8 +256,8 @@ int rf69_set_deviation(struct spi_device *spi, u32 deviation)
201 f_reg = deviation * factor; 256 f_reg = deviation * factor;
202 do_div(f_reg, f_step); 257 do_div(f_reg, f_step);
203 258
204 msb = (f_reg&0xff00) >> 8; 259 msb = (f_reg & 0xff00) >> 8;
205 lsb = (f_reg&0xff); 260 lsb = (f_reg & 0xff);
206 261
207 // check msb 262 // check msb
208 if (msb & ~FDEVMASB_MASK) { 263 if (msb & ~FDEVMASB_MASK) {
@@ -211,11 +266,10 @@ int rf69_set_deviation(struct spi_device *spi, u32 deviation)
211 } 266 }
212 267
213 // write to chip 268 // write to chip
214 retval = WRITE_REG(REG_FDEV_MSB, msb); 269 retval = rf69_write_reg(spi, REG_FDEV_MSB, msb);
215 if (retval) 270 if (retval)
216 return retval; 271 return retval;
217 272 retval = rf69_write_reg(spi, REG_FDEV_LSB, lsb);
218 retval = WRITE_REG(REG_FDEV_LSB, lsb);
219 if (retval) 273 if (retval)
220 return retval; 274 return retval;
221 275
@@ -233,10 +287,6 @@ int rf69_set_frequency(struct spi_device *spi, u32 frequency)
233 u8 lsb; 287 u8 lsb;
234 u64 factor = 1000000; // to improve precision of calculation 288 u64 factor = 1000000; // to improve precision of calculation
235 289
236 #ifdef DEBUG
237 dev_dbg(&spi->dev, "set: frequency");
238 #endif
239
240 // calculat f step 290 // calculat f step
241 f_step = F_OSC * factor; 291 f_step = F_OSC * factor;
242 do_div(f_step, 524288); // 524288 = 2^19 292 do_div(f_step, 524288); // 524288 = 2^19
@@ -252,78 +302,38 @@ int rf69_set_frequency(struct spi_device *spi, u32 frequency)
252 f_reg = frequency * factor; 302 f_reg = frequency * factor;
253 do_div(f_reg, f_step); 303 do_div(f_reg, f_step);
254 304
255 msb = (f_reg&0xff0000) >> 16; 305 msb = (f_reg & 0xff0000) >> 16;
256 mid = (f_reg&0xff00) >> 8; 306 mid = (f_reg & 0xff00) >> 8;
257 lsb = (f_reg&0xff); 307 lsb = (f_reg & 0xff);
258 308
259 // write to chip 309 // write to chip
260 retval = WRITE_REG(REG_FRF_MSB, msb); 310 retval = rf69_write_reg(spi, REG_FRF_MSB, msb);
261 if (retval) 311 if (retval)
262 return retval; 312 return retval;
263 313 retval = rf69_write_reg(spi, REG_FRF_MID, mid);
264 retval = WRITE_REG(REG_FRF_MID, mid);
265 if (retval) 314 if (retval)
266 return retval; 315 return retval;
267 316 retval = rf69_write_reg(spi, REG_FRF_LSB, lsb);
268 retval = WRITE_REG(REG_FRF_LSB, lsb);
269 if (retval) 317 if (retval)
270 return retval; 318 return retval;
271 319
272 return 0; 320 return 0;
273} 321}
274 322
275int rf69_set_amplifier_0(struct spi_device *spi, enum optionOnOff optionOnOff) 323int rf69_enable_amplifier(struct spi_device *spi, u8 amplifier_mask)
276{ 324{
277 #ifdef DEBUG 325 return rf69_set_bit(spi, REG_PALEVEL, amplifier_mask);
278 dev_dbg(&spi->dev, "set: amp #0");
279 #endif
280
281 switch (optionOnOff) {
282 case optionOn: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) | MASK_PALEVEL_PA0));
283 case optionOff: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) & ~MASK_PALEVEL_PA0));
284 default:
285 dev_dbg(&spi->dev, "set: illegal input param");
286 return -EINVAL;
287 }
288}
289
290int rf69_set_amplifier_1(struct spi_device *spi, enum optionOnOff optionOnOff)
291{
292 #ifdef DEBUG
293 dev_dbg(&spi->dev, "set: amp #1");
294 #endif
295
296 switch (optionOnOff) {
297 case optionOn: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) | MASK_PALEVEL_PA1));
298 case optionOff: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) & ~MASK_PALEVEL_PA1));
299 default:
300 dev_dbg(&spi->dev, "set: illegal input param");
301 return -EINVAL;
302 }
303} 326}
304 327
305int rf69_set_amplifier_2(struct spi_device *spi, enum optionOnOff optionOnOff) 328int rf69_disable_amplifier(struct spi_device *spi, u8 amplifier_mask)
306{ 329{
307 #ifdef DEBUG 330 return rf69_clear_bit(spi, REG_PALEVEL, amplifier_mask);
308 dev_dbg(&spi->dev, "set: amp #2");
309 #endif
310
311 switch (optionOnOff) {
312 case optionOn: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) | MASK_PALEVEL_PA2));
313 case optionOff: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) & ~MASK_PALEVEL_PA2));
314 default:
315 dev_dbg(&spi->dev, "set: illegal input param");
316 return -EINVAL;
317 }
318} 331}
319 332
320int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel) 333int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel)
321{ 334{
322 #ifdef DEBUG 335 // TODO: Dependency to PA0,1,2 setting
323 dev_dbg(&spi->dev, "set: power level"); 336 powerLevel += 18;
324 #endif
325
326 powerLevel += 18; // TODO Abhängigkeit von PA0,1,2 setting
327 337
328 // check input value 338 // check input value
329 if (powerLevel > 0x1f) { 339 if (powerLevel > 0x1f) {
@@ -332,32 +342,44 @@ int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel)
332 } 342 }
333 343
334 // write value 344 // write value
335 return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) & ~MASK_PALEVEL_OUTPUT_POWER) | powerLevel); 345 return rf69_read_mod_write(spi, REG_PALEVEL, MASK_PALEVEL_OUTPUT_POWER, powerLevel);
336} 346}
337 347
338int rf69_set_pa_ramp(struct spi_device *spi, enum paRamp paRamp) 348int rf69_set_pa_ramp(struct spi_device *spi, enum paRamp paRamp)
339{ 349{
340 #ifdef DEBUG
341 dev_dbg(&spi->dev, "set: pa ramp");
342 #endif
343
344 switch (paRamp) { 350 switch (paRamp) {
345 case ramp3400: return WRITE_REG(REG_PARAMP, PARAMP_3400); 351 case ramp3400:
346 case ramp2000: return WRITE_REG(REG_PARAMP, PARAMP_2000); 352 return rf69_write_reg(spi, REG_PARAMP, PARAMP_3400);
347 case ramp1000: return WRITE_REG(REG_PARAMP, PARAMP_1000); 353 case ramp2000:
348 case ramp500: return WRITE_REG(REG_PARAMP, PARAMP_500); 354 return rf69_write_reg(spi, REG_PARAMP, PARAMP_2000);
349 case ramp250: return WRITE_REG(REG_PARAMP, PARAMP_250); 355 case ramp1000:
350 case ramp125: return WRITE_REG(REG_PARAMP, PARAMP_125); 356 return rf69_write_reg(spi, REG_PARAMP, PARAMP_1000);
351 case ramp100: return WRITE_REG(REG_PARAMP, PARAMP_100); 357 case ramp500:
352 case ramp62: return WRITE_REG(REG_PARAMP, PARAMP_62); 358 return rf69_write_reg(spi, REG_PARAMP, PARAMP_500);
353 case ramp50: return WRITE_REG(REG_PARAMP, PARAMP_50); 359 case ramp250:
354 case ramp40: return WRITE_REG(REG_PARAMP, PARAMP_40); 360 return rf69_write_reg(spi, REG_PARAMP, PARAMP_250);
355 case ramp31: return WRITE_REG(REG_PARAMP, PARAMP_31); 361 case ramp125:
356 case ramp25: return WRITE_REG(REG_PARAMP, PARAMP_25); 362 return rf69_write_reg(spi, REG_PARAMP, PARAMP_125);
357 case ramp20: return WRITE_REG(REG_PARAMP, PARAMP_20); 363 case ramp100:
358 case ramp15: return WRITE_REG(REG_PARAMP, PARAMP_15); 364 return rf69_write_reg(spi, REG_PARAMP, PARAMP_100);
359 case ramp12: return WRITE_REG(REG_PARAMP, PARAMP_12); 365 case ramp62:
360 case ramp10: return WRITE_REG(REG_PARAMP, PARAMP_10); 366 return rf69_write_reg(spi, REG_PARAMP, PARAMP_62);
367 case ramp50:
368 return rf69_write_reg(spi, REG_PARAMP, PARAMP_50);
369 case ramp40:
370 return rf69_write_reg(spi, REG_PARAMP, PARAMP_40);
371 case ramp31:
372 return rf69_write_reg(spi, REG_PARAMP, PARAMP_31);
373 case ramp25:
374 return rf69_write_reg(spi, REG_PARAMP, PARAMP_25);
375 case ramp20:
376 return rf69_write_reg(spi, REG_PARAMP, PARAMP_20);
377 case ramp15:
378 return rf69_write_reg(spi, REG_PARAMP, PARAMP_15);
379 case ramp12:
380 return rf69_write_reg(spi, REG_PARAMP, PARAMP_12);
381 case ramp10:
382 return rf69_write_reg(spi, REG_PARAMP, PARAMP_10);
361 default: 383 default:
362 dev_dbg(&spi->dev, "set: illegal input param"); 384 dev_dbg(&spi->dev, "set: illegal input param");
363 return -EINVAL; 385 return -EINVAL;
@@ -366,13 +388,11 @@ int rf69_set_pa_ramp(struct spi_device *spi, enum paRamp paRamp)
366 388
367int rf69_set_antenna_impedance(struct spi_device *spi, enum antennaImpedance antennaImpedance) 389int rf69_set_antenna_impedance(struct spi_device *spi, enum antennaImpedance antennaImpedance)
368{ 390{
369 #ifdef DEBUG
370 dev_dbg(&spi->dev, "set: antenna impedance");
371 #endif
372
373 switch (antennaImpedance) { 391 switch (antennaImpedance) {
374 case fiftyOhm: return WRITE_REG(REG_LNA, (READ_REG(REG_LNA) & ~MASK_LNA_ZIN)); 392 case fiftyOhm:
375 case twohundretOhm: return WRITE_REG(REG_LNA, (READ_REG(REG_LNA) | MASK_LNA_ZIN)); 393 return rf69_clear_bit(spi, REG_LNA, MASK_LNA_ZIN);
394 case twohundretOhm:
395 return rf69_set_bit(spi, REG_LNA, MASK_LNA_ZIN);
376 default: 396 default:
377 dev_dbg(&spi->dev, "set: illegal input param"); 397 dev_dbg(&spi->dev, "set: illegal input param");
378 return -EINVAL; 398 return -EINVAL;
@@ -381,81 +401,27 @@ int rf69_set_antenna_impedance(struct spi_device *spi, enum antennaImpedance ant
381 401
382int rf69_set_lna_gain(struct spi_device *spi, enum lnaGain lnaGain) 402int rf69_set_lna_gain(struct spi_device *spi, enum lnaGain lnaGain)
383{ 403{
384 #ifdef DEBUG
385 dev_dbg(&spi->dev, "set: lna gain");
386 #endif
387
388 switch (lnaGain) { 404 switch (lnaGain) {
389 case automatic: return WRITE_REG(REG_LNA, ((READ_REG(REG_LNA) & ~MASK_LNA_GAIN) & LNA_GAIN_AUTO)); 405 case automatic:
390 case max: return WRITE_REG(REG_LNA, ((READ_REG(REG_LNA) & ~MASK_LNA_GAIN) & LNA_GAIN_MAX)); 406 return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, LNA_GAIN_AUTO);
391 case maxMinus6: return WRITE_REG(REG_LNA, ((READ_REG(REG_LNA) & ~MASK_LNA_GAIN) & LNA_GAIN_MAX_MINUS_6)); 407 case max:
392 case maxMinus12: return WRITE_REG(REG_LNA, ((READ_REG(REG_LNA) & ~MASK_LNA_GAIN) & LNA_GAIN_MAX_MINUS_12)); 408 return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, LNA_GAIN_MAX);
393 case maxMinus24: return WRITE_REG(REG_LNA, ((READ_REG(REG_LNA) & ~MASK_LNA_GAIN) & LNA_GAIN_MAX_MINUS_24)); 409 case max_minus_6:
394 case maxMinus36: return WRITE_REG(REG_LNA, ((READ_REG(REG_LNA) & ~MASK_LNA_GAIN) & LNA_GAIN_MAX_MINUS_36)); 410 return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, LNA_GAIN_MAX_MINUS_6);
395 case maxMinus48: return WRITE_REG(REG_LNA, ((READ_REG(REG_LNA) & ~MASK_LNA_GAIN) & LNA_GAIN_MAX_MINUS_48)); 411 case max_minus_12:
412 return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, LNA_GAIN_MAX_MINUS_12);
413 case max_minus_24:
414 return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, LNA_GAIN_MAX_MINUS_24);
415 case max_minus_36:
416 return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, LNA_GAIN_MAX_MINUS_36);
417 case max_minus_48:
418 return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, LNA_GAIN_MAX_MINUS_48);
396 default: 419 default:
397 dev_dbg(&spi->dev, "set: illegal input param"); 420 dev_dbg(&spi->dev, "set: illegal input param");
398 return -EINVAL; 421 return -EINVAL;
399 } 422 }
400} 423}
401 424
402enum lnaGain rf69_get_lna_gain(struct spi_device *spi)
403{
404 u8 currentValue;
405
406 #ifdef DEBUG
407 dev_dbg(&spi->dev, "get: lna gain");
408 #endif
409
410 currentValue = READ_REG(REG_LNA);
411
412 switch (currentValue & MASK_LNA_CURRENT_GAIN >> 3) { // improvement: change 3 to define
413 case LNA_GAIN_AUTO: return automatic;
414 case LNA_GAIN_MAX: return max;
415 case LNA_GAIN_MAX_MINUS_6: return maxMinus6;
416 case LNA_GAIN_MAX_MINUS_12: return maxMinus12;
417 case LNA_GAIN_MAX_MINUS_24: return maxMinus24;
418 case LNA_GAIN_MAX_MINUS_36: return maxMinus36;
419 case LNA_GAIN_MAX_MINUS_48: return maxMinus48;
420 default: return undefined;
421 }
422}
423
424int rf69_set_dc_cut_off_frequency_intern(struct spi_device *spi, u8 reg, enum dccPercent dccPercent)
425{
426 switch (dccPercent) {
427 case dcc16Percent: return WRITE_REG(reg, ((READ_REG(reg) & ~MASK_BW_DCC_FREQ) | BW_DCC_16_PERCENT));
428 case dcc8Percent: return WRITE_REG(reg, ((READ_REG(reg) & ~MASK_BW_DCC_FREQ) | BW_DCC_8_PERCENT));
429 case dcc4Percent: return WRITE_REG(reg, ((READ_REG(reg) & ~MASK_BW_DCC_FREQ) | BW_DCC_4_PERCENT));
430 case dcc2Percent: return WRITE_REG(reg, ((READ_REG(reg) & ~MASK_BW_DCC_FREQ) | BW_DCC_2_PERCENT));
431 case dcc1Percent: return WRITE_REG(reg, ((READ_REG(reg) & ~MASK_BW_DCC_FREQ) | BW_DCC_1_PERCENT));
432 case dcc0_5Percent: return WRITE_REG(reg, ((READ_REG(reg) & ~MASK_BW_DCC_FREQ) | BW_DCC_0_5_PERCENT));
433 case dcc0_25Percent: return WRITE_REG(reg, ((READ_REG(reg) & ~MASK_BW_DCC_FREQ) | BW_DCC_0_25_PERCENT));
434 case dcc0_125Percent: return WRITE_REG(reg, ((READ_REG(reg) & ~MASK_BW_DCC_FREQ) | BW_DCC_0_125_PERCENT));
435 default:
436 dev_dbg(&spi->dev, "set: illegal input param");
437 return -EINVAL;
438 }
439}
440
441int rf69_set_dc_cut_off_frequency(struct spi_device *spi, enum dccPercent dccPercent)
442{
443 #ifdef DEBUG
444 dev_dbg(&spi->dev, "set: cut off freq");
445 #endif
446
447 return rf69_set_dc_cut_off_frequency_intern(spi, REG_RXBW, dccPercent);
448}
449
450int rf69_set_dc_cut_off_frequency_during_afc(struct spi_device *spi, enum dccPercent dccPercent)
451{
452 #ifdef DEBUG
453 dev_dbg(&spi->dev, "set: cut off freq during afc");
454 #endif
455
456 return rf69_set_dc_cut_off_frequency_intern(spi, REG_AFCBW, dccPercent);
457}
458
459static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg, 425static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,
460 enum mantisse mantisse, u8 exponent) 426 enum mantisse mantisse, u8 exponent)
461{ 427{
@@ -475,7 +441,7 @@ static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,
475 } 441 }
476 442
477 // read old value 443 // read old value
478 newValue = READ_REG(reg); 444 newValue = rf69_read_reg(spi, reg);
479 445
480 // "delete" mantisse and exponent = just keep the DCC setting 446 // "delete" mantisse and exponent = just keep the DCC setting
481 newValue = newValue & MASK_BW_DCC_FREQ; 447 newValue = newValue & MASK_BW_DCC_FREQ;
@@ -497,79 +463,38 @@ static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,
497 newValue = newValue | exponent; 463 newValue = newValue | exponent;
498 464
499 // write back 465 // write back
500 return WRITE_REG(reg, newValue); 466 return rf69_write_reg(spi, reg, newValue);
501} 467}
502 468
503int rf69_set_bandwidth(struct spi_device *spi, enum mantisse mantisse, u8 exponent) 469int rf69_set_bandwidth(struct spi_device *spi, enum mantisse mantisse, u8 exponent)
504{ 470{
505 #ifdef DEBUG
506 dev_dbg(&spi->dev, "set: band width");
507 #endif
508
509 return rf69_set_bandwidth_intern(spi, REG_RXBW, mantisse, exponent); 471 return rf69_set_bandwidth_intern(spi, REG_RXBW, mantisse, exponent);
510} 472}
511 473
512int rf69_set_bandwidth_during_afc(struct spi_device *spi, enum mantisse mantisse, u8 exponent) 474int rf69_set_bandwidth_during_afc(struct spi_device *spi, enum mantisse mantisse, u8 exponent)
513{ 475{
514 #ifdef DEBUG
515 dev_dbg(&spi->dev, "set: band width during afc");
516 #endif
517
518 return rf69_set_bandwidth_intern(spi, REG_AFCBW, mantisse, exponent); 476 return rf69_set_bandwidth_intern(spi, REG_AFCBW, mantisse, exponent);
519} 477}
520 478
521int rf69_set_ook_threshold_type(struct spi_device *spi, enum thresholdType thresholdType)
522{
523 #ifdef DEBUG
524 dev_dbg(&spi->dev, "set: threshold type");
525 #endif
526
527 switch (thresholdType) {
528 case fixed: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESTYPE) | OOKPEAK_THRESHTYPE_FIXED));
529 case peak: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESTYPE) | OOKPEAK_THRESHTYPE_PEAK));
530 case average: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESTYPE) | OOKPEAK_THRESHTYPE_AVERAGE));
531 default:
532 dev_dbg(&spi->dev, "set: illegal input param");
533 return -EINVAL;
534 }
535}
536
537int rf69_set_ook_threshold_step(struct spi_device *spi, enum thresholdStep thresholdStep)
538{
539 #ifdef DEBUG
540 dev_dbg(&spi->dev, "set: threshold step");
541 #endif
542
543 switch (thresholdStep) {
544 case step_0_5db: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESSTEP) | OOKPEAK_THRESHSTEP_0_5_DB));
545 case step_1_0db: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESSTEP) | OOKPEAK_THRESHSTEP_1_0_DB));
546 case step_1_5db: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESSTEP) | OOKPEAK_THRESHSTEP_1_5_DB));
547 case step_2_0db: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESSTEP) | OOKPEAK_THRESHSTEP_2_0_DB));
548 case step_3_0db: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESSTEP) | OOKPEAK_THRESHSTEP_3_0_DB));
549 case step_4_0db: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESSTEP) | OOKPEAK_THRESHSTEP_4_0_DB));
550 case step_5_0db: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESSTEP) | OOKPEAK_THRESHSTEP_5_0_DB));
551 case step_6_0db: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESSTEP) | OOKPEAK_THRESHSTEP_6_0_DB));
552 default:
553 dev_dbg(&spi->dev, "set: illegal input param");
554 return -EINVAL;
555 }
556}
557
558int rf69_set_ook_threshold_dec(struct spi_device *spi, enum thresholdDecrement thresholdDecrement) 479int rf69_set_ook_threshold_dec(struct spi_device *spi, enum thresholdDecrement thresholdDecrement)
559{ 480{
560 #ifdef DEBUG
561 dev_dbg(&spi->dev, "set: threshold decrement");
562 #endif
563
564 switch (thresholdDecrement) { 481 switch (thresholdDecrement) {
565 case dec_every8th: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESDEC) | OOKPEAK_THRESHDEC_EVERY_8TH)); 482 case dec_every8th:
566 case dec_every4th: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESDEC) | OOKPEAK_THRESHDEC_EVERY_4TH)); 483 return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, OOKPEAK_THRESHDEC_EVERY_8TH);
567 case dec_every2nd: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESDEC) | OOKPEAK_THRESHDEC_EVERY_2ND)); 484 case dec_every4th:
568 case dec_once: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESDEC) | OOKPEAK_THRESHDEC_ONCE)); 485 return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, OOKPEAK_THRESHDEC_EVERY_4TH);
569 case dec_twice: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESDEC) | OOKPEAK_THRESHDEC_TWICE)); 486 case dec_every2nd:
570 case dec_4times: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESDEC) | OOKPEAK_THRESHDEC_4_TIMES)); 487 return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, OOKPEAK_THRESHDEC_EVERY_2ND);
571 case dec_8times: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESDEC) | OOKPEAK_THRESHDEC_8_TIMES)); 488 case dec_once:
572 case dec_16times: return WRITE_REG(REG_OOKPEAK, ((READ_REG(REG_OOKPEAK) & ~MASK_OOKPEAK_THRESDEC) | OOKPEAK_THRESHDEC_16_TIMES)); 489 return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, OOKPEAK_THRESHDEC_ONCE);
490 case dec_twice:
491 return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, OOKPEAK_THRESHDEC_TWICE);
492 case dec_4times:
493 return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, OOKPEAK_THRESHDEC_4_TIMES);
494 case dec_8times:
495 return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, OOKPEAK_THRESHDEC_8_TIMES);
496 case dec_16times:
497 return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, OOKPEAK_THRESHDEC_16_TIMES);
573 default: 498 default:
574 dev_dbg(&spi->dev, "set: illegal input param"); 499 dev_dbg(&spi->dev, "set: illegal input param");
575 return -EINVAL; 500 return -EINVAL;
@@ -583,10 +508,6 @@ int rf69_set_dio_mapping(struct spi_device *spi, u8 DIONumber, u8 value)
583 u8 regaddr; 508 u8 regaddr;
584 u8 regValue; 509 u8 regValue;
585 510
586 #ifdef DEBUG
587 dev_dbg(&spi->dev, "set: DIO mapping");
588 #endif
589
590 switch (DIONumber) { 511 switch (DIONumber) {
591 case 0: 512 case 0:
592 mask = MASK_DIO0; shift = SHIFT_DIO0; regaddr = REG_DIOMAPPING1; 513 mask = MASK_DIO0; shift = SHIFT_DIO0; regaddr = REG_DIOMAPPING1;
@@ -607,95 +528,66 @@ int rf69_set_dio_mapping(struct spi_device *spi, u8 DIONumber, u8 value)
607 mask = MASK_DIO5; shift = SHIFT_DIO5; regaddr = REG_DIOMAPPING2; 528 mask = MASK_DIO5; shift = SHIFT_DIO5; regaddr = REG_DIOMAPPING2;
608 break; 529 break;
609 default: 530 default:
610 dev_dbg(&spi->dev, "set: illegal input param"); 531 dev_dbg(&spi->dev, "set: illegal input param");
611 return -EINVAL; 532 return -EINVAL;
612 } 533 }
613 534
614 // read reg 535 // read reg
615 regValue = READ_REG(regaddr); 536 regValue = rf69_read_reg(spi, regaddr);
616 // delete old value 537 // delete old value
617 regValue = regValue & ~mask; 538 regValue = regValue & ~mask;
618 // add new value 539 // add new value
619 regValue = regValue | value << shift; 540 regValue = regValue | value << shift;
620 // write back 541 // write back
621 return WRITE_REG(regaddr, regValue); 542 return rf69_write_reg(spi, regaddr, regValue);
622} 543}
623 544
624bool rf69_get_flag(struct spi_device *spi, enum flag flag) 545bool rf69_get_flag(struct spi_device *spi, enum flag flag)
625{ 546{
626 #ifdef DEBUG
627 dev_dbg(&spi->dev, "get: flag");
628 #endif
629
630 switch (flag) {
631 case modeSwitchCompleted: return (READ_REG(REG_IRQFLAGS1) & MASK_IRQFLAGS1_MODE_READY);
632 case readyToReceive: return (READ_REG(REG_IRQFLAGS1) & MASK_IRQFLAGS1_RX_READY);
633 case readyToSend: return (READ_REG(REG_IRQFLAGS1) & MASK_IRQFLAGS1_TX_READY);
634 case pllLocked: return (READ_REG(REG_IRQFLAGS1) & MASK_IRQFLAGS1_PLL_LOCK);
635 case rssiExceededThreshold: return (READ_REG(REG_IRQFLAGS1) & MASK_IRQFLAGS1_RSSI);
636 case timeout: return (READ_REG(REG_IRQFLAGS1) & MASK_IRQFLAGS1_TIMEOUT);
637 case automode: return (READ_REG(REG_IRQFLAGS1) & MASK_IRQFLAGS1_AUTOMODE);
638 case syncAddressMatch: return (READ_REG(REG_IRQFLAGS1) & MASK_IRQFLAGS1_SYNC_ADDRESS_MATCH);
639 case fifoFull: return (READ_REG(REG_IRQFLAGS2) & MASK_IRQFLAGS2_FIFO_FULL);
640/* case fifoNotEmpty: return (READ_REG(REG_IRQFLAGS2) & MASK_IRQFLAGS2_FIFO_NOT_EMPTY); */
641 case fifoEmpty: return !(READ_REG(REG_IRQFLAGS2) & MASK_IRQFLAGS2_FIFO_NOT_EMPTY);
642 case fifoLevelBelowThreshold: return (READ_REG(REG_IRQFLAGS2) & MASK_IRQFLAGS2_FIFO_LEVEL);
643 case fifoOverrun: return (READ_REG(REG_IRQFLAGS2) & MASK_IRQFLAGS2_FIFO_OVERRUN);
644 case packetSent: return (READ_REG(REG_IRQFLAGS2) & MASK_IRQFLAGS2_PACKET_SENT);
645 case payloadReady: return (READ_REG(REG_IRQFLAGS2) & MASK_IRQFLAGS2_PAYLOAD_READY);
646 case crcOk: return (READ_REG(REG_IRQFLAGS2) & MASK_IRQFLAGS2_CRC_OK);
647 case batteryLow: return (READ_REG(REG_IRQFLAGS2) & MASK_IRQFLAGS2_LOW_BAT);
648 default: return false;
649 }
650}
651
652int rf69_reset_flag(struct spi_device *spi, enum flag flag)
653{
654 #ifdef DEBUG
655 dev_dbg(&spi->dev, "reset: flag");
656 #endif
657
658 switch (flag) { 547 switch (flag) {
659 case rssiExceededThreshold: return WRITE_REG(REG_IRQFLAGS1, MASK_IRQFLAGS1_RSSI); 548 case modeSwitchCompleted:
660 case syncAddressMatch: return WRITE_REG(REG_IRQFLAGS1, MASK_IRQFLAGS1_SYNC_ADDRESS_MATCH); 549 return (rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_MODE_READY);
661 case fifoOverrun: return WRITE_REG(REG_IRQFLAGS2, MASK_IRQFLAGS2_FIFO_OVERRUN); 550 case readyToReceive:
662 default: 551 return (rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_RX_READY);
663 dev_dbg(&spi->dev, "set: illegal input param"); 552 case readyToSend:
664 return -EINVAL; 553 return (rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_TX_READY);
554 case pllLocked:
555 return (rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_PLL_LOCK);
556 case rssiExceededThreshold:
557 return (rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_RSSI);
558 case timeout:
559 return (rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_TIMEOUT);
560 case automode:
561 return (rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_AUTOMODE);
562 case syncAddressMatch:
563 return (rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_SYNC_ADDRESS_MATCH);
564 case fifo_full:
565 return (rf69_read_reg(spi, REG_IRQFLAGS2) & MASK_IRQFLAGS2_FIFO_FULL);
566/* case fifo_not_empty:
567 * return (rf69_read_reg(spi, REG_IRQFLAGS2) & MASK_IRQFLAGS2_FIFO_NOT_EMPTY); */
568 case fifo_empty:
569 return !(rf69_read_reg(spi, REG_IRQFLAGS2) & MASK_IRQFLAGS2_FIFO_NOT_EMPTY);
570 case fifo_level_below_threshold:
571 return (rf69_read_reg(spi, REG_IRQFLAGS2) & MASK_IRQFLAGS2_FIFO_LEVEL);
572 case fifo_overrun:
573 return (rf69_read_reg(spi, REG_IRQFLAGS2) & MASK_IRQFLAGS2_FIFO_OVERRUN);
574 case packetSent:
575 return (rf69_read_reg(spi, REG_IRQFLAGS2) & MASK_IRQFLAGS2_PACKET_SENT);
576 case payload_ready:
577 return (rf69_read_reg(spi, REG_IRQFLAGS2) & MASK_IRQFLAGS2_PAYLOAD_READY);
578 case crcOk:
579 return (rf69_read_reg(spi, REG_IRQFLAGS2) & MASK_IRQFLAGS2_CRC_OK);
580 case batteryLow:
581 return (rf69_read_reg(spi, REG_IRQFLAGS2) & MASK_IRQFLAGS2_LOW_BAT);
582 default: return false;
665 } 583 }
666} 584}
667 585
668int rf69_set_rssi_threshold(struct spi_device *spi, u8 threshold) 586int rf69_set_rssi_threshold(struct spi_device *spi, u8 threshold)
669{ 587{
670 #ifdef DEBUG
671 dev_dbg(&spi->dev, "set: rssi threshold");
672 #endif
673
674 /* no value check needed - u8 exactly matches register size */ 588 /* no value check needed - u8 exactly matches register size */
675 589
676 return WRITE_REG(REG_RSSITHRESH, threshold); 590 return rf69_write_reg(spi, REG_RSSITHRESH, threshold);
677}
678
679int rf69_set_rx_start_timeout(struct spi_device *spi, u8 timeout)
680{
681 #ifdef DEBUG
682 dev_dbg(&spi->dev, "set: start timeout");
683 #endif
684
685 /* no value check needed - u8 exactly matches register size */
686
687 return WRITE_REG(REG_RXTIMEOUT1, timeout);
688}
689
690int rf69_set_rssi_timeout(struct spi_device *spi, u8 timeout)
691{
692 #ifdef DEBUG
693 dev_dbg(&spi->dev, "set: rssi timeout");
694 #endif
695
696 /* no value check needed - u8 exactly matches register size */
697
698 return WRITE_REG(REG_RXTIMEOUT2, timeout);
699} 591}
700 592
701int rf69_set_preamble_length(struct spi_device *spi, u16 preambleLength) 593int rf69_set_preamble_length(struct spi_device *spi, u16 preambleLength)
@@ -703,47 +595,38 @@ int rf69_set_preamble_length(struct spi_device *spi, u16 preambleLength)
703 int retval; 595 int retval;
704 u8 msb, lsb; 596 u8 msb, lsb;
705 597
706 #ifdef DEBUG
707 dev_dbg(&spi->dev, "set: preamble length");
708 #endif
709
710 /* no value check needed - u16 exactly matches register size */ 598 /* no value check needed - u16 exactly matches register size */
711 599
712 /* calculate reg settings */ 600 /* calculate reg settings */
713 msb = (preambleLength&0xff00) >> 8; 601 msb = (preambleLength & 0xff00) >> 8;
714 lsb = (preambleLength&0xff); 602 lsb = (preambleLength & 0xff);
715 603
716 /* transmit to chip */ 604 /* transmit to chip */
717 retval = WRITE_REG(REG_PREAMBLE_MSB, msb); 605 retval = rf69_write_reg(spi, REG_PREAMBLE_MSB, msb);
718 if (retval) 606 if (retval)
719 return retval; 607 return retval;
720 return WRITE_REG(REG_PREAMBLE_LSB, lsb); 608 retval = rf69_write_reg(spi, REG_PREAMBLE_LSB, lsb);
609
610 return retval;
721} 611}
722 612
723int rf69_set_sync_enable(struct spi_device *spi, enum optionOnOff optionOnOff) 613int rf69_enable_sync(struct spi_device *spi)
724{ 614{
725 #ifdef DEBUG 615 return rf69_set_bit(spi, REG_SYNC_CONFIG, MASK_SYNC_CONFIG_SYNC_ON);
726 dev_dbg(&spi->dev, "set: sync enable");
727 #endif
728
729 switch (optionOnOff) {
730 case optionOn: return WRITE_REG(REG_SYNC_CONFIG, (READ_REG(REG_SYNC_CONFIG) | MASK_SYNC_CONFIG_SYNC_ON));
731 case optionOff: return WRITE_REG(REG_SYNC_CONFIG, (READ_REG(REG_SYNC_CONFIG) & ~MASK_SYNC_CONFIG_SYNC_ON));
732 default:
733 dev_dbg(&spi->dev, "set: illegal input param");
734 return -EINVAL;
735 }
736} 616}
737 617
738int rf69_set_fifo_fill_condition(struct spi_device *spi, enum fifoFillCondition fifoFillCondition) 618int rf69_disable_sync(struct spi_device *spi)
739{ 619{
740 #ifdef DEBUG 620 return rf69_clear_bit(spi, REG_SYNC_CONFIG, MASK_SYNC_CONFIG_SYNC_ON);
741 dev_dbg(&spi->dev, "set: fifo fill condition"); 621}
742 #endif
743 622
744 switch (fifoFillCondition) { 623int rf69_set_fifo_fill_condition(struct spi_device *spi, enum fifo_fill_condition fifo_fill_condition)
745 case always: return WRITE_REG(REG_SYNC_CONFIG, (READ_REG(REG_SYNC_CONFIG) | MASK_SYNC_CONFIG_FIFO_FILL_CONDITION)); 624{
746 case afterSyncInterrupt: return WRITE_REG(REG_SYNC_CONFIG, (READ_REG(REG_SYNC_CONFIG) & ~MASK_SYNC_CONFIG_FIFO_FILL_CONDITION)); 625 switch (fifo_fill_condition) {
626 case always:
627 return rf69_set_bit(spi, REG_SYNC_CONFIG, MASK_SYNC_CONFIG_FIFO_FILL_CONDITION);
628 case afterSyncInterrupt:
629 return rf69_clear_bit(spi, REG_SYNC_CONFIG, MASK_SYNC_CONFIG_FIFO_FILL_CONDITION);
747 default: 630 default:
748 dev_dbg(&spi->dev, "set: illegal input param"); 631 dev_dbg(&spi->dev, "set: illegal input param");
749 return -EINVAL; 632 return -EINVAL;
@@ -752,10 +635,6 @@ int rf69_set_fifo_fill_condition(struct spi_device *spi, enum fifoFillCondition
752 635
753int rf69_set_sync_size(struct spi_device *spi, u8 syncSize) 636int rf69_set_sync_size(struct spi_device *spi, u8 syncSize)
754{ 637{
755 #ifdef DEBUG
756 dev_dbg(&spi->dev, "set: sync size");
757 #endif
758
759 // check input value 638 // check input value
760 if (syncSize > 0x07) { 639 if (syncSize > 0x07) {
761 dev_dbg(&spi->dev, "set: illegal input param"); 640 dev_dbg(&spi->dev, "set: illegal input param");
@@ -763,136 +642,85 @@ int rf69_set_sync_size(struct spi_device *spi, u8 syncSize)
763 } 642 }
764 643
765 // write value 644 // write value
766 return WRITE_REG(REG_SYNC_CONFIG, (READ_REG(REG_SYNC_CONFIG) & ~MASK_SYNC_CONFIG_SYNC_SIZE) | (syncSize << 3)); 645 return rf69_read_mod_write(spi, REG_SYNC_CONFIG, MASK_SYNC_CONFIG_SYNC_SIZE, (syncSize << 3));
767}
768
769int rf69_set_sync_tolerance(struct spi_device *spi, u8 syncTolerance)
770{
771 #ifdef DEBUG
772 dev_dbg(&spi->dev, "set: sync tolerance");
773 #endif
774
775 // check input value
776 if (syncTolerance > 0x07) {
777 dev_dbg(&spi->dev, "set: illegal input param");
778 return -EINVAL;
779 }
780
781 // write value
782 return WRITE_REG(REG_SYNC_CONFIG, (READ_REG(REG_SYNC_CONFIG) & ~MASK_SYNC_CONFIG_SYNC_SIZE) | syncTolerance);
783} 646}
784 647
785int rf69_set_sync_values(struct spi_device *spi, u8 syncValues[8]) 648int rf69_set_sync_values(struct spi_device *spi, u8 syncValues[8])
786{ 649{
787 int retval = 0; 650 int retval = 0;
788 651
789 #ifdef DEBUG 652 retval += rf69_write_reg(spi, REG_SYNCVALUE1, syncValues[0]);
790 dev_dbg(&spi->dev, "set: sync values"); 653 retval += rf69_write_reg(spi, REG_SYNCVALUE2, syncValues[1]);
791 #endif 654 retval += rf69_write_reg(spi, REG_SYNCVALUE3, syncValues[2]);
792 655 retval += rf69_write_reg(spi, REG_SYNCVALUE4, syncValues[3]);
793 retval += WRITE_REG(REG_SYNCVALUE1, syncValues[0]); 656 retval += rf69_write_reg(spi, REG_SYNCVALUE5, syncValues[4]);
794 retval += WRITE_REG(REG_SYNCVALUE2, syncValues[1]); 657 retval += rf69_write_reg(spi, REG_SYNCVALUE6, syncValues[5]);
795 retval += WRITE_REG(REG_SYNCVALUE3, syncValues[2]); 658 retval += rf69_write_reg(spi, REG_SYNCVALUE7, syncValues[6]);
796 retval += WRITE_REG(REG_SYNCVALUE4, syncValues[3]); 659 retval += rf69_write_reg(spi, REG_SYNCVALUE8, syncValues[7]);
797 retval += WRITE_REG(REG_SYNCVALUE5, syncValues[4]);
798 retval += WRITE_REG(REG_SYNCVALUE6, syncValues[5]);
799 retval += WRITE_REG(REG_SYNCVALUE7, syncValues[6]);
800 retval += WRITE_REG(REG_SYNCVALUE8, syncValues[7]);
801 660
802 return retval; 661 return retval;
803} 662}
804 663
805int rf69_set_packet_format(struct spi_device *spi, enum packetFormat packetFormat) 664int rf69_set_packet_format(struct spi_device *spi, enum packetFormat packetFormat)
806{ 665{
807 #ifdef DEBUG
808 dev_dbg(&spi->dev, "set: packet format");
809 #endif
810
811 switch (packetFormat) { 666 switch (packetFormat) {
812 case packetLengthVar: return WRITE_REG(REG_PACKETCONFIG1, (READ_REG(REG_PACKETCONFIG1) | MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE)); 667 case packetLengthVar:
813 case packetLengthFix: return WRITE_REG(REG_PACKETCONFIG1, (READ_REG(REG_PACKETCONFIG1) & ~MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE)); 668 return rf69_set_bit(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE);
669 case packetLengthFix:
670 return rf69_clear_bit(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE);
814 default: 671 default:
815 dev_dbg(&spi->dev, "set: illegal input param"); 672 dev_dbg(&spi->dev, "set: illegal input param");
816 return -EINVAL; 673 return -EINVAL;
817 } 674 }
818} 675}
819 676
820int rf69_set_crc_enable(struct spi_device *spi, enum optionOnOff optionOnOff) 677int rf69_enable_crc(struct spi_device *spi)
821{ 678{
822 #ifdef DEBUG 679 return rf69_set_bit(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_CRC_ON);
823 dev_dbg(&spi->dev, "set: crc enable"); 680}
824 #endif
825 681
826 switch (optionOnOff) { 682int rf69_disable_crc(struct spi_device *spi)
827 case optionOn: return WRITE_REG(REG_PACKETCONFIG1, (READ_REG(REG_PACKETCONFIG1) | MASK_PACKETCONFIG1_CRC_ON)); 683{
828 case optionOff: return WRITE_REG(REG_PACKETCONFIG1, (READ_REG(REG_PACKETCONFIG1) & ~MASK_PACKETCONFIG1_CRC_ON)); 684 return rf69_clear_bit(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_CRC_ON);
829 default:
830 dev_dbg(&spi->dev, "set: illegal input param");
831 return -EINVAL;
832 }
833} 685}
834 686
835int rf69_set_adressFiltering(struct spi_device *spi, enum addressFiltering addressFiltering) 687int rf69_set_adressFiltering(struct spi_device *spi, enum addressFiltering addressFiltering)
836{ 688{
837 #ifdef DEBUG
838 dev_dbg(&spi->dev, "set: address filtering");
839 #endif
840
841 switch (addressFiltering) { 689 switch (addressFiltering) {
842 case filteringOff: return WRITE_REG(REG_PACKETCONFIG1, ((READ_REG(REG_PACKETCONFIG1) & ~MASK_PACKETCONFIG1_ADDRESSFILTERING) | PACKETCONFIG1_ADDRESSFILTERING_OFF)); 690 case filteringOff:
843 case nodeAddress: return WRITE_REG(REG_PACKETCONFIG1, ((READ_REG(REG_PACKETCONFIG1) & ~MASK_PACKETCONFIG1_ADDRESSFILTERING) | PACKETCONFIG1_ADDRESSFILTERING_NODE)); 691 return rf69_read_mod_write(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_ADDRESSFILTERING, PACKETCONFIG1_ADDRESSFILTERING_OFF);
844 case nodeOrBroadcastAddress: return WRITE_REG(REG_PACKETCONFIG1, ((READ_REG(REG_PACKETCONFIG1) & ~MASK_PACKETCONFIG1_ADDRESSFILTERING) | PACKETCONFIG1_ADDRESSFILTERING_NODEBROADCAST)); 692 case nodeAddress:
693 return rf69_read_mod_write(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_ADDRESSFILTERING, PACKETCONFIG1_ADDRESSFILTERING_NODE);
694 case nodeOrBroadcastAddress:
695 return rf69_read_mod_write(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_ADDRESSFILTERING, PACKETCONFIG1_ADDRESSFILTERING_NODEBROADCAST);
845 default: 696 default:
846 dev_dbg(&spi->dev, "set: illegal input param"); 697 dev_dbg(&spi->dev, "set: illegal input param");
847 return -EINVAL; 698 return -EINVAL;
848 } 699 }
849} 700}
850 701
851int rf69_set_payload_length(struct spi_device *spi, u8 payloadLength) 702int rf69_set_payload_length(struct spi_device *spi, u8 payload_length)
852{ 703{
853 #ifdef DEBUG 704 return rf69_write_reg(spi, REG_PAYLOAD_LENGTH, payload_length);
854 dev_dbg(&spi->dev, "set: payload length");
855 #endif
856
857 return WRITE_REG(REG_PAYLOAD_LENGTH, payloadLength);
858}
859
860u8 rf69_get_payload_length(struct spi_device *spi)
861{
862 #ifdef DEBUG
863 dev_dbg(&spi->dev, "get: payload length");
864 #endif
865
866 return (u8) READ_REG(REG_PAYLOAD_LENGTH);
867} 705}
868 706
869int rf69_set_node_address(struct spi_device *spi, u8 nodeAddress) 707int rf69_set_node_address(struct spi_device *spi, u8 nodeAddress)
870{ 708{
871 #ifdef DEBUG 709 return rf69_write_reg(spi, REG_NODEADRS, nodeAddress);
872 dev_dbg(&spi->dev, "set: node address");
873 #endif
874
875 return WRITE_REG(REG_NODEADRS, nodeAddress);
876} 710}
877 711
878int rf69_set_broadcast_address(struct spi_device *spi, u8 broadcastAddress) 712int rf69_set_broadcast_address(struct spi_device *spi, u8 broadcastAddress)
879{ 713{
880 #ifdef DEBUG 714 return rf69_write_reg(spi, REG_BROADCASTADRS, broadcastAddress);
881 dev_dbg(&spi->dev, "set: broadcast address");
882 #endif
883
884 return WRITE_REG(REG_BROADCASTADRS, broadcastAddress);
885} 715}
886 716
887int rf69_set_tx_start_condition(struct spi_device *spi, enum txStartCondition txStartCondition) 717int rf69_set_tx_start_condition(struct spi_device *spi, enum txStartCondition txStartCondition)
888{ 718{
889 #ifdef DEBUG
890 dev_dbg(&spi->dev, "set: start condition");
891 #endif
892
893 switch (txStartCondition) { 719 switch (txStartCondition) {
894 case fifoLevel: return WRITE_REG(REG_FIFO_THRESH, (READ_REG(REG_FIFO_THRESH) & ~MASK_FIFO_THRESH_TXSTART)); 720 case fifo_level:
895 case fifoNotEmpty: return WRITE_REG(REG_FIFO_THRESH, (READ_REG(REG_FIFO_THRESH) | MASK_FIFO_THRESH_TXSTART)); 721 return rf69_clear_bit(spi, REG_FIFO_THRESH, MASK_FIFO_THRESH_TXSTART);
722 case fifo_not_empty:
723 return rf69_set_bit(spi, REG_FIFO_THRESH, MASK_FIFO_THRESH_TXSTART);
896 default: 724 default:
897 dev_dbg(&spi->dev, "set: illegal input param"); 725 dev_dbg(&spi->dev, "set: illegal input param");
898 return -EINVAL; 726 return -EINVAL;
@@ -903,35 +731,32 @@ int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold)
903{ 731{
904 int retval; 732 int retval;
905 733
906 #ifdef DEBUG 734 /* check input value */
907 dev_dbg(&spi->dev, "set: fifo threshold");
908 #endif
909
910 // check input value
911 if (threshold & 0x80) { 735 if (threshold & 0x80) {
912 dev_dbg(&spi->dev, "set: illegal input param"); 736 dev_dbg(&spi->dev, "set: illegal input param");
913 return -EINVAL; 737 return -EINVAL;
914 } 738 }
915 739
916 // write value 740 /* write value */
917 retval = WRITE_REG(REG_FIFO_THRESH, (READ_REG(REG_FIFO_THRESH) & ~MASK_FIFO_THRESH_VALUE) | threshold); 741 retval = rf69_read_mod_write(spi, REG_FIFO_THRESH, MASK_FIFO_THRESH_VALUE, threshold);
918 if (retval) 742 if (retval)
919 return retval; 743 return retval;
920 744
921 // access the fifo to activate new threshold 745 /* access the fifo to activate new threshold
922 return rf69_read_fifo(spi, (u8 *)&retval, 1); // retval used as buffer 746 * retval (mis-) used as buffer here
747 */
748 return rf69_read_fifo(spi, (u8 *)&retval, 1);
923} 749}
924 750
925int rf69_set_dagc(struct spi_device *spi, enum dagc dagc) 751int rf69_set_dagc(struct spi_device *spi, enum dagc dagc)
926{ 752{
927 #ifdef DEBUG
928 dev_dbg(&spi->dev, "set: dagc");
929 #endif
930
931 switch (dagc) { 753 switch (dagc) {
932 case normalMode: return WRITE_REG(REG_TESTDAGC, DAGC_NORMAL); 754 case normalMode:
933 case improve: return WRITE_REG(REG_TESTDAGC, DAGC_IMPROVED_LOWBETA0); 755 return rf69_write_reg(spi, REG_TESTDAGC, DAGC_NORMAL);
934 case improve4LowModulationIndex: return WRITE_REG(REG_TESTDAGC, DAGC_IMPROVED_LOWBETA1); 756 case improve:
757 return rf69_write_reg(spi, REG_TESTDAGC, DAGC_IMPROVED_LOWBETA0);
758 case improve4LowModulationIndex:
759 return rf69_write_reg(spi, REG_TESTDAGC, DAGC_IMPROVED_LOWBETA1);
935 default: 760 default:
936 dev_dbg(&spi->dev, "set: illegal input param"); 761 dev_dbg(&spi->dev, "set: illegal input param");
937 return -EINVAL; 762 return -EINVAL;
@@ -940,19 +765,17 @@ int rf69_set_dagc(struct spi_device *spi, enum dagc dagc)
940 765
941/*-------------------------------------------------------------------------*/ 766/*-------------------------------------------------------------------------*/
942 767
943int rf69_read_fifo (struct spi_device *spi, u8 *buffer, unsigned int size) 768int rf69_read_fifo(struct spi_device *spi, u8 *buffer, unsigned int size)
944{ 769{
945 #ifdef DEBUG_FIFO_ACCESS 770#ifdef DEBUG_FIFO_ACCESS
946 int i; 771 int i;
947 #endif 772#endif
948 struct spi_transfer transfer; 773 struct spi_transfer transfer;
949 u8 local_buffer[FIFO_SIZE + 1]; 774 u8 local_buffer[FIFO_SIZE + 1];
950 int retval; 775 int retval;
951 776
952 if (size > FIFO_SIZE) { 777 if (size > FIFO_SIZE) {
953 #ifdef DEBUG 778 dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer\n");
954 dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer \n");
955 #endif
956 return -EMSGSIZE; 779 return -EMSGSIZE;
957 } 780 }
958 781
@@ -961,97 +784,41 @@ int rf69_read_fifo (struct spi_device *spi, u8 *buffer, unsigned int size)
961 memset(&transfer, 0, sizeof(transfer)); 784 memset(&transfer, 0, sizeof(transfer));
962 transfer.tx_buf = local_buffer; 785 transfer.tx_buf = local_buffer;
963 transfer.rx_buf = local_buffer; 786 transfer.rx_buf = local_buffer;
964 transfer.len = size+1; 787 transfer.len = size + 1;
965 788
966 retval = spi_sync_transfer(spi, &transfer, 1); 789 retval = spi_sync_transfer(spi, &transfer, 1);
967 790
968 #ifdef DEBUG_FIFO_ACCESS 791#ifdef DEBUG_FIFO_ACCESS
969 for (i = 0; i < size; i++) 792 for (i = 0; i < size; i++)
970 dev_dbg(&spi->dev, "%d - 0x%x\n", i, local_buffer[i+1]); 793 dev_dbg(&spi->dev, "%d - 0x%x\n", i, local_buffer[i + 1]);
971 #endif 794#endif
972 795
973 memcpy(buffer, &local_buffer[1], size); // TODO: ohne memcopy wäre schöner 796 memcpy(buffer, &local_buffer[1], size);
974 797
975 return retval; 798 return retval;
976} 799}
977 800
978int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size) 801int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size)
979{ 802{
980 #ifdef DEBUG_FIFO_ACCESS 803#ifdef DEBUG_FIFO_ACCESS
981 int i; 804 int i;
982 #endif 805#endif
983 char spi_address = REG_FIFO | WRITE_BIT; 806 char spi_address = REG_FIFO | WRITE_BIT;
984 u8 local_buffer[FIFO_SIZE + 1]; 807 u8 local_buffer[FIFO_SIZE + 1];
985 808
986 if (size > FIFO_SIZE) { 809 if (size > FIFO_SIZE) {
987 #ifdef DEBUG 810 dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer\n");
988 dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer \n");
989 #endif
990 return -EMSGSIZE; 811 return -EMSGSIZE;
991 } 812 }
992 813
993 local_buffer[0] = spi_address; 814 local_buffer[0] = spi_address;
994 memcpy(&local_buffer[1], buffer, size); // TODO: ohne memcopy wäre schöner 815 memcpy(&local_buffer[1], buffer, size);
995 816
996 #ifdef DEBUG_FIFO_ACCESS 817#ifdef DEBUG_FIFO_ACCESS
997 for (i = 0; i < size; i++) 818 for (i = 0; i < size; i++)
998 dev_dbg(&spi->dev, "0x%x\n", buffer[i]); 819 dev_dbg(&spi->dev, "0x%x\n", buffer[i]);
999 #endif 820#endif
1000 821
1001 return spi_write (spi, local_buffer, size + 1); 822 return spi_write(spi, local_buffer, size + 1);
1002} 823}
1003 824
1004/*-------------------------------------------------------------------------*/
1005
1006u8 rf69_read_reg(struct spi_device *spi, u8 addr)
1007{
1008 int retval;
1009
1010 retval = spi_w8r8(spi, addr);
1011
1012 #ifdef DEBUG_VALUES
1013 if (retval < 0)
1014 /* should never happen, since we already checked,
1015 * that module is connected. Therefore no error
1016 * handling, just an optional error message...
1017 */
1018 dev_dbg(&spi->dev, "read 0x%x FAILED\n",
1019 addr);
1020 else
1021 dev_dbg(&spi->dev, "read 0x%x from reg 0x%x\n",
1022 retval,
1023 addr);
1024 #endif
1025
1026 return retval;
1027}
1028
1029int rf69_write_reg(struct spi_device *spi, u8 addr, u8 value)
1030{
1031 int retval;
1032 char buffer[2];
1033
1034 buffer[0] = addr | WRITE_BIT;
1035 buffer[1] = value;
1036
1037 retval = spi_write(spi, &buffer, 2);
1038
1039 #ifdef DEBUG_VALUES
1040 if (retval < 0)
1041 /* should never happen, since we already checked,
1042 * that module is connected. Therefore no error
1043 * handling, just an optional error message...
1044 */
1045 dev_dbg(&spi->dev, "write 0x%x to 0x%x FAILED\n",
1046 value,
1047 addr);
1048 else
1049 dev_dbg(&spi->dev, "wrote 0x%x to reg 0x%x\n",
1050 value,
1051 addr);
1052 #endif
1053
1054 return retval;
1055}
1056
1057
diff --git a/drivers/staging/pi433/rf69.h b/drivers/staging/pi433/rf69.h
index 5c0c95628f2f..09d221b8b6df 100644
--- a/drivers/staging/pi433/rf69.h
+++ b/drivers/staging/pi433/rf69.h
@@ -26,57 +26,42 @@
26#define FIFO_THRESHOLD 15 /* in byte */ 26#define FIFO_THRESHOLD 15 /* in byte */
27 27
28int rf69_set_mode(struct spi_device *spi, enum mode mode); 28int rf69_set_mode(struct spi_device *spi, enum mode mode);
29int rf69_set_data_mode(struct spi_device *spi, enum dataMode dataMode); 29int rf69_set_data_mode(struct spi_device *spi, u8 data_mode);
30int rf69_set_modulation(struct spi_device *spi, enum modulation modulation); 30int rf69_set_modulation(struct spi_device *spi, enum modulation modulation);
31enum modulation rf69_get_modulation(struct spi_device *spi); 31int rf69_set_modulation_shaping(struct spi_device *spi, enum mod_shaping mod_shaping);
32int rf69_set_modulation_shaping(struct spi_device *spi, enum modShaping modShaping);
33int rf69_set_bit_rate(struct spi_device *spi, u16 bitRate); 32int rf69_set_bit_rate(struct spi_device *spi, u16 bitRate);
34int rf69_set_deviation(struct spi_device *spi, u32 deviation); 33int rf69_set_deviation(struct spi_device *spi, u32 deviation);
35int rf69_set_frequency(struct spi_device *spi, u32 frequency); 34int rf69_set_frequency(struct spi_device *spi, u32 frequency);
36int rf69_set_amplifier_0(struct spi_device *spi, enum optionOnOff optionOnOff); 35int rf69_enable_amplifier(struct spi_device *spi, u8 amplifier_mask);
37int rf69_set_amplifier_1(struct spi_device *spi, enum optionOnOff optionOnOff); 36int rf69_disable_amplifier(struct spi_device *spi, u8 amplifier_mask);
38int rf69_set_amplifier_2(struct spi_device *spi, enum optionOnOff optionOnOff);
39int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel); 37int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel);
40int rf69_set_pa_ramp(struct spi_device *spi, enum paRamp paRamp); 38int rf69_set_pa_ramp(struct spi_device *spi, enum paRamp paRamp);
41int rf69_set_antenna_impedance(struct spi_device *spi, enum antennaImpedance antennaImpedance); 39int rf69_set_antenna_impedance(struct spi_device *spi, enum antennaImpedance antennaImpedance);
42int rf69_set_lna_gain(struct spi_device *spi, enum lnaGain lnaGain); 40int rf69_set_lna_gain(struct spi_device *spi, enum lnaGain lnaGain);
43enum lnaGain rf69_get_lna_gain(struct spi_device *spi);
44int rf69_set_dc_cut_off_frequency_intern(struct spi_device *spi, u8 reg, enum dccPercent dccPercent);
45int rf69_set_dc_cut_off_frequency(struct spi_device *spi, enum dccPercent dccPercent);
46int rf69_set_dc_cut_off_frequency_during_afc(struct spi_device *spi, enum dccPercent dccPercent);
47int rf69_set_bandwidth(struct spi_device *spi, enum mantisse mantisse, u8 exponent); 41int rf69_set_bandwidth(struct spi_device *spi, enum mantisse mantisse, u8 exponent);
48int rf69_set_bandwidth_during_afc(struct spi_device *spi, enum mantisse mantisse, u8 exponent); 42int rf69_set_bandwidth_during_afc(struct spi_device *spi, enum mantisse mantisse, u8 exponent);
49int rf69_set_ook_threshold_type(struct spi_device *spi, enum thresholdType thresholdType);
50int rf69_set_ook_threshold_step(struct spi_device *spi, enum thresholdStep thresholdStep);
51int rf69_set_ook_threshold_dec(struct spi_device *spi, enum thresholdDecrement thresholdDecrement); 43int rf69_set_ook_threshold_dec(struct spi_device *spi, enum thresholdDecrement thresholdDecrement);
52int rf69_set_dio_mapping(struct spi_device *spi, u8 DIONumber, u8 value); 44int rf69_set_dio_mapping(struct spi_device *spi, u8 DIONumber, u8 value);
53bool rf69_get_flag(struct spi_device *spi, enum flag flag); 45bool rf69_get_flag(struct spi_device *spi, enum flag flag);
54int rf69_reset_flag(struct spi_device *spi, enum flag flag);
55int rf69_set_rssi_threshold(struct spi_device *spi, u8 threshold); 46int rf69_set_rssi_threshold(struct spi_device *spi, u8 threshold);
56int rf69_set_rx_start_timeout(struct spi_device *spi, u8 timeout);
57int rf69_set_rssi_timeout(struct spi_device *spi, u8 timeout);
58int rf69_set_preamble_length(struct spi_device *spi, u16 preambleLength); 47int rf69_set_preamble_length(struct spi_device *spi, u16 preambleLength);
59int rf69_set_sync_enable(struct spi_device *spi, enum optionOnOff optionOnOff); 48int rf69_enable_sync(struct spi_device *spi);
60int rf69_set_fifo_fill_condition(struct spi_device *spi, enum fifoFillCondition fifoFillCondition); 49int rf69_disable_sync(struct spi_device *spi);
50int rf69_set_fifo_fill_condition(struct spi_device *spi, enum fifo_fill_condition fifo_fill_condition);
61int rf69_set_sync_size(struct spi_device *spi, u8 sync_size); 51int rf69_set_sync_size(struct spi_device *spi, u8 sync_size);
62int rf69_set_sync_tolerance(struct spi_device *spi, u8 syncTolerance);
63int rf69_set_sync_values(struct spi_device *spi, u8 syncValues[8]); 52int rf69_set_sync_values(struct spi_device *spi, u8 syncValues[8]);
64int rf69_set_packet_format(struct spi_device *spi, enum packetFormat packetFormat); 53int rf69_set_packet_format(struct spi_device *spi, enum packetFormat packetFormat);
65int rf69_set_crc_enable(struct spi_device *spi, enum optionOnOff optionOnOff); 54int rf69_enable_crc(struct spi_device *spi);
55int rf69_disable_crc(struct spi_device *spi);
66int rf69_set_adressFiltering(struct spi_device *spi, enum addressFiltering addressFiltering); 56int rf69_set_adressFiltering(struct spi_device *spi, enum addressFiltering addressFiltering);
67int rf69_set_payload_length(struct spi_device *spi, u8 payloadLength); 57int rf69_set_payload_length(struct spi_device *spi, u8 payload_length);
68u8 rf69_get_payload_length(struct spi_device *spi);
69int rf69_set_node_address(struct spi_device *spi, u8 nodeAddress); 58int rf69_set_node_address(struct spi_device *spi, u8 nodeAddress);
70int rf69_set_broadcast_address(struct spi_device *spi, u8 broadcastAddress); 59int rf69_set_broadcast_address(struct spi_device *spi, u8 broadcastAddress);
71int rf69_set_tx_start_condition(struct spi_device *spi, enum txStartCondition txStartCondition); 60int rf69_set_tx_start_condition(struct spi_device *spi, enum txStartCondition txStartCondition);
72int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold); 61int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold);
73int rf69_set_dagc(struct spi_device *spi, enum dagc dagc); 62int rf69_set_dagc(struct spi_device *spi, enum dagc dagc);
74 63
75int rf69_read_fifo (struct spi_device *spi, u8 *buffer, unsigned int size); 64int rf69_read_fifo(struct spi_device *spi, u8 *buffer, unsigned int size);
76int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size); 65int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size);
77 66
78u8 rf69_read_reg (struct spi_device *spi, u8 addr);
79int rf69_write_reg(struct spi_device *spi, u8 addr, u8 value);
80
81
82#endif 67#endif
diff --git a/drivers/staging/pi433/rf69_enum.h b/drivers/staging/pi433/rf69_enum.h
index fbfb59bd3f3d..03440cfa957c 100644
--- a/drivers/staging/pi433/rf69_enum.h
+++ b/drivers/staging/pi433/rf69_enum.h
@@ -18,184 +18,126 @@
18#ifndef RF69_ENUM_H 18#ifndef RF69_ENUM_H
19#define RF69_ENUM_H 19#define RF69_ENUM_H
20 20
21enum optionOnOff 21enum mode {
22{ 22 mode_sleep,
23 optionOff, 23 standby,
24 optionOn 24 synthesizer,
25 transmit,
26 receive
27};
28
29enum modulation {
30 OOK,
31 FSK,
32 UNDEF
33};
34
35enum mod_shaping {
36 SHAPING_OFF,
37 SHAPING_1_0,
38 SHAPING_0_5,
39 SHAPING_0_3,
40 SHAPING_BR,
41 SHAPING_2BR
42};
43
44enum paRamp {
45 ramp3400,
46 ramp2000,
47 ramp1000,
48 ramp500,
49 ramp250,
50 ramp125,
51 ramp100,
52 ramp62,
53 ramp50,
54 ramp40,
55 ramp31,
56 ramp25,
57 ramp20,
58 ramp15,
59 ramp12,
60 ramp10
61};
62
63enum antennaImpedance {
64 fiftyOhm,
65 twohundretOhm
66};
67
68enum lnaGain {
69 automatic,
70 max,
71 max_minus_6,
72 max_minus_12,
73 max_minus_24,
74 max_minus_36,
75 max_minus_48,
76 undefined
77};
78
79enum mantisse {
80 mantisse16,
81 mantisse20,
82 mantisse24
83};
84
85enum thresholdDecrement {
86 dec_every8th,
87 dec_every4th,
88 dec_every2nd,
89 dec_once,
90 dec_twice,
91 dec_4times,
92 dec_8times,
93 dec_16times
94};
95
96enum flag {
97 modeSwitchCompleted,
98 readyToReceive,
99 readyToSend,
100 pllLocked,
101 rssiExceededThreshold,
102 timeout,
103 automode,
104 syncAddressMatch,
105 fifo_full,
106// fifo_not_empty, collision with next enum; replaced by following enum...
107 fifo_empty,
108 fifo_level_below_threshold,
109 fifo_overrun,
110 packetSent,
111 payload_ready,
112 crcOk,
113 batteryLow
114};
115
116enum fifo_fill_condition {
117 afterSyncInterrupt,
118 always
119};
120
121enum packetFormat {
122 packetLengthFix,
123 packetLengthVar
124};
125
126enum txStartCondition {
127 fifo_level,
128 fifo_not_empty
129};
130
131enum addressFiltering {
132 filteringOff,
133 nodeAddress,
134 nodeOrBroadcastAddress
135};
136
137enum dagc {
138 normalMode,
139 improve,
140 improve4LowModulationIndex
25}; 141};
26 142
27enum mode
28{
29 mode_sleep,
30 standby,
31 synthesizer,
32 transmit,
33 receive
34};
35
36enum dataMode
37{
38 packet,
39 continuous,
40 continuousNoSync
41};
42
43enum modulation
44{
45 OOK,
46 FSK
47};
48
49enum modShaping
50{
51 shapingOff,
52 shaping1_0,
53 shaping0_5,
54 shaping0_3,
55 shapingBR,
56 shaping2BR
57};
58
59enum paRamp
60{
61 ramp3400,
62 ramp2000,
63 ramp1000,
64 ramp500,
65 ramp250,
66 ramp125,
67 ramp100,
68 ramp62,
69 ramp50,
70 ramp40,
71 ramp31,
72 ramp25,
73 ramp20,
74 ramp15,
75 ramp12,
76 ramp10
77};
78
79enum antennaImpedance
80{
81 fiftyOhm,
82 twohundretOhm
83};
84
85enum lnaGain
86{
87 automatic,
88 max,
89 maxMinus6,
90 maxMinus12,
91 maxMinus24,
92 maxMinus36,
93 maxMinus48,
94 undefined
95};
96
97enum dccPercent
98{
99 dcc16Percent,
100 dcc8Percent,
101 dcc4Percent,
102 dcc2Percent,
103 dcc1Percent,
104 dcc0_5Percent,
105 dcc0_25Percent,
106 dcc0_125Percent
107};
108
109enum mantisse
110{
111 mantisse16,
112 mantisse20,
113 mantisse24
114};
115
116enum thresholdType
117{
118 fixed,
119 peak,
120 average
121};
122
123enum thresholdStep
124{
125 step_0_5db,
126 step_1_0db,
127 step_1_5db,
128 step_2_0db,
129 step_3_0db,
130 step_4_0db,
131 step_5_0db,
132 step_6_0db
133};
134
135enum thresholdDecrement
136{
137 dec_every8th,
138 dec_every4th,
139 dec_every2nd,
140 dec_once,
141 dec_twice,
142 dec_4times,
143 dec_8times,
144 dec_16times
145};
146
147enum flag
148{
149 modeSwitchCompleted,
150 readyToReceive,
151 readyToSend,
152 pllLocked,
153 rssiExceededThreshold,
154 timeout,
155 automode,
156 syncAddressMatch,
157 fifoFull,
158// fifoNotEmpty, collision with next enum; replaced by following enum...
159 fifoEmpty,
160 fifoLevelBelowThreshold,
161 fifoOverrun,
162 packetSent,
163 payloadReady,
164 crcOk,
165 batteryLow
166};
167
168enum fifoFillCondition
169{
170 afterSyncInterrupt,
171 always
172};
173
174enum packetFormat
175{
176 packetLengthFix,
177 packetLengthVar
178};
179
180enum txStartCondition
181{
182 fifoLevel,
183 fifoNotEmpty
184};
185
186enum addressFiltering
187{
188 filteringOff,
189 nodeAddress,
190 nodeOrBroadcastAddress
191};
192
193enum dagc
194{
195 normalMode,
196 improve,
197 improve4LowModulationIndex
198};
199
200
201#endif 143#endif
diff --git a/drivers/staging/pi433/rf69_registers.h b/drivers/staging/pi433/rf69_registers.h
index 6335d42142fe..33fd91518bb0 100644
--- a/drivers/staging/pi433/rf69_registers.h
+++ b/drivers/staging/pi433/rf69_registers.h
@@ -188,8 +188,6 @@
188#define MASK_PALEVEL_PA2 0x20 188#define MASK_PALEVEL_PA2 0x20
189#define MASK_PALEVEL_OUTPUT_POWER 0x1F 189#define MASK_PALEVEL_OUTPUT_POWER 0x1F
190 190
191
192
193// RegPaRamp 191// RegPaRamp
194#define PARAMP_3400 0x00 192#define PARAMP_3400 0x00
195#define PARAMP_2000 0x01 193#define PARAMP_2000 0x01
@@ -246,7 +244,6 @@
246#define LNA_GAIN_MAX_MINUS_36 0x05 244#define LNA_GAIN_MAX_MINUS_36 0x05
247#define LNA_GAIN_MAX_MINUS_48 0x06 245#define LNA_GAIN_MAX_MINUS_48 0x06
248 246
249
250/* RegRxBw (0x19) and RegAfcBw (0x1A) */ 247/* RegRxBw (0x19) and RegAfcBw (0x1A) */
251#define MASK_BW_DCC_FREQ 0xE0 248#define MASK_BW_DCC_FREQ 0xE0
252#define MASK_BW_MANTISSE 0x18 249#define MASK_BW_MANTISSE 0x18
@@ -265,7 +262,6 @@
265#define BW_MANT_20 0x08 262#define BW_MANT_20 0x08
266#define BW_MANT_24 0x10 /* default */ 263#define BW_MANT_24 0x10 /* default */
267 264
268
269/* RegOokPeak (0x1B) */ 265/* RegOokPeak (0x1B) */
270#define MASK_OOKPEAK_THRESTYPE 0xc0 266#define MASK_OOKPEAK_THRESTYPE 0xc0
271#define MASK_OOKPEAK_THRESSTEP 0x38 267#define MASK_OOKPEAK_THRESSTEP 0x38
@@ -346,28 +342,28 @@
346#define DIO5 5 342#define DIO5 5
347 343
348/* DIO Mapping values (packet mode) */ 344/* DIO Mapping values (packet mode) */
349#define DIO_ModeReady_DIO4 0x00 345#define DIO_MODE_READY_DIO4 0x00
350#define DIO_ModeReady_DIO5 0x03 346#define DIO_MODE_READY_DIO5 0x03
351#define DIO_ClkOut 0x00 347#define DIO_CLK_OUT 0x00
352#define DIO_Data 0x01 348#define DIO_DATA 0x01
353#define DIO_TimeOut_DIO1 0x03 349#define DIO_TIMEOUT_DIO1 0x03
354#define DIO_TimeOut_DIO4 0x00 350#define DIO_TIMEOUT_DIO4 0x00
355#define DIO_Rssi_DIO0 0x03 351#define DIO_RSSI_DIO0 0x03
356#define DIO_Rssi_DIO3_4 0x01 352#define DIO_RSSI_DIO3_4 0x01
357#define DIO_RxReady 0x02 353#define DIO_RX_READY 0x02
358#define DIO_PLLLock 0x03 354#define DIO_PLL_LOCK 0x03
359#define DIO_TxReady 0x01 355#define DIO_TX_READY 0x01
360#define DIO_FifoFull_DIO1 0x01 356#define DIO_FIFO_FULL_DIO1 0x01
361#define DIO_FifoFull_DIO3 0x00 357#define DIO_FIFO_FULL_DIO3 0x00
362#define DIO_SyncAddress 0x02 358#define DIO_SYNC_ADDRESS 0x02
363#define DIO_FifoNotEmpty_DIO1 0x02 359#define DIO_FIFO_NOT_EMPTY_DIO1 0x02
364#define DIO_FifoNotEmpty_FIO2 0x00 360#define DIO_FIFO_NOT_EMPTY_FIO2 0x00
365#define DIO_Automode 0x04 361#define DIO_AUTOMODE 0x04
366#define DIO_FifoLevel 0x00 362#define DIO_FIFO_LEVEL 0x00
367#define DIO_CrcOk 0x00 363#define DIO_CRC_OK 0x00
368#define DIO_PayloadReady 0x01 364#define DIO_PAYLOAD_READY 0x01
369#define DIO_PacketSent 0x00 365#define DIO_PACKET_SENT 0x00
370#define DIO_Dclk 0x00 366#define DIO_DCLK 0x00
371 367
372/* RegDioMapping2 CLK_OUT part */ 368/* RegDioMapping2 CLK_OUT part */
373#define MASK_DIOMAPPING2_CLK_OUT 0x07 369#define MASK_DIOMAPPING2_CLK_OUT 0x07
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index d73e9bdc80cc..bcb6919bb7d5 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -5395,14 +5395,14 @@ u8 set_tx_beacon_cmd(struct adapter *padapter)
5395 int len_diff = 0; 5395 int len_diff = 0;
5396 5396
5397 5397
5398 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 5398 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
5399 if (!ph2c) { 5399 if (!ph2c) {
5400 res = _FAIL; 5400 res = _FAIL;
5401 goto exit; 5401 goto exit;
5402 } 5402 }
5403 5403
5404 ptxBeacon_parm = kmemdup(&(pmlmeinfo->network), 5404 ptxBeacon_parm = kmemdup(&(pmlmeinfo->network),
5405 sizeof(struct wlan_bssid_ex), GFP_KERNEL); 5405 sizeof(struct wlan_bssid_ex), GFP_ATOMIC);
5406 if (ptxBeacon_parm == NULL) { 5406 if (ptxBeacon_parm == NULL) {
5407 kfree(ph2c); 5407 kfree(ph2c);
5408 res = _FAIL; 5408 res = _FAIL;
diff --git a/drivers/staging/rtl8188eu/hal/pwrseqcmd.c b/drivers/staging/rtl8188eu/hal/pwrseqcmd.c
index 2867864bbfbe..e6867eea3530 100644
--- a/drivers/staging/rtl8188eu/hal/pwrseqcmd.c
+++ b/drivers/staging/rtl8188eu/hal/pwrseqcmd.c
@@ -22,7 +22,7 @@
22u8 rtl88eu_pwrseqcmdparsing(struct adapter *padapter, u8 cut_vers, 22u8 rtl88eu_pwrseqcmdparsing(struct adapter *padapter, u8 cut_vers,
23 struct wl_pwr_cfg pwrseqcmd[]) 23 struct wl_pwr_cfg pwrseqcmd[])
24{ 24{
25 struct wl_pwr_cfg pwrcfgcmd = {0}; 25 struct wl_pwr_cfg pwrcfgcmd;
26 u8 poll_bit = false; 26 u8 poll_bit = false;
27 u32 aryidx = 0; 27 u32 aryidx = 0;
28 u8 value = 0; 28 u8 value = 0;
diff --git a/drivers/staging/rtl8192e/rtllib_rx.c b/drivers/staging/rtl8192e/rtllib_rx.c
index 7bc9cb131bcc..30f72d220af1 100644
--- a/drivers/staging/rtl8192e/rtllib_rx.c
+++ b/drivers/staging/rtl8192e/rtllib_rx.c
@@ -1317,7 +1317,6 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
1317 bool bToOtherSTA = false; 1317 bool bToOtherSTA = false;
1318 int ret = 0, i = 0; 1318 int ret = 0, i = 0;
1319 1319
1320 hdr = (struct rtllib_hdr_4addr *)skb->data;
1321 fc = le16_to_cpu(hdr->frame_ctl); 1320 fc = le16_to_cpu(hdr->frame_ctl);
1322 type = WLAN_FC_GET_TYPE(fc); 1321 type = WLAN_FC_GET_TYPE(fc);
1323 stype = WLAN_FC_GET_STYPE(fc); 1322 stype = WLAN_FC_GET_STYPE(fc);
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index c2b9ffba354a..919231fec09c 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -1968,7 +1968,7 @@ void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee)
1968 1968
1969static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time) 1969static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time)
1970{ 1970{
1971 int timeout = ieee->ps_timeout; 1971 int timeout;
1972 u8 dtim; 1972 u8 dtim;
1973 struct rt_pwr_save_ctrl *pPSC = &(ieee->PowerSaveControl); 1973 struct rt_pwr_save_ctrl *pPSC = &(ieee->PowerSaveControl);
1974 1974
diff --git a/drivers/staging/rtl8192u/ieee80211/dot11d.c b/drivers/staging/rtl8192u/ieee80211/dot11d.c
index 64b13a5da3cb..ba284bfb3b6d 100644
--- a/drivers/staging/rtl8192u/ieee80211/dot11d.c
+++ b/drivers/staging/rtl8192u/ieee80211/dot11d.c
@@ -11,7 +11,7 @@ void Dot11d_Init(struct ieee80211_device *ieee)
11 11
12 pDot11dInfo->State = DOT11D_STATE_NONE; 12 pDot11dInfo->State = DOT11D_STATE_NONE;
13 pDot11dInfo->CountryIeLen = 0; 13 pDot11dInfo->CountryIeLen = 0;
14 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1); 14 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER + 1);
15 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1); 15 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
16 RESET_CIE_WATCHDOG(ieee); 16 RESET_CIE_WATCHDOG(ieee);
17 17
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index cbf8eb4a049d..37a610d05ad2 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -110,12 +110,12 @@ ieee80211_frag_cache_get(struct ieee80211_device *ieee,
110 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr; 110 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr;
111 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; 111 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
112 tid = UP2AC(tid); 112 tid = UP2AC(tid);
113 tid ++; 113 tid++;
114 } else if (IEEE80211_QOS_HAS_SEQ(fc)) { 114 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
115 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr; 115 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr;
116 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; 116 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
117 tid = UP2AC(tid); 117 tid = UP2AC(tid);
118 tid ++; 118 tid++;
119 } else { 119 } else {
120 tid = 0; 120 tid = 0;
121 } 121 }
@@ -177,12 +177,12 @@ static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
177 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr; 177 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr;
178 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; 178 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
179 tid = UP2AC(tid); 179 tid = UP2AC(tid);
180 tid ++; 180 tid++;
181 } else if (IEEE80211_QOS_HAS_SEQ(fc)) { 181 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
182 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr; 182 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr;
183 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; 183 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
184 tid = UP2AC(tid); 184 tid = UP2AC(tid);
185 tid ++; 185 tid++;
186 } else { 186 } else {
187 tid = 0; 187 tid = 0;
188 } 188 }
@@ -434,12 +434,12 @@ static int is_duplicate_packet(struct ieee80211_device *ieee,
434 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)header; 434 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)header;
435 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; 435 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
436 tid = UP2AC(tid); 436 tid = UP2AC(tid);
437 tid ++; 437 tid++;
438 } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS 438 } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
439 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)header; 439 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)header;
440 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; 440 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
441 tid = UP2AC(tid); 441 tid = UP2AC(tid);
442 tid ++; 442 tid++;
443 } else { // no QoS 443 } else { // no QoS
444 tid = 0; 444 tid = 0;
445 } 445 }
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index f56fdc7a4b61..25c186a8bde3 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -1725,7 +1725,7 @@ static void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee,
1725static short ieee80211_sta_ps_sleep(struct ieee80211_device *ieee, u32 *time_h, 1725static short ieee80211_sta_ps_sleep(struct ieee80211_device *ieee, u32 *time_h,
1726 u32 *time_l) 1726 u32 *time_l)
1727{ 1727{
1728 int timeout = ieee->ps_timeout; 1728 int timeout;
1729 u8 dtim; 1729 u8 dtim;
1730 /*if(ieee->ps == IEEE80211_PS_DISABLED || 1730 /*if(ieee->ps == IEEE80211_PS_DISABLED ||
1731 ieee->iw_mode != IW_MODE_INFRA || 1731 ieee->iw_mode != IW_MODE_INFRA ||
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index 09f66b386e44..3c300f7b6a62 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -4998,7 +4998,7 @@ fail:
4998 kfree(priv->pFirmware); 4998 kfree(priv->pFirmware);
4999 priv->pFirmware = NULL; 4999 priv->pFirmware = NULL;
5000 rtl8192_usb_deleteendpoints(dev); 5000 rtl8192_usb_deleteendpoints(dev);
5001 mdelay(10); 5001 msleep(10);
5002 free_ieee80211(dev); 5002 free_ieee80211(dev);
5003 5003
5004 RT_TRACE(COMP_ERR, "wlan driver load failed\n"); 5004 RT_TRACE(COMP_ERR, "wlan driver load failed\n");
diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c
index de832b0b5eec..2a3f0746ee2c 100644
--- a/drivers/staging/rtl8712/hal_init.c
+++ b/drivers/staging/rtl8712/hal_init.c
@@ -336,7 +336,6 @@ uint rtl8712_hal_init(struct _adapter *padapter)
336 r8712_read32(padapter, RCR)); 336 r8712_read32(padapter, RCR));
337 val32 = r8712_read32(padapter, RCR); 337 val32 = r8712_read32(padapter, RCR);
338 r8712_write32(padapter, RCR, (val32 | BIT(25))); /* Append PHY status */ 338 r8712_write32(padapter, RCR, (val32 | BIT(25))); /* Append PHY status */
339 val32 = 0;
340 val32 = r8712_read32(padapter, 0x10250040); 339 val32 = r8712_read32(padapter, 0x10250040);
341 r8712_write32(padapter, 0x10250040, (val32 & 0x00FFFFFF)); 340 r8712_write32(padapter, 0x10250040, (val32 & 0x00FFFFFF));
342 /* for usb rx aggregation */ 341 /* for usb rx aggregation */
diff --git a/drivers/staging/rtl8712/ieee80211.c b/drivers/staging/rtl8712/ieee80211.c
index 33e82a9dd462..987270395635 100644
--- a/drivers/staging/rtl8712/ieee80211.c
+++ b/drivers/staging/rtl8712/ieee80211.c
@@ -169,12 +169,13 @@ int r8712_generate_ie(struct registry_priv *pregistrypriv)
169 int sz = 0, rate_len; 169 int sz = 0, rate_len;
170 struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network; 170 struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network;
171 u8 *ie = pdev_network->IEs; 171 u8 *ie = pdev_network->IEs;
172 u16 beaconPeriod = (u16)pdev_network->Configuration.BeaconPeriod;
172 173
173 /*timestamp will be inserted by hardware*/ 174 /*timestamp will be inserted by hardware*/
174 sz += 8; 175 sz += 8;
175 ie += sz; 176 ie += sz;
176 /*beacon interval : 2bytes*/ 177 /*beacon interval : 2bytes*/
177 *(__le16 *)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod); 178 *(__le16 *)ie = cpu_to_le16(beaconPeriod);
178 sz += 2; 179 sz += 2;
179 ie += 2; 180 ie += 2;
180 /*capability info*/ 181 /*capability info*/
@@ -221,7 +222,8 @@ unsigned char *r8712_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)
221 pbuf = r8712_get_ie(pbuf, _WPA_IE_ID_, &len, limit); 222 pbuf = r8712_get_ie(pbuf, _WPA_IE_ID_, &len, limit);
222 if (pbuf) { 223 if (pbuf) {
223 /*check if oui matches...*/ 224 /*check if oui matches...*/
224 if (memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type))) 225 if (memcmp((pbuf + 2), wpa_oui_type,
226 sizeof(wpa_oui_type)))
225 goto check_next_ie; 227 goto check_next_ie;
226 /*check version...*/ 228 /*check version...*/
227 memcpy((u8 *)&val16, (pbuf + 6), sizeof(val16)); 229 memcpy((u8 *)&val16, (pbuf + 6), sizeof(val16));
diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c
index 95caf8df9a13..e7df5d7986fc 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -238,10 +238,13 @@ static u32 start_drv_threads(struct _adapter *padapter)
238 238
239void r8712_stop_drv_threads(struct _adapter *padapter) 239void r8712_stop_drv_threads(struct _adapter *padapter)
240{ 240{
241 struct completion *completion =
242 &padapter->cmdpriv.terminate_cmdthread_comp;
243
241 /*Below is to terminate r8712_cmd_thread & event_thread...*/ 244 /*Below is to terminate r8712_cmd_thread & event_thread...*/
242 complete(&padapter->cmdpriv.cmd_queue_comp); 245 complete(&padapter->cmdpriv.cmd_queue_comp);
243 if (padapter->cmdThread) 246 if (padapter->cmdThread)
244 wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp); 247 wait_for_completion_interruptible(completion);
245 padapter->cmdpriv.cmd_seq = 1; 248 padapter->cmdpriv.cmd_seq = 1;
246} 249}
247 250
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c b/drivers/staging/rtl8712/rtl8712_cmd.c
index 3c88994fdfcd..9c8e0c50a804 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -321,10 +321,13 @@ int r8712_cmd_thread(void *context)
321 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd); 321 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd);
322 struct _adapter *padapter = context; 322 struct _adapter *padapter = context;
323 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv); 323 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
324 struct completion *cmd_queue_comp =
325 &pcmdpriv->cmd_queue_comp;
326 struct mutex *pwctrl_lock = &padapter->pwrctrlpriv.mutex_lock;
324 327
325 allow_signal(SIGTERM); 328 allow_signal(SIGTERM);
326 while (1) { 329 while (1) {
327 if (wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp)) 330 if (wait_for_completion_interruptible(cmd_queue_comp))
328 break; 331 break;
329 if (padapter->bDriverStopped || padapter->bSurpriseRemoved) 332 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
330 break; 333 break;
@@ -343,6 +346,7 @@ _next:
343 if (pcmd) { /* if pcmd != NULL, cmd will be handled by f/w */ 346 if (pcmd) { /* if pcmd != NULL, cmd will be handled by f/w */
344 struct dvobj_priv *pdvobj = &padapter->dvobjpriv; 347 struct dvobj_priv *pdvobj = &padapter->dvobjpriv;
345 u8 blnPending = 0; 348 u8 blnPending = 0;
349 u16 cmdcode = pcmd->cmdcode;
346 350
347 pcmdpriv->cmd_issued_cnt++; 351 pcmdpriv->cmd_issued_cnt++;
348 cmdsz = round_up(pcmd->cmdsz, 8); 352 cmdsz = round_up(pcmd->cmdsz, 8);
@@ -387,20 +391,18 @@ _next:
387 r8712_write_mem(padapter, RTL8712_DMA_H2CCMD, wr_sz, 391 r8712_write_mem(padapter, RTL8712_DMA_H2CCMD, wr_sz,
388 (u8 *)pdesc); 392 (u8 *)pdesc);
389 pcmdpriv->cmd_seq++; 393 pcmdpriv->cmd_seq++;
390 if (pcmd->cmdcode == GEN_CMD_CODE(_CreateBss)) { 394 if (cmdcode == GEN_CMD_CODE(_CreateBss)) {
391 pcmd->res = H2C_SUCCESS; 395 pcmd->res = H2C_SUCCESS;
392 pcmd_callback = cmd_callback[pcmd-> 396 pcmd_callback = cmd_callback[cmdcode].callback;
393 cmdcode].callback;
394 if (pcmd_callback) 397 if (pcmd_callback)
395 pcmd_callback(padapter, pcmd); 398 pcmd_callback(padapter, pcmd);
396 continue; 399 continue;
397 } 400 }
398 if (pcmd->cmdcode == GEN_CMD_CODE(_SetPwrMode)) { 401 if (cmdcode == GEN_CMD_CODE(_SetPwrMode)) {
399 if (padapter->pwrctrlpriv.bSleep) { 402 if (padapter->pwrctrlpriv.bSleep) {
400 mutex_lock(&padapter-> 403 mutex_lock(pwctrl_lock);
401 pwrctrlpriv.mutex_lock);
402 r8712_set_rpwm(padapter, PS_STATE_S2); 404 r8712_set_rpwm(padapter, PS_STATE_S2);
403 mutex_unlock(&padapter->pwrctrlpriv.mutex_lock); 405 mutex_unlock(pwctrl_lock);
404 } 406 }
405 } 407 }
406 r8712_free_cmd_obj(pcmd); 408 r8712_free_cmd_obj(pcmd);
diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c
index 8f555e6e1b3f..4264cd341f03 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.c
+++ b/drivers/staging/rtl8712/rtl8712_recv.c
@@ -899,6 +899,7 @@ static void process_link_qual(struct _adapter *padapter,
899{ 899{
900 u32 last_evm = 0, tmpVal; 900 u32 last_evm = 0, tmpVal;
901 struct rx_pkt_attrib *pattrib; 901 struct rx_pkt_attrib *pattrib;
902 struct smooth_rssi_data *sqd = &padapter->recvpriv.signal_qual_data;
902 903
903 if (prframe == NULL || padapter == NULL) 904 if (prframe == NULL || padapter == NULL)
904 return; 905 return;
@@ -907,27 +908,18 @@ static void process_link_qual(struct _adapter *padapter,
907 /* 908 /*
908 * 1. Record the general EVM to the sliding window. 909 * 1. Record the general EVM to the sliding window.
909 */ 910 */
910 if (padapter->recvpriv.signal_qual_data.total_num++ >= 911 if (sqd->total_num++ >= PHY_LINKQUALITY_SLID_WIN_MAX) {
911 PHY_LINKQUALITY_SLID_WIN_MAX) { 912 sqd->total_num = PHY_LINKQUALITY_SLID_WIN_MAX;
912 padapter->recvpriv.signal_qual_data.total_num = 913 last_evm = sqd->elements[sqd->index];
913 PHY_LINKQUALITY_SLID_WIN_MAX; 914 sqd->total_val -= last_evm;
914 last_evm = padapter->recvpriv.signal_qual_data.elements
915 [padapter->recvpriv.signal_qual_data.index];
916 padapter->recvpriv.signal_qual_data.total_val -=
917 last_evm;
918 } 915 }
919 padapter->recvpriv.signal_qual_data.total_val += 916 sqd->total_val += pattrib->signal_qual;
920 pattrib->signal_qual; 917 sqd->elements[sqd->index++] = pattrib->signal_qual;
921 padapter->recvpriv.signal_qual_data.elements[padapter-> 918 if (sqd->index >= PHY_LINKQUALITY_SLID_WIN_MAX)
922 recvpriv.signal_qual_data.index++] = 919 sqd->index = 0;
923 pattrib->signal_qual;
924 if (padapter->recvpriv.signal_qual_data.index >=
925 PHY_LINKQUALITY_SLID_WIN_MAX)
926 padapter->recvpriv.signal_qual_data.index = 0;
927 920
928 /* <1> Showed on UI for user, in percentage. */ 921 /* <1> Showed on UI for user, in percentage. */
929 tmpVal = padapter->recvpriv.signal_qual_data.total_val / 922 tmpVal = sqd->total_val / sqd->total_num;
930 padapter->recvpriv.signal_qual_data.total_num;
931 padapter->recvpriv.signal = (u8)tmpVal; 923 padapter->recvpriv.signal = (u8)tmpVal;
932 } 924 }
933} 925}
@@ -936,25 +928,18 @@ static void process_rssi(struct _adapter *padapter, union recv_frame *prframe)
936{ 928{
937 u32 last_rssi, tmp_val; 929 u32 last_rssi, tmp_val;
938 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib; 930 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
931 struct smooth_rssi_data *ssd = &padapter->recvpriv.signal_strength_data;
939 932
940 if (padapter->recvpriv.signal_strength_data.total_num++ >= 933 if (ssd->total_num++ >= PHY_RSSI_SLID_WIN_MAX) {
941 PHY_RSSI_SLID_WIN_MAX) { 934 ssd->total_num = PHY_RSSI_SLID_WIN_MAX;
942 padapter->recvpriv.signal_strength_data.total_num = 935 last_rssi = ssd->elements[ssd->index];
943 PHY_RSSI_SLID_WIN_MAX; 936 ssd->total_val -= last_rssi;
944 last_rssi = padapter->recvpriv.signal_strength_data.elements
945 [padapter->recvpriv.signal_strength_data.index];
946 padapter->recvpriv.signal_strength_data.total_val -= last_rssi;
947 } 937 }
948 padapter->recvpriv.signal_strength_data.total_val += 938 ssd->total_val += pattrib->signal_strength;
949 pattrib->signal_strength; 939 ssd->elements[ssd->index++] = pattrib->signal_strength;
950 padapter->recvpriv.signal_strength_data.elements[padapter->recvpriv. 940 if (ssd->index >= PHY_RSSI_SLID_WIN_MAX)
951 signal_strength_data.index++] = 941 ssd->index = 0;
952 pattrib->signal_strength; 942 tmp_val = ssd->total_val / ssd->total_num;
953 if (padapter->recvpriv.signal_strength_data.index >=
954 PHY_RSSI_SLID_WIN_MAX)
955 padapter->recvpriv.signal_strength_data.index = 0;
956 tmp_val = padapter->recvpriv.signal_strength_data.total_val /
957 padapter->recvpriv.signal_strength_data.total_num;
958 padapter->recvpriv.rssi = (s8)translate2dbm(padapter, (u8)tmp_val); 943 padapter->recvpriv.rssi = (s8)translate2dbm(padapter, (u8)tmp_val);
959} 944}
960 945
diff --git a/drivers/staging/rtl8712/rtl8712_xmit.c b/drivers/staging/rtl8712/rtl8712_xmit.c
index 42d014007764..fb64c2891e22 100644
--- a/drivers/staging/rtl8712/rtl8712_xmit.c
+++ b/drivers/staging/rtl8712/rtl8712_xmit.c
@@ -573,7 +573,8 @@ static void update_txdesc(struct xmit_frame *pxmitframe, uint *pmem, int sz)
573 } 573 }
574 } else if (pxmitframe->frame_tag == MGNT_FRAMETAG) { 574 } else if (pxmitframe->frame_tag == MGNT_FRAMETAG) {
575 /* offset 4 */ 575 /* offset 4 */
576 ptxdesc->txdw1 |= cpu_to_le32((0x05) & 0x1f);/*CAM_ID(MAC_ID), default=5;*/ 576 /* CAM_ID(MAC_ID), default=5; */
577 ptxdesc->txdw1 |= cpu_to_le32((0x05) & 0x1f);
577 qsel = (uint)(pattrib->qsel & 0x0000001f); 578 qsel = (uint)(pattrib->qsel & 0x0000001f);
578 ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00); 579 ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00);
579 ptxdesc->txdw1 |= cpu_to_le32(BIT(16));/* Non-QoS */ 580 ptxdesc->txdw1 |= cpu_to_le32(BIT(16));/* Non-QoS */
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c b/drivers/staging/rtl8712/rtl871x_cmd.c
index a424f447a725..620cee8b8514 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -455,8 +455,8 @@ u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork)
455 struct qos_priv *pqospriv = &pmlmepriv->qospriv; 455 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
456 struct security_priv *psecuritypriv = &padapter->securitypriv; 456 struct security_priv *psecuritypriv = &padapter->securitypriv;
457 struct registry_priv *pregistrypriv = &padapter->registrypriv; 457 struct registry_priv *pregistrypriv = &padapter->registrypriv;
458 enum NDIS_802_11_NETWORK_INFRASTRUCTURE ndis_network_mode = pnetwork-> 458 enum NDIS_802_11_NETWORK_INFRASTRUCTURE ndis_network_mode =
459 network.InfrastructureMode; 459 pnetwork->network.InfrastructureMode;
460 460
461 padapter->ledpriv.LedControlHandler(padapter, LED_CTL_START_TO_LINK); 461 padapter->ledpriv.LedControlHandler(padapter, LED_CTL_START_TO_LINK);
462 pcmd = kmalloc(sizeof(*pcmd), GFP_ATOMIC); 462 pcmd = kmalloc(sizeof(*pcmd), GFP_ATOMIC);
@@ -862,22 +862,22 @@ void r8712_createbss_cmd_callback(struct _adapter *padapter,
862 pnetwork->Privacy = le32_to_cpu(pnetwork->Privacy); 862 pnetwork->Privacy = le32_to_cpu(pnetwork->Privacy);
863 pnetwork->Rssi = le32_to_cpu(pnetwork->Rssi); 863 pnetwork->Rssi = le32_to_cpu(pnetwork->Rssi);
864 pnetwork->NetworkTypeInUse = le32_to_cpu(pnetwork->NetworkTypeInUse); 864 pnetwork->NetworkTypeInUse = le32_to_cpu(pnetwork->NetworkTypeInUse);
865 pnetwork->Configuration.ATIMWindow = le32_to_cpu(pnetwork-> 865 pnetwork->Configuration.ATIMWindow =
866 Configuration.ATIMWindow); 866 le32_to_cpu(pnetwork->Configuration.ATIMWindow);
867 pnetwork->Configuration.DSConfig = le32_to_cpu(pnetwork-> 867 pnetwork->Configuration.DSConfig =
868 Configuration.DSConfig); 868 le32_to_cpu(pnetwork->Configuration.DSConfig);
869 pnetwork->Configuration.FHConfig.DwellTime = le32_to_cpu(pnetwork-> 869 pnetwork->Configuration.FHConfig.DwellTime =
870 Configuration.FHConfig.DwellTime); 870 le32_to_cpu(pnetwork->Configuration.FHConfig.DwellTime);
871 pnetwork->Configuration.FHConfig.HopPattern = le32_to_cpu(pnetwork-> 871 pnetwork->Configuration.FHConfig.HopPattern =
872 Configuration.FHConfig.HopPattern); 872 le32_to_cpu(pnetwork->Configuration.FHConfig.HopPattern);
873 pnetwork->Configuration.FHConfig.HopSet = le32_to_cpu(pnetwork-> 873 pnetwork->Configuration.FHConfig.HopSet =
874 Configuration.FHConfig.HopSet); 874 le32_to_cpu(pnetwork->Configuration.FHConfig.HopSet);
875 pnetwork->Configuration.FHConfig.Length = le32_to_cpu(pnetwork-> 875 pnetwork->Configuration.FHConfig.Length =
876 Configuration.FHConfig.Length); 876 le32_to_cpu(pnetwork->Configuration.FHConfig.Length);
877 pnetwork->Configuration.Length = le32_to_cpu(pnetwork-> 877 pnetwork->Configuration.Length =
878 Configuration.Length); 878 le32_to_cpu(pnetwork->Configuration.Length);
879 pnetwork->InfrastructureMode = le32_to_cpu(pnetwork-> 879 pnetwork->InfrastructureMode =
880 InfrastructureMode); 880 le32_to_cpu(pnetwork->InfrastructureMode);
881 pnetwork->IELength = le32_to_cpu(pnetwork->IELength); 881 pnetwork->IELength = le32_to_cpu(pnetwork->IELength);
882#endif 882#endif
883 spin_lock_irqsave(&pmlmepriv->lock, irqL); 883 spin_lock_irqsave(&pmlmepriv->lock, irqL);
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index e30a5be5f318..c3ff7c3e6681 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -114,23 +114,27 @@ static inline void handle_pairwise_key(struct sta_info *psta,
114static inline void handle_group_key(struct ieee_param *param, 114static inline void handle_group_key(struct ieee_param *param,
115 struct _adapter *padapter) 115 struct _adapter *padapter)
116{ 116{
117 union Keytype *gk = padapter->securitypriv.XGrpKey;
118 union Keytype *gtk = padapter->securitypriv.XGrptxmickey;
119 union Keytype *grk = padapter->securitypriv.XGrprxmickey;
120
117 if (param->u.crypt.idx > 0 && 121 if (param->u.crypt.idx > 0 &&
118 param->u.crypt.idx < 3) { 122 param->u.crypt.idx < 3) {
119 /* group key idx is 1 or 2 */ 123 /* group key idx is 1 or 2 */
120 memcpy(padapter->securitypriv.XGrpKey[param->u.crypt. 124 memcpy(gk[param->u.crypt.idx - 1].skey,
121 idx - 1].skey, param->u.crypt.key, 125 param->u.crypt.key,
122 (param->u.crypt.key_len > 16 ? 16 : 126 (param->u.crypt.key_len > 16 ? 16 :
123 param->u.crypt.key_len)); 127 param->u.crypt.key_len));
124 memcpy(padapter->securitypriv.XGrptxmickey[param-> 128 memcpy(gtk[param->u.crypt.idx - 1].skey,
125 u.crypt.idx - 1].skey, &(param->u.crypt.key[16]), 8); 129 &param->u.crypt.key[16], 8);
126 memcpy(padapter->securitypriv. XGrprxmickey[param-> 130 memcpy(grk[param->u.crypt.idx - 1].skey,
127 u.crypt.idx - 1].skey, &(param->u.crypt.key[24]), 8); 131 &param->u.crypt.key[24], 8);
128 padapter->securitypriv.binstallGrpkey = true; 132 padapter->securitypriv.binstallGrpkey = true;
129 r8712_set_key(padapter, &padapter->securitypriv, 133 r8712_set_key(padapter, &padapter->securitypriv,
130 param->u.crypt.idx); 134 param->u.crypt.idx);
131 if (padapter->registrypriv.power_mgnt > PS_MODE_ACTIVE) { 135 if (padapter->registrypriv.power_mgnt > PS_MODE_ACTIVE) {
132 if (padapter->registrypriv.power_mgnt != padapter-> 136 if (padapter->registrypriv.power_mgnt !=
133 pwrctrlpriv.pwr_mode) 137 padapter->pwrctrlpriv.pwr_mode)
134 mod_timer(&padapter->mlmepriv.dhcp_timer, 138 mod_timer(&padapter->mlmepriv.dhcp_timer,
135 jiffies + msecs_to_jiffies(60000)); 139 jiffies + msecs_to_jiffies(60000));
136 } 140 }
@@ -216,9 +220,9 @@ static noinline_for_stack char *translate_scan(struct _adapter *padapter,
216 220
217 if (dsconfig >= 1 && dsconfig <= sizeof( 221 if (dsconfig >= 1 && dsconfig <= sizeof(
218 ieee80211_wlan_frequencies) / sizeof(long)) 222 ieee80211_wlan_frequencies) / sizeof(long))
219 iwe.u.freq.m = (s32)(ieee80211_wlan_frequencies[ 223 iwe.u.freq.m =
220 pnetwork->network.Configuration. 224 (s32)(ieee80211_wlan_frequencies
221 DSConfig - 1] * 100000); 225 [dsconfig - 1] * 100000);
222 else 226 else
223 iwe.u.freq.m = 0; 227 iwe.u.freq.m = 0;
224 } 228 }
@@ -425,9 +429,9 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
425 ret = -EOPNOTSUPP; 429 ret = -EOPNOTSUPP;
426 goto exit; 430 goto exit;
427 } 431 }
428 memcpy(&(psecuritypriv->DefKey[wep_key_idx]. 432 memcpy(&psecuritypriv->DefKey[wep_key_idx].skey[0],
429 skey[0]), pwep->KeyMaterial, 433 pwep->KeyMaterial,
430 pwep->KeyLength); 434 pwep->KeyLength);
431 psecuritypriv->DefKeylen[wep_key_idx] = 435 psecuritypriv->DefKeylen[wep_key_idx] =
432 pwep->KeyLength; 436 pwep->KeyLength;
433 r8712_set_key(padapter, psecuritypriv, wep_key_idx); 437 r8712_set_key(padapter, psecuritypriv, wep_key_idx);
@@ -437,6 +441,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
437 if (padapter->securitypriv.AuthAlgrthm == 2) { /* 802_1x */ 441 if (padapter->securitypriv.AuthAlgrthm == 2) { /* 802_1x */
438 struct sta_info *psta, *pbcmc_sta; 442 struct sta_info *psta, *pbcmc_sta;
439 struct sta_priv *pstapriv = &padapter->stapriv; 443 struct sta_priv *pstapriv = &padapter->stapriv;
444 struct security_priv *spriv = &padapter->securitypriv;
440 445
441 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | 446 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE |
442 WIFI_MP_STATE)) { /* sta mode */ 447 WIFI_MP_STATE)) { /* sta mode */
@@ -444,12 +449,11 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
444 get_bssid(pmlmepriv)); 449 get_bssid(pmlmepriv));
445 if (psta) { 450 if (psta) {
446 psta->ieee8021x_blocked = false; 451 psta->ieee8021x_blocked = false;
447 if ((padapter->securitypriv.ndisencryptstatus == 452 if (spriv->ndisencryptstatus ==
448 Ndis802_11Encryption2Enabled) || 453 Ndis802_11Encryption2Enabled ||
449 (padapter->securitypriv.ndisencryptstatus == 454 spriv->ndisencryptstatus ==
450 Ndis802_11Encryption3Enabled)) 455 Ndis802_11Encryption3Enabled)
451 psta->XPrivacy = padapter-> 456 psta->XPrivacy = spriv->PrivacyAlgrthm;
452 securitypriv.PrivacyAlgrthm;
453 if (param->u.crypt.set_tx == 1) 457 if (param->u.crypt.set_tx == 1)
454 handle_pairwise_key(psta, param, 458 handle_pairwise_key(psta, param,
455 padapter); 459 padapter);
@@ -459,13 +463,12 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
459 pbcmc_sta = r8712_get_bcmc_stainfo(padapter); 463 pbcmc_sta = r8712_get_bcmc_stainfo(padapter);
460 if (pbcmc_sta) { 464 if (pbcmc_sta) {
461 pbcmc_sta->ieee8021x_blocked = false; 465 pbcmc_sta->ieee8021x_blocked = false;
462 if ((padapter->securitypriv.ndisencryptstatus == 466 if (spriv->ndisencryptstatus ==
463 Ndis802_11Encryption2Enabled) || 467 Ndis802_11Encryption2Enabled ||
464 (padapter->securitypriv.ndisencryptstatus == 468 spriv->ndisencryptstatus ==
465 Ndis802_11Encryption3Enabled)) 469 Ndis802_11Encryption3Enabled)
466 pbcmc_sta->XPrivacy = 470 pbcmc_sta->XPrivacy =
467 padapter->securitypriv. 471 spriv->PrivacyAlgrthm;
468 PrivacyAlgrthm;
469 } 472 }
470 } 473 }
471 } 474 }
@@ -763,6 +766,7 @@ static int r871x_wx_set_pmkid(struct net_device *dev,
763 struct _adapter *padapter = netdev_priv(dev); 766 struct _adapter *padapter = netdev_priv(dev);
764 struct security_priv *psecuritypriv = &padapter->securitypriv; 767 struct security_priv *psecuritypriv = &padapter->securitypriv;
765 struct iw_pmksa *pPMK = (struct iw_pmksa *) extra; 768 struct iw_pmksa *pPMK = (struct iw_pmksa *) extra;
769 struct RT_PMKID_LIST *pl = psecuritypriv->PMKIDList;
766 u8 strZeroMacAddress[ETH_ALEN] = {0x00}; 770 u8 strZeroMacAddress[ETH_ALEN] = {0x00};
767 u8 strIssueBssid[ETH_ALEN] = {0x00}; 771 u8 strIssueBssid[ETH_ALEN] = {0x00};
768 u8 j, blInserted = false; 772 u8 j, blInserted = false;
@@ -787,16 +791,14 @@ static int r871x_wx_set_pmkid(struct net_device *dev,
787 blInserted = false; 791 blInserted = false;
788 /* overwrite PMKID */ 792 /* overwrite PMKID */
789 for (j = 0; j < NUM_PMKID_CACHE; j++) { 793 for (j = 0; j < NUM_PMKID_CACHE; j++) {
790 if (!memcmp(psecuritypriv->PMKIDList[j].Bssid, 794 if (!memcmp(pl[j].Bssid, strIssueBssid, ETH_ALEN)) {
791 strIssueBssid, ETH_ALEN)) {
792 /* BSSID is matched, the same AP => rewrite 795 /* BSSID is matched, the same AP => rewrite
793 * with new PMKID. 796 * with new PMKID.
794 */ 797 */
795 netdev_info(dev, "r8712u: %s: BSSID exists in the PMKList.\n", 798 netdev_info(dev, "r8712u: %s: BSSID exists in the PMKList.\n",
796 __func__); 799 __func__);
797 memcpy(psecuritypriv->PMKIDList[j].PMKID, 800 memcpy(pl[j].PMKID, pPMK->pmkid, IW_PMKID_LEN);
798 pPMK->pmkid, IW_PMKID_LEN); 801 pl[j].bUsed = true;
799 psecuritypriv->PMKIDList[j].bUsed = true;
800 psecuritypriv->PMKIDIndex = j + 1; 802 psecuritypriv->PMKIDIndex = j + 1;
801 blInserted = true; 803 blInserted = true;
802 break; 804 break;
@@ -806,12 +808,11 @@ static int r871x_wx_set_pmkid(struct net_device *dev,
806 /* Find a new entry */ 808 /* Find a new entry */
807 netdev_info(dev, "r8712u: %s: Use the new entry index = %d for this PMKID.\n", 809 netdev_info(dev, "r8712u: %s: Use the new entry index = %d for this PMKID.\n",
808 __func__, psecuritypriv->PMKIDIndex); 810 __func__, psecuritypriv->PMKIDIndex);
809 memcpy(psecuritypriv->PMKIDList[psecuritypriv-> 811 memcpy(pl[psecuritypriv->PMKIDIndex].Bssid,
810 PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN); 812 strIssueBssid, ETH_ALEN);
811 memcpy(psecuritypriv->PMKIDList[psecuritypriv-> 813 memcpy(pl[psecuritypriv->PMKIDIndex].PMKID,
812 PMKIDIndex].PMKID, pPMK->pmkid, IW_PMKID_LEN); 814 pPMK->pmkid, IW_PMKID_LEN);
813 psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex]. 815 pl[psecuritypriv->PMKIDIndex].bUsed = true;
814 bUsed = true;
815 psecuritypriv->PMKIDIndex++; 816 psecuritypriv->PMKIDIndex++;
816 if (psecuritypriv->PMKIDIndex == NUM_PMKID_CACHE) 817 if (psecuritypriv->PMKIDIndex == NUM_PMKID_CACHE)
817 psecuritypriv->PMKIDIndex = 0; 818 psecuritypriv->PMKIDIndex = 0;
@@ -820,13 +821,12 @@ static int r871x_wx_set_pmkid(struct net_device *dev,
820 case IW_PMKSA_REMOVE: 821 case IW_PMKSA_REMOVE:
821 intReturn = true; 822 intReturn = true;
822 for (j = 0; j < NUM_PMKID_CACHE; j++) { 823 for (j = 0; j < NUM_PMKID_CACHE; j++) {
823 if (!memcmp(psecuritypriv->PMKIDList[j].Bssid, 824 if (!memcmp(pl[j].Bssid, strIssueBssid, ETH_ALEN)) {
824 strIssueBssid, ETH_ALEN)) {
825 /* BSSID is matched, the same AP => Remove 825 /* BSSID is matched, the same AP => Remove
826 * this PMKID information and reset it. 826 * this PMKID information and reset it.
827 */ 827 */
828 eth_zero_addr(psecuritypriv->PMKIDList[j].Bssid); 828 eth_zero_addr(pl[j].Bssid);
829 psecuritypriv->PMKIDList[j].bUsed = false; 829 pl[j].bUsed = false;
830 break; 830 break;
831 } 831 }
832 } 832 }
@@ -1598,6 +1598,7 @@ static int r8711_wx_get_enc(struct net_device *dev,
1598 struct _adapter *padapter = netdev_priv(dev); 1598 struct _adapter *padapter = netdev_priv(dev);
1599 struct iw_point *erq = &(wrqu->encoding); 1599 struct iw_point *erq = &(wrqu->encoding);
1600 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1600 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1601 union Keytype *dk = padapter->securitypriv.DefKey;
1601 1602
1602 if (!check_fwstate(pmlmepriv, _FW_LINKED)) { 1603 if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
1603 if (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { 1604 if (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
@@ -1624,9 +1625,8 @@ static int r8711_wx_get_enc(struct net_device *dev,
1624 case Ndis802_11Encryption1Enabled: 1625 case Ndis802_11Encryption1Enabled:
1625 erq->length = padapter->securitypriv.DefKeylen[key]; 1626 erq->length = padapter->securitypriv.DefKeylen[key];
1626 if (erq->length) { 1627 if (erq->length) {
1627 memcpy(keybuf, padapter->securitypriv.DefKey[ 1628 memcpy(keybuf, dk[key].skey,
1628 key].skey, padapter->securitypriv. 1629 padapter->securitypriv.DefKeylen[key]);
1629 DefKeylen[key]);
1630 erq->flags |= IW_ENCODE_ENABLED; 1630 erq->flags |= IW_ENCODE_ENABLED;
1631 if (padapter->securitypriv.ndisauthtype == 1631 if (padapter->securitypriv.ndisauthtype ==
1632 Ndis802_11AuthModeOpen) 1632 Ndis802_11AuthModeOpen)
@@ -1719,12 +1719,12 @@ static int r871x_wx_set_auth(struct net_device *dev,
1719 */ 1719 */
1720 if (padapter->securitypriv.ndisencryptstatus == 1720 if (padapter->securitypriv.ndisencryptstatus ==
1721 Ndis802_11Encryption1Enabled) { 1721 Ndis802_11Encryption1Enabled) {
1722 /* it means init value, or using wep, 1722 /* it means init value, or using wep,
1723 * ndisencryptstatus = 1723 * ndisencryptstatus =
1724 * Ndis802_11Encryption1Enabled, 1724 * Ndis802_11Encryption1Enabled,
1725 * then it needn't reset it; 1725 * then it needn't reset it;
1726 */ 1726 */
1727 break; 1727 break;
1728 } 1728 }
1729 1729
1730 if (paramval) { 1730 if (paramval) {
@@ -1853,7 +1853,7 @@ static int dummy(struct net_device *dev,
1853 struct iw_request_info *a, 1853 struct iw_request_info *a,
1854 union iwreq_data *wrqu, char *b) 1854 union iwreq_data *wrqu, char *b)
1855{ 1855{
1856 return -ENOSYS; 1856 return -EINVAL;
1857} 1857}
1858 1858
1859static int r8711_drvext_hdl(struct net_device *dev, 1859static int r8711_drvext_hdl(struct net_device *dev,
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_set.c b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
index 8a5ced4fa9d3..f4a53df7f2c1 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_set.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
@@ -55,6 +55,7 @@ static u8 do_join(struct _adapter *padapter)
55 u8 *pibss = NULL; 55 u8 *pibss = NULL;
56 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 56 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
57 struct __queue *queue = &(pmlmepriv->scanned_queue); 57 struct __queue *queue = &(pmlmepriv->scanned_queue);
58 int ret;
58 59
59 phead = &queue->queue; 60 phead = &queue->queue;
60 plist = phead->next; 61 plist = phead->next;
@@ -74,45 +75,42 @@ static u8 do_join(struct _adapter *padapter)
74 if (!pmlmepriv->sitesurveyctrl.traffic_busy) 75 if (!pmlmepriv->sitesurveyctrl.traffic_busy)
75 r8712_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid); 76 r8712_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid);
76 return true; 77 return true;
77 } else { 78 }
78 int ret;
79 79
80 ret = r8712_select_and_join_from_scan(pmlmepriv); 80 ret = r8712_select_and_join_from_scan(pmlmepriv);
81 if (ret == _SUCCESS) { 81 if (ret == _SUCCESS) {
82 mod_timer(&pmlmepriv->assoc_timer, 82 mod_timer(&pmlmepriv->assoc_timer,
83 jiffies + msecs_to_jiffies(MAX_JOIN_TIMEOUT)); 83 jiffies + msecs_to_jiffies(MAX_JOIN_TIMEOUT));
84 } else {
85 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
86 /* submit r8712_createbss_cmd to change to an
87 * ADHOC_MASTER pmlmepriv->lock has been
88 * acquired by caller...
89 */
90 struct wlan_bssid_ex *pdev_network =
91 &(padapter->registrypriv.dev_network);
92 pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;
93 pibss = padapter->registrypriv.dev_network.MacAddress;
94 memcpy(&pdev_network->Ssid,
95 &pmlmepriv->assoc_ssid,
96 sizeof(struct ndis_802_11_ssid));
97 r8712_update_registrypriv_dev_network(padapter);
98 r8712_generate_random_ibss(pibss);
99 if (r8712_createbss_cmd(padapter) != _SUCCESS)
100 return false;
101 pmlmepriv->to_join = false;
84 } else { 102 } else {
85 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { 103 /* can't associate ; reset under-linking */
86 /* submit r8712_createbss_cmd to change to an 104 if (pmlmepriv->fw_state & _FW_UNDER_LINKING)
87 * ADHOC_MASTER pmlmepriv->lock has been 105 pmlmepriv->fw_state ^=
88 * acquired by caller... 106 _FW_UNDER_LINKING;
89 */ 107 /* when set_ssid/set_bssid for do_join(), but
90 struct wlan_bssid_ex *pdev_network = 108 * there are no desired bss in scanning queue
91 &(padapter->registrypriv.dev_network); 109 * we try to issue sitesurvey first
92 pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE; 110 */
93 pibss = padapter->registrypriv.dev_network. 111 if (!pmlmepriv->sitesurveyctrl.traffic_busy)
94 MacAddress; 112 r8712_sitesurvey_cmd(padapter,
95 memcpy(&pdev_network->Ssid, 113 &pmlmepriv->assoc_ssid);
96 &pmlmepriv->assoc_ssid,
97 sizeof(struct ndis_802_11_ssid));
98 r8712_update_registrypriv_dev_network(padapter);
99 r8712_generate_random_ibss(pibss);
100 if (r8712_createbss_cmd(padapter) != _SUCCESS)
101 return false;
102 pmlmepriv->to_join = false;
103 } else {
104 /* can't associate ; reset under-linking */
105 if (pmlmepriv->fw_state & _FW_UNDER_LINKING)
106 pmlmepriv->fw_state ^=
107 _FW_UNDER_LINKING;
108 /* when set_ssid/set_bssid for do_join(), but
109 * there are no desired bss in scanning queue
110 * we try to issue sitesurvey first
111 */
112 if (!pmlmepriv->sitesurveyctrl.traffic_busy)
113 r8712_sitesurvey_cmd(padapter,
114 &pmlmepriv->assoc_ssid);
115 }
116 } 114 }
117 } 115 }
118 return true; 116 return true;
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c
index 111c809afc51..78245080e328 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -319,6 +319,7 @@ static void update_network(struct wlan_bssid_ex *dst,
319 struct _adapter *padapter) 319 struct _adapter *padapter)
320{ 320{
321 u32 last_evm = 0, tmpVal; 321 u32 last_evm = 0, tmpVal;
322 struct smooth_rssi_data *sqd = &padapter->recvpriv.signal_qual_data;
322 323
323 if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) && 324 if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) &&
324 is_same_network(&(padapter->mlmepriv.cur_network.network), src)) { 325 is_same_network(&(padapter->mlmepriv.cur_network.network), src)) {
@@ -326,17 +327,13 @@ static void update_network(struct wlan_bssid_ex *dst,
326 PHY_LINKQUALITY_SLID_WIN_MAX) { 327 PHY_LINKQUALITY_SLID_WIN_MAX) {
327 padapter->recvpriv.signal_qual_data.total_num = 328 padapter->recvpriv.signal_qual_data.total_num =
328 PHY_LINKQUALITY_SLID_WIN_MAX; 329 PHY_LINKQUALITY_SLID_WIN_MAX;
329 last_evm = padapter->recvpriv.signal_qual_data. 330 last_evm = sqd->elements[sqd->index];
330 elements[padapter->recvpriv.
331 signal_qual_data.index];
332 padapter->recvpriv.signal_qual_data.total_val -= 331 padapter->recvpriv.signal_qual_data.total_val -=
333 last_evm; 332 last_evm;
334 } 333 }
335 padapter->recvpriv.signal_qual_data.total_val += src->Rssi; 334 padapter->recvpriv.signal_qual_data.total_val += src->Rssi;
336 335
337 padapter->recvpriv.signal_qual_data. 336 sqd->elements[sqd->index++] = src->Rssi;
338 elements[padapter->recvpriv.signal_qual_data.
339 index++] = src->Rssi;
340 if (padapter->recvpriv.signal_qual_data.index >= 337 if (padapter->recvpriv.signal_qual_data.index >=
341 PHY_LINKQUALITY_SLID_WIN_MAX) 338 PHY_LINKQUALITY_SLID_WIN_MAX)
342 padapter->recvpriv.signal_qual_data.index = 0; 339 padapter->recvpriv.signal_qual_data.index = 0;
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.h b/drivers/staging/rtl8712/rtl871x_mlme.h
index b21f28140f53..918947f38151 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.h
+++ b/drivers/staging/rtl8712/rtl871x_mlme.h
@@ -55,7 +55,8 @@
55 * single-tone 55 * single-tone
56 */ 56 */
57#define WIFI_MP_CTX_BACKGROUND_PENDING 0x00080000 /* pending in cont, tx 57#define WIFI_MP_CTX_BACKGROUND_PENDING 0x00080000 /* pending in cont, tx
58 * background due to out of skb 58 * background due
59 * to out of skb
59 */ 60 */
60#define WIFI_MP_CTX_CCK_HW 0x00100000 /* in continuous tx*/ 61#define WIFI_MP_CTX_CCK_HW 0x00100000 /* in continuous tx*/
61#define WIFI_MP_CTX_CCK_CS 0x00200000 /* in cont, tx with carrier 62#define WIFI_MP_CTX_CCK_CS 0x00200000 /* in cont, tx with carrier
diff --git a/drivers/staging/rtl8712/rtl871x_mp.c b/drivers/staging/rtl8712/rtl871x_mp.c
index 3c10a2c848c8..ba208a2e1e4e 100644
--- a/drivers/staging/rtl8712/rtl871x_mp.c
+++ b/drivers/staging/rtl8712/rtl871x_mp.c
@@ -541,7 +541,7 @@ void r8712_SetSingleCarrierTx(struct _adapter *pAdapter, u8 bStart)
541 541
542void r8712_SetSingleToneTx(struct _adapter *pAdapter, u8 bStart) 542void r8712_SetSingleToneTx(struct _adapter *pAdapter, u8 bStart)
543{ 543{
544 u8 rfPath = pAdapter->mppriv.curr_rfpath; 544 u8 rfPath;
545 545
546 switch (pAdapter->mppriv.antenna_tx) { 546 switch (pAdapter->mppriv.antenna_tx) {
547 case ANTENNA_B: 547 case ANTENNA_B:
diff --git a/drivers/staging/rtl8712/rtl871x_security.c b/drivers/staging/rtl8712/rtl871x_security.c
index 56d36f6f9c46..7bc74d7d8a3a 100644
--- a/drivers/staging/rtl8712/rtl871x_security.c
+++ b/drivers/staging/rtl8712/rtl871x_security.c
@@ -165,7 +165,7 @@ void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
165{ /* exclude ICV */ 165{ /* exclude ICV */
166 unsigned char crc[4]; 166 unsigned char crc[4];
167 struct arc4context mycontext; 167 struct arc4context mycontext;
168 u32 curfragnum, length, keylength; 168 u32 curfragnum, length, keylength, pki;
169 u8 *pframe, *payload, *iv; /*,*wepkey*/ 169 u8 *pframe, *payload, *iv; /*,*wepkey*/
170 u8 wepkey[16]; 170 u8 wepkey[16];
171 struct pkt_attrib *pattrib = &((struct xmit_frame *) 171 struct pkt_attrib *pattrib = &((struct xmit_frame *)
@@ -178,8 +178,8 @@ void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
178 pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + TXDESC_OFFSET; 178 pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + TXDESC_OFFSET;
179 /*start to encrypt each fragment*/ 179 /*start to encrypt each fragment*/
180 if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) { 180 if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) {
181 keylength = psecuritypriv->DefKeylen[psecuritypriv-> 181 pki = psecuritypriv->PrivacyKeyIndex;
182 PrivacyKeyIndex]; 182 keylength = psecuritypriv->DefKeylen[pki];
183 for (curfragnum = 0; curfragnum < pattrib->nr_frags; 183 for (curfragnum = 0; curfragnum < pattrib->nr_frags;
184 curfragnum++) { 184 curfragnum++) {
185 iv = pframe + pattrib->hdrlen; 185 iv = pframe + pattrib->hdrlen;
@@ -189,9 +189,10 @@ void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
189 keylength); 189 keylength);
190 payload = pframe + pattrib->iv_len + pattrib->hdrlen; 190 payload = pframe + pattrib->iv_len + pattrib->hdrlen;
191 if ((curfragnum + 1) == pattrib->nr_frags) { 191 if ((curfragnum + 1) == pattrib->nr_frags) {
192 length = pattrib->last_txcmdsz - pattrib-> 192 length = pattrib->last_txcmdsz -
193 hdrlen - pattrib->iv_len - 193 pattrib->hdrlen -
194 pattrib->icv_len; 194 pattrib->iv_len -
195 pattrib->icv_len;
195 *((__le32 *)crc) = cpu_to_le32(getcrc32( 196 *((__le32 *)crc) = cpu_to_le32(getcrc32(
196 payload, length)); 197 payload, length));
197 arcfour_init(&mycontext, wepkey, 3 + keylength); 198 arcfour_init(&mycontext, wepkey, 3 + keylength);
@@ -606,8 +607,8 @@ u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
606 GET_TKIP_PN(iv, txpn); 607 GET_TKIP_PN(iv, txpn);
607 pnl = (u16)(txpn.val); 608 pnl = (u16)(txpn.val);
608 pnh = (u32)(txpn.val >> 16); 609 pnh = (u32)(txpn.val >> 16);
609 phase1((u16 *)&ttkey[0], prwskey, &pattrib-> 610 phase1((u16 *)&ttkey[0], prwskey,
610 ta[0], pnh); 611 &pattrib->ta[0], pnh);
611 phase2(&rc4key[0], prwskey, (u16 *)&ttkey[0], 612 phase2(&rc4key[0], prwskey, (u16 *)&ttkey[0],
612 pnl); 613 pnl);
613 if ((curfragnum + 1) == pattrib->nr_frags) { 614 if ((curfragnum + 1) == pattrib->nr_frags) {
@@ -997,8 +998,9 @@ static void construct_mic_header2(u8 *mic_header2, u8 *mpdu, sint a4_exists,
997/* Builds the last MIC header block from */ 998/* Builds the last MIC header block from */
998/* header fields. */ 999/* header fields. */
999/************************************************/ 1000/************************************************/
1000static void construct_ctr_preload(u8 *ctr_preload, sint a4_exists, sint qc_exists, 1001static void construct_ctr_preload(u8 *ctr_preload,
1001 u8 *mpdu, u8 *pn_vector, sint c) 1002 sint a4_exists, sint qc_exists,
1003 u8 *mpdu, u8 *pn_vector, sint c)
1002{ 1004{
1003 sint i; 1005 sint i;
1004 1006
@@ -1067,16 +1069,16 @@ static sint aes_cipher(u8 *key, uint hdrlen,
1067 if ((frtype == WIFI_DATA_CFACK) || 1069 if ((frtype == WIFI_DATA_CFACK) ||
1068 (frtype == WIFI_DATA_CFPOLL) || 1070 (frtype == WIFI_DATA_CFPOLL) ||
1069 (frtype == WIFI_DATA_CFACKPOLL)) { 1071 (frtype == WIFI_DATA_CFACKPOLL)) {
1070 qc_exists = 1; 1072 qc_exists = 1;
1071 if (hdrlen != WLAN_HDR_A3_QOS_LEN) 1073 if (hdrlen != WLAN_HDR_A3_QOS_LEN)
1072 hdrlen += 2; 1074 hdrlen += 2;
1073 } else if ((frsubtype == 0x08) || 1075 } else if ((frsubtype == 0x08) ||
1074 (frsubtype == 0x09) || 1076 (frsubtype == 0x09) ||
1075 (frsubtype == 0x0a) || 1077 (frsubtype == 0x0a) ||
1076 (frsubtype == 0x0b)) { 1078 (frsubtype == 0x0b)) {
1077 if (hdrlen != WLAN_HDR_A3_QOS_LEN) 1079 if (hdrlen != WLAN_HDR_A3_QOS_LEN)
1078 hdrlen += 2; 1080 hdrlen += 2;
1079 qc_exists = 1; 1081 qc_exists = 1;
1080 } else { 1082 } else {
1081 qc_exists = 0; 1083 qc_exists = 0;
1082 } 1084 }
@@ -1184,15 +1186,15 @@ u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe)
1184 pattrib->hdrlen - 1186 pattrib->hdrlen -
1185 pattrib->iv_len - 1187 pattrib->iv_len -
1186 pattrib->icv_len; 1188 pattrib->icv_len;
1187 aes_cipher(prwskey, pattrib-> 1189 aes_cipher(prwskey, pattrib->hdrlen,
1188 hdrlen, pframe, length); 1190 pframe, length);
1189 } else { 1191 } else {
1190 length = pxmitpriv->frag_len - 1192 length = pxmitpriv->frag_len -
1191 pattrib->hdrlen - 1193 pattrib->hdrlen -
1192 pattrib->iv_len - 1194 pattrib->iv_len -
1193 pattrib->icv_len; 1195 pattrib->icv_len;
1194 aes_cipher(prwskey, pattrib-> 1196 aes_cipher(prwskey, pattrib->hdrlen,
1195 hdrlen, pframe, length); 1197 pframe, length);
1196 pframe += pxmitpriv->frag_len; 1198 pframe += pxmitpriv->frag_len;
1197 pframe = (u8 *)RND4((addr_t)(pframe)); 1199 pframe = (u8 *)RND4((addr_t)(pframe));
1198 } 1200 }
@@ -1405,7 +1407,7 @@ u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe)
1405void r8712_use_tkipkey_handler(struct timer_list *t) 1407void r8712_use_tkipkey_handler(struct timer_list *t)
1406{ 1408{
1407 struct _adapter *padapter = 1409 struct _adapter *padapter =
1408 from_timer(padapter, t, securitypriv.tkip_timer); 1410 from_timer(padapter, t, securitypriv.tkip_timer);
1409 1411
1410 padapter->securitypriv.busetkipkey = true; 1412 padapter->securitypriv.busetkipkey = true;
1411} 1413}
diff --git a/drivers/staging/rtl8712/usb_ops_linux.c b/drivers/staging/rtl8712/usb_ops_linux.c
index 441e76b8959d..6d12a96fa65f 100644
--- a/drivers/staging/rtl8712/usb_ops_linux.c
+++ b/drivers/staging/rtl8712/usb_ops_linux.c
@@ -145,7 +145,7 @@ static unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, u32 addr)
145 break; 145 break;
146 } 146 }
147 } else { 147 } else {
148 pipe = 0; 148 pipe = 0;
149 } 149 }
150 return pipe; 150 return pipe;
151} 151}
diff --git a/drivers/staging/rtl8723bs/core/rtw_cmd.c b/drivers/staging/rtl8723bs/core/rtw_cmd.c
index 9ac2dea6dff1..af0a9e0a00df 100644
--- a/drivers/staging/rtl8723bs/core/rtw_cmd.c
+++ b/drivers/staging/rtl8723bs/core/rtw_cmd.c
@@ -846,9 +846,7 @@ u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork)
846 846
847 psecnetwork = (struct wlan_bssid_ex *)&psecuritypriv->sec_bss; 847 psecnetwork = (struct wlan_bssid_ex *)&psecuritypriv->sec_bss;
848 if (psecnetwork == NULL) { 848 if (psecnetwork == NULL) {
849 if (pcmd != NULL) 849 kfree(pcmd);
850 kfree(pcmd);
851
852 res = _FAIL; 850 res = _FAIL;
853 851
854 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("rtw_joinbss_cmd :psecnetwork == NULL!!!\n")); 852 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("rtw_joinbss_cmd :psecnetwork == NULL!!!\n"));
diff --git a/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c b/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c
index c16e147d8adc..a99a863be656 100644
--- a/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c
+++ b/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c
@@ -1052,7 +1052,7 @@ static u8 phy_PathB_RxIQK8723B(struct adapter *padapter, bool configPathB)
1052 1052
1053 /* Check failed */ 1053 /* Check failed */
1054 regEAC = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_After_IQK_A_2, bMaskDWord); 1054 regEAC = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_After_IQK_A_2, bMaskDWord);
1055 regEA4 = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_Before_IQK_A_2, bMaskDWord);; 1055 regEA4 = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_Before_IQK_A_2, bMaskDWord);
1056 1056
1057 ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("0xeac = 0x%x\n", regEAC)); 1057 ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("0xeac = 0x%x\n", regEAC));
1058 ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("0xea4 = 0x%x, 0xeac = 0x%x\n", regEA4, regEAC)); 1058 ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("0xea4 = 0x%x, 0xeac = 0x%x\n", regEA4, regEAC));
diff --git a/drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c b/drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c
index f4619768a99f..334d680b9b1c 100644
--- a/drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c
+++ b/drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c
@@ -50,7 +50,7 @@ u8 HalPwrSeqCmdParsing(
50 WLAN_PWR_CFG PwrSeqCmd[] 50 WLAN_PWR_CFG PwrSeqCmd[]
51) 51)
52{ 52{
53 WLAN_PWR_CFG PwrCfgCmd = {0}; 53 WLAN_PWR_CFG PwrCfgCmd;
54 u8 bPollingBit = false; 54 u8 bPollingBit = false;
55 u32 AryIdx = 0; 55 u32 AryIdx = 0;
56 u8 value = 0; 56 u8 value = 0;
diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
index e6787c22e00b..93d6cc478706 100644
--- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
+++ b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
@@ -66,8 +66,7 @@ u8 PHY_GetTxPowerByRateBase(struct adapter *Adapter, u8 Band, u8 RfPath,
66 DBG_871X("Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n", 66 DBG_871X("Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n",
67 RateSection, RfPath, TxNum); 67 RateSection, RfPath, TxNum);
68 break; 68 break;
69 69 }
70 };
71 } else if (Band == BAND_ON_5G) { 70 } else if (Band == BAND_ON_5G) {
72 switch (RateSection) { 71 switch (RateSection) {
73 case OFDM: 72 case OFDM:
@@ -101,7 +100,7 @@ u8 PHY_GetTxPowerByRateBase(struct adapter *Adapter, u8 Band, u8 RfPath,
101 DBG_871X("Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n", 100 DBG_871X("Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n",
102 RateSection, RfPath, TxNum); 101 RateSection, RfPath, TxNum);
103 break; 102 break;
104 }; 103 }
105 } else 104 } else
106 DBG_871X("Invalid Band %d in PHY_GetTxPowerByRateBase()\n", Band); 105 DBG_871X("Invalid Band %d in PHY_GetTxPowerByRateBase()\n", Band);
107 106
@@ -161,7 +160,7 @@ phy_SetTxPowerByRateBase(
161 DBG_871X("Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in phy_SetTxPowerByRateBase()\n", 160 DBG_871X("Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in phy_SetTxPowerByRateBase()\n",
162 RateSection, RfPath, TxNum); 161 RateSection, RfPath, TxNum);
163 break; 162 break;
164 }; 163 }
165 } else if (Band == BAND_ON_5G) { 164 } else if (Band == BAND_ON_5G) {
166 switch (RateSection) { 165 switch (RateSection) {
167 case OFDM: 166 case OFDM:
@@ -195,7 +194,7 @@ phy_SetTxPowerByRateBase(
195 DBG_871X("Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in phy_SetTxPowerByRateBase()\n", 194 DBG_871X("Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in phy_SetTxPowerByRateBase()\n",
196 RateSection, RfPath, TxNum); 195 RateSection, RfPath, TxNum);
197 break; 196 break;
198 }; 197 }
199 } else 198 } else
200 DBG_871X("Invalid Band %d in phy_SetTxPowerByRateBase()\n", Band); 199 DBG_871X("Invalid Band %d in phy_SetTxPowerByRateBase()\n", Band);
201} 200}
@@ -336,7 +335,7 @@ u8 PHY_GetRateSectionIndexOfTxPowerByRate(
336 default: 335 default:
337 DBG_871X("Invalid RegAddr 0x3%x in PHY_GetRateSectionIndexOfTxPowerByRate()", RegAddr); 336 DBG_871X("Invalid RegAddr 0x3%x in PHY_GetRateSectionIndexOfTxPowerByRate()", RegAddr);
338 break; 337 break;
339 }; 338 }
340 } 339 }
341 340
342 return index; 341 return index;
@@ -726,7 +725,7 @@ PHY_GetRateValuesOfTxPowerByRate(
726 default: 725 default:
727 DBG_871X("Invalid RegAddr 0x%x in %s()\n", RegAddr, __func__); 726 DBG_871X("Invalid RegAddr 0x%x in %s()\n", RegAddr, __func__);
728 break; 727 break;
729 }; 728 }
730} 729}
731 730
732static void PHY_StoreTxPowerByRateNew( 731static void PHY_StoreTxPowerByRateNew(
@@ -1474,8 +1473,7 @@ u8 PHY_GetRateIndexOfTxPowerByRate(u8 Rate)
1474 default: 1473 default:
1475 DBG_871X("Invalid rate 0x%x in %s\n", Rate, __func__); 1474 DBG_871X("Invalid rate 0x%x in %s\n", Rate, __func__);
1476 break; 1475 break;
1477 }; 1476 }
1478
1479 return index; 1477 return index;
1480} 1478}
1481 1479
diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c b/drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c
index 21ec890fd60c..e34d133075c0 100644
--- a/drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c
+++ b/drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c
@@ -153,7 +153,7 @@ static u32 phy_RFSerialRead_8723B(
153 NewOffset = Offset; 153 NewOffset = Offset;
154 154
155 if (eRFPath == RF_PATH_A) { 155 if (eRFPath == RF_PATH_A) {
156 tmplong2 = PHY_QueryBBReg(Adapter, rFPGA0_XA_HSSIParameter2|MaskforPhySet, bMaskDWord);; 156 tmplong2 = PHY_QueryBBReg(Adapter, rFPGA0_XA_HSSIParameter2|MaskforPhySet, bMaskDWord);
157 tmplong2 = (tmplong2 & (~bLSSIReadAddress)) | (NewOffset<<23) | bLSSIReadEdge; /* T65 RF */ 157 tmplong2 = (tmplong2 & (~bLSSIReadAddress)) | (NewOffset<<23) | bLSSIReadEdge; /* T65 RF */
158 PHY_SetBBReg(Adapter, rFPGA0_XA_HSSIParameter2|MaskforPhySet, bMaskDWord, tmplong2&(~bLSSIReadEdge)); 158 PHY_SetBBReg(Adapter, rFPGA0_XA_HSSIParameter2|MaskforPhySet, bMaskDWord, tmplong2&(~bLSSIReadEdge));
159 } else { 159 } else {
diff --git a/drivers/staging/rtl8723bs/hal/sdio_ops.c b/drivers/staging/rtl8723bs/hal/sdio_ops.c
index 9a4c24861947..ab2ff53a8e57 100644
--- a/drivers/staging/rtl8723bs/hal/sdio_ops.c
+++ b/drivers/staging/rtl8723bs/hal/sdio_ops.c
@@ -28,35 +28,35 @@
28/* Creadted by Roger, 2011.01.31. */ 28/* Creadted by Roger, 2011.01.31. */
29/* */ 29/* */
30static void HalSdioGetCmdAddr8723BSdio( 30static void HalSdioGetCmdAddr8723BSdio(
31 struct adapter *padapter, 31 struct adapter *adapter,
32 u8 DeviceID, 32 u8 device_id,
33 u32 Addr, 33 u32 addr,
34 u32 *pCmdAddr 34 u32 *cmdaddr
35) 35)
36{ 36{
37 switch (DeviceID) { 37 switch (device_id) {
38 case SDIO_LOCAL_DEVICE_ID: 38 case SDIO_LOCAL_DEVICE_ID:
39 *pCmdAddr = ((SDIO_LOCAL_DEVICE_ID << 13) | (Addr & SDIO_LOCAL_MSK)); 39 *cmdaddr = ((SDIO_LOCAL_DEVICE_ID << 13) | (addr & SDIO_LOCAL_MSK));
40 break; 40 break;
41 41
42 case WLAN_IOREG_DEVICE_ID: 42 case WLAN_IOREG_DEVICE_ID:
43 *pCmdAddr = ((WLAN_IOREG_DEVICE_ID << 13) | (Addr & WLAN_IOREG_MSK)); 43 *cmdaddr = ((WLAN_IOREG_DEVICE_ID << 13) | (addr & WLAN_IOREG_MSK));
44 break; 44 break;
45 45
46 case WLAN_TX_HIQ_DEVICE_ID: 46 case WLAN_TX_HIQ_DEVICE_ID:
47 *pCmdAddr = ((WLAN_TX_HIQ_DEVICE_ID << 13) | (Addr & WLAN_FIFO_MSK)); 47 *cmdaddr = ((WLAN_TX_HIQ_DEVICE_ID << 13) | (addr & WLAN_FIFO_MSK));
48 break; 48 break;
49 49
50 case WLAN_TX_MIQ_DEVICE_ID: 50 case WLAN_TX_MIQ_DEVICE_ID:
51 *pCmdAddr = ((WLAN_TX_MIQ_DEVICE_ID << 13) | (Addr & WLAN_FIFO_MSK)); 51 *cmdaddr = ((WLAN_TX_MIQ_DEVICE_ID << 13) | (addr & WLAN_FIFO_MSK));
52 break; 52 break;
53 53
54 case WLAN_TX_LOQ_DEVICE_ID: 54 case WLAN_TX_LOQ_DEVICE_ID:
55 *pCmdAddr = ((WLAN_TX_LOQ_DEVICE_ID << 13) | (Addr & WLAN_FIFO_MSK)); 55 *cmdaddr = ((WLAN_TX_LOQ_DEVICE_ID << 13) | (addr & WLAN_FIFO_MSK));
56 break; 56 break;
57 57
58 case WLAN_RX0FF_DEVICE_ID: 58 case WLAN_RX0FF_DEVICE_ID:
59 *pCmdAddr = ((WLAN_RX0FF_DEVICE_ID << 13) | (Addr & WLAN_RX0FF_MSK)); 59 *cmdaddr = ((WLAN_RX0FF_DEVICE_ID << 13) | (addr & WLAN_RX0FF_MSK));
60 break; 60 break;
61 61
62 default: 62 default:
@@ -66,64 +66,64 @@ static void HalSdioGetCmdAddr8723BSdio(
66 66
67static u8 get_deviceid(u32 addr) 67static u8 get_deviceid(u32 addr)
68{ 68{
69 u8 devideId; 69 u8 devide_id;
70 u16 pseudoId; 70 u16 pseudo_id;
71 71
72 72
73 pseudoId = (u16)(addr >> 16); 73 pseudo_id = (u16)(addr >> 16);
74 switch (pseudoId) { 74 switch (pseudo_id) {
75 case 0x1025: 75 case 0x1025:
76 devideId = SDIO_LOCAL_DEVICE_ID; 76 devide_id = SDIO_LOCAL_DEVICE_ID;
77 break; 77 break;
78 78
79 case 0x1026: 79 case 0x1026:
80 devideId = WLAN_IOREG_DEVICE_ID; 80 devide_id = WLAN_IOREG_DEVICE_ID;
81 break; 81 break;
82 82
83/* case 0x1027: */ 83/* case 0x1027: */
84/* devideId = SDIO_FIRMWARE_FIFO; */ 84/* devide_id = SDIO_FIRMWARE_FIFO; */
85/* break; */ 85/* break; */
86 86
87 case 0x1031: 87 case 0x1031:
88 devideId = WLAN_TX_HIQ_DEVICE_ID; 88 devide_id = WLAN_TX_HIQ_DEVICE_ID;
89 break; 89 break;
90 90
91 case 0x1032: 91 case 0x1032:
92 devideId = WLAN_TX_MIQ_DEVICE_ID; 92 devide_id = WLAN_TX_MIQ_DEVICE_ID;
93 break; 93 break;
94 94
95 case 0x1033: 95 case 0x1033:
96 devideId = WLAN_TX_LOQ_DEVICE_ID; 96 devide_id = WLAN_TX_LOQ_DEVICE_ID;
97 break; 97 break;
98 98
99 case 0x1034: 99 case 0x1034:
100 devideId = WLAN_RX0FF_DEVICE_ID; 100 devide_id = WLAN_RX0FF_DEVICE_ID;
101 break; 101 break;
102 102
103 default: 103 default:
104/* devideId = (u8)((addr >> 13) & 0xF); */ 104/* devide_id = (u8)((addr >> 13) & 0xF); */
105 devideId = WLAN_IOREG_DEVICE_ID; 105 devide_id = WLAN_IOREG_DEVICE_ID;
106 break; 106 break;
107 } 107 }
108 108
109 return devideId; 109 return devide_id;
110} 110}
111 111
112/* 112/*
113 * Ref: 113 * Ref:
114 *HalSdioGetCmdAddr8723BSdio() 114 *HalSdioGetCmdAddr8723BSdio()
115 */ 115 */
116static u32 _cvrt2ftaddr(const u32 addr, u8 *pdeviceId, u16 *poffset) 116static u32 _cvrt2ftaddr(const u32 addr, u8 *pdevice_id, u16 *poffset)
117{ 117{
118 u8 deviceId; 118 u8 device_id;
119 u16 offset; 119 u16 offset;
120 u32 ftaddr; 120 u32 ftaddr;
121 121
122 122
123 deviceId = get_deviceid(addr); 123 device_id = get_deviceid(addr);
124 offset = 0; 124 offset = 0;
125 125
126 switch (deviceId) { 126 switch (device_id) {
127 case SDIO_LOCAL_DEVICE_ID: 127 case SDIO_LOCAL_DEVICE_ID:
128 offset = addr & SDIO_LOCAL_MSK; 128 offset = addr & SDIO_LOCAL_MSK;
129 break; 129 break;
@@ -140,47 +140,44 @@ static u32 _cvrt2ftaddr(const u32 addr, u8 *pdeviceId, u16 *poffset)
140 140
141 case WLAN_IOREG_DEVICE_ID: 141 case WLAN_IOREG_DEVICE_ID:
142 default: 142 default:
143 deviceId = WLAN_IOREG_DEVICE_ID; 143 device_id = WLAN_IOREG_DEVICE_ID;
144 offset = addr & WLAN_IOREG_MSK; 144 offset = addr & WLAN_IOREG_MSK;
145 break; 145 break;
146 } 146 }
147 ftaddr = (deviceId << 13) | offset; 147 ftaddr = (device_id << 13) | offset;
148 148
149 if (pdeviceId) 149 if (pdevice_id)
150 *pdeviceId = deviceId; 150 *pdevice_id = device_id;
151 if (poffset) 151 if (poffset)
152 *poffset = offset; 152 *poffset = offset;
153 153
154 return ftaddr; 154 return ftaddr;
155} 155}
156 156
157static u8 sdio_read8(struct intf_hdl *pintfhdl, u32 addr) 157static u8 sdio_read8(struct intf_hdl *intfhdl, u32 addr)
158{ 158{
159 u32 ftaddr; 159 u32 ftaddr;
160 u8 val;
161
162 ftaddr = _cvrt2ftaddr(addr, NULL, NULL); 160 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
163 val = sd_read8(pintfhdl, ftaddr, NULL); 161
164 return val; 162 return sd_read8(intfhdl, ftaddr, NULL);
165} 163}
166 164
167static u16 sdio_read16(struct intf_hdl *pintfhdl, u32 addr) 165static u16 sdio_read16(struct intf_hdl *intfhdl, u32 addr)
168{ 166{
169 u32 ftaddr; 167 u32 ftaddr;
170 u16 val;
171 __le16 le_tmp; 168 __le16 le_tmp;
172 169
173 ftaddr = _cvrt2ftaddr(addr, NULL, NULL); 170 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
174 sd_cmd52_read(pintfhdl, ftaddr, 2, (u8 *)&le_tmp); 171 sd_cmd52_read(intfhdl, ftaddr, 2, (u8 *)&le_tmp);
175 val = le16_to_cpu(le_tmp); 172
176 return val; 173 return le16_to_cpu(le_tmp);
177} 174}
178 175
179static u32 sdio_read32(struct intf_hdl *pintfhdl, u32 addr) 176static u32 sdio_read32(struct intf_hdl *intfhdl, u32 addr)
180{ 177{
181 struct adapter *padapter; 178 struct adapter *adapter;
182 u8 bMacPwrCtrlOn; 179 u8 mac_pwr_ctrl_on;
183 u8 deviceId; 180 u8 device_id;
184 u16 offset; 181 u16 offset;
185 u32 ftaddr; 182 u32 ftaddr;
186 u8 shift; 183 u8 shift;
@@ -188,21 +185,20 @@ static u32 sdio_read32(struct intf_hdl *pintfhdl, u32 addr)
188 s32 err; 185 s32 err;
189 __le32 le_tmp; 186 __le32 le_tmp;
190 187
191 padapter = pintfhdl->padapter; 188 adapter = intfhdl->padapter;
192 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset); 189 ftaddr = _cvrt2ftaddr(addr, &device_id, &offset);
193 190
194 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); 191 rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on);
195 if ( 192 if (
196 ((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100)) || 193 ((device_id == WLAN_IOREG_DEVICE_ID) && (offset < 0x100)) ||
197 (false == bMacPwrCtrlOn) || 194 (!mac_pwr_ctrl_on) ||
198 (true == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode) 195 (adapter_to_pwrctl(adapter)->bFwCurrentInPSMode)
199 ) { 196 ) {
200 err = sd_cmd52_read(pintfhdl, ftaddr, 4, (u8 *)&le_tmp); 197 err = sd_cmd52_read(intfhdl, ftaddr, 4, (u8 *)&le_tmp);
201#ifdef SDIO_DEBUG_IO 198#ifdef SDIO_DEBUG_IO
202 if (!err) { 199 if (!err) {
203#endif 200#endif
204 val = le32_to_cpu(le_tmp); 201 return le32_to_cpu(le_tmp);
205 return val;
206#ifdef SDIO_DEBUG_IO 202#ifdef SDIO_DEBUG_IO
207 } 203 }
208 204
@@ -214,191 +210,184 @@ static u32 sdio_read32(struct intf_hdl *pintfhdl, u32 addr)
214 /* 4 bytes alignment */ 210 /* 4 bytes alignment */
215 shift = ftaddr & 0x3; 211 shift = ftaddr & 0x3;
216 if (shift == 0) { 212 if (shift == 0) {
217 val = sd_read32(pintfhdl, ftaddr, NULL); 213 val = sd_read32(intfhdl, ftaddr, NULL);
218 } else { 214 } else {
219 u8 *ptmpbuf; 215 u8 *tmpbuf;
220 216
221 ptmpbuf = rtw_malloc(8); 217 tmpbuf = rtw_malloc(8);
222 if (NULL == ptmpbuf) { 218 if (!tmpbuf) {
223 DBG_8192C(KERN_ERR "%s: Allocate memory FAIL!(size =8) addr = 0x%x\n", __func__, addr); 219 DBG_8192C(KERN_ERR "%s: Allocate memory FAIL!(size =8) addr = 0x%x\n", __func__, addr);
224 return SDIO_ERR_VAL32; 220 return SDIO_ERR_VAL32;
225 } 221 }
226 222
227 ftaddr &= ~(u16)0x3; 223 ftaddr &= ~(u16)0x3;
228 sd_read(pintfhdl, ftaddr, 8, ptmpbuf); 224 sd_read(intfhdl, ftaddr, 8, tmpbuf);
229 memcpy(&le_tmp, ptmpbuf+shift, 4); 225 memcpy(&le_tmp, tmpbuf+shift, 4);
230 val = le32_to_cpu(le_tmp); 226 val = le32_to_cpu(le_tmp);
231 227
232 kfree(ptmpbuf); 228 kfree(tmpbuf);
233 } 229 }
234 return val; 230 return val;
235} 231}
236 232
237static s32 sdio_readN(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pbuf) 233static s32 sdio_readN(struct intf_hdl *intfhdl, u32 addr, u32 cnt, u8 *buf)
238{ 234{
239 struct adapter *padapter; 235 struct adapter *adapter;
240 u8 bMacPwrCtrlOn; 236 u8 mac_pwr_ctrl_on;
241 u8 deviceId; 237 u8 device_id;
242 u16 offset; 238 u16 offset;
243 u32 ftaddr; 239 u32 ftaddr;
244 u8 shift; 240 u8 shift;
245 s32 err; 241 s32 err;
246 242
247 padapter = pintfhdl->padapter; 243 adapter = intfhdl->padapter;
248 err = 0; 244 err = 0;
249 245
250 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset); 246 ftaddr = _cvrt2ftaddr(addr, &device_id, &offset);
251 247
252 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); 248 rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on);
253 if ( 249 if (
254 ((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100)) || 250 ((device_id == WLAN_IOREG_DEVICE_ID) && (offset < 0x100)) ||
255 (false == bMacPwrCtrlOn) || 251 (!mac_pwr_ctrl_on) ||
256 (true == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode) 252 (adapter_to_pwrctl(adapter)->bFwCurrentInPSMode)
257 ) { 253 )
258 err = sd_cmd52_read(pintfhdl, ftaddr, cnt, pbuf); 254 return sd_cmd52_read(intfhdl, ftaddr, cnt, buf);
259 return err;
260 }
261 255
262 /* 4 bytes alignment */ 256 /* 4 bytes alignment */
263 shift = ftaddr & 0x3; 257 shift = ftaddr & 0x3;
264 if (shift == 0) { 258 if (shift == 0) {
265 err = sd_read(pintfhdl, ftaddr, cnt, pbuf); 259 err = sd_read(intfhdl, ftaddr, cnt, buf);
266 } else { 260 } else {
267 u8 *ptmpbuf; 261 u8 *tmpbuf;
268 u32 n; 262 u32 n;
269 263
270 ftaddr &= ~(u16)0x3; 264 ftaddr &= ~(u16)0x3;
271 n = cnt + shift; 265 n = cnt + shift;
272 ptmpbuf = rtw_malloc(n); 266 tmpbuf = rtw_malloc(n);
273 if (NULL == ptmpbuf) 267 if (!tmpbuf)
274 return -1; 268 return -1;
275 269
276 err = sd_read(pintfhdl, ftaddr, n, ptmpbuf); 270 err = sd_read(intfhdl, ftaddr, n, tmpbuf);
277 if (!err) 271 if (!err)
278 memcpy(pbuf, ptmpbuf+shift, cnt); 272 memcpy(buf, tmpbuf+shift, cnt);
279 kfree(ptmpbuf); 273 kfree(tmpbuf);
280 } 274 }
281 return err; 275 return err;
282} 276}
283 277
284static s32 sdio_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val) 278static s32 sdio_write8(struct intf_hdl *intfhdl, u32 addr, u8 val)
285{ 279{
286 u32 ftaddr; 280 u32 ftaddr;
287 s32 err; 281 s32 err;
288 282
289 ftaddr = _cvrt2ftaddr(addr, NULL, NULL); 283 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
290 sd_write8(pintfhdl, ftaddr, val, &err); 284 sd_write8(intfhdl, ftaddr, val, &err);
291 285
292 return err; 286 return err;
293} 287}
294 288
295static s32 sdio_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val) 289static s32 sdio_write16(struct intf_hdl *intfhdl, u32 addr, u16 val)
296{ 290{
297 u32 ftaddr; 291 u32 ftaddr;
298 s32 err;
299 __le16 le_tmp; 292 __le16 le_tmp;
300 293
301 ftaddr = _cvrt2ftaddr(addr, NULL, NULL); 294 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
302 le_tmp = cpu_to_le16(val); 295 le_tmp = cpu_to_le16(val);
303 err = sd_cmd52_write(pintfhdl, ftaddr, 2, (u8 *)&le_tmp); 296 return sd_cmd52_write(intfhdl, ftaddr, 2, (u8 *)&le_tmp);
304
305 return err;
306} 297}
307 298
308static s32 sdio_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val) 299static s32 sdio_write32(struct intf_hdl *intfhdl, u32 addr, u32 val)
309{ 300{
310 struct adapter *padapter; 301 struct adapter *adapter;
311 u8 bMacPwrCtrlOn; 302 u8 mac_pwr_ctrl_on;
312 u8 deviceId; 303 u8 device_id;
313 u16 offset; 304 u16 offset;
314 u32 ftaddr; 305 u32 ftaddr;
315 u8 shift; 306 u8 shift;
316 s32 err; 307 s32 err;
317 __le32 le_tmp; 308 __le32 le_tmp;
318 309
319 padapter = pintfhdl->padapter; 310 adapter = intfhdl->padapter;
320 err = 0; 311 err = 0;
321 312
322 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset); 313 ftaddr = _cvrt2ftaddr(addr, &device_id, &offset);
323 314
324 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); 315 rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on);
325 if ( 316 if (
326 ((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100)) || 317 ((device_id == WLAN_IOREG_DEVICE_ID) && (offset < 0x100)) ||
327 (!bMacPwrCtrlOn) || 318 (!mac_pwr_ctrl_on) ||
328 (adapter_to_pwrctl(padapter)->bFwCurrentInPSMode) 319 (adapter_to_pwrctl(adapter)->bFwCurrentInPSMode)
329 ) { 320 ) {
330 le_tmp = cpu_to_le32(val); 321 le_tmp = cpu_to_le32(val);
331 err = sd_cmd52_write(pintfhdl, ftaddr, 4, (u8 *)&le_tmp); 322
332 return err; 323 return sd_cmd52_write(intfhdl, ftaddr, 4, (u8 *)&le_tmp);
333 } 324 }
334 325
335 /* 4 bytes alignment */ 326 /* 4 bytes alignment */
336 shift = ftaddr & 0x3; 327 shift = ftaddr & 0x3;
337 if (shift == 0) { 328 if (shift == 0) {
338 sd_write32(pintfhdl, ftaddr, val, &err); 329 sd_write32(intfhdl, ftaddr, val, &err);
339 } else { 330 } else {
340 le_tmp = cpu_to_le32(val); 331 le_tmp = cpu_to_le32(val);
341 err = sd_cmd52_write(pintfhdl, ftaddr, 4, (u8 *)&le_tmp); 332 err = sd_cmd52_write(intfhdl, ftaddr, 4, (u8 *)&le_tmp);
342 } 333 }
343 return err; 334 return err;
344} 335}
345 336
346static s32 sdio_writeN(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pbuf) 337static s32 sdio_writeN(struct intf_hdl *intfhdl, u32 addr, u32 cnt, u8 *buf)
347{ 338{
348 struct adapter *padapter; 339 struct adapter *adapter;
349 u8 bMacPwrCtrlOn; 340 u8 mac_pwr_ctrl_on;
350 u8 deviceId; 341 u8 device_id;
351 u16 offset; 342 u16 offset;
352 u32 ftaddr; 343 u32 ftaddr;
353 u8 shift; 344 u8 shift;
354 s32 err; 345 s32 err;
355 346
356 padapter = pintfhdl->padapter; 347 adapter = intfhdl->padapter;
357 err = 0; 348 err = 0;
358 349
359 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset); 350 ftaddr = _cvrt2ftaddr(addr, &device_id, &offset);
360 351
361 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); 352 rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on);
362 if ( 353 if (
363 ((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100)) || 354 ((device_id == WLAN_IOREG_DEVICE_ID) && (offset < 0x100)) ||
364 (false == bMacPwrCtrlOn) || 355 (!mac_pwr_ctrl_on) ||
365 (true == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode) 356 (adapter_to_pwrctl(adapter)->bFwCurrentInPSMode)
366 ) { 357 )
367 err = sd_cmd52_write(pintfhdl, ftaddr, cnt, pbuf); 358 return sd_cmd52_write(intfhdl, ftaddr, cnt, buf);
368 return err;
369 }
370 359
371 shift = ftaddr & 0x3; 360 shift = ftaddr & 0x3;
372 if (shift == 0) { 361 if (shift == 0) {
373 err = sd_write(pintfhdl, ftaddr, cnt, pbuf); 362 err = sd_write(intfhdl, ftaddr, cnt, buf);
374 } else { 363 } else {
375 u8 *ptmpbuf; 364 u8 *tmpbuf;
376 u32 n; 365 u32 n;
377 366
378 ftaddr &= ~(u16)0x3; 367 ftaddr &= ~(u16)0x3;
379 n = cnt + shift; 368 n = cnt + shift;
380 ptmpbuf = rtw_malloc(n); 369 tmpbuf = rtw_malloc(n);
381 if (NULL == ptmpbuf) 370 if (!tmpbuf)
382 return -1; 371 return -1;
383 err = sd_read(pintfhdl, ftaddr, 4, ptmpbuf); 372 err = sd_read(intfhdl, ftaddr, 4, tmpbuf);
384 if (err) { 373 if (err) {
385 kfree(ptmpbuf); 374 kfree(tmpbuf);
386 return err; 375 return err;
387 } 376 }
388 memcpy(ptmpbuf+shift, pbuf, cnt); 377 memcpy(tmpbuf+shift, buf, cnt);
389 err = sd_write(pintfhdl, ftaddr, n, ptmpbuf); 378 err = sd_write(intfhdl, ftaddr, n, tmpbuf);
390 kfree(ptmpbuf); 379 kfree(tmpbuf);
391 } 380 }
392 return err; 381 return err;
393} 382}
394 383
395static u8 sdio_f0_read8(struct intf_hdl *pintfhdl, u32 addr) 384static u8 sdio_f0_read8(struct intf_hdl *intfhdl, u32 addr)
396{ 385{
397 return sd_f0_read8(pintfhdl, addr, NULL); 386 return sd_f0_read8(intfhdl, addr, NULL);
398} 387}
399 388
400static void sdio_read_mem( 389static void sdio_read_mem(
401 struct intf_hdl *pintfhdl, 390 struct intf_hdl *intfhdl,
402 u32 addr, 391 u32 addr,
403 u32 cnt, 392 u32 cnt,
404 u8 *rmem 393 u8 *rmem
@@ -406,18 +395,18 @@ static void sdio_read_mem(
406{ 395{
407 s32 err; 396 s32 err;
408 397
409 err = sdio_readN(pintfhdl, addr, cnt, rmem); 398 err = sdio_readN(intfhdl, addr, cnt, rmem);
410 /* TODO: Report error is err not zero */ 399 /* TODO: Report error is err not zero */
411} 400}
412 401
413static void sdio_write_mem( 402static void sdio_write_mem(
414 struct intf_hdl *pintfhdl, 403 struct intf_hdl *intfhdl,
415 u32 addr, 404 u32 addr,
416 u32 cnt, 405 u32 cnt,
417 u8 *wmem 406 u8 *wmem
418) 407)
419{ 408{
420 sdio_writeN(pintfhdl, addr, cnt, wmem); 409 sdio_writeN(intfhdl, addr, cnt, wmem);
421} 410}
422 411
423/* 412/*
@@ -427,7 +416,7 @@ static void sdio_write_mem(
427 *and make sure data transfer will be done in one command. 416 *and make sure data transfer will be done in one command.
428 * 417 *
429 * Parameters: 418 * Parameters:
430 *pintfhdl a pointer of intf_hdl 419 *intfhdl a pointer of intf_hdl
431 *addr port ID 420 *addr port ID
432 *cnt size to read 421 *cnt size to read
433 *rmem address to put data 422 *rmem address to put data
@@ -437,15 +426,15 @@ static void sdio_write_mem(
437 *_FAIL(0) Fail 426 *_FAIL(0) Fail
438 */ 427 */
439static u32 sdio_read_port( 428static u32 sdio_read_port(
440 struct intf_hdl *pintfhdl, 429 struct intf_hdl *intfhdl,
441 u32 addr, 430 u32 addr,
442 u32 cnt, 431 u32 cnt,
443 u8 *mem 432 u8 *mem
444) 433)
445{ 434{
446 struct adapter *padapter; 435 struct adapter *adapter;
447 PSDIO_DATA psdio; 436 PSDIO_DATA psdio;
448 struct hal_com_data *phal; 437 struct hal_com_data *hal;
449 u32 oldcnt; 438 u32 oldcnt;
450#ifdef SDIO_DYNAMIC_ALLOC_MEM 439#ifdef SDIO_DYNAMIC_ALLOC_MEM
451 u8 *oldmem; 440 u8 *oldmem;
@@ -453,33 +442,18 @@ static u32 sdio_read_port(
453 s32 err; 442 s32 err;
454 443
455 444
456 padapter = pintfhdl->padapter; 445 adapter = intfhdl->padapter;
457 psdio = &adapter_to_dvobj(padapter)->intf_data; 446 psdio = &adapter_to_dvobj(adapter)->intf_data;
458 phal = GET_HAL_DATA(padapter); 447 hal = GET_HAL_DATA(adapter);
459 448
460 HalSdioGetCmdAddr8723BSdio(padapter, addr, phal->SdioRxFIFOCnt++, &addr); 449 HalSdioGetCmdAddr8723BSdio(adapter, addr, hal->SdioRxFIFOCnt++, &addr);
461 450
462 oldcnt = cnt; 451 oldcnt = cnt;
463 if (cnt > psdio->block_transfer_len) 452 if (cnt > psdio->block_transfer_len)
464 cnt = _RND(cnt, psdio->block_transfer_len); 453 cnt = _RND(cnt, psdio->block_transfer_len);
465/* cnt = sdio_align_size(cnt); */ 454/* cnt = sdio_align_size(cnt); */
466 455
467 if (oldcnt != cnt) { 456 err = _sd_read(intfhdl, addr, cnt, mem);
468#ifdef SDIO_DYNAMIC_ALLOC_MEM
469 oldmem = mem;
470 mem = rtw_malloc(cnt);
471 if (mem == NULL) {
472 DBG_8192C(KERN_WARNING "%s: allocate memory %d bytes fail!\n", __func__, cnt);
473 mem = oldmem;
474 oldmem == NULL;
475 }
476#else
477 /* in this case, caller should gurante the buffer is big enough */
478 /* to receive data after alignment */
479#endif
480 }
481
482 err = _sd_read(pintfhdl, addr, cnt, mem);
483 457
484#ifdef SDIO_DYNAMIC_ALLOC_MEM 458#ifdef SDIO_DYNAMIC_ALLOC_MEM
485 if ((oldcnt != cnt) && (oldmem)) { 459 if ((oldcnt != cnt) && (oldmem)) {
@@ -500,7 +474,7 @@ static u32 sdio_read_port(
500 *and make sure data could be written in one command. 474 *and make sure data could be written in one command.
501 * 475 *
502 * Parameters: 476 * Parameters:
503 *pintfhdl a pointer of intf_hdl 477 *intfhdl a pointer of intf_hdl
504 *addr port ID 478 *addr port ID
505 *cnt size to write 479 *cnt size to write
506 *wmem data pointer to write 480 *wmem data pointer to write
@@ -510,33 +484,33 @@ static u32 sdio_read_port(
510 *_FAIL(0) Fail 484 *_FAIL(0) Fail
511 */ 485 */
512static u32 sdio_write_port( 486static u32 sdio_write_port(
513 struct intf_hdl *pintfhdl, 487 struct intf_hdl *intfhdl,
514 u32 addr, 488 u32 addr,
515 u32 cnt, 489 u32 cnt,
516 u8 *mem 490 u8 *mem
517) 491)
518{ 492{
519 struct adapter *padapter; 493 struct adapter *adapter;
520 PSDIO_DATA psdio; 494 PSDIO_DATA psdio;
521 s32 err; 495 s32 err;
522 struct xmit_buf *xmitbuf = (struct xmit_buf *)mem; 496 struct xmit_buf *xmitbuf = (struct xmit_buf *)mem;
523 497
524 padapter = pintfhdl->padapter; 498 adapter = intfhdl->padapter;
525 psdio = &adapter_to_dvobj(padapter)->intf_data; 499 psdio = &adapter_to_dvobj(adapter)->intf_data;
526 500
527 if (padapter->hw_init_completed == false) { 501 if (!adapter->hw_init_completed) {
528 DBG_871X("%s [addr = 0x%x cnt =%d] padapter->hw_init_completed == false\n", __func__, addr, cnt); 502 DBG_871X("%s [addr = 0x%x cnt =%d] adapter->hw_init_completed == false\n", __func__, addr, cnt);
529 return _FAIL; 503 return _FAIL;
530 } 504 }
531 505
532 cnt = _RND4(cnt); 506 cnt = _RND4(cnt);
533 HalSdioGetCmdAddr8723BSdio(padapter, addr, cnt >> 2, &addr); 507 HalSdioGetCmdAddr8723BSdio(adapter, addr, cnt >> 2, &addr);
534 508
535 if (cnt > psdio->block_transfer_len) 509 if (cnt > psdio->block_transfer_len)
536 cnt = _RND(cnt, psdio->block_transfer_len); 510 cnt = _RND(cnt, psdio->block_transfer_len);
537/* cnt = sdio_align_size(cnt); */ 511/* cnt = sdio_align_size(cnt); */
538 512
539 err = sd_write(pintfhdl, addr, cnt, xmitbuf->pdata); 513 err = sd_write(intfhdl, addr, cnt, xmitbuf->pdata);
540 514
541 rtw_sctx_done_err( 515 rtw_sctx_done_err(
542 &xmitbuf->sctx, 516 &xmitbuf->sctx,
@@ -548,61 +522,59 @@ static u32 sdio_write_port(
548 return _SUCCESS; 522 return _SUCCESS;
549} 523}
550 524
551void sdio_set_intf_ops(struct adapter *padapter, struct _io_ops *pops) 525void sdio_set_intf_ops(struct adapter *adapter, struct _io_ops *ops)
552{ 526{
553 pops->_read8 = &sdio_read8; 527 ops->_read8 = &sdio_read8;
554 pops->_read16 = &sdio_read16; 528 ops->_read16 = &sdio_read16;
555 pops->_read32 = &sdio_read32; 529 ops->_read32 = &sdio_read32;
556 pops->_read_mem = &sdio_read_mem; 530 ops->_read_mem = &sdio_read_mem;
557 pops->_read_port = &sdio_read_port; 531 ops->_read_port = &sdio_read_port;
558 532
559 pops->_write8 = &sdio_write8; 533 ops->_write8 = &sdio_write8;
560 pops->_write16 = &sdio_write16; 534 ops->_write16 = &sdio_write16;
561 pops->_write32 = &sdio_write32; 535 ops->_write32 = &sdio_write32;
562 pops->_writeN = &sdio_writeN; 536 ops->_writeN = &sdio_writeN;
563 pops->_write_mem = &sdio_write_mem; 537 ops->_write_mem = &sdio_write_mem;
564 pops->_write_port = &sdio_write_port; 538 ops->_write_port = &sdio_write_port;
565 539
566 pops->_sd_f0_read8 = sdio_f0_read8; 540 ops->_sd_f0_read8 = sdio_f0_read8;
567} 541}
568 542
569/* 543/*
570 * Todo: align address to 4 bytes. 544 * Todo: align address to 4 bytes.
571 */ 545 */
572static s32 _sdio_local_read( 546static s32 _sdio_local_read(
573 struct adapter *padapter, 547 struct adapter *adapter,
574 u32 addr, 548 u32 addr,
575 u32 cnt, 549 u32 cnt,
576 u8 *pbuf 550 u8 *buf
577) 551)
578{ 552{
579 struct intf_hdl *pintfhdl; 553 struct intf_hdl *intfhdl;
580 u8 bMacPwrCtrlOn; 554 u8 mac_pwr_ctrl_on;
581 s32 err; 555 s32 err;
582 u8 *ptmpbuf; 556 u8 *tmpbuf;
583 u32 n; 557 u32 n;
584 558
585 559
586 pintfhdl = &padapter->iopriv.intf; 560 intfhdl = &adapter->iopriv.intf;
587 561
588 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); 562 HalSdioGetCmdAddr8723BSdio(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
589 563
590 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); 564 rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on);
591 if (false == bMacPwrCtrlOn) { 565 if (!mac_pwr_ctrl_on)
592 err = _sd_cmd52_read(pintfhdl, addr, cnt, pbuf); 566 return _sd_cmd52_read(intfhdl, addr, cnt, buf);
593 return err;
594 }
595 567
596 n = RND4(cnt); 568 n = RND4(cnt);
597 ptmpbuf = rtw_malloc(n); 569 tmpbuf = rtw_malloc(n);
598 if (!ptmpbuf) 570 if (!tmpbuf)
599 return (-1); 571 return (-1);
600 572
601 err = _sd_read(pintfhdl, addr, n, ptmpbuf); 573 err = _sd_read(intfhdl, addr, n, tmpbuf);
602 if (!err) 574 if (!err)
603 memcpy(pbuf, ptmpbuf, cnt); 575 memcpy(buf, tmpbuf, cnt);
604 576
605 kfree(ptmpbuf); 577 kfree(tmpbuf);
606 578
607 return err; 579 return err;
608} 580}
@@ -611,41 +583,39 @@ static s32 _sdio_local_read(
611 * Todo: align address to 4 bytes. 583 * Todo: align address to 4 bytes.
612 */ 584 */
613s32 sdio_local_read( 585s32 sdio_local_read(
614 struct adapter *padapter, 586 struct adapter *adapter,
615 u32 addr, 587 u32 addr,
616 u32 cnt, 588 u32 cnt,
617 u8 *pbuf 589 u8 *buf
618) 590)
619{ 591{
620 struct intf_hdl *pintfhdl; 592 struct intf_hdl *intfhdl;
621 u8 bMacPwrCtrlOn; 593 u8 mac_pwr_ctrl_on;
622 s32 err; 594 s32 err;
623 u8 *ptmpbuf; 595 u8 *tmpbuf;
624 u32 n; 596 u32 n;
625 597
626 pintfhdl = &padapter->iopriv.intf; 598 intfhdl = &adapter->iopriv.intf;
627 599
628 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); 600 HalSdioGetCmdAddr8723BSdio(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
629 601
630 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); 602 rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on);
631 if ( 603 if (
632 (false == bMacPwrCtrlOn) || 604 (!mac_pwr_ctrl_on) ||
633 (true == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode) 605 (adapter_to_pwrctl(adapter)->bFwCurrentInPSMode)
634 ) { 606 )
635 err = sd_cmd52_read(pintfhdl, addr, cnt, pbuf); 607 return sd_cmd52_read(intfhdl, addr, cnt, buf);
636 return err;
637 }
638 608
639 n = RND4(cnt); 609 n = RND4(cnt);
640 ptmpbuf = rtw_malloc(n); 610 tmpbuf = rtw_malloc(n);
641 if (!ptmpbuf) 611 if (!tmpbuf)
642 return (-1); 612 return (-1);
643 613
644 err = sd_read(pintfhdl, addr, n, ptmpbuf); 614 err = sd_read(intfhdl, addr, n, tmpbuf);
645 if (!err) 615 if (!err)
646 memcpy(pbuf, ptmpbuf, cnt); 616 memcpy(buf, tmpbuf, cnt);
647 617
648 kfree(ptmpbuf); 618 kfree(tmpbuf);
649 619
650 return err; 620 return err;
651} 621}
@@ -654,16 +624,16 @@ s32 sdio_local_read(
654 * Todo: align address to 4 bytes. 624 * Todo: align address to 4 bytes.
655 */ 625 */
656s32 sdio_local_write( 626s32 sdio_local_write(
657 struct adapter *padapter, 627 struct adapter *adapter,
658 u32 addr, 628 u32 addr,
659 u32 cnt, 629 u32 cnt,
660 u8 *pbuf 630 u8 *buf
661) 631)
662{ 632{
663 struct intf_hdl *pintfhdl; 633 struct intf_hdl *intfhdl;
664 u8 bMacPwrCtrlOn; 634 u8 mac_pwr_ctrl_on;
665 s32 err; 635 s32 err;
666 u8 *ptmpbuf; 636 u8 *tmpbuf;
667 637
668 if (addr & 0x3) 638 if (addr & 0x3)
669 DBG_8192C("%s, address must be 4 bytes alignment\n", __func__); 639 DBG_8192C("%s, address must be 4 bytes alignment\n", __func__);
@@ -671,101 +641,99 @@ s32 sdio_local_write(
671 if (cnt & 0x3) 641 if (cnt & 0x3)
672 DBG_8192C("%s, size must be the multiple of 4\n", __func__); 642 DBG_8192C("%s, size must be the multiple of 4\n", __func__);
673 643
674 pintfhdl = &padapter->iopriv.intf; 644 intfhdl = &adapter->iopriv.intf;
675 645
676 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); 646 HalSdioGetCmdAddr8723BSdio(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
677 647
678 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); 648 rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on);
679 if ( 649 if (
680 (false == bMacPwrCtrlOn) || 650 (!mac_pwr_ctrl_on) ||
681 (true == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode) 651 (adapter_to_pwrctl(adapter)->bFwCurrentInPSMode)
682 ) { 652 )
683 err = sd_cmd52_write(pintfhdl, addr, cnt, pbuf); 653 return sd_cmd52_write(intfhdl, addr, cnt, buf);
684 return err;
685 }
686 654
687 ptmpbuf = rtw_malloc(cnt); 655 tmpbuf = rtw_malloc(cnt);
688 if (!ptmpbuf) 656 if (!tmpbuf)
689 return (-1); 657 return (-1);
690 658
691 memcpy(ptmpbuf, pbuf, cnt); 659 memcpy(tmpbuf, buf, cnt);
692 660
693 err = sd_write(pintfhdl, addr, cnt, ptmpbuf); 661 err = sd_write(intfhdl, addr, cnt, tmpbuf);
694 662
695 kfree(ptmpbuf); 663 kfree(tmpbuf);
696 664
697 return err; 665 return err;
698} 666}
699 667
700u8 SdioLocalCmd52Read1Byte(struct adapter *padapter, u32 addr) 668u8 SdioLocalCmd52Read1Byte(struct adapter *adapter, u32 addr)
701{ 669{
702 u8 val = 0; 670 u8 val = 0;
703 struct intf_hdl *pintfhdl = &padapter->iopriv.intf; 671 struct intf_hdl *intfhdl = &adapter->iopriv.intf;
704 672
705 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); 673 HalSdioGetCmdAddr8723BSdio(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
706 sd_cmd52_read(pintfhdl, addr, 1, &val); 674 sd_cmd52_read(intfhdl, addr, 1, &val);
707 675
708 return val; 676 return val;
709} 677}
710 678
711static u16 SdioLocalCmd52Read2Byte(struct adapter *padapter, u32 addr) 679static u16 SdioLocalCmd52Read2Byte(struct adapter *adapter, u32 addr)
712{ 680{
713 __le16 val = 0; 681 __le16 val = 0;
714 struct intf_hdl *pintfhdl = &padapter->iopriv.intf; 682 struct intf_hdl *intfhdl = &adapter->iopriv.intf;
715 683
716 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); 684 HalSdioGetCmdAddr8723BSdio(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
717 sd_cmd52_read(pintfhdl, addr, 2, (u8 *)&val); 685 sd_cmd52_read(intfhdl, addr, 2, (u8 *)&val);
718 686
719 return le16_to_cpu(val); 687 return le16_to_cpu(val);
720} 688}
721 689
722static u32 SdioLocalCmd53Read4Byte(struct adapter *padapter, u32 addr) 690static u32 SdioLocalCmd53Read4Byte(struct adapter *adapter, u32 addr)
723{ 691{
724 692
725 u8 bMacPwrCtrlOn; 693 u8 mac_pwr_ctrl_on;
726 u32 val = 0; 694 u32 val = 0;
727 struct intf_hdl *pintfhdl = &padapter->iopriv.intf; 695 struct intf_hdl *intfhdl = &adapter->iopriv.intf;
728 __le32 le_tmp; 696 __le32 le_tmp;
729 697
730 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); 698 HalSdioGetCmdAddr8723BSdio(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
731 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); 699 rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on);
732 if (!bMacPwrCtrlOn || adapter_to_pwrctl(padapter)->bFwCurrentInPSMode) { 700 if (!mac_pwr_ctrl_on || adapter_to_pwrctl(adapter)->bFwCurrentInPSMode) {
733 sd_cmd52_read(pintfhdl, addr, 4, (u8 *)&le_tmp); 701 sd_cmd52_read(intfhdl, addr, 4, (u8 *)&le_tmp);
734 val = le32_to_cpu(le_tmp); 702 val = le32_to_cpu(le_tmp);
735 } else { 703 } else {
736 val = sd_read32(pintfhdl, addr, NULL); 704 val = sd_read32(intfhdl, addr, NULL);
737 } 705 }
738 return val; 706 return val;
739} 707}
740 708
741void SdioLocalCmd52Write1Byte(struct adapter *padapter, u32 addr, u8 v) 709void SdioLocalCmd52Write1Byte(struct adapter *adapter, u32 addr, u8 v)
742{ 710{
743 struct intf_hdl *pintfhdl = &padapter->iopriv.intf; 711 struct intf_hdl *intfhdl = &adapter->iopriv.intf;
744 712
745 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); 713 HalSdioGetCmdAddr8723BSdio(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
746 sd_cmd52_write(pintfhdl, addr, 1, &v); 714 sd_cmd52_write(intfhdl, addr, 1, &v);
747} 715}
748 716
749static void SdioLocalCmd52Write4Byte(struct adapter *padapter, u32 addr, u32 v) 717static void SdioLocalCmd52Write4Byte(struct adapter *adapter, u32 addr, u32 v)
750{ 718{
751 struct intf_hdl *pintfhdl = &padapter->iopriv.intf; 719 struct intf_hdl *intfhdl = &adapter->iopriv.intf;
752 __le32 le_tmp; 720 __le32 le_tmp;
753 721
754 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); 722 HalSdioGetCmdAddr8723BSdio(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
755 le_tmp = cpu_to_le32(v); 723 le_tmp = cpu_to_le32(v);
756 sd_cmd52_write(pintfhdl, addr, 4, (u8 *)&le_tmp); 724 sd_cmd52_write(intfhdl, addr, 4, (u8 *)&le_tmp);
757} 725}
758 726
759static s32 ReadInterrupt8723BSdio(struct adapter *padapter, u32 *phisr) 727static s32 ReadInterrupt8723BSdio(struct adapter *adapter, u32 *phisr)
760{ 728{
761 u32 hisr, himr; 729 u32 hisr, himr;
762 u8 val8, hisr_len; 730 u8 val8, hisr_len;
763 731
764 732
765 if (phisr == NULL) 733 if (!phisr)
766 return false; 734 return false;
767 735
768 himr = GET_HAL_DATA(padapter)->sdio_himr; 736 himr = GET_HAL_DATA(adapter)->sdio_himr;
769 737
770 /* decide how many bytes need to be read */ 738 /* decide how many bytes need to be read */
771 hisr_len = 0; 739 hisr_len = 0;
@@ -777,7 +745,7 @@ static s32 ReadInterrupt8723BSdio(struct adapter *padapter, u32 *phisr)
777 hisr = 0; 745 hisr = 0;
778 while (hisr_len != 0) { 746 while (hisr_len != 0) {
779 hisr_len--; 747 hisr_len--;
780 val8 = SdioLocalCmd52Read1Byte(padapter, SDIO_REG_HISR+hisr_len); 748 val8 = SdioLocalCmd52Read1Byte(adapter, SDIO_REG_HISR+hisr_len);
781 hisr |= (val8 << (8*hisr_len)); 749 hisr |= (val8 << (8*hisr_len));
782 } 750 }
783 751
@@ -795,13 +763,13 @@ static s32 ReadInterrupt8723BSdio(struct adapter *padapter, u32 *phisr)
795/* */ 763/* */
796/* Created by Roger, 2011.02.11. */ 764/* Created by Roger, 2011.02.11. */
797/* */ 765/* */
798void InitInterrupt8723BSdio(struct adapter *padapter) 766void InitInterrupt8723BSdio(struct adapter *adapter)
799{ 767{
800 struct hal_com_data *pHalData; 768 struct hal_com_data *haldata;
801 769
802 770
803 pHalData = GET_HAL_DATA(padapter); 771 haldata = GET_HAL_DATA(adapter);
804 pHalData->sdio_himr = (u32)( \ 772 haldata->sdio_himr = (u32)( \
805 SDIO_HIMR_RX_REQUEST_MSK | 773 SDIO_HIMR_RX_REQUEST_MSK |
806 SDIO_HIMR_AVAL_MSK | 774 SDIO_HIMR_AVAL_MSK |
807/* SDIO_HIMR_TXERR_MSK | */ 775/* SDIO_HIMR_TXERR_MSK | */
@@ -829,14 +797,14 @@ void InitInterrupt8723BSdio(struct adapter *padapter)
829/* */ 797/* */
830/* Created by Roger, 2011.08.03. */ 798/* Created by Roger, 2011.08.03. */
831/* */ 799/* */
832void InitSysInterrupt8723BSdio(struct adapter *padapter) 800void InitSysInterrupt8723BSdio(struct adapter *adapter)
833{ 801{
834 struct hal_com_data *pHalData; 802 struct hal_com_data *haldata;
835 803
836 804
837 pHalData = GET_HAL_DATA(padapter); 805 haldata = GET_HAL_DATA(adapter);
838 806
839 pHalData->SysIntrMask = ( \ 807 haldata->SysIntrMask = ( \
840/* HSIMR_GPIO12_0_INT_EN | */ 808/* HSIMR_GPIO12_0_INT_EN | */
841/* HSIMR_SPS_OCP_INT_EN | */ 809/* HSIMR_SPS_OCP_INT_EN | */
842/* HSIMR_RON_INT_EN | */ 810/* HSIMR_RON_INT_EN | */
@@ -855,20 +823,19 @@ void InitSysInterrupt8723BSdio(struct adapter *padapter)
855/* */ 823/* */
856/* Created by Roger, 2011.02.11. */ 824/* Created by Roger, 2011.02.11. */
857/* */ 825/* */
858void ClearInterrupt8723BSdio(struct adapter *padapter) 826void clearinterrupt8723bsdio(struct adapter *adapter)
859{ 827{
860 struct hal_com_data *pHalData; 828 struct hal_com_data *haldata;
861 u8 *clear; 829 u8 *clear;
862 830
863 831 if (adapter->bSurpriseRemoved)
864 if (true == padapter->bSurpriseRemoved)
865 return; 832 return;
866 833
867 pHalData = GET_HAL_DATA(padapter); 834 haldata = GET_HAL_DATA(adapter);
868 clear = rtw_zmalloc(4); 835 clear = rtw_zmalloc(4);
869 836
870 /* Clear corresponding HISR Content if needed */ 837 /* Clear corresponding HISR Content if needed */
871 *(__le32 *)clear = cpu_to_le32(pHalData->sdio_hisr & MASK_SDIO_HISR_CLEAR); 838 *(__le32 *)clear = cpu_to_le32(haldata->sdio_hisr & MASK_SDIO_HISR_CLEAR);
872 if (*(__le32 *)clear) { 839 if (*(__le32 *)clear) {
873 /* Perform write one clear operation */ 840 /* Perform write one clear operation */
874 sdio_local_write(padapter, SDIO_REG_HISR, 4, clear); 841 sdio_local_write(padapter, SDIO_REG_HISR, 4, clear);
@@ -888,16 +855,16 @@ void ClearInterrupt8723BSdio(struct adapter *padapter)
888/* */ 855/* */
889/* Created by Roger, 2011.02.11. */ 856/* Created by Roger, 2011.02.11. */
890/* */ 857/* */
891void EnableInterrupt8723BSdio(struct adapter *padapter) 858void EnableInterrupt8723BSdio(struct adapter *adapter)
892{ 859{
893 struct hal_com_data *pHalData; 860 struct hal_com_data *haldata;
894 __le32 himr; 861 __le32 himr;
895 u32 tmp; 862 u32 tmp;
896 863
897 pHalData = GET_HAL_DATA(padapter); 864 haldata = GET_HAL_DATA(adapter);
898 865
899 himr = cpu_to_le32(pHalData->sdio_himr); 866 himr = cpu_to_le32(haldata->sdio_himr);
900 sdio_local_write(padapter, SDIO_REG_HIMR, 4, (u8 *)&himr); 867 sdio_local_write(adapter, SDIO_REG_HIMR, 4, (u8 *)&himr);
901 868
902 RT_TRACE( 869 RT_TRACE(
903 _module_hci_ops_c_, 870 _module_hci_ops_c_,
@@ -905,13 +872,13 @@ void EnableInterrupt8723BSdio(struct adapter *padapter)
905 ( 872 (
906 "%s: enable SDIO HIMR = 0x%08X\n", 873 "%s: enable SDIO HIMR = 0x%08X\n",
907 __func__, 874 __func__,
908 pHalData->sdio_himr 875 haldata->sdio_himr
909 ) 876 )
910 ); 877 );
911 878
912 /* Update current system IMR settings */ 879 /* Update current system IMR settings */
913 tmp = rtw_read32(padapter, REG_HSIMR); 880 tmp = rtw_read32(adapter, REG_HSIMR);
914 rtw_write32(padapter, REG_HSIMR, tmp | pHalData->SysIntrMask); 881 rtw_write32(adapter, REG_HSIMR, tmp | haldata->SysIntrMask);
915 882
916 RT_TRACE( 883 RT_TRACE(
917 _module_hci_ops_c_, 884 _module_hci_ops_c_,
@@ -919,7 +886,7 @@ void EnableInterrupt8723BSdio(struct adapter *padapter)
919 ( 886 (
920 "%s: enable HSIMR = 0x%08X\n", 887 "%s: enable HSIMR = 0x%08X\n",
921 __func__, 888 __func__,
922 pHalData->SysIntrMask 889 haldata->SysIntrMask
923 ) 890 )
924 ); 891 );
925 892
@@ -928,7 +895,7 @@ void EnableInterrupt8723BSdio(struct adapter *padapter)
928 /* So we need to clear all C2H events that FW has notified, otherwise FW won't schedule any commands anymore. */ 895 /* So we need to clear all C2H events that FW has notified, otherwise FW won't schedule any commands anymore. */
929 /* 2011.10.19. */ 896 /* 2011.10.19. */
930 /* */ 897 /* */
931 rtw_write8(padapter, REG_C2HEVT_CLEAR, C2H_EVT_HOST_CLOSE); 898 rtw_write8(adapter, REG_C2HEVT_CLEAR, C2H_EVT_HOST_CLOSE);
932} 899}
933 900
934/* */ 901/* */
@@ -940,12 +907,12 @@ void EnableInterrupt8723BSdio(struct adapter *padapter)
940/* */ 907/* */
941/* Created by Roger, 2011.02.11. */ 908/* Created by Roger, 2011.02.11. */
942/* */ 909/* */
943void DisableInterrupt8723BSdio(struct adapter *padapter) 910void DisableInterrupt8723BSdio(struct adapter *adapter)
944{ 911{
945 __le32 himr; 912 __le32 himr;
946 913
947 himr = cpu_to_le32(SDIO_HIMR_DISABLED); 914 himr = cpu_to_le32(SDIO_HIMR_DISABLED);
948 sdio_local_write(padapter, SDIO_REG_HIMR, 4, (u8 *)&himr); 915 sdio_local_write(adapter, SDIO_REG_HIMR, 4, (u8 *)&himr);
949} 916}
950 917
951/* */ 918/* */
@@ -957,27 +924,27 @@ void DisableInterrupt8723BSdio(struct adapter *padapter)
957/* */ 924/* */
958/* Created by Isaac, 2013.09.10. */ 925/* Created by Isaac, 2013.09.10. */
959/* */ 926/* */
960u8 CheckIPSStatus(struct adapter *padapter) 927u8 CheckIPSStatus(struct adapter *adapter)
961{ 928{
962 DBG_871X( 929 DBG_871X(
963 "%s(): Read 0x100 = 0x%02x 0x86 = 0x%02x\n", 930 "%s(): Read 0x100 = 0x%02x 0x86 = 0x%02x\n",
964 __func__, 931 __func__,
965 rtw_read8(padapter, 0x100), 932 rtw_read8(adapter, 0x100),
966 rtw_read8(padapter, 0x86) 933 rtw_read8(adapter, 0x86)
967 ); 934 );
968 935
969 if (rtw_read8(padapter, 0x100) == 0xEA) 936 if (rtw_read8(adapter, 0x100) == 0xEA)
970 return true; 937 return true;
971 else 938 else
972 return false; 939 return false;
973} 940}
974 941
975static struct recv_buf *sd_recv_rxfifo(struct adapter *padapter, u32 size) 942static struct recv_buf *sd_recv_rxfifo(struct adapter *adapter, u32 size)
976{ 943{
977 u32 readsize, ret; 944 u32 readsize, ret;
978 u8 *preadbuf; 945 u8 *readbuf;
979 struct recv_priv *precvpriv; 946 struct recv_priv *recv_priv;
980 struct recv_buf *precvbuf; 947 struct recv_buf *recvbuf;
981 948
982 949
983 /* Patch for some SDIO Host 4 bytes issue */ 950 /* Patch for some SDIO Host 4 bytes issue */
@@ -985,37 +952,37 @@ static struct recv_buf *sd_recv_rxfifo(struct adapter *padapter, u32 size)
985 readsize = RND4(size); 952 readsize = RND4(size);
986 953
987 /* 3 1. alloc recvbuf */ 954 /* 3 1. alloc recvbuf */
988 precvpriv = &padapter->recvpriv; 955 recv_priv = &adapter->recvpriv;
989 precvbuf = rtw_dequeue_recvbuf(&precvpriv->free_recv_buf_queue); 956 recvbuf = rtw_dequeue_recvbuf(&recv_priv->free_recv_buf_queue);
990 if (precvbuf == NULL) { 957 if (!recvbuf) {
991 DBG_871X_LEVEL(_drv_err_, "%s: alloc recvbuf FAIL!\n", __func__); 958 DBG_871X_LEVEL(_drv_err_, "%s: alloc recvbuf FAIL!\n", __func__);
992 return NULL; 959 return NULL;
993 } 960 }
994 961
995 /* 3 2. alloc skb */ 962 /* 3 2. alloc skb */
996 if (precvbuf->pskb == NULL) { 963 if (!recvbuf->pskb) {
997 SIZE_PTR tmpaddr = 0; 964 SIZE_PTR tmpaddr = 0;
998 SIZE_PTR alignment = 0; 965 SIZE_PTR alignment = 0;
999 966
1000 precvbuf->pskb = rtw_skb_alloc(MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ); 967 recvbuf->pskb = rtw_skb_alloc(MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ);
1001 968
1002 if (precvbuf->pskb) { 969 if (recvbuf->pskb) {
1003 precvbuf->pskb->dev = padapter->pnetdev; 970 recvbuf->pskb->dev = adapter->pnetdev;
1004 971
1005 tmpaddr = (SIZE_PTR)precvbuf->pskb->data; 972 tmpaddr = (SIZE_PTR)recvbuf->pskb->data;
1006 alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1); 973 alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1);
1007 skb_reserve(precvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment)); 974 skb_reserve(recvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
1008 } 975 }
1009 976
1010 if (precvbuf->pskb == NULL) { 977 if (!recvbuf->pskb) {
1011 DBG_871X("%s: alloc_skb fail! read =%d\n", __func__, readsize); 978 DBG_871X("%s: alloc_skb fail! read =%d\n", __func__, readsize);
1012 return NULL; 979 return NULL;
1013 } 980 }
1014 } 981 }
1015 982
1016 /* 3 3. read data from rxfifo */ 983 /* 3 3. read data from rxfifo */
1017 preadbuf = precvbuf->pskb->data; 984 readbuf = recvbuf->pskb->data;
1018 ret = sdio_read_port(&padapter->iopriv.intf, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf); 985 ret = sdio_read_port(&adapter->iopriv.intf, WLAN_RX0FF_DEVICE_ID, readsize, readbuf);
1019 if (ret == _FAIL) { 986 if (ret == _FAIL) {
1020 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("%s: read port FAIL!\n", __func__)); 987 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("%s: read port FAIL!\n", __func__));
1021 return NULL; 988 return NULL;
@@ -1023,72 +990,72 @@ static struct recv_buf *sd_recv_rxfifo(struct adapter *padapter, u32 size)
1023 990
1024 991
1025 /* 3 4. init recvbuf */ 992 /* 3 4. init recvbuf */
1026 precvbuf->len = size; 993 recvbuf->len = size;
1027 precvbuf->phead = precvbuf->pskb->head; 994 recvbuf->phead = recvbuf->pskb->head;
1028 precvbuf->pdata = precvbuf->pskb->data; 995 recvbuf->pdata = recvbuf->pskb->data;
1029 skb_set_tail_pointer(precvbuf->pskb, size); 996 skb_set_tail_pointer(recvbuf->pskb, size);
1030 precvbuf->ptail = skb_tail_pointer(precvbuf->pskb); 997 recvbuf->ptail = skb_tail_pointer(recvbuf->pskb);
1031 precvbuf->pend = skb_end_pointer(precvbuf->pskb); 998 recvbuf->pend = skb_end_pointer(recvbuf->pskb);
1032 999
1033 return precvbuf; 1000 return recvbuf;
1034} 1001}
1035 1002
1036static void sd_rxhandler(struct adapter *padapter, struct recv_buf *precvbuf) 1003static void sd_rxhandler(struct adapter *adapter, struct recv_buf *recvbuf)
1037{ 1004{
1038 struct recv_priv *precvpriv; 1005 struct recv_priv *recv_priv;
1039 struct __queue *ppending_queue; 1006 struct __queue *pending_queue;
1040 1007
1041 precvpriv = &padapter->recvpriv; 1008 recv_priv = &adapter->recvpriv;
1042 ppending_queue = &precvpriv->recv_buf_pending_queue; 1009 pending_queue = &recv_priv->recv_buf_pending_queue;
1043 1010
1044 /* 3 1. enqueue recvbuf */ 1011 /* 3 1. enqueue recvbuf */
1045 rtw_enqueue_recvbuf(precvbuf, ppending_queue); 1012 rtw_enqueue_recvbuf(recvbuf, pending_queue);
1046 1013
1047 /* 3 2. schedule tasklet */ 1014 /* 3 2. schedule tasklet */
1048 tasklet_schedule(&precvpriv->recv_tasklet); 1015 tasklet_schedule(&recv_priv->recv_tasklet);
1049} 1016}
1050 1017
1051void sd_int_dpc(struct adapter *padapter) 1018void sd_int_dpc(struct adapter *adapter)
1052{ 1019{
1053 struct hal_com_data *phal; 1020 struct hal_com_data *hal;
1054 struct dvobj_priv *dvobj; 1021 struct dvobj_priv *dvobj;
1055 struct intf_hdl *pintfhdl = &padapter->iopriv.intf; 1022 struct intf_hdl *intfhdl = &adapter->iopriv.intf;
1056 struct pwrctrl_priv *pwrctl; 1023 struct pwrctrl_priv *pwrctl;
1057 1024
1058 1025
1059 phal = GET_HAL_DATA(padapter); 1026 hal = GET_HAL_DATA(adapter);
1060 dvobj = adapter_to_dvobj(padapter); 1027 dvobj = adapter_to_dvobj(adapter);
1061 pwrctl = dvobj_to_pwrctl(dvobj); 1028 pwrctl = dvobj_to_pwrctl(dvobj);
1062 1029
1063 if (phal->sdio_hisr & SDIO_HISR_AVAL) { 1030 if (hal->sdio_hisr & SDIO_HISR_AVAL) {
1064 u8 freepage[4]; 1031 u8 freepage[4];
1065 1032
1066 _sdio_local_read(padapter, SDIO_REG_FREE_TXPG, 4, freepage); 1033 _sdio_local_read(adapter, SDIO_REG_FREE_TXPG, 4, freepage);
1067 up(&(padapter->xmitpriv.xmit_sema)); 1034 up(&(adapter->xmitpriv.xmit_sema));
1068 } 1035 }
1069 1036
1070 if (phal->sdio_hisr & SDIO_HISR_CPWM1) { 1037 if (hal->sdio_hisr & SDIO_HISR_CPWM1) {
1071 struct reportpwrstate_parm report; 1038 struct reportpwrstate_parm report;
1072 1039
1073 u8 bcancelled; 1040 u8 bcancelled;
1074 _cancel_timer(&(pwrctl->pwr_rpwm_timer), &bcancelled); 1041 _cancel_timer(&(pwrctl->pwr_rpwm_timer), &bcancelled);
1075 1042
1076 report.state = SdioLocalCmd52Read1Byte(padapter, SDIO_REG_HCPWM1_8723B); 1043 report.state = SdioLocalCmd52Read1Byte(adapter, SDIO_REG_HCPWM1_8723B);
1077 1044
1078 /* cpwm_int_hdl(padapter, &report); */ 1045 /* cpwm_int_hdl(adapter, &report); */
1079 _set_workitem(&(pwrctl->cpwm_event)); 1046 _set_workitem(&(pwrctl->cpwm_event));
1080 } 1047 }
1081 1048
1082 if (phal->sdio_hisr & SDIO_HISR_TXERR) { 1049 if (hal->sdio_hisr & SDIO_HISR_TXERR) {
1083 u8 *status; 1050 u8 *status;
1084 u32 addr; 1051 u32 addr;
1085 1052
1086 status = rtw_malloc(4); 1053 status = rtw_malloc(4);
1087 if (status) { 1054 if (status) {
1088 addr = REG_TXDMA_STATUS; 1055 addr = REG_TXDMA_STATUS;
1089 HalSdioGetCmdAddr8723BSdio(padapter, WLAN_IOREG_DEVICE_ID, addr, &addr); 1056 HalSdioGetCmdAddr8723BSdio(adapter, WLAN_IOREG_DEVICE_ID, addr, &addr);
1090 _sd_read(pintfhdl, addr, 4, status); 1057 _sd_read(intfhdl, addr, 4, status);
1091 _sd_write(pintfhdl, addr, 4, status); 1058 _sd_write(intfhdl, addr, 4, status);
1092 DBG_8192C("%s: SDIO_HISR_TXERR (0x%08x)\n", __func__, le32_to_cpu(*(u32 *)status)); 1059 DBG_8192C("%s: SDIO_HISR_TXERR (0x%08x)\n", __func__, le32_to_cpu(*(u32 *)status));
1093 kfree(status); 1060 kfree(status);
1094 } else { 1061 } else {
@@ -1096,71 +1063,71 @@ void sd_int_dpc(struct adapter *padapter)
1096 } 1063 }
1097 } 1064 }
1098 1065
1099 if (phal->sdio_hisr & SDIO_HISR_TXBCNOK) { 1066 if (hal->sdio_hisr & SDIO_HISR_TXBCNOK) {
1100 DBG_8192C("%s: SDIO_HISR_TXBCNOK\n", __func__); 1067 DBG_8192C("%s: SDIO_HISR_TXBCNOK\n", __func__);
1101 } 1068 }
1102 1069
1103 if (phal->sdio_hisr & SDIO_HISR_TXBCNERR) { 1070 if (hal->sdio_hisr & SDIO_HISR_TXBCNERR) {
1104 DBG_8192C("%s: SDIO_HISR_TXBCNERR\n", __func__); 1071 DBG_8192C("%s: SDIO_HISR_TXBCNERR\n", __func__);
1105 } 1072 }
1106#ifndef CONFIG_C2H_PACKET_EN 1073#ifndef CONFIG_C2H_PACKET_EN
1107 if (phal->sdio_hisr & SDIO_HISR_C2HCMD) { 1074 if (hal->sdio_hisr & SDIO_HISR_C2HCMD) {
1108 struct c2h_evt_hdr_88xx *c2h_evt; 1075 struct c2h_evt_hdr_88xx *c2h_evt;
1109 1076
1110 DBG_8192C("%s: C2H Command\n", __func__); 1077 DBG_8192C("%s: C2H Command\n", __func__);
1111 c2h_evt = rtw_zmalloc(16); 1078 c2h_evt = rtw_zmalloc(16);
1112 if (c2h_evt != NULL) { 1079 if (c2h_evt != NULL) {
1113 if (rtw_hal_c2h_evt_read(padapter, (u8 *)c2h_evt) == _SUCCESS) { 1080 if (rtw_hal_c2h_evt_read(adapter, (u8 *)c2h_evt) == _SUCCESS) {
1114 if (c2h_id_filter_ccx_8723b((u8 *)c2h_evt)) { 1081 if (c2h_id_filter_ccx_8723b((u8 *)c2h_evt)) {
1115 /* Handle CCX report here */ 1082 /* Handle CCX report here */
1116 rtw_hal_c2h_handler(padapter, (u8 *)c2h_evt); 1083 rtw_hal_c2h_handler(adapter, (u8 *)c2h_evt);
1117 kfree((u8 *)c2h_evt); 1084 kfree((u8 *)c2h_evt);
1118 } else { 1085 } else {
1119 rtw_c2h_wk_cmd(padapter, (u8 *)c2h_evt); 1086 rtw_c2h_wk_cmd(adapter, (u8 *)c2h_evt);
1120 } 1087 }
1121 } 1088 }
1122 } else { 1089 } else {
1123 /* Error handling for malloc fail */ 1090 /* Error handling for malloc fail */
1124 if (rtw_cbuf_push(padapter->evtpriv.c2h_queue, NULL) != _SUCCESS) 1091 if (rtw_cbuf_push(adapter->evtpriv.c2h_queue, NULL) != _SUCCESS)
1125 DBG_871X("%s rtw_cbuf_push fail\n", __func__); 1092 DBG_871X("%s rtw_cbuf_push fail\n", __func__);
1126 _set_workitem(&padapter->evtpriv.c2h_wk); 1093 _set_workitem(&adapter->evtpriv.c2h_wk);
1127 } 1094 }
1128 } 1095 }
1129#endif 1096#endif
1130 1097
1131 if (phal->sdio_hisr & SDIO_HISR_RXFOVW) { 1098 if (hal->sdio_hisr & SDIO_HISR_RXFOVW) {
1132 DBG_8192C("%s: Rx Overflow\n", __func__); 1099 DBG_8192C("%s: Rx Overflow\n", __func__);
1133 } 1100 }
1134 1101
1135 if (phal->sdio_hisr & SDIO_HISR_RXERR) { 1102 if (hal->sdio_hisr & SDIO_HISR_RXERR) {
1136 DBG_8192C("%s: Rx Error\n", __func__); 1103 DBG_8192C("%s: Rx Error\n", __func__);
1137 } 1104 }
1138 1105
1139 if (phal->sdio_hisr & SDIO_HISR_RX_REQUEST) { 1106 if (hal->sdio_hisr & SDIO_HISR_RX_REQUEST) {
1140 struct recv_buf *precvbuf; 1107 struct recv_buf *recvbuf;
1141 int alloc_fail_time = 0; 1108 int alloc_fail_time = 0;
1142 u32 hisr; 1109 u32 hisr;
1143 1110
1144/* DBG_8192C("%s: RX Request, size =%d\n", __func__, phal->SdioRxFIFOSize); */ 1111/* DBG_8192C("%s: RX Request, size =%d\n", __func__, hal->SdioRxFIFOSize); */
1145 phal->sdio_hisr ^= SDIO_HISR_RX_REQUEST; 1112 hal->sdio_hisr ^= SDIO_HISR_RX_REQUEST;
1146 do { 1113 do {
1147 phal->SdioRxFIFOSize = SdioLocalCmd52Read2Byte(padapter, SDIO_REG_RX0_REQ_LEN); 1114 hal->SdioRxFIFOSize = SdioLocalCmd52Read2Byte(adapter, SDIO_REG_RX0_REQ_LEN);
1148 if (phal->SdioRxFIFOSize != 0) { 1115 if (hal->SdioRxFIFOSize != 0) {
1149 precvbuf = sd_recv_rxfifo(padapter, phal->SdioRxFIFOSize); 1116 recvbuf = sd_recv_rxfifo(adapter, hal->SdioRxFIFOSize);
1150 if (precvbuf) 1117 if (recvbuf)
1151 sd_rxhandler(padapter, precvbuf); 1118 sd_rxhandler(adapter, recvbuf);
1152 else { 1119 else {
1153 alloc_fail_time++; 1120 alloc_fail_time++;
1154 DBG_871X("precvbuf is Null for %d times because alloc memory failed\n", alloc_fail_time); 1121 DBG_871X("recvbuf is Null for %d times because alloc memory failed\n", alloc_fail_time);
1155 if (alloc_fail_time >= 10) 1122 if (alloc_fail_time >= 10)
1156 break; 1123 break;
1157 } 1124 }
1158 phal->SdioRxFIFOSize = 0; 1125 hal->SdioRxFIFOSize = 0;
1159 } else 1126 } else
1160 break; 1127 break;
1161 1128
1162 hisr = 0; 1129 hisr = 0;
1163 ReadInterrupt8723BSdio(padapter, &hisr); 1130 ReadInterrupt8723BSdio(adapter, &hisr);
1164 hisr &= SDIO_HISR_RX_REQUEST; 1131 hisr &= SDIO_HISR_RX_REQUEST;
1165 if (!hisr) 1132 if (!hisr)
1166 break; 1133 break;
@@ -1172,38 +1139,37 @@ void sd_int_dpc(struct adapter *padapter)
1172 } 1139 }
1173} 1140}
1174 1141
1175void sd_int_hdl(struct adapter *padapter) 1142void sd_int_hdl(struct adapter *adapter)
1176{ 1143{
1177 struct hal_com_data *phal; 1144 struct hal_com_data *hal;
1178 1145
1179 1146
1180 if ( 1147 if (
1181 (padapter->bDriverStopped == true) || 1148 (adapter->bDriverStopped) || (adapter->bSurpriseRemoved)
1182 (padapter->bSurpriseRemoved == true)
1183 ) 1149 )
1184 return; 1150 return;
1185 1151
1186 phal = GET_HAL_DATA(padapter); 1152 hal = GET_HAL_DATA(adapter);
1187 1153
1188 phal->sdio_hisr = 0; 1154 hal->sdio_hisr = 0;
1189 ReadInterrupt8723BSdio(padapter, &phal->sdio_hisr); 1155 ReadInterrupt8723BSdio(adapter, &hal->sdio_hisr);
1190 1156
1191 if (phal->sdio_hisr & phal->sdio_himr) { 1157 if (hal->sdio_hisr & hal->sdio_himr) {
1192 u32 v32; 1158 u32 v32;
1193 1159
1194 phal->sdio_hisr &= phal->sdio_himr; 1160 hal->sdio_hisr &= hal->sdio_himr;
1195 1161
1196 /* clear HISR */ 1162 /* clear HISR */
1197 v32 = phal->sdio_hisr & MASK_SDIO_HISR_CLEAR; 1163 v32 = hal->sdio_hisr & MASK_SDIO_HISR_CLEAR;
1198 if (v32) { 1164 if (v32) {
1199 SdioLocalCmd52Write4Byte(padapter, SDIO_REG_HISR, v32); 1165 SdioLocalCmd52Write4Byte(adapter, SDIO_REG_HISR, v32);
1200 } 1166 }
1201 1167
1202 sd_int_dpc(padapter); 1168 sd_int_dpc(adapter);
1203 } else { 1169 } else {
1204 RT_TRACE(_module_hci_ops_c_, _drv_err_, 1170 RT_TRACE(_module_hci_ops_c_, _drv_err_,
1205 ("%s: HISR(0x%08x) and HIMR(0x%08x) not match!\n", 1171 ("%s: HISR(0x%08x) and HIMR(0x%08x) not match!\n",
1206 __func__, phal->sdio_hisr, phal->sdio_himr)); 1172 __func__, hal->sdio_hisr, hal->sdio_himr));
1207 } 1173 }
1208} 1174}
1209 1175
@@ -1217,27 +1183,27 @@ void sd_int_hdl(struct adapter *padapter)
1217/* */ 1183/* */
1218/* Created by Roger, 2011.01.28. */ 1184/* Created by Roger, 2011.01.28. */
1219/* */ 1185/* */
1220u8 HalQueryTxBufferStatus8723BSdio(struct adapter *padapter) 1186u8 HalQueryTxBufferStatus8723BSdio(struct adapter *adapter)
1221{ 1187{
1222 struct hal_com_data *phal; 1188 struct hal_com_data *hal;
1223 u32 NumOfFreePage; 1189 u32 numof_free_page;
1224 /* _irqL irql; */ 1190 /* _irql irql; */
1225 1191
1226 1192
1227 phal = GET_HAL_DATA(padapter); 1193 hal = GET_HAL_DATA(adapter);
1228 1194
1229 NumOfFreePage = SdioLocalCmd53Read4Byte(padapter, SDIO_REG_FREE_TXPG); 1195 numof_free_page = SdioLocalCmd53Read4Byte(adapter, SDIO_REG_FREE_TXPG);
1230 1196
1231 /* spin_lock_bh(&phal->SdioTxFIFOFreePageLock); */ 1197 /* spin_lock_bh(&phal->SdioTxFIFOFreePageLock); */
1232 memcpy(phal->SdioTxFIFOFreePage, &NumOfFreePage, 4); 1198 memcpy(hal->SdioTxFIFOFreePage, &numof_free_page, 4);
1233 RT_TRACE(_module_hci_ops_c_, _drv_notice_, 1199 RT_TRACE(_module_hci_ops_c_, _drv_notice_,
1234 ("%s: Free page for HIQ(%#x), MIDQ(%#x), LOWQ(%#x), PUBQ(%#x)\n", 1200 ("%s: Free page for HIQ(%#x), MIDQ(%#x), LOWQ(%#x), PUBQ(%#x)\n",
1235 __func__, 1201 __func__,
1236 phal->SdioTxFIFOFreePage[HI_QUEUE_IDX], 1202 hal->SdioTxFIFOFreePage[HI_QUEUE_IDX],
1237 phal->SdioTxFIFOFreePage[MID_QUEUE_IDX], 1203 hal->SdioTxFIFOFreePage[MID_QUEUE_IDX],
1238 phal->SdioTxFIFOFreePage[LOW_QUEUE_IDX], 1204 hal->SdioTxFIFOFreePage[LOW_QUEUE_IDX],
1239 phal->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX])); 1205 hal->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX]));
1240 /* spin_unlock_bh(&phal->SdioTxFIFOFreePageLock); */ 1206 /* spin_unlock_bh(&hal->SdioTxFIFOFreePageLock); */
1241 1207
1242 return true; 1208 return true;
1243} 1209}
@@ -1246,19 +1212,19 @@ u8 HalQueryTxBufferStatus8723BSdio(struct adapter *padapter)
1246/* Description: */ 1212/* Description: */
1247/* Query SDIO Local register to get the current number of TX OQT Free Space. */ 1213/* Query SDIO Local register to get the current number of TX OQT Free Space. */
1248/* */ 1214/* */
1249u8 HalQueryTxOQTBufferStatus8723BSdio(struct adapter *padapter) 1215u8 HalQueryTxOQTBufferStatus8723BSdio(struct adapter *adapter)
1250{ 1216{
1251 struct hal_com_data *pHalData = GET_HAL_DATA(padapter); 1217 struct hal_com_data *haldata = GET_HAL_DATA(adapter);
1252 1218
1253 pHalData->SdioTxOQTFreeSpace = SdioLocalCmd52Read1Byte(padapter, SDIO_REG_OQT_FREE_PG); 1219 haldata->SdioTxOQTFreeSpace = SdioLocalCmd52Read1Byte(adapter, SDIO_REG_OQT_FREE_PG);
1254 return true; 1220 return true;
1255} 1221}
1256 1222
1257#if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN) 1223#if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
1258u8 RecvOnePkt(struct adapter *padapter, u32 size) 1224u8 RecvOnePkt(struct adapter *adapter, u32 size)
1259{ 1225{
1260 struct recv_buf *precvbuf; 1226 struct recv_buf *recvbuf;
1261 struct dvobj_priv *psddev; 1227 struct dvobj_priv *sddev;
1262 PSDIO_DATA psdio_data; 1228 PSDIO_DATA psdio_data;
1263 struct sdio_func *func; 1229 struct sdio_func *func;
1264 1230
@@ -1266,22 +1232,22 @@ u8 RecvOnePkt(struct adapter *padapter, u32 size)
1266 1232
1267 DBG_871X("+%s: size: %d+\n", __func__, size); 1233 DBG_871X("+%s: size: %d+\n", __func__, size);
1268 1234
1269 if (padapter == NULL) { 1235 if (!adapter) {
1270 DBG_871X(KERN_ERR "%s: padapter is NULL!\n", __func__); 1236 DBG_871X(KERN_ERR "%s: adapter is NULL!\n", __func__);
1271 return false; 1237 return false;
1272 } 1238 }
1273 1239
1274 psddev = adapter_to_dvobj(padapter); 1240 sddev = adapter_to_dvobj(adapter);
1275 psdio_data = &psddev->intf_data; 1241 psdio_data = &sddev->intf_data;
1276 func = psdio_data->func; 1242 func = psdio_data->func;
1277 1243
1278 if (size) { 1244 if (size) {
1279 sdio_claim_host(func); 1245 sdio_claim_host(func);
1280 precvbuf = sd_recv_rxfifo(padapter, size); 1246 recvbuf = sd_recv_rxfifo(adapter, size);
1281 1247
1282 if (precvbuf) { 1248 if (recvbuf) {
1283 /* printk("Completed Recv One Pkt.\n"); */ 1249 /* printk("Completed Recv One Pkt.\n"); */
1284 sd_rxhandler(padapter, precvbuf); 1250 sd_rxhandler(adapter, recvbuf);
1285 res = true; 1251 res = true;
1286 } else { 1252 } else {
1287 res = false; 1253 res = false;
diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
index 3fca0c2d4c8d..cc18d0ad7d7b 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
@@ -371,7 +371,7 @@ static char *translate_scan(struct adapter *padapter,
371 u8 *wpsie_ptr = NULL; 371 u8 *wpsie_ptr = NULL;
372 uint wps_ielen = 0; 372 uint wps_ielen = 0;
373 373
374 u8 *ie_ptr = pnetwork->network.IEs + ie_offset; 374 u8 *ie_ptr;
375 total_ielen = pnetwork->network.IELength - ie_offset; 375 total_ielen = pnetwork->network.IELength - ie_offset;
376 376
377 if (pnetwork->network.Reserved[0] == 2) { /* Probe Request */ 377 if (pnetwork->network.Reserved[0] == 2) { /* Probe Request */
@@ -967,7 +967,7 @@ static int rtw_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
967 break; 967 break;
968 968
969 default : 969 default :
970 ret = -EINVAL;; 970 ret = -EINVAL;
971 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("\n Mode: %s is not supported \n", iw_operation_mode[wrqu->mode])); 971 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("\n Mode: %s is not supported \n", iw_operation_mode[wrqu->mode]));
972 goto exit; 972 goto exit;
973 } 973 }
diff --git a/drivers/staging/rtlwifi/Kconfig b/drivers/staging/rtlwifi/Kconfig
index cb3a29ae764b..b6b03950987b 100644
--- a/drivers/staging/rtlwifi/Kconfig
+++ b/drivers/staging/rtlwifi/Kconfig
@@ -6,16 +6,6 @@ config R8822BE
6 This is the staging driver for Realtek RTL8822BE 802.11ac PCIe 6 This is the staging driver for Realtek RTL8822BE 802.11ac PCIe
7 wireless network adapters. 7 wireless network adapters.
8 8
9config RTLHALMAC_ST
10 tristate
11 depends on R8822BE
12 default m
13
14config RTLPHYDM_ST
15 tristate
16 depends on R8822BE
17 default m
18
19config RTLWIFI_DEBUG_ST 9config RTLWIFI_DEBUG_ST
20 boolean 10 boolean
21 depends on R8822BE 11 depends on R8822BE
diff --git a/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c b/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
index 52620b72cfa9..493011a54e64 100644
--- a/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
+++ b/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
@@ -800,7 +800,7 @@ static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
800 u32 wifi_link_status = 0x0; 800 u32 wifi_link_status = 0x0;
801 bool bt_hs_on = false, under_ips = false, under_lps = false; 801 bool bt_hs_on = false, under_ips = false, under_lps = false;
802 bool low_power = false, dc_mode = false; 802 bool low_power = false, dc_mode = false;
803 u8 wifi_chnl = 0, wifi_hs_chnl = 0, fw_ps_state; 803 u8 wifi_chnl = 0, wifi_hs_chnl = 0;
804 u8 ap_num = 0; 804 u8 ap_num = 0;
805 805
806 wifi_link_status = halbtc_get_wifi_link_status(btcoexist); 806 wifi_link_status = halbtc_get_wifi_link_status(btcoexist);
@@ -856,7 +856,6 @@ static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
856 dc_mode = true; /*TODO*/ 856 dc_mode = true; /*TODO*/
857 under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0; 857 under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0;
858 under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1; 858 under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1;
859 fw_ps_state = 0;
860 low_power = 0; /*TODO*/ 859 low_power = 0; /*TODO*/
861 seq_printf(m, "\n %-35s = %s%s%s%s", 860 seq_printf(m, "\n %-35s = %s%s%s%s",
862 "Power Status", 861 "Power Status",
@@ -1644,26 +1643,9 @@ void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1644 1643
1645void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type) 1644void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
1646{ 1645{
1647 u8 stack_op_type;
1648
1649 if (!halbtc_is_bt_coexist_available(btcoexist)) 1646 if (!halbtc_is_bt_coexist_available(btcoexist))
1650 return; 1647 return;
1651 btcoexist->statistics.cnt_stack_operation_notify++; 1648 btcoexist->statistics.cnt_stack_operation_notify++;
1652 if (btcoexist->manual_control)
1653 return;
1654
1655 if ((type == HCI_BT_OP_INQUIRY_START) ||
1656 (type == HCI_BT_OP_PAGING_START) ||
1657 (type == HCI_BT_OP_PAIRING_START)) {
1658 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_START;
1659 } else if ((type == HCI_BT_OP_INQUIRY_FINISH) ||
1660 (type == HCI_BT_OP_PAGING_SUCCESS) ||
1661 (type == HCI_BT_OP_PAGING_UNSUCCESS) ||
1662 (type == HCI_BT_OP_PAIRING_FINISH)) {
1663 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
1664 } else {
1665 stack_op_type = BTC_STACK_OP_NONE;
1666 }
1667} 1649}
1668 1650
1669void exhalbtc_halt_notify(struct btc_coexist *btcoexist) 1651void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
diff --git a/drivers/staging/rtlwifi/cam.c b/drivers/staging/rtlwifi/cam.c
index 9c8c907cb48e..ca1c9e36d976 100644
--- a/drivers/staging/rtlwifi/cam.c
+++ b/drivers/staging/rtlwifi/cam.c
@@ -181,7 +181,7 @@ void rtl_cam_mark_invalid(struct ieee80211_hw *hw, u8 uc_index)
181 181
182 u32 ul_command; 182 u32 ul_command;
183 u32 ul_content; 183 u32 ul_content;
184 u32 ul_enc_algo = rtlpriv->cfg->maps[SEC_CAM_AES]; 184 u32 ul_enc_algo;
185 185
186 switch (rtlpriv->sec.pairwise_enc_algorithm) { 186 switch (rtlpriv->sec.pairwise_enc_algorithm) {
187 case WEP40_ENCRYPTION: 187 case WEP40_ENCRYPTION:
@@ -221,7 +221,7 @@ void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)
221 221
222 u32 ul_command; 222 u32 ul_command;
223 u32 ul_content; 223 u32 ul_content;
224 u32 ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES]; 224 u32 ul_encalgo;
225 u8 entry_i; 225 u8 entry_i;
226 226
227 switch (rtlpriv->sec.pairwise_enc_algorithm) { 227 switch (rtlpriv->sec.pairwise_enc_algorithm) {
diff --git a/drivers/staging/rtlwifi/core.c b/drivers/staging/rtlwifi/core.c
index b00e51df984f..3ec039498208 100644
--- a/drivers/staging/rtlwifi/core.c
+++ b/drivers/staging/rtlwifi/core.c
@@ -509,15 +509,13 @@ static int rtl_op_suspend(struct ieee80211_hw *hw,
509 struct rtl_priv *rtlpriv = rtl_priv(hw); 509 struct rtl_priv *rtlpriv = rtl_priv(hw);
510 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 510 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
511 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 511 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
512 struct timeval ts;
513 512
514 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, "\n"); 513 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, "\n");
515 if (WARN_ON(!wow)) 514 if (WARN_ON(!wow))
516 return -EINVAL; 515 return -EINVAL;
517 516
518 /* to resolve s4 can not wake up*/ 517 /* to resolve s4 can not wake up*/
519 do_gettimeofday(&ts); 518 rtlhal->last_suspend_sec = ktime_get_real_seconds();
520 rtlhal->last_suspend_sec = ts.tv_sec;
521 519
522 if ((ppsc->wo_wlan_mode & WAKE_ON_PATTERN_MATCH) && wow->n_patterns) 520 if ((ppsc->wo_wlan_mode & WAKE_ON_PATTERN_MATCH) && wow->n_patterns)
523 _rtl_add_wowlan_patterns(hw, wow); 521 _rtl_add_wowlan_patterns(hw, wow);
@@ -536,7 +534,6 @@ static int rtl_op_resume(struct ieee80211_hw *hw)
536 struct rtl_priv *rtlpriv = rtl_priv(hw); 534 struct rtl_priv *rtlpriv = rtl_priv(hw);
537 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 535 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
538 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 536 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
539 struct timeval ts;
540 537
541 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, "\n"); 538 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, "\n");
542 rtlhal->driver_is_goingto_unload = false; 539 rtlhal->driver_is_goingto_unload = false;
@@ -544,8 +541,7 @@ static int rtl_op_resume(struct ieee80211_hw *hw)
544 rtlhal->wake_from_pnp_sleep = true; 541 rtlhal->wake_from_pnp_sleep = true;
545 542
546 /* to resovle s4 can not wake up*/ 543 /* to resovle s4 can not wake up*/
547 do_gettimeofday(&ts); 544 if (ktime_get_real_seconds() - rtlhal->last_suspend_sec < 5)
548 if (ts.tv_sec - rtlhal->last_suspend_sec < 5)
549 return -1; 545 return -1;
550 546
551 rtl_op_start(hw); 547 rtl_op_start(hw);
@@ -1820,7 +1816,7 @@ bool rtl_hal_pwrseqcmdparsing(struct rtl_priv *rtlpriv, u8 cut_version,
1820 u8 faversion, u8 interface_type, 1816 u8 faversion, u8 interface_type,
1821 struct wlan_pwr_cfg pwrcfgcmd[]) 1817 struct wlan_pwr_cfg pwrcfgcmd[])
1822{ 1818{
1823 struct wlan_pwr_cfg cfg_cmd = {0}; 1819 struct wlan_pwr_cfg cfg_cmd;
1824 bool polling_bit = false; 1820 bool polling_bit = false;
1825 u32 ary_idx = 0; 1821 u32 ary_idx = 0;
1826 u8 value = 0; 1822 u8 value = 0;
diff --git a/drivers/staging/rtlwifi/rtl8822be/fw.c b/drivers/staging/rtlwifi/rtl8822be/fw.c
index f45487122517..483ea85943c3 100644
--- a/drivers/staging/rtlwifi/rtl8822be/fw.c
+++ b/drivers/staging/rtlwifi/rtl8822be/fw.c
@@ -464,6 +464,8 @@ bool rtl8822b_halmac_cb_write_data_rsvd_page(struct rtl_priv *rtlpriv, u8 *buf,
464 int count; 464 int count;
465 465
466 skb = dev_alloc_skb(size); 466 skb = dev_alloc_skb(size);
467 if (!skb)
468 return false;
467 memcpy((u8 *)skb_put(skb, size), buf, size); 469 memcpy((u8 *)skb_put(skb, size), buf, size);
468 470
469 if (!_rtl8822be_send_bcn_or_cmd_packet(rtlpriv->hw, skb, BEACON_QUEUE)) 471 if (!_rtl8822be_send_bcn_or_cmd_packet(rtlpriv->hw, skb, BEACON_QUEUE))
diff --git a/drivers/staging/rtlwifi/wifi.h b/drivers/staging/rtlwifi/wifi.h
index eb91c130b245..ca0243fa2e66 100644
--- a/drivers/staging/rtlwifi/wifi.h
+++ b/drivers/staging/rtlwifi/wifi.h
@@ -1670,7 +1670,7 @@ struct rtl_hal {
1670 bool enter_pnp_sleep; 1670 bool enter_pnp_sleep;
1671 bool wake_from_pnp_sleep; 1671 bool wake_from_pnp_sleep;
1672 bool wow_enabled; 1672 bool wow_enabled;
1673 __kernel_time_t last_suspend_sec; 1673 time64_t last_suspend_sec;
1674 u32 wowlan_fwsize; 1674 u32 wowlan_fwsize;
1675 u8 *wowlan_firmware; 1675 u8 *wowlan_firmware;
1676 1676
diff --git a/drivers/staging/rts5208/ms.c b/drivers/staging/rts5208/ms.c
index 7cdce87f3051..821256b95e22 100644
--- a/drivers/staging/rts5208/ms.c
+++ b/drivers/staging/rts5208/ms.c
@@ -2821,6 +2821,7 @@ BUILD_FAIL:
2821int reset_ms_card(struct rtsx_chip *chip) 2821int reset_ms_card(struct rtsx_chip *chip)
2822{ 2822{
2823 struct ms_info *ms_card = &chip->ms_card; 2823 struct ms_info *ms_card = &chip->ms_card;
2824 int seg_no = ms_card->total_block / 512 - 1;
2824 int retval; 2825 int retval;
2825 2826
2826 memset(ms_card, 0, sizeof(struct ms_info)); 2827 memset(ms_card, 0, sizeof(struct ms_info));
@@ -2863,7 +2864,7 @@ int reset_ms_card(struct rtsx_chip *chip)
2863 /* Build table for the last segment, 2864 /* Build table for the last segment,
2864 * to check if L2P table block exists, erasing it 2865 * to check if L2P table block exists, erasing it
2865 */ 2866 */
2866 retval = ms_build_l2p_tbl(chip, ms_card->total_block / 512 - 1); 2867 retval = ms_build_l2p_tbl(chip, seg_no);
2867 if (retval != STATUS_SUCCESS) { 2868 if (retval != STATUS_SUCCESS) {
2868 rtsx_trace(chip); 2869 rtsx_trace(chip);
2869 return STATUS_FAIL; 2870 return STATUS_FAIL;
diff --git a/drivers/staging/rts5208/rtsx.c b/drivers/staging/rts5208/rtsx.c
index 89e2cfe7d1cc..70e0b8623110 100644
--- a/drivers/staging/rts5208/rtsx.c
+++ b/drivers/staging/rts5208/rtsx.c
@@ -275,23 +275,6 @@ static int rtsx_acquire_irq(struct rtsx_dev *dev)
275 return 0; 275 return 0;
276} 276}
277 277
278int rtsx_read_pci_cfg_byte(u8 bus, u8 dev, u8 func, u8 offset, u8 *val)
279{
280 struct pci_dev *pdev;
281 u8 data;
282 u8 devfn = (dev << 3) | func;
283
284 pdev = pci_get_bus_and_slot(bus, devfn);
285 if (!pdev)
286 return -1;
287
288 pci_read_config_byte(pdev, offset, &data);
289 if (val)
290 *val = data;
291
292 return 0;
293}
294
295#ifdef CONFIG_PM 278#ifdef CONFIG_PM
296/* 279/*
297 * power management 280 * power management
diff --git a/drivers/staging/rts5208/rtsx.h b/drivers/staging/rts5208/rtsx.h
index 575e5734f2a5..62e467c5a6d7 100644
--- a/drivers/staging/rts5208/rtsx.h
+++ b/drivers/staging/rts5208/rtsx.h
@@ -174,8 +174,6 @@ static inline void get_current_time(u8 *timeval_buf, int buf_len)
174/* struct scsi_cmnd transfer buffer access utilities */ 174/* struct scsi_cmnd transfer buffer access utilities */
175enum xfer_buf_dir {TO_XFER_BUF, FROM_XFER_BUF}; 175enum xfer_buf_dir {TO_XFER_BUF, FROM_XFER_BUF};
176 176
177int rtsx_read_pci_cfg_byte(u8 bus, u8 dev, u8 func, u8 offset, u8 *val);
178
179#define _MSG_TRACE 177#define _MSG_TRACE
180 178
181#include "trace.h" 179#include "trace.h"
diff --git a/drivers/staging/rts5208/sd.h b/drivers/staging/rts5208/sd.h
index 55764e16b93a..900be444acf9 100644
--- a/drivers/staging/rts5208/sd.h
+++ b/drivers/staging/rts5208/sd.h
@@ -118,7 +118,7 @@
118#define SUPPORT_MAX_POWER_PERMANCE 0x10000000 118#define SUPPORT_MAX_POWER_PERMANCE 0x10000000
119#define SUPPORT_1V8 0x01000000 119#define SUPPORT_1V8 0x01000000
120 120
121#define SWTICH_NO_ERR 0x00 121#define SWITCH_NO_ERR 0x00
122#define CARD_NOT_EXIST 0x01 122#define CARD_NOT_EXIST 0x01
123#define SPEC_NOT_SUPPORT 0x02 123#define SPEC_NOT_SUPPORT 0x02
124#define CHECK_MODE_ERR 0x03 124#define CHECK_MODE_ERR 0x03
diff --git a/drivers/staging/sm750fb/TODO b/drivers/staging/sm750fb/TODO
index a3a877d90066..f710ab15abfe 100644
--- a/drivers/staging/sm750fb/TODO
+++ b/drivers/staging/sm750fb/TODO
@@ -6,8 +6,8 @@ TODO:
6- check on hardware effects of removal of USE_HW_I2C and USE_DVICHIP (these two 6- check on hardware effects of removal of USE_HW_I2C and USE_DVICHIP (these two
7 are supposed to be sample code which is given here if someone wants to 7 are supposed to be sample code which is given here if someone wants to
8 use those functionalities) 8 use those functionalities)
9- move it to drivers/video/fbdev 9- must be ported to the atomic kms framework in the drm subsystem (which will
10- modify the code for drm framework 10 give you a basic fbdev driver for free)
11 11
12Please send any patches to 12Please send any patches to
13 Greg Kroah-Hartman <greg@kroah.com> 13 Greg Kroah-Hartman <greg@kroah.com>
diff --git a/drivers/staging/sm750fb/ddk750_sii164.c b/drivers/staging/sm750fb/ddk750_sii164.c
index c787a74c4f9c..4b34a083f5cf 100644
--- a/drivers/staging/sm750fb/ddk750_sii164.c
+++ b/drivers/staging/sm750fb/ddk750_sii164.c
@@ -62,8 +62,6 @@ unsigned short sii164GetDeviceID(void)
62 return deviceID; 62 return deviceID;
63} 63}
64 64
65
66
67/* DVI.C will handle all SiI164 chip stuffs and try it best to make code minimal and useful */ 65/* DVI.C will handle all SiI164 chip stuffs and try it best to make code minimal and useful */
68 66
69/* 67/*
@@ -239,10 +237,6 @@ long sii164InitChip(unsigned char edgeSelect,
239 return -1; 237 return -1;
240} 238}
241 239
242
243
244
245
246/* below sii164 function is not necessary */ 240/* below sii164 function is not necessary */
247 241
248#ifdef SII164_FULL_FUNCTIONS 242#ifdef SII164_FULL_FUNCTIONS
@@ -402,5 +396,3 @@ void sii164ClearInterrupt(void)
402#endif 396#endif
403 397
404#endif 398#endif
405
406
diff --git a/drivers/staging/sm750fb/ddk750_sii164.h b/drivers/staging/sm750fb/ddk750_sii164.h
index 2e9a88cd6af3..862e7bf27353 100644
--- a/drivers/staging/sm750fb/ddk750_sii164.h
+++ b/drivers/staging/sm750fb/ddk750_sii164.h
@@ -12,7 +12,6 @@ enum sii164_hot_plug_mode {
12 SII164_HOTPLUG_USE_HTPLG /* Use Hot Plug detect bit. */ 12 SII164_HOTPLUG_USE_HTPLG /* Use Hot Plug detect bit. */
13}; 13};
14 14
15
16/* Silicon Image SiI164 chip prototype */ 15/* Silicon Image SiI164 chip prototype */
17long sii164InitChip(unsigned char edgeSelect, 16long sii164InitChip(unsigned char edgeSelect,
18 unsigned char busSelect, 17 unsigned char busSelect,
@@ -28,7 +27,6 @@ long sii164InitChip(unsigned char edgeSelect,
28unsigned short sii164GetVendorID(void); 27unsigned short sii164GetVendorID(void);
29unsigned short sii164GetDeviceID(void); 28unsigned short sii164GetDeviceID(void);
30 29
31
32#ifdef SII164_FULL_FUNCTIONS 30#ifdef SII164_FULL_FUNCTIONS
33void sii164ResetChip(void); 31void sii164ResetChip(void);
34char *sii164GetChipString(void); 32char *sii164GetChipString(void);
diff --git a/drivers/staging/sm750fb/sm750_hw.c b/drivers/staging/sm750fb/sm750_hw.c
index ffd114a6d09b..a8c79864ee4b 100644
--- a/drivers/staging/sm750fb/sm750_hw.c
+++ b/drivers/staging/sm750fb/sm750_hw.c
@@ -185,29 +185,29 @@ int hw_sm750_output_setMode(struct lynxfb_output *output,
185 struct fb_fix_screeninfo *fix) 185 struct fb_fix_screeninfo *fix)
186{ 186{
187 int ret; 187 int ret;
188 disp_output_t dispSet; 188 disp_output_t disp_set;
189 int channel; 189 int channel;
190 190
191 ret = 0; 191 ret = 0;
192 dispSet = 0; 192 disp_set = 0;
193 channel = *output->channel; 193 channel = *output->channel;
194 194
195 if (sm750_get_chip_type() != SM750LE) { 195 if (sm750_get_chip_type() != SM750LE) {
196 if (channel == sm750_primary) { 196 if (channel == sm750_primary) {
197 pr_info("primary channel\n"); 197 pr_info("primary channel\n");
198 if (output->paths & sm750_panel) 198 if (output->paths & sm750_panel)
199 dispSet |= do_LCD1_PRI; 199 disp_set |= do_LCD1_PRI;
200 if (output->paths & sm750_crt) 200 if (output->paths & sm750_crt)
201 dispSet |= do_CRT_PRI; 201 disp_set |= do_CRT_PRI;
202 202
203 } else { 203 } else {
204 pr_info("secondary channel\n"); 204 pr_info("secondary channel\n");
205 if (output->paths & sm750_panel) 205 if (output->paths & sm750_panel)
206 dispSet |= do_LCD1_SEC; 206 disp_set |= do_LCD1_SEC;
207 if (output->paths & sm750_crt) 207 if (output->paths & sm750_crt)
208 dispSet |= do_CRT_SEC; 208 disp_set |= do_CRT_SEC;
209 } 209 }
210 ddk750_setLogicalDispOut(dispSet); 210 ddk750_setLogicalDispOut(disp_set);
211 } else { 211 } else {
212 /* just open DISPLAY_CONTROL_750LE register bit 3:0 */ 212 /* just open DISPLAY_CONTROL_750LE register bit 3:0 */
213 u32 reg; 213 u32 reg;
diff --git a/drivers/staging/speakup/buffers.c b/drivers/staging/speakup/buffers.c
index 6137fa83c609..461f131644a2 100644
--- a/drivers/staging/speakup/buffers.c
+++ b/drivers/staging/speakup/buffers.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/console.h> 2#include <linux/console.h>
2#include <linux/types.h> 3#include <linux/types.h>
3#include <linux/wait.h> 4#include <linux/wait.h>
diff --git a/drivers/staging/speakup/fakekey.c b/drivers/staging/speakup/fakekey.c
index 294c74b47224..cd029968462f 100644
--- a/drivers/staging/speakup/fakekey.c
+++ b/drivers/staging/speakup/fakekey.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* fakekey.c 2/* fakekey.c
2 * Functions for simulating keypresses. 3 * Functions for simulating keypresses.
3 * 4 *
4 * Copyright (C) 2010 the Speakup Team 5 * Copyright (C) 2010 the Speakup Team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */ 6 */
16#include <linux/types.h> 7#include <linux/types.h>
17#include <linux/slab.h> 8#include <linux/slab.h>
diff --git a/drivers/staging/speakup/keyhelp.c b/drivers/staging/speakup/keyhelp.c
index 4e6e5daba50c..5f1bda37f86d 100644
--- a/drivers/staging/speakup/keyhelp.c
+++ b/drivers/staging/speakup/keyhelp.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* speakup_keyhelp.c 2/* speakup_keyhelp.c
2 * help module for speakup 3 * help module for speakup
3 * 4 *
4 *written by David Borowski. 5 *written by David Borowski.
5 * 6 *
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */ 8 */
18 9
19#include <linux/keyboard.h> 10#include <linux/keyboard.h>
diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
index ca85476e3ff7..f1f90222186b 100644
--- a/drivers/staging/speakup/kobjects.c
+++ b/drivers/staging/speakup/kobjects.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Speakup kobject implementation 3 * Speakup kobject implementation
3 * 4 *
diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c
index aae868509e13..cf1259059776 100644
--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* speakup.c 2/* speakup.c
2 * review functions for the speakup screen review package. 3 * review functions for the speakup screen review package.
3 * originally written by: Kirk Reiser and Andy Berdan. 4 * originally written by: Kirk Reiser and Andy Berdan.
@@ -6,16 +7,6 @@
6 * 7 *
7 ** Copyright (C) 1998 Kirk Reiser. 8 ** Copyright (C) 1998 Kirk Reiser.
8 * Copyright (C) 2003 David Borowski. 9 * Copyright (C) 2003 David Borowski.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21#include <linux/kernel.h> 12#include <linux/kernel.h>
diff --git a/drivers/staging/speakup/selection.c b/drivers/staging/speakup/selection.c
index 66061b5c3427..0ed1fefee0e9 100644
--- a/drivers/staging/speakup/selection.c
+++ b/drivers/staging/speakup/selection.c
@@ -64,13 +64,8 @@ int speakup_set_selection(struct tty_struct *tty)
64 ps = spk_ys * vc->vc_size_row + (spk_xs << 1); 64 ps = spk_ys * vc->vc_size_row + (spk_xs << 1);
65 pe = spk_ye * vc->vc_size_row + (spk_xe << 1); 65 pe = spk_ye * vc->vc_size_row + (spk_xe << 1);
66 66
67 if (ps > pe) { 67 if (ps > pe) /* make sel_start <= sel_end */
68 /* make sel_start <= sel_end */ 68 swap(ps, pe);
69 int tmp = ps;
70
71 ps = pe;
72 pe = tmp;
73 }
74 69
75 if (spk_sel_cons != vc_cons[fg_console].d) { 70 if (spk_sel_cons != vc_cons[fg_console].d) {
76 speakup_clear_selection(); 71 speakup_clear_selection();
diff --git a/drivers/staging/speakup/serialio.c b/drivers/staging/speakup/serialio.c
index 9cfc8142a318..177a2988641c 100644
--- a/drivers/staging/speakup/serialio.c
+++ b/drivers/staging/speakup/serialio.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/interrupt.h> 2#include <linux/interrupt.h>
2#include <linux/ioport.h> 3#include <linux/ioport.h>
3 4
diff --git a/drivers/staging/speakup/speakup_acntpc.c b/drivers/staging/speakup/speakup_acntpc.c
index a041441766aa..28519754b2f0 100644
--- a/drivers/staging/speakup/speakup_acntpc.c
+++ b/drivers/staging/speakup/speakup_acntpc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -5,15 +6,6 @@
5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * this code is specificly written as a driver for the speakup screenreview 9 * this code is specificly written as a driver for the speakup screenreview
18 * package and is not a general device driver. 10 * package and is not a general device driver.
19 * This driver is for the Aicom Acent PC internal synthesizer. 11 * This driver is for the Aicom Acent PC internal synthesizer.
diff --git a/drivers/staging/speakup/speakup_acntsa.c b/drivers/staging/speakup/speakup_acntsa.c
index 43315849b7b6..3a863dc61286 100644
--- a/drivers/staging/speakup/speakup_acntsa.c
+++ b/drivers/staging/speakup/speakup_acntsa.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -5,16 +6,6 @@
5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * this code is specificly written as a driver for the speakup screenreview 9 * this code is specificly written as a driver for the speakup screenreview
19 * package and is not a general device driver. 10 * package and is not a general device driver.
20 */ 11 */
diff --git a/drivers/staging/speakup/speakup_apollo.c b/drivers/staging/speakup/speakup_apollo.c
index dcf0c3b59fdd..0877b4044c28 100644
--- a/drivers/staging/speakup/speakup_apollo.c
+++ b/drivers/staging/speakup/speakup_apollo.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -5,16 +6,6 @@
5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * this code is specificly written as a driver for the speakup screenreview 9 * this code is specificly written as a driver for the speakup screenreview
19 * package and is not a general device driver. 10 * package and is not a general device driver.
20 */ 11 */
diff --git a/drivers/staging/speakup/speakup_audptr.c b/drivers/staging/speakup/speakup_audptr.c
index 45b5721441ba..e6a6a9665d8f 100644
--- a/drivers/staging/speakup/speakup_audptr.c
+++ b/drivers/staging/speakup/speakup_audptr.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -5,16 +6,6 @@
5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * specificly written as a driver for the speakup screenreview 9 * specificly written as a driver for the speakup screenreview
19 * s not a general device driver. 10 * s not a general device driver.
20 */ 11 */
diff --git a/drivers/staging/speakup/speakup_bns.c b/drivers/staging/speakup/speakup_bns.c
index 402b0fbfb94d..76dfa3f7c058 100644
--- a/drivers/staging/speakup/speakup_bns.c
+++ b/drivers/staging/speakup/speakup_bns.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -5,16 +6,6 @@
5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * this code is specificly written as a driver for the speakup screenreview 9 * this code is specificly written as a driver for the speakup screenreview
19 * package and is not a general device driver. 10 * package and is not a general device driver.
20 */ 11 */
diff --git a/drivers/staging/speakup/speakup_decext.c b/drivers/staging/speakup/speakup_decext.c
index 4310c2c276c4..3741c0fcf5bb 100644
--- a/drivers/staging/speakup/speakup_decext.c
+++ b/drivers/staging/speakup/speakup_decext.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -5,16 +6,6 @@
5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * specificly written as a driver for the speakup screenreview 9 * specificly written as a driver for the speakup screenreview
19 * s not a general device driver. 10 * s not a general device driver.
20 */ 11 */
diff --git a/drivers/staging/speakup/speakup_decpc.c b/drivers/staging/speakup/speakup_decpc.c
index 7a8df7dc1e38..303f393d3f2f 100644
--- a/drivers/staging/speakup/speakup_decpc.c
+++ b/drivers/staging/speakup/speakup_decpc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * This is the DECtalk PC speakup driver 3 * This is the DECtalk PC speakup driver
3 * 4 *
@@ -14,16 +15,6 @@
14 * Copyright (c) 2003 David Borowski <david575@golden.net> 15 * Copyright (c) 2003 David Borowski <david575@golden.net>
15 * 16 *
16 * All rights reserved. 17 * All rights reserved.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 */ 18 */
28#include <linux/jiffies.h> 19#include <linux/jiffies.h>
29#include <linux/sched.h> 20#include <linux/sched.h>
diff --git a/drivers/staging/speakup/speakup_dectlk.c b/drivers/staging/speakup/speakup_dectlk.c
index 5d6a861c9b1e..2ea22a2eb5f9 100644
--- a/drivers/staging/speakup/speakup_dectlk.c
+++ b/drivers/staging/speakup/speakup_dectlk.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -5,16 +6,6 @@
5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * specificly written as a driver for the speakup screenreview 9 * specificly written as a driver for the speakup screenreview
19 * s not a general device driver. 10 * s not a general device driver.
20 */ 11 */
diff --git a/drivers/staging/speakup/speakup_dtlk.c b/drivers/staging/speakup/speakup_dtlk.c
index 8999e3eb5c26..f8cb83c9b82e 100644
--- a/drivers/staging/speakup/speakup_dtlk.c
+++ b/drivers/staging/speakup/speakup_dtlk.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -5,16 +6,6 @@
5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * specificly written as a driver for the speakup screenreview 9 * specificly written as a driver for the speakup screenreview
19 * package it's not a general device driver. 10 * package it's not a general device driver.
20 * This driver is for the RC Systems DoubleTalk PC internal synthesizer. 11 * This driver is for the RC Systems DoubleTalk PC internal synthesizer.
diff --git a/drivers/staging/speakup/speakup_dummy.c b/drivers/staging/speakup/speakup_dummy.c
index ea3b2911cab9..a30d60450bd5 100644
--- a/drivers/staging/speakup/speakup_dummy.c
+++ b/drivers/staging/speakup/speakup_dummy.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -7,16 +8,6 @@
7 * Copyright (C) 2003 David Borowski. 8 * Copyright (C) 2003 David Borowski.
8 * Copyright (C) 2007 Samuel Thibault. 9 * Copyright (C) 2007 Samuel Thibault.
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * specificly written as a driver for the speakup screenreview 11 * specificly written as a driver for the speakup screenreview
21 * s not a general device driver. 12 * s not a general device driver.
22 */ 13 */
diff --git a/drivers/staging/speakup/speakup_keypc.c b/drivers/staging/speakup/speakup_keypc.c
index d3203f8fc3d0..de76183932e1 100644
--- a/drivers/staging/speakup/speakup_keypc.c
+++ b/drivers/staging/speakup/speakup_keypc.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * written by David Borowski 3 * written by David Borowski
3 * 4 *
4 * Copyright (C) 2003 David Borowski. 5 * Copyright (C) 2003 David Borowski.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * specificly written as a driver for the speakup screenreview 7 * specificly written as a driver for the speakup screenreview
17 * package it's not a general device driver. 8 * package it's not a general device driver.
18 * This driver is for the Keynote Gold internal synthesizer. 9 * This driver is for the Keynote Gold internal synthesizer.
diff --git a/drivers/staging/speakup/speakup_ltlk.c b/drivers/staging/speakup/speakup_ltlk.c
index 95efaab73813..3c59519a871f 100644
--- a/drivers/staging/speakup/speakup_ltlk.c
+++ b/drivers/staging/speakup/speakup_ltlk.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -5,16 +6,6 @@
5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * specificly written as a driver for the speakup screenreview 9 * specificly written as a driver for the speakup screenreview
19 * s not a general device driver. 10 * s not a general device driver.
20 */ 11 */
diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
index 585c6aa124cd..0e74d09e18ea 100644
--- a/drivers/staging/speakup/speakup_soft.c
+++ b/drivers/staging/speakup/speakup_soft.c
@@ -1,20 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* speakup_soft.c - speakup driver to register and make available 2/* speakup_soft.c - speakup driver to register and make available
2 * a user space device for software synthesizers. written by: Kirk 3 * a user space device for software synthesizers. written by: Kirk
3 * Reiser <kirk@braille.uwo.ca> 4 * Reiser <kirk@braille.uwo.ca>
4 * 5 *
5 * Copyright (C) 2003 Kirk Reiser. 6 * Copyright (C) 2003 Kirk Reiser.
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 *
18 * this code is specificly written as a driver for the speakup screenreview 8 * this code is specificly written as a driver for the speakup screenreview
19 * package and is not a general device driver. 9 * package and is not a general device driver.
20 */ 10 */
diff --git a/drivers/staging/speakup/speakup_spkout.c b/drivers/staging/speakup/speakup_spkout.c
index 1037aa0d085a..6e933bf1de2e 100644
--- a/drivers/staging/speakup/speakup_spkout.c
+++ b/drivers/staging/speakup/speakup_spkout.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -5,16 +6,6 @@
5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * specificly written as a driver for the speakup screenreview 9 * specificly written as a driver for the speakup screenreview
19 * s not a general device driver. 10 * s not a general device driver.
20 */ 11 */
diff --git a/drivers/staging/speakup/speakup_txprt.c b/drivers/staging/speakup/speakup_txprt.c
index e160034e4a68..a7326f226a5e 100644
--- a/drivers/staging/speakup/speakup_txprt.c
+++ b/drivers/staging/speakup/speakup_txprt.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 3 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com 4 * this version considerably modified by David Borowski, david575@rogers.com
@@ -5,16 +6,6 @@
5 * Copyright (C) 1998-99 Kirk Reiser. 6 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 7 * Copyright (C) 2003 David Borowski.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * specificly written as a driver for the speakup screenreview 9 * specificly written as a driver for the speakup screenreview
19 * s not a general device driver. 10 * s not a general device driver.
20 */ 11 */
diff --git a/drivers/staging/speakup/spk_priv.h b/drivers/staging/speakup/spk_priv.h
index 046040ac074c..00430437eb4c 100644
--- a/drivers/staging/speakup/spk_priv.h
+++ b/drivers/staging/speakup/spk_priv.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* spk_priv.h 2/* spk_priv.h
2 * review functions for the speakup screen review package. 3 * review functions for the speakup screen review package.
3 * originally written by: Kirk Reiser and Andy Berdan. 4 * originally written by: Kirk Reiser and Andy Berdan.
@@ -6,16 +7,6 @@
6 * 7 *
7 * Copyright (C) 1998 Kirk Reiser. 8 * Copyright (C) 1998 Kirk Reiser.
8 * Copyright (C) 2003 David Borowski. 9 * Copyright (C) 2003 David Borowski.
9
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20#ifndef _SPEAKUP_PRIVATE_H 11#ifndef _SPEAKUP_PRIVATE_H
21#define _SPEAKUP_PRIVATE_H 12#define _SPEAKUP_PRIVATE_H
diff --git a/drivers/staging/speakup/spk_priv_keyinfo.h b/drivers/staging/speakup/spk_priv_keyinfo.h
index c95b68ebd8e7..cc99fcd1bc6e 100644
--- a/drivers/staging/speakup/spk_priv_keyinfo.h
+++ b/drivers/staging/speakup/spk_priv_keyinfo.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* spk_priv.h 2/* spk_priv.h
2 * review functions for the speakup screen review package. 3 * review functions for the speakup screen review package.
3 * originally written by: Kirk Reiser and Andy Berdan. 4 * originally written by: Kirk Reiser and Andy Berdan.
@@ -6,16 +7,6 @@
6 * 7 *
7 * Copyright (C) 1998 Kirk Reiser. 8 * Copyright (C) 1998 Kirk Reiser.
8 * Copyright (C) 2003 David Borowski. 9 * Copyright (C) 2003 David Borowski.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */ 10 */
20 11
21#ifndef _SPEAKUP_KEYINFO_H 12#ifndef _SPEAKUP_KEYINFO_H
diff --git a/drivers/staging/speakup/spk_ttyio.c b/drivers/staging/speakup/spk_ttyio.c
index 513cebbd161c..5aa3ffa3772d 100644
--- a/drivers/staging/speakup/spk_ttyio.c
+++ b/drivers/staging/speakup/spk_ttyio.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/types.h> 2#include <linux/types.h>
2#include <linux/tty.h> 3#include <linux/tty.h>
3#include <linux/tty_flip.h> 4#include <linux/tty_flip.h>
diff --git a/drivers/staging/speakup/synth.c b/drivers/staging/speakup/synth.c
index aac29c816d09..c06e6a810999 100644
--- a/drivers/staging/speakup/synth.c
+++ b/drivers/staging/speakup/synth.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/types.h> 2#include <linux/types.h>
2#include <linux/ctype.h> /* for isdigit() and friends */ 3#include <linux/ctype.h> /* for isdigit() and friends */
3#include <linux/fs.h> 4#include <linux/fs.h>
diff --git a/drivers/staging/speakup/thread.c b/drivers/staging/speakup/thread.c
index 8c64f1ada6e0..2fc75e60fbac 100644
--- a/drivers/staging/speakup/thread.c
+++ b/drivers/staging/speakup/thread.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/kthread.h> 2#include <linux/kthread.h>
2#include <linux/wait.h> 3#include <linux/wait.h>
3 4
diff --git a/drivers/staging/speakup/varhandlers.c b/drivers/staging/speakup/varhandlers.c
index d37d24e26641..321405532a8e 100644
--- a/drivers/staging/speakup/varhandlers.c
+++ b/drivers/staging/speakup/varhandlers.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/ctype.h> 2#include <linux/ctype.h>
2#include "spk_types.h" 3#include "spk_types.h"
3#include "spk_priv.h" 4#include "spk_priv.h"
diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
index b6abaf79ef0b..9bd4412356c9 100644
--- a/drivers/staging/typec/tcpci.c
+++ b/drivers/staging/typec/tcpci.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright 2015-2017 Google, Inc 3 * Copyright 2015-2017 Google, Inc
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * USB Type-C Port Controller Interface. 5 * USB Type-C Port Controller Interface.
15 */ 6 */
16 7
@@ -47,7 +38,7 @@ static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc)
47} 38}
48 39
49static int tcpci_read16(struct tcpci *tcpci, unsigned int reg, 40static int tcpci_read16(struct tcpci *tcpci, unsigned int reg,
50 unsigned int *val) 41 u16 *val)
51{ 42{
52 return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16)); 43 return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16));
53} 44}
@@ -285,15 +276,15 @@ static int tcpci_pd_transmit(struct tcpc_dev *tcpc,
285 const struct pd_message *msg) 276 const struct pd_message *msg)
286{ 277{
287 struct tcpci *tcpci = tcpc_to_tcpci(tcpc); 278 struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
288 unsigned int reg, cnt, header; 279 u16 header = msg ? le16_to_cpu(msg->header) : 0;
280 unsigned int reg, cnt;
289 int ret; 281 int ret;
290 282
291 cnt = msg ? pd_header_cnt(msg->header) * 4 : 0; 283 cnt = msg ? pd_header_cnt(header) * 4 : 0;
292 ret = regmap_write(tcpci->regmap, TCPC_TX_BYTE_CNT, cnt + 2); 284 ret = regmap_write(tcpci->regmap, TCPC_TX_BYTE_CNT, cnt + 2);
293 if (ret < 0) 285 if (ret < 0)
294 return ret; 286 return ret;
295 287
296 header = msg ? msg->header : 0;
297 ret = tcpci_write16(tcpci, TCPC_TX_HDR, header); 288 ret = tcpci_write16(tcpci, TCPC_TX_HDR, header);
298 if (ret < 0) 289 if (ret < 0)
299 return ret; 290 return ret;
@@ -356,7 +347,7 @@ static int tcpci_init(struct tcpc_dev *tcpc)
356static irqreturn_t tcpci_irq(int irq, void *dev_id) 347static irqreturn_t tcpci_irq(int irq, void *dev_id)
357{ 348{
358 struct tcpci *tcpci = dev_id; 349 struct tcpci *tcpci = dev_id;
359 unsigned int status, reg; 350 u16 status;
360 351
361 tcpci_read16(tcpci, TCPC_ALERT, &status); 352 tcpci_read16(tcpci, TCPC_ALERT, &status);
362 353
@@ -372,6 +363,8 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id)
372 tcpm_cc_change(tcpci->port); 363 tcpm_cc_change(tcpci->port);
373 364
374 if (status & TCPC_ALERT_POWER_STATUS) { 365 if (status & TCPC_ALERT_POWER_STATUS) {
366 unsigned int reg;
367
375 regmap_read(tcpci->regmap, TCPC_POWER_STATUS_MASK, &reg); 368 regmap_read(tcpci->regmap, TCPC_POWER_STATUS_MASK, &reg);
376 369
377 /* 370 /*
@@ -387,11 +380,12 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id)
387 if (status & TCPC_ALERT_RX_STATUS) { 380 if (status & TCPC_ALERT_RX_STATUS) {
388 struct pd_message msg; 381 struct pd_message msg;
389 unsigned int cnt; 382 unsigned int cnt;
383 u16 header;
390 384
391 regmap_read(tcpci->regmap, TCPC_RX_BYTE_CNT, &cnt); 385 regmap_read(tcpci->regmap, TCPC_RX_BYTE_CNT, &cnt);
392 386
393 tcpci_read16(tcpci, TCPC_RX_HDR, &reg); 387 tcpci_read16(tcpci, TCPC_RX_HDR, &header);
394 msg.header = reg; 388 msg.header = cpu_to_le16(header);
395 389
396 if (WARN_ON(cnt > sizeof(msg.payload))) 390 if (WARN_ON(cnt > sizeof(msg.payload)))
397 cnt = sizeof(msg.payload); 391 cnt = sizeof(msg.payload);
diff --git a/drivers/staging/typec/tcpci.h b/drivers/staging/typec/tcpci.h
index 10b04c8723da..fdfb06cc3b86 100644
--- a/drivers/staging/typec/tcpci.h
+++ b/drivers/staging/typec/tcpci.h
@@ -1,16 +1,7 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * Copyright 2015-2017 Google, Inc 3 * Copyright 2015-2017 Google, Inc
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * USB Type-C Port Controller Interface. 5 * USB Type-C Port Controller Interface.
15 */ 6 */
16 7
diff --git a/drivers/staging/unisys/Kconfig b/drivers/staging/unisys/Kconfig
index 4f1f5e624604..c27dab3b610f 100644
--- a/drivers/staging/unisys/Kconfig
+++ b/drivers/staging/unisys/Kconfig
@@ -3,15 +3,11 @@
3# 3#
4menuconfig UNISYSSPAR 4menuconfig UNISYSSPAR
5 bool "Unisys SPAR driver support" 5 bool "Unisys SPAR driver support"
6 depends on X86_64 && !UML
7 select PCI
8 select ACPI
9 ---help--- 6 ---help---
10 Support for the Unisys SPAR drivers 7 Support for the Unisys SPAR drivers
11 8
12if UNISYSSPAR 9if UNISYSSPAR
13 10
14source "drivers/staging/unisys/visorbus/Kconfig"
15source "drivers/staging/unisys/visornic/Kconfig" 11source "drivers/staging/unisys/visornic/Kconfig"
16source "drivers/staging/unisys/visorinput/Kconfig" 12source "drivers/staging/unisys/visorinput/Kconfig"
17source "drivers/staging/unisys/visorhba/Kconfig" 13source "drivers/staging/unisys/visorhba/Kconfig"
diff --git a/drivers/staging/unisys/Makefile b/drivers/staging/unisys/Makefile
index 20eb098538d3..e45f44b64202 100644
--- a/drivers/staging/unisys/Makefile
+++ b/drivers/staging/unisys/Makefile
@@ -1,7 +1,6 @@
1# 1#
2# Makefile for Unisys SPAR drivers 2# Makefile for Unisys SPAR drivers
3# 3#
4obj-$(CONFIG_UNISYS_VISORBUS) += visorbus/
5obj-$(CONFIG_UNISYS_VISORNIC) += visornic/ 4obj-$(CONFIG_UNISYS_VISORNIC) += visornic/
6obj-$(CONFIG_UNISYS_VISORINPUT) += visorinput/ 5obj-$(CONFIG_UNISYS_VISORINPUT) += visorinput/
7obj-$(CONFIG_UNISYS_VISORHBA) += visorhba/ 6obj-$(CONFIG_UNISYS_VISORHBA) += visorhba/
diff --git a/drivers/staging/unisys/include/iochannel.h b/drivers/staging/unisys/include/iochannel.h
index 5cd407ca2251..45c785d80ce4 100644
--- a/drivers/staging/unisys/include/iochannel.h
+++ b/drivers/staging/unisys/include/iochannel.h
@@ -1,17 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (C) 2010 - 2016 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2016 UNISYS CORPORATION
3 * All rights reserved. 4 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
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, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
14 * details.
15 */ 5 */
16 6
17#ifndef __IOCHANNEL_H__ 7#ifndef __IOCHANNEL_H__
@@ -43,8 +33,7 @@
43 33
44#include <linux/uuid.h> 34#include <linux/uuid.h>
45#include <linux/skbuff.h> 35#include <linux/skbuff.h>
46 36#include <linux/visorbus.h>
47#include "visorchannel.h"
48 37
49/* 38/*
50 * Must increment these whenever you insert or delete fields within this channel 39 * Must increment these whenever you insert or delete fields within this channel
diff --git a/drivers/staging/unisys/include/visorchannel.h b/drivers/staging/unisys/include/visorchannel.h
deleted file mode 100644
index 33945749c8b6..000000000000
--- a/drivers/staging/unisys/include/visorchannel.h
+++ /dev/null
@@ -1,189 +0,0 @@
1/*
2 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
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, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
14 * details.
15 */
16
17#ifndef __VISORCHANNEL_H__
18#define __VISORCHANNEL_H__
19
20#include <linux/types.h>
21#include <linux/uuid.h>
22
23#define VISOR_CHANNEL_SIGNATURE ('L' << 24 | 'N' << 16 | 'C' << 8 | 'E')
24
25/*
26 * enum channel_serverstate
27 * @CHANNELSRV_UNINITIALIZED: Channel is in an undefined state.
28 * @CHANNELSRV_READY: Channel has been initialized by server.
29 */
30enum channel_serverstate {
31 CHANNELSRV_UNINITIALIZED = 0,
32 CHANNELSRV_READY = 1
33};
34
35/*
36 * enum channel_clientstate
37 * @CHANNELCLI_DETACHED:
38 * @CHANNELCLI_DISABLED: Client can see channel but is NOT allowed to use it
39 * unless given TBD* explicit request
40 * (should actually be < DETACHED).
41 * @CHANNELCLI_ATTACHING: Legacy EFI client request for EFI server to attach.
42 * @CHANNELCLI_ATTACHED: Idle, but client may want to use channel any time.
43 * @CHANNELCLI_BUSY: Client either wants to use or is using channel.
44 * @CHANNELCLI_OWNED: "No worries" state - client can access channel
45 * anytime.
46 */
47enum channel_clientstate {
48 CHANNELCLI_DETACHED = 0,
49 CHANNELCLI_DISABLED = 1,
50 CHANNELCLI_ATTACHING = 2,
51 CHANNELCLI_ATTACHED = 3,
52 CHANNELCLI_BUSY = 4,
53 CHANNELCLI_OWNED = 5
54};
55
56/*
57 * Values for VISOR_CHANNEL_PROTOCOL.Features: This define exists so that
58 * a guest can look at the FeatureFlags in the io channel, and configure the
59 * driver to use interrupts or not based on this setting. All feature bits for
60 * all channels should be defined here. The io channel feature bits are defined
61 * below.
62 */
63#define VISOR_DRIVER_ENABLES_INTS (0x1ULL << 1)
64#define VISOR_CHANNEL_IS_POLLING (0x1ULL << 3)
65#define VISOR_IOVM_OK_DRIVER_DISABLING_INTS (0x1ULL << 4)
66#define VISOR_DRIVER_DISABLES_INTS (0x1ULL << 5)
67#define VISOR_DRIVER_ENHANCED_RCVBUF_CHECKING (0x1ULL << 6)
68
69/*
70 * struct channel_header - Common Channel Header
71 * @signature: Signature.
72 * @legacy_state: DEPRECATED - being replaced by.
73 * @header_size: sizeof(struct channel_header).
74 * @size: Total size of this channel in bytes.
75 * @features: Flags to modify behavior.
76 * @chtype: Channel type: data, bus, control, etc..
77 * @partition_handle: ID of guest partition.
78 * @handle: Device number of this channel in client.
79 * @ch_space_offset: Offset in bytes to channel specific area.
80 * @version_id: Struct channel_header Version ID.
81 * @partition_index: Index of guest partition.
82 * @zone_uuid: Guid of Channel's zone.
83 * @cli_str_offset: Offset from channel header to null-terminated
84 * ClientString (0 if ClientString not present).
85 * @cli_state_boot: CHANNEL_CLIENTSTATE of pre-boot EFI client of this
86 * channel.
87 * @cmd_state_cli: CHANNEL_COMMANDSTATE (overloaded in Windows drivers, see
88 * ServerStateUp, ServerStateDown, etc).
89 * @cli_state_os: CHANNEL_CLIENTSTATE of Guest OS client of this channel.
90 * @ch_characteristic: CHANNEL_CHARACTERISTIC_<xxx>.
91 * @cmd_state_srv: CHANNEL_COMMANDSTATE (overloaded in Windows drivers, see
92 * ServerStateUp, ServerStateDown, etc).
93 * @srv_state: CHANNEL_SERVERSTATE.
94 * @cli_error_boot: Bits to indicate err states for boot clients, so err
95 * messages can be throttled.
96 * @cli_error_os: Bits to indicate err states for OS clients, so err
97 * messages can be throttled.
98 * @filler: Pad out to 128 byte cacheline.
99 * @recover_channel: Please add all new single-byte values below here.
100 */
101struct channel_header {
102 u64 signature;
103 u32 legacy_state;
104 /* SrvState, CliStateBoot, and CliStateOS below */
105 u32 header_size;
106 u64 size;
107 u64 features;
108 guid_t chtype;
109 u64 partition_handle;
110 u64 handle;
111 u64 ch_space_offset;
112 u32 version_id;
113 u32 partition_index;
114 guid_t zone_guid;
115 u32 cli_str_offset;
116 u32 cli_state_boot;
117 u32 cmd_state_cli;
118 u32 cli_state_os;
119 u32 ch_characteristic;
120 u32 cmd_state_srv;
121 u32 srv_state;
122 u8 cli_error_boot;
123 u8 cli_error_os;
124 u8 filler[1];
125 u8 recover_channel;
126} __packed;
127
128#define VISOR_CHANNEL_ENABLE_INTS (0x1ULL << 0)
129
130/*
131 * struct signal_queue_header - Subheader for the Signal Type variation of the
132 * Common Channel.
133 * @version: SIGNAL_QUEUE_HEADER Version ID.
134 * @chtype: Queue type: storage, network.
135 * @size: Total size of this queue in bytes.
136 * @sig_base_offset: Offset to signal queue area.
137 * @features: Flags to modify behavior.
138 * @num_sent: Total # of signals placed in this queue.
139 * @num_overflows: Total # of inserts failed due to full queue.
140 * @signal_size: Total size of a signal for this queue.
141 * @max_slots: Max # of slots in queue, 1 slot is always empty.
142 * @max_signals: Max # of signals in queue (MaxSignalSlots-1).
143 * @head: Queue head signal #.
144 * @num_received: Total # of signals removed from this queue.
145 * @tail: Queue tail signal.
146 * @reserved1: Reserved field.
147 * @reserved2: Reserved field.
148 * @client_queue:
149 * @num_irq_received: Total # of Interrupts received. This is incremented by the
150 * ISR in the guest windows driver.
151 * @num_empty: Number of times that visor_signal_remove is called and
152 * returned Empty Status.
153 * @errorflags: Error bits set during SignalReinit to denote trouble with
154 * client's fields.
155 * @filler: Pad out to 64 byte cacheline.
156 */
157struct signal_queue_header {
158 /* 1st cache line */
159 u32 version;
160 u32 chtype;
161 u64 size;
162 u64 sig_base_offset;
163 u64 features;
164 u64 num_sent;
165 u64 num_overflows;
166 u32 signal_size;
167 u32 max_slots;
168 u32 max_signals;
169 u32 head;
170 /* 2nd cache line */
171 u64 num_received;
172 u32 tail;
173 u32 reserved1;
174 u64 reserved2;
175 u64 client_queue;
176 u64 num_irq_received;
177 u64 num_empty;
178 u32 errorflags;
179 u8 filler[12];
180} __packed;
181
182/* VISORCHANNEL Guids */
183/* {414815ed-c58c-11da-95a9-00e08161165f} */
184#define VISOR_VHBA_CHANNEL_GUID \
185 GUID_INIT(0x414815ed, 0xc58c, 0x11da, \
186 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f)
187#define VISOR_VHBA_CHANNEL_GUID_STR \
188 "414815ed-c58c-11da-95a9-00e08161165f"
189#endif
diff --git a/drivers/staging/unisys/visorhba/visorhba_main.c b/drivers/staging/unisys/visorhba/visorhba_main.c
index 0bcd3acb7b0c..167e98f8688e 100644
--- a/drivers/staging/unisys/visorhba/visorhba_main.c
+++ b/drivers/staging/unisys/visorhba/visorhba_main.c
@@ -1,17 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 2012 - 2015 UNISYS CORPORATION 3 * Copyright (c) 2012 - 2015 UNISYS CORPORATION
3 * All rights reserved. 4 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
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, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
14 * details.
15 */ 5 */
16 6
17#include <linux/debugfs.h> 7#include <linux/debugfs.h>
@@ -19,12 +9,12 @@
19#include <linux/idr.h> 9#include <linux/idr.h>
20#include <linux/module.h> 10#include <linux/module.h>
21#include <linux/seq_file.h> 11#include <linux/seq_file.h>
12#include <linux/visorbus.h>
22#include <scsi/scsi.h> 13#include <scsi/scsi.h>
23#include <scsi/scsi_host.h> 14#include <scsi/scsi_host.h>
24#include <scsi/scsi_cmnd.h> 15#include <scsi/scsi_cmnd.h>
25#include <scsi/scsi_device.h> 16#include <scsi/scsi_device.h>
26 17
27#include "visorbus.h"
28#include "iochannel.h" 18#include "iochannel.h"
29 19
30/* The Send and Receive Buffers of the IO Queue may both be full */ 20/* The Send and Receive Buffers of the IO Queue may both be full */
diff --git a/drivers/staging/unisys/visorinput/ultrainputreport.h b/drivers/staging/unisys/visorinput/ultrainputreport.h
index 53975a09535f..67dac430ce0c 100644
--- a/drivers/staging/unisys/visorinput/ultrainputreport.h
+++ b/drivers/staging/unisys/visorinput/ultrainputreport.h
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2010 - 2015 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
3 * All rights reserved. 4 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
13 * details.
14 */ 5 */
15 6
16#ifndef __SPAR_ULTRAINPUTREPORT_H__ 7#ifndef __SPAR_ULTRAINPUTREPORT_H__
diff --git a/drivers/staging/unisys/visorinput/visorinput.c b/drivers/staging/unisys/visorinput/visorinput.c
index 450f003743c0..d8048e48658f 100644
--- a/drivers/staging/unisys/visorinput/visorinput.c
+++ b/drivers/staging/unisys/visorinput/visorinput.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2011 - 2015 UNISYS CORPORATION 3 * Copyright (C) 2011 - 2015 UNISYS CORPORATION
3 * All rights reserved. 4 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
13 * details.
14 */ 5 */
15 6
16/* 7/*
@@ -25,8 +16,8 @@
25#include <linux/kernel.h> 16#include <linux/kernel.h>
26#include <linux/module.h> 17#include <linux/module.h>
27#include <linux/uuid.h> 18#include <linux/uuid.h>
19#include <linux/visorbus.h>
28 20
29#include "visorbus.h"
30#include "ultrainputreport.h" 21#include "ultrainputreport.h"
31 22
32/* Keyboard channel {c73416d0-b0b8-44af-b304-9d2ae99f1b3d} */ 23/* Keyboard channel {c73416d0-b0b8-44af-b304-9d2ae99f1b3d} */
diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
index 6d8239163ba5..92dceb557886 100644
--- a/drivers/staging/unisys/visornic/visornic_main.c
+++ b/drivers/staging/unisys/visornic/visornic_main.c
@@ -1,15 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Copyright (c) 2012 - 2015 UNISYS CORPORATION 2/* Copyright (c) 2012 - 2015 UNISYS CORPORATION
2 * All rights reserved. 3 * All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for more
12 * details.
13 */ 4 */
14 5
15/* This driver lives in a spar partition, and registers to ethernet io 6/* This driver lives in a spar partition, and registers to ethernet io
@@ -25,8 +16,8 @@
25#include <linux/kthread.h> 16#include <linux/kthread.h>
26#include <linux/skbuff.h> 17#include <linux/skbuff.h>
27#include <linux/rtnetlink.h> 18#include <linux/rtnetlink.h>
19#include <linux/visorbus.h>
28 20
29#include "visorbus.h"
30#include "iochannel.h" 21#include "iochannel.h"
31 22
32#define VISORNIC_INFINITE_RSP_WAIT 0 23#define VISORNIC_INFINITE_RSP_WAIT 0
diff --git a/drivers/staging/vboxvideo/vbox_fb.c b/drivers/staging/vboxvideo/vbox_fb.c
index 8aed248db6e2..43c39eca4ae1 100644
--- a/drivers/staging/vboxvideo/vbox_fb.c
+++ b/drivers/staging/vboxvideo/vbox_fb.c
@@ -170,7 +170,7 @@ static int vboxfb_create(struct drm_fb_helper *helper,
170 drm_fb_helper_fill_var(info, &fbdev->helper, sizes->fb_width, 170 drm_fb_helper_fill_var(info, &fbdev->helper, sizes->fb_width,
171 sizes->fb_height); 171 sizes->fb_height);
172 172
173 info->screen_base = bo->kmap.virtual; 173 info->screen_base = (char __iomem *)bo->kmap.virtual;
174 info->screen_size = size; 174 info->screen_size = size;
175 175
176#ifdef CONFIG_DRM_KMS_FB_HELPER 176#ifdef CONFIG_DRM_KMS_FB_HELPER
diff --git a/drivers/staging/vboxvideo/vbox_main.c b/drivers/staging/vboxvideo/vbox_main.c
index 80bd039fa08e..973b3bcc04b1 100644
--- a/drivers/staging/vboxvideo/vbox_main.c
+++ b/drivers/staging/vboxvideo/vbox_main.c
@@ -61,7 +61,7 @@ void vbox_enable_accel(struct vbox_private *vbox)
61 if (vbox->vbva_info[i].vbva) 61 if (vbox->vbva_info[i].vbva)
62 continue; 62 continue;
63 63
64 vbva = (void *)vbox->vbva_buffers + i * VBVA_MIN_BUFFER_SIZE; 64 vbva = (void __force *)vbox->vbva_buffers + i * VBVA_MIN_BUFFER_SIZE;
65 if (!vbva_enable(&vbox->vbva_info[i], 65 if (!vbva_enable(&vbox->vbva_info[i],
66 vbox->guest_pool, vbva, i)) { 66 vbox->guest_pool, vbva, i)) {
67 /* very old host or driver error. */ 67 /* very old host or driver error. */
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c
index f484bb055df7..ec468d5719b1 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c
@@ -1,16 +1,5 @@
1/***************************************************************************** 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright 2011 Broadcom Corporation. All rights reserved. 2/* Copyright 2011 Broadcom Corporation. All rights reserved. */
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14 3
15#include <linux/platform_device.h> 4#include <linux/platform_device.h>
16#include <linux/init.h> 5#include <linux/init.h>
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
index 7e68b3e28246..5f7551fbf5cf 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
@@ -1,16 +1,5 @@
1/***************************************************************************** 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright 2011 Broadcom Corporation. All rights reserved. 2/* Copyright 2011 Broadcom Corporation. All rights reserved. */
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14 3
15#include <linux/interrupt.h> 4#include <linux/interrupt.h>
16#include <linux/slab.h> 5#include <linux/slab.h>
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
index 3c6f1d91d22d..a4a48f31f1a3 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
@@ -1,16 +1,5 @@
1/***************************************************************************** 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright 2011 Broadcom Corporation. All rights reserved. 2/* Copyright 2011 Broadcom Corporation. All rights reserved. */
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14 3
15#include <linux/device.h> 4#include <linux/device.h>
16#include <sound/core.h> 5#include <sound/core.h>
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
index 8f2d508183b2..045d577fe4f8 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
@@ -1,16 +1,5 @@
1/***************************************************************************** 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright 2011 Broadcom Corporation. All rights reserved. 2/* Copyright 2011 Broadcom Corporation. All rights reserved. */
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14 3
15#include <linux/platform_device.h> 4#include <linux/platform_device.h>
16 5
@@ -443,7 +432,6 @@ static struct platform_driver bcm2835_alsa0_driver = {
443#endif 432#endif
444 .driver = { 433 .driver = {
445 .name = "bcm2835_audio", 434 .name = "bcm2835_audio",
446 .owner = THIS_MODULE,
447 .of_match_table = snd_bcm2835_of_match_table, 435 .of_match_table = snd_bcm2835_of_match_table,
448 }, 436 },
449}; 437};
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h
index f1e43e45fd67..dc6ec915f9f5 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h
@@ -1,16 +1,5 @@
1/***************************************************************************** 1/* SPDX-License-Identifier: GPL-2.0 */
2 * Copyright 2011 Broadcom Corporation. All rights reserved. 2/* Copyright 2011 Broadcom Corporation. All rights reserved. */
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14 3
15#ifndef __SOUND_ARM_BCM2835_H 4#ifndef __SOUND_ARM_BCM2835_H
16#define __SOUND_ARM_BCM2835_H 5#define __SOUND_ARM_BCM2835_H
diff --git a/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h b/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h
index da96f1bc2516..1a7f0884ac9c 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h
+++ b/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h
@@ -1,16 +1,5 @@
1/***************************************************************************** 1/* SPDX-License-Identifier: GPL-2.0 */
2 * Copyright 2011 Broadcom Corporation. All rights reserved. 2/* Copyright 2011 Broadcom Corporation. All rights reserved. */
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14 3
15#ifndef _VC_AUDIO_DEFS_H_ 4#ifndef _VC_AUDIO_DEFS_H_
16#define _VC_AUDIO_DEFS_H_ 5#define _VC_AUDIO_DEFS_H_
diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
index be936b8fe317..d2262275a870 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
@@ -1,12 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
@@ -328,11 +325,9 @@ static void buffer_cb(struct vchiq_mmal_instance *instance,
328 pr_debug("Grab another frame"); 325 pr_debug("Grab another frame");
329 vchiq_mmal_port_parameter_set( 326 vchiq_mmal_port_parameter_set(
330 instance, 327 instance,
331 dev->capture. 328 dev->capture.camera_port,
332 camera_port,
333 MMAL_PARAMETER_CAPTURE, 329 MMAL_PARAMETER_CAPTURE,
334 &dev->capture. 330 &dev->capture.frame_count,
335 frame_count,
336 sizeof(dev->capture.frame_count)); 331 sizeof(dev->capture.frame_count));
337 } 332 }
338 } else { 333 } else {
@@ -343,37 +338,17 @@ static void buffer_cb(struct vchiq_mmal_instance *instance,
343 if (dev->capture.frame_count) { 338 if (dev->capture.frame_count) {
344 if (dev->capture.vc_start_timestamp != -1 && 339 if (dev->capture.vc_start_timestamp != -1 &&
345 pts != 0) { 340 pts != 0) {
346 struct timeval timestamp; 341 ktime_t timestamp;
347 s64 runtime_us = pts - 342 s64 runtime_us = pts -
348 dev->capture.vc_start_timestamp; 343 dev->capture.vc_start_timestamp;
349 u32 div = 0; 344 timestamp = ktime_add_us(dev->capture.kernel_start_ts,
350 u32 rem = 0; 345 runtime_us);
351
352 div =
353 div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
354 timestamp.tv_sec =
355 dev->capture.kernel_start_ts.tv_sec + div;
356 timestamp.tv_usec =
357 dev->capture.kernel_start_ts.tv_usec + rem;
358
359 if (timestamp.tv_usec >=
360 USEC_PER_SEC) {
361 timestamp.tv_sec++;
362 timestamp.tv_usec -=
363 USEC_PER_SEC;
364 }
365 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, 346 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
366 "Convert start time %d.%06d and %llu " 347 "Convert start time %llu and %llu with offset %llu to %llu\n",
367 "with offset %llu to %d.%06d\n", 348 ktime_to_ns(dev->capture.kernel_start_ts),
368 (int)dev->capture.kernel_start_ts.
369 tv_sec,
370 (int)dev->capture.kernel_start_ts.
371 tv_usec,
372 dev->capture.vc_start_timestamp, pts, 349 dev->capture.vc_start_timestamp, pts,
373 (int)timestamp.tv_sec, 350 ktime_to_ns(timestamp));
374 (int)timestamp.tv_usec); 351 buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp);
375 buf->vb.vb2_buf.timestamp = timestamp.tv_sec * 1000000000ULL +
376 timestamp.tv_usec * 1000ULL;
377 } else { 352 } else {
378 buf->vb.vb2_buf.timestamp = ktime_get_ns(); 353 buf->vb.vb2_buf.timestamp = ktime_get_ns();
379 } 354 }
@@ -387,11 +362,9 @@ static void buffer_cb(struct vchiq_mmal_instance *instance,
387 "Grab another frame as buffer has EOS"); 362 "Grab another frame as buffer has EOS");
388 vchiq_mmal_port_parameter_set( 363 vchiq_mmal_port_parameter_set(
389 instance, 364 instance,
390 dev->capture. 365 dev->capture.camera_port,
391 camera_port,
392 MMAL_PARAMETER_CAPTURE, 366 MMAL_PARAMETER_CAPTURE,
393 &dev->capture. 367 &dev->capture.frame_count,
394 frame_count,
395 sizeof(dev->capture.frame_count)); 368 sizeof(dev->capture.frame_count));
396 } 369 }
397 } else { 370 } else {
@@ -547,7 +520,7 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
547 "Start time %lld size %d\n", 520 "Start time %lld size %d\n",
548 dev->capture.vc_start_timestamp, parameter_size); 521 dev->capture.vc_start_timestamp, parameter_size);
549 522
550 v4l2_get_timestamp(&dev->capture.kernel_start_ts); 523 dev->capture.kernel_start_ts = ktime_get();
551 524
552 /* enable the camera port */ 525 /* enable the camera port */
553 dev->capture.port->cb_ctx = dev; 526 dev->capture.port->cb_ctx = dev;
@@ -555,8 +528,8 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
555 vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb); 528 vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
556 if (ret) { 529 if (ret) {
557 v4l2_err(&dev->v4l2_dev, 530 v4l2_err(&dev->v4l2_dev,
558 "Failed to enable capture port - error %d. " 531 "Failed to enable capture port - error %d. Disabling camera port again\n",
559 "Disabling camera port again\n", ret); 532 ret);
560 533
561 vchiq_mmal_port_disable(dev->instance, 534 vchiq_mmal_port_disable(dev->instance,
562 dev->capture.camera_port); 535 dev->capture.camera_port);
@@ -1213,8 +1186,8 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
1213 port->current_buffer.size = 1186 port->current_buffer.size =
1214 (f->fmt.pix.sizeimage < 1187 (f->fmt.pix.sizeimage <
1215 (100 << 10)) 1188 (100 << 10))
1216 ? (100 << 10) : f->fmt.pix. 1189 ? (100 << 10)
1217 sizeimage; 1190 : f->fmt.pix.sizeimage;
1218 } 1191 }
1219 v4l2_dbg(1, bcm2835_v4l2_debug, 1192 v4l2_dbg(1, bcm2835_v4l2_debug,
1220 &dev->v4l2_dev, 1193 &dev->v4l2_dev,
diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
index 404037476bc5..2b5679eb5b4a 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
@@ -1,12 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
@@ -92,7 +89,7 @@ struct bm2835_mmal_dev {
92 /* VC start timestamp for streaming */ 89 /* VC start timestamp for streaming */
93 s64 vc_start_timestamp; 90 s64 vc_start_timestamp;
94 /* Kernel start timestamp for streaming */ 91 /* Kernel start timestamp for streaming */
95 struct timeval kernel_start_ts; 92 ktime_t kernel_start_ts;
96 93
97 struct vchiq_mmal_port *port; /* port being used for capture */ 94 struct vchiq_mmal_port *port; /* port being used for capture */
98 /* camera port being used for capture */ 95 /* camera port being used for capture */
diff --git a/drivers/staging/vc04_services/bcm2835-camera/controls.c b/drivers/staging/vc04_services/bcm2835-camera/controls.c
index 77a5d6f4e1eb..0736214e1422 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/controls.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/controls.c
@@ -1,12 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h
index 840fd139e033..800e4e7e5f96 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h
@@ -1,12 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-encodings.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-encodings.h
index e71d9600b278..129203597f91 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-encodings.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-encodings.h
@@ -1,12 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-common.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-common.h
index 66e8a6edf628..ec8455639d49 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-common.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-common.h
@@ -1,12 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-format.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-format.h
index 24b002e8df0c..c9d6fbe25fe4 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-format.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-format.h
@@ -1,12 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-port.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-port.h
index 84a0f4b717ef..dd4b4ce72081 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-port.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-port.h
@@ -1,12 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-msg.h
index 5a1b2a7d8eb0..d1c57edbe2b8 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-msg.h
@@ -1,12 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-parameters.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-parameters.h
index e7300229842d..1607bc4c0347 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-parameters.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-parameters.h
@@ -1,12 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
index 6ea7fb0ea50e..a91ef6ea29ce 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
@@ -1,12 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
@@ -618,8 +615,8 @@ static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
618 struct mmal_msg_context *msg_context; 615 struct mmal_msg_context *msg_context;
619 u32 handle; 616 u32 handle;
620 617
621 pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n", 618 pr_debug("%s: instance:%p msg:%p msg_len:%d\n",
622 instance, msg, msg_len); 619 __func__, instance, msg, msg_len);
623 620
624 if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) { 621 if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
625 handle = msg->u.buffer_from_host.drvbuf.client_context; 622 handle = msg->u.buffer_from_host.drvbuf.client_context;
@@ -1360,8 +1357,7 @@ static int port_action_handle(struct vchiq_mmal_instance *instance,
1360 1357
1361 ret = -rmsg->u.port_action_reply.status; 1358 ret = -rmsg->u.port_action_reply.status;
1362 1359
1363 pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \ 1360 pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d) connect component:0x%x connect port:%d\n",
1364 " connect component:0x%x connect port:%d\n",
1365 __func__, 1361 __func__,
1366 ret, port->component->handle, port->handle, 1362 ret, port->component->handle, port->handle,
1367 port_action_type_names[action_type], 1363 port_action_type_names[action_type],
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
index db39900c9d91..b1f22b6dca10 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
@@ -1,12 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Broadcom BM2835 V4L2 driver 3 * Broadcom BM2835 V4L2 driver
3 * 4 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com> 8 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com>
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
index 315b49c1de3b..b59ef14890aa 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
@@ -224,8 +224,7 @@ vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
224 224
225 platform_state = (struct vchiq_2835_state *)state->platform_state; 225 platform_state = (struct vchiq_2835_state *)state->platform_state;
226 226
227 if (!platform_state->inited) 227 WARN_ON_ONCE(!platform_state->inited);
228 BUG();
229 228
230 return &platform_state->arm_state; 229 return &platform_state->arm_state;
231} 230}
@@ -485,8 +484,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
485 __func__, actual_pages, num_pages); 484 __func__, actual_pages, num_pages);
486 485
487 /* This is probably due to the process being killed */ 486 /* This is probably due to the process being killed */
488 while (actual_pages > 0) 487 while (actual_pages > 0) {
489 {
490 actual_pages--; 488 actual_pages--;
491 put_page(pages[actual_pages]); 489 put_page(pages[actual_pages]);
492 } 490 }
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index 411539f8ff8c..c2c440009cac 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -682,8 +682,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
682 if (user_service->close_pending && 682 if (user_service->close_pending &&
683 down_interruptible(&user_service->close_event)) 683 down_interruptible(&user_service->close_event))
684 status = VCHIQ_RETRY; 684 status = VCHIQ_RETRY;
685 } 685 } else
686 else
687 ret = -EINVAL; 686 ret = -EINVAL;
688 } break; 687 } break;
689 688
@@ -708,8 +707,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
708 if (user_service->close_pending && 707 if (user_service->close_pending &&
709 down_interruptible(&user_service->close_event)) 708 down_interruptible(&user_service->close_event))
710 status = VCHIQ_RETRY; 709 status = VCHIQ_RETRY;
711 } 710 } else
712 else
713 ret = -EINVAL; 711 ret = -EINVAL;
714 } break; 712 } break;
715 713
@@ -1171,8 +1169,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1171 USER_SERVICE_T *user_service = 1169 USER_SERVICE_T *user_service =
1172 (USER_SERVICE_T *)service->base.userdata; 1170 (USER_SERVICE_T *)service->base.userdata;
1173 close_delivered(user_service); 1171 close_delivered(user_service);
1174 } 1172 } else
1175 else
1176 ret = -EINVAL; 1173 ret = -EINVAL;
1177 } break; 1174 } break;
1178 1175
@@ -1810,8 +1807,7 @@ vchiq_release(struct inode *inode, struct file *file)
1810 instance->completion_remove & 1807 instance->completion_remove &
1811 (MAX_COMPLETIONS - 1)]; 1808 (MAX_COMPLETIONS - 1)];
1812 service = completion->service_userdata; 1809 service = completion->service_userdata;
1813 if (completion->reason == VCHIQ_SERVICE_CLOSED) 1810 if (completion->reason == VCHIQ_SERVICE_CLOSED) {
1814 {
1815 USER_SERVICE_T *user_service = 1811 USER_SERVICE_T *user_service =
1816 service->base.userdata; 1812 service->base.userdata;
1817 1813
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
index ecff92bae200..5d28fff46557 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
@@ -66,8 +66,7 @@ struct vchiq_openack_payload {
66 short version; 66 short version;
67}; 67};
68 68
69enum 69enum {
70{
71 QMFLAGS_IS_BLOCKING = (1 << 0), 70 QMFLAGS_IS_BLOCKING = (1 << 0),
72 QMFLAGS_NO_MUTEX_LOCK = (1 << 1), 71 QMFLAGS_NO_MUTEX_LOCK = (1 << 1),
73 QMFLAGS_NO_MUTEX_UNLOCK = (1 << 2) 72 QMFLAGS_NO_MUTEX_UNLOCK = (1 << 2)
@@ -212,7 +211,8 @@ find_service_by_port(VCHIQ_STATE_T *state, int localport)
212 211
213VCHIQ_SERVICE_T * 212VCHIQ_SERVICE_T *
214find_service_for_instance(VCHIQ_INSTANCE_T instance, 213find_service_for_instance(VCHIQ_INSTANCE_T instance,
215 VCHIQ_SERVICE_HANDLE_T handle) { 214 VCHIQ_SERVICE_HANDLE_T handle)
215{
216 VCHIQ_SERVICE_T *service; 216 VCHIQ_SERVICE_T *service;
217 217
218 spin_lock(&service_spinlock); 218 spin_lock(&service_spinlock);
@@ -235,7 +235,8 @@ find_service_for_instance(VCHIQ_INSTANCE_T instance,
235 235
236VCHIQ_SERVICE_T * 236VCHIQ_SERVICE_T *
237find_closed_service_for_instance(VCHIQ_INSTANCE_T instance, 237find_closed_service_for_instance(VCHIQ_INSTANCE_T instance,
238 VCHIQ_SERVICE_HANDLE_T handle) { 238 VCHIQ_SERVICE_HANDLE_T handle)
239{
239 VCHIQ_SERVICE_T *service; 240 VCHIQ_SERVICE_T *service;
240 241
241 spin_lock(&service_spinlock); 242 spin_lock(&service_spinlock);
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
index 34f746db19cd..43c89a08bda9 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
@@ -64,11 +64,6 @@ static VCHIQ_STATUS_T
64vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data, 64vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
65 unsigned int size, VCHIQ_BULK_DIR_T dir); 65 unsigned int size, VCHIQ_BULK_DIR_T dir);
66 66
67/****************************************************************************
68*
69* vchiq_initialise
70*
71***************************************************************************/
72#define VCHIQ_INIT_RETRIES 10 67#define VCHIQ_INIT_RETRIES 10
73VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instance_out) 68VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instance_out)
74{ 69{
@@ -80,7 +75,9 @@ VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instance_out)
80 vchiq_log_trace(vchiq_core_log_level, "%s called", __func__); 75 vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
81 76
82 /* VideoCore may not be ready due to boot up timing. 77 /* VideoCore may not be ready due to boot up timing.
83 It may never be ready if kernel and firmware are mismatched, so don't block forever. */ 78 * It may never be ready if kernel and firmware are mismatched,so don't
79 * block forever.
80 */
84 for (i = 0; i < VCHIQ_INIT_RETRIES; i++) { 81 for (i = 0; i < VCHIQ_INIT_RETRIES; i++) {
85 state = vchiq_get_state(); 82 state = vchiq_get_state();
86 if (state) 83 if (state)
@@ -93,7 +90,8 @@ VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instance_out)
93 goto failed; 90 goto failed;
94 } else if (i > 0) { 91 } else if (i > 0) {
95 vchiq_log_warning(vchiq_core_log_level, 92 vchiq_log_warning(vchiq_core_log_level,
96 "%s: videocore initialized after %d retries\n", __func__, i); 93 "%s: videocore initialized after %d retries\n",
94 __func__, i);
97 } 95 }
98 96
99 instance = kzalloc(sizeof(*instance), GFP_KERNEL); 97 instance = kzalloc(sizeof(*instance), GFP_KERNEL);
@@ -120,12 +118,6 @@ failed:
120} 118}
121EXPORT_SYMBOL(vchiq_initialise); 119EXPORT_SYMBOL(vchiq_initialise);
122 120
123/****************************************************************************
124*
125* vchiq_shutdown
126*
127***************************************************************************/
128
129VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance) 121VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
130{ 122{
131 VCHIQ_STATUS_T status; 123 VCHIQ_STATUS_T status;
@@ -168,23 +160,11 @@ VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
168} 160}
169EXPORT_SYMBOL(vchiq_shutdown); 161EXPORT_SYMBOL(vchiq_shutdown);
170 162
171/****************************************************************************
172*
173* vchiq_is_connected
174*
175***************************************************************************/
176
177static int vchiq_is_connected(VCHIQ_INSTANCE_T instance) 163static int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
178{ 164{
179 return instance->connected; 165 return instance->connected;
180} 166}
181 167
182/****************************************************************************
183*
184* vchiq_connect
185*
186***************************************************************************/
187
188VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance) 168VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
189{ 169{
190 VCHIQ_STATUS_T status; 170 VCHIQ_STATUS_T status;
@@ -214,12 +194,6 @@ failed:
214} 194}
215EXPORT_SYMBOL(vchiq_connect); 195EXPORT_SYMBOL(vchiq_connect);
216 196
217/****************************************************************************
218*
219* vchiq_add_service
220*
221***************************************************************************/
222
223VCHIQ_STATUS_T vchiq_add_service( 197VCHIQ_STATUS_T vchiq_add_service(
224 VCHIQ_INSTANCE_T instance, 198 VCHIQ_INSTANCE_T instance,
225 const VCHIQ_SERVICE_PARAMS_T *params, 199 const VCHIQ_SERVICE_PARAMS_T *params,
@@ -259,12 +233,6 @@ VCHIQ_STATUS_T vchiq_add_service(
259} 233}
260EXPORT_SYMBOL(vchiq_add_service); 234EXPORT_SYMBOL(vchiq_add_service);
261 235
262/****************************************************************************
263*
264* vchiq_open_service
265*
266***************************************************************************/
267
268VCHIQ_STATUS_T vchiq_open_service( 236VCHIQ_STATUS_T vchiq_open_service(
269 VCHIQ_INSTANCE_T instance, 237 VCHIQ_INSTANCE_T instance,
270 const VCHIQ_SERVICE_PARAMS_T *params, 238 const VCHIQ_SERVICE_PARAMS_T *params,
@@ -414,8 +382,9 @@ vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
414 if ((bulk->data != data) || 382 if ((bulk->data != data) ||
415 (bulk->size != size)) { 383 (bulk->size != size)) {
416 /* This is not a retry of the previous one. 384 /* This is not a retry of the previous one.
417 ** Cancel the signal when the transfer 385 * Cancel the signal when the transfer
418 ** completes. */ 386 * completes.
387 */
419 spin_lock(&bulk_waiter_spinlock); 388 spin_lock(&bulk_waiter_spinlock);
420 bulk->userdata = NULL; 389 bulk->userdata = NULL;
421 spin_unlock(&bulk_waiter_spinlock); 390 spin_unlock(&bulk_waiter_spinlock);
@@ -441,7 +410,8 @@ vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
441 410
442 if (bulk) { 411 if (bulk) {
443 /* Cancel the signal when the transfer 412 /* Cancel the signal when the transfer
444 ** completes. */ 413 * completes.
414 */
445 spin_lock(&bulk_waiter_spinlock); 415 spin_lock(&bulk_waiter_spinlock);
446 bulk->userdata = NULL; 416 bulk->userdata = NULL;
447 spin_unlock(&bulk_waiter_spinlock); 417 spin_unlock(&bulk_waiter_spinlock);
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
index d465e1cf5db9..29984f9795c7 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
@@ -800,8 +800,7 @@ int32_t vchi_get_peer_version(const VCHI_SERVICE_HANDLE_T handle, short *peer_ve
800 int32_t ret = -1; 800 int32_t ret = -1;
801 struct shim_service *service = (struct shim_service *)handle; 801 struct shim_service *service = (struct shim_service *)handle;
802 802
803 if (service) 803 if (service) {
804 {
805 VCHIQ_STATUS_T status; 804 VCHIQ_STATUS_T status;
806 805
807 status = vchiq_get_peer_version(service->handle, peer_version); 806 status = vchiq_get_peer_version(service->handle, peer_version);
diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
index 4c8c6fa0a79f..3242dee8246f 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * VMEbus User access driver 3 * VMEbus User access driver
3 * 4 *
@@ -7,12 +8,6 @@
7 * Based on work by: 8 * Based on work by:
8 * Tom Armistead and Ajit Prem 9 * Tom Armistead and Ajit Prem
9 * Copyright 2004 Motorola Inc. 10 * Copyright 2004 Motorola Inc.
10 *
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 */ 11 */
17 12
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -573,7 +568,7 @@ static int vme_user_probe(struct vme_dev *vdev)
573 * by all windows. 568 * by all windows.
574 */ 569 */
575 image[i].resource = vme_slave_request(vme_user_bridge, 570 image[i].resource = vme_slave_request(vme_user_bridge,
576 VME_A24, VME_SCT); 571 VME_A24, VME_SCT);
577 if (!image[i].resource) { 572 if (!image[i].resource) {
578 dev_warn(&vdev->dev, 573 dev_warn(&vdev->dev,
579 "Unable to allocate slave resource\n"); 574 "Unable to allocate slave resource\n");
@@ -582,7 +577,8 @@ static int vme_user_probe(struct vme_dev *vdev)
582 } 577 }
583 image[i].size_buf = PCI_BUF_SIZE; 578 image[i].size_buf = PCI_BUF_SIZE;
584 image[i].kern_buf = vme_alloc_consistent(image[i].resource, 579 image[i].kern_buf = vme_alloc_consistent(image[i].resource,
585 image[i].size_buf, &image[i].pci_buf); 580 image[i].size_buf,
581 &image[i].pci_buf);
586 if (!image[i].kern_buf) { 582 if (!image[i].kern_buf) {
587 dev_warn(&vdev->dev, 583 dev_warn(&vdev->dev,
588 "Unable to allocate memory for buffer\n"); 584 "Unable to allocate memory for buffer\n");
@@ -600,7 +596,8 @@ static int vme_user_probe(struct vme_dev *vdev)
600 for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++) { 596 for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++) {
601 /* XXX Need to properly request attributes */ 597 /* XXX Need to properly request attributes */
602 image[i].resource = vme_master_request(vme_user_bridge, 598 image[i].resource = vme_master_request(vme_user_bridge,
603 VME_A32, VME_SCT, VME_D32); 599 VME_A32, VME_SCT,
600 VME_D32);
604 if (!image[i].resource) { 601 if (!image[i].resource) {
605 dev_warn(&vdev->dev, 602 dev_warn(&vdev->dev,
606 "Unable to allocate master resource\n"); 603 "Unable to allocate master resource\n");
@@ -645,7 +642,8 @@ static int vme_user_probe(struct vme_dev *vdev)
645 642
646 num = (type[i] == SLAVE_MINOR) ? i - (MASTER_MAX + 1) : i; 643 num = (type[i] == SLAVE_MINOR) ? i - (MASTER_MAX + 1) : i;
647 image[i].device = device_create(vme_user_sysfs_class, NULL, 644 image[i].device = device_create(vme_user_sysfs_class, NULL,
648 MKDEV(VME_MAJOR, i), NULL, name, num); 645 MKDEV(VME_MAJOR, i), NULL,
646 name, num);
649 if (IS_ERR(image[i].device)) { 647 if (IS_ERR(image[i].device)) {
650 dev_info(&vdev->dev, "Error creating sysfs device\n"); 648 dev_info(&vdev->dev, "Error creating sysfs device\n");
651 err = PTR_ERR(image[i].device); 649 err = PTR_ERR(image[i].device);
diff --git a/drivers/staging/vt6655/baseband.c b/drivers/staging/vt6655/baseband.c
index 44dfa5421374..f0b163473426 100644
--- a/drivers/staging/vt6655/baseband.c
+++ b/drivers/staging/vt6655/baseband.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: baseband.c 6 * File: baseband.c
16 * 7 *
17 * Purpose: Implement functions to access baseband 8 * Purpose: Implement functions to access baseband
diff --git a/drivers/staging/vt6655/baseband.h b/drivers/staging/vt6655/baseband.h
index feaf222574ee..b8ee33dcb352 100644
--- a/drivers/staging/vt6655/baseband.h
+++ b/drivers/staging/vt6655/baseband.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: baseband.h 6 * File: baseband.h
16 * 7 *
17 * Purpose: Implement functions to access baseband 8 * Purpose: Implement functions to access baseband
diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c
index 14034e342aa6..ea0a4b57852c 100644
--- a/drivers/staging/vt6655/card.c
+++ b/drivers/staging/vt6655/card.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: card.c 6 * File: card.c
16 * Purpose: Provide functions to setup NIC operation mode 7 * Purpose: Provide functions to setup NIC operation mode
17 * Functions: 8 * Functions:
diff --git a/drivers/staging/vt6655/card.h b/drivers/staging/vt6655/card.h
index 1a04dbb57d42..487039a64587 100644
--- a/drivers/staging/vt6655/card.h
+++ b/drivers/staging/vt6655/card.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: card.h 6 * File: card.h
16 * 7 *
17 * Purpose: Provide functions to setup NIC operation mode 8 * Purpose: Provide functions to setup NIC operation mode
diff --git a/drivers/staging/vt6655/channel.c b/drivers/staging/vt6655/channel.c
index ab89956511a0..dec6f0f23b88 100644
--- a/drivers/staging/vt6655/channel.c
+++ b/drivers/staging/vt6655/channel.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: channel.c 6 * File: channel.c
16 * 7 *
17 */ 8 */
diff --git a/drivers/staging/vt6655/channel.h b/drivers/staging/vt6655/channel.h
index 8fe70760e548..53f623a4af65 100644
--- a/drivers/staging/vt6655/channel.h
+++ b/drivers/staging/vt6655/channel.h
@@ -1,19 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: channel.h 6 * File: channel.h
16 *
17 */ 7 */
18 8
19#ifndef _CHANNEL_H_ 9#ifndef _CHANNEL_H_
diff --git a/drivers/staging/vt6655/desc.h b/drivers/staging/vt6655/desc.h
index 2fee6e759ad8..b4a0037b40c1 100644
--- a/drivers/staging/vt6655/desc.h
+++ b/drivers/staging/vt6655/desc.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: desc.h 6 * File: desc.h
16 * 7 *
17 * Purpose:The header file of descriptor 8 * Purpose:The header file of descriptor
diff --git a/drivers/staging/vt6655/device.h b/drivers/staging/vt6655/device.h
index 3ae40d846a09..2f9e9219e8c8 100644
--- a/drivers/staging/vt6655/device.h
+++ b/drivers/staging/vt6655/device.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: device.h 6 * File: device.h
16 * 7 *
17 * Purpose: MAC Data structure 8 * Purpose: MAC Data structure
diff --git a/drivers/staging/vt6655/device_cfg.h b/drivers/staging/vt6655/device_cfg.h
index 0298ea923f97..73f904b51b96 100644
--- a/drivers/staging/vt6655/device_cfg.h
+++ b/drivers/staging/vt6655/device_cfg.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: device_cfg.h 6 * File: device_cfg.h
16 * 7 *
17 * Purpose: Driver configuration header 8 * Purpose: Driver configuration header
diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
index 1123b4f1e1d6..0dc902022a91 100644
--- a/drivers/staging/vt6655/device_main.c
+++ b/drivers/staging/vt6655/device_main.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: device_main.c 6 * File: device_main.c
16 * 7 *
17 * Purpose: driver entry for initial, open, close, tx and rx. 8 * Purpose: driver entry for initial, open, close, tx and rx.
@@ -547,7 +538,7 @@ static void device_init_rd0_ring(struct vnt_private *priv)
547 for (i = 0; i < priv->opts.rx_descs0; 538 for (i = 0; i < priv->opts.rx_descs0;
548 i ++, curr += sizeof(struct vnt_rx_desc)) { 539 i ++, curr += sizeof(struct vnt_rx_desc)) {
549 desc = &priv->aRD0Ring[i]; 540 desc = &priv->aRD0Ring[i];
550 desc->rd_info = kzalloc(sizeof(*desc->rd_info), GFP_ATOMIC); 541 desc->rd_info = kzalloc(sizeof(*desc->rd_info), GFP_KERNEL);
551 542
552 if (!device_alloc_rx_buf(priv, desc)) 543 if (!device_alloc_rx_buf(priv, desc))
553 dev_err(&priv->pcid->dev, "can not alloc rx bufs\n"); 544 dev_err(&priv->pcid->dev, "can not alloc rx bufs\n");
@@ -571,7 +562,7 @@ static void device_init_rd1_ring(struct vnt_private *priv)
571 for (i = 0; i < priv->opts.rx_descs1; 562 for (i = 0; i < priv->opts.rx_descs1;
572 i ++, curr += sizeof(struct vnt_rx_desc)) { 563 i ++, curr += sizeof(struct vnt_rx_desc)) {
573 desc = &priv->aRD1Ring[i]; 564 desc = &priv->aRD1Ring[i];
574 desc->rd_info = kzalloc(sizeof(*desc->rd_info), GFP_ATOMIC); 565 desc->rd_info = kzalloc(sizeof(*desc->rd_info), GFP_KERNEL);
575 566
576 if (!device_alloc_rx_buf(priv, desc)) 567 if (!device_alloc_rx_buf(priv, desc))
577 dev_err(&priv->pcid->dev, "can not alloc rx bufs\n"); 568 dev_err(&priv->pcid->dev, "can not alloc rx bufs\n");
@@ -629,7 +620,7 @@ static void device_init_td0_ring(struct vnt_private *priv)
629 for (i = 0; i < priv->opts.tx_descs[0]; 620 for (i = 0; i < priv->opts.tx_descs[0];
630 i++, curr += sizeof(struct vnt_tx_desc)) { 621 i++, curr += sizeof(struct vnt_tx_desc)) {
631 desc = &priv->apTD0Rings[i]; 622 desc = &priv->apTD0Rings[i];
632 desc->td_info = kzalloc(sizeof(*desc->td_info), GFP_ATOMIC); 623 desc->td_info = kzalloc(sizeof(*desc->td_info), GFP_KERNEL);
633 624
634 desc->td_info->buf = priv->tx0_bufs + i * PKT_BUF_SZ; 625 desc->td_info->buf = priv->tx0_bufs + i * PKT_BUF_SZ;
635 desc->td_info->buf_dma = priv->tx_bufs_dma0 + i * PKT_BUF_SZ; 626 desc->td_info->buf_dma = priv->tx_bufs_dma0 + i * PKT_BUF_SZ;
@@ -654,7 +645,7 @@ static void device_init_td1_ring(struct vnt_private *priv)
654 for (i = 0; i < priv->opts.tx_descs[1]; 645 for (i = 0; i < priv->opts.tx_descs[1];
655 i++, curr += sizeof(struct vnt_tx_desc)) { 646 i++, curr += sizeof(struct vnt_tx_desc)) {
656 desc = &priv->apTD1Rings[i]; 647 desc = &priv->apTD1Rings[i];
657 desc->td_info = kzalloc(sizeof(*desc->td_info), GFP_ATOMIC); 648 desc->td_info = kzalloc(sizeof(*desc->td_info), GFP_KERNEL);
658 649
659 desc->td_info->buf = priv->tx1_bufs + i * PKT_BUF_SZ; 650 desc->td_info->buf = priv->tx1_bufs + i * PKT_BUF_SZ;
660 desc->td_info->buf_dma = priv->tx_bufs_dma1 + i * PKT_BUF_SZ; 651 desc->td_info->buf_dma = priv->tx_bufs_dma1 + i * PKT_BUF_SZ;
diff --git a/drivers/staging/vt6655/dpc.c b/drivers/staging/vt6655/dpc.c
index 9b3fa779258a..088d2d9dbc21 100644
--- a/drivers/staging/vt6655/dpc.c
+++ b/drivers/staging/vt6655/dpc.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: dpc.c 6 * File: dpc.c
16 * 7 *
17 * Purpose: handle dpc rx functions 8 * Purpose: handle dpc rx functions
diff --git a/drivers/staging/vt6655/dpc.h b/drivers/staging/vt6655/dpc.h
index 6e75fa9c5618..93af4220605f 100644
--- a/drivers/staging/vt6655/dpc.h
+++ b/drivers/staging/vt6655/dpc.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: dpc.h 6 * File: dpc.h
16 * 7 *
17 * Purpose: 8 * Purpose:
diff --git a/drivers/staging/vt6655/key.c b/drivers/staging/vt6655/key.c
index d891993b20cf..4d6b48fd119d 100644
--- a/drivers/staging/vt6655/key.c
+++ b/drivers/staging/vt6655/key.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: key.c 6 * File: key.c
16 * 7 *
17 * Purpose: Implement functions for 802.11i Key management 8 * Purpose: Implement functions for 802.11i Key management
diff --git a/drivers/staging/vt6655/key.h b/drivers/staging/vt6655/key.h
index a5024611af60..0942d8703f98 100644
--- a/drivers/staging/vt6655/key.h
+++ b/drivers/staging/vt6655/key.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: key.h 6 * File: key.h
16 * 7 *
17 * Purpose: Implement functions for 802.11i Key management 8 * Purpose: Implement functions for 802.11i Key management
diff --git a/drivers/staging/vt6655/mac.c b/drivers/staging/vt6655/mac.c
index f7550b215f72..4750863c1bb7 100644
--- a/drivers/staging/vt6655/mac.c
+++ b/drivers/staging/vt6655/mac.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: mac.c 6 * File: mac.c
16 * 7 *
17 * Purpose: MAC routines 8 * Purpose: MAC routines
diff --git a/drivers/staging/vt6655/mac.h b/drivers/staging/vt6655/mac.h
index db401e32ae23..b8ab09434773 100644
--- a/drivers/staging/vt6655/mac.h
+++ b/drivers/staging/vt6655/mac.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: mac.h 6 * File: mac.h
16 * 7 *
17 * Purpose: MAC routines 8 * Purpose: MAC routines
diff --git a/drivers/staging/vt6655/power.c b/drivers/staging/vt6655/power.c
index 716d2a80f840..d6c581b31569 100644
--- a/drivers/staging/vt6655/power.c
+++ b/drivers/staging/vt6655/power.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: power.c 6 * File: power.c
16 * 7 *
17 * Purpose: Handles 802.11 power management functions 8 * Purpose: Handles 802.11 power management functions
diff --git a/drivers/staging/vt6655/power.h b/drivers/staging/vt6655/power.h
index f360c5966523..2ec40045fddb 100644
--- a/drivers/staging/vt6655/power.h
+++ b/drivers/staging/vt6655/power.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: power.h 6 * File: power.h
16 * 7 *
17 * Purpose: Handles 802.11 power management functions 8 * Purpose: Handles 802.11 power management functions
diff --git a/drivers/staging/vt6655/rf.c b/drivers/staging/vt6655/rf.c
index edf7db9d53b3..03b0d56dbe9e 100644
--- a/drivers/staging/vt6655/rf.c
+++ b/drivers/staging/vt6655/rf.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: rf.c 6 * File: rf.c
16 * 7 *
17 * Purpose: rf function code 8 * Purpose: rf function code
diff --git a/drivers/staging/vt6655/rf.h b/drivers/staging/vt6655/rf.h
index ba222301d49d..bfce5a89657d 100644
--- a/drivers/staging/vt6655/rf.h
+++ b/drivers/staging/vt6655/rf.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: rf.h 6 * File: rf.h
16 * 7 *
17 * Purpose: 8 * Purpose:
diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c
index 3efe19a1b13f..9aa4d5262aaa 100644
--- a/drivers/staging/vt6655/rxtx.c
+++ b/drivers/staging/vt6655/rxtx.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: rxtx.c 6 * File: rxtx.c
16 * 7 *
17 * Purpose: handle WMAC/802.3/802.11 rx & tx functions 8 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
diff --git a/drivers/staging/vt6655/rxtx.h b/drivers/staging/vt6655/rxtx.h
index 095258923ebd..08db848613f0 100644
--- a/drivers/staging/vt6655/rxtx.h
+++ b/drivers/staging/vt6655/rxtx.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: rxtx.h 6 * File: rxtx.h
16 * 7 *
17 * Purpose: 8 * Purpose:
diff --git a/drivers/staging/vt6655/srom.c b/drivers/staging/vt6655/srom.c
index 635f271595f6..df57d120ed30 100644
--- a/drivers/staging/vt6655/srom.c
+++ b/drivers/staging/vt6655/srom.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: srom.c 6 * File: srom.c
16 * 7 *
17 * Purpose:Implement functions to access eeprom 8 * Purpose:Implement functions to access eeprom
diff --git a/drivers/staging/vt6655/srom.h b/drivers/staging/vt6655/srom.h
index 6e03ab6dfa9d..577f20dc4308 100644
--- a/drivers/staging/vt6655/srom.h
+++ b/drivers/staging/vt6655/srom.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: srom.h 6 * File: srom.h
16 * 7 *
17 * Purpose: Implement functions to access eeprom 8 * Purpose: Implement functions to access eeprom
diff --git a/drivers/staging/vt6655/tmacro.h b/drivers/staging/vt6655/tmacro.h
index d6a0563ad55c..6795b5d74cfc 100644
--- a/drivers/staging/vt6655/tmacro.h
+++ b/drivers/staging/vt6655/tmacro.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: tmacro.h 6 * File: tmacro.h
16 * 7 *
17 * Purpose: define basic common types and macros 8 * Purpose: define basic common types and macros
diff --git a/drivers/staging/vt6655/upc.h b/drivers/staging/vt6655/upc.h
index 9806b5989014..61b3e568ff9a 100644
--- a/drivers/staging/vt6655/upc.h
+++ b/drivers/staging/vt6655/upc.h
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: upc.h 6 * File: upc.h
16 * 7 *
17 * Purpose: Macros to access device 8 * Purpose: Macros to access device
diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c
index 882fe54ce41d..b29ba237fa29 100644
--- a/drivers/staging/vt6656/baseband.c
+++ b/drivers/staging/vt6656/baseband.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: baseband.c 6 * File: baseband.c
17 * 7 *
18 * Purpose: Implement functions to access baseband 8 * Purpose: Implement functions to access baseband
diff --git a/drivers/staging/vt6656/baseband.h b/drivers/staging/vt6656/baseband.h
index fe1c25c64cca..a907e3026012 100644
--- a/drivers/staging/vt6656/baseband.h
+++ b/drivers/staging/vt6656/baseband.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: baseband.h 6 * File: baseband.h
17 * 7 *
18 * Purpose: Implement functions to access baseband 8 * Purpose: Implement functions to access baseband
diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
index 4fd9cd64c6e8..501f482b41c4 100644
--- a/drivers/staging/vt6656/card.c
+++ b/drivers/staging/vt6656/card.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: card.c 6 * File: card.c
17 * Purpose: Provide functions to setup NIC operation mode 7 * Purpose: Provide functions to setup NIC operation mode
18 * Functions: 8 * Functions:
diff --git a/drivers/staging/vt6656/card.h b/drivers/staging/vt6656/card.h
index 7f08cda27e2c..0a91d9ba4688 100644
--- a/drivers/staging/vt6656/card.h
+++ b/drivers/staging/vt6656/card.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: card.h 6 * File: card.h
17 * 7 *
18 * Purpose: Provide functions to setup NIC operation mode 8 * Purpose: Provide functions to setup NIC operation mode
diff --git a/drivers/staging/vt6656/channel.c b/drivers/staging/vt6656/channel.c
index a4299f405d7f..5d57d34577f5 100644
--- a/drivers/staging/vt6656/channel.c
+++ b/drivers/staging/vt6656/channel.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: channel.c 6 * File: channel.c
17 * 7 *
18 * Purpose: Channel number mapping 8 * Purpose: Channel number mapping
diff --git a/drivers/staging/vt6656/channel.h b/drivers/staging/vt6656/channel.h
index 62f18a959098..6d0d2825d992 100644
--- a/drivers/staging/vt6656/channel.h
+++ b/drivers/staging/vt6656/channel.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: channel.h 6 * File: channel.h
17 * 7 *
18 * Purpose: Country Regulation Rules header file 8 * Purpose: Country Regulation Rules header file
diff --git a/drivers/staging/vt6656/desc.h b/drivers/staging/vt6656/desc.h
index 59e3071021bd..ac45ebb71195 100644
--- a/drivers/staging/vt6656/desc.h
+++ b/drivers/staging/vt6656/desc.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: desc.h 6 * File: desc.h
17 * 7 *
18 * Purpose:The header file of descriptor 8 * Purpose:The header file of descriptor
diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h
index 74715c854856..a2feeb916836 100644
--- a/drivers/staging/vt6656/device.h
+++ b/drivers/staging/vt6656/device.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: device.h 6 * File: device.h
17 * 7 *
18 * Purpose: MAC Data structure 8 * Purpose: MAC Data structure
diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c
index 655f0002f880..c3b5b1431048 100644
--- a/drivers/staging/vt6656/dpc.c
+++ b/drivers/staging/vt6656/dpc.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: dpc.c 6 * File: dpc.c
17 * 7 *
18 * Purpose: handle dpc rx functions 8 * Purpose: handle dpc rx functions
diff --git a/drivers/staging/vt6656/dpc.h b/drivers/staging/vt6656/dpc.h
index 5d0454f3af0e..ddd0cb710512 100644
--- a/drivers/staging/vt6656/dpc.h
+++ b/drivers/staging/vt6656/dpc.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: dpc.h 6 * File: dpc.h
17 * 7 *
18 * Purpose: 8 * Purpose:
diff --git a/drivers/staging/vt6656/firmware.c b/drivers/staging/vt6656/firmware.c
index 093a6048bd22..38521c338917 100644
--- a/drivers/staging/vt6656/firmware.c
+++ b/drivers/staging/vt6656/firmware.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: baseband.c 6 * File: baseband.c
17 * 7 *
18 * Purpose: Implement functions to access baseband 8 * Purpose: Implement functions to access baseband
diff --git a/drivers/staging/vt6656/firmware.h b/drivers/staging/vt6656/firmware.h
index f753019c94c9..f30ae90cbb1f 100644
--- a/drivers/staging/vt6656/firmware.h
+++ b/drivers/staging/vt6656/firmware.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: firmware.h 6 * File: firmware.h
17 * 7 *
18 * Purpose: Version and Release Information 8 * Purpose: Version and Release Information
diff --git a/drivers/staging/vt6656/int.c b/drivers/staging/vt6656/int.c
index c6ffbe0e2728..504424b19fcf 100644
--- a/drivers/staging/vt6656/int.c
+++ b/drivers/staging/vt6656/int.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: int.c 6 * File: int.c
17 * 7 *
18 * Purpose: Handle USB interrupt endpoint 8 * Purpose: Handle USB interrupt endpoint
diff --git a/drivers/staging/vt6656/int.h b/drivers/staging/vt6656/int.h
index b5f1b4b02ce4..1e6ff925701a 100644
--- a/drivers/staging/vt6656/int.h
+++ b/drivers/staging/vt6656/int.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: int.h 6 * File: int.h
17 * 7 *
18 * Purpose: 8 * Purpose:
diff --git a/drivers/staging/vt6656/key.c b/drivers/staging/vt6656/key.c
index cc18cb141bff..91dede54cc1f 100644
--- a/drivers/staging/vt6656/key.c
+++ b/drivers/staging/vt6656/key.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: key.c 6 * File: key.c
17 * 7 *
18 * Purpose: Implement functions for 802.11i Key management 8 * Purpose: Implement functions for 802.11i Key management
diff --git a/drivers/staging/vt6656/key.h b/drivers/staging/vt6656/key.h
index cfc6c2131536..1306ff441b87 100644
--- a/drivers/staging/vt6656/key.h
+++ b/drivers/staging/vt6656/key.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: key.h 6 * File: key.h
17 * 7 *
18 * Purpose: Implement functions for 802.11i Key management 8 * Purpose: Implement functions for 802.11i Key management
diff --git a/drivers/staging/vt6656/mac.c b/drivers/staging/vt6656/mac.c
index 417fdad1f9ae..0b543854ea97 100644
--- a/drivers/staging/vt6656/mac.c
+++ b/drivers/staging/vt6656/mac.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: mac.c 6 * File: mac.c
17 * 7 *
18 * Purpose: MAC routines 8 * Purpose: MAC routines
diff --git a/drivers/staging/vt6656/mac.h b/drivers/staging/vt6656/mac.h
index 29f37a0ff156..94e700fcd0b6 100644
--- a/drivers/staging/vt6656/mac.h
+++ b/drivers/staging/vt6656/mac.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: mac.h 6 * File: mac.h
17 * 7 *
18 * Purpose: MAC routines 8 * Purpose: MAC routines
diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
index cc6d8778fe5b..ccafcc2c87ac 100644
--- a/drivers/staging/vt6656/main_usb.c
+++ b/drivers/staging/vt6656/main_usb.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: main_usb.c 6 * File: main_usb.c
17 * 7 *
18 * Purpose: driver entry for initial, open, close, tx and rx. 8 * Purpose: driver entry for initial, open, close, tx and rx.
@@ -437,11 +427,8 @@ static bool vnt_alloc_bufs(struct vnt_private *priv)
437 427
438 for (ii = 0; ii < priv->num_rcb; ii++) { 428 for (ii = 0; ii < priv->num_rcb; ii++) {
439 priv->rcb[ii] = kzalloc(sizeof(*priv->rcb[ii]), GFP_KERNEL); 429 priv->rcb[ii] = kzalloc(sizeof(*priv->rcb[ii]), GFP_KERNEL);
440 if (!priv->rcb[ii]) { 430 if (!priv->rcb[ii])
441 dev_err(&priv->usb->dev,
442 "failed to allocate rcb no %d\n", ii);
443 goto free_rx_tx; 431 goto free_rx_tx;
444 }
445 432
446 rcb = priv->rcb[ii]; 433 rcb = priv->rcb[ii];
447 434
diff --git a/drivers/staging/vt6656/power.c b/drivers/staging/vt6656/power.c
index c466e0614bc4..7a086c72d5a8 100644
--- a/drivers/staging/vt6656/power.c
+++ b/drivers/staging/vt6656/power.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: power.c 6 * File: power.c
17 * 7 *
18 * Purpose: Handles 802.11 power management functions 8 * Purpose: Handles 802.11 power management functions
diff --git a/drivers/staging/vt6656/power.h b/drivers/staging/vt6656/power.h
index 859e75fc77ac..d5a3198206da 100644
--- a/drivers/staging/vt6656/power.h
+++ b/drivers/staging/vt6656/power.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: power.h 6 * File: power.h
17 * 7 *
18 * Purpose: Handles 802.11 power management functions 8 * Purpose: Handles 802.11 power management functions
diff --git a/drivers/staging/vt6656/rf.c b/drivers/staging/vt6656/rf.c
index 3a9d19a0b842..18f75dcc65d2 100644
--- a/drivers/staging/vt6656/rf.c
+++ b/drivers/staging/vt6656/rf.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: rf.c 6 * File: rf.c
17 * 7 *
18 * Purpose: rf function code 8 * Purpose: rf function code
diff --git a/drivers/staging/vt6656/rf.h b/drivers/staging/vt6656/rf.h
index c907a18047d2..f77866a9c177 100644
--- a/drivers/staging/vt6656/rf.h
+++ b/drivers/staging/vt6656/rf.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: rf.h 6 * File: rf.h
17 * 7 *
18 * Purpose: 8 * Purpose:
diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c
index a44abcce6fb4..26ca3fa29301 100644
--- a/drivers/staging/vt6656/rxtx.c
+++ b/drivers/staging/vt6656/rxtx.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: rxtx.c 6 * File: rxtx.c
17 * 7 *
18 * Purpose: handle WMAC/802.3/802.11 rx & tx functions 8 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
diff --git a/drivers/staging/vt6656/rxtx.h b/drivers/staging/vt6656/rxtx.h
index 1ba8647bea86..44698f41a234 100644
--- a/drivers/staging/vt6656/rxtx.h
+++ b/drivers/staging/vt6656/rxtx.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: rxtx.h 6 * File: rxtx.h
17 * 7 *
18 * Purpose: 8 * Purpose:
diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c
index 23eaef458556..273176386a51 100644
--- a/drivers/staging/vt6656/usbpipe.c
+++ b/drivers/staging/vt6656/usbpipe.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: usbpipe.c 6 * File: usbpipe.c
17 * 7 *
18 * Purpose: Handle USB control endpoint 8 * Purpose: Handle USB control endpoint
diff --git a/drivers/staging/vt6656/usbpipe.h b/drivers/staging/vt6656/usbpipe.h
index 9fc5ac0ef6c1..5d7708fcf557 100644
--- a/drivers/staging/vt6656/usbpipe.h
+++ b/drivers/staging/vt6656/usbpipe.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: usbpipe.h 6 * File: usbpipe.h
17 * 7 *
18 * Purpose: 8 * Purpose:
diff --git a/drivers/staging/vt6656/wcmd.c b/drivers/staging/vt6656/wcmd.c
index b2fc17f1381b..3eb2f11a5de1 100644
--- a/drivers/staging/vt6656/wcmd.c
+++ b/drivers/staging/vt6656/wcmd.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: wcmd.c 6 * File: wcmd.c
17 * 7 *
18 * Purpose: Handles the management command interface functions 8 * Purpose: Handles the management command interface functions
diff --git a/drivers/staging/vt6656/wcmd.h b/drivers/staging/vt6656/wcmd.h
index 727ec14380c4..4a96f4de980d 100644
--- a/drivers/staging/vt6656/wcmd.h
+++ b/drivers/staging/vt6656/wcmd.h
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved. 4 * All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 * File: wcmd.h 6 * File: wcmd.h
17 * 7 *
18 * Purpose: Handles the management command interface functions 8 * Purpose: Handles the management command interface functions
diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c
index 8cf886d32afb..e98fc8e93011 100644
--- a/drivers/staging/wilc1000/coreconfigurator.c
+++ b/drivers/staging/wilc1000/coreconfigurator.c
@@ -201,7 +201,7 @@ static inline u16 get_cap_info(u8 *data)
201 201
202 st = get_sub_type(data); 202 st = get_sub_type(data);
203 203
204 if ((st == BEACON) || (st == PROBE_RSP)) 204 if (st == BEACON || st == PROBE_RSP)
205 index += TIME_STAMP_LEN + BEACON_INTERVAL_LEN; 205 index += TIME_STAMP_LEN + BEACON_INTERVAL_LEN;
206 206
207 cap_info = data[index]; 207 cap_info = data[index];
diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index d69248a8c7b5..358354b3a2b4 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -202,7 +202,7 @@ struct host_if_msg {
202}; 202};
203 203
204struct join_bss_param { 204struct join_bss_param {
205 BSSTYPE_T bss_type; 205 enum bss_types bss_type;
206 u8 dtim_period; 206 u8 dtim_period;
207 u16 beacon_period; 207 u16 beacon_period;
208 u16 cap_info; 208 u16 cap_info;
@@ -394,7 +394,7 @@ static void handle_set_operation_mode(struct wilc_vif *vif,
394 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1, 394 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
395 wilc_get_vif_idx(vif)); 395 wilc_get_vif_idx(vif));
396 396
397 if ((hif_op_mode->mode) == IDLE_MODE) 397 if (hif_op_mode->mode == IDLE_MODE)
398 complete(&hif_driver_comp); 398 complete(&hif_driver_comp);
399 399
400 if (ret) 400 if (ret)
@@ -760,8 +760,8 @@ static s32 handle_scan(struct wilc_vif *vif, struct scan_attr *scan_info)
760 hif_drv->usr_scan_req.scan_result = scan_info->result; 760 hif_drv->usr_scan_req.scan_result = scan_info->result;
761 hif_drv->usr_scan_req.arg = scan_info->arg; 761 hif_drv->usr_scan_req.arg = scan_info->arg;
762 762
763 if ((hif_drv->hif_state >= HOST_IF_SCANNING) && 763 if (hif_drv->hif_state >= HOST_IF_SCANNING &&
764 (hif_drv->hif_state < HOST_IF_CONNECTED)) { 764 hif_drv->hif_state < HOST_IF_CONNECTED) {
765 netdev_err(vif->ndev, "Already scan\n"); 765 netdev_err(vif->ndev, "Already scan\n");
766 result = -EBUSY; 766 result = -EBUSY;
767 goto ERRORHANDLER; 767 goto ERRORHANDLER;
@@ -1025,7 +1025,7 @@ static s32 Handle_Connect(struct wilc_vif *vif,
1025 pu8CurrByte += MAX_SSID_LEN; 1025 pu8CurrByte += MAX_SSID_LEN;
1026 *(pu8CurrByte++) = INFRASTRUCTURE; 1026 *(pu8CurrByte++) = INFRASTRUCTURE;
1027 1027
1028 if ((pstrHostIFconnectAttr->ch >= 1) && (pstrHostIFconnectAttr->ch <= 14)) { 1028 if (pstrHostIFconnectAttr->ch >= 1 && pstrHostIFconnectAttr->ch <= 14) {
1029 *(pu8CurrByte++) = pstrHostIFconnectAttr->ch; 1029 *(pu8CurrByte++) = pstrHostIFconnectAttr->ch;
1030 } else { 1030 } else {
1031 netdev_err(vif->ndev, "Channel out of range\n"); 1031 netdev_err(vif->ndev, "Channel out of range\n");
@@ -1258,8 +1258,8 @@ static s32 Handle_RcvdNtwrkInfo(struct wilc_vif *vif,
1258 1258
1259 if (hif_drv->usr_scan_req.scan_result) { 1259 if (hif_drv->usr_scan_req.scan_result) {
1260 wilc_parse_network_info(pstrRcvdNetworkInfo->buffer, &pstrNetworkInfo); 1260 wilc_parse_network_info(pstrRcvdNetworkInfo->buffer, &pstrNetworkInfo);
1261 if ((!pstrNetworkInfo) || 1261 if (!pstrNetworkInfo ||
1262 (!hif_drv->usr_scan_req.scan_result)) { 1262 !hif_drv->usr_scan_req.scan_result) {
1263 netdev_err(vif->ndev, "driver is null\n"); 1263 netdev_err(vif->ndev, "driver is null\n");
1264 result = -EINVAL; 1264 result = -EINVAL;
1265 goto done; 1265 goto done;
@@ -1340,8 +1340,8 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct wilc_vif *vif,
1340 return -ENODEV; 1340 return -ENODEV;
1341 } 1341 }
1342 1342
1343 if ((hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) || 1343 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
1344 (hif_drv->hif_state == HOST_IF_CONNECTED) || 1344 hif_drv->hif_state == HOST_IF_CONNECTED ||
1345 hif_drv->usr_scan_req.scan_result) { 1345 hif_drv->usr_scan_req.scan_result) {
1346 if (!pstrRcvdGnrlAsyncInfo->buffer || 1346 if (!pstrRcvdGnrlAsyncInfo->buffer ||
1347 !hif_drv->usr_conn_req.conn_result) { 1347 !hif_drv->usr_conn_req.conn_result) {
@@ -1400,8 +1400,8 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct wilc_vif *vif,
1400 } 1400 }
1401 } 1401 }
1402 1402
1403 if ((u8MacStatus == MAC_CONNECTED) && 1403 if (u8MacStatus == MAC_CONNECTED &&
1404 (strConnectInfo.status != SUCCESSFUL_STATUSCODE)) { 1404 strConnectInfo.status != SUCCESSFUL_STATUSCODE) {
1405 netdev_err(vif->ndev, "Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE\n"); 1405 netdev_err(vif->ndev, "Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE\n");
1406 eth_zero_addr(wilc_connected_ssid); 1406 eth_zero_addr(wilc_connected_ssid);
1407 } else if (u8MacStatus == MAC_DISCONNECTED) { 1407 } else if (u8MacStatus == MAC_DISCONNECTED) {
@@ -1412,8 +1412,8 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct wilc_vif *vif,
1412 if (hif_drv->usr_conn_req.bssid) { 1412 if (hif_drv->usr_conn_req.bssid) {
1413 memcpy(strConnectInfo.bssid, hif_drv->usr_conn_req.bssid, 6); 1413 memcpy(strConnectInfo.bssid, hif_drv->usr_conn_req.bssid, 6);
1414 1414
1415 if ((u8MacStatus == MAC_CONNECTED) && 1415 if (u8MacStatus == MAC_CONNECTED &&
1416 (strConnectInfo.status == SUCCESSFUL_STATUSCODE)) { 1416 strConnectInfo.status == SUCCESSFUL_STATUSCODE) {
1417 memcpy(hif_drv->assoc_bssid, 1417 memcpy(hif_drv->assoc_bssid,
1418 hif_drv->usr_conn_req.bssid, ETH_ALEN); 1418 hif_drv->usr_conn_req.bssid, ETH_ALEN);
1419 } 1419 }
@@ -1434,8 +1434,8 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct wilc_vif *vif,
1434 NULL, 1434 NULL,
1435 hif_drv->usr_conn_req.arg); 1435 hif_drv->usr_conn_req.arg);
1436 1436
1437 if ((u8MacStatus == MAC_CONNECTED) && 1437 if (u8MacStatus == MAC_CONNECTED &&
1438 (strConnectInfo.status == SUCCESSFUL_STATUSCODE)) { 1438 strConnectInfo.status == SUCCESSFUL_STATUSCODE) {
1439 wilc_set_power_mgmt(vif, 0, 0); 1439 wilc_set_power_mgmt(vif, 0, 0);
1440 1440
1441 hif_drv->hif_state = HOST_IF_CONNECTED; 1441 hif_drv->hif_state = HOST_IF_CONNECTED;
@@ -1864,8 +1864,8 @@ void wilc_resolve_disconnect_aberration(struct wilc_vif *vif)
1864{ 1864{
1865 if (!vif->hif_drv) 1865 if (!vif->hif_drv)
1866 return; 1866 return;
1867 if ((vif->hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) || 1867 if (vif->hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
1868 (vif->hif_drv->hif_state == HOST_IF_CONNECTING)) 1868 vif->hif_drv->hif_state == HOST_IF_CONNECTING)
1869 wilc_disconnect(vif, 1); 1869 wilc_disconnect(vif, 1);
1870} 1870}
1871 1871
@@ -2414,7 +2414,7 @@ static void Handle_SetMulticastFilter(struct wilc_vif *vif,
2414 2414
2415 wid.id = (u16)WID_SETUP_MULTICAST_FILTER; 2415 wid.id = (u16)WID_SETUP_MULTICAST_FILTER;
2416 wid.type = WID_BIN; 2416 wid.type = WID_BIN;
2417 wid.size = sizeof(struct set_multicast) + ((strHostIfSetMulti->cnt) * ETH_ALEN); 2417 wid.size = sizeof(struct set_multicast) + (strHostIfSetMulti->cnt * ETH_ALEN);
2418 wid.val = kmalloc(wid.size, GFP_KERNEL); 2418 wid.val = kmalloc(wid.size, GFP_KERNEL);
2419 if (!wid.val) 2419 if (!wid.val)
2420 goto ERRORHANDLER; 2420 goto ERRORHANDLER;
@@ -3730,8 +3730,8 @@ int wilc_add_station(struct wilc_vif *vif, struct add_sta_param *sta_param)
3730 memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param)); 3730 memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param));
3731 if (add_sta_info->rates_len > 0) { 3731 if (add_sta_info->rates_len > 0) {
3732 add_sta_info->rates = kmemdup(sta_param->rates, 3732 add_sta_info->rates = kmemdup(sta_param->rates,
3733 add_sta_info->rates_len, 3733 add_sta_info->rates_len,
3734 GFP_KERNEL); 3734 GFP_KERNEL);
3735 if (!add_sta_info->rates) 3735 if (!add_sta_info->rates)
3736 return -ENOMEM; 3736 return -ENOMEM;
3737 } 3737 }
diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 119f3459b5bb..d9725efe0537 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "wilc_wfi_cfgoperations.h" 2#include "wilc_wfi_cfgoperations.h"
2#include "wilc_wlan_if.h" 3#include "wilc_wlan_if.h"
3#include "wilc_wlan.h" 4#include "wilc_wlan.h"
@@ -694,7 +695,7 @@ static int wlan_initialize_threads(struct net_device *dev)
694 wilc = vif->wilc; 695 wilc = vif->wilc;
695 696
696 wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev, 697 wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev,
697 "K_TXQ_TASK"); 698 "K_TXQ_TASK");
698 if (IS_ERR(wilc->txq_thread)) { 699 if (IS_ERR(wilc->txq_thread)) {
699 netdev_err(dev, "couldn't create TXQ thread\n"); 700 netdev_err(dev, "couldn't create TXQ thread\n");
700 wilc->close = 0; 701 wilc->close = 0;
@@ -910,13 +911,13 @@ static void wilc_set_multicast_list(struct net_device *dev)
910 if (dev->flags & IFF_PROMISC) 911 if (dev->flags & IFF_PROMISC)
911 return; 912 return;
912 913
913 if ((dev->flags & IFF_ALLMULTI) || 914 if (dev->flags & IFF_ALLMULTI ||
914 (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) { 915 dev->mc.count > WILC_MULTICAST_TABLE_SIZE) {
915 wilc_setup_multicast_filter(vif, false, 0); 916 wilc_setup_multicast_filter(vif, false, 0);
916 return; 917 return;
917 } 918 }
918 919
919 if ((dev->mc.count) == 0) { 920 if (dev->mc.count == 0) {
920 wilc_setup_multicast_filter(vif, true, 0); 921 wilc_setup_multicast_filter(vif, true, 0);
921 return; 922 return;
922 } 923 }
@@ -1029,7 +1030,7 @@ static int wilc_mac_close(struct net_device *ndev)
1029 if (!hif_drv) 1030 if (!hif_drv)
1030 return 0; 1031 return 0;
1031 1032
1032 if ((wl->open_ifcs) > 0) 1033 if (wl->open_ifcs > 0)
1033 wl->open_ifcs--; 1034 wl->open_ifcs--;
1034 else 1035 else
1035 return 0; 1036 return 0;
diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
index ce54864569c7..0deb61a21b27 100644
--- a/drivers/staging/wilc1000/wilc_debugfs.c
+++ b/drivers/staging/wilc1000/wilc_debugfs.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * NewportMedia WiFi chipset driver test tools - wilc-debug 3 * NewportMedia WiFi chipset driver test tools - wilc-debug
3 * Copyright (c) 2012 NewportMedia Inc. 4 * Copyright (c) 2012 NewportMedia Inc.
diff --git a/drivers/staging/wilc1000/wilc_sdio.c b/drivers/staging/wilc1000/wilc_sdio.c
index 0189e3edbbbe..bb65b374c1ce 100644
--- a/drivers/staging/wilc1000/wilc_sdio.c
+++ b/drivers/staging/wilc1000/wilc_sdio.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (c) Atmel Corporation. All rights reserved. 3 * Copyright (c) Atmel Corporation. All rights reserved.
3 * 4 *
@@ -374,7 +375,7 @@ static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data)
374 375
375 data = cpu_to_le32(data); 376 data = cpu_to_le32(data);
376 377
377 if ((addr >= 0xf0) && (addr <= 0xff)) { 378 if (addr >= 0xf0 && addr <= 0xff) {
378 struct sdio_cmd52 cmd; 379 struct sdio_cmd52 cmd;
379 380
380 cmd.read_write = 1; 381 cmd.read_write = 1;
@@ -514,7 +515,7 @@ static int sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data)
514 struct sdio_func *func = dev_to_sdio_func(wilc->dev); 515 struct sdio_func *func = dev_to_sdio_func(wilc->dev);
515 int ret; 516 int ret;
516 517
517 if ((addr >= 0xf0) && (addr <= 0xff)) { 518 if (addr >= 0xf0 && addr <= 0xff) {
518 struct sdio_cmd52 cmd; 519 struct sdio_cmd52 cmd;
519 520
520 cmd.read_write = 0; 521 cmd.read_write = 0;
diff --git a/drivers/staging/wilc1000/wilc_spi.c b/drivers/staging/wilc1000/wilc_spi.c
index 5ef84410e0f2..8f71a6022721 100644
--- a/drivers/staging/wilc1000/wilc_spi.c
+++ b/drivers/staging/wilc1000/wilc_spi.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (c) Atmel Corporation. All rights reserved. 3 * Copyright (c) Atmel Corporation. All rights reserved.
3 * 4 *
@@ -389,11 +390,11 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
389#define NUM_DATA_BYTES (4) 390#define NUM_DATA_BYTES (4)
390#define NUM_CRC_BYTES (2) 391#define NUM_CRC_BYTES (2)
391#define NUM_DUMMY_BYTES (3) 392#define NUM_DUMMY_BYTES (3)
392 if ((cmd == CMD_RESET) || 393 if (cmd == CMD_RESET ||
393 (cmd == CMD_TERMINATE) || 394 cmd == CMD_TERMINATE ||
394 (cmd == CMD_REPEAT)) { 395 cmd == CMD_REPEAT) {
395 len2 = len + (NUM_SKIP_BYTES + NUM_RSP_BYTES + NUM_DUMMY_BYTES); 396 len2 = len + (NUM_SKIP_BYTES + NUM_RSP_BYTES + NUM_DUMMY_BYTES);
396 } else if ((cmd == CMD_INTERNAL_READ) || (cmd == CMD_SINGLE_READ)) { 397 } else if (cmd == CMD_INTERNAL_READ || cmd == CMD_SINGLE_READ) {
397 if (!g_spi.crc_off) { 398 if (!g_spi.crc_off) {
398 len2 = len + (NUM_RSP_BYTES + NUM_DATA_HDR_BYTES + NUM_DATA_BYTES 399 len2 = len + (NUM_RSP_BYTES + NUM_DATA_HDR_BYTES + NUM_DATA_BYTES
399 + NUM_CRC_BYTES + NUM_DUMMY_BYTES); 400 + NUM_CRC_BYTES + NUM_DUMMY_BYTES);
@@ -424,9 +425,9 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
424 /** 425 /**
425 * Command/Control response 426 * Command/Control response
426 **/ 427 **/
427 if ((cmd == CMD_RESET) || 428 if (cmd == CMD_RESET ||
428 (cmd == CMD_TERMINATE) || 429 cmd == CMD_TERMINATE ||
429 (cmd == CMD_REPEAT)) { 430 cmd == CMD_REPEAT) {
430 rix++; /* skip 1 byte */ 431 rix++; /* skip 1 byte */
431 } 432 }
432 433
@@ -452,8 +453,8 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
452 return N_FAIL; 453 return N_FAIL;
453 } 454 }
454 455
455 if ((cmd == CMD_INTERNAL_READ) || (cmd == CMD_SINGLE_READ) || 456 if (cmd == CMD_INTERNAL_READ || cmd == CMD_SINGLE_READ ||
456 (cmd == CMD_DMA_READ) || (cmd == CMD_DMA_EXT_READ)) { 457 cmd == CMD_DMA_READ || cmd == CMD_DMA_EXT_READ) {
457 int retry; 458 int retry;
458 /* u16 crc1, crc2; */ 459 /* u16 crc1, crc2; */
459 u8 crc[2]; 460 u8 crc[2];
@@ -479,7 +480,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
479 return N_RESET; 480 return N_RESET;
480 } 481 }
481 482
482 if ((cmd == CMD_INTERNAL_READ) || (cmd == CMD_SINGLE_READ)) { 483 if (cmd == CMD_INTERNAL_READ || cmd == CMD_SINGLE_READ) {
483 /** 484 /**
484 * Read bytes 485 * Read bytes
485 **/ 486 **/
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 028da1dc1b81..621810d70450 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -379,7 +379,7 @@ static void CfgScanResult(enum scan_event scan_event,
379 struct cfg80211_bss *bss = NULL; 379 struct cfg80211_bss *bss = NULL;
380 380
381 priv = user_void; 381 priv = user_void;
382 if (priv->bCfgScanning) { 382 if (priv->cfg_scanning) {
383 if (scan_event == SCAN_EVENT_NETWORK_FOUND) { 383 if (scan_event == SCAN_EVENT_NETWORK_FOUND) {
384 wiphy = priv->dev->ieee80211_ptr->wiphy; 384 wiphy = priv->dev->ieee80211_ptr->wiphy;
385 385
@@ -399,8 +399,8 @@ static void CfgScanResult(enum scan_event scan_event,
399 return; 399 return;
400 400
401 if (network_info->new_network) { 401 if (network_info->new_network) {
402 if (priv->u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) { 402 if (priv->rcvd_ch_cnt < MAX_NUM_SCANNED_NETWORKS) {
403 priv->u32RcvdChCount++; 403 priv->rcvd_ch_cnt++;
404 404
405 add_network_to_shadow(network_info, priv, join_params); 405 add_network_to_shadow(network_info, priv, join_params);
406 406
@@ -422,7 +422,7 @@ static void CfgScanResult(enum scan_event scan_event,
422 } else { 422 } else {
423 u32 i; 423 u32 i;
424 424
425 for (i = 0; i < priv->u32RcvdChCount; i++) { 425 for (i = 0; i < priv->rcvd_ch_cnt; i++) {
426 if (memcmp(last_scanned_shadow[i].bssid, network_info->bssid, 6) == 0) { 426 if (memcmp(last_scanned_shadow[i].bssid, network_info->bssid, 6) == 0) {
427 last_scanned_shadow[i].rssi = network_info->rssi; 427 last_scanned_shadow[i].rssi = network_info->rssi;
428 last_scanned_shadow[i].time_scan = jiffies; 428 last_scanned_shadow[i].time_scan = jiffies;
@@ -436,21 +436,21 @@ static void CfgScanResult(enum scan_event scan_event,
436 436
437 mutex_lock(&priv->scan_req_lock); 437 mutex_lock(&priv->scan_req_lock);
438 438
439 if (priv->pstrScanReq) { 439 if (priv->scan_req) {
440 struct cfg80211_scan_info info = { 440 struct cfg80211_scan_info info = {
441 .aborted = false, 441 .aborted = false,
442 }; 442 };
443 443
444 cfg80211_scan_done(priv->pstrScanReq, &info); 444 cfg80211_scan_done(priv->scan_req, &info);
445 priv->u32RcvdChCount = 0; 445 priv->rcvd_ch_cnt = 0;
446 priv->bCfgScanning = false; 446 priv->cfg_scanning = false;
447 priv->pstrScanReq = NULL; 447 priv->scan_req = NULL;
448 } 448 }
449 mutex_unlock(&priv->scan_req_lock); 449 mutex_unlock(&priv->scan_req_lock);
450 } else if (scan_event == SCAN_EVENT_ABORTED) { 450 } else if (scan_event == SCAN_EVENT_ABORTED) {
451 mutex_lock(&priv->scan_req_lock); 451 mutex_lock(&priv->scan_req_lock);
452 452
453 if (priv->pstrScanReq) { 453 if (priv->scan_req) {
454 struct cfg80211_scan_info info = { 454 struct cfg80211_scan_info info = {
455 .aborted = false, 455 .aborted = false,
456 }; 456 };
@@ -458,9 +458,9 @@ static void CfgScanResult(enum scan_event scan_event,
458 update_scan_time(); 458 update_scan_time();
459 refresh_scan(priv, false); 459 refresh_scan(priv, false);
460 460
461 cfg80211_scan_done(priv->pstrScanReq, &info); 461 cfg80211_scan_done(priv->scan_req, &info);
462 priv->bCfgScanning = false; 462 priv->cfg_scanning = false;
463 priv->pstrScanReq = NULL; 463 priv->scan_req = NULL;
464 } 464 }
465 mutex_unlock(&priv->scan_req_lock); 465 mutex_unlock(&priv->scan_req_lock);
466 } 466 }
@@ -469,92 +469,92 @@ static void CfgScanResult(enum scan_event scan_event,
469 469
470int wilc_connecting; 470int wilc_connecting;
471 471
472static void CfgConnectResult(enum conn_event enuConnDisconnEvent, 472static void cfg_connect_result(enum conn_event conn_disconn_evt,
473 struct connect_info *pstrConnectInfo, 473 struct connect_info *conn_info,
474 u8 u8MacStatus, 474 u8 mac_status,
475 struct disconnect_info *pstrDisconnectNotifInfo, 475 struct disconnect_info *disconn_info,
476 void *pUserVoid) 476 void *priv_data)
477{ 477{
478 struct wilc_priv *priv; 478 struct wilc_priv *priv;
479 struct net_device *dev; 479 struct net_device *dev;
480 struct host_if_drv *pstrWFIDrv; 480 struct host_if_drv *wfi_drv;
481 u8 NullBssid[ETH_ALEN] = {0}; 481 u8 null_bssid[ETH_ALEN] = {0};
482 struct wilc *wl; 482 struct wilc *wl;
483 struct wilc_vif *vif; 483 struct wilc_vif *vif;
484 484
485 wilc_connecting = 0; 485 wilc_connecting = 0;
486 486
487 priv = pUserVoid; 487 priv = priv_data;
488 dev = priv->dev; 488 dev = priv->dev;
489 vif = netdev_priv(dev); 489 vif = netdev_priv(dev);
490 wl = vif->wilc; 490 wl = vif->wilc;
491 pstrWFIDrv = (struct host_if_drv *)priv->hif_drv; 491 wfi_drv = (struct host_if_drv *)priv->hif_drv;
492 492
493 if (enuConnDisconnEvent == CONN_DISCONN_EVENT_CONN_RESP) { 493 if (conn_disconn_evt == CONN_DISCONN_EVENT_CONN_RESP) {
494 u16 u16ConnectStatus; 494 u16 connect_status;
495 495
496 u16ConnectStatus = pstrConnectInfo->status; 496 connect_status = conn_info->status;
497 497
498 if ((u8MacStatus == MAC_DISCONNECTED) && 498 if (mac_status == MAC_DISCONNECTED &&
499 (pstrConnectInfo->status == SUCCESSFUL_STATUSCODE)) { 499 conn_info->status == SUCCESSFUL_STATUSCODE) {
500 u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE; 500 connect_status = WLAN_STATUS_UNSPECIFIED_FAILURE;
501 wilc_wlan_set_bssid(priv->dev, NullBssid, 501 wilc_wlan_set_bssid(priv->dev, null_bssid,
502 STATION_MODE); 502 STATION_MODE);
503 eth_zero_addr(wilc_connected_ssid); 503 eth_zero_addr(wilc_connected_ssid);
504 504
505 if (!pstrWFIDrv->p2p_connect) 505 if (!wfi_drv->p2p_connect)
506 wlan_channel = INVALID_CHANNEL; 506 wlan_channel = INVALID_CHANNEL;
507 507
508 netdev_err(dev, "Unspecified failure\n"); 508 netdev_err(dev, "Unspecified failure\n");
509 } 509 }
510 510
511 if (u16ConnectStatus == WLAN_STATUS_SUCCESS) { 511 if (connect_status == WLAN_STATUS_SUCCESS) {
512 bool bNeedScanRefresh = false; 512 bool scan_refresh = false;
513 u32 i; 513 u32 i;
514 514
515 memcpy(priv->au8AssociatedBss, pstrConnectInfo->bssid, ETH_ALEN); 515 memcpy(priv->associated_bss, conn_info->bssid, ETH_ALEN);
516 516
517 for (i = 0; i < last_scanned_cnt; i++) { 517 for (i = 0; i < last_scanned_cnt; i++) {
518 if (memcmp(last_scanned_shadow[i].bssid, 518 if (memcmp(last_scanned_shadow[i].bssid,
519 pstrConnectInfo->bssid, 519 conn_info->bssid,
520 ETH_ALEN) == 0) { 520 ETH_ALEN) == 0) {
521 unsigned long now = jiffies; 521 unsigned long now = jiffies;
522 522
523 if (time_after(now, 523 if (time_after(now,
524 last_scanned_shadow[i].time_scan_cached + 524 last_scanned_shadow[i].time_scan_cached +
525 (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) 525 (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ))))
526 bNeedScanRefresh = true; 526 scan_refresh = true;
527 527
528 break; 528 break;
529 } 529 }
530 } 530 }
531 531
532 if (bNeedScanRefresh) 532 if (scan_refresh)
533 refresh_scan(priv, true); 533 refresh_scan(priv, true);
534 } 534 }
535 535
536 cfg80211_connect_result(dev, pstrConnectInfo->bssid, 536 cfg80211_connect_result(dev, conn_info->bssid,
537 pstrConnectInfo->req_ies, pstrConnectInfo->req_ies_len, 537 conn_info->req_ies, conn_info->req_ies_len,
538 pstrConnectInfo->resp_ies, pstrConnectInfo->resp_ies_len, 538 conn_info->resp_ies, conn_info->resp_ies_len,
539 u16ConnectStatus, GFP_KERNEL); 539 connect_status, GFP_KERNEL);
540 } else if (enuConnDisconnEvent == CONN_DISCONN_EVENT_DISCONN_NOTIF) { 540 } else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
541 wilc_optaining_ip = false; 541 wilc_optaining_ip = false;
542 p2p_local_random = 0x01; 542 p2p_local_random = 0x01;
543 p2p_recv_random = 0x00; 543 p2p_recv_random = 0x00;
544 wilc_ie = false; 544 wilc_ie = false;
545 eth_zero_addr(priv->au8AssociatedBss); 545 eth_zero_addr(priv->associated_bss);
546 wilc_wlan_set_bssid(priv->dev, NullBssid, STATION_MODE); 546 wilc_wlan_set_bssid(priv->dev, null_bssid, STATION_MODE);
547 eth_zero_addr(wilc_connected_ssid); 547 eth_zero_addr(wilc_connected_ssid);
548 548
549 if (!pstrWFIDrv->p2p_connect) 549 if (!wfi_drv->p2p_connect)
550 wlan_channel = INVALID_CHANNEL; 550 wlan_channel = INVALID_CHANNEL;
551 if ((pstrWFIDrv->IFC_UP) && (dev == wl->vif[1]->ndev)) 551 if (wfi_drv->IFC_UP && dev == wl->vif[1]->ndev)
552 pstrDisconnectNotifInfo->reason = 3; 552 disconn_info->reason = 3;
553 else if ((!pstrWFIDrv->IFC_UP) && (dev == wl->vif[1]->ndev)) 553 else if (!wfi_drv->IFC_UP && dev == wl->vif[1]->ndev)
554 pstrDisconnectNotifInfo->reason = 1; 554 disconn_info->reason = 1;
555 555
556 cfg80211_disconnected(dev, pstrDisconnectNotifInfo->reason, pstrDisconnectNotifInfo->ie, 556 cfg80211_disconnected(dev, disconn_info->reason, disconn_info->ie,
557 pstrDisconnectNotifInfo->ie_len, false, 557 disconn_info->ie_len, false,
558 GFP_KERNEL); 558 GFP_KERNEL);
559 } 559 }
560} 560}
@@ -585,7 +585,7 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
585{ 585{
586 struct wilc_priv *priv; 586 struct wilc_priv *priv;
587 u32 i; 587 u32 i;
588 s32 s32Error = 0; 588 s32 ret = 0;
589 u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS]; 589 u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS];
590 struct hidden_network strHiddenNetwork; 590 struct hidden_network strHiddenNetwork;
591 struct wilc_vif *vif; 591 struct wilc_vif *vif;
@@ -593,13 +593,13 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
593 priv = wiphy_priv(wiphy); 593 priv = wiphy_priv(wiphy);
594 vif = netdev_priv(priv->dev); 594 vif = netdev_priv(priv->dev);
595 595
596 priv->pstrScanReq = request; 596 priv->scan_req = request;
597 597
598 priv->u32RcvdChCount = 0; 598 priv->rcvd_ch_cnt = 0;
599 599
600 reset_shadow_found(); 600 reset_shadow_found();
601 601
602 priv->bCfgScanning = true; 602 priv->cfg_scanning = true;
603 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { 603 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) {
604 for (i = 0; i < request->n_channels; i++) 604 for (i = 0; i < request->n_channels; i++)
605 au8ScanChanList[i] = (u8)ieee80211_frequency_to_channel(request->channels[i]->center_freq); 605 au8ScanChanList[i] = (u8)ieee80211_frequency_to_channel(request->channels[i]->center_freq);
@@ -622,56 +622,56 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
622 strHiddenNetwork.n_ssids -= 1; 622 strHiddenNetwork.n_ssids -= 1;
623 } 623 }
624 } 624 }
625 s32Error = wilc_scan(vif, USER_SCAN, ACTIVE_SCAN, 625 ret = wilc_scan(vif, USER_SCAN, ACTIVE_SCAN,
626 au8ScanChanList, 626 au8ScanChanList,
627 request->n_channels, 627 request->n_channels,
628 (const u8 *)request->ie, 628 (const u8 *)request->ie,
629 request->ie_len, CfgScanResult, 629 request->ie_len, CfgScanResult,
630 (void *)priv, &strHiddenNetwork); 630 (void *)priv, &strHiddenNetwork);
631 } else { 631 } else {
632 s32Error = wilc_scan(vif, USER_SCAN, ACTIVE_SCAN, 632 ret = wilc_scan(vif, USER_SCAN, ACTIVE_SCAN,
633 au8ScanChanList, 633 au8ScanChanList,
634 request->n_channels, 634 request->n_channels,
635 (const u8 *)request->ie, 635 (const u8 *)request->ie,
636 request->ie_len, CfgScanResult, 636 request->ie_len, CfgScanResult,
637 (void *)priv, NULL); 637 (void *)priv, NULL);
638 } 638 }
639 } else { 639 } else {
640 netdev_err(priv->dev, "Requested scanned channels over\n"); 640 netdev_err(priv->dev, "Requested scanned channels over\n");
641 } 641 }
642 642
643 if (s32Error != 0) 643 if (ret != 0)
644 s32Error = -EBUSY; 644 ret = -EBUSY;
645 645
646 return s32Error; 646 return ret;
647} 647}
648 648
649static int connect(struct wiphy *wiphy, struct net_device *dev, 649static int connect(struct wiphy *wiphy, struct net_device *dev,
650 struct cfg80211_connect_params *sme) 650 struct cfg80211_connect_params *sme)
651{ 651{
652 s32 s32Error = 0; 652 s32 ret = 0;
653 u32 i; 653 u32 i;
654 u32 sel_bssi_idx = UINT_MAX; 654 u32 sel_bssi_idx = UINT_MAX;
655 u8 u8security = NO_ENCRYPT; 655 u8 u8security = NO_ENCRYPT;
656 enum AUTHTYPE tenuAuth_type = ANY; 656 enum AUTHTYPE auth_type = ANY;
657 657
658 struct wilc_priv *priv; 658 struct wilc_priv *priv;
659 struct host_if_drv *pstrWFIDrv; 659 struct host_if_drv *wfi_drv;
660 struct network_info *pstrNetworkInfo = NULL; 660 struct network_info *pstrNetworkInfo = NULL;
661 struct wilc_vif *vif; 661 struct wilc_vif *vif;
662 662
663 wilc_connecting = 1; 663 wilc_connecting = 1;
664 priv = wiphy_priv(wiphy); 664 priv = wiphy_priv(wiphy);
665 vif = netdev_priv(priv->dev); 665 vif = netdev_priv(priv->dev);
666 pstrWFIDrv = (struct host_if_drv *)priv->hif_drv; 666 wfi_drv = (struct host_if_drv *)priv->hif_drv;
667 667
668 if (!(strncmp(sme->ssid, "DIRECT-", 7))) 668 if (!(strncmp(sme->ssid, "DIRECT-", 7)))
669 pstrWFIDrv->p2p_connect = 1; 669 wfi_drv->p2p_connect = 1;
670 else 670 else
671 pstrWFIDrv->p2p_connect = 0; 671 wfi_drv->p2p_connect = 0;
672 672
673 for (i = 0; i < last_scanned_cnt; i++) { 673 for (i = 0; i < last_scanned_cnt; i++) {
674 if ((sme->ssid_len == last_scanned_shadow[i].ssid_len) && 674 if (sme->ssid_len == last_scanned_shadow[i].ssid_len &&
675 memcmp(last_scanned_shadow[i].ssid, 675 memcmp(last_scanned_shadow[i].ssid,
676 sme->ssid, 676 sme->ssid,
677 sme->ssid_len) == 0) { 677 sme->ssid_len) == 0) {
@@ -694,9 +694,9 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
694 if (sel_bssi_idx < last_scanned_cnt) { 694 if (sel_bssi_idx < last_scanned_cnt) {
695 pstrNetworkInfo = &last_scanned_shadow[sel_bssi_idx]; 695 pstrNetworkInfo = &last_scanned_shadow[sel_bssi_idx];
696 } else { 696 } else {
697 s32Error = -ENOENT; 697 ret = -ENOENT;
698 wilc_connecting = 0; 698 wilc_connecting = 0;
699 return s32Error; 699 return ret;
700 } 700 }
701 701
702 memset(priv->WILC_WFI_wep_key, 0, sizeof(priv->WILC_WFI_wep_key)); 702 memset(priv->WILC_WFI_wep_key, 0, sizeof(priv->WILC_WFI_wep_key));
@@ -744,10 +744,10 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
744 else 744 else
745 u8security = ENCRYPT_ENABLED | WPA | AES; 745 u8security = ENCRYPT_ENABLED | WPA | AES;
746 } else { 746 } else {
747 s32Error = -ENOTSUPP; 747 ret = -ENOTSUPP;
748 netdev_err(dev, "Not supported cipher\n"); 748 netdev_err(dev, "Not supported cipher\n");
749 wilc_connecting = 0; 749 wilc_connecting = 0;
750 return s32Error; 750 return ret;
751 } 751 }
752 } 752 }
753 753
@@ -763,11 +763,11 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
763 763
764 switch (sme->auth_type) { 764 switch (sme->auth_type) {
765 case NL80211_AUTHTYPE_OPEN_SYSTEM: 765 case NL80211_AUTHTYPE_OPEN_SYSTEM:
766 tenuAuth_type = OPEN_SYSTEM; 766 auth_type = OPEN_SYSTEM;
767 break; 767 break;
768 768
769 case NL80211_AUTHTYPE_SHARED_KEY: 769 case NL80211_AUTHTYPE_SHARED_KEY:
770 tenuAuth_type = SHARED_KEY; 770 auth_type = SHARED_KEY;
771 break; 771 break;
772 772
773 default: 773 default:
@@ -777,7 +777,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
777 if (sme->crypto.n_akm_suites) { 777 if (sme->crypto.n_akm_suites) {
778 switch (sme->crypto.akm_suites[0]) { 778 switch (sme->crypto.akm_suites[0]) {
779 case WLAN_AKM_SUITE_8021X: 779 case WLAN_AKM_SUITE_8021X:
780 tenuAuth_type = IEEE8021; 780 auth_type = IEEE8021;
781 break; 781 break;
782 782
783 default: 783 default:
@@ -787,35 +787,35 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
787 787
788 curr_channel = pstrNetworkInfo->ch; 788 curr_channel = pstrNetworkInfo->ch;
789 789
790 if (!pstrWFIDrv->p2p_connect) 790 if (!wfi_drv->p2p_connect)
791 wlan_channel = pstrNetworkInfo->ch; 791 wlan_channel = pstrNetworkInfo->ch;
792 792
793 wilc_wlan_set_bssid(dev, pstrNetworkInfo->bssid, STATION_MODE); 793 wilc_wlan_set_bssid(dev, pstrNetworkInfo->bssid, STATION_MODE);
794 794
795 s32Error = wilc_set_join_req(vif, pstrNetworkInfo->bssid, sme->ssid, 795 ret = wilc_set_join_req(vif, pstrNetworkInfo->bssid, sme->ssid,
796 sme->ssid_len, sme->ie, sme->ie_len, 796 sme->ssid_len, sme->ie, sme->ie_len,
797 CfgConnectResult, (void *)priv, 797 cfg_connect_result, (void *)priv,
798 u8security, tenuAuth_type, 798 u8security, auth_type,
799 pstrNetworkInfo->ch, 799 pstrNetworkInfo->ch,
800 pstrNetworkInfo->join_params); 800 pstrNetworkInfo->join_params);
801 if (s32Error != 0) { 801 if (ret != 0) {
802 netdev_err(dev, "wilc_set_join_req(): Error\n"); 802 netdev_err(dev, "wilc_set_join_req(): Error\n");
803 s32Error = -ENOENT; 803 ret = -ENOENT;
804 wilc_connecting = 0; 804 wilc_connecting = 0;
805 return s32Error; 805 return ret;
806 } 806 }
807 807
808 return s32Error; 808 return ret;
809} 809}
810 810
811static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code) 811static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code)
812{ 812{
813 s32 s32Error = 0; 813 s32 ret = 0;
814 struct wilc_priv *priv; 814 struct wilc_priv *priv;
815 struct host_if_drv *pstrWFIDrv; 815 struct host_if_drv *wfi_drv;
816 struct wilc_vif *vif; 816 struct wilc_vif *vif;
817 struct wilc *wilc; 817 struct wilc *wilc;
818 u8 NullBssid[ETH_ALEN] = {0}; 818 u8 null_bssid[ETH_ALEN] = {0};
819 819
820 wilc_connecting = 0; 820 wilc_connecting = 0;
821 priv = wiphy_priv(wiphy); 821 priv = wiphy_priv(wiphy);
@@ -831,23 +831,23 @@ static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_co
831 return 0; 831 return 0;
832 } 832 }
833 833
834 pstrWFIDrv = (struct host_if_drv *)priv->hif_drv; 834 wfi_drv = (struct host_if_drv *)priv->hif_drv;
835 if (!pstrWFIDrv->p2p_connect) 835 if (!wfi_drv->p2p_connect)
836 wlan_channel = INVALID_CHANNEL; 836 wlan_channel = INVALID_CHANNEL;
837 wilc_wlan_set_bssid(priv->dev, NullBssid, STATION_MODE); 837 wilc_wlan_set_bssid(priv->dev, null_bssid, STATION_MODE);
838 838
839 p2p_local_random = 0x01; 839 p2p_local_random = 0x01;
840 p2p_recv_random = 0x00; 840 p2p_recv_random = 0x00;
841 wilc_ie = false; 841 wilc_ie = false;
842 pstrWFIDrv->p2p_timeout = 0; 842 wfi_drv->p2p_timeout = 0;
843 843
844 s32Error = wilc_disconnect(vif, reason_code); 844 ret = wilc_disconnect(vif, reason_code);
845 if (s32Error != 0) { 845 if (ret != 0) {
846 netdev_err(priv->dev, "Error in disconnecting\n"); 846 netdev_err(priv->dev, "Error in disconnecting\n");
847 s32Error = -EINVAL; 847 ret = -EINVAL;
848 } 848 }
849 849
850 return s32Error; 850 return ret;
851} 851}
852 852
853static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, 853static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
@@ -855,14 +855,14 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
855 const u8 *mac_addr, struct key_params *params) 855 const u8 *mac_addr, struct key_params *params)
856 856
857{ 857{
858 s32 s32Error = 0, KeyLen = params->key_len; 858 s32 ret = 0, keylen = params->key_len;
859 struct wilc_priv *priv; 859 struct wilc_priv *priv;
860 const u8 *pu8RxMic = NULL; 860 const u8 *rx_mic = NULL;
861 const u8 *pu8TxMic = NULL; 861 const u8 *tx_mic = NULL;
862 u8 u8mode = NO_ENCRYPT; 862 u8 u8mode = NO_ENCRYPT;
863 u8 u8gmode = NO_ENCRYPT; 863 u8 u8gmode = NO_ENCRYPT;
864 u8 u8pmode = NO_ENCRYPT; 864 u8 u8pmode = NO_ENCRYPT;
865 enum AUTHTYPE tenuAuth_type = ANY; 865 enum AUTHTYPE auth_type = ANY;
866 struct wilc *wl; 866 struct wilc *wl;
867 struct wilc_vif *vif; 867 struct wilc_vif *vif;
868 868
@@ -877,7 +877,7 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
877 priv->WILC_WFI_wep_key_len[key_index] = params->key_len; 877 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
878 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len); 878 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
879 879
880 tenuAuth_type = OPEN_SYSTEM; 880 auth_type = OPEN_SYSTEM;
881 881
882 if (params->cipher == WLAN_CIPHER_SUITE_WEP40) 882 if (params->cipher == WLAN_CIPHER_SUITE_WEP40)
883 u8mode = ENCRYPT_ENABLED | WEP; 883 u8mode = ENCRYPT_ENABLED | WEP;
@@ -886,7 +886,7 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
886 886
887 wilc_add_wep_key_bss_ap(vif, params->key, 887 wilc_add_wep_key_bss_ap(vif, params->key,
888 params->key_len, key_index, 888 params->key_len, key_index,
889 u8mode, tenuAuth_type); 889 u8mode, auth_type);
890 break; 890 break;
891 } 891 }
892 if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) { 892 if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) {
@@ -922,9 +922,9 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
922 priv->wilc_groupkey = u8gmode; 922 priv->wilc_groupkey = u8gmode;
923 923
924 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { 924 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
925 pu8TxMic = params->key + 24; 925 tx_mic = params->key + 24;
926 pu8RxMic = params->key + 16; 926 rx_mic = params->key + 16;
927 KeyLen = params->key_len - 16; 927 keylen = params->key_len - 16;
928 } 928 }
929 kfree(priv->wilc_gtk[key_index]->key); 929 kfree(priv->wilc_gtk[key_index]->key);
930 930
@@ -932,7 +932,7 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
932 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len); 932 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
933 kfree(priv->wilc_gtk[key_index]->seq); 933 kfree(priv->wilc_gtk[key_index]->seq);
934 934
935 if ((params->seq_len) > 0) { 935 if (params->seq_len > 0) {
936 priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL); 936 priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
937 memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len); 937 memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
938 } 938 }
@@ -941,10 +941,10 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
941 priv->wilc_gtk[key_index]->key_len = params->key_len; 941 priv->wilc_gtk[key_index]->key_len = params->key_len;
942 priv->wilc_gtk[key_index]->seq_len = params->seq_len; 942 priv->wilc_gtk[key_index]->seq_len = params->seq_len;
943 943
944 wilc_add_rx_gtk(vif, params->key, KeyLen, 944 wilc_add_rx_gtk(vif, params->key, keylen,
945 key_index, params->seq_len, 945 key_index, params->seq_len,
946 params->seq, pu8RxMic, 946 params->seq, rx_mic,
947 pu8TxMic, AP_MODE, u8gmode); 947 tx_mic, AP_MODE, u8gmode);
948 948
949 } else { 949 } else {
950 if (params->cipher == WLAN_CIPHER_SUITE_TKIP) 950 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
@@ -953,9 +953,9 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
953 u8pmode = priv->wilc_groupkey | AES; 953 u8pmode = priv->wilc_groupkey | AES;
954 954
955 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { 955 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
956 pu8TxMic = params->key + 24; 956 tx_mic = params->key + 24;
957 pu8RxMic = params->key + 16; 957 rx_mic = params->key + 16;
958 KeyLen = params->key_len - 16; 958 keylen = params->key_len - 16;
959 } 959 }
960 960
961 kfree(priv->wilc_ptk[key_index]->key); 961 kfree(priv->wilc_ptk[key_index]->key);
@@ -964,20 +964,20 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
964 964
965 kfree(priv->wilc_ptk[key_index]->seq); 965 kfree(priv->wilc_ptk[key_index]->seq);
966 966
967 if ((params->seq_len) > 0) 967 if (params->seq_len > 0)
968 priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL); 968 priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
969 969
970 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len); 970 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
971 971
972 if ((params->seq_len) > 0) 972 if (params->seq_len > 0)
973 memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len); 973 memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
974 974
975 priv->wilc_ptk[key_index]->cipher = params->cipher; 975 priv->wilc_ptk[key_index]->cipher = params->cipher;
976 priv->wilc_ptk[key_index]->key_len = params->key_len; 976 priv->wilc_ptk[key_index]->key_len = params->key_len;
977 priv->wilc_ptk[key_index]->seq_len = params->seq_len; 977 priv->wilc_ptk[key_index]->seq_len = params->seq_len;
978 978
979 wilc_add_ptk(vif, params->key, KeyLen, 979 wilc_add_ptk(vif, params->key, keylen,
980 mac_addr, pu8RxMic, pu8TxMic, 980 mac_addr, rx_mic, tx_mic,
981 AP_MODE, u8pmode, key_index); 981 AP_MODE, u8pmode, key_index);
982 } 982 }
983 break; 983 break;
@@ -987,9 +987,9 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
987 u8mode = 0; 987 u8mode = 0;
988 if (!pairwise) { 988 if (!pairwise) {
989 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { 989 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
990 pu8RxMic = params->key + 24; 990 rx_mic = params->key + 24;
991 pu8TxMic = params->key + 16; 991 tx_mic = params->key + 16;
992 KeyLen = params->key_len - 16; 992 keylen = params->key_len - 16;
993 } 993 }
994 994
995 if (!g_gtk_keys_saved && netdev == wl->vif[0]->ndev) { 995 if (!g_gtk_keys_saved && netdev == wl->vif[0]->ndev) {
@@ -1013,16 +1013,16 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1013 g_gtk_keys_saved = true; 1013 g_gtk_keys_saved = true;
1014 } 1014 }
1015 1015
1016 wilc_add_rx_gtk(vif, params->key, KeyLen, 1016 wilc_add_rx_gtk(vif, params->key, keylen,
1017 key_index, params->seq_len, 1017 key_index, params->seq_len,
1018 params->seq, pu8RxMic, 1018 params->seq, rx_mic,
1019 pu8TxMic, STATION_MODE, 1019 tx_mic, STATION_MODE,
1020 u8mode); 1020 u8mode);
1021 } else { 1021 } else {
1022 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { 1022 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1023 pu8RxMic = params->key + 24; 1023 rx_mic = params->key + 24;
1024 pu8TxMic = params->key + 16; 1024 tx_mic = params->key + 16;
1025 KeyLen = params->key_len - 16; 1025 keylen = params->key_len - 16;
1026 } 1026 }
1027 1027
1028 if (!g_ptk_keys_saved && netdev == wl->vif[0]->ndev) { 1028 if (!g_ptk_keys_saved && netdev == wl->vif[0]->ndev) {
@@ -1046,8 +1046,8 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1046 g_ptk_keys_saved = true; 1046 g_ptk_keys_saved = true;
1047 } 1047 }
1048 1048
1049 wilc_add_ptk(vif, params->key, KeyLen, 1049 wilc_add_ptk(vif, params->key, keylen,
1050 mac_addr, pu8RxMic, pu8TxMic, 1050 mac_addr, rx_mic, tx_mic,
1051 STATION_MODE, u8mode, key_index); 1051 STATION_MODE, u8mode, key_index);
1052 } 1052 }
1053 } 1053 }
@@ -1055,10 +1055,10 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
1055 1055
1056 default: 1056 default:
1057 netdev_err(netdev, "Not supported cipher\n"); 1057 netdev_err(netdev, "Not supported cipher\n");
1058 s32Error = -ENOTSUPP; 1058 ret = -ENOTSUPP;
1059 } 1059 }
1060 1060
1061 return s32Error; 1061 return ret;
1062} 1062}
1063 1063
1064static int del_key(struct wiphy *wiphy, struct net_device *netdev, 1064static int del_key(struct wiphy *wiphy, struct net_device *netdev,
@@ -1082,7 +1082,7 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1082 kfree(g_key_wep_params.key); 1082 kfree(g_key_wep_params.key);
1083 g_key_wep_params.key = NULL; 1083 g_key_wep_params.key = NULL;
1084 1084
1085 if ((priv->wilc_gtk[key_index]) != NULL) { 1085 if (priv->wilc_gtk[key_index] != NULL) {
1086 kfree(priv->wilc_gtk[key_index]->key); 1086 kfree(priv->wilc_gtk[key_index]->key);
1087 priv->wilc_gtk[key_index]->key = NULL; 1087 priv->wilc_gtk[key_index]->key = NULL;
1088 kfree(priv->wilc_gtk[key_index]->seq); 1088 kfree(priv->wilc_gtk[key_index]->seq);
@@ -1092,7 +1092,7 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev,
1092 priv->wilc_gtk[key_index] = NULL; 1092 priv->wilc_gtk[key_index] = NULL;
1093 } 1093 }
1094 1094
1095 if ((priv->wilc_ptk[key_index]) != NULL) { 1095 if (priv->wilc_ptk[key_index] != NULL) {
1096 kfree(priv->wilc_ptk[key_index]->key); 1096 kfree(priv->wilc_ptk[key_index]->key);
1097 priv->wilc_ptk[key_index]->key = NULL; 1097 priv->wilc_ptk[key_index]->key = NULL;
1098 kfree(priv->wilc_ptk[key_index]->seq); 1098 kfree(priv->wilc_ptk[key_index]->seq);
@@ -1182,7 +1182,7 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev,
1182 1182
1183 if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) { 1183 if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) {
1184 for (i = 0; i < NUM_STA_ASSOCIATED; i++) { 1184 for (i = 0; i < NUM_STA_ASSOCIATED; i++) {
1185 if (!(memcmp(mac, priv->assoc_stainfo.au8Sta_AssociatedBss[i], ETH_ALEN))) { 1185 if (!(memcmp(mac, priv->assoc_stainfo.sta_associated_bss[i], ETH_ALEN))) {
1186 associatedsta = i; 1186 associatedsta = i;
1187 break; 1187 break;
1188 } 1188 }
@@ -1200,9 +1200,9 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev,
1200 } 1200 }
1201 1201
1202 if (vif->iftype == STATION_MODE) { 1202 if (vif->iftype == STATION_MODE) {
1203 struct rf_info strStatistics; 1203 struct rf_info stats;
1204 1204
1205 wilc_get_statistics(vif, &strStatistics); 1205 wilc_get_statistics(vif, &stats);
1206 1206
1207 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) | 1207 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
1208 BIT(NL80211_STA_INFO_RX_PACKETS) | 1208 BIT(NL80211_STA_INFO_RX_PACKETS) |
@@ -1210,16 +1210,16 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev,
1210 BIT(NL80211_STA_INFO_TX_FAILED) | 1210 BIT(NL80211_STA_INFO_TX_FAILED) |
1211 BIT(NL80211_STA_INFO_TX_BITRATE); 1211 BIT(NL80211_STA_INFO_TX_BITRATE);
1212 1212
1213 sinfo->signal = strStatistics.rssi; 1213 sinfo->signal = stats.rssi;
1214 sinfo->rx_packets = strStatistics.rx_cnt; 1214 sinfo->rx_packets = stats.rx_cnt;
1215 sinfo->tx_packets = strStatistics.tx_cnt + strStatistics.tx_fail_cnt; 1215 sinfo->tx_packets = stats.tx_cnt + stats.tx_fail_cnt;
1216 sinfo->tx_failed = strStatistics.tx_fail_cnt; 1216 sinfo->tx_failed = stats.tx_fail_cnt;
1217 sinfo->txrate.legacy = strStatistics.link_speed * 10; 1217 sinfo->txrate.legacy = stats.link_speed * 10;
1218 1218
1219 if ((strStatistics.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && 1219 if (stats.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
1220 (strStatistics.link_speed != DEFAULT_LINK_SPEED)) 1220 stats.link_speed != DEFAULT_LINK_SPEED)
1221 wilc_enable_tcp_ack_filter(true); 1221 wilc_enable_tcp_ack_filter(true);
1222 else if (strStatistics.link_speed != DEFAULT_LINK_SPEED) 1222 else if (stats.link_speed != DEFAULT_LINK_SPEED)
1223 wilc_enable_tcp_ack_filter(false); 1223 wilc_enable_tcp_ack_filter(false);
1224 } 1224 }
1225 return 0; 1225 return 0;
@@ -1233,46 +1233,46 @@ static int change_bss(struct wiphy *wiphy, struct net_device *dev,
1233 1233
1234static int set_wiphy_params(struct wiphy *wiphy, u32 changed) 1234static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
1235{ 1235{
1236 s32 s32Error = 0; 1236 s32 ret = 0;
1237 struct cfg_param_attr pstrCfgParamVal; 1237 struct cfg_param_attr cfg_param_val;
1238 struct wilc_priv *priv; 1238 struct wilc_priv *priv;
1239 struct wilc_vif *vif; 1239 struct wilc_vif *vif;
1240 1240
1241 priv = wiphy_priv(wiphy); 1241 priv = wiphy_priv(wiphy);
1242 vif = netdev_priv(priv->dev); 1242 vif = netdev_priv(priv->dev);
1243 1243
1244 pstrCfgParamVal.flag = 0; 1244 cfg_param_val.flag = 0;
1245 1245
1246 if (changed & WIPHY_PARAM_RETRY_SHORT) { 1246 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1247 pstrCfgParamVal.flag |= RETRY_SHORT; 1247 cfg_param_val.flag |= RETRY_SHORT;
1248 pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short; 1248 cfg_param_val.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short;
1249 } 1249 }
1250 if (changed & WIPHY_PARAM_RETRY_LONG) { 1250 if (changed & WIPHY_PARAM_RETRY_LONG) {
1251 pstrCfgParamVal.flag |= RETRY_LONG; 1251 cfg_param_val.flag |= RETRY_LONG;
1252 pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long; 1252 cfg_param_val.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long;
1253 } 1253 }
1254 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { 1254 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1255 pstrCfgParamVal.flag |= FRAG_THRESHOLD; 1255 cfg_param_val.flag |= FRAG_THRESHOLD;
1256 pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold; 1256 cfg_param_val.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold;
1257 } 1257 }
1258 1258
1259 if (changed & WIPHY_PARAM_RTS_THRESHOLD) { 1259 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1260 pstrCfgParamVal.flag |= RTS_THRESHOLD; 1260 cfg_param_val.flag |= RTS_THRESHOLD;
1261 pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold; 1261 cfg_param_val.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold;
1262 } 1262 }
1263 1263
1264 s32Error = wilc_hif_set_cfg(vif, &pstrCfgParamVal); 1264 ret = wilc_hif_set_cfg(vif, &cfg_param_val);
1265 if (s32Error) 1265 if (ret)
1266 netdev_err(priv->dev, "Error in setting WIPHY PARAMS\n"); 1266 netdev_err(priv->dev, "Error in setting WIPHY PARAMS\n");
1267 1267
1268 return s32Error; 1268 return ret;
1269} 1269}
1270 1270
1271static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev, 1271static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1272 struct cfg80211_pmksa *pmksa) 1272 struct cfg80211_pmksa *pmksa)
1273{ 1273{
1274 u32 i; 1274 u32 i;
1275 s32 s32Error = 0; 1275 s32 ret = 0;
1276 u8 flag = 0; 1276 u8 flag = 0;
1277 struct wilc_vif *vif; 1277 struct wilc_vif *vif;
1278 struct wilc_priv *priv = wiphy_priv(wiphy); 1278 struct wilc_priv *priv = wiphy_priv(wiphy);
@@ -1295,20 +1295,20 @@ static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1295 priv->pmkid_list.numpmkid++; 1295 priv->pmkid_list.numpmkid++;
1296 } else { 1296 } else {
1297 netdev_err(netdev, "Invalid PMKID index\n"); 1297 netdev_err(netdev, "Invalid PMKID index\n");
1298 s32Error = -EINVAL; 1298 ret = -EINVAL;
1299 } 1299 }
1300 1300
1301 if (!s32Error) 1301 if (!ret)
1302 s32Error = wilc_set_pmkid_info(vif, &priv->pmkid_list); 1302 ret = wilc_set_pmkid_info(vif, &priv->pmkid_list);
1303 1303
1304 return s32Error; 1304 return ret;
1305} 1305}
1306 1306
1307static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev, 1307static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1308 struct cfg80211_pmksa *pmksa) 1308 struct cfg80211_pmksa *pmksa)
1309{ 1309{
1310 u32 i; 1310 u32 i;
1311 s32 s32Error = 0; 1311 s32 ret = 0;
1312 1312
1313 struct wilc_priv *priv = wiphy_priv(wiphy); 1313 struct wilc_priv *priv = wiphy_priv(wiphy);
1314 1314
@@ -1331,10 +1331,10 @@ static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1331 } 1331 }
1332 priv->pmkid_list.numpmkid--; 1332 priv->pmkid_list.numpmkid--;
1333 } else { 1333 } else {
1334 s32Error = -EINVAL; 1334 ret = -EINVAL;
1335 } 1335 }
1336 1336
1337 return s32Error; 1337 return ret;
1338} 1338}
1339 1339
1340static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev) 1340static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
@@ -1346,7 +1346,7 @@ static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1346 return 0; 1346 return 0;
1347} 1347}
1348 1348
1349static void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len) 1349static void wilc_wfi_cfg_parse_rx_action(u8 *buf, u32 len)
1350{ 1350{
1351 u32 index = 0; 1351 u32 index = 0;
1352 u32 i = 0, j = 0; 1352 u32 i = 0, j = 0;
@@ -1382,7 +1382,7 @@ static void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
1382 } 1382 }
1383} 1383}
1384 1384
1385static void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype) 1385static void wilc_wfi_cfg_parse_tx_action(u8 *buf, u32 len, bool oper_ch, u8 iftype)
1386{ 1386{
1387 u32 index = 0; 1387 u32 index = 0;
1388 u32 i = 0, j = 0; 1388 u32 i = 0, j = 0;
@@ -1403,7 +1403,7 @@ static void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftyp
1403 op_channel_attr_index = index; 1403 op_channel_attr_index = index;
1404 index += buf[index + 1] + 3; 1404 index += buf[index + 1] + 3;
1405 } 1405 }
1406 if (wlan_channel != INVALID_CHANNEL && bOperChan) { 1406 if (wlan_channel != INVALID_CHANNEL && oper_ch) {
1407 if (channel_list_attr_index) { 1407 if (channel_list_attr_index) {
1408 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) { 1408 for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) {
1409 if (buf[i] == 0x51) { 1409 if (buf[i] == 0x51) {
@@ -1425,12 +1425,12 @@ void WILC_WFI_p2p_rx(struct net_device *dev, u8 *buff, u32 size)
1425{ 1425{
1426 struct wilc_priv *priv; 1426 struct wilc_priv *priv;
1427 u32 header, pkt_offset; 1427 u32 header, pkt_offset;
1428 struct host_if_drv *pstrWFIDrv; 1428 struct host_if_drv *wfi_drv;
1429 u32 i = 0; 1429 u32 i = 0;
1430 s32 s32Freq; 1430 s32 s32Freq;
1431 1431
1432 priv = wiphy_priv(dev->ieee80211_ptr->wiphy); 1432 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
1433 pstrWFIDrv = (struct host_if_drv *)priv->hif_drv; 1433 wfi_drv = (struct host_if_drv *)priv->hif_drv;
1434 1434
1435 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET); 1435 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
1436 1436
@@ -1438,20 +1438,20 @@ void WILC_WFI_p2p_rx(struct net_device *dev, u8 *buff, u32 size)
1438 1438
1439 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) { 1439 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
1440 if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP) { 1440 if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP) {
1441 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL); 1441 cfg80211_mgmt_tx_status(priv->wdev, priv->tx_cookie, buff, size, true, GFP_KERNEL);
1442 return; 1442 return;
1443 } else { 1443 } else {
1444 if (pkt_offset & IS_MGMT_STATUS_SUCCES) 1444 if (pkt_offset & IS_MGMT_STATUS_SUCCES)
1445 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, true, GFP_KERNEL); 1445 cfg80211_mgmt_tx_status(priv->wdev, priv->tx_cookie, buff, size, true, GFP_KERNEL);
1446 else 1446 else
1447 cfg80211_mgmt_tx_status(priv->wdev, priv->u64tx_cookie, buff, size, false, GFP_KERNEL); 1447 cfg80211_mgmt_tx_status(priv->wdev, priv->tx_cookie, buff, size, false, GFP_KERNEL);
1448 return; 1448 return;
1449 } 1449 }
1450 } else { 1450 } else {
1451 s32Freq = ieee80211_channel_to_frequency(curr_channel, NL80211_BAND_2GHZ); 1451 s32Freq = ieee80211_channel_to_frequency(curr_channel, NL80211_BAND_2GHZ);
1452 1452
1453 if (ieee80211_is_action(buff[FRAME_TYPE_ID])) { 1453 if (ieee80211_is_action(buff[FRAME_TYPE_ID])) {
1454 if (priv->bCfgScanning && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->p2p_timeout)) { 1454 if (priv->cfg_scanning && time_after_eq(jiffies, (unsigned long)wfi_drv->p2p_timeout)) {
1455 netdev_dbg(dev, "Receiving action wrong ch\n"); 1455 netdev_dbg(dev, "Receiving action wrong ch\n");
1456 return; 1456 return;
1457 } 1457 }
@@ -1481,7 +1481,7 @@ void WILC_WFI_p2p_rx(struct net_device *dev, u8 *buff, u32 size)
1481 buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) { 1481 buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
1482 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) { 1482 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) {
1483 if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(p2p_oui, &buff[i + 2], 4))) { 1483 if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(p2p_oui, &buff[i + 2], 4))) {
1484 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6)); 1484 wilc_wfi_cfg_parse_rx_action(&buff[i + 6], size - (i + 6));
1485 break; 1485 break;
1486 } 1486 }
1487 } 1487 }
@@ -1508,7 +1508,7 @@ void WILC_WFI_p2p_rx(struct net_device *dev, u8 *buff, u32 size)
1508 } 1508 }
1509} 1509}
1510 1510
1511static void WILC_WFI_mgmt_tx_complete(void *priv, int status) 1511static void wilc_wfi_mgmt_tx_complete(void *priv, int status)
1512{ 1512{
1513 struct p2p_mgmt_data *pv_data = priv; 1513 struct p2p_mgmt_data *pv_data = priv;
1514 1514
@@ -1516,33 +1516,33 @@ static void WILC_WFI_mgmt_tx_complete(void *priv, int status)
1516 kfree(pv_data); 1516 kfree(pv_data);
1517} 1517}
1518 1518
1519static void WILC_WFI_RemainOnChannelReady(void *pUserVoid) 1519static void wilc_wfi_remain_on_channel_ready(void *priv_data)
1520{ 1520{
1521 struct wilc_priv *priv; 1521 struct wilc_priv *priv;
1522 1522
1523 priv = pUserVoid; 1523 priv = priv_data;
1524 1524
1525 priv->bInP2PlistenState = true; 1525 priv->p2p_listen_state = true;
1526 1526
1527 cfg80211_ready_on_channel(priv->wdev, 1527 cfg80211_ready_on_channel(priv->wdev,
1528 priv->strRemainOnChanParams.u64ListenCookie, 1528 priv->remain_on_ch_params.listen_cookie,
1529 priv->strRemainOnChanParams.pstrListenChan, 1529 priv->remain_on_ch_params.listen_ch,
1530 priv->strRemainOnChanParams.u32ListenDuration, 1530 priv->remain_on_ch_params.listen_duration,
1531 GFP_KERNEL); 1531 GFP_KERNEL);
1532} 1532}
1533 1533
1534static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID) 1534static void wilc_wfi_remain_on_channel_expired(void *data, u32 session_id)
1535{ 1535{
1536 struct wilc_priv *priv; 1536 struct wilc_priv *priv;
1537 1537
1538 priv = pUserVoid; 1538 priv = data;
1539 1539
1540 if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) { 1540 if (session_id == priv->remain_on_ch_params.listen_session_id) {
1541 priv->bInP2PlistenState = false; 1541 priv->p2p_listen_state = false;
1542 1542
1543 cfg80211_remain_on_channel_expired(priv->wdev, 1543 cfg80211_remain_on_channel_expired(priv->wdev,
1544 priv->strRemainOnChanParams.u64ListenCookie, 1544 priv->remain_on_ch_params.listen_cookie,
1545 priv->strRemainOnChanParams.pstrListenChan, 1545 priv->remain_on_ch_params.listen_ch,
1546 GFP_KERNEL); 1546 GFP_KERNEL);
1547 } 1547 }
1548} 1548}
@@ -1552,7 +1552,7 @@ static int remain_on_channel(struct wiphy *wiphy,
1552 struct ieee80211_channel *chan, 1552 struct ieee80211_channel *chan,
1553 unsigned int duration, u64 *cookie) 1553 unsigned int duration, u64 *cookie)
1554{ 1554{
1555 s32 s32Error = 0; 1555 s32 ret = 0;
1556 struct wilc_priv *priv; 1556 struct wilc_priv *priv;
1557 struct wilc_vif *vif; 1557 struct wilc_vif *vif;
1558 1558
@@ -1561,21 +1561,21 @@ static int remain_on_channel(struct wiphy *wiphy,
1561 1561
1562 if (wdev->iftype == NL80211_IFTYPE_AP) { 1562 if (wdev->iftype == NL80211_IFTYPE_AP) {
1563 netdev_dbg(vif->ndev, "Required while in AP mode\n"); 1563 netdev_dbg(vif->ndev, "Required while in AP mode\n");
1564 return s32Error; 1564 return ret;
1565 } 1565 }
1566 1566
1567 curr_channel = chan->hw_value; 1567 curr_channel = chan->hw_value;
1568 1568
1569 priv->strRemainOnChanParams.pstrListenChan = chan; 1569 priv->remain_on_ch_params.listen_ch = chan;
1570 priv->strRemainOnChanParams.u64ListenCookie = *cookie; 1570 priv->remain_on_ch_params.listen_cookie = *cookie;
1571 priv->strRemainOnChanParams.u32ListenDuration = duration; 1571 priv->remain_on_ch_params.listen_duration = duration;
1572 priv->strRemainOnChanParams.u32ListenSessionID++; 1572 priv->remain_on_ch_params.listen_session_id++;
1573 1573
1574 return wilc_remain_on_channel(vif, 1574 return wilc_remain_on_channel(vif,
1575 priv->strRemainOnChanParams.u32ListenSessionID, 1575 priv->remain_on_ch_params.listen_session_id,
1576 duration, chan->hw_value, 1576 duration, chan->hw_value,
1577 WILC_WFI_RemainOnChannelExpired, 1577 wilc_wfi_remain_on_channel_expired,
1578 WILC_WFI_RemainOnChannelReady, (void *)priv); 1578 wilc_wfi_remain_on_channel_ready, (void *)priv);
1579} 1579}
1580 1580
1581static int cancel_remain_on_channel(struct wiphy *wiphy, 1581static int cancel_remain_on_channel(struct wiphy *wiphy,
@@ -1589,7 +1589,7 @@ static int cancel_remain_on_channel(struct wiphy *wiphy,
1589 vif = netdev_priv(priv->dev); 1589 vif = netdev_priv(priv->dev);
1590 1590
1591 return wilc_listen_state_expired(vif, 1591 return wilc_listen_state_expired(vif,
1592 priv->strRemainOnChanParams.u32ListenSessionID); 1592 priv->remain_on_ch_params.listen_session_id);
1593} 1593}
1594 1594
1595static int mgmt_tx(struct wiphy *wiphy, 1595static int mgmt_tx(struct wiphy *wiphy,
@@ -1604,17 +1604,17 @@ static int mgmt_tx(struct wiphy *wiphy,
1604 const struct ieee80211_mgmt *mgmt; 1604 const struct ieee80211_mgmt *mgmt;
1605 struct p2p_mgmt_data *mgmt_tx; 1605 struct p2p_mgmt_data *mgmt_tx;
1606 struct wilc_priv *priv; 1606 struct wilc_priv *priv;
1607 struct host_if_drv *pstrWFIDrv; 1607 struct host_if_drv *wfi_drv;
1608 u32 i; 1608 u32 i;
1609 struct wilc_vif *vif; 1609 struct wilc_vif *vif;
1610 u32 buf_len = len + sizeof(p2p_vendor_spec) + sizeof(p2p_local_random); 1610 u32 buf_len = len + sizeof(p2p_vendor_spec) + sizeof(p2p_local_random);
1611 1611
1612 vif = netdev_priv(wdev->netdev); 1612 vif = netdev_priv(wdev->netdev);
1613 priv = wiphy_priv(wiphy); 1613 priv = wiphy_priv(wiphy);
1614 pstrWFIDrv = (struct host_if_drv *)priv->hif_drv; 1614 wfi_drv = (struct host_if_drv *)priv->hif_drv;
1615 1615
1616 *cookie = (unsigned long)buf; 1616 *cookie = (unsigned long)buf;
1617 priv->u64tx_cookie = *cookie; 1617 priv->tx_cookie = *cookie;
1618 mgmt = (const struct ieee80211_mgmt *)buf; 1618 mgmt = (const struct ieee80211_mgmt *)buf;
1619 1619
1620 if (ieee80211_is_mgmt(mgmt->frame_control)) { 1620 if (ieee80211_is_mgmt(mgmt->frame_control)) {
@@ -1665,9 +1665,9 @@ static int mgmt_tx(struct wiphy *wiphy,
1665 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) { 1665 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
1666 if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(p2p_oui, &buf[i + 2], 4))) { 1666 if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(p2p_oui, &buf[i + 2], 4))) {
1667 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP) 1667 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
1668 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, vif->iftype); 1668 wilc_wfi_cfg_parse_tx_action(&mgmt_tx->buff[i + 6], len - (i + 6), true, vif->iftype);
1669 else 1669 else
1670 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, vif->iftype); 1670 wilc_wfi_cfg_parse_tx_action(&mgmt_tx->buff[i + 6], len - (i + 6), false, vif->iftype);
1671 break; 1671 break;
1672 } 1672 }
1673 } 1673 }
@@ -1695,12 +1695,12 @@ static int mgmt_tx(struct wiphy *wiphy,
1695 } 1695 }
1696 } 1696 }
1697 1697
1698 pstrWFIDrv->p2p_timeout = (jiffies + msecs_to_jiffies(wait)); 1698 wfi_drv->p2p_timeout = (jiffies + msecs_to_jiffies(wait));
1699 } 1699 }
1700 1700
1701 wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx, 1701 wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx,
1702 mgmt_tx->buff, mgmt_tx->size, 1702 mgmt_tx->buff, mgmt_tx->size,
1703 WILC_WFI_mgmt_tx_complete); 1703 wilc_wfi_mgmt_tx_complete);
1704 } 1704 }
1705 return 0; 1705 return 0;
1706} 1706}
@@ -1710,16 +1710,16 @@ static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
1710 u64 cookie) 1710 u64 cookie)
1711{ 1711{
1712 struct wilc_priv *priv; 1712 struct wilc_priv *priv;
1713 struct host_if_drv *pstrWFIDrv; 1713 struct host_if_drv *wfi_drv;
1714 1714
1715 priv = wiphy_priv(wiphy); 1715 priv = wiphy_priv(wiphy);
1716 pstrWFIDrv = (struct host_if_drv *)priv->hif_drv; 1716 wfi_drv = (struct host_if_drv *)priv->hif_drv;
1717 pstrWFIDrv->p2p_timeout = jiffies; 1717 wfi_drv->p2p_timeout = jiffies;
1718 1718
1719 if (!priv->bInP2PlistenState) { 1719 if (!priv->p2p_listen_state) {
1720 cfg80211_remain_on_channel_expired(priv->wdev, 1720 cfg80211_remain_on_channel_expired(priv->wdev,
1721 priv->strRemainOnChanParams.u64ListenCookie, 1721 priv->remain_on_ch_params.listen_cookie,
1722 priv->strRemainOnChanParams.pstrListenChan, 1722 priv->remain_on_ch_params.listen_ch,
1723 GFP_KERNEL); 1723 GFP_KERNEL);
1724 } 1724 }
1725 1725
@@ -1788,7 +1788,7 @@ static int dump_station(struct wiphy *wiphy, struct net_device *dev,
1788 1788
1789 wilc_get_rssi(vif, &sinfo->signal); 1789 wilc_get_rssi(vif, &sinfo->signal);
1790 1790
1791 memcpy(mac, priv->au8AssociatedBss, ETH_ALEN); 1791 memcpy(mac, priv->associated_bss, ETH_ALEN);
1792 return 0; 1792 return 0;
1793} 1793}
1794 1794
@@ -1837,7 +1837,7 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
1837 vif->iftype = STATION_MODE; 1837 vif->iftype = STATION_MODE;
1838 wilc_set_operation_mode(vif, STATION_MODE); 1838 wilc_set_operation_mode(vif, STATION_MODE);
1839 1839
1840 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN); 1840 memset(priv->assoc_stainfo.sta_associated_bss, 0, MAX_NUM_STA * ETH_ALEN);
1841 1841
1842 wilc_enable_ps = true; 1842 wilc_enable_ps = true;
1843 wilc_set_power_mgmt(vif, 1, 0); 1843 wilc_set_power_mgmt(vif, 1, 0);
@@ -1893,9 +1893,9 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
1893static int start_ap(struct wiphy *wiphy, struct net_device *dev, 1893static int start_ap(struct wiphy *wiphy, struct net_device *dev,
1894 struct cfg80211_ap_settings *settings) 1894 struct cfg80211_ap_settings *settings)
1895{ 1895{
1896 struct cfg80211_beacon_data *beacon = &(settings->beacon); 1896 struct cfg80211_beacon_data *beacon = &settings->beacon;
1897 struct wilc_priv *priv; 1897 struct wilc_priv *priv;
1898 s32 s32Error = 0; 1898 s32 ret = 0;
1899 struct wilc *wl; 1899 struct wilc *wl;
1900 struct wilc_vif *vif; 1900 struct wilc_vif *vif;
1901 1901
@@ -1903,9 +1903,9 @@ static int start_ap(struct wiphy *wiphy, struct net_device *dev,
1903 vif = netdev_priv(dev); 1903 vif = netdev_priv(dev);
1904 wl = vif->wilc; 1904 wl = vif->wilc;
1905 1905
1906 s32Error = set_channel(wiphy, &settings->chandef); 1906 ret = set_channel(wiphy, &settings->chandef);
1907 1907
1908 if (s32Error != 0) 1908 if (ret != 0)
1909 netdev_err(dev, "Error in setting channel\n"); 1909 netdev_err(dev, "Error in setting channel\n");
1910 1910
1911 wilc_wlan_set_bssid(dev, wl->vif[vif->idx]->src_addr, AP_MODE); 1911 wilc_wlan_set_bssid(dev, wl->vif[vif->idx]->src_addr, AP_MODE);
@@ -1933,10 +1933,10 @@ static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
1933 1933
1934static int stop_ap(struct wiphy *wiphy, struct net_device *dev) 1934static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
1935{ 1935{
1936 s32 s32Error = 0; 1936 s32 ret = 0;
1937 struct wilc_priv *priv; 1937 struct wilc_priv *priv;
1938 struct wilc_vif *vif; 1938 struct wilc_vif *vif;
1939 u8 NullBssid[ETH_ALEN] = {0}; 1939 u8 null_bssid[ETH_ALEN] = {0};
1940 1940
1941 if (!wiphy) 1941 if (!wiphy)
1942 return -EFAULT; 1942 return -EFAULT;
@@ -1944,22 +1944,22 @@ static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
1944 priv = wiphy_priv(wiphy); 1944 priv = wiphy_priv(wiphy);
1945 vif = netdev_priv(priv->dev); 1945 vif = netdev_priv(priv->dev);
1946 1946
1947 wilc_wlan_set_bssid(dev, NullBssid, AP_MODE); 1947 wilc_wlan_set_bssid(dev, null_bssid, AP_MODE);
1948 1948
1949 s32Error = wilc_del_beacon(vif); 1949 ret = wilc_del_beacon(vif);
1950 1950
1951 if (s32Error) 1951 if (ret)
1952 netdev_err(dev, "Host delete beacon fail\n"); 1952 netdev_err(dev, "Host delete beacon fail\n");
1953 1953
1954 return s32Error; 1954 return ret;
1955} 1955}
1956 1956
1957static int add_station(struct wiphy *wiphy, struct net_device *dev, 1957static int add_station(struct wiphy *wiphy, struct net_device *dev,
1958 const u8 *mac, struct station_parameters *params) 1958 const u8 *mac, struct station_parameters *params)
1959{ 1959{
1960 s32 s32Error = 0; 1960 s32 ret = 0;
1961 struct wilc_priv *priv; 1961 struct wilc_priv *priv;
1962 struct add_sta_param strStaParams = { {0} }; 1962 struct add_sta_param sta_params = { {0} };
1963 struct wilc_vif *vif; 1963 struct wilc_vif *vif;
1964 1964
1965 if (!wiphy) 1965 if (!wiphy)
@@ -1969,35 +1969,35 @@ static int add_station(struct wiphy *wiphy, struct net_device *dev,
1969 vif = netdev_priv(dev); 1969 vif = netdev_priv(dev);
1970 1970
1971 if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) { 1971 if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) {
1972 memcpy(strStaParams.bssid, mac, ETH_ALEN); 1972 memcpy(sta_params.bssid, mac, ETH_ALEN);
1973 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN); 1973 memcpy(priv->assoc_stainfo.sta_associated_bss[params->aid], mac, ETH_ALEN);
1974 strStaParams.aid = params->aid; 1974 sta_params.aid = params->aid;
1975 strStaParams.rates_len = params->supported_rates_len; 1975 sta_params.rates_len = params->supported_rates_len;
1976 strStaParams.rates = params->supported_rates; 1976 sta_params.rates = params->supported_rates;
1977 1977
1978 if (!params->ht_capa) { 1978 if (!params->ht_capa) {
1979 strStaParams.ht_supported = false; 1979 sta_params.ht_supported = false;
1980 } else { 1980 } else {
1981 strStaParams.ht_supported = true; 1981 sta_params.ht_supported = true;
1982 strStaParams.ht_capa = *params->ht_capa; 1982 sta_params.ht_capa = *params->ht_capa;
1983 } 1983 }
1984 1984
1985 strStaParams.flags_mask = params->sta_flags_mask; 1985 sta_params.flags_mask = params->sta_flags_mask;
1986 strStaParams.flags_set = params->sta_flags_set; 1986 sta_params.flags_set = params->sta_flags_set;
1987 1987
1988 s32Error = wilc_add_station(vif, &strStaParams); 1988 ret = wilc_add_station(vif, &sta_params);
1989 if (s32Error) 1989 if (ret)
1990 netdev_err(dev, "Host add station fail\n"); 1990 netdev_err(dev, "Host add station fail\n");
1991 } 1991 }
1992 1992
1993 return s32Error; 1993 return ret;
1994} 1994}
1995 1995
1996static int del_station(struct wiphy *wiphy, struct net_device *dev, 1996static int del_station(struct wiphy *wiphy, struct net_device *dev,
1997 struct station_del_parameters *params) 1997 struct station_del_parameters *params)
1998{ 1998{
1999 const u8 *mac = params->mac; 1999 const u8 *mac = params->mac;
2000 s32 s32Error = 0; 2000 s32 ret = 0;
2001 struct wilc_priv *priv; 2001 struct wilc_priv *priv;
2002 struct wilc_vif *vif; 2002 struct wilc_vif *vif;
2003 2003
@@ -2009,23 +2009,23 @@ static int del_station(struct wiphy *wiphy, struct net_device *dev,
2009 2009
2010 if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) { 2010 if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) {
2011 if (!mac) 2011 if (!mac)
2012 s32Error = wilc_del_allstation(vif, 2012 ret = wilc_del_allstation(vif,
2013 priv->assoc_stainfo.au8Sta_AssociatedBss); 2013 priv->assoc_stainfo.sta_associated_bss);
2014 2014
2015 s32Error = wilc_del_station(vif, mac); 2015 ret = wilc_del_station(vif, mac);
2016 2016
2017 if (s32Error) 2017 if (ret)
2018 netdev_err(dev, "Host delete station fail\n"); 2018 netdev_err(dev, "Host delete station fail\n");
2019 } 2019 }
2020 return s32Error; 2020 return ret;
2021} 2021}
2022 2022
2023static int change_station(struct wiphy *wiphy, struct net_device *dev, 2023static int change_station(struct wiphy *wiphy, struct net_device *dev,
2024 const u8 *mac, struct station_parameters *params) 2024 const u8 *mac, struct station_parameters *params)
2025{ 2025{
2026 s32 s32Error = 0; 2026 s32 ret = 0;
2027 struct wilc_priv *priv; 2027 struct wilc_priv *priv;
2028 struct add_sta_param strStaParams = { {0} }; 2028 struct add_sta_param sta_params = { {0} };
2029 struct wilc_vif *vif; 2029 struct wilc_vif *vif;
2030 2030
2031 if (!wiphy) 2031 if (!wiphy)
@@ -2035,26 +2035,26 @@ static int change_station(struct wiphy *wiphy, struct net_device *dev,
2035 vif = netdev_priv(dev); 2035 vif = netdev_priv(dev);
2036 2036
2037 if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) { 2037 if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) {
2038 memcpy(strStaParams.bssid, mac, ETH_ALEN); 2038 memcpy(sta_params.bssid, mac, ETH_ALEN);
2039 strStaParams.aid = params->aid; 2039 sta_params.aid = params->aid;
2040 strStaParams.rates_len = params->supported_rates_len; 2040 sta_params.rates_len = params->supported_rates_len;
2041 strStaParams.rates = params->supported_rates; 2041 sta_params.rates = params->supported_rates;
2042 2042
2043 if (!params->ht_capa) { 2043 if (!params->ht_capa) {
2044 strStaParams.ht_supported = false; 2044 sta_params.ht_supported = false;
2045 } else { 2045 } else {
2046 strStaParams.ht_supported = true; 2046 sta_params.ht_supported = true;
2047 strStaParams.ht_capa = *params->ht_capa; 2047 sta_params.ht_capa = *params->ht_capa;
2048 } 2048 }
2049 2049
2050 strStaParams.flags_mask = params->sta_flags_mask; 2050 sta_params.flags_mask = params->sta_flags_mask;
2051 strStaParams.flags_set = params->sta_flags_set; 2051 sta_params.flags_set = params->sta_flags_set;
2052 2052
2053 s32Error = wilc_edit_station(vif, &strStaParams); 2053 ret = wilc_edit_station(vif, &sta_params);
2054 if (s32Error) 2054 if (ret)
2055 netdev_err(dev, "Host edit station fail\n"); 2055 netdev_err(dev, "Host edit station fail\n");
2056 } 2056 }
2057 return s32Error; 2057 return ret;
2058} 2058}
2059 2059
2060static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy, 2060static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
@@ -2198,7 +2198,7 @@ static const struct cfg80211_ops wilc_cfg80211_ops = {
2198 2198
2199}; 2199};
2200 2200
2201static struct wireless_dev *WILC_WFI_CfgAlloc(void) 2201static struct wireless_dev *wilc_wfi_cfg_alloc(void)
2202{ 2202{
2203 struct wireless_dev *wdev; 2203 struct wireless_dev *wdev;
2204 2204
@@ -2230,9 +2230,9 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net, struct device *de
2230{ 2230{
2231 struct wilc_priv *priv; 2231 struct wilc_priv *priv;
2232 struct wireless_dev *wdev; 2232 struct wireless_dev *wdev;
2233 s32 s32Error = 0; 2233 s32 ret = 0;
2234 2234
2235 wdev = WILC_WFI_CfgAlloc(); 2235 wdev = wilc_wfi_cfg_alloc();
2236 if (!wdev) { 2236 if (!wdev) {
2237 netdev_err(net, "wiphy new allocate failed\n"); 2237 netdev_err(net, "wiphy new allocate failed\n");
2238 return NULL; 2238 return NULL;
@@ -2262,8 +2262,8 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net, struct device *de
2262 2262
2263 set_wiphy_dev(wdev->wiphy, dev); 2263 set_wiphy_dev(wdev->wiphy, dev);
2264 2264
2265 s32Error = wiphy_register(wdev->wiphy); 2265 ret = wiphy_register(wdev->wiphy);
2266 if (s32Error) 2266 if (ret)
2267 netdev_err(net, "Cannot register wiphy device\n"); 2267 netdev_err(net, "Cannot register wiphy device\n");
2268 2268
2269 priv->dev = net; 2269 priv->dev = net;
@@ -2272,7 +2272,7 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net, struct device *de
2272 2272
2273int wilc_init_host_int(struct net_device *net) 2273int wilc_init_host_int(struct net_device *net)
2274{ 2274{
2275 int s32Error = 0; 2275 int ret = 0;
2276 2276
2277 struct wilc_priv *priv; 2277 struct wilc_priv *priv;
2278 2278
@@ -2283,43 +2283,43 @@ int wilc_init_host_int(struct net_device *net)
2283 } 2283 }
2284 op_ifcs++; 2284 op_ifcs++;
2285 2285
2286 priv->gbAutoRateAdjusted = false; 2286 priv->auto_rate_adjusted = false;
2287 2287
2288 priv->bInP2PlistenState = false; 2288 priv->p2p_listen_state = false;
2289 2289
2290 mutex_init(&priv->scan_req_lock); 2290 mutex_init(&priv->scan_req_lock);
2291 s32Error = wilc_init(net, &priv->hif_drv); 2291 ret = wilc_init(net, &priv->hif_drv);
2292 if (s32Error) 2292 if (ret)
2293 netdev_err(net, "Error while initializing hostinterface\n"); 2293 netdev_err(net, "Error while initializing hostinterface\n");
2294 2294
2295 return s32Error; 2295 return ret;
2296} 2296}
2297 2297
2298int wilc_deinit_host_int(struct net_device *net) 2298int wilc_deinit_host_int(struct net_device *net)
2299{ 2299{
2300 int s32Error = 0; 2300 int ret = 0;
2301 struct wilc_vif *vif; 2301 struct wilc_vif *vif;
2302 struct wilc_priv *priv; 2302 struct wilc_priv *priv;
2303 2303
2304 priv = wdev_priv(net->ieee80211_ptr); 2304 priv = wdev_priv(net->ieee80211_ptr);
2305 vif = netdev_priv(priv->dev); 2305 vif = netdev_priv(priv->dev);
2306 2306
2307 priv->gbAutoRateAdjusted = false; 2307 priv->auto_rate_adjusted = false;
2308 2308
2309 priv->bInP2PlistenState = false; 2309 priv->p2p_listen_state = false;
2310 2310
2311 op_ifcs--; 2311 op_ifcs--;
2312 2312
2313 s32Error = wilc_deinit(vif); 2313 ret = wilc_deinit(vif);
2314 2314
2315 clear_shadow_scan(); 2315 clear_shadow_scan();
2316 if (op_ifcs == 0) 2316 if (op_ifcs == 0)
2317 del_timer_sync(&wilc_during_ip_timer); 2317 del_timer_sync(&wilc_during_ip_timer);
2318 2318
2319 if (s32Error) 2319 if (ret)
2320 netdev_err(net, "Error while deinitializing host interface\n"); 2320 netdev_err(net, "Error while deinitializing host interface\n");
2321 2321
2322 return s32Error; 2322 return ret;
2323} 2323}
2324 2324
2325void wilc_free_wiphy(struct net_device *net) 2325void wilc_free_wiphy(struct net_device *net)
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index e6f4d84971c3..3337fb26c8e2 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -86,29 +86,28 @@ struct wilc_wfi_wep_key {
86}; 86};
87 87
88struct sta_info { 88struct sta_info {
89 u8 au8Sta_AssociatedBss[MAX_NUM_STA][ETH_ALEN]; 89 u8 sta_associated_bss[MAX_NUM_STA][ETH_ALEN];
90}; 90};
91 91
92/*Parameters needed for host interface for remaining on channel*/ 92/*Parameters needed for host interface for remaining on channel*/
93struct wilc_wfi_p2pListenParams { 93struct wilc_wfi_p2p_listen_params {
94 struct ieee80211_channel *pstrListenChan; 94 struct ieee80211_channel *listen_ch;
95 enum nl80211_channel_type tenuChannelType; 95 u32 listen_duration;
96 u32 u32ListenDuration; 96 u64 listen_cookie;
97 u64 u64ListenCookie; 97 u32 listen_session_id;
98 u32 u32ListenSessionID;
99}; 98};
100 99
101struct wilc_priv { 100struct wilc_priv {
102 struct wireless_dev *wdev; 101 struct wireless_dev *wdev;
103 struct cfg80211_scan_request *pstrScanReq; 102 struct cfg80211_scan_request *scan_req;
104 103
105 struct wilc_wfi_p2pListenParams strRemainOnChanParams; 104 struct wilc_wfi_p2p_listen_params remain_on_ch_params;
106 u64 u64tx_cookie; 105 u64 tx_cookie;
107 106
108 bool bCfgScanning; 107 bool cfg_scanning;
109 u32 u32RcvdChCount; 108 u32 rcvd_ch_cnt;
110 109
111 u8 au8AssociatedBss[ETH_ALEN]; 110 u8 associated_bss[ETH_ALEN];
112 struct sta_info assoc_stainfo; 111 struct sta_info assoc_stainfo;
113 struct net_device_stats stats; 112 struct net_device_stats stats;
114 u8 monitor_flag; 113 u8 monitor_flag;
@@ -135,9 +134,9 @@ struct wilc_priv {
135 /* mutexes */ 134 /* mutexes */
136 struct mutex scan_req_lock; 135 struct mutex scan_req_lock;
137 /* */ 136 /* */
138 bool gbAutoRateAdjusted; 137 bool auto_rate_adjusted;
139 138
140 bool bInP2PlistenState; 139 bool p2p_listen_state;
141 140
142}; 141};
143 142
diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index f49dfa82f1b8..acaeafc2c350 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -1,19 +1,20 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/completion.h> 2#include <linux/completion.h>
2#include "wilc_wlan_if.h" 3#include "wilc_wlan_if.h"
3#include "wilc_wlan.h" 4#include "wilc_wlan.h"
4#include "wilc_wfi_netdevice.h" 5#include "wilc_wfi_netdevice.h"
5#include "wilc_wlan_cfg.h" 6#include "wilc_wlan_cfg.h"
6 7
7static CHIP_PS_STATE_T chip_ps_state = CHIP_WAKEDUP; 8static enum chip_ps_states chip_ps_state = CHIP_WAKEDUP;
8 9
9static inline void acquire_bus(struct wilc *wilc, BUS_ACQUIRE_T acquire) 10static inline void acquire_bus(struct wilc *wilc, enum bus_acquire acquire)
10{ 11{
11 mutex_lock(&wilc->hif_cs); 12 mutex_lock(&wilc->hif_cs);
12 if (acquire == ACQUIRE_AND_WAKEUP) 13 if (acquire == ACQUIRE_AND_WAKEUP)
13 chip_wakeup(wilc); 14 chip_wakeup(wilc);
14} 15}
15 16
16static inline void release_bus(struct wilc *wilc, BUS_RELEASE_T release) 17static inline void release_bus(struct wilc *wilc, enum bus_release release)
17{ 18{
18 if (release == RELEASE_ALLOW_SLEEP) 19 if (release == RELEASE_ALLOW_SLEEP)
19 chip_allow_sleep(wilc); 20 chip_allow_sleep(wilc);
@@ -692,7 +693,7 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count)
692 i = 0; 693 i = 0;
693 do { 694 do {
694 tqe = wilc_wlan_txq_remove_from_head(dev); 695 tqe = wilc_wlan_txq_remove_from_head(dev);
695 if (tqe && (vmm_table[i] != 0)) { 696 if (tqe && vmm_table[i] != 0) {
696 u32 header, buffer_offset; 697 u32 header, buffer_offset;
697 698
698 vmm_table[i] = cpu_to_le32(vmm_table[i]); 699 vmm_table[i] = cpu_to_le32(vmm_table[i]);
diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index 19e4f85fdd27..aeb5417f3587 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -235,7 +235,7 @@ static int wilc_wlan_cfg_set_str(u8 *frame, u32 offset, u16 id, u8 *str, u32 siz
235 buf[2] = (u8)size; 235 buf[2] = (u8)size;
236 buf[3] = (u8)(size >> 8); 236 buf[3] = (u8)(size >> 8);
237 237
238 if ((str) && (size != 0)) 238 if (str && size != 0)
239 memcpy(&buf[4], str, size); 239 memcpy(&buf[4], str, size);
240 240
241 return (size + 4); 241 return (size + 4);
@@ -256,7 +256,7 @@ static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size)
256 buf[2] = (u8)size; 256 buf[2] = (u8)size;
257 buf[3] = (u8)(size >> 8); 257 buf[3] = (u8)(size >> 8);
258 258
259 if ((b) && (size != 0)) { 259 if ((b) && size != 0) {
260 memcpy(&buf[4], b, size); 260 memcpy(&buf[4], b, size);
261 for (i = 0; i < size; i++) 261 for (i = 0; i < size; i++)
262 checksum += buf[i + 4]; 262 checksum += buf[i + 4];
@@ -370,7 +370,7 @@ static int wilc_wlan_parse_info_frame(u8 *info, int size)
370 370
371 len = info[2]; 371 len = info[2];
372 372
373 if ((len == 1) && (wid == WID_STATUS)) { 373 if (len == 1 && wid == WID_STATUS) {
374 pd->mac_status = info[3]; 374 pd->mac_status = info[3];
375 type = WILC_CFG_RSP_STATUS; 375 type = WILC_CFG_RSP_STATUS;
376 } 376 }
diff --git a/drivers/staging/wilc1000/wilc_wlan_if.h b/drivers/staging/wilc1000/wilc_wlan_if.h
index c1693cfc076d..e186509ad334 100644
--- a/drivers/staging/wilc1000/wilc_wlan_if.h
+++ b/drivers/staging/wilc1000/wilc_wlan_if.h
@@ -75,7 +75,7 @@ typedef void (*wilc_tx_complete_func_t)(void *, int);
75#define MAX_SSID_LEN 33 75#define MAX_SSID_LEN 33
76#define MAX_RATES_SUPPORTED 12 76#define MAX_RATES_SUPPORTED 12
77 77
78typedef enum { 78enum {
79 SUPP_RATES_IE = 1, 79 SUPP_RATES_IE = 1,
80 EXT_SUPP_RATES_IE = 50, 80 EXT_SUPP_RATES_IE = 50,
81 HT_CAPABILITY_IE = 45, 81 HT_CAPABILITY_IE = 45,
@@ -83,15 +83,15 @@ typedef enum {
83 WPA_IE = 221, 83 WPA_IE = 221,
84 WMM_IE = 221, 84 WMM_IE = 221,
85 P2P_IE = 221, 85 P2P_IE = 221,
86} BEACON_IE; 86};
87 87
88typedef enum { 88enum bss_types {
89 INFRASTRUCTURE = 0, 89 INFRASTRUCTURE = 0,
90 INDEPENDENT, 90 INDEPENDENT,
91 AP, 91 AP,
92} BSSTYPE_T; 92};
93 93
94typedef enum { 94enum {
95 RATE_AUTO = 0, 95 RATE_AUTO = 0,
96 RATE_1MB = 1, 96 RATE_1MB = 1,
97 RATE_2MB = 2, 97 RATE_2MB = 2,
@@ -105,55 +105,55 @@ typedef enum {
105 RATE_26MB = 36, 105 RATE_26MB = 36,
106 RATE_48MB = 48, 106 RATE_48MB = 48,
107 RATE_54MB = 54 107 RATE_54MB = 54
108} TX_RATE_T; 108};
109 109
110typedef enum { 110enum {
111 B_ONLY_MODE = 0, /* 1, 2 M, otherwise 5, 11 M */ 111 B_ONLY_MODE = 0, /* 1, 2 M, otherwise 5, 11 M */
112 G_ONLY_MODE, /* 6,12,24 otherwise 9,18,36,48,54 */ 112 G_ONLY_MODE, /* 6,12,24 otherwise 9,18,36,48,54 */
113 G_MIXED_11B_1_MODE, /* 1,2,5.5,11 otherwise all on */ 113 G_MIXED_11B_1_MODE, /* 1,2,5.5,11 otherwise all on */
114 G_MIXED_11B_2_MODE, /* 1,2,5,11,6,12,24 otherwise all on */ 114 G_MIXED_11B_2_MODE, /* 1,2,5,11,6,12,24 otherwise all on */
115} G_OPERATING_MODE_T; 115};
116 116
117typedef enum { 117enum {
118 G_SHORT_PREAMBLE = 0, /* Short Preamble */ 118 G_SHORT_PREAMBLE = 0, /* Short Preamble */
119 G_LONG_PREAMBLE = 1, /* Long Preamble */ 119 G_LONG_PREAMBLE = 1, /* Long Preamble */
120 G_AUTO_PREAMBLE = 2, /* Auto Preamble Selection */ 120 G_AUTO_PREAMBLE = 2, /* Auto Preamble Selection */
121} G_PREAMBLE_T; 121};
122 122
123#define MAC_CONNECTED 1 123#define MAC_CONNECTED 1
124#define MAC_DISCONNECTED 0 124#define MAC_DISCONNECTED 0
125 125
126#define SCAN_DONE TRUE 126#define SCAN_DONE TRUE
127typedef enum { 127enum {
128 PASSIVE_SCAN = 0, 128 PASSIVE_SCAN = 0,
129 ACTIVE_SCAN = 1, 129 ACTIVE_SCAN = 1,
130} SCANTYPE_T; 130};
131 131
132typedef enum { 132enum {
133 NO_POWERSAVE = 0, 133 NO_POWERSAVE = 0,
134 MIN_FAST_PS = 1, 134 MIN_FAST_PS = 1,
135 MAX_FAST_PS = 2, 135 MAX_FAST_PS = 2,
136 MIN_PSPOLL_PS = 3, 136 MIN_PSPOLL_PS = 3,
137 MAX_PSPOLL_PS = 4 137 MAX_PSPOLL_PS = 4
138} USER_PS_MODE_T; 138};
139 139
140typedef enum { 140enum chip_ps_states {
141 CHIP_WAKEDUP = 0, 141 CHIP_WAKEDUP = 0,
142 CHIP_SLEEPING_AUTO = 1, 142 CHIP_SLEEPING_AUTO = 1,
143 CHIP_SLEEPING_MANUAL = 2 143 CHIP_SLEEPING_MANUAL = 2
144} CHIP_PS_STATE_T; 144};
145 145
146typedef enum { 146enum bus_acquire {
147 ACQUIRE_ONLY = 0, 147 ACQUIRE_ONLY = 0,
148 ACQUIRE_AND_WAKEUP = 1, 148 ACQUIRE_AND_WAKEUP = 1,
149} BUS_ACQUIRE_T; 149};
150 150
151typedef enum { 151enum bus_release {
152 RELEASE_ONLY = 0, 152 RELEASE_ONLY = 0,
153 RELEASE_ALLOW_SLEEP = 1, 153 RELEASE_ALLOW_SLEEP = 1,
154} BUS_RELEASE_T; 154};
155 155
156typedef enum { 156enum {
157 NO_SECURITY = 0, 157 NO_SECURITY = 0,
158 WEP_40 = 0x3, 158 WEP_40 = 0x3,
159 WEP_104 = 0x7, 159 WEP_104 = 0x7,
@@ -163,7 +163,7 @@ typedef enum {
163 WPA2_AES = 0x31, 163 WPA2_AES = 0x31,
164 WPA2_TKIP = 0x51, 164 WPA2_TKIP = 0x51,
165 WPA2_AES_TKIP = 0x71, /* Aes or Tkip */ 165 WPA2_AES_TKIP = 0x71, /* Aes or Tkip */
166} SECURITY_T; 166};
167 167
168enum AUTHTYPE { 168enum AUTHTYPE {
169 OPEN_SYSTEM = 1, 169 OPEN_SYSTEM = 1,
@@ -178,88 +178,88 @@ enum SITESURVEY {
178 SITE_SURVEY_OFF = 2 178 SITE_SURVEY_OFF = 2
179}; 179};
180 180
181typedef enum { 181enum {
182 NORMAL_ACK = 0, 182 NORMAL_ACK = 0,
183 NO_ACK, 183 NO_ACK,
184} ACK_POLICY_T; 184};
185 185
186typedef enum { 186enum {
187 DONT_RESET = 0, 187 DONT_RESET = 0,
188 DO_RESET = 1, 188 DO_RESET = 1,
189 NO_REQUEST = 2, 189 NO_REQUEST = 2,
190} RESET_REQ_T; 190};
191 191
192typedef enum { 192enum {
193 REKEY_DISABLE = 1, 193 REKEY_DISABLE = 1,
194 REKEY_TIME_BASE, 194 REKEY_TIME_BASE,
195 REKEY_PKT_BASE, 195 REKEY_PKT_BASE,
196 REKEY_TIME_PKT_BASE 196 REKEY_TIME_PKT_BASE
197} RSNA_REKEY_POLICY_T; 197};
198 198
199typedef enum { 199enum {
200 FILTER_NO = 0x00, 200 FILTER_NO = 0x00,
201 FILTER_AP_ONLY = 0x01, 201 FILTER_AP_ONLY = 0x01,
202 FILTER_STA_ONLY = 0x02 202 FILTER_STA_ONLY = 0x02
203} SCAN_CLASS_FITLER_T; 203};
204 204
205typedef enum { 205enum {
206 PRI_HIGH_RSSI = 0x00, 206 PRI_HIGH_RSSI = 0x00,
207 PRI_LOW_RSSI = 0x04, 207 PRI_LOW_RSSI = 0x04,
208 PRI_DETECT = 0x08 208 PRI_DETECT = 0x08
209} SCAN_PRI_T; 209};
210 210
211typedef enum { 211enum {
212 CH_FILTER_OFF = 0x00, 212 CH_FILTER_OFF = 0x00,
213 CH_FILTER_ON = 0x10 213 CH_FILTER_ON = 0x10
214} CH_FILTER_T; 214};
215 215
216typedef enum { 216enum {
217 AUTO_PROT = 0, /* Auto */ 217 AUTO_PROT = 0, /* Auto */
218 NO_PROT, /* Do not use any protection */ 218 NO_PROT, /* Do not use any protection */
219 ERP_PROT, /* Protect all ERP frame exchanges */ 219 ERP_PROT, /* Protect all ERP frame exchanges */
220 HT_PROT, /* Protect all HT frame exchanges */ 220 HT_PROT, /* Protect all HT frame exchanges */
221 GF_PROT, /* Protect all GF frame exchanges */ 221 GF_PROT, /* Protect all GF frame exchanges */
222} N_PROTECTION_MODE_T; 222};
223 223
224typedef enum { 224enum {
225 G_SELF_CTS_PROT, 225 G_SELF_CTS_PROT,
226 G_RTS_CTS_PROT, 226 G_RTS_CTS_PROT,
227} G_PROTECTION_MODE_T; 227};
228 228
229typedef enum { 229enum {
230 HT_MIXED_MODE = 1, 230 HT_MIXED_MODE = 1,
231 HT_ONLY_20MHZ_MODE, 231 HT_ONLY_20MHZ_MODE,
232 HT_ONLY_20_40MHZ_MODE, 232 HT_ONLY_20_40MHZ_MODE,
233} N_OPERATING_MODE_T; 233};
234 234
235typedef enum { 235enum {
236 NO_DETECT = 0, 236 NO_DETECT = 0,
237 DETECT_ONLY = 1, 237 DETECT_ONLY = 1,
238 DETECT_PROTECT = 2, 238 DETECT_PROTECT = 2,
239 DETECT_PROTECT_REPORT = 3, 239 DETECT_PROTECT_REPORT = 3,
240} N_OBSS_DETECTION_T; 240};
241 241
242typedef enum { 242enum {
243 RTS_CTS_NONHT_PROT = 0, /* RTS-CTS at non-HT rate */ 243 RTS_CTS_NONHT_PROT = 0, /* RTS-CTS at non-HT rate */
244 FIRST_FRAME_NONHT_PROT, /* First frame at non-HT rate */ 244 FIRST_FRAME_NONHT_PROT, /* First frame at non-HT rate */
245 LSIG_TXOP_PROT, /* LSIG TXOP Protection */ 245 LSIG_TXOP_PROT, /* LSIG TXOP Protection */
246 FIRST_FRAME_MIXED_PROT, /* First frame at Mixed format */ 246 FIRST_FRAME_MIXED_PROT, /* First frame at Mixed format */
247} N_PROTECTION_TYPE_T; 247};
248 248
249typedef enum { 249enum {
250 STATIC_MODE = 1, 250 STATIC_MODE = 1,
251 DYNAMIC_MODE = 2, 251 DYNAMIC_MODE = 2,
252 MIMO_MODE = 3, /* power save disable */ 252 MIMO_MODE = 3, /* power save disable */
253} N_SMPS_MODE_T; 253};
254 254
255typedef enum { 255enum {
256 DISABLE_SELF_CTS, 256 DISABLE_SELF_CTS,
257 ENABLE_SELF_CTS, 257 ENABLE_SELF_CTS,
258 DISABLE_TX_ABORT, 258 DISABLE_TX_ABORT,
259 ENABLE_TX_ABORT, 259 ENABLE_TX_ABORT,
260 HW_TRIGGER_ABORT, 260 HW_TRIGGER_ABORT,
261 SW_TRIGGER_ABORT, 261 SW_TRIGGER_ABORT,
262} TX_ABORT_OPTION_T; 262};
263 263
264enum wid_type { 264enum wid_type {
265 WID_CHAR = 0, 265 WID_CHAR = 0,
@@ -281,7 +281,7 @@ struct wid {
281 s8 *val; 281 s8 *val;
282}; 282};
283 283
284typedef enum { 284enum {
285 WID_NIL = 0xffff, 285 WID_NIL = 0xffff,
286 286
287 /* 287 /*
@@ -889,7 +889,7 @@ typedef enum {
889 /* Miscellaneous WIDs */ 889 /* Miscellaneous WIDs */
890 WID_ALL = 0x7FFE, 890 WID_ALL = 0x7FFE,
891 WID_MAX = 0xFFFF 891 WID_MAX = 0xFFFF
892} WID_T; 892};
893 893
894struct wilc; 894struct wilc;
895int wilc_wlan_init(struct net_device *dev); 895int wilc_wlan_init(struct net_device *dev);
diff --git a/drivers/staging/wlan-ng/hfa384x.h b/drivers/staging/wlan-ng/hfa384x.h
index f5a3a1ce21ce..85c3af00abd2 100644
--- a/drivers/staging/wlan-ng/hfa384x.h
+++ b/drivers/staging/wlan-ng/hfa384x.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* hfa384x.h 2/* hfa384x.h
2 * 3 *
3 * Defines the constants and data structures for the hfa384x 4 * Defines the constants and data structures for the hfa384x
diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
index 197f5a914e8f..555711bc12f0 100644
--- a/drivers/staging/wlan-ng/hfa384x_usb.c
+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* src/prism2/driver/hfa384x_usb.c 2/* src/prism2/driver/hfa384x_usb.c
2 * 3 *
3 * Functions that talk to the USB variantof the Intersil hfa384x MAC 4 * Functions that talk to the USB variantof the Intersil hfa384x MAC
@@ -2457,7 +2458,8 @@ int hfa384x_drvr_start(struct hfa384x *hw)
2457 * ok 2458 * ok
2458 */ 2459 */
2459 result = 2460 result =
2460 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status); 2461 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in,
2462 &status);
2461 if (result < 0) { 2463 if (result < 0) {
2462 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n"); 2464 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
2463 goto done; 2465 goto done;
@@ -2466,7 +2468,8 @@ int hfa384x_drvr_start(struct hfa384x *hw)
2466 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n"); 2468 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
2467 2469
2468 result = 2470 result =
2469 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status); 2471 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out,
2472 &status);
2470 if (result < 0) { 2473 if (result < 0) {
2471 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n"); 2474 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
2472 goto done; 2475 goto done;
diff --git a/drivers/staging/wlan-ng/p80211conv.c b/drivers/staging/wlan-ng/p80211conv.c
index c1b6d426bcad..855b424f6423 100644
--- a/drivers/staging/wlan-ng/p80211conv.c
+++ b/drivers/staging/wlan-ng/p80211conv.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* src/p80211/p80211conv.c 2/* src/p80211/p80211conv.c
2 * 3 *
3 * Ether/802.11 conversions and packet buffer routines 4 * Ether/802.11 conversions and packet buffer routines
diff --git a/drivers/staging/wlan-ng/p80211conv.h b/drivers/staging/wlan-ng/p80211conv.h
index 66332b1fb6d5..28459dcea4b1 100644
--- a/drivers/staging/wlan-ng/p80211conv.h
+++ b/drivers/staging/wlan-ng/p80211conv.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* p80211conv.h 2/* p80211conv.h
2 * 3 *
3 * Ether/802.11 conversions and packet buffer routines 4 * Ether/802.11 conversions and packet buffer routines
diff --git a/drivers/staging/wlan-ng/p80211hdr.h b/drivers/staging/wlan-ng/p80211hdr.h
index 2c44c613a586..133d70c08ecf 100644
--- a/drivers/staging/wlan-ng/p80211hdr.h
+++ b/drivers/staging/wlan-ng/p80211hdr.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* p80211hdr.h 2/* p80211hdr.h
2 * 3 *
3 * Macros, types, and functions for handling 802.11 MAC headers 4 * Macros, types, and functions for handling 802.11 MAC headers
diff --git a/drivers/staging/wlan-ng/p80211ioctl.h b/drivers/staging/wlan-ng/p80211ioctl.h
index ab6067e65050..d8cde1d8870b 100644
--- a/drivers/staging/wlan-ng/p80211ioctl.h
+++ b/drivers/staging/wlan-ng/p80211ioctl.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* p80211ioctl.h 2/* p80211ioctl.h
2 * 3 *
3 * Declares constants and types for the p80211 ioctls 4 * Declares constants and types for the p80211 ioctls
diff --git a/drivers/staging/wlan-ng/p80211metadef.h b/drivers/staging/wlan-ng/p80211metadef.h
index ea3d9ce222b9..4ac2f08a520a 100644
--- a/drivers/staging/wlan-ng/p80211metadef.h
+++ b/drivers/staging/wlan-ng/p80211metadef.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* This file is GENERATED AUTOMATICALLY. DO NOT EDIT OR MODIFY. 2/* This file is GENERATED AUTOMATICALLY. DO NOT EDIT OR MODIFY.
2 * -------------------------------------------------------------------- 3 * --------------------------------------------------------------------
3 * 4 *
diff --git a/drivers/staging/wlan-ng/p80211metastruct.h b/drivers/staging/wlan-ng/p80211metastruct.h
index 850d897fc163..15b7c08e210d 100644
--- a/drivers/staging/wlan-ng/p80211metastruct.h
+++ b/drivers/staging/wlan-ng/p80211metastruct.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* This file is GENERATED AUTOMATICALLY. DO NOT EDIT OR MODIFY. 2/* This file is GENERATED AUTOMATICALLY. DO NOT EDIT OR MODIFY.
2* -------------------------------------------------------------------- 3* --------------------------------------------------------------------
3* 4*
diff --git a/drivers/staging/wlan-ng/p80211mgmt.h b/drivers/staging/wlan-ng/p80211mgmt.h
index 653950fd9843..3c12929858cb 100644
--- a/drivers/staging/wlan-ng/p80211mgmt.h
+++ b/drivers/staging/wlan-ng/p80211mgmt.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* p80211mgmt.h 2/* p80211mgmt.h
2 * 3 *
3 * Macros, types, and functions to handle 802.11 mgmt frames 4 * Macros, types, and functions to handle 802.11 mgmt frames
diff --git a/drivers/staging/wlan-ng/p80211msg.h b/drivers/staging/wlan-ng/p80211msg.h
index 40c5cf5997c7..ae119ecd74b0 100644
--- a/drivers/staging/wlan-ng/p80211msg.h
+++ b/drivers/staging/wlan-ng/p80211msg.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* p80211msg.h 2/* p80211msg.h
2 * 3 *
3 * Macros, constants, types, and funcs for req and ind messages 4 * Macros, constants, types, and funcs for req and ind messages
diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
index 0f503652740f..ec9cc00ee241 100644
--- a/drivers/staging/wlan-ng/p80211netdev.c
+++ b/drivers/staging/wlan-ng/p80211netdev.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* src/p80211/p80211knetdev.c 2/* src/p80211/p80211knetdev.c
2 * 3 *
3 * Linux Kernel net device interface 4 * Linux Kernel net device interface
@@ -640,7 +641,8 @@ static int p80211knetdev_set_mac_address(struct net_device *dev, void *addr)
640 dot11req.msgcode = DIDmsg_dot11req_mibset; 641 dot11req.msgcode = DIDmsg_dot11req_mibset;
641 dot11req.msglen = sizeof(dot11req); 642 dot11req.msglen = sizeof(dot11req);
642 memcpy(dot11req.devname, 643 memcpy(dot11req.devname,
643 ((struct wlandevice *)dev->ml_priv)->name, WLAN_DEVNAMELEN_MAX - 1); 644 ((struct wlandevice *)dev->ml_priv)->name,
645 WLAN_DEVNAMELEN_MAX - 1);
644 646
645 /* Set up the mibattribute argument */ 647 /* Set up the mibattribute argument */
646 mibattr->did = DIDmsg_dot11req_mibset_mibattribute; 648 mibattr->did = DIDmsg_dot11req_mibset_mibattribute;
diff --git a/drivers/staging/wlan-ng/p80211netdev.h b/drivers/staging/wlan-ng/p80211netdev.h
index 8e0d08298c8b..cebbe746a52f 100644
--- a/drivers/staging/wlan-ng/p80211netdev.h
+++ b/drivers/staging/wlan-ng/p80211netdev.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* p80211netdev.h 2/* p80211netdev.h
2 * 3 *
3 * WLAN net device structure and functions 4 * WLAN net device structure and functions
diff --git a/drivers/staging/wlan-ng/p80211req.c b/drivers/staging/wlan-ng/p80211req.c
index afe847722cf7..c36d01469afc 100644
--- a/drivers/staging/wlan-ng/p80211req.c
+++ b/drivers/staging/wlan-ng/p80211req.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* src/p80211/p80211req.c 2/* src/p80211/p80211req.c
2 * 3 *
3 * Request/Indication/MacMgmt interface handling functions 4 * Request/Indication/MacMgmt interface handling functions
diff --git a/drivers/staging/wlan-ng/p80211req.h b/drivers/staging/wlan-ng/p80211req.h
index 6c72f59993e0..20be2c3af4c1 100644
--- a/drivers/staging/wlan-ng/p80211req.h
+++ b/drivers/staging/wlan-ng/p80211req.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* p80211req.h 2/* p80211req.h
2 * 3 *
3 * Request handling functions 4 * Request handling functions
diff --git a/drivers/staging/wlan-ng/p80211types.h b/drivers/staging/wlan-ng/p80211types.h
index 263ef2ddb197..94420562c418 100644
--- a/drivers/staging/wlan-ng/p80211types.h
+++ b/drivers/staging/wlan-ng/p80211types.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* 2/*
2 * p80211types.h 3 * p80211types.h
3 * 4 *
diff --git a/drivers/staging/wlan-ng/p80211wep.c b/drivers/staging/wlan-ng/p80211wep.c
index 6492ffe59085..8bd92bba0ac1 100644
--- a/drivers/staging/wlan-ng/p80211wep.c
+++ b/drivers/staging/wlan-ng/p80211wep.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* src/p80211/p80211wep.c 2/* src/p80211/p80211wep.c
2 * 3 *
3 * WEP encode/decode for P80211. 4 * WEP encode/decode for P80211.
diff --git a/drivers/staging/wlan-ng/prism2fw.c b/drivers/staging/wlan-ng/prism2fw.c
index 344bec8cc31b..5860d0d65841 100644
--- a/drivers/staging/wlan-ng/prism2fw.c
+++ b/drivers/staging/wlan-ng/prism2fw.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* from src/prism2/download/prism2dl.c 2/* from src/prism2/download/prism2dl.c
2 * 3 *
3 * utility for downloading prism2 images moved into kernelspace 4 * utility for downloading prism2 images moved into kernelspace
diff --git a/drivers/staging/wlan-ng/prism2mgmt.c b/drivers/staging/wlan-ng/prism2mgmt.c
index 72070593394a..78934e435fcf 100644
--- a/drivers/staging/wlan-ng/prism2mgmt.c
+++ b/drivers/staging/wlan-ng/prism2mgmt.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* src/prism2/driver/prism2mgmt.c 2/* src/prism2/driver/prism2mgmt.c
2 * 3 *
3 * Management request handler functions. 4 * Management request handler functions.
diff --git a/drivers/staging/wlan-ng/prism2mgmt.h b/drivers/staging/wlan-ng/prism2mgmt.h
index c062418f1202..564c3f4a3e03 100644
--- a/drivers/staging/wlan-ng/prism2mgmt.h
+++ b/drivers/staging/wlan-ng/prism2mgmt.h
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* prism2mgmt.h 2/* prism2mgmt.h
2 * 3 *
3 * Declares the mgmt command handler functions 4 * Declares the mgmt command handler functions
diff --git a/drivers/staging/wlan-ng/prism2mib.c b/drivers/staging/wlan-ng/prism2mib.c
index e41207d97309..edad299ff5ad 100644
--- a/drivers/staging/wlan-ng/prism2mib.c
+++ b/drivers/staging/wlan-ng/prism2mib.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* src/prism2/driver/prism2mib.c 2/* src/prism2/driver/prism2mib.c
2 * 3 *
3 * Management request for mibset/mibget 4 * Management request for mibset/mibget
diff --git a/drivers/staging/wlan-ng/prism2sta.c b/drivers/staging/wlan-ng/prism2sta.c
index 99316b9a4e49..fed0b8ceca6f 100644
--- a/drivers/staging/wlan-ng/prism2sta.c
+++ b/drivers/staging/wlan-ng/prism2sta.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
1/* src/prism2/driver/prism2sta.c 2/* src/prism2/driver/prism2sta.c
2 * 3 *
3 * Implements the station functionality for prism2 4 * Implements the station functionality for prism2
diff --git a/drivers/staging/xgifb/XGI_main.h b/drivers/staging/xgifb/XGI_main.h
index a3af1cbbf8ee..e19a8291cb2a 100644
--- a/drivers/staging/xgifb/XGI_main.h
+++ b/drivers/staging/xgifb/XGI_main.h
@@ -18,19 +18,6 @@ static const struct pci_device_id xgifb_pci_table[] = {
18 18
19MODULE_DEVICE_TABLE(pci, xgifb_pci_table); 19MODULE_DEVICE_TABLE(pci, xgifb_pci_table);
20 20
21/* To be included in fb.h */
22#define XGISR (xgifb_info->dev_info.P3c4)
23#define XGICR (xgifb_info->dev_info.P3d4)
24#define XGIDACA (xgifb_info->dev_info.P3c8)
25#define XGIDACD (xgifb_info->dev_info.P3c9)
26#define XGIPART1 (xgifb_info->dev_info.Part1Port)
27#define XGIPART2 (xgifb_info->dev_info.Part2Port)
28#define XGIPART3 (xgifb_info->dev_info.Part3Port)
29#define XGIPART4 (xgifb_info->dev_info.Part4Port)
30#define XGIPART5 (xgifb_info->dev_info.Part5Port)
31#define XGIDAC2A XGIPART5
32#define XGIDAC2D (XGIPART5 + 1)
33
34#define IND_XGI_SCRATCH_REG_CR30 0x30 /* CRs */ 21#define IND_XGI_SCRATCH_REG_CR30 0x30 /* CRs */
35#define IND_XGI_SCRATCH_REG_CR31 0x31 22#define IND_XGI_SCRATCH_REG_CR31 0x31
36#define IND_XGI_SCRATCH_REG_CR32 0x32 23#define IND_XGI_SCRATCH_REG_CR32 0x32
diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c
index b813f1d460ce..10107de0119a 100644
--- a/drivers/staging/xgifb/XGI_main_26.c
+++ b/drivers/staging/xgifb/XGI_main_26.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * XG20, XG21, XG40, XG42 frame buffer device 3 * XG20, XG21, XG40, XG42 frame buffer device
3 * for Linux kernels 2.5.x, 2.6.x 4 * for Linux kernels 2.5.x, 2.6.x
@@ -31,18 +32,19 @@ static unsigned int refresh_rate;
31#ifdef DEBUG 32#ifdef DEBUG
32static void dumpVGAReg(struct xgifb_video_info *xgifb_info) 33static void dumpVGAReg(struct xgifb_video_info *xgifb_info)
33{ 34{
35 struct vb_device_info *vb = &xgifb_info->dev_info;
34 u8 i, reg; 36 u8 i, reg;
35 37
36 xgifb_reg_set(XGISR, 0x05, 0x86); 38 xgifb_reg_set(vb->P3c4, 0x05, 0x86);
37 39
38 for (i = 0; i < 0x4f; i++) { 40 for (i = 0; i < 0x4f; i++) {
39 reg = xgifb_reg_get(XGISR, i); 41 reg = xgifb_reg_get(vb->P3c4, i);
40 pr_debug("o 3c4 %x\n", i); 42 pr_debug("o 3c4 %x\n", i);
41 pr_debug("i 3c5 => %x\n", reg); 43 pr_debug("i 3c5 => %x\n", reg);
42 } 44 }
43 45
44 for (i = 0; i < 0xF0; i++) { 46 for (i = 0; i < 0xF0; i++) {
45 reg = xgifb_reg_get(XGICR, i); 47 reg = xgifb_reg_get(vb->P3d4, i);
46 pr_debug("o 3d4 %x\n", i); 48 pr_debug("o 3d4 %x\n", i);
47 pr_debug("i 3d5 => %x\n", reg); 49 pr_debug("i 3d5 => %x\n", reg);
48 } 50 }
@@ -644,9 +646,10 @@ static void XGIfb_bpp_to_var(struct xgifb_video_info *xgifb_info,
644 646
645static void XGIfb_pre_setmode(struct xgifb_video_info *xgifb_info) 647static void XGIfb_pre_setmode(struct xgifb_video_info *xgifb_info)
646{ 648{
649 struct vb_device_info *vb = &xgifb_info->dev_info;
647 u8 cr30 = 0, cr31 = 0; 650 u8 cr30 = 0, cr31 = 0;
648 651
649 cr31 = xgifb_reg_get(XGICR, 0x31); 652 cr31 = xgifb_reg_get(vb->P3d4, 0x31);
650 cr31 &= ~0x60; 653 cr31 &= ~0x60;
651 654
652 switch (xgifb_info->display2) { 655 switch (xgifb_info->display2) {
@@ -683,14 +686,15 @@ static void XGIfb_pre_setmode(struct xgifb_video_info *xgifb_info)
683 cr31 |= (SIS_DRIVER_MODE | SIS_VB_OUTPUT_DISABLE); 686 cr31 |= (SIS_DRIVER_MODE | SIS_VB_OUTPUT_DISABLE);
684 } 687 }
685 688
686 xgifb_reg_set(XGICR, IND_XGI_SCRATCH_REG_CR30, cr30); 689 xgifb_reg_set(vb->P3d4, IND_XGI_SCRATCH_REG_CR30, cr30);
687 xgifb_reg_set(XGICR, IND_XGI_SCRATCH_REG_CR31, cr31); 690 xgifb_reg_set(vb->P3d4, IND_XGI_SCRATCH_REG_CR31, cr31);
688 xgifb_reg_set(XGICR, IND_XGI_SCRATCH_REG_CR33, 691 xgifb_reg_set(vb->P3d4, IND_XGI_SCRATCH_REG_CR33,
689 (xgifb_info->rate_idx & 0x0F)); 692 (xgifb_info->rate_idx & 0x0F));
690} 693}
691 694
692static void XGIfb_post_setmode(struct xgifb_video_info *xgifb_info) 695static void XGIfb_post_setmode(struct xgifb_video_info *xgifb_info)
693{ 696{
697 struct vb_device_info *vb = &xgifb_info->dev_info;
694 u8 reg; 698 u8 reg;
695 unsigned char doit = 1; 699 unsigned char doit = 1;
696 700
@@ -713,7 +717,7 @@ static void XGIfb_post_setmode(struct xgifb_video_info *xgifb_info)
713 717
714 /* We can't switch off CRT1 if bridge is in slave mode */ 718 /* We can't switch off CRT1 if bridge is in slave mode */
715 if (xgifb_info->hasVB != HASVB_NONE) { 719 if (xgifb_info->hasVB != HASVB_NONE) {
716 reg = xgifb_reg_get(XGIPART1, 0x00); 720 reg = xgifb_reg_get(vb->Part1Port, 0x00);
717 721
718 if ((reg & 0x50) == 0x10) 722 if ((reg & 0x50) == 0x10)
719 doit = 0; 723 doit = 0;
@@ -722,18 +726,18 @@ static void XGIfb_post_setmode(struct xgifb_video_info *xgifb_info)
722 XGIfb_crt1off = 0; 726 XGIfb_crt1off = 0;
723 } 727 }
724 728
725 reg = xgifb_reg_get(XGICR, 0x17); 729 reg = xgifb_reg_get(vb->P3d4, 0x17);
726 if ((XGIfb_crt1off) && (doit)) 730 if ((XGIfb_crt1off) && (doit))
727 reg &= ~0x80; 731 reg &= ~0x80;
728 else 732 else
729 reg |= 0x80; 733 reg |= 0x80;
730 xgifb_reg_set(XGICR, 0x17, reg); 734 xgifb_reg_set(vb->P3d4, 0x17, reg);
731 735
732 xgifb_reg_and(XGISR, IND_SIS_RAMDAC_CONTROL, ~0x04); 736 xgifb_reg_and(vb->P3c4, IND_SIS_RAMDAC_CONTROL, ~0x04);
733 737
734 if (xgifb_info->display2 == XGIFB_DISP_TV && 738 if (xgifb_info->display2 == XGIFB_DISP_TV &&
735 xgifb_info->hasVB == HASVB_301) { 739 xgifb_info->hasVB == HASVB_301) {
736 reg = xgifb_reg_get(XGIPART4, 0x01); 740 reg = xgifb_reg_get(vb->Part4Port, 0x01);
737 741
738 if (reg < 0xB0) { /* Set filter for XGI301 */ 742 if (reg < 0xB0) { /* Set filter for XGI301 */
739 int filter_tb; 743 int filter_tb;
@@ -760,60 +764,58 @@ static void XGIfb_post_setmode(struct xgifb_video_info *xgifb_info)
760 filter = -1; 764 filter = -1;
761 break; 765 break;
762 } 766 }
763 xgifb_reg_or(XGIPART1, 767 xgifb_reg_or(vb->Part1Port, SIS_CRT2_WENABLE_315, 0x01);
764 SIS_CRT2_WENABLE_315,
765 0x01);
766 768
767 if (xgifb_info->TV_type == TVMODE_NTSC) { 769 if (xgifb_info->TV_type == TVMODE_NTSC) {
768 xgifb_reg_and(XGIPART2, 0x3a, 0x1f); 770 xgifb_reg_and(vb->Part2Port, 0x3a, 0x1f);
769 771
770 if (xgifb_info->TV_plug == TVPLUG_SVIDEO) { 772 if (xgifb_info->TV_plug == TVPLUG_SVIDEO) {
771 xgifb_reg_and(XGIPART2, 0x30, 0xdf); 773 xgifb_reg_and(vb->Part2Port, 0x30, 0xdf);
772 774
773 } else if (xgifb_info->TV_plug 775 } else if (xgifb_info->TV_plug
774 == TVPLUG_COMPOSITE) { 776 == TVPLUG_COMPOSITE) {
775 xgifb_reg_or(XGIPART2, 0x30, 0x20); 777 xgifb_reg_or(vb->Part2Port, 0x30, 0x20);
776 778
777 switch (xgifb_info->video_width) { 779 switch (xgifb_info->video_width) {
778 case 640: 780 case 640:
779 xgifb_reg_set(XGIPART2, 781 xgifb_reg_set(vb->Part2Port,
780 0x35, 782 0x35,
781 0xEB); 783 0xEB);
782 xgifb_reg_set(XGIPART2, 784 xgifb_reg_set(vb->Part2Port,
783 0x36, 785 0x36,
784 0x04); 786 0x04);
785 xgifb_reg_set(XGIPART2, 787 xgifb_reg_set(vb->Part2Port,
786 0x37, 788 0x37,
787 0x25); 789 0x25);
788 xgifb_reg_set(XGIPART2, 790 xgifb_reg_set(vb->Part2Port,
789 0x38, 791 0x38,
790 0x18); 792 0x18);
791 break; 793 break;
792 case 720: 794 case 720:
793 xgifb_reg_set(XGIPART2, 795 xgifb_reg_set(vb->Part2Port,
794 0x35, 796 0x35,
795 0xEE); 797 0xEE);
796 xgifb_reg_set(XGIPART2, 798 xgifb_reg_set(vb->Part2Port,
797 0x36, 799 0x36,
798 0x0C); 800 0x0C);
799 xgifb_reg_set(XGIPART2, 801 xgifb_reg_set(vb->Part2Port,
800 0x37, 802 0x37,
801 0x22); 803 0x22);
802 xgifb_reg_set(XGIPART2, 804 xgifb_reg_set(vb->Part2Port,
803 0x38, 805 0x38,
804 0x08); 806 0x08);
805 break; 807 break;
806 case 800: 808 case 800:
807 xgifb_reg_set(XGIPART2, 809 xgifb_reg_set(vb->Part2Port,
808 0x35, 810 0x35,
809 0xEB); 811 0xEB);
810 xgifb_reg_set(XGIPART2, 812 xgifb_reg_set(vb->Part2Port,
811 0x36, 813 0x36,
812 0x15); 814 0x15);
813 xgifb_reg_set(XGIPART2, 815 xgifb_reg_set(vb->Part2Port,
814 0x37, 816 0x37,
815 0x25); 817 0x25);
816 xgifb_reg_set(XGIPART2, 818 xgifb_reg_set(vb->Part2Port,
817 0x38, 819 0x38,
818 0xF6); 820 0xF6);
819 break; 821 break;
@@ -821,55 +823,55 @@ static void XGIfb_post_setmode(struct xgifb_video_info *xgifb_info)
821 } 823 }
822 824
823 } else if (xgifb_info->TV_type == TVMODE_PAL) { 825 } else if (xgifb_info->TV_type == TVMODE_PAL) {
824 xgifb_reg_and(XGIPART2, 0x3A, 0x1F); 826 xgifb_reg_and(vb->Part2Port, 0x3A, 0x1F);
825 827
826 if (xgifb_info->TV_plug == TVPLUG_SVIDEO) { 828 if (xgifb_info->TV_plug == TVPLUG_SVIDEO) {
827 xgifb_reg_and(XGIPART2, 0x30, 0xDF); 829 xgifb_reg_and(vb->Part2Port, 0x30, 0xDF);
828 830
829 } else if (xgifb_info->TV_plug 831 } else if (xgifb_info->TV_plug
830 == TVPLUG_COMPOSITE) { 832 == TVPLUG_COMPOSITE) {
831 xgifb_reg_or(XGIPART2, 0x30, 0x20); 833 xgifb_reg_or(vb->Part2Port, 0x30, 0x20);
832 834
833 switch (xgifb_info->video_width) { 835 switch (xgifb_info->video_width) {
834 case 640: 836 case 640:
835 xgifb_reg_set(XGIPART2, 837 xgifb_reg_set(vb->Part2Port,
836 0x35, 838 0x35,
837 0xF1); 839 0xF1);
838 xgifb_reg_set(XGIPART2, 840 xgifb_reg_set(vb->Part2Port,
839 0x36, 841 0x36,
840 0xF7); 842 0xF7);
841 xgifb_reg_set(XGIPART2, 843 xgifb_reg_set(vb->Part2Port,
842 0x37, 844 0x37,
843 0x1F); 845 0x1F);
844 xgifb_reg_set(XGIPART2, 846 xgifb_reg_set(vb->Part2Port,
845 0x38, 847 0x38,
846 0x32); 848 0x32);
847 break; 849 break;
848 case 720: 850 case 720:
849 xgifb_reg_set(XGIPART2, 851 xgifb_reg_set(vb->Part2Port,
850 0x35, 852 0x35,
851 0xF3); 853 0xF3);
852 xgifb_reg_set(XGIPART2, 854 xgifb_reg_set(vb->Part2Port,
853 0x36, 855 0x36,
854 0x00); 856 0x00);
855 xgifb_reg_set(XGIPART2, 857 xgifb_reg_set(vb->Part2Port,
856 0x37, 858 0x37,
857 0x1D); 859 0x1D);
858 xgifb_reg_set(XGIPART2, 860 xgifb_reg_set(vb->Part2Port,
859 0x38, 861 0x38,
860 0x20); 862 0x20);
861 break; 863 break;
862 case 800: 864 case 800:
863 xgifb_reg_set(XGIPART2, 865 xgifb_reg_set(vb->Part2Port,
864 0x35, 866 0x35,
865 0xFC); 867 0xFC);
866 xgifb_reg_set(XGIPART2, 868 xgifb_reg_set(vb->Part2Port,
867 0x36, 869 0x36,
868 0xFB); 870 0xFB);
869 xgifb_reg_set(XGIPART2, 871 xgifb_reg_set(vb->Part2Port,
870 0x37, 872 0x37,
871 0x14); 873 0x14);
872 xgifb_reg_set(XGIPART2, 874 xgifb_reg_set(vb->Part2Port,
873 0x38, 875 0x38,
874 0x2A); 876 0x2A);
875 break; 877 break;
@@ -882,10 +884,10 @@ static void XGIfb_post_setmode(struct xgifb_video_info *xgifb_info)
882 884
883 pr_debug("FilterTable[%d]-%d: %*ph\n", 885 pr_debug("FilterTable[%d]-%d: %*ph\n",
884 filter_tb, filter, 4, f); 886 filter_tb, filter, 4, f);
885 xgifb_reg_set(XGIPART2, 0x35, f[0]); 887 xgifb_reg_set(vb->Part2Port, 0x35, f[0]);
886 xgifb_reg_set(XGIPART2, 0x36, f[1]); 888 xgifb_reg_set(vb->Part2Port, 0x36, f[1]);
887 xgifb_reg_set(XGIPART2, 0x37, f[2]); 889 xgifb_reg_set(vb->Part2Port, 0x37, f[2]);
888 xgifb_reg_set(XGIPART2, 0x38, f[3]); 890 xgifb_reg_set(vb->Part2Port, 0x38, f[3]);
889 } 891 }
890 } 892 }
891 } 893 }
@@ -895,6 +897,7 @@ static int XGIfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
895 struct fb_info *info) 897 struct fb_info *info)
896{ 898{
897 struct xgifb_video_info *xgifb_info = info->par; 899 struct xgifb_video_info *xgifb_info = info->par;
900 struct vb_device_info *vb = &xgifb_info->dev_info;
898 struct xgi_hw_device_info *hw_info = &xgifb_info->hw_info; 901 struct xgi_hw_device_info *hw_info = &xgifb_info->hw_info;
899 unsigned int htotal = var->left_margin + var->xres + var->right_margin 902 unsigned int htotal = var->left_margin + var->xres + var->right_margin
900 + var->hsync_len; 903 + var->hsync_len;
@@ -981,11 +984,10 @@ static int XGIfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
981 info->fix.line_length = (info->var.xres_virtual 984 info->fix.line_length = (info->var.xres_virtual
982 * info->var.bits_per_pixel) >> 6; 985 * info->var.bits_per_pixel) >> 6;
983 986
984 xgifb_reg_set(XGISR, IND_SIS_PASSWORD, SIS_PASSWORD); 987 xgifb_reg_set(vb->P3c4, IND_SIS_PASSWORD, SIS_PASSWORD);
985 988
986 xgifb_reg_set(XGICR, 0x13, (info->fix.line_length & 0x00ff)); 989 xgifb_reg_set(vb->P3d4, 0x13, (info->fix.line_length & 0x00ff));
987 xgifb_reg_set(XGISR, 990 xgifb_reg_set(vb->P3c4, 0x0E,
988 0x0E,
989 (info->fix.line_length & 0xff00) >> 8); 991 (info->fix.line_length & 0xff00) >> 8);
990 992
991 XGIfb_post_setmode(xgifb_info); 993 XGIfb_post_setmode(xgifb_info);
@@ -1013,16 +1015,16 @@ static int XGIfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
1013 xgifb_info->XGI310_AccelDepth = 0x00000000; 1015 xgifb_info->XGI310_AccelDepth = 0x00000000;
1014 xgifb_info->video_cmap_len = 256; 1016 xgifb_info->video_cmap_len = 256;
1015#if defined(__BIG_ENDIAN) 1017#if defined(__BIG_ENDIAN)
1016 cr_data = xgifb_reg_get(XGICR, 0x4D); 1018 cr_data = xgifb_reg_get(vb->P3d4, 0x4D);
1017 xgifb_reg_set(XGICR, 0x4D, (cr_data & 0xE0)); 1019 xgifb_reg_set(vb->P3d4, 0x4D, (cr_data & 0xE0));
1018#endif 1020#endif
1019 break; 1021 break;
1020 case 16: 1022 case 16:
1021 xgifb_info->DstColor = 0x8000; 1023 xgifb_info->DstColor = 0x8000;
1022 xgifb_info->XGI310_AccelDepth = 0x00010000; 1024 xgifb_info->XGI310_AccelDepth = 0x00010000;
1023#if defined(__BIG_ENDIAN) 1025#if defined(__BIG_ENDIAN)
1024 cr_data = xgifb_reg_get(XGICR, 0x4D); 1026 cr_data = xgifb_reg_get(vb->P3d4, 0x4D);
1025 xgifb_reg_set(XGICR, 0x4D, ((cr_data & 0xE0) | 0x0B)); 1027 xgifb_reg_set(vb->P3d4, 0x4D, ((cr_data & 0xE0) | 0x0B));
1026#endif 1028#endif
1027 xgifb_info->video_cmap_len = 16; 1029 xgifb_info->video_cmap_len = 16;
1028 break; 1030 break;
@@ -1031,8 +1033,8 @@ static int XGIfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
1031 xgifb_info->XGI310_AccelDepth = 0x00020000; 1033 xgifb_info->XGI310_AccelDepth = 0x00020000;
1032 xgifb_info->video_cmap_len = 16; 1034 xgifb_info->video_cmap_len = 16;
1033#if defined(__BIG_ENDIAN) 1035#if defined(__BIG_ENDIAN)
1034 cr_data = xgifb_reg_get(XGICR, 0x4D); 1036 cr_data = xgifb_reg_get(vb->P3d4, 0x4D);
1035 xgifb_reg_set(XGICR, 0x4D, ((cr_data & 0xE0) | 0x15)); 1037 xgifb_reg_set(vb->P3d4, 0x4D, ((cr_data & 0xE0) | 0x15));
1036#endif 1038#endif
1037 break; 1039 break;
1038 default: 1040 default:
@@ -1051,6 +1053,7 @@ static int XGIfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
1051static int XGIfb_pan_var(struct fb_var_screeninfo *var, struct fb_info *info) 1053static int XGIfb_pan_var(struct fb_var_screeninfo *var, struct fb_info *info)
1052{ 1054{
1053 struct xgifb_video_info *xgifb_info = info->par; 1055 struct xgifb_video_info *xgifb_info = info->par;
1056 struct vb_device_info *vb = &xgifb_info->dev_info;
1054 unsigned int base; 1057 unsigned int base;
1055 1058
1056 base = var->yoffset * info->var.xres_virtual + var->xoffset; 1059 base = var->yoffset * info->var.xres_virtual + var->xoffset;
@@ -1068,22 +1071,20 @@ static int XGIfb_pan_var(struct fb_var_screeninfo *var, struct fb_info *info)
1068 break; 1071 break;
1069 } 1072 }
1070 1073
1071 xgifb_reg_set(XGISR, IND_SIS_PASSWORD, SIS_PASSWORD); 1074 xgifb_reg_set(vb->P3c4, IND_SIS_PASSWORD, SIS_PASSWORD);
1072 1075
1073 xgifb_reg_set(XGICR, 0x0D, base & 0xFF); 1076 xgifb_reg_set(vb->P3d4, 0x0D, base & 0xFF);
1074 xgifb_reg_set(XGICR, 0x0C, (base >> 8) & 0xFF); 1077 xgifb_reg_set(vb->P3d4, 0x0C, (base >> 8) & 0xFF);
1075 xgifb_reg_set(XGISR, 0x0D, (base >> 16) & 0xFF); 1078 xgifb_reg_set(vb->P3c4, 0x0D, (base >> 16) & 0xFF);
1076 xgifb_reg_set(XGISR, 0x37, (base >> 24) & 0x03); 1079 xgifb_reg_set(vb->P3c4, 0x37, (base >> 24) & 0x03);
1077 xgifb_reg_and_or(XGISR, 0x37, 0xDF, (base >> 21) & 0x04); 1080 xgifb_reg_and_or(vb->P3c4, 0x37, 0xDF, (base >> 21) & 0x04);
1078 1081
1079 if (xgifb_info->display2 != XGIFB_DISP_NONE) { 1082 if (xgifb_info->display2 != XGIFB_DISP_NONE) {
1080 xgifb_reg_or(XGIPART1, SIS_CRT2_WENABLE_315, 0x01); 1083 xgifb_reg_or(vb->Part1Port, SIS_CRT2_WENABLE_315, 0x01);
1081 xgifb_reg_set(XGIPART1, 0x06, (base & 0xFF)); 1084 xgifb_reg_set(vb->Part1Port, 0x06, (base & 0xFF));
1082 xgifb_reg_set(XGIPART1, 0x05, ((base >> 8) & 0xFF)); 1085 xgifb_reg_set(vb->Part1Port, 0x05, ((base >> 8) & 0xFF));
1083 xgifb_reg_set(XGIPART1, 0x04, ((base >> 16) & 0xFF)); 1086 xgifb_reg_set(vb->Part1Port, 0x04, ((base >> 16) & 0xFF));
1084 xgifb_reg_and_or(XGIPART1, 1087 xgifb_reg_and_or(vb->Part1Port, 0x02, 0x7F,
1085 0x02,
1086 0x7F,
1087 ((base >> 24) & 0x01) << 7); 1088 ((base >> 24) & 0x01) << 7);
1088 } 1089 }
1089 return 0; 1090 return 0;
@@ -1110,21 +1111,22 @@ static int XGIfb_setcolreg(unsigned int regno, unsigned int red,
1110 unsigned int transp, struct fb_info *info) 1111 unsigned int transp, struct fb_info *info)
1111{ 1112{
1112 struct xgifb_video_info *xgifb_info = info->par; 1113 struct xgifb_video_info *xgifb_info = info->par;
1114 struct vb_device_info *vb = &xgifb_info->dev_info;
1113 1115
1114 if (regno >= XGIfb_get_cmap_len(&info->var)) 1116 if (regno >= XGIfb_get_cmap_len(&info->var))
1115 return 1; 1117 return 1;
1116 1118
1117 switch (info->var.bits_per_pixel) { 1119 switch (info->var.bits_per_pixel) {
1118 case 8: 1120 case 8:
1119 outb(regno, XGIDACA); 1121 outb(regno, vb->P3c8);
1120 outb((red >> 10), XGIDACD); 1122 outb((red >> 10), vb->P3c9);
1121 outb((green >> 10), XGIDACD); 1123 outb((green >> 10), vb->P3c9);
1122 outb((blue >> 10), XGIDACD); 1124 outb((blue >> 10), vb->P3c9);
1123 if (xgifb_info->display2 != XGIFB_DISP_NONE) { 1125 if (xgifb_info->display2 != XGIFB_DISP_NONE) {
1124 outb(regno, XGIDAC2A); 1126 outb(regno, vb->Part5Port);
1125 outb((red >> 8), XGIDAC2D); 1127 outb((red >> 8), (vb->Part5Port + 1));
1126 outb((green >> 8), XGIDAC2D); 1128 outb((green >> 8), (vb->Part5Port + 1));
1127 outb((blue >> 8), XGIDAC2D); 1129 outb((blue >> 8), (vb->Part5Port + 1));
1128 } 1130 }
1129 break; 1131 break;
1130 case 16: 1132 case 16:
@@ -1344,18 +1346,19 @@ static int XGIfb_pan_display(struct fb_var_screeninfo *var,
1344static int XGIfb_blank(int blank, struct fb_info *info) 1346static int XGIfb_blank(int blank, struct fb_info *info)
1345{ 1347{
1346 struct xgifb_video_info *xgifb_info = info->par; 1348 struct xgifb_video_info *xgifb_info = info->par;
1349 struct vb_device_info *vb = &xgifb_info->dev_info;
1347 u8 reg; 1350 u8 reg;
1348 1351
1349 reg = xgifb_reg_get(XGICR, 0x17); 1352 reg = xgifb_reg_get(vb->P3d4, 0x17);
1350 1353
1351 if (blank > 0) 1354 if (blank > 0)
1352 reg &= 0x7f; 1355 reg &= 0x7f;
1353 else 1356 else
1354 reg |= 0x80; 1357 reg |= 0x80;
1355 1358
1356 xgifb_reg_set(XGICR, 0x17, reg); 1359 xgifb_reg_set(vb->P3d4, 0x17, reg);
1357 xgifb_reg_set(XGISR, 0x00, 0x01); /* Synchronous Reset */ 1360 xgifb_reg_set(vb->P3c4, 0x00, 0x01); /* Synchronous Reset */
1358 xgifb_reg_set(XGISR, 0x00, 0x03); /* End Reset */ 1361 xgifb_reg_set(vb->P3c4, 0x00, 0x03); /* End Reset */
1359 return 0; 1362 return 0;
1360} 1363}
1361 1364
@@ -1379,14 +1382,15 @@ static struct fb_ops XGIfb_ops = {
1379 1382
1380static int XGIfb_get_dram_size(struct xgifb_video_info *xgifb_info) 1383static int XGIfb_get_dram_size(struct xgifb_video_info *xgifb_info)
1381{ 1384{
1385 struct vb_device_info *vb = &xgifb_info->dev_info;
1382 u8 ChannelNum, tmp; 1386 u8 ChannelNum, tmp;
1383 u8 reg = 0; 1387 u8 reg = 0;
1384 1388
1385 /* xorg driver sets 32MB * 1 channel */ 1389 /* xorg driver sets 32MB * 1 channel */
1386 if (xgifb_info->chip == XG27) 1390 if (xgifb_info->chip == XG27)
1387 xgifb_reg_set(XGISR, IND_SIS_DRAM_SIZE, 0x51); 1391 xgifb_reg_set(vb->P3c4, IND_SIS_DRAM_SIZE, 0x51);
1388 1392
1389 reg = xgifb_reg_get(XGISR, IND_SIS_DRAM_SIZE); 1393 reg = xgifb_reg_get(vb->P3c4, IND_SIS_DRAM_SIZE);
1390 if (!reg) 1394 if (!reg)
1391 return -1; 1395 return -1;
1392 1396
@@ -1457,12 +1461,13 @@ static int XGIfb_get_dram_size(struct xgifb_video_info *xgifb_info)
1457 1461
1458static void XGIfb_detect_VB(struct xgifb_video_info *xgifb_info) 1462static void XGIfb_detect_VB(struct xgifb_video_info *xgifb_info)
1459{ 1463{
1464 struct vb_device_info *vb = &xgifb_info->dev_info;
1460 u8 cr32, temp = 0; 1465 u8 cr32, temp = 0;
1461 1466
1462 xgifb_info->TV_plug = 0; 1467 xgifb_info->TV_plug = 0;
1463 xgifb_info->TV_type = 0; 1468 xgifb_info->TV_type = 0;
1464 1469
1465 cr32 = xgifb_reg_get(XGICR, IND_XGI_SCRATCH_REG_CR32); 1470 cr32 = xgifb_reg_get(vb->P3d4, IND_XGI_SCRATCH_REG_CR32);
1466 1471
1467 if ((cr32 & SIS_CRT1) && !XGIfb_crt1off) { 1472 if ((cr32 & SIS_CRT1) && !XGIfb_crt1off) {
1468 XGIfb_crt1off = 0; 1473 XGIfb_crt1off = 0;
@@ -1499,7 +1504,7 @@ static void XGIfb_detect_VB(struct xgifb_video_info *xgifb_info)
1499 } 1504 }
1500 1505
1501 if (xgifb_info->TV_type == 0) { 1506 if (xgifb_info->TV_type == 0) {
1502 temp = xgifb_reg_get(XGICR, 0x38); 1507 temp = xgifb_reg_get(vb->P3d4, 0x38);
1503 if (temp & 0x10) 1508 if (temp & 0x10)
1504 xgifb_info->TV_type = TVMODE_PAL; 1509 xgifb_info->TV_type = TVMODE_PAL;
1505 else 1510 else
@@ -1519,7 +1524,7 @@ static bool XGIfb_has_VB(struct xgifb_video_info *xgifb_info)
1519{ 1524{
1520 u8 vb_chipid; 1525 u8 vb_chipid;
1521 1526
1522 vb_chipid = xgifb_reg_get(XGIPART4, 0x00); 1527 vb_chipid = xgifb_reg_get(xgifb_info->dev_info.Part4Port, 0x00);
1523 switch (vb_chipid) { 1528 switch (vb_chipid) {
1524 case 0x01: 1529 case 0x01:
1525 xgifb_info->hasVB = HASVB_301; 1530 xgifb_info->hasVB = HASVB_301;
@@ -1539,7 +1544,8 @@ static void XGIfb_get_VB_type(struct xgifb_video_info *xgifb_info)
1539 u8 reg; 1544 u8 reg;
1540 1545
1541 if (!XGIfb_has_VB(xgifb_info)) { 1546 if (!XGIfb_has_VB(xgifb_info)) {
1542 reg = xgifb_reg_get(XGICR, IND_XGI_SCRATCH_REG_CR37); 1547 reg = xgifb_reg_get(xgifb_info->dev_info.P3d4,
1548 IND_XGI_SCRATCH_REG_CR37);
1543 switch ((reg & SIS_EXTERNAL_CHIP_MASK) >> 1) { 1549 switch ((reg & SIS_EXTERNAL_CHIP_MASK) >> 1) {
1544 case SIS_EXTERNAL_CHIP_LVDS: 1550 case SIS_EXTERNAL_CHIP_LVDS:
1545 xgifb_info->hasVB = HASVB_LVDS; 1551 xgifb_info->hasVB = HASVB_LVDS;
@@ -1617,6 +1623,7 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1617 int ret; 1623 int ret;
1618 struct fb_info *fb_info; 1624 struct fb_info *fb_info;
1619 struct xgifb_video_info *xgifb_info; 1625 struct xgifb_video_info *xgifb_info;
1626 struct vb_device_info *vb;
1620 struct xgi_hw_device_info *hw_info; 1627 struct xgi_hw_device_info *hw_info;
1621 unsigned long video_size_max; 1628 unsigned long video_size_max;
1622 1629
@@ -1625,6 +1632,7 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1625 return -ENOMEM; 1632 return -ENOMEM;
1626 1633
1627 xgifb_info = fb_info->par; 1634 xgifb_info = fb_info->par;
1635 vb = &xgifb_info->dev_info;
1628 hw_info = &xgifb_info->hw_info; 1636 hw_info = &xgifb_info->hw_info;
1629 xgifb_info->fb_info = fb_info; 1637 xgifb_info->fb_info = fb_info;
1630 xgifb_info->chip_id = pdev->device; 1638 xgifb_info->chip_id = pdev->device;
@@ -1658,10 +1666,11 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1658 xgifb_info->display2_force = true; 1666 xgifb_info->display2_force = true;
1659 } 1667 }
1660 1668
1661 XGIRegInit(&xgifb_info->dev_info, xgifb_info->vga_base); 1669 XGIRegInit(vb, xgifb_info->vga_base);
1662 1670
1663 xgifb_reg_set(XGISR, IND_SIS_PASSWORD, SIS_PASSWORD); 1671 xgifb_reg_set(vb->P3c4,
1664 reg1 = xgifb_reg_get(XGISR, IND_SIS_PASSWORD); 1672 IND_SIS_PASSWORD, SIS_PASSWORD);
1673 reg1 = xgifb_reg_get(vb->P3c4, IND_SIS_PASSWORD);
1665 1674
1666 if (reg1 != 0xa1) { /* I/O error */ 1675 if (reg1 != 0xa1) { /* I/O error */
1667 dev_err(&pdev->dev, "I/O error\n"); 1676 dev_err(&pdev->dev, "I/O error\n");
@@ -1671,8 +1680,10 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1671 1680
1672 switch (xgifb_info->chip_id) { 1681 switch (xgifb_info->chip_id) {
1673 case PCI_DEVICE_ID_XGI_20: 1682 case PCI_DEVICE_ID_XGI_20:
1674 xgifb_reg_or(XGICR, Index_CR_GPIO_Reg3, GPIOG_EN); 1683 xgifb_reg_or(vb->P3d4,
1675 CR48 = xgifb_reg_get(XGICR, Index_CR_GPIO_Reg1); 1684 Index_CR_GPIO_Reg3, GPIOG_EN);
1685 CR48 = xgifb_reg_get(vb->P3d4,
1686 Index_CR_GPIO_Reg1);
1676 if (CR48 & GPIOG_READ) 1687 if (CR48 & GPIOG_READ)
1677 xgifb_info->chip = XG21; 1688 xgifb_info->chip = XG21;
1678 else 1689 else
@@ -1703,11 +1714,12 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1703 } 1714 }
1704 1715
1705 /* Enable PCI_LINEAR_ADDRESSING and MMIO_ENABLE */ 1716 /* Enable PCI_LINEAR_ADDRESSING and MMIO_ENABLE */
1706 xgifb_reg_or(XGISR, 1717 xgifb_reg_or(vb->P3c4,
1707 IND_SIS_PCI_ADDRESS_SET, 1718 IND_SIS_PCI_ADDRESS_SET,
1708 (SIS_PCI_ADDR_ENABLE | SIS_MEM_MAP_IO_ENABLE)); 1719 (SIS_PCI_ADDR_ENABLE | SIS_MEM_MAP_IO_ENABLE));
1709 /* Enable 2D accelerator engine */ 1720 /* Enable 2D accelerator engine */
1710 xgifb_reg_or(XGISR, IND_SIS_MODULE_ENABLE, SIS_ENABLE_2D); 1721 xgifb_reg_or(vb->P3c4,
1722 IND_SIS_MODULE_ENABLE, SIS_ENABLE_2D);
1711 1723
1712 hw_info->ulVideoMemorySize = xgifb_info->video_size; 1724 hw_info->ulVideoMemorySize = xgifb_info->video_size;
1713 1725
@@ -1760,7 +1772,7 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1760 (xgifb_info->chip == XG27)) { 1772 (xgifb_info->chip == XG27)) {
1761 xgifb_info->hasVB = HASVB_NONE; 1773 xgifb_info->hasVB = HASVB_NONE;
1762 } else if (xgifb_info->chip == XG21) { 1774 } else if (xgifb_info->chip == XG21) {
1763 CR38 = xgifb_reg_get(XGICR, 0x38); 1775 CR38 = xgifb_reg_get(vb->P3d4, 0x38);
1764 if ((CR38 & 0xE0) == 0xC0) 1776 if ((CR38 & 0xE0) == 0xC0)
1765 xgifb_info->display2 = XGIFB_DISP_LCD; 1777 xgifb_info->display2 = XGIFB_DISP_LCD;
1766 else if ((CR38 & 0xE0) == 0x60) 1778 else if ((CR38 & 0xE0) == 0x60)
@@ -1777,7 +1789,7 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1777 1789
1778 switch (xgifb_info->hasVB) { 1790 switch (xgifb_info->hasVB) {
1779 case HASVB_301: 1791 case HASVB_301:
1780 reg = xgifb_reg_get(XGIPART4, 0x01); 1792 reg = xgifb_reg_get(vb->Part4Port, 0x01);
1781 if (reg >= 0xE0) { 1793 if (reg >= 0xE0) {
1782 hw_info->ujVBChipID = VB_CHIP_302LV; 1794 hw_info->ujVBChipID = VB_CHIP_302LV;
1783 dev_info(&pdev->dev, 1795 dev_info(&pdev->dev,
@@ -1794,7 +1806,7 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1794 } 1806 }
1795 break; 1807 break;
1796 case HASVB_302: 1808 case HASVB_302:
1797 reg = xgifb_reg_get(XGIPART4, 0x01); 1809 reg = xgifb_reg_get(vb->Part4Port, 0x01);
1798 if (reg >= 0xE0) { 1810 if (reg >= 0xE0) {
1799 hw_info->ujVBChipID = VB_CHIP_302LV; 1811 hw_info->ujVBChipID = VB_CHIP_302LV;
1800 dev_info(&pdev->dev, 1812 dev_info(&pdev->dev,
@@ -1806,7 +1818,8 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1806 "XGI302LV bridge detected (revision 0x%02x)\n", 1818 "XGI302LV bridge detected (revision 0x%02x)\n",
1807 reg); 1819 reg);
1808 } else if (reg >= 0xB0) { 1820 } else if (reg >= 0xB0) {
1809 reg1 = xgifb_reg_get(XGIPART4, 0x23); 1821 reg1 = xgifb_reg_get(vb->Part4Port,
1822 0x23);
1810 1823
1811 hw_info->ujVBChipID = VB_CHIP_302B; 1824 hw_info->ujVBChipID = VB_CHIP_302B;
1812 1825
@@ -1844,7 +1857,8 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1844 1857
1845 if (xgifb_info->display2 == XGIFB_DISP_LCD) { 1858 if (xgifb_info->display2 == XGIFB_DISP_LCD) {
1846 if (!enable_dstn) { 1859 if (!enable_dstn) {
1847 reg = xgifb_reg_get(XGICR, IND_XGI_LCD_PANEL); 1860 reg = xgifb_reg_get(vb->P3d4,
1861 IND_XGI_LCD_PANEL);
1848 reg &= 0x0f; 1862 reg &= 0x0f;
1849 hw_info->ulCRT2LCDType = XGI310paneltype[reg]; 1863 hw_info->ulCRT2LCDType = XGI310paneltype[reg];
1850 } 1864 }
@@ -1940,11 +1954,11 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1940 XGIfb_bpp_to_var(xgifb_info, &fb_info->var); 1954 XGIfb_bpp_to_var(xgifb_info, &fb_info->var);
1941 1955
1942 fb_info->var.pixclock = (u32)(1000000000 / XGIfb_mode_rate_to_dclock 1956 fb_info->var.pixclock = (u32)(1000000000 / XGIfb_mode_rate_to_dclock
1943 (&xgifb_info->dev_info, hw_info, 1957 (vb, hw_info,
1944 XGIbios_mode[xgifb_info->mode_idx].mode_no)); 1958 XGIbios_mode[xgifb_info->mode_idx].mode_no));
1945 1959
1946 if (XGIfb_mode_rate_to_ddata(&xgifb_info->dev_info, 1960 if (XGIfb_mode_rate_to_ddata(vb, hw_info,
1947 hw_info, XGIbios_mode[xgifb_info->mode_idx].mode_no, 1961 XGIbios_mode[xgifb_info->mode_idx].mode_no,
1948 &fb_info->var.left_margin, 1962 &fb_info->var.left_margin,
1949 &fb_info->var.right_margin, 1963 &fb_info->var.right_margin,
1950 &fb_info->var.upper_margin, 1964 &fb_info->var.upper_margin,
diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c
index e9d930f150cb..1fa0dc66406e 100644
--- a/drivers/staging/xgifb/vb_setmode.c
+++ b/drivers/staging/xgifb/vb_setmode.c
@@ -74,7 +74,8 @@ static void XGI_SetSeqRegs(struct vb_device_info *pVBInfo)
74 /* Get SR1,2,3,4 from file */ 74 /* Get SR1,2,3,4 from file */
75 /* SR1 is with screen off 0x20 */ 75 /* SR1 is with screen off 0x20 */
76 SRdata = XGI330_StandTable.SR[i]; 76 SRdata = XGI330_StandTable.SR[i];
77 xgifb_reg_set(pVBInfo->P3c4, i + 1, SRdata); /* Set SR 1 2 3 4 */ 77 /* Set SR 1 2 3 4 */
78 xgifb_reg_set(pVBInfo->P3c4, i + 1, SRdata);
78 } 79 }
79} 80}
80 81
@@ -628,12 +629,14 @@ static void xgifb_set_lcd(int chip_id,
628 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */ 629 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
629 630
630 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag; 631 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
631 if (temp & 0x4000) 632 if (temp & 0x4000) {
632 /* Hsync polarity */ 633 /* Hsync polarity */
633 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20); 634 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
634 if (temp & 0x8000) 635 }
636 if (temp & 0x8000) {
635 /* Vsync polarity */ 637 /* Vsync polarity */
636 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80); 638 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
639 }
637} 640}
638 641
639/* 642/*
@@ -1225,9 +1228,10 @@ static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
1225 return table[i].DATAPTR; 1228 return table[i].DATAPTR;
1226} 1229}
1227 1230
1228static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeIdIndex, 1231static struct SiS_TVData const *XGI_GetTVPtr(
1229 unsigned short RefreshRateTableIndex, 1232 unsigned short ModeIdIndex,
1230 struct vb_device_info *pVBInfo) 1233 unsigned short RefreshRateTableIndex,
1234 struct vb_device_info *pVBInfo)
1231{ 1235{
1232 unsigned short i, tempdx, tempal, modeflag; 1236 unsigned short i, tempdx, tempal, modeflag;
1233 1237
@@ -1480,14 +1484,16 @@ static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
1480 if (tempcx >= tempax) 1484 if (tempcx >= tempax)
1481 tempcx -= tempax; 1485 tempcx -= tempax;
1482 1486
1483 xgifb_reg_set(pVBInfo->Part1Port, 0x1b, (unsigned short)(tempbx & 0xff)); 1487 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1484 xgifb_reg_set(pVBInfo->Part1Port, 0x1c, (unsigned short)(tempcx & 0xff)); 1488 (unsigned short)(tempbx & 0xff));
1489 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1490 (unsigned short)(tempcx & 0xff));
1485 1491
1486 tempbx = (tempbx >> 8) & 0x07; 1492 tempbx = (tempbx >> 8) & 0x07;
1487 tempcx = (tempcx >> 8) & 0x07; 1493 tempcx = (tempcx >> 8) & 0x07;
1488 1494
1489 xgifb_reg_set(pVBInfo->Part1Port, 0x1d, (unsigned short)((tempcx << 3) | 1495 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1490 tempbx)); 1496 (unsigned short)((tempcx << 3) | tempbx));
1491 1497
1492 tempax = pVBInfo->VT; 1498 tempax = pVBInfo->VT;
1493 tempbx = LCDPtr1->LCDVRS; 1499 tempbx = LCDPtr1->LCDVRS;
@@ -1501,8 +1507,10 @@ static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
1501 if (tempcx >= tempax) 1507 if (tempcx >= tempax)
1502 tempcx -= tempax; 1508 tempcx -= tempax;
1503 1509
1504 xgifb_reg_set(pVBInfo->Part1Port, 0x18, (unsigned short)(tempbx & 0xff)); 1510 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1505 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f, (unsigned short)(tempcx & 0x0f)); 1511 (unsigned short)(tempbx & 0xff));
1512 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1513 (unsigned short)(tempcx & 0x0f));
1506 1514
1507 tempax = ((tempbx >> 8) & 0x07) << 3; 1515 tempax = ((tempbx >> 8) & 0x07) << 3;
1508 1516
@@ -1592,16 +1600,20 @@ static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
1592 1600
1593 tempax = ((tempbx >> 8) & 0xff) << 3; 1601 tempax = ((tempbx >> 8) & 0xff) << 3;
1594 tempax |= (unsigned short)((temp3 >> 8) & 0x07); 1602 tempax |= (unsigned short)((temp3 >> 8) & 0x07);
1595 xgifb_reg_set(pVBInfo->Part1Port, 0x20, (unsigned short)(tempax & 0xff)); 1603 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1596 xgifb_reg_set(pVBInfo->Part1Port, 0x21, (unsigned short)(tempbx & 0xff)); 1604 (unsigned short)(tempax & 0xff));
1605 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1606 (unsigned short)(tempbx & 0xff));
1597 1607
1598 temp3 >>= 16; 1608 temp3 >>= 16;
1599 1609
1600 if (modeflag & HalfDCLK) 1610 if (modeflag & HalfDCLK)
1601 temp3 >>= 1; 1611 temp3 >>= 1;
1602 1612
1603 xgifb_reg_set(pVBInfo->Part1Port, 0x22, (unsigned short)((temp3 >> 8) & 0xff)); 1613 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1604 xgifb_reg_set(pVBInfo->Part1Port, 0x23, (unsigned short)(temp3 & 0xff)); 1614 (unsigned short)((temp3 >> 8) & 0xff));
1615 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1616 (unsigned short)(temp3 & 0xff));
1605} 1617}
1606 1618
1607/* 1619/*
@@ -1760,9 +1772,10 @@ static void XGI_UpdateModeInfo(struct vb_device_info *pVBInfo)
1760 1772
1761 temp &= 0x05; 1773 temp &= 0x05;
1762 1774
1763 if (!(tempcl & ActiveLCD)) 1775 if (!(tempcl & ActiveLCD)) {
1764 if (temp == 0x01) 1776 if (temp == 0x01)
1765 tempcl |= ActiveCRT2; 1777 tempcl |= ActiveCRT2;
1778 }
1766 1779
1767 if (temp == 0x04) 1780 if (temp == 0x04)
1768 tempcl |= ActiveLCD; 1781 tempcl |= ActiveLCD;
@@ -1856,7 +1869,8 @@ finish:
1856 pVBInfo->VBType = tempbx; 1869 pVBInfo->VBType = tempbx;
1857} 1870}
1858 1871
1859static void XGI_GetVBInfo(unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) 1872static void XGI_GetVBInfo(unsigned short ModeIdIndex,
1873 struct vb_device_info *pVBInfo)
1860{ 1874{
1861 unsigned short tempax, push, tempbx, temp, modeflag; 1875 unsigned short tempax, push, tempbx, temp, modeflag;
1862 1876
@@ -1981,7 +1995,8 @@ static void XGI_GetVBInfo(unsigned short ModeIdIndex, struct vb_device_info *pVB
1981 pVBInfo->VBInfo = tempbx; 1995 pVBInfo->VBInfo = tempbx;
1982} 1996}
1983 1997
1984static void XGI_GetTVInfo(unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) 1998static void XGI_GetTVInfo(unsigned short ModeIdIndex,
1999 struct vb_device_info *pVBInfo)
1985{ 2000{
1986 unsigned short tempbx = 0, resinfo = 0, modeflag, index1; 2001 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
1987 2002
@@ -1998,10 +2013,11 @@ static void XGI_GetTVInfo(unsigned short ModeIdIndex, struct vb_device_info *pVB
1998 if (tempbx & TVSetPALM) 2013 if (tempbx & TVSetPALM)
1999 /* set to NTSC if PAL-M */ 2014 /* set to NTSC if PAL-M */
2000 tempbx &= ~TVSetPAL; 2015 tempbx &= ~TVSetPAL;
2001 } else 2016 } else {
2002 tempbx &= (SetCHTVOverScan | 2017 tempbx &= (SetCHTVOverScan |
2003 TVSetNTSCJ | 2018 TVSetNTSCJ |
2004 TVSetPAL); 2019 TVSetPAL);
2020 }
2005 2021
2006 if (pVBInfo->VBInfo & SetCRT2ToSCART) 2022 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2007 tempbx |= TVSetPAL; 2023 tempbx |= TVSetPAL;
@@ -2026,9 +2042,10 @@ static void XGI_GetTVInfo(unsigned short ModeIdIndex, struct vb_device_info *pVB
2026 (!(pVBInfo->VBInfo & SetNotSimuMode))) 2042 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2027 tempbx |= TVSimuMode; 2043 tempbx |= TVSimuMode;
2028 2044
2029 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8)) 2045 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8)) {
2030 /* NTSC 1024x768, */ 2046 /* NTSC 1024x768, */
2031 tempbx |= NTSC1024x768; 2047 tempbx |= NTSC1024x768;
2048 }
2032 2049
2033 tempbx |= RPLLDIV2XO; 2050 tempbx |= RPLLDIV2XO;
2034 2051
@@ -2327,9 +2344,10 @@ void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2327 mdelay(xgifb_info->lvds_data.PSC_S3); 2344 mdelay(xgifb_info->lvds_data.PSC_S3);
2328 } 2345 }
2329 2346
2330 if (pVBInfo->IF_DEF_LVDS == 0) 2347 if (pVBInfo->IF_DEF_LVDS == 0) {
2331 /* DVO/DVI signal off */ 2348 /* DVO/DVI signal off */
2332 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo); 2349 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
2350 }
2333 } 2351 }
2334 2352
2335 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20); 2353 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
@@ -2688,7 +2706,7 @@ static unsigned short XGI_GetColorDepth(unsigned short ModeIdIndex)
2688 2706
2689static unsigned short XGI_GetOffset(unsigned short ModeNo, 2707static unsigned short XGI_GetOffset(unsigned short ModeNo,
2690 unsigned short ModeIdIndex, 2708 unsigned short ModeIdIndex,
2691 unsigned short RefreshRateTableIndex) 2709 unsigned short RefreshRateTableIndex)
2692{ 2710{
2693 unsigned short temp, colordepth, modeinfo, index, infoflag, 2711 unsigned short temp, colordepth, modeinfo, index, infoflag,
2694 ColorDepth[] = { 0x01, 0x02, 0x04 }; 2712 ColorDepth[] = { 0x01, 0x02, 0x04 };
@@ -3633,7 +3651,8 @@ static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
3633 } 3651 }
3634} 3652}
3635 3653
3636static void XGI_SetLCDRegs(unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) 3654static void XGI_SetLCDRegs(unsigned short ModeIdIndex,
3655 struct vb_device_info *pVBInfo)
3637{ 3656{
3638 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah, 3657 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3639 tempbh, tempch; 3658 tempbh, tempch;
@@ -4527,8 +4546,10 @@ static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
4527 * 1 : 301B/302B/301LV/302LV 4546 * 1 : 301B/302B/301LV/302LV
4528 * Description : 4547 * Description :
4529 */ 4548 */
4530static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl, 4549static void XGI_GetTVPtrIndex2(unsigned short *tempbx,
4531 unsigned char *tempch, struct vb_device_info *pVBInfo) 4550 unsigned char *tempcl,
4551 unsigned char *tempch,
4552 struct vb_device_info *pVBInfo)
4532{ 4553{
4533 *tempbx = 0; 4554 *tempbx = 0;
4534 *tempcl = 0; 4555 *tempcl = 0;
@@ -4632,13 +4653,14 @@ static void XGI_SetLCDCap_A(unsigned short tempcx,
4632static void XGI_SetLCDCap_B(unsigned short tempcx, 4653static void XGI_SetLCDCap_B(unsigned short tempcx,
4633 struct vb_device_info *pVBInfo) 4654 struct vb_device_info *pVBInfo)
4634{ 4655{
4635 if (tempcx & EnableLCD24bpp) /* 24bits */ 4656 if (tempcx & EnableLCD24bpp) { /* 24bits */
4636 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0, 4657 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
4637 (unsigned short)(((tempcx & 0x00ff) >> 6) | 0x0c)); 4658 (unsigned short)(((tempcx & 0x00ff) >> 6) | 0x0c));
4638 else 4659 } else {
4639 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0, 4660 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
4640 (unsigned short)(((tempcx & 0x00ff) >> 6) | 0x18)); 4661 (unsigned short)(((tempcx & 0x00ff) >> 6) | 0x18));
4641 /* Enable Dither */ 4662 /* Enable Dither */
4663 }
4642} 4664}
4643 4665
4644static void XGI_LongWait(struct vb_device_info *pVBInfo) 4666static void XGI_LongWait(struct vb_device_info *pVBInfo)
@@ -5461,8 +5483,9 @@ unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5461 switch (HwDeviceExtension->ujVBChipID) { 5483 switch (HwDeviceExtension->ujVBChipID) {
5462 case VB_CHIP_301: /* fall through */ 5484 case VB_CHIP_301: /* fall through */
5463 case VB_CHIP_302: 5485 case VB_CHIP_302:
5486 /* add for CRT2 */
5464 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension, 5487 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5465 pVBInfo); /* add for CRT2 */ 5488 pVBInfo);
5466 break; 5489 break;
5467 5490
5468 default: 5491 default:
diff --git a/drivers/staging/xgifb/vb_table.h b/drivers/staging/xgifb/vb_table.h
index 0da63e1da32f..42ecf7fe6766 100644
--- a/drivers/staging/xgifb/vb_table.h
+++ b/drivers/staging/xgifb/vb_table.h
@@ -2493,7 +2493,7 @@ static const struct XGI301C_Tap4TimingStruct xgifb_ntsc_525_tap4_timing[] = {
2493 0x02, 0x0C, 0x0E, 0x04, 0x01, 0x0B, 0x0E, 0x06, /* ; EA-EF */ 2493 0x02, 0x0C, 0x0E, 0x04, 0x01, 0x0B, 0x0E, 0x06, /* ; EA-EF */
2494 0x01, 0x0B, 0x0E, 0x06, 0x00, 0x0A, 0x0F, 0x07, /* ; F0-F7 */ 2494 0x01, 0x0B, 0x0E, 0x06, 0x00, 0x0A, 0x0F, 0x07, /* ; F0-F7 */
2495 0x00, 0x0A, 0x0F, 0x07, 0x00, 0x09, 0x0F, 0x08 /* ; F8-FF */ 2495 0x00, 0x0A, 0x0F, 0x07, 0x00, 0x09, 0x0F, 0x08 /* ; F8-FF */
2496 } 2496 }
2497 } 2497 }
2498}; 2498};
2499 2499
@@ -2507,7 +2507,7 @@ static const struct XGI301C_Tap4TimingStruct YPbPr750pTap4Timing[] = {
2507 0x7D, 0x0F, 0x16, 0x7E, 0x7D, 0x0E, 0x17, 0x7E, /* ; EA-EF */ 2507 0x7D, 0x0F, 0x16, 0x7E, 0x7D, 0x0E, 0x17, 0x7E, /* ; EA-EF */
2508 0x7D, 0x0C, 0x18, 0x7F, 0x7D, 0x0A, 0x18, 0x01, /* ; F0-F7 */ 2508 0x7D, 0x0C, 0x18, 0x7F, 0x7D, 0x0A, 0x18, 0x01, /* ; F0-F7 */
2509 0x7D, 0x08, 0x19, 0x02, 0x7D, 0x06, 0x19, 0x04 /* F8-FF */ 2509 0x7D, 0x08, 0x19, 0x02, 0x7D, 0x06, 0x19, 0x04 /* F8-FF */
2510 } 2510 }
2511 } 2511 }
2512}; 2512};
2513#endif 2513#endif
diff --git a/drivers/staging/unisys/visorbus/Kconfig b/drivers/visorbus/Kconfig
index 511388075ffa..1f5812b936d0 100644
--- a/drivers/staging/unisys/visorbus/Kconfig
+++ b/drivers/visorbus/Kconfig
@@ -4,7 +4,7 @@
4 4
5config UNISYS_VISORBUS 5config UNISYS_VISORBUS
6 tristate "Unisys visorbus driver" 6 tristate "Unisys visorbus driver"
7 depends on UNISYSSPAR 7 depends on X86_64 && ACPI
8 ---help--- 8 ---help---
9 The visorbus driver is a virtualized bus for the Unisys s-Par firmware. 9 The visorbus driver is a virtualized bus for the Unisys s-Par firmware.
10 Virtualized devices allow Linux guests on a system to share disks and 10 Virtualized devices allow Linux guests on a system to share disks and
diff --git a/drivers/staging/unisys/visorbus/Makefile b/drivers/visorbus/Makefile
index 784cdc1f9d6a..e8df59d1301f 100644
--- a/drivers/staging/unisys/visorbus/Makefile
+++ b/drivers/visorbus/Makefile
@@ -8,5 +8,3 @@ obj-$(CONFIG_UNISYS_VISORBUS) += visorbus.o
8visorbus-y := visorbus_main.o 8visorbus-y := visorbus_main.o
9visorbus-y += visorchannel.o 9visorbus-y += visorchannel.o
10visorbus-y += visorchipset.o 10visorbus-y += visorchipset.o
11
12ccflags-y += -Idrivers/staging/unisys/include
diff --git a/drivers/staging/unisys/visorbus/controlvmchannel.h b/drivers/visorbus/controlvmchannel.h
index 9ee9886a9aed..8c57562a070a 100644
--- a/drivers/staging/unisys/visorbus/controlvmchannel.h
+++ b/drivers/visorbus/controlvmchannel.h
@@ -1,24 +1,14 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2010 - 2015 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
3 * All rights reserved. 4 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
13 * details.
14 */ 5 */
15 6
16#ifndef __CONTROLVMCHANNEL_H__ 7#ifndef __CONTROLVMCHANNEL_H__
17#define __CONTROLVMCHANNEL_H__ 8#define __CONTROLVMCHANNEL_H__
18 9
19#include <linux/uuid.h> 10#include <linux/uuid.h>
20 11#include <linux/visorbus.h>
21#include "visorchannel.h"
22 12
23/* {2B3C2D10-7EF5-4ad8-B966-3448B7386B3D} */ 13/* {2B3C2D10-7EF5-4ad8-B966-3448B7386B3D} */
24#define VISOR_CONTROLVM_CHANNEL_GUID \ 14#define VISOR_CONTROLVM_CHANNEL_GUID \
diff --git a/drivers/staging/unisys/visorbus/vbuschannel.h b/drivers/visorbus/vbuschannel.h
index 981b180f3c4b..b1dce26166bf 100644
--- a/drivers/staging/unisys/visorbus/vbuschannel.h
+++ b/drivers/visorbus/vbuschannel.h
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2010 - 2015 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
3 * All rights reserved. 4 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
13 * details.
14 */ 5 */
15 6
16#ifndef __VBUSCHANNEL_H__ 7#ifndef __VBUSCHANNEL_H__
@@ -26,7 +17,7 @@
26 */ 17 */
27 18
28#include <linux/uuid.h> 19#include <linux/uuid.h>
29#include "visorchannel.h" 20#include <linux/visorbus.h>
30 21
31/* {193b331b-c58f-11da-95a9-00e08161165f} */ 22/* {193b331b-c58f-11da-95a9-00e08161165f} */
32#define VISOR_VBUS_CHANNEL_GUID \ 23#define VISOR_VBUS_CHANNEL_GUID \
diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c b/drivers/visorbus/visorbus_main.c
index 6cb6eb0673c6..0b2434cc4ecd 100644
--- a/drivers/staging/unisys/visorbus/visorbus_main.c
+++ b/drivers/visorbus/visorbus_main.c
@@ -1,25 +1,16 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright � 2010 - 2015 UNISYS CORPORATION 3 * Copyright � 2010 - 2015 UNISYS CORPORATION
3 * All rights reserved. 4 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
13 * details.
14 */ 5 */
15 6
16#include <linux/ctype.h> 7#include <linux/ctype.h>
17#include <linux/debugfs.h> 8#include <linux/debugfs.h>
18#include <linux/module.h> 9#include <linux/module.h>
19#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/visorbus.h>
20#include <linux/uuid.h> 12#include <linux/uuid.h>
21 13
22#include "visorbus.h"
23#include "visorbus_private.h" 14#include "visorbus_private.h"
24 15
25static const guid_t visor_vbus_channel_guid = VISOR_VBUS_CHANNEL_GUID; 16static const guid_t visor_vbus_channel_guid = VISOR_VBUS_CHANNEL_GUID;
diff --git a/drivers/staging/unisys/visorbus/visorbus_private.h b/drivers/visorbus/visorbus_private.h
index 4a8b12d7cfaa..366380b7f8d9 100644
--- a/drivers/staging/unisys/visorbus/visorbus_private.h
+++ b/drivers/visorbus/visorbus_private.h
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2010 - 2015 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
3 * All rights reserved. 4 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
13 * details.
14 */ 5 */
15 6
16#ifndef __VISORBUS_PRIVATE_H__ 7#ifndef __VISORBUS_PRIVATE_H__
@@ -18,10 +9,10 @@
18 9
19#include <linux/uuid.h> 10#include <linux/uuid.h>
20#include <linux/utsname.h> 11#include <linux/utsname.h>
12#include <linux/visorbus.h>
21 13
22#include "controlvmchannel.h" 14#include "controlvmchannel.h"
23#include "vbuschannel.h" 15#include "vbuschannel.h"
24#include "visorbus.h"
25 16
26struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no, 17struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no,
27 struct visor_device *from); 18 struct visor_device *from);
diff --git a/drivers/staging/unisys/visorbus/visorchannel.c b/drivers/visorbus/visorchannel.c
index aae16073ba03..bd890e0f456b 100644
--- a/drivers/staging/unisys/visorbus/visorchannel.c
+++ b/drivers/visorbus/visorchannel.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2010 - 2015 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
3 * All rights reserved. 4 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
13 * details.
14 */ 5 */
15 6
16/* 7/*
@@ -21,8 +12,8 @@
21#include <linux/uuid.h> 12#include <linux/uuid.h>
22#include <linux/io.h> 13#include <linux/io.h>
23#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/visorbus.h>
24 16
25#include "visorbus.h"
26#include "visorbus_private.h" 17#include "visorbus_private.h"
27#include "controlvmchannel.h" 18#include "controlvmchannel.h"
28 19
diff --git a/drivers/staging/unisys/visorbus/visorchipset.c b/drivers/visorbus/visorchipset.c
index fed554a43151..ca752b8f495f 100644
--- a/drivers/staging/unisys/visorbus/visorchipset.c
+++ b/drivers/visorbus/visorchipset.c
@@ -1,22 +1,13 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2010 - 2015 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
3 * All rights reserved. 4 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
13 * details.
14 */ 5 */
15 6
16#include <linux/acpi.h> 7#include <linux/acpi.h>
17#include <linux/crash_dump.h> 8#include <linux/crash_dump.h>
9#include <linux/visorbus.h>
18 10
19#include "visorbus.h"
20#include "visorbus_private.h" 11#include "visorbus_private.h"
21 12
22/* {72120008-4AAB-11DC-8530-444553544200} */ 13/* {72120008-4AAB-11DC-8530-444553544200} */
@@ -590,7 +581,8 @@ static void *parser_name_get(struct parser_context *ctx)
590 struct visor_controlvm_parameters_header *phdr; 581 struct visor_controlvm_parameters_header *phdr;
591 582
592 phdr = &ctx->data; 583 phdr = &ctx->data;
593 if (phdr->name_offset + phdr->name_length > ctx->param_bytes) 584 if ((unsigned long)phdr->name_offset +
585 (unsigned long)phdr->name_length > ctx->param_bytes)
594 return NULL; 586 return NULL;
595 ctx->curr = (char *)&phdr + phdr->name_offset; 587 ctx->curr = (char *)&phdr + phdr->name_offset;
596 ctx->bytes_remaining = phdr->name_length; 588 ctx->bytes_remaining = phdr->name_length;
@@ -1317,13 +1309,13 @@ static void parser_done(struct parser_context *ctx)
1317static struct parser_context *parser_init_stream(u64 addr, u32 bytes, 1309static struct parser_context *parser_init_stream(u64 addr, u32 bytes,
1318 bool *retry) 1310 bool *retry)
1319{ 1311{
1320 int allocbytes; 1312 unsigned long allocbytes;
1321 struct parser_context *ctx; 1313 struct parser_context *ctx;
1322 void *mapping; 1314 void *mapping;
1323 1315
1324 *retry = false; 1316 *retry = false;
1325 /* alloc an extra byte to ensure payload is \0 terminated */ 1317 /* alloc an extra byte to ensure payload is \0 terminated */
1326 allocbytes = bytes + 1 + (sizeof(struct parser_context) - 1318 allocbytes = (unsigned long)bytes + 1 + (sizeof(struct parser_context) -
1327 sizeof(struct visor_controlvm_parameters_header)); 1319 sizeof(struct visor_controlvm_parameters_header));
1328 if ((chipset_dev->controlvm_payload_bytes_buffered + bytes) > 1320 if ((chipset_dev->controlvm_payload_bytes_buffered + bytes) >
1329 MAX_CONTROLVM_PAYLOAD_BYTES) { 1321 MAX_CONTROLVM_PAYLOAD_BYTES) {
diff --git a/fs/Kconfig b/fs/Kconfig
index 0ed56752f208..9774588da60e 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -294,7 +294,6 @@ config NFS_COMMON
294source "net/sunrpc/Kconfig" 294source "net/sunrpc/Kconfig"
295source "fs/ceph/Kconfig" 295source "fs/ceph/Kconfig"
296source "fs/cifs/Kconfig" 296source "fs/cifs/Kconfig"
297source "fs/ncpfs/Kconfig"
298source "fs/coda/Kconfig" 297source "fs/coda/Kconfig"
299source "fs/afs/Kconfig" 298source "fs/afs/Kconfig"
300source "fs/9p/Kconfig" 299source "fs/9p/Kconfig"
diff --git a/fs/Makefile b/fs/Makefile
index ef772f1eaff8..add789ea270a 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -92,7 +92,6 @@ obj-$(CONFIG_LOCKD) += lockd/
92obj-$(CONFIG_NLS) += nls/ 92obj-$(CONFIG_NLS) += nls/
93obj-$(CONFIG_SYSV_FS) += sysv/ 93obj-$(CONFIG_SYSV_FS) += sysv/
94obj-$(CONFIG_CIFS) += cifs/ 94obj-$(CONFIG_CIFS) += cifs/
95obj-$(CONFIG_NCP_FS) += ncpfs/
96obj-$(CONFIG_HPFS_FS) += hpfs/ 95obj-$(CONFIG_HPFS_FS) += hpfs/
97obj-$(CONFIG_NTFS_FS) += ntfs/ 96obj-$(CONFIG_NTFS_FS) += ntfs/
98obj-$(CONFIG_UFS_FS) += ufs/ 97obj-$(CONFIG_UFS_FS) += ufs/
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index f12a61be1ede..11579fd4126e 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -578,8 +578,8 @@ const struct iio_chan_spec
578 * iio_device_register() - register a device with the IIO subsystem 578 * iio_device_register() - register a device with the IIO subsystem
579 * @indio_dev: Device structure filled by the device driver 579 * @indio_dev: Device structure filled by the device driver
580 **/ 580 **/
581#define iio_device_register(iio_dev) \ 581#define iio_device_register(indio_dev) \
582 __iio_device_register((iio_dev), THIS_MODULE) 582 __iio_device_register((indio_dev), THIS_MODULE)
583int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod); 583int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod);
584void iio_device_unregister(struct iio_dev *indio_dev); 584void iio_device_unregister(struct iio_dev *indio_dev);
585/** 585/**
diff --git a/include/linux/iio/machine.h b/include/linux/iio/machine.h
index 1601a2a63a72..5e1cfa75f652 100644
--- a/include/linux/iio/machine.h
+++ b/include/linux/iio/machine.h
@@ -28,4 +28,11 @@ struct iio_map {
28 void *consumer_data; 28 void *consumer_data;
29}; 29};
30 30
31#define IIO_MAP(_provider_channel, _consumer_dev_name, _consumer_channel) \
32{ \
33 .adc_channel_label = _provider_channel, \
34 .consumer_dev_name = _consumer_dev_name, \
35 .consumer_channel = _consumer_channel, \
36}
37
31#endif 38#endif
diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h
index 7d5e44518379..b19b7204ef84 100644
--- a/include/linux/iio/trigger.h
+++ b/include/linux/iio/trigger.h
@@ -43,12 +43,13 @@ struct iio_trigger_ops {
43/** 43/**
44 * struct iio_trigger - industrial I/O trigger device 44 * struct iio_trigger - industrial I/O trigger device
45 * @ops: [DRIVER] operations structure 45 * @ops: [DRIVER] operations structure
46 * @owner: [INTERN] owner of this driver module
46 * @id: [INTERN] unique id number 47 * @id: [INTERN] unique id number
47 * @name: [DRIVER] unique name 48 * @name: [DRIVER] unique name
48 * @dev: [DRIVER] associated device (if relevant) 49 * @dev: [DRIVER] associated device (if relevant)
49 * @list: [INTERN] used in maintenance of global trigger list 50 * @list: [INTERN] used in maintenance of global trigger list
50 * @alloc_list: [DRIVER] used for driver specific trigger list 51 * @alloc_list: [DRIVER] used for driver specific trigger list
51 * @use_count: use count for the trigger 52 * @use_count: [INTERN] use count for the trigger.
52 * @subirq_chip: [INTERN] associate 'virtual' irq chip. 53 * @subirq_chip: [INTERN] associate 'virtual' irq chip.
53 * @subirq_base: [INTERN] base number for irqs provided by trigger. 54 * @subirq_base: [INTERN] base number for irqs provided by trigger.
54 * @subirqs: [INTERN] information about the 'child' irqs. 55 * @subirqs: [INTERN] information about the 'child' irqs.
diff --git a/drivers/staging/unisys/include/visorbus.h b/include/linux/visorbus.h
index 1a0986ba3d24..0d8bd6769b13 100644
--- a/drivers/staging/unisys/include/visorbus.h
+++ b/include/linux/visorbus.h
@@ -1,17 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (C) 2010 - 2013 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
3 * All rights reserved. 4 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
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, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
14 * details.
15 */ 5 */
16 6
17/* 7/*
@@ -29,8 +19,172 @@
29 19
30#include <linux/device.h> 20#include <linux/device.h>
31 21
32#include "visorchannel.h" 22#define VISOR_CHANNEL_SIGNATURE ('L' << 24 | 'N' << 16 | 'C' << 8 | 'E')
23
24/*
25 * enum channel_serverstate
26 * @CHANNELSRV_UNINITIALIZED: Channel is in an undefined state.
27 * @CHANNELSRV_READY: Channel has been initialized by server.
28 */
29enum channel_serverstate {
30 CHANNELSRV_UNINITIALIZED = 0,
31 CHANNELSRV_READY = 1
32};
33
34/*
35 * enum channel_clientstate
36 * @CHANNELCLI_DETACHED:
37 * @CHANNELCLI_DISABLED: Client can see channel but is NOT allowed to use it
38 * unless given TBD* explicit request
39 * (should actually be < DETACHED).
40 * @CHANNELCLI_ATTACHING: Legacy EFI client request for EFI server to attach.
41 * @CHANNELCLI_ATTACHED: Idle, but client may want to use channel any time.
42 * @CHANNELCLI_BUSY: Client either wants to use or is using channel.
43 * @CHANNELCLI_OWNED: "No worries" state - client can access channel
44 * anytime.
45 */
46enum channel_clientstate {
47 CHANNELCLI_DETACHED = 0,
48 CHANNELCLI_DISABLED = 1,
49 CHANNELCLI_ATTACHING = 2,
50 CHANNELCLI_ATTACHED = 3,
51 CHANNELCLI_BUSY = 4,
52 CHANNELCLI_OWNED = 5
53};
54
55/*
56 * Values for VISOR_CHANNEL_PROTOCOL.Features: This define exists so that
57 * a guest can look at the FeatureFlags in the io channel, and configure the
58 * driver to use interrupts or not based on this setting. All feature bits for
59 * all channels should be defined here. The io channel feature bits are defined
60 * below.
61 */
62#define VISOR_DRIVER_ENABLES_INTS (0x1ULL << 1)
63#define VISOR_CHANNEL_IS_POLLING (0x1ULL << 3)
64#define VISOR_IOVM_OK_DRIVER_DISABLING_INTS (0x1ULL << 4)
65#define VISOR_DRIVER_DISABLES_INTS (0x1ULL << 5)
66#define VISOR_DRIVER_ENHANCED_RCVBUF_CHECKING (0x1ULL << 6)
67
68/*
69 * struct channel_header - Common Channel Header
70 * @signature: Signature.
71 * @legacy_state: DEPRECATED - being replaced by.
72 * @header_size: sizeof(struct channel_header).
73 * @size: Total size of this channel in bytes.
74 * @features: Flags to modify behavior.
75 * @chtype: Channel type: data, bus, control, etc..
76 * @partition_handle: ID of guest partition.
77 * @handle: Device number of this channel in client.
78 * @ch_space_offset: Offset in bytes to channel specific area.
79 * @version_id: Struct channel_header Version ID.
80 * @partition_index: Index of guest partition.
81 * @zone_uuid: Guid of Channel's zone.
82 * @cli_str_offset: Offset from channel header to null-terminated
83 * ClientString (0 if ClientString not present).
84 * @cli_state_boot: CHANNEL_CLIENTSTATE of pre-boot EFI client of this
85 * channel.
86 * @cmd_state_cli: CHANNEL_COMMANDSTATE (overloaded in Windows drivers, see
87 * ServerStateUp, ServerStateDown, etc).
88 * @cli_state_os: CHANNEL_CLIENTSTATE of Guest OS client of this channel.
89 * @ch_characteristic: CHANNEL_CHARACTERISTIC_<xxx>.
90 * @cmd_state_srv: CHANNEL_COMMANDSTATE (overloaded in Windows drivers, see
91 * ServerStateUp, ServerStateDown, etc).
92 * @srv_state: CHANNEL_SERVERSTATE.
93 * @cli_error_boot: Bits to indicate err states for boot clients, so err
94 * messages can be throttled.
95 * @cli_error_os: Bits to indicate err states for OS clients, so err
96 * messages can be throttled.
97 * @filler: Pad out to 128 byte cacheline.
98 * @recover_channel: Please add all new single-byte values below here.
99 */
100struct channel_header {
101 u64 signature;
102 u32 legacy_state;
103 /* SrvState, CliStateBoot, and CliStateOS below */
104 u32 header_size;
105 u64 size;
106 u64 features;
107 guid_t chtype;
108 u64 partition_handle;
109 u64 handle;
110 u64 ch_space_offset;
111 u32 version_id;
112 u32 partition_index;
113 guid_t zone_guid;
114 u32 cli_str_offset;
115 u32 cli_state_boot;
116 u32 cmd_state_cli;
117 u32 cli_state_os;
118 u32 ch_characteristic;
119 u32 cmd_state_srv;
120 u32 srv_state;
121 u8 cli_error_boot;
122 u8 cli_error_os;
123 u8 filler[1];
124 u8 recover_channel;
125} __packed;
126
127#define VISOR_CHANNEL_ENABLE_INTS (0x1ULL << 0)
128
129/*
130 * struct signal_queue_header - Subheader for the Signal Type variation of the
131 * Common Channel.
132 * @version: SIGNAL_QUEUE_HEADER Version ID.
133 * @chtype: Queue type: storage, network.
134 * @size: Total size of this queue in bytes.
135 * @sig_base_offset: Offset to signal queue area.
136 * @features: Flags to modify behavior.
137 * @num_sent: Total # of signals placed in this queue.
138 * @num_overflows: Total # of inserts failed due to full queue.
139 * @signal_size: Total size of a signal for this queue.
140 * @max_slots: Max # of slots in queue, 1 slot is always empty.
141 * @max_signals: Max # of signals in queue (MaxSignalSlots-1).
142 * @head: Queue head signal #.
143 * @num_received: Total # of signals removed from this queue.
144 * @tail: Queue tail signal.
145 * @reserved1: Reserved field.
146 * @reserved2: Reserved field.
147 * @client_queue:
148 * @num_irq_received: Total # of Interrupts received. This is incremented by the
149 * ISR in the guest windows driver.
150 * @num_empty: Number of times that visor_signal_remove is called and
151 * returned Empty Status.
152 * @errorflags: Error bits set during SignalReinit to denote trouble with
153 * client's fields.
154 * @filler: Pad out to 64 byte cacheline.
155 */
156struct signal_queue_header {
157 /* 1st cache line */
158 u32 version;
159 u32 chtype;
160 u64 size;
161 u64 sig_base_offset;
162 u64 features;
163 u64 num_sent;
164 u64 num_overflows;
165 u32 signal_size;
166 u32 max_slots;
167 u32 max_signals;
168 u32 head;
169 /* 2nd cache line */
170 u64 num_received;
171 u32 tail;
172 u32 reserved1;
173 u64 reserved2;
174 u64 client_queue;
175 u64 num_irq_received;
176 u64 num_empty;
177 u32 errorflags;
178 u8 filler[12];
179} __packed;
33 180
181/* VISORCHANNEL Guids */
182/* {414815ed-c58c-11da-95a9-00e08161165f} */
183#define VISOR_VHBA_CHANNEL_GUID \
184 GUID_INIT(0x414815ed, 0xc58c, 0x11da, \
185 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f)
186#define VISOR_VHBA_CHANNEL_GUID_STR \
187 "414815ed-c58c-11da-95a9-00e08161165f"
34struct visorchipset_state { 188struct visorchipset_state {
35 u32 created:1; 189 u32 created:1;
36 u32 attached:1; 190 u32 attached:1;
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 8dd2e66e8383..017044c26233 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3807,6 +3807,7 @@ int apply_workqueue_attrs(struct workqueue_struct *wq,
3807 3807
3808 return ret; 3808 return ret;
3809} 3809}
3810EXPORT_SYMBOL_GPL(apply_workqueue_attrs);
3810 3811
3811/** 3812/**
3812 * wq_update_unbound_numa - update NUMA affinity of a wq for CPU hot[un]plug 3813 * wq_update_unbound_numa - update NUMA affinity of a wq for CPU hot[un]plug
diff --git a/net/Kconfig b/net/Kconfig
index 37ec8e67af57..0428f12c25c2 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -213,7 +213,6 @@ source "net/dsa/Kconfig"
213source "net/8021q/Kconfig" 213source "net/8021q/Kconfig"
214source "net/decnet/Kconfig" 214source "net/decnet/Kconfig"
215source "net/llc/Kconfig" 215source "net/llc/Kconfig"
216source "net/ipx/Kconfig"
217source "drivers/net/appletalk/Kconfig" 216source "drivers/net/appletalk/Kconfig"
218source "net/x25/Kconfig" 217source "net/x25/Kconfig"
219source "net/lapb/Kconfig" 218source "net/lapb/Kconfig"
diff --git a/net/Makefile b/net/Makefile
index 14fede520840..a6147c61b174 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -24,7 +24,6 @@ obj-$(CONFIG_PACKET) += packet/
24obj-$(CONFIG_NET_KEY) += key/ 24obj-$(CONFIG_NET_KEY) += key/
25obj-$(CONFIG_BRIDGE) += bridge/ 25obj-$(CONFIG_BRIDGE) += bridge/
26obj-$(CONFIG_NET_DSA) += dsa/ 26obj-$(CONFIG_NET_DSA) += dsa/
27obj-$(CONFIG_IPX) += ipx/
28obj-$(CONFIG_ATALK) += appletalk/ 27obj-$(CONFIG_ATALK) += appletalk/
29obj-$(CONFIG_X25) += x25/ 28obj-$(CONFIG_X25) += x25/
30obj-$(CONFIG_LAPB) += lapb/ 29obj-$(CONFIG_LAPB) += lapb/