diff options
211 files changed, 6903 insertions, 5763 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-proximity b/Documentation/ABI/testing/sysfs-bus-iio-proximity new file mode 100644 index 000000000000..2172f3bb9c64 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-iio-proximity @@ -0,0 +1,10 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_proximity_nearlevel +Date: March 2020 +KernelVersion: 5.7 +Contact: linux-iio@vger.kernel.org +Description: + Near level for proximity sensors. This is a single integer + value that tells user space when an object should be + considered close to the device. If the value read from the + sensor is above or equal to the value in this file an object + should typically be considered near. diff --git a/Documentation/ABI/testing/sysfs-bus-iio-sx9310 b/Documentation/ABI/testing/sysfs-bus-iio-sx9310 new file mode 100644 index 000000000000..3ac7759013e5 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-iio-sx9310 @@ -0,0 +1,10 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_proximity3_comb_raw +Date: February 2019 +KernelVersion: 5.6 +Contact: Daniel Campello <campello@chromium.org> +Description: + Proximity measurement indicating that some object is + near the combined sensor. The combined sensor presents + proximity measurements constructed by hardware by + combining measurements taken from a given set of + physical sensors. diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad9467.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad9467.yaml new file mode 100644 index 000000000000..c4f57fa6aad1 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad9467.yaml @@ -0,0 +1,65 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ad9467.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD9467 High-Speed ADC + +maintainers: + - Michael Hennerich <michael.hennerich@analog.com> + - Alexandru Ardelean <alexandru.ardelean@analog.com> + +description: | + The AD9467 is a 16-bit, monolithic, IF sampling analog-to-digital + converter (ADC). + + https://www.analog.com/media/en/technical-documentation/data-sheets/AD9467.pdf + +properties: + compatible: + enum: + - adi,ad9467 + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: adc-clk + + powerdown-gpios: + description: + Pin that controls the powerdown mode of the device. + maxItems: 1 + + reset-gpios: + description: + Reset pin for the device. + maxItems: 1 + +required: + - compatible + - reg + - clocks + - clock-names + +additionalProperties: false + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + adc@0 { + compatible = "adi,ad9467"; + reg = <0>; + clocks = <&adc_clk>; + clock-names = "adc-clk"; + }; + }; +... diff --git a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml new file mode 100644 index 000000000000..0924b2b4972b --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,axi-adc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AXI ADC IP core + +maintainers: + - Michael Hennerich <michael.hennerich@analog.com> + - Alexandru Ardelean <alexandru.ardelean@analog.com> + +description: | + Analog Devices Generic AXI ADC IP core for interfacing an ADC device + with a high speed serial (JESD204B/C) or source synchronous parallel + interface (LVDS/CMOS). + Usually, some other interface type (i.e SPI) is used as a control + interface for the actual ADC, while this IP core will interface + to the data-lines of the ADC and handle the streaming of data into + memory via DMA. + + https://wiki.analog.com/resources/fpga/docs/axi_adc_ip + +properties: + compatible: + enum: + - adi,axi-adc-10.0.a + + reg: + maxItems: 1 + + dmas: + maxItems: 1 + + dma-names: + items: + - const: rx + + adi,adc-dev: + $ref: /schemas/types.yaml#/definitions/phandle + description: + A reference to a the actual ADC to which this FPGA ADC interfaces to. + +required: + - compatible + - dmas + - reg + - adi,adc-dev + +additionalProperties: false + +examples: + - | + axi-adc@44a00000 { + compatible = "adi,axi-adc-10.0.a"; + reg = <0x44a00000 0x10000>; + dmas = <&rx_dma 0>; + dma-names = "rx"; + + adi,adc-dev = <&spi_adc>; + }; +... diff --git a/Documentation/devicetree/bindings/iio/adc/maxim,max1241.yaml b/Documentation/devicetree/bindings/iio/adc/maxim,max1241.yaml new file mode 100644 index 000000000000..f562505f5ecd --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/maxim,max1241.yaml @@ -0,0 +1,63 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2020 Alexandru Lazar +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/maxim,max1241.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim MAX1241 12-bit, single-channel analog to digital converter + +maintainers: + - Alexandru Lazar <alazar@startmail.com> + +description: | + Bindings for the max1241 12-bit, single-channel ADC device. Datasheet + can be found at: + https://datasheets.maximintegrated.com/en/ds/MAX1240-MAX1241.pdf + +properties: + compatible: + enum: + - maxim,max1241 + + reg: + maxItems: 1 + + vdd-supply: + description: + Device tree identifier of the regulator that powers the ADC. + + vref-supply: + description: + Device tree identifier of the regulator that provides the external + reference voltage. + + shutdown-gpios: + description: + GPIO spec for the GPIO pin connected to the ADC's /SHDN pin. If + specified, the /SHDN pin will be asserted between conversions, + thus enabling power-down mode. + maxItems: 1 + +required: + - compatible + - reg + - vdd-supply + - vref-supply + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + adc@0 { + compatible = "maxim,max1241"; + reg = <0>; + vdd-supply = <&adc_vdd>; + vref-supply = <&adc_vref>; + spi-max-frequency = <1000000>; + shutdown-gpios = <&gpio 26 1>; + }; + }; diff --git a/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt b/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt deleted file mode 100644 index c2c50b59873d..000000000000 --- a/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt +++ /dev/null @@ -1,37 +0,0 @@ -Rockchip Successive Approximation Register (SAR) A/D Converter bindings - -Required properties: -- compatible: should be "rockchip,<name>-saradc" or "rockchip,rk3066-tsadc" - - "rockchip,saradc": for rk3188, rk3288 - - "rockchip,rk3066-tsadc": for rk3036 - - "rockchip,rk3328-saradc", "rockchip,rk3399-saradc": for rk3328 - - "rockchip,rk3399-saradc": for rk3399 - - "rockchip,rv1108-saradc", "rockchip,rk3399-saradc": for rv1108 - -- reg: physical base address of the controller and length of memory mapped - region. -- interrupts: The interrupt number to the cpu. The interrupt specifier format - depends on the interrupt controller. -- clocks: Must contain an entry for each entry in clock-names. -- clock-names: Shall be "saradc" for the converter-clock, and "apb_pclk" for - the peripheral clock. -- vref-supply: The regulator supply ADC reference voltage. -- #io-channel-cells: Should be 1, see ../iio-bindings.txt - -Optional properties: -- resets: Must contain an entry for each entry in reset-names if need support - this option. See ../reset/reset.txt for details. -- reset-names: Must include the name "saradc-apb". - -Example: - saradc: saradc@2006c000 { - compatible = "rockchip,saradc"; - reg = <0x2006c000 0x100>; - interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>; - clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>; - clock-names = "saradc", "apb_pclk"; - resets = <&cru SRST_SARADC>; - reset-names = "saradc-apb"; - #io-channel-cells = <1>; - vref-supply = <&vcc18>; - }; diff --git a/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml b/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml new file mode 100644 index 000000000000..bcff82a423bc --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml @@ -0,0 +1,80 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/rockchip-saradc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Rockchip Successive Approximation Register (SAR) A/D Converter + +maintainers: + - Heiko Stuebner <heiko@sntech.de> + +properties: + compatible: + oneOf: + - const: rockchip,saradc + - const: rockchip,rk3066-tsadc + - const: rockchip,rk3399-saradc + - items: + - enum: + - rockchip,px30-saradc + - rockchip,rk3308-saradc + - rockchip,rk3328-saradc + - rockchip,rv1108-saradc + - const: rockchip,rk3399-saradc + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + items: + - description: converter clock + - description: peripheral clock + + clock-names: + items: + - const: saradc + - const: apb_pclk + + resets: + maxItems: 1 + + reset-names: + const: saradc-apb + + vref-supply: + description: + The regulator supply for the ADC reference voltage. + + "#io-channel-cells": + const: 1 + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + - vref-supply + - "#io-channel-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/rk3288-cru.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + saradc: saradc@2006c000 { + compatible = "rockchip,saradc"; + reg = <0x2006c000 0x100>; + interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>; + clock-names = "saradc", "apb_pclk"; + resets = <&cru SRST_SARADC>; + reset-names = "saradc-apb"; + vref-supply = <&vcc18>; + #io-channel-cells = <1>; + }; diff --git a/Documentation/devicetree/bindings/iio/common.yaml b/Documentation/devicetree/bindings/iio/common.yaml new file mode 100644 index 000000000000..97ffcb77043d --- /dev/null +++ b/Documentation/devicetree/bindings/iio/common.yaml @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/common.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Common properties for iio sensors + +maintainers: + - Jonathan Cameron <jic23@kernel.org> + - Guido Günther <agx@sigxcpu.org> + +description: | + This document defines device tree properties common to several iio + sensors. It doesn't constitue a device tree binding specification by itself but + is meant to be referenced by device tree bindings. + + When referenced from sensor tree bindings the properties defined in this + document are defined as follows. The sensor tree bindings are responsible for + defining whether each property is required or optional. + +properties: + proximity-near-level: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + For proximity sensors whether an object can be considered near to the + device depends on parameters like sensor position, covering glass and + aperture. This value gives an indication to userspace for which + sensor readings this is the case. + + Raw proximity values equal or above this level should be + considered 'near' to the device (an object is near to the + sensor). + +... diff --git a/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt b/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt deleted file mode 100644 index bf2925c671c6..000000000000 --- a/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt +++ /dev/null @@ -1,63 +0,0 @@ -STMicroelectronics STM32 DAC - -The STM32 DAC is a 12-bit voltage output digital-to-analog converter. The DAC -may be configured in 8 or 12-bit mode. It has two output channels, each with -its own converter. -It has built-in noise and triangle waveform generator and supports external -triggers for conversions. The DAC's output buffer allows a high drive output -current. - -Contents of a stm32 dac root node: ------------------------------------ -Required properties: -- compatible: Should be one of: - "st,stm32f4-dac-core" - "st,stm32h7-dac-core" -- reg: Offset and length of the device's register set. -- clocks: Must contain an entry for pclk (which feeds the peripheral bus - interface) -- clock-names: Must be "pclk". -- vref-supply: Phandle to the vref+ input analog reference supply. -- #address-cells = <1>; -- #size-cells = <0>; - -Optional properties: -- resets: Must contain the phandle to the reset controller. -- A pinctrl state named "default" for each DAC channel may be defined to set - DAC_OUTx pin in mode of operation for analog output on external pin. - -Contents of a stm32 dac child node: ------------------------------------ -DAC core node should contain at least one subnode, representing a -DAC instance/channel available on the machine. - -Required properties: -- compatible: Must be "st,stm32-dac". -- reg: Must be either 1 or 2, to define (single) channel in use -- #io-channel-cells = <1>: See the IIO bindings section "IIO consumers" in - Documentation/devicetree/bindings/iio/iio-bindings.txt - -Example: - dac: dac@40007400 { - compatible = "st,stm32h7-dac-core"; - reg = <0x40007400 0x400>; - clocks = <&clk>; - clock-names = "pclk"; - vref-supply = <®_vref>; - pinctrl-names = "default"; - pinctrl-0 = <&dac_out1 &dac_out2>; - #address-cells = <1>; - #size-cells = <0>; - - dac1: dac@1 { - compatible = "st,stm32-dac"; - #io-channels-cells = <1>; - reg = <1>; - }; - - dac2: dac@2 { - compatible = "st,stm32-dac"; - #io-channels-cells = <1>; - reg = <2>; - }; - }; diff --git a/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.yaml b/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.yaml new file mode 100644 index 000000000000..393f7005941a --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.yaml @@ -0,0 +1,110 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/iio/dac/st,stm32-dac.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: STMicroelectronics STM32 DAC bindings + +description: | + The STM32 DAC is a 12-bit voltage output digital-to-analog converter. The DAC + may be configured in 8 or 12-bit mode. It has two output channels, each with + its own converter. + It has built-in noise and triangle waveform generator and supports external + triggers for conversions. The DAC's output buffer allows a high drive output + current. + +maintainers: + - Fabrice Gasnier <fabrice.gasnier@st.com> + +properties: + compatible: + enum: + - st,stm32f4-dac-core + - st,stm32h7-dac-core + + reg: + maxItems: 1 + + resets: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: pclk + + vref-supply: + description: Phandle to the vref input analog reference voltage. + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +additionalProperties: false + +required: + - compatible + - reg + - clocks + - clock-names + - vref-supply + - '#address-cells' + - '#size-cells' + +patternProperties: + "^dac@[1-2]+$": + type: object + description: + A DAC block node should contain at least one subnode, representing an + DAC instance/channel available on the machine. + + properties: + compatible: + const: st,stm32-dac + + reg: + description: Must be either 1 or 2, to define (single) channel in use + enum: [1, 2] + + '#io-channel-cells': + const: 1 + + additionalProperties: false + + required: + - compatible + - reg + - '#io-channel-cells' + +examples: + - | + // Example on stm32mp157c + #include <dt-bindings/clock/stm32mp1-clks.h> + dac: dac@40017000 { + compatible = "st,stm32h7-dac-core"; + reg = <0x40017000 0x400>; + clocks = <&rcc DAC12>; + clock-names = "pclk"; + vref-supply = <&vref>; + #address-cells = <1>; + #size-cells = <0>; + + dac@1 { + compatible = "st,stm32-dac"; + #io-channel-cells = <1>; + reg = <1>; + }; + + dac@2 { + compatible = "st,stm32-dac"; + #io-channel-cells = <1>; + reg = <2>; + }; + }; + +... diff --git a/Documentation/devicetree/bindings/iio/gyroscope/bmg160.txt b/Documentation/devicetree/bindings/iio/gyroscope/bmg160.txt index 78e18a1e9c1d..bb43d1ad9c9f 100644 --- a/Documentation/devicetree/bindings/iio/gyroscope/bmg160.txt +++ b/Documentation/devicetree/bindings/iio/gyroscope/bmg160.txt @@ -2,7 +2,7 @@ Required properties: - - compatible : should be "bosch,bmg160" or "bosch,bmi055_gyro" + - compatible : should be "bosch,bmg160", "bosch,bmi055_gyro" or "bosch,bmi088_gyro" - reg : the I2C address of the sensor (0x69) Optional properties: diff --git a/Documentation/devicetree/bindings/iio/light/amstaos,tsl2563.yaml b/Documentation/devicetree/bindings/iio/light/amstaos,tsl2563.yaml new file mode 100644 index 000000000000..efd2eba5f23c --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/amstaos,tsl2563.yaml @@ -0,0 +1,49 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/amstaos,tsl2563.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: AMS TAOS TSL2563 ambient light sensor + +maintainers: + - Sebastian Reichel <sre@kernel.org> + +description: | + Ambient light sensor with an i2c interface. + +properties: + compatible: + enum: + - amstaos,tsl2560 + - amstaos,tsl2561 + - amstaos,tsl2562 + - amstaos,tsl2563 + + reg: + maxItems: 1 + + amstaos,cover-comp-gain: + description: Multiplier for gain compensation + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [1, 16] + +required: + - compatible + - reg + +examples: + - | + i2c { + + #address-cells = <1>; + #size-cells = <0>; + + light-sensor@29 { + compatible = "amstaos,tsl2563"; + reg = <0x29>; + amstaos,cover-comp-gain = <16>; + }; + }; +... diff --git a/Documentation/devicetree/bindings/iio/light/tsl2563.txt b/Documentation/devicetree/bindings/iio/light/tsl2563.txt deleted file mode 100644 index f91e809e736e..000000000000 --- a/Documentation/devicetree/bindings/iio/light/tsl2563.txt +++ /dev/null @@ -1,19 +0,0 @@ -* AMS TAOS TSL2563 ambient light sensor - -Required properties: - - - compatible : should be "amstaos,tsl2563" - - reg : the I2C address of the sensor - -Optional properties: - - - amstaos,cover-comp-gain : integer used as multiplier for gain - compensation (default = 1) - -Example: - -tsl2563@29 { - compatible = "amstaos,tsl2563"; - reg = <0x29>; - amstaos,cover-comp-gain = <16>; -}; diff --git a/Documentation/devicetree/bindings/iio/light/vcnl4000.txt b/Documentation/devicetree/bindings/iio/light/vcnl4000.txt deleted file mode 100644 index 955af4555c90..000000000000 --- a/Documentation/devicetree/bindings/iio/light/vcnl4000.txt +++ /dev/null @@ -1,24 +0,0 @@ -VISHAY VCNL4000 - Ambient Light and proximity sensor - -This driver supports the VCNL4000/10/20/40 and VCNL4200 chips - -Required properties: - - -compatible: must be one of : - vishay,vcnl4000 - vishay,vcnl4010 - vishay,vcnl4020 - vishay,vcnl4040 - vishay,vcnl4200 - - -reg: I2C address of the sensor, should be one from below based on the model: - 0x13 - 0x51 - 0x60 - -Example: - -light-sensor@51 { - compatible = "vishay,vcnl4200"; - reg = <0x51>; -}; diff --git a/Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml b/Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml new file mode 100644 index 000000000000..da8f2e872535 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml @@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/vishay,vcnl4000.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: VISHAY VCNL4000 ambient light and proximity sensor + +maintainers: + - Peter Meerwald <pmeerw@pmeerw.net> + +description: | + Ambient light sensing with proximity detection over an i2c + interface. + +allOf: + - $ref: ../common.yaml# + +properties: + compatible: + enum: + - vishay,vcnl4000 + - vishay,vcnl4010 + - vishay,vcnl4020 + - vishay,vcnl4040 + - vishay,vcnl4200 + reg: + maxItems: 1 + + proximity-near-level: true + +required: + - compatible + - reg + +additionalProperties: false + +examples: +- | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + light-sensor@51 { + compatible = "vishay,vcnl4200"; + reg = <0x51>; + proximity-near-level = <220>; + }; + }; +... diff --git a/Documentation/devicetree/bindings/iio/st-sensors.txt b/Documentation/devicetree/bindings/iio/st-sensors.txt index 0ef64a444479..3213599c5071 100644 --- a/Documentation/devicetree/bindings/iio/st-sensors.txt +++ b/Documentation/devicetree/bindings/iio/st-sensors.txt @@ -50,6 +50,7 @@ Accelerometers: - st,lis3dhh - st,lis3de - st,lis2de12 +- st,lis2hh12 Gyroscopes: - st,l3g4200d-gyro diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst index 46c13780994c..91b0b8e5556c 100644 --- a/Documentation/driver-api/driver-model/devres.rst +++ b/Documentation/driver-api/driver-model/devres.rst @@ -284,21 +284,13 @@ I2C IIO devm_iio_device_alloc() - devm_iio_device_free() devm_iio_device_register() - devm_iio_device_unregister() devm_iio_kfifo_allocate() - devm_iio_kfifo_free() devm_iio_triggered_buffer_setup() - devm_iio_triggered_buffer_cleanup() devm_iio_trigger_alloc() - devm_iio_trigger_free() devm_iio_trigger_register() - devm_iio_trigger_unregister() devm_iio_channel_get() - devm_iio_channel_release() devm_iio_channel_get_all() - devm_iio_channel_release_all() INPUT devm_input_allocate_device() diff --git a/Documentation/driver-api/iio/triggers.rst b/Documentation/driver-api/iio/triggers.rst index 5c2156de6284..dfd7ba3eabde 100644 --- a/Documentation/driver-api/iio/triggers.rst +++ b/Documentation/driver-api/iio/triggers.rst @@ -4,9 +4,7 @@ Triggers * struct :c:type:`iio_trigger` — industrial I/O trigger device * :c:func:`devm_iio_trigger_alloc` — Resource-managed iio_trigger_alloc -* :c:func:`devm_iio_trigger_free` — Resource-managed iio_trigger_free * :c:func:`devm_iio_trigger_register` — Resource-managed iio_trigger_register -* :c:func:`devm_iio_trigger_unregister` — Resource-managed iio_trigger_unregister * :c:func:`iio_trigger_validate_own_device` — Check if a trigger and IIO device belong to the same device diff --git a/MAINTAINERS b/MAINTAINERS index 26f281d9f32a..fc884fa245f0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -294,6 +294,7 @@ F: drivers/gpio/gpio-104-idio-16.c ACCES 104-QUAD-8 DRIVER M: William Breathitt Gray <vilhelm.gray@gmail.com> +M: Syed Nayyar Waris <syednwaris@gmail.com> L: linux-iio@vger.kernel.org S: Maintained F: Documentation/ABI/testing/sysfs-bus-counter-104-quad-8 @@ -7036,6 +7037,7 @@ GASKET DRIVER FRAMEWORK M: Rob Springer <rspringer@google.com> M: Todd Poynor <toddpoynor@google.com> M: Ben Chan <benchan@chromium.org> +M: Richard Yeh <rcy@google.com> S: Maintained F: drivers/staging/gasket/ diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index 5d91a6dda894..24ebe9e76915 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -238,7 +238,7 @@ config IIO_ST_ACCEL_3AXIS Say yes here to build support for STMicroelectronics accelerometers: LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC, LIS331DLH, LSM303DL, LSM303DLM, LSM330, LIS2DH12, H3LIS331DL, - LNG2DM, LIS3DE, LIS2DE12 + LNG2DM, LIS3DE, LIS2DE12, LIS2HH12 This driver can also be built as a module. If so, these modules will be created: diff --git a/drivers/iio/accel/kxsd9-i2c.c b/drivers/iio/accel/kxsd9-i2c.c index 38411e1c155b..b6f3de7ef8ea 100644 --- a/drivers/iio/accel/kxsd9-i2c.c +++ b/drivers/iio/accel/kxsd9-i2c.c @@ -21,8 +21,8 @@ static int kxsd9_i2c_probe(struct i2c_client *i2c, regmap = devm_regmap_init_i2c(i2c, &config); if (IS_ERR(regmap)) { - dev_err(&i2c->dev, "Failed to register i2c regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&i2c->dev, "Failed to register i2c regmap: %pe\n", + regmap); return PTR_ERR(regmap); } diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c index 3d5bea651923..9d07642c0de1 100644 --- a/drivers/iio/accel/mxc4005.c +++ b/drivers/iio/accel/mxc4005.c @@ -135,7 +135,7 @@ static int mxc4005_read_xyz(struct mxc4005_data *data) int ret; ret = regmap_bulk_read(data->regmap, MXC4005_REG_XOUT_UPPER, - (u8 *) data->buffer, sizeof(data->buffer)); + data->buffer, sizeof(data->buffer)); if (ret < 0) { dev_err(data->dev, "failed to read axes\n"); return ret; @@ -150,7 +150,7 @@ static int mxc4005_read_axis(struct mxc4005_data *data, __be16 reg; int ret; - ret = regmap_bulk_read(data->regmap, addr, (u8 *) ®, sizeof(reg)); + ret = regmap_bulk_read(data->regmap, addr, ®, sizeof(reg)); if (ret < 0) { dev_err(data->dev, "failed to read reg %02x\n", addr); return ret; diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h index 5b13e293cade..5d356288e001 100644 --- a/drivers/iio/accel/st_accel.h +++ b/drivers/iio/accel/st_accel.h @@ -35,6 +35,7 @@ enum st_accel_type { LIS2DW12, LIS3DHH, LIS2DE12, + LIS2HH12, ST_ACCEL_MAX, }; @@ -59,6 +60,7 @@ enum st_accel_type { #define LIS3DHH_ACCEL_DEV_NAME "lis3dhh" #define LIS3DE_ACCEL_DEV_NAME "lis3de" #define LIS2DE12_ACCEL_DEV_NAME "lis2de12" +#define LIS2HH12_ACCEL_DEV_NAME "lis2hh12" /** * struct st_sensors_platform_data - default accel platform data diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c index 9f2b40474b8e..b5c814ef1637 100644 --- a/drivers/iio/accel/st_accel_buffer.c +++ b/drivers/iio/accel/st_accel_buffer.c @@ -37,8 +37,7 @@ static int st_accel_buffer_postenable(struct iio_dev *indio_dev) if (err < 0) return err; - err = st_sensors_set_axis_enable(indio_dev, - (u8)indio_dev->active_scan_mask[0]); + err = st_sensors_set_axis_enable(indio_dev, indio_dev->active_scan_mask[0]); if (err < 0) goto st_accel_buffer_predisable; diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index 7320275c7e56..43c50167d220 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -904,6 +904,83 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { .multi_read_bit = true, .bootime = 2, }, + { + .wai = 0x41, + .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, + .sensors_supported = { + [0] = LIS2HH12_ACCEL_DEV_NAME, + }, + .ch = (struct iio_chan_spec *)st_accel_16bit_channels, + .odr = { + .addr = 0x20, + .mask = 0x70, + .odr_avl = { + { .hz = 10, .value = 0x01, }, + { .hz = 50, .value = 0x02, }, + { .hz = 100, .value = 0x03, }, + { .hz = 200, .value = 0x04, }, + { .hz = 400, .value = 0x05, }, + { .hz = 800, .value = 0x06, }, + }, + }, + .pw = { + .addr = 0x20, + .mask = 0x70, + .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, + }, + .enable_axis = { + .addr = ST_SENSORS_DEFAULT_AXIS_ADDR, + .mask = ST_SENSORS_DEFAULT_AXIS_MASK, + }, + .fs = { + .addr = 0x23, + .mask = 0x30, + .fs_avl = { + [0] = { + .num = ST_ACCEL_FS_AVL_2G, + .value = 0x00, + .gain = IIO_G_TO_M_S_2(61), + }, + [1] = { + .num = ST_ACCEL_FS_AVL_4G, + .value = 0x02, + .gain = IIO_G_TO_M_S_2(122), + }, + [2] = { + .num = ST_ACCEL_FS_AVL_8G, + .value = 0x03, + .gain = IIO_G_TO_M_S_2(244), + }, + }, + }, + .bdu = { + .addr = 0x20, + .mask = 0x08, + }, + .drdy_irq = { + .int1 = { + .addr = 0x22, + .mask = 0x01, + }, + .int2 = { + .addr = 0x25, + .mask = 0x01, + }, + .addr_ihl = 0x24, + .mask_ihl = 0x02, + .stat_drdy = { + .addr = ST_SENSORS_DEFAULT_STAT_ADDR, + .mask = 0x07, + }, + }, + .sim = { + .addr = 0x23, + .value = BIT(0), + }, + .multi_read_bit = true, + .bootime = 2, + }, + }; static int st_accel_read_raw(struct iio_dev *indio_dev, @@ -1170,8 +1247,7 @@ EXPORT_SYMBOL(st_accel_get_settings); int st_accel_common_probe(struct iio_dev *indio_dev) { struct st_sensor_data *adata = iio_priv(indio_dev); - struct st_sensors_platform_data *pdata = - (struct st_sensors_platform_data *)adata->dev->platform_data; + struct st_sensors_platform_data *pdata = dev_get_platdata(adata->dev); struct iio_chan_spec *channels; size_t channels_size; int err; @@ -1204,8 +1280,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev) "failed to apply ACPI orientation data: %d\n", err); indio_dev->channels = channels; - adata->current_fullscale = (struct st_sensor_fullscale_avl *) - &adata->sensor_settings->fs.fs_avl[0]; + adata->current_fullscale = &adata->sensor_settings->fs.fs_avl[0]; adata->odr = adata->sensor_settings->odr.odr_avl[0].hz; if (!pdata) diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c index 6b283be26ebc..360e16f2cadb 100644 --- a/drivers/iio/accel/st_accel_i2c.c +++ b/drivers/iio/accel/st_accel_i2c.c @@ -104,6 +104,10 @@ static const struct of_device_id st_accel_of_match[] = { .compatible = "st,lis2de12", .data = LIS2DE12_ACCEL_DEV_NAME, }, + { + .compatible = "st,lis2hh12", + .data = LIS2HH12_ACCEL_DEV_NAME, + }, {}, }; MODULE_DEVICE_TABLE(of, st_accel_of_match); @@ -138,6 +142,7 @@ static const struct i2c_device_id st_accel_id_table[] = { { LIS2DW12_ACCEL_DEV_NAME }, { LIS3DE_ACCEL_DEV_NAME }, { LIS2DE12_ACCEL_DEV_NAME }, + { LIS2HH12_ACCEL_DEV_NAME }, {}, }; MODULE_DEVICE_TABLE(i2c, st_accel_id_table); diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 12bb8b7ca1ff..c48c00077775 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -246,6 +246,41 @@ config AD799X To compile this driver as a module, choose M here: the module will be called ad799x. +config AD9467 + tristate "Analog Devices AD9467 High Speed ADC driver" + depends on SPI + select ADI_AXI_ADC + help + Say yes here to build support for Analog Devices: + * AD9467 16-Bit, 200 MSPS/250 MSPS Analog-to-Digital Converter + + The driver requires the assistance of the AXI ADC IP core to operate, + since SPI is used for configuration only, while data has to be + streamed into memory via DMA. + + To compile this driver as a module, choose M here: the module will be + called ad9467. + +config ADI_AXI_ADC + tristate "Analog Devices Generic AXI ADC IP core driver" + select IIO_BUFFER + select IIO_BUFFER_HW_CONSUMER + select IIO_BUFFER_DMAENGINE + help + Say yes here to build support for Analog Devices Generic + AXI ADC IP core. The IP core is used for interfacing with + analog-to-digital (ADC) converters that require either a high-speed + serial interface (JESD204B/C) or a source synchronous parallel + interface (LVDS/CMOS). + Typically (for such devices) SPI will be used for configuration only, + while this IP core handles the streaming of data into memory via DMA. + + Link: https://wiki.analog.com/resources/fpga/docs/axi_adc_ip + If unsure, say N (but it's safe to say "Y"). + + To compile this driver as a module, choose M here: the + module will be called adi-axi-adc. + config ASPEED_ADC tristate "Aspeed ADC" depends on ARCH_ASPEED || COMPILE_TEST @@ -595,6 +630,16 @@ config MAX1118 To compile this driver as a module, choose M here: the module will be called max1118. +config MAX1241 + tristate "Maxim max1241 ADC driver" + depends on SPI_MASTER + help + Say yes here to build support for Maxim max1241 12-bit, single-channel + ADC. + + To compile this driver as a module, choose M here: the module will be + called max1241. + config MAX1363 tristate "Maxim max1363 ADC driver" depends on I2C diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 637807861112..2f5bc224412b 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -26,6 +26,8 @@ obj-$(CONFIG_AD7793) += ad7793.o obj-$(CONFIG_AD7887) += ad7887.o obj-$(CONFIG_AD7949) += ad7949.o obj-$(CONFIG_AD799X) += ad799x.o +obj-$(CONFIG_AD9467) += ad9467.o +obj-$(CONFIG_ADI_AXI_ADC) += adi-axi-adc.o obj-$(CONFIG_ASPEED_ADC) += aspeed_adc.o obj-$(CONFIG_AT91_ADC) += at91_adc.o obj-$(CONFIG_AT91_SAMA5D2_ADC) += at91-sama5d2_adc.o @@ -57,6 +59,7 @@ obj-$(CONFIG_LTC2497) += ltc2497.o ltc2497-core.o obj-$(CONFIG_MAX1027) += max1027.o obj-$(CONFIG_MAX11100) += max11100.o obj-$(CONFIG_MAX1118) += max1118.o +obj-$(CONFIG_MAX1241) += max1241.o obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_MAX9611) += max9611.o obj-$(CONFIG_MCP320X) += mcp320x.o diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c index 76747488044b..e9984a38fc4c 100644 --- a/drivers/iio/adc/ad7476.c +++ b/drivers/iio/adc/ad7476.c @@ -12,9 +12,11 @@ #include <linux/sysfs.h> #include <linux/spi/spi.h> #include <linux/regulator/consumer.h> +#include <linux/gpio/consumer.h> #include <linux/err.h> #include <linux/module.h> #include <linux/bitops.h> +#include <linux/delay.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> @@ -27,6 +29,8 @@ struct ad7476_state; struct ad7476_chip_info { unsigned int int_vref_uv; struct iio_chan_spec channel[2]; + /* channels used when convst gpio is defined */ + struct iio_chan_spec convst_channel[2]; void (*reset)(struct ad7476_state *); }; @@ -34,6 +38,7 @@ struct ad7476_state { struct spi_device *spi; const struct ad7476_chip_info *chip_info; struct regulator *reg; + struct gpio_desc *convst_gpio; struct spi_transfer xfer; struct spi_message msg; /* @@ -64,6 +69,17 @@ enum ad7476_supported_device_ids { ID_ADS7868, }; +static void ad7091_convst(struct ad7476_state *st) +{ + if (!st->convst_gpio) + return; + + gpiod_set_value(st->convst_gpio, 0); + udelay(1); /* CONVST pulse width: 10 ns min */ + gpiod_set_value(st->convst_gpio, 1); + udelay(1); /* Conversion time: 650 ns max */ +} + static irqreturn_t ad7476_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; @@ -71,6 +87,8 @@ static irqreturn_t ad7476_trigger_handler(int irq, void *p) struct ad7476_state *st = iio_priv(indio_dev); int b_sent; + ad7091_convst(st); + b_sent = spi_sync(st->spi, &st->msg); if (b_sent < 0) goto done; @@ -93,6 +111,8 @@ static int ad7476_scan_direct(struct ad7476_state *st) { int ret; + ad7091_convst(st); + ret = spi_sync(st->spi, &st->msg); if (ret) return ret; @@ -160,6 +180,8 @@ static int ad7476_read_raw(struct iio_dev *indio_dev, #define AD7940_CHAN(bits) _AD7476_CHAN((bits), 15 - (bits), \ BIT(IIO_CHAN_INFO_RAW)) #define AD7091R_CHAN(bits) _AD7476_CHAN((bits), 16 - (bits), 0) +#define AD7091R_CONVST_CHAN(bits) _AD7476_CHAN((bits), 16 - (bits), \ + BIT(IIO_CHAN_INFO_RAW)) #define ADS786X_CHAN(bits) _AD7476_CHAN((bits), 12 - (bits), \ BIT(IIO_CHAN_INFO_RAW)) @@ -167,6 +189,8 @@ static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { [ID_AD7091R] = { .channel[0] = AD7091R_CHAN(12), .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), + .convst_channel[0] = AD7091R_CONVST_CHAN(12), + .convst_channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), .reset = ad7091_reset, }, [ID_AD7276] = { @@ -232,6 +256,13 @@ static const struct iio_info ad7476_info = { .read_raw = &ad7476_read_raw, }; +static void ad7476_reg_disable(void *data) +{ + struct ad7476_state *st = data; + + regulator_disable(st->reg); +} + static int ad7476_probe(struct spi_device *spi) { struct ad7476_state *st; @@ -254,6 +285,17 @@ static int ad7476_probe(struct spi_device *spi) if (ret) return ret; + ret = devm_add_action_or_reset(&spi->dev, ad7476_reg_disable, + st); + if (ret) + return ret; + + st->convst_gpio = devm_gpiod_get_optional(&spi->dev, + "adi,conversion-start", + GPIOD_OUT_LOW); + if (IS_ERR(st->convst_gpio)) + return PTR_ERR(st->convst_gpio); + spi_set_drvdata(spi, indio_dev); st->spi = spi; @@ -266,6 +308,9 @@ static int ad7476_probe(struct spi_device *spi) indio_dev->channels = st->chip_info->channel; indio_dev->num_channels = 2; indio_dev->info = &ad7476_info; + + if (st->convst_gpio && st->chip_info->convst_channel) + indio_dev->channels = st->chip_info->convst_channel; /* Setup default message */ st->xfer.rx_buf = &st->data; @@ -295,19 +340,8 @@ error_disable_reg: return ret; } -static int ad7476_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7476_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); - regulator_disable(st->reg); - - return 0; -} - static const struct spi_device_id ad7476_id[] = { + {"ad7091", ID_AD7091R}, {"ad7091r", ID_AD7091R}, {"ad7273", ID_AD7277}, {"ad7274", ID_AD7276}, @@ -343,7 +377,6 @@ static struct spi_driver ad7476_driver = { .name = "ad7476", }, .probe = ad7476_probe, - .remove = ad7476_remove, .id_table = ad7476_id, }; module_spi_driver(ad7476_driver); diff --git a/drivers/iio/adc/ad7780.c b/drivers/iio/adc/ad7780.c index 291c1a898129..f47606ebbbbe 100644 --- a/drivers/iio/adc/ad7780.c +++ b/drivers/iio/adc/ad7780.c @@ -206,10 +206,29 @@ static const struct ad_sigma_delta_info ad7780_sigma_delta_info = { .irq_flags = IRQF_TRIGGER_LOW, }; -#define AD7780_CHANNEL(bits, wordsize) \ - AD_SD_CHANNEL(1, 0, 0, bits, 32, (wordsize) - (bits)) -#define AD7170_CHANNEL(bits, wordsize) \ - AD_SD_CHANNEL_NO_SAMP_FREQ(1, 0, 0, bits, 32, (wordsize) - (bits)) +#define _AD7780_CHANNEL(_bits, _wordsize, _mask_all) \ +{ \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = 0, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_OFFSET), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all = _mask_all, \ + .scan_index = 1, \ + .scan_type = { \ + .sign = 'u', \ + .realbits = (_bits), \ + .storagebits = 32, \ + .shift = (_wordsize) - (_bits), \ + .endianness = IIO_BE, \ + }, \ +} + +#define AD7780_CHANNEL(_bits, _wordsize) \ + _AD7780_CHANNEL(_bits, _wordsize, BIT(IIO_CHAN_INFO_SAMP_FREQ)) +#define AD7170_CHANNEL(_bits, _wordsize) \ + _AD7780_CHANNEL(_bits, _wordsize, 0) static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { [ID_AD7170] = { diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c index abb239392631..48432b6f6002 100644 --- a/drivers/iio/adc/ad7791.c +++ b/drivers/iio/adc/ad7791.c @@ -64,25 +64,73 @@ #define AD7791_MODE_SEL_MASK (0x3 << 6) #define AD7791_MODE_SEL(x) ((x) << 6) +#define __AD7991_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift, _extend_name, _type, _mask_all) \ + { \ + .type = (_type), \ + .differential = (_channel2 == -1 ? 0 : 1), \ + .indexed = 1, \ + .channel = (_channel1), \ + .channel2 = (_channel2), \ + .address = (_address), \ + .extend_name = (_extend_name), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_OFFSET), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all = _mask_all, \ + .scan_index = (_si), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = (_bits), \ + .storagebits = (_storagebits), \ + .shift = (_shift), \ + .endianness = IIO_BE, \ + }, \ + } + +#define AD7991_SHORTED_CHANNEL(_si, _channel, _address, _bits, \ + _storagebits, _shift) \ + __AD7991_CHANNEL(_si, _channel, _channel, _address, _bits, \ + _storagebits, _shift, "shorted", IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7991_CHANNEL(_si, _channel, _address, _bits, \ + _storagebits, _shift) \ + __AD7991_CHANNEL(_si, _channel, -1, _address, _bits, \ + _storagebits, _shift, NULL, IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7991_DIFF_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift) \ + __AD7991_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift, NULL, IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7991_SUPPLY_CHANNEL(_si, _channel, _address, _bits, _storagebits, \ + _shift) \ + __AD7991_CHANNEL(_si, _channel, -1, _address, _bits, \ + _storagebits, _shift, "supply", IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + #define DECLARE_AD7787_CHANNELS(name, bits, storagebits) \ const struct iio_chan_spec name[] = { \ - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ + AD7991_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ (bits), (storagebits), 0), \ - AD_SD_CHANNEL(1, 1, AD7791_CH_AIN2, (bits), (storagebits), 0), \ - AD_SD_SHORTED_CHANNEL(2, 0, AD7791_CH_AIN1N_AIN1N, \ + AD7991_CHANNEL(1, 1, AD7791_CH_AIN2, (bits), (storagebits), 0), \ + AD7991_SHORTED_CHANNEL(2, 0, AD7791_CH_AIN1N_AIN1N, \ (bits), (storagebits), 0), \ - AD_SD_SUPPLY_CHANNEL(3, 2, AD7791_CH_AVDD_MONITOR, \ + AD7991_SUPPLY_CHANNEL(3, 2, AD7791_CH_AVDD_MONITOR, \ (bits), (storagebits), 0), \ IIO_CHAN_SOFT_TIMESTAMP(4), \ } #define DECLARE_AD7791_CHANNELS(name, bits, storagebits) \ const struct iio_chan_spec name[] = { \ - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ + AD7991_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ (bits), (storagebits), 0), \ - AD_SD_SHORTED_CHANNEL(1, 0, AD7791_CH_AIN1N_AIN1N, \ + AD7991_SHORTED_CHANNEL(1, 0, AD7791_CH_AIN1N_AIN1N, \ (bits), (storagebits), 0), \ - AD_SD_SUPPLY_CHANNEL(2, 1, AD7791_CH_AVDD_MONITOR, \ + AD7991_SUPPLY_CHANNEL(2, 1, AD7791_CH_AVDD_MONITOR, \ (bits), (storagebits), 0), \ IIO_CHAN_SOFT_TIMESTAMP(3), \ } @@ -444,5 +492,5 @@ static struct spi_driver ad7791_driver = { module_spi_driver(ad7791_driver); MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); -MODULE_DESCRIPTION("Analog Device AD7787/AD7788/AD7789/AD7790/AD7791 ADC driver"); +MODULE_DESCRIPTION("Analog Devices AD7787/AD7788/AD7789/AD7790/AD7791 ADC driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c index e5691e330323..808485f42415 100644 --- a/drivers/iio/adc/ad7793.c +++ b/drivers/iio/adc/ad7793.c @@ -354,29 +354,28 @@ static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( static IIO_CONST_ATTR_NAMED(sampling_frequency_available_ad7797, sampling_frequency_available, "123 62 50 33 17 16 12 10 8 6 4"); -static ssize_t ad7793_show_scale_available(struct device *dev, - struct device_attribute *attr, char *buf) +static int ad7793_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) { - struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ad7793_state *st = iio_priv(indio_dev); - int i, len = 0; - for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) - len += sprintf(buf + len, "%d.%09u ", st->scale_avail[i][0], - st->scale_avail[i][1]); - - len += sprintf(buf + len, "\n"); + switch (mask) { + case IIO_CHAN_INFO_SCALE: + *vals = (int *)st->scale_avail; + *type = IIO_VAL_INT_PLUS_NANO; + /* Values are stored in a 2D matrix */ + *length = ARRAY_SIZE(st->scale_avail) * 2; - return len; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } } -static IIO_DEVICE_ATTR_NAMED(in_m_in_scale_available, - in_voltage-voltage_scale_available, S_IRUGO, - ad7793_show_scale_available, NULL, 0); - static struct attribute *ad7793_attributes[] = { &iio_const_attr_sampling_frequency_available.dev_attr.attr, - &iio_dev_attr_in_m_in_scale_available.dev_attr.attr, NULL }; @@ -534,6 +533,7 @@ static const struct iio_info ad7793_info = { .read_raw = &ad7793_read_raw, .write_raw = &ad7793_write_raw, .write_raw_get_fmt = &ad7793_write_raw_get_fmt, + .read_avail = ad7793_read_avail, .attrs = &ad7793_attribute_group, .validate_trigger = ad_sd_validate_trigger, }; @@ -546,47 +546,113 @@ static const struct iio_info ad7797_info = { .validate_trigger = ad_sd_validate_trigger, }; +#define __AD7793_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift, _extend_name, _type, _mask_type_av, _mask_all) \ + { \ + .type = (_type), \ + .differential = (_channel2 == -1 ? 0 : 1), \ + .indexed = 1, \ + .channel = (_channel1), \ + .channel2 = (_channel2), \ + .address = (_address), \ + .extend_name = (_extend_name), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_OFFSET), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_type_available = (_mask_type_av), \ + .info_mask_shared_by_all = _mask_all, \ + .scan_index = (_si), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = (_bits), \ + .storagebits = (_storagebits), \ + .shift = (_shift), \ + .endianness = IIO_BE, \ + }, \ + } + +#define AD7793_DIFF_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift) \ + __AD7793_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift, NULL, IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SCALE), \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7793_SHORTED_CHANNEL(_si, _channel, _address, _bits, \ + _storagebits, _shift) \ + __AD7793_CHANNEL(_si, _channel, _channel, _address, _bits, \ + _storagebits, _shift, "shorted", IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SCALE), \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7793_TEMP_CHANNEL(_si, _address, _bits, _storagebits, _shift) \ + __AD7793_CHANNEL(_si, 0, -1, _address, _bits, \ + _storagebits, _shift, NULL, IIO_TEMP, \ + 0, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7793_SUPPLY_CHANNEL(_si, _channel, _address, _bits, _storagebits, \ + _shift) \ + __AD7793_CHANNEL(_si, _channel, -1, _address, _bits, \ + _storagebits, _shift, "supply", IIO_VOLTAGE, \ + 0, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7797_DIFF_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift) \ + __AD7793_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift, NULL, IIO_VOLTAGE, \ + 0, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7797_SHORTED_CHANNEL(_si, _channel, _address, _bits, \ + _storagebits, _shift) \ + __AD7793_CHANNEL(_si, _channel, _channel, _address, _bits, \ + _storagebits, _shift, "shorted", IIO_VOLTAGE, \ + 0, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + #define DECLARE_AD7793_CHANNELS(_name, _b, _sb, _s) \ const struct iio_chan_spec _name##_channels[] = { \ - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), (_s)), \ - AD_SD_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), (_s)), \ - AD_SD_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), (_s)), \ - AD_SD_SHORTED_CHANNEL(3, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), (_s)), \ - AD_SD_TEMP_CHANNEL(4, AD7793_CH_TEMP, (_b), (_sb), (_s)), \ - AD_SD_SUPPLY_CHANNEL(5, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), (_s)), \ + AD7793_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), (_s)), \ + AD7793_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), (_s)), \ + AD7793_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), (_s)), \ + AD7793_SHORTED_CHANNEL(3, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), (_s)), \ + AD7793_TEMP_CHANNEL(4, AD7793_CH_TEMP, (_b), (_sb), (_s)), \ + AD7793_SUPPLY_CHANNEL(5, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), (_s)), \ IIO_CHAN_SOFT_TIMESTAMP(6), \ } #define DECLARE_AD7795_CHANNELS(_name, _b, _sb) \ const struct iio_chan_spec _name##_channels[] = { \ - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(3, 3, 3, AD7795_CH_AIN4P_AIN4M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(4, 4, 4, AD7795_CH_AIN5P_AIN5M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(5, 5, 5, AD7795_CH_AIN6P_AIN6M, (_b), (_sb), 0), \ - AD_SD_SHORTED_CHANNEL(6, 0, AD7795_CH_AIN1M_AIN1M, (_b), (_sb), 0), \ - AD_SD_TEMP_CHANNEL(7, AD7793_CH_TEMP, (_b), (_sb), 0), \ - AD_SD_SUPPLY_CHANNEL(8, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \ + AD7793_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \ + AD7793_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), 0), \ + AD7793_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), 0), \ + AD7793_DIFF_CHANNEL(3, 3, 3, AD7795_CH_AIN4P_AIN4M, (_b), (_sb), 0), \ + AD7793_DIFF_CHANNEL(4, 4, 4, AD7795_CH_AIN5P_AIN5M, (_b), (_sb), 0), \ + AD7793_DIFF_CHANNEL(5, 5, 5, AD7795_CH_AIN6P_AIN6M, (_b), (_sb), 0), \ + AD7793_SHORTED_CHANNEL(6, 0, AD7795_CH_AIN1M_AIN1M, (_b), (_sb), 0), \ + AD7793_TEMP_CHANNEL(7, AD7793_CH_TEMP, (_b), (_sb), 0), \ + AD7793_SUPPLY_CHANNEL(8, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \ IIO_CHAN_SOFT_TIMESTAMP(9), \ } #define DECLARE_AD7797_CHANNELS(_name, _b, _sb) \ const struct iio_chan_spec _name##_channels[] = { \ - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \ - AD_SD_SHORTED_CHANNEL(1, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), 0), \ - AD_SD_TEMP_CHANNEL(2, AD7793_CH_TEMP, (_b), (_sb), 0), \ - AD_SD_SUPPLY_CHANNEL(3, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \ + AD7797_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \ + AD7797_SHORTED_CHANNEL(1, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), 0), \ + AD7793_TEMP_CHANNEL(2, AD7793_CH_TEMP, (_b), (_sb), 0), \ + AD7793_SUPPLY_CHANNEL(3, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \ IIO_CHAN_SOFT_TIMESTAMP(4), \ } #define DECLARE_AD7799_CHANNELS(_name, _b, _sb) \ const struct iio_chan_spec _name##_channels[] = { \ - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), 0), \ - AD_SD_SHORTED_CHANNEL(3, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), 0), \ - AD_SD_SUPPLY_CHANNEL(4, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \ + AD7793_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \ + AD7793_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), 0), \ + AD7793_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), 0), \ + AD7793_SHORTED_CHANNEL(3, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), 0), \ + AD7793_SUPPLY_CHANNEL(4, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \ IIO_CHAN_SOFT_TIMESTAMP(5), \ } diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c new file mode 100644 index 000000000000..1e8fd83b9bc2 --- /dev/null +++ b/drivers/iio/adc/ad9467.c @@ -0,0 +1,422 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Analog Devices AD9467 SPI ADC driver + * + * Copyright 2012-2020 Analog Devices Inc. + */ + +#include <linux/module.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/spi/spi.h> +#include <linux/err.h> +#include <linux/delay.h> +#include <linux/gpio/consumer.h> +#include <linux/of_device.h> + + +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> + +#include <linux/clk.h> + +#include <linux/iio/adc/adi-axi-adc.h> + +/* + * ADI High-Speed ADC common spi interface registers + * See Application-Note AN-877: + * https://www.analog.com/media/en/technical-documentation/application-notes/AN-877.pdf + */ + +#define AN877_ADC_REG_CHIP_PORT_CONF 0x00 +#define AN877_ADC_REG_CHIP_ID 0x01 +#define AN877_ADC_REG_CHIP_GRADE 0x02 +#define AN877_ADC_REG_CHAN_INDEX 0x05 +#define AN877_ADC_REG_TRANSFER 0xFF +#define AN877_ADC_REG_MODES 0x08 +#define AN877_ADC_REG_TEST_IO 0x0D +#define AN877_ADC_REG_ADC_INPUT 0x0F +#define AN877_ADC_REG_OFFSET 0x10 +#define AN877_ADC_REG_OUTPUT_MODE 0x14 +#define AN877_ADC_REG_OUTPUT_ADJUST 0x15 +#define AN877_ADC_REG_OUTPUT_PHASE 0x16 +#define AN877_ADC_REG_OUTPUT_DELAY 0x17 +#define AN877_ADC_REG_VREF 0x18 +#define AN877_ADC_REG_ANALOG_INPUT 0x2C + +/* AN877_ADC_REG_TEST_IO */ +#define AN877_ADC_TESTMODE_OFF 0x0 +#define AN877_ADC_TESTMODE_MIDSCALE_SHORT 0x1 +#define AN877_ADC_TESTMODE_POS_FULLSCALE 0x2 +#define AN877_ADC_TESTMODE_NEG_FULLSCALE 0x3 +#define AN877_ADC_TESTMODE_ALT_CHECKERBOARD 0x4 +#define AN877_ADC_TESTMODE_PN23_SEQ 0x5 +#define AN877_ADC_TESTMODE_PN9_SEQ 0x6 +#define AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE 0x7 +#define AN877_ADC_TESTMODE_USER 0x8 +#define AN877_ADC_TESTMODE_BIT_TOGGLE 0x9 +#define AN877_ADC_TESTMODE_SYNC 0xA +#define AN877_ADC_TESTMODE_ONE_BIT_HIGH 0xB +#define AN877_ADC_TESTMODE_MIXED_BIT_FREQUENCY 0xC +#define AN877_ADC_TESTMODE_RAMP 0xF + +/* AN877_ADC_REG_TRANSFER */ +#define AN877_ADC_TRANSFER_SYNC 0x1 + +/* AN877_ADC_REG_OUTPUT_MODE */ +#define AN877_ADC_OUTPUT_MODE_OFFSET_BINARY 0x0 +#define AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT 0x1 +#define AN877_ADC_OUTPUT_MODE_GRAY_CODE 0x2 + +/* AN877_ADC_REG_OUTPUT_PHASE */ +#define AN877_ADC_OUTPUT_EVEN_ODD_MODE_EN 0x20 +#define AN877_ADC_INVERT_DCO_CLK 0x80 + +/* AN877_ADC_REG_OUTPUT_DELAY */ +#define AN877_ADC_DCO_DELAY_ENABLE 0x80 + +/* + * Analog Devices AD9467 16-Bit, 200/250 MSPS ADC + */ + +#define CHIPID_AD9467 0x50 +#define AD9467_DEF_OUTPUT_MODE 0x08 +#define AD9467_REG_VREF_MASK 0x0F + +enum { + ID_AD9467, +}; + +struct ad9467_state { + struct spi_device *spi; + struct clk *clk; + unsigned int output_mode; + + struct gpio_desc *pwrdown_gpio; + struct gpio_desc *reset_gpio; +}; + +static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) +{ + unsigned char tbuf[2], rbuf[1]; + int ret; + + tbuf[0] = 0x80 | (reg >> 8); + tbuf[1] = reg & 0xFF; + + ret = spi_write_then_read(spi, + tbuf, ARRAY_SIZE(tbuf), + rbuf, ARRAY_SIZE(rbuf)); + + if (ret < 0) + return ret; + + return rbuf[0]; +} + +static int ad9467_spi_write(struct spi_device *spi, unsigned int reg, + unsigned int val) +{ + unsigned char buf[3]; + + buf[0] = reg >> 8; + buf[1] = reg & 0xFF; + buf[2] = val; + + return spi_write(spi, buf, ARRAY_SIZE(buf)); +} + +static int ad9467_reg_access(struct adi_axi_adc_conv *conv, unsigned int reg, + unsigned int writeval, unsigned int *readval) +{ + struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + struct spi_device *spi = st->spi; + int ret; + + if (readval == NULL) { + ret = ad9467_spi_write(spi, reg, writeval); + ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER, + AN877_ADC_TRANSFER_SYNC); + return ret; + } + + ret = ad9467_spi_read(spi, reg); + if (ret < 0) + return ret; + *readval = ret; + + return 0; +} + +static const unsigned int ad9467_scale_table[][2] = { + {2000, 0}, {2100, 6}, {2200, 7}, + {2300, 8}, {2400, 9}, {2500, 10}, +}; + +static void __ad9467_get_scale(struct adi_axi_adc_conv *conv, int index, + unsigned int *val, unsigned int *val2) +{ + const struct adi_axi_adc_chip_info *info = conv->chip_info; + const struct iio_chan_spec *chan = &info->channels[0]; + unsigned int tmp; + + tmp = (info->scale_table[index][0] * 1000000ULL) >> + chan->scan_type.realbits; + *val = tmp / 1000000; + *val2 = tmp % 1000000; +} + +#define AD9467_CHAN(_chan, _si, _bits, _sign) \ +{ \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = _chan, \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = _si, \ + .scan_type = { \ + .sign = _sign, \ + .realbits = _bits, \ + .storagebits = 16, \ + }, \ +} + +static const struct iio_chan_spec ad9467_channels[] = { + AD9467_CHAN(0, 0, 16, 'S'), +}; + +static const struct adi_axi_adc_chip_info ad9467_chip_tbl[] = { + [ID_AD9467] = { + .id = CHIPID_AD9467, + .max_rate = 250000000UL, + .scale_table = ad9467_scale_table, + .num_scales = ARRAY_SIZE(ad9467_scale_table), + .channels = ad9467_channels, + .num_channels = ARRAY_SIZE(ad9467_channels), + }, +}; + +static int ad9467_get_scale(struct adi_axi_adc_conv *conv, int *val, int *val2) +{ + const struct adi_axi_adc_chip_info *info = conv->chip_info; + struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + unsigned int i, vref_val, vref_mask; + + vref_val = ad9467_spi_read(st->spi, AN877_ADC_REG_VREF); + + switch (info->id) { + case CHIPID_AD9467: + vref_mask = AD9467_REG_VREF_MASK; + break; + default: + vref_mask = 0xFFFF; + break; + } + + vref_val &= vref_mask; + + for (i = 0; i < info->num_scales; i++) { + if (vref_val == info->scale_table[i][1]) + break; + } + + if (i == info->num_scales) + return -ERANGE; + + __ad9467_get_scale(conv, i, val, val2); + + return IIO_VAL_INT_PLUS_MICRO; +} + +static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2) +{ + const struct adi_axi_adc_chip_info *info = conv->chip_info; + struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + unsigned int scale_val[2]; + unsigned int i; + + if (val != 0) + return -EINVAL; + + for (i = 0; i < info->num_scales; i++) { + __ad9467_get_scale(conv, i, &scale_val[0], &scale_val[1]); + if (scale_val[0] != val || scale_val[1] != val2) + continue; + + ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, + info->scale_table[i][1]); + ad9467_spi_write(st->spi, AN877_ADC_REG_TRANSFER, + AN877_ADC_TRANSFER_SYNC); + return 0; + } + + return -EINVAL; +} + +static int ad9467_read_raw(struct adi_axi_adc_conv *conv, + struct iio_chan_spec const *chan, + int *val, int *val2, long m) +{ + struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + + switch (m) { + case IIO_CHAN_INFO_SCALE: + return ad9467_get_scale(conv, val, val2); + case IIO_CHAN_INFO_SAMP_FREQ: + *val = clk_get_rate(st->clk); + + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int ad9467_write_raw(struct adi_axi_adc_conv *conv, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + const struct adi_axi_adc_chip_info *info = conv->chip_info; + struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + long r_clk; + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + return ad9467_set_scale(conv, val, val2); + case IIO_CHAN_INFO_SAMP_FREQ: + r_clk = clk_round_rate(st->clk, val); + if (r_clk < 0 || r_clk > info->max_rate) { + dev_warn(&st->spi->dev, + "Error setting ADC sample rate %ld", r_clk); + return -EINVAL; + } + + return clk_set_rate(st->clk, r_clk); + default: + return -EINVAL; + } +} + +static int ad9467_outputmode_set(struct spi_device *spi, unsigned int mode) +{ + int ret; + + ret = ad9467_spi_write(spi, AN877_ADC_REG_OUTPUT_MODE, mode); + if (ret < 0) + return ret; + + return ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER, + AN877_ADC_TRANSFER_SYNC); +} + +static int ad9467_preenable_setup(struct adi_axi_adc_conv *conv) +{ + struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + + return ad9467_outputmode_set(st->spi, st->output_mode); +} + +static int ad9467_setup(struct ad9467_state *st, unsigned int chip_id) +{ + switch (chip_id) { + case CHIPID_AD9467: + st->output_mode = AD9467_DEF_OUTPUT_MODE | + AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT; + return 0; + default: + return -EINVAL; + } +} + +static void ad9467_clk_disable(void *data) +{ + struct ad9467_state *st = data; + + clk_disable_unprepare(st->clk); +} + +static int ad9467_probe(struct spi_device *spi) +{ + const struct adi_axi_adc_chip_info *info; + struct adi_axi_adc_conv *conv; + struct ad9467_state *st; + unsigned int id; + int ret; + + info = of_device_get_match_data(&spi->dev); + if (!info) + return -ENODEV; + + conv = devm_adi_axi_adc_conv_register(&spi->dev, sizeof(*st)); + if (IS_ERR(conv)) + return PTR_ERR(conv); + + st = adi_axi_adc_conv_priv(conv); + st->spi = spi; + + st->clk = devm_clk_get(&spi->dev, "adc-clk"); + if (IS_ERR(st->clk)) + return PTR_ERR(st->clk); + + ret = clk_prepare_enable(st->clk); + if (ret < 0) + return ret; + + ret = devm_add_action_or_reset(&spi->dev, ad9467_clk_disable, st); + if (ret) + return ret; + + st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown", + GPIOD_OUT_LOW); + if (IS_ERR(st->pwrdown_gpio)) + return PTR_ERR(st->pwrdown_gpio); + + st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(st->reset_gpio)) + return PTR_ERR(st->reset_gpio); + + if (st->reset_gpio) { + udelay(1); + ret = gpiod_direction_output(st->reset_gpio, 1); + if (ret) + return ret; + mdelay(10); + } + + spi_set_drvdata(spi, st); + + conv->chip_info = info; + + id = ad9467_spi_read(spi, AN877_ADC_REG_CHIP_ID); + if (id != conv->chip_info->id) { + dev_err(&spi->dev, "Unrecognized CHIP_ID 0x%X\n", id); + return -ENODEV; + } + + conv->reg_access = ad9467_reg_access; + conv->write_raw = ad9467_write_raw; + conv->read_raw = ad9467_read_raw; + conv->preenable_setup = ad9467_preenable_setup; + + return ad9467_setup(st, id); +} + +static const struct of_device_id ad9467_of_match[] = { + { .compatible = "adi,ad9467", .data = &ad9467_chip_tbl[ID_AD9467], }, + {} +}; +MODULE_DEVICE_TABLE(of, ad9467_of_match); + +static struct spi_driver ad9467_driver = { + .driver = { + .name = "ad9467", + .of_match_table = ad9467_of_match, + }, + .probe = ad9467_probe, +}; +module_spi_driver(ad9467_driver); + +MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); +MODULE_DESCRIPTION("Analog Devices AD9467 ADC driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c new file mode 100644 index 000000000000..c24c8da99eb4 --- /dev/null +++ b/drivers/iio/adc/adi-axi-adc.c @@ -0,0 +1,482 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Analog Devices Generic AXI ADC IP core + * Link: https://wiki.analog.com/resources/fpga/docs/axi_adc_ip + * + * Copyright 2012-2020 Analog Devices Inc. + */ + +#include <linux/bitfield.h> +#include <linux/clk.h> +#include <linux/io.h> +#include <linux/delay.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/slab.h> + +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/buffer.h> +#include <linux/iio/buffer-dmaengine.h> + +#include <linux/fpga/adi-axi-common.h> +#include <linux/iio/adc/adi-axi-adc.h> + +/** + * Register definitions: + * https://wiki.analog.com/resources/fpga/docs/axi_adc_ip#register_map + */ + +/* ADC controls */ + +#define ADI_AXI_REG_RSTN 0x0040 +#define ADI_AXI_REG_RSTN_CE_N BIT(2) +#define ADI_AXI_REG_RSTN_MMCM_RSTN BIT(1) +#define ADI_AXI_REG_RSTN_RSTN BIT(0) + +/* ADC Channel controls */ + +#define ADI_AXI_REG_CHAN_CTRL(c) (0x0400 + (c) * 0x40) +#define ADI_AXI_REG_CHAN_CTRL_LB_OWR BIT(11) +#define ADI_AXI_REG_CHAN_CTRL_PN_SEL_OWR BIT(10) +#define ADI_AXI_REG_CHAN_CTRL_IQCOR_EN BIT(9) +#define ADI_AXI_REG_CHAN_CTRL_DCFILT_EN BIT(8) +#define ADI_AXI_REG_CHAN_CTRL_FMT_SIGNEXT BIT(6) +#define ADI_AXI_REG_CHAN_CTRL_FMT_TYPE BIT(5) +#define ADI_AXI_REG_CHAN_CTRL_FMT_EN BIT(4) +#define ADI_AXI_REG_CHAN_CTRL_PN_TYPE_OWR BIT(1) +#define ADI_AXI_REG_CHAN_CTRL_ENABLE BIT(0) + +#define ADI_AXI_REG_CHAN_CTRL_DEFAULTS \ + (ADI_AXI_REG_CHAN_CTRL_FMT_SIGNEXT | \ + ADI_AXI_REG_CHAN_CTRL_FMT_EN | \ + ADI_AXI_REG_CHAN_CTRL_ENABLE) + +struct adi_axi_adc_core_info { + unsigned int version; +}; + +struct adi_axi_adc_state { + struct mutex lock; + + struct adi_axi_adc_client *client; + void __iomem *regs; +}; + +struct adi_axi_adc_client { + struct list_head entry; + struct adi_axi_adc_conv conv; + struct adi_axi_adc_state *state; + struct device *dev; + const struct adi_axi_adc_core_info *info; +}; + +static LIST_HEAD(registered_clients); +static DEFINE_MUTEX(registered_clients_lock); + +static struct adi_axi_adc_client *conv_to_client(struct adi_axi_adc_conv *conv) +{ + return container_of(conv, struct adi_axi_adc_client, conv); +} + +void *adi_axi_adc_conv_priv(struct adi_axi_adc_conv *conv) +{ + struct adi_axi_adc_client *cl = conv_to_client(conv); + + return (char *)cl + ALIGN(sizeof(struct adi_axi_adc_client), IIO_ALIGN); +} +EXPORT_SYMBOL_GPL(adi_axi_adc_conv_priv); + +static void adi_axi_adc_write(struct adi_axi_adc_state *st, + unsigned int reg, + unsigned int val) +{ + iowrite32(val, st->regs + reg); +} + +static unsigned int adi_axi_adc_read(struct adi_axi_adc_state *st, + unsigned int reg) +{ + return ioread32(st->regs + reg); +} + +static int adi_axi_adc_config_dma_buffer(struct device *dev, + struct iio_dev *indio_dev) +{ + struct iio_buffer *buffer; + const char *dma_name; + + if (!device_property_present(dev, "dmas")) + return 0; + + if (device_property_read_string(dev, "dma-names", &dma_name)) + dma_name = "rx"; + + buffer = devm_iio_dmaengine_buffer_alloc(indio_dev->dev.parent, + dma_name); + if (IS_ERR(buffer)) + return PTR_ERR(buffer); + + indio_dev->modes |= INDIO_BUFFER_HARDWARE; + iio_device_attach_buffer(indio_dev, buffer); + + return 0; +} + +static int adi_axi_adc_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct adi_axi_adc_state *st = iio_priv(indio_dev); + struct adi_axi_adc_conv *conv = &st->client->conv; + + if (!conv->read_raw) + return -EOPNOTSUPP; + + return conv->read_raw(conv, chan, val, val2, mask); +} + +static int adi_axi_adc_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct adi_axi_adc_state *st = iio_priv(indio_dev); + struct adi_axi_adc_conv *conv = &st->client->conv; + + if (!conv->write_raw) + return -EOPNOTSUPP; + + return conv->write_raw(conv, chan, val, val2, mask); +} + +static int adi_axi_adc_update_scan_mode(struct iio_dev *indio_dev, + const unsigned long *scan_mask) +{ + struct adi_axi_adc_state *st = iio_priv(indio_dev); + struct adi_axi_adc_conv *conv = &st->client->conv; + unsigned int i, ctrl; + + for (i = 0; i < conv->chip_info->num_channels; i++) { + ctrl = adi_axi_adc_read(st, ADI_AXI_REG_CHAN_CTRL(i)); + + if (test_bit(i, scan_mask)) + ctrl |= ADI_AXI_REG_CHAN_CTRL_ENABLE; + else + ctrl &= ~ADI_AXI_REG_CHAN_CTRL_ENABLE; + + adi_axi_adc_write(st, ADI_AXI_REG_CHAN_CTRL(i), ctrl); + } + + return 0; +} + +static struct adi_axi_adc_conv *adi_axi_adc_conv_register(struct device *dev, + size_t sizeof_priv) +{ + struct adi_axi_adc_client *cl; + size_t alloc_size; + + alloc_size = ALIGN(sizeof(struct adi_axi_adc_client), IIO_ALIGN); + if (sizeof_priv) + alloc_size += ALIGN(sizeof_priv, IIO_ALIGN); + + cl = kzalloc(alloc_size, GFP_KERNEL); + if (!cl) + return ERR_PTR(-ENOMEM); + + mutex_lock(®istered_clients_lock); + + cl->dev = get_device(dev); + + list_add_tail(&cl->entry, ®istered_clients); + + mutex_unlock(®istered_clients_lock); + + return &cl->conv; +} + +static void adi_axi_adc_conv_unregister(struct adi_axi_adc_conv *conv) +{ + struct adi_axi_adc_client *cl = conv_to_client(conv); + + mutex_lock(®istered_clients_lock); + + list_del(&cl->entry); + put_device(cl->dev); + + mutex_unlock(®istered_clients_lock); + + kfree(cl); +} + +static void devm_adi_axi_adc_conv_release(struct device *dev, void *res) +{ + adi_axi_adc_conv_unregister(*(struct adi_axi_adc_conv **)res); +} + +struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev, + size_t sizeof_priv) +{ + struct adi_axi_adc_conv **ptr, *conv; + + ptr = devres_alloc(devm_adi_axi_adc_conv_release, sizeof(*ptr), + GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + conv = adi_axi_adc_conv_register(dev, sizeof_priv); + if (IS_ERR(conv)) { + devres_free(ptr); + return ERR_CAST(conv); + } + + *ptr = conv; + devres_add(dev, ptr); + + return conv; +} +EXPORT_SYMBOL_GPL(devm_adi_axi_adc_conv_register); + +static ssize_t in_voltage_scale_available_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adi_axi_adc_state *st = iio_priv(indio_dev); + struct adi_axi_adc_conv *conv = &st->client->conv; + size_t len = 0; + int i; + + for (i = 0; i < conv->chip_info->num_scales; i++) { + const unsigned int *s = conv->chip_info->scale_table[i]; + + len += scnprintf(buf + len, PAGE_SIZE - len, + "%u.%06u ", s[0], s[1]); + } + buf[len - 1] = '\n'; + + return len; +} + +static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); + +enum { + ADI_AXI_ATTR_SCALE_AVAIL, +}; + +#define ADI_AXI_ATTR(_en_, _file_) \ + [ADI_AXI_ATTR_##_en_] = &iio_dev_attr_##_file_.dev_attr.attr + +static struct attribute *adi_axi_adc_attributes[] = { + ADI_AXI_ATTR(SCALE_AVAIL, in_voltage_scale_available), + NULL +}; + +static umode_t axi_adc_attr_is_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adi_axi_adc_state *st = iio_priv(indio_dev); + struct adi_axi_adc_conv *conv = &st->client->conv; + + switch (n) { + case ADI_AXI_ATTR_SCALE_AVAIL: + if (!conv->chip_info->num_scales) + return 0; + return attr->mode; + default: + return attr->mode; + } +} + +static const struct attribute_group adi_axi_adc_attribute_group = { + .attrs = adi_axi_adc_attributes, + .is_visible = axi_adc_attr_is_visible, +}; + +static const struct iio_info adi_axi_adc_info = { + .read_raw = &adi_axi_adc_read_raw, + .write_raw = &adi_axi_adc_write_raw, + .attrs = &adi_axi_adc_attribute_group, + .update_scan_mode = &adi_axi_adc_update_scan_mode, +}; + +static const struct adi_axi_adc_core_info adi_axi_adc_10_0_a_info = { + .version = ADI_AXI_PCORE_VER(10, 0, 'a'), +}; + +static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev) +{ + const struct adi_axi_adc_core_info *info; + struct adi_axi_adc_client *cl; + struct device_node *cln; + + info = of_device_get_match_data(dev); + if (!info) + return ERR_PTR(-ENODEV); + + cln = of_parse_phandle(dev->of_node, "adi,adc-dev", 0); + if (!cln) { + dev_err(dev, "No 'adi,adc-dev' node defined\n"); + return ERR_PTR(-ENODEV); + } + + mutex_lock(®istered_clients_lock); + + list_for_each_entry(cl, ®istered_clients, entry) { + if (!cl->dev) + continue; + + if (cl->dev->of_node != cln) + continue; + + if (!try_module_get(dev->driver->owner)) { + mutex_unlock(®istered_clients_lock); + return ERR_PTR(-ENODEV); + } + + get_device(dev); + cl->info = info; + mutex_unlock(®istered_clients_lock); + return cl; + } + + mutex_unlock(®istered_clients_lock); + + return ERR_PTR(-EPROBE_DEFER); +} + +static int adi_axi_adc_setup_channels(struct device *dev, + struct adi_axi_adc_state *st) +{ + struct adi_axi_adc_conv *conv = &st->client->conv; + int i, ret; + + if (conv->preenable_setup) { + ret = conv->preenable_setup(conv); + if (ret) + return ret; + } + + for (i = 0; i < conv->chip_info->num_channels; i++) { + adi_axi_adc_write(st, ADI_AXI_REG_CHAN_CTRL(i), + ADI_AXI_REG_CHAN_CTRL_DEFAULTS); + } + + return 0; +} + +static void axi_adc_reset(struct adi_axi_adc_state *st) +{ + adi_axi_adc_write(st, ADI_AXI_REG_RSTN, 0); + mdelay(10); + adi_axi_adc_write(st, ADI_AXI_REG_RSTN, ADI_AXI_REG_RSTN_MMCM_RSTN); + mdelay(10); + adi_axi_adc_write(st, ADI_AXI_REG_RSTN, + ADI_AXI_REG_RSTN_RSTN | ADI_AXI_REG_RSTN_MMCM_RSTN); +} + +static void adi_axi_adc_cleanup(void *data) +{ + struct adi_axi_adc_client *cl = data; + + put_device(cl->dev); + module_put(cl->dev->driver->owner); +} + +static int adi_axi_adc_probe(struct platform_device *pdev) +{ + struct adi_axi_adc_conv *conv; + struct iio_dev *indio_dev; + struct adi_axi_adc_client *cl; + struct adi_axi_adc_state *st; + unsigned int ver; + int ret; + + cl = adi_axi_adc_attach_client(&pdev->dev); + if (IS_ERR(cl)) + return PTR_ERR(cl); + + ret = devm_add_action_or_reset(&pdev->dev, adi_axi_adc_cleanup, cl); + if (ret) + return ret; + + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); + if (indio_dev == NULL) + return -ENOMEM; + + st = iio_priv(indio_dev); + st->client = cl; + cl->state = st; + mutex_init(&st->lock); + + st->regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(st->regs)) + return PTR_ERR(st->regs); + + conv = &st->client->conv; + + axi_adc_reset(st); + + ver = adi_axi_adc_read(st, ADI_AXI_REG_VERSION); + + if (cl->info->version > ver) { + dev_err(&pdev->dev, + "IP core version is too old. Expected %d.%.2d.%c, Reported %d.%.2d.%c\n", + ADI_AXI_PCORE_VER_MAJOR(cl->info->version), + ADI_AXI_PCORE_VER_MINOR(cl->info->version), + ADI_AXI_PCORE_VER_PATCH(cl->info->version), + ADI_AXI_PCORE_VER_MAJOR(ver), + ADI_AXI_PCORE_VER_MINOR(ver), + ADI_AXI_PCORE_VER_PATCH(ver)); + return -ENODEV; + } + + indio_dev->info = &adi_axi_adc_info; + indio_dev->dev.parent = &pdev->dev; + indio_dev->name = "adi-axi-adc"; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->num_channels = conv->chip_info->num_channels; + indio_dev->channels = conv->chip_info->channels; + + ret = adi_axi_adc_config_dma_buffer(&pdev->dev, indio_dev); + if (ret) + return ret; + + ret = adi_axi_adc_setup_channels(&pdev->dev, st); + if (ret) + return ret; + + ret = devm_iio_device_register(&pdev->dev, indio_dev); + if (ret) + return ret; + + dev_info(&pdev->dev, "AXI ADC IP core (%d.%.2d.%c) probed\n", + ADI_AXI_PCORE_VER_MAJOR(ver), + ADI_AXI_PCORE_VER_MINOR(ver), + ADI_AXI_PCORE_VER_PATCH(ver)); + + return 0; +} + +/* Match table for of_platform binding */ +static const struct of_device_id adi_axi_adc_of_match[] = { + { .compatible = "adi,axi-adc-10.0.a", .data = &adi_axi_adc_10_0_a_info }, + { /* end of list */ } +}; +MODULE_DEVICE_TABLE(of, adi_axi_adc_of_match); + +static struct platform_driver adi_axi_adc_driver = { + .driver = { + .name = KBUILD_MODNAME, + .of_match_table = adi_axi_adc_of_match, + }, + .probe = adi_axi_adc_probe, +}; +module_platform_driver(adi_axi_adc_driver); + +MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); +MODULE_DESCRIPTION("Analog Devices Generic AXI ADC IP core driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c index abe99856c823..0368b6dc6d60 100644 --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c @@ -1152,7 +1152,6 @@ static int at91_adc_probe(struct platform_device *pdev) int ret; struct iio_dev *idev; struct at91_adc_state *st; - struct resource *res; u32 reg; idev = devm_iio_device_alloc(&pdev->dev, sizeof(struct at91_adc_state)); @@ -1182,9 +1181,7 @@ static int at91_adc_probe(struct platform_device *pdev) if (st->irq < 0) return -ENODEV; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - - st->reg_base = devm_ioremap_resource(&pdev->dev, res); + st->reg_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(st->reg_base)) return PTR_ERR(st->reg_base); diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c index fa71489195c6..b0a4dc88ba9b 100644 --- a/drivers/iio/adc/fsl-imx25-gcq.c +++ b/drivers/iio/adc/fsl-imx25-gcq.c @@ -294,7 +294,6 @@ static int mx25_gcq_probe(struct platform_device *pdev) struct mx25_gcq_priv *priv; struct mx25_tsadc *tsadc = dev_get_drvdata(pdev->dev.parent); struct device *dev = &pdev->dev; - struct resource *res; void __iomem *mem; int ret; int i; @@ -305,8 +304,7 @@ static int mx25_gcq_probe(struct platform_device *pdev) priv = iio_priv(indio_dev); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - mem = devm_ioremap_resource(dev, res); + mem = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(mem)) return PTR_ERR(mem); diff --git a/drivers/iio/adc/intel_mrfld_adc.c b/drivers/iio/adc/intel_mrfld_adc.c index c35a1beb817c..a6d2e1f27e76 100644 --- a/drivers/iio/adc/intel_mrfld_adc.c +++ b/drivers/iio/adc/intel_mrfld_adc.c @@ -75,7 +75,7 @@ static int mrfld_adc_single_conv(struct iio_dev *indio_dev, struct regmap *regmap = adc->regmap; unsigned int req; long timeout; - u8 buf[2]; + __be16 value; int ret; reinit_completion(&adc->completion); @@ -105,11 +105,11 @@ static int mrfld_adc_single_conv(struct iio_dev *indio_dev, goto done; } - ret = regmap_bulk_read(regmap, chan->address, buf, 2); + ret = regmap_bulk_read(regmap, chan->address, &value, sizeof(value)); if (ret) goto done; - *result = get_unaligned_be16(buf); + *result = be16_to_cpu(value); ret = IIO_VAL_INT; done: diff --git a/drivers/iio/adc/max1241.c b/drivers/iio/adc/max1241.c new file mode 100644 index 000000000000..541939c7abca --- /dev/null +++ b/drivers/iio/adc/max1241.c @@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * MAX1241 low-power, 12-bit serial ADC + * + * Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX1240-MAX1241.pdf + */ + +#include <linux/delay.h> +#include <linux/gpio/consumer.h> +#include <linux/iio/iio.h> +#include <linux/module.h> +#include <linux/regulator/consumer.h> +#include <linux/spi/spi.h> + +#define MAX1241_VAL_MASK GENMASK(11, 0) +#define MAX1241_SHUTDOWN_DELAY_USEC 4 + +enum max1241_id { + max1241, +}; + +struct max1241 { + struct spi_device *spi; + struct mutex lock; + struct regulator *vdd; + struct regulator *vref; + struct gpio_desc *shutdown; + + __be16 data ____cacheline_aligned; +}; + +static const struct iio_chan_spec max1241_channels[] = { + { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + }, +}; + +static int max1241_read(struct max1241 *adc) +{ + struct spi_transfer xfers[] = { + /* + * Begin conversion by bringing /CS low for at least + * tconv us. + */ + { + .len = 0, + .delay.value = 8, + .delay.unit = SPI_DELAY_UNIT_USECS, + }, + /* + * Then read two bytes of data in our RX buffer. + */ + { + .rx_buf = &adc->data, + .len = 2, + }, + }; + + return spi_sync_transfer(adc->spi, xfers, ARRAY_SIZE(xfers)); +} + +static int max1241_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + int ret, vref_uV; + struct max1241 *adc = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + mutex_lock(&adc->lock); + + if (adc->shutdown) { + gpiod_set_value(adc->shutdown, 0); + udelay(MAX1241_SHUTDOWN_DELAY_USEC); + ret = max1241_read(adc); + gpiod_set_value(adc->shutdown, 1); + } else + ret = max1241_read(adc); + + if (ret) { + mutex_unlock(&adc->lock); + return ret; + } + + *val = (be16_to_cpu(adc->data) >> 3) & MAX1241_VAL_MASK; + + mutex_unlock(&adc->lock); + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + vref_uV = regulator_get_voltage(adc->vref); + + if (vref_uV < 0) + return vref_uV; + + *val = vref_uV / 1000; + *val2 = 12; + + return IIO_VAL_FRACTIONAL_LOG2; + default: + return -EINVAL; + } +} + +static const struct iio_info max1241_info = { + .read_raw = max1241_read_raw, +}; + +static void max1241_disable_vdd_action(void *data) +{ + struct max1241 *adc = data; + struct device *dev = &adc->spi->dev; + int err; + + err = regulator_disable(adc->vdd); + if (err) + dev_err(dev, "could not disable vdd regulator.\n"); +} + +static void max1241_disable_vref_action(void *data) +{ + struct max1241 *adc = data; + struct device *dev = &adc->spi->dev; + int err; + + err = regulator_disable(adc->vref); + if (err) + dev_err(dev, "could not disable vref regulator.\n"); +} + +static int max1241_probe(struct spi_device *spi) +{ + struct device *dev = &spi->dev; + struct iio_dev *indio_dev; + struct max1241 *adc; + int ret; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); + if (!indio_dev) + return -ENOMEM; + + adc = iio_priv(indio_dev); + adc->spi = spi; + mutex_init(&adc->lock); + + spi_set_drvdata(spi, indio_dev); + + adc->vdd = devm_regulator_get(dev, "vdd"); + if (IS_ERR(adc->vdd)) { + dev_err(dev, "failed to get vdd regulator\n"); + return PTR_ERR(adc->vdd); + } + + ret = regulator_enable(adc->vdd); + if (ret) + return ret; + + ret = devm_add_action_or_reset(dev, max1241_disable_vdd_action, adc); + if (ret) { + dev_err(dev, "could not set up vdd regulator cleanup action\n"); + return ret; + } + + adc->vref = devm_regulator_get(dev, "vref"); + if (IS_ERR(adc->vref)) { + dev_err(dev, "failed to get vref regulator\n"); + return PTR_ERR(adc->vref); + } + + ret = regulator_enable(adc->vref); + if (ret) + return ret; + + ret = devm_add_action_or_reset(dev, max1241_disable_vref_action, adc); + if (ret) { + dev_err(dev, "could not set up vref regulator cleanup action\n"); + return ret; + } + + adc->shutdown = devm_gpiod_get_optional(dev, "shutdown", + GPIOD_OUT_HIGH); + if (IS_ERR(adc->shutdown)) + return PTR_ERR(adc->shutdown); + + if (adc->shutdown) + dev_dbg(dev, "shutdown pin passed, low-power mode enabled"); + else + dev_dbg(dev, "no shutdown pin passed, low-power mode disabled"); + + indio_dev->name = spi_get_device_id(spi)->name; + indio_dev->dev.parent = dev; + indio_dev->info = &max1241_info; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = max1241_channels; + indio_dev->num_channels = ARRAY_SIZE(max1241_channels); + + return devm_iio_device_register(dev, indio_dev); +} + +static const struct spi_device_id max1241_id[] = { + { "max1241", max1241 }, + {} +}; + +static const struct of_device_id max1241_dt_ids[] = { + { .compatible = "maxim,max1241" }, + {} +}; +MODULE_DEVICE_TABLE(of, max1241_dt_ids); + +static struct spi_driver max1241_spi_driver = { + .driver = { + .name = "max1241", + .of_match_table = max1241_dt_ids, + }, + .probe = max1241_probe, + .id_table = max1241_id, +}; +module_spi_driver(max1241_spi_driver); + +MODULE_AUTHOR("Alexandru Lazar <alazar@startmail.com>"); +MODULE_DESCRIPTION("MAX1241 ADC driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 5c2cc61b666e..9d92017c79b2 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -150,6 +150,7 @@ struct max1363_chip_info { * @current_mode: the scan mode of this chip * @requestedmask: a valid requested set of channels * @reg: supply regulator + * @lock lock to ensure state is consistent * @monitor_on: whether monitor mode is enabled * @monitor_speed: parameter corresponding to device monitor speed setting * @mask_high: bitmask for enabled high thresholds @@ -169,6 +170,7 @@ struct max1363_state { const struct max1363_mode *current_mode; u32 requestedmask; struct regulator *reg; + struct mutex lock; /* Using monitor modes and buffer at the same time is currently not supported */ @@ -364,7 +366,11 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, struct max1363_state *st = iio_priv(indio_dev); struct i2c_client *client = st->client; - mutex_lock(&indio_dev->mlock); + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + mutex_lock(&st->lock); + /* * If monitor mode is enabled, the method for reading a single * channel will have to be rather different and has not yet @@ -372,7 +378,7 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, * * Also, cannot read directly if buffered capture enabled. */ - if (st->monitor_on || iio_buffer_enabled(indio_dev)) { + if (st->monitor_on) { ret = -EBUSY; goto error_ret; } @@ -404,8 +410,10 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, data = rxbuf[0]; } *val = data; + error_ret: - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); + iio_device_release_direct_mode(indio_dev); return ret; } @@ -705,9 +713,9 @@ static ssize_t max1363_monitor_store_freq(struct device *dev, if (!found) return -EINVAL; - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->lock); st->monitor_speed = i; - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); return 0; } @@ -810,12 +818,12 @@ static int max1363_read_event_config(struct iio_dev *indio_dev, int val; int number = chan->channel; - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->lock); if (dir == IIO_EV_DIR_FALLING) val = (1 << number) & st->mask_low; else val = (1 << number) & st->mask_high; - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); return val; } @@ -962,7 +970,11 @@ static int max1363_write_event_config(struct iio_dev *indio_dev, u16 unifiedmask; int number = chan->channel; - mutex_lock(&indio_dev->mlock); + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + mutex_lock(&st->lock); + unifiedmask = st->mask_low | st->mask_high; if (dir == IIO_EV_DIR_FALLING) { @@ -989,7 +1001,8 @@ static int max1363_write_event_config(struct iio_dev *indio_dev, max1363_monitor_mode_update(st, !!(st->mask_high | st->mask_low)); error_ret: - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); + iio_device_release_direct_mode(indio_dev); return ret; } @@ -1587,6 +1600,7 @@ static int max1363_probe(struct i2c_client *client, st = iio_priv(indio_dev); + mutex_init(&st->lock); st->reg = devm_regulator_get(&client->dev, "vcc"); if (IS_ERR(st->reg)) { ret = PTR_ERR(st->reg); diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index 176e1cb4abb1..0f2c1738a90d 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -496,7 +496,6 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, struct iio_dev *indio_dev) { struct sun4i_gpadc_iio *info = iio_priv(indio_dev); - struct resource *mem; void __iomem *base; int ret; @@ -508,8 +507,7 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, indio_dev->num_channels = ARRAY_SIZE(sun8i_a33_gpadc_channels); indio_dev->channels = sun8i_a33_gpadc_channels; - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); - base = devm_ioremap_resource(&pdev->dev, mem); + base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(base)) return PTR_ERR(base); diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index 6fd06e4eff73..d7fecab9252e 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -3,7 +3,7 @@ * Xilinx XADC driver * * Copyright 2013-2014 Analog Devices Inc. - * Author: Lars-Peter Clauen <lars@metafoo.de> + * Author: Lars-Peter Clausen <lars@metafoo.de> * * Documentation for the parts can be found at: * - XADC hardmacro: Xilinx UG480 @@ -663,7 +663,7 @@ static int xadc_trigger_set_state(struct iio_trigger *trigger, bool state) mutex_lock(&xadc->mutex); if (state) { - /* Only one of the two triggers can be active at the a time. */ + /* Only one of the two triggers can be active at a time. */ if (xadc->trigger != NULL) { ret = -EBUSY; goto err_out; diff --git a/drivers/iio/adc/xilinx-xadc-events.c b/drivers/iio/adc/xilinx-xadc-events.c index dbfd5da290a4..2357f585720a 100644 --- a/drivers/iio/adc/xilinx-xadc-events.c +++ b/drivers/iio/adc/xilinx-xadc-events.c @@ -3,7 +3,7 @@ * Xilinx XADC driver * * Copyright 2013 Analog Devices Inc. - * Author: Lars-Peter Clauen <lars@metafoo.de> + * Author: Lars-Peter Clausen <lars@metafoo.de> */ #include <linux/iio/events.h> diff --git a/drivers/iio/adc/xilinx-xadc.h b/drivers/iio/adc/xilinx-xadc.h index 4017f18b0a4f..25abed9c0285 100644 --- a/drivers/iio/adc/xilinx-xadc.h +++ b/drivers/iio/adc/xilinx-xadc.h @@ -3,7 +3,7 @@ * Xilinx XADC driver * * Copyright 2013 Analog Devices Inc. - * Author: Lars-Peter Clauen <lars@metafoo.de> + * Author: Lars-Peter Clausen <lars@metafoo.de> */ #ifndef __IIO_XILINX_XADC__ diff --git a/drivers/iio/buffer/industrialio-buffer-dma.c b/drivers/iio/buffer/industrialio-buffer-dma.c index a74bd9c0587c..d348af8b9705 100644 --- a/drivers/iio/buffer/industrialio-buffer-dma.c +++ b/drivers/iio/buffer/industrialio-buffer-dma.c @@ -12,7 +12,6 @@ #include <linux/mutex.h> #include <linux/sched.h> #include <linux/poll.h> -#include <linux/iio/buffer.h> #include <linux/iio/buffer_impl.h> #include <linux/iio/buffer-dma.h> #include <linux/dma-mapping.h> diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c index b129693af0fd..6dedf12b69a4 100644 --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c @@ -134,7 +134,7 @@ static ssize_t iio_dmaengine_buffer_get_length_align(struct device *dev, struct dmaengine_buffer *dmaengine_buffer = iio_buffer_to_dmaengine_buffer(indio_dev->buffer); - return sprintf(buf, "%u\n", dmaengine_buffer->align); + return sprintf(buf, "%zu\n", dmaengine_buffer->align); } static IIO_DEVICE_ATTR(length_align_bytes, 0444, @@ -229,6 +229,45 @@ void iio_dmaengine_buffer_free(struct iio_buffer *buffer) } EXPORT_SYMBOL_GPL(iio_dmaengine_buffer_free); +static void __devm_iio_dmaengine_buffer_free(struct device *dev, void *res) +{ + iio_dmaengine_buffer_free(*(struct iio_buffer **)res); +} + +/** + * devm_iio_dmaengine_buffer_alloc() - Resource-managed iio_dmaengine_buffer_alloc() + * @dev: Parent device for the buffer + * @channel: DMA channel name, typically "rx". + * + * This allocates a new IIO buffer which internally uses the DMAengine framework + * to perform its transfers. The parent device will be used to request the DMA + * channel. + * + * The buffer will be automatically de-allocated once the device gets destroyed. + */ +struct iio_buffer *devm_iio_dmaengine_buffer_alloc(struct device *dev, + const char *channel) +{ + struct iio_buffer **bufferp, *buffer; + + bufferp = devres_alloc(__devm_iio_dmaengine_buffer_free, + sizeof(*bufferp), GFP_KERNEL); + if (!bufferp) + return ERR_PTR(-ENOMEM); + + buffer = iio_dmaengine_buffer_alloc(dev, channel); + if (IS_ERR(buffer)) { + devres_free(bufferp); + return buffer; + } + + *bufferp = buffer; + devres_add(dev, bufferp); + + return buffer; +} +EXPORT_SYMBOL_GPL(devm_iio_dmaengine_buffer_alloc); + MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); MODULE_DESCRIPTION("DMA buffer for the IIO framework"); MODULE_LICENSE("GPL"); diff --git a/drivers/iio/buffer/industrialio-hw-consumer.c b/drivers/iio/buffer/industrialio-hw-consumer.c index 95165697d8ae..f2d27788f666 100644 --- a/drivers/iio/buffer/industrialio-hw-consumer.c +++ b/drivers/iio/buffer/industrialio-hw-consumer.c @@ -142,17 +142,6 @@ static void devm_iio_hw_consumer_release(struct device *dev, void *res) iio_hw_consumer_free(*(struct iio_hw_consumer **)res); } -static int devm_iio_hw_consumer_match(struct device *dev, void *res, void *data) -{ - struct iio_hw_consumer **r = res; - - if (!r || !*r) { - WARN_ON(!r || !*r); - return 0; - } - return *r == data; -} - /** * devm_iio_hw_consumer_alloc - Resource-managed iio_hw_consumer_alloc() * @dev: Pointer to consumer device. @@ -160,9 +149,6 @@ static int devm_iio_hw_consumer_match(struct device *dev, void *res, void *data) * Managed iio_hw_consumer_alloc. iio_hw_consumer allocated with this function * is automatically freed on driver detach. * - * If an iio_hw_consumer allocated with this function needs to be freed - * separately, devm_iio_hw_consumer_free() must be used. - * * returns pointer to allocated iio_hw_consumer on success, NULL on failure. */ struct iio_hw_consumer *devm_iio_hw_consumer_alloc(struct device *dev) @@ -187,23 +173,6 @@ struct iio_hw_consumer *devm_iio_hw_consumer_alloc(struct device *dev) EXPORT_SYMBOL_GPL(devm_iio_hw_consumer_alloc); /** - * devm_iio_hw_consumer_free - Resource-managed iio_hw_consumer_free() - * @dev: Pointer to consumer device. - * @hwc: iio_hw_consumer to free. - * - * Free iio_hw_consumer allocated with devm_iio_hw_consumer_alloc(). - */ -void devm_iio_hw_consumer_free(struct device *dev, struct iio_hw_consumer *hwc) -{ - int rc; - - rc = devres_release(dev, devm_iio_hw_consumer_release, - devm_iio_hw_consumer_match, hwc); - WARN_ON(rc); -} -EXPORT_SYMBOL_GPL(devm_iio_hw_consumer_free); - -/** * iio_hw_consumer_enable() - Enable IIO hardware consumer * @hwc: iio_hw_consumer to enable. * diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c index cb322b2f09cd..e8046c1ecd6b 100644 --- a/drivers/iio/buffer/industrialio-triggered-buffer.c +++ b/drivers/iio/buffer/industrialio-triggered-buffer.c @@ -126,17 +126,6 @@ int devm_iio_triggered_buffer_setup(struct device *dev, } EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_setup); -void devm_iio_triggered_buffer_cleanup(struct device *dev, - struct iio_dev *indio_dev) -{ - int rc; - - rc = devres_release(dev, devm_iio_triggered_buffer_clean, - devm_iio_device_match, indio_dev); - WARN_ON(rc); -} -EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_cleanup); - MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); MODULE_DESCRIPTION("IIO helper functions for setting up triggered buffers"); MODULE_LICENSE("GPL"); diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c index 3150f8ab984b..1359abed3b31 100644 --- a/drivers/iio/buffer/kfifo_buf.c +++ b/drivers/iio/buffer/kfifo_buf.c @@ -179,16 +179,6 @@ static void devm_iio_kfifo_release(struct device *dev, void *res) iio_kfifo_free(*(struct iio_buffer **)res); } -static int devm_iio_kfifo_match(struct device *dev, void *res, void *data) -{ - struct iio_buffer **r = res; - - if (WARN_ON(!r || !*r)) - return 0; - - return *r == data; -} - /** * devm_iio_fifo_allocate - Resource-managed iio_kfifo_allocate() * @dev: Device to allocate kfifo buffer for @@ -216,16 +206,4 @@ struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev) } EXPORT_SYMBOL(devm_iio_kfifo_allocate); -/** - * devm_iio_fifo_free - Resource-managed iio_kfifo_free() - * @dev: Device the buffer belongs to - * @r: The buffer associated with the device - */ -void devm_iio_kfifo_free(struct device *dev, struct iio_buffer *r) -{ - WARN_ON(devres_release(dev, devm_iio_kfifo_release, - devm_iio_kfifo_match, r)); -} -EXPORT_SYMBOL(devm_iio_kfifo_free); - MODULE_LICENSE("GPL"); diff --git a/drivers/iio/chemical/atlas-sensor.c b/drivers/iio/chemical/atlas-sensor.c index 82d470561ad3..973cdb4f1e83 100644 --- a/drivers/iio/chemical/atlas-sensor.c +++ b/drivers/iio/chemical/atlas-sensor.c @@ -426,8 +426,7 @@ static irqreturn_t atlas_trigger_handler(int irq, void *private) int ret; ret = regmap_bulk_read(data->regmap, data->chip->data_reg, - (u8 *) &data->buffer, - sizeof(__be32) * channels); + &data->buffer, sizeof(__be32) * channels); if (!ret) iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, @@ -463,7 +462,7 @@ static int atlas_read_measurement(struct atlas_data *data, int reg, __be32 *val) if (suspended) msleep(data->chip->delay); - ret = regmap_bulk_read(data->regmap, reg, (u8 *) val, sizeof(*val)); + ret = regmap_bulk_read(data->regmap, reg, val, sizeof(*val)); pm_runtime_mark_last_busy(dev); pm_runtime_put_autosuspend(dev); @@ -485,7 +484,7 @@ static int atlas_read_raw(struct iio_dev *indio_dev, switch (chan->type) { case IIO_TEMP: ret = regmap_bulk_read(data->regmap, chan->address, - (u8 *) ®, sizeof(reg)); + ®, sizeof(reg)); break; case IIO_PH: case IIO_CONCENTRATION: diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index ccde4c65ff93..13773e01699b 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -114,14 +114,16 @@ static int bme680_read_calib(struct bme680_data *data, __le16 buf; /* Temperature related coefficients */ - ret = regmap_bulk_read(data->regmap, BME680_T1_LSB_REG, (u8 *) &buf, 2); + ret = regmap_bulk_read(data->regmap, BME680_T1_LSB_REG, + &buf, sizeof(buf)); if (ret < 0) { dev_err(dev, "failed to read BME680_T1_LSB_REG\n"); return ret; } calib->par_t1 = le16_to_cpu(buf); - ret = regmap_bulk_read(data->regmap, BME680_T2_LSB_REG, (u8 *) &buf, 2); + ret = regmap_bulk_read(data->regmap, BME680_T2_LSB_REG, + &buf, sizeof(buf)); if (ret < 0) { dev_err(dev, "failed to read BME680_T2_LSB_REG\n"); return ret; @@ -136,14 +138,16 @@ static int bme680_read_calib(struct bme680_data *data, calib->par_t3 = tmp; /* Pressure related coefficients */ - ret = regmap_bulk_read(data->regmap, BME680_P1_LSB_REG, (u8 *) &buf, 2); + ret = regmap_bulk_read(data->regmap, BME680_P1_LSB_REG, + &buf, sizeof(buf)); if (ret < 0) { dev_err(dev, "failed to read BME680_P1_LSB_REG\n"); return ret; } calib->par_p1 = le16_to_cpu(buf); - ret = regmap_bulk_read(data->regmap, BME680_P2_LSB_REG, (u8 *) &buf, 2); + ret = regmap_bulk_read(data->regmap, BME680_P2_LSB_REG, + &buf, sizeof(buf)); if (ret < 0) { dev_err(dev, "failed to read BME680_P2_LSB_REG\n"); return ret; @@ -157,14 +161,16 @@ static int bme680_read_calib(struct bme680_data *data, } calib->par_p3 = tmp; - ret = regmap_bulk_read(data->regmap, BME680_P4_LSB_REG, (u8 *) &buf, 2); + ret = regmap_bulk_read(data->regmap, BME680_P4_LSB_REG, + &buf, sizeof(buf)); if (ret < 0) { dev_err(dev, "failed to read BME680_P4_LSB_REG\n"); return ret; } calib->par_p4 = le16_to_cpu(buf); - ret = regmap_bulk_read(data->regmap, BME680_P5_LSB_REG, (u8 *) &buf, 2); + ret = regmap_bulk_read(data->regmap, BME680_P5_LSB_REG, + &buf, sizeof(buf)); if (ret < 0) { dev_err(dev, "failed to read BME680_P5_LSB_REG\n"); return ret; @@ -185,14 +191,16 @@ static int bme680_read_calib(struct bme680_data *data, } calib->par_p7 = tmp; - ret = regmap_bulk_read(data->regmap, BME680_P8_LSB_REG, (u8 *) &buf, 2); + ret = regmap_bulk_read(data->regmap, BME680_P8_LSB_REG, + &buf, sizeof(buf)); if (ret < 0) { dev_err(dev, "failed to read BME680_P8_LSB_REG\n"); return ret; } calib->par_p8 = le16_to_cpu(buf); - ret = regmap_bulk_read(data->regmap, BME680_P9_LSB_REG, (u8 *) &buf, 2); + ret = regmap_bulk_read(data->regmap, BME680_P9_LSB_REG, + &buf, sizeof(buf)); if (ret < 0) { dev_err(dev, "failed to read BME680_P9_LSB_REG\n"); return ret; @@ -276,8 +284,8 @@ static int bme680_read_calib(struct bme680_data *data, } calib->par_gh1 = tmp; - ret = regmap_bulk_read(data->regmap, BME680_GH2_LSB_REG, (u8 *) &buf, - 2); + ret = regmap_bulk_read(data->regmap, BME680_GH2_LSB_REG, + &buf, sizeof(buf)); if (ret < 0) { dev_err(dev, "failed to read BME680_GH2_LSB_REG\n"); return ret; @@ -615,7 +623,7 @@ static int bme680_read_temp(struct bme680_data *data, int *val) return ret; ret = regmap_bulk_read(data->regmap, BME680_REG_TEMP_MSB, - (u8 *) &tmp, 3); + &tmp, 3); if (ret < 0) { dev_err(dev, "failed to read temperature\n"); return ret; @@ -656,7 +664,7 @@ static int bme680_read_press(struct bme680_data *data, return ret; ret = regmap_bulk_read(data->regmap, BME680_REG_PRESS_MSB, - (u8 *) &tmp, 3); + &tmp, 3); if (ret < 0) { dev_err(dev, "failed to read pressure\n"); return ret; @@ -689,7 +697,7 @@ static int bme680_read_humid(struct bme680_data *data, return ret; ret = regmap_bulk_read(data->regmap, BM6880_REG_HUMIDITY_MSB, - (u8 *) &tmp, 2); + &tmp, sizeof(tmp)); if (ret < 0) { dev_err(dev, "failed to read humidity\n"); return ret; @@ -754,7 +762,7 @@ static int bme680_read_gas(struct bme680_data *data, } ret = regmap_bulk_read(data->regmap, BME680_REG_GAS_MSB, - (u8 *) &tmp, 2); + &tmp, sizeof(tmp)); if (ret < 0) { dev_err(dev, "failed to read gas resistance\n"); return ret; diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index 13bdfbbf5f71..cccd4c26dfa4 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -150,8 +150,7 @@ static int st_sensors_set_fullscale(struct iio_dev *indio_dev, unsigned int fs) if (err < 0) goto st_accel_set_fullscale_error; - sdata->current_fullscale = (struct st_sensor_fullscale_avl *) - &sdata->sensor_settings->fs.fs_avl[i]; + sdata->current_fullscale = &sdata->sensor_settings->fs.fs_avl[i]; return err; st_accel_set_fullscale_error: @@ -278,8 +277,7 @@ static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev, !sdata->sensor_settings->drdy_irq.int2.addr) { if (pdata->drdy_int_pin) dev_info(&indio_dev->dev, - "DRDY on pin INT%d specified, but sensor " - "does not support interrupts\n", + "DRDY on pin INT%d specified, but sensor does not support interrupts\n", pdata->drdy_int_pin); return 0; } diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c index 286830fb5d35..b400560bac93 100644 --- a/drivers/iio/common/st_sensors/st_sensors_i2c.c +++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c @@ -49,8 +49,8 @@ int st_sensors_i2c_configure(struct iio_dev *indio_dev, sdata->regmap = devm_regmap_init_i2c(client, config); if (IS_ERR(sdata->regmap)) { - dev_err(&client->dev, "Failed to register i2c regmap (%d)\n", - (int)PTR_ERR(sdata->regmap)); + dev_err(&client->dev, "Failed to register i2c regmap (%ld)\n", + PTR_ERR(sdata->regmap)); return PTR_ERR(sdata->regmap); } diff --git a/drivers/iio/common/st_sensors/st_sensors_spi.c b/drivers/iio/common/st_sensors/st_sensors_spi.c index 1275fb0eda31..ee70515bb89f 100644 --- a/drivers/iio/common/st_sensors/st_sensors_spi.c +++ b/drivers/iio/common/st_sensors/st_sensors_spi.c @@ -44,7 +44,7 @@ static bool st_sensors_is_spi_3_wire(struct spi_device *spi) if (device_property_read_bool(dev, "spi-3wire")) return true; - pdata = (struct st_sensors_platform_data *)dev->platform_data; + pdata = dev_get_platdata(dev); if (pdata && pdata->spi_3wire) return true; @@ -101,8 +101,8 @@ int st_sensors_spi_configure(struct iio_dev *indio_dev, sdata->regmap = devm_regmap_init_spi(spi, config); if (IS_ERR(sdata->regmap)) { - dev_err(&spi->dev, "Failed to register spi regmap (%d)\n", - (int)PTR_ERR(sdata->regmap)); + dev_err(&spi->dev, "Failed to register spi regmap (%ld)\n", + PTR_ERR(sdata->regmap)); return PTR_ERR(sdata->regmap); } diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c index e817537cdfb5..0507283bd4c1 100644 --- a/drivers/iio/common/st_sensors/st_sensors_trigger.c +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c @@ -44,8 +44,7 @@ static int st_sensors_new_samples_available(struct iio_dev *indio_dev, sdata->sensor_settings->drdy_irq.stat_drdy.addr, &status); if (ret < 0) { - dev_err(sdata->dev, - "error checking samples available\n"); + dev_err(sdata->dev, "error checking samples available\n"); return ret; } @@ -148,9 +147,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev, case IRQF_TRIGGER_LOW: if (!sdata->sensor_settings->drdy_irq.addr_ihl) { dev_err(&indio_dev->dev, - "falling/low specified for IRQ " - "but hardware supports only rising/high: " - "will request rising/high\n"); + "falling/low specified for IRQ but hardware supports only rising/high: will request rising/high\n"); if (irq_trig == IRQF_TRIGGER_FALLING) irq_trig = IRQF_TRIGGER_RISING; if (irq_trig == IRQF_TRIGGER_LOW) @@ -163,8 +160,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev, if (err < 0) goto iio_trigger_free; dev_info(&indio_dev->dev, - "interrupts on the falling edge or " - "active low level\n"); + "interrupts on the falling edge or active low level\n"); } break; case IRQF_TRIGGER_RISING: @@ -178,8 +174,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev, default: /* This is the most preferred mode, if possible */ dev_err(&indio_dev->dev, - "unsupported IRQ trigger specified (%lx), enforce " - "rising edge\n", irq_trig); + "unsupported IRQ trigger specified (%lx), enforce rising edge\n", irq_trig); irq_trig = IRQF_TRIGGER_RISING; } diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig index 7eaf77707b0b..6daeddf37f60 100644 --- a/drivers/iio/gyro/Kconfig +++ b/drivers/iio/gyro/Kconfig @@ -61,7 +61,7 @@ config BMG160 help Say yes here to build support for BOSCH BMG160 Tri-axis Gyro Sensor driver connected via I2C or SPI. This driver also supports BMI055 - gyroscope. + and BMI088 gyroscope. This driver can also be built as a module. If so, the module will be called bmg160_i2c or bmg160_spi. diff --git a/drivers/iio/gyro/bmg160_i2c.c b/drivers/iio/gyro/bmg160_i2c.c index 4fc9c6a3321f..b3fa46bd02cb 100644 --- a/drivers/iio/gyro/bmg160_i2c.c +++ b/drivers/iio/gyro/bmg160_i2c.c @@ -21,8 +21,8 @@ static int bmg160_i2c_probe(struct i2c_client *client, regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf); if (IS_ERR(regmap)) { - dev_err(&client->dev, "Failed to register i2c regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&client->dev, "Failed to register i2c regmap: %pe\n", + regmap); return PTR_ERR(regmap); } @@ -42,6 +42,7 @@ static int bmg160_i2c_remove(struct i2c_client *client) static const struct acpi_device_id bmg160_acpi_match[] = { {"BMG0160", 0}, {"BMI055B", 0}, + {"BMI088B", 0}, {}, }; @@ -50,6 +51,7 @@ MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match); static const struct i2c_device_id bmg160_i2c_id[] = { {"bmg160", 0}, {"bmi055_gyro", 0}, + {"bmi088_gyro", 0}, {} }; diff --git a/drivers/iio/gyro/bmg160_spi.c b/drivers/iio/gyro/bmg160_spi.c index 182a59c42507..745962e1e423 100644 --- a/drivers/iio/gyro/bmg160_spi.c +++ b/drivers/iio/gyro/bmg160_spi.c @@ -19,8 +19,8 @@ static int bmg160_spi_probe(struct spi_device *spi) regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf); if (IS_ERR(regmap)) { - dev_err(&spi->dev, "Failed to register spi regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&spi->dev, "Failed to register spi regmap: %pe\n", + regmap); return PTR_ERR(regmap); } @@ -37,6 +37,7 @@ static int bmg160_spi_remove(struct spi_device *spi) static const struct spi_device_id bmg160_spi_id[] = { {"bmg160", 0}, {"bmi055_gyro", 0}, + {"bmi088_gyro", 0}, {} }; diff --git a/drivers/iio/gyro/mpu3050-i2c.c b/drivers/iio/gyro/mpu3050-i2c.c index afa8018b9238..ef5bcbc4b45b 100644 --- a/drivers/iio/gyro/mpu3050-i2c.c +++ b/drivers/iio/gyro/mpu3050-i2c.c @@ -51,8 +51,8 @@ static int mpu3050_i2c_probe(struct i2c_client *client, regmap = devm_regmap_init_i2c(client, &mpu3050_i2c_regmap_config); if (IS_ERR(regmap)) { - dev_err(&client->dev, "Failed to register i2c regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&client->dev, "Failed to register i2c regmap: %pe\n", + regmap); return PTR_ERR(regmap); } diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c index 7465ad62391c..9c92ff7a82be 100644 --- a/drivers/iio/gyro/st_gyro_buffer.c +++ b/drivers/iio/gyro/st_gyro_buffer.c @@ -37,8 +37,7 @@ static int st_gyro_buffer_postenable(struct iio_dev *indio_dev) if (err < 0) return err; - err = st_sensors_set_axis_enable(indio_dev, - (u8)indio_dev->active_scan_mask[0]); + err = st_sensors_set_axis_enable(indio_dev, indio_dev->active_scan_mask[0]); if (err < 0) goto st_gyro_buffer_predisable; diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c index 26c50b24bc08..c8aa051995d3 100644 --- a/drivers/iio/gyro/st_gyro_core.c +++ b/drivers/iio/gyro/st_gyro_core.c @@ -460,6 +460,7 @@ EXPORT_SYMBOL(st_gyro_get_settings); int st_gyro_common_probe(struct iio_dev *indio_dev) { struct st_sensor_data *gdata = iio_priv(indio_dev); + struct st_sensors_platform_data *pdata; int err; indio_dev->modes = INDIO_DIRECT_MODE; @@ -477,12 +478,12 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) indio_dev->channels = gdata->sensor_settings->ch; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; - gdata->current_fullscale = (struct st_sensor_fullscale_avl *) - &gdata->sensor_settings->fs.fs_avl[0]; + gdata->current_fullscale = &gdata->sensor_settings->fs.fs_avl[0]; gdata->odr = gdata->sensor_settings->odr.odr_avl[0].hz; - err = st_sensors_init_sensor(indio_dev, - (struct st_sensors_platform_data *)&gyro_pdata); + pdata = (struct st_sensors_platform_data *)&gyro_pdata; + + err = st_sensors_init_sensor(indio_dev, pdata); if (err < 0) goto st_gyro_power_off; diff --git a/drivers/iio/health/max30100.c b/drivers/iio/health/max30100.c index 84010501762d..546fc37ad75d 100644 --- a/drivers/iio/health/max30100.c +++ b/drivers/iio/health/max30100.c @@ -16,7 +16,7 @@ #include <linux/irq.h> #include <linux/i2c.h> #include <linux/mutex.h> -#include <linux/of.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> @@ -267,11 +267,10 @@ static int max30100_get_current_idx(unsigned int val, int *reg) static int max30100_led_init(struct max30100_data *data) { struct device *dev = &data->client->dev; - struct device_node *np = dev->of_node; unsigned int val[2]; int reg, ret; - ret = of_property_read_u32_array(np, "maxim,led-current-microamp", + ret = device_property_read_u32_array(dev, "maxim,led-current-microamp", (unsigned int *) &val, 2); if (ret) { /* Default to 24 mA RED LED, 50 mA IR LED */ @@ -502,7 +501,7 @@ MODULE_DEVICE_TABLE(of, max30100_dt_ids); static struct i2c_driver max30100_driver = { .driver = { .name = MAX30100_DRV_NAME, - .of_match_table = of_match_ptr(max30100_dt_ids), + .of_match_table = max30100_dt_ids, }, .probe = max30100_probe, .remove = max30100_remove, diff --git a/drivers/iio/humidity/hts221_buffer.c b/drivers/iio/humidity/hts221_buffer.c index 81d50a861c22..9fb3f33614d4 100644 --- a/drivers/iio/humidity/hts221_buffer.c +++ b/drivers/iio/humidity/hts221_buffer.c @@ -74,10 +74,9 @@ static irqreturn_t hts221_trigger_handler_thread(int irq, void *private) int hts221_allocate_trigger(struct hts221_hw *hw) { + struct st_sensors_platform_data *pdata = dev_get_platdata(hw->dev); struct iio_dev *iio_dev = iio_priv_to_dev(hw); bool irq_active_low = false, open_drain = false; - struct device_node *np = hw->dev->of_node; - struct st_sensors_platform_data *pdata; unsigned long irq_type; int err; @@ -106,8 +105,7 @@ int hts221_allocate_trigger(struct hts221_hw *hw) if (err < 0) return err; - pdata = (struct st_sensors_platform_data *)hw->dev->platform_data; - if ((np && of_property_read_bool(np, "drive-open-drain")) || + if (device_property_read_bool(hw->dev, "drive-open-drain") || (pdata && pdata->open_drain)) { irq_type |= IRQF_SHARED; open_drain = true; diff --git a/drivers/iio/humidity/hts221_i2c.c b/drivers/iio/humidity/hts221_i2c.c index 4272b7030c44..cab39c4756f8 100644 --- a/drivers/iio/humidity/hts221_i2c.c +++ b/drivers/iio/humidity/hts221_i2c.c @@ -32,8 +32,8 @@ static int hts221_i2c_probe(struct i2c_client *client, regmap = devm_regmap_init_i2c(client, &hts221_i2c_regmap_config); if (IS_ERR(regmap)) { - dev_err(&client->dev, "Failed to register i2c regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&client->dev, "Failed to register i2c regmap %ld\n", + PTR_ERR(regmap)); return PTR_ERR(regmap); } @@ -63,7 +63,7 @@ static struct i2c_driver hts221_driver = { .driver = { .name = "hts221_i2c", .pm = &hts221_pm_ops, - .of_match_table = of_match_ptr(hts221_i2c_of_match), + .of_match_table = hts221_i2c_of_match, .acpi_match_table = ACPI_PTR(hts221_acpi_match), }, .probe = hts221_i2c_probe, diff --git a/drivers/iio/humidity/hts221_spi.c b/drivers/iio/humidity/hts221_spi.c index 055dba8897d2..729e86e433b1 100644 --- a/drivers/iio/humidity/hts221_spi.c +++ b/drivers/iio/humidity/hts221_spi.c @@ -31,8 +31,8 @@ static int hts221_spi_probe(struct spi_device *spi) regmap = devm_regmap_init_spi(spi, &hts221_spi_regmap_config); if (IS_ERR(regmap)) { - dev_err(&spi->dev, "Failed to register spi regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&spi->dev, "Failed to register spi regmap %ld\n", + PTR_ERR(regmap)); return PTR_ERR(regmap); } @@ -56,7 +56,7 @@ static struct spi_driver hts221_driver = { .driver = { .name = "hts221_spi", .pm = &hts221_pm_ops, - .of_match_table = of_match_ptr(hts221_spi_of_match), + .of_match_table = hts221_spi_of_match, }, .probe = hts221_spi_probe, .id_table = hts221_spi_id_table, diff --git a/drivers/iio/imu/adis.c b/drivers/iio/imu/adis.c index a8afd01de4f3..2e7d0d337f8f 100644 --- a/drivers/iio/imu/adis.c +++ b/drivers/iio/imu/adis.c @@ -419,7 +419,7 @@ int __adis_initial_startup(struct adis *adis) if (prod_id != adis->data->prod_id) dev_warn(&adis->spi->dev, - "Device ID(%u) and product ID(%u) do not match.", + "Device ID(%u) and product ID(%u) do not match.\n", adis->data->prod_id, prod_id); return 0; diff --git a/drivers/iio/imu/adis16400.c b/drivers/iio/imu/adis16400.c index 05e70c1c4835..4445c242709c 100644 --- a/drivers/iio/imu/adis16400.c +++ b/drivers/iio/imu/adis16400.c @@ -258,7 +258,7 @@ static int adis16400_show_product_id(void *arg, u64 *val) return 0; } -DEFINE_SIMPLE_ATTRIBUTE(adis16400_product_id_fops, +DEFINE_DEBUGFS_ATTRIBUTE(adis16400_product_id_fops, adis16400_show_product_id, NULL, "%lld\n"); static int adis16400_show_flash_count(void *arg, u64 *val) @@ -275,7 +275,7 @@ static int adis16400_show_flash_count(void *arg, u64 *val) return 0; } -DEFINE_SIMPLE_ATTRIBUTE(adis16400_flash_count_fops, +DEFINE_DEBUGFS_ATTRIBUTE(adis16400_flash_count_fops, adis16400_show_flash_count, NULL, "%lld\n"); static int adis16400_debugfs_init(struct iio_dev *indio_dev) @@ -283,15 +283,16 @@ static int adis16400_debugfs_init(struct iio_dev *indio_dev) struct adis16400_state *st = iio_priv(indio_dev); if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER) - debugfs_create_file("serial_number", 0400, - indio_dev->debugfs_dentry, st, - &adis16400_serial_number_fops); + debugfs_create_file_unsafe("serial_number", 0400, + indio_dev->debugfs_dentry, st, + &adis16400_serial_number_fops); if (st->variant->flags & ADIS16400_HAS_PROD_ID) - debugfs_create_file("product_id", 0400, + debugfs_create_file_unsafe("product_id", 0400, + indio_dev->debugfs_dentry, st, + &adis16400_product_id_fops); + debugfs_create_file_unsafe("flash_count", 0400, indio_dev->debugfs_dentry, st, - &adis16400_product_id_fops); - debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry, - st, &adis16400_flash_count_fops); + &adis16400_flash_count_fops); return 0; } diff --git a/drivers/iio/imu/adis16460.c b/drivers/iio/imu/adis16460.c index 0027683d0256..0957f5cfe9c0 100644 --- a/drivers/iio/imu/adis16460.c +++ b/drivers/iio/imu/adis16460.c @@ -87,8 +87,8 @@ static int adis16460_show_serial_number(void *arg, u64 *val) return 0; } -DEFINE_SIMPLE_ATTRIBUTE(adis16460_serial_number_fops, - adis16460_show_serial_number, NULL, "0x%.4llx\n"); +DEFINE_DEBUGFS_ATTRIBUTE(adis16460_serial_number_fops, + adis16460_show_serial_number, NULL, "0x%.4llx\n"); static int adis16460_show_product_id(void *arg, u64 *val) { @@ -105,8 +105,8 @@ static int adis16460_show_product_id(void *arg, u64 *val) return 0; } -DEFINE_SIMPLE_ATTRIBUTE(adis16460_product_id_fops, - adis16460_show_product_id, NULL, "%llu\n"); +DEFINE_DEBUGFS_ATTRIBUTE(adis16460_product_id_fops, + adis16460_show_product_id, NULL, "%llu\n"); static int adis16460_show_flash_count(void *arg, u64 *val) { @@ -123,19 +123,22 @@ static int adis16460_show_flash_count(void *arg, u64 *val) return 0; } -DEFINE_SIMPLE_ATTRIBUTE(adis16460_flash_count_fops, - adis16460_show_flash_count, NULL, "%lld\n"); +DEFINE_DEBUGFS_ATTRIBUTE(adis16460_flash_count_fops, + adis16460_show_flash_count, NULL, "%lld\n"); static int adis16460_debugfs_init(struct iio_dev *indio_dev) { struct adis16460 *adis16460 = iio_priv(indio_dev); - debugfs_create_file("serial_number", 0400, indio_dev->debugfs_dentry, - adis16460, &adis16460_serial_number_fops); - debugfs_create_file("product_id", 0400, indio_dev->debugfs_dentry, - adis16460, &adis16460_product_id_fops); - debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry, - adis16460, &adis16460_flash_count_fops); + debugfs_create_file_unsafe("serial_number", 0400, + indio_dev->debugfs_dentry, adis16460, + &adis16460_serial_number_fops); + debugfs_create_file_unsafe("product_id", 0400, + indio_dev->debugfs_dentry, adis16460, + &adis16460_product_id_fops); + debugfs_create_file_unsafe("flash_count", 0400, + indio_dev->debugfs_dentry, adis16460, + &adis16460_flash_count_fops); return 0; } diff --git a/drivers/iio/imu/bmi160/bmi160_i2c.c b/drivers/iio/imu/bmi160/bmi160_i2c.c index e36f5e82d400..26398614eddf 100644 --- a/drivers/iio/imu/bmi160/bmi160_i2c.c +++ b/drivers/iio/imu/bmi160/bmi160_i2c.c @@ -24,8 +24,8 @@ static int bmi160_i2c_probe(struct i2c_client *client, regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config); if (IS_ERR(regmap)) { - dev_err(&client->dev, "Failed to register i2c regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&client->dev, "Failed to register i2c regmap: %pe\n", + regmap); return PTR_ERR(regmap); } diff --git a/drivers/iio/imu/bmi160/bmi160_spi.c b/drivers/iio/imu/bmi160/bmi160_spi.c index c19e3df35559..61389b41c6d9 100644 --- a/drivers/iio/imu/bmi160/bmi160_spi.c +++ b/drivers/iio/imu/bmi160/bmi160_spi.c @@ -20,8 +20,8 @@ static int bmi160_spi_probe(struct spi_device *spi) regmap = devm_regmap_init_spi(spi, &bmi160_regmap_config); if (IS_ERR(regmap)) { - dev_err(&spi->dev, "Failed to register spi regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&spi->dev, "Failed to register spi regmap: %pe\n", + regmap); return PTR_ERR(regmap); } return bmi160_core_probe(&spi->dev, regmap, id->name, true); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c index 2f8560ba4572..c27d06035c8b 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c @@ -135,6 +135,7 @@ int inv_mpu_acpi_create_mux_client(struct i2c_client *client) st->mux_client = NULL; if (ACPI_HANDLE(&client->dev)) { struct i2c_board_info info; + struct i2c_client *mux_client; struct acpi_device *adev; int ret = -1; @@ -172,9 +173,10 @@ int inv_mpu_acpi_create_mux_client(struct i2c_client *client) } else return 0; /* no secondary addr, which is OK */ } - st->mux_client = i2c_new_device(st->muxc->adapter[0], &info); - if (!st->mux_client) - return -ENODEV; + mux_client = i2c_new_client_device(st->muxc->adapter[0], &info); + if (IS_ERR(mux_client)) + return PTR_ERR(mux_client); + st->mux_client = mux_client; } return 0; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 0b8d2f7a0165..4d604fe842e5 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -526,7 +526,7 @@ static int inv_mpu6050_sensor_set(struct inv_mpu6050_state *st, int reg, __be16 d = cpu_to_be16(val); ind = (axis - IIO_MOD_X) * 2; - result = regmap_bulk_write(st->map, reg + ind, (u8 *)&d, 2); + result = regmap_bulk_write(st->map, reg + ind, &d, sizeof(d)); if (result) return -EINVAL; @@ -540,7 +540,7 @@ static int inv_mpu6050_sensor_show(struct inv_mpu6050_state *st, int reg, __be16 d; ind = (axis - IIO_MOD_X) * 2; - result = regmap_bulk_read(st->map, reg + ind, (u8 *)&d, 2); + result = regmap_bulk_read(st->map, reg + ind, &d, sizeof(d)); if (result) return -EINVAL; *val = (short)be16_to_cpup(&d); @@ -1248,12 +1248,31 @@ static const struct attribute_group inv_attribute_group = { .attrs = inv_attributes }; +static int inv_mpu6050_reg_access(struct iio_dev *indio_dev, + unsigned int reg, + unsigned int writeval, + unsigned int *readval) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + int ret; + + mutex_lock(&st->lock); + if (readval) + ret = regmap_read(st->map, reg, readval); + else + ret = regmap_write(st->map, reg, writeval); + mutex_unlock(&st->lock); + + return ret; +} + static const struct iio_info mpu_info = { .read_raw = &inv_mpu6050_read_raw, .write_raw = &inv_mpu6050_write_raw, .write_raw_get_fmt = &inv_write_raw_get_fmt, .attrs = &inv_attribute_group, .validate_trigger = inv_mpu6050_validate_trigger, + .debugfs_reg_access = &inv_mpu6050_reg_access, }; /** diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c index 6993d3b87bb0..28cfae1e61cf 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c @@ -122,8 +122,8 @@ static int inv_mpu_probe(struct i2c_client *client, regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config); if (IS_ERR(regmap)) { - dev_err(&client->dev, "Failed to register i2c regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&client->dev, "Failed to register i2c regmap: %pe\n", + regmap); return PTR_ERR(regmap); } diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c index 673b198e6368..6f968ce687e1 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c @@ -53,8 +53,8 @@ static int inv_mpu_probe(struct spi_device *spi) regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config); if (IS_ERR(regmap)) { - dev_err(&spi->dev, "Failed to register spi regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&spi->dev, "Failed to register spi regmap: %pe\n", + regmap); return PTR_ERR(regmap); } diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h index 41cb20cb3809..b56df409ed0f 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h @@ -111,7 +111,7 @@ struct st_lsm6dsx_odr { u8 val; }; -#define ST_LSM6DSX_ODR_LIST_SIZE 6 +#define ST_LSM6DSX_ODR_LIST_SIZE 8 struct st_lsm6dsx_odr_table_entry { struct st_lsm6dsx_reg reg; diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c index 64ef07a30726..e20d2ca928cc 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c @@ -88,6 +88,69 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = { .len = 6, }, }, + /* LIS3MDL */ + { + .i2c_addr = { 0x1e }, + .wai = { + .addr = 0x0f, + .val = 0x3d, + }, + .id = ST_LSM6DSX_ID_MAGN, + .odr_table = { + .reg = { + .addr = 0x20, + .mask = GENMASK(4, 2), + }, + .odr_avl[0] = { 1000, 0x0 }, + .odr_avl[1] = { 2000, 0x1 }, + .odr_avl[2] = { 3000, 0x2 }, + .odr_avl[3] = { 5000, 0x3 }, + .odr_avl[4] = { 10000, 0x4 }, + .odr_avl[5] = { 20000, 0x5 }, + .odr_avl[6] = { 40000, 0x6 }, + .odr_avl[7] = { 80000, 0x7 }, + .odr_len = 8, + }, + .fs_table = { + .reg = { + .addr = 0x21, + .mask = GENMASK(6, 5), + }, + .fs_avl[0] = { + .gain = 146, + .val = 0x00, + }, /* 4000 uG/LSB */ + .fs_avl[1] = { + .gain = 292, + .val = 0x01, + }, /* 8000 uG/LSB */ + .fs_avl[2] = { + .gain = 438, + .val = 0x02, + }, /* 12000 uG/LSB */ + .fs_avl[3] = { + .gain = 584, + .val = 0x03, + }, /* 16000 uG/LSB */ + .fs_len = 4, + }, + .pwr_table = { + .reg = { + .addr = 0x22, + .mask = GENMASK(1, 0), + }, + .off_val = 0x2, + .on_val = 0x0, + }, + .bdu = { + .addr = 0x24, + .mask = BIT(6), + }, + .out = { + .addr = 0x28, + .len = 6, + }, + }, }; static void st_lsm6dsx_shub_wait_complete(struct st_lsm6dsx_hw *hw) @@ -519,6 +582,36 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev, } static int +st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor, + u32 gain) +{ + const struct st_lsm6dsx_fs_table_entry *fs_table; + int i, err; + + fs_table = &sensor->ext_info.settings->fs_table; + if (!fs_table->reg.addr) + return -ENOTSUPP; + + for (i = 0; i < fs_table->fs_len; i++) { + if (fs_table->fs_avl[i].gain == gain) + break; + } + + if (i == fs_table->fs_len) + return -EINVAL; + + err = st_lsm6dsx_shub_write_with_mask(sensor, fs_table->reg.addr, + fs_table->reg.mask, + fs_table->fs_avl[i].val); + if (err < 0) + return err; + + sensor->gain = gain; + + return 0; +} + +static int st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) @@ -552,6 +645,9 @@ st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev, } break; } + case IIO_CHAN_INFO_SCALE: + err = st_lsm6dsx_shub_set_full_scale(sensor, val2); + break; default: err = -EINVAL; break; diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index 4ada5592aa2b..221157136af6 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -316,8 +316,7 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev, const unsigned long *mask; unsigned long *trialmask; - trialmask = kcalloc(BITS_TO_LONGS(indio_dev->masklength), - sizeof(*trialmask), GFP_KERNEL); + trialmask = bitmap_zalloc(indio_dev->masklength, GFP_KERNEL); if (trialmask == NULL) return -ENOMEM; if (!indio_dev->masklength) { @@ -687,6 +686,13 @@ static int iio_verify_update(struct iio_dev *indio_dev, bool scan_timestamp; unsigned int modes; + if (insert_buffer && + bitmap_empty(insert_buffer->scan_mask, indio_dev->masklength)) { + dev_dbg(&indio_dev->dev, + "At least one scan element must be enabled first\n"); + return -EINVAL; + } + memset(config, 0, sizeof(*config)); config->watermark = ~0; @@ -1277,11 +1283,6 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) indio_dev->groups[indio_dev->groupcounter++] = &buffer->buffer_group; - if (buffer->scan_el_attrs != NULL) { - attr = buffer->scan_el_attrs->attrs; - while (*attr++ != NULL) - attrcount_orig++; - } attrcount = attrcount_orig; INIT_LIST_HEAD(&buffer->scan_el_dev_attr_list); channels = indio_dev->channels; @@ -1319,9 +1320,6 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) ret = -ENOMEM; goto error_free_scan_mask; } - if (buffer->scan_el_attrs) - memcpy(buffer->scan_el_group.attrs, buffer->scan_el_attrs, - sizeof(buffer->scan_el_group.attrs[0])*attrcount_orig); attrn = attrcount_orig; list_for_each_entry(p, &buffer->scan_el_dev_attr_list, l) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 24f7bbff4938..31d7664c5b4f 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -572,46 +572,46 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type, switch (type) { case IIO_VAL_INT: - return snprintf(buf, len, "%d", vals[0]); + return scnprintf(buf, len, "%d", vals[0]); case IIO_VAL_INT_PLUS_MICRO_DB: scale_db = true; /* fall through */ case IIO_VAL_INT_PLUS_MICRO: if (vals[1] < 0) - return snprintf(buf, len, "-%d.%06u%s", abs(vals[0]), + return scnprintf(buf, len, "-%d.%06u%s", abs(vals[0]), -vals[1], scale_db ? " dB" : ""); else - return snprintf(buf, len, "%d.%06u%s", vals[0], vals[1], + return scnprintf(buf, len, "%d.%06u%s", vals[0], vals[1], scale_db ? " dB" : ""); case IIO_VAL_INT_PLUS_NANO: if (vals[1] < 0) - return snprintf(buf, len, "-%d.%09u", abs(vals[0]), + return scnprintf(buf, len, "-%d.%09u", abs(vals[0]), -vals[1]); else - return snprintf(buf, len, "%d.%09u", vals[0], vals[1]); + return scnprintf(buf, len, "%d.%09u", vals[0], vals[1]); case IIO_VAL_FRACTIONAL: tmp = div_s64((s64)vals[0] * 1000000000LL, vals[1]); tmp1 = vals[1]; tmp0 = (int)div_s64_rem(tmp, 1000000000, &tmp1); - return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1)); + return scnprintf(buf, len, "%d.%09u", tmp0, abs(tmp1)); case IIO_VAL_FRACTIONAL_LOG2: tmp = shift_right((s64)vals[0] * 1000000000LL, vals[1]); tmp0 = (int)div_s64_rem(tmp, 1000000000LL, &tmp1); - return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1)); + return scnprintf(buf, len, "%d.%09u", tmp0, abs(tmp1)); case IIO_VAL_INT_MULTIPLE: { int i; int l = 0; for (i = 0; i < size; ++i) { - l += snprintf(&buf[l], len - l, "%d ", vals[i]); + l += scnprintf(&buf[l], len - l, "%d ", vals[i]); if (l >= len) break; } return l; } case IIO_VAL_CHAR: - return snprintf(buf, len, "%c", (char)vals[0]); + return scnprintf(buf, len, "%c", (char)vals[0]); default: return 0; } @@ -682,10 +682,10 @@ static ssize_t iio_format_avail_list(char *buf, const int *vals, if (len >= PAGE_SIZE) return -EFBIG; if (i < length - 1) - len += snprintf(buf + len, PAGE_SIZE - len, + len += scnprintf(buf + len, PAGE_SIZE - len, " "); else - len += snprintf(buf + len, PAGE_SIZE - len, + len += scnprintf(buf + len, PAGE_SIZE - len, "\n"); if (len >= PAGE_SIZE) return -EFBIG; @@ -698,10 +698,10 @@ static ssize_t iio_format_avail_list(char *buf, const int *vals, if (len >= PAGE_SIZE) return -EFBIG; if (i < length / 2 - 1) - len += snprintf(buf + len, PAGE_SIZE - len, + len += scnprintf(buf + len, PAGE_SIZE - len, " "); else - len += snprintf(buf + len, PAGE_SIZE - len, + len += scnprintf(buf + len, PAGE_SIZE - len, "\n"); if (len >= PAGE_SIZE) return -EFBIG; @@ -725,10 +725,10 @@ static ssize_t iio_format_avail_range(char *buf, const int *vals, int type) if (len >= PAGE_SIZE) return -EFBIG; if (i < 2) - len += snprintf(buf + len, PAGE_SIZE - len, + len += scnprintf(buf + len, PAGE_SIZE - len, " "); else - len += snprintf(buf + len, PAGE_SIZE - len, + len += scnprintf(buf + len, PAGE_SIZE - len, "]\n"); if (len >= PAGE_SIZE) return -EFBIG; @@ -741,10 +741,10 @@ static ssize_t iio_format_avail_range(char *buf, const int *vals, int type) if (len >= PAGE_SIZE) return -EFBIG; if (i < 2) - len += snprintf(buf + len, PAGE_SIZE - len, + len += scnprintf(buf + len, PAGE_SIZE - len, " "); else - len += snprintf(buf + len, PAGE_SIZE - len, + len += scnprintf(buf + len, PAGE_SIZE - len, "]\n"); if (len >= PAGE_SIZE) return -EFBIG; @@ -1549,17 +1549,6 @@ static void devm_iio_device_release(struct device *dev, void *res) iio_device_free(*(struct iio_dev **)res); } -int devm_iio_device_match(struct device *dev, void *res, void *data) -{ - struct iio_dev **r = res; - if (!r || !*r) { - WARN_ON(!r || !*r); - return 0; - } - return *r == data; -} -EXPORT_SYMBOL_GPL(devm_iio_device_match); - /** * devm_iio_device_alloc - Resource-managed iio_device_alloc() * @dev: Device to allocate iio_dev for @@ -1568,9 +1557,6 @@ EXPORT_SYMBOL_GPL(devm_iio_device_match); * Managed iio_device_alloc. iio_dev allocated with this function is * automatically freed on driver detach. * - * If an iio_dev allocated with this function needs to be freed separately, - * devm_iio_device_free() must be used. - * * RETURNS: * Pointer to allocated iio_dev on success, NULL on failure. */ @@ -1596,23 +1582,6 @@ struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv) EXPORT_SYMBOL_GPL(devm_iio_device_alloc); /** - * devm_iio_device_free - Resource-managed iio_device_free() - * @dev: Device this iio_dev belongs to - * @iio_dev: the iio_dev associated with the device - * - * Free iio_dev allocated with devm_iio_device_alloc(). - */ -void devm_iio_device_free(struct device *dev, struct iio_dev *iio_dev) -{ - int rc; - - rc = devres_release(dev, devm_iio_device_release, - devm_iio_device_match, iio_dev); - WARN_ON(rc); -} -EXPORT_SYMBOL_GPL(devm_iio_device_free); - -/** * iio_chrdev_open() - chrdev file open for buffer access and ioctls * @inode: Inode structure for identifying the device in the file system * @filp: File structure for iio device used to keep and later access @@ -1714,6 +1683,9 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) { int ret; + if (!indio_dev->info) + return -EINVAL; + indio_dev->driver_module = this_mod; /* If the calling driver did not initialize of_node, do it here */ if (!indio_dev->dev.of_node && indio_dev->dev.parent) @@ -1726,9 +1698,6 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) if (ret < 0) return ret; - if (!indio_dev->info) - return -EINVAL; - /* configure elements for the chrdev */ indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id); @@ -1834,23 +1803,6 @@ int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev, EXPORT_SYMBOL_GPL(__devm_iio_device_register); /** - * devm_iio_device_unregister - Resource-managed iio_device_unregister() - * @dev: Device this iio_dev belongs to - * @indio_dev: the iio_dev associated with the device - * - * Unregister iio_dev registered with devm_iio_device_register(). - */ -void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev) -{ - int rc; - - rc = devres_release(dev, devm_iio_device_unreg, - devm_iio_device_match, indio_dev); - WARN_ON(rc); -} -EXPORT_SYMBOL_GPL(devm_iio_device_unregister); - -/** * iio_device_claim_direct_mode - Keep device in direct mode * @indio_dev: the iio_dev associated with the device * diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index 3908a9a90035..53d1931f6be8 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -585,18 +585,6 @@ static void devm_iio_trigger_release(struct device *dev, void *res) iio_trigger_free(*(struct iio_trigger **)res); } -static int devm_iio_trigger_match(struct device *dev, void *res, void *data) -{ - struct iio_trigger **r = res; - - if (!r || !*r) { - WARN_ON(!r || !*r); - return 0; - } - - return *r == data; -} - /** * devm_iio_trigger_alloc - Resource-managed iio_trigger_alloc() * @dev: Device to allocate iio_trigger for @@ -608,9 +596,6 @@ static int devm_iio_trigger_match(struct device *dev, void *res, void *data) * Managed iio_trigger_alloc. iio_trigger allocated with this function is * automatically freed on driver detach. * - * If an iio_trigger allocated with this function needs to be freed separately, - * devm_iio_trigger_free() must be used. - * * RETURNS: * Pointer to allocated iio_trigger on success, NULL on failure. */ @@ -640,23 +625,6 @@ struct iio_trigger *devm_iio_trigger_alloc(struct device *dev, } EXPORT_SYMBOL_GPL(devm_iio_trigger_alloc); -/** - * devm_iio_trigger_free - Resource-managed iio_trigger_free() - * @dev: Device this iio_dev belongs to - * @iio_trig: the iio_trigger associated with the device - * - * Free iio_trigger allocated with devm_iio_trigger_alloc(). - */ -void devm_iio_trigger_free(struct device *dev, struct iio_trigger *iio_trig) -{ - int rc; - - rc = devres_release(dev, devm_iio_trigger_release, - devm_iio_trigger_match, iio_trig); - WARN_ON(rc); -} -EXPORT_SYMBOL_GPL(devm_iio_trigger_free); - static void devm_iio_trigger_unreg(struct device *dev, void *res) { iio_trigger_unregister(*(struct iio_trigger **)res); @@ -673,9 +641,6 @@ static void devm_iio_trigger_unreg(struct device *dev, void *res) * calls iio_trigger_register() internally. Refer to that function for more * information. * - * If an iio_trigger registered with this function needs to be unregistered - * separately, devm_iio_trigger_unregister() must be used. - * * RETURNS: * 0 on success, negative error number on failure. */ @@ -701,24 +666,6 @@ int __devm_iio_trigger_register(struct device *dev, } EXPORT_SYMBOL_GPL(__devm_iio_trigger_register); -/** - * devm_iio_trigger_unregister - Resource-managed iio_trigger_unregister() - * @dev: device this iio_trigger belongs to - * @trig_info: the trigger associated with the device - * - * Unregister trigger registered with devm_iio_trigger_register(). - */ -void devm_iio_trigger_unregister(struct device *dev, - struct iio_trigger *trig_info) -{ - int rc; - - rc = devres_release(dev, devm_iio_trigger_unreg, devm_iio_trigger_match, - trig_info); - WARN_ON(rc); -} -EXPORT_SYMBOL_GPL(devm_iio_trigger_unregister); - bool iio_trigger_using_own(struct iio_dev *indio_dev) { return indio_dev->trig->attached_own_device; diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 5a8351c9a426..ede99e0d5371 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -360,18 +360,6 @@ static void devm_iio_channel_free(struct device *dev, void *res) iio_channel_release(channel); } -static int devm_iio_channel_match(struct device *dev, void *res, void *data) -{ - struct iio_channel **r = res; - - if (!r || !*r) { - WARN_ON(!r || !*r); - return 0; - } - - return *r == data; -} - struct iio_channel *devm_iio_channel_get(struct device *dev, const char *channel_name) { @@ -394,13 +382,6 @@ struct iio_channel *devm_iio_channel_get(struct device *dev, } EXPORT_SYMBOL_GPL(devm_iio_channel_get); -void devm_iio_channel_release(struct device *dev, struct iio_channel *channel) -{ - WARN_ON(devres_release(dev, devm_iio_channel_free, - devm_iio_channel_match, channel)); -} -EXPORT_SYMBOL_GPL(devm_iio_channel_release); - struct iio_channel *iio_channel_get_all(struct device *dev) { const char *name; @@ -514,14 +495,6 @@ struct iio_channel *devm_iio_channel_get_all(struct device *dev) } EXPORT_SYMBOL_GPL(devm_iio_channel_get_all); -void devm_iio_channel_release_all(struct device *dev, - struct iio_channel *channels) -{ - WARN_ON(devres_release(dev, devm_iio_channel_free_all, - devm_iio_channel_match, channels)); -} -EXPORT_SYMBOL_GPL(devm_iio_channel_release_all); - static int iio_channel_read(struct iio_channel *chan, int *val, int *val2, enum iio_chan_info_enum info) { diff --git a/drivers/iio/light/isl29125.c b/drivers/iio/light/isl29125.c index e37894f0ae0b..95611f5eff01 100644 --- a/drivers/iio/light/isl29125.c +++ b/drivers/iio/light/isl29125.c @@ -213,13 +213,24 @@ static const struct iio_info isl29125_info = { .attrs = &isl29125_attribute_group, }; -static int isl29125_buffer_preenable(struct iio_dev *indio_dev) +static int isl29125_buffer_postenable(struct iio_dev *indio_dev) { struct isl29125_data *data = iio_priv(indio_dev); + int err; + + err = iio_triggered_buffer_postenable(indio_dev); + if (err) + return err; data->conf1 |= ISL29125_MODE_RGB; - return i2c_smbus_write_byte_data(data->client, ISL29125_CONF1, + err = i2c_smbus_write_byte_data(data->client, ISL29125_CONF1, data->conf1); + if (err) { + iio_triggered_buffer_predisable(indio_dev); + return err; + } + + return 0; } static int isl29125_buffer_predisable(struct iio_dev *indio_dev) @@ -227,19 +238,18 @@ static int isl29125_buffer_predisable(struct iio_dev *indio_dev) struct isl29125_data *data = iio_priv(indio_dev); int ret; - ret = iio_triggered_buffer_predisable(indio_dev); - if (ret < 0) - return ret; - data->conf1 &= ~ISL29125_MODE_MASK; data->conf1 |= ISL29125_MODE_PD; - return i2c_smbus_write_byte_data(data->client, ISL29125_CONF1, + ret = i2c_smbus_write_byte_data(data->client, ISL29125_CONF1, data->conf1); + + iio_triggered_buffer_predisable(indio_dev); + + return ret; } static const struct iio_buffer_setup_ops isl29125_buffer_setup_ops = { - .preenable = isl29125_buffer_preenable, - .postenable = &iio_triggered_buffer_postenable, + .postenable = isl29125_buffer_postenable, .predisable = isl29125_buffer_predisable, }; diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c index 71f99d2a22c1..0626927251bb 100644 --- a/drivers/iio/light/ltr501.c +++ b/drivers/iio/light/ltr501.c @@ -1263,7 +1263,7 @@ static irqreturn_t ltr501_trigger_handler(int irq, void *p) if (mask & LTR501_STATUS_ALS_RDY) { ret = regmap_bulk_read(data->regmap, LTR501_ALS_DATA1, - (u8 *)als_buf, sizeof(als_buf)); + als_buf, sizeof(als_buf)); if (ret < 0) return ret; if (test_bit(0, indio_dev->active_scan_mask)) diff --git a/drivers/iio/light/st_uvis25_i2c.c b/drivers/iio/light/st_uvis25_i2c.c index 4889bbeb0c73..400724069d19 100644 --- a/drivers/iio/light/st_uvis25_i2c.c +++ b/drivers/iio/light/st_uvis25_i2c.c @@ -31,8 +31,8 @@ static int st_uvis25_i2c_probe(struct i2c_client *client, regmap = devm_regmap_init_i2c(client, &st_uvis25_i2c_regmap_config); if (IS_ERR(regmap)) { - dev_err(&client->dev, "Failed to register i2c regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&client->dev, "Failed to register i2c regmap %ld\n", + PTR_ERR(regmap)); return PTR_ERR(regmap); } diff --git a/drivers/iio/light/st_uvis25_spi.c b/drivers/iio/light/st_uvis25_spi.c index a9ceae4f58b3..cd3761a3ee3f 100644 --- a/drivers/iio/light/st_uvis25_spi.c +++ b/drivers/iio/light/st_uvis25_spi.c @@ -31,8 +31,8 @@ static int st_uvis25_spi_probe(struct spi_device *spi) regmap = devm_regmap_init_spi(spi, &st_uvis25_spi_regmap_config); if (IS_ERR(regmap)) { - dev_err(&spi->dev, "Failed to register spi regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&spi->dev, "Failed to register spi regmap %ld\n", + PTR_ERR(regmap)); return PTR_ERR(regmap); } diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c index d8c40a83097d..27a5c28aac7f 100644 --- a/drivers/iio/light/tsl2563.c +++ b/drivers/iio/light/tsl2563.c @@ -69,7 +69,7 @@ #define TSL2563_TIMING_GAIN16 0x10 #define TSL2563_TIMING_GAIN1 0x00 -#define TSL2563_INT_DISBLED 0x00 +#define TSL2563_INT_DISABLED 0x00 #define TSL2563_INT_LEVEL 0x10 #define TSL2563_INT_PERSIST(n) ((n) & 0x0F) diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c index be37fcbd4654..9fbde9b71b63 100644 --- a/drivers/iio/light/tsl2772.c +++ b/drivers/iio/light/tsl2772.c @@ -932,7 +932,7 @@ static ssize_t in_illuminance0_target_input_show(struct device *dev, { struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev)); - return snprintf(buf, PAGE_SIZE, "%d\n", chip->settings.als_cal_target); + return scnprintf(buf, PAGE_SIZE, "%d\n", chip->settings.als_cal_target); } static ssize_t in_illuminance0_target_input_store(struct device *dev, @@ -986,7 +986,7 @@ static ssize_t in_illuminance0_lux_table_show(struct device *dev, int offset = 0; while (i < TSL2772_MAX_LUX_TABLE_SIZE) { - offset += snprintf(buf + offset, PAGE_SIZE, "%u,%u,", + offset += scnprintf(buf + offset, PAGE_SIZE - offset, "%u,%u,", chip->tsl2772_device_lux[i].ch0, chip->tsl2772_device_lux[i].ch1); if (chip->tsl2772_device_lux[i].ch0 == 0) { @@ -1000,7 +1000,7 @@ static ssize_t in_illuminance0_lux_table_show(struct device *dev, i++; } - offset += snprintf(buf + offset, PAGE_SIZE, "\n"); + offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n"); return offset; } diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c index ec803c1e81df..985cc39ede8e 100644 --- a/drivers/iio/light/vcnl4000.c +++ b/drivers/iio/light/vcnl4000.c @@ -83,6 +83,7 @@ struct vcnl4000_data { struct mutex vcnl4000_lock; struct vcnl4200_channel vcnl4200_al; struct vcnl4200_channel vcnl4200_ps; + uint32_t near_level; }; struct vcnl4000_chip_spec { @@ -343,6 +344,25 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = { }, }; +static ssize_t vcnl4000_read_near_level(struct iio_dev *indio_dev, + uintptr_t priv, + const struct iio_chan_spec *chan, + char *buf) +{ + struct vcnl4000_data *data = iio_priv(indio_dev); + + return sprintf(buf, "%u\n", data->near_level); +} + +static const struct iio_chan_spec_ext_info vcnl4000_ext_info[] = { + { + .name = "nearlevel", + .shared = IIO_SEPARATE, + .read = vcnl4000_read_near_level, + }, + { /* sentinel */ } +}; + static const struct iio_chan_spec vcnl4000_channels[] = { { .type = IIO_LIGHT, @@ -351,6 +371,7 @@ static const struct iio_chan_spec vcnl4000_channels[] = { }, { .type = IIO_PROXIMITY, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .ext_info = vcnl4000_ext_info, } }; @@ -440,6 +461,10 @@ static int vcnl4000_probe(struct i2c_client *client, dev_dbg(&client->dev, "%s Ambient light/proximity sensor, Rev: %02x\n", data->chip_spec->prod, data->rev); + if (device_property_read_u32(&client->dev, "proximity-near-level", + &data->near_level)) + data->near_level = 0; + indio_dev->dev.parent = &client->dev; indio_dev->info = &vcnl4000_info; indio_dev->channels = vcnl4000_channels; diff --git a/drivers/iio/magnetometer/ak8974.c b/drivers/iio/magnetometer/ak8974.c index d32996702110..372c80c25dd4 100644 --- a/drivers/iio/magnetometer/ak8974.c +++ b/drivers/iio/magnetometer/ak8974.c @@ -746,7 +746,12 @@ static int ak8974_probe(struct i2c_client *i2c, ARRAY_SIZE(ak8974->regs), ak8974->regs); if (ret < 0) { - dev_err(&i2c->dev, "cannot get regulators\n"); + if (ret != -EPROBE_DEFER) + dev_err(&i2c->dev, "cannot get regulators: %d\n", ret); + else + dev_dbg(&i2c->dev, + "regulators unavailable, deferring probe\n"); + return ret; } diff --git a/drivers/iio/magnetometer/bmc150_magn_spi.c b/drivers/iio/magnetometer/bmc150_magn_spi.c index ed9be0490d77..c6ed3ea8460a 100644 --- a/drivers/iio/magnetometer/bmc150_magn_spi.c +++ b/drivers/iio/magnetometer/bmc150_magn_spi.c @@ -22,8 +22,8 @@ static int bmc150_magn_spi_probe(struct spi_device *spi) regmap = devm_regmap_init_spi(spi, &bmc150_magn_regmap_config); if (IS_ERR(regmap)) { - dev_err(&spi->dev, "Failed to register spi regmap %d\n", - (int)PTR_ERR(regmap)); + dev_err(&spi->dev, "Failed to register spi regmap: %pe\n", + regmap); return PTR_ERR(regmap); } return bmc150_magn_probe(&spi->dev, regmap, spi->irq, id->name); diff --git a/drivers/iio/magnetometer/mmc35240.c b/drivers/iio/magnetometer/mmc35240.c index 425cdd07b4e5..1787d656d009 100644 --- a/drivers/iio/magnetometer/mmc35240.c +++ b/drivers/iio/magnetometer/mmc35240.c @@ -239,7 +239,7 @@ static int mmc35240_init(struct mmc35240_data *data) return ret; ret = regmap_bulk_read(data->regmap, MMC35240_OTP_START_ADDR, - (u8 *)otp_data, sizeof(otp_data)); + otp_data, sizeof(otp_data)); if (ret < 0) return ret; @@ -295,7 +295,7 @@ static int mmc35240_read_measurement(struct mmc35240_data *data, __le16 buf[3]) if (ret < 0) return ret; - return regmap_bulk_read(data->regmap, MMC35240_REG_XOUT_L, (u8 *)buf, + return regmap_bulk_read(data->regmap, MMC35240_REG_XOUT_L, buf, 3 * sizeof(__le16)); } diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c index e68184a93a6d..79de721e6015 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -506,8 +506,7 @@ int st_magn_common_probe(struct iio_dev *indio_dev) indio_dev->channels = mdata->sensor_settings->ch; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; - mdata->current_fullscale = (struct st_sensor_fullscale_avl *) - &mdata->sensor_settings->fs.fs_avl[0]; + mdata->current_fullscale = &mdata->sensor_settings->fs.fs_avl[0]; mdata->odr = mdata->sensor_settings->odr.odr_avl[0].hz; err = st_sensors_init_sensor(indio_dev, NULL); diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 29c209cc1108..a33048390118 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -337,8 +337,7 @@ static int bmp280_read_temp(struct bmp280_data *data, __be32 tmp = 0; s32 adc_temp, comp_temp; - ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, - (u8 *) &tmp, 3); + ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, &tmp, 3); if (ret < 0) { dev_err(data->dev, "failed to read temperature\n"); return ret; @@ -377,8 +376,7 @@ static int bmp280_read_press(struct bmp280_data *data, if (ret < 0) return ret; - ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, - (u8 *) &tmp, 3); + ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, &tmp, 3); if (ret < 0) { dev_err(data->dev, "failed to read pressure\n"); return ret; @@ -400,8 +398,8 @@ static int bmp280_read_press(struct bmp280_data *data, static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2) { + __be16 tmp; int ret; - __be16 tmp = 0; s32 adc_humidity; u32 comp_humidity; @@ -410,8 +408,7 @@ static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2) if (ret < 0) return ret; - ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB, - (u8 *) &tmp, 2); + ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB, &tmp, 2); if (ret < 0) { dev_err(data->dev, "failed to read humidity\n"); return ret; @@ -575,57 +572,38 @@ static int bmp280_write_raw(struct iio_dev *indio_dev, return ret; } -static ssize_t bmp280_show_avail(char *buf, const int *vals, const int n) +static int bmp280_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) { - size_t len = 0; - int i; - - for (i = 0; i < n; i++) - len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", vals[i]); - - buf[len - 1] = '\n'; - - return len; -} - -static ssize_t bmp280_show_temp_oversampling_avail(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct bmp280_data *data = iio_priv(dev_to_iio_dev(dev)); - - return bmp280_show_avail(buf, data->chip_info->oversampling_temp_avail, - data->chip_info->num_oversampling_temp_avail); -} - -static ssize_t bmp280_show_press_oversampling_avail(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct bmp280_data *data = iio_priv(dev_to_iio_dev(dev)); + struct bmp280_data *data = iio_priv(indio_dev); - return bmp280_show_avail(buf, data->chip_info->oversampling_press_avail, - data->chip_info->num_oversampling_press_avail); + switch (mask) { + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + switch (chan->type) { + case IIO_PRESSURE: + *vals = data->chip_info->oversampling_press_avail; + *length = data->chip_info->num_oversampling_press_avail; + break; + case IIO_TEMP: + *vals = data->chip_info->oversampling_temp_avail; + *length = data->chip_info->num_oversampling_temp_avail; + break; + default: + return -EINVAL; + } + *type = IIO_VAL_INT; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } } -static IIO_DEVICE_ATTR(in_temp_oversampling_ratio_available, - S_IRUGO, bmp280_show_temp_oversampling_avail, NULL, 0); - -static IIO_DEVICE_ATTR(in_pressure_oversampling_ratio_available, - S_IRUGO, bmp280_show_press_oversampling_avail, NULL, 0); - -static struct attribute *bmp280_attributes[] = { - &iio_dev_attr_in_temp_oversampling_ratio_available.dev_attr.attr, - &iio_dev_attr_in_pressure_oversampling_ratio_available.dev_attr.attr, - NULL, -}; - -static const struct attribute_group bmp280_attrs_group = { - .attrs = bmp280_attributes, -}; - static const struct iio_info bmp280_info = { .read_raw = &bmp280_read_raw, + .read_avail = &bmp280_read_avail, .write_raw = &bmp280_write_raw, - .attrs = &bmp280_attrs_group, }; static int bmp280_chip_config(struct bmp280_data *data) @@ -713,7 +691,7 @@ static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas) unsigned int ctrl; if (data->use_eoc) - init_completion(&data->done); + reinit_completion(&data->done); ret = regmap_write(data->regmap, BMP280_REG_CTRL_MEAS, ctrl_meas); if (ret) @@ -752,14 +730,14 @@ static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas) static int bmp180_read_adc_temp(struct bmp280_data *data, int *val) { + __be16 tmp; int ret; - __be16 tmp = 0; ret = bmp180_measure(data, BMP180_MEAS_TEMP); if (ret) return ret; - ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, (u8 *)&tmp, 2); + ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, &tmp, 2); if (ret) return ret; @@ -856,7 +834,7 @@ static int bmp180_read_adc_press(struct bmp280_data *data, int *val) if (ret) return ret; - ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, (u8 *)&tmp, 3); + ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, &tmp, 3); if (ret) return ret; @@ -965,10 +943,12 @@ static int bmp085_fetch_eoc_irq(struct device *dev, irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq)); if (irq_trig != IRQF_TRIGGER_RISING) { - dev_err(dev, "non-rising trigger given for EOC interrupt, " - "trying to enforce it\n"); + dev_err(dev, "non-rising trigger given for EOC interrupt, trying to enforce it\n"); irq_trig = IRQF_TRIGGER_RISING; } + + init_completion(&data->done); + ret = devm_request_threaded_irq(dev, irq, bmp085_eoc_irq, @@ -1082,9 +1062,9 @@ int bmp280_common_probe(struct device *dev, usleep_range(data->start_up_time, data->start_up_time + 100); /* Bring chip out of reset if there is an assigned GPIO line */ - gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); /* Deassert the signal */ - if (!IS_ERR(gpiod)) { + if (gpiod) { dev_info(dev, "release reset\n"); gpiod_set_value(gpiod, 0); } diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c index bd972cec4830..789a2928504a 100644 --- a/drivers/iio/pressure/st_pressure_core.c +++ b/drivers/iio/pressure/st_pressure_core.c @@ -683,8 +683,7 @@ EXPORT_SYMBOL(st_press_get_settings); int st_press_common_probe(struct iio_dev *indio_dev) { struct st_sensor_data *press_data = iio_priv(indio_dev); - struct st_sensors_platform_data *pdata = - (struct st_sensors_platform_data *)press_data->dev->platform_data; + struct st_sensors_platform_data *pdata = dev_get_platdata(press_data->dev); int err; indio_dev->modes = INDIO_DIRECT_MODE; @@ -708,9 +707,7 @@ int st_press_common_probe(struct iio_dev *indio_dev) indio_dev->channels = press_data->sensor_settings->ch; indio_dev->num_channels = press_data->sensor_settings->num_ch; - press_data->current_fullscale = - (struct st_sensor_fullscale_avl *) - &press_data->sensor_settings->fs.fs_avl[0]; + press_data->current_fullscale = &press_data->sensor_settings->fs.fs_avl[0]; press_data->odr = press_data->sensor_settings->odr.odr_avl[0].hz; diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig index 37606d400805..d57e8cc17e42 100644 --- a/drivers/iio/proximity/Kconfig +++ b/drivers/iio/proximity/Kconfig @@ -101,6 +101,19 @@ config SRF04 To compile this driver as a module, choose M here: the module will be called srf04. +config SX9310 + tristate "SX9310/SX9311 Semtech proximity sensor" + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + select REGMAP_I2C + depends on I2C + help + Say Y here to build a driver for Semtech's SX9310/SX9311 capacitive + proximity/button sensor. + + To compile this driver as a module, choose M here: the + module will be called sx9310. + config SX9500 tristate "SX9500 Semtech proximity sensor" select IIO_BUFFER diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile index c591b019304e..25e5a04da101 100644 --- a/drivers/iio/proximity/Makefile +++ b/drivers/iio/proximity/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_PING) += ping.o obj-$(CONFIG_RFD77402) += rfd77402.o obj-$(CONFIG_SRF04) += srf04.o obj-$(CONFIG_SRF08) += srf08.o +obj-$(CONFIG_SX9310) += sx9310.o obj-$(CONFIG_SX9500) += sx9500.o obj-$(CONFIG_VL53L0X_I2C) += vl53l0x-i2c.o diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c new file mode 100644 index 000000000000..d161f3061e35 --- /dev/null +++ b/drivers/iio/proximity/sx9310.c @@ -0,0 +1,1069 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2018 Google LLC. + * + * Driver for Semtech's SX9310/SX9311 capacitive proximity/button solution. + * Based on SX9500 driver and Semtech driver using the input framework + * <https://my.syncplicity.com/share/teouwsim8niiaud/ + * linux-driver-SX9310_NoSmartHSensing>. + * Reworked April 2019 by Evan Green <evgreen@chromium.org> + * and January 2020 by Daniel Campello <campello@chromium.org> + */ + +#include <linux/acpi.h> +#include <linux/delay.h> +#include <linux/i2c.h> +#include <linux/irq.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/pm.h> +#include <linux/regmap.h> +#include <linux/slab.h> + +#include <linux/iio/buffer.h> +#include <linux/iio/events.h> +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/trigger.h> +#include <linux/iio/triggered_buffer.h> +#include <linux/iio/trigger_consumer.h> + +/* Register definitions. */ +#define SX9310_REG_IRQ_SRC 0x00 +#define SX9310_REG_STAT0 0x01 +#define SX9310_REG_STAT1 0x02 +#define SX9310_REG_IRQ_MSK 0x03 +#define SX9310_CONVDONE_IRQ BIT(3) +#define SX9310_FAR_IRQ BIT(5) +#define SX9310_CLOSE_IRQ BIT(6) +#define SX9310_EVENT_IRQ (SX9310_FAR_IRQ | \ + SX9310_CLOSE_IRQ) +#define SX9310_REG_IRQ_FUNC 0x04 + +#define SX9310_REG_PROX_CTRL0 0x10 +#define SX9310_REG_PROX_CTRL0_PROXSTAT2 0x10 +#define SX9310_REG_PROX_CTRL0_EN_MASK 0x0F +#define SX9310_REG_PROX_CTRL1 0x11 +#define SX9310_REG_PROX_CTRL2 0x12 +#define SX9310_REG_PROX_CTRL2_COMBMODE_ALL 0x80 +#define SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC 0x04 +#define SX9310_REG_PROX_CTRL3 0x13 +#define SX9310_REG_PROX_CTRL3_GAIN0_X8 0x0c +#define SX9310_REG_PROX_CTRL3_GAIN12_X4 0x02 +#define SX9310_REG_PROX_CTRL4 0x14 +#define SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST 0x07 +#define SX9310_REG_PROX_CTRL5 0x15 +#define SX9310_REG_PROX_CTRL5_RANGE_SMALL 0xc0 +#define SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 0x04 +#define SX9310_REG_PROX_CTRL5_RAWFILT_1P25 0x02 +#define SX9310_REG_PROX_CTRL6 0x16 +#define SX9310_REG_PROX_CTRL6_COMP_COMMON 0x20 +#define SX9310_REG_PROX_CTRL7 0x17 +#define SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 0x08 +#define SX9310_REG_PROX_CTRL7_AVGPOSFILT_512 0x05 +#define SX9310_REG_PROX_CTRL8 0x18 +#define SX9310_REG_PROX_CTRL9 0x19 +#define SX9310_REG_PROX_CTRL8_9_PTHRESH12_28 0x40 +#define SX9310_REG_PROX_CTRL8_9_PTHRESH_96 0x88 +#define SX9310_REG_PROX_CTRL8_9_BODYTHRESH_900 0x03 +#define SX9310_REG_PROX_CTRL8_9_BODYTHRESH_1500 0x05 +#define SX9310_REG_PROX_CTRL10 0x1a +#define SX9310_REG_PROX_CTRL10_HYST_6PCT 0x10 +#define SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_8 0x12 +#define SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_8 0x03 +#define SX9310_REG_PROX_CTRL11 0x1b +#define SX9310_REG_PROX_CTRL12 0x1c +#define SX9310_REG_PROX_CTRL13 0x1d +#define SX9310_REG_PROX_CTRL14 0x1e +#define SX9310_REG_PROX_CTRL15 0x1f +#define SX9310_REG_PROX_CTRL16 0x20 +#define SX9310_REG_PROX_CTRL17 0x21 +#define SX9310_REG_PROX_CTRL18 0x22 +#define SX9310_REG_PROX_CTRL19 0x23 +#define SX9310_REG_SAR_CTRL0 0x2a +#define SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES 0x40 +#define SX9310_REG_SAR_CTRL0_SARHYST_8 0x10 +#define SX9310_REG_SAR_CTRL1 0x2b +/* Each increment of the slope register is 0.0078125. */ +#define SX9310_REG_SAR_CTRL1_SLOPE(_hnslope) (_hnslope / 78125) +#define SX9310_REG_SAR_CTRL2 0x2c +#define SX9310_REG_SAR_CTRL2_SAROFFSET_DEFAULT 0x3c + +#define SX9310_REG_SENSOR_SEL 0x30 + +#define SX9310_REG_USE_MSB 0x31 +#define SX9310_REG_USE_LSB 0x32 + +#define SX9310_REG_AVG_MSB 0x33 +#define SX9310_REG_AVG_LSB 0x34 + +#define SX9310_REG_DIFF_MSB 0x35 +#define SX9310_REG_DIFF_LSB 0x36 + +#define SX9310_REG_OFFSET_MSB 0x37 +#define SX9310_REG_OFFSET_LSB 0x38 + +#define SX9310_REG_SAR_MSB 0x39 +#define SX9310_REG_SAR_LSB 0x3a + +#define SX9310_REG_I2CADDR 0x40 +#define SX9310_REG_PAUSE 0x41 +#define SX9310_REG_WHOAMI 0x42 +#define SX9310_WHOAMI_VALUE 0x01 +#define SX9311_WHOAMI_VALUE 0x02 + +#define SX9310_REG_RESET 0x7f +#define SX9310_SOFT_RESET 0xde + +#define SX9310_SCAN_PERIOD_MASK GENMASK(7, 4) +#define SX9310_SCAN_PERIOD_SHIFT 4 + +#define SX9310_COMPSTAT_MASK GENMASK(3, 0) + +/* 4 hardware channels, as defined in STAT0: COMB, CS2, CS1 and CS0. */ +#define SX9310_NUM_CHANNELS 4 +#define SX9310_CHAN_ENABLED_MASK GENMASK(3, 0) + +struct sx9310_data { + /* Serialize access to registers and channel configuration */ + struct mutex mutex; + struct i2c_client *client; + struct iio_trigger *trig; + struct regmap *regmap; + /* + * Last reading of the proximity status for each channel. + * We only send an event to user space when this changes. + */ + bool prox_stat[SX9310_NUM_CHANNELS]; + bool trigger_enabled; + __be16 buffer[SX9310_NUM_CHANNELS + + 4]; /* 64-bit data + 64-bit timestamp */ + /* Remember enabled channels and sample rate during suspend. */ + unsigned int suspend_ctrl0; + struct completion completion; + unsigned int chan_read, chan_event; + int channel_users[SX9310_NUM_CHANNELS]; + int whoami; +}; + +static const struct iio_event_spec sx9310_events[] = { + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_EITHER, + .mask_separate = BIT(IIO_EV_INFO_ENABLE), + }, +}; + +#define SX9310_NAMED_CHANNEL(idx, name) \ + { \ + .type = IIO_PROXIMITY, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .indexed = 1, \ + .channel = idx, \ + .extend_name = name, \ + .address = SX9310_REG_DIFF_MSB, \ + .event_spec = sx9310_events, \ + .num_event_specs = ARRAY_SIZE(sx9310_events), \ + .scan_index = idx, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 12, \ + .storagebits = 16, \ + .endianness = IIO_BE, \ + }, \ + } +#define SX9310_CHANNEL(idx) SX9310_NAMED_CHANNEL(idx, NULL) + +static const struct iio_chan_spec sx9310_channels[] = { + SX9310_CHANNEL(0), /* CS0 */ + SX9310_CHANNEL(1), /* CS1 */ + SX9310_CHANNEL(2), /* CS2 */ + SX9310_NAMED_CHANNEL(3, "comb"), /* COMB */ + + IIO_CHAN_SOFT_TIMESTAMP(4), +}; + +/* + * Each entry contains the integer part (val) and the fractional part, in micro + * seconds. It conforms to the IIO output IIO_VAL_INT_PLUS_MICRO. + */ +static const struct { + int val; + int val2; +} sx9310_samp_freq_table[] = { + { 500, 0 }, /* 0000: Min (no idle time) */ + { 66, 666666 }, /* 0001: 15 ms */ + { 33, 333333 }, /* 0010: 30 ms (Typ.) */ + { 22, 222222 }, /* 0011: 45 ms */ + { 16, 666666 }, /* 0100: 60 ms */ + { 11, 111111 }, /* 0101: 90 ms */ + { 8, 333333 }, /* 0110: 120 ms */ + { 5, 0 }, /* 0111: 200 ms */ + { 2, 500000 }, /* 1000: 400 ms */ + { 1, 666666 }, /* 1001: 600 ms */ + { 1, 250000 }, /* 1010: 800 ms */ + { 1, 0 }, /* 1011: 1 s */ + { 0, 500000 }, /* 1100: 2 s */ + { 0, 333333 }, /* 1101: 3 s */ + { 0, 250000 }, /* 1110: 4 s */ + { 0, 200000 }, /* 1111: 5 s */ +}; +static const unsigned int sx9310_scan_period_table[] = { + 2, 15, 30, 45, 60, 90, 120, 200, + 400, 600, 800, 1000, 2000, 3000, 4000, 5000, +}; + +static ssize_t sx9310_show_samp_freq_avail(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + size_t len = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(sx9310_samp_freq_table); i++) + len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%d ", + sx9310_samp_freq_table[i].val, + sx9310_samp_freq_table[i].val2); + buf[len - 1] = '\n'; + return len; +} +static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(sx9310_show_samp_freq_avail); + +static const struct regmap_range sx9310_writable_reg_ranges[] = { + regmap_reg_range(SX9310_REG_IRQ_MSK, SX9310_REG_IRQ_FUNC), + regmap_reg_range(SX9310_REG_PROX_CTRL0, SX9310_REG_PROX_CTRL19), + regmap_reg_range(SX9310_REG_SAR_CTRL0, SX9310_REG_SAR_CTRL2), + regmap_reg_range(SX9310_REG_SENSOR_SEL, SX9310_REG_SENSOR_SEL), + regmap_reg_range(SX9310_REG_OFFSET_MSB, SX9310_REG_OFFSET_LSB), + regmap_reg_range(SX9310_REG_PAUSE, SX9310_REG_PAUSE), + regmap_reg_range(SX9310_REG_RESET, SX9310_REG_RESET), +}; + +static const struct regmap_access_table sx9310_writeable_regs = { + .yes_ranges = sx9310_writable_reg_ranges, + .n_yes_ranges = ARRAY_SIZE(sx9310_writable_reg_ranges), +}; + +static const struct regmap_range sx9310_readable_reg_ranges[] = { + regmap_reg_range(SX9310_REG_IRQ_SRC, SX9310_REG_IRQ_FUNC), + regmap_reg_range(SX9310_REG_PROX_CTRL0, SX9310_REG_PROX_CTRL19), + regmap_reg_range(SX9310_REG_SAR_CTRL0, SX9310_REG_SAR_CTRL2), + regmap_reg_range(SX9310_REG_SENSOR_SEL, SX9310_REG_SAR_LSB), + regmap_reg_range(SX9310_REG_I2CADDR, SX9310_REG_WHOAMI), + regmap_reg_range(SX9310_REG_RESET, SX9310_REG_RESET), +}; + +static const struct regmap_access_table sx9310_readable_regs = { + .yes_ranges = sx9310_readable_reg_ranges, + .n_yes_ranges = ARRAY_SIZE(sx9310_readable_reg_ranges), +}; + +static const struct regmap_range sx9310_volatile_reg_ranges[] = { + regmap_reg_range(SX9310_REG_IRQ_SRC, SX9310_REG_STAT1), + regmap_reg_range(SX9310_REG_USE_MSB, SX9310_REG_DIFF_LSB), + regmap_reg_range(SX9310_REG_SAR_MSB, SX9310_REG_SAR_LSB), + regmap_reg_range(SX9310_REG_RESET, SX9310_REG_RESET), +}; + +static const struct regmap_access_table sx9310_volatile_regs = { + .yes_ranges = sx9310_volatile_reg_ranges, + .n_yes_ranges = ARRAY_SIZE(sx9310_volatile_reg_ranges), +}; + +static const struct regmap_config sx9310_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + + .max_register = SX9310_REG_RESET, + .cache_type = REGCACHE_RBTREE, + + .wr_table = &sx9310_writeable_regs, + .rd_table = &sx9310_readable_regs, + .volatile_table = &sx9310_volatile_regs, +}; + +static int sx9310_update_chan_en(struct sx9310_data *data, + unsigned int chan_read, + unsigned int chan_event) +{ + int ret; + + if ((data->chan_read | data->chan_event) != (chan_read | chan_event)) { + ret = regmap_update_bits(data->regmap, SX9310_REG_PROX_CTRL0, + SX9310_CHAN_ENABLED_MASK, + chan_read | chan_event); + if (ret) + return ret; + } + data->chan_read = chan_read; + data->chan_event = chan_event; + return 0; +} + +static int sx9310_get_read_channel(struct sx9310_data *data, int channel) +{ + return sx9310_update_chan_en(data, data->chan_read | BIT(channel), + data->chan_event); +} + +static int sx9310_put_read_channel(struct sx9310_data *data, int channel) +{ + return sx9310_update_chan_en(data, data->chan_read & ~BIT(channel), + data->chan_event); +} + +static int sx9310_get_event_channel(struct sx9310_data *data, int channel) +{ + return sx9310_update_chan_en(data, data->chan_read, + data->chan_event | BIT(channel)); +} + +static int sx9310_put_event_channel(struct sx9310_data *data, int channel) +{ + return sx9310_update_chan_en(data, data->chan_read, + data->chan_event & ~BIT(channel)); +} + +static int sx9310_enable_irq(struct sx9310_data *data, unsigned int irq) +{ + return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, irq); +} + +static int sx9310_disable_irq(struct sx9310_data *data, unsigned int irq) +{ + return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, 0); +} + +static int sx9310_read_prox_data(struct sx9310_data *data, + const struct iio_chan_spec *chan, __be16 *val) +{ + int ret; + + ret = regmap_write(data->regmap, SX9310_REG_SENSOR_SEL, chan->channel); + if (ret < 0) + return ret; + + return regmap_bulk_read(data->regmap, chan->address, val, 2); +} + +/* + * If we have no interrupt support, we have to wait for a scan period + * after enabling a channel to get a result. + */ +static int sx9310_wait_for_sample(struct sx9310_data *data) +{ + int ret; + unsigned int val; + + ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &val); + if (ret < 0) + return ret; + + val = (val & SX9310_SCAN_PERIOD_MASK) >> SX9310_SCAN_PERIOD_SHIFT; + + msleep(sx9310_scan_period_table[val]); + + return 0; +} + +static int sx9310_read_proximity(struct sx9310_data *data, + const struct iio_chan_spec *chan, int *val) +{ + int ret = 0; + __be16 rawval; + + mutex_lock(&data->mutex); + + ret = sx9310_get_read_channel(data, chan->channel); + if (ret < 0) + goto out; + + ret = sx9310_enable_irq(data, SX9310_CONVDONE_IRQ); + if (ret < 0) + goto out_put_channel; + + mutex_unlock(&data->mutex); + + if (data->client->irq > 0) { + ret = wait_for_completion_interruptible(&data->completion); + reinit_completion(&data->completion); + } else { + ret = sx9310_wait_for_sample(data); + } + + mutex_lock(&data->mutex); + + if (ret < 0) + goto out_disable_irq; + + ret = sx9310_read_prox_data(data, chan, &rawval); + if (ret < 0) + goto out_disable_irq; + + *val = sign_extend32(be16_to_cpu(rawval), + (chan->address == SX9310_REG_DIFF_MSB ? 11 : 15)); + + ret = sx9310_disable_irq(data, SX9310_CONVDONE_IRQ); + if (ret < 0) + goto out_put_channel; + + ret = sx9310_put_read_channel(data, chan->channel); + if (ret < 0) + goto out; + + mutex_unlock(&data->mutex); + + return IIO_VAL_INT; + +out_disable_irq: + sx9310_disable_irq(data, SX9310_CONVDONE_IRQ); +out_put_channel: + sx9310_put_read_channel(data, chan->channel); +out: + mutex_unlock(&data->mutex); + + return ret; +} + +static int sx9310_read_samp_freq(struct sx9310_data *data, int *val, int *val2) +{ + unsigned int regval; + int ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, ®val); + + if (ret < 0) + return ret; + + regval = (regval & SX9310_SCAN_PERIOD_MASK) >> SX9310_SCAN_PERIOD_SHIFT; + *val = sx9310_samp_freq_table[regval].val; + *val2 = sx9310_samp_freq_table[regval].val2; + + return IIO_VAL_INT_PLUS_MICRO; +} + +static int sx9310_read_raw(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, int *val, + int *val2, long mask) +{ + struct sx9310_data *data = iio_priv(indio_dev); + int ret; + + if (chan->type != IIO_PROXIMITY) + return -EINVAL; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + + ret = sx9310_read_proximity(data, chan, val); + iio_device_release_direct_mode(indio_dev); + return ret; + case IIO_CHAN_INFO_SAMP_FREQ: + return sx9310_read_samp_freq(data, val, val2); + default: + return -EINVAL; + } +} + +static int sx9310_set_samp_freq(struct sx9310_data *data, int val, int val2) +{ + int i, ret; + + for (i = 0; i < ARRAY_SIZE(sx9310_samp_freq_table); i++) + if (val == sx9310_samp_freq_table[i].val && + val2 == sx9310_samp_freq_table[i].val2) + break; + + if (i == ARRAY_SIZE(sx9310_samp_freq_table)) + return -EINVAL; + + mutex_lock(&data->mutex); + + ret = regmap_update_bits(data->regmap, SX9310_REG_PROX_CTRL0, + SX9310_SCAN_PERIOD_MASK, + i << SX9310_SCAN_PERIOD_SHIFT); + + mutex_unlock(&data->mutex); + + return ret; +} + +static int sx9310_write_raw(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, int val, int val2, + long mask) +{ + struct sx9310_data *data = iio_priv(indio_dev); + + if (chan->type != IIO_PROXIMITY) + return -EINVAL; + + if (mask != IIO_CHAN_INFO_SAMP_FREQ) + return -EINVAL; + + return sx9310_set_samp_freq(data, val, val2); +} + +static irqreturn_t sx9310_irq_handler(int irq, void *private) +{ + struct iio_dev *indio_dev = private; + struct sx9310_data *data = iio_priv(indio_dev); + + if (data->trigger_enabled) + iio_trigger_poll(data->trig); + + /* + * Even if no event is enabled, we need to wake the thread to + * clear the interrupt state by reading SX9310_REG_IRQ_SRC. It + * is not possible to do that here because regmap_read takes a + * mutex. + */ + return IRQ_WAKE_THREAD; +} + +static void sx9310_push_events(struct iio_dev *indio_dev) +{ + int ret; + unsigned int val, chan; + struct sx9310_data *data = iio_priv(indio_dev); + s64 timestamp = iio_get_time_ns(indio_dev); + + /* Read proximity state on all channels */ + ret = regmap_read(data->regmap, SX9310_REG_STAT0, &val); + if (ret < 0) { + dev_err(&data->client->dev, "i2c transfer error in irq\n"); + return; + } + + for (chan = 0; chan < SX9310_NUM_CHANNELS; chan++) { + int dir; + u64 ev; + bool new_prox = val & BIT(chan); + + if (!(data->chan_event & BIT(chan))) + continue; + if (new_prox == data->prox_stat[chan]) + /* No change on this channel. */ + continue; + + dir = new_prox ? IIO_EV_DIR_FALLING : IIO_EV_DIR_RISING; + ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, chan, + IIO_EV_TYPE_THRESH, dir); + + iio_push_event(indio_dev, ev, timestamp); + data->prox_stat[chan] = new_prox; + } +} + +static irqreturn_t sx9310_irq_thread_handler(int irq, void *private) +{ + struct iio_dev *indio_dev = private; + struct sx9310_data *data = iio_priv(indio_dev); + int ret; + unsigned int val; + + mutex_lock(&data->mutex); + + ret = regmap_read(data->regmap, SX9310_REG_IRQ_SRC, &val); + if (ret < 0) { + dev_err(&data->client->dev, "i2c transfer error in irq\n"); + goto out; + } + + if (val & SX9310_EVENT_IRQ) + sx9310_push_events(indio_dev); + + if (val & SX9310_CONVDONE_IRQ) + complete(&data->completion); + +out: + mutex_unlock(&data->mutex); + + return IRQ_HANDLED; +} + +static int sx9310_read_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) +{ + struct sx9310_data *data = iio_priv(indio_dev); + + return !!(data->chan_event & BIT(chan->channel)); +} + +static int sx9310_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, int state) +{ + struct sx9310_data *data = iio_priv(indio_dev); + int ret; + + /* If the state hasn't changed, there's nothing to do. */ + if (!!(data->chan_event & BIT(chan->channel)) == state) + return 0; + + mutex_lock(&data->mutex); + if (state) { + ret = sx9310_get_event_channel(data, chan->channel); + if (ret < 0) + goto out_unlock; + if (!(data->chan_event & ~BIT(chan->channel))) { + ret = sx9310_enable_irq(data, SX9310_EVENT_IRQ); + if (ret < 0) + sx9310_put_event_channel(data, chan->channel); + } + } else { + ret = sx9310_put_event_channel(data, chan->channel); + if (ret < 0) + goto out_unlock; + if (!data->chan_event) { + ret = sx9310_disable_irq(data, SX9310_EVENT_IRQ); + if (ret < 0) + sx9310_get_event_channel(data, chan->channel); + } + } + +out_unlock: + mutex_unlock(&data->mutex); + return ret; +} + +static struct attribute *sx9310_attributes[] = { + &iio_dev_attr_sampling_frequency_available.dev_attr.attr, + NULL, +}; + +static const struct attribute_group sx9310_attribute_group = { + .attrs = sx9310_attributes, +}; + +static const struct iio_info sx9310_info = { + .attrs = &sx9310_attribute_group, + .read_raw = sx9310_read_raw, + .write_raw = sx9310_write_raw, + .read_event_config = sx9310_read_event_config, + .write_event_config = sx9310_write_event_config, +}; + +static int sx9310_set_trigger_state(struct iio_trigger *trig, bool state) +{ + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); + struct sx9310_data *data = iio_priv(indio_dev); + int ret = 0; + + mutex_lock(&data->mutex); + + if (state) + ret = sx9310_enable_irq(data, SX9310_CONVDONE_IRQ); + else if (!data->chan_read) + ret = sx9310_disable_irq(data, SX9310_CONVDONE_IRQ); + if (ret < 0) + goto out; + + data->trigger_enabled = state; + +out: + mutex_unlock(&data->mutex); + + return ret; +} + +static const struct iio_trigger_ops sx9310_trigger_ops = { + .set_trigger_state = sx9310_set_trigger_state, +}; + +static irqreturn_t sx9310_trigger_handler(int irq, void *private) +{ + struct iio_poll_func *pf = private; + struct iio_dev *indio_dev = pf->indio_dev; + struct sx9310_data *data = iio_priv(indio_dev); + __be16 val; + int bit, ret, i = 0; + + mutex_lock(&data->mutex); + + for_each_set_bit(bit, indio_dev->active_scan_mask, + indio_dev->masklength) { + ret = sx9310_read_prox_data(data, &indio_dev->channels[bit], + &val); + if (ret < 0) + goto out; + + data->buffer[i++] = val; + } + + iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, + pf->timestamp); + +out: + mutex_unlock(&data->mutex); + + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + +static int sx9310_buffer_preenable(struct iio_dev *indio_dev) +{ + struct sx9310_data *data = iio_priv(indio_dev); + unsigned int channels = 0; + int bit, ret; + + mutex_lock(&data->mutex); + for_each_set_bit(bit, indio_dev->active_scan_mask, + indio_dev->masklength) + channels |= BIT(indio_dev->channels[bit].channel); + + ret = sx9310_update_chan_en(data, channels, data->chan_event); + mutex_unlock(&data->mutex); + return ret; +} + +static int sx9310_buffer_postdisable(struct iio_dev *indio_dev) +{ + struct sx9310_data *data = iio_priv(indio_dev); + int ret; + + mutex_lock(&data->mutex); + ret = sx9310_update_chan_en(data, 0, data->chan_event); + mutex_unlock(&data->mutex); + return ret; +} + +static const struct iio_buffer_setup_ops sx9310_buffer_setup_ops = { + .preenable = sx9310_buffer_preenable, + .postenable = iio_triggered_buffer_postenable, + .predisable = iio_triggered_buffer_predisable, + .postdisable = sx9310_buffer_postdisable, +}; + +struct sx9310_reg_default { + u8 reg; + u8 def; +}; + +#define SX_INIT(_reg, _def) \ + { \ + .reg = SX9310_REG_##_reg, \ + .def = _def, \ + } + +static const struct sx9310_reg_default sx9310_default_regs[] = { + SX_INIT(IRQ_MSK, 0x00), + SX_INIT(IRQ_FUNC, 0x00), + /* + * The lower 4 bits should not be set as it enable sensors measurements. + * Turning the detection on before the configuration values are set to + * good values can cause the device to return erroneous readings. + */ + SX_INIT(PROX_CTRL0, SX9310_REG_PROX_CTRL0_PROXSTAT2), + SX_INIT(PROX_CTRL1, 0x00), + SX_INIT(PROX_CTRL2, SX9310_REG_PROX_CTRL2_COMBMODE_ALL | + SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC), + SX_INIT(PROX_CTRL3, SX9310_REG_PROX_CTRL3_GAIN0_X8 | + SX9310_REG_PROX_CTRL3_GAIN12_X4), + SX_INIT(PROX_CTRL4, SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST), + SX_INIT(PROX_CTRL5, SX9310_REG_PROX_CTRL5_RANGE_SMALL | + SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 | + SX9310_REG_PROX_CTRL5_RAWFILT_1P25), + SX_INIT(PROX_CTRL6, SX9310_REG_PROX_CTRL6_COMP_COMMON), + SX_INIT(PROX_CTRL7, SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 | + SX9310_REG_PROX_CTRL7_AVGPOSFILT_512), + SX_INIT(PROX_CTRL8, SX9310_REG_PROX_CTRL8_9_PTHRESH_96 | + SX9310_REG_PROX_CTRL8_9_BODYTHRESH_1500), + SX_INIT(PROX_CTRL9, SX9310_REG_PROX_CTRL8_9_PTHRESH12_28 | + SX9310_REG_PROX_CTRL8_9_BODYTHRESH_900), + SX_INIT(PROX_CTRL10, SX9310_REG_PROX_CTRL10_HYST_6PCT | + SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_8 | + SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_8), + SX_INIT(PROX_CTRL11, 0x00), + SX_INIT(PROX_CTRL12, 0x00), + SX_INIT(PROX_CTRL13, 0x00), + SX_INIT(PROX_CTRL14, 0x00), + SX_INIT(PROX_CTRL15, 0x00), + SX_INIT(PROX_CTRL16, 0x00), + SX_INIT(PROX_CTRL17, 0x00), + SX_INIT(PROX_CTRL18, 0x00), + SX_INIT(PROX_CTRL19, 0x00), + SX_INIT(SAR_CTRL0, SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES | + SX9310_REG_SAR_CTRL0_SARHYST_8), + SX_INIT(SAR_CTRL1, SX9310_REG_SAR_CTRL1_SLOPE(10781250)), + SX_INIT(SAR_CTRL2, SX9310_REG_SAR_CTRL2_SAROFFSET_DEFAULT), +}; + +/* Activate all channels and perform an initial compensation. */ +static int sx9310_init_compensation(struct iio_dev *indio_dev) +{ + struct sx9310_data *data = iio_priv(indio_dev); + int i, ret; + unsigned int val; + unsigned int ctrl0; + + ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &ctrl0); + if (ret < 0) + return ret; + + /* run the compensation phase on all channels */ + ret = regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, + ctrl0 | SX9310_REG_PROX_CTRL0_EN_MASK); + if (ret < 0) + return ret; + + for (i = 100; i >= 0; i--) { + msleep(20); + ret = regmap_read(data->regmap, SX9310_REG_STAT1, &val); + if (ret < 0) + goto out; + if (!(val & SX9310_COMPSTAT_MASK)) + break; + } + + if (i < 0) { + dev_err(&data->client->dev, + "initial compensation timed out: 0x%02x", val); + ret = -ETIMEDOUT; + } + +out: + regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0); + return ret; +} + +static int sx9310_init_device(struct iio_dev *indio_dev) +{ + struct sx9310_data *data = iio_priv(indio_dev); + const struct sx9310_reg_default *initval; + int ret; + unsigned int i, val; + + ret = regmap_write(data->regmap, SX9310_REG_RESET, SX9310_SOFT_RESET); + if (ret < 0) + return ret; + + usleep_range(1000, 2000); /* power-up time is ~1ms. */ + + /* Clear reset interrupt state by reading SX9310_REG_IRQ_SRC. */ + ret = regmap_read(data->regmap, SX9310_REG_IRQ_SRC, &val); + if (ret < 0) + return ret; + + /* Program some sane defaults. */ + for (i = 0; i < ARRAY_SIZE(sx9310_default_regs); i++) { + initval = &sx9310_default_regs[i]; + ret = regmap_write(data->regmap, initval->reg, initval->def); + if (ret < 0) + return ret; + } + + return sx9310_init_compensation(indio_dev); +} + +static int sx9310_set_indio_dev_name(struct device *dev, + struct iio_dev *indio_dev, + const struct i2c_device_id *id, int whoami) +{ + const struct acpi_device_id *acpi_id; + + /* id will be NULL when enumerated via ACPI */ + if (id) { + if (id->driver_data != whoami) + dev_err(dev, "WHOAMI does not match i2c_device_id: %s", + id->name); + } else if (ACPI_HANDLE(dev)) { + acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); + if (!acpi_id) + return -ENODEV; + if (acpi_id->driver_data != whoami) + dev_err(dev, "WHOAMI does not match acpi_device_id: %s", + acpi_id->id); + } else + return -ENODEV; + + switch (whoami) { + case SX9310_WHOAMI_VALUE: + indio_dev->name = "sx9310"; + break; + case SX9311_WHOAMI_VALUE: + indio_dev->name = "sx9311"; + break; + default: + dev_err(dev, "unexpected WHOAMI response: %u", whoami); + return -ENODEV; + } + + return 0; +} + +static int sx9310_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int ret; + struct iio_dev *indio_dev; + struct sx9310_data *data; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (indio_dev == NULL) + return -ENOMEM; + + data = iio_priv(indio_dev); + data->client = client; + mutex_init(&data->mutex); + init_completion(&data->completion); + + data->regmap = devm_regmap_init_i2c(client, &sx9310_regmap_config); + if (IS_ERR(data->regmap)) + return PTR_ERR(data->regmap); + + ret = regmap_read(data->regmap, SX9310_REG_WHOAMI, &data->whoami); + if (ret < 0) { + dev_err(&client->dev, "error in reading WHOAMI register: %d", + ret); + return ret; + } + + ret = sx9310_set_indio_dev_name(&client->dev, indio_dev, id, + data->whoami); + if (ret < 0) + return ret; + + ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(&client->dev)); + indio_dev->dev.parent = &client->dev; + indio_dev->channels = sx9310_channels; + indio_dev->num_channels = ARRAY_SIZE(sx9310_channels); + indio_dev->info = &sx9310_info; + indio_dev->modes = INDIO_DIRECT_MODE; + i2c_set_clientdata(client, indio_dev); + + ret = sx9310_init_device(indio_dev); + if (ret < 0) + return ret; + + if (client->irq) { + ret = devm_request_threaded_irq(&client->dev, client->irq, + sx9310_irq_handler, + sx9310_irq_thread_handler, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + "sx9310_event", indio_dev); + if (ret < 0) + return ret; + + data->trig = + devm_iio_trigger_alloc(&client->dev, "%s-dev%d", + indio_dev->name, indio_dev->id); + if (!data->trig) + return -ENOMEM; + + data->trig->dev.parent = &client->dev; + data->trig->ops = &sx9310_trigger_ops; + iio_trigger_set_drvdata(data->trig, indio_dev); + + ret = devm_iio_trigger_register(&client->dev, data->trig); + if (ret) + return ret; + } + + ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, + iio_pollfunc_store_time, + sx9310_trigger_handler, + &sx9310_buffer_setup_ops); + if (ret < 0) + return ret; + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static int __maybe_unused sx9310_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct sx9310_data *data = iio_priv(indio_dev); + u8 ctrl0; + int ret; + + disable_irq_nosync(data->client->irq); + + mutex_lock(&data->mutex); + ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, + &data->suspend_ctrl0); + + if (ret) + goto out; + + ctrl0 = data->suspend_ctrl0 & ~SX9310_REG_PROX_CTRL0_EN_MASK; + ret = regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0); + if (ret) + goto out; + + ret = regmap_write(data->regmap, SX9310_REG_PAUSE, 0); + +out: + mutex_unlock(&data->mutex); + return ret; +} + +static int __maybe_unused sx9310_resume(struct device *dev) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct sx9310_data *data = iio_priv(indio_dev); + int ret; + + mutex_lock(&data->mutex); + ret = regmap_write(data->regmap, SX9310_REG_PAUSE, 1); + if (ret) + goto out; + + ret = regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, + data->suspend_ctrl0); + +out: + mutex_unlock(&data->mutex); + + enable_irq(data->client->irq); + + return ret; +} + +static const struct dev_pm_ops sx9310_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(sx9310_suspend, sx9310_resume) +}; + +static const struct acpi_device_id sx9310_acpi_match[] = { + { "STH9310", SX9310_WHOAMI_VALUE }, + { "STH9311", SX9311_WHOAMI_VALUE }, + {}, +}; +MODULE_DEVICE_TABLE(acpi, sx9310_acpi_match); + +static const struct of_device_id sx9310_of_match[] = { + { .compatible = "semtech,sx9310" }, + { .compatible = "semtech,sx9311" }, + {}, +}; +MODULE_DEVICE_TABLE(of, sx9310_of_match); + +static const struct i2c_device_id sx9310_id[] = { + { "sx9310", SX9310_WHOAMI_VALUE }, + { "sx9311", SX9311_WHOAMI_VALUE }, + {}, +}; +MODULE_DEVICE_TABLE(i2c, sx9310_id); + +static struct i2c_driver sx9310_driver = { + .driver = { + .name = "sx9310", + .acpi_match_table = ACPI_PTR(sx9310_acpi_match), + .of_match_table = of_match_ptr(sx9310_of_match), + .pm = &sx9310_pm_ops, + }, + .probe = sx9310_probe, + .id_table = sx9310_id, +}; +module_i2c_driver(sx9310_driver); + +MODULE_AUTHOR("Gwendal Grignou <gwendal@chromium.org>"); +MODULE_AUTHOR("Daniel Campello <campello@chromium.org>"); +MODULE_DESCRIPTION("Driver for Semtech SX9310/SX9311 proximity sensor"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c index d39c0d6b77f1..8976e8d59826 100644 --- a/drivers/iio/temperature/ltc2983.c +++ b/drivers/iio/temperature/ltc2983.c @@ -390,8 +390,8 @@ static struct ltc2983_custom_sensor *__ltc2983_custom_sensor_new( * For custom steinhart, the full u32 is taken. For all the others * the MSB is discarded. */ - const u8 n_size = (is_steinhart == true) ? 4 : 3; - const u8 e_size = (is_steinhart == true) ? sizeof(u32) : sizeof(u64); + const u8 n_size = is_steinhart ? 4 : 3; + const u8 e_size = is_steinhart ? sizeof(u32) : sizeof(u64); n_entries = of_property_count_elems_of_size(np, propname, e_size); /* n_entries must be an even number */ diff --git a/drivers/iio/trigger/iio-trig-hrtimer.c b/drivers/iio/trigger/iio-trig-hrtimer.c index a5e670726717..f59bf8d58586 100644 --- a/drivers/iio/trigger/iio-trig-hrtimer.c +++ b/drivers/iio/trigger/iio-trig-hrtimer.c @@ -4,7 +4,7 @@ * * Copyright (C) Intuitive Aerial AB * Written by Marten Svanfeldt, marten@intuitiveaerial.com - * Copyright (C) 2012, Analog Device Inc. + * Copyright (C) 2012, Analog Devices Inc. * Author: Lars-Peter Clausen <lars@metafoo.de> * Copyright (C) 2015, Intel Corporation */ diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c index f85ec5b16b65..0198b886d906 100644 --- a/drivers/staging/android/ion/ion_page_pool.c +++ b/drivers/staging/android/ion/ion_page_pool.c @@ -37,7 +37,7 @@ static void ion_page_pool_add(struct ion_page_pool *pool, struct page *page) } mod_node_page_state(page_pgdat(page), NR_KERNEL_MISC_RECLAIMABLE, - 1 << pool->order); + 1 << pool->order); mutex_unlock(&pool->mutex); } @@ -57,7 +57,7 @@ static struct page *ion_page_pool_remove(struct ion_page_pool *pool, bool high) list_del(&page->lru); mod_node_page_state(page_pgdat(page), NR_KERNEL_MISC_RECLAIMABLE, - -(1 << pool->order)); + -(1 << pool->order)); return page; } diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c index 5801067e7c1b..2bb1c2e9cb57 100644 --- a/drivers/staging/axis-fifo/axis-fifo.c +++ b/drivers/staging/axis-fifo/axis-fifo.c @@ -383,8 +383,9 @@ static ssize_t axis_fifo_read(struct file *f, char __user *buf, mutex_lock(&fifo->read_lock); ret = wait_event_interruptible_timeout(fifo->read_queue, ioread32(fifo->base_addr + XLLF_RDFO_OFFSET), - (read_timeout >= 0) ? msecs_to_jiffies(read_timeout) : - MAX_SCHEDULE_TIMEOUT); + (read_timeout >= 0) ? + msecs_to_jiffies(read_timeout) : + MAX_SCHEDULE_TIMEOUT); if (ret <= 0) { if (ret == 0) { @@ -525,9 +526,10 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf, mutex_lock(&fifo->write_lock); ret = wait_event_interruptible_timeout(fifo->write_queue, ioread32(fifo->base_addr + XLLF_TDFV_OFFSET) - >= words_to_write, - (write_timeout >= 0) ? msecs_to_jiffies(write_timeout) : - MAX_SCHEDULE_TIMEOUT); + >= words_to_write, + (write_timeout >= 0) ? + msecs_to_jiffies(write_timeout) : + MAX_SCHEDULE_TIMEOUT); if (ret <= 0) { if (ret == 0) { diff --git a/drivers/staging/comedi/comedi_internal.h b/drivers/staging/comedi/comedi_internal.h index 515f293a5d26..1d54a0dba347 100644 --- a/drivers/staging/comedi/comedi_internal.h +++ b/drivers/staging/comedi/comedi_internal.h @@ -32,8 +32,8 @@ void comedi_buf_map_get(struct comedi_buf_map *bm); int comedi_buf_map_put(struct comedi_buf_map *bm); int comedi_buf_map_access(struct comedi_buf_map *bm, unsigned long offset, void *buf, int len, int write); -struct comedi_buf_map *comedi_buf_map_from_subdev_get( - struct comedi_subdevice *s); +struct comedi_buf_map * +comedi_buf_map_from_subdev_get(struct comedi_subdevice *s); unsigned int comedi_buf_write_n_available(struct comedi_subdevice *s); unsigned int comedi_buf_write_n_allocated(struct comedi_subdevice *s); void comedi_device_cancel_all(struct comedi_device *dev); diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c index 676d1ad1b50d..546ad376df99 100644 --- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c +++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c @@ -1094,7 +1094,8 @@ static int swdev_port_obj_del(struct net_device *netdev, static int ethsw_switchdev_port_attr_set_event(struct net_device *netdev, - struct switchdev_notifier_port_attr_info *port_attr_info) + struct switchdev_notifier_port_attr_info + *port_attr_info) { int err; @@ -1277,7 +1278,8 @@ err_addr_alloc: static int ethsw_switchdev_port_obj_event(unsigned long event, struct net_device *netdev, - struct switchdev_notifier_port_obj_info *port_obj_info) + struct switchdev_notifier_port_obj_info + *port_obj_info) { int err = -EOPNOTSUPP; diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c index f6d715787da8..f3dbe0fe2a67 100644 --- a/drivers/staging/gasket/gasket_page_table.c +++ b/drivers/staging/gasket/gasket_page_table.c @@ -898,7 +898,7 @@ static int gasket_alloc_extended_subtable(struct gasket_page_table *pg_tbl, * * Note that memory for second level page tables is allocated as needed, but * that memory is only freed on the final close of the device file, when the - * page tables are repartitioned, or the the device is removed. If there is an + * page tables are repartitioned, or the device is removed. If there is an * error or if the full range of slots is not available, any memory * allocated for second level page tables remains allocated until final close, * repartition, or device removal. diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c index 5f0e089573a2..af26bc9f184a 100644 --- a/drivers/staging/gasket/gasket_sysfs.c +++ b/drivers/staging/gasket/gasket_sysfs.c @@ -339,6 +339,7 @@ void gasket_sysfs_put_attr(struct device *device, dev_err(device, "Unable to put unknown attribute: %s\n", attr->attr.attr.name); + put_mapping(mapping); } EXPORT_SYMBOL(gasket_sysfs_put_attr); @@ -372,6 +373,7 @@ ssize_t gasket_sysfs_register_store(struct device *device, gasket_dev = mapping->gasket_dev; if (!gasket_dev) { dev_err(device, "Device driver may have been removed\n"); + put_mapping(mapping); return 0; } diff --git a/drivers/staging/gdm724x/gdm_lte.c b/drivers/staging/gdm724x/gdm_lte.c index 354727f0a1fc..eb309190f5be 100644 --- a/drivers/staging/gdm724x/gdm_lte.c +++ b/drivers/staging/gdm724x/gdm_lte.c @@ -172,7 +172,7 @@ static int gdm_lte_emulate_arp(struct sk_buff *skb_in, u32 nic_type) static __sum16 icmp6_checksum(struct ipv6hdr *ipv6, u16 *ptr, int len) { - unsigned short *w = ptr; + unsigned short *w; __wsum sum = 0; int i; u16 pa; diff --git a/drivers/staging/greybus/hid.c b/drivers/staging/greybus/hid.c index 04bfd9110502..ed706f39e87a 100644 --- a/drivers/staging/greybus/hid.c +++ b/drivers/staging/greybus/hid.c @@ -290,9 +290,8 @@ static int gb_hid_parse(struct hid_device *hid) } rdesc = kzalloc(rsize, GFP_KERNEL); - if (!rdesc) { + if (!rdesc) return -ENOMEM; - } ret = gb_hid_get_report_desc(ghid, rdesc); if (ret) { diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c index d6ba25f21d80..d2672b65c3f4 100644 --- a/drivers/staging/greybus/light.c +++ b/drivers/staging/greybus/light.c @@ -1026,7 +1026,8 @@ static int gb_lights_light_config(struct gb_lights *glights, u8 id) light->channels_count = conf.channel_count; light->name = kstrndup(conf.name, NAMES_MAX, GFP_KERNEL); - + if (!light->name) + return -ENOMEM; light->channels = kcalloc(light->channels_count, sizeof(struct gb_channel), GFP_KERNEL); if (!light->channels) diff --git a/drivers/staging/iio/Documentation/overview.txt b/drivers/staging/iio/Documentation/overview.txt index 43f92b06bc3e..ebdc64f451d7 100644 --- a/drivers/staging/iio/Documentation/overview.txt +++ b/drivers/staging/iio/Documentation/overview.txt @@ -34,7 +34,7 @@ turned on or off (if possible) via sysfs interfaces. fifo / ring buffers on the sensor chip. These greatly reduce the load on the host CPU by buffering relatively large numbers of data samples based on an internal sampling clock. Examples include VTI SCA3000 -series and Analog Device ADXL345 accelerometers. Each buffer supports +series and Analog Devices ADXL345 accelerometers. Each buffer supports polling to establish when data is available. * Trigger and software buffer support. In many data analysis diff --git a/drivers/staging/mt7621-dts/mt7621.dtsi b/drivers/staging/mt7621-dts/mt7621.dtsi index 9e5cf68731bb..82aa93634eda 100644 --- a/drivers/staging/mt7621-dts/mt7621.dtsi +++ b/drivers/staging/mt7621-dts/mt7621.dtsi @@ -523,11 +523,10 @@ 0x01000000 0 0x00000000 0x1e160000 0 0x00010000 /* io space */ >; - #interrupt-cells = <1>; - interrupt-map-mask = <0xF0000 0 0 1>; - interrupt-map = <0x10000 0 0 1 &gic GIC_SHARED 4 IRQ_TYPE_LEVEL_HIGH>, - <0x20000 0 0 1 &gic GIC_SHARED 24 IRQ_TYPE_LEVEL_HIGH>, - <0x30000 0 0 1 &gic GIC_SHARED 25 IRQ_TYPE_LEVEL_HIGH>; + interrupt-parent = <&gic>; + interrupts = <GIC_SHARED 4 IRQ_TYPE_LEVEL_HIGH + GIC_SHARED 24 IRQ_TYPE_LEVEL_HIGH + GIC_SHARED 25 IRQ_TYPE_LEVEL_HIGH>; status = "disabled"; diff --git a/drivers/staging/mt7621-pci-phy/mediatek,mt7621-pci-phy.txt b/drivers/staging/mt7621-pci-phy/mediatek,mt7621-pci-phy.txt deleted file mode 100644 index a369d715378b..000000000000 --- a/drivers/staging/mt7621-pci-phy/mediatek,mt7621-pci-phy.txt +++ /dev/null @@ -1,28 +0,0 @@ -Mediatek Mt7621 PCIe PHY - -Required properties: -- compatible: must be "mediatek,mt7621-pci-phy" -- reg: base address and length of the PCIe PHY block -- #phy-cells: must be <1> for pcie0_phy and for pcie1_phy. - -Example: - pcie0_phy: pcie-phy@1e149000 { - compatible = "mediatek,mt7621-pci-phy"; - reg = <0x1e149000 0x0700>; - #phy-cells = <1>; - }; - - pcie1_phy: pcie-phy@1e14a000 { - compatible = "mediatek,mt7621-pci-phy"; - reg = <0x1e14a000 0x0700>; - #phy-cells = <1>; - }; - - /* users of the PCIe phy */ - - pcie: pcie@1e140000 { - ... - ... - phys = <&pcie0_phy 0>, <&pcie0_phy 1>, <&pcie1_phy 0>; - phy-names = "pcie-phy0", "pcie-phy1", "pcie-phy2"; - }; diff --git a/drivers/staging/mt7621-pci-phy/mediatek,mt7621-pci-phy.yaml b/drivers/staging/mt7621-pci-phy/mediatek,mt7621-pci-phy.yaml new file mode 100644 index 000000000000..cf32bbc45b5d --- /dev/null +++ b/drivers/staging/mt7621-pci-phy/mediatek,mt7621-pci-phy.yaml @@ -0,0 +1,36 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/phy/mediatek,mt7621-pci-phy.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Mediatek Mt7621 PCIe PHY Device Tree Bindings + +maintainers: + - Sergio Paracuellos <sergio.paracuellos@gmail.com> + +properties: + compatible: + const: mediatek,mt7621-pci-phy + + reg: + maxItems: 1 + + "#phy-cells": + const: 1 + description: selects if the phy is dual-ported + +required: + - compatible + - reg + - "#phy-cells" + +additionalProperties: false + +examples: + - | + pcie0_phy: pcie-phy@1e149000 { + compatible = "mediatek,mt7621-pci-phy"; + reg = <0x1e149000 0x0700>; + #phy-cells = <1>; + }; diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c index f58e3a51fc71..f961b353c22e 100644 --- a/drivers/staging/mt7621-pci/pci-mt7621.c +++ b/drivers/staging/mt7621-pci/pci-mt7621.c @@ -55,7 +55,7 @@ #define RALINK_PCI_IOBASE 0x002C /* PCICFG virtual bridges */ -#define PCIE_P2P_MAX 3 +#define PCIE_P2P_CNT 3 #define PCIE_P2P_BR_DEVNUM_SHIFT(p) (16 + (p) * 4) #define PCIE_P2P_BR_DEVNUM0_SHIFT PCIE_P2P_BR_DEVNUM_SHIFT(0) #define PCIE_P2P_BR_DEVNUM1_SHIFT PCIE_P2P_BR_DEVNUM_SHIFT(1) @@ -97,6 +97,7 @@ * @pcie_rst: pointer to port reset control * @gpio_rst: gpio reset * @slot: port slot + * @irq: GIC irq * @enabled: indicates if port is enabled */ struct mt7621_pcie_port { @@ -107,6 +108,7 @@ struct mt7621_pcie_port { struct reset_control *pcie_rst; struct gpio_desc *gpio_rst; u32 slot; + int irq; bool enabled; }; @@ -120,6 +122,7 @@ struct mt7621_pcie_port { * @dev: Pointer to PCIe device * @io_map_base: virtual memory base address for io * @ports: pointer to PCIe port information + * @irq_map: irq mapping info according pcie link status * @resets_inverted: depends on chip revision * reset lines are inverted. */ @@ -135,6 +138,7 @@ struct mt7621_pcie { } offset; unsigned long io_map_base; struct list_head ports; + int irq_map[PCIE_P2P_CNT]; bool resets_inverted; }; @@ -279,6 +283,16 @@ static void setup_cm_memory_region(struct mt7621_pcie *pcie) } } +static int mt7621_map_irq(const struct pci_dev *pdev, u8 slot, u8 pin) +{ + struct mt7621_pcie *pcie = pdev->bus->sysdata; + struct device *dev = pcie->dev; + int irq = pcie->irq_map[slot]; + + dev_info(dev, "bus=%d slot=%d irq=%d\n", pdev->bus->number, slot, irq); + return irq; +} + static int mt7621_pci_parse_request_of_pci_ranges(struct mt7621_pcie *pcie) { struct device *dev = pcie->dev; @@ -330,6 +344,7 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie, { struct mt7621_pcie_port *port; struct device *dev = pcie->dev; + struct platform_device *pdev = to_platform_device(dev); struct device_node *pnode = dev->of_node; struct resource regs; char name[10]; @@ -371,6 +386,12 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie, port->slot = slot; port->pcie = pcie; + port->irq = platform_get_irq(pdev, slot); + if (port->irq < 0) { + dev_err(dev, "Failed to get IRQ for PCIe%d\n", slot); + return -ENXIO; + } + INIT_LIST_HEAD(&port->list); list_add_tail(&port->list, &pcie->ports); @@ -502,17 +523,25 @@ static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie) mt7621_pcie_reset_ep_deassert(pcie); + tmp = NULL; list_for_each_entry(port, &pcie->ports, list) { u32 slot = port->slot; if (!mt7621_pcie_port_is_linkup(port)) { dev_err(dev, "pcie%d no card, disable it (RST & CLK)\n", slot); - if (slot != 1) - phy_power_off(port->phy); mt7621_control_assert(port); mt7621_pcie_port_clk_disable(port); port->enabled = false; + + if (slot == 0) { + tmp = port; + continue; + } + + if (slot == 1 && tmp && !tmp->enabled) + phy_power_off(tmp->phy); + } } } @@ -576,14 +605,16 @@ static void mt7621_pcie_enable_ports(struct mt7621_pcie *pcie) static int mt7621_pcie_init_virtual_bridges(struct mt7621_pcie *pcie) { u32 pcie_link_status = 0; - u32 n; - int i; - u32 p2p_br_devnum[PCIE_P2P_MAX]; + u32 n = 0; + int i = 0; + u32 p2p_br_devnum[PCIE_P2P_CNT]; + int irqs[PCIE_P2P_CNT]; struct mt7621_pcie_port *port; list_for_each_entry(port, &pcie->ports, list) { u32 slot = port->slot; + irqs[i++] = port->irq; if (port->enabled) pcie_link_status |= BIT(slot); } @@ -591,12 +622,16 @@ static int mt7621_pcie_init_virtual_bridges(struct mt7621_pcie *pcie) if (pcie_link_status == 0) return -1; - n = 0; - for (i = 0; i < PCIE_P2P_MAX; i++) + /* + * Assign device numbers from zero to the enabled ports, + * then assigning remaining device numbers to any disabled + * ports. + */ + for (i = 0; i < PCIE_P2P_CNT; i++) if (pcie_link_status & BIT(i)) p2p_br_devnum[i] = n++; - for (i = 0; i < PCIE_P2P_MAX; i++) + for (i = 0; i < PCIE_P2P_CNT; i++) if ((pcie_link_status & BIT(i)) == 0) p2p_br_devnum[i] = n++; @@ -606,6 +641,15 @@ static int mt7621_pcie_init_virtual_bridges(struct mt7621_pcie *pcie) (p2p_br_devnum[1] << PCIE_P2P_BR_DEVNUM1_SHIFT) | (p2p_br_devnum[2] << PCIE_P2P_BR_DEVNUM2_SHIFT)); + /* Assign IRQs */ + n = 0; + for (i = 0; i < PCIE_P2P_CNT; i++) + if (pcie_link_status & BIT(i)) + pcie->irq_map[n++] = irqs[i]; + + for (i = n; i < PCIE_P2P_CNT; i++) + pcie->irq_map[i] = -1; + return 0; } @@ -630,7 +674,7 @@ static int mt7621_pcie_register_host(struct pci_host_bridge *host, host->busnr = pcie->busn.start; host->dev.parent = pcie->dev; host->ops = &mt7621_pci_ops; - host->map_irq = of_irq_parse_and_map_pci; + host->map_irq = mt7621_map_irq; host->swizzle_irq = pci_common_swizzle; host->sysdata = pcie; diff --git a/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c b/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c index d0f06790d38f..caaf9e34f1ee 100644 --- a/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c +++ b/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c @@ -220,7 +220,7 @@ static int rt2880_pinmux_index(struct rt2880_priv *p) /* allocate our function and group mapping index buffers */ f = p->func = devm_kcalloc(p->dev, p->func_count, - sizeof(struct rt2880_pmx_func), + sizeof(*p->func), GFP_KERNEL); gpio_func.groups = devm_kcalloc(p->dev, p->group_count, sizeof(int), GFP_KERNEL); diff --git a/drivers/staging/qlge/qlge_dbg.c b/drivers/staging/qlge/qlge_dbg.c index 1795533cbd3a..216b13d8c131 100644 --- a/drivers/staging/qlge/qlge_dbg.c +++ b/drivers/staging/qlge/qlge_dbg.c @@ -1564,7 +1564,7 @@ void ql_dump_stat(struct ql_adapter *qdev) pr_err("qdev->%-24s = %llx\n", #field, (unsigned long long)qdev->field) #define DUMP_QDEV_ARRAY(qdev, type, array, index, field) \ pr_err("%s[%d].%s = " type "\n", \ - #array, index, #field, (qdev)->array[index].field); + #array, index, #field, (qdev)->array[index].field) void ql_dump_qdev(struct ql_adapter *qdev) { int i; diff --git a/drivers/staging/qlge/qlge_main.c b/drivers/staging/qlge/qlge_main.c index c92820f07968..d7e4dfafc1a3 100644 --- a/drivers/staging/qlge/qlge_main.c +++ b/drivers/staging/qlge/qlge_main.c @@ -214,12 +214,13 @@ int ql_write_cfg(struct ql_adapter *qdev, void *ptr, int size, u32 bit, u32 mask; u32 value; - direction = - (bit & (CFG_LRQ | CFG_LR | CFG_LCQ)) ? PCI_DMA_TODEVICE : - PCI_DMA_FROMDEVICE; + if (bit & (CFG_LRQ | CFG_LR | CFG_LCQ)) + direction = DMA_TO_DEVICE; + else + direction = DMA_FROM_DEVICE; - map = pci_map_single(qdev->pdev, ptr, size, direction); - if (pci_dma_mapping_error(qdev->pdev, map)) { + map = dma_map_single(&qdev->pdev->dev, ptr, size, direction); + if (dma_mapping_error(&qdev->pdev->dev, map)) { netif_err(qdev, ifup, qdev->ndev, "Couldn't map DMA area.\n"); return -ENOMEM; } @@ -248,7 +249,7 @@ int ql_write_cfg(struct ql_adapter *qdev, void *ptr, int size, u32 bit, status = ql_wait_cfg(qdev, bit); exit: ql_sem_unlock(qdev, SEM_ICB_MASK); /* does flush too */ - pci_unmap_single(qdev->pdev, map, size, direction); + dma_unmap_single(&qdev->pdev->dev, map, size, direction); return status; } @@ -983,14 +984,14 @@ static struct qlge_bq_desc *ql_get_curr_lchunk(struct ql_adapter *qdev, { struct qlge_bq_desc *lbq_desc = qlge_get_curr_buf(&rx_ring->lbq); - pci_dma_sync_single_for_cpu(qdev->pdev, lbq_desc->dma_addr, - qdev->lbq_buf_size, PCI_DMA_FROMDEVICE); + dma_sync_single_for_cpu(&qdev->pdev->dev, lbq_desc->dma_addr, + qdev->lbq_buf_size, DMA_FROM_DEVICE); if ((lbq_desc->p.pg_chunk.offset + qdev->lbq_buf_size) == ql_lbq_block_size(qdev)) { /* last chunk of the master page */ - pci_unmap_page(qdev->pdev, lbq_desc->dma_addr, - ql_lbq_block_size(qdev), PCI_DMA_FROMDEVICE); + dma_unmap_page(&qdev->pdev->dev, lbq_desc->dma_addr, + ql_lbq_block_size(qdev), DMA_FROM_DEVICE); } return lbq_desc; @@ -1036,10 +1037,10 @@ static int qlge_refill_sb(struct rx_ring *rx_ring, return -ENOMEM; skb_reserve(skb, QLGE_SB_PAD); - sbq_desc->dma_addr = pci_map_single(qdev->pdev, skb->data, + sbq_desc->dma_addr = dma_map_single(&qdev->pdev->dev, skb->data, SMALL_BUF_MAP_SIZE, - PCI_DMA_FROMDEVICE); - if (pci_dma_mapping_error(qdev->pdev, sbq_desc->dma_addr)) { + DMA_FROM_DEVICE); + if (dma_mapping_error(&qdev->pdev->dev, sbq_desc->dma_addr)) { netif_err(qdev, ifup, qdev->ndev, "PCI mapping failed.\n"); dev_kfree_skb_any(skb); return -EIO; @@ -1064,10 +1065,10 @@ static int qlge_refill_lb(struct rx_ring *rx_ring, page = alloc_pages(gfp | __GFP_COMP, qdev->lbq_buf_order); if (unlikely(!page)) return -ENOMEM; - dma_addr = pci_map_page(qdev->pdev, page, 0, + dma_addr = dma_map_page(&qdev->pdev->dev, page, 0, ql_lbq_block_size(qdev), - PCI_DMA_FROMDEVICE); - if (pci_dma_mapping_error(qdev->pdev, dma_addr)) { + DMA_FROM_DEVICE); + if (dma_mapping_error(&qdev->pdev->dev, dma_addr)) { __free_pages(page, qdev->lbq_buf_order); netif_err(qdev, drv, qdev->ndev, "PCI mapping failed.\n"); @@ -1224,20 +1225,20 @@ static void ql_unmap_send(struct ql_adapter *qdev, qdev->ndev, "unmapping OAL area.\n"); } - pci_unmap_single(qdev->pdev, + dma_unmap_single(&qdev->pdev->dev, dma_unmap_addr(&tx_ring_desc->map[i], mapaddr), dma_unmap_len(&tx_ring_desc->map[i], maplen), - PCI_DMA_TODEVICE); + DMA_TO_DEVICE); } else { netif_printk(qdev, tx_done, KERN_DEBUG, qdev->ndev, "unmapping frag %d.\n", i); - pci_unmap_page(qdev->pdev, + dma_unmap_page(&qdev->pdev->dev, dma_unmap_addr(&tx_ring_desc->map[i], mapaddr), dma_unmap_len(&tx_ring_desc->map[i], - maplen), PCI_DMA_TODEVICE); + maplen), DMA_TO_DEVICE); } } @@ -1263,9 +1264,9 @@ static int ql_map_send(struct ql_adapter *qdev, /* * Map the skb buffer first. */ - map = pci_map_single(qdev->pdev, skb->data, len, PCI_DMA_TODEVICE); + map = dma_map_single(&qdev->pdev->dev, skb->data, len, DMA_TO_DEVICE); - err = pci_dma_mapping_error(qdev->pdev, map); + err = dma_mapping_error(&qdev->pdev->dev, map); if (err) { netif_err(qdev, tx_queued, qdev->ndev, "PCI mapping failed with error: %d\n", err); @@ -1310,10 +1311,10 @@ static int ql_map_send(struct ql_adapter *qdev, * etc... */ /* Tack on the OAL in the eighth segment of IOCB. */ - map = pci_map_single(qdev->pdev, &tx_ring_desc->oal, + map = dma_map_single(&qdev->pdev->dev, &tx_ring_desc->oal, sizeof(struct oal), - PCI_DMA_TODEVICE); - err = pci_dma_mapping_error(qdev->pdev, map); + DMA_TO_DEVICE); + err = dma_mapping_error(&qdev->pdev->dev, map); if (err) { netif_err(qdev, tx_queued, qdev->ndev, "PCI mapping outbound address list with error: %d\n", @@ -1584,8 +1585,8 @@ static void ql_process_mac_rx_skb(struct ql_adapter *qdev, } skb_reserve(new_skb, NET_IP_ALIGN); - pci_dma_sync_single_for_cpu(qdev->pdev, sbq_desc->dma_addr, - SMALL_BUF_MAP_SIZE, PCI_DMA_FROMDEVICE); + dma_sync_single_for_cpu(&qdev->pdev->dev, sbq_desc->dma_addr, + SMALL_BUF_MAP_SIZE, DMA_FROM_DEVICE); skb_put_data(new_skb, skb->data, length); @@ -1707,8 +1708,8 @@ static struct sk_buff *ql_build_rx_skb(struct ql_adapter *qdev, * Headers fit nicely into a small buffer. */ sbq_desc = qlge_get_curr_buf(&rx_ring->sbq); - pci_unmap_single(qdev->pdev, sbq_desc->dma_addr, - SMALL_BUF_MAP_SIZE, PCI_DMA_FROMDEVICE); + dma_unmap_single(&qdev->pdev->dev, sbq_desc->dma_addr, + SMALL_BUF_MAP_SIZE, DMA_FROM_DEVICE); skb = sbq_desc->p.skb; ql_realign_skb(skb, hdr_len); skb_put(skb, hdr_len); @@ -1737,10 +1738,10 @@ static struct sk_buff *ql_build_rx_skb(struct ql_adapter *qdev, * buffer. */ sbq_desc = qlge_get_curr_buf(&rx_ring->sbq); - pci_dma_sync_single_for_cpu(qdev->pdev, - sbq_desc->dma_addr, - SMALL_BUF_MAP_SIZE, - PCI_DMA_FROMDEVICE); + dma_sync_single_for_cpu(&qdev->pdev->dev, + sbq_desc->dma_addr, + SMALL_BUF_MAP_SIZE, + DMA_FROM_DEVICE); skb_put_data(skb, sbq_desc->p.skb->data, length); } else { netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev, @@ -1750,9 +1751,9 @@ static struct sk_buff *ql_build_rx_skb(struct ql_adapter *qdev, skb = sbq_desc->p.skb; ql_realign_skb(skb, length); skb_put(skb, length); - pci_unmap_single(qdev->pdev, sbq_desc->dma_addr, + dma_unmap_single(&qdev->pdev->dev, sbq_desc->dma_addr, SMALL_BUF_MAP_SIZE, - PCI_DMA_FROMDEVICE); + DMA_FROM_DEVICE); sbq_desc->p.skb = NULL; } } else if (ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_DL) { @@ -1787,9 +1788,9 @@ static struct sk_buff *ql_build_rx_skb(struct ql_adapter *qdev, "No skb available, drop the packet.\n"); return NULL; } - pci_unmap_page(qdev->pdev, lbq_desc->dma_addr, + dma_unmap_page(&qdev->pdev->dev, lbq_desc->dma_addr, qdev->lbq_buf_size, - PCI_DMA_FROMDEVICE); + DMA_FROM_DEVICE); skb_reserve(skb, NET_IP_ALIGN); netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev, "%d bytes of headers and data in large. Chain page to new skb and pull tail.\n", @@ -1820,8 +1821,8 @@ static struct sk_buff *ql_build_rx_skb(struct ql_adapter *qdev, int size, i = 0; sbq_desc = qlge_get_curr_buf(&rx_ring->sbq); - pci_unmap_single(qdev->pdev, sbq_desc->dma_addr, - SMALL_BUF_MAP_SIZE, PCI_DMA_FROMDEVICE); + dma_unmap_single(&qdev->pdev->dev, sbq_desc->dma_addr, + SMALL_BUF_MAP_SIZE, DMA_FROM_DEVICE); if (!(ib_mac_rsp->flags4 & IB_MAC_IOCB_RSP_HS)) { /* * This is an non TCP/UDP IP frame, so @@ -2636,17 +2637,17 @@ static netdev_tx_t qlge_send(struct sk_buff *skb, struct net_device *ndev) static void ql_free_shadow_space(struct ql_adapter *qdev) { if (qdev->rx_ring_shadow_reg_area) { - pci_free_consistent(qdev->pdev, - PAGE_SIZE, - qdev->rx_ring_shadow_reg_area, - qdev->rx_ring_shadow_reg_dma); + dma_free_coherent(&qdev->pdev->dev, + PAGE_SIZE, + qdev->rx_ring_shadow_reg_area, + qdev->rx_ring_shadow_reg_dma); qdev->rx_ring_shadow_reg_area = NULL; } if (qdev->tx_ring_shadow_reg_area) { - pci_free_consistent(qdev->pdev, - PAGE_SIZE, - qdev->tx_ring_shadow_reg_area, - qdev->tx_ring_shadow_reg_dma); + dma_free_coherent(&qdev->pdev->dev, + PAGE_SIZE, + qdev->tx_ring_shadow_reg_area, + qdev->tx_ring_shadow_reg_dma); qdev->tx_ring_shadow_reg_area = NULL; } } @@ -2654,8 +2655,8 @@ static void ql_free_shadow_space(struct ql_adapter *qdev) static int ql_alloc_shadow_space(struct ql_adapter *qdev) { qdev->rx_ring_shadow_reg_area = - pci_zalloc_consistent(qdev->pdev, PAGE_SIZE, - &qdev->rx_ring_shadow_reg_dma); + dma_alloc_coherent(&qdev->pdev->dev, PAGE_SIZE, + &qdev->rx_ring_shadow_reg_dma, GFP_ATOMIC); if (!qdev->rx_ring_shadow_reg_area) { netif_err(qdev, ifup, qdev->ndev, "Allocation of RX shadow space failed.\n"); @@ -2663,8 +2664,8 @@ static int ql_alloc_shadow_space(struct ql_adapter *qdev) } qdev->tx_ring_shadow_reg_area = - pci_zalloc_consistent(qdev->pdev, PAGE_SIZE, - &qdev->tx_ring_shadow_reg_dma); + dma_alloc_coherent(&qdev->pdev->dev, PAGE_SIZE, + &qdev->tx_ring_shadow_reg_dma, GFP_ATOMIC); if (!qdev->tx_ring_shadow_reg_area) { netif_err(qdev, ifup, qdev->ndev, "Allocation of TX shadow space failed.\n"); @@ -2673,10 +2674,10 @@ static int ql_alloc_shadow_space(struct ql_adapter *qdev) return 0; err_wqp_sh_area: - pci_free_consistent(qdev->pdev, - PAGE_SIZE, - qdev->rx_ring_shadow_reg_area, - qdev->rx_ring_shadow_reg_dma); + dma_free_coherent(&qdev->pdev->dev, + PAGE_SIZE, + qdev->rx_ring_shadow_reg_area, + qdev->rx_ring_shadow_reg_dma); return -ENOMEM; } @@ -2702,8 +2703,8 @@ static void ql_free_tx_resources(struct ql_adapter *qdev, struct tx_ring *tx_ring) { if (tx_ring->wq_base) { - pci_free_consistent(qdev->pdev, tx_ring->wq_size, - tx_ring->wq_base, tx_ring->wq_base_dma); + dma_free_coherent(&qdev->pdev->dev, tx_ring->wq_size, + tx_ring->wq_base, tx_ring->wq_base_dma); tx_ring->wq_base = NULL; } kfree(tx_ring->q); @@ -2714,8 +2715,8 @@ static int ql_alloc_tx_resources(struct ql_adapter *qdev, struct tx_ring *tx_ring) { tx_ring->wq_base = - pci_alloc_consistent(qdev->pdev, tx_ring->wq_size, - &tx_ring->wq_base_dma); + dma_alloc_coherent(&qdev->pdev->dev, tx_ring->wq_size, + &tx_ring->wq_base_dma, GFP_ATOMIC); if (!tx_ring->wq_base || tx_ring->wq_base_dma & WQ_ADDR_ALIGN) @@ -2729,8 +2730,8 @@ static int ql_alloc_tx_resources(struct ql_adapter *qdev, return 0; err: - pci_free_consistent(qdev->pdev, tx_ring->wq_size, - tx_ring->wq_base, tx_ring->wq_base_dma); + dma_free_coherent(&qdev->pdev->dev, tx_ring->wq_size, + tx_ring->wq_base, tx_ring->wq_base_dma); tx_ring->wq_base = NULL; pci_alloc_err: netif_err(qdev, ifup, qdev->ndev, "tx_ring alloc failed.\n"); @@ -2748,17 +2749,17 @@ static void ql_free_lbq_buffers(struct ql_adapter *qdev, struct rx_ring *rx_ring &lbq->queue[lbq->next_to_clean]; if (lbq_desc->p.pg_chunk.offset == last_offset) - pci_unmap_page(qdev->pdev, lbq_desc->dma_addr, + dma_unmap_page(&qdev->pdev->dev, lbq_desc->dma_addr, ql_lbq_block_size(qdev), - PCI_DMA_FROMDEVICE); + DMA_FROM_DEVICE); put_page(lbq_desc->p.pg_chunk.page); lbq->next_to_clean = QLGE_BQ_WRAP(lbq->next_to_clean + 1); } if (rx_ring->master_chunk.page) { - pci_unmap_page(qdev->pdev, rx_ring->chunk_dma_addr, - ql_lbq_block_size(qdev), PCI_DMA_FROMDEVICE); + dma_unmap_page(&qdev->pdev->dev, rx_ring->chunk_dma_addr, + ql_lbq_block_size(qdev), DMA_FROM_DEVICE); put_page(rx_ring->master_chunk.page); rx_ring->master_chunk.page = NULL; } @@ -2777,9 +2778,9 @@ static void ql_free_sbq_buffers(struct ql_adapter *qdev, struct rx_ring *rx_ring return; } if (sbq_desc->p.skb) { - pci_unmap_single(qdev->pdev, sbq_desc->dma_addr, + dma_unmap_single(&qdev->pdev->dev, sbq_desc->dma_addr, SMALL_BUF_MAP_SIZE, - PCI_DMA_FROMDEVICE); + DMA_FROM_DEVICE); dev_kfree_skb(sbq_desc->p.skb); sbq_desc->p.skb = NULL; } @@ -2820,8 +2821,8 @@ static int qlge_init_bq(struct qlge_bq *bq) __le64 *buf_ptr; int i; - bq->base = pci_alloc_consistent(qdev->pdev, QLGE_BQ_SIZE, - &bq->base_dma); + bq->base = dma_alloc_coherent(&qdev->pdev->dev, QLGE_BQ_SIZE, + &bq->base_dma, GFP_ATOMIC); if (!bq->base) { netif_err(qdev, ifup, qdev->ndev, "ring %u %s allocation failed.\n", rx_ring->cq_id, @@ -2850,8 +2851,8 @@ static void ql_free_rx_resources(struct ql_adapter *qdev, { /* Free the small buffer queue. */ if (rx_ring->sbq.base) { - pci_free_consistent(qdev->pdev, QLGE_BQ_SIZE, - rx_ring->sbq.base, rx_ring->sbq.base_dma); + dma_free_coherent(&qdev->pdev->dev, QLGE_BQ_SIZE, + rx_ring->sbq.base, rx_ring->sbq.base_dma); rx_ring->sbq.base = NULL; } @@ -2861,8 +2862,8 @@ static void ql_free_rx_resources(struct ql_adapter *qdev, /* Free the large buffer queue. */ if (rx_ring->lbq.base) { - pci_free_consistent(qdev->pdev, QLGE_BQ_SIZE, - rx_ring->lbq.base, rx_ring->lbq.base_dma); + dma_free_coherent(&qdev->pdev->dev, QLGE_BQ_SIZE, + rx_ring->lbq.base, rx_ring->lbq.base_dma); rx_ring->lbq.base = NULL; } @@ -2872,9 +2873,9 @@ static void ql_free_rx_resources(struct ql_adapter *qdev, /* Free the rx queue. */ if (rx_ring->cq_base) { - pci_free_consistent(qdev->pdev, - rx_ring->cq_size, - rx_ring->cq_base, rx_ring->cq_base_dma); + dma_free_coherent(&qdev->pdev->dev, + rx_ring->cq_size, + rx_ring->cq_base, rx_ring->cq_base_dma); rx_ring->cq_base = NULL; } } @@ -2890,8 +2891,8 @@ static int ql_alloc_rx_resources(struct ql_adapter *qdev, * Allocate the completion queue for this rx_ring. */ rx_ring->cq_base = - pci_alloc_consistent(qdev->pdev, rx_ring->cq_size, - &rx_ring->cq_base_dma); + dma_alloc_coherent(&qdev->pdev->dev, rx_ring->cq_size, + &rx_ring->cq_base_dma, GFP_ATOMIC); if (!rx_ring->cq_base) { netif_err(qdev, ifup, qdev->ndev, "rx_ring alloc failed.\n"); @@ -4125,11 +4126,11 @@ static struct net_device_stats *qlge_get_stats(struct net_device /* Get RX stats. */ pkts = mcast = dropped = errors = bytes = 0; for (i = 0; i < qdev->rss_ring_count; i++, rx_ring++) { - pkts += rx_ring->rx_packets; - bytes += rx_ring->rx_bytes; - dropped += rx_ring->rx_dropped; - errors += rx_ring->rx_errors; - mcast += rx_ring->rx_multicast; + pkts += rx_ring->rx_packets; + bytes += rx_ring->rx_bytes; + dropped += rx_ring->rx_dropped; + errors += rx_ring->rx_errors; + mcast += rx_ring->rx_multicast; } ndev->stats.rx_packets = pkts; ndev->stats.rx_bytes = bytes; @@ -4140,9 +4141,9 @@ static struct net_device_stats *qlge_get_stats(struct net_device /* Get TX stats. */ pkts = errors = bytes = 0; for (i = 0; i < qdev->tx_ring_count; i++, tx_ring++) { - pkts += tx_ring->tx_packets; - bytes += tx_ring->tx_bytes; - errors += tx_ring->tx_errors; + pkts += tx_ring->tx_packets; + bytes += tx_ring->tx_bytes; + errors += tx_ring->tx_errors; } ndev->stats.tx_packets = pkts; ndev->stats.tx_bytes = bytes; @@ -4430,13 +4431,13 @@ static int ql_init_device(struct pci_dev *pdev, struct net_device *ndev, } pci_set_master(pdev); - if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { + if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) { set_bit(QL_DMA64, &qdev->flags); - err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); + err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); } else { - err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); + err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); if (!err) - err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); + err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); } if (err) { diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c index 93283c7deec4..817793b9aff2 100644 --- a/drivers/staging/rtl8188eu/core/rtw_ap.c +++ b/drivers/staging/rtl8188eu/core/rtw_ap.c @@ -264,8 +264,10 @@ void expire_timeout_chk(struct adapter *padapter) list_del_init(&psta->asoc_list); pstapriv->asoc_list_cnt--; - DBG_88E("asoc expire %pM, state = 0x%x\n", (psta->hwaddr), psta->state); - updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING); + DBG_88E("asoc expire %pM, state = 0x%x\n", + (psta->hwaddr), psta->state); + updated = ap_free_sta(padapter, psta, true, + WLAN_REASON_DEAUTH_LEAVING); } else { /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */ if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt) && @@ -294,16 +296,21 @@ void expire_timeout_chk(struct adapter *padapter) for (i = 0; i < chk_alive_num; i++) { int ret = _FAIL; - psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]); + psta = rtw_get_stainfo_by_offset(pstapriv, + chk_alive_list[i]); - if (psta->state & WIFI_SLEEP_STATE) - ret = issue_nulldata(padapter, psta->hwaddr, 0, 1, 50); - else - ret = issue_nulldata(padapter, psta->hwaddr, 0, 3, 50); + if (psta->state & WIFI_SLEEP_STATE) { + ret = issue_nulldata(padapter, psta->hwaddr, + 0, 1, 50); + } else { + ret = issue_nulldata(padapter, psta->hwaddr, + 0, 3, 50); + } psta->keep_alive_trycnt++; if (ret == _SUCCESS) { - DBG_88E("asoc check, sta(%pM) is alive\n", (psta->hwaddr)); + DBG_88E("asoc check, sta(%pM) is alive\n", + (psta->hwaddr)); psta->expire_to = pstapriv->expire_to; psta->keep_alive_trycnt = 0; continue; @@ -315,11 +322,13 @@ void expire_timeout_chk(struct adapter *padapter) psta->keep_alive_trycnt = 0; - DBG_88E("asoc expire %pM, state = 0x%x\n", (psta->hwaddr), psta->state); + DBG_88E("asoc expire %pM, state = 0x%x\n", + psta->hwaddr, psta->state); spin_lock_bh(&pstapriv->asoc_list_lock); list_del_init(&psta->asoc_list); pstapriv->asoc_list_cnt--; - updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING); + updated = ap_free_sta(padapter, psta, true, + WLAN_REASON_DEAUTH_LEAVING); spin_unlock_bh(&pstapriv->asoc_list_lock); } @@ -431,7 +440,8 @@ static void update_bmc_sta(struct adapter *padapter) supportRateNum = rtw_get_rateset_len((u8 *)&pcur_network->SupportedRates); network_type = rtw_check_network_type((u8 *)&pcur_network->SupportedRates); - memcpy(psta->bssrateset, &pcur_network->SupportedRates, supportRateNum); + memcpy(psta->bssrateset, &pcur_network->SupportedRates, + supportRateNum); psta->bssratelen = supportRateNum; /* b/g mode ra_bitmap */ @@ -445,7 +455,8 @@ static void update_bmc_sta(struct adapter *padapter) tx_ra_bitmap = 0xf; raid = networktype_to_raid(network_type); - init_rate = get_highest_rate_idx(tx_ra_bitmap & 0x0fffffff) & 0x3f; + init_rate = get_highest_rate_idx(tx_ra_bitmap & 0x0fffffff) & + 0x3f; /* ap mode */ rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true); @@ -456,7 +467,8 @@ static void update_bmc_sta(struct adapter *padapter) arg = psta->mac_id & 0x1f; arg |= BIT(7); tx_ra_bitmap |= ((raid << 28) & 0xf0000000); - DBG_88E("%s, mask = 0x%x, arg = 0x%x\n", __func__, tx_ra_bitmap, arg); + DBG_88E("%s, mask = 0x%x, arg = 0x%x\n", __func__, + tx_ra_bitmap, arg); /* bitmap[0:27] = tx_rate_bitmap */ /* bitmap[28:31]= Rate Adaptive id */ @@ -647,7 +659,8 @@ static void start_bss_network(struct adapter *padapter, u8 *pbuf) rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8)); /* Beacon Control related register */ - rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval)); + rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, + (u8 *)(&bcn_interval)); UpdateBrateTbl(padapter, pnetwork->SupportedRates); rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates); @@ -657,7 +670,10 @@ static void start_bss_network(struct adapter *padapter, u8 *pbuf) Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true); } /* set channel, bwmode */ - p = rtw_get_ie((pnetwork->ies + sizeof(struct ndis_802_11_fixed_ie)), _HT_ADD_INFO_IE_, &ie_len, (pnetwork->ie_length - sizeof(struct ndis_802_11_fixed_ie))); + p = rtw_get_ie(pnetwork->ies + sizeof(struct ndis_802_11_fixed_ie), + _HT_ADD_INFO_IE_, &ie_len, + pnetwork->ie_length - + sizeof(struct ndis_802_11_fixed_ie)); if (p && ie_len) { pht_info = (struct HT_info_element *)(p + 2); @@ -682,7 +698,8 @@ static void start_bss_network(struct adapter *padapter, u8 *pbuf) */ set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode); - DBG_88E("CH =%d, BW =%d, offset =%d\n", cur_channel, cur_bwmode, cur_ch_offset); + DBG_88E("CH =%d, BW =%d, offset =%d\n", cur_channel, cur_bwmode, + cur_ch_offset); /* */ pmlmeext->cur_channel = cur_channel; @@ -771,17 +788,19 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) cap = get_unaligned_le16(ie); /* SSID */ - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_)); + p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, + pbss_network->ie_length - _BEACON_IE_OFFSET_); if (p && ie_len > 0) { memset(&pbss_network->ssid, 0, sizeof(struct ndis_802_11_ssid)); - memcpy(pbss_network->ssid.ssid, (p + 2), ie_len); + memcpy(pbss_network->ssid.ssid, p + 2, ie_len); pbss_network->ssid.ssid_length = ie_len; } /* channel */ channel = 0; pbss_network->Configuration.Length = 0; - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _DSSET_IE_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_)); + p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _DSSET_IE_, &ie_len, + (pbss_network->ie_length - _BEACON_IE_OFFSET_)); if (p && ie_len > 0) channel = *(p + 2); @@ -789,14 +808,16 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX); /* get supported rates */ - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_)); + p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_len, + pbss_network->ie_length - _BEACON_IE_OFFSET_); if (p) { memcpy(supportRate, p + 2, ie_len); supportRateNum = ie_len; } /* get ext_supported rates */ - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ie_len, pbss_network->ie_length - _BEACON_IE_OFFSET_); + p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, + &ie_len, pbss_network->ie_length - _BEACON_IE_OFFSET_); if (p) { memcpy(supportRate + supportRateNum, p + 2, ie_len); supportRateNum += ie_len; @@ -807,7 +828,8 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) rtw_set_supported_rate(pbss_network->SupportedRates, network_type); /* parsing ERP_IE */ - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_)); + p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &ie_len, + pbss_network->ie_length - _BEACON_IE_OFFSET_); if (p && ie_len > 0) ERP_IE_handler(padapter, (struct ndis_802_11_var_ie *)p); @@ -824,7 +846,8 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) pairwise_cipher = 0; psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_; psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_; - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_)); + p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, + pbss_network->ie_length - _BEACON_IE_OFFSET_); if (p && ie_len > 0) { if (rtw_parse_wpa2_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) { psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; @@ -844,7 +867,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_; for (p = ie + _BEACON_IE_OFFSET_;; p += (ie_len + 2)) { p = rtw_get_ie(p, _SSN_IE_1_, &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_ - (ie_len + 2))); + pbss_network->ie_length - _BEACON_IE_OFFSET_ - (ie_len + 2)); if ((p) && (!memcmp(p + 2, OUI1, 4))) { if (rtw_parse_wpa_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) { @@ -869,7 +892,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) if (pregistrypriv->wmm_enable) { for (p = ie + _BEACON_IE_OFFSET_;; p += (ie_len + 2)) { p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_ - (ie_len + 2))); + pbss_network->ie_length - _BEACON_IE_OFFSET_ - (ie_len + 2)); if ((p) && !memcmp(p + 2, WMM_PARA_IE, 6)) { pmlmepriv->qospriv.qos_option = 1; @@ -892,7 +915,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) } /* parsing HT_CAP_IE */ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_)); + pbss_network->ie_length - _BEACON_IE_OFFSET_); if (p && ie_len > 0) { struct ieee80211_ht_cap *pht_cap = (struct ieee80211_ht_cap *)(p + 2); @@ -916,7 +939,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) /* parsing HT_INFO_IE */ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_)); + pbss_network->ie_length - _BEACON_IE_OFFSET_); if (p && ie_len > 0) pHT_info_ie = p; switch (network_type) { @@ -1226,17 +1249,17 @@ void update_beacon(struct adapter *padapter, u8 ie_id, u8 *oui, u8 tx) } /* -op_mode -Set to 0 (HT pure) under the following conditions - - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or - - all STAs in the BSS are 20 MHz HT in 20 MHz BSS -Set to 1 (HT non-member protection) if there may be non-HT STAs - in both the primary and the secondary channel -Set to 2 if only HT STAs are associated in BSS, - however and at least one 20 MHz HT STA is associated -Set to 3 (HT mixed mode) when one or more non-HT STAs are associated - (currently non-GF HT station is considered as non-HT STA also) -*/ + * op_mode + * Set to 0 (HT pure) under the following conditions + * - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or + * - all STAs in the BSS are 20 MHz HT in 20 MHz BSS + * Set to 1 (HT non-member protection) if there may be non-HT STAs + * in both the primary and the secondary channel + * Set to 2 if only HT STAs are associated in BSS, + * however and at least one 20 MHz HT STA is associated + * Set to 3 (HT mixed mode) when one or more non-HT STAs are associated + * (currently non-GF HT station is considered as non-HT STA also) + */ static int rtw_ht_operation_update(struct adapter *padapter) { u16 cur_op_mode, new_op_mode; diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c index c525682d0edf..9bb3ec0cd62f 100644 --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c @@ -370,28 +370,27 @@ static u16 Efuse_GetCurrentSize(struct adapter *pAdapter) while (efuse_OneByteRead(pAdapter, efuse_addr, &efuse_data) && AVAILABLE_EFUSE_ADDR(efuse_addr)) { - if (efuse_data != 0xFF) { - if ((efuse_data & 0x1F) == 0x0F) { /* extended header */ - hoffset = efuse_data; + if (efuse_data == 0xFF) + break; + if ((efuse_data & 0x1F) == 0x0F) { /* extended header */ + hoffset = efuse_data; + efuse_addr++; + efuse_OneByteRead(pAdapter, efuse_addr, &efuse_data); + if ((efuse_data & 0x0F) == 0x0F) { efuse_addr++; - efuse_OneByteRead(pAdapter, efuse_addr, &efuse_data); - if ((efuse_data & 0x0F) == 0x0F) { - efuse_addr++; - continue; - } else { - hoffset = ((hoffset & 0xE0) >> 5) | ((efuse_data & 0xF0) >> 1); - hworden = efuse_data & 0x0F; - } + continue; } else { - hoffset = (efuse_data >> 4) & 0x0F; - hworden = efuse_data & 0x0F; + hoffset = ((hoffset & 0xE0) >> 5) | + ((efuse_data & 0xF0) >> 1); + hworden = efuse_data & 0x0F; } - word_cnts = Efuse_CalculateWordCnts(hworden); - /* read next header */ - efuse_addr = efuse_addr + (word_cnts * 2) + 1; } else { - break; + hoffset = (efuse_data >> 4) & 0x0F; + hworden = efuse_data & 0x0F; } + word_cnts = Efuse_CalculateWordCnts(hworden); + /* read next header */ + efuse_addr = efuse_addr + (word_cnts * 2) + 1; } rtw_hal_set_hwreg(pAdapter, HW_VAR_EFUSE_BYTES, (u8 *)&efuse_addr); diff --git a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c index e186982d5908..caf600eba03b 100644 --- a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c +++ b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c @@ -253,11 +253,11 @@ int rtw_generate_ie(struct registry_priv *pregistrypriv) } /* DS parameter set */ - ie = rtw_set_ie(ie, _DSSET_IE_, 1, (u8 *)&(pdev_network->Configuration.DSConfig), &sz); + ie = rtw_set_ie(ie, _DSSET_IE_, 1, (u8 *)&pdev_network->Configuration.DSConfig, &sz); /* IBSS Parameter Set */ - ie = rtw_set_ie(ie, _IBSS_PARA_IE_, 2, (u8 *)&(pdev_network->Configuration.ATIMWindow), &sz); + ie = rtw_set_ie(ie, _IBSS_PARA_IE_, 2, (u8 *)&pdev_network->Configuration.ATIMWindow, &sz); if (rateLen > 8) ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz); diff --git a/drivers/staging/rtl8188eu/core/rtw_led.c b/drivers/staging/rtl8188eu/core/rtw_led.c index d1406cc99768..32dccae186ca 100644 --- a/drivers/staging/rtl8188eu/core/rtw_led.c +++ b/drivers/staging/rtl8188eu/core/rtw_led.c @@ -90,7 +90,6 @@ static void SwLedBlink1(struct LED_871x *pLed) { struct adapter *padapter = pLed->padapter; struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - u8 bStopBlinking = false; /* Change LED according to BlinkingLedState specified. */ if (pLed->BlinkingLedState == RTW_LED_ON) { @@ -128,9 +127,7 @@ static void SwLedBlink1(struct LED_871x *pLed) break; case LED_BLINK_SCAN: pLed->BlinkTimes--; - if (pLed->BlinkTimes == 0) - bStopBlinking = true; - if (bStopBlinking) { + if (pLed->BlinkTimes == 0) { if (check_fwstate(pmlmepriv, _FW_LINKED)) { pLed->bLedLinkBlinkInProgress = true; pLed->CurrLedState = LED_BLINK_NORMAL; @@ -164,9 +161,7 @@ static void SwLedBlink1(struct LED_871x *pLed) break; case LED_BLINK_TXRX: pLed->BlinkTimes--; - if (pLed->BlinkTimes == 0) - bStopBlinking = true; - if (bStopBlinking) { + if (pLed->BlinkTimes == 0) { if (check_fwstate(pmlmepriv, _FW_LINKED)) { pLed->bLedLinkBlinkInProgress = true; pLed->CurrLedState = LED_BLINK_NORMAL; @@ -188,7 +183,6 @@ static void SwLedBlink1(struct LED_871x *pLed) msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA)); RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState)); } - pLed->BlinkTimes = 0; pLed->bLedBlinkInProgress = false; } else { if (pLed->bLedOn) @@ -208,12 +202,7 @@ static void SwLedBlink1(struct LED_871x *pLed) msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA)); break; case LED_BLINK_WPS_STOP: /* WPS success */ - if (pLed->BlinkingLedState == RTW_LED_ON) - bStopBlinking = false; - else - bStopBlinking = true; - - if (bStopBlinking) { + if (pLed->BlinkingLedState != RTW_LED_ON) { pLed->bLedLinkBlinkInProgress = true; pLed->CurrLedState = LED_BLINK_NORMAL; if (pLed->bLedOn) diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c index 04897cd48370..8d035f67ef61 100644 --- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c @@ -1781,7 +1781,7 @@ static void issue_action_BSSCoexistPacket(struct adapter *padapter) p = rtw_get_ie(pbss_network->ies + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pbss_network->ie_length - _FIXED_IE_LENGTH_); if (!p || len == 0) { /* non-HT */ - if ((pbss_network->Configuration.DSConfig <= 0) || (pbss_network->Configuration.DSConfig > 14)) + if (pbss_network->Configuration.DSConfig <= 0) continue; ICS[0][pbss_network->Configuration.DSConfig] = 1; @@ -1932,11 +1932,11 @@ static void site_survey(struct adapter *padapter) if (pmlmeext->sitesurvey_res.ssid[i].ssid_length) { /* todo: to issue two probe req??? */ issue_probereq(padapter, - &(pmlmeext->sitesurvey_res.ssid[i]), + &pmlmeext->sitesurvey_res.ssid[i], NULL, false); /* msleep(SURVEY_TO>>1); */ issue_probereq(padapter, - &(pmlmeext->sitesurvey_res.ssid[i]), + &pmlmeext->sitesurvey_res.ssid[i], NULL, false); } } diff --git a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c index c4f58507dbfd..c000382c96d9 100644 --- a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c +++ b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c @@ -173,7 +173,7 @@ int ips_leave(struct adapter *padapter) DBG_88E_LEVEL(_drv_info_, "nolinked power save leave\n"); - if ((_WEP40_ == psecuritypriv->dot11PrivacyAlgrthm) || (_WEP104_ == psecuritypriv->dot11PrivacyAlgrthm)) { + if ((psecuritypriv->dot11PrivacyAlgrthm == _WEP40_) || (psecuritypriv->dot11PrivacyAlgrthm == _WEP104_)) { DBG_88E("==>%s, channel(%d), processing(%x)\n", __func__, padapter->mlmeextpriv.cur_channel, pwrpriv->bips_processing); set_channel_bwmode(padapter, padapter->mlmeextpriv.cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20); for (keyid = 0; keyid < 4; keyid++) { diff --git a/drivers/staging/rtl8188eu/hal/fw.c b/drivers/staging/rtl8188eu/hal/fw.c index 486ee4bd4744..3d1d29e9f8e0 100644 --- a/drivers/staging/rtl8188eu/hal/fw.c +++ b/drivers/staging/rtl8188eu/hal/fw.c @@ -111,7 +111,7 @@ static int _rtl88e_fw_free_to_go(struct adapter *adapt) do { value32 = usb_read32(adapt, REG_MCUFWDL); - if (value32 & FWDL_ChkSum_rpt) + if (value32 & FWDL_CHKSUM_RPT) break; } while (counter++ < POLLING_READY_TIMEOUT_COUNT); @@ -146,7 +146,7 @@ int rtl88eu_download_fw(struct adapter *adapt) struct dvobj_priv *dvobj = adapter_to_dvobj(adapt); struct device *device = dvobj_to_dev(dvobj); const struct firmware *fw; - const char fw_name[] = "rtlwifi/rtl8188eufw.bin"; + static const char fw_name[] = "rtlwifi/rtl8188eufw.bin"; struct rtl92c_firmware_header *pfwheader = NULL; u8 *download_data, *fw_data; size_t download_size; @@ -192,7 +192,8 @@ int rtl88eu_download_fw(struct adapter *adapt) rtl88e_firmware_selfreset(adapt); } _rtl88e_enable_fw_download(adapt, true); - usb_write8(adapt, REG_MCUFWDL, usb_read8(adapt, REG_MCUFWDL) | FWDL_ChkSum_rpt); + usb_write8(adapt, REG_MCUFWDL, + usb_read8(adapt, REG_MCUFWDL) | FWDL_CHKSUM_RPT); _rtl88e_write_fw(adapt, download_data, download_size); _rtl88e_enable_fw_download(adapt, false); diff --git a/drivers/staging/rtl8188eu/hal/odm.c b/drivers/staging/rtl8188eu/hal/odm.c index 698377ea60ee..b3cc40527730 100644 --- a/drivers/staging/rtl8188eu/hal/odm.c +++ b/drivers/staging/rtl8188eu/hal/odm.c @@ -193,7 +193,7 @@ void ODM_DMWatchdog(struct odm_dm_struct *pDM_Odm) odm_DIG(pDM_Odm); odm_CCKPacketDetectionThresh(pDM_Odm); - if (*(pDM_Odm->pbPowerSaving)) + if (*pDM_Odm->pbPowerSaving) return; odm_RefreshRateAdaptiveMask(pDM_Odm); @@ -229,13 +229,13 @@ void odm_CommonInfoSelfUpdate(struct odm_dm_struct *pDM_Odm) u8 i; struct sta_info *pEntry; - if (*(pDM_Odm->pBandWidth) == ODM_BW40M) { - if (*(pDM_Odm->pSecChOffset) == 1) - pDM_Odm->ControlChannel = *(pDM_Odm->pChannel) - 2; - else if (*(pDM_Odm->pSecChOffset) == 2) - pDM_Odm->ControlChannel = *(pDM_Odm->pChannel) + 2; + if (*pDM_Odm->pBandWidth == ODM_BW40M) { + if (*pDM_Odm->pSecChOffset == 1) + pDM_Odm->ControlChannel = *pDM_Odm->pChannel - 2; + else if (*pDM_Odm->pSecChOffset == 2) + pDM_Odm->ControlChannel = *pDM_Odm->pChannel + 2; } else { - pDM_Odm->ControlChannel = *(pDM_Odm->pChannel); + pDM_Odm->ControlChannel = *pDM_Odm->pChannel; } for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) { @@ -270,16 +270,16 @@ void odm_CmnInfoInit_Debug(struct odm_dm_struct *pDM_Odm) void odm_CmnInfoHook_Debug(struct odm_dm_struct *pDM_Odm) { ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("odm_CmnInfoHook_Debug==>\n")); - ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pNumTxBytesUnicast=%llu\n", *(pDM_Odm->pNumTxBytesUnicast))); - ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pNumRxBytesUnicast=%llu\n", *(pDM_Odm->pNumRxBytesUnicast))); - ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pWirelessMode=0x%x\n", *(pDM_Odm->pWirelessMode))); - ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pSecChOffset=%d\n", *(pDM_Odm->pSecChOffset))); - ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pSecurity=%d\n", *(pDM_Odm->pSecurity))); - ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pBandWidth=%d\n", *(pDM_Odm->pBandWidth))); - ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pChannel=%d\n", *(pDM_Odm->pChannel))); - - ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pbScanInProcess=%d\n", *(pDM_Odm->pbScanInProcess))); - ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pbPowerSaving=%d\n", *(pDM_Odm->pbPowerSaving))); + ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pNumTxBytesUnicast=%llu\n", *pDM_Odm->pNumTxBytesUnicast)); + ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pNumRxBytesUnicast=%llu\n", *pDM_Odm->pNumRxBytesUnicast)); + ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pWirelessMode=0x%x\n", *pDM_Odm->pWirelessMode)); + ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pSecChOffset=%d\n", *pDM_Odm->pSecChOffset)); + ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pSecurity=%d\n", *pDM_Odm->pSecurity)); + ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pBandWidth=%d\n", *pDM_Odm->pBandWidth)); + ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pChannel=%d\n", *pDM_Odm->pChannel)); + + ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pbScanInProcess=%d\n", *pDM_Odm->pbScanInProcess)); + ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("pbPowerSaving=%d\n", *pDM_Odm->pbPowerSaving)); } void odm_CmnInfoUpdate_Debug(struct odm_dm_struct *pDM_Odm) @@ -348,7 +348,7 @@ void odm_DIG(struct odm_dm_struct *pDM_Odm) return; } - if (*(pDM_Odm->pbScanInProcess)) { + if (*pDM_Odm->pbScanInProcess) { ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() Return: In Scan Progress\n")); return; } @@ -508,7 +508,7 @@ void odm_FalseAlarmCounterStatistics(struct odm_dm_struct *pDM_Odm) { struct adapter *adapter = pDM_Odm->Adapter; u32 ret_value; - struct false_alarm_stats *FalseAlmCnt = &(pDM_Odm->FalseAlmCnt); + struct false_alarm_stats *FalseAlmCnt = &pDM_Odm->FalseAlmCnt; if (!(pDM_Odm->SupportAbility & ODM_BB_FA_CNT)) return; @@ -581,7 +581,7 @@ void odm_FalseAlarmCounterStatistics(struct odm_dm_struct *pDM_Odm) void odm_CCKPacketDetectionThresh(struct odm_dm_struct *pDM_Odm) { u8 CurCCK_CCAThres; - struct false_alarm_stats *FalseAlmCnt = &(pDM_Odm->FalseAlmCnt); + struct false_alarm_stats *FalseAlmCnt = &pDM_Odm->FalseAlmCnt; if (!(pDM_Odm->SupportAbility & (ODM_BB_CCK_PD | ODM_BB_FA_CNT))) return; @@ -739,7 +739,7 @@ u32 ODM_Get_Rate_Bitmap(struct odm_dm_struct *pDM_Odm, u32 macid, u32 ra_mask, u } else if (rssi_level == DM_RATR_STA_MIDDLE) { rate_bitmap = 0x000ff000; } else { - if (*(pDM_Odm->pBandWidth) == ODM_BW40M) + if (*pDM_Odm->pBandWidth == ODM_BW40M) rate_bitmap = 0x000ff015; else rate_bitmap = 0x000ff005; @@ -945,7 +945,7 @@ void odm_TXPowerTrackingInit(struct odm_dm_struct *pDM_Odm) { pDM_Odm->RFCalibrateInfo.bTXPowerTracking = true; pDM_Odm->RFCalibrateInfo.TXPowercount = 0; - if (*(pDM_Odm->mp_mode) != 1) + if (*pDM_Odm->mp_mode != 1) pDM_Odm->RFCalibrateInfo.TxPowerTrackControl = true; MSG_88E("pDM_Odm TxPowerTrackControl = %d\n", pDM_Odm->RFCalibrateInfo.TxPowerTrackControl); @@ -1035,11 +1035,11 @@ void odm_EdcaTurboCheckCE(struct odm_dm_struct *pDM_Odm) u64 cur_tx_bytes = 0; u64 cur_rx_bytes = 0; u8 bbtchange = false; - struct xmit_priv *pxmitpriv = &(Adapter->xmitpriv); - struct recv_priv *precvpriv = &(Adapter->recvpriv); + struct xmit_priv *pxmitpriv = &Adapter->xmitpriv; + struct recv_priv *precvpriv = &Adapter->recvpriv; struct registry_priv *pregpriv = &Adapter->registrypriv; - struct mlme_ext_priv *pmlmeext = &(Adapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); + struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv; + struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; if (pregpriv->wifi_spec == 1) /* (pmlmeinfo->HT_enable == 0)) */ goto dm_CheckEdcaTurbo_EXIT; diff --git a/drivers/staging/rtl8188eu/hal/phy.c b/drivers/staging/rtl8188eu/hal/phy.c index b9025815b682..5eca3625d5a8 100644 --- a/drivers/staging/rtl8188eu/hal/phy.c +++ b/drivers/staging/rtl8188eu/hal/phy.c @@ -345,8 +345,8 @@ static void dm_txpwr_track_setpwr(struct odm_dm_struct *dm_odm) { if (dm_odm->BbSwingFlagOfdm || dm_odm->BbSwingFlagCck) { ODM_RT_TRACE(dm_odm, ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD, - ("dm_txpwr_track_setpwr CH=%d\n", *(dm_odm->pChannel))); - phy_set_tx_power_level(dm_odm->Adapter, *(dm_odm->pChannel)); + ("dm_txpwr_track_setpwr CH=%d\n", *dm_odm->pChannel)); + phy_set_tx_power_level(dm_odm->Adapter, *dm_odm->pChannel); dm_odm->BbSwingFlagOfdm = false; dm_odm->BbSwingFlagCck = false; } @@ -975,7 +975,7 @@ static void phy_iq_calibrate(struct adapter *adapt, s32 result[][8], u32 retry_count = 9; - if (*(dm_odm->mp_mode) == 1) + if (*dm_odm->mp_mode == 1) retry_count = 9; else retry_count = 2; @@ -1320,7 +1320,7 @@ void rtl88eu_phy_lc_calibrate(struct adapter *adapt) if (singletone || carrier_sup) return; - while (*(dm_odm->pbScanInProcess) && timecount < timeout) { + while (*dm_odm->pbScanInProcess && timecount < timeout) { mdelay(50); timecount += 50; } diff --git a/drivers/staging/rtl8188eu/hal/rf.c b/drivers/staging/rtl8188eu/hal/rf.c index 00a9f692bb06..6702f263c770 100644 --- a/drivers/staging/rtl8188eu/hal/rf.c +++ b/drivers/staging/rtl8188eu/hal/rf.c @@ -79,7 +79,7 @@ void rtl88eu_phy_rf6052_set_cck_txpower(struct adapter *adapt, u8 *powerlevel) } } for (idx1 = RF_PATH_A; idx1 <= RF_PATH_B; idx1++) { - ptr = (u8 *)(&(tx_agc[idx1])); + ptr = (u8 *)(&tx_agc[idx1]); for (idx2 = 0; idx2 < 4; idx2++) { if (*ptr > RF6052_MAX_TX_PWR) *ptr = RF6052_MAX_TX_PWR; diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c b/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c index 371e746915dd..176716d3e903 100644 --- a/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c +++ b/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c @@ -256,7 +256,7 @@ static void ConstructBeacon(struct adapter *adapt, u8 *pframe, u32 *pLength) pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, min_t(u32, rate_len, 8), cur_network->SupportedRates, &pktlen); /* DS parameter set */ - pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pktlen); + pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&cur_network->Configuration.DSConfig, &pktlen); if ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) { u32 ATIMWindow; diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h index c0114ad79788..0d3e4a6e7e85 100644 --- a/drivers/staging/rtl8188eu/include/osdep_service.h +++ b/drivers/staging/rtl8188eu/include/osdep_service.h @@ -50,7 +50,7 @@ struct __queue { static inline struct list_head *get_list_head(struct __queue *queue) { - return &(queue->queue); + return &queue->queue; } static inline int rtw_netif_queue_stopped(struct net_device *pnetdev) diff --git a/drivers/staging/rtl8188eu/include/rtl8188e_spec.h b/drivers/staging/rtl8188eu/include/rtl8188e_spec.h index dd943c831d91..be30c9434a29 100644 --- a/drivers/staging/rtl8188eu/include/rtl8188e_spec.h +++ b/drivers/staging/rtl8188eu/include/rtl8188e_spec.h @@ -817,7 +817,7 @@ So the following defines for 92C is not entire!!!!!! /* 2 MCUFWDL */ #define MCUFWDL_EN BIT(0) #define MCUFWDL_RDY BIT(1) -#define FWDL_ChkSum_rpt BIT(2) +#define FWDL_CHKSUM_RPT BIT(2) #define MACINI_RDY BIT(3) #define BBINI_RDY BIT(4) #define RFINI_RDY BIT(5) diff --git a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c index 9a89791720e0..d5968ef9f43d 100644 --- a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c +++ b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c @@ -93,7 +93,7 @@ static char *translate_scan(struct adapter *padapter, struct wlan_network *pnetwork, char *start, char *stop) { - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct iw_event iwe; u16 cap; __le16 le_tmp; @@ -417,7 +417,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, ret = -EOPNOTSUPP; goto exit; } - memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength); + memcpy(&psecuritypriv->dot11DefKey[wep_key_idx].skey[0], pwep->KeyMaterial, pwep->KeyLength); psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength; rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0); } @@ -444,8 +444,8 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16)); if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */ - memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); - memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); + memcpy(psta->dot11tkiptxmickey.skey, ¶m->u.crypt.key[16], 8); + memcpy(psta->dot11tkiprxmickey.skey, ¶m->u.crypt.key[24], 8); padapter->securitypriv.busetkipkey = false; } @@ -454,8 +454,8 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, rtw_setstakey_cmd(padapter, (unsigned char *)psta, true); } else { /* group key */ memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16 )); - memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); - memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); + memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, ¶m->u.crypt.key[16], 8); + memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, ¶m->u.crypt.key[24], 8); padapter->securitypriv.binstallGrpkey = true; DBG_88E(" ~~~~set sta key:groupkey\n"); @@ -620,7 +620,7 @@ static int rtw_wx_get_name(struct net_device *dev, u32 ht_ielen = 0; char *p; u8 ht_cap = false; - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; NDIS_802_11_RATES_EX *prates = NULL; @@ -669,7 +669,7 @@ static int rtw_wx_get_freq(struct net_device *dev, union iwreq_data *wrqu, char *extra) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; if (check_fwstate(pmlmepriv, _FW_LINKED)) { @@ -738,7 +738,7 @@ static int rtw_wx_get_mode(struct net_device *dev, struct iw_request_info *a, union iwreq_data *wrqu, char *b) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, (" rtw_wx_get_mode\n")); @@ -938,10 +938,10 @@ static int rtw_wx_set_wap(struct net_device *dev, uint ret = 0; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); struct sockaddr *temp = (struct sockaddr *)awrq; - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct list_head *phead; u8 *dst_bssid, *src_bssid; - struct __queue *queue = &(pmlmepriv->scanned_queue); + struct __queue *queue = &pmlmepriv->scanned_queue; struct wlan_network *pnetwork = NULL; enum ndis_802_11_auth_mode authmode; @@ -1002,7 +1002,7 @@ static int rtw_wx_get_wap(struct net_device *dev, union iwreq_data *wrqu, char *extra) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; wrqu->ap_addr.sa_family = ARPHRD_ETHER; @@ -1188,8 +1188,8 @@ static int rtw_wx_get_scan(struct net_device *dev, struct iw_request_info *a, { struct list_head *plist, *phead; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - struct __queue *queue = &(pmlmepriv->scanned_queue); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; + struct __queue *queue = &pmlmepriv->scanned_queue; struct wlan_network *pnetwork = NULL; char *ev = extra; char *stop = ev + wrqu->data.length; @@ -1217,7 +1217,7 @@ static int rtw_wx_get_scan(struct net_device *dev, struct iw_request_info *a, break; } - spin_lock_bh(&(pmlmepriv->scanned_queue.lock)); + spin_lock_bh(&pmlmepriv->scanned_queue.lock); phead = get_list_head(queue); plist = phead->next; @@ -1358,7 +1358,7 @@ static int rtw_wx_get_essid(struct net_device *dev, { u32 len; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_essid\n")); @@ -1564,7 +1564,7 @@ static int rtw_wx_set_enc(struct net_device *dev, struct ndis_802_11_wep wep; enum ndis_802_11_auth_mode authmode; - struct iw_point *erq = &(wrqu->encoding); + struct iw_point *erq = &wrqu->encoding; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv; @@ -1675,8 +1675,8 @@ static int rtw_wx_get_enc(struct net_device *dev, { uint key; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct iw_point *erq = &(wrqu->encoding); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct iw_point *erq = &wrqu->encoding; + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; if (!check_fwstate(pmlmepriv, _FW_LINKED)) { if (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { @@ -1759,7 +1759,7 @@ static int rtw_wx_set_auth(struct net_device *dev, union iwreq_data *wrqu, char *extra) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct iw_param *param = (struct iw_param *)&(wrqu->param); + struct iw_param *param = (struct iw_param *)&wrqu->param; int ret = 0; switch (param->flags & IW_AUTH_INDEX) { @@ -2012,14 +2012,9 @@ static int wpa_supplicant_ioctl(struct net_device *dev, struct iw_point *p) if (!p->pointer || p->length != sizeof(struct ieee_param)) return -EINVAL; - param = (struct ieee_param *)rtw_malloc(p->length); - if (!param) - return -ENOMEM; - - if (copy_from_user(param, p->pointer, p->length)) { - kfree(param); - return -EFAULT; - } + param = memdup_user(p->pointer, p->length); + if (IS_ERR(param)) + return PTR_ERR(param); switch (param->cmd) { case IEEE_CMD_SET_WPA_PARAM: @@ -2093,7 +2088,7 @@ static int set_group_key(struct adapter *padapter, u8 *key, u8 alg, int keyid) u8 keylen; struct cmd_obj *pcmd; struct setkey_parm *psetkeyparm; - struct cmd_priv *pcmdpriv = &(padapter->cmdpriv); + struct cmd_priv *pcmdpriv = &padapter->cmdpriv; int res = _SUCCESS; DBG_88E("%s\n", __func__); @@ -2130,7 +2125,7 @@ static int set_group_key(struct adapter *padapter, u8 *key, u8 alg, int keyid) keylen = 16; } - memcpy(&(psetkeyparm->key[0]), key, keylen); + memcpy(&psetkeyparm->key[0], key, keylen); pcmd->cmdcode = _SetKey_CMD_; pcmd->parmbuf = (u8 *)psetkeyparm; @@ -2173,7 +2168,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, struct sta_info *psta = NULL, *pbcmc_sta = NULL; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &(padapter->securitypriv); + struct security_priv *psecuritypriv = &padapter->securitypriv; struct sta_priv *pstapriv = &padapter->stapriv; DBG_88E("%s\n", __func__); @@ -2245,7 +2240,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx; - memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength); + memcpy(&psecuritypriv->dot11DefKey[wep_key_idx].skey[0], pwep->KeyMaterial, pwep->KeyLength); psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength; @@ -2256,7 +2251,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, /* don't update "psecuritypriv->dot11PrivacyAlgrthm" and */ /* psecuritypriv->dot11PrivacyKeyIndex = keyid", but can rtw_set_key to cam */ - memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength); + memcpy(&psecuritypriv->dot11DefKey[wep_key_idx].skey[0], pwep->KeyMaterial, pwep->KeyLength); psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength; @@ -2283,8 +2278,8 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16)); /* set mic key */ - memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); - memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); + memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, ¶m->u.crypt.key[16], 8); + memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, ¶m->u.crypt.key[24], 8); psecuritypriv->busetkipkey = true; } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { @@ -2326,8 +2321,8 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, psta->dot118021XPrivacy = _TKIP_; /* set mic key */ - memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); - memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); + memcpy(psta->dot11tkiptxmickey.skey, ¶m->u.crypt.key[16], 8); + memcpy(psta->dot11tkiprxmickey.skey, ¶m->u.crypt.key[24], 8); psecuritypriv->busetkipkey = true; } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { @@ -2357,8 +2352,8 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16)); /* set mic key */ - memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); - memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); + memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, ¶m->u.crypt.key[16], 8); + memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, ¶m->u.crypt.key[24], 8); psecuritypriv->busetkipkey = true; } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { @@ -2398,7 +2393,7 @@ static int rtw_set_beacon(struct net_device *dev, struct ieee_param *param, int { int ret = 0; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct sta_priv *pstapriv = &padapter->stapriv; unsigned char *pbuf = param->u.bcn_ie.buf; @@ -2436,7 +2431,7 @@ static int rtw_add_sta(struct net_device *dev, struct ieee_param *param) int ret = 0; struct sta_info *psta = NULL; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct sta_priv *pstapriv = &padapter->stapriv; DBG_88E("rtw_add_sta(aid =%d) =%pM\n", param->u.add_sta.aid, (param->sta_addr)); @@ -2489,7 +2484,7 @@ static int rtw_del_sta(struct net_device *dev, struct ieee_param *param) { struct sta_info *psta = NULL; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct sta_priv *pstapriv = &padapter->stapriv; int updated = 0; @@ -2524,7 +2519,7 @@ static int rtw_ioctl_get_sta_data(struct net_device *dev, struct ieee_param *par int ret = 0; struct sta_info *psta = NULL; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct sta_priv *pstapriv = &padapter->stapriv; struct ieee_param_ex *param_ex = (struct ieee_param_ex *)param; struct sta_data *psta_data = (struct sta_data *)param_ex->data; @@ -2580,7 +2575,7 @@ static int rtw_get_sta_wpaie(struct net_device *dev, struct ieee_param *param) int ret = 0; struct sta_info *psta = NULL; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct sta_priv *pstapriv = &padapter->stapriv; DBG_88E("rtw_get_sta_wpaie, sta_addr: %pM\n", (param->sta_addr)); @@ -2616,8 +2611,8 @@ static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param, { unsigned char wps_oui[4] = {0x0, 0x50, 0xf2, 0x04}; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; + struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; int ie_len; DBG_88E("%s, len =%d\n", __func__, len); @@ -2651,7 +2646,7 @@ static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param, static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *param, int len) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; int ie_len; DBG_88E("%s, len =%d\n", __func__, len); @@ -2680,7 +2675,7 @@ static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *par static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *param, int len) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; int ie_len; DBG_88E("%s, len =%d\n", __func__, len); @@ -2710,9 +2705,9 @@ static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *par static int rtw_set_hidden_ssid(struct net_device *dev, struct ieee_param *param, int len) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; + struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; + struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; u8 value; @@ -2734,7 +2729,7 @@ static int rtw_set_hidden_ssid(struct net_device *dev, struct ieee_param *param, static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *param, int len) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; if (!check_fwstate(pmlmepriv, WIFI_AP_STATE)) return -EINVAL; @@ -2748,7 +2743,7 @@ static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *p static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *param, int len) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; if (!check_fwstate(pmlmepriv, WIFI_AP_STATE)) return -EINVAL; @@ -2762,7 +2757,7 @@ static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *para static int rtw_ioctl_set_macaddr_acl(struct net_device *dev, struct ieee_param *param, int len) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; if (!check_fwstate(pmlmepriv, WIFI_AP_STATE)) return -EINVAL; @@ -2789,14 +2784,9 @@ static int rtw_hostapd_ioctl(struct net_device *dev, struct iw_point *p) if (!p->pointer || p->length != sizeof(struct ieee_param)) return -EINVAL; - param = (struct ieee_param *)rtw_malloc(p->length); - if (!param) - return -ENOMEM; - - if (copy_from_user(param, p->pointer, p->length)) { - kfree(param); - return -EFAULT; - } + param = memdup_user(p->pointer, p->length); + if (IS_ERR(param)) + return PTR_ERR(param); switch (param->cmd) { case RTL871X_HOSTAPD_FLUSH: @@ -2882,7 +2872,7 @@ static int rtw_wx_set_priv(struct net_device *dev, /* added for wps2.0 @20110524 */ if (dwrq->flags == 0x8766 && len > 8) { u32 cp_sz; - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; u8 *probereq_wpsie = ext; int probereq_wpsie_len = len; u8 wps_oui[4] = {0x0, 0x50, 0xf2, 0x04}; diff --git a/drivers/staging/rtl8188eu/os_dep/rtw_android.c b/drivers/staging/rtl8188eu/os_dep/rtw_android.c index daf6db354982..bf86d03820ca 100644 --- a/drivers/staging/rtl8188eu/os_dep/rtw_android.c +++ b/drivers/staging/rtl8188eu/os_dep/rtw_android.c @@ -77,7 +77,7 @@ static int rtw_android_get_rssi(struct net_device *net, char *command, int total_len) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(net); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); + struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct wlan_network *pcur_network = &pmlmepriv->cur_network; int bytes_written = 0; diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c index 20e494186c9e..43494a2b6f05 100644 --- a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c +++ b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c @@ -2444,7 +2444,7 @@ static void _rtl92e_dm_init_dynamic_tx_power(struct net_device *dev) static void _rtl92e_dm_dynamic_tx_power(struct net_device *dev) { struct r8192_priv *priv = rtllib_priv(dev); - unsigned int txhipower_threshhold = 0; + unsigned int txhipower_threshold = 0; unsigned int txlowpower_threshold = 0; if (priv->rtllib->bdynamic_txpower_enable != true) { @@ -2454,10 +2454,10 @@ static void _rtl92e_dm_dynamic_tx_power(struct net_device *dev) } if ((priv->rtllib->pHTInfo->IOTPeer == HT_IOT_PEER_ATHEROS) && (priv->rtllib->mode == IEEE_G)) { - txhipower_threshhold = TX_POWER_ATHEROAP_THRESH_HIGH; + txhipower_threshold = TX_POWER_ATHEROAP_THRESH_HIGH; txlowpower_threshold = TX_POWER_ATHEROAP_THRESH_LOW; } else { - txhipower_threshhold = TX_POWER_NEAR_FIELD_THRESH_HIGH; + txhipower_threshold = TX_POWER_NEAR_FIELD_THRESH_HIGH; txlowpower_threshold = TX_POWER_NEAR_FIELD_THRESH_LOW; } @@ -2465,7 +2465,7 @@ static void _rtl92e_dm_dynamic_tx_power(struct net_device *dev) priv->undecorated_smoothed_pwdb); if (priv->rtllib->state == RTLLIB_LINKED) { - if (priv->undecorated_smoothed_pwdb >= txhipower_threshhold) { + if (priv->undecorated_smoothed_pwdb >= txhipower_threshold) { priv->bDynamicTxHighPower = true; priv->bDynamicTxLowPower = false; } else { diff --git a/drivers/staging/rtl8712/rtl871x_xmit.c b/drivers/staging/rtl8712/rtl871x_xmit.c index f0b85338b567..2f0d0ffa6fae 100644 --- a/drivers/staging/rtl8712/rtl871x_xmit.c +++ b/drivers/staging/rtl8712/rtl871x_xmit.c @@ -71,12 +71,13 @@ int _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv, _init_queue(&pxmitpriv->apsd_queue); _init_queue(&pxmitpriv->free_xmit_queue); /* - * Please allocate memory with the sz = (struct xmit_frame) * NR_XMITFRAME, + * Please allocate memory with sz = (struct xmit_frame) * NR_XMITFRAME, * and initialize free_xmit_frame below. * Please also apply free_txobj to link_up all the xmit_frames... */ pxmitpriv->pallocated_frame_buf = - kmalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4, GFP_ATOMIC); + kmalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4, + GFP_ATOMIC); if (!pxmitpriv->pallocated_frame_buf) { pxmitpriv->pxmit_frame_buf = NULL; return -ENOMEM; @@ -126,8 +127,8 @@ int _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv, pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf; for (i = 0; i < NR_XMITBUFF; i++) { INIT_LIST_HEAD(&pxmitbuf->list); - pxmitbuf->pallocated_buf = kmalloc(MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ, - GFP_ATOMIC); + pxmitbuf->pallocated_buf = + kmalloc(MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ, GFP_ATOMIC); if (!pxmitbuf->pallocated_buf) return -ENOMEM; pxmitbuf->pbuf = pxmitbuf->pallocated_buf + XMITBUF_ALIGN_SZ - @@ -350,7 +351,7 @@ static int xmitframe_addmic(struct _adapter *padapter, struct sta_info *stainfo; struct qos_priv *pqospriv = &(padapter->mlmepriv.qospriv); struct pkt_attrib *pattrib = &pxmitframe->attrib; - struct security_priv *psecuritypriv = &padapter->securitypriv; + struct security_priv *psecpriv = &padapter->securitypriv; struct xmit_priv *pxmitpriv = &padapter->xmitpriv; u8 priority[4] = {0x0, 0x0, 0x0, 0x0}; bool bmcst = is_multicast_ether_addr(pattrib->ra); @@ -368,15 +369,14 @@ static int xmitframe_addmic(struct _adapter *padapter, 0x0, 0x0}; pframe = pxmitframe->buf_addr + TXDESC_OFFSET; if (bmcst) { - if (!memcmp(psecuritypriv->XGrptxmickey - [psecuritypriv->XGrpKeyid].skey, + if (!memcmp(psecpriv->XGrptxmickey + [psecpriv->XGrpKeyid].skey, null_key, 16)) return -ENOMEM; /*start to calculate the mic code*/ r8712_secmicsetkey(&micdata, - psecuritypriv-> - XGrptxmickey[psecuritypriv-> - XGrpKeyid].skey); + psecpriv->XGrptxmickey + [psecpriv->XGrpKeyid].skey); } else { if (!memcmp(&stainfo->tkiptxmickey.skey[0], null_key, 16)) @@ -416,7 +416,7 @@ static int xmitframe_addmic(struct _adapter *padapter, length = pattrib->last_txcmdsz - pattrib->hdrlen - pattrib->iv_len - - ((psecuritypriv->sw_encrypt) + ((psecpriv->sw_encrypt) ? pattrib->icv_len : 0); r8712_secmicappend(&micdata, payload, length); @@ -424,7 +424,7 @@ static int xmitframe_addmic(struct _adapter *padapter, } else { length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - - ((psecuritypriv->sw_encrypt) ? + ((psecpriv->sw_encrypt) ? pattrib->icv_len : 0); r8712_secmicappend(&micdata, payload, length); @@ -477,75 +477,72 @@ static int make_wlanhdr(struct _adapter *padapter, u8 *hdr, struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct qos_priv *pqospriv = &pmlmepriv->qospriv; __le16 *fctrl = &pwlanhdr->frame_ctl; + u8 *bssid; memset(hdr, 0, WLANHDR_OFFSET); SetFrameSubType(fctrl, pattrib->subtype); - if (pattrib->subtype & WIFI_DATA_TYPE) { - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - /* to_ds = 1, fr_ds = 0; */ - SetToDs(fctrl); - memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv), - ETH_ALEN); - memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN); - memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN); - } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - /* to_ds = 0, fr_ds = 1; */ - SetFrDs(fctrl); - memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN); - memcpy(pwlanhdr->addr2, get_bssid(pmlmepriv), - ETH_ALEN); - memcpy(pwlanhdr->addr3, pattrib->src, ETH_ALEN); - } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) || - check_fwstate(pmlmepriv, - WIFI_ADHOC_MASTER_STATE)) { - memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN); - memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN); - memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), - ETH_ALEN); - } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) { - memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN); - memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN); - memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), - ETH_ALEN); - } else { - return -EINVAL; - } + if (!(pattrib->subtype & WIFI_DATA_TYPE)) + return 0; - if (pattrib->encrypt) - SetPrivacy(fctrl); - if (pqospriv->qos_option) { - qc = (unsigned short *)(hdr + pattrib->hdrlen - 2); - if (pattrib->priority) - SetPriority(qc, pattrib->priority); - SetAckpolicy(qc, pattrib->ack_policy); - } - /* TODO: fill HT Control Field */ - /* Update Seq Num will be handled by f/w */ - { - struct sta_info *psta; - bool bmcst = is_multicast_ether_addr(pattrib->ra); - - if (pattrib->psta) { - psta = pattrib->psta; - } else { - if (bmcst) - psta = r8712_get_bcmc_stainfo(padapter); - else - psta = - r8712_get_stainfo(&padapter->stapriv, - pattrib->ra); - } - if (psta) { - psta->sta_xmitpriv.txseq_tid - [pattrib->priority]++; - psta->sta_xmitpriv.txseq_tid[pattrib->priority] - &= 0xFFF; - pattrib->seqnum = psta->sta_xmitpriv. - txseq_tid[pattrib->priority]; - SetSeqNum(hdr, pattrib->seqnum); - } + bssid = get_bssid(pmlmepriv); + + if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { + /* to_ds = 1, fr_ds = 0; */ + SetToDs(fctrl); + ether_addr_copy(pwlanhdr->addr1, bssid); + ether_addr_copy(pwlanhdr->addr2, pattrib->src); + ether_addr_copy(pwlanhdr->addr3, pattrib->dst); + } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { + /* to_ds = 0, fr_ds = 1; */ + SetFrDs(fctrl); + ether_addr_copy(pwlanhdr->addr1, pattrib->dst); + ether_addr_copy(pwlanhdr->addr2, bssid); + ether_addr_copy(pwlanhdr->addr3, pattrib->src); + } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) || + check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { + ether_addr_copy(pwlanhdr->addr1, pattrib->dst); + ether_addr_copy(pwlanhdr->addr2, pattrib->src); + ether_addr_copy(pwlanhdr->addr3, bssid); + } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) { + ether_addr_copy(pwlanhdr->addr1, pattrib->dst); + ether_addr_copy(pwlanhdr->addr2, pattrib->src); + ether_addr_copy(pwlanhdr->addr3, bssid); + } else { + return -EINVAL; + } + + if (pattrib->encrypt) + SetPrivacy(fctrl); + if (pqospriv->qos_option) { + qc = (unsigned short *)(hdr + pattrib->hdrlen - 2); + if (pattrib->priority) + SetPriority(qc, pattrib->priority); + SetAckpolicy(qc, pattrib->ack_policy); + } + /* TODO: fill HT Control Field */ + /* Update Seq Num will be handled by f/w */ + { + struct sta_info *psta; + bool bmcst = is_multicast_ether_addr(pattrib->ra); + + if (pattrib->psta) + psta = pattrib->psta; + else if (bmcst) + psta = r8712_get_bcmc_stainfo(padapter); + else + psta = r8712_get_stainfo(&padapter->stapriv, + pattrib->ra); + + if (psta) { + u16 *txtid = psta->sta_xmitpriv.txseq_tid; + + txtid[pattrib->priority]++; + txtid[pattrib->priority] &= 0xFFF; + pattrib->seqnum = txtid[pattrib->priority]; + SetSeqNum(hdr, pattrib->seqnum); } } + return 0; } @@ -589,7 +586,7 @@ sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt, addr_t addr; u8 *pframe, *mem_start, *ptxdesc; struct sta_info *psta; - struct security_priv *psecuritypriv = &padapter->securitypriv; + struct security_priv *psecpriv = &padapter->securitypriv; struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct xmit_priv *pxmitpriv = &padapter->xmitpriv; struct pkt_attrib *pattrib = &pxmitframe->attrib; @@ -632,15 +629,13 @@ sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt, case _WEP40_: case _WEP104_: WEP_IV(pattrib->iv, psta->txpn, - (u8)psecuritypriv-> - PrivacyKeyIndex); + (u8)psecpriv->PrivacyKeyIndex); break; case _TKIP_: if (bmcst) TKIP_IV(pattrib->iv, psta->txpn, - (u8)psecuritypriv-> - XGrpKeyid); + (u8)psecpriv->XGrpKeyid); else TKIP_IV(pattrib->iv, psta->txpn, 0); @@ -648,8 +643,7 @@ sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt, case _AES_: if (bmcst) AES_IV(pattrib->iv, psta->txpn, - (u8)psecuritypriv-> - XGrpKeyid); + (u8)psecpriv->XGrpKeyid); else AES_IV(pattrib->iv, psta->txpn, 0); diff --git a/drivers/staging/rtl8712/rtl871x_xmit.h b/drivers/staging/rtl8712/rtl871x_xmit.h index f227828094bf..c0c0c781fe17 100644 --- a/drivers/staging/rtl8712/rtl871x_xmit.h +++ b/drivers/staging/rtl8712/rtl871x_xmit.h @@ -115,7 +115,7 @@ struct pkt_attrib { u8 icv_len; unsigned char iv[8]; unsigned char icv[8]; - u8 dst[ETH_ALEN]; + u8 dst[ETH_ALEN] __aligned(2); /* for ether_addr_copy */ u8 src[ETH_ALEN]; u8 ta[ETH_ALEN]; u8 ra[ETH_ALEN]; diff --git a/drivers/staging/rtl8712/usb_halinit.c b/drivers/staging/rtl8712/usb_halinit.c index 6cc4a704c3a0..313c569748e9 100644 --- a/drivers/staging/rtl8712/usb_halinit.c +++ b/drivers/staging/rtl8712/usb_halinit.c @@ -58,7 +58,7 @@ u8 r8712_usb_hal_bus_init(struct _adapter *adapter) r8712_write8(adapter, SYS_ISO_CTRL + 1, val8); val8 = r8712_read8(adapter, SYS_ISO_CTRL + 1); val8 = val8 & 0xEF; - /* attatch AFE PLL to MACTOP/BB/PCIe Digital */ + /* attach AFE PLL to MACTOP/BB/PCIe Digital */ r8712_write8(adapter, SYS_ISO_CTRL + 1, val8); val8 = r8712_read8(adapter, AFE_XTAL_CTRL + 1); val8 = val8 & 0xFB; diff --git a/drivers/staging/rtl8723bs/core/rtw_cmd.c b/drivers/staging/rtl8723bs/core/rtw_cmd.c index efb5135ad743..bd18d1803e27 100644 --- a/drivers/staging/rtl8723bs/core/rtw_cmd.c +++ b/drivers/staging/rtl8723bs/core/rtw_cmd.c @@ -822,7 +822,7 @@ u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork) psecnetwork->IELength = 0; /* Added by Albert 2009/02/18 */ - /* If the the driver wants to use the bssid to create the connection. */ + /* If the driver wants to use the bssid to create the connection. */ /* If not, we have to copy the connecting AP's MAC address to it so that */ /* the driver just has the bssid information for PMKIDList searching. */ diff --git a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c index 110338dbe372..69bcd172b298 100644 --- a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c +++ b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c @@ -1271,13 +1271,13 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len) unsigned char *pbuf; u32 wpa_ielen = 0; u8 *pbssid = GetAddr3Ptr(pframe); - u32 hidden_ssid = 0; struct HT_info_element *pht_info = NULL; struct rtw_ieee80211_ht_cap *pht_cap = NULL; u32 bcn_channel; unsigned short ht_cap_info; unsigned char ht_info_infos_0; struct mlme_priv *pmlmepriv = &Adapter->mlmepriv; + int ssid_len; if (is_client_associated_to_ap(Adapter) == false) return true; @@ -1370,21 +1370,15 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len) } /* checking SSID */ + ssid_len = 0; p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _SSID_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_); - if (!p) { - DBG_871X("%s marc: cannot find SSID for survey event\n", __func__); - hidden_ssid = true; - } else { - hidden_ssid = false; - } - - if ((NULL != p) && (false == hidden_ssid && (*(p + 1)))) { - memcpy(bssid->Ssid.Ssid, (p + 2), *(p + 1)); - bssid->Ssid.SsidLength = *(p + 1); - } else { - bssid->Ssid.SsidLength = 0; - bssid->Ssid.Ssid[0] = '\0'; + if (p) { + ssid_len = *(p + 1); + if (ssid_len > NDIS_802_11_LENGTH_SSID) + ssid_len = 0; } + memcpy(bssid->Ssid.Ssid, (p + 2), ssid_len); + bssid->Ssid.SsidLength = ssid_len; RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s bssid.Ssid.Ssid:%s bssid.Ssid.SsidLength:%d " "cur_network->network.Ssid.Ssid:%s len:%d\n", __func__, bssid->Ssid.Ssid, diff --git a/drivers/staging/rtl8723bs/hal/hal_btcoex.c b/drivers/staging/rtl8723bs/hal/hal_btcoex.c index d5793e4614bf..a6ed1bb9945e 100644 --- a/drivers/staging/rtl8723bs/hal/hal_btcoex.c +++ b/drivers/staging/rtl8723bs/hal/hal_btcoex.c @@ -12,49 +12,6 @@ #include <Mp_Precomp.h> /* Global variables */ -static const char *const BtProfileString[] = { - "NONE", - "A2DP", - "PAN", - "HID", - "SCO", -}; - -static const char *const BtSpecString[] = { - "1.0b", - "1.1", - "1.2", - "2.0+EDR", - "2.1+EDR", - "3.0+HS", - "4.0", -}; - -static const char *const BtLinkRoleString[] = { - "Master", - "Slave", -}; - -static const char *const h2cStaString[] = { - "successful", - "h2c busy", - "rf off", - "fw not read", -}; - -static const char *const ioStaString[] = { - "success", - "can not IO", - "rf off", - "fw not read", - "wait io timeout", - "invalid len", - "idle Q empty", - "insert waitQ fail", - "unknown fail", - "wrong level", - "h2c stopped", -}; BTC_COEXIST GLBtCoexist; static u8 GLBtcWiFiInScanState; diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c index 767e2a784f78..10250642d30a 100644 --- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +++ b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c @@ -1816,7 +1816,7 @@ static void phy_CrossReferenceHTAndVHTTxPowerLimit(struct adapter *padapter) s8 tempPwrLmt = 0; for (regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation) { - for (bw = 0; bw < MAX_5G_BANDWITH_NUM; ++bw) { + for (bw = 0; bw < MAX_5G_BANDWIDTH_NUM; ++bw) { for (channel = 0; channel < CHANNEL_MAX_NUMBER_5G; ++channel) { for (rateSection = 0; rateSection < MAX_RATE_SECTION_NUM; ++rateSection) { tempPwrLmt = pHalData->TxPwrLimit_5G[regulation][bw][rateSection][channel][ODM_RF_PATH_A]; @@ -1877,7 +1877,7 @@ void PHY_ConvertTxPowerLimitToPowerIndex(struct adapter *Adapter) phy_CrossReferenceHTAndVHTTxPowerLimit(Adapter); for (regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation) { - for (bw = 0; bw < MAX_2_4G_BANDWITH_NUM; ++bw) { + for (bw = 0; bw < MAX_2_4G_BANDWIDTH_NUM; ++bw) { for (channel = 0; channel < CHANNEL_MAX_NUMBER_2G; ++channel) { for (rateSection = 0; rateSection < MAX_RATE_SECTION_NUM; ++rateSection) { tempPwrLmt = pHalData->TxPwrLimit_2_4G[regulation][bw][rateSection][channel][ODM_RF_PATH_A]; @@ -1920,7 +1920,7 @@ void PHY_InitTxPowerLimit(struct adapter *Adapter) /* DBG_871X("=====> PHY_InitTxPowerLimit()!\n"); */ for (i = 0; i < MAX_REGULATION_NUM; ++i) { - for (j = 0; j < MAX_2_4G_BANDWITH_NUM; ++j) + for (j = 0; j < MAX_2_4G_BANDWIDTH_NUM; ++j) for (k = 0; k < MAX_RATE_SECTION_NUM; ++k) for (m = 0; m < CHANNEL_MAX_NUMBER_2G; ++m) for (l = 0; l < MAX_RF_PATH_NUM; ++l) @@ -1928,7 +1928,7 @@ void PHY_InitTxPowerLimit(struct adapter *Adapter) } for (i = 0; i < MAX_REGULATION_NUM; ++i) { - for (j = 0; j < MAX_5G_BANDWITH_NUM; ++j) + for (j = 0; j < MAX_5G_BANDWIDTH_NUM; ++j) for (k = 0; k < MAX_RATE_SECTION_NUM; ++k) for (m = 0; m < CHANNEL_MAX_NUMBER_5G; ++m) for (l = 0; l < MAX_RF_PATH_NUM; ++l) diff --git a/drivers/staging/rtl8723bs/hal/odm.c b/drivers/staging/rtl8723bs/hal/odm.c index aa6631ee4ea7..f2a9e95a1563 100644 --- a/drivers/staging/rtl8723bs/hal/odm.c +++ b/drivers/staging/rtl8723bs/hal/odm.c @@ -7,19 +7,6 @@ #include "odm_precomp.h" -static const u16 dB_Invert_Table[8][12] = { - {1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4}, - {4, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16}, - {18, 20, 22, 25, 28, 32, 35, 40, 45, 50, 56, 63}, - {71, 79, 89, 100, 112, 126, 141, 158, 178, 200, 224, 251}, - {282, 316, 355, 398, 447, 501, 562, 631, 708, 794, 891, 1000}, - {1122, 1259, 1413, 1585, 1778, 1995, 2239, 2512, 2818, 3162, 3548, 3981}, - {4467, 5012, 5623, 6310, 7079, 7943, 8913, 10000, 11220, 12589, 14125, - 15849}, - {17783, 19953, 22387, 25119, 28184, 31623, 35481, 39811, 44668, 50119, - 56234, 65535} - }; - /* Global var */ u32 OFDMSwingTable[OFDM_TABLE_SIZE] = { diff --git a/drivers/staging/rtl8723bs/hal/odm.h b/drivers/staging/rtl8723bs/hal/odm.h index b77d1fe33a28..16e8f66a3171 100644 --- a/drivers/staging/rtl8723bs/hal/odm.h +++ b/drivers/staging/rtl8723bs/hal/odm.h @@ -541,7 +541,7 @@ typedef enum tag_Operation_Mode_Definition { /* ODM_CMNINFO_WM_MODE */ typedef enum tag_Wireless_Mode_Definition { - ODM_WM_UNKNOW = 0x0, + ODM_WM_UNKNOWN = 0x0, ODM_WM_B = BIT0, ODM_WM_G = BIT1, ODM_WM_A = BIT2, diff --git a/drivers/staging/rtl8723bs/hal/odm_RegDefine11N.h b/drivers/staging/rtl8723bs/hal/odm_RegDefine11N.h index f2c0707aad4c..1c6c08000e27 100644 --- a/drivers/staging/rtl8723bs/hal/odm_RegDefine11N.h +++ b/drivers/staging/rtl8723bs/hal/odm_RegDefine11N.h @@ -31,8 +31,8 @@ #define ODM_REG_TX_ANT_CTRL_11N 0x80C #define ODM_REG_BB_PWR_SAV5_11N 0x818 #define ODM_REG_CCK_RPT_FORMAT_11N 0x824 -#define ODM_REG_RX_DEFUALT_A_11N 0x858 -#define ODM_REG_RX_DEFUALT_B_11N 0x85A +#define ODM_REG_RX_DEFAULT_A_11N 0x858 +#define ODM_REG_RX_DEFAULT_B_11N 0x85A #define ODM_REG_BB_PWR_SAV3_11N 0x85C #define ODM_REG_ANTSEL_CTRL_11N 0x860 #define ODM_REG_RX_ANT_CTRL_11N 0x864 diff --git a/drivers/staging/rtl8723bs/hal/sdio_halinit.c b/drivers/staging/rtl8723bs/hal/sdio_halinit.c index 7853af53051d..e42d8c18e1ae 100644 --- a/drivers/staging/rtl8723bs/hal/sdio_halinit.c +++ b/drivers/staging/rtl8723bs/hal/sdio_halinit.c @@ -544,13 +544,9 @@ static void _InitRetryFunction(struct adapter *padapter) static void HalRxAggr8723BSdio(struct adapter *padapter) { - struct registry_priv *pregistrypriv; u8 valueDMATimeout; u8 valueDMAPageCount; - - pregistrypriv = &padapter->registrypriv; - valueDMATimeout = 0x06; valueDMAPageCount = 0x06; diff --git a/drivers/staging/rtl8723bs/include/hal_data.h b/drivers/staging/rtl8723bs/include/hal_data.h index e5e667df6154..fa5d70016f05 100644 --- a/drivers/staging/rtl8723bs/include/hal_data.h +++ b/drivers/staging/rtl8723bs/include/hal_data.h @@ -56,9 +56,9 @@ enum RT_AMPDU_BURST { /* Tx Power Limit Table Size */ #define MAX_REGULATION_NUM 4 #define MAX_RF_PATH_NUM_IN_POWER_LIMIT_TABLE 4 -#define MAX_2_4G_BANDWITH_NUM 4 +#define MAX_2_4G_BANDWIDTH_NUM 4 #define MAX_RATE_SECTION_NUM 10 -#define MAX_5G_BANDWITH_NUM 4 +#define MAX_5G_BANDWIDTH_NUM 4 #define MAX_BASE_NUM_IN_PHY_REG_PG_2_4G 10 /* CCK:1, OFDM:1, HT:4, VHT:4 */ #define MAX_BASE_NUM_IN_PHY_REG_PG_5G 9 /* OFDM:1, HT:4, VHT:4 */ @@ -280,14 +280,14 @@ struct hal_com_data { /* Power Limit Table for 2.4G */ s8 TxPwrLimit_2_4G[MAX_REGULATION_NUM] - [MAX_2_4G_BANDWITH_NUM] + [MAX_2_4G_BANDWIDTH_NUM] [MAX_RATE_SECTION_NUM] [CHANNEL_MAX_NUMBER_2G] [MAX_RF_PATH_NUM]; /* Power Limit Table for 5G */ s8 TxPwrLimit_5G[MAX_REGULATION_NUM] - [MAX_5G_BANDWITH_NUM] + [MAX_5G_BANDWIDTH_NUM] [MAX_RATE_SECTION_NUM] [CHANNEL_MAX_NUMBER_5G] [MAX_RF_PATH_NUM]; diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c index 59568d18ce23..e478290b60a8 100644 --- a/drivers/staging/sm750fb/sm750.c +++ b/drivers/staging/sm750fb/sm750.c @@ -709,7 +709,9 @@ static int sm750fb_set_drv(struct lynxfb_par *par) } else { output->paths = sm750_crt; crtc->channel = sm750_primary; - /* not consider of padding stuffs for oScreen,need fix */ + /* not consider of padding stuffs for oScreen, + * need fix + */ crtc->oScreen = sm750_dev->vidmem_size >> 1; crtc->vScreen = sm750_dev->pvMem + crtc->oScreen; } diff --git a/drivers/staging/sm750fb/sm750.h b/drivers/staging/sm750fb/sm750.h index ce90adcb449d..55fe5a28a174 100644 --- a/drivers/staging/sm750fb/sm750.h +++ b/drivers/staging/sm750fb/sm750.h @@ -59,16 +59,19 @@ struct lynx_accel { int (*de_wait)(void);/* see if hardware ready to work */ - int (*de_fillrect)(struct lynx_accel *, u32, u32, u32, u32, - u32, u32, u32, u32, u32); - - int (*de_copyarea)(struct lynx_accel *, u32, u32, u32, u32, - u32, u32, u32, u32, - u32, u32, u32, u32); - - int (*de_imageblit)(struct lynx_accel *, const char *, u32, u32, u32, u32, - u32, u32, u32, u32, - u32, u32, u32, u32); + int (*de_fillrect)(struct lynx_accel *, + u32, u32, u32, u32, + u32, u32, u32, u32, u32); + + int (*de_copyarea)(struct lynx_accel *, + u32, u32, u32, u32, + u32, u32, u32, u32, + u32, u32, u32, u32); + + int (*de_imageblit)(struct lynx_accel *, const char *, + u32, u32, u32, u32, + u32, u32, u32, u32, + u32, u32, u32, u32); }; diff --git a/drivers/staging/sm750fb/sm750_hw.c b/drivers/staging/sm750fb/sm750_hw.c index b8d60701f898..7136d751cff5 100644 --- a/drivers/staging/sm750fb/sm750_hw.c +++ b/drivers/staging/sm750fb/sm750_hw.c @@ -51,7 +51,7 @@ int hw_sm750_map(struct sm750_dev *sm750_dev, struct pci_dev *pdev) /* now map mmio and vidmem */ sm750_dev->pvReg = ioremap(sm750_dev->vidreg_start, - sm750_dev->vidreg_size); + sm750_dev->vidreg_size); if (!sm750_dev->pvReg) { pr_err("mmio failed\n"); ret = -EFAULT; diff --git a/drivers/staging/unisys/visorhba/visorhba_main.c b/drivers/staging/unisys/visorhba/visorhba_main.c index dd979ee4dcf1..99c57ceeb357 100644 --- a/drivers/staging/unisys/visorhba/visorhba_main.c +++ b/drivers/staging/unisys/visorhba/visorhba_main.c @@ -292,7 +292,7 @@ static void cleanup_scsitaskmgmt_handles(struct idr *idrtable, * @tasktype: Type of taskmgmt command * @scsidev: Scsidev that issued command * - * Create a cmdrsp packet and send it to the Serivce Partition + * Create a cmdrsp packet and send it to the Service Partition * that will service this request. * * Return: Int representing whether command was queued successfully or not diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c index 33485184a98a..f783b632141b 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c @@ -233,7 +233,7 @@ static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream) } static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream, - struct snd_pcm_indirect *rec, size_t bytes) + struct snd_pcm_indirect *rec, size_t bytes) { struct snd_pcm_runtime *runtime = substream->runtime; struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; @@ -346,7 +346,7 @@ int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, const char *name, &snd_bcm2835_playback_ops); snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, - chip->card->dev, 128 * 1024, 128 * 1024); + chip->card->dev, 128 * 1024, 128 * 1024); if (spdif) chip->pcm_spdif = pcm; diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c index 597acef35d0b..6d554d49fd3f 100644 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c @@ -369,8 +369,7 @@ static void buffer_cb(struct vchiq_mmal_instance *instance, if (dev->capture.vc_start_timestamp != -1 && pts) { ktime_t timestamp; - s64 runtime_us = pts - - dev->capture.vc_start_timestamp; + s64 runtime_us = pts - dev->capture.vc_start_timestamp; timestamp = ktime_add_us(dev->capture.kernel_start_ts, runtime_us); v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, @@ -420,9 +419,8 @@ static int enable_camera(struct bm2835_mmal_dev *dev) return -EINVAL; } - ret = vchiq_mmal_component_enable( - dev->instance, - dev->component[COMP_CAMERA]); + ret = vchiq_mmal_component_enable(dev->instance, + dev->component[COMP_CAMERA]); if (ret < 0) { v4l2_err(&dev->v4l2_dev, "Failed enabling camera, ret %d\n", ret); @@ -451,10 +449,8 @@ static int disable_camera(struct bm2835_mmal_dev *dev) v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "Disabling camera\n"); - ret = - vchiq_mmal_component_disable( - dev->instance, - dev->component[COMP_CAMERA]); + ret = vchiq_mmal_component_disable(dev->instance, + dev->component[COMP_CAMERA]); if (ret < 0) { v4l2_err(&dev->v4l2_dev, "Failed disabling camera, ret %d\n", ret); @@ -555,8 +551,8 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count) /* enable the camera port */ dev->capture.port->cb_ctx = dev; - ret = - vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb); + ret = vchiq_mmal_port_enable(dev->instance, dev->capture.port, + buffer_cb); if (ret) { v4l2_err(&dev->v4l2_dev, "Failed to enable capture port - error %d. Disabling camera port again\n", @@ -668,7 +664,7 @@ static int set_overlay_params(struct bm2835_mmal_dev *dev, MMAL_DISPLAY_SET_ALPHA | MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN, - .layer = PREVIEW_LAYER, + .layer = 2, .alpha = dev->overlay.global_alpha, .fullscreen = 0, .dest_rect = { @@ -767,16 +763,14 @@ static int vidioc_overlay(struct file *file, void *f, unsigned int on) (!on && !dev->component[COMP_PREVIEW]->enabled)) return 0; /* already in requested state */ - src = - &dev->component[COMP_CAMERA]->output[CAM_PORT_PREVIEW]; + src = &dev->component[COMP_CAMERA]->output[CAM_PORT_PREVIEW]; if (!on) { /* disconnect preview ports and disable component */ ret = vchiq_mmal_port_disable(dev->instance, src); if (!ret) - ret = - vchiq_mmal_port_connect_tunnel(dev->instance, src, - NULL); + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, + NULL); if (ret >= 0) ret = vchiq_mmal_component_disable( dev->instance, @@ -800,9 +794,8 @@ static int vidioc_overlay(struct file *file, void *f, unsigned int on) if (enable_camera(dev) < 0) return -EINVAL; - ret = vchiq_mmal_component_enable( - dev->instance, - dev->component[COMP_PREVIEW]); + ret = vchiq_mmal_component_enable(dev->instance, + dev->component[COMP_PREVIEW]); if (ret < 0) return ret; @@ -1001,6 +994,141 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, return 0; } + +static int mmal_setup_video_component(struct bm2835_mmal_dev *dev, + struct v4l2_format *f) +{ + bool overlay_enabled = !!dev->component[COMP_PREVIEW]->enabled; + struct vchiq_mmal_port *preview_port; + int ret; + + preview_port = &dev->component[COMP_CAMERA]->output[CAM_PORT_PREVIEW]; + + /* Preview and encode ports need to match on resolution */ + if (overlay_enabled) { + /* Need to disable the overlay before we can update + * the resolution + */ + ret = vchiq_mmal_port_disable(dev->instance, preview_port); + if (!ret) { + ret = vchiq_mmal_port_connect_tunnel(dev->instance, + preview_port, + NULL); + } + } + preview_port->es.video.width = f->fmt.pix.width; + preview_port->es.video.height = f->fmt.pix.height; + preview_port->es.video.crop.x = 0; + preview_port->es.video.crop.y = 0; + preview_port->es.video.crop.width = f->fmt.pix.width; + preview_port->es.video.crop.height = f->fmt.pix.height; + preview_port->es.video.frame_rate.num = + dev->capture.timeperframe.denominator; + preview_port->es.video.frame_rate.den = + dev->capture.timeperframe.numerator; + ret = vchiq_mmal_port_set_format(dev->instance, preview_port); + + if (overlay_enabled) { + ret = vchiq_mmal_port_connect_tunnel(dev->instance, + preview_port, + &dev->component[COMP_PREVIEW]->input[0]); + if (ret) + return ret; + + ret = vchiq_mmal_port_enable(dev->instance, preview_port, NULL); + } + + return ret; +} + +static int mmal_setup_encode_component(struct bm2835_mmal_dev *dev, + struct v4l2_format *f, + struct vchiq_mmal_port *port, + struct vchiq_mmal_port *camera_port, + struct vchiq_mmal_component *component) +{ + struct mmal_fmt *mfmt = get_format(f); + int ret; + + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, + "vid_cap - set up encode comp\n"); + + /* configure buffering */ + camera_port->current_buffer.size = camera_port->recommended_buffer.size; + camera_port->current_buffer.num = camera_port->recommended_buffer.num; + + ret = vchiq_mmal_port_connect_tunnel(dev->instance, camera_port, + &component->input[0]); + if (ret) { + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, + "%s failed to create connection\n", __func__); + /* ensure capture is not going to be tried */ + dev->capture.port = NULL; + return ret; + } + + port->es.video.width = f->fmt.pix.width; + port->es.video.height = f->fmt.pix.height; + port->es.video.crop.x = 0; + port->es.video.crop.y = 0; + port->es.video.crop.width = f->fmt.pix.width; + port->es.video.crop.height = f->fmt.pix.height; + port->es.video.frame_rate.num = + dev->capture.timeperframe.denominator; + port->es.video.frame_rate.den = + dev->capture.timeperframe.numerator; + + port->format.encoding = mfmt->mmal; + port->format.encoding_variant = 0; + /* Set any encoding specific parameters */ + switch (mfmt->mmal_component) { + case COMP_VIDEO_ENCODE: + port->format.bitrate = dev->capture.encode_bitrate; + break; + case COMP_IMAGE_ENCODE: + /* Could set EXIF parameters here */ + break; + default: + break; + } + + ret = vchiq_mmal_port_set_format(dev->instance, port); + if (ret) { + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, + "%s failed to set format %dx%d fmt %08X\n", + __func__, + f->fmt.pix.width, + f->fmt.pix.height, + f->fmt.pix.pixelformat); + return ret; + } + + ret = vchiq_mmal_component_enable(dev->instance, component); + if (ret) { + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, + "%s Failed to enable encode components\n", __func__); + return ret; + } + + /* configure buffering */ + port->current_buffer.num = 1; + port->current_buffer.size = f->fmt.pix.sizeimage; + if (port->format.encoding == MMAL_ENCODING_JPEG) { + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, + "JPG - buf size now %d was %d\n", + f->fmt.pix.sizeimage, + port->current_buffer.size); + port->current_buffer.size = + (f->fmt.pix.sizeimage < (100 << 10)) ? + (100 << 10) : f->fmt.pix.sizeimage; + } + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, + "vid_cap - cur_buf.size set to %d\n", f->fmt.pix.sizeimage); + port->current_buffer.alignment = 0; + + return 0; +} + static int mmal_setup_components(struct bm2835_mmal_dev *dev, struct v4l2_format *f) { @@ -1075,8 +1203,7 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev, } remove_padding = mfmt->remove_padding; - vchiq_mmal_port_parameter_set(dev->instance, - camera_port, + vchiq_mmal_port_parameter_set(dev->instance, camera_port, MMAL_PARAMETER_NO_IMAGE_PADDING, &remove_padding, sizeof(remove_padding)); @@ -1096,46 +1223,7 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev, if (!ret && camera_port == &dev->component[COMP_CAMERA]->output[CAM_PORT_VIDEO]) { - bool overlay_enabled = - !!dev->component[COMP_PREVIEW]->enabled; - struct vchiq_mmal_port *preview_port = - &dev->component[COMP_CAMERA]->output[CAM_PORT_PREVIEW]; - /* Preview and encode ports need to match on resolution */ - if (overlay_enabled) { - /* Need to disable the overlay before we can update - * the resolution - */ - ret = - vchiq_mmal_port_disable(dev->instance, - preview_port); - if (!ret) - ret = - vchiq_mmal_port_connect_tunnel( - dev->instance, - preview_port, - NULL); - } - preview_port->es.video.width = f->fmt.pix.width; - preview_port->es.video.height = f->fmt.pix.height; - preview_port->es.video.crop.x = 0; - preview_port->es.video.crop.y = 0; - preview_port->es.video.crop.width = f->fmt.pix.width; - preview_port->es.video.crop.height = f->fmt.pix.height; - preview_port->es.video.frame_rate.num = - dev->capture.timeperframe.denominator; - preview_port->es.video.frame_rate.den = - dev->capture.timeperframe.numerator; - ret = vchiq_mmal_port_set_format(dev->instance, preview_port); - if (overlay_enabled) { - ret = vchiq_mmal_port_connect_tunnel( - dev->instance, - preview_port, - &dev->component[COMP_PREVIEW]->input[0]); - if (!ret) - ret = vchiq_mmal_port_enable(dev->instance, - preview_port, - NULL); - } + ret = mmal_setup_video_component(dev, f); } if (ret) { @@ -1145,128 +1233,39 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev, f->fmt.pix.pixelformat); /* ensure capture is not going to be tried */ dev->capture.port = NULL; - } else { - if (encode_component) { - v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, - "vid_cap - set up encode comp\n"); + return ret; + } - /* configure buffering */ - camera_port->current_buffer.size = - camera_port->recommended_buffer.size; - camera_port->current_buffer.num = - camera_port->recommended_buffer.num; + if (encode_component) { + ret = mmal_setup_encode_component(dev, f, port, + camera_port, + encode_component); - ret = - vchiq_mmal_port_connect_tunnel( - dev->instance, - camera_port, - &encode_component->input[0]); - if (ret) { - v4l2_dbg(1, bcm2835_v4l2_debug, - &dev->v4l2_dev, - "%s failed to create connection\n", - __func__); - /* ensure capture is not going to be tried */ - dev->capture.port = NULL; - } else { - port->es.video.width = f->fmt.pix.width; - port->es.video.height = f->fmt.pix.height; - port->es.video.crop.x = 0; - port->es.video.crop.y = 0; - port->es.video.crop.width = f->fmt.pix.width; - port->es.video.crop.height = f->fmt.pix.height; - port->es.video.frame_rate.num = - dev->capture.timeperframe.denominator; - port->es.video.frame_rate.den = - dev->capture.timeperframe.numerator; - - port->format.encoding = mfmt->mmal; - port->format.encoding_variant = 0; - /* Set any encoding specific parameters */ - switch (mfmt->mmal_component) { - case COMP_VIDEO_ENCODE: - port->format.bitrate = - dev->capture.encode_bitrate; - break; - case COMP_IMAGE_ENCODE: - /* Could set EXIF parameters here */ - break; - default: - break; - } - ret = vchiq_mmal_port_set_format(dev->instance, - port); - if (ret) - v4l2_dbg(1, bcm2835_v4l2_debug, - &dev->v4l2_dev, - "%s failed to set format %dx%d fmt %08X\n", - __func__, - f->fmt.pix.width, - f->fmt.pix.height, - f->fmt.pix.pixelformat - ); - } + if (ret) + return ret; + } else { + /* configure buffering */ + camera_port->current_buffer.num = 1; + camera_port->current_buffer.size = f->fmt.pix.sizeimage; + camera_port->current_buffer.alignment = 0; + } - if (!ret) { - ret = vchiq_mmal_component_enable( - dev->instance, - encode_component); - if (ret) { - v4l2_dbg(1, bcm2835_v4l2_debug, - &dev->v4l2_dev, - "%s Failed to enable encode components\n", - __func__); - } - } - if (!ret) { - /* configure buffering */ - port->current_buffer.num = 1; - port->current_buffer.size = - f->fmt.pix.sizeimage; - if (port->format.encoding == - MMAL_ENCODING_JPEG) { - v4l2_dbg(1, bcm2835_v4l2_debug, - &dev->v4l2_dev, - "JPG - buf size now %d was %d\n", - f->fmt.pix.sizeimage, - port->current_buffer.size); - port->current_buffer.size = - (f->fmt.pix.sizeimage < - (100 << 10)) ? - (100 << 10) : f->fmt.pix.sizeimage; - } - v4l2_dbg(1, bcm2835_v4l2_debug, - &dev->v4l2_dev, - "vid_cap - cur_buf.size set to %d\n", - f->fmt.pix.sizeimage); - port->current_buffer.alignment = 0; - } - } else { - /* configure buffering */ - camera_port->current_buffer.num = 1; - camera_port->current_buffer.size = f->fmt.pix.sizeimage; - camera_port->current_buffer.alignment = 0; - } + dev->capture.fmt = mfmt; + dev->capture.stride = f->fmt.pix.bytesperline; + dev->capture.width = camera_port->es.video.crop.width; + dev->capture.height = camera_port->es.video.crop.height; + dev->capture.buffersize = port->current_buffer.size; - if (!ret) { - dev->capture.fmt = mfmt; - dev->capture.stride = f->fmt.pix.bytesperline; - dev->capture.width = camera_port->es.video.crop.width; - dev->capture.height = camera_port->es.video.crop.height; - dev->capture.buffersize = port->current_buffer.size; - - /* select port for capture */ - dev->capture.port = port; - dev->capture.camera_port = camera_port; - dev->capture.encode_component = encode_component; - v4l2_dbg(1, bcm2835_v4l2_debug, - &dev->v4l2_dev, - "Set dev->capture.fmt %08X, %dx%d, stride %d, size %d", - port->format.encoding, - dev->capture.width, dev->capture.height, - dev->capture.stride, dev->capture.buffersize); - } - } + /* select port for capture */ + dev->capture.port = port; + dev->capture.camera_port = camera_port; + dev->capture.encode_component = encode_component; + v4l2_dbg(1, bcm2835_v4l2_debug, + &dev->v4l2_dev, + "Set dev->capture.fmt %08X, %dx%d, stride %d, size %d", + port->format.encoding, + dev->capture.width, dev->capture.height, + dev->capture.stride, dev->capture.buffersize); /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */ return ret; @@ -1658,9 +1657,8 @@ static int mmal_init(struct bm2835_mmal_dev *dev) dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0; /* get the preview component ready */ - ret = vchiq_mmal_component_init( - dev->instance, "ril.video_render", - &dev->component[COMP_PREVIEW]); + ret = vchiq_mmal_component_init(dev->instance, "ril.video_render", + &dev->component[COMP_PREVIEW]); if (ret < 0) goto unreg_camera; @@ -1672,9 +1670,8 @@ static int mmal_init(struct bm2835_mmal_dev *dev) } /* get the image encoder component ready */ - ret = vchiq_mmal_component_init( - dev->instance, "ril.image_encode", - &dev->component[COMP_IMAGE_ENCODE]); + ret = vchiq_mmal_component_init(dev->instance, "ril.image_encode", + &dev->component[COMP_IMAGE_ENCODE]); if (ret < 0) goto unreg_preview; @@ -1734,15 +1731,13 @@ static int mmal_init(struct bm2835_mmal_dev *dev) unreg_vid_encoder: pr_err("Cleanup: Destroy video encoder\n"); - vchiq_mmal_component_finalise( - dev->instance, - dev->component[COMP_VIDEO_ENCODE]); + vchiq_mmal_component_finalise(dev->instance, + dev->component[COMP_VIDEO_ENCODE]); unreg_image_encoder: pr_err("Cleanup: Destroy image encoder\n"); - vchiq_mmal_component_finalise( - dev->instance, - dev->component[COMP_IMAGE_ENCODE]); + vchiq_mmal_component_finalise(dev->instance, + dev->component[COMP_IMAGE_ENCODE]); unreg_preview: pr_err("Cleanup: Destroy video render\n"); @@ -1775,8 +1770,7 @@ static int bm2835_mmal_init_device(struct bm2835_mmal_dev *dev, /* video device needs to be able to access instance data */ video_set_drvdata(vfd, dev); - ret = video_register_device(vfd, - VFL_TYPE_VIDEO, + ret = video_register_device(vfd, VFL_TYPE_VIDEO, video_nr[dev->camera_num]); if (ret < 0) return ret; diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h index b5fce38de038..75524adff0f5 100644 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h @@ -30,79 +30,77 @@ enum { CAM_PORT_COUNT }; -#define PREVIEW_LAYER 2 - extern int bcm2835_v4l2_debug; struct bm2835_mmal_dev { /* v4l2 devices */ - struct v4l2_device v4l2_dev; - struct video_device vdev; - struct mutex mutex; + struct v4l2_device v4l2_dev; + struct video_device vdev; + struct mutex mutex; /* controls */ - struct v4l2_ctrl_handler ctrl_handler; - struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT]; - enum v4l2_scene_mode scene_mode; - struct mmal_colourfx colourfx; - int hflip; - int vflip; - int red_gain; - int blue_gain; + struct v4l2_ctrl_handler ctrl_handler; + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT]; + enum v4l2_scene_mode scene_mode; + struct mmal_colourfx colourfx; + int hflip; + int vflip; + int red_gain; + int blue_gain; enum mmal_parameter_exposuremode exposure_mode_user; enum v4l2_exposure_auto_type exposure_mode_v4l2_user; /* active exposure mode may differ if selected via a scene mode */ enum mmal_parameter_exposuremode exposure_mode_active; enum mmal_parameter_exposuremeteringmode metering_mode; - unsigned int manual_shutter_speed; - bool exp_auto_priority; + unsigned int manual_shutter_speed; + bool exp_auto_priority; bool manual_iso_enabled; u32 iso; /* allocated mmal instance and components */ - struct vchiq_mmal_instance *instance; - struct vchiq_mmal_component *component[COMP_COUNT]; + struct vchiq_mmal_instance *instance; + struct vchiq_mmal_component *component[COMP_COUNT]; int camera_use_count; struct v4l2_window overlay; struct { - unsigned int width; /* width */ - unsigned int height; /* height */ - unsigned int stride; /* stride */ - unsigned int buffersize; /* buffer size with padding */ - struct mmal_fmt *fmt; + unsigned int width; /* width */ + unsigned int height; /* height */ + unsigned int stride; /* stride */ + unsigned int buffersize; /* buffer size with padding */ + struct mmal_fmt *fmt; struct v4l2_fract timeperframe; /* H264 encode bitrate */ - int encode_bitrate; + int encode_bitrate; /* H264 bitrate mode. CBR/VBR */ - int encode_bitrate_mode; + int encode_bitrate_mode; /* H264 profile */ enum v4l2_mpeg_video_h264_profile enc_profile; /* H264 level */ enum v4l2_mpeg_video_h264_level enc_level; /* JPEG Q-factor */ - int q_factor; + int q_factor; - struct vb2_queue vb_vidq; + struct vb2_queue vb_vidq; /* VC start timestamp for streaming */ - s64 vc_start_timestamp; + s64 vc_start_timestamp; /* Kernel start timestamp for streaming */ ktime_t kernel_start_ts; /* Sequence number of last buffer */ - u32 sequence; + u32 sequence; - struct vchiq_mmal_port *port; /* port being used for capture */ + struct vchiq_mmal_port *port; /* port being used for capture */ /* camera port being used for capture */ - struct vchiq_mmal_port *camera_port; + struct vchiq_mmal_port *camera_port; /* component being used for encode */ struct vchiq_mmal_component *encode_component; /* number of frames remaining which driver should capture */ - unsigned int frame_count; + unsigned int frame_count; /* last frame completion */ - struct completion frame_cmplt; + struct completion frame_cmplt; } capture; diff --git a/drivers/staging/vc04_services/bcm2835-camera/controls.c b/drivers/staging/vc04_services/bcm2835-camera/controls.c index 5137fcf203d6..b096a12387f7 100644 --- a/drivers/staging/vc04_services/bcm2835-camera/controls.c +++ b/drivers/staging/vc04_services/bcm2835-camera/controls.c @@ -135,8 +135,8 @@ static const struct v4l2_to_mmal_effects_setting }; struct v4l2_mmal_scene_config { - enum v4l2_scene_mode v4l2_scene; - enum mmal_parameter_exposuremode exposure_mode; + enum v4l2_scene_mode v4l2_scene; + enum mmal_parameter_exposuremode exposure_mode; enum mmal_parameter_exposuremeteringmode metering_mode; }; @@ -377,11 +377,9 @@ static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev, dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT; break; - /* todo matrix weighting not added to Linux API till 3.9 - * case V4L2_EXPOSURE_METERING_MATRIX: - * dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX; - * break; - */ + case V4L2_EXPOSURE_METERING_MATRIX: + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX; + break; } if (dev->scene_mode == V4L2_SCENE_MODE_NONE) { @@ -516,42 +514,41 @@ static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev, struct mmal_parameter_imagefx_parameters imagefx; for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) { - if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) { - imagefx.effect = - v4l2_to_mmal_effects_values[i].mmal_effect; - imagefx.num_effect_params = - v4l2_to_mmal_effects_values[i].num_effect_params; - - if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS) - imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS; - - for (j = 0; j < imagefx.num_effect_params; j++) - imagefx.effect_parameter[j] = - v4l2_to_mmal_effects_values[i].effect_params[j]; - - dev->colourfx.enable = - v4l2_to_mmal_effects_values[i].col_fx_enable; - if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) { - dev->colourfx.u = - v4l2_to_mmal_effects_values[i].u; - dev->colourfx.v = - v4l2_to_mmal_effects_values[i].v; - } + if (ctrl->val != v4l2_to_mmal_effects_values[i].v4l2_effect) + continue; + + imagefx.effect = + v4l2_to_mmal_effects_values[i].mmal_effect; + imagefx.num_effect_params = + v4l2_to_mmal_effects_values[i].num_effect_params; - control = &dev->component[COMP_CAMERA]->control; + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS) + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS; - ret = vchiq_mmal_port_parameter_set( - dev->instance, control, - MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS, - &imagefx, sizeof(imagefx)); - if (ret) - goto exit; + for (j = 0; j < imagefx.num_effect_params; j++) + imagefx.effect_parameter[j] = + v4l2_to_mmal_effects_values[i].effect_params[j]; - ret = vchiq_mmal_port_parameter_set( - dev->instance, control, - MMAL_PARAMETER_COLOUR_EFFECT, - &dev->colourfx, sizeof(dev->colourfx)); + dev->colourfx.enable = + v4l2_to_mmal_effects_values[i].col_fx_enable; + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) { + dev->colourfx.u = v4l2_to_mmal_effects_values[i].u; + dev->colourfx.v = v4l2_to_mmal_effects_values[i].v; } + + control = &dev->component[COMP_CAMERA]->control; + + ret = vchiq_mmal_port_parameter_set( + dev->instance, control, + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS, + &imagefx, sizeof(imagefx)); + if (ret) + goto exit; + + ret = vchiq_mmal_port_parameter_set( + dev->instance, control, + MMAL_PARAMETER_COLOUR_EFFECT, + &dev->colourfx, sizeof(dev->colourfx)); } exit: @@ -841,8 +838,7 @@ static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev, enum mmal_parameter_exposuremeteringmode metering_mode; for (i = 0; i < ARRAY_SIZE(scene_configs); i++) { - if (scene_configs[i].v4l2_scene == - ctrl->val) { + if (scene_configs[i].v4l2_scene == ctrl->val) { scene = &scene_configs[i]; break; } @@ -1045,8 +1041,8 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = { { .id = V4L2_CID_EXPOSURE_METERING, .type = MMAL_CONTROL_TYPE_STD_MENU, - .min = ~0x7, - .max = V4L2_EXPOSURE_METERING_SPOT, + .min = ~0xf, + .max = V4L2_EXPOSURE_METERING_MATRIX, .def = V4L2_EXPOSURE_METERING_AVERAGE, .step = 0, .imenu = NULL, @@ -1282,21 +1278,18 @@ int set_framerate_params(struct bm2835_mmal_dev *dev) struct mmal_parameter_fps_range fps_range; int ret; + fps_range.fps_high.num = dev->capture.timeperframe.denominator; + fps_range.fps_high.den = dev->capture.timeperframe.numerator; + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) && (dev->exp_auto_priority)) { - /* Variable FPS. Define min FPS as 1fps. - * Max as max defined FPS. - */ + /* Variable FPS. Define min FPS as 1fps. */ fps_range.fps_low.num = 1; fps_range.fps_low.den = 1; - fps_range.fps_high.num = dev->capture.timeperframe.denominator; - fps_range.fps_high.den = dev->capture.timeperframe.numerator; } else { /* Fixed FPS - set min and max to be the same */ - fps_range.fps_low.num = fps_range.fps_high.num = - dev->capture.timeperframe.denominator; - fps_range.fps_low.den = fps_range.fps_high.den = - dev->capture.timeperframe.numerator; + fps_range.fps_low.num = fps_range.fps_high.num; + fps_range.fps_low.den = fps_range.fps_high.den; } v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h index ff5398737b4a..ce88fac7c24b 100644 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h @@ -26,13 +26,13 @@ struct mmal_msg_context; /* mapping between v4l and mmal video modes */ struct mmal_fmt { - u32 fourcc; /* v4l2 format id */ - int flags; /* v4l2 flags field */ - u32 mmal; - int depth; - u32 mmal_component; /* MMAL component index to be used to encode */ - u32 ybbp; /* depth of first Y plane for planar formats */ - bool remove_padding; /* Does the GPU have to remove padding, + u32 fourcc; /* v4l2 format id */ + int flags; /* v4l2 flags field */ + u32 mmal; + int depth; + u32 mmal_component; /* MMAL component index to be used to encode */ + u32 ybbp; /* depth of first Y plane for planar formats */ + bool remove_padding; /* Does the GPU have to remove padding, * or can we do hide padding via bytesperline. */ }; @@ -40,10 +40,10 @@ struct mmal_fmt { /* buffer for one video frame */ struct mmal_buffer { /* v4l buffer data -- must be first */ - struct vb2_v4l2_buffer vb; + struct vb2_v4l2_buffer vb; /* list of buffers available */ - struct list_head list; + struct list_head list; void *buffer; /* buffer pointer */ unsigned long buffer_size; /* size of allocated buffer */ diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-parameters.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-parameters.h index 80a99128f5f3..f4ac5a6149ea 100644 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-parameters.h +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-parameters.h @@ -724,11 +724,11 @@ struct mmal_parameter_imagefx_parameters { #define MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN 16 struct mmal_parameter_camera_info_camera_t { - u32 port_id; - u32 max_width; - u32 max_height; - u32 lens_present; - u8 camera_name[MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN]; + u32 port_id; + u32 max_width; + u32 max_height; + u32 lens_present; + u8 camera_name[MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN]; }; enum mmal_parameter_camera_info_flash_type_t { @@ -744,8 +744,8 @@ struct mmal_parameter_camera_info_flash_t { }; struct mmal_parameter_camera_info_t { - u32 num_cameras; - u32 num_flashes; + u32 num_cameras; + u32 num_flashes; struct mmal_parameter_camera_info_camera_t cameras[MMAL_PARAMETER_CAMERA_INFO_MAX_CAMERAS]; struct mmal_parameter_camera_info_flash_t 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 a1ea9777a444..2d3e114f4a66 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -2353,7 +2353,7 @@ vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service, enum vchiq_status ret = VCHIQ_SUCCESS; char entity[16]; int *entity_uc; - int local_uc, local_entity_uc; + int local_uc; if (!arm_state) goto out; @@ -2377,7 +2377,7 @@ vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service, write_lock_bh(&arm_state->susp_res_lock); local_uc = ++arm_state->videocore_use_count; - local_entity_uc = ++(*entity_uc); + ++(*entity_uc); vchiq_log_trace(vchiq_susp_log_level, "%s %s count %d, state count %d", diff --git a/drivers/staging/vt6655/baseband.c b/drivers/staging/vt6655/baseband.c index b4cdc0b7fee7..6b25d75d2501 100644 --- a/drivers/staging/vt6655/baseband.c +++ b/drivers/staging/vt6655/baseband.c @@ -12,12 +12,10 @@ * Date: Aug.22, 2002 * * Functions: - * BBuGetFrameTime - Calculate data frame transmitting time - * BBvCalculateParameter - Calculate PhyLength, PhyService and Phy Signal - * parameter for baseband Tx - * BBbReadEmbedded - Embedded read baseband register via MAC - * BBbWriteEmbedded - Embedded write baseband register via MAC - * BBbVT3253Init - VIA VT3253 baseband chip init code + * bb_get_frame_time - Calculate data frame transmitting time + * bb_read_embedded - Embedded read baseband register via MAC + * bb_write_embedded - Embedded write baseband register via MAC + * bb_vt3253_init - VIA VT3253 baseband chip init code * * Revision History: * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec. @@ -1695,53 +1693,53 @@ static const unsigned short awcFrameTime[MAX_RATE] = { * * Parameters: * In: - * byPreambleType - Preamble Type - * byPktType - PK_TYPE_11A, PK_TYPE_11B, PK_TYPE_11GB, PK_TYPE_11GA - * cbFrameLength - Baseband Type - * wRate - Tx Rate + * by_preamble_type - Preamble Type + * by_pkt_type - PK_TYPE_11A, PK_TYPE_11B, PK_TYPE_11GB, PK_TYPE_11GA + * cb_frame_length - Baseband Type + * tx_rate - Tx Rate * Out: * * Return Value: FrameTime * */ -unsigned int BBuGetFrameTime(unsigned char byPreambleType, - unsigned char byPktType, - unsigned int cbFrameLength, unsigned short wRate) +unsigned int bb_get_frame_time(unsigned char by_preamble_type, + unsigned char by_pkt_type, + unsigned int cb_frame_length, + unsigned short tx_rate) { - unsigned int uFrameTime; - unsigned int uPreamble; - unsigned int uTmp; - unsigned int uRateIdx = (unsigned int)wRate; - unsigned int uRate = 0; + unsigned int frame_time; + unsigned int preamble; + unsigned int tmp; + unsigned int rate_idx = (unsigned int)tx_rate; + unsigned int rate = 0; - if (uRateIdx > RATE_54M) + if (rate_idx > RATE_54M) return 0; - uRate = (unsigned int)awcFrameTime[uRateIdx]; + rate = (unsigned int)awcFrameTime[rate_idx]; - if (uRateIdx <= 3) { /* CCK mode */ - if (byPreambleType == 1) /* Short */ - uPreamble = 96; + if (rate_idx <= 3) { /* CCK mode */ + if (by_preamble_type == 1) /* Short */ + preamble = 96; else - uPreamble = 192; - - uFrameTime = (cbFrameLength * 80) / uRate; /* ????? */ - uTmp = (uFrameTime * uRate) / 80; - if (cbFrameLength != uTmp) - uFrameTime++; + preamble = 192; + frame_time = (cb_frame_length * 80) / rate; /* ????? */ + tmp = (frame_time * rate) / 80; + if (cb_frame_length != tmp) + frame_time++; - return uPreamble + uFrameTime; + return preamble + frame_time; } - uFrameTime = (cbFrameLength * 8 + 22) / uRate; /* ???????? */ - uTmp = ((uFrameTime * uRate) - 22) / 8; - if (cbFrameLength != uTmp) - uFrameTime++; + frame_time = (cb_frame_length * 8 + 22) / rate; /* ???????? */ + tmp = ((frame_time * rate) - 22) / 8; + if (cb_frame_length != tmp) + frame_time++; - uFrameTime = uFrameTime * 4; /* ??????? */ - if (byPktType != PK_TYPE_11A) - uFrameTime += 6; /* ?????? */ + frame_time = frame_time * 4; /* ??????? */ + if (by_pkt_type != PK_TYPE_11A) + frame_time += 6; /* ?????? */ - return 20 + uFrameTime; /* ?????? */ + return 20 + frame_time; /* ?????? */ } /* @@ -1899,34 +1897,34 @@ void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length, * Parameters: * In: * iobase - I/O base address - * byBBAddr - address of register in Baseband + * by_bb_addr - address of register in Baseband * Out: - * pbyData - data read + * pby_data - data read * * Return Value: true if succeeded; false if failed. * */ -bool BBbReadEmbedded(struct vnt_private *priv, - unsigned char byBBAddr, unsigned char *pbyData) +bool bb_read_embedded(struct vnt_private *priv, unsigned char by_bb_addr, + unsigned char *pby_data) { void __iomem *iobase = priv->PortOffset; unsigned short ww; - unsigned char byValue; + unsigned char by_value; /* BB reg offset */ - VNSvOutPortB(iobase + MAC_REG_BBREGADR, byBBAddr); + VNSvOutPortB(iobase + MAC_REG_BBREGADR, by_bb_addr); /* turn on REGR */ MACvRegBitsOn(iobase, MAC_REG_BBREGCTL, BBREGCTL_REGR); /* W_MAX_TIMEOUT is the timeout period */ for (ww = 0; ww < W_MAX_TIMEOUT; ww++) { - VNSvInPortB(iobase + MAC_REG_BBREGCTL, &byValue); - if (byValue & BBREGCTL_DONE) + VNSvInPortB(iobase + MAC_REG_BBREGCTL, &by_value); + if (by_value & BBREGCTL_DONE) break; } /* get BB data */ - VNSvInPortB(iobase + MAC_REG_BBREGDATA, pbyData); + VNSvInPortB(iobase + MAC_REG_BBREGDATA, pby_data); if (ww == W_MAX_TIMEOUT) { pr_debug(" DBG_PORT80(0x30)\n"); @@ -1941,32 +1939,32 @@ bool BBbReadEmbedded(struct vnt_private *priv, * Parameters: * In: * iobase - I/O base address - * byBBAddr - address of register in Baseband - * byData - data to write + * by_bb_addr - address of register in Baseband + * by_data - data to write * Out: * none * * Return Value: true if succeeded; false if failed. * */ -bool BBbWriteEmbedded(struct vnt_private *priv, - unsigned char byBBAddr, unsigned char byData) +bool bb_write_embedded(struct vnt_private *priv, unsigned char by_bb_addr, + unsigned char by_data) { void __iomem *iobase = priv->PortOffset; unsigned short ww; - unsigned char byValue; + unsigned char by_value; /* BB reg offset */ - VNSvOutPortB(iobase + MAC_REG_BBREGADR, byBBAddr); + VNSvOutPortB(iobase + MAC_REG_BBREGADR, by_bb_addr); /* set BB data */ - VNSvOutPortB(iobase + MAC_REG_BBREGDATA, byData); + VNSvOutPortB(iobase + MAC_REG_BBREGDATA, by_data); /* turn on BBREGCTL_REGW */ MACvRegBitsOn(iobase, MAC_REG_BBREGCTL, BBREGCTL_REGW); /* W_MAX_TIMEOUT is the timeout period */ for (ww = 0; ww < W_MAX_TIMEOUT; ww++) { - VNSvInPortB(iobase + MAC_REG_BBREGCTL, &byValue); - if (byValue & BBREGCTL_DONE) + VNSvInPortB(iobase + MAC_REG_BBREGCTL, &by_value); + if (by_value & BBREGCTL_DONE) break; } @@ -1992,29 +1990,29 @@ bool BBbWriteEmbedded(struct vnt_private *priv, * */ -bool BBbVT3253Init(struct vnt_private *priv) +bool bb_vt3253_init(struct vnt_private *priv) { - bool bResult = true; + bool result = true; int ii; void __iomem *iobase = priv->PortOffset; - unsigned char byRFType = priv->byRFType; - unsigned char byLocalID = priv->byLocalID; + unsigned char by_rf_type = priv->byRFType; + unsigned char by_local_id = priv->byLocalID; - if (byRFType == RF_RFMD2959) { - if (byLocalID <= REV_ID_VT3253_A1) { + if (by_rf_type == RF_RFMD2959) { + if (by_local_id <= REV_ID_VT3253_A1) { for (ii = 0; ii < CB_VT3253_INIT_FOR_RFMD; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253InitTab_RFMD[ii][0], byVT3253InitTab_RFMD[ii][1]); } else { for (ii = 0; ii < CB_VT3253B0_INIT_FOR_RFMD; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_RFMD[ii][0], byVT3253B0_RFMD[ii][1]); for (ii = 0; ii < CB_VT3253B0_AGC_FOR_RFMD2959; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_AGC4_RFMD2959[ii][0], byVT3253B0_AGC4_RFMD2959[ii][1]); @@ -2029,14 +2027,14 @@ bool BBbVT3253Init(struct vnt_private *priv) priv->ldBmThreshold[1] = -50; priv->ldBmThreshold[2] = 0; priv->ldBmThreshold[3] = 0; - } else if ((byRFType == RF_AIROHA) || (byRFType == RF_AL2230S)) { + } else if ((by_rf_type == RF_AIROHA) || (by_rf_type == RF_AL2230S)) { for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]); for (ii = 0; ii < CB_VT3253B0_AGC; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]); priv->abyBBVGA[0] = 0x1C; @@ -2047,14 +2045,14 @@ bool BBbVT3253Init(struct vnt_private *priv) priv->ldBmThreshold[1] = -48; priv->ldBmThreshold[2] = 0; priv->ldBmThreshold[3] = 0; - } else if (byRFType == RF_UW2451) { + } else if (by_rf_type == RF_UW2451) { for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_UW2451[ii][0], byVT3253B0_UW2451[ii][1]); for (ii = 0; ii < CB_VT3253B0_AGC; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]); @@ -2069,9 +2067,9 @@ bool BBbVT3253Init(struct vnt_private *priv) priv->ldBmThreshold[1] = -50; priv->ldBmThreshold[2] = 0; priv->ldBmThreshold[3] = 0; - } else if (byRFType == RF_UW2452) { + } else if (by_rf_type == RF_UW2452) { for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_UW2451[ii][0], byVT3253B0_UW2451[ii][1]); @@ -2080,7 +2078,7 @@ bool BBbVT3253Init(struct vnt_private *priv) * 0x45->0x41(VC1/VC2 define, make the ANT_A, ANT_B inverted) */ - /*bResult &= BBbWriteEmbedded(iobase,0x09,0x41);*/ + /*bResult &= bb_write_embedded(iobase,0x09,0x41);*/ /* Init ANT B select, * RX Config CR10 = 0x28->0x2A, @@ -2088,23 +2086,23 @@ bool BBbVT3253Init(struct vnt_private *priv) * make the ANT_A, ANT_B inverted) */ - /*bResult &= BBbWriteEmbedded(iobase,0x0a,0x28);*/ + /*bResult &= bb_write_embedded(iobase,0x0a,0x28);*/ /* Select VC1/VC2, CR215 = 0x02->0x06 */ - bResult &= BBbWriteEmbedded(priv, 0xd7, 0x06); + result &= bb_write_embedded(priv, 0xd7, 0x06); /* {{RobertYu:20050125, request by Jack */ - bResult &= BBbWriteEmbedded(priv, 0x90, 0x20); - bResult &= BBbWriteEmbedded(priv, 0x97, 0xeb); + result &= bb_write_embedded(priv, 0x90, 0x20); + result &= bb_write_embedded(priv, 0x97, 0xeb); /* }} */ /* {{RobertYu:20050221, request by Jack */ - bResult &= BBbWriteEmbedded(priv, 0xa6, 0x00); - bResult &= BBbWriteEmbedded(priv, 0xa8, 0x30); + result &= bb_write_embedded(priv, 0xa6, 0x00); + result &= bb_write_embedded(priv, 0xa8, 0x30); /* }} */ - bResult &= BBbWriteEmbedded(priv, 0xb0, 0x58); + result &= bb_write_embedded(priv, 0xb0, 0x58); for (ii = 0; ii < CB_VT3253B0_AGC; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]); priv->abyBBVGA[0] = 0x14; @@ -2117,14 +2115,14 @@ bool BBbVT3253Init(struct vnt_private *priv) priv->ldBmThreshold[3] = 0; /* }} RobertYu */ - } else if (byRFType == RF_VT3226) { + } else if (by_rf_type == RF_VT3226) { for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]); for (ii = 0; ii < CB_VT3253B0_AGC; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]); priv->abyBBVGA[0] = 0x1C; @@ -2138,9 +2136,9 @@ bool BBbVT3253Init(struct vnt_private *priv) /* Fix VT3226 DFC system timing issue */ MACvSetRFLE_LatchBase(iobase); /* {{ RobertYu: 20050104 */ - } else if (byRFType == RF_AIROHA7230) { + } else if (by_rf_type == RF_AIROHA7230) { for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]); @@ -2148,17 +2146,17 @@ bool BBbVT3253Init(struct vnt_private *priv) /* Init ANT B select,TX Config CR09 = 0x61->0x45, * 0x45->0x41(VC1/VC2 define, make the ANT_A, ANT_B inverted) */ - /*bResult &= BBbWriteEmbedded(iobase,0x09,0x41);*/ + /* bResult &= bb_write_embedded(iobase,0x09,0x41);*/ /* Init ANT B select,RX Config CR10 = 0x28->0x2A, * 0x2A->0x28(VC1/VC2 define, make the ANT_A, ANT_B inverted) */ - /*bResult &= BBbWriteEmbedded(iobase,0x0a,0x28);*/ + /* bResult &= BBbWriteEmbedded(iobase,0x0a,0x28);*/ /* Select VC1/VC2, CR215 = 0x02->0x06 */ - bResult &= BBbWriteEmbedded(priv, 0xd7, 0x06); + result &= bb_write_embedded(priv, 0xd7, 0x06); /* }} */ for (ii = 0; ii < CB_VT3253B0_AGC; ii++) - bResult &= BBbWriteEmbedded(priv, + result &= bb_write_embedded(priv, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]); priv->abyBBVGA[0] = 0x1C; @@ -2176,12 +2174,12 @@ bool BBbVT3253Init(struct vnt_private *priv) priv->abyBBVGA[0] = 0x1C; } - if (byLocalID > REV_ID_VT3253_A1) { - BBbWriteEmbedded(priv, 0x04, 0x7F); - BBbWriteEmbedded(priv, 0x0D, 0x01); + if (by_local_id > REV_ID_VT3253_A1) { + bb_write_embedded(priv, 0x04, 0x7F); + bb_write_embedded(priv, 0x0D, 0x01); } - return bResult; + return result; } /* @@ -2197,42 +2195,42 @@ bool BBbVT3253Init(struct vnt_private *priv) * */ void -BBvSetShortSlotTime(struct vnt_private *priv) +bb_set_short_slot_time(struct vnt_private *priv) { - unsigned char byBBRxConf = 0; - unsigned char byBBVGA = 0; + unsigned char by_bb_rx_conf = 0; + unsigned char by_bb_vga = 0; - BBbReadEmbedded(priv, 0x0A, &byBBRxConf); /* CR10 */ + bb_read_embedded(priv, 0x0A, &by_bb_rx_conf); /* CR10 */ if (priv->bShortSlotTime) - byBBRxConf &= 0xDF; /* 1101 1111 */ + by_bb_rx_conf &= 0xDF; /* 1101 1111 */ else - byBBRxConf |= 0x20; /* 0010 0000 */ + by_bb_rx_conf |= 0x20; /* 0010 0000 */ /* patch for 3253B0 Baseband with Cardbus module */ - BBbReadEmbedded(priv, 0xE7, &byBBVGA); - if (byBBVGA == priv->abyBBVGA[0]) - byBBRxConf |= 0x20; /* 0010 0000 */ + bb_read_embedded(priv, 0xE7, &by_bb_vga); + if (by_bb_vga == priv->abyBBVGA[0]) + by_bb_rx_conf |= 0x20; /* 0010 0000 */ - BBbWriteEmbedded(priv, 0x0A, byBBRxConf); /* CR10 */ + bb_write_embedded(priv, 0x0A, by_bb_rx_conf); /* CR10 */ } -void BBvSetVGAGainOffset(struct vnt_private *priv, unsigned char byData) +void bb_set_vga_gain_offset(struct vnt_private *priv, unsigned char by_data) { - unsigned char byBBRxConf = 0; + unsigned char by_bb_rx_conf = 0; - BBbWriteEmbedded(priv, 0xE7, byData); + bb_write_embedded(priv, 0xE7, by_data); - BBbReadEmbedded(priv, 0x0A, &byBBRxConf); /* CR10 */ + bb_read_embedded(priv, 0x0A, &by_bb_rx_conf); /* CR10 */ /* patch for 3253B0 Baseband with Cardbus module */ - if (byData == priv->abyBBVGA[0]) - byBBRxConf |= 0x20; /* 0010 0000 */ + if (by_data == priv->abyBBVGA[0]) + by_bb_rx_conf |= 0x20; /* 0010 0000 */ else if (priv->bShortSlotTime) - byBBRxConf &= 0xDF; /* 1101 1111 */ + by_bb_rx_conf &= 0xDF; /* 1101 1111 */ else - byBBRxConf |= 0x20; /* 0010 0000 */ - priv->byBBVGACurrent = byData; - BBbWriteEmbedded(priv, 0x0A, byBBRxConf); /* CR10 */ + by_bb_rx_conf |= 0x20; /* 0010 0000 */ + priv->byBBVGACurrent = by_data; + bb_write_embedded(priv, 0x0A, by_bb_rx_conf); /* CR10 */ } /* @@ -2248,12 +2246,12 @@ void BBvSetVGAGainOffset(struct vnt_private *priv, unsigned char byData) * */ void -BBvSoftwareReset(struct vnt_private *priv) +bb_software_reset(struct vnt_private *priv) { - BBbWriteEmbedded(priv, 0x50, 0x40); - BBbWriteEmbedded(priv, 0x50, 0); - BBbWriteEmbedded(priv, 0x9C, 0x01); - BBbWriteEmbedded(priv, 0x9C, 0); + bb_write_embedded(priv, 0x50, 0x40); + bb_write_embedded(priv, 0x50, 0); + bb_write_embedded(priv, 0x9C, 0x01); + bb_write_embedded(priv, 0x9C, 0); } /* @@ -2269,13 +2267,13 @@ BBvSoftwareReset(struct vnt_private *priv) * */ void -BBvPowerSaveModeON(struct vnt_private *priv) +bb_power_save_mode_on(struct vnt_private *priv) { - unsigned char byOrgData; + unsigned char by_org_data; - BBbReadEmbedded(priv, 0x0D, &byOrgData); - byOrgData |= BIT(0); - BBbWriteEmbedded(priv, 0x0D, byOrgData); + bb_read_embedded(priv, 0x0D, &by_org_data); + by_org_data |= BIT(0); + bb_write_embedded(priv, 0x0D, by_org_data); } /* @@ -2291,13 +2289,13 @@ BBvPowerSaveModeON(struct vnt_private *priv) * */ void -BBvPowerSaveModeOFF(struct vnt_private *priv) +bb_power_save_mode_off(struct vnt_private *priv) { - unsigned char byOrgData; + unsigned char by_org_data; - BBbReadEmbedded(priv, 0x0D, &byOrgData); - byOrgData &= ~(BIT(0)); - BBbWriteEmbedded(priv, 0x0D, byOrgData); + bb_read_embedded(priv, 0x0D, &by_org_data); + by_org_data &= ~(BIT(0)); + bb_write_embedded(priv, 0x0D, by_org_data); } /* @@ -2306,7 +2304,7 @@ BBvPowerSaveModeOFF(struct vnt_private *priv) * Parameters: * In: * priv - Device Structure - * byAntennaMode - Antenna Mode + * by_antenna_mode - Antenna Mode * Out: * none * @@ -2315,22 +2313,22 @@ BBvPowerSaveModeOFF(struct vnt_private *priv) */ void -BBvSetTxAntennaMode(struct vnt_private *priv, unsigned char byAntennaMode) +bb_set_tx_antenna_mode(struct vnt_private *priv, unsigned char by_antenna_mode) { - unsigned char byBBTxConf; + unsigned char by_bb_tx_conf; - BBbReadEmbedded(priv, 0x09, &byBBTxConf); /* CR09 */ - if (byAntennaMode == ANT_DIVERSITY) { + bb_read_embedded(priv, 0x09, &by_bb_tx_conf); /* CR09 */ + if (by_antenna_mode == ANT_DIVERSITY) { /* bit 1 is diversity */ - byBBTxConf |= 0x02; - } else if (byAntennaMode == ANT_A) { + by_bb_tx_conf |= 0x02; + } else if (by_antenna_mode == ANT_A) { /* bit 2 is ANTSEL */ - byBBTxConf &= 0xF9; /* 1111 1001 */ - } else if (byAntennaMode == ANT_B) { - byBBTxConf &= 0xFD; /* 1111 1101 */ - byBBTxConf |= 0x04; + by_bb_tx_conf &= 0xF9; /* 1111 1001 */ + } else if (by_antenna_mode == ANT_B) { + by_bb_tx_conf &= 0xFD; /* 1111 1101 */ + by_bb_tx_conf |= 0x04; } - BBbWriteEmbedded(priv, 0x09, byBBTxConf); /* CR09 */ + bb_write_embedded(priv, 0x09, by_bb_tx_conf); /* CR09 */ } /* @@ -2339,7 +2337,7 @@ BBvSetTxAntennaMode(struct vnt_private *priv, unsigned char byAntennaMode) * Parameters: * In: * priv - Device Structure - * byAntennaMode - Antenna Mode + * by_antenna_mode - Antenna Mode * Out: * none * @@ -2348,25 +2346,25 @@ BBvSetTxAntennaMode(struct vnt_private *priv, unsigned char byAntennaMode) */ void -BBvSetRxAntennaMode(struct vnt_private *priv, unsigned char byAntennaMode) +bb_set_rx_antenna_mode(struct vnt_private *priv, unsigned char by_antenna_mode) { - unsigned char byBBRxConf; + unsigned char by_bb_rx_conf; - BBbReadEmbedded(priv, 0x0A, &byBBRxConf); /* CR10 */ - if (byAntennaMode == ANT_DIVERSITY) { - byBBRxConf |= 0x01; + bb_read_embedded(priv, 0x0A, &by_bb_rx_conf); /* CR10 */ + if (by_antenna_mode == ANT_DIVERSITY) { + by_bb_rx_conf |= 0x01; - } else if (byAntennaMode == ANT_A) { - byBBRxConf &= 0xFC; /* 1111 1100 */ - } else if (byAntennaMode == ANT_B) { - byBBRxConf &= 0xFE; /* 1111 1110 */ - byBBRxConf |= 0x02; + } else if (by_antenna_mode == ANT_A) { + by_bb_rx_conf &= 0xFC; /* 1111 1100 */ + } else if (by_antenna_mode == ANT_B) { + by_bb_rx_conf &= 0xFE; /* 1111 1110 */ + by_bb_rx_conf |= 0x02; } - BBbWriteEmbedded(priv, 0x0A, byBBRxConf); /* CR10 */ + bb_write_embedded(priv, 0x0A, by_bb_rx_conf); /* CR10 */ } /* - * Description: BBvSetDeepSleep + * Description: bb_set_deep_sleep * * Parameters: * In: @@ -2378,15 +2376,9 @@ BBvSetRxAntennaMode(struct vnt_private *priv, unsigned char byAntennaMode) * */ void -BBvSetDeepSleep(struct vnt_private *priv, unsigned char byLocalID) +bb_set_deep_sleep(struct vnt_private *priv, unsigned char by_local_id) { - BBbWriteEmbedded(priv, 0x0C, 0x17); /* CR12 */ - BBbWriteEmbedded(priv, 0x0D, 0xB9); /* CR13 */ + bb_write_embedded(priv, 0x0C, 0x17); /* CR12 */ + bb_write_embedded(priv, 0x0D, 0xB9); /* CR13 */ } -void -BBvExitDeepSleep(struct vnt_private *priv, unsigned char byLocalID) -{ - BBbWriteEmbedded(priv, 0x0C, 0x00); /* CR12 */ - BBbWriteEmbedded(priv, 0x0D, 0x01); /* CR13 */ -} diff --git a/drivers/staging/vt6655/baseband.h b/drivers/staging/vt6655/baseband.h index 0cc2e07829c5..9354ce724446 100644 --- a/drivers/staging/vt6655/baseband.h +++ b/drivers/staging/vt6655/baseband.h @@ -46,30 +46,31 @@ #define TOP_RATE_2M 0x00200000 #define TOP_RATE_1M 0x00100000 -unsigned int BBuGetFrameTime(unsigned char byPreambleType, - unsigned char byPktType, - unsigned int cbFrameLength, - unsigned short wRate); +unsigned int bb_get_frame_time(unsigned char by_preamble_type, + unsigned char by_pkt_type, + unsigned int cb_frame_length, + unsigned short w_rate); void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length, u16 tx_rate, u8 pkt_type, struct vnt_phy_field *phy); -bool BBbReadEmbedded(struct vnt_private *priv, unsigned char byBBAddr, - unsigned char *pbyData); -bool BBbWriteEmbedded(struct vnt_private *priv, unsigned char byBBAddr, - unsigned char byData); +bool bb_read_embedded(struct vnt_private *priv, unsigned char by_bb_addr, + unsigned char *pby_data); +bool bb_write_embedded(struct vnt_private *priv, unsigned char by_bb_addr, + unsigned char by_data); -void BBvSetShortSlotTime(struct vnt_private *priv); -void BBvSetVGAGainOffset(struct vnt_private *priv, unsigned char byData); +void bb_set_short_slot_time(struct vnt_private *priv); +void bb_set_vga_gain_offset(struct vnt_private *priv, unsigned char by_data); /* VT3253 Baseband */ -bool BBbVT3253Init(struct vnt_private *priv); -void BBvSoftwareReset(struct vnt_private *priv); -void BBvPowerSaveModeON(struct vnt_private *priv); -void BBvPowerSaveModeOFF(struct vnt_private *priv); -void BBvSetTxAntennaMode(struct vnt_private *priv, unsigned char byAntennaMode); -void BBvSetRxAntennaMode(struct vnt_private *priv, unsigned char byAntennaMode); -void BBvSetDeepSleep(struct vnt_private *priv, unsigned char byLocalID); -void BBvExitDeepSleep(struct vnt_private *priv, unsigned char byLocalID); +bool bb_vt3253_init(struct vnt_private *priv); +void bb_software_reset(struct vnt_private *priv); +void bb_power_save_mode_on(struct vnt_private *priv); +void bb_power_save_mode_off(struct vnt_private *priv); +void bb_set_tx_antenna_mode(struct vnt_private *priv, + unsigned char by_antenna_mode); +void bb_set_rx_antenna_mode(struct vnt_private *priv, + unsigned char by_antenna_mode); +void bb_set_deep_sleep(struct vnt_private *priv, unsigned char by_local_id); #endif /* __BASEBAND_H__ */ diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c index e65c9825ea5a..6148310c06d6 100644 --- a/drivers/staging/vt6655/card.c +++ b/drivers/staging/vt6655/card.c @@ -11,15 +11,12 @@ * CARDvUpdateBasicTopRate - Update BasicTopRate * CARDbAddBasicRate - Add to BasicRateSet * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet - * CARDvSetLoopbackMode - Set Loopback mode - * CARDbSoftwareReset - Sortware reset NIC * CARDqGetTSFOffset - Calculate TSFOffset * CARDbGetCurrentTSF - Read Current NIC TSF counter * CARDqGetNextTBTT - Calculate Next Beacon TSF counter * CARDvSetFirstNextTBTT - Set NIC Beacon time * CARDvUpdateNextTBTT - Sync. NIC Beacon time * CARDbRadioPowerOff - Turn Off NIC Radio Power - * CARDbRadioPowerOn - Turn On NIC Radio Power * * Revision History: * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec. @@ -198,22 +195,22 @@ bool CARDbSetPhyParameter(struct vnt_private *priv, u8 bb_type) priv->abyBBVGA[0] = 0x20; priv->abyBBVGA[2] = 0x10; priv->abyBBVGA[3] = 0x10; - BBbReadEmbedded(priv, 0xE7, &byData); + bb_read_embedded(priv, 0xE7, &byData); if (byData == 0x1C) - BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); + bb_write_embedded(priv, 0xE7, priv->abyBBVGA[0]); } else if (priv->byRFType == RF_UW2452) { MACvSetBBType(priv->PortOffset, BB_TYPE_11A); priv->abyBBVGA[0] = 0x18; - BBbReadEmbedded(priv, 0xE7, &byData); + bb_read_embedded(priv, 0xE7, &byData); if (byData == 0x14) { - BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); - BBbWriteEmbedded(priv, 0xE1, 0x57); + bb_write_embedded(priv, 0xE7, priv->abyBBVGA[0]); + bb_write_embedded(priv, 0xE1, 0x57); } } else { MACvSetBBType(priv->PortOffset, BB_TYPE_11A); } - BBbWriteEmbedded(priv, 0x88, 0x03); + bb_write_embedded(priv, 0x88, 0x03); bySlot = C_SLOT_SHORT; bySIFS = C_SIFS_A; byDIFS = C_SIFS_A + 2 * C_SLOT_SHORT; @@ -224,19 +221,19 @@ bool CARDbSetPhyParameter(struct vnt_private *priv, u8 bb_type) priv->abyBBVGA[0] = 0x1C; priv->abyBBVGA[2] = 0x00; priv->abyBBVGA[3] = 0x00; - BBbReadEmbedded(priv, 0xE7, &byData); + bb_read_embedded(priv, 0xE7, &byData); if (byData == 0x20) - BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); + bb_write_embedded(priv, 0xE7, priv->abyBBVGA[0]); } else if (priv->byRFType == RF_UW2452) { priv->abyBBVGA[0] = 0x14; - BBbReadEmbedded(priv, 0xE7, &byData); + bb_read_embedded(priv, 0xE7, &byData); if (byData == 0x18) { - BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); - BBbWriteEmbedded(priv, 0xE1, 0xD3); + bb_write_embedded(priv, 0xE7, priv->abyBBVGA[0]); + bb_write_embedded(priv, 0xE1, 0xD3); } } - BBbWriteEmbedded(priv, 0x88, 0x02); + bb_write_embedded(priv, 0x88, 0x02); bySlot = C_SLOT_LONG; bySIFS = C_SIFS_BG; byDIFS = C_SIFS_BG + 2 * C_SLOT_LONG; @@ -247,19 +244,19 @@ bool CARDbSetPhyParameter(struct vnt_private *priv, u8 bb_type) priv->abyBBVGA[0] = 0x1C; priv->abyBBVGA[2] = 0x00; priv->abyBBVGA[3] = 0x00; - BBbReadEmbedded(priv, 0xE7, &byData); + bb_read_embedded(priv, 0xE7, &byData); if (byData == 0x20) - BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); + bb_write_embedded(priv, 0xE7, priv->abyBBVGA[0]); } else if (priv->byRFType == RF_UW2452) { priv->abyBBVGA[0] = 0x14; - BBbReadEmbedded(priv, 0xE7, &byData); + bb_read_embedded(priv, 0xE7, &byData); if (byData == 0x18) { - BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); - BBbWriteEmbedded(priv, 0xE1, 0xD3); + bb_write_embedded(priv, 0xE7, priv->abyBBVGA[0]); + bb_write_embedded(priv, 0xE1, 0xD3); } } - BBbWriteEmbedded(priv, 0x88, 0x08); + bb_write_embedded(priv, 0x88, 0x08); bySIFS = C_SIFS_BG; if (priv->bShortSlotTime) { @@ -310,7 +307,7 @@ bool CARDbSetPhyParameter(struct vnt_private *priv, u8 bb_type) priv->bySlot = bySlot; VNSvOutPortB(priv->PortOffset + MAC_REG_SLOT, priv->bySlot); - BBvSetShortSlotTime(priv); + bb_set_short_slot_time(priv); } if (priv->byCWMaxMin != byCWMaxMin) { priv->byCWMaxMin = byCWMaxMin; @@ -431,7 +428,7 @@ void CARDbRadioPowerOff(struct vnt_private *priv) MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON); - BBvSetDeepSleep(priv, priv->byLocalID); + bb_set_deep_sleep(priv, priv->byLocalID); priv->bRadioOff = true; pr_debug("chester power off\n"); @@ -439,60 +436,6 @@ void CARDbRadioPowerOff(struct vnt_private *priv) LED_ACTSET); /* LED issue */ } -/* - * Description: Turn on Radio power - * - * Parameters: - * In: - * priv - The adapter to be turned on - * Out: - * none - * - * Return Value: true if success; otherwise false - */ -bool CARDbRadioPowerOn(struct vnt_private *priv) -{ - bool bResult = true; - - pr_debug("chester power on\n"); - if (priv->bRadioControlOff) { - if (priv->bHWRadioOff) - pr_debug("chester bHWRadioOff\n"); - if (priv->bRadioControlOff) - pr_debug("chester bRadioControlOff\n"); - return false; } - - if (!priv->bRadioOff) { - pr_debug("chester pbRadioOff\n"); - return true; } - - BBvExitDeepSleep(priv, priv->byLocalID); - - MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON); - - switch (priv->byRFType) { - case RF_RFMD2959: - MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL, - SOFTPWRCTL_TXPEINV); - MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL, - SOFTPWRCTL_SWPE1); - break; - - case RF_AIROHA: - case RF_AL2230S: - case RF_AIROHA7230: - MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL, - (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3)); - break; - } - - priv->bRadioOff = false; - pr_debug("chester power on\n"); - MACvRegBitsOff(priv->PortOffset, MAC_REG_GPIOCTL0, - LED_ACTSET); /* LED issue */ - return bResult; -} - void CARDvSafeResetTx(struct vnt_private *priv) { unsigned int uu; @@ -816,54 +759,6 @@ unsigned char CARDbyGetPktType(struct vnt_private *priv) } /* - * Description: Set NIC Loopback mode - * - * Parameters: - * In: - * priv - The adapter to be set - * wLoopbackMode - Loopback mode to be set - * Out: - * none - * - * Return Value: none - */ -void CARDvSetLoopbackMode(struct vnt_private *priv, - unsigned short wLoopbackMode) -{ - switch (wLoopbackMode) { - case CARD_LB_NONE: - case CARD_LB_MAC: - case CARD_LB_PHY: - break; - default: - break; - } - /* set MAC loopback */ - MACvSetLoopbackMode(priv, LOBYTE(wLoopbackMode)); - /* set Baseband loopback */ -} - -/* - * Description: Software Reset NIC - * - * Parameters: - * In: - * priv - The adapter to be reset - * Out: - * none - * - * Return Value: none - */ -bool CARDbSoftwareReset(struct vnt_private *priv) -{ - /* reset MAC */ - if (!MACbSafeSoftwareReset(priv)) - return false; - - return true; -} - -/* * Description: Calculate TSF offset of two TSF input * Get TSF Offset from RxBCN's TSF and local TSF * diff --git a/drivers/staging/vt6655/card.h b/drivers/staging/vt6655/card.h index 337266add6b2..568a2ddd6588 100644 --- a/drivers/staging/vt6655/card.h +++ b/drivers/staging/vt6655/card.h @@ -44,9 +44,6 @@ struct vnt_private; void CARDvSetRSPINF(struct vnt_private *priv, u8 bb_type); void CARDvUpdateBasicTopRate(struct vnt_private *priv); bool CARDbIsOFDMinBasicRate(struct vnt_private *priv); -void CARDvSetLoopbackMode(struct vnt_private *priv, - unsigned short wLoopbackMode); -bool CARDbSoftwareReset(struct vnt_private *priv); void CARDvSetFirstNextTBTT(struct vnt_private *priv, unsigned short wBeaconInterval); void CARDvUpdateNextTBTT(struct vnt_private *priv, u64 qwTSF, @@ -58,7 +55,6 @@ unsigned char CARDbyGetPktType(struct vnt_private *priv); void CARDvSafeResetTx(struct vnt_private *priv); void CARDvSafeResetRx(struct vnt_private *priv); void CARDbRadioPowerOff(struct vnt_private *priv); -bool CARDbRadioPowerOn(struct vnt_private *priv); bool CARDbSetPhyParameter(struct vnt_private *priv, u8 bb_type); bool CARDbUpdateTSF(struct vnt_private *priv, unsigned char byRxRate, u64 qwBSSTimestamp); diff --git a/drivers/staging/vt6655/channel.c b/drivers/staging/vt6655/channel.c index dec6f0f23b88..62a85c1ca6c4 100644 --- a/drivers/staging/vt6655/channel.c +++ b/drivers/staging/vt6655/channel.c @@ -173,7 +173,7 @@ bool set_channel(struct vnt_private *priv, struct ieee80211_channel *ch) priv->byBBVGACurrent != priv->abyBBVGA[0]) { priv->byBBVGACurrent = priv->abyBBVGA[0]; - BBvSetVGAGainOffset(priv, priv->byBBVGACurrent); + bb_set_vga_gain_offset(priv, priv->byBBVGACurrent); } /* clear NAV */ @@ -195,7 +195,7 @@ bool set_channel(struct vnt_private *priv, struct ieee80211_channel *ch) if (priv->bEnablePSMode) RFvWriteWakeProgSyn(priv, priv->byRFType, ch->hw_value); - BBvSoftwareReset(priv); + bb_software_reset(priv); if (priv->byLocalID > REV_ID_VT3253_B1) { unsigned long flags; diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c index 5c86cc60eb5c..5889023d19c4 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -21,14 +21,14 @@ * device_alloc_rx_buf - rx buffer pre-allocated function * device_free_rx_buf - free rx buffer function * device_free_tx_buf - free tx buffer function - * device_init_rd0_ring- initial rd dma0 ring - * device_init_rd1_ring- initial rd dma1 ring - * device_init_td0_ring- initial tx dma0 ring buffer - * device_init_td1_ring- initial tx dma1 ring buffer - * device_init_registers- initial MAC & BBP & RF internal registers. - * device_init_rings- initial tx/rx ring buffer - * device_free_rings- free all allocated ring buffer - * device_tx_srv- tx interrupt service function + * device_init_rd0_ring - initial rd dma0 ring + * device_init_rd1_ring - initial rd dma1 ring + * device_init_td0_ring - initial tx dma0 ring buffer + * device_init_td1_ring - initial tx dma1 ring buffer + * device_init_registers - initial MAC & BBP & RF internal registers. + * device_init_rings - initial tx/rx ring buffer + * device_free_rings - free all allocated ring buffer + * device_tx_srv - tx interrupt service function * * Revision History: */ @@ -202,7 +202,7 @@ static void device_init_registers(struct vnt_private *priv) unsigned char byOFDMPwrdBm = 0; MACbShutdown(priv); - BBvSoftwareReset(priv); + bb_software_reset(priv); /* Do MACbSoftwareReset in MACvInitialize */ MACbSoftwareReset(priv); @@ -279,8 +279,8 @@ static void device_init_registers(struct vnt_private *priv) } /* Set initial antenna mode */ - BBvSetTxAntennaMode(priv, priv->byTxAntennaMode); - BBvSetRxAntennaMode(priv, priv->byRxAntennaMode); + bb_set_tx_antenna_mode(priv, priv->byTxAntennaMode); + bb_set_rx_antenna_mode(priv, priv->byRxAntennaMode); /* zonetype initial */ priv->byOriginalZonetype = priv->abyEEPROM[EEP_OFS_ZONETYPE]; @@ -357,16 +357,16 @@ static void device_init_registers(struct vnt_private *priv) VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); /* initialize BBP registers */ - BBbVT3253Init(priv); + bb_vt3253_init(priv); if (priv->bUpdateBBVGA) { priv->byBBVGACurrent = priv->abyBBVGA[0]; priv->byBBVGANew = priv->byBBVGACurrent; - BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]); + bb_set_vga_gain_offset(priv, priv->abyBBVGA[0]); } - BBvSetRxAntennaMode(priv, priv->byRxAntennaMode); - BBvSetTxAntennaMode(priv, priv->byTxAntennaMode); + bb_set_rx_antenna_mode(priv, priv->byRxAntennaMode); + bb_set_tx_antenna_mode(priv, priv->byTxAntennaMode); /* Set BB and packet type at the same time. */ /* Set Short Slot Time, xIFS, and RSPINF. */ @@ -1001,7 +1001,7 @@ static void vnt_check_bb_vga(struct vnt_private *priv) if (priv->uBBVGADiffCount == 1) { /* first VGA diff gain */ - BBvSetVGAGainOffset(priv, priv->byBBVGANew); + bb_set_vga_gain_offset(priv, priv->byBBVGANew); dev_dbg(&priv->pcid->dev, "First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n", @@ -1017,7 +1017,7 @@ static void vnt_check_bb_vga(struct vnt_private *priv) priv->byBBVGACurrent, (int)priv->uBBVGADiffCount); - BBvSetVGAGainOffset(priv, priv->byBBVGANew); + bb_set_vga_gain_offset(priv, priv->byBBVGANew); } } @@ -1445,7 +1445,7 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw, priv->bShortSlotTime = false; CARDbSetPhyParameter(priv, priv->byBBType); - BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]); + bb_set_vga_gain_offset(priv, priv->abyBBVGA[0]); } if (changed & BSS_CHANGED_TXPOWER) diff --git a/drivers/staging/vt6655/rf.c b/drivers/staging/vt6655/rf.c index d6ca6e5551a7..747d79265a7c 100644 --- a/drivers/staging/vt6655/rf.c +++ b/drivers/staging/vt6655/rf.c @@ -419,7 +419,7 @@ static bool s_bAL7230Init(struct vnt_private *priv) MACvWordRegBitsOn(iobase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPECTI | SOFTPWRCTL_TXPEINV)); - BBvPowerSaveModeOFF(priv); /* RobertYu:20050106, have DC value for Calibration */ + bb_power_save_mode_off(priv); /* RobertYu:20050106, have DC value for Calibration */ for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++) ret &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[ii]); @@ -443,7 +443,7 @@ static bool s_bAL7230Init(struct vnt_private *priv) SOFTPWRCTL_SWPECTI | SOFTPWRCTL_TXPEINV)); - BBvPowerSaveModeON(priv); /* RobertYu:20050106 */ + bb_power_save_mode_on(priv); /* RobertYu:20050106 */ /* PE1: TX_ON, PE2: RX_ON, PE3: PLLON */ /* 3-wire control for power saving mode */ diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c index 37fcc42ed000..2f9c2ead3cb8 100644 --- a/drivers/staging/vt6655/rxtx.c +++ b/drivers/staging/vt6655/rxtx.c @@ -165,11 +165,11 @@ s_uGetTxRsvTime( { unsigned int uDataTime, uAckTime; - uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate); + uDataTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, cbFrameLength, wRate); if (byPktType == PK_TYPE_11B) /* llb,CCK mode */ - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopCCKBasicRate); + uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopCCKBasicRate); else /* 11g 2.4G OFDM mode & 11a 5G OFDM mode */ - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopOFDMBasicRate); + uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopOFDMBasicRate); if (bNeedAck) return uDataTime + pDevice->uSIFS + uAckTime; @@ -195,24 +195,28 @@ s_uGetRTSCTSRsvTime( unsigned short wCurrentRate ) { - unsigned int uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime; + unsigned int uRrvTime = 0; + unsigned int uRTSTime = 0; + unsigned int uCTSTime = 0; + unsigned int uAckTime = 0; + unsigned int uDataTime = 0; - uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0; - - uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate); + uDataTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate); if (byRTSRsvType == 0) { /* RTSTxRrvTime_bb */ - uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate); - uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); + uRTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate); + uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); + uCTSTime = uAckTime; } else if (byRTSRsvType == 1) { /* RTSTxRrvTime_ba, only in 2.4GHZ */ - uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate); - uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); + uRTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate); + uCTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); + uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); } else if (byRTSRsvType == 2) { /* RTSTxRrvTime_aa */ - uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate); - uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); + uRTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate); + uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); + uCTSTime = uAckTime; } else if (byRTSRsvType == 3) { /* CTSTxRrvTime_ba, only in 2.4GHZ */ - uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); + uCTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); + uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); uRrvTime = uCTSTime + uAckTime + uDataTime + 2 * pDevice->uSIFS; return cpu_to_le16((u16)uRrvTime); } @@ -239,136 +243,125 @@ s_uGetDataDuration( ) { bool bLastFrag = false; - unsigned int uAckTime = 0, uNextPktTime = 0; + unsigned int uAckTime = 0, uNextPktTime = 0, len; if (uFragIdx == (uMACfragNum - 1)) bLastFrag = true; + if (uFragIdx == (uMACfragNum - 2)) + len = cbLastFragmentSize; + else + len = cbFrameLength; + switch (byDurType) { case DATADUR_B: /* DATADUR_B */ if (((uMACfragNum == 1)) || bLastFrag) {/* Non Frag or Last Frag */ if (bNeedAck) { - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); + uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); return pDevice->uSIFS + uAckTime; } else { return 0; } } else {/* First Frag or Mid Frag */ - if (uFragIdx == (uMACfragNum - 2)) - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); - else - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, len, wRate, bNeedAck); if (bNeedAck) { - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); - return pDevice->uSIFS + uAckTime + uNextPktTime; - } else { - return pDevice->uSIFS + uNextPktTime; + uAckTime = bb_get_frame_time(pDevice->byPreambleType, + byPktType, 14, + pDevice->byTopCCKBasicRate); } + return pDevice->uSIFS + uAckTime + uNextPktTime; } break; case DATADUR_A: /* DATADUR_A */ if (((uMACfragNum == 1)) || bLastFrag) {/* Non Frag or Last Frag */ if (bNeedAck) { - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); + uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); return pDevice->uSIFS + uAckTime; } else { return 0; } } else {/* First Frag or Mid Frag */ - if (uFragIdx == (uMACfragNum - 2)) - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); - else - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, len, + wRate, bNeedAck); if (bNeedAck) { - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); - return pDevice->uSIFS + uAckTime + uNextPktTime; - } else { - return pDevice->uSIFS + uNextPktTime; + uAckTime = bb_get_frame_time(pDevice->byPreambleType, + byPktType, 14, + pDevice->byTopOFDMBasicRate); } + return pDevice->uSIFS + uAckTime + uNextPktTime; } break; case DATADUR_A_F0: /* DATADUR_A_F0 */ if (((uMACfragNum == 1)) || bLastFrag) {/* Non Frag or Last Frag */ if (bNeedAck) { - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); + uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); return pDevice->uSIFS + uAckTime; } else { return 0; } } else { /* First Frag or Mid Frag */ + if (wRate < RATE_18M) + wRate = RATE_18M; + else if (wRate > RATE_54M) + wRate = RATE_54M; + if (byFBOption == AUTO_FB_0) { - if (wRate < RATE_18M) - wRate = RATE_18M; - else if (wRate > RATE_54M) - wRate = RATE_54M; - - if (uFragIdx == (uMACfragNum - 2)) - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck); - else - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck); - - } else { /* (byFBOption == AUTO_FB_1) */ - if (wRate < RATE_18M) - wRate = RATE_18M; - else if (wRate > RATE_54M) - wRate = RATE_54M; - - if (uFragIdx == (uMACfragNum - 2)) - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck); - else - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck); + uNextPktTime = s_uGetTxRsvTime(pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0][wRate - RATE_18M], + bNeedAck); + } else { + uNextPktTime = s_uGetTxRsvTime(pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0][wRate - RATE_18M], + bNeedAck); } if (bNeedAck) { - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); - return pDevice->uSIFS + uAckTime + uNextPktTime; - } else { - return pDevice->uSIFS + uNextPktTime; + uAckTime = bb_get_frame_time(pDevice->byPreambleType, + byPktType, 14, + pDevice->byTopOFDMBasicRate); } + return pDevice->uSIFS + uAckTime + uNextPktTime; } break; case DATADUR_A_F1: /* DATADUR_A_F1 */ if (((uMACfragNum == 1)) || bLastFrag) { /* Non Frag or Last Frag */ if (bNeedAck) { - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); + uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); return pDevice->uSIFS + uAckTime; } else { return 0; } } else { /* First Frag or Mid Frag */ + if (wRate < RATE_18M) + wRate = RATE_18M; + else if (wRate > RATE_54M) + wRate = RATE_54M; + if (byFBOption == AUTO_FB_0) { - if (wRate < RATE_18M) - wRate = RATE_18M; - else if (wRate > RATE_54M) - wRate = RATE_54M; - - if (uFragIdx == (uMACfragNum - 2)) - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck); - else - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck); - - } else { /* (byFBOption == AUTO_FB_1) */ - if (wRate < RATE_18M) - wRate = RATE_18M; - else if (wRate > RATE_54M) - wRate = RATE_54M; - - if (uFragIdx == (uMACfragNum - 2)) - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck); - else - uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck); + uNextPktTime = s_uGetTxRsvTime(pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0][wRate - RATE_18M], + bNeedAck); + } else { + uNextPktTime = s_uGetTxRsvTime(pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0][wRate - RATE_18M], + bNeedAck); } + if (bNeedAck) { - uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); - return pDevice->uSIFS + uAckTime + uNextPktTime; - } else { - return pDevice->uSIFS + uNextPktTime; + uAckTime = bb_get_frame_time(pDevice->byPreambleType, + byPktType, 14, + pDevice->byTopOFDMBasicRate); } + return pDevice->uSIFS + uAckTime + uNextPktTime; } break; @@ -396,17 +389,17 @@ s_uGetRTSCTSDuration( switch (byDurType) { case RTSDUR_BB: /* RTSDuration_bb */ - uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); + uCTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck); break; case RTSDUR_BA: /* RTSDuration_ba */ - uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); + uCTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck); break; case RTSDUR_AA: /* RTSDuration_aa */ - uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); + uCTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck); break; @@ -415,7 +408,7 @@ s_uGetRTSCTSDuration( break; case RTSDUR_BA_F0: /* RTSDuration_ba_f0 */ - uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); + uCTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck); else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) @@ -424,7 +417,7 @@ s_uGetRTSCTSDuration( break; case RTSDUR_AA_F0: /* RTSDuration_aa_f0 */ - uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); + uCTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck); else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) @@ -433,7 +426,7 @@ s_uGetRTSCTSDuration( break; case RTSDUR_BA_F1: /* RTSDuration_ba_f1 */ - uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); + uCTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck); else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) @@ -442,7 +435,7 @@ s_uGetRTSCTSDuration( break; case RTSDUR_AA_F1: /* RTSDuration_aa_f1 */ - uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); + uCTSTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck); else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) @@ -1040,16 +1033,14 @@ s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType, bool bRTS = (bool)(fifo_ctl & FIFOCTL_RTS); struct vnt_tx_desc *ptdCurr; unsigned int cbHeaderLength = 0; - void *pvRrvTime; - struct vnt_mic_hdr *pMICHDR; - void *pvRTS; - void *pvCTS; - void *pvTxDataHd; + void *pvRrvTime = NULL; + struct vnt_mic_hdr *pMICHDR = NULL; + void *pvRTS = NULL; + void *pvCTS = NULL; + void *pvTxDataHd = NULL; unsigned short wTxBufSize; /* FFinfo size */ unsigned char byFBOption = AUTO_FB_NONE; - pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL; - cbFrameSize = skb->len + 4; if (info->control.hw_key) { diff --git a/drivers/staging/vt6656/Makefile b/drivers/staging/vt6656/Makefile index 375f54e9f58b..a0f3862dea75 100644 --- a/drivers/staging/vt6656/Makefile +++ b/drivers/staging/vt6656/Makefile @@ -13,7 +13,6 @@ vt6656_stage-y += main_usb.o \ key.o \ rf.o \ usbpipe.o \ - channel.o \ - firmware.o + channel.o obj-$(CONFIG_VT6656) += vt6656_stage.o diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c index a19a563d8bcc..e7000bba644a 100644 --- a/drivers/staging/vt6656/baseband.c +++ b/drivers/staging/vt6656/baseband.c @@ -24,6 +24,7 @@ #include <linux/bits.h> #include <linux/kernel.h> +#include "device.h" #include "mac.h" #include "baseband.h" #include "rf.h" @@ -111,198 +112,85 @@ static u8 vnt_vt3184_vt3226d0[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */ }; -static const u16 vnt_frame_time[MAX_RATE] = { - 10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216 +struct vnt_threshold { + u8 bb_pre_ed_rssi; + u8 cr_201; + u8 cr_206; }; -/* - * Description: Calculate data frame transmitting time - * - * Parameters: - * In: - * preamble_type - Preamble Type - * pkt_type - PK_TYPE_11A, PK_TYPE_11B, PK_TYPE_11GB, PK_TYPE_11GA - * frame_length - Baseband Type - * tx_rate - Tx Rate - * Out: - * - * Return Value: FrameTime - * - */ -unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type, - unsigned int frame_length, u16 tx_rate) -{ - unsigned int frame_time; - unsigned int preamble; - unsigned int rate = 0; - - if (tx_rate > RATE_54M) - return 0; - - rate = (unsigned int)vnt_frame_time[tx_rate]; - - if (tx_rate <= 3) { - if (preamble_type == 1) - preamble = 96; - else - preamble = 192; - - frame_time = DIV_ROUND_UP(frame_length * 80, rate); - return preamble + frame_time; - } - - frame_time = DIV_ROUND_UP(frame_length * 8 + 22, rate); - frame_time = frame_time * 4; - - if (pkt_type != PK_TYPE_11A) - frame_time += 6; - return 20 + frame_time; -} - -/* - * Description: Calculate Length, Service, and Signal fields of Phy for Tx - * - * Parameters: - * In: - * priv - Device Structure - * frame_length - Tx Frame Length - * tx_rate - Tx Rate - * Out: - * struct vnt_phy_field *phy - * - pointer to Phy Length field - * - pointer to Phy Service field - * - pointer to Phy Signal field - * - * Return Value: none - * - */ -void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length, - u16 tx_rate, u8 pkt_type, struct vnt_phy_field *phy) -{ - u32 bit_count; - u32 count = 0; - u32 tmp; - int ext_bit; - u8 preamble_type = priv->preamble_type; - - bit_count = frame_length * 8; - ext_bit = false; - - switch (tx_rate) { - case RATE_1M: - count = bit_count; - - phy->signal = 0x00; - - break; - case RATE_2M: - count = bit_count / 2; - - if (preamble_type == 1) - phy->signal = 0x09; - else - phy->signal = 0x01; - - break; - case RATE_5M: - count = DIV_ROUND_UP(bit_count * 10, 55); - - if (preamble_type == 1) - phy->signal = 0x0a; - else - phy->signal = 0x02; - - break; - case RATE_11M: - count = bit_count / 11; - tmp = count * 11; - - if (tmp != bit_count) { - count++; - - if ((bit_count - tmp) <= 3) - ext_bit = true; - } - - if (preamble_type == 1) - phy->signal = 0x0b; - else - phy->signal = 0x03; - - break; - case RATE_6M: - if (pkt_type == PK_TYPE_11A) - phy->signal = 0x9b; - else - phy->signal = 0x8b; - - break; - case RATE_9M: - if (pkt_type == PK_TYPE_11A) - phy->signal = 0x9f; - else - phy->signal = 0x8f; - - break; - case RATE_12M: - if (pkt_type == PK_TYPE_11A) - phy->signal = 0x9a; - else - phy->signal = 0x8a; - - break; - case RATE_18M: - if (pkt_type == PK_TYPE_11A) - phy->signal = 0x9e; - else - phy->signal = 0x8e; - - break; - case RATE_24M: - if (pkt_type == PK_TYPE_11A) - phy->signal = 0x99; - else - phy->signal = 0x89; - - break; - case RATE_36M: - if (pkt_type == PK_TYPE_11A) - phy->signal = 0x9d; - else - phy->signal = 0x8d; - - break; - case RATE_48M: - if (pkt_type == PK_TYPE_11A) - phy->signal = 0x98; - else - phy->signal = 0x88; +static const struct vnt_threshold al2230_vnt_threshold[] = { + {0, 0x00, 0x30}, /* Max sensitivity */ + {68, 0x00, 0x36}, + {67, 0x00, 0x43}, + {66, 0x00, 0x51}, + {65, 0x00, 0x62}, + {64, 0x00, 0x79}, + {63, 0x00, 0x93}, + {62, 0x00, 0xb9}, + {61, 0x00, 0xe3}, + {60, 0x01, 0x18}, + {59, 0x01, 0x54}, + {58, 0x01, 0xa0}, + {57, 0x02, 0x20}, + {56, 0x02, 0xa0}, + {55, 0x03, 0x00}, + {53, 0x06, 0x00}, + {51, 0x09, 0x00}, + {49, 0x0e, 0x00}, + {47, 0x15, 0x00}, + {46, 0x1a, 0x00}, + {45, 0xff, 0x00} +}; - break; - case RATE_54M: - if (pkt_type == PK_TYPE_11A) - phy->signal = 0x9c; - else - phy->signal = 0x8c; - break; - default: - if (pkt_type == PK_TYPE_11A) - phy->signal = 0x9c; - else - phy->signal = 0x8c; - break; - } +static const struct vnt_threshold vt3226_vnt_threshold[] = { + {0, 0x00, 0x24}, /* Max sensitivity */ + {68, 0x00, 0x2d}, + {67, 0x00, 0x36}, + {66, 0x00, 0x43}, + {65, 0x00, 0x52}, + {64, 0x00, 0x68}, + {63, 0x00, 0x80}, + {62, 0x00, 0x9c}, + {61, 0x00, 0xc0}, + {60, 0x00, 0xea}, + {59, 0x01, 0x30}, + {58, 0x01, 0x70}, + {57, 0x01, 0xb0}, + {56, 0x02, 0x30}, + {55, 0x02, 0xc0}, + {53, 0x04, 0x00}, + {51, 0x07, 0x00}, + {49, 0x0a, 0x00}, + {47, 0x11, 0x00}, + {45, 0x18, 0x00}, + {43, 0x26, 0x00}, + {42, 0x36, 0x00}, + {41, 0xff, 0x00} +}; - if (pkt_type == PK_TYPE_11B) { - phy->service = 0x00; - if (ext_bit) - phy->service |= 0x80; - phy->len = cpu_to_le16((u16)count); - } else { - phy->service = 0x00; - phy->len = cpu_to_le16((u16)frame_length); - } -} +static const struct vnt_threshold vt3342_vnt_threshold[] = { + {0, 0x00, 0x38}, /* Max sensitivity */ + {66, 0x00, 0x43}, + {65, 0x00, 0x52}, + {64, 0x00, 0x68}, + {63, 0x00, 0x80}, + {62, 0x00, 0x9c}, + {61, 0x00, 0xc0}, + {60, 0x00, 0xea}, + {59, 0x01, 0x30}, + {58, 0x01, 0x70}, + {57, 0x01, 0xb0}, + {56, 0x02, 0x30}, + {55, 0x02, 0xc0}, + {53, 0x04, 0x00}, + {51, 0x07, 0x00}, + {49, 0x0a, 0x00}, + {47, 0x11, 0x00}, + {45, 0x18, 0x00}, + {43, 0x26, 0x00}, + {42, 0x36, 0x00}, + {41, 0xff, 0x00} +}; /* * Description: Set Antenna mode @@ -352,7 +240,7 @@ int vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode) int vnt_vt3184_init(struct vnt_private *priv) { - int ret = 0; + int ret; u16 length; u8 *addr; u8 data; @@ -366,23 +254,15 @@ int vnt_vt3184_init(struct vnt_private *priv) dev_dbg(&priv->usb->dev, "RF Type %d\n", priv->rf_type); - if (priv->rf_type == RF_AL2230 || - priv->rf_type == RF_AL2230S) { + if ((priv->rf_type == RF_AL2230) || + (priv->rf_type == RF_AL2230S) || + (priv->rf_type == RF_AIROHA7230)) { priv->bb_rx_conf = vnt_vt3184_al2230[10]; length = sizeof(vnt_vt3184_al2230); addr = vnt_vt3184_al2230; - priv->bb_vga[0] = 0x1C; - priv->bb_vga[1] = 0x10; - priv->bb_vga[2] = 0x0; - priv->bb_vga[3] = 0x0; - - } else if (priv->rf_type == RF_AIROHA7230) { - priv->bb_rx_conf = vnt_vt3184_al2230[10]; - length = sizeof(vnt_vt3184_al2230); - addr = vnt_vt3184_al2230; - - addr[0xd7] = 0x06; + if (priv->rf_type == RF_AIROHA7230) + addr[0xd7] = 0x06; priv->bb_vga[0] = 0x1c; priv->bb_vga[1] = 0x10; @@ -390,22 +270,8 @@ int vnt_vt3184_init(struct vnt_private *priv) priv->bb_vga[3] = 0x0; } else if ((priv->rf_type == RF_VT3226) || - (priv->rf_type == RF_VT3226D0)) { - priv->bb_rx_conf = vnt_vt3184_vt3226d0[10]; - length = sizeof(vnt_vt3184_vt3226d0); - addr = vnt_vt3184_vt3226d0; - - priv->bb_vga[0] = 0x20; - priv->bb_vga[1] = 0x10; - priv->bb_vga[2] = 0x0; - priv->bb_vga[3] = 0x0; - - /* Fix VT3226 DFC system timing issue */ - ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2, - SOFTPWRCTL_RFLEOPT); - if (ret) - goto end; - } else if (priv->rf_type == RF_VT3342A0) { + (priv->rf_type == RF_VT3226D0) || + (priv->rf_type == RF_VT3342A0)) { priv->bb_rx_conf = vnt_vt3184_vt3226d0[10]; length = sizeof(vnt_vt3184_vt3226d0); addr = vnt_vt3184_vt3226d0; @@ -435,19 +301,13 @@ int vnt_vt3184_init(struct vnt_private *priv) if (ret) goto end; - if (priv->rf_type == RF_VT3226 || - priv->rf_type == RF_VT3342A0) { - ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, - MAC_REG_ITRTMSET, 0x23); - if (ret) - goto end; + if ((priv->rf_type == RF_VT3226) || + (priv->rf_type == RF_VT3342A0) || + (priv->rf_type == RF_VT3226D0)) { + data = (priv->rf_type == RF_VT3226D0) ? 0x11 : 0x23; - ret = vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, BIT(0)); - if (ret) - goto end; - } else if (priv->rf_type == RF_VT3226D0) { ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, - MAC_REG_ITRTMSET, 0x11); + MAC_REG_ITRTMSET, data); if (ret) goto end; @@ -572,254 +432,42 @@ int vnt_exit_deep_sleep(struct vnt_private *priv) void vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning) { - u8 cr_201 = 0x0, cr_206 = 0x0; - u8 ed_inx = priv->bb_pre_ed_index; + const struct vnt_threshold *threshold = NULL; + u8 length; + u8 cr_201, cr_206; + u8 ed_inx; switch (priv->rf_type) { case RF_AL2230: case RF_AL2230S: case RF_AIROHA7230: - if (scanning) { /* Max sensitivity */ - ed_inx = 0; - cr_206 = 0x30; - break; - } - - if (priv->bb_pre_ed_rssi <= 45) { - ed_inx = 20; - cr_201 = 0xff; - } else if (priv->bb_pre_ed_rssi <= 46) { - ed_inx = 19; - cr_201 = 0x1a; - } else if (priv->bb_pre_ed_rssi <= 47) { - ed_inx = 18; - cr_201 = 0x15; - } else if (priv->bb_pre_ed_rssi <= 49) { - ed_inx = 17; - cr_201 = 0xe; - } else if (priv->bb_pre_ed_rssi <= 51) { - ed_inx = 16; - cr_201 = 0x9; - } else if (priv->bb_pre_ed_rssi <= 53) { - ed_inx = 15; - cr_201 = 0x6; - } else if (priv->bb_pre_ed_rssi <= 55) { - ed_inx = 14; - cr_201 = 0x3; - } else if (priv->bb_pre_ed_rssi <= 56) { - ed_inx = 13; - cr_201 = 0x2; - cr_206 = 0xa0; - } else if (priv->bb_pre_ed_rssi <= 57) { - ed_inx = 12; - cr_201 = 0x2; - cr_206 = 0x20; - } else if (priv->bb_pre_ed_rssi <= 58) { - ed_inx = 11; - cr_201 = 0x1; - cr_206 = 0xa0; - } else if (priv->bb_pre_ed_rssi <= 59) { - ed_inx = 10; - cr_201 = 0x1; - cr_206 = 0x54; - } else if (priv->bb_pre_ed_rssi <= 60) { - ed_inx = 9; - cr_201 = 0x1; - cr_206 = 0x18; - } else if (priv->bb_pre_ed_rssi <= 61) { - ed_inx = 8; - cr_206 = 0xe3; - } else if (priv->bb_pre_ed_rssi <= 62) { - ed_inx = 7; - cr_206 = 0xb9; - } else if (priv->bb_pre_ed_rssi <= 63) { - ed_inx = 6; - cr_206 = 0x93; - } else if (priv->bb_pre_ed_rssi <= 64) { - ed_inx = 5; - cr_206 = 0x79; - } else if (priv->bb_pre_ed_rssi <= 65) { - ed_inx = 4; - cr_206 = 0x62; - } else if (priv->bb_pre_ed_rssi <= 66) { - ed_inx = 3; - cr_206 = 0x51; - } else if (priv->bb_pre_ed_rssi <= 67) { - ed_inx = 2; - cr_206 = 0x43; - } else if (priv->bb_pre_ed_rssi <= 68) { - ed_inx = 1; - cr_206 = 0x36; - } else { - ed_inx = 0; - cr_206 = 0x30; - } + threshold = al2230_vnt_threshold; + length = ARRAY_SIZE(al2230_vnt_threshold); break; case RF_VT3226: case RF_VT3226D0: - if (scanning) { /* Max sensitivity */ - ed_inx = 0; - cr_206 = 0x24; - break; - } - - if (priv->bb_pre_ed_rssi <= 41) { - ed_inx = 22; - cr_201 = 0xff; - } else if (priv->bb_pre_ed_rssi <= 42) { - ed_inx = 21; - cr_201 = 0x36; - } else if (priv->bb_pre_ed_rssi <= 43) { - ed_inx = 20; - cr_201 = 0x26; - } else if (priv->bb_pre_ed_rssi <= 45) { - ed_inx = 19; - cr_201 = 0x18; - } else if (priv->bb_pre_ed_rssi <= 47) { - ed_inx = 18; - cr_201 = 0x11; - } else if (priv->bb_pre_ed_rssi <= 49) { - ed_inx = 17; - cr_201 = 0xa; - } else if (priv->bb_pre_ed_rssi <= 51) { - ed_inx = 16; - cr_201 = 0x7; - } else if (priv->bb_pre_ed_rssi <= 53) { - ed_inx = 15; - cr_201 = 0x4; - } else if (priv->bb_pre_ed_rssi <= 55) { - ed_inx = 14; - cr_201 = 0x2; - cr_206 = 0xc0; - } else if (priv->bb_pre_ed_rssi <= 56) { - ed_inx = 13; - cr_201 = 0x2; - cr_206 = 0x30; - } else if (priv->bb_pre_ed_rssi <= 57) { - ed_inx = 12; - cr_201 = 0x1; - cr_206 = 0xb0; - } else if (priv->bb_pre_ed_rssi <= 58) { - ed_inx = 11; - cr_201 = 0x1; - cr_206 = 0x70; - } else if (priv->bb_pre_ed_rssi <= 59) { - ed_inx = 10; - cr_201 = 0x1; - cr_206 = 0x30; - } else if (priv->bb_pre_ed_rssi <= 60) { - ed_inx = 9; - cr_206 = 0xea; - } else if (priv->bb_pre_ed_rssi <= 61) { - ed_inx = 8; - cr_206 = 0xc0; - } else if (priv->bb_pre_ed_rssi <= 62) { - ed_inx = 7; - cr_206 = 0x9c; - } else if (priv->bb_pre_ed_rssi <= 63) { - ed_inx = 6; - cr_206 = 0x80; - } else if (priv->bb_pre_ed_rssi <= 64) { - ed_inx = 5; - cr_206 = 0x68; - } else if (priv->bb_pre_ed_rssi <= 65) { - ed_inx = 4; - cr_206 = 0x52; - } else if (priv->bb_pre_ed_rssi <= 66) { - ed_inx = 3; - cr_206 = 0x43; - } else if (priv->bb_pre_ed_rssi <= 67) { - ed_inx = 2; - cr_206 = 0x36; - } else if (priv->bb_pre_ed_rssi <= 68) { - ed_inx = 1; - cr_206 = 0x2d; - } else { - ed_inx = 0; - cr_206 = 0x24; - } + threshold = vt3226_vnt_threshold; + length = ARRAY_SIZE(vt3226_vnt_threshold); break; case RF_VT3342A0: - if (scanning) { /* need Max sensitivity */ - ed_inx = 0; - cr_206 = 0x38; - break; - } - - if (priv->bb_pre_ed_rssi <= 41) { - ed_inx = 20; - cr_201 = 0xff; - } else if (priv->bb_pre_ed_rssi <= 42) { - ed_inx = 19; - cr_201 = 0x36; - } else if (priv->bb_pre_ed_rssi <= 43) { - ed_inx = 18; - cr_201 = 0x26; - } else if (priv->bb_pre_ed_rssi <= 45) { - ed_inx = 17; - cr_201 = 0x18; - } else if (priv->bb_pre_ed_rssi <= 47) { - ed_inx = 16; - cr_201 = 0x11; - } else if (priv->bb_pre_ed_rssi <= 49) { - ed_inx = 15; - cr_201 = 0xa; - } else if (priv->bb_pre_ed_rssi <= 51) { - ed_inx = 14; - cr_201 = 0x7; - } else if (priv->bb_pre_ed_rssi <= 53) { - ed_inx = 13; - cr_201 = 0x4; - } else if (priv->bb_pre_ed_rssi <= 55) { - ed_inx = 12; - cr_201 = 0x2; - cr_206 = 0xc0; - } else if (priv->bb_pre_ed_rssi <= 56) { - ed_inx = 11; - cr_201 = 0x2; - cr_206 = 0x30; - } else if (priv->bb_pre_ed_rssi <= 57) { - ed_inx = 10; - cr_201 = 0x1; - cr_206 = 0xb0; - } else if (priv->bb_pre_ed_rssi <= 58) { - ed_inx = 9; - cr_201 = 0x1; - cr_206 = 0x70; - } else if (priv->bb_pre_ed_rssi <= 59) { - ed_inx = 8; - cr_201 = 0x1; - cr_206 = 0x30; - } else if (priv->bb_pre_ed_rssi <= 60) { - ed_inx = 7; - cr_206 = 0xea; - } else if (priv->bb_pre_ed_rssi <= 61) { - ed_inx = 6; - cr_206 = 0xc0; - } else if (priv->bb_pre_ed_rssi <= 62) { - ed_inx = 5; - cr_206 = 0x9c; - } else if (priv->bb_pre_ed_rssi <= 63) { - ed_inx = 4; - cr_206 = 0x80; - } else if (priv->bb_pre_ed_rssi <= 64) { - ed_inx = 3; - cr_206 = 0x68; - } else if (priv->bb_pre_ed_rssi <= 65) { - ed_inx = 2; - cr_206 = 0x52; - } else if (priv->bb_pre_ed_rssi <= 66) { - ed_inx = 1; - cr_206 = 0x43; - } else { - ed_inx = 0; - cr_206 = 0x38; - } + threshold = vt3342_vnt_threshold; + length = ARRAY_SIZE(vt3342_vnt_threshold); break; } + if (!threshold) + return; + + for (ed_inx = scanning ? 0 : length - 1; ed_inx > 0; ed_inx--) { + if (priv->bb_pre_ed_rssi <= threshold[ed_inx].bb_pre_ed_rssi) + break; + } + + cr_201 = threshold[ed_inx].cr_201; + cr_206 = threshold[ed_inx].cr_206; + if (ed_inx == priv->bb_pre_ed_index && !scanning) return; @@ -828,9 +476,6 @@ void vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning) dev_dbg(&priv->usb->dev, "%s bb_pre_ed_rssi %d\n", __func__, priv->bb_pre_ed_rssi); - if (!cr_201 && !cr_206) - return; - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xc9, cr_201); vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xce, cr_206); } diff --git a/drivers/staging/vt6656/baseband.h b/drivers/staging/vt6656/baseband.h index dc42aa6ae1d9..ee7325d942fe 100644 --- a/drivers/staging/vt6656/baseband.h +++ b/drivers/staging/vt6656/baseband.h @@ -66,19 +66,6 @@ #define TOP_RATE_2M 0x00200000 #define TOP_RATE_1M 0x00100000 -/* Length, Service, and Signal fields of Phy for Tx */ -struct vnt_phy_field { - u8 signal; - u8 service; - __le16 len; -} __packed; - -unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type, - unsigned int frame_length, u16 tx_rate); - -void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length, - u16 tx_rate, u8 pkt_type, struct vnt_phy_field *phy); - int vnt_set_short_slot_time(struct vnt_private *priv); void vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data); int vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode); diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c index dc3ab10eb630..939bf11d5a6f 100644 --- a/drivers/staging/vt6656/card.c +++ b/drivers/staging/vt6656/card.c @@ -26,7 +26,7 @@ * */ -#include <linux/bits.h> +#include <linux/bitops.h> #include "device.h" #include "card.h" #include "baseband.h" @@ -74,167 +74,25 @@ void vnt_set_channel(struct vnt_private *priv, u32 connection_channel) (u8)(connection_channel | 0x80)); } -/* - * Description: Get CCK mode basic rate - * - * Parameters: - * In: - * priv - The adapter to be set - * rate_idx - Receiving data rate - * Out: - * none - * - * Return Value: response Control frame rate - * - */ -static u16 vnt_get_cck_rate(struct vnt_private *priv, u16 rate_idx) -{ - u16 ui = rate_idx; - - while (ui > RATE_1M) { - if (priv->basic_rates & (1 << ui)) - return ui; - ui--; - } - - return RATE_1M; -} - -/* - * Description: Get OFDM mode basic rate - * - * Parameters: - * In: - * priv - The adapter to be set - * rate_idx - Receiving data rate - * Out: - * none - * - * Return Value: response Control frame rate - * - */ -static u16 vnt_get_ofdm_rate(struct vnt_private *priv, u16 rate_idx) -{ - u16 ui = rate_idx; - - dev_dbg(&priv->usb->dev, "%s basic rate: %d\n", - __func__, priv->basic_rates); - - if (!vnt_ofdm_min_rate(priv)) { - dev_dbg(&priv->usb->dev, "%s (NO OFDM) %d\n", - __func__, rate_idx); - if (rate_idx > RATE_24M) - rate_idx = RATE_24M; - return rate_idx; - } - - while (ui > RATE_11M) { - if (priv->basic_rates & (1 << ui)) { - dev_dbg(&priv->usb->dev, "%s rate: %d\n", - __func__, ui); - return ui; - } - ui--; - } +static const u8 vnt_rspinf_b_short_table[] = { + 0x70, 0x00, 0x00, 0x00, 0x38, 0x00, 0x09, 0x00, + 0x15, 0x00, 0x0a, 0x00, 0x0b, 0x00, 0x0b, 0x80 +}; - dev_dbg(&priv->usb->dev, "%s basic rate: 24M\n", __func__); +static const u8 vnt_rspinf_b_long_table[] = { + 0x70, 0x00, 0x00, 0x00, 0x38, 0x00, 0x01, 0x00, + 0x15, 0x00, 0x02, 0x00, 0x0b, 0x00, 0x03, 0x80 +}; - return RATE_24M; -} +static const u8 vnt_rspinf_a_table[] = { + 0x9b, 0x18, 0x9f, 0x10, 0x9a, 0x0a, 0x9e, 0x08, 0x99, + 0x08, 0x9d, 0x04, 0x98, 0x04, 0x9c, 0x04, 0x9c, 0x04 +}; -/* - * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode. - * - * Parameters: - * In: - * rate - Tx Rate - * bb_type - Tx Packet type - * Out: - * tx_rate - pointer to RSPINF TxRate field - * rsv_time- pointer to RSPINF RsvTime field - * - * Return Value: none - * - */ -static void vnt_calculate_ofdm_rate(u16 rate, u8 bb_type, - u8 *tx_rate, u8 *rsv_time) -{ - switch (rate) { - case RATE_6M: - if (bb_type == BB_TYPE_11A) { - *tx_rate = 0x9b; - *rsv_time = 24; - } else { - *tx_rate = 0x8b; - *rsv_time = 30; - } - break; - case RATE_9M: - if (bb_type == BB_TYPE_11A) { - *tx_rate = 0x9f; - *rsv_time = 16; - } else { - *tx_rate = 0x8f; - *rsv_time = 22; - } - break; - case RATE_12M: - if (bb_type == BB_TYPE_11A) { - *tx_rate = 0x9a; - *rsv_time = 12; - } else { - *tx_rate = 0x8a; - *rsv_time = 18; - } - break; - case RATE_18M: - if (bb_type == BB_TYPE_11A) { - *tx_rate = 0x9e; - *rsv_time = 8; - } else { - *tx_rate = 0x8e; - *rsv_time = 14; - } - break; - case RATE_36M: - if (bb_type == BB_TYPE_11A) { - *tx_rate = 0x9d; - *rsv_time = 4; - } else { - *tx_rate = 0x8d; - *rsv_time = 10; - } - break; - case RATE_48M: - if (bb_type == BB_TYPE_11A) { - *tx_rate = 0x98; - *rsv_time = 4; - } else { - *tx_rate = 0x88; - *rsv_time = 10; - } - break; - case RATE_54M: - if (bb_type == BB_TYPE_11A) { - *tx_rate = 0x9c; - *rsv_time = 4; - } else { - *tx_rate = 0x8c; - *rsv_time = 10; - } - break; - case RATE_24M: - default: - if (bb_type == BB_TYPE_11A) { - *tx_rate = 0x99; - *rsv_time = 8; - } else { - *tx_rate = 0x89; - *rsv_time = 14; - } - break; - } -} +static const u8 vnt_rspinf_gb_table[] = { + 0x8b, 0x1e, 0x8f, 0x16, 0x8a, 0x12, 0x8e, 0x0e, 0x89, + 0x0e, 0x8d, 0x0a, 0x88, 0x0a, 0x8c, 0x0a, 0x8c, 0x0a +}; /* * Description: Set RSPINF @@ -251,82 +109,32 @@ static void vnt_calculate_ofdm_rate(u16 rate, u8 bb_type, void vnt_set_rspinf(struct vnt_private *priv, u8 bb_type) { - struct vnt_phy_field phy[4]; - u8 tx_rate[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* For OFDM */ - u8 rsv_time[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; - u8 data[34]; - int i; - - /*RSPINF_b_1*/ - vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_1M), - PK_TYPE_11B, &phy[0]); - - /*RSPINF_b_2*/ - vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_2M), - PK_TYPE_11B, &phy[1]); - - /*RSPINF_b_5*/ - vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_5M), - PK_TYPE_11B, &phy[2]); - - /*RSPINF_b_11*/ - vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_11M), - PK_TYPE_11B, &phy[3]); - - /*RSPINF_a_6*/ - vnt_calculate_ofdm_rate(RATE_6M, bb_type, &tx_rate[0], &rsv_time[0]); - - /*RSPINF_a_9*/ - vnt_calculate_ofdm_rate(RATE_9M, bb_type, &tx_rate[1], &rsv_time[1]); - - /*RSPINF_a_12*/ - vnt_calculate_ofdm_rate(RATE_12M, bb_type, &tx_rate[2], &rsv_time[2]); - - /*RSPINF_a_18*/ - vnt_calculate_ofdm_rate(RATE_18M, bb_type, &tx_rate[3], &rsv_time[3]); - - /*RSPINF_a_24*/ - vnt_calculate_ofdm_rate(RATE_24M, bb_type, &tx_rate[4], &rsv_time[4]); - - /*RSPINF_a_36*/ - vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_36M), - bb_type, &tx_rate[5], &rsv_time[5]); + const u8 *data; + u16 len; - /*RSPINF_a_48*/ - vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_48M), - bb_type, &tx_rate[6], &rsv_time[6]); - - /*RSPINF_a_54*/ - vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_54M), - bb_type, &tx_rate[7], &rsv_time[7]); - - /*RSPINF_a_72*/ - vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_54M), - bb_type, &tx_rate[8], &rsv_time[8]); - - put_unaligned(phy[0].len, (u16 *)&data[0]); - data[2] = phy[0].signal; - data[3] = phy[0].service; - - put_unaligned(phy[1].len, (u16 *)&data[4]); - data[6] = phy[1].signal; - data[7] = phy[1].service; - - put_unaligned(phy[2].len, (u16 *)&data[8]); - data[10] = phy[2].signal; - data[11] = phy[2].service; + if (priv->preamble_type) { + data = vnt_rspinf_b_short_table; + len = ARRAY_SIZE(vnt_rspinf_b_short_table); + } else { + data = vnt_rspinf_b_long_table; + len = ARRAY_SIZE(vnt_rspinf_b_long_table); + } - put_unaligned(phy[3].len, (u16 *)&data[12]); - data[14] = phy[3].signal; - data[15] = phy[3].service; + /* RSPINF_b_1 to RSPINF_b_11 */ + vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_RSPINF_B_1, + MESSAGE_REQUEST_MACREG, len, data); - for (i = 0; i < 9; i++) { - data[16 + i * 2] = tx_rate[i]; - data[16 + i * 2 + 1] = rsv_time[i]; + if (bb_type == BB_TYPE_11A) { + data = vnt_rspinf_a_table; + len = ARRAY_SIZE(vnt_rspinf_a_table); + } else { + data = vnt_rspinf_gb_table; + len = ARRAY_SIZE(vnt_rspinf_gb_table); } - vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_RSPINF_B_1, - MESSAGE_REQUEST_MACREG, 34, &data[0]); + /* RSPINF_a_6 to RSPINF_a_72 */ + vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_RSPINF_A_6, + MESSAGE_REQUEST_MACREG, len, data); } /* @@ -415,41 +223,18 @@ void vnt_update_ifs(struct vnt_private *priv) void vnt_update_top_rates(struct vnt_private *priv) { - u8 top_ofdm = RATE_24M, top_cck = RATE_1M; - u8 i; - - /*Determines the highest basic rate.*/ - for (i = RATE_54M; i >= RATE_6M; i--) { - if (priv->basic_rates & (u16)(1 << i)) { - top_ofdm = i; - break; - } - } + int pos; - priv->top_ofdm_basic_rate = top_ofdm; + pos = fls(priv->basic_rates & GENMASK(RATE_54M, RATE_6M)); + priv->top_ofdm_basic_rate = pos ? (pos - 1) : RATE_24M; - for (i = RATE_11M;; i--) { - if (priv->basic_rates & (u16)(1 << i)) { - top_cck = i; - break; - } - if (i == RATE_1M) - break; - } - - priv->top_cck_basic_rate = top_cck; + pos = fls(priv->basic_rates & GENMASK(RATE_11M, RATE_1M)); + priv->top_cck_basic_rate = pos ? (pos - 1) : RATE_1M; } -int vnt_ofdm_min_rate(struct vnt_private *priv) +bool vnt_ofdm_min_rate(struct vnt_private *priv) { - int ii; - - for (ii = RATE_54M; ii >= RATE_6M; ii--) { - if ((priv->basic_rates) & ((u16)BIT(ii))) - return true; - } - - return false; + return priv->basic_rates & GENMASK(RATE_54M, RATE_6M) ? true : false; } u8 vnt_get_pkt_type(struct vnt_private *priv) @@ -723,9 +508,13 @@ int vnt_radio_power_on(struct vnt_private *priv) { int ret = 0; - vnt_exit_deep_sleep(priv); + ret = vnt_exit_deep_sleep(priv); + if (ret) + return ret; - vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON); + ret = vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON); + if (ret) + return ret; switch (priv->rf_type) { case RF_AL2230: @@ -734,14 +523,14 @@ int vnt_radio_power_on(struct vnt_private *priv) case RF_VT3226: case RF_VT3226D0: case RF_VT3342A0: - vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL, - (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3)); - break; + ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL, + (SOFTPWRCTL_SWPE2 | + SOFTPWRCTL_SWPE3)); + if (ret) + return ret; } - vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD); - - return ret; + return vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD); } void vnt_set_bss_mode(struct vnt_private *priv) diff --git a/drivers/staging/vt6656/card.h b/drivers/staging/vt6656/card.h index 75cd340c0cce..eaa15d0c291a 100644 --- a/drivers/staging/vt6656/card.h +++ b/drivers/staging/vt6656/card.h @@ -29,7 +29,7 @@ void vnt_set_channel(struct vnt_private *priv, u32 connection_channel); void vnt_set_rspinf(struct vnt_private *priv, u8 bb_type); void vnt_update_ifs(struct vnt_private *priv); void vnt_update_top_rates(struct vnt_private *priv); -int vnt_ofdm_min_rate(struct vnt_private *priv); +bool vnt_ofdm_min_rate(struct vnt_private *priv); void vnt_adjust_tsf(struct vnt_private *priv, u8 rx_rate, u64 time_stamp, u64 local_tsf); bool vnt_get_current_tsf(struct vnt_private *priv, u64 *current_tsf); diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h index e6ee9411f080..7834d69e7ac0 100644 --- a/drivers/staging/vt6656/device.h +++ b/drivers/staging/vt6656/device.h @@ -73,6 +73,10 @@ #define DEVICE_VERSION "mac80211" +#define FIRMWARE_VERSION 0x133 /* version 1.51 */ +#define FIRMWARE_NAME "vntwusb.fw" +#define FIRMWARE_CHUNK_SIZE 0x400 + #define CONFIG_PATH "/etc/vntconfiguration.dat" #define MAX_UINTS 8 @@ -344,7 +348,6 @@ struct vnt_private { u8 ofdm_pwr_tbl[14]; u8 ofdm_a_pwr_tbl[42]; - u16 current_rate; u16 tx_rate_fb0; u16 tx_rate_fb1; diff --git a/drivers/staging/vt6656/firmware.c b/drivers/staging/vt6656/firmware.c deleted file mode 100644 index 70358d427211..000000000000 --- a/drivers/staging/vt6656/firmware.c +++ /dev/null @@ -1,106 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. - * All rights reserved. - * - * File: baseband.c - * - * Purpose: Implement functions to access baseband - * - * Author: Yiching Chen - * - * Date: May 20, 2004 - * - * Functions: - * - * Revision History: - * - */ - -#include <linux/compiler.h> -#include "firmware.h" -#include "usbpipe.h" - -#define FIRMWARE_VERSION 0x133 /* version 1.51 */ -#define FIRMWARE_NAME "vntwusb.fw" - -#define FIRMWARE_CHUNK_SIZE 0x400 - -int vnt_download_firmware(struct vnt_private *priv) -{ - struct device *dev = &priv->usb->dev; - const struct firmware *fw; - u16 length; - int ii; - int ret = 0; - - dev_dbg(dev, "---->Download firmware\n"); - - ret = request_firmware(&fw, FIRMWARE_NAME, dev); - if (ret) { - dev_err(dev, "firmware file %s request failed (%d)\n", - FIRMWARE_NAME, ret); - goto end; - } - - for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) { - length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE); - - ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length, - fw->data + ii); - if (ret) - goto free_fw; - - dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size); - } - -free_fw: - release_firmware(fw); -end: - return ret; -} -MODULE_FIRMWARE(FIRMWARE_NAME); - -int vnt_firmware_branch_to_sram(struct vnt_private *priv) -{ - dev_dbg(&priv->usb->dev, "---->Branch to Sram\n"); - - return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL); -} - -int vnt_check_firmware_version(struct vnt_private *priv) -{ - int ret = 0; - - ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0, - MESSAGE_REQUEST_VERSION, 2, - (u8 *)&priv->firmware_version); - if (ret) { - dev_dbg(&priv->usb->dev, - "Could not get firmware version: %d.\n", ret); - goto end; - } - - dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n", - priv->firmware_version); - - if (priv->firmware_version == 0xFFFF) { - dev_dbg(&priv->usb->dev, "In Loader.\n"); - ret = -EINVAL; - goto end; - } - - if (priv->firmware_version < FIRMWARE_VERSION) { - /* branch to loader for download new firmware */ - ret = vnt_firmware_branch_to_sram(priv); - if (ret) { - dev_dbg(&priv->usb->dev, - "Could not branch to SRAM: %d.\n", ret); - } else { - ret = -EINVAL; - } - } - -end: - return ret; -} diff --git a/drivers/staging/vt6656/firmware.h b/drivers/staging/vt6656/firmware.h deleted file mode 100644 index 161126faf396..000000000000 --- a/drivers/staging/vt6656/firmware.h +++ /dev/null @@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. - * All rights reserved. - * - * File: firmware.h - * - * Purpose: Version and Release Information - * - * Author: Yiching Chen - * - * Date: May 20, 2004 - * - */ - -#ifndef __FIRMWARE_H__ -#define __FIRMWARE_H__ - -#include "device.h" - -int vnt_download_firmware(struct vnt_private *priv); -int vnt_firmware_branch_to_sram(struct vnt_private *priv); -int vnt_check_firmware_version(struct vnt_private *priv); - -#endif /* __FIRMWARE_H__ */ diff --git a/drivers/staging/vt6656/mac.h b/drivers/staging/vt6656/mac.h index c532b27de37f..b01d9ee8677e 100644 --- a/drivers/staging/vt6656/mac.h +++ b/drivers/staging/vt6656/mac.h @@ -177,7 +177,7 @@ #define EnCFG_BBType_a 0x00 #define EnCFG_BBType_b BIT(0) #define EnCFG_BBType_g BIT(1) -#define EnCFG_BBType_MASK (BIT(0) | BIT(1)) +#define EnCFG_BBType_MASK (EnCFG_BBType_b | EnCFG_BBType_g) #define EnCFG_ProtectMd BIT(5) /* Bits in the EnhanceCFG_1 register */ diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c index 5f78cad3b647..aad97fcaf9c8 100644 --- a/drivers/staging/vt6656/main_usb.c +++ b/drivers/staging/vt6656/main_usb.c @@ -33,7 +33,6 @@ #include "wcmd.h" #include "rxtx.h" #include "rf.h" -#include "firmware.h" #include "usbpipe.h" #include "channel.h" @@ -99,10 +98,88 @@ static void vnt_set_options(struct vnt_private *priv) priv->op_mode = NL80211_IFTYPE_UNSPECIFIED; priv->bb_type = BBP_TYPE_DEF; priv->packet_type = priv->bb_type; - priv->preamble_type = 0; + priv->preamble_type = PREAMBLE_LONG; priv->exist_sw_net_addr = false; } +static int vnt_download_firmware(struct vnt_private *priv) +{ + struct device *dev = &priv->usb->dev; + const struct firmware *fw; + u16 length; + int ii; + int ret = 0; + + dev_dbg(dev, "---->Download firmware\n"); + + ret = request_firmware(&fw, FIRMWARE_NAME, dev); + if (ret) { + dev_err(dev, "firmware file %s request failed (%d)\n", + FIRMWARE_NAME, ret); + goto end; + } + + for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) { + length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE); + + ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length, + fw->data + ii); + if (ret) + goto free_fw; + + dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size); + } + +free_fw: + release_firmware(fw); +end: + return ret; +} + +static int vnt_firmware_branch_to_sram(struct vnt_private *priv) +{ + dev_dbg(&priv->usb->dev, "---->Branch to Sram\n"); + + return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL); +} + +static int vnt_check_firmware_version(struct vnt_private *priv) +{ + int ret = 0; + + ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0, + MESSAGE_REQUEST_VERSION, 2, + (u8 *)&priv->firmware_version); + if (ret) { + dev_dbg(&priv->usb->dev, + "Could not get firmware version: %d.\n", ret); + goto end; + } + + dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n", + priv->firmware_version); + + if (priv->firmware_version == 0xFFFF) { + dev_dbg(&priv->usb->dev, "In Loader.\n"); + ret = -EINVAL; + goto end; + } + + if (priv->firmware_version < FIRMWARE_VERSION) { + /* branch to loader for download new firmware */ + ret = vnt_firmware_branch_to_sram(priv); + if (ret) { + dev_dbg(&priv->usb->dev, + "Could not branch to SRAM: %d.\n", ret); + } else { + ret = -EINVAL; + } + } + +end: + return ret; +} + /* * initialization of MAC & BBP registers */ @@ -683,15 +760,14 @@ static int vnt_config(struct ieee80211_hw *hw, u32 changed) priv->bb_type = BB_TYPE_11G; } - if (changed & IEEE80211_CONF_CHANGE_POWER) { - if (priv->bb_type == BB_TYPE_11B) - priv->current_rate = RATE_1M; - else - priv->current_rate = RATE_54M; + if (changed & IEEE80211_CONF_CHANGE_POWER) + vnt_rf_setpower(priv, conf->chandef.chan); - vnt_rf_setpower(priv, priv->current_rate, - conf->chandef.chan->hw_value); - } + if (conf->flags & (IEEE80211_CONF_OFFCHANNEL | IEEE80211_CONF_IDLE)) + /* Set max sensitivity*/ + vnt_update_pre_ed_threshold(priv, true); + else + vnt_update_pre_ed_threshold(priv, false); return 0; } @@ -718,10 +794,10 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw, if (changed & BSS_CHANGED_ERP_PREAMBLE) { if (conf->use_short_preamble) { vnt_mac_enable_barker_preamble_mode(priv); - priv->preamble_type = true; + priv->preamble_type = PREAMBLE_SHORT; } else { vnt_mac_disable_barker_preamble_mode(priv); - priv->preamble_type = false; + priv->preamble_type = PREAMBLE_LONG; } } @@ -740,16 +816,14 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw, vnt_set_short_slot_time(priv); vnt_set_vga_gain_offset(priv, priv->bb_vga[0]); - vnt_update_pre_ed_threshold(priv, false); } if (changed & (BSS_CHANGED_BASIC_RATES | BSS_CHANGED_ERP_PREAMBLE | BSS_CHANGED_ERP_SLOT)) vnt_set_bss_mode(priv); - if (changed & BSS_CHANGED_TXPOWER) - vnt_rf_setpower(priv, priv->current_rate, - conf->chandef.chan->hw_value); + if (changed & (BSS_CHANGED_TXPOWER | BSS_CHANGED_BANDWIDTH)) + vnt_rf_setpower(priv, conf->chandef.chan); if (changed & BSS_CHANGED_BEACON_ENABLED) { dev_dbg(&priv->usb->dev, @@ -868,25 +942,6 @@ static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, return 0; } -static void vnt_sw_scan_start(struct ieee80211_hw *hw, - struct ieee80211_vif *vif, - const u8 *addr) -{ - struct vnt_private *priv = hw->priv; - - /* Set max sensitivity*/ - vnt_update_pre_ed_threshold(priv, true); -} - -static void vnt_sw_scan_complete(struct ieee80211_hw *hw, - struct ieee80211_vif *vif) -{ - struct vnt_private *priv = hw->priv; - - /* Return sensitivity to channel level*/ - vnt_update_pre_ed_threshold(priv, false); -} - static int vnt_get_stats(struct ieee80211_hw *hw, struct ieee80211_low_level_stats *stats) { @@ -932,8 +987,6 @@ static const struct ieee80211_ops vnt_mac_ops = { .prepare_multicast = vnt_prepare_multicast, .configure_filter = vnt_configure, .set_key = vnt_set_key, - .sw_scan_start = vnt_sw_scan_start, - .sw_scan_complete = vnt_sw_scan_complete, .get_stats = vnt_get_stats, .get_tsf = vnt_get_tsf, .set_tsf = vnt_set_tsf, @@ -1078,3 +1131,5 @@ static struct usb_driver vt6656_driver = { }; module_usb_driver(vt6656_driver); + +MODULE_FIRMWARE(FIRMWARE_NAME); diff --git a/drivers/staging/vt6656/rf.c b/drivers/staging/vt6656/rf.c index 43237b7e1dbe..06fa8867cfa3 100644 --- a/drivers/staging/vt6656/rf.c +++ b/drivers/staging/vt6656/rf.c @@ -21,13 +21,13 @@ * */ +#include <linux/errno.h> #include "mac.h" #include "rf.h" #include "baseband.h" #include "usbpipe.h" #define CB_AL2230_INIT_SEQ 15 -#define AL2230_PWR_IDX_LEN 64 #define CB_AL7230_INIT_SEQ 16 #define AL7230_PWR_IDX_LEN 64 @@ -518,74 +518,6 @@ static u8 vt3342_channel_table1[CB_MAX_CHANNEL][3] = { {0x03, 0x00, 0x04} }; -/* Power Table */ -static const u32 al2230_power_table[AL2230_PWR_IDX_LEN] = { - 0x04040900, - 0x04041900, - 0x04042900, - 0x04043900, - 0x04044900, - 0x04045900, - 0x04046900, - 0x04047900, - 0x04048900, - 0x04049900, - 0x0404a900, - 0x0404b900, - 0x0404c900, - 0x0404d900, - 0x0404e900, - 0x0404f900, - 0x04050900, - 0x04051900, - 0x04052900, - 0x04053900, - 0x04054900, - 0x04055900, - 0x04056900, - 0x04057900, - 0x04058900, - 0x04059900, - 0x0405a900, - 0x0405b900, - 0x0405c900, - 0x0405d900, - 0x0405e900, - 0x0405f900, - 0x04060900, - 0x04061900, - 0x04062900, - 0x04063900, - 0x04064900, - 0x04065900, - 0x04066900, - 0x04067900, - 0x04068900, - 0x04069900, - 0x0406a900, - 0x0406b900, - 0x0406c900, - 0x0406d900, - 0x0406e900, - 0x0406f900, - 0x04070900, - 0x04071900, - 0x04072900, - 0x04073900, - 0x04074900, - 0x04075900, - 0x04076900, - 0x04077900, - 0x04078900, - 0x04079900, - 0x0407a900, - 0x0407b900, - 0x0407c900, - 0x0407d900, - 0x0407e900, - 0x0407f900 -}; - /* * Description: Write to IF/RF, by embedded programming */ @@ -600,46 +532,8 @@ int vnt_rf_write_embedded(struct vnt_private *priv, u32 data) reg_data[2] = (u8)(data >> 16); reg_data[3] = (u8)(data >> 24); - vnt_control_out(priv, MESSAGE_TYPE_WRITE_IFRF, - 0, 0, ARRAY_SIZE(reg_data), reg_data); - - return true; -} - -/* Set Tx power by rate and channel number */ -int vnt_rf_setpower(struct vnt_private *priv, u32 rate, u32 channel) -{ - u8 power = priv->cck_pwr; - - if (channel == 0) - return -EINVAL; - - switch (rate) { - case RATE_1M: - case RATE_2M: - case RATE_5M: - case RATE_11M: - channel--; - - if (channel < sizeof(priv->cck_pwr_tbl)) - power = priv->cck_pwr_tbl[channel]; - break; - case RATE_6M: - case RATE_9M: - case RATE_12M: - case RATE_18M: - case RATE_24M: - case RATE_36M: - case RATE_48M: - case RATE_54M: - if (channel > CB_MAX_CHANNEL_24G) - power = priv->ofdm_a_pwr_tbl[channel - 15]; - else - power = priv->ofdm_pwr_tbl[channel - 1]; - break; - } - - return vnt_rf_set_txpower(priv, power, rate); + return vnt_control_out(priv, MESSAGE_TYPE_WRITE_IFRF, 0, 0, + ARRAY_SIZE(reg_data), reg_data); } static u8 vnt_rf_addpower(struct vnt_private *priv) @@ -669,55 +563,69 @@ static u8 vnt_rf_addpower(struct vnt_private *priv) } /* Set Tx power by power level and rate */ -int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate) +static int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, + struct ieee80211_channel *ch) { u32 power_setting = 0; - int ret = true; + int ret = 0; power += vnt_rf_addpower(priv); if (power > VNT_RF_MAX_POWER) power = VNT_RF_MAX_POWER; if (priv->power == power) - return true; + return 0; priv->power = power; switch (priv->rf_type) { case RF_AL2230: - if (power >= AL2230_PWR_IDX_LEN) - return false; + power_setting = 0x0404090 | (power << 12); - ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]); + ret = vnt_rf_write_embedded(priv, power_setting); + if (ret) + return ret; - if (rate <= RATE_11M) - ret &= vnt_rf_write_embedded(priv, 0x0001b400); + if (ch->flags & IEEE80211_CHAN_NO_OFDM) + ret = vnt_rf_write_embedded(priv, 0x0001b400); else - ret &= vnt_rf_write_embedded(priv, 0x0005a400); + ret = vnt_rf_write_embedded(priv, 0x0005a400); + break; case RF_AL2230S: - if (power >= AL2230_PWR_IDX_LEN) - return false; + power_setting = 0x0404090 | (power << 12); - ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]); + ret = vnt_rf_write_embedded(priv, power_setting); + if (ret) + return ret; - if (rate <= RATE_11M) { - ret &= vnt_rf_write_embedded(priv, 0x040c1400); - ret &= vnt_rf_write_embedded(priv, 0x00299b00); + if (ch->flags & IEEE80211_CHAN_NO_OFDM) { + ret = vnt_rf_write_embedded(priv, 0x040c1400); + if (ret) + return ret; + + ret = vnt_rf_write_embedded(priv, 0x00299b00); } else { - ret &= vnt_rf_write_embedded(priv, 0x0005a400); - ret &= vnt_rf_write_embedded(priv, 0x00099b00); + ret = vnt_rf_write_embedded(priv, 0x0005a400); + if (ret) + return ret; + + ret = vnt_rf_write_embedded(priv, 0x00099b00); } + break; case RF_AIROHA7230: - if (rate <= RATE_11M) - ret &= vnt_rf_write_embedded(priv, 0x111bb900); + if (ch->flags & IEEE80211_CHAN_NO_OFDM) + ret = vnt_rf_write_embedded(priv, 0x111bb900); else - ret &= vnt_rf_write_embedded(priv, 0x221bb900); + ret = vnt_rf_write_embedded(priv, 0x221bb900); + + if (ret) + return ret; if (power >= AL7230_PWR_IDX_LEN) - return false; + return -EINVAL; /* * 0x080F1B00 for 3 wire control TxGain(D10) @@ -725,61 +633,76 @@ int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate) */ power_setting = 0x080c0b00 | (power << 12); - ret &= vnt_rf_write_embedded(priv, power_setting); - + ret = vnt_rf_write_embedded(priv, power_setting); break; case RF_VT3226: if (power >= VT3226_PWR_IDX_LEN) - return false; + return -EINVAL; power_setting = ((0x3f - power) << 20) | (0x17 << 8); - ret &= vnt_rf_write_embedded(priv, power_setting); - + ret = vnt_rf_write_embedded(priv, power_setting); break; case RF_VT3226D0: if (power >= VT3226_PWR_IDX_LEN) - return false; + return -EINVAL; - if (rate <= RATE_11M) { - u16 hw_value = priv->hw->conf.chandef.chan->hw_value; + if (ch->flags & IEEE80211_CHAN_NO_OFDM) { + u16 hw_value = ch->hw_value; power_setting = ((0x3f - power) << 20) | (0xe07 << 8); - ret &= vnt_rf_write_embedded(priv, power_setting); - ret &= vnt_rf_write_embedded(priv, 0x03c6a200); + ret = vnt_rf_write_embedded(priv, power_setting); + if (ret) + return ret; + + ret = vnt_rf_write_embedded(priv, 0x03c6a200); + if (ret) + return ret; dev_dbg(&priv->usb->dev, "%s 11b channel [%d]\n", __func__, hw_value); hw_value--; - if (hw_value < ARRAY_SIZE(vt3226d0_lo_current_table)) - ret &= vnt_rf_write_embedded(priv, + if (hw_value < ARRAY_SIZE(vt3226d0_lo_current_table)) { + ret = vnt_rf_write_embedded(priv, vt3226d0_lo_current_table[hw_value]); + if (ret) + return ret; + } - ret &= vnt_rf_write_embedded(priv, 0x015C0800); + ret = vnt_rf_write_embedded(priv, 0x015C0800); } else { dev_dbg(&priv->usb->dev, "@@@@ %s> 11G mode\n", __func__); power_setting = ((0x3f - power) << 20) | (0x7 << 8); - ret &= vnt_rf_write_embedded(priv, power_setting); - ret &= vnt_rf_write_embedded(priv, 0x00C6A200); - ret &= vnt_rf_write_embedded(priv, 0x016BC600); - ret &= vnt_rf_write_embedded(priv, 0x00900800); + ret = vnt_rf_write_embedded(priv, power_setting); + if (ret) + return ret; + + ret = vnt_rf_write_embedded(priv, 0x00C6A200); + if (ret) + return ret; + + ret = vnt_rf_write_embedded(priv, 0x016BC600); + if (ret) + return ret; + + ret = vnt_rf_write_embedded(priv, 0x00900800); } + break; case RF_VT3342A0: if (power >= VT3342_PWR_IDX_LEN) - return false; + return -EINVAL; power_setting = ((0x3f - power) << 20) | (0x27 << 8); - ret &= vnt_rf_write_embedded(priv, power_setting); - + ret = vnt_rf_write_embedded(priv, power_setting); break; default: break; @@ -787,6 +710,36 @@ int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate) return ret; } +/* Set Tx power by channel number type */ +int vnt_rf_setpower(struct vnt_private *priv, + struct ieee80211_channel *ch) +{ + u16 channel; + u8 power = priv->cck_pwr; + + if (!ch) + return -EINVAL; + + /* set channel number to array number */ + channel = ch->hw_value - 1; + + if (ch->flags & IEEE80211_CHAN_NO_OFDM) { + if (channel < ARRAY_SIZE(priv->cck_pwr_tbl)) + power = priv->cck_pwr_tbl[channel]; + } else if (ch->band == NL80211_BAND_5GHZ) { + /* remove 14 channels to array size */ + channel -= 14; + + if (channel < ARRAY_SIZE(priv->ofdm_a_pwr_tbl)) + power = priv->ofdm_a_pwr_tbl[channel]; + } else { + if (channel < ARRAY_SIZE(priv->ofdm_pwr_tbl)) + power = priv->ofdm_pwr_tbl[channel]; + } + + return vnt_rf_set_txpower(priv, power, ch); +} + /* Convert rssi to dbm */ void vnt_rf_rssi_to_dbm(struct vnt_private *priv, u8 rssi, long *dbm) { diff --git a/drivers/staging/vt6656/rf.h b/drivers/staging/vt6656/rf.h index 7494546d71b8..493faaf4e2b5 100644 --- a/drivers/staging/vt6656/rf.h +++ b/drivers/staging/vt6656/rf.h @@ -41,8 +41,7 @@ #define VNT_RF_REG_LEN 0x17 /* 24 bit length */ int vnt_rf_write_embedded(struct vnt_private *priv, u32 data); -int vnt_rf_setpower(struct vnt_private *priv, u32 rate, u32 channel); -int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate); +int vnt_rf_setpower(struct vnt_private *priv, struct ieee80211_channel *ch); void vnt_rf_rssi_to_dbm(struct vnt_private *priv, u8 rssi, long *dbm); int vnt_rf_table_download(struct vnt_private *priv); diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c index 9439d190f431..335ef4fd104f 100644 --- a/drivers/staging/vt6656/rxtx.c +++ b/drivers/staging/vt6656/rxtx.c @@ -45,6 +45,25 @@ static const u16 vnt_time_stampoff[2][MAX_RATE] = { #define DATADUR_B 10 #define DATADUR_A 11 +static const u16 vnt_frame_time[MAX_RATE] = { + 10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216 +}; + +static const u8 vnt_phy_signal[] = { + 0x00, /* RATE_1M */ + 0x01, /* RATE_2M */ + 0x02, /* RATE_5M */ + 0x03, /* RATE_11M */ + 0x8b, /* RATE_6M */ + 0x8f, /* RATE_9M */ + 0x8a, /* RATE_12M */ + 0x8e, /* RATE_18M */ + 0x89, /* RATE_24M */ + 0x8d, /* RATE_36M */ + 0x88, /* RATE_48M */ + 0x8c /* RATE_54M */ +}; + static struct vnt_usb_send_context *vnt_get_free_context(struct vnt_private *priv) { @@ -78,6 +97,98 @@ static struct vnt_usb_send_context return NULL; } +/* Frame time for Tx */ +static unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type, + unsigned int frame_length, u16 tx_rate) +{ + unsigned int frame_time; + unsigned int preamble; + unsigned int rate; + + if (tx_rate > RATE_54M) + return 0; + + rate = (unsigned int)vnt_frame_time[tx_rate]; + + if (tx_rate <= RATE_11M) { + if (preamble_type == PREAMBLE_SHORT) + preamble = 96; + else + preamble = 192; + + frame_time = DIV_ROUND_UP(frame_length * 80, rate); + return preamble + frame_time; + } + + frame_time = DIV_ROUND_UP(frame_length * 8 + 22, rate); + frame_time = frame_time * 4; + + if (pkt_type != PK_TYPE_11A) + frame_time += 6; + return 20 + frame_time; +} + +/* Get Length, Service, and Signal fields of Phy for Tx */ +static void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length, + u16 tx_rate, u8 pkt_type, + struct vnt_phy_field *phy) +{ + u32 bit_count; + u32 count = 0; + u32 tmp; + int ext_bit; + int i; + u8 mask = 0; + u8 preamble_type = priv->preamble_type; + + bit_count = frame_length * 8; + ext_bit = false; + + switch (tx_rate) { + case RATE_1M: + count = bit_count; + break; + case RATE_2M: + count = bit_count / 2; + break; + case RATE_5M: + count = DIV_ROUND_UP(bit_count * 10, 55); + break; + case RATE_11M: + count = bit_count / 11; + tmp = count * 11; + + if (tmp != bit_count) { + count++; + + if ((bit_count - tmp) <= 3) + ext_bit = true; + } + + break; + } + + if (tx_rate > RATE_11M) { + if (pkt_type == PK_TYPE_11A) + mask = BIT(4); + } else if (tx_rate > RATE_1M) { + if (preamble_type == PREAMBLE_SHORT) + mask = BIT(3); + } + + i = tx_rate > RATE_54M ? RATE_54M : tx_rate; + phy->signal = vnt_phy_signal[i] | mask; + phy->service = 0x00; + + if (pkt_type == PK_TYPE_11B) { + if (ext_bit) + phy->service |= 0x80; + phy->len = cpu_to_le16((u16)count); + } else { + phy->len = cpu_to_le16((u16)frame_length); + } +} + static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate) { return cpu_to_le16(vnt_time_stampoff[priv->preamble_type % 2] @@ -547,7 +658,7 @@ int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) struct vnt_tx_fifo_head *tx_buffer_head; struct vnt_usb_send_context *tx_context; unsigned long flags; - u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id; + u16 tx_bytes, tx_header_size, tx_body_size, duration_id; u8 pkt_type; bool need_rts = false; bool need_mic = false; @@ -556,14 +667,7 @@ int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) rate = ieee80211_get_tx_rate(priv->hw, info); - current_rate = rate->hw_value; - if (priv->current_rate != current_rate && - !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) { - priv->current_rate = current_rate; - vnt_schedule_command(priv, WLAN_CMD_SETPOWER); - } - - if (current_rate > RATE_11M) { + if (rate->hw_value > RATE_11M) { if (info->band == NL80211_BAND_5GHZ) { pkt_type = PK_TYPE_11A; } else { @@ -593,7 +697,7 @@ int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) tx_context->pkt_type = pkt_type; tx_context->need_ack = false; tx_context->frame_len = skb->len + 4; - tx_context->tx_rate = current_rate; + tx_context->tx_rate = rate->hw_value; spin_unlock_irqrestore(&priv->lock, flags); @@ -666,7 +770,7 @@ int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) tx_context->frame_len += tx_key->icv_len; } - tx_buffer_head->current_rate = cpu_to_le16(current_rate); + tx_buffer_head->current_rate = cpu_to_le16(rate->hw_value); duration_id = vnt_generate_tx_parameter(tx_context, tx_buffer, &mic_hdr, need_mic, need_rts); diff --git a/drivers/staging/vt6656/rxtx.h b/drivers/staging/vt6656/rxtx.h index 0e6226af7d41..3c36a4b893dc 100644 --- a/drivers/staging/vt6656/rxtx.h +++ b/drivers/staging/vt6656/rxtx.h @@ -23,6 +23,13 @@ #define DEFAULT_MGN_LIFETIME_RES_64us 125 /* 64us */ #define DEFAULT_MSDU_LIFETIME_RES_64us 8000 +/* Length, Service, and Signal fields of Phy for Tx */ +struct vnt_phy_field { + u8 signal; + u8 service; + __le16 len; +} __packed; + /* MIC HDR data header */ struct vnt_mic_hdr { u8 id; diff --git a/drivers/staging/vt6656/wcmd.c b/drivers/staging/vt6656/wcmd.c index 2c5250ca2801..0ccc87da394e 100644 --- a/drivers/staging/vt6656/wcmd.c +++ b/drivers/staging/vt6656/wcmd.c @@ -122,8 +122,7 @@ void vnt_run_command(struct work_struct *work) case WLAN_CMD_SETPOWER_START: - vnt_rf_setpower(priv, priv->current_rate, - priv->hw->conf.chandef.chan->hw_value); + vnt_rf_setpower(priv, priv->hw->conf.chandef.chan); break; diff --git a/drivers/staging/wfx/Makefile b/drivers/staging/wfx/Makefile index 0d9c1ed092f6..0e0cc982ceab 100644 --- a/drivers/staging/wfx/Makefile +++ b/drivers/staging/wfx/Makefile @@ -7,6 +7,7 @@ wfx-y := \ bh.o \ hwio.o \ fwio.o \ + hif_tx_mib.o \ hif_tx.o \ hif_rx.o \ queue.o \ diff --git a/drivers/staging/wfx/TODO b/drivers/staging/wfx/TODO index efcb7c6a5aa7..fca3332e42ce 100644 --- a/drivers/staging/wfx/TODO +++ b/drivers/staging/wfx/TODO @@ -1,26 +1,18 @@ This is a list of things that need to be done to get this driver out of the staging directory. - - All structures defined in hif_api_*.h are intended to sent/received to/from - hardware. All their members whould be declared __le32 or __le16. - See: - https://lore.kernel.org/lkml/20191111202852.GX26530@ZenIV.linux.org.uk + - The HIF API is not yet clean enough. - - Once previous item done, it will be possible to audit the driver with - `sparse'. It will probably find tons of problems with big endian - architectures. + - Fix support for big endian architectures. See: + https://lore.kernel.org/lkml/20191111202852.GX26530@ZenIV.linux.org.uk - - hif_api_*.h whave been imported from firmware code. Some of the structures - are never used in driver. + - The pointers returned by allocation functions are always checked. - - Driver try to maintains power save status of the stations. However, this - work is already done by mac80211. sta_asleep_mask and pspoll_mask should be - dropped. + - The code that check the corectness of received message (in rx_helper()) can + be improved. See: + https://lore.kernel.org/driverdev-devel/2302785.6C7ODC2LYm@pc-42/ - - wfx_tx_queues_get() should be reworked. It currently try compute itself the - QoS policy. However, firmware already do the job. Firmware would prefer to - have a few packets in each queue and be able to choose itself which queue to - use. + - Support for SDIO with external IRQ is broken. - As suggested by Felix, rate control could be improved following this idea: https://lore.kernel.org/lkml/3099559.gv3Q75KnN1@pc-42/ @@ -28,17 +20,8 @@ staging directory. - When driver is about to loose BSS, it forge its own Null Func request (see wfx_cqm_bssloss_sm()). It should use mechanism provided by mac80211. - - AP is actually is setup after a call to wfx_bss_info_changed(). Yet, - ieee80211_ops provide callback start_ap(). - - - The current process for joining a network is incredibly complex. Should be - reworked. - - Monitoring mode is not implemented despite being mandatory by mac80211. - - "compatible" value are not correct. They should be "vendor,chip". See: - https://lore.kernel.org/driverdev-devel/5226570.CMH5hVlZcI@pc-42 - - The "state" field from wfx_vif should be replaced by "vif->type". - It seems that wfx_upload_keys() is useless. @@ -49,12 +32,13 @@ staging directory. - Feature called "secure link" should be either developed (using kernel crypto API) or dropped. + - The device allows to filter multicast traffic. The code to support these + filters exists in the driver but it is disabled because it has never been + tested. + - In wfx_cmd_send(), "async" allow to send command without waiting the reply. It may help in some situation, but it is not yet used. In add, it may cause some trouble: https://lore.kernel.org/driverdev-devel/alpine.DEB.2.21.1910041317381.2992@hadrien/ So, fix it (by replacing the mutex with a semaphore) or drop it. - - Chip support P2P, but driver does not implement it. - - - Chip support kind of Mesh, but driver does not implement it. diff --git a/drivers/staging/wfx/bh.c b/drivers/staging/wfx/bh.c index 9fcab00a3733..ba7fa0a7cd9a 100644 --- a/drivers/staging/wfx/bh.c +++ b/drivers/staging/wfx/bh.c @@ -108,8 +108,6 @@ static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf) release_count = 1; WARN(wdev->hif.tx_buffers_used < release_count, "corrupted buffer counter"); wdev->hif.tx_buffers_used -= release_count; - if (!wdev->hif.tx_buffers_used) - wake_up(&wdev->hif.tx_buffers_empty); } _trace_hif_recv(hif, wdev->hif.tx_buffers_used); @@ -123,6 +121,8 @@ static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf) skb_put(skb, hif->len); // wfx_handle_rx takes care on SKB livetime wfx_handle_rx(wdev, skb); + if (!wdev->hif.tx_buffers_used) + wake_up(&wdev->hif.tx_buffers_empty); return piggyback; diff --git a/drivers/staging/wfx/data_rx.c b/drivers/staging/wfx/data_rx.c index c5b83fedeb55..c3b3edae3420 100644 --- a/drivers/staging/wfx/data_rx.c +++ b/drivers/staging/wfx/data_rx.c @@ -118,18 +118,6 @@ void wfx_rx_cb(struct wfx_vif *wvif, arg->rx_flags.match_uc_addr && mgmt->u.action.category == WLAN_CATEGORY_BACK) goto drop; - if (ieee80211_is_beacon(frame->frame_control) && - !arg->status && wvif->vif && - ether_addr_equal(ieee80211_get_SA(frame), - wvif->vif->bss_conf.bssid)) { - /* Disable beacon filter once we're associated... */ - if (wvif->disable_beacon_filter && - (wvif->vif->bss_conf.assoc || - wvif->vif->bss_conf.ibss_joined)) { - wvif->disable_beacon_filter = false; - schedule_work(&wvif->update_filtering_work); - } - } ieee80211_rx_irqsafe(wvif->wdev->hw, skb); return; diff --git a/drivers/staging/wfx/data_tx.c b/drivers/staging/wfx/data_tx.c index 42183c70d4df..9c1a91207dd8 100644 --- a/drivers/staging/wfx/data_tx.c +++ b/drivers/staging/wfx/data_tx.c @@ -6,6 +6,7 @@ * Copyright (c) 2010, ST-Ericsson */ #include <net/mac80211.h> +#include <linux/etherdevice.h> #include "data_tx.h" #include "wfx.h" @@ -16,9 +17,6 @@ #include "traces.h" #include "hif_tx_mib.h" -#define WFX_INVALID_RATE_ID 15 -#define WFX_LINK_ID_GC_TIMEOUT ((unsigned long)(10 * HZ)) - static int wfx_get_hw_rate(struct wfx_dev *wdev, const struct ieee80211_tx_rate *rate) { @@ -51,59 +49,6 @@ static void wfx_tx_policy_build(struct wfx_vif *wvif, struct tx_policy *policy, if (rates[i].idx < 0) break; count = i; - - /* HACK!!! Device has problems (at least) switching from - * 54Mbps CTS to 1Mbps. This switch takes enormous amount - * of time (100-200 ms), leading to valuable throughput drop. - * As a workaround, additional g-rates are injected to the - * policy. - */ - if (count == 2 && !(rates[0].flags & IEEE80211_TX_RC_MCS) && - rates[0].idx > 4 && rates[0].count > 2 && - rates[1].idx < 2) { - int mid_rate = (rates[0].idx + 4) >> 1; - - /* Decrease number of retries for the initial rate */ - rates[0].count -= 2; - - if (mid_rate != 4) { - /* Keep fallback rate at 1Mbps. */ - rates[3] = rates[1]; - - /* Inject 1 transmission on lowest g-rate */ - rates[2].idx = 4; - rates[2].count = 1; - rates[2].flags = rates[1].flags; - - /* Inject 1 transmission on mid-rate */ - rates[1].idx = mid_rate; - rates[1].count = 1; - - /* Fallback to 1 Mbps is a really bad thing, - * so let's try to increase probability of - * successful transmission on the lowest g rate - * even more - */ - if (rates[0].count >= 3) { - --rates[0].count; - ++rates[2].count; - } - - /* Adjust amount of rates defined */ - count += 2; - } else { - /* Keep fallback rate at 1Mbps. */ - rates[2] = rates[1]; - - /* Inject 2 transmissions on lowest g-rate */ - rates[1].idx = 4; - rates[1].count = 2; - - /* Adjust amount of rates defined */ - count += 1; - } - } - for (i = 0; i < IEEE80211_TX_MAX_RATES; ++i) { int rateid; u8 count; @@ -171,7 +116,7 @@ static int wfx_tx_policy_get(struct wfx_vif *wvif, if (list_empty(&cache->free)) { WARN(1, "unable to get a valid Tx policy"); spin_unlock_bh(&cache->lock); - return WFX_INVALID_RATE_ID; + return HIF_TX_RETRY_POLICY_INVALID; } idx = wfx_tx_policy_find(cache, &wanted); if (idx >= 0) { @@ -189,10 +134,8 @@ static int wfx_tx_policy_get(struct wfx_vif *wvif, idx = entry - cache->cache; } wfx_tx_policy_use(cache, &cache->cache[idx]); - if (list_empty(&cache->free)) { - /* Lock TX queues. */ - wfx_tx_queues_lock(wvif->wdev); - } + if (list_empty(&cache->free)) + ieee80211_stop_queues(wvif->wdev->hw); spin_unlock_bh(&cache->lock); return idx; } @@ -202,15 +145,13 @@ static void wfx_tx_policy_put(struct wfx_vif *wvif, int idx) int usage, locked; struct tx_policy_cache *cache = &wvif->tx_policy_cache; - if (idx == WFX_INVALID_RATE_ID) + if (idx == HIF_TX_RETRY_POLICY_INVALID) return; spin_lock_bh(&cache->lock); locked = list_empty(&cache->free); usage = wfx_tx_policy_release(cache, &cache->cache[idx]); - if (locked && !usage) { - /* Unlock TX queues. */ - wfx_tx_queues_unlock(wvif->wdev); - } + if (locked && !usage) + ieee80211_wake_queues(wvif->wdev->hw); spin_unlock_bh(&cache->lock); } @@ -222,11 +163,11 @@ static int wfx_tx_policy_upload(struct wfx_vif *wvif) do { spin_lock_bh(&wvif->tx_policy_cache.lock); - for (i = 0; i < HIF_MIB_NUM_TX_RATE_RETRY_POLICIES; ++i) + for (i = 0; i < HIF_TX_RETRY_POLICY_MAX; ++i) if (!policies[i].uploaded && memzcmp(policies[i].rates, sizeof(policies[i].rates))) break; - if (i < HIF_MIB_NUM_TX_RATE_RETRY_POLICIES) { + if (i < HIF_TX_RETRY_POLICY_MAX) { policies[i].uploaded = true; memcpy(tmp_rates, policies[i].rates, sizeof(tmp_rates)); spin_unlock_bh(&wvif->tx_policy_cache.lock); @@ -234,7 +175,7 @@ static int wfx_tx_policy_upload(struct wfx_vif *wvif) } else { spin_unlock_bh(&wvif->tx_policy_cache.lock); } - } while (i < HIF_MIB_NUM_TX_RATE_RETRY_POLICIES); + } while (i < HIF_TX_RETRY_POLICY_MAX); return 0; } @@ -244,9 +185,7 @@ void wfx_tx_policy_upload_work(struct work_struct *work) container_of(work, struct wfx_vif, tx_policy_upload_work); wfx_tx_policy_upload(wvif); - wfx_tx_unlock(wvif->wdev); - wfx_tx_queues_unlock(wvif->wdev); } void wfx_tx_policy_init(struct wfx_vif *wvif) @@ -260,7 +199,7 @@ void wfx_tx_policy_init(struct wfx_vif *wvif) INIT_LIST_HEAD(&cache->used); INIT_LIST_HEAD(&cache->free); - for (i = 0; i < HIF_MIB_NUM_TX_RATE_RETRY_POLICIES; ++i) + for (i = 0; i < HIF_TX_RETRY_POLICY_MAX; ++i) list_add(&cache->cache[i].link, &cache->free); } @@ -281,15 +220,9 @@ static void wfx_tx_manage_pm(struct wfx_vif *wvif, struct ieee80211_hdr *hdr, struct wfx_tx_priv *tx_priv, struct ieee80211_sta *sta) { - u32 mask = ~BIT(tx_priv->raw_link_id); struct wfx_sta_priv *sta_priv; int tid = ieee80211_get_tid(hdr); - spin_lock_bh(&wvif->ps_state_lock); - if (ieee80211_is_auth(hdr->frame_control)) - wvif->sta_asleep_mask &= mask; - spin_unlock_bh(&wvif->ps_state_lock); - if (sta) { sta_priv = (struct wfx_sta_priv *)&sta->drv_priv; spin_lock_bh(&sta_priv->lock); @@ -299,9 +232,8 @@ static void wfx_tx_manage_pm(struct wfx_vif *wvif, struct ieee80211_hdr *hdr, } } -static u8 wfx_tx_get_raw_link_id(struct wfx_vif *wvif, - struct ieee80211_sta *sta, - struct ieee80211_hdr *hdr) +static u8 wfx_tx_get_link_id(struct wfx_vif *wvif, struct ieee80211_sta *sta, + struct ieee80211_hdr *hdr) { struct wfx_sta_priv *sta_priv = sta ? (struct wfx_sta_priv *)&sta->drv_priv : NULL; @@ -313,7 +245,7 @@ static u8 wfx_tx_get_raw_link_id(struct wfx_vif *wvif, return 0; if (is_multicast_ether_addr(da)) return 0; - return WFX_LINK_ID_NO_ASSOC; + return HIF_LINK_ID_NOT_ASSOCIATED; } static void wfx_tx_fixup_rates(struct ieee80211_tx_rate *rates) @@ -375,19 +307,13 @@ static u8 wfx_tx_get_rate_id(struct wfx_vif *wvif, rate_id = wfx_tx_policy_get(wvif, tx_info->driver_rates, &tx_policy_renew); - if (rate_id == WFX_INVALID_RATE_ID) + if (rate_id == HIF_TX_RETRY_POLICY_INVALID) dev_warn(wvif->wdev->dev, "unable to get a valid Tx policy"); if (tx_policy_renew) { - /* FIXME: It's not so optimal to stop TX queues every now and - * then. Better to reimplement task scheduling with a counter. - */ wfx_tx_lock(wvif->wdev); - wfx_tx_queues_lock(wvif->wdev); - if (!schedule_work(&wvif->tx_policy_upload_work)) { - wfx_tx_queues_unlock(wvif->wdev); + if (!schedule_work(&wvif->tx_policy_upload_work)) wfx_tx_unlock(wvif->wdev); - } } return rate_id; } @@ -429,7 +355,7 @@ static int wfx_tx_inner(struct wfx_vif *wvif, struct ieee80211_sta *sta, struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); struct ieee80211_key_conf *hw_key = tx_info->control.hw_key; struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; - int queue_id = tx_info->hw_queue; + int queue_id = skb_get_queue_mapping(skb); size_t offset = (size_t)skb->data & 3; int wmsg_len = sizeof(struct hif_msg) + sizeof(struct hif_req_tx) + offset; @@ -441,14 +367,8 @@ static int wfx_tx_inner(struct wfx_vif *wvif, struct ieee80211_sta *sta, memset(tx_info->rate_driver_data, 0, sizeof(struct wfx_tx_priv)); // Fill tx_priv tx_priv = (struct wfx_tx_priv *)tx_info->rate_driver_data; - tx_priv->raw_link_id = wfx_tx_get_raw_link_id(wvif, sta, hdr); - tx_priv->link_id = tx_priv->raw_link_id; if (ieee80211_has_protected(hdr->frame_control)) tx_priv->hw_key = hw_key; - if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) - tx_priv->link_id = WFX_LINK_ID_AFTER_DTIM; - if (sta && (sta->uapsd_queues & BIT(queue_id))) - tx_priv->link_id = WFX_LINK_ID_UAPSD; // Fill hif_msg WARN(skb_headroom(skb) < wmsg_len, "not enough space in skb"); @@ -478,7 +398,7 @@ static int wfx_tx_inner(struct wfx_vif *wvif, struct ieee80211_sta *sta, req->data_flags.fc_offset = offset; if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) req->data_flags.after_dtim = 1; - req->queue_id.peer_sta_id = tx_priv->raw_link_id; + req->queue_id.peer_sta_id = wfx_tx_get_link_id(wvif, sta, hdr); // Queue index are inverted between firmware and Linux req->queue_id.queue_id = 3 - queue_id; req->ht_tx_parameters = wfx_tx_get_tx_parms(wvif->wdev, tx_info); @@ -486,7 +406,7 @@ static int wfx_tx_inner(struct wfx_vif *wvif, struct ieee80211_sta *sta, // Auxiliary operations wfx_tx_manage_pm(wvif, hdr, tx_priv, sta); - wfx_tx_queue_put(wvif->wdev, &wvif->wdev->tx_queue[queue_id], skb); + wfx_tx_queues_put(wvif->wdev, skb); if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) schedule_work(&wvif->update_tim_work); wfx_bh_request_tx(wvif->wdev); @@ -528,6 +448,43 @@ drop: ieee80211_tx_status_irqsafe(wdev->hw, skb); } +static void wfx_notify_buffered_tx(struct wfx_vif *wvif, struct sk_buff *skb) +{ + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; + struct ieee80211_sta *sta; + struct wfx_sta_priv *sta_priv; + int tid = ieee80211_get_tid(hdr); + + rcu_read_lock(); // protect sta + sta = ieee80211_find_sta(wvif->vif, hdr->addr1); + if (sta) { + sta_priv = (struct wfx_sta_priv *)&sta->drv_priv; + spin_lock_bh(&sta_priv->lock); + WARN(!sta_priv->buffered[tid], "inconsistent notification"); + sta_priv->buffered[tid]--; + if (!sta_priv->buffered[tid]) + ieee80211_sta_set_buffered(sta, tid, false); + spin_unlock_bh(&sta_priv->lock); + } + rcu_read_unlock(); +} + +static void wfx_skb_dtor(struct wfx_dev *wdev, struct sk_buff *skb) +{ + struct hif_msg *hif = (struct hif_msg *)skb->data; + struct hif_req_tx *req = (struct hif_req_tx *)hif->body; + struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface); + unsigned int offset = sizeof(struct hif_req_tx) + + sizeof(struct hif_msg) + + req->data_flags.fc_offset; + + WARN_ON(!wvif); + skb_pull(skb, offset); + wfx_notify_buffered_tx(wvif, skb); + wfx_tx_policy_put(wvif, req->tx_flags.retry_policy_index); + ieee80211_tx_status_irqsafe(wdev->hw, skb); +} + void wfx_tx_confirm_cb(struct wfx_vif *wvif, const struct hif_cnf_tx *arg) { int i; @@ -590,9 +547,6 @@ void wfx_tx_confirm_cb(struct wfx_vif *wvif, const struct hif_cnf_tx *arg) memset(tx_info->pad, 0, sizeof(tx_info->pad)); if (!arg->status) { - if (wvif->bss_loss_state && - arg->packet_id == wvif->bss_loss_confirm_id) - wfx_cqm_bssloss_sm(wvif, 0, 1, 0); tx_info->status.tx_time = arg->media_delay - arg->tx_queue_delay; if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) @@ -606,47 +560,40 @@ void wfx_tx_confirm_cb(struct wfx_vif *wvif, const struct hif_cnf_tx *arg) schedule_work(&wvif->update_tim_work); } tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED; - } else { - if (wvif->bss_loss_state && - arg->packet_id == wvif->bss_loss_confirm_id) - wfx_cqm_bssloss_sm(wvif, 0, 0, 1); } - wfx_pending_remove(wvif->wdev, skb); + wfx_skb_dtor(wvif->wdev, skb); } -static void wfx_notify_buffered_tx(struct wfx_vif *wvif, struct sk_buff *skb) +void wfx_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, + u32 queues, bool drop) { - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; - struct ieee80211_sta *sta; - struct wfx_sta_priv *sta_priv; - int tid = ieee80211_get_tid(hdr); + struct wfx_dev *wdev = hw->priv; + struct sk_buff_head dropped; + struct wfx_queue *queue; + struct sk_buff *skb; + int vif_id = -1; + int i; - rcu_read_lock(); // protect sta - sta = ieee80211_find_sta(wvif->vif, hdr->addr1); - if (sta) { - sta_priv = (struct wfx_sta_priv *)&sta->drv_priv; - spin_lock_bh(&sta_priv->lock); - WARN(!sta_priv->buffered[tid], "inconsistent notification"); - sta_priv->buffered[tid]--; - if (!sta_priv->buffered[tid]) - ieee80211_sta_set_buffered(sta, tid, false); - spin_unlock_bh(&sta_priv->lock); + if (vif) + vif_id = ((struct wfx_vif *)vif->drv_priv)->id; + skb_queue_head_init(&dropped); + for (i = 0; i < IEEE80211_NUM_ACS; i++) { + if (!(BIT(i) & queues)) + continue; + queue = &wdev->tx_queue[i]; + if (drop) + wfx_tx_queue_drop(wdev, queue, vif_id, &dropped); + if (wdev->chip_frozen) + continue; + if (wait_event_timeout(wdev->tx_dequeue, + wfx_tx_queue_empty(wdev, queue, vif_id), + msecs_to_jiffies(1000)) <= 0) + dev_warn(wdev->dev, "frames queued while flushing tx queues?"); } - rcu_read_unlock(); + wfx_tx_flush(wdev); + if (wdev->chip_frozen) + wfx_pending_drop(wdev, &dropped); + while ((skb = skb_dequeue(&dropped)) != NULL) + wfx_skb_dtor(wdev, skb); } -void wfx_skb_dtor(struct wfx_dev *wdev, struct sk_buff *skb) -{ - struct hif_msg *hif = (struct hif_msg *)skb->data; - struct hif_req_tx *req = (struct hif_req_tx *)hif->body; - struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface); - unsigned int offset = sizeof(struct hif_req_tx) + - sizeof(struct hif_msg) + - req->data_flags.fc_offset; - - WARN_ON(!wvif); - skb_pull(skb, offset); - wfx_notify_buffered_tx(wvif, skb); - wfx_tx_policy_put(wvif, req->tx_flags.retry_policy_index); - ieee80211_tx_status_irqsafe(wdev->hw, skb); -} diff --git a/drivers/staging/wfx/data_tx.h b/drivers/staging/wfx/data_tx.h index c545dd75449b..a308af3d68ad 100644 --- a/drivers/staging/wfx/data_tx.h +++ b/drivers/staging/wfx/data_tx.h @@ -26,7 +26,7 @@ struct tx_policy { }; struct tx_policy_cache { - struct tx_policy cache[HIF_MIB_NUM_TX_RATE_RETRY_POLICIES]; + struct tx_policy cache[HIF_TX_RETRY_POLICY_MAX]; // FIXME: use a trees and drop hash from tx_policy struct list_head used; struct list_head free; @@ -36,8 +36,6 @@ struct tx_policy_cache { struct wfx_tx_priv { ktime_t xmit_timestamp; struct ieee80211_key_conf *hw_key; - u8 link_id; - u8 raw_link_id; } __packed; void wfx_tx_policy_init(struct wfx_vif *wvif); @@ -46,7 +44,8 @@ void wfx_tx_policy_upload_work(struct work_struct *work); void wfx_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, struct sk_buff *skb); void wfx_tx_confirm_cb(struct wfx_vif *wvif, const struct hif_cnf_tx *arg); -void wfx_skb_dtor(struct wfx_dev *wdev, struct sk_buff *skb); +void wfx_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, + u32 queues, bool drop); static inline struct wfx_tx_priv *wfx_skb_tx_priv(struct sk_buff *skb) { diff --git a/drivers/staging/wfx/hif_api_cmd.h b/drivers/staging/wfx/hif_api_cmd.h index 071b71e2a107..6f70801949bb 100644 --- a/drivers/staging/wfx/hif_api_cmd.h +++ b/drivers/staging/wfx/hif_api_cmd.h @@ -10,56 +10,54 @@ #include "hif_api_general.h" -#define HIF_NUM_AC 4 - #define HIF_API_SSID_SIZE API_SSID_SIZE enum hif_requests_ids { - HIF_REQ_ID_RESET = 0x0a, - HIF_REQ_ID_READ_MIB = 0x05, - HIF_REQ_ID_WRITE_MIB = 0x06, - HIF_REQ_ID_START_SCAN = 0x07, - HIF_REQ_ID_STOP_SCAN = 0x08, - HIF_REQ_ID_TX = 0x04, - HIF_REQ_ID_JOIN = 0x0b, - HIF_REQ_ID_SET_PM_MODE = 0x10, - HIF_REQ_ID_SET_BSS_PARAMS = 0x11, - HIF_REQ_ID_ADD_KEY = 0x0c, - HIF_REQ_ID_REMOVE_KEY = 0x0d, - HIF_REQ_ID_EDCA_QUEUE_PARAMS = 0x13, - HIF_REQ_ID_START = 0x17, - HIF_REQ_ID_BEACON_TRANSMIT = 0x18, - HIF_REQ_ID_UPDATE_IE = 0x1b, - HIF_REQ_ID_MAP_LINK = 0x1c, + HIF_REQ_ID_RESET = 0x0a, + HIF_REQ_ID_READ_MIB = 0x05, + HIF_REQ_ID_WRITE_MIB = 0x06, + HIF_REQ_ID_START_SCAN = 0x07, + HIF_REQ_ID_STOP_SCAN = 0x08, + HIF_REQ_ID_TX = 0x04, + HIF_REQ_ID_JOIN = 0x0b, + HIF_REQ_ID_SET_PM_MODE = 0x10, + HIF_REQ_ID_SET_BSS_PARAMS = 0x11, + HIF_REQ_ID_ADD_KEY = 0x0c, + HIF_REQ_ID_REMOVE_KEY = 0x0d, + HIF_REQ_ID_EDCA_QUEUE_PARAMS = 0x13, + HIF_REQ_ID_START = 0x17, + HIF_REQ_ID_BEACON_TRANSMIT = 0x18, + HIF_REQ_ID_UPDATE_IE = 0x1b, + HIF_REQ_ID_MAP_LINK = 0x1c, }; enum hif_confirmations_ids { - HIF_CNF_ID_RESET = 0x0a, - HIF_CNF_ID_READ_MIB = 0x05, - HIF_CNF_ID_WRITE_MIB = 0x06, - HIF_CNF_ID_START_SCAN = 0x07, - HIF_CNF_ID_STOP_SCAN = 0x08, - HIF_CNF_ID_TX = 0x04, - HIF_CNF_ID_MULTI_TRANSMIT = 0x1e, - HIF_CNF_ID_JOIN = 0x0b, - HIF_CNF_ID_SET_PM_MODE = 0x10, - HIF_CNF_ID_SET_BSS_PARAMS = 0x11, - HIF_CNF_ID_ADD_KEY = 0x0c, - HIF_CNF_ID_REMOVE_KEY = 0x0d, - HIF_CNF_ID_EDCA_QUEUE_PARAMS = 0x13, - HIF_CNF_ID_START = 0x17, - HIF_CNF_ID_BEACON_TRANSMIT = 0x18, - HIF_CNF_ID_UPDATE_IE = 0x1b, - HIF_CNF_ID_MAP_LINK = 0x1c, + HIF_CNF_ID_RESET = 0x0a, + HIF_CNF_ID_READ_MIB = 0x05, + HIF_CNF_ID_WRITE_MIB = 0x06, + HIF_CNF_ID_START_SCAN = 0x07, + HIF_CNF_ID_STOP_SCAN = 0x08, + HIF_CNF_ID_TX = 0x04, + HIF_CNF_ID_MULTI_TRANSMIT = 0x1e, + HIF_CNF_ID_JOIN = 0x0b, + HIF_CNF_ID_SET_PM_MODE = 0x10, + HIF_CNF_ID_SET_BSS_PARAMS = 0x11, + HIF_CNF_ID_ADD_KEY = 0x0c, + HIF_CNF_ID_REMOVE_KEY = 0x0d, + HIF_CNF_ID_EDCA_QUEUE_PARAMS = 0x13, + HIF_CNF_ID_START = 0x17, + HIF_CNF_ID_BEACON_TRANSMIT = 0x18, + HIF_CNF_ID_UPDATE_IE = 0x1b, + HIF_CNF_ID_MAP_LINK = 0x1c, }; enum hif_indications_ids { - HIF_IND_ID_RX = 0x84, - HIF_IND_ID_SCAN_CMPL = 0x86, - HIF_IND_ID_JOIN_COMPLETE = 0x8f, - HIF_IND_ID_SET_PM_MODE_CMPL = 0x89, - HIF_IND_ID_SUSPEND_RESUME_TX = 0x8c, - HIF_IND_ID_EVENT = 0x85 + HIF_IND_ID_RX = 0x84, + HIF_IND_ID_SCAN_CMPL = 0x86, + HIF_IND_ID_JOIN_COMPLETE = 0x8f, + HIF_IND_ID_SET_PM_MODE_CMPL = 0x89, + HIF_IND_ID_SUSPEND_RESUME_TX = 0x8c, + HIF_IND_ID_EVENT = 0x85 }; union hif_commands_ids { @@ -69,26 +67,26 @@ union hif_commands_ids { }; enum hif_status { - HIF_STATUS_SUCCESS = 0x0, - HIF_STATUS_FAILURE = 0x1, - HIF_INVALID_PARAMETER = 0x2, - HIF_STATUS_WARNING = 0x3, - HIF_ERROR_UNSUPPORTED_MSG_ID = 0x4, - HIF_STATUS_DECRYPTFAILURE = 0x10, - HIF_STATUS_MICFAILURE = 0x11, - HIF_STATUS_NO_KEY_FOUND = 0x12, - HIF_STATUS_RETRY_EXCEEDED = 0x13, - HIF_STATUS_TX_LIFETIME_EXCEEDED = 0x14, - HIF_REQUEUE = 0x15, - HIF_STATUS_REFUSED = 0x16, - HIF_STATUS_BUSY = 0x17 + HIF_STATUS_SUCCESS = 0x0, + HIF_STATUS_FAILURE = 0x1, + HIF_INVALID_PARAMETER = 0x2, + HIF_STATUS_WARNING = 0x3, + HIF_ERROR_UNSUPPORTED_MSG_ID = 0x4, + HIF_STATUS_DECRYPTFAILURE = 0x10, + HIF_STATUS_MICFAILURE = 0x11, + HIF_STATUS_NO_KEY_FOUND = 0x12, + HIF_STATUS_RETRY_EXCEEDED = 0x13, + HIF_STATUS_TX_LIFETIME_EXCEEDED = 0x14, + HIF_REQUEUE = 0x15, + HIF_STATUS_REFUSED = 0x16, + HIF_STATUS_BUSY = 0x17 }; struct hif_reset_flags { - u8 reset_stat:1; - u8 reset_all_int:1; - u8 reserved1:6; - u8 reserved2[3]; + u8 reset_stat:1; + u8 reset_all_int:1; + u8 reserved1:6; + u8 reserved2[3]; } __packed; struct hif_req_reset { @@ -96,117 +94,101 @@ struct hif_req_reset { } __packed; struct hif_req_read_mib { - u16 mib_id; - u16 reserved; + __le16 mib_id; + __le16 reserved; } __packed; struct hif_cnf_read_mib { - u32 status; - u16 mib_id; - u16 length; - u8 mib_data[]; + __le32 status; + __le16 mib_id; + __le16 length; + u8 mib_data[]; } __packed; struct hif_req_write_mib { - u16 mib_id; - u16 length; - u8 mib_data[]; + __le16 mib_id; + __le16 length; + u8 mib_data[]; } __packed; struct hif_cnf_write_mib { - u32 status; + __le32 status; } __packed; struct hif_ie_flags { - u8 beacon:1; - u8 probe_resp:1; - u8 probe_req:1; - u8 reserved1:5; - u8 reserved2; + u8 beacon:1; + u8 probe_resp:1; + u8 probe_req:1; + u8 reserved1:5; + u8 reserved2; } __packed; struct hif_ie_tlv { - u8 type; - u8 length; - u8 data[]; + u8 type; + u8 length; + u8 data[]; } __packed; struct hif_req_update_ie { struct hif_ie_flags ie_flags; - u16 num_ies; + __le16 num_ies; struct hif_ie_tlv ie[]; } __packed; struct hif_cnf_update_ie { - u32 status; + __le32 status; } __packed; struct hif_scan_type { - u8 type:1; - u8 mode:1; - u8 reserved:6; + u8 type:1; + u8 mode:1; + u8 reserved:6; } __packed; struct hif_scan_flags { - u8 fbg:1; - u8 reserved1:1; - u8 pre:1; - u8 reserved2:5; + u8 fbg:1; + u8 reserved1:1; + u8 pre:1; + u8 reserved2:5; } __packed; struct hif_auto_scan_param { - u16 interval; - u8 reserved; + __le16 interval; + u8 reserved; s8 rssi_thr; } __packed; struct hif_ssid_def { - u32 ssid_length; - u8 ssid[HIF_API_SSID_SIZE]; + __le32 ssid_length; + u8 ssid[HIF_API_SSID_SIZE]; } __packed; #define HIF_API_MAX_NB_SSIDS 2 #define HIF_API_MAX_NB_CHANNELS 14 -struct hif_req_start_scan { - u8 band; - struct hif_scan_type scan_type; - struct hif_scan_flags scan_flags; - u8 max_transmit_rate; - struct hif_auto_scan_param auto_scan_param; - u8 num_of_probe_requests; - u8 probe_delay; - u8 num_of_ssids; - u8 num_of_channels; - u32 min_channel_time; - u32 max_channel_time; - s32 tx_power_level; - u8 ssid_and_channel_lists[]; -} __packed; - struct hif_req_start_scan_alt { - u8 band; + u8 band; struct hif_scan_type scan_type; struct hif_scan_flags scan_flags; - u8 max_transmit_rate; + u8 max_transmit_rate; struct hif_auto_scan_param auto_scan_param; - u8 num_of_probe_requests; - u8 probe_delay; - u8 num_of_ssids; - u8 num_of_channels; - u32 min_channel_time; - u32 max_channel_time; - s32 tx_power_level; + u8 num_of_probe_requests; + u8 probe_delay; + u8 num_of_ssids; + u8 num_of_channels; + __le32 min_channel_time; + __le32 max_channel_time; + __le32 tx_power_level; // signed value struct hif_ssid_def ssid_def[HIF_API_MAX_NB_SSIDS]; - u8 channel_list[]; + u8 channel_list[]; } __packed; struct hif_cnf_start_scan { - u32 status; + __le32 status; } __packed; struct hif_cnf_stop_scan { - u32 status; + __le32 status; } __packed; enum hif_pm_mode_status { @@ -216,10 +198,10 @@ enum hif_pm_mode_status { }; struct hif_ind_scan_cmpl { - u32 status; - u8 pm_mode; - u8 num_channels_completed; - u16 reserved; + __le32 status; + u8 pm_mode; + u8 num_channels_completed; + __le16 reserved; } __packed; enum hif_queue_id { @@ -241,46 +223,46 @@ enum hif_stbc { }; struct hif_queue { - u8 queue_id:2; - u8 peer_sta_id:4; - u8 reserved:2; + u8 queue_id:2; + u8 peer_sta_id:4; + u8 reserved:2; } __packed; struct hif_data_flags { - u8 more:1; - u8 fc_offset:3; - u8 after_dtim:1; - u8 reserved:3; + u8 more:1; + u8 fc_offset:3; + u8 after_dtim:1; + u8 reserved:3; } __packed; struct hif_tx_flags { - u8 start_exp:1; - u8 reserved:3; - u8 retry_policy_index:4; + u8 start_exp:1; + u8 reserved:3; + u8 retry_policy_index:4; } __packed; struct hif_ht_tx_parameters { - u8 frame_format:4; - u8 fec_coding:1; - u8 short_gi:1; - u8 reserved1:1; - u8 stbc:1; - u8 reserved2; - u8 aggregation:1; - u8 reserved3:7; - u8 reserved4; + u8 frame_format:4; + u8 fec_coding:1; + u8 short_gi:1; + u8 reserved1:1; + u8 stbc:1; + u8 reserved2; + u8 aggregation:1; + u8 reserved3:7; + u8 reserved4; } __packed; struct hif_req_tx { - u32 packet_id; - u8 max_tx_rate; + __le32 packet_id; + u8 max_tx_rate; struct hif_queue queue_id; struct hif_data_flags data_flags; struct hif_tx_flags tx_flags; - u32 reserved; - u32 expire_time; + __le32 reserved; + __le32 expire_time; struct hif_ht_tx_parameters ht_tx_parameters; - u8 frame[]; + u8 frame[]; } __packed; enum hif_qos_ackplcy { @@ -291,26 +273,26 @@ enum hif_qos_ackplcy { }; struct hif_tx_result_flags { - u8 aggr:1; - u8 requeue:1; - u8 ack_policy:2; - u8 txop_limit:1; - u8 reserved1:3; - u8 reserved2; + u8 aggr:1; + u8 requeue:1; + u8 ack_policy:2; + u8 txop_limit:1; + u8 reserved1:3; + u8 reserved2; } __packed; struct hif_cnf_tx { - u32 status; - u32 packet_id; - u8 txed_rate; - u8 ack_failures; + __le32 status; + __le32 packet_id; + u8 txed_rate; + u8 ack_failures; struct hif_tx_result_flags tx_result_flags; - u32 media_delay; - u32 tx_queue_delay; + __le32 media_delay; + __le32 tx_queue_delay; } __packed; struct hif_cnf_multi_transmit { - u32 num_tx_confs; + __le32 num_tx_confs; struct hif_cnf_tx tx_conf_payload[]; } __packed; @@ -323,147 +305,147 @@ enum hif_ri_flags_encrypt { }; struct hif_rx_flags { - u8 encryp:3; - u8 in_aggr:1; - u8 first_aggr:1; - u8 last_aggr:1; - u8 defrag:1; - u8 beacon:1; - u8 tim:1; - u8 bitmap:1; - u8 match_ssid:1; - u8 match_bssid:1; - u8 more:1; - u8 reserved1:1; - u8 ht:1; - u8 stbc:1; - u8 match_uc_addr:1; - u8 match_mc_addr:1; - u8 match_bc_addr:1; - u8 key_type:1; - u8 key_index:4; - u8 reserved2:1; - u8 peer_sta_id:4; - u8 reserved3:2; - u8 reserved4:1; + u8 encryp:3; + u8 in_aggr:1; + u8 first_aggr:1; + u8 last_aggr:1; + u8 defrag:1; + u8 beacon:1; + u8 tim:1; + u8 bitmap:1; + u8 match_ssid:1; + u8 match_bssid:1; + u8 more:1; + u8 reserved1:1; + u8 ht:1; + u8 stbc:1; + u8 match_uc_addr:1; + u8 match_mc_addr:1; + u8 match_bc_addr:1; + u8 key_type:1; + u8 key_index:4; + u8 reserved2:1; + u8 peer_sta_id:4; + u8 reserved3:2; + u8 reserved4:1; } __packed; struct hif_ind_rx { - u32 status; - u16 channel_number; - u8 rxed_rate; - u8 rcpi_rssi; + __le32 status; + __le16 channel_number; + u8 rxed_rate; + u8 rcpi_rssi; struct hif_rx_flags rx_flags; - u8 frame[]; + u8 frame[]; } __packed; struct hif_req_edca_queue_params { - u8 queue_id; - u8 reserved1; - u8 aifsn; - u8 reserved2; - u16 cw_min; - u16 cw_max; - u16 tx_op_limit; - u16 allowed_medium_time; - u32 reserved3; + u8 queue_id; + u8 reserved1; + u8 aifsn; + u8 reserved2; + __le16 cw_min; + __le16 cw_max; + __le16 tx_op_limit; + __le16 allowed_medium_time; + __le32 reserved3; } __packed; struct hif_cnf_edca_queue_params { - u32 status; + __le32 status; } __packed; struct hif_join_flags { - u8 reserved1:2; - u8 force_no_beacon:1; - u8 force_with_ind:1; - u8 reserved2:4; + u8 reserved1:2; + u8 force_no_beacon:1; + u8 force_with_ind:1; + u8 reserved2:4; } __packed; struct hif_req_join { - u8 infrastructure_bss_mode:1; - u8 reserved1:7; - u8 band; - u16 channel_number; - u8 bssid[ETH_ALEN]; - u16 atim_window; - u8 short_preamble:1; - u8 reserved2:7; - u8 probe_for_join; - u8 reserved3; + u8 infrastructure_bss_mode:1; + u8 reserved1:7; + u8 band; + __le16 channel_number; + u8 bssid[ETH_ALEN]; + __le16 atim_window; + u8 short_preamble:1; + u8 reserved2:7; + u8 probe_for_join; + u8 reserved3; struct hif_join_flags join_flags; - u32 ssid_length; - u8 ssid[HIF_API_SSID_SIZE]; - u32 beacon_interval; - u32 basic_rate_set; + __le32 ssid_length; + u8 ssid[HIF_API_SSID_SIZE]; + __le32 beacon_interval; + __le32 basic_rate_set; } __packed; struct hif_cnf_join { - u32 status; + __le32 status; } __packed; struct hif_ind_join_complete { - u32 status; + __le32 status; } __packed; struct hif_bss_flags { - u8 lost_count_only:1; - u8 reserved:7; + u8 lost_count_only:1; + u8 reserved:7; } __packed; struct hif_req_set_bss_params { struct hif_bss_flags bss_flags; - u8 beacon_lost_count; - u16 aid; - u32 operational_rate_set; + u8 beacon_lost_count; + __le16 aid; + __le32 operational_rate_set; } __packed; struct hif_cnf_set_bss_params { - u32 status; + __le32 status; } __packed; struct hif_pm_mode { - u8 enter_psm:1; - u8 reserved:6; - u8 fast_psm:1; + u8 enter_psm:1; + u8 reserved:6; + u8 fast_psm:1; } __packed; struct hif_req_set_pm_mode { struct hif_pm_mode pm_mode; - u8 fast_psm_idle_period; - u8 ap_psm_change_period; - u8 min_auto_ps_poll_period; + u8 fast_psm_idle_period; + u8 ap_psm_change_period; + u8 min_auto_ps_poll_period; } __packed; struct hif_cnf_set_pm_mode { - u32 status; + __le32 status; } __packed; struct hif_ind_set_pm_mode_cmpl { - u32 status; - u8 pm_mode; - u8 reserved[3]; + __le32 status; + u8 pm_mode; + u8 reserved[3]; } __packed; struct hif_req_start { - u8 mode; - u8 band; - u16 channel_number; - u32 reserved1; - u32 beacon_interval; - u8 dtim_period; - u8 short_preamble:1; - u8 reserved2:7; - u8 reserved3; - u8 ssid_length; - u8 ssid[HIF_API_SSID_SIZE]; - u32 basic_rate_set; + u8 mode; + u8 band; + __le16 channel_number; + __le32 reserved1; + __le32 beacon_interval; + u8 dtim_period; + u8 short_preamble:1; + u8 reserved2:7; + u8 reserved3; + u8 ssid_length; + u8 ssid[HIF_API_SSID_SIZE]; + __le32 basic_rate_set; } __packed; struct hif_cnf_start { - u32 status; + __le32 status; } __packed; enum hif_beacon { @@ -472,46 +454,49 @@ enum hif_beacon { }; struct hif_req_beacon_transmit { - u8 enable_beaconing; - u8 reserved[3]; + u8 enable_beaconing; + u8 reserved[3]; } __packed; struct hif_cnf_beacon_transmit { - u32 status; + __le32 status; } __packed; +#define HIF_LINK_ID_MAX 14 +#define HIF_LINK_ID_NOT_ASSOCIATED (HIF_LINK_ID_MAX + 1) + enum hif_sta_map_direction { HIF_STA_MAP = 0x0, HIF_STA_UNMAP = 0x1 }; struct hif_map_link_flags { - u8 map_direction:1; - u8 mfpc:1; - u8 reserved:6; + u8 map_direction:1; + u8 mfpc:1; + u8 reserved:6; } __packed; struct hif_req_map_link { - u8 mac_addr[ETH_ALEN]; + u8 mac_addr[ETH_ALEN]; struct hif_map_link_flags map_link_flags; - u8 peer_sta_id; + u8 peer_sta_id; } __packed; struct hif_cnf_map_link { - u32 status; + __le32 status; } __packed; struct hif_suspend_resume_flags { - u8 resume:1; - u8 reserved1:2; - u8 bc_mc_only:1; - u8 reserved2:4; - u8 reserved3; + u8 resume:1; + u8 reserved1:2; + u8 bc_mc_only:1; + u8 reserved2:4; + u8 reserved3; } __packed; struct hif_ind_suspend_resume_tx { struct hif_suspend_resume_flags suspend_resume_flags; - u16 peer_sta_set; + __le16 peer_sta_set; } __packed; @@ -541,102 +526,102 @@ enum hif_key_type { }; struct hif_wep_pairwise_key { - u8 peer_address[ETH_ALEN]; - u8 reserved; - u8 key_length; - u8 key_data[HIF_API_WEP_KEY_DATA_SIZE]; + u8 peer_address[ETH_ALEN]; + u8 reserved; + u8 key_length; + u8 key_data[HIF_API_WEP_KEY_DATA_SIZE]; } __packed; struct hif_wep_group_key { - u8 key_id; - u8 key_length; - u8 reserved[2]; - u8 key_data[HIF_API_WEP_KEY_DATA_SIZE]; + u8 key_id; + u8 key_length; + u8 reserved[2]; + u8 key_data[HIF_API_WEP_KEY_DATA_SIZE]; } __packed; struct hif_tkip_pairwise_key { - u8 peer_address[ETH_ALEN]; - u8 reserved[2]; - u8 tkip_key_data[HIF_API_TKIP_KEY_DATA_SIZE]; - u8 rx_mic_key[HIF_API_RX_MIC_KEY_SIZE]; - u8 tx_mic_key[HIF_API_TX_MIC_KEY_SIZE]; + u8 peer_address[ETH_ALEN]; + u8 reserved[2]; + u8 tkip_key_data[HIF_API_TKIP_KEY_DATA_SIZE]; + u8 rx_mic_key[HIF_API_RX_MIC_KEY_SIZE]; + u8 tx_mic_key[HIF_API_TX_MIC_KEY_SIZE]; } __packed; struct hif_tkip_group_key { - u8 tkip_key_data[HIF_API_TKIP_KEY_DATA_SIZE]; - u8 rx_mic_key[HIF_API_RX_MIC_KEY_SIZE]; - u8 key_id; - u8 reserved[3]; - u8 rx_sequence_counter[HIF_API_RX_SEQUENCE_COUNTER_SIZE]; + u8 tkip_key_data[HIF_API_TKIP_KEY_DATA_SIZE]; + u8 rx_mic_key[HIF_API_RX_MIC_KEY_SIZE]; + u8 key_id; + u8 reserved[3]; + u8 rx_sequence_counter[HIF_API_RX_SEQUENCE_COUNTER_SIZE]; } __packed; struct hif_aes_pairwise_key { - u8 peer_address[ETH_ALEN]; - u8 reserved[2]; - u8 aes_key_data[HIF_API_AES_KEY_DATA_SIZE]; + u8 peer_address[ETH_ALEN]; + u8 reserved[2]; + u8 aes_key_data[HIF_API_AES_KEY_DATA_SIZE]; } __packed; struct hif_aes_group_key { - u8 aes_key_data[HIF_API_AES_KEY_DATA_SIZE]; - u8 key_id; - u8 reserved[3]; - u8 rx_sequence_counter[HIF_API_RX_SEQUENCE_COUNTER_SIZE]; + u8 aes_key_data[HIF_API_AES_KEY_DATA_SIZE]; + u8 key_id; + u8 reserved[3]; + u8 rx_sequence_counter[HIF_API_RX_SEQUENCE_COUNTER_SIZE]; } __packed; struct hif_wapi_pairwise_key { - u8 peer_address[ETH_ALEN]; - u8 key_id; - u8 reserved; - u8 wapi_key_data[HIF_API_WAPI_KEY_DATA_SIZE]; - u8 mic_key_data[HIF_API_MIC_KEY_DATA_SIZE]; + u8 peer_address[ETH_ALEN]; + u8 key_id; + u8 reserved; + u8 wapi_key_data[HIF_API_WAPI_KEY_DATA_SIZE]; + u8 mic_key_data[HIF_API_MIC_KEY_DATA_SIZE]; } __packed; struct hif_wapi_group_key { - u8 wapi_key_data[HIF_API_WAPI_KEY_DATA_SIZE]; - u8 mic_key_data[HIF_API_MIC_KEY_DATA_SIZE]; - u8 key_id; - u8 reserved[3]; + u8 wapi_key_data[HIF_API_WAPI_KEY_DATA_SIZE]; + u8 mic_key_data[HIF_API_MIC_KEY_DATA_SIZE]; + u8 key_id; + u8 reserved[3]; } __packed; struct hif_igtk_group_key { - u8 igtk_key_data[HIF_API_IGTK_KEY_DATA_SIZE]; - u8 key_id; - u8 reserved[3]; - u8 ipn[HIF_API_IPN_SIZE]; + u8 igtk_key_data[HIF_API_IGTK_KEY_DATA_SIZE]; + u8 key_id; + u8 reserved[3]; + u8 ipn[HIF_API_IPN_SIZE]; } __packed; union hif_privacy_key_data { - struct hif_wep_pairwise_key wep_pairwise_key; - struct hif_wep_group_key wep_group_key; - struct hif_tkip_pairwise_key tkip_pairwise_key; - struct hif_tkip_group_key tkip_group_key; - struct hif_aes_pairwise_key aes_pairwise_key; - struct hif_aes_group_key aes_group_key; - struct hif_wapi_pairwise_key wapi_pairwise_key; - struct hif_wapi_group_key wapi_group_key; - struct hif_igtk_group_key igtk_group_key; + struct hif_wep_pairwise_key wep_pairwise_key; + struct hif_wep_group_key wep_group_key; + struct hif_tkip_pairwise_key tkip_pairwise_key; + struct hif_tkip_group_key tkip_group_key; + struct hif_aes_pairwise_key aes_pairwise_key; + struct hif_aes_group_key aes_group_key; + struct hif_wapi_pairwise_key wapi_pairwise_key; + struct hif_wapi_group_key wapi_group_key; + struct hif_igtk_group_key igtk_group_key; }; struct hif_req_add_key { - u8 type; - u8 entry_index; - u8 int_id:2; - u8 reserved1:6; - u8 reserved2; + u8 type; + u8 entry_index; + u8 int_id:2; + u8 reserved1:6; + u8 reserved2; union hif_privacy_key_data key; } __packed; struct hif_cnf_add_key { - u32 status; + __le32 status; } __packed; struct hif_req_remove_key { - u8 entry_index; - u8 reserved[3]; + u8 entry_index; + u8 reserved[3]; } __packed; struct hif_cnf_remove_key { - u32 status; + __le32 status; } __packed; enum hif_event_ind { @@ -656,13 +641,13 @@ enum hif_ps_mode_error { }; union hif_event_data { - u8 rcpi_rssi; - u32 ps_mode_error; - u32 peer_sta_set; + u8 rcpi_rssi; + __le32 ps_mode_error; + __le32 peer_sta_set; }; struct hif_ind_event { - u32 event_id; + __le32 event_id; union hif_event_data event_data; } __packed; diff --git a/drivers/staging/wfx/hif_api_general.h b/drivers/staging/wfx/hif_api_general.h index a069c3a21b4d..275354eb6b6a 100644 --- a/drivers/staging/wfx/hif_api_general.h +++ b/drivers/staging/wfx/hif_api_general.h @@ -17,13 +17,13 @@ #define __packed __attribute__((__packed__)) #endif -#define API_SSID_SIZE 32 +#define API_SSID_SIZE 32 -#define HIF_ID_IS_INDICATION 0x80 -#define HIF_COUNTER_MAX 7 +#define HIF_ID_IS_INDICATION 0x80 +#define HIF_COUNTER_MAX 7 struct hif_msg { - u16 len; + __le16 len; u8 id; u8 reserved:1; u8 interface:2; @@ -33,38 +33,38 @@ struct hif_msg { } __packed; enum hif_general_requests_ids { - HIF_REQ_ID_CONFIGURATION = 0x09, - HIF_REQ_ID_CONTROL_GPIO = 0x26, - HIF_REQ_ID_SET_SL_MAC_KEY = 0x27, - HIF_REQ_ID_SL_EXCHANGE_PUB_KEYS = 0x28, - HIF_REQ_ID_SL_CONFIGURE = 0x29, - HIF_REQ_ID_PREVENT_ROLLBACK = 0x2a, - HIF_REQ_ID_PTA_SETTINGS = 0x2b, - HIF_REQ_ID_PTA_PRIORITY = 0x2c, - HIF_REQ_ID_PTA_STATE = 0x2d, - HIF_REQ_ID_SHUT_DOWN = 0x32, + HIF_REQ_ID_CONFIGURATION = 0x09, + HIF_REQ_ID_CONTROL_GPIO = 0x26, + HIF_REQ_ID_SET_SL_MAC_KEY = 0x27, + HIF_REQ_ID_SL_EXCHANGE_PUB_KEYS = 0x28, + HIF_REQ_ID_SL_CONFIGURE = 0x29, + HIF_REQ_ID_PREVENT_ROLLBACK = 0x2a, + HIF_REQ_ID_PTA_SETTINGS = 0x2b, + HIF_REQ_ID_PTA_PRIORITY = 0x2c, + HIF_REQ_ID_PTA_STATE = 0x2d, + HIF_REQ_ID_SHUT_DOWN = 0x32, }; enum hif_general_confirmations_ids { - HIF_CNF_ID_CONFIGURATION = 0x09, - HIF_CNF_ID_CONTROL_GPIO = 0x26, - HIF_CNF_ID_SET_SL_MAC_KEY = 0x27, - HIF_CNF_ID_SL_EXCHANGE_PUB_KEYS = 0x28, - HIF_CNF_ID_SL_CONFIGURE = 0x29, - HIF_CNF_ID_PREVENT_ROLLBACK = 0x2a, - HIF_CNF_ID_PTA_SETTINGS = 0x2b, - HIF_CNF_ID_PTA_PRIORITY = 0x2c, - HIF_CNF_ID_PTA_STATE = 0x2d, - HIF_CNF_ID_SHUT_DOWN = 0x32, + HIF_CNF_ID_CONFIGURATION = 0x09, + HIF_CNF_ID_CONTROL_GPIO = 0x26, + HIF_CNF_ID_SET_SL_MAC_KEY = 0x27, + HIF_CNF_ID_SL_EXCHANGE_PUB_KEYS = 0x28, + HIF_CNF_ID_SL_CONFIGURE = 0x29, + HIF_CNF_ID_PREVENT_ROLLBACK = 0x2a, + HIF_CNF_ID_PTA_SETTINGS = 0x2b, + HIF_CNF_ID_PTA_PRIORITY = 0x2c, + HIF_CNF_ID_PTA_STATE = 0x2d, + HIF_CNF_ID_SHUT_DOWN = 0x32, }; enum hif_general_indications_ids { - HIF_IND_ID_EXCEPTION = 0xe0, - HIF_IND_ID_STARTUP = 0xe1, - HIF_IND_ID_WAKEUP = 0xe2, - HIF_IND_ID_GENERIC = 0xe3, - HIF_IND_ID_ERROR = 0xe4, - HIF_IND_ID_SL_EXCHANGE_PUB_KEYS = 0xe5 + HIF_IND_ID_EXCEPTION = 0xe0, + HIF_IND_ID_STARTUP = 0xe1, + HIF_IND_ID_WAKEUP = 0xe2, + HIF_IND_ID_GENERIC = 0xe3, + HIF_IND_ID_ERROR = 0xe4, + HIF_IND_ID_SL_EXCHANGE_PUB_KEYS = 0xe5 }; enum hif_hi_status { @@ -84,188 +84,175 @@ enum hif_hi_status { }; enum hif_api_rate_index { - API_RATE_INDEX_B_1MBPS = 0, - API_RATE_INDEX_B_2MBPS = 1, - API_RATE_INDEX_B_5P5MBPS = 2, - API_RATE_INDEX_B_11MBPS = 3, - API_RATE_INDEX_PBCC_22MBPS = 4, - API_RATE_INDEX_PBCC_33MBPS = 5, - API_RATE_INDEX_G_6MBPS = 6, - API_RATE_INDEX_G_9MBPS = 7, - API_RATE_INDEX_G_12MBPS = 8, - API_RATE_INDEX_G_18MBPS = 9, - API_RATE_INDEX_G_24MBPS = 10, - API_RATE_INDEX_G_36MBPS = 11, - API_RATE_INDEX_G_48MBPS = 12, - API_RATE_INDEX_G_54MBPS = 13, - API_RATE_INDEX_N_6P5MBPS = 14, - API_RATE_INDEX_N_13MBPS = 15, - API_RATE_INDEX_N_19P5MBPS = 16, - API_RATE_INDEX_N_26MBPS = 17, - API_RATE_INDEX_N_39MBPS = 18, - API_RATE_INDEX_N_52MBPS = 19, - API_RATE_INDEX_N_58P5MBPS = 20, - API_RATE_INDEX_N_65MBPS = 21, - API_RATE_NUM_ENTRIES = 22 + API_RATE_INDEX_B_1MBPS = 0, + API_RATE_INDEX_B_2MBPS = 1, + API_RATE_INDEX_B_5P5MBPS = 2, + API_RATE_INDEX_B_11MBPS = 3, + API_RATE_INDEX_PBCC_22MBPS = 4, + API_RATE_INDEX_PBCC_33MBPS = 5, + API_RATE_INDEX_G_6MBPS = 6, + API_RATE_INDEX_G_9MBPS = 7, + API_RATE_INDEX_G_12MBPS = 8, + API_RATE_INDEX_G_18MBPS = 9, + API_RATE_INDEX_G_24MBPS = 10, + API_RATE_INDEX_G_36MBPS = 11, + API_RATE_INDEX_G_48MBPS = 12, + API_RATE_INDEX_G_54MBPS = 13, + API_RATE_INDEX_N_6P5MBPS = 14, + API_RATE_INDEX_N_13MBPS = 15, + API_RATE_INDEX_N_19P5MBPS = 16, + API_RATE_INDEX_N_26MBPS = 17, + API_RATE_INDEX_N_39MBPS = 18, + API_RATE_INDEX_N_52MBPS = 19, + API_RATE_INDEX_N_58P5MBPS = 20, + API_RATE_INDEX_N_65MBPS = 21, + API_RATE_NUM_ENTRIES = 22 }; enum hif_fw_type { - HIF_FW_TYPE_ETF = 0x0, - HIF_FW_TYPE_WFM = 0x1, - HIF_FW_TYPE_WSM = 0x2 + HIF_FW_TYPE_ETF = 0x0, + HIF_FW_TYPE_WFM = 0x1, + HIF_FW_TYPE_WSM = 0x2 }; struct hif_capabilities { - u8 link_mode:2; - u8 reserved1:6; - u8 reserved2; - u8 reserved3; - u8 reserved4; + u8 link_mode:2; + u8 reserved1:6; + u8 reserved2; + u8 reserved3; + u8 reserved4; } __packed; struct hif_otp_regul_sel_mode_info { - u8 region_sel_mode:4; - u8 reserved:4; + u8 region_sel_mode:4; + u8 reserved:4; } __packed; struct hif_otp_phy_info { - u8 phy1_region:3; - u8 phy0_region:3; - u8 otp_phy_ver:2; + u8 phy1_region:3; + u8 phy0_region:3; + u8 otp_phy_ver:2; } __packed; -#define API_OPN_SIZE 14 -#define API_UID_SIZE 8 -#define API_DISABLED_CHANNEL_LIST_SIZE 2 -#define API_FIRMWARE_LABEL_SIZE 128 - struct hif_ind_startup { - u32 status; - u16 hardware_id; - u8 opn[API_OPN_SIZE]; - u8 uid[API_UID_SIZE]; - u16 num_inp_ch_bufs; - u16 size_inp_ch_buf; - u8 num_links_ap; - u8 num_interfaces; - u8 mac_addr[2][ETH_ALEN]; - u8 api_version_minor; - u8 api_version_major; + __le32 status; + __le16 hardware_id; + u8 opn[14]; + u8 uid[8]; + __le16 num_inp_ch_bufs; + __le16 size_inp_ch_buf; + u8 num_links_ap; + u8 num_interfaces; + u8 mac_addr[2][ETH_ALEN]; + u8 api_version_minor; + u8 api_version_major; struct hif_capabilities capabilities; - u8 firmware_build; - u8 firmware_minor; - u8 firmware_major; - u8 firmware_type; - u8 disabled_channel_list[API_DISABLED_CHANNEL_LIST_SIZE]; + u8 firmware_build; + u8 firmware_minor; + u8 firmware_major; + u8 firmware_type; + u8 disabled_channel_list[2]; struct hif_otp_regul_sel_mode_info regul_sel_mode_info; struct hif_otp_phy_info otp_phy_info; - u32 supported_rate_mask; - u8 firmware_label[API_FIRMWARE_LABEL_SIZE]; + __le32 supported_rate_mask; + u8 firmware_label[128]; } __packed; struct hif_ind_wakeup { } __packed; struct hif_req_configuration { - u16 length; - u8 pds_data[]; + __le16 length; + u8 pds_data[]; } __packed; struct hif_cnf_configuration { - u32 status; + __le32 status; } __packed; enum hif_gpio_mode { - HIF_GPIO_MODE_D0 = 0x0, - HIF_GPIO_MODE_D1 = 0x1, - HIF_GPIO_MODE_OD0 = 0x2, - HIF_GPIO_MODE_OD1 = 0x3, - HIF_GPIO_MODE_TRISTATE = 0x4, - HIF_GPIO_MODE_TOGGLE = 0x5, - HIF_GPIO_MODE_READ = 0x6 + HIF_GPIO_MODE_D0 = 0x0, + HIF_GPIO_MODE_D1 = 0x1, + HIF_GPIO_MODE_OD0 = 0x2, + HIF_GPIO_MODE_OD1 = 0x3, + HIF_GPIO_MODE_TRISTATE = 0x4, + HIF_GPIO_MODE_TOGGLE = 0x5, + HIF_GPIO_MODE_READ = 0x6 }; struct hif_req_control_gpio { - u8 gpio_label; - u8 gpio_mode; + u8 gpio_label; + u8 gpio_mode; } __packed; -enum hif_gpio_error { - HIF_GPIO_ERROR_0 = 0x0, - HIF_GPIO_ERROR_1 = 0x1, - HIF_GPIO_ERROR_2 = 0x2 -}; - struct hif_cnf_control_gpio { - u32 status; - u32 value; + __le32 status; + __le32 value; } __packed; enum hif_generic_indication_type { - HIF_GENERIC_INDICATION_TYPE_RAW = 0x0, - HIF_GENERIC_INDICATION_TYPE_STRING = 0x1, - HIF_GENERIC_INDICATION_TYPE_RX_STATS = 0x2 + HIF_GENERIC_INDICATION_TYPE_RAW = 0x0, + HIF_GENERIC_INDICATION_TYPE_STRING = 0x1, + HIF_GENERIC_INDICATION_TYPE_RX_STATS = 0x2 }; struct hif_rx_stats { - u32 nb_rx_frame; - u32 nb_crc_frame; - u32 per_total; - u32 throughput; - u32 nb_rx_by_rate[API_RATE_NUM_ENTRIES]; - u16 per[API_RATE_NUM_ENTRIES]; - s16 snr[API_RATE_NUM_ENTRIES]; - s16 rssi[API_RATE_NUM_ENTRIES]; - s16 cfo[API_RATE_NUM_ENTRIES]; - u32 date; - u32 pwr_clk_freq; - u8 is_ext_pwr_clk; + __le32 nb_rx_frame; + __le32 nb_crc_frame; + __le32 per_total; + __le32 throughput; + __le32 nb_rx_by_rate[API_RATE_NUM_ENTRIES]; + __le16 per[API_RATE_NUM_ENTRIES]; + __le16 snr[API_RATE_NUM_ENTRIES]; // signed value + __le16 rssi[API_RATE_NUM_ENTRIES]; // signed value + __le16 cfo[API_RATE_NUM_ENTRIES]; // signed value + __le32 date; + __le32 pwr_clk_freq; + u8 is_ext_pwr_clk; s8 current_temp; } __packed; union hif_indication_data { - struct hif_rx_stats rx_stats; - u8 raw_data[1]; + struct hif_rx_stats rx_stats; + u8 raw_data[1]; }; struct hif_ind_generic { - u32 indication_type; + __le32 indication_type; union hif_indication_data indication_data; } __packed; -#define HIF_EXCEPTION_DATA_SIZE 124 - struct hif_ind_exception { - u8 data[HIF_EXCEPTION_DATA_SIZE]; + u8 data[124]; } __packed; enum hif_error { - HIF_ERROR_FIRMWARE_ROLLBACK = 0x0, - HIF_ERROR_FIRMWARE_DEBUG_ENABLED = 0x1, - HIF_ERROR_OUTDATED_SESSION_KEY = 0x2, - HIF_ERROR_INVALID_SESSION_KEY = 0x3, - HIF_ERROR_OOR_VOLTAGE = 0x4, - HIF_ERROR_PDS_VERSION = 0x5, - HIF_ERROR_OOR_TEMPERATURE = 0x6, - HIF_ERROR_REQ_DURING_KEY_EXCHANGE = 0x7, - HIF_ERROR_MULTI_TX_CNF_SECURELINK = 0x8, - HIF_ERROR_SECURELINK_OVERFLOW = 0x9, - HIF_ERROR_SECURELINK_DECRYPTION = 0xa + HIF_ERROR_FIRMWARE_ROLLBACK = 0x0, + HIF_ERROR_FIRMWARE_DEBUG_ENABLED = 0x1, + HIF_ERROR_OUTDATED_SESSION_KEY = 0x2, + HIF_ERROR_INVALID_SESSION_KEY = 0x3, + HIF_ERROR_OOR_VOLTAGE = 0x4, + HIF_ERROR_PDS_VERSION = 0x5, + HIF_ERROR_OOR_TEMPERATURE = 0x6, + HIF_ERROR_REQ_DURING_KEY_EXCHANGE = 0x7, + HIF_ERROR_MULTI_TX_CNF_SECURELINK = 0x8, + HIF_ERROR_SECURELINK_OVERFLOW = 0x9, + HIF_ERROR_SECURELINK_DECRYPTION = 0xa }; struct hif_ind_error { - u32 type; - u8 data[]; + __le32 type; + u8 data[]; } __packed; enum hif_secure_link_state { - SEC_LINK_UNAVAILABLE = 0x0, - SEC_LINK_RESERVED = 0x1, - SEC_LINK_EVAL = 0x2, - SEC_LINK_ENFORCED = 0x3 + SEC_LINK_UNAVAILABLE = 0x0, + SEC_LINK_RESERVED = 0x1, + SEC_LINK_EVAL = 0x2, + SEC_LINK_ENFORCED = 0x3 }; enum hif_sl_encryption_type { @@ -282,156 +269,70 @@ struct hif_sl_msg_hdr { struct hif_sl_msg { struct hif_sl_msg_hdr hdr; - u16 len; - u8 payload[]; + __le16 len; + u8 payload[]; } __packed; -#define AES_CCM_TAG_SIZE 16 +#define AES_CCM_TAG_SIZE 16 struct hif_sl_tag { - u8 tag[16]; + u8 tag[16]; } __packed; enum hif_sl_mac_key_dest { - SL_MAC_KEY_DEST_OTP = 0x78, - SL_MAC_KEY_DEST_RAM = 0x87 + SL_MAC_KEY_DEST_OTP = 0x78, + SL_MAC_KEY_DEST_RAM = 0x87 }; -#define API_KEY_VALUE_SIZE 32 +#define API_KEY_VALUE_SIZE 32 struct hif_req_set_sl_mac_key { - u8 otp_or_ram; - u8 key_value[API_KEY_VALUE_SIZE]; + u8 otp_or_ram; + u8 key_value[API_KEY_VALUE_SIZE]; } __packed; struct hif_cnf_set_sl_mac_key { - u32 status; + __le32 status; } __packed; -#define API_HOST_PUB_KEY_SIZE 32 -#define API_HOST_PUB_KEY_MAC_SIZE 64 - enum hif_sl_session_key_alg { - HIF_SL_CURVE25519 = 0x01, - HIF_SL_KDF = 0x02 + HIF_SL_CURVE25519 = 0x01, + HIF_SL_KDF = 0x02 }; +#define API_HOST_PUB_KEY_SIZE 32 +#define API_HOST_PUB_KEY_MAC_SIZE 64 + struct hif_req_sl_exchange_pub_keys { - u8 algorithm:2; - u8 reserved1:6; - u8 reserved2[3]; - u8 host_pub_key[API_HOST_PUB_KEY_SIZE]; - u8 host_pub_key_mac[API_HOST_PUB_KEY_MAC_SIZE]; + u8 algorithm:2; + u8 reserved1:6; + u8 reserved2[3]; + u8 host_pub_key[API_HOST_PUB_KEY_SIZE]; + u8 host_pub_key_mac[API_HOST_PUB_KEY_MAC_SIZE]; } __packed; struct hif_cnf_sl_exchange_pub_keys { - u32 status; + __le32 status; } __packed; -#define API_NCP_PUB_KEY_SIZE 32 -#define API_NCP_PUB_KEY_MAC_SIZE 64 +#define API_NCP_PUB_KEY_SIZE 32 +#define API_NCP_PUB_KEY_MAC_SIZE 64 struct hif_ind_sl_exchange_pub_keys { - u32 status; - u8 ncp_pub_key[API_NCP_PUB_KEY_SIZE]; - u8 ncp_pub_key_mac[API_NCP_PUB_KEY_MAC_SIZE]; + __le32 status; + u8 ncp_pub_key[API_NCP_PUB_KEY_SIZE]; + u8 ncp_pub_key_mac[API_NCP_PUB_KEY_MAC_SIZE]; } __packed; -#define API_ENCR_BMP_SIZE 32 - struct hif_req_sl_configure { - u8 encr_bmp[API_ENCR_BMP_SIZE]; - u8 disable_session_key_protection:1; - u8 reserved1:7; - u8 reserved2[3]; + u8 encr_bmp[32]; + u8 disable_session_key_protection:1; + u8 reserved1:7; + u8 reserved2[3]; } __packed; struct hif_cnf_sl_configure { - u32 status; -} __packed; - -struct hif_req_prevent_rollback { - u32 magic_word; -} __packed; - -struct hif_cnf_prevent_rollback { - u32 status; -} __packed; - -enum hif_pta_mode { - PTA_1W_WLAN_MASTER = 0, - PTA_1W_COEX_MASTER = 1, - PTA_2W = 2, - PTA_3W = 3, - PTA_4W = 4 -}; - -enum hif_signal_level { - SIGNAL_LOW = 0, - SIGNAL_HIGH = 1 -}; - -enum hif_coex_type { - COEX_TYPE_GENERIC = 0, - COEX_TYPE_BLE = 1 -}; - -enum hif_grant_state { - NO_GRANT = 0, - GRANT = 1 -}; - -struct hif_req_pta_settings { - u8 pta_mode; - u8 request_signal_active_level; - u8 priority_signal_active_level; - u8 freq_signal_active_level; - u8 grant_signal_active_level; - u8 coex_type; - u8 default_grant_state; - u8 simultaneous_rx_accesses; - u8 priority_sampling_time; - u8 tx_rx_sampling_time; - u8 freq_sampling_time; - u8 grant_valid_time; - u8 fem_control_time; - u8 first_slot_time; - u16 periodic_tx_rx_sampling_time; - u16 coex_quota; - u16 wlan_quota; -} __packed; - -struct hif_cnf_pta_settings { - u32 status; -} __packed; - -enum hif_pta_priority { - HIF_PTA_PRIORITY_COEX_MAXIMIZED = 0x00000562, - HIF_PTA_PRIORITY_COEX_HIGH = 0x00000462, - HIF_PTA_PRIORITY_BALANCED = 0x00001461, - HIF_PTA_PRIORITY_WLAN_HIGH = 0x00001851, - HIF_PTA_PRIORITY_WLAN_MAXIMIZED = 0x00001A51 -}; - -struct hif_req_pta_priority { - u32 priority; -} __packed; - -struct hif_cnf_pta_priority { - u32 status; -} __packed; - -enum hif_pta_state { - PTA_OFF = 0, - PTA_ON = 1 -}; - -struct hif_req_pta_state { - u32 pta_state; -} __packed; - -struct hif_cnf_pta_state { - u32 status; + __le32 status; } __packed; #endif diff --git a/drivers/staging/wfx/hif_api_mib.h b/drivers/staging/wfx/hif_api_mib.h index 0c67cd4c1593..6f1434795fa8 100644 --- a/drivers/staging/wfx/hif_api_mib.h +++ b/drivers/staging/wfx/hif_api_mib.h @@ -10,175 +10,88 @@ #include "hif_api_general.h" -#define HIF_API_IPV4_ADDRESS_SIZE 4 -#define HIF_API_IPV6_ADDRESS_SIZE 16 +#define HIF_API_IPV4_ADDRESS_SIZE 4 +#define HIF_API_IPV6_ADDRESS_SIZE 16 enum hif_mib_ids { - HIF_MIB_ID_GL_OPERATIONAL_POWER_MODE = 0x2000, - HIF_MIB_ID_GL_BLOCK_ACK_INFO = 0x2001, - HIF_MIB_ID_GL_SET_MULTI_MSG = 0x2002, - HIF_MIB_ID_CCA_CONFIG = 0x2003, - HIF_MIB_ID_ETHERTYPE_DATAFRAME_CONDITION = 0x2010, - HIF_MIB_ID_PORT_DATAFRAME_CONDITION = 0x2011, - HIF_MIB_ID_MAGIC_DATAFRAME_CONDITION = 0x2012, - HIF_MIB_ID_MAC_ADDR_DATAFRAME_CONDITION = 0x2013, - HIF_MIB_ID_IPV4_ADDR_DATAFRAME_CONDITION = 0x2014, - HIF_MIB_ID_IPV6_ADDR_DATAFRAME_CONDITION = 0x2015, - HIF_MIB_ID_UC_MC_BC_DATAFRAME_CONDITION = 0x2016, - HIF_MIB_ID_CONFIG_DATA_FILTER = 0x2017, - HIF_MIB_ID_SET_DATA_FILTERING = 0x2018, - HIF_MIB_ID_ARP_IP_ADDRESSES_TABLE = 0x2019, - HIF_MIB_ID_NS_IP_ADDRESSES_TABLE = 0x201A, - HIF_MIB_ID_RX_FILTER = 0x201B, - HIF_MIB_ID_BEACON_FILTER_TABLE = 0x201C, - HIF_MIB_ID_BEACON_FILTER_ENABLE = 0x201D, - HIF_MIB_ID_GRP_SEQ_COUNTER = 0x2030, - HIF_MIB_ID_TSF_COUNTER = 0x2031, - HIF_MIB_ID_STATISTICS_TABLE = 0x2032, - HIF_MIB_ID_COUNTERS_TABLE = 0x2033, - HIF_MIB_ID_MAX_TX_POWER_LEVEL = 0x2034, - HIF_MIB_ID_EXTENDED_COUNTERS_TABLE = 0x2035, - HIF_MIB_ID_DOT11_MAC_ADDRESS = 0x2040, + HIF_MIB_ID_GL_OPERATIONAL_POWER_MODE = 0x2000, + HIF_MIB_ID_GL_BLOCK_ACK_INFO = 0x2001, + HIF_MIB_ID_GL_SET_MULTI_MSG = 0x2002, + HIF_MIB_ID_CCA_CONFIG = 0x2003, + HIF_MIB_ID_ETHERTYPE_DATAFRAME_CONDITION = 0x2010, + HIF_MIB_ID_PORT_DATAFRAME_CONDITION = 0x2011, + HIF_MIB_ID_MAGIC_DATAFRAME_CONDITION = 0x2012, + HIF_MIB_ID_MAC_ADDR_DATAFRAME_CONDITION = 0x2013, + HIF_MIB_ID_IPV4_ADDR_DATAFRAME_CONDITION = 0x2014, + HIF_MIB_ID_IPV6_ADDR_DATAFRAME_CONDITION = 0x2015, + HIF_MIB_ID_UC_MC_BC_DATAFRAME_CONDITION = 0x2016, + HIF_MIB_ID_CONFIG_DATA_FILTER = 0x2017, + HIF_MIB_ID_SET_DATA_FILTERING = 0x2018, + HIF_MIB_ID_ARP_IP_ADDRESSES_TABLE = 0x2019, + HIF_MIB_ID_NS_IP_ADDRESSES_TABLE = 0x201A, + HIF_MIB_ID_RX_FILTER = 0x201B, + HIF_MIB_ID_BEACON_FILTER_TABLE = 0x201C, + HIF_MIB_ID_BEACON_FILTER_ENABLE = 0x201D, + HIF_MIB_ID_GRP_SEQ_COUNTER = 0x2030, + HIF_MIB_ID_TSF_COUNTER = 0x2031, + HIF_MIB_ID_STATISTICS_TABLE = 0x2032, + HIF_MIB_ID_COUNTERS_TABLE = 0x2033, + HIF_MIB_ID_MAX_TX_POWER_LEVEL = 0x2034, + HIF_MIB_ID_EXTENDED_COUNTERS_TABLE = 0x2035, + HIF_MIB_ID_DOT11_MAC_ADDRESS = 0x2040, HIF_MIB_ID_DOT11_MAX_TRANSMIT_MSDU_LIFETIME = 0x2041, - HIF_MIB_ID_DOT11_MAX_RECEIVE_LIFETIME = 0x2042, - HIF_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID = 0x2043, - HIF_MIB_ID_DOT11_RTS_THRESHOLD = 0x2044, - HIF_MIB_ID_SLOT_TIME = 0x2045, - HIF_MIB_ID_CURRENT_TX_POWER_LEVEL = 0x2046, - HIF_MIB_ID_NON_ERP_PROTECTION = 0x2047, - HIF_MIB_ID_TEMPLATE_FRAME = 0x2048, - HIF_MIB_ID_BEACON_WAKEUP_PERIOD = 0x2049, - HIF_MIB_ID_RCPI_RSSI_THRESHOLD = 0x204A, - HIF_MIB_ID_BLOCK_ACK_POLICY = 0x204B, - HIF_MIB_ID_OVERRIDE_INTERNAL_TX_RATE = 0x204C, - HIF_MIB_ID_SET_ASSOCIATION_MODE = 0x204D, - HIF_MIB_ID_SET_UAPSD_INFORMATION = 0x204E, - HIF_MIB_ID_SET_TX_RATE_RETRY_POLICY = 0x204F, - HIF_MIB_ID_PROTECTED_MGMT_POLICY = 0x2050, - HIF_MIB_ID_SET_HT_PROTECTION = 0x2051, - HIF_MIB_ID_KEEP_ALIVE_PERIOD = 0x2052, - HIF_MIB_ID_ARP_KEEP_ALIVE_PERIOD = 0x2053, - HIF_MIB_ID_INACTIVITY_TIMER = 0x2054, - HIF_MIB_ID_INTERFACE_PROTECTION = 0x2055, - HIF_MIB_ID_BEACON_STATS = 0x2056, + HIF_MIB_ID_DOT11_MAX_RECEIVE_LIFETIME = 0x2042, + HIF_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID = 0x2043, + HIF_MIB_ID_DOT11_RTS_THRESHOLD = 0x2044, + HIF_MIB_ID_SLOT_TIME = 0x2045, + HIF_MIB_ID_CURRENT_TX_POWER_LEVEL = 0x2046, + HIF_MIB_ID_NON_ERP_PROTECTION = 0x2047, + HIF_MIB_ID_TEMPLATE_FRAME = 0x2048, + HIF_MIB_ID_BEACON_WAKEUP_PERIOD = 0x2049, + HIF_MIB_ID_RCPI_RSSI_THRESHOLD = 0x204A, + HIF_MIB_ID_BLOCK_ACK_POLICY = 0x204B, + HIF_MIB_ID_OVERRIDE_INTERNAL_TX_RATE = 0x204C, + HIF_MIB_ID_SET_ASSOCIATION_MODE = 0x204D, + HIF_MIB_ID_SET_UAPSD_INFORMATION = 0x204E, + HIF_MIB_ID_SET_TX_RATE_RETRY_POLICY = 0x204F, + HIF_MIB_ID_PROTECTED_MGMT_POLICY = 0x2050, + HIF_MIB_ID_SET_HT_PROTECTION = 0x2051, + HIF_MIB_ID_KEEP_ALIVE_PERIOD = 0x2052, + HIF_MIB_ID_ARP_KEEP_ALIVE_PERIOD = 0x2053, + HIF_MIB_ID_INACTIVITY_TIMER = 0x2054, + HIF_MIB_ID_INTERFACE_PROTECTION = 0x2055, + HIF_MIB_ID_BEACON_STATS = 0x2056, }; -#define HIF_OP_POWER_MODE_MASK 0xf - enum hif_op_power_mode { - HIF_OP_POWER_MODE_ACTIVE = 0x0, - HIF_OP_POWER_MODE_DOZE = 0x1, - HIF_OP_POWER_MODE_QUIESCENT = 0x2 + HIF_OP_POWER_MODE_ACTIVE = 0x0, + HIF_OP_POWER_MODE_DOZE = 0x1, + HIF_OP_POWER_MODE_QUIESCENT = 0x2 }; struct hif_mib_gl_operational_power_mode { - u8 power_mode:4; - u8 reserved1:3; - u8 wup_ind_activation:1; - u8 reserved2[3]; -} __packed; - -struct hif_mib_gl_block_ack_info { - u8 rx_buffer_size; - u8 rx_max_num_agreements; - u8 tx_buffer_size; - u8 tx_max_num_agreements; + u8 power_mode:4; + u8 reserved1:3; + u8 wup_ind_activation:1; + u8 reserved2[3]; } __packed; struct hif_mib_gl_set_multi_msg { - u8 enable_multi_tx_conf:1; - u8 reserved1:7; - u8 reserved2[3]; -} __packed; - -enum hif_cca_thr_mode { - HIF_CCA_THR_MODE_RELATIVE = 0x0, - HIF_CCA_THR_MODE_ABSOLUTE = 0x1 -}; - -struct hif_mib_gl_cca_config { - u8 cca_thr_mode; - u8 reserved[3]; -} __packed; - -#define MAX_NUMBER_DATA_FILTERS 0xA - -#define MAX_NUMBER_IPV4_ADDR_CONDITIONS 0x4 -#define MAX_NUMBER_IPV6_ADDR_CONDITIONS 0x4 -#define MAX_NUMBER_MAC_ADDR_CONDITIONS 0x4 -#define MAX_NUMBER_UC_MC_BC_CONDITIONS 0x4 -#define MAX_NUMBER_ETHER_TYPE_CONDITIONS 0x4 -#define MAX_NUMBER_PORT_CONDITIONS 0x4 -#define MAX_NUMBER_MAGIC_CONDITIONS 0x4 -#define MAX_NUMBER_ARP_CONDITIONS 0x2 -#define MAX_NUMBER_NS_CONDITIONS 0x2 - -struct hif_mib_ethertype_data_frame_condition { - u8 condition_idx; - u8 reserved; - u16 ether_type; -} __packed; - -enum hif_udp_tcp_protocol { - HIF_PROTOCOL_UDP = 0x0, - HIF_PROTOCOL_TCP = 0x1, - HIF_PROTOCOL_BOTH_UDP_TCP = 0x2 -}; - -enum hif_which_port { - HIF_PORT_DST = 0x0, - HIF_PORT_SRC = 0x1, - HIF_PORT_SRC_OR_DST = 0x2 -}; - -struct hif_mib_ports_data_frame_condition { - u8 condition_idx; - u8 protocol; - u8 which_port; - u8 reserved1; - u16 port_number; - u8 reserved2[2]; -} __packed; - -#define HIF_API_MAGIC_PATTERN_SIZE 32 - -struct hif_mib_magic_data_frame_condition { - u8 condition_idx; - u8 offset; - u8 magic_pattern_length; - u8 reserved; - u8 magic_pattern[HIF_API_MAGIC_PATTERN_SIZE]; + u8 enable_multi_tx_conf:1; + u8 reserved1:7; + u8 reserved2[3]; } __packed; enum hif_mac_addr_type { - HIF_MAC_ADDR_A1 = 0x0, - HIF_MAC_ADDR_A2 = 0x1, - HIF_MAC_ADDR_A3 = 0x2 + HIF_MAC_ADDR_A1 = 0x0, + HIF_MAC_ADDR_A2 = 0x1, + HIF_MAC_ADDR_A3 = 0x2 }; struct hif_mib_mac_addr_data_frame_condition { - u8 condition_idx; - u8 address_type; - u8 mac_address[ETH_ALEN]; -} __packed; - -enum hif_ip_addr_mode { - HIF_IP_ADDR_SRC = 0x0, - HIF_IP_ADDR_DST = 0x1 -}; - -struct hif_mib_ipv4_addr_data_frame_condition { - u8 condition_idx; - u8 address_mode; - u8 reserved[2]; - u8 i_pv4_address[HIF_API_IPV4_ADDRESS_SIZE]; -} __packed; - -struct hif_mib_ipv6_addr_data_frame_condition { - u8 condition_idx; - u8 address_mode; - u8 reserved[2]; - u8 i_pv6_address[HIF_API_IPV6_ADDRESS_SIZE]; + u8 condition_idx; + u8 address_type; + u8 mac_address[ETH_ALEN]; } __packed; #define HIF_FILTER_UNICAST 0x1 @@ -186,365 +99,289 @@ struct hif_mib_ipv6_addr_data_frame_condition { #define HIF_FILTER_BROADCAST 0x4 struct hif_mib_uc_mc_bc_data_frame_condition { - u8 condition_idx; - u8 allowed_frames; - u8 reserved[2]; + u8 condition_idx; + u8 allowed_frames; + u8 reserved[2]; } __packed; struct hif_mib_config_data_filter { - u8 filter_idx; - u8 enable; - u8 reserved1[2]; - u8 eth_type_cond; - u8 port_cond; - u8 magic_cond; - u8 mac_cond; - u8 ipv4_cond; - u8 ipv6_cond; - u8 uc_mc_bc_cond; - u8 reserved2; + u8 filter_idx; + u8 enable; + u8 reserved1[2]; + u8 eth_type_cond; + u8 port_cond; + u8 magic_cond; + u8 mac_cond; + u8 ipv4_cond; + u8 ipv6_cond; + u8 uc_mc_bc_cond; + u8 reserved2; } __packed; struct hif_mib_set_data_filtering { - u8 invert_matching:1; - u8 reserved1:7; - u8 enable:1; - u8 reserved2:7; - u8 reserved3[2]; + u8 invert_matching:1; + u8 reserved1:7; + u8 enable:1; + u8 reserved2:7; + u8 reserved3[2]; } __packed; enum hif_arp_ns_frame_treatment { - HIF_ARP_NS_FILTERING_DISABLE = 0x0, - HIF_ARP_NS_FILTERING_ENABLE = 0x1, - HIF_ARP_NS_REPLY_ENABLE = 0x2 + HIF_ARP_NS_FILTERING_DISABLE = 0x0, + HIF_ARP_NS_FILTERING_ENABLE = 0x1, + HIF_ARP_NS_REPLY_ENABLE = 0x2 }; struct hif_mib_arp_ip_addr_table { - u8 condition_idx; - u8 arp_enable; - u8 reserved[2]; - u8 ipv4_address[HIF_API_IPV4_ADDRESS_SIZE]; -} __packed; - -struct hif_mib_ns_ip_addr_table { - u8 condition_idx; - u8 ns_enable; - u8 reserved[2]; - u8 ipv6_address[HIF_API_IPV6_ADDRESS_SIZE]; + u8 condition_idx; + u8 arp_enable; + u8 reserved[2]; + u8 ipv4_address[HIF_API_IPV4_ADDRESS_SIZE]; } __packed; struct hif_mib_rx_filter { - u8 reserved1:1; - u8 bssid_filter:1; - u8 reserved2:1; - u8 fwd_probe_req:1; - u8 keep_alive_filter:1; - u8 reserved3:3; - u8 reserved4[3]; + u8 reserved1:1; + u8 bssid_filter:1; + u8 reserved2:1; + u8 fwd_probe_req:1; + u8 keep_alive_filter:1; + u8 reserved3:3; + u8 reserved4[3]; } __packed; -#define HIF_API_OUI_SIZE 3 -#define HIF_API_MATCH_DATA_SIZE 3 - struct hif_ie_table_entry { - u8 ie_id; - u8 has_changed:1; - u8 no_longer:1; - u8 has_appeared:1; - u8 reserved:1; - u8 num_match_data:4; - u8 oui[HIF_API_OUI_SIZE]; - u8 match_data[HIF_API_MATCH_DATA_SIZE]; + u8 ie_id; + u8 has_changed:1; + u8 no_longer:1; + u8 has_appeared:1; + u8 reserved:1; + u8 num_match_data:4; + u8 oui[3]; + u8 match_data[3]; } __packed; struct hif_mib_bcn_filter_table { - u32 num_of_info_elmts; + __le32 num_of_info_elmts; struct hif_ie_table_entry ie_table[]; } __packed; enum hif_beacon_filter { - HIF_BEACON_FILTER_DISABLE = 0x0, - HIF_BEACON_FILTER_ENABLE = 0x1, - HIF_BEACON_FILTER_AUTO_ERP = 0x2 + HIF_BEACON_FILTER_DISABLE = 0x0, + HIF_BEACON_FILTER_ENABLE = 0x1, + HIF_BEACON_FILTER_AUTO_ERP = 0x2 }; struct hif_mib_bcn_filter_enable { - u32 enable; - u32 bcn_count; -} __packed; - -struct hif_mib_group_seq_counter { - u32 bits4716; - u16 bits1500; - u16 reserved; -} __packed; - -struct hif_mib_tsf_counter { - u32 tsf_counterlo; - u32 tsf_counterhi; -} __packed; - -struct hif_mib_stats_table { - s16 latest_snr; - u8 latest_rcpi; - s8 latest_rssi; + __le32 enable; + __le32 bcn_count; } __packed; struct hif_mib_extended_count_table { - u32 count_plcp_errors; - u32 count_fcs_errors; - u32 count_tx_packets; - u32 count_rx_packets; - u32 count_rx_packet_errors; - u32 count_rx_decryption_failures; - u32 count_rx_mic_failures; - u32 count_rx_no_key_failures; - u32 count_tx_multicast_frames; - u32 count_tx_frames_success; - u32 count_tx_frame_failures; - u32 count_tx_frames_retried; - u32 count_tx_frames_multi_retried; - u32 count_rx_frame_duplicates; - u32 count_rts_success; - u32 count_rts_failures; - u32 count_ack_failures; - u32 count_rx_multicast_frames; - u32 count_rx_frames_success; - u32 count_rx_cmacicv_errors; - u32 count_rx_cmac_replays; - u32 count_rx_mgmt_ccmp_replays; - u32 count_rx_bipmic_errors; - u32 count_rx_beacon; - u32 count_miss_beacon; - u32 reserved[15]; + __le32 count_plcp_errors; + __le32 count_fcs_errors; + __le32 count_tx_packets; + __le32 count_rx_packets; + __le32 count_rx_packet_errors; + __le32 count_rx_decryption_failures; + __le32 count_rx_mic_failures; + __le32 count_rx_no_key_failures; + __le32 count_tx_multicast_frames; + __le32 count_tx_frames_success; + __le32 count_tx_frame_failures; + __le32 count_tx_frames_retried; + __le32 count_tx_frames_multi_retried; + __le32 count_rx_frame_duplicates; + __le32 count_rts_success; + __le32 count_rts_failures; + __le32 count_ack_failures; + __le32 count_rx_multicast_frames; + __le32 count_rx_frames_success; + __le32 count_rx_cmacicv_errors; + __le32 count_rx_cmac_replays; + __le32 count_rx_mgmt_ccmp_replays; + __le32 count_rx_bipmic_errors; + __le32 count_rx_beacon; + __le32 count_miss_beacon; + __le32 reserved[15]; } __packed; struct hif_mib_count_table { - u32 count_plcp_errors; - u32 count_fcs_errors; - u32 count_tx_packets; - u32 count_rx_packets; - u32 count_rx_packet_errors; - u32 count_rx_decryption_failures; - u32 count_rx_mic_failures; - u32 count_rx_no_key_failures; - u32 count_tx_multicast_frames; - u32 count_tx_frames_success; - u32 count_tx_frame_failures; - u32 count_tx_frames_retried; - u32 count_tx_frames_multi_retried; - u32 count_rx_frame_duplicates; - u32 count_rts_success; - u32 count_rts_failures; - u32 count_ack_failures; - u32 count_rx_multicast_frames; - u32 count_rx_frames_success; - u32 count_rx_cmacicv_errors; - u32 count_rx_cmac_replays; - u32 count_rx_mgmt_ccmp_replays; - u32 count_rx_bipmic_errors; -} __packed; - -struct hif_mib_max_tx_power_level { - s32 max_tx_power_level_rf_port1; - s32 max_tx_power_level_rf_port2; -} __packed; - -struct hif_mib_beacon_stats { - s32 latest_tbtt_diff; - u32 reserved[4]; + __le32 count_plcp_errors; + __le32 count_fcs_errors; + __le32 count_tx_packets; + __le32 count_rx_packets; + __le32 count_rx_packet_errors; + __le32 count_rx_decryption_failures; + __le32 count_rx_mic_failures; + __le32 count_rx_no_key_failures; + __le32 count_tx_multicast_frames; + __le32 count_tx_frames_success; + __le32 count_tx_frame_failures; + __le32 count_tx_frames_retried; + __le32 count_tx_frames_multi_retried; + __le32 count_rx_frame_duplicates; + __le32 count_rts_success; + __le32 count_rts_failures; + __le32 count_ack_failures; + __le32 count_rx_multicast_frames; + __le32 count_rx_frames_success; + __le32 count_rx_cmacicv_errors; + __le32 count_rx_cmac_replays; + __le32 count_rx_mgmt_ccmp_replays; + __le32 count_rx_bipmic_errors; } __packed; struct hif_mib_mac_address { - u8 mac_addr[ETH_ALEN]; - u16 reserved; -} __packed; - -struct hif_mib_dot11_max_transmit_msdu_lifetime { - u32 max_life_time; -} __packed; - -struct hif_mib_dot11_max_receive_lifetime { - u32 max_life_time; + u8 mac_addr[ETH_ALEN]; + __le16 reserved; } __packed; struct hif_mib_wep_default_key_id { - u8 wep_default_key_id; - u8 reserved[3]; + u8 wep_default_key_id; + u8 reserved[3]; } __packed; struct hif_mib_dot11_rts_threshold { - u32 threshold; + __le32 threshold; } __packed; struct hif_mib_slot_time { - u32 slot_time; + __le32 slot_time; } __packed; struct hif_mib_current_tx_power_level { - s32 power_level; + __le32 power_level; // signed value } __packed; struct hif_mib_non_erp_protection { - u8 use_cts_to_self:1; - u8 reserved1:7; - u8 reserved2[3]; + u8 use_cts_to_self:1; + u8 reserved1:7; + u8 reserved2[3]; } __packed; enum hif_tmplt { - HIF_TMPLT_PRBREQ = 0x0, - HIF_TMPLT_BCN = 0x1, - HIF_TMPLT_NULL = 0x2, - HIF_TMPLT_QOSNUL = 0x3, - HIF_TMPLT_PSPOLL = 0x4, - HIF_TMPLT_PRBRES = 0x5, - HIF_TMPLT_ARP = 0x6, - HIF_TMPLT_NA = 0x7 + HIF_TMPLT_PRBREQ = 0x0, + HIF_TMPLT_BCN = 0x1, + HIF_TMPLT_NULL = 0x2, + HIF_TMPLT_QOSNUL = 0x3, + HIF_TMPLT_PSPOLL = 0x4, + HIF_TMPLT_PRBRES = 0x5, + HIF_TMPLT_ARP = 0x6, + HIF_TMPLT_NA = 0x7 }; -#define HIF_API_MAX_TEMPLATE_FRAME_SIZE 700 +#define HIF_API_MAX_TEMPLATE_FRAME_SIZE 700 struct hif_mib_template_frame { - u8 frame_type; - u8 init_rate:7; - u8 mode:1; - u16 frame_length; - u8 frame[HIF_API_MAX_TEMPLATE_FRAME_SIZE]; + u8 frame_type; + u8 init_rate:7; + u8 mode:1; + __le16 frame_length; + u8 frame[]; } __packed; struct hif_mib_beacon_wake_up_period { - u8 wakeup_period_min; - u8 receive_dtim:1; - u8 reserved1:7; - u8 wakeup_period_max; - u8 reserved2; + u8 wakeup_period_min; + u8 receive_dtim:1; + u8 reserved1:7; + u8 wakeup_period_max; + u8 reserved2; } __packed; struct hif_mib_rcpi_rssi_threshold { - u8 detection:1; - u8 rcpi_rssi:1; - u8 upperthresh:1; - u8 lowerthresh:1; - u8 reserved:4; - u8 lower_threshold; - u8 upper_threshold; - u8 rolling_average_count; + u8 detection:1; + u8 rcpi_rssi:1; + u8 upperthresh:1; + u8 lowerthresh:1; + u8 reserved:4; + u8 lower_threshold; + u8 upper_threshold; + u8 rolling_average_count; } __packed; #define DEFAULT_BA_MAX_RX_BUFFER_SIZE 16 struct hif_mib_block_ack_policy { - u8 block_ack_tx_tid_policy; - u8 reserved1; - u8 block_ack_rx_tid_policy; - u8 block_ack_rx_max_buffer_size; -} __packed; - -struct hif_mib_override_int_rate { - u8 internal_tx_rate; - u8 non_erp_internal_tx_rate; - u8 reserved[2]; + u8 block_ack_tx_tid_policy; + u8 reserved1; + u8 block_ack_rx_tid_policy; + u8 block_ack_rx_max_buffer_size; } __packed; enum hif_mpdu_start_spacing { - HIF_MPDU_START_SPACING_NO_RESTRIC = 0x0, - HIF_MPDU_START_SPACING_QUARTER = 0x1, - HIF_MPDU_START_SPACING_HALF = 0x2, - HIF_MPDU_START_SPACING_ONE = 0x3, - HIF_MPDU_START_SPACING_TWO = 0x4, - HIF_MPDU_START_SPACING_FOUR = 0x5, - HIF_MPDU_START_SPACING_EIGHT = 0x6, - HIF_MPDU_START_SPACING_SIXTEEN = 0x7 + HIF_MPDU_START_SPACING_NO_RESTRIC = 0x0, + HIF_MPDU_START_SPACING_QUARTER = 0x1, + HIF_MPDU_START_SPACING_HALF = 0x2, + HIF_MPDU_START_SPACING_ONE = 0x3, + HIF_MPDU_START_SPACING_TWO = 0x4, + HIF_MPDU_START_SPACING_FOUR = 0x5, + HIF_MPDU_START_SPACING_EIGHT = 0x6, + HIF_MPDU_START_SPACING_SIXTEEN = 0x7 }; struct hif_mib_set_association_mode { - u8 preambtype_use:1; - u8 mode:1; - u8 rateset:1; - u8 spacing:1; - u8 reserved1:4; - u8 short_preamble:1; - u8 reserved2:7; - u8 greenfield:1; - u8 reserved3:7; - u8 mpdu_start_spacing; - u32 basic_rate_set; + u8 preambtype_use:1; + u8 mode:1; + u8 rateset:1; + u8 spacing:1; + u8 reserved1:4; + u8 short_preamble:1; + u8 reserved2:7; + u8 greenfield:1; + u8 reserved3:7; + u8 mpdu_start_spacing; + __le32 basic_rate_set; } __packed; struct hif_mib_set_uapsd_information { - u8 trig_bckgrnd:1; - u8 trig_be:1; - u8 trig_video:1; - u8 trig_voice:1; - u8 reserved1:4; - u8 deliv_bckgrnd:1; - u8 deliv_be:1; - u8 deliv_video:1; - u8 deliv_voice:1; - u8 reserved2:4; - u16 min_auto_trigger_interval; - u16 max_auto_trigger_interval; - u16 auto_trigger_step; + u8 trig_bckgrnd:1; + u8 trig_be:1; + u8 trig_video:1; + u8 trig_voice:1; + u8 reserved1:4; + u8 deliv_bckgrnd:1; + u8 deliv_be:1; + u8 deliv_video:1; + u8 deliv_voice:1; + u8 reserved2:4; + __le16 min_auto_trigger_interval; + __le16 max_auto_trigger_interval; + __le16 auto_trigger_step; } __packed; struct hif_mib_tx_rate_retry_policy { - u8 policy_index; - u8 short_retry_count; - u8 long_retry_count; - u8 first_rate_sel:2; - u8 terminate:1; - u8 count_init:1; - u8 reserved1:4; - u8 rate_recovery_count; - u8 reserved2[3]; - u8 rates[12]; + u8 policy_index; + u8 short_retry_count; + u8 long_retry_count; + u8 first_rate_sel:2; + u8 terminate:1; + u8 count_init:1; + u8 reserved1:4; + u8 rate_recovery_count; + u8 reserved2[3]; + u8 rates[12]; } __packed; -#define HIF_MIB_NUM_TX_RATE_RETRY_POLICIES 15 +#define HIF_TX_RETRY_POLICY_MAX 15 +#define HIF_TX_RETRY_POLICY_INVALID HIF_TX_RETRY_POLICY_MAX struct hif_mib_set_tx_rate_retry_policy { - u8 num_tx_rate_policies; - u8 reserved[3]; + u8 num_tx_rate_policies; + u8 reserved[3]; struct hif_mib_tx_rate_retry_policy tx_rate_retry_policy[]; } __packed; struct hif_mib_protected_mgmt_policy { - u8 pmf_enable:1; - u8 unpmf_allowed:1; - u8 host_enc_auth_frames:1; - u8 reserved1:5; - u8 reserved2[3]; -} __packed; - -struct hif_mib_set_ht_protection { - u8 dual_cts_prot:1; - u8 reserved1:7; - u8 reserved2[3]; + u8 pmf_enable:1; + u8 unpmf_allowed:1; + u8 host_enc_auth_frames:1; + u8 reserved1:5; + u8 reserved2[3]; } __packed; struct hif_mib_keep_alive_period { - u16 keep_alive_period; - u8 reserved[2]; -} __packed; - -struct hif_mib_arp_keep_alive_period { - u16 arp_keep_alive_period; - u8 encr_type; - u8 reserved; - u8 sender_ipv4_address[HIF_API_IPV4_ADDRESS_SIZE]; - u8 target_ipv4_address[HIF_API_IPV4_ADDRESS_SIZE]; -} __packed; - -struct hif_mib_inactivity_timer { - u8 min_active_time; - u8 max_active_time; - u16 reserved; -} __packed; - -struct hif_mib_interface_protection { - u8 use_cts_prot:1; - u8 reserved1:7; - u8 reserved2[3]; + __le16 keep_alive_period; + u8 reserved[2]; } __packed; #endif diff --git a/drivers/staging/wfx/hif_rx.c b/drivers/staging/wfx/hif_rx.c index 33c22c5d629d..b8d570256498 100644 --- a/drivers/staging/wfx/hif_rx.c +++ b/drivers/staging/wfx/hif_rx.c @@ -158,26 +158,31 @@ static int hif_event_indication(struct wfx_dev *wdev, { struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface); const struct hif_ind_event *body = buf; - struct wfx_hif_event *event; - int first; - WARN_ON(!wvif); - if (!wvif) + if (!wvif) { + dev_warn(wdev->dev, "received event for non-existent vif\n"); return 0; + } - event = kzalloc(sizeof(*event), GFP_KERNEL); - if (!event) - return -ENOMEM; - - memcpy(&event->evt, body, sizeof(struct hif_ind_event)); - spin_lock(&wvif->event_queue_lock); - first = list_empty(&wvif->event_queue); - list_add_tail(&event->link, &wvif->event_queue); - spin_unlock(&wvif->event_queue_lock); - - if (first) - schedule_work(&wvif->event_handler_work); - + switch (body->event_id) { + case HIF_EVENT_IND_RCPI_RSSI: + wfx_event_report_rssi(wvif, body->event_data.rcpi_rssi); + break; + case HIF_EVENT_IND_BSSLOST: + schedule_delayed_work(&wvif->beacon_loss_work, 0); + break; + case HIF_EVENT_IND_BSSREGAINED: + cancel_delayed_work(&wvif->beacon_loss_work); + dev_dbg(wdev->dev, "ignore BSSREGAINED indication\n"); + break; + case HIF_EVENT_IND_PS_MODE_ERROR: + dev_warn(wdev->dev, "error while processing power save request\n"); + break; + default: + dev_warn(wdev->dev, "unhandled event indication: %.2x\n", + body->event_id); + break; + } return 0; } diff --git a/drivers/staging/wfx/hif_tx.c b/drivers/staging/wfx/hif_tx.c index 77bca43aca42..17721cf9e2a3 100644 --- a/drivers/staging/wfx/hif_tx.c +++ b/drivers/staging/wfx/hif_tx.c @@ -296,7 +296,10 @@ int hif_join(struct wfx_vif *wvif, const struct ieee80211_bss_conf *conf, struct hif_msg *hif; struct hif_req_join *body = wfx_alloc_hif(sizeof(*body), &hif); + WARN_ON(!conf->beacon_int); WARN_ON(!conf->basic_rates); + WARN_ON(sizeof(body->ssid) < ssidlen); + WARN(!conf->ibss_joined && !ssidlen, "joining an unknown BSS"); body->infrastructure_bss_mode = !conf->ibss_joined; body->short_preamble = conf->use_short_preamble; if (channel && channel->flags & IEEE80211_CHAN_NO_IR) @@ -308,7 +311,7 @@ int hif_join(struct wfx_vif *wvif, const struct ieee80211_bss_conf *conf, body->basic_rate_set = cpu_to_le32(wfx_rate_mask_to_hw(wvif->wdev, conf->basic_rates)); memcpy(body->bssid, conf->bssid, sizeof(body->bssid)); - if (!conf->ibss_joined && ssid) { + if (ssid) { body->ssid_length = cpu_to_le32(ssidlen); memcpy(body->ssid, ssid, ssidlen); } @@ -318,17 +321,15 @@ int hif_join(struct wfx_vif *wvif, const struct ieee80211_bss_conf *conf, return ret; } -int hif_set_bss_params(struct wfx_vif *wvif, - const struct hif_req_set_bss_params *arg) +int hif_set_bss_params(struct wfx_vif *wvif, int aid, int beacon_lost_count) { int ret; struct hif_msg *hif; - struct hif_req_set_bss_params *body = wfx_alloc_hif(sizeof(*body), - &hif); + struct hif_req_set_bss_params *body = + wfx_alloc_hif(sizeof(*body), &hif); - memcpy(body, arg, sizeof(*body)); - cpu_to_le16s(&body->aid); - cpu_to_le32s(&body->operational_rate_set); + body->aid = cpu_to_le16(aid); + body->beacon_lost_count = beacon_lost_count; wfx_fill_header(hif, wvif->id, HIF_REQ_ID_SET_BSS_PARAMS, sizeof(*body)); ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false); @@ -428,6 +429,7 @@ int hif_start(struct wfx_vif *wvif, const struct ieee80211_bss_conf *conf, struct hif_msg *hif; struct hif_req_start *body = wfx_alloc_hif(sizeof(*body), &hif); + WARN_ON(!conf->beacon_int); body->dtim_period = conf->dtim_period; body->short_preamble = conf->use_short_preamble; body->channel_number = cpu_to_le16(channel->hw_value); diff --git a/drivers/staging/wfx/hif_tx.h b/drivers/staging/wfx/hif_tx.h index f8520a14c14c..038ea54e2574 100644 --- a/drivers/staging/wfx/hif_tx.h +++ b/drivers/staging/wfx/hif_tx.h @@ -48,8 +48,7 @@ int hif_stop_scan(struct wfx_vif *wvif); int hif_join(struct wfx_vif *wvif, const struct ieee80211_bss_conf *conf, struct ieee80211_channel *channel, const u8 *ssid, int ssidlen); int hif_set_pm(struct wfx_vif *wvif, bool ps, int dynamic_ps_timeout); -int hif_set_bss_params(struct wfx_vif *wvif, - const struct hif_req_set_bss_params *arg); +int hif_set_bss_params(struct wfx_vif *wvif, int aid, int beacon_lost_count); int hif_add_key(struct wfx_dev *wdev, const struct hif_req_add_key *arg); int hif_remove_key(struct wfx_dev *wdev, int idx); int hif_set_edca_queue_params(struct wfx_vif *wvif, u16 queue, diff --git a/drivers/staging/wfx/hif_tx_mib.c b/drivers/staging/wfx/hif_tx_mib.c new file mode 100644 index 000000000000..16f4908055af --- /dev/null +++ b/drivers/staging/wfx/hif_tx_mib.c @@ -0,0 +1,384 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Implementation of host-to-chip MIBs of WFxxx Split Mac (WSM) API. + * + * Copyright (c) 2017-2019, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + * Copyright (C) 2010, ST-Ericsson SA + */ + +#include <linux/etherdevice.h> + +#include "wfx.h" +#include "hif_tx.h" +#include "hif_tx_mib.h" +#include "hif_api_mib.h" + +int hif_set_output_power(struct wfx_vif *wvif, int val) +{ + struct hif_mib_current_tx_power_level arg = { + .power_level = cpu_to_le32(val * 10), + }; + + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_CURRENT_TX_POWER_LEVEL, + &arg, sizeof(arg)); +} + +int hif_set_beacon_wakeup_period(struct wfx_vif *wvif, + unsigned int dtim_interval, + unsigned int listen_interval) +{ + struct hif_mib_beacon_wake_up_period val = { + .wakeup_period_min = dtim_interval, + .receive_dtim = 0, + .wakeup_period_max = cpu_to_le16(listen_interval), + }; + + if (dtim_interval > 0xFF || listen_interval > 0xFFFF) + return -EINVAL; + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_BEACON_WAKEUP_PERIOD, + &val, sizeof(val)); +} + +int hif_set_rcpi_rssi_threshold(struct wfx_vif *wvif, + int rssi_thold, int rssi_hyst) +{ + struct hif_mib_rcpi_rssi_threshold arg = { + .rolling_average_count = 8, + .detection = 1, + }; + + if (!rssi_thold && !rssi_hyst) { + arg.upperthresh = 1; + arg.lowerthresh = 1; + } else { + arg.upper_threshold = rssi_thold + rssi_hyst; + arg.upper_threshold = (arg.upper_threshold + 110) * 2; + arg.lower_threshold = rssi_thold; + arg.lower_threshold = (arg.lower_threshold + 110) * 2; + } + + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_RCPI_RSSI_THRESHOLD, &arg, sizeof(arg)); +} + +int hif_get_counters_table(struct wfx_dev *wdev, + struct hif_mib_extended_count_table *arg) +{ + if (wfx_api_older_than(wdev, 1, 3)) { + // extended_count_table is wider than count_table + memset(arg, 0xFF, sizeof(*arg)); + return hif_read_mib(wdev, 0, HIF_MIB_ID_COUNTERS_TABLE, + arg, sizeof(struct hif_mib_count_table)); + } else { + return hif_read_mib(wdev, 0, + HIF_MIB_ID_EXTENDED_COUNTERS_TABLE, arg, + sizeof(struct hif_mib_extended_count_table)); + } +} + +int hif_set_macaddr(struct wfx_vif *wvif, u8 *mac) +{ + struct hif_mib_mac_address msg = { }; + + if (mac) + ether_addr_copy(msg.mac_addr, mac); + return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_DOT11_MAC_ADDRESS, + &msg, sizeof(msg)); +} + +int hif_set_rx_filter(struct wfx_vif *wvif, + bool filter_bssid, bool filter_prbreq) +{ + struct hif_mib_rx_filter val = { }; + + if (filter_bssid) + val.bssid_filter = 1; + if (!filter_prbreq) + val.fwd_probe_req = 1; + return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_RX_FILTER, + &val, sizeof(val)); +} + +int hif_set_beacon_filter_table(struct wfx_vif *wvif, int tbl_len, + const struct hif_ie_table_entry *tbl) +{ + int ret; + struct hif_mib_bcn_filter_table *val; + int buf_len = struct_size(val, ie_table, tbl_len); + + val = kzalloc(buf_len, GFP_KERNEL); + if (!val) + return -ENOMEM; + val->num_of_info_elmts = cpu_to_le32(tbl_len); + memcpy(val->ie_table, tbl, tbl_len * sizeof(*tbl)); + ret = hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_BEACON_FILTER_TABLE, val, buf_len); + kfree(val); + return ret; +} + +int hif_beacon_filter_control(struct wfx_vif *wvif, + int enable, int beacon_count) +{ + struct hif_mib_bcn_filter_enable arg = { + .enable = cpu_to_le32(enable), + .bcn_count = cpu_to_le32(beacon_count), + }; + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_BEACON_FILTER_ENABLE, + &arg, sizeof(arg)); +} + +int hif_set_operational_mode(struct wfx_dev *wdev, enum hif_op_power_mode mode) +{ + struct hif_mib_gl_operational_power_mode val = { + .power_mode = mode, + .wup_ind_activation = 1, + }; + + return hif_write_mib(wdev, -1, HIF_MIB_ID_GL_OPERATIONAL_POWER_MODE, + &val, sizeof(val)); +} + +int hif_set_template_frame(struct wfx_vif *wvif, struct sk_buff *skb, + u8 frame_type, int init_rate) +{ + struct hif_mib_template_frame *arg; + + WARN(skb->len > HIF_API_MAX_TEMPLATE_FRAME_SIZE, "frame is too big"); + skb_push(skb, 4); + arg = (struct hif_mib_template_frame *)skb->data; + skb_pull(skb, 4); + arg->init_rate = init_rate; + arg->frame_type = frame_type; + arg->frame_length = cpu_to_le16(skb->len); + return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_TEMPLATE_FRAME, + arg, sizeof(*arg) + skb->len); +} + +int hif_set_mfp(struct wfx_vif *wvif, bool capable, bool required) +{ + struct hif_mib_protected_mgmt_policy val = { }; + + WARN(required && !capable, "incoherent arguments"); + if (capable) { + val.pmf_enable = 1; + val.host_enc_auth_frames = 1; + } + if (!required) + val.unpmf_allowed = 1; + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_PROTECTED_MGMT_POLICY, + &val, sizeof(val)); +} + +int hif_set_block_ack_policy(struct wfx_vif *wvif, + u8 tx_tid_policy, u8 rx_tid_policy) +{ + struct hif_mib_block_ack_policy val = { + .block_ack_tx_tid_policy = tx_tid_policy, + .block_ack_rx_tid_policy = rx_tid_policy, + }; + + return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_BLOCK_ACK_POLICY, + &val, sizeof(val)); +} + +int hif_set_association_mode(struct wfx_vif *wvif, + struct ieee80211_bss_conf *info) +{ + struct ieee80211_sta *sta = NULL; + struct hif_mib_set_association_mode val = { + .preambtype_use = 1, + .mode = 1, + .spacing = 1, + .short_preamble = info->use_short_preamble, + }; + + rcu_read_lock(); // protect sta + if (info->bssid && !info->ibss_joined) + sta = ieee80211_find_sta(wvif->vif, info->bssid); + + // FIXME: it is strange to not retrieve all information from bss_info + if (sta && sta->ht_cap.ht_supported) { + val.mpdu_start_spacing = sta->ht_cap.ampdu_density; + if (!(info->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT)) + val.greenfield = !!(sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD); + } + rcu_read_unlock(); + + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_SET_ASSOCIATION_MODE, &val, sizeof(val)); +} + +int hif_set_tx_rate_retry_policy(struct wfx_vif *wvif, + int policy_index, uint8_t *rates) +{ + struct hif_mib_set_tx_rate_retry_policy *arg; + size_t size = struct_size(arg, tx_rate_retry_policy, 1); + int ret; + + arg = kzalloc(size, GFP_KERNEL); + arg->num_tx_rate_policies = 1; + arg->tx_rate_retry_policy[0].policy_index = policy_index; + arg->tx_rate_retry_policy[0].short_retry_count = 255; + arg->tx_rate_retry_policy[0].long_retry_count = 255; + arg->tx_rate_retry_policy[0].first_rate_sel = 1; + arg->tx_rate_retry_policy[0].terminate = 1; + arg->tx_rate_retry_policy[0].count_init = 1; + memcpy(&arg->tx_rate_retry_policy[0].rates, rates, + sizeof(arg->tx_rate_retry_policy[0].rates)); + ret = hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_SET_TX_RATE_RETRY_POLICY, arg, size); + kfree(arg); + return ret; +} + +int hif_set_mac_addr_condition(struct wfx_vif *wvif, + int idx, const u8 *mac_addr) +{ + struct hif_mib_mac_addr_data_frame_condition val = { + .condition_idx = idx, + .address_type = HIF_MAC_ADDR_A1, + }; + + ether_addr_copy(val.mac_address, mac_addr); + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_MAC_ADDR_DATAFRAME_CONDITION, + &val, sizeof(val)); +} + +int hif_set_uc_mc_bc_condition(struct wfx_vif *wvif, int idx, u8 allowed_frames) +{ + struct hif_mib_uc_mc_bc_data_frame_condition val = { + .condition_idx = idx, + .allowed_frames = allowed_frames, + }; + + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_UC_MC_BC_DATAFRAME_CONDITION, + &val, sizeof(val)); +} + +int hif_set_config_data_filter(struct wfx_vif *wvif, bool enable, int idx, + int mac_filters, int frames_types_filters) +{ + struct hif_mib_config_data_filter val = { + .enable = enable, + .filter_idx = idx, + .mac_cond = mac_filters, + .uc_mc_bc_cond = frames_types_filters, + }; + + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_CONFIG_DATA_FILTER, &val, sizeof(val)); +} + +int hif_set_data_filtering(struct wfx_vif *wvif, bool enable, bool invert) +{ + struct hif_mib_set_data_filtering val = { + .enable = enable, + .invert_matching = invert, + }; + + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_SET_DATA_FILTERING, &val, sizeof(val)); +} + +int hif_keep_alive_period(struct wfx_vif *wvif, int period) +{ + struct hif_mib_keep_alive_period arg = { + .keep_alive_period = cpu_to_le16(period), + }; + + return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_KEEP_ALIVE_PERIOD, + &arg, sizeof(arg)); +}; + +int hif_set_arp_ipv4_filter(struct wfx_vif *wvif, int idx, __be32 *addr) +{ + struct hif_mib_arp_ip_addr_table arg = { + .condition_idx = idx, + .arp_enable = HIF_ARP_NS_FILTERING_DISABLE, + }; + + if (addr) { + // Caution: type of addr is __be32 + memcpy(arg.ipv4_address, addr, sizeof(arg.ipv4_address)); + arg.arp_enable = HIF_ARP_NS_FILTERING_ENABLE; + } + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_ARP_IP_ADDRESSES_TABLE, + &arg, sizeof(arg)); +} + +int hif_use_multi_tx_conf(struct wfx_dev *wdev, bool enable) +{ + struct hif_mib_gl_set_multi_msg arg = { + .enable_multi_tx_conf = enable, + }; + + return hif_write_mib(wdev, -1, HIF_MIB_ID_GL_SET_MULTI_MSG, + &arg, sizeof(arg)); +} + +int hif_set_uapsd_info(struct wfx_vif *wvif, unsigned long val) +{ + struct hif_mib_set_uapsd_information arg = { }; + + if (val & BIT(IEEE80211_AC_VO)) + arg.trig_voice = 1; + if (val & BIT(IEEE80211_AC_VI)) + arg.trig_video = 1; + if (val & BIT(IEEE80211_AC_BE)) + arg.trig_be = 1; + if (val & BIT(IEEE80211_AC_BK)) + arg.trig_bckgrnd = 1; + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_SET_UAPSD_INFORMATION, + &arg, sizeof(arg)); +} + +int hif_erp_use_protection(struct wfx_vif *wvif, bool enable) +{ + struct hif_mib_non_erp_protection arg = { + .use_cts_to_self = enable, + }; + + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_NON_ERP_PROTECTION, &arg, sizeof(arg)); +} + +int hif_slot_time(struct wfx_vif *wvif, int val) +{ + struct hif_mib_slot_time arg = { + .slot_time = cpu_to_le32(val), + }; + + return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_SLOT_TIME, + &arg, sizeof(arg)); +} + +int hif_wep_default_key_id(struct wfx_vif *wvif, int val) +{ + struct hif_mib_wep_default_key_id arg = { + .wep_default_key_id = val, + }; + + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID, + &arg, sizeof(arg)); +} + +int hif_rts_threshold(struct wfx_vif *wvif, int val) +{ + struct hif_mib_dot11_rts_threshold arg = { + .threshold = cpu_to_le32(val >= 0 ? val : 0xFFFF), + }; + + return hif_write_mib(wvif->wdev, wvif->id, + HIF_MIB_ID_DOT11_RTS_THRESHOLD, &arg, sizeof(arg)); +} diff --git a/drivers/staging/wfx/hif_tx_mib.h b/drivers/staging/wfx/hif_tx_mib.h index 26b1406f9f6c..bb7c104a03d8 100644 --- a/drivers/staging/wfx/hif_tx_mib.h +++ b/drivers/staging/wfx/hif_tx_mib.h @@ -9,398 +9,50 @@ #ifndef WFX_HIF_TX_MIB_H #define WFX_HIF_TX_MIB_H -#include <linux/etherdevice.h> - -#include "wfx.h" -#include "hif_tx.h" #include "hif_api_mib.h" -static inline int hif_set_output_power(struct wfx_vif *wvif, int val) -{ - struct hif_mib_current_tx_power_level arg = { - .power_level = cpu_to_le32(val * 10), - }; - - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_CURRENT_TX_POWER_LEVEL, - &arg, sizeof(arg)); -} - -static inline int hif_set_beacon_wakeup_period(struct wfx_vif *wvif, - unsigned int dtim_interval, - unsigned int listen_interval) -{ - struct hif_mib_beacon_wake_up_period val = { - .wakeup_period_min = dtim_interval, - .receive_dtim = 0, - .wakeup_period_max = cpu_to_le16(listen_interval), - }; - - if (dtim_interval > 0xFF || listen_interval > 0xFFFF) - return -EINVAL; - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_BEACON_WAKEUP_PERIOD, - &val, sizeof(val)); -} - -static inline int hif_set_rcpi_rssi_threshold(struct wfx_vif *wvif, - int rssi_thold, int rssi_hyst) -{ - struct hif_mib_rcpi_rssi_threshold arg = { - .rolling_average_count = 8, - .detection = 1, - }; - - if (!rssi_thold && !rssi_hyst) { - arg.upperthresh = 1; - arg.lowerthresh = 1; - } else { - arg.upper_threshold = rssi_thold + rssi_hyst; - arg.upper_threshold = (arg.upper_threshold + 110) * 2; - arg.lower_threshold = rssi_thold; - arg.lower_threshold = (arg.lower_threshold + 110) * 2; - } - - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_RCPI_RSSI_THRESHOLD, &arg, sizeof(arg)); -} - -static inline int hif_get_counters_table(struct wfx_dev *wdev, - struct hif_mib_extended_count_table *arg) -{ - if (wfx_api_older_than(wdev, 1, 3)) { - // extended_count_table is wider than count_table - memset(arg, 0xFF, sizeof(*arg)); - return hif_read_mib(wdev, 0, HIF_MIB_ID_COUNTERS_TABLE, - arg, sizeof(struct hif_mib_count_table)); - } else { - return hif_read_mib(wdev, 0, - HIF_MIB_ID_EXTENDED_COUNTERS_TABLE, arg, - sizeof(struct hif_mib_extended_count_table)); - } -} - -static inline int hif_set_macaddr(struct wfx_vif *wvif, u8 *mac) -{ - struct hif_mib_mac_address msg = { }; - - if (mac) - ether_addr_copy(msg.mac_addr, mac); - return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_DOT11_MAC_ADDRESS, - &msg, sizeof(msg)); -} - -static inline int hif_set_rx_filter(struct wfx_vif *wvif, bool filter_bssid, - bool fwd_probe_req) -{ - struct hif_mib_rx_filter val = { }; - - if (filter_bssid) - val.bssid_filter = 1; - if (fwd_probe_req) - val.fwd_probe_req = 1; - return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_RX_FILTER, - &val, sizeof(val)); -} - -static inline int hif_set_beacon_filter_table(struct wfx_vif *wvif, - int tbl_len, - struct hif_ie_table_entry *tbl) -{ - int ret; - struct hif_mib_bcn_filter_table *val; - int buf_len = struct_size(val, ie_table, tbl_len); - - val = kzalloc(buf_len, GFP_KERNEL); - if (!val) - return -ENOMEM; - val->num_of_info_elmts = cpu_to_le32(tbl_len); - memcpy(val->ie_table, tbl, tbl_len * sizeof(*tbl)); - ret = hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_BEACON_FILTER_TABLE, val, buf_len); - kfree(val); - return ret; -} - -static inline int hif_beacon_filter_control(struct wfx_vif *wvif, - int enable, int beacon_count) -{ - struct hif_mib_bcn_filter_enable arg = { - .enable = cpu_to_le32(enable), - .bcn_count = cpu_to_le32(beacon_count), - }; - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_BEACON_FILTER_ENABLE, - &arg, sizeof(arg)); -} - -static inline int hif_set_operational_mode(struct wfx_dev *wdev, - enum hif_op_power_mode mode) -{ - struct hif_mib_gl_operational_power_mode val = { - .power_mode = mode, - .wup_ind_activation = 1, - }; - - return hif_write_mib(wdev, -1, HIF_MIB_ID_GL_OPERATIONAL_POWER_MODE, - &val, sizeof(val)); -} - -static inline int hif_set_template_frame(struct wfx_vif *wvif, - struct sk_buff *skb, - u8 frame_type, int init_rate) -{ - struct hif_mib_template_frame *arg; - - skb_push(skb, 4); - arg = (struct hif_mib_template_frame *)skb->data; - skb_pull(skb, 4); - arg->init_rate = init_rate; - arg->frame_type = frame_type; - arg->frame_length = cpu_to_le16(skb->len); - return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_TEMPLATE_FRAME, - arg, sizeof(*arg)); -} - -static inline int hif_set_mfp(struct wfx_vif *wvif, bool capable, bool required) -{ - struct hif_mib_protected_mgmt_policy val = { }; - - WARN(required && !capable, "incoherent arguments"); - if (capable) { - val.pmf_enable = 1; - val.host_enc_auth_frames = 1; - } - if (!required) - val.unpmf_allowed = 1; - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_PROTECTED_MGMT_POLICY, - &val, sizeof(val)); -} - -static inline int hif_set_block_ack_policy(struct wfx_vif *wvif, - u8 tx_tid_policy, u8 rx_tid_policy) -{ - struct hif_mib_block_ack_policy val = { - .block_ack_tx_tid_policy = tx_tid_policy, - .block_ack_rx_tid_policy = rx_tid_policy, - }; - - return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_BLOCK_ACK_POLICY, - &val, sizeof(val)); -} - -static inline int hif_set_association_mode(struct wfx_vif *wvif, - struct ieee80211_bss_conf *info) -{ - int basic_rates = wfx_rate_mask_to_hw(wvif->wdev, info->basic_rates); - struct ieee80211_sta *sta = NULL; - struct hif_mib_set_association_mode val = { - .preambtype_use = 1, - .mode = 1, - .rateset = 1, - .spacing = 1, - .short_preamble = info->use_short_preamble, - .basic_rate_set = cpu_to_le32(basic_rates) - }; - - rcu_read_lock(); // protect sta - if (info->bssid && !info->ibss_joined) - sta = ieee80211_find_sta(wvif->vif, info->bssid); - - // FIXME: it is strange to not retrieve all information from bss_info - if (sta && sta->ht_cap.ht_supported) { - val.mpdu_start_spacing = sta->ht_cap.ampdu_density; - if (!(info->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT)) - val.greenfield = !!(sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD); - } - rcu_read_unlock(); - - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_SET_ASSOCIATION_MODE, &val, sizeof(val)); -} - -static inline int hif_set_tx_rate_retry_policy(struct wfx_vif *wvif, - int policy_index, uint8_t *rates) -{ - struct hif_mib_set_tx_rate_retry_policy *arg; - size_t size = struct_size(arg, tx_rate_retry_policy, 1); - int ret; - - arg = kzalloc(size, GFP_KERNEL); - arg->num_tx_rate_policies = 1; - arg->tx_rate_retry_policy[0].policy_index = policy_index; - arg->tx_rate_retry_policy[0].short_retry_count = 255; - arg->tx_rate_retry_policy[0].long_retry_count = 255; - arg->tx_rate_retry_policy[0].first_rate_sel = 1; - arg->tx_rate_retry_policy[0].terminate = 1; - arg->tx_rate_retry_policy[0].count_init = 1; - memcpy(&arg->tx_rate_retry_policy[0].rates, rates, - sizeof(arg->tx_rate_retry_policy[0].rates)); - ret = hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_SET_TX_RATE_RETRY_POLICY, arg, size); - kfree(arg); - return ret; -} - -static inline int hif_set_mac_addr_condition(struct wfx_vif *wvif, - int idx, const u8 *mac_addr) -{ - struct hif_mib_mac_addr_data_frame_condition val = { - .condition_idx = idx, - .address_type = HIF_MAC_ADDR_A1, - }; - - ether_addr_copy(val.mac_address, mac_addr); - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_MAC_ADDR_DATAFRAME_CONDITION, - &val, sizeof(val)); -} - -static inline int hif_set_uc_mc_bc_condition(struct wfx_vif *wvif, - int idx, u8 allowed_frames) -{ - struct hif_mib_uc_mc_bc_data_frame_condition val = { - .condition_idx = idx, - .allowed_frames = allowed_frames, - }; - - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_UC_MC_BC_DATAFRAME_CONDITION, - &val, sizeof(val)); -} - -static inline int hif_set_config_data_filter(struct wfx_vif *wvif, bool enable, - int idx, int mac_filters, - int frames_types_filters) -{ - struct hif_mib_config_data_filter val = { - .enable = enable, - .filter_idx = idx, - .mac_cond = mac_filters, - .uc_mc_bc_cond = frames_types_filters, - }; - - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_CONFIG_DATA_FILTER, &val, sizeof(val)); -} - -static inline int hif_set_data_filtering(struct wfx_vif *wvif, - bool enable, bool invert) -{ - struct hif_mib_set_data_filtering val = { - .enable = enable, - .invert_matching = invert, - }; - - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_SET_DATA_FILTERING, &val, sizeof(val)); -} - -static inline int hif_keep_alive_period(struct wfx_vif *wvif, int period) -{ - struct hif_mib_keep_alive_period arg = { - .keep_alive_period = cpu_to_le16(period), - }; - - return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_KEEP_ALIVE_PERIOD, - &arg, sizeof(arg)); -}; - -static inline int hif_set_arp_ipv4_filter(struct wfx_vif *wvif, int idx, - __be32 *addr) -{ - struct hif_mib_arp_ip_addr_table arg = { - .condition_idx = idx, - .arp_enable = HIF_ARP_NS_FILTERING_DISABLE, - }; - - if (addr) { - // Caution: type of addr is __be32 - memcpy(arg.ipv4_address, addr, sizeof(arg.ipv4_address)); - arg.arp_enable = HIF_ARP_NS_FILTERING_ENABLE; - } - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_ARP_IP_ADDRESSES_TABLE, - &arg, sizeof(arg)); -} - -static inline int hif_use_multi_tx_conf(struct wfx_dev *wdev, bool enable) -{ - struct hif_mib_gl_set_multi_msg arg = { - .enable_multi_tx_conf = enable, - }; - - return hif_write_mib(wdev, -1, HIF_MIB_ID_GL_SET_MULTI_MSG, - &arg, sizeof(arg)); -} - -static inline int hif_set_uapsd_info(struct wfx_vif *wvif, unsigned long val) -{ - struct hif_mib_set_uapsd_information arg = { }; - - if (val & BIT(IEEE80211_AC_VO)) - arg.trig_voice = 1; - if (val & BIT(IEEE80211_AC_VI)) - arg.trig_video = 1; - if (val & BIT(IEEE80211_AC_BE)) - arg.trig_be = 1; - if (val & BIT(IEEE80211_AC_BK)) - arg.trig_bckgrnd = 1; - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_SET_UAPSD_INFORMATION, - &arg, sizeof(arg)); -} - -static inline int hif_erp_use_protection(struct wfx_vif *wvif, bool enable) -{ - struct hif_mib_non_erp_protection arg = { - .use_cts_to_self = enable, - }; - - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_NON_ERP_PROTECTION, &arg, sizeof(arg)); -} - -static inline int hif_slot_time(struct wfx_vif *wvif, int val) -{ - struct hif_mib_slot_time arg = { - .slot_time = cpu_to_le32(val), - }; - - return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_SLOT_TIME, - &arg, sizeof(arg)); -} - -static inline int hif_dual_cts_protection(struct wfx_vif *wvif, bool enable) -{ - struct hif_mib_set_ht_protection arg = { - .dual_cts_prot = enable, - }; - - return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_SET_HT_PROTECTION, - &arg, sizeof(arg)); -} - -static inline int hif_wep_default_key_id(struct wfx_vif *wvif, int val) -{ - struct hif_mib_wep_default_key_id arg = { - .wep_default_key_id = val, - }; - - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID, - &arg, sizeof(arg)); -} - -static inline int hif_rts_threshold(struct wfx_vif *wvif, int val) -{ - struct hif_mib_dot11_rts_threshold arg = { - .threshold = cpu_to_le32(val >= 0 ? val : 0xFFFF), - }; - - return hif_write_mib(wvif->wdev, wvif->id, - HIF_MIB_ID_DOT11_RTS_THRESHOLD, &arg, sizeof(arg)); -} +struct wfx_vif; +struct sk_buff; + +int hif_set_output_power(struct wfx_vif *wvif, int val); +int hif_set_beacon_wakeup_period(struct wfx_vif *wvif, + unsigned int dtim_interval, + unsigned int listen_interval); +int hif_set_rcpi_rssi_threshold(struct wfx_vif *wvif, + int rssi_thold, int rssi_hyst); +int hif_get_counters_table(struct wfx_dev *wdev, + struct hif_mib_extended_count_table *arg); +int hif_set_macaddr(struct wfx_vif *wvif, u8 *mac); +int hif_set_rx_filter(struct wfx_vif *wvif, + bool filter_bssid, bool fwd_probe_req); +int hif_set_beacon_filter_table(struct wfx_vif *wvif, int tbl_len, + const struct hif_ie_table_entry *tbl); +int hif_beacon_filter_control(struct wfx_vif *wvif, + int enable, int beacon_count); +int hif_set_operational_mode(struct wfx_dev *wdev, enum hif_op_power_mode mode); +int hif_set_template_frame(struct wfx_vif *wvif, struct sk_buff *skb, + u8 frame_type, int init_rate); +int hif_set_mfp(struct wfx_vif *wvif, bool capable, bool required); +int hif_set_block_ack_policy(struct wfx_vif *wvif, + u8 tx_tid_policy, u8 rx_tid_policy); +int hif_set_association_mode(struct wfx_vif *wvif, + struct ieee80211_bss_conf *info); +int hif_set_tx_rate_retry_policy(struct wfx_vif *wvif, + int policy_index, uint8_t *rates); +int hif_set_mac_addr_condition(struct wfx_vif *wvif, + int idx, const u8 *mac_addr); +int hif_set_uc_mc_bc_condition(struct wfx_vif *wvif, + int idx, u8 allowed_frames); +int hif_set_config_data_filter(struct wfx_vif *wvif, bool enable, int idx, + int mac_filters, int frames_types_filters); +int hif_set_data_filtering(struct wfx_vif *wvif, bool enable, bool invert); +int hif_keep_alive_period(struct wfx_vif *wvif, int period); +int hif_set_arp_ipv4_filter(struct wfx_vif *wvif, int idx, __be32 *addr); +int hif_use_multi_tx_conf(struct wfx_dev *wdev, bool enable); +int hif_set_uapsd_info(struct wfx_vif *wvif, unsigned long val); +int hif_erp_use_protection(struct wfx_vif *wvif, bool enable); +int hif_slot_time(struct wfx_vif *wvif, int val); +int hif_wep_default_key_id(struct wfx_vif *wvif, int val); +int hif_rts_threshold(struct wfx_vif *wvif, int val); #endif diff --git a/drivers/staging/wfx/key.c b/drivers/staging/wfx/key.c index 96adfa330604..ceb57cbdfefd 100644 --- a/drivers/staging/wfx/key.c +++ b/drivers/staging/wfx/key.c @@ -5,6 +5,7 @@ * Copyright (c) 2017-2019, Silicon Laboratories, Inc. * Copyright (c) 2010, ST-Ericsson */ +#include <linux/etherdevice.h> #include <net/mac80211.h> #include "key.h" @@ -20,14 +21,12 @@ static int wfx_alloc_key(struct wfx_dev *wdev) return -1; wdev->key_map |= BIT(idx); - wdev->keys[idx].entry_index = idx; return idx; } static void wfx_free_key(struct wfx_dev *wdev, int idx) { WARN(!(wdev->key_map & BIT(idx)), "inconsistent key allocation"); - memset(&wdev->keys[idx], 0, sizeof(wdev->keys[idx])); wdev->key_map &= ~BIT(idx); } @@ -159,7 +158,7 @@ static int wfx_add_key(struct wfx_vif *wvif, struct ieee80211_sta *sta, struct ieee80211_key_conf *key) { int ret; - struct hif_req_add_key *k; + struct hif_req_add_key k = { }; struct ieee80211_key_seq seq; struct wfx_dev *wdev = wvif->wdev; int idx = wfx_alloc_key(wvif->wdev); @@ -169,44 +168,44 @@ static int wfx_add_key(struct wfx_vif *wvif, struct ieee80211_sta *sta, ieee80211_get_key_rx_seq(key, 0, &seq); if (idx < 0) return -EINVAL; - k = &wdev->keys[idx]; - k->int_id = wvif->id; + k.int_id = wvif->id; + k.entry_index = idx; if (key->cipher == WLAN_CIPHER_SUITE_WEP40 || key->cipher == WLAN_CIPHER_SUITE_WEP104) { if (pairwise) - k->type = fill_wep_pair(&k->key.wep_pairwise_key, key, - sta->addr); + k.type = fill_wep_pair(&k.key.wep_pairwise_key, key, + sta->addr); else - k->type = fill_wep_group(&k->key.wep_group_key, key); + k.type = fill_wep_group(&k.key.wep_group_key, key); } else if (key->cipher == WLAN_CIPHER_SUITE_TKIP) { if (pairwise) - k->type = fill_tkip_pair(&k->key.tkip_pairwise_key, key, - sta->addr); + k.type = fill_tkip_pair(&k.key.tkip_pairwise_key, key, + sta->addr); else - k->type = fill_tkip_group(&k->key.tkip_group_key, key, - &seq, wvif->vif->type); + k.type = fill_tkip_group(&k.key.tkip_group_key, key, + &seq, wvif->vif->type); } else if (key->cipher == WLAN_CIPHER_SUITE_CCMP) { if (pairwise) - k->type = fill_ccmp_pair(&k->key.aes_pairwise_key, key, - sta->addr); + k.type = fill_ccmp_pair(&k.key.aes_pairwise_key, key, + sta->addr); else - k->type = fill_ccmp_group(&k->key.aes_group_key, key, - &seq); + k.type = fill_ccmp_group(&k.key.aes_group_key, key, + &seq); } else if (key->cipher == WLAN_CIPHER_SUITE_SMS4) { if (pairwise) - k->type = fill_sms4_pair(&k->key.wapi_pairwise_key, key, - sta->addr); + k.type = fill_sms4_pair(&k.key.wapi_pairwise_key, key, + sta->addr); else - k->type = fill_sms4_group(&k->key.wapi_group_key, key); + k.type = fill_sms4_group(&k.key.wapi_group_key, key); } else if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { - k->type = fill_aes_cmac_group(&k->key.igtk_group_key, key, - &seq); + k.type = fill_aes_cmac_group(&k.key.igtk_group_key, key, + &seq); } else { dev_warn(wdev->dev, "unsupported key type %d\n", key->cipher); wfx_free_key(wdev, idx); return -EOPNOTSUPP; } - ret = hif_add_key(wdev, k); + ret = hif_add_key(wdev, &k); if (ret) { wfx_free_key(wdev, idx); return -EOPNOTSUPP; @@ -240,29 +239,3 @@ int wfx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, return ret; } -int wfx_upload_keys(struct wfx_vif *wvif) -{ - int i; - struct hif_req_add_key *key; - struct wfx_dev *wdev = wvif->wdev; - - for (i = 0; i < ARRAY_SIZE(wdev->keys); i++) { - if (wdev->key_map & BIT(i)) { - key = &wdev->keys[i]; - if (key->int_id == wvif->id) - hif_add_key(wdev, key); - } - } - return 0; -} - -void wfx_wep_key_work(struct work_struct *work) -{ - struct wfx_vif *wvif = container_of(work, struct wfx_vif, wep_key_work); - - wfx_tx_flush(wvif->wdev); - hif_wep_default_key_id(wvif, wvif->wep_default_key_id); - wfx_pending_requeue(wvif->wdev, wvif->wep_pending_skb); - wvif->wep_pending_skb = NULL; - wfx_tx_unlock(wvif->wdev); -} diff --git a/drivers/staging/wfx/key.h b/drivers/staging/wfx/key.h index 9436ccdf4d3b..ff31fc9c565a 100644 --- a/drivers/staging/wfx/key.h +++ b/drivers/staging/wfx/key.h @@ -16,7 +16,5 @@ struct wfx_vif; int wfx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, struct ieee80211_vif *vif, struct ieee80211_sta *sta, struct ieee80211_key_conf *key); -int wfx_upload_keys(struct wfx_vif *wvif); -void wfx_wep_key_work(struct work_struct *work); #endif /* WFX_STA_H */ diff --git a/drivers/staging/wfx/main.c b/drivers/staging/wfx/main.c index 3c4c240229ad..cc7f924f3106 100644 --- a/drivers/staging/wfx/main.c +++ b/drivers/staging/wfx/main.c @@ -133,15 +133,19 @@ static const struct ieee80211_ops wfx_ops = { .remove_interface = wfx_remove_interface, .config = wfx_config, .tx = wfx_tx, + .join_ibss = wfx_join_ibss, + .leave_ibss = wfx_leave_ibss, .conf_tx = wfx_conf_tx, .hw_scan = wfx_hw_scan, .cancel_hw_scan = wfx_cancel_hw_scan, + .start_ap = wfx_start_ap, + .stop_ap = wfx_stop_ap, .sta_add = wfx_sta_add, .sta_remove = wfx_sta_remove, - .sta_notify = wfx_sta_notify, .set_tim = wfx_set_tim, .set_key = wfx_set_key, .set_rts_threshold = wfx_set_rts_threshold, + .set_default_unicast_key = wfx_set_default_unicast_key, .bss_info_changed = wfx_bss_info_changed, .prepare_multicast = wfx_prepare_multicast, .configure_filter = wfx_configure_filter, @@ -268,7 +272,6 @@ static void wfx_free_common(void *data) mutex_destroy(&wdev->rx_stats_lock); mutex_destroy(&wdev->conf_mutex); - wfx_tx_queues_deinit(wdev); ieee80211_free_hw(wdev->hw); } @@ -286,7 +289,6 @@ struct wfx_dev *wfx_init_common(struct device *dev, SET_IEEE80211_DEV(hw, dev); - ieee80211_hw_set(hw, NEED_DTIM_BEFORE_ASSOC); ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); ieee80211_hw_set(hw, AMPDU_AGGREGATION); ieee80211_hw_set(hw, CONNECTION_MONITOR); @@ -315,7 +317,7 @@ struct wfx_dev *wfx_init_common(struct device *dev, hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; - hw->wiphy->max_ap_assoc_sta = WFX_MAX_STA_IN_AP_MODE; + hw->wiphy->max_ap_assoc_sta = HIF_LINK_ID_MAX; hw->wiphy->max_scan_ssids = 2; hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; hw->wiphy->n_iface_combinations = ARRAY_SIZE(wfx_iface_combinations); diff --git a/drivers/staging/wfx/queue.c b/drivers/staging/wfx/queue.c index 39d9127ce4b9..2f6f9faf15be 100644 --- a/drivers/staging/wfx/queue.c +++ b/drivers/staging/wfx/queue.c @@ -30,15 +30,23 @@ void wfx_tx_unlock(struct wfx_dev *wdev) void wfx_tx_flush(struct wfx_dev *wdev) { int ret; + int i; // Do not wait for any reply if chip is frozen if (wdev->chip_frozen) return; + wfx_tx_lock(wdev); mutex_lock(&wdev->hif_cmd.lock); ret = wait_event_timeout(wdev->hif.tx_buffers_empty, !wdev->hif.tx_buffers_used, msecs_to_jiffies(3000)); + if (ret) { + for (i = 0; i < IEEE80211_NUM_ACS; i++) + WARN(atomic_read(&wdev->tx_queue[i].pending_frames), + "there are still %d pending frames on queue %d", + atomic_read(&wdev->tx_queue[i].pending_frames), i); + } if (!ret) { dev_warn(wdev->dev, "cannot flush tx buffers (%d still busy)\n", wdev->hif.tx_buffers_used); @@ -47,6 +55,7 @@ void wfx_tx_flush(struct wfx_dev *wdev) wdev->chip_frozen = 1; } mutex_unlock(&wdev->hif_cmd.lock); + wfx_tx_unlock(wdev); } void wfx_tx_lock_flush(struct wfx_dev *wdev) @@ -55,261 +64,155 @@ void wfx_tx_lock_flush(struct wfx_dev *wdev) wfx_tx_flush(wdev); } -void wfx_tx_queues_lock(struct wfx_dev *wdev) +void wfx_tx_queues_init(struct wfx_dev *wdev) { int i; - struct wfx_queue *queue; + skb_queue_head_init(&wdev->tx_pending); + init_waitqueue_head(&wdev->tx_dequeue); for (i = 0; i < IEEE80211_NUM_ACS; ++i) { - queue = &wdev->tx_queue[i]; - spin_lock_bh(&queue->queue.lock); - if (queue->tx_locked_cnt++ == 0) - ieee80211_stop_queue(wdev->hw, queue->queue_id); - spin_unlock_bh(&queue->queue.lock); + skb_queue_head_init(&wdev->tx_queue[i].normal); + skb_queue_head_init(&wdev->tx_queue[i].cab); } } -void wfx_tx_queues_unlock(struct wfx_dev *wdev) +void wfx_tx_queues_check_empty(struct wfx_dev *wdev) { int i; - struct wfx_queue *queue; + WARN_ON(!skb_queue_empty_lockless(&wdev->tx_pending)); for (i = 0; i < IEEE80211_NUM_ACS; ++i) { - queue = &wdev->tx_queue[i]; - spin_lock_bh(&queue->queue.lock); - WARN(!queue->tx_locked_cnt, "queue already unlocked"); - if (--queue->tx_locked_cnt == 0) - ieee80211_wake_queue(wdev->hw, queue->queue_id); - spin_unlock_bh(&queue->queue.lock); + WARN_ON(atomic_read(&wdev->tx_queue[i].pending_frames)); + WARN_ON(!skb_queue_empty_lockless(&wdev->tx_queue[i].normal)); + WARN_ON(!skb_queue_empty_lockless(&wdev->tx_queue[i].cab)); } } -/* If successful, LOCKS the TX queue! */ -void wfx_tx_queues_wait_empty_vif(struct wfx_vif *wvif) +static bool __wfx_tx_queue_empty(struct wfx_dev *wdev, + struct sk_buff_head *skb_queue, int vif_id) { - int i; - bool done; - struct wfx_queue *queue; - struct sk_buff *item; - struct wfx_dev *wdev = wvif->wdev; - struct hif_msg *hif; - - if (wvif->wdev->chip_frozen) { - wfx_tx_lock_flush(wdev); - wfx_tx_queues_clear(wdev); - return; - } + struct hif_msg *hif_msg; + struct sk_buff *skb; - do { - done = true; - wfx_tx_lock_flush(wdev); - for (i = 0; i < IEEE80211_NUM_ACS && done; ++i) { - queue = &wdev->tx_queue[i]; - spin_lock_bh(&queue->queue.lock); - skb_queue_walk(&queue->queue, item) { - hif = (struct hif_msg *) item->data; - if (hif->interface == wvif->id) - done = false; - } - spin_unlock_bh(&queue->queue.lock); - } - if (!done) { - wfx_tx_unlock(wdev); - msleep(20); + spin_lock_bh(&skb_queue->lock); + skb_queue_walk(skb_queue, skb) { + hif_msg = (struct hif_msg *)skb->data; + if (vif_id < 0 || hif_msg->interface == vif_id) { + spin_unlock_bh(&skb_queue->lock); + return false; } - } while (!done); -} - -static void wfx_tx_queue_clear(struct wfx_dev *wdev, struct wfx_queue *queue, - struct sk_buff_head *gc_list) -{ - int i; - struct sk_buff *item; - struct wfx_queue_stats *stats = &wdev->tx_queue_stats; - - spin_lock_bh(&queue->queue.lock); - while ((item = __skb_dequeue(&queue->queue)) != NULL) - skb_queue_head(gc_list, item); - spin_lock_nested(&stats->pending.lock, 1); - for (i = 0; i < ARRAY_SIZE(stats->link_map_cache); ++i) { - stats->link_map_cache[i] -= queue->link_map_cache[i]; - queue->link_map_cache[i] = 0; } - spin_unlock(&stats->pending.lock); - spin_unlock_bh(&queue->queue.lock); + spin_unlock_bh(&skb_queue->lock); + return true; } -void wfx_tx_queues_clear(struct wfx_dev *wdev) +bool wfx_tx_queue_empty(struct wfx_dev *wdev, + struct wfx_queue *queue, int vif_id) { - int i; - struct sk_buff *item; - struct sk_buff_head gc_list; - struct wfx_queue_stats *stats = &wdev->tx_queue_stats; - - skb_queue_head_init(&gc_list); - for (i = 0; i < IEEE80211_NUM_ACS; ++i) - wfx_tx_queue_clear(wdev, &wdev->tx_queue[i], &gc_list); - wake_up(&stats->wait_link_id_empty); - while ((item = skb_dequeue(&gc_list)) != NULL) - wfx_skb_dtor(wdev, item); + return __wfx_tx_queue_empty(wdev, &queue->normal, vif_id) && + __wfx_tx_queue_empty(wdev, &queue->cab, vif_id); } -void wfx_tx_queues_init(struct wfx_dev *wdev) +static void __wfx_tx_queue_drop(struct wfx_dev *wdev, + struct sk_buff_head *skb_queue, int vif_id, + struct sk_buff_head *dropped) { - int i; - - memset(&wdev->tx_queue_stats, 0, sizeof(wdev->tx_queue_stats)); - memset(wdev->tx_queue, 0, sizeof(wdev->tx_queue)); - skb_queue_head_init(&wdev->tx_queue_stats.pending); - init_waitqueue_head(&wdev->tx_queue_stats.wait_link_id_empty); - - for (i = 0; i < IEEE80211_NUM_ACS; ++i) { - wdev->tx_queue[i].queue_id = i; - skb_queue_head_init(&wdev->tx_queue[i].queue); + struct sk_buff *skb, *tmp; + struct hif_msg *hif_msg; + + spin_lock_bh(&skb_queue->lock); + skb_queue_walk_safe(skb_queue, skb, tmp) { + hif_msg = (struct hif_msg *)skb->data; + if (vif_id < 0 || hif_msg->interface == vif_id) { + __skb_unlink(skb, skb_queue); + skb_queue_head(dropped, skb); + } } + spin_unlock_bh(&skb_queue->lock); } -void wfx_tx_queues_deinit(struct wfx_dev *wdev) -{ - WARN_ON(!skb_queue_empty(&wdev->tx_queue_stats.pending)); - wfx_tx_queues_clear(wdev); -} - -int wfx_tx_queue_get_num_queued(struct wfx_queue *queue, u32 link_id_map) +void wfx_tx_queue_drop(struct wfx_dev *wdev, struct wfx_queue *queue, + int vif_id, struct sk_buff_head *dropped) { - int ret, i; - - if (!link_id_map) - return 0; - - spin_lock_bh(&queue->queue.lock); - if (link_id_map == (u32)-1) { - ret = skb_queue_len(&queue->queue); - } else { - ret = 0; - for (i = 0; i < ARRAY_SIZE(queue->link_map_cache); i++) - if (link_id_map & BIT(i)) - ret += queue->link_map_cache[i]; - } - spin_unlock_bh(&queue->queue.lock); - return ret; + __wfx_tx_queue_drop(wdev, &queue->cab, vif_id, dropped); + __wfx_tx_queue_drop(wdev, &queue->normal, vif_id, dropped); + wake_up(&wdev->tx_dequeue); } -void wfx_tx_queue_put(struct wfx_dev *wdev, struct wfx_queue *queue, - struct sk_buff *skb) +void wfx_tx_queues_put(struct wfx_dev *wdev, struct sk_buff *skb) { - struct wfx_queue_stats *stats = &wdev->tx_queue_stats; - struct wfx_tx_priv *tx_priv = wfx_skb_tx_priv(skb); - - WARN(tx_priv->link_id >= ARRAY_SIZE(stats->link_map_cache), "invalid link-id value"); - spin_lock_bh(&queue->queue.lock); - __skb_queue_tail(&queue->queue, skb); - - ++queue->link_map_cache[tx_priv->link_id]; - - spin_lock_nested(&stats->pending.lock, 1); - ++stats->link_map_cache[tx_priv->link_id]; - spin_unlock(&stats->pending.lock); - spin_unlock_bh(&queue->queue.lock); -} + struct wfx_queue *queue = &wdev->tx_queue[skb_get_queue_mapping(skb)]; + struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); -static struct sk_buff *wfx_tx_queue_get(struct wfx_dev *wdev, - struct wfx_queue *queue, - u32 link_id_map) -{ - struct sk_buff *skb = NULL; - struct sk_buff *item; - struct wfx_queue_stats *stats = &wdev->tx_queue_stats; - struct wfx_tx_priv *tx_priv; - bool wakeup_stats = false; - - spin_lock_bh(&queue->queue.lock); - skb_queue_walk(&queue->queue, item) { - tx_priv = wfx_skb_tx_priv(item); - if (link_id_map & BIT(tx_priv->link_id)) { - skb = item; - break; - } - } - if (skb) { - tx_priv = wfx_skb_tx_priv(skb); - tx_priv->xmit_timestamp = ktime_get(); - __skb_unlink(skb, &queue->queue); - --queue->link_map_cache[tx_priv->link_id]; - - spin_lock_nested(&stats->pending.lock, 1); - __skb_queue_tail(&stats->pending, skb); - if (!--stats->link_map_cache[tx_priv->link_id]) - wakeup_stats = true; - spin_unlock(&stats->pending.lock); - } - spin_unlock_bh(&queue->queue.lock); - if (wakeup_stats) - wake_up(&stats->wait_link_id_empty); - return skb; + if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) + skb_queue_tail(&queue->cab, skb); + else + skb_queue_tail(&queue->normal, skb); } int wfx_pending_requeue(struct wfx_dev *wdev, struct sk_buff *skb) { - struct wfx_queue_stats *stats = &wdev->tx_queue_stats; - struct wfx_tx_priv *tx_priv = wfx_skb_tx_priv(skb); struct wfx_queue *queue = &wdev->tx_queue[skb_get_queue_mapping(skb)]; WARN_ON(skb_get_queue_mapping(skb) > 3); - spin_lock_bh(&queue->queue.lock); - ++queue->link_map_cache[tx_priv->link_id]; - - spin_lock_nested(&stats->pending.lock, 1); - ++stats->link_map_cache[tx_priv->link_id]; - __skb_unlink(skb, &stats->pending); - spin_unlock(&stats->pending.lock); - __skb_queue_tail(&queue->queue, skb); - spin_unlock_bh(&queue->queue.lock); + WARN_ON(!atomic_read(&queue->pending_frames)); + + atomic_dec(&queue->pending_frames); + skb_unlink(skb, &wdev->tx_pending); + wfx_tx_queues_put(wdev, skb); return 0; } -int wfx_pending_remove(struct wfx_dev *wdev, struct sk_buff *skb) +void wfx_pending_drop(struct wfx_dev *wdev, struct sk_buff_head *dropped) { - struct wfx_queue_stats *stats = &wdev->tx_queue_stats; - - spin_lock_bh(&stats->pending.lock); - __skb_unlink(skb, &stats->pending); - spin_unlock_bh(&stats->pending.lock); - wfx_skb_dtor(wdev, skb); + struct wfx_queue *queue; + struct sk_buff *skb; - return 0; + WARN(!wdev->chip_frozen, "%s should only be used to recover a frozen device", + __func__); + while ((skb = skb_dequeue(&wdev->tx_pending)) != NULL) { + queue = &wdev->tx_queue[skb_get_queue_mapping(skb)]; + WARN_ON(skb_get_queue_mapping(skb) > 3); + WARN_ON(!atomic_read(&queue->pending_frames)); + atomic_dec(&queue->pending_frames); + skb_queue_head(dropped, skb); + } } struct sk_buff *wfx_pending_get(struct wfx_dev *wdev, u32 packet_id) { - struct sk_buff *skb; + struct wfx_queue *queue; struct hif_req_tx *req; - struct wfx_queue_stats *stats = &wdev->tx_queue_stats; + struct sk_buff *skb; - spin_lock_bh(&stats->pending.lock); - skb_queue_walk(&stats->pending, skb) { + spin_lock_bh(&wdev->tx_pending.lock); + skb_queue_walk(&wdev->tx_pending, skb) { req = wfx_skb_txreq(skb); if (req->packet_id == packet_id) { - spin_unlock_bh(&stats->pending.lock); + spin_unlock_bh(&wdev->tx_pending.lock); + queue = &wdev->tx_queue[skb_get_queue_mapping(skb)]; + WARN_ON(skb_get_queue_mapping(skb) > 3); + WARN_ON(!atomic_read(&queue->pending_frames)); + atomic_dec(&queue->pending_frames); + skb_unlink(skb, &wdev->tx_pending); return skb; } } - spin_unlock_bh(&stats->pending.lock); + spin_unlock_bh(&wdev->tx_pending.lock); WARN(1, "cannot find packet in pending queue"); return NULL; } void wfx_pending_dump_old_frames(struct wfx_dev *wdev, unsigned int limit_ms) { - struct wfx_queue_stats *stats = &wdev->tx_queue_stats; ktime_t now = ktime_get(); struct wfx_tx_priv *tx_priv; struct hif_req_tx *req; struct sk_buff *skb; bool first = true; - spin_lock_bh(&stats->pending.lock); - skb_queue_walk(&stats->pending, skb) { + spin_lock_bh(&wdev->tx_pending.lock); + skb_queue_walk(&wdev->tx_pending, skb) { tx_priv = wfx_skb_tx_priv(skb); req = wfx_skb_txreq(skb); if (ktime_after(now, ktime_add_ms(tx_priv->xmit_timestamp, @@ -324,7 +227,7 @@ void wfx_pending_dump_old_frames(struct wfx_dev *wdev, unsigned int limit_ms) ktime_ms_delta(now, tx_priv->xmit_timestamp)); } } - spin_unlock_bh(&stats->pending.lock); + spin_unlock_bh(&wdev->tx_pending.lock); } unsigned int wfx_pending_get_pkt_us_delay(struct wfx_dev *wdev, @@ -336,138 +239,66 @@ unsigned int wfx_pending_get_pkt_us_delay(struct wfx_dev *wdev, return ktime_us_delta(now, tx_priv->xmit_timestamp); } -bool wfx_tx_queues_is_empty(struct wfx_dev *wdev) +bool wfx_tx_queues_has_cab(struct wfx_vif *wvif) { + struct wfx_dev *wdev = wvif->wdev; int i; - struct sk_buff_head *queue; - bool ret = true; - - for (i = 0; i < IEEE80211_NUM_ACS; i++) { - queue = &wdev->tx_queue[i].queue; - spin_lock_bh(&queue->lock); - if (!skb_queue_empty(queue)) - ret = false; - spin_unlock_bh(&queue->lock); - } - return ret; -} -static bool hif_handle_tx_data(struct wfx_vif *wvif, struct sk_buff *skb, - struct wfx_queue *queue) -{ - struct hif_req_tx *req = wfx_skb_txreq(skb); - struct ieee80211_key_conf *hw_key = wfx_skb_tx_priv(skb)->hw_key; - struct ieee80211_hdr *frame = - (struct ieee80211_hdr *)(req->frame + req->data_flags.fc_offset); - - // FIXME: mac80211 is smart enough to handle BSS loss. Driver should not - // try to do anything about that. - if (ieee80211_is_nullfunc(frame->frame_control)) { - mutex_lock(&wvif->bss_loss_lock); - if (wvif->bss_loss_state) { - wvif->bss_loss_confirm_id = req->packet_id; - req->queue_id.queue_id = HIF_QUEUE_ID_VOICE; - } - mutex_unlock(&wvif->bss_loss_lock); - } - - // FIXME: identify the exact scenario matched by this condition. Does it - // happen yet? - if (ieee80211_has_protected(frame->frame_control) && - hw_key && hw_key->keyidx != wvif->wep_default_key_id && - (hw_key->cipher == WLAN_CIPHER_SUITE_WEP40 || - hw_key->cipher == WLAN_CIPHER_SUITE_WEP104)) { - wfx_tx_lock(wvif->wdev); - WARN_ON(wvif->wep_pending_skb); - wvif->wep_default_key_id = hw_key->keyidx; - wvif->wep_pending_skb = skb; - if (!schedule_work(&wvif->wep_key_work)) - wfx_tx_unlock(wvif->wdev); - return true; - } else { + if (wvif->vif->type != NL80211_IFTYPE_AP) return false; - } -} - -static int wfx_get_prio_queue(struct wfx_vif *wvif, - u32 tx_allowed_mask, int *total) -{ - static const int urgent = BIT(WFX_LINK_ID_AFTER_DTIM) | - BIT(WFX_LINK_ID_UAPSD); - const struct ieee80211_tx_queue_params *edca; - unsigned int score, best = -1; - int winner = -1; - int i; - - /* search for a winner using edca params */ - for (i = 0; i < IEEE80211_NUM_ACS; ++i) { - int queued; - - edca = &wvif->edca_params[i]; - queued = wfx_tx_queue_get_num_queued(&wvif->wdev->tx_queue[i], - tx_allowed_mask); - if (!queued) - continue; - *total += queued; - score = ((edca->aifs + edca->cw_min) << 16) + - ((edca->cw_max - edca->cw_min) * - (get_random_int() & 0xFFFF)); - if (score < best && (winner < 0 || i != 3)) { - best = score; - winner = i; - } - } - - /* override winner if bursting */ - if (winner >= 0 && wvif->wdev->tx_burst_idx >= 0 && - winner != wvif->wdev->tx_burst_idx && - !wfx_tx_queue_get_num_queued(&wvif->wdev->tx_queue[winner], - tx_allowed_mask & urgent) && - wfx_tx_queue_get_num_queued(&wvif->wdev->tx_queue[wvif->wdev->tx_burst_idx], tx_allowed_mask)) - winner = wvif->wdev->tx_burst_idx; - - return winner; -} - -static int wfx_tx_queue_mask_get(struct wfx_vif *wvif, - struct wfx_queue **queue_p, - u32 *tx_allowed_mask_p) -{ - int idx; - u32 tx_allowed_mask; - int total = 0; - - /* Search for unicast traffic */ - tx_allowed_mask = ~wvif->sta_asleep_mask; - tx_allowed_mask |= BIT(WFX_LINK_ID_UAPSD); - if (wvif->sta_asleep_mask) - tx_allowed_mask &= ~BIT(WFX_LINK_ID_AFTER_DTIM); - else - tx_allowed_mask |= BIT(WFX_LINK_ID_AFTER_DTIM); - idx = wfx_get_prio_queue(wvif, tx_allowed_mask, &total); - if (idx < 0) - return -ENOENT; - - *queue_p = &wvif->wdev->tx_queue[idx]; - *tx_allowed_mask_p = tx_allowed_mask; - return 0; + for (i = 0; i < IEEE80211_NUM_ACS; ++i) + // Note: since only AP can have mcast frames in queue and only + // one vif can be AP, all queued frames has same interface id + if (!skb_queue_empty_lockless(&wdev->tx_queue[i].cab)) + return true; + return false; } -struct hif_msg *wfx_tx_queues_get_after_dtim(struct wfx_vif *wvif) +static struct sk_buff *wfx_tx_queues_get_skb(struct wfx_dev *wdev) { - struct wfx_dev *wdev = wvif->wdev; - struct ieee80211_tx_info *tx_info; + struct wfx_queue *sorted_queues[IEEE80211_NUM_ACS]; + struct wfx_vif *wvif; struct hif_msg *hif; struct sk_buff *skb; - int i; + int i, j; - for (i = 0; i < IEEE80211_NUM_ACS; ++i) { - skb_queue_walk(&wdev->tx_queue[i].queue, skb) { - tx_info = IEEE80211_SKB_CB(skb); + // bubble sort + for (i = 0; i < IEEE80211_NUM_ACS; i++) { + sorted_queues[i] = &wdev->tx_queue[i]; + for (j = i; j > 0; j--) + if (atomic_read(&sorted_queues[j]->pending_frames) > + atomic_read(&sorted_queues[j - 1]->pending_frames)) + swap(sorted_queues[j - 1], sorted_queues[j]); + } + wvif = NULL; + while ((wvif = wvif_iterate(wdev, wvif)) != NULL) { + if (!wvif->after_dtim_tx_allowed) + continue; + for (i = 0; i < IEEE80211_NUM_ACS; i++) { + skb = skb_dequeue(&sorted_queues[i]->cab); + if (!skb) + continue; + // Note: since only AP can have mcast frames in queue + // and only one vif can be AP, all queued frames has + // same interface id hif = (struct hif_msg *)skb->data; - if ((tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) && - (hif->interface == wvif->id)) - return (struct hif_msg *)skb->data; + WARN_ON(hif->interface != wvif->id); + WARN_ON(sorted_queues[i] != + &wdev->tx_queue[skb_get_queue_mapping(skb)]); + atomic_inc(&sorted_queues[i]->pending_frames); + return skb; + } + // No more multicast to sent + wvif->after_dtim_tx_allowed = false; + schedule_work(&wvif->update_tim_work); + } + for (i = 0; i < IEEE80211_NUM_ACS; i++) { + skb = skb_dequeue(&sorted_queues[i]->normal); + if (skb) { + WARN_ON(sorted_queues[i] != + &wdev->tx_queue[skb_get_queue_mapping(skb)]); + atomic_inc(&sorted_queues[i]->pending_frames); + return skb; } } return NULL; @@ -475,90 +306,20 @@ struct hif_msg *wfx_tx_queues_get_after_dtim(struct wfx_vif *wvif) struct hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev) { + struct wfx_tx_priv *tx_priv; struct sk_buff *skb; - struct hif_msg *hif = NULL; - struct wfx_queue *queue = NULL; - struct wfx_queue *vif_queue = NULL; - u32 tx_allowed_mask = 0; - u32 vif_tx_allowed_mask = 0; - struct wfx_vif *wvif; - int not_found; - int burst; - int i; if (atomic_read(&wdev->tx_lock)) return NULL; - wvif = NULL; - while ((wvif = wvif_iterate(wdev, wvif)) != NULL) { - if (wvif->after_dtim_tx_allowed) { - for (i = 0; i < IEEE80211_NUM_ACS; ++i) { - skb = wfx_tx_queue_get(wvif->wdev, - &wdev->tx_queue[i], - BIT(WFX_LINK_ID_AFTER_DTIM)); - if (skb) { - hif = (struct hif_msg *)skb->data; - // Cannot happen since only one vif can - // be AP at time - WARN_ON(wvif->id != hif->interface); - return hif; - } - } - // No more multicast to sent - wvif->after_dtim_tx_allowed = false; - schedule_work(&wvif->update_tim_work); - } - } - for (;;) { - int ret = -ENOENT; - int queue_num; - - wvif = NULL; - while ((wvif = wvif_iterate(wdev, wvif)) != NULL) { - spin_lock_bh(&wvif->ps_state_lock); - - not_found = wfx_tx_queue_mask_get(wvif, &vif_queue, - &vif_tx_allowed_mask); - - spin_unlock_bh(&wvif->ps_state_lock); - - if (!not_found) { - if (queue && queue != vif_queue) - dev_info(wdev->dev, "vifs disagree about queue priority\n"); - tx_allowed_mask |= vif_tx_allowed_mask; - queue = vif_queue; - ret = 0; - } - } - - if (ret) - return NULL; - - queue_num = queue - wdev->tx_queue; - - skb = wfx_tx_queue_get(wdev, queue, tx_allowed_mask); + skb = wfx_tx_queues_get_skb(wdev); if (!skb) - continue; - hif = (struct hif_msg *)skb->data; - wvif = wdev_to_wvif(wdev, hif->interface); - WARN_ON(!wvif); - - if (hif_handle_tx_data(wvif, skb, queue)) - continue; /* Handled by WSM */ - - /* allow bursting if txop is set */ - if (wvif->edca_params[queue_num].txop) - burst = wfx_tx_queue_get_num_queued(queue, tx_allowed_mask) + 1; - else - burst = 1; - - /* store index of bursting queue */ - if (burst > 1) - wdev->tx_burst_idx = queue_num; - else - wdev->tx_burst_idx = -1; - - return hif; + return NULL; + skb_queue_tail(&wdev->tx_pending, skb); + wake_up(&wdev->tx_dequeue); + tx_priv = wfx_skb_tx_priv(skb); + tx_priv->xmit_timestamp = ktime_get(); + return (struct hif_msg *)skb->data; } } diff --git a/drivers/staging/wfx/queue.h b/drivers/staging/wfx/queue.h index 90bb060d1204..1020dfde399b 100644 --- a/drivers/staging/wfx/queue.h +++ b/drivers/staging/wfx/queue.h @@ -9,29 +9,17 @@ #define WFX_QUEUE_H #include <linux/skbuff.h> +#include <linux/atomic.h> #include "hif_api_cmd.h" -#define WFX_MAX_STA_IN_AP_MODE 14 -#define WFX_LINK_ID_NO_ASSOC 15 -#define WFX_LINK_ID_AFTER_DTIM (WFX_LINK_ID_NO_ASSOC + 1) -#define WFX_LINK_ID_UAPSD (WFX_LINK_ID_NO_ASSOC + 2) -#define WFX_LINK_ID_MAX (WFX_LINK_ID_NO_ASSOC + 3) - struct wfx_dev; struct wfx_vif; struct wfx_queue { - struct sk_buff_head queue; - int tx_locked_cnt; - int link_map_cache[WFX_LINK_ID_MAX]; - u8 queue_id; -}; - -struct wfx_queue_stats { - int link_map_cache[WFX_LINK_ID_MAX]; - struct sk_buff_head pending; - wait_queue_head_t wait_link_id_empty; + struct sk_buff_head normal; + struct sk_buff_head cab; // Content After (DTIM) Beacon + atomic_t pending_frames; }; void wfx_tx_lock(struct wfx_dev *wdev); @@ -40,21 +28,18 @@ void wfx_tx_flush(struct wfx_dev *wdev); void wfx_tx_lock_flush(struct wfx_dev *wdev); void wfx_tx_queues_init(struct wfx_dev *wdev); -void wfx_tx_queues_deinit(struct wfx_dev *wdev); -void wfx_tx_queues_lock(struct wfx_dev *wdev); -void wfx_tx_queues_unlock(struct wfx_dev *wdev); -void wfx_tx_queues_clear(struct wfx_dev *wdev); -bool wfx_tx_queues_is_empty(struct wfx_dev *wdev); -void wfx_tx_queues_wait_empty_vif(struct wfx_vif *wvif); +void wfx_tx_queues_check_empty(struct wfx_dev *wdev); +bool wfx_tx_queues_has_cab(struct wfx_vif *wvif); +void wfx_tx_queues_put(struct wfx_dev *wdev, struct sk_buff *skb); struct hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev); -struct hif_msg *wfx_tx_queues_get_after_dtim(struct wfx_vif *wvif); -void wfx_tx_queue_put(struct wfx_dev *wdev, struct wfx_queue *queue, - struct sk_buff *skb); -int wfx_tx_queue_get_num_queued(struct wfx_queue *queue, u32 link_id_map); +bool wfx_tx_queue_empty(struct wfx_dev *wdev, struct wfx_queue *queue, + int vif_id); +void wfx_tx_queue_drop(struct wfx_dev *wdev, struct wfx_queue *queue, + int vif_id, struct sk_buff_head *dropped); struct sk_buff *wfx_pending_get(struct wfx_dev *wdev, u32 packet_id); -int wfx_pending_remove(struct wfx_dev *wdev, struct sk_buff *skb); +void wfx_pending_drop(struct wfx_dev *wdev, struct sk_buff_head *dropped); int wfx_pending_requeue(struct wfx_dev *wdev, struct sk_buff *skb); unsigned int wfx_pending_get_pkt_us_delay(struct wfx_dev *wdev, struct sk_buff *skb); diff --git a/drivers/staging/wfx/scan.c b/drivers/staging/wfx/scan.c index 6e1e50048651..76761e4960dd 100644 --- a/drivers/staging/wfx/scan.c +++ b/drivers/staging/wfx/scan.c @@ -86,18 +86,17 @@ void wfx_hw_scan_work(struct work_struct *work) struct ieee80211_scan_request *hw_req = wvif->scan_req; int chan_cur, ret; - mutex_lock(&wvif->scan_lock); mutex_lock(&wvif->wdev->conf_mutex); + mutex_lock(&wvif->scan_lock); update_probe_tmpl(wvif, &hw_req->req); - wfx_fwd_probe_req(wvif, true); chan_cur = 0; do { ret = send_scan_req(wvif, &hw_req->req, chan_cur); if (ret > 0) chan_cur += ret; } while (ret > 0 && chan_cur < hw_req->req.n_channels); - mutex_unlock(&wvif->wdev->conf_mutex); mutex_unlock(&wvif->scan_lock); + mutex_unlock(&wvif->wdev->conf_mutex); __ieee80211_scan_completed_compat(wvif->wdev->hw, ret < 0); } @@ -111,9 +110,6 @@ int wfx_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, if (vif->type == NL80211_IFTYPE_AP) return -EOPNOTSUPP; - if (wvif->state == WFX_STATE_PRE_STA) - return -EBUSY; - wvif->scan_req = hw_req; schedule_work(&wvif->scan_work); return 0; diff --git a/drivers/staging/wfx/sta.c b/drivers/staging/wfx/sta.c index 9d430346a58b..f3e106f7eeac 100644 --- a/drivers/staging/wfx/sta.c +++ b/drivers/staging/wfx/sta.c @@ -5,6 +5,7 @@ * Copyright (c) 2017-2019, Silicon Laboratories, Inc. * Copyright (c) 2010, ST-Ericsson */ +#include <linux/etherdevice.h> #include <net/mac80211.h> #include "sta.h" @@ -37,117 +38,9 @@ u32 wfx_rate_mask_to_hw(struct wfx_dev *wdev, u32 rates) return ret; } -static void __wfx_free_event_queue(struct list_head *list) +static void wfx_filter_beacon(struct wfx_vif *wvif, bool filter_beacon) { - struct wfx_hif_event *event, *tmp; - - list_for_each_entry_safe(event, tmp, list, link) { - list_del(&event->link); - kfree(event); - } -} - -static void wfx_free_event_queue(struct wfx_vif *wvif) -{ - LIST_HEAD(list); - - spin_lock(&wvif->event_queue_lock); - list_splice_init(&wvif->event_queue, &list); - spin_unlock(&wvif->event_queue_lock); - - __wfx_free_event_queue(&list); -} - -void wfx_cqm_bssloss_sm(struct wfx_vif *wvif, int init, int good, int bad) -{ - int tx = 0; - - mutex_lock(&wvif->bss_loss_lock); - cancel_work_sync(&wvif->bss_params_work); - - if (init) { - schedule_delayed_work(&wvif->bss_loss_work, HZ); - wvif->bss_loss_state = 0; - - if (!atomic_read(&wvif->wdev->tx_lock)) - tx = 1; - } else if (good) { - cancel_delayed_work_sync(&wvif->bss_loss_work); - wvif->bss_loss_state = 0; - schedule_work(&wvif->bss_params_work); - } else if (bad) { - /* FIXME Should we just keep going until we time out? */ - if (wvif->bss_loss_state < 3) - tx = 1; - } else { - cancel_delayed_work_sync(&wvif->bss_loss_work); - wvif->bss_loss_state = 0; - } - - /* Spit out a NULL packet to our AP if necessary */ - // FIXME: call ieee80211_beacon_loss/ieee80211_connection_loss instead - if (tx) { - struct sk_buff *skb; - struct ieee80211_hdr *hdr; - struct ieee80211_tx_control control = { }; - - wvif->bss_loss_state++; - - skb = ieee80211_nullfunc_get(wvif->wdev->hw, wvif->vif, false); - if (!skb) - goto end; - hdr = (struct ieee80211_hdr *)skb->data; - memset(IEEE80211_SKB_CB(skb), 0, - sizeof(*IEEE80211_SKB_CB(skb))); - IEEE80211_SKB_CB(skb)->control.vif = wvif->vif; - IEEE80211_SKB_CB(skb)->driver_rates[0].idx = 0; - IEEE80211_SKB_CB(skb)->driver_rates[0].count = 1; - IEEE80211_SKB_CB(skb)->driver_rates[1].idx = -1; - rcu_read_lock(); // protect control.sta - control.sta = ieee80211_find_sta(wvif->vif, hdr->addr1); - wfx_tx(wvif->wdev->hw, &control, skb); - rcu_read_unlock(); - } -end: - mutex_unlock(&wvif->bss_loss_lock); -} - -int wfx_fwd_probe_req(struct wfx_vif *wvif, bool enable) -{ - wvif->fwd_probe_req = enable; - return hif_set_rx_filter(wvif, wvif->filter_bssid, - wvif->fwd_probe_req); -} - -static int wfx_set_mcast_filter(struct wfx_vif *wvif, - struct wfx_grp_addr_table *fp) -{ - int i; - - // Temporary workaround for filters - return hif_set_data_filtering(wvif, false, true); - - if (!fp->enable) - return hif_set_data_filtering(wvif, false, true); - - for (i = 0; i < fp->num_addresses; i++) - hif_set_mac_addr_condition(wvif, i, fp->address_list[i]); - hif_set_uc_mc_bc_condition(wvif, 0, - HIF_FILTER_UNICAST | HIF_FILTER_BROADCAST); - hif_set_config_data_filter(wvif, true, 0, BIT(1), - BIT(fp->num_addresses) - 1); - hif_set_data_filtering(wvif, true, true); - - return 0; -} - -void wfx_update_filtering(struct wfx_vif *wvif) -{ - int ret; - int bf_enable; - int bf_count; - int n_filter_ies; - struct hif_ie_table_entry filter_ies[] = { + const struct hif_ie_table_entry filter_ies[] = { { .ie_id = WLAN_EID_VENDOR_SPECIFIC, .has_changed = 1, @@ -167,40 +60,34 @@ void wfx_update_filtering(struct wfx_vif *wvif) } }; - if (wvif->state == WFX_STATE_PASSIVE) - return; - - if (wvif->disable_beacon_filter) { - bf_enable = 0; - bf_count = 1; - n_filter_ies = 0; - } else if (wvif->vif->type != NL80211_IFTYPE_STATION) { - bf_enable = HIF_BEACON_FILTER_ENABLE | HIF_BEACON_FILTER_AUTO_ERP; - bf_count = 0; - n_filter_ies = 2; + if (!filter_beacon) { + hif_set_beacon_filter_table(wvif, 0, NULL); + hif_beacon_filter_control(wvif, 0, 1); } else { - bf_enable = HIF_BEACON_FILTER_ENABLE; - bf_count = 0; - n_filter_ies = 3; + hif_set_beacon_filter_table(wvif, 3, filter_ies); + hif_beacon_filter_control(wvif, HIF_BEACON_FILTER_ENABLE, 0); } - - ret = hif_set_rx_filter(wvif, wvif->filter_bssid, wvif->fwd_probe_req); - if (!ret) - ret = hif_set_beacon_filter_table(wvif, n_filter_ies, filter_ies); - if (!ret) - ret = hif_beacon_filter_control(wvif, bf_enable, bf_count); - if (!ret) - ret = wfx_set_mcast_filter(wvif, &wvif->mcast_filter); - if (ret) - dev_err(wvif->wdev->dev, "update filtering failed: %d\n", ret); } -static void wfx_update_filtering_work(struct work_struct *work) +static void wfx_filter_mcast(struct wfx_vif *wvif, bool filter_mcast) { - struct wfx_vif *wvif = container_of(work, struct wfx_vif, - update_filtering_work); + int i; - wfx_update_filtering(wvif); + // Temporary workaround for filters + hif_set_data_filtering(wvif, false, true); + return; + + if (!filter_mcast) { + hif_set_data_filtering(wvif, false, true); + return; + } + for (i = 0; i < wvif->filter_mcast_count; i++) + hif_set_mac_addr_condition(wvif, i, wvif->filter_mcast_addr[i]); + hif_set_uc_mc_bc_condition(wvif, 0, + HIF_FILTER_UNICAST | HIF_FILTER_BROADCAST); + hif_set_config_data_filter(wvif, true, 0, BIT(1), + BIT(wvif->filter_mcast_count) - 1); + hif_set_data_filtering(wvif, true, true); } u64 wfx_prepare_multicast(struct ieee80211_hw *hw, @@ -213,19 +100,17 @@ u64 wfx_prepare_multicast(struct ieee80211_hw *hw, int count = netdev_hw_addr_list_count(mc_list); while ((wvif = wvif_iterate(wdev, wvif)) != NULL) { - memset(&wvif->mcast_filter, 0x00, sizeof(wvif->mcast_filter)); - if (!count || - count > ARRAY_SIZE(wvif->mcast_filter.address_list)) + if (count > ARRAY_SIZE(wvif->filter_mcast_addr)) { + wvif->filter_mcast_count = 0; continue; + } + wvif->filter_mcast_count = count; i = 0; netdev_hw_addr_list_for_each(ha, mc_list) { - ether_addr_copy(wvif->mcast_filter.address_list[i], - ha->addr); + ether_addr_copy(wvif->filter_mcast_addr[i], ha->addr); i++; } - wvif->mcast_filter.enable = true; - wvif->mcast_filter.num_addresses = count; } return 0; @@ -238,18 +123,61 @@ void wfx_configure_filter(struct ieee80211_hw *hw, { struct wfx_vif *wvif = NULL; struct wfx_dev *wdev = hw->priv; + bool filter_bssid, filter_prbreq, filter_beacon, filter_mcast; + + // Notes: + // - Probe responses (FIF_BCN_PRBRESP_PROMISC) are never filtered + // - PS-Poll (FIF_PSPOLL) are never filtered + // - RTS, CTS and Ack (FIF_CONTROL) are always filtered + // - Broken frames (FIF_FCSFAIL and FIF_PLCPFAIL) are always filtered + // - Firmware does (yet) allow to forward unicast traffic sent to + // other stations (aka. promiscuous mode) + *total_flags &= FIF_BCN_PRBRESP_PROMISC | FIF_ALLMULTI | FIF_OTHER_BSS | + FIF_PROBE_REQ | FIF_PSPOLL; - *total_flags &= FIF_OTHER_BSS | FIF_FCSFAIL | FIF_PROBE_REQ; - + mutex_lock(&wdev->conf_mutex); while ((wvif = wvif_iterate(wdev, wvif)) != NULL) { mutex_lock(&wvif->scan_lock); - wvif->filter_bssid = (*total_flags & - (FIF_OTHER_BSS | FIF_PROBE_REQ)) ? 0 : 1; - wvif->disable_beacon_filter = !(*total_flags & FIF_PROBE_REQ); - wfx_fwd_probe_req(wvif, true); - wfx_update_filtering(wvif); + + // Note: FIF_BCN_PRBRESP_PROMISC covers probe response and + // beacons from other BSS + if (*total_flags & FIF_BCN_PRBRESP_PROMISC) + filter_beacon = false; + else + filter_beacon = true; + wfx_filter_beacon(wvif, filter_beacon); + + if (*total_flags & FIF_ALLMULTI) { + filter_mcast = false; + } else if (!wvif->filter_mcast_count) { + dev_dbg(wdev->dev, "disabling unconfigured multicast filter"); + filter_mcast = false; + } else { + filter_mcast = true; + } + wfx_filter_mcast(wvif, filter_mcast); + + if (*total_flags & FIF_OTHER_BSS) + filter_bssid = false; + else + filter_bssid = true; + + // In AP mode, chip can reply to probe request itself + if (*total_flags & FIF_PROBE_REQ && + wvif->vif->type == NL80211_IFTYPE_AP) { + dev_dbg(wdev->dev, "do not forward probe request in AP mode\n"); + *total_flags &= ~FIF_PROBE_REQ; + } + + if (*total_flags & FIF_PROBE_REQ) + filter_prbreq = false; + else + filter_prbreq = true; + hif_set_rx_filter(wvif, filter_bssid, filter_prbreq); + mutex_unlock(&wvif->scan_lock); } + mutex_unlock(&wdev->conf_mutex); } static int wfx_update_pm(struct wfx_vif *wvif) @@ -260,7 +188,7 @@ static int wfx_update_pm(struct wfx_vif *wvif) struct ieee80211_channel *chan0 = NULL, *chan1 = NULL; WARN_ON(conf->dynamic_ps_timeout < 0); - if (wvif->state != WFX_STATE_STA || !wvif->bss_params.aid) + if (!wvif->vif->bss_conf.assoc) return 0; if (!ps) ps_timeout = 0; @@ -298,7 +226,6 @@ int wfx_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mutex_lock(&wdev->conf_mutex); assign_bit(queue, &wvif->uapsd_mask, params->uapsd); - memcpy(&wvif->edca_params[queue], params, sizeof(*params)); hif_set_edca_queue_params(wvif, queue, params); if (wvif->vif->type == NL80211_IFTYPE_STATION && old_uapsd != wvif->uapsd_mask) { @@ -319,32 +246,9 @@ int wfx_set_rts_threshold(struct ieee80211_hw *hw, u32 value) return 0; } -static int __wfx_flush(struct wfx_dev *wdev, bool drop) -{ - for (;;) { - if (drop) - wfx_tx_queues_clear(wdev); - if (wait_event_timeout(wdev->tx_queue_stats.wait_link_id_empty, - wfx_tx_queues_is_empty(wdev), - 2 * HZ) <= 0) - return -ETIMEDOUT; - wfx_tx_flush(wdev); - if (wfx_tx_queues_is_empty(wdev)) - return 0; - dev_warn(wdev->dev, "frames queued while flushing tx queues"); - } -} - -void wfx_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, - u32 queues, bool drop) -{ - // FIXME: only flush requested vif and queues - __wfx_flush(hw->priv, drop); -} - /* WSM callbacks */ -static void wfx_event_report_rssi(struct wfx_vif *wvif, u8 raw_rcpi_rssi) +void wfx_event_report_rssi(struct wfx_vif *wvif, u8 raw_rcpi_rssi) { /* RSSI: signed Q8.0, RCPI: unsigned Q7.1 * RSSI = RCPI / 2 - 110 @@ -360,100 +264,36 @@ static void wfx_event_report_rssi(struct wfx_vif *wvif, u8 raw_rcpi_rssi) ieee80211_cqm_rssi_notify(wvif->vif, cqm_evt, rcpi_rssi, GFP_KERNEL); } -static void wfx_event_handler_work(struct work_struct *work) -{ - struct wfx_vif *wvif = - container_of(work, struct wfx_vif, event_handler_work); - struct wfx_hif_event *event; - - LIST_HEAD(list); - - spin_lock(&wvif->event_queue_lock); - list_splice_init(&wvif->event_queue, &list); - spin_unlock(&wvif->event_queue_lock); - - list_for_each_entry(event, &list, link) { - switch (event->evt.event_id) { - case HIF_EVENT_IND_BSSLOST: - cancel_work_sync(&wvif->unjoin_work); - mutex_lock(&wvif->scan_lock); - wfx_cqm_bssloss_sm(wvif, 1, 0, 0); - mutex_unlock(&wvif->scan_lock); - break; - case HIF_EVENT_IND_BSSREGAINED: - wfx_cqm_bssloss_sm(wvif, 0, 0, 0); - cancel_work_sync(&wvif->unjoin_work); - break; - case HIF_EVENT_IND_RCPI_RSSI: - wfx_event_report_rssi(wvif, - event->evt.event_data.rcpi_rssi); - break; - case HIF_EVENT_IND_PS_MODE_ERROR: - dev_warn(wvif->wdev->dev, - "error while processing power save request\n"); - break; - default: - dev_warn(wvif->wdev->dev, - "unhandled event indication: %.2x\n", - event->evt.event_id); - break; - } - } - __wfx_free_event_queue(&list); -} - -static void wfx_bss_loss_work(struct work_struct *work) +static void wfx_beacon_loss_work(struct work_struct *work) { - struct wfx_vif *wvif = container_of(work, struct wfx_vif, - bss_loss_work.work); + struct wfx_vif *wvif = container_of(to_delayed_work(work), + struct wfx_vif, beacon_loss_work); + struct ieee80211_bss_conf *bss_conf = &wvif->vif->bss_conf; - ieee80211_connection_loss(wvif->vif); + ieee80211_beacon_loss(wvif->vif); + schedule_delayed_work(to_delayed_work(work), + msecs_to_jiffies(bss_conf->beacon_int)); } -static void wfx_bss_params_work(struct work_struct *work) +void wfx_set_default_unicast_key(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, int idx) { - struct wfx_vif *wvif = container_of(work, struct wfx_vif, - bss_params_work); - - mutex_lock(&wvif->wdev->conf_mutex); - wvif->bss_params.bss_flags.lost_count_only = 1; - hif_set_bss_params(wvif, &wvif->bss_params); - wvif->bss_params.bss_flags.lost_count_only = 0; - mutex_unlock(&wvif->wdev->conf_mutex); + struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv; + + hif_wep_default_key_id(wvif, idx); } +// Call it with wdev->conf_mutex locked static void wfx_do_unjoin(struct wfx_vif *wvif) { - mutex_lock(&wvif->wdev->conf_mutex); - - if (!wvif->state) - goto done; - - if (wvif->state == WFX_STATE_AP) - goto done; - - cancel_work_sync(&wvif->update_filtering_work); - wvif->state = WFX_STATE_PASSIVE; - /* Unjoin is a reset. */ - wfx_tx_flush(wvif->wdev); - hif_keep_alive_period(wvif, 0); + wfx_tx_lock_flush(wvif->wdev); hif_reset(wvif, false); wfx_tx_policy_init(wvif); - hif_set_macaddr(wvif, wvif->vif->addr); - wfx_free_event_queue(wvif); - cancel_work_sync(&wvif->event_handler_work); - wfx_cqm_bssloss_sm(wvif, 0, 0, 0); - - /* Disable Block ACKs */ - hif_set_block_ack_policy(wvif, 0, 0); - - wvif->disable_beacon_filter = false; - wfx_update_filtering(wvif); - memset(&wvif->bss_params, 0, sizeof(wvif->bss_params)); - -done: - mutex_unlock(&wvif->wdev->conf_mutex); + if (wvif_count(wvif->wdev) <= 1) + hif_set_block_ack_policy(wvif, 0xFF, 0xFF); + wfx_tx_unlock(wvif->wdev); + cancel_delayed_work_sync(&wvif->beacon_loss_work); } static void wfx_set_mfp(struct wfx_vif *wvif, @@ -498,9 +338,6 @@ static void wfx_do_join(struct wfx_vif *wvif) wfx_tx_lock_flush(wvif->wdev); - if (wvif->state) - wfx_do_unjoin(wvif); - bss = cfg80211_get_bss(wvif->wdev->hw->wiphy, wvif->channel, conf->bssid, NULL, 0, IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY); @@ -509,66 +346,32 @@ static void wfx_do_join(struct wfx_vif *wvif) return; } - mutex_lock(&wvif->wdev->conf_mutex); - - /* Sanity check beacon interval */ - if (!wvif->beacon_int) - wvif->beacon_int = 1; - rcu_read_lock(); // protect ssidie - if (!conf->ibss_joined) + if (bss) ssidie = ieee80211_bss_get_ie(bss, WLAN_EID_SSID); if (ssidie) { ssidlen = ssidie[1]; - memcpy(ssid, &ssidie[2], ssidie[1]); + if (ssidlen > IEEE80211_MAX_SSID_LEN) + ssidlen = IEEE80211_MAX_SSID_LEN; + memcpy(ssid, &ssidie[2], ssidlen); } rcu_read_unlock(); - wfx_tx_flush(wvif->wdev); - - if (wvif_count(wvif->wdev) <= 1) - hif_set_block_ack_policy(wvif, 0xFF, 0xFF); - wfx_set_mfp(wvif, bss); + cfg80211_put_bss(wvif->wdev->hw->wiphy, bss); - wvif->wdev->tx_burst_idx = -1; ret = hif_join(wvif, conf, wvif->channel, ssid, ssidlen); if (ret) { ieee80211_connection_loss(wvif->vif); - wvif->join_complete_status = -1; - /* Tx lock still held, unjoin will clear it. */ - if (!schedule_work(&wvif->unjoin_work)) - wfx_tx_unlock(wvif->wdev); + wfx_do_unjoin(wvif); } else { - wvif->join_complete_status = 0; - if (wvif->vif->type == NL80211_IFTYPE_ADHOC) - wvif->state = WFX_STATE_IBSS; - else - wvif->state = WFX_STATE_PRE_STA; - wfx_tx_unlock(wvif->wdev); - - /* Upload keys */ - wfx_upload_keys(wvif); - /* Due to beacon filtering it is possible that the * AP's beacon is not known for the mac80211 stack. * Disable filtering temporary to make sure the stack * receives at least one */ - wvif->disable_beacon_filter = true; + wfx_filter_beacon(wvif, false); } - wfx_update_filtering(wvif); - - mutex_unlock(&wvif->wdev->conf_mutex); - if (bss) - cfg80211_put_bss(wvif->wdev->hw->wiphy, bss); -} - -static void wfx_unjoin_work(struct work_struct *work) -{ - struct wfx_vif *wvif = container_of(work, struct wfx_vif, unjoin_work); - - wfx_do_unjoin(wvif); wfx_tx_unlock(wvif->wdev); } @@ -588,14 +391,9 @@ int wfx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, sta_priv->link_id = ffz(wvif->link_id_map); wvif->link_id_map |= BIT(sta_priv->link_id); WARN_ON(!sta_priv->link_id); - WARN_ON(sta_priv->link_id >= WFX_MAX_STA_IN_AP_MODE); + WARN_ON(sta_priv->link_id >= HIF_LINK_ID_MAX); hif_map_link(wvif, sta->addr, 0, sta_priv->link_id); - spin_lock_bh(&wvif->ps_state_lock); - if ((sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) == - IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) - wvif->sta_asleep_mask |= BIT(sta_priv->link_id); - spin_unlock_bh(&wvif->ps_state_lock); return 0; } @@ -619,50 +417,10 @@ int wfx_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, return 0; } -static int wfx_start_ap(struct wfx_vif *wvif) -{ - int ret; - - wvif->beacon_int = wvif->vif->bss_conf.beacon_int; - wvif->wdev->tx_burst_idx = -1; - ret = hif_start(wvif, &wvif->vif->bss_conf, wvif->channel); - if (ret) - return ret; - ret = wfx_upload_keys(wvif); - if (ret) - return ret; - if (wvif_count(wvif->wdev) <= 1) - hif_set_block_ack_policy(wvif, 0xFF, 0xFF); - wvif->state = WFX_STATE_AP; - wfx_update_filtering(wvif); - return 0; -} - -static int wfx_update_beaconing(struct wfx_vif *wvif) -{ - if (wvif->vif->type != NL80211_IFTYPE_AP) - return 0; - if (wvif->state == WFX_STATE_AP && - wvif->beacon_int == wvif->vif->bss_conf.beacon_int) - return 0; - wfx_tx_lock_flush(wvif->wdev); - hif_reset(wvif, false); - wfx_tx_policy_init(wvif); - wvif->state = WFX_STATE_PASSIVE; - wfx_start_ap(wvif); - wfx_tx_unlock(wvif->wdev); - return 0; -} - static int wfx_upload_ap_templates(struct wfx_vif *wvif) { struct sk_buff *skb; - if (wvif->vif->type == NL80211_IFTYPE_STATION || - wvif->vif->type == NL80211_IFTYPE_MONITOR || - wvif->vif->type == NL80211_IFTYPE_UNSPECIFIED) - return 0; - skb = ieee80211_beacon_get(wvif->wdev->hw, wvif->vif); if (!skb) return -ENOMEM; @@ -679,42 +437,64 @@ static int wfx_upload_ap_templates(struct wfx_vif *wvif) return 0; } +int wfx_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif) +{ + struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv; + + wfx_upload_ap_templates(wvif); + hif_start(wvif, &vif->bss_conf, wvif->channel); + return 0; +} + +void wfx_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif) +{ + struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv; + + hif_reset(wvif, false); + wfx_tx_policy_init(wvif); + if (wvif_count(wvif->wdev) <= 1) + hif_set_block_ack_policy(wvif, 0xFF, 0xFF); +} + static void wfx_join_finalize(struct wfx_vif *wvif, struct ieee80211_bss_conf *info) { - struct ieee80211_sta *sta = NULL; - - wvif->beacon_int = info->beacon_int; - rcu_read_lock(); // protect sta - if (info->bssid && !info->ibss_joined) - sta = ieee80211_find_sta(wvif->vif, info->bssid); - if (sta) - wvif->bss_params.operational_rate_set = - wfx_rate_mask_to_hw(wvif->wdev, sta->supp_rates[wvif->channel->band]); - else - wvif->bss_params.operational_rate_set = -1; - rcu_read_unlock(); - if (sta && - info->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) - hif_dual_cts_protection(wvif, true); - else - hif_dual_cts_protection(wvif, false); + hif_set_association_mode(wvif, info); + hif_keep_alive_period(wvif, 0); + // beacon_loss_count is defined to 7 in net/mac80211/mlme.c. Let's use + // the same value. + hif_set_bss_params(wvif, info->aid, 7); + hif_set_beacon_wakeup_period(wvif, 1, 1); + wfx_update_pm(wvif); +} - wfx_cqm_bssloss_sm(wvif, 0, 0, 0); - cancel_work_sync(&wvif->unjoin_work); +int wfx_join_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif) +{ + struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv; + + wfx_upload_ap_templates(wvif); + wfx_do_join(wvif); + return 0; +} - wvif->bss_params.beacon_lost_count = 20; - wvif->bss_params.aid = info->aid; +void wfx_leave_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif) +{ + struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv; - hif_set_association_mode(wvif, info); + wfx_do_unjoin(wvif); +} - if (!info->ibss_joined) { - hif_keep_alive_period(wvif, 30 /* sec */); - hif_set_bss_params(wvif, &wvif->bss_params); - hif_set_beacon_wakeup_period(wvif, info->dtim_period, - info->dtim_period); - wfx_update_pm(wvif); +void wfx_enable_beacon(struct wfx_vif *wvif, bool enable) +{ + // Driver has Content After DTIM Beacon in queue. Driver is waiting for + // a signal from the firmware. Since we are going to stop to send + // beacons, this signal will never happens. See also + // wfx_suspend_resume_mc() + if (!enable && wfx_tx_queues_has_cab(wvif)) { + wvif->after_dtim_tx_allowed = true; + wfx_bh_request_tx(wvif->wdev); } + hif_beacon_transmit(wvif, enable); } void wfx_bss_info_changed(struct ieee80211_hw *hw, @@ -724,7 +504,6 @@ void wfx_bss_info_changed(struct ieee80211_hw *hw, { struct wfx_dev *wdev = hw->priv; struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv; - bool do_join = false; int i; mutex_lock(&wdev->conf_mutex); @@ -742,92 +521,52 @@ void wfx_bss_info_changed(struct ieee80211_hw *hw, } } - if (changed & BSS_CHANGED_BEACON || - changed & BSS_CHANGED_AP_PROBE_RESP || - changed & BSS_CHANGED_BSSID || - changed & BSS_CHANGED_SSID || - changed & BSS_CHANGED_IBSS) { - wvif->beacon_int = info->beacon_int; - wfx_update_beaconing(wvif); - wfx_upload_ap_templates(wvif); - wfx_fwd_probe_req(wvif, false); + if (changed & BSS_CHANGED_BASIC_RATES || + changed & BSS_CHANGED_BEACON_INT || + changed & BSS_CHANGED_BSSID) { + if (vif->type == NL80211_IFTYPE_STATION) + wfx_do_join(wvif); } - if (changed & BSS_CHANGED_BEACON_ENABLED && - wvif->state != WFX_STATE_IBSS) - hif_beacon_transmit(wvif, info->enable_beacon); + if (changed & BSS_CHANGED_AP_PROBE_RESP || + changed & BSS_CHANGED_BEACON) + wfx_upload_ap_templates(wvif); + + if (changed & BSS_CHANGED_BEACON_ENABLED) + wfx_enable_beacon(wvif, info->enable_beacon); - if (changed & BSS_CHANGED_BEACON_INFO) + if (changed & BSS_CHANGED_BEACON_INFO) { + if (vif->type != NL80211_IFTYPE_STATION) + dev_warn(wdev->dev, "%s: misunderstood change: BEACON_INFO\n", + __func__); hif_set_beacon_wakeup_period(wvif, info->dtim_period, info->dtim_period); - - /* assoc/disassoc, or maybe AID changed */ - if (changed & BSS_CHANGED_ASSOC) { - wfx_tx_lock_flush(wdev); - wvif->wep_default_key_id = -1; - wfx_tx_unlock(wdev); + // We temporary forwarded beacon for join process. It is now no + // more necessary. + wfx_filter_beacon(wvif, true); } - if (changed & BSS_CHANGED_ASSOC && !info->assoc && - (wvif->state == WFX_STATE_STA || wvif->state == WFX_STATE_IBSS)) { - /* Shedule unjoin work */ - wfx_tx_lock(wdev); - if (!schedule_work(&wvif->unjoin_work)) - wfx_tx_unlock(wdev); - } else { - if (changed & BSS_CHANGED_BEACON_INT) { - if (info->ibss_joined) - do_join = true; - else if (wvif->state == WFX_STATE_AP) - wfx_update_beaconing(wvif); - } - - if (changed & BSS_CHANGED_BSSID) - do_join = true; - - if (changed & BSS_CHANGED_ASSOC || - changed & BSS_CHANGED_BSSID || - changed & BSS_CHANGED_IBSS || - changed & BSS_CHANGED_BASIC_RATES || - changed & BSS_CHANGED_HT) { - if (info->assoc) { - if (wvif->state < WFX_STATE_PRE_STA) { - ieee80211_connection_loss(vif); - mutex_unlock(&wdev->conf_mutex); - return; - } else if (wvif->state == WFX_STATE_PRE_STA) { - wvif->state = WFX_STATE_STA; - } - } else { - do_join = true; - } - - if (info->assoc || info->ibss_joined) - wfx_join_finalize(wvif, info); - else - memset(&wvif->bss_params, 0, - sizeof(wvif->bss_params)); - } + if (changed & BSS_CHANGED_ASSOC) { + if (info->assoc || info->ibss_joined) + wfx_join_finalize(wvif, info); + else if (!info->assoc && vif->type == NL80211_IFTYPE_STATION) + wfx_do_unjoin(wvif); + else + dev_warn(wdev->dev, "%s: misunderstood change: ASSOC\n", + __func__); } - if (changed & BSS_CHANGED_ASSOC || - changed & BSS_CHANGED_ERP_CTS_PROT || - changed & BSS_CHANGED_ERP_PREAMBLE) { - u8 erp_ie[3] = { WLAN_EID_ERP_INFO, 1, 0 }; + if (changed & BSS_CHANGED_KEEP_ALIVE) + hif_keep_alive_period(wvif, info->max_idle_period * + USEC_PER_TU / USEC_PER_MSEC); + if (changed & BSS_CHANGED_ERP_CTS_PROT) hif_erp_use_protection(wvif, info->use_cts_prot); - if (info->use_cts_prot) - erp_ie[2] |= WLAN_ERP_USE_PROTECTION; - if (info->use_short_preamble) - erp_ie[2] |= WLAN_ERP_BARKER_PREAMBLE; - if (wvif->vif->type != NL80211_IFTYPE_STATION) - hif_update_ie_beacon(wvif, erp_ie, sizeof(erp_ie)); - } - if (changed & BSS_CHANGED_ASSOC || changed & BSS_CHANGED_ERP_SLOT) + if (changed & BSS_CHANGED_ERP_SLOT) hif_slot_time(wvif, info->use_short_slot ? 9 : 20); - if (changed & BSS_CHANGED_ASSOC || changed & BSS_CHANGED_CQM) + if (changed & BSS_CHANGED_CQM) hif_set_rcpi_rssi_threshold(wvif, info->cqm_rssi_thold, info->cqm_rssi_hyst); @@ -838,31 +577,6 @@ void wfx_bss_info_changed(struct ieee80211_hw *hw, wfx_update_pm(wvif); mutex_unlock(&wdev->conf_mutex); - - if (do_join) - wfx_do_join(wvif); -} - -static void wfx_ps_notify_sta(struct wfx_vif *wvif, - enum sta_notify_cmd notify_cmd, int link_id) -{ - spin_lock_bh(&wvif->ps_state_lock); - if (notify_cmd == STA_NOTIFY_SLEEP) - wvif->sta_asleep_mask |= BIT(link_id); - else // notify_cmd == STA_NOTIFY_AWAKE - wvif->sta_asleep_mask &= ~BIT(link_id); - spin_unlock_bh(&wvif->ps_state_lock); - if (notify_cmd == STA_NOTIFY_AWAKE) - wfx_bh_request_tx(wvif->wdev); -} - -void wfx_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif, - enum sta_notify_cmd notify_cmd, struct ieee80211_sta *sta) -{ - struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv; - struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *) &sta->drv_priv; - - wfx_ps_notify_sta(wvif, notify_cmd, sta_priv->link_id); } static int wfx_update_tim(struct wfx_vif *wvif) @@ -873,10 +587,8 @@ static int wfx_update_tim(struct wfx_vif *wvif) skb = ieee80211_beacon_get_tim(wvif->wdev->hw, wvif->vif, &tim_offset, &tim_length); - if (!skb) { - __wfx_flush(wvif->wdev, true); + if (!skb) return -ENOENT; - } tim_ptr = skb->data + tim_offset; if (tim_offset && tim_length >= 6) { @@ -886,7 +598,7 @@ static int wfx_update_tim(struct wfx_vif *wvif) tim_ptr[2] = 0; /* Set/reset aid0 bit */ - if (wfx_tx_queues_get_after_dtim(wvif)) + if (wfx_tx_queues_has_cab(wvif)) tim_ptr[4] |= 1; else tim_ptr[4] &= ~1; @@ -917,7 +629,7 @@ int wfx_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set) void wfx_suspend_resume_mc(struct wfx_vif *wvif, enum sta_notify_cmd notify_cmd) { - WARN(!wfx_tx_queues_get_after_dtim(wvif), "incorrect sequence"); + WARN(!wfx_tx_queues_has_cab(wvif), "incorrect sequence"); WARN(wvif->after_dtim_tx_allowed, "incorrect sequence"); wvif->after_dtim_tx_allowed = true; wfx_bh_request_tx(wvif->wdev); @@ -1021,26 +733,11 @@ int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) wvif->wdev = wdev; wvif->link_id_map = 1; // link-id 0 is reserved for multicast - spin_lock_init(&wvif->ps_state_lock); INIT_WORK(&wvif->update_tim_work, wfx_update_tim_work); - - memset(&wvif->bss_params, 0, sizeof(wvif->bss_params)); - - mutex_init(&wvif->bss_loss_lock); - INIT_DELAYED_WORK(&wvif->bss_loss_work, wfx_bss_loss_work); - - wvif->wep_default_key_id = -1; - INIT_WORK(&wvif->wep_key_work, wfx_wep_key_work); - - spin_lock_init(&wvif->event_queue_lock); - INIT_LIST_HEAD(&wvif->event_queue); - INIT_WORK(&wvif->event_handler_work, wfx_event_handler_work); + INIT_DELAYED_WORK(&wvif->beacon_loss_work, wfx_beacon_loss_work); init_completion(&wvif->set_pm_mode_complete); complete(&wvif->set_pm_mode_complete); - INIT_WORK(&wvif->update_filtering_work, wfx_update_filtering_work); - INIT_WORK(&wvif->bss_params_work, wfx_bss_params_work); - INIT_WORK(&wvif->unjoin_work, wfx_unjoin_work); INIT_WORK(&wvif->tx_policy_upload_work, wfx_tx_policy_upload_work); mutex_init(&wvif->scan_lock); @@ -1076,34 +773,12 @@ void wfx_remove_interface(struct ieee80211_hw *hw, mutex_lock(&wdev->conf_mutex); WARN(wvif->link_id_map != 1, "corrupted state"); - switch (wvif->state) { - case WFX_STATE_PRE_STA: - case WFX_STATE_STA: - case WFX_STATE_IBSS: - wfx_tx_lock_flush(wdev); - if (!schedule_work(&wvif->unjoin_work)) - wfx_tx_unlock(wdev); - break; - case WFX_STATE_AP: - wvif->sta_asleep_mask = 0; - /* reset.link_id = 0; */ - hif_reset(wvif, false); - break; - default: - break; - } - wvif->state = WFX_STATE_PASSIVE; - wfx_tx_queues_wait_empty_vif(wvif); - wfx_tx_unlock(wdev); - - /* FIXME: In add to reset MAC address, try to reset interface */ + hif_reset(wvif, false); hif_set_macaddr(wvif, NULL); + wfx_tx_policy_init(wvif); - wfx_cqm_bssloss_sm(wvif, 0, 0, 0); - cancel_work_sync(&wvif->unjoin_work); - wfx_free_event_queue(wvif); - + cancel_delayed_work_sync(&wvif->beacon_loss_work); wdev->vif[wvif->id] = NULL; wvif->vif = NULL; @@ -1129,10 +804,5 @@ void wfx_stop(struct ieee80211_hw *hw) { struct wfx_dev *wdev = hw->priv; - wfx_tx_lock_flush(wdev); - mutex_lock(&wdev->conf_mutex); - wfx_tx_queues_clear(wdev); - mutex_unlock(&wdev->conf_mutex); - wfx_tx_unlock(wdev); - WARN(atomic_read(&wdev->tx_lock), "tx_lock is locked"); + wfx_tx_queues_check_empty(wdev); } diff --git a/drivers/staging/wfx/sta.h b/drivers/staging/wfx/sta.h index cf99a8a74a81..e814fe743b7d 100644 --- a/drivers/staging/wfx/sta.h +++ b/drivers/staging/wfx/sta.h @@ -15,25 +15,6 @@ struct wfx_dev; struct wfx_vif; -enum wfx_state { - WFX_STATE_PASSIVE = 0, - WFX_STATE_PRE_STA, - WFX_STATE_STA, - WFX_STATE_IBSS, - WFX_STATE_AP, -}; - -struct wfx_hif_event { - struct list_head link; - struct hif_ind_event evt; -}; - -struct wfx_grp_addr_table { - bool enable; - int num_addresses; - u8 address_list[8][ETH_ALEN]; -}; - struct wfx_sta_priv { int link_id; int vif_id; @@ -47,6 +28,8 @@ int wfx_start(struct ieee80211_hw *hw); void wfx_stop(struct ieee80211_hw *hw); int wfx_config(struct ieee80211_hw *hw, u32 changed); int wfx_set_rts_threshold(struct ieee80211_hw *hw, u32 value); +void wfx_set_default_unicast_key(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, int idx); u64 wfx_prepare_multicast(struct ieee80211_hw *hw, struct netdev_hw_addr_list *mc_list); void wfx_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, @@ -54,8 +37,10 @@ void wfx_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif); void wfx_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif); -void wfx_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, - u32 queues, bool drop); +int wfx_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif); +void wfx_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif); +int wfx_join_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif); +void wfx_leave_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif); int wfx_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue, const struct ieee80211_tx_queue_params *params); void wfx_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, @@ -83,11 +68,9 @@ void wfx_unassign_vif_chanctx(struct ieee80211_hw *hw, // WSM Callbacks void wfx_suspend_resume_mc(struct wfx_vif *wvif, enum sta_notify_cmd cmd); +void wfx_event_report_rssi(struct wfx_vif *wvif, u8 raw_rcpi_rssi); // Other Helpers -void wfx_cqm_bssloss_sm(struct wfx_vif *wvif, int init, int good, int bad); -void wfx_update_filtering(struct wfx_vif *wvif); -int wfx_fwd_probe_req(struct wfx_vif *wvif, bool enable); u32 wfx_rate_mask_to_hw(struct wfx_dev *wdev, u32 rates); #endif /* WFX_STA_H */ diff --git a/drivers/staging/wfx/wfx.h b/drivers/staging/wfx/wfx.h index 8b85bb1abb9c..706e95cd1092 100644 --- a/drivers/staging/wfx/wfx.h +++ b/drivers/staging/wfx/wfx.h @@ -50,13 +50,12 @@ struct wfx_dev { struct wfx_hif_cmd hif_cmd; struct wfx_queue tx_queue[4]; - struct wfx_queue_stats tx_queue_stats; - int tx_burst_idx; + struct sk_buff_head tx_pending; + wait_queue_head_t tx_dequeue; atomic_t tx_lock; atomic_t packet_id; u32 key_map; - struct hif_req_add_key keys[MAX_KEY_ENTRIES]; struct hif_rx_stats rx_stats; struct mutex rx_stats_lock; @@ -67,42 +66,21 @@ struct wfx_vif { struct ieee80211_vif *vif; struct ieee80211_channel *channel; int id; - enum wfx_state state; - - int bss_loss_state; - u32 bss_loss_confirm_id; - struct mutex bss_loss_lock; - struct delayed_work bss_loss_work; u32 link_id_map; bool after_dtim_tx_allowed; - struct wfx_grp_addr_table mcast_filter; - - s8 wep_default_key_id; - struct sk_buff *wep_pending_skb; - struct work_struct wep_key_work; + struct delayed_work beacon_loss_work; struct tx_policy_cache tx_policy_cache; struct work_struct tx_policy_upload_work; - u32 sta_asleep_mask; - spinlock_t ps_state_lock; struct work_struct update_tim_work; - int beacon_int; - bool filter_bssid; - bool fwd_probe_req; - bool disable_beacon_filter; - struct work_struct update_filtering_work; + int filter_mcast_count; + u8 filter_mcast_addr[8][ETH_ALEN]; unsigned long uapsd_mask; - struct ieee80211_tx_queue_params edca_params[IEEE80211_NUM_ACS]; - struct hif_req_set_bss_params bss_params; - struct work_struct bss_params_work; - - int join_complete_status; - struct work_struct unjoin_work; /* avoid some operations in parallel with scan */ struct mutex scan_lock; @@ -112,10 +90,6 @@ struct wfx_vif { struct ieee80211_scan_request *scan_req; struct completion set_pm_mode_complete; - - struct list_head event_queue; - spinlock_t event_queue_lock; - struct work_struct event_handler_work; }; static inline struct wfx_vif *wdev_to_wvif(struct wfx_dev *wdev, int vif_id) diff --git a/include/linux/fpga/adi-axi-common.h b/include/linux/fpga/adi-axi-common.h index 7fc95d5c95bb..141ac3f251e6 100644 --- a/include/linux/fpga/adi-axi-common.h +++ b/include/linux/fpga/adi-axi-common.h @@ -11,9 +11,13 @@ #ifndef ADI_AXI_COMMON_H_ #define ADI_AXI_COMMON_H_ -#define ADI_AXI_REG_VERSION 0x0000 +#define ADI_AXI_REG_VERSION 0x0000 #define ADI_AXI_PCORE_VER(major, minor, patch) \ (((major) << 16) | ((minor) << 8) | (patch)) +#define ADI_AXI_PCORE_VER_MAJOR(version) (((version) >> 16) & 0xff) +#define ADI_AXI_PCORE_VER_MINOR(version) (((version) >> 8) & 0xff) +#define ADI_AXI_PCORE_VER_PATCH(version) ((version) & 0xff) + #endif /* ADI_AXI_COMMON_H_ */ diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h index 5a127c0ed200..a3a838dcf8e4 100644 --- a/include/linux/iio/adc/ad_sigma_delta.h +++ b/include/linux/iio/adc/ad_sigma_delta.h @@ -133,62 +133,4 @@ void ad_sd_cleanup_buffer_and_trigger(struct iio_dev *indio_dev); int ad_sd_validate_trigger(struct iio_dev *indio_dev, struct iio_trigger *trig); -#define __AD_SD_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ - _storagebits, _shift, _extend_name, _type, _mask_all) \ - { \ - .type = (_type), \ - .differential = (_channel2 == -1 ? 0 : 1), \ - .indexed = 1, \ - .channel = (_channel1), \ - .channel2 = (_channel2), \ - .address = (_address), \ - .extend_name = (_extend_name), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_OFFSET), \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ - .info_mask_shared_by_all = _mask_all, \ - .scan_index = (_si), \ - .scan_type = { \ - .sign = 'u', \ - .realbits = (_bits), \ - .storagebits = (_storagebits), \ - .shift = (_shift), \ - .endianness = IIO_BE, \ - }, \ - } - -#define AD_SD_DIFF_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ - _storagebits, _shift) \ - __AD_SD_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ - _storagebits, _shift, NULL, IIO_VOLTAGE, \ - BIT(IIO_CHAN_INFO_SAMP_FREQ)) - -#define AD_SD_SHORTED_CHANNEL(_si, _channel, _address, _bits, \ - _storagebits, _shift) \ - __AD_SD_CHANNEL(_si, _channel, _channel, _address, _bits, \ - _storagebits, _shift, "shorted", IIO_VOLTAGE, \ - BIT(IIO_CHAN_INFO_SAMP_FREQ)) - -#define AD_SD_CHANNEL(_si, _channel, _address, _bits, \ - _storagebits, _shift) \ - __AD_SD_CHANNEL(_si, _channel, -1, _address, _bits, \ - _storagebits, _shift, NULL, IIO_VOLTAGE, \ - BIT(IIO_CHAN_INFO_SAMP_FREQ)) - -#define AD_SD_CHANNEL_NO_SAMP_FREQ(_si, _channel, _address, _bits, \ - _storagebits, _shift) \ - __AD_SD_CHANNEL(_si, _channel, -1, _address, _bits, \ - _storagebits, _shift, NULL, IIO_VOLTAGE, 0) - -#define AD_SD_TEMP_CHANNEL(_si, _address, _bits, _storagebits, _shift) \ - __AD_SD_CHANNEL(_si, 0, -1, _address, _bits, \ - _storagebits, _shift, NULL, IIO_TEMP, \ - BIT(IIO_CHAN_INFO_SAMP_FREQ)) - -#define AD_SD_SUPPLY_CHANNEL(_si, _channel, _address, _bits, _storagebits, \ - _shift) \ - __AD_SD_CHANNEL(_si, _channel, -1, _address, _bits, \ - _storagebits, _shift, "supply", IIO_VOLTAGE, \ - BIT(IIO_CHAN_INFO_SAMP_FREQ)) - #endif diff --git a/include/linux/iio/adc/adi-axi-adc.h b/include/linux/iio/adc/adi-axi-adc.h new file mode 100644 index 000000000000..c5d48e1c2d36 --- /dev/null +++ b/include/linux/iio/adc/adi-axi-adc.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Analog Devices Generic AXI ADC IP core driver/library + * Link: https://wiki.analog.com/resources/fpga/docs/axi_adc_ip + * + * Copyright 2012-2020 Analog Devices Inc. + */ +#ifndef __ADI_AXI_ADC_H__ +#define __ADI_AXI_ADC_H__ + +struct device; +struct iio_chan_spec; + +/** + * struct adi_axi_adc_chip_info - Chip specific information + * @name Chip name + * @id Chip ID (usually product ID) + * @channels Channel specifications of type @struct axi_adc_chan_spec + * @num_channels Number of @channels + * @scale_table Supported scales by the chip; tuples of 2 ints + * @num_scales Number of scales in the table + * @max_rate Maximum sampling rate supported by the device + */ +struct adi_axi_adc_chip_info { + const char *name; + unsigned int id; + + const struct iio_chan_spec *channels; + unsigned int num_channels; + + const unsigned int (*scale_table)[2]; + int num_scales; + + unsigned long max_rate; +}; + +/** + * struct adi_axi_adc_conv - data of the ADC attached to the AXI ADC + * @chip_info chip info details for the client ADC + * @preenable_setup op to run in the client before enabling the AXI ADC + * @reg_access IIO debugfs_reg_access hook for the client ADC + * @read_raw IIO read_raw hook for the client ADC + * @write_raw IIO write_raw hook for the client ADC + */ +struct adi_axi_adc_conv { + const struct adi_axi_adc_chip_info *chip_info; + + int (*preenable_setup)(struct adi_axi_adc_conv *conv); + int (*reg_access)(struct adi_axi_adc_conv *conv, unsigned int reg, + unsigned int writeval, unsigned int *readval); + int (*read_raw)(struct adi_axi_adc_conv *conv, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask); + int (*write_raw)(struct adi_axi_adc_conv *conv, + struct iio_chan_spec const *chan, + int val, int val2, long mask); +}; + +struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev, + size_t sizeof_priv); + +void *adi_axi_adc_conv_priv(struct adi_axi_adc_conv *conv); + +#endif diff --git a/include/linux/iio/buffer-dma.h b/include/linux/iio/buffer-dma.h index 016d8a068353..ff15c61bf319 100644 --- a/include/linux/iio/buffer-dma.h +++ b/include/linux/iio/buffer-dma.h @@ -11,7 +11,7 @@ #include <linux/kref.h> #include <linux/spinlock.h> #include <linux/mutex.h> -#include <linux/iio/buffer.h> +#include <linux/iio/buffer_impl.h> struct iio_dma_buffer_queue; struct iio_dma_buffer_ops; diff --git a/include/linux/iio/buffer-dmaengine.h b/include/linux/iio/buffer-dmaengine.h index b3a57444a886..0e503db71289 100644 --- a/include/linux/iio/buffer-dmaengine.h +++ b/include/linux/iio/buffer-dmaengine.h @@ -14,4 +14,7 @@ struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev, const char *channel); void iio_dmaengine_buffer_free(struct iio_buffer *buffer); +struct iio_buffer *devm_iio_dmaengine_buffer_alloc(struct device *dev, + const char *channel); + #endif diff --git a/include/linux/iio/buffer_impl.h b/include/linux/iio/buffer_impl.h index a4d2d8061ef6..a63dc07b7350 100644 --- a/include/linux/iio/buffer_impl.h +++ b/include/linux/iio/buffer_impl.h @@ -94,12 +94,6 @@ struct iio_buffer { unsigned int watermark; /* private: */ - /* - * @scan_el_attrs: Control of scan elements if that scan mode - * control method is used. - */ - struct attribute_group *scan_el_attrs; - /* @scan_timestamp: Does the scan mode include a timestamp. */ bool scan_timestamp; @@ -115,9 +109,6 @@ struct iio_buffer { */ struct attribute_group scan_el_group; - /* @stufftoread: Flag to indicate new data. */ - bool stufftoread; - /* @attrs: Standard attributes of the buffer. */ const struct attribute **attrs; diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h index 2bde8c912d4d..c4118dcb8e05 100644 --- a/include/linux/iio/consumer.h +++ b/include/linux/iio/consumer.h @@ -64,15 +64,6 @@ void iio_channel_release(struct iio_channel *chan); struct iio_channel *devm_iio_channel_get(struct device *dev, const char *consumer_channel); /** - * devm_iio_channel_release() - Resource managed version of - * iio_channel_release(). - * @dev: Pointer to consumer device for which resource - * is allocared. - * @chan: The channel to be released. - */ -void devm_iio_channel_release(struct device *dev, struct iio_channel *chan); - -/** * iio_channel_get_all() - get all channels associated with a client * @dev: Pointer to consumer device. * @@ -106,15 +97,6 @@ void iio_channel_release_all(struct iio_channel *chan); */ struct iio_channel *devm_iio_channel_get_all(struct device *dev); -/** - * devm_iio_channel_release_all() - Resource managed version of - * iio_channel_release_all(). - * @dev: Pointer to consumer device for which resource - * is allocared. - * @chan: Array channel to be released. - */ -void devm_iio_channel_release_all(struct device *dev, struct iio_channel *chan); - struct iio_cb_buffer; /** * iio_channel_get_all_cb() - register callback for triggered capture diff --git a/include/linux/iio/hw-consumer.h b/include/linux/iio/hw-consumer.h index 44d48bb1d39f..e8255c2e33bc 100644 --- a/include/linux/iio/hw-consumer.h +++ b/include/linux/iio/hw-consumer.h @@ -14,7 +14,6 @@ struct iio_hw_consumer; struct iio_hw_consumer *iio_hw_consumer_alloc(struct device *dev); void iio_hw_consumer_free(struct iio_hw_consumer *hwc); struct iio_hw_consumer *devm_iio_hw_consumer_alloc(struct device *dev); -void devm_iio_hw_consumer_free(struct device *dev, struct iio_hw_consumer *hwc); int iio_hw_consumer_enable(struct iio_hw_consumer *hwc); void iio_hw_consumer_disable(struct iio_hw_consumer *hwc); diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 25c87507a1fa..a1be82e74c93 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -492,7 +492,7 @@ struct iio_buffer_setup_ops { * @buffer: [DRIVER] any buffer present * @buffer_list: [INTERN] list of all buffers currently attached * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux - * @mlock: [DRIVER] lock used to prevent simultaneous device state + * @mlock: [INTERN] lock used to prevent simultaneous device state * changes * @available_scan_masks: [DRIVER] optional array of allowed bitmasks * @masklength: [INTERN] the length of the mask established from @@ -593,9 +593,6 @@ void iio_device_unregister(struct iio_dev *indio_dev); * calls iio_device_register() internally. Refer to that function for more * information. * - * If an iio_dev registered with this function needs to be unregistered - * separately, devm_iio_device_unregister() must be used. - * * RETURNS: * 0 on success, negative error number on failure. */ @@ -603,7 +600,6 @@ void iio_device_unregister(struct iio_dev *indio_dev); __devm_iio_device_register((dev), (indio_dev), THIS_MODULE) int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev, struct module *this_mod); -void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev); int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); int iio_device_claim_direct_mode(struct iio_dev *indio_dev); void iio_device_release_direct_mode(struct iio_dev *indio_dev); @@ -694,13 +690,9 @@ static inline struct iio_dev *iio_priv_to_dev(void *priv) } void iio_device_free(struct iio_dev *indio_dev); -int devm_iio_device_match(struct device *dev, void *res, void *data); struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv); -void devm_iio_device_free(struct device *dev, struct iio_dev *indio_dev); struct iio_trigger *devm_iio_trigger_alloc(struct device *dev, const char *fmt, ...); -void devm_iio_trigger_free(struct device *dev, struct iio_trigger *iio_trig); - /** * iio_buffer_enabled() - helper function to test if the buffer is enabled * @indio_dev: IIO device structure for device diff --git a/include/linux/iio/kfifo_buf.h b/include/linux/iio/kfifo_buf.h index 764659e01b68..1fc1efa7799d 100644 --- a/include/linux/iio/kfifo_buf.h +++ b/include/linux/iio/kfifo_buf.h @@ -9,6 +9,5 @@ struct iio_buffer *iio_kfifo_allocate(void); void iio_kfifo_free(struct iio_buffer *r); struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev); -void devm_iio_kfifo_free(struct device *dev, struct iio_buffer *r); #endif diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h index 84995e2967ac..cad8325903f9 100644 --- a/include/linux/iio/trigger.h +++ b/include/linux/iio/trigger.h @@ -141,9 +141,6 @@ int __devm_iio_trigger_register(struct device *dev, **/ void iio_trigger_unregister(struct iio_trigger *trig_info); -void devm_iio_trigger_unregister(struct device *dev, - struct iio_trigger *trig_info); - /** * iio_trigger_set_immutable() - set an immutable trigger on destination * diff --git a/include/linux/iio/triggered_buffer.h b/include/linux/iio/triggered_buffer.h index 238ad30ce166..e99c91799359 100644 --- a/include/linux/iio/triggered_buffer.h +++ b/include/linux/iio/triggered_buffer.h @@ -18,7 +18,5 @@ int devm_iio_triggered_buffer_setup(struct device *dev, irqreturn_t (*h)(int irq, void *p), irqreturn_t (*thread)(int irq, void *p), const struct iio_buffer_setup_ops *ops); -void devm_iio_triggered_buffer_cleanup(struct device *dev, - struct iio_dev *indio_dev); #endif |