diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-01-13 21:13:36 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-01-13 21:13:36 +0300 |
commit | 39272dde8ffcfd1322209e05f3f8fa4d14f796de (patch) | |
tree | 1c06907119d0ae484319379ec4404edf95ac37b5 | |
parent | 67ad058d97b8cff441211b791d97e5f776b81210 (diff) | |
parent | 841e3ed977e0284e3680d6345d880a64e8072573 (diff) | |
download | linux-39272dde8ffcfd1322209e05f3f8fa4d14f796de.tar.xz |
Merge tag 'staging-4.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging driver updates from Greg KH:
"Here is the big staging driver pull request for 4.5-rc1.
Lots of cleanups and fixes here, not as many as some releases, but
800+ isn't that bad. Full details in the shortlog. All of these have
been in linux-next for a while"
* tag 'staging-4.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (843 commits)
Revert "arm64: dts: Add dts files to enable ION on Hi6220 SoC."
staging: gdm724x: constify tty_port_operations structs
staging: gdm72xx: add userspace data struct
staging: gdm72xx: Replace timeval with ktime_t
iio: adc: ina2xx: Fix incorrect report of data endianness to userspace.
iio: light: us5182d: Refactor read_raw function
iio: light: us5182d: Add interrupt support and events
iio: light: us5182d: Fix enable status inconcistency
iio: Make IIO value formating function globally available.
staging: emxx_udc: use list_first_entry_or_null()
staging/emxx_udc: fix 64-bit warnings
STAGING: COMEDI: Using kernel types in plx9080.h
STAGING: COMEDI: Added spaces around binary operators in plx9080.h
STAGING: COMEDI: Fixed format of comments in plx9080.h
staging: comedi: comedilib.h: Coding style warning fix for block comments
staging: comedi: s526: add macros for counter control reg values
staging: comedi: s526: replace counter mode bitfield struct
staging: comedi: check for more errors for zero-length write
staging: comedi: simplify returned errors for comedi_write()
staging: comedi: return error on "write" if no command set up
...
504 files changed, 20836 insertions, 13892 deletions
diff --git a/Documentation/ABI/testing/configfs-iio b/Documentation/ABI/testing/configfs-iio new file mode 100644 index 000000000000..2483756fccf5 --- /dev/null +++ b/Documentation/ABI/testing/configfs-iio @@ -0,0 +1,21 @@ +What: /config/iio +Date: October 2015 +KernelVersion: 4.4 +Contact: linux-iio@vger.kernel.org +Description: + This represents Industrial IO configuration entry point + directory. It contains sub-groups corresponding to IIO + objects. + +What: /config/iio/triggers +Date: October 2015 +KernelVersion: 4.4 +Description: + Industrial IO software triggers directory. + +What: /config/iio/triggers/hrtimers +Date: October 2015 +KernelVersion: 4.4 +Description: + High resolution timers directory. Creating a directory here + will result in creating a hrtimer trigger in the IIO subsystem. diff --git a/Documentation/ABI/testing/sysfs-bus-iio-ina2xx-adc b/Documentation/ABI/testing/sysfs-bus-iio-ina2xx-adc new file mode 100644 index 000000000000..8916f7ec6507 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-iio-ina2xx-adc @@ -0,0 +1,24 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_allow_async_readout +Date: December 2015 +KernelVersion: 4.4 +Contact: linux-iio@vger.kernel.org +Description: + By default (value '0'), the capture thread checks for the Conversion + Ready Flag to being set prior to committing a new value to the sample + buffer. This synchronizes the in-chip conversion rate with the + in-driver readout rate at the cost of an additional register read. + + Writing '1' will remove the polling for the Conversion Ready Flags to + save the additional i2c transaction, which will improve the bandwidth + available for reading data. However, samples can be occasionally skipped + or repeated, depending on the beat between the capture and conversion + rates. + +What: /sys/bus/iio/devices/iio:deviceX/in_shunt_resistor +Date: December 2015 +KernelVersion: 4.4 +Contact: linux-iio@vger.kernel.org +Description: + The value of the shunt resistor may be known only at runtime fom an + eeprom content read by a client application. This attribute allows to + set its value in ohms. diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt index c50cf13c852e..f6fec952d683 100644 --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt @@ -20,6 +20,7 @@ adi,adt7476 +/-1C TDM Extended Temp Range I.C adi,adt7490 +/-1C TDM Extended Temp Range I.C adi,adxl345 Three-Axis Digital Accelerometer adi,adxl346 Three-Axis Digital Accelerometer (backward-compatibility value "adi,adxl345" must be listed too) +ams,iaq-core AMS iAQ-Core VOC Sensor at,24c08 i2c serial eeprom (24cxx) atmel,24c00 i2c serial eeprom (24cxx) atmel,24c01 i2c serial eeprom (24cxx) diff --git a/Documentation/devicetree/bindings/iio/accel/mma8452.txt b/Documentation/devicetree/bindings/iio/accel/mma8452.txt index e3c37467d7da..3c10e8581144 100644 --- a/Documentation/devicetree/bindings/iio/accel/mma8452.txt +++ b/Documentation/devicetree/bindings/iio/accel/mma8452.txt @@ -7,13 +7,18 @@ Required properties: * "fsl,mma8453" * "fsl,mma8652" * "fsl,mma8653" + - reg: the I2C address of the chip Optional properties: - interrupt-parent: should be the phandle for the interrupt controller + - interrupts: interrupt mapping for GPIO IRQ + - interrupt-names: should contain "INT1" and/or "INT2", the accelerometer's + interrupt line in use. + Example: mma8453fc@1d { @@ -21,4 +26,5 @@ Example: reg = <0x1d>; interrupt-parent = <&gpio1>; interrupts = <5 0>; + interrupt-names = "INT2"; }; diff --git a/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt new file mode 100644 index 000000000000..5c184b940669 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt @@ -0,0 +1,22 @@ +Freescale imx7d ADC bindings + +The devicetree bindings are for the ADC driver written for +imx7d SoC. + +Required properties: +- compatible: Should be "fsl,imx7d-adc" +- reg: Offset and length of the register set for the ADC device +- interrupts: The interrupt number for the ADC device +- clocks: The root clock of the ADC controller +- clock-names: Must contain "adc", matching entry in the clocks property +- vref-supply: The regulator supply ADC reference voltage + +Example: +adc1: adc@30610000 { + compatible = "fsl,imx7d-adc"; + reg = <0x30610000 0x10000>; + interrupts = <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clks IMX7D_ADC_ROOT_CLK>; + clock-names = "adc"; + vref-supply = <®_vcc_3v3_mcu>; +}; diff --git a/Documentation/devicetree/bindings/iio/adc/mcp320x.txt b/Documentation/devicetree/bindings/iio/adc/mcp320x.txt index 2a1f3af30155..bcd3ac8e6e0c 100644 --- a/Documentation/devicetree/bindings/iio/adc/mcp320x.txt +++ b/Documentation/devicetree/bindings/iio/adc/mcp320x.txt @@ -10,16 +10,28 @@ must be specified. Required properties: - compatible: Must be one of the following, depending on the model: - "mcp3001" - "mcp3002" - "mcp3004" - "mcp3008" - "mcp3201" - "mcp3202" - "mcp3204" - "mcp3208" - "mcp3301" + "mcp3001" (DEPRECATED) + "mcp3002" (DEPRECATED) + "mcp3004" (DEPRECATED) + "mcp3008" (DEPRECATED) + "mcp3201" (DEPRECATED) + "mcp3202" (DEPRECATED) + "mcp3204" (DEPRECATED) + "mcp3208" (DEPRECATED) + "mcp3301" (DEPRECATED) + "microchip,mcp3001" + "microchip,mcp3002" + "microchip,mcp3004" + "microchip,mcp3008" + "microchip,mcp3201" + "microchip,mcp3202" + "microchip,mcp3204" + "microchip,mcp3208" + "microchip,mcp3301" + + NOTE: The use of the compatibles with no vendor prefix + is deprecated and only listed because old DT use them. Examples: spi_controller { diff --git a/Documentation/devicetree/bindings/iio/adc/mcp3422.txt b/Documentation/devicetree/bindings/iio/adc/mcp3422.txt index 333139cc0bfb..dcae4ccfcc52 100644 --- a/Documentation/devicetree/bindings/iio/adc/mcp3422.txt +++ b/Documentation/devicetree/bindings/iio/adc/mcp3422.txt @@ -1,7 +1,8 @@ -* Microchip mcp3422/3/4/6/7/8 chip family (ADC) +* Microchip mcp3421/2/3/4/6/7/8 chip family (ADC) Required properties: - compatible: Should be + "microchip,mcp3421" or "microchip,mcp3422" or "microchip,mcp3423" or "microchip,mcp3424" or diff --git a/Documentation/devicetree/bindings/iio/adc/palmas-gpadc.txt b/Documentation/devicetree/bindings/iio/adc/palmas-gpadc.txt new file mode 100644 index 000000000000..4bb9a86065d1 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/palmas-gpadc.txt @@ -0,0 +1,48 @@ +* Palmas general purpose ADC IP block devicetree bindings + +Channels list: + 0 battery type + 1 battery temp NTC (optional current source) + 2 GP + 3 temp (with ext. diode, optional current source) + 4 GP + 5 GP + 6 VBAT_SENSE + 7 VCC_SENSE + 8 Backup Battery voltage + 9 external charger (VCHG) + 10 VBUS + 11 DC-DC current probe (how does this work?) + 12 internal die temp + 13 internal die temp + 14 USB ID pin voltage + 15 test network + +Required properties: +- compatible : Must be "ti,palmas-gpadc". +- #io-channel-cells: Should be set to <1>. + +Optional sub-nodes: +ti,channel0-current-microamp: Channel 0 current in uA. + Values are rounded to derive 0uA, 5uA, 15uA, 20uA. +ti,channel3-current-microamp: Channel 3 current in uA. + Values are rounded to derive 0uA, 10uA, 400uA, 800uA. +ti,enable-extended-delay: Enable extended delay. + +Example: + +pmic { + compatible = "ti,twl6035-pmic", "ti,palmas-pmic"; + ... + gpadc { + compatible = "ti,palmas-gpadc"; + interrupts = <18 0 + 16 0 + 17 0>; + #io-channel-cells = <1>; + ti,channel0-current-microamp = <5>; + ti,channel3-current-microamp = <10>; + }; + }; + ... +}; diff --git a/Documentation/devicetree/bindings/iio/adc/ti-adc128s052.txt b/Documentation/devicetree/bindings/iio/adc/ti-adc128s052.txt index 15ca6b47958e..daa2b2c29428 100644 --- a/Documentation/devicetree/bindings/iio/adc/ti-adc128s052.txt +++ b/Documentation/devicetree/bindings/iio/adc/ti-adc128s052.txt @@ -1,7 +1,7 @@ -* Texas Instruments' ADC128S052 and ADC122S021 ADC chip +* Texas Instruments' ADC128S052, ADC122S021 and ADC124S021 ADC chip Required properties: - - compatible: Should be "ti,adc128s052" or "ti,adc122s021" + - compatible: Should be "ti,adc128s052", "ti,adc122s021" or "ti,adc124s021" - reg: spi chip select number for the device - vref-supply: The regulator supply for ADC reference voltage diff --git a/Documentation/devicetree/bindings/iio/adc/ti-ads8688.txt b/Documentation/devicetree/bindings/iio/adc/ti-ads8688.txt new file mode 100644 index 000000000000..a02337d7efa4 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/ti-ads8688.txt @@ -0,0 +1,20 @@ +* Texas Instruments' ADS8684 and ADS8688 ADC chip + +Required properties: + - compatible: Should be "ti,ads8684" or "ti,ads8688" + - reg: spi chip select number for the device + +Recommended properties: + - spi-max-frequency: Definition as per + Documentation/devicetree/bindings/spi/spi-bus.txt + +Optional properties: + - vref-supply: The regulator supply for ADC reference voltage + +Example: +adc@0 { + compatible = "ti,ads8688"; + reg = <0>; + vref-supply = <&vdd_supply>; + spi-max-frequency = <1000000>; +}; diff --git a/Documentation/devicetree/bindings/iio/health/max30100.txt b/Documentation/devicetree/bindings/iio/health/max30100.txt new file mode 100644 index 000000000000..f6fbac66ad06 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/health/max30100.txt @@ -0,0 +1,21 @@ +Maxim MAX30100 heart rate and pulse oximeter sensor + +* https://datasheets.maximintegrated.com/en/ds/MAX30100.pdf + +Required properties: + - compatible: must be "maxim,max30100" + - reg: the I2C address of the sensor + - interrupt-parent: should be the phandle for the interrupt controller + - interrupts: the sole interrupt generated by the device + + Refer to interrupt-controller/interrupts.txt for generic + interrupt client node bindings. + +Example: + +max30100@057 { + compatible = "maxim,max30100"; + reg = <57>; + interrupt-parent = <&gpio1>; + interrupts = <16 2>; +}; diff --git a/Documentation/devicetree/bindings/iio/light/us5182d.txt b/Documentation/devicetree/bindings/iio/light/us5182d.txt index 6f0a530144fd..a61979997f37 100644 --- a/Documentation/devicetree/bindings/iio/light/us5182d.txt +++ b/Documentation/devicetree/bindings/iio/light/us5182d.txt @@ -7,13 +7,24 @@ Required properties: Optional properties: - upisemi,glass-coef: glass attenuation factor - compensation factor of resolution 1000 for material transmittance. + - upisemi,dark-ths: array of 8 elements containing 16-bit thresholds (adc counts) corresponding to every scale. + - upisemi,upper-dark-gain: 8-bit dark gain compensation factor(4 int and 4 fractional bits - Q4.4) applied when light > threshold + - upisemi,lower-dark-gain: 8-bit dark gain compensation factor(4 int and 4 fractional bits - Q4.4) applied when light < threshold +- upisemi,continuous: This chip has two power modes: one-shot (chip takes one + measurement and then shuts itself down) and continuous ( + chip takes continuous measurements). The one-shot mode is + more power-friendly but the continuous mode may be more + reliable. If this property is specified the continuous + mode will be used instead of the default one-shot one for + raw reads. + If the optional properties are not specified these factors will default to the values in the below example. The glass-coef defaults to no compensation for the covering material. diff --git a/Documentation/devicetree/bindings/iio/st-sensors.txt b/Documentation/devicetree/bindings/iio/st-sensors.txt index d3ccdb190c53..d4b87cc1e446 100644 --- a/Documentation/devicetree/bindings/iio/st-sensors.txt +++ b/Documentation/devicetree/bindings/iio/st-sensors.txt @@ -36,6 +36,7 @@ Accelerometers: - st,lsm303dlm-accel - st,lsm330-accel - st,lsm303agr-accel +- st,lis2dh12-accel Gyroscopes: - st,l3g4200d-gyro diff --git a/Documentation/devicetree/bindings/staging/ion/hi6220-ion.txt b/Documentation/devicetree/bindings/staging/ion/hi6220-ion.txt new file mode 100644 index 000000000000..c59e27c632c1 --- /dev/null +++ b/Documentation/devicetree/bindings/staging/ion/hi6220-ion.txt @@ -0,0 +1,31 @@ +Hi6220 SoC ION +=================================================================== +Required properties: +- compatible : "hisilicon,hi6220-ion" +- list of the ION heaps + - heap name : maybe heap_sys_user@0 + - heap id : id should be unique in the system. + - heap base : base ddr address of the heap,0 means that + it is dynamic. + - heap size : memory size and 0 means it is dynamic. + - heap type : the heap type of the heap, please also + see the define in ion.h(drivers/staging/android/uapi/ion.h) +------------------------------------------------------------------- +Example: + hi6220-ion { + compatible = "hisilicon,hi6220-ion"; + heap_sys_user@0 { + heap-name = "sys_user"; + heap-id = <0x0>; + heap-base = <0x0>; + heap-size = <0x0>; + heap-type = "ion_system"; + }; + heap_sys_contig@0 { + heap-name = "sys_contig"; + heap-id = <0x1>; + heap-base = <0x0>; + heap-size = <0x0>; + heap-type = "ion_system_contig"; + }; + }; diff --git a/Documentation/iio/iio_configfs.txt b/Documentation/iio/iio_configfs.txt new file mode 100644 index 000000000000..f0add35cd52e --- /dev/null +++ b/Documentation/iio/iio_configfs.txt @@ -0,0 +1,93 @@ +Industrial IIO configfs support + +1. Overview + +Configfs is a filesystem-based manager of kernel objects. IIO uses some +objects that could be easily configured using configfs (e.g.: devices, +triggers). + +See Documentation/filesystems/configfs/configfs.txt for more information +about how configfs works. + +2. Usage + +In order to use configfs support in IIO we need to select it at compile +time via CONFIG_IIO_CONFIGFS config option. + +Then, mount the configfs filesystem (usually under /config directory): + +$ mkdir /config +$ mount -t configfs none /config + +At this point, all default IIO groups will be created and can be accessed +under /config/iio. Next chapters will describe available IIO configuration +objects. + +3. Software triggers + +One of the IIO default configfs groups is the "triggers" group. It is +automagically accessible when the configfs is mounted and can be found +under /config/iio/triggers. + +IIO software triggers implementation offers support for creating multiple +trigger types. A new trigger type is usually implemented as a separate +kernel module following the interface in include/linux/iio/sw_trigger.h: + +/* + * drivers/iio/trigger/iio-trig-sample.c + * sample kernel module implementing a new trigger type + */ +#include <linux/iio/sw_trigger.h> + + +static struct iio_sw_trigger *iio_trig_sample_probe(const char *name) +{ + /* + * This allocates and registers an IIO trigger plus other + * trigger type specific initialization. + */ +} + +static int iio_trig_hrtimer_remove(struct iio_sw_trigger *swt) +{ + /* + * This undoes the actions in iio_trig_sample_probe + */ +} + +static const struct iio_sw_trigger_ops iio_trig_sample_ops = { + .probe = iio_trig_sample_probe, + .remove = iio_trig_sample_remove, +}; + +static struct iio_sw_trigger_type iio_trig_sample = { + .name = "trig-sample", + .owner = THIS_MODULE, + .ops = &iio_trig_sample_ops, +}; + +module_iio_sw_trigger_driver(iio_trig_sample); + +Each trigger type has its own directory under /config/iio/triggers. Loading +iio-trig-sample module will create 'trig-sample' trigger type directory +/config/iio/triggers/trig-sample. + +We support the following interrupt sources (trigger types): + * hrtimer, uses high resolution timers as interrupt source + +3.1 Hrtimer triggers creation and destruction + +Loading iio-trig-hrtimer module will register hrtimer trigger types allowing +users to create hrtimer triggers under /config/iio/triggers/hrtimer. + +e.g: + +$ mkdir /config/triggers/hrtimer/instance1 +$ rmdir /config/triggers/hrtimer/instance1 + +Each trigger can have one or more attributes specific to the trigger type. + +3.2 "hrtimer" trigger types attributes + +"hrtimer" trigger type doesn't have any configurable attribute from /config dir. +It does introduce the sampling_frequency attribute to trigger directory. diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig index 66792e707d74..505e921f0b19 100644 --- a/drivers/iio/Kconfig +++ b/drivers/iio/Kconfig @@ -22,6 +22,14 @@ if IIO_BUFFER source "drivers/iio/buffer/Kconfig" endif # IIO_BUFFER +config IIO_CONFIGFS + tristate "Enable IIO configuration via configfs" + select CONFIGFS_FS + help + This allows configuring various IIO bits through configfs + (e.g. software triggers). For more info see + Documentation/iio/iio_configfs.txt. + config IIO_TRIGGER bool "Enable triggered sampling support" help @@ -38,6 +46,14 @@ config IIO_CONSUMERS_PER_TRIGGER This value controls the maximum number of consumers that a given trigger may handle. Default is 2. +config IIO_SW_TRIGGER + tristate "Enable software triggers support" + select IIO_CONFIGFS + help + Provides IIO core support for software triggers. A software + trigger can be created via configfs or directly by a driver + using the API provided. + config IIO_TRIGGERED_EVENT tristate select IIO_TRIGGER @@ -50,8 +66,10 @@ source "drivers/iio/amplifiers/Kconfig" source "drivers/iio/chemical/Kconfig" source "drivers/iio/common/Kconfig" source "drivers/iio/dac/Kconfig" +source "drivers/iio/dummy/Kconfig" source "drivers/iio/frequency/Kconfig" source "drivers/iio/gyro/Kconfig" +source "drivers/iio/health/Kconfig" source "drivers/iio/humidity/Kconfig" source "drivers/iio/imu/Kconfig" source "drivers/iio/light/Kconfig" diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile index aeca7269fe44..20f649073462 100644 --- a/drivers/iio/Makefile +++ b/drivers/iio/Makefile @@ -7,6 +7,8 @@ industrialio-y := industrialio-core.o industrialio-event.o inkern.o industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o +obj-$(CONFIG_IIO_CONFIGFS) += industrialio-configfs.o +obj-$(CONFIG_IIO_SW_TRIGGER) += industrialio-sw-trigger.o obj-$(CONFIG_IIO_TRIGGERED_EVENT) += industrialio-triggered-event.o obj-y += accel/ @@ -16,8 +18,10 @@ obj-y += buffer/ obj-y += chemical/ obj-y += common/ obj-y += dac/ +obj-y += dummy/ obj-y += gyro/ obj-y += frequency/ +obj-y += health/ obj-y += humidity/ obj-y += imu/ obj-y += light/ diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index 969428dd6329..edc29b173f6c 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -64,7 +64,7 @@ config IIO_ST_ACCEL_3AXIS help Say yes here to build support for STMicroelectronics accelerometers: LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC, - LIS331DLH, LSM303DL, LSM303DLM, LSM330. + LIS331DLH, LSM303DL, LSM303DLM, LSM330, LIS2DH12. This driver can also be built as a module. If so, these modules will be created: @@ -107,6 +107,35 @@ config KXCJK1013 To compile this driver as a module, choose M here: the module will be called kxcjk-1013. +config MMA7455 + tristate + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + +config MMA7455_I2C + tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver" + depends on I2C + select MMA7455 + select REGMAP_I2C + help + Say yes here to build support for the Freescale MMA7455L and + MMA7456L 3-axis accelerometer. + + To compile this driver as a module, choose M here: the module + will be called mma7455_i2c. + +config MMA7455_SPI + tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver" + depends on SPI_MASTER + select MMA7455 + select REGMAP_SPI + help + Say yes here to build support for the Freescale MMA7455L and + MMA7456L 3-axis accelerometer. + + To compile this driver as a module, choose M here: the module + will be called mma7455_spi. + config MMA8452 tristate "Freescale MMA8452Q and similar Accelerometers Driver" depends on I2C @@ -158,6 +187,17 @@ config MXC4005 To compile this driver as a module, choose M. The module will be called mxc4005. +config MXC6255 + tristate "Memsic MXC6255 Orientation Sensing Accelerometer Driver" + depends on I2C + select REGMAP_I2C + help + Say yes here to build support for the Memsic MXC6255 Orientation + Sensing Accelerometer Driver. + + To compile this driver as a module, choose M here: the module will be + called mxc6255. + config STK8312 tristate "Sensortek STK8312 3-Axis Accelerometer Driver" depends on I2C diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index 7925f166e6e9..71b6794de885 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile @@ -10,6 +10,11 @@ obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o obj-$(CONFIG_KXSD9) += kxsd9.o + +obj-$(CONFIG_MMA7455) += mma7455_core.o +obj-$(CONFIG_MMA7455_I2C) += mma7455_i2c.o +obj-$(CONFIG_MMA7455_SPI) += mma7455_spi.o + obj-$(CONFIG_MMA8452) += mma8452.o obj-$(CONFIG_MMA9551_CORE) += mma9551_core.o @@ -17,6 +22,7 @@ obj-$(CONFIG_MMA9551) += mma9551.o obj-$(CONFIG_MMA9553) += mma9553.o obj-$(CONFIG_MXC4005) += mxc4005.o +obj-$(CONFIG_MXC6255) += mxc6255.o obj-$(CONFIG_STK8312) += stk8312.o obj-$(CONFIG_STK8BA50) += stk8ba50.o diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c index 2d33f1e821db..c73331f7782b 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -1623,24 +1623,22 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, } } - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(dev, "Unable to register iio device\n"); - goto err_trigger_unregister; - } - ret = pm_runtime_set_active(dev); if (ret) - goto err_iio_unregister; + goto err_trigger_unregister; pm_runtime_enable(dev); pm_runtime_set_autosuspend_delay(dev, BMC150_AUTO_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(dev); + ret = iio_device_register(indio_dev); + if (ret < 0) { + dev_err(dev, "Unable to register iio device\n"); + goto err_trigger_unregister; + } + return 0; -err_iio_unregister: - iio_device_unregister(indio_dev); err_trigger_unregister: bmc150_accel_unregister_triggers(data, BMC150_ACCEL_TRIGGERS - 1); err_buffer_cleanup: @@ -1655,12 +1653,12 @@ int bmc150_accel_core_remove(struct device *dev) struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmc150_accel_data *data = iio_priv(indio_dev); + iio_device_unregister(indio_dev); + pm_runtime_disable(data->dev); pm_runtime_set_suspended(data->dev); pm_runtime_put_noidle(data->dev); - iio_device_unregister(indio_dev); - bmc150_accel_unregister_triggers(data, BMC150_ACCEL_TRIGGERS - 1); iio_triggered_buffer_cleanup(indio_dev); diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c index 18c1b06684c1..edec1d099e91 100644 --- a/drivers/iio/accel/kxcjk-1013.c +++ b/drivers/iio/accel/kxcjk-1013.c @@ -1264,25 +1264,23 @@ static int kxcjk1013_probe(struct i2c_client *client, goto err_trigger_unregister; } - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&client->dev, "unable to register iio device\n"); - goto err_buffer_cleanup; - } - ret = pm_runtime_set_active(&client->dev); if (ret) - goto err_iio_unregister; + goto err_buffer_cleanup; pm_runtime_enable(&client->dev); pm_runtime_set_autosuspend_delay(&client->dev, KXCJK1013_SLEEP_DELAY_MS); pm_runtime_use_autosuspend(&client->dev); + ret = iio_device_register(indio_dev); + if (ret < 0) { + dev_err(&client->dev, "unable to register iio device\n"); + goto err_buffer_cleanup; + } + return 0; -err_iio_unregister: - iio_device_unregister(indio_dev); err_buffer_cleanup: if (data->dready_trig) iio_triggered_buffer_cleanup(indio_dev); @@ -1302,12 +1300,12 @@ static int kxcjk1013_remove(struct i2c_client *client) struct iio_dev *indio_dev = i2c_get_clientdata(client); struct kxcjk1013_data *data = iio_priv(indio_dev); + iio_device_unregister(indio_dev); + pm_runtime_disable(&client->dev); pm_runtime_set_suspended(&client->dev); pm_runtime_put_noidle(&client->dev); - iio_device_unregister(indio_dev); - if (data->dready_trig) { iio_triggered_buffer_cleanup(indio_dev); iio_trigger_unregister(data->dready_trig); diff --git a/drivers/iio/accel/mma7455.h b/drivers/iio/accel/mma7455.h new file mode 100644 index 000000000000..2b1152c53d4f --- /dev/null +++ b/drivers/iio/accel/mma7455.h @@ -0,0 +1,19 @@ +/* + * IIO accel driver for Freescale MMA7455L 3-axis 10-bit accelerometer + * Copyright 2015 Joachim Eastwood <manabian@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __MMA7455_H +#define __MMA7455_H + +extern const struct regmap_config mma7455_core_regmap; + +int mma7455_core_probe(struct device *dev, struct regmap *regmap, + const char *name); +int mma7455_core_remove(struct device *dev); + +#endif diff --git a/drivers/iio/accel/mma7455_core.c b/drivers/iio/accel/mma7455_core.c new file mode 100644 index 000000000000..c633cc2c0789 --- /dev/null +++ b/drivers/iio/accel/mma7455_core.c @@ -0,0 +1,311 @@ +/* + * IIO accel core driver for Freescale MMA7455L 3-axis 10-bit accelerometer + * Copyright 2015 Joachim Eastwood <manabian@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * UNSUPPORTED hardware features: + * - 8-bit mode with different scales + * - INT1/INT2 interrupts + * - Offset calibration + * - Events + */ + +#include <linux/delay.h> +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/buffer.h> +#include <linux/iio/trigger.h> +#include <linux/iio/trigger_consumer.h> +#include <linux/iio/triggered_buffer.h> +#include <linux/module.h> +#include <linux/regmap.h> + +#include "mma7455.h" + +#define MMA7455_REG_XOUTL 0x00 +#define MMA7455_REG_XOUTH 0x01 +#define MMA7455_REG_YOUTL 0x02 +#define MMA7455_REG_YOUTH 0x03 +#define MMA7455_REG_ZOUTL 0x04 +#define MMA7455_REG_ZOUTH 0x05 +#define MMA7455_REG_STATUS 0x09 +#define MMA7455_STATUS_DRDY BIT(0) +#define MMA7455_REG_WHOAMI 0x0f +#define MMA7455_WHOAMI_ID 0x55 +#define MMA7455_REG_MCTL 0x16 +#define MMA7455_MCTL_MODE_STANDBY 0x00 +#define MMA7455_MCTL_MODE_MEASURE 0x01 +#define MMA7455_REG_CTL1 0x18 +#define MMA7455_CTL1_DFBW_MASK BIT(7) +#define MMA7455_CTL1_DFBW_125HZ BIT(7) +#define MMA7455_CTL1_DFBW_62_5HZ 0 +#define MMA7455_REG_TW 0x1e + +/* + * When MMA7455 is used in 10-bit it has a fullscale of -8g + * corresponding to raw value -512. The userspace interface + * uses m/s^2 and we declare micro units. + * So scale factor is given by: + * g * 8 * 1e6 / 512 = 153228.90625, with g = 9.80665 + */ +#define MMA7455_10BIT_SCALE 153229 + +struct mma7455_data { + struct regmap *regmap; + struct device *dev; +}; + +static int mma7455_drdy(struct mma7455_data *mma7455) +{ + unsigned int reg; + int tries = 3; + int ret; + + while (tries-- > 0) { + ret = regmap_read(mma7455->regmap, MMA7455_REG_STATUS, ®); + if (ret) + return ret; + + if (reg & MMA7455_STATUS_DRDY) + return 0; + + msleep(20); + } + + dev_warn(mma7455->dev, "data not ready\n"); + + return -EIO; +} + +static irqreturn_t mma7455_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct mma7455_data *mma7455 = iio_priv(indio_dev); + u8 buf[16]; /* 3 x 16-bit channels + padding + ts */ + int ret; + + ret = mma7455_drdy(mma7455); + if (ret) + goto done; + + ret = regmap_bulk_read(mma7455->regmap, MMA7455_REG_XOUTL, buf, + sizeof(__le16) * 3); + if (ret) + goto done; + + iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); + +done: + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + +static int mma7455_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct mma7455_data *mma7455 = iio_priv(indio_dev); + unsigned int reg; + __le16 data; + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + if (iio_buffer_enabled(indio_dev)) + return -EBUSY; + + ret = mma7455_drdy(mma7455); + if (ret) + return ret; + + ret = regmap_bulk_read(mma7455->regmap, chan->address, &data, + sizeof(data)); + if (ret) + return ret; + + *val = sign_extend32(le16_to_cpu(data), 9); + + return IIO_VAL_INT; + + case IIO_CHAN_INFO_SCALE: + *val = 0; + *val2 = MMA7455_10BIT_SCALE; + + return IIO_VAL_INT_PLUS_MICRO; + + case IIO_CHAN_INFO_SAMP_FREQ: + ret = regmap_read(mma7455->regmap, MMA7455_REG_CTL1, ®); + if (ret) + return ret; + + if (reg & MMA7455_CTL1_DFBW_MASK) + *val = 250; + else + *val = 125; + + return IIO_VAL_INT; + } + + return -EINVAL; +} + +static int mma7455_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct mma7455_data *mma7455 = iio_priv(indio_dev); + int i; + + switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: + if (val == 250 && val2 == 0) + i = MMA7455_CTL1_DFBW_125HZ; + else if (val == 125 && val2 == 0) + i = MMA7455_CTL1_DFBW_62_5HZ; + else + return -EINVAL; + + return regmap_update_bits(mma7455->regmap, MMA7455_REG_CTL1, + MMA7455_CTL1_DFBW_MASK, i); + + case IIO_CHAN_INFO_SCALE: + /* In 10-bit mode there is only one scale available */ + if (val == 0 && val2 == MMA7455_10BIT_SCALE) + return 0; + break; + } + + return -EINVAL; +} + +static IIO_CONST_ATTR(sampling_frequency_available, "125 250"); + +static struct attribute *mma7455_attributes[] = { + &iio_const_attr_sampling_frequency_available.dev_attr.attr, + NULL +}; + +static const struct attribute_group mma7455_group = { + .attrs = mma7455_attributes, +}; + +static const struct iio_info mma7455_info = { + .attrs = &mma7455_group, + .read_raw = mma7455_read_raw, + .write_raw = mma7455_write_raw, + .driver_module = THIS_MODULE, +}; + +#define MMA7455_CHANNEL(axis, idx) { \ + .type = IIO_ACCEL, \ + .modified = 1, \ + .address = MMA7455_REG_##axis##OUTL,\ + .channel2 = IIO_MOD_##axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = idx, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 10, \ + .storagebits = 16, \ + .endianness = IIO_LE, \ + }, \ +} + +static const struct iio_chan_spec mma7455_channels[] = { + MMA7455_CHANNEL(X, 0), + MMA7455_CHANNEL(Y, 1), + MMA7455_CHANNEL(Z, 2), + IIO_CHAN_SOFT_TIMESTAMP(3), +}; + +static const unsigned long mma7455_scan_masks[] = {0x7, 0}; + +const struct regmap_config mma7455_core_regmap = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MMA7455_REG_TW, +}; +EXPORT_SYMBOL_GPL(mma7455_core_regmap); + +int mma7455_core_probe(struct device *dev, struct regmap *regmap, + const char *name) +{ + struct mma7455_data *mma7455; + struct iio_dev *indio_dev; + unsigned int reg; + int ret; + + ret = regmap_read(regmap, MMA7455_REG_WHOAMI, ®); + if (ret) { + dev_err(dev, "unable to read reg\n"); + return ret; + } + + if (reg != MMA7455_WHOAMI_ID) { + dev_err(dev, "device id mismatch\n"); + return -ENODEV; + } + + indio_dev = devm_iio_device_alloc(dev, sizeof(*mma7455)); + if (!indio_dev) + return -ENOMEM; + + dev_set_drvdata(dev, indio_dev); + mma7455 = iio_priv(indio_dev); + mma7455->regmap = regmap; + mma7455->dev = dev; + + indio_dev->info = &mma7455_info; + indio_dev->name = name; + indio_dev->dev.parent = dev; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = mma7455_channels; + indio_dev->num_channels = ARRAY_SIZE(mma7455_channels); + indio_dev->available_scan_masks = mma7455_scan_masks; + + regmap_write(mma7455->regmap, MMA7455_REG_MCTL, + MMA7455_MCTL_MODE_MEASURE); + + ret = iio_triggered_buffer_setup(indio_dev, NULL, + mma7455_trigger_handler, NULL); + if (ret) { + dev_err(dev, "unable to setup triggered buffer\n"); + return ret; + } + + ret = iio_device_register(indio_dev); + if (ret) { + dev_err(dev, "unable to register device\n"); + iio_triggered_buffer_cleanup(indio_dev); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(mma7455_core_probe); + +int mma7455_core_remove(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct mma7455_data *mma7455 = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + iio_triggered_buffer_cleanup(indio_dev); + + regmap_write(mma7455->regmap, MMA7455_REG_MCTL, + MMA7455_MCTL_MODE_STANDBY); + + return 0; +} +EXPORT_SYMBOL_GPL(mma7455_core_remove); + +MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>"); +MODULE_DESCRIPTION("Freescale MMA7455L core accelerometer driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/accel/mma7455_i2c.c b/drivers/iio/accel/mma7455_i2c.c new file mode 100644 index 000000000000..3cab5fb4a3c4 --- /dev/null +++ b/drivers/iio/accel/mma7455_i2c.c @@ -0,0 +1,56 @@ +/* + * IIO accel I2C driver for Freescale MMA7455L 3-axis 10-bit accelerometer + * Copyright 2015 Joachim Eastwood <manabian@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/regmap.h> + +#include "mma7455.h" + +static int mma7455_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ + struct regmap *regmap; + const char *name = NULL; + + regmap = devm_regmap_init_i2c(i2c, &mma7455_core_regmap); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + if (id) + name = id->name; + + return mma7455_core_probe(&i2c->dev, regmap, name); +} + +static int mma7455_i2c_remove(struct i2c_client *i2c) +{ + return mma7455_core_remove(&i2c->dev); +} + +static const struct i2c_device_id mma7455_i2c_ids[] = { + { "mma7455", 0 }, + { "mma7456", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, mma7455_i2c_ids); + +static struct i2c_driver mma7455_i2c_driver = { + .probe = mma7455_i2c_probe, + .remove = mma7455_i2c_remove, + .id_table = mma7455_i2c_ids, + .driver = { + .name = "mma7455-i2c", + }, +}; +module_i2c_driver(mma7455_i2c_driver); + +MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>"); +MODULE_DESCRIPTION("Freescale MMA7455L I2C accelerometer driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/accel/mma7455_spi.c b/drivers/iio/accel/mma7455_spi.c new file mode 100644 index 000000000000..79df8f27cf99 --- /dev/null +++ b/drivers/iio/accel/mma7455_spi.c @@ -0,0 +1,52 @@ +/* + * IIO accel SPI driver for Freescale MMA7455L 3-axis 10-bit accelerometer + * Copyright 2015 Joachim Eastwood <manabian@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <linux/module.h> +#include <linux/regmap.h> +#include <linux/spi/spi.h> + +#include "mma7455.h" + +static int mma7455_spi_probe(struct spi_device *spi) +{ + const struct spi_device_id *id = spi_get_device_id(spi); + struct regmap *regmap; + + regmap = devm_regmap_init_spi(spi, &mma7455_core_regmap); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + return mma7455_core_probe(&spi->dev, regmap, id->name); +} + +static int mma7455_spi_remove(struct spi_device *spi) +{ + return mma7455_core_remove(&spi->dev); +} + +static const struct spi_device_id mma7455_spi_ids[] = { + { "mma7455", 0 }, + { "mma7456", 0 }, + { } +}; +MODULE_DEVICE_TABLE(spi, mma7455_spi_ids); + +static struct spi_driver mma7455_spi_driver = { + .probe = mma7455_spi_probe, + .remove = mma7455_spi_remove, + .id_table = mma7455_spi_ids, + .driver = { + .name = "mma7455-spi", + }, +}; +module_spi_driver(mma7455_spi_driver); + +MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>"); +MODULE_DESCRIPTION("Freescale MMA7455L SPI accelerometer driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c index 1eccc2dcf14c..ccc632a7cf01 100644 --- a/drivers/iio/accel/mma8452.c +++ b/drivers/iio/accel/mma8452.c @@ -29,6 +29,7 @@ #include <linux/iio/events.h> #include <linux/delay.h> #include <linux/of_device.h> +#include <linux/of_irq.h> #define MMA8452_STATUS 0x00 #define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0)) @@ -57,7 +58,6 @@ #define MMA8452_FF_MT_COUNT 0x18 #define MMA8452_TRANSIENT_CFG 0x1d #define MMA8452_TRANSIENT_CFG_HPF_BYP BIT(0) -#define MMA8452_TRANSIENT_CFG_CHAN(chan) BIT(chan + 1) #define MMA8452_TRANSIENT_CFG_ELE BIT(4) #define MMA8452_TRANSIENT_SRC 0x1e #define MMA8452_TRANSIENT_SRC_XTRANSE BIT(1) @@ -143,6 +143,13 @@ struct mma_chip_info { u8 ev_count; }; +enum { + idx_x, + idx_y, + idx_z, + idx_ts, +}; + static int mma8452_drdy(struct mma8452_data *data) { int tries = 150; @@ -816,31 +823,31 @@ static struct attribute_group mma8452_event_attribute_group = { } static const struct iio_chan_spec mma8452_channels[] = { - MMA8452_CHANNEL(X, 0, 12), - MMA8452_CHANNEL(Y, 1, 12), - MMA8452_CHANNEL(Z, 2, 12), - IIO_CHAN_SOFT_TIMESTAMP(3), + MMA8452_CHANNEL(X, idx_x, 12), + MMA8452_CHANNEL(Y, idx_y, 12), + MMA8452_CHANNEL(Z, idx_z, 12), + IIO_CHAN_SOFT_TIMESTAMP(idx_ts), }; static const struct iio_chan_spec mma8453_channels[] = { - MMA8452_CHANNEL(X, 0, 10), - MMA8452_CHANNEL(Y, 1, 10), - MMA8452_CHANNEL(Z, 2, 10), - IIO_CHAN_SOFT_TIMESTAMP(3), + MMA8452_CHANNEL(X, idx_x, 10), + MMA8452_CHANNEL(Y, idx_y, 10), + MMA8452_CHANNEL(Z, idx_z, 10), + IIO_CHAN_SOFT_TIMESTAMP(idx_ts), }; static const struct iio_chan_spec mma8652_channels[] = { - MMA8652_CHANNEL(X, 0, 12), - MMA8652_CHANNEL(Y, 1, 12), - MMA8652_CHANNEL(Z, 2, 12), - IIO_CHAN_SOFT_TIMESTAMP(3), + MMA8652_CHANNEL(X, idx_x, 12), + MMA8652_CHANNEL(Y, idx_y, 12), + MMA8652_CHANNEL(Z, idx_z, 12), + IIO_CHAN_SOFT_TIMESTAMP(idx_ts), }; static const struct iio_chan_spec mma8653_channels[] = { - MMA8652_CHANNEL(X, 0, 10), - MMA8652_CHANNEL(Y, 1, 10), - MMA8652_CHANNEL(Z, 2, 10), - IIO_CHAN_SOFT_TIMESTAMP(3), + MMA8652_CHANNEL(X, idx_x, 10), + MMA8652_CHANNEL(Y, idx_y, 10), + MMA8652_CHANNEL(Z, idx_z, 10), + IIO_CHAN_SOFT_TIMESTAMP(idx_ts), }; enum { @@ -1130,13 +1137,21 @@ static int mma8452_probe(struct i2c_client *client, MMA8452_INT_FF_MT; int enabled_interrupts = MMA8452_INT_TRANS | MMA8452_INT_FF_MT; + int irq2; - /* Assume wired to INT1 pin */ - ret = i2c_smbus_write_byte_data(client, - MMA8452_CTRL_REG5, - supported_interrupts); - if (ret < 0) - return ret; + irq2 = of_irq_get_byname(client->dev.of_node, "INT2"); + + if (irq2 == client->irq) { + dev_dbg(&client->dev, "using interrupt line INT2\n"); + } else { + ret = i2c_smbus_write_byte_data(client, + MMA8452_CTRL_REG5, + supported_interrupts); + if (ret < 0) + return ret; + + dev_dbg(&client->dev, "using interrupt line INT1\n"); + } ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG4, diff --git a/drivers/iio/accel/mma9551.c b/drivers/iio/accel/mma9551.c index 7db7cc0bf362..d899a4d4307f 100644 --- a/drivers/iio/accel/mma9551.c +++ b/drivers/iio/accel/mma9551.c @@ -495,25 +495,23 @@ static int mma9551_probe(struct i2c_client *client, if (ret < 0) goto out_poweroff; - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&client->dev, "unable to register iio device\n"); - goto out_poweroff; - } - ret = pm_runtime_set_active(&client->dev); if (ret < 0) - goto out_iio_unregister; + goto out_poweroff; pm_runtime_enable(&client->dev); pm_runtime_set_autosuspend_delay(&client->dev, MMA9551_AUTO_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(&client->dev); + ret = iio_device_register(indio_dev); + if (ret < 0) { + dev_err(&client->dev, "unable to register iio device\n"); + goto out_poweroff; + } + return 0; -out_iio_unregister: - iio_device_unregister(indio_dev); out_poweroff: mma9551_set_device_state(client, false); @@ -525,11 +523,12 @@ static int mma9551_remove(struct i2c_client *client) struct iio_dev *indio_dev = i2c_get_clientdata(client); struct mma9551_data *data = iio_priv(indio_dev); + iio_device_unregister(indio_dev); + pm_runtime_disable(&client->dev); pm_runtime_set_suspended(&client->dev); pm_runtime_put_noidle(&client->dev); - iio_device_unregister(indio_dev); mutex_lock(&data->mutex); mma9551_set_device_state(data->client, false); mutex_unlock(&data->mutex); diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c index 9408ef3add58..fa7d36217c4b 100644 --- a/drivers/iio/accel/mma9553.c +++ b/drivers/iio/accel/mma9553.c @@ -1133,27 +1133,24 @@ static int mma9553_probe(struct i2c_client *client, } } - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&client->dev, "unable to register iio device\n"); - goto out_poweroff; - } - ret = pm_runtime_set_active(&client->dev); if (ret < 0) - goto out_iio_unregister; + goto out_poweroff; pm_runtime_enable(&client->dev); pm_runtime_set_autosuspend_delay(&client->dev, MMA9551_AUTO_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(&client->dev); - dev_dbg(&indio_dev->dev, "Registered device %s\n", name); + ret = iio_device_register(indio_dev); + if (ret < 0) { + dev_err(&client->dev, "unable to register iio device\n"); + goto out_poweroff; + } + dev_dbg(&indio_dev->dev, "Registered device %s\n", name); return 0; -out_iio_unregister: - iio_device_unregister(indio_dev); out_poweroff: mma9551_set_device_state(client, false); return ret; @@ -1164,11 +1161,12 @@ static int mma9553_remove(struct i2c_client *client) struct iio_dev *indio_dev = i2c_get_clientdata(client); struct mma9553_data *data = iio_priv(indio_dev); + iio_device_unregister(indio_dev); + pm_runtime_disable(&client->dev); pm_runtime_set_suspended(&client->dev); pm_runtime_put_noidle(&client->dev); - iio_device_unregister(indio_dev); mutex_lock(&data->mutex); mma9551_set_device_state(data->client, false); mutex_unlock(&data->mutex); diff --git a/drivers/iio/accel/mxc6255.c b/drivers/iio/accel/mxc6255.c new file mode 100644 index 000000000000..97ccde722e7b --- /dev/null +++ b/drivers/iio/accel/mxc6255.c @@ -0,0 +1,198 @@ +/* + * MXC6255 - MEMSIC orientation sensing accelerometer + * + * Copyright (c) 2015, Intel Corporation. + * + * This file is subject to the terms and conditions of version 2 of + * the GNU General Public License. See the file COPYING in the main + * directory of this archive for more details. + * + * IIO driver for MXC6255 (7-bit I2C slave address 0x15). + */ + +#include <linux/module.h> +#include <linux/i2c.h> +#include <linux/init.h> +#include <linux/iio/iio.h> +#include <linux/delay.h> +#include <linux/acpi.h> +#include <linux/regmap.h> +#include <linux/iio/sysfs.h> + +#define MXC6255_DRV_NAME "mxc6255" +#define MXC6255_REGMAP_NAME "mxc6255_regmap" + +#define MXC6255_REG_XOUT 0x00 +#define MXC6255_REG_YOUT 0x01 +#define MXC6255_REG_CHIP_ID 0x08 + +#define MXC6255_CHIP_ID 0x05 + +/* + * MXC6255 has only one measurement range: +/- 2G. + * The acceleration output is an 8-bit value. + * + * Scale is calculated as follows: + * (2 + 2) * 9.80665 / (2^8 - 1) = 0.153829 + * + * Scale value for +/- 2G measurement range + */ +#define MXC6255_SCALE 153829 + +enum mxc6255_axis { + AXIS_X, + AXIS_Y, +}; + +struct mxc6255_data { + struct i2c_client *client; + struct regmap *regmap; +}; + +static int mxc6255_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct mxc6255_data *data = iio_priv(indio_dev); + unsigned int reg; + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = regmap_read(data->regmap, chan->address, ®); + if (ret < 0) { + dev_err(&data->client->dev, + "Error reading reg %lu\n", chan->address); + return ret; + } + + *val = sign_extend32(reg, 7); + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 0; + *val2 = MXC6255_SCALE; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } +} + +static const struct iio_info mxc6255_info = { + .driver_module = THIS_MODULE, + .read_raw = mxc6255_read_raw, +}; + +#define MXC6255_CHANNEL(_axis, reg) { \ + .type = IIO_ACCEL, \ + .modified = 1, \ + .channel2 = IIO_MOD_##_axis, \ + .address = reg, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ +} + +static const struct iio_chan_spec mxc6255_channels[] = { + MXC6255_CHANNEL(X, MXC6255_REG_XOUT), + MXC6255_CHANNEL(Y, MXC6255_REG_YOUT), +}; + +static bool mxc6255_is_readable_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case MXC6255_REG_XOUT: + case MXC6255_REG_YOUT: + case MXC6255_REG_CHIP_ID: + return true; + default: + return false; + } +} + +static const struct regmap_config mxc6255_regmap_config = { + .name = MXC6255_REGMAP_NAME, + + .reg_bits = 8, + .val_bits = 8, + + .readable_reg = mxc6255_is_readable_reg, +}; + +static int mxc6255_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct mxc6255_data *data; + struct iio_dev *indio_dev; + struct regmap *regmap; + unsigned int chip_id; + int ret; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + regmap = devm_regmap_init_i2c(client, &mxc6255_regmap_config); + if (IS_ERR(regmap)) { + dev_err(&client->dev, "Error initializing regmap\n"); + return PTR_ERR(regmap); + } + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->client = client; + data->regmap = regmap; + + indio_dev->name = MXC6255_DRV_NAME; + indio_dev->dev.parent = &client->dev; + indio_dev->channels = mxc6255_channels; + indio_dev->num_channels = ARRAY_SIZE(mxc6255_channels); + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &mxc6255_info; + + ret = regmap_read(data->regmap, MXC6255_REG_CHIP_ID, &chip_id); + if (ret < 0) { + dev_err(&client->dev, "Error reading chip id %d\n", ret); + return ret; + } + + if (chip_id != MXC6255_CHIP_ID) { + dev_err(&client->dev, "Invalid chip id %x\n", chip_id); + return -ENODEV; + } + + dev_dbg(&client->dev, "Chip id %x\n", chip_id); + + ret = devm_iio_device_register(&client->dev, indio_dev); + if (ret < 0) { + dev_err(&client->dev, "Could not register IIO device\n"); + return ret; + } + + return 0; +} + +static const struct acpi_device_id mxc6255_acpi_match[] = { + {"MXC6255", 0}, + { } +}; +MODULE_DEVICE_TABLE(acpi, mxc6255_acpi_match); + +static const struct i2c_device_id mxc6255_id[] = { + {"mxc6255", 0}, + { } +}; +MODULE_DEVICE_TABLE(i2c, mxc6255_id); + +static struct i2c_driver mxc6255_driver = { + .driver = { + .name = MXC6255_DRV_NAME, + .acpi_match_table = ACPI_PTR(mxc6255_acpi_match), + }, + .probe = mxc6255_probe, + .id_table = mxc6255_id, +}; + +module_i2c_driver(mxc6255_driver); + +MODULE_AUTHOR("Teodora Baluta <teodora.baluta@intel.com>"); +MODULE_DESCRIPTION("MEMSIC MXC6255 orientation sensing accelerometer driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h index 468f21fa2950..5d4a1897b293 100644 --- a/drivers/iio/accel/st_accel.h +++ b/drivers/iio/accel/st_accel.h @@ -27,6 +27,7 @@ #define LSM303DLM_ACCEL_DEV_NAME "lsm303dlm_accel" #define LSM330_ACCEL_DEV_NAME "lsm330_accel" #define LSM303AGR_ACCEL_DEV_NAME "lsm303agr_accel" +#define LIS2DH12_ACCEL_DEV_NAME "lis2dh12_accel" /** * struct st_sensors_platform_data - default accel platform data diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index 197a08b4e2f3..70f042797f15 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -232,6 +232,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { [3] = LSM330DL_ACCEL_DEV_NAME, [4] = LSM330DLC_ACCEL_DEV_NAME, [5] = LSM303AGR_ACCEL_DEV_NAME, + [6] = LIS2DH12_ACCEL_DEV_NAME, }, .ch = (struct iio_chan_spec *)st_accel_12bit_channels, .odr = { diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c index 8b9cc84fd44f..294a32f89367 100644 --- a/drivers/iio/accel/st_accel_i2c.c +++ b/drivers/iio/accel/st_accel_i2c.c @@ -72,6 +72,10 @@ static const struct of_device_id st_accel_of_match[] = { .compatible = "st,lsm303agr-accel", .data = LSM303AGR_ACCEL_DEV_NAME, }, + { + .compatible = "st,lis2dh12-accel", + .data = LIS2DH12_ACCEL_DEV_NAME, + }, {}, }; MODULE_DEVICE_TABLE(of, st_accel_of_match); @@ -121,6 +125,7 @@ static const struct i2c_device_id st_accel_id_table[] = { { LSM303DLM_ACCEL_DEV_NAME }, { LSM330_ACCEL_DEV_NAME }, { LSM303AGR_ACCEL_DEV_NAME }, + { LIS2DH12_ACCEL_DEV_NAME }, {}, }; MODULE_DEVICE_TABLE(i2c, st_accel_id_table); diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c index f71b0d391272..fcd5847a3fd3 100644 --- a/drivers/iio/accel/st_accel_spi.c +++ b/drivers/iio/accel/st_accel_spi.c @@ -58,6 +58,7 @@ static const struct spi_device_id st_accel_id_table[] = { { LSM303DLM_ACCEL_DEV_NAME }, { LSM330_ACCEL_DEV_NAME }, { LSM303AGR_ACCEL_DEV_NAME }, + { LIS2DH12_ACCEL_DEV_NAME }, {}, }; MODULE_DEVICE_TABLE(spi, st_accel_id_table); diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 7868c744fd4b..605ff42c4631 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -194,6 +194,25 @@ config HI8435 This driver can also be built as a module. If so, the module will be called hi8435. +config INA2XX_ADC + tristate "Texas Instruments INA2xx Power Monitors IIO driver" + depends on I2C && !SENSORS_INA2XX + select REGMAP_I2C + select IIO_BUFFER + select IIO_KFIFO_BUF + help + Say yes here to build support for TI INA2xx family of Power Monitors. + This driver is mutually exclusive with the HWMON version. + +config IMX7D_ADC + tristate "IMX7D ADC driver" + depends on ARCH_MXC || COMPILE_TEST + help + Say yes here to build support for IMX7D ADC. + + This driver can also be built as a module. If so, the module will be + called imx7d_adc. + config LP8788_ADC tristate "LP8788 ADC driver" depends on MFD_LP8788 @@ -275,6 +294,14 @@ config NAU7802 To compile this driver as a module, choose M here: the module will be called nau7802. +config PALMAS_GPADC + tristate "TI Palmas General Purpose ADC" + depends on MFD_PALMAS + help + Palmas series pmic chip by Texas Instruments (twl6035/6037) + is used in smartphones and tablets and supports a 16 channel + general purpose ADC. + config QCOM_SPMI_IADC tristate "Qualcomm SPMI PMIC current ADC" depends on SPMI @@ -324,15 +351,25 @@ config TI_ADC081C called ti-adc081c. config TI_ADC128S052 - tristate "Texas Instruments ADC128S052/ADC122S021" + tristate "Texas Instruments ADC128S052/ADC122S021/ADC124S021" depends on SPI help - If you say yes here you get support for Texas Instruments ADC128S052 - and ADC122S021 chips. + If you say yes here you get support for Texas Instruments ADC128S052, + ADC122S021 and ADC124S021 chips. This driver can also be built as a module. If so, the module will be called ti-adc128s052. +config TI_ADS8688 + tristate "Texas Instruments ADS8688" + depends on SPI && OF + help + If you say yes here you get support for Texas Instruments ADS8684 and + and ADS8688 ADC chips + + This driver can also be built as a module. If so, the module will be + called ti-ads8688. + config TI_AM335X_ADC tristate "TI's AM335X ADC driver" depends on MFD_TI_AM335X_TSCADC diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 99b37a963a1e..6435780e9b71 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -20,6 +20,8 @@ obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o obj-$(CONFIG_HI8435) += hi8435.o +obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o +obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o obj-$(CONFIG_MAX1027) += max1027.o obj-$(CONFIG_MAX1363) += max1363.o @@ -27,11 +29,13 @@ obj-$(CONFIG_MCP320X) += mcp320x.o obj-$(CONFIG_MCP3422) += mcp3422.o obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o obj-$(CONFIG_NAU7802) += nau7802.o +obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o +obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c index 4d960d3b93c0..7b07bb651671 100644 --- a/drivers/iio/adc/ad7793.c +++ b/drivers/iio/adc/ad7793.c @@ -478,10 +478,9 @@ static int ad7793_read_raw(struct iio_dev *indio_dev, *val2 = st-> scale_avail[(st->conf >> 8) & 0x7][1]; return IIO_VAL_INT_PLUS_NANO; - } else { - /* 1170mV / 2^23 * 6 */ - scale_uv = (1170ULL * 1000000000ULL * 6ULL); } + /* 1170mV / 2^23 * 6 */ + scale_uv = (1170ULL * 1000000000ULL * 6ULL); break; case IIO_TEMP: /* 1170mV / 0.81 mV/C / 2^23 */ diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c index 7b40925dd4ff..f284cd6a93d6 100644 --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c @@ -742,7 +742,7 @@ static int at91_adc_of_get_resolution(struct at91_adc_state *st, return count; } - resolutions = kmalloc(count * sizeof(*resolutions), GFP_KERNEL); + resolutions = kmalloc_array(count, sizeof(*resolutions), GFP_KERNEL); if (!resolutions) return -ENOMEM; diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c new file mode 100644 index 000000000000..e2241ee94783 --- /dev/null +++ b/drivers/iio/adc/imx7d_adc.c @@ -0,0 +1,609 @@ +/* + * Freescale i.MX7D ADC driver + * + * Copyright (C) 2015 Freescale Semiconductor, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include <linux/clk.h> +#include <linux/completion.h> +#include <linux/err.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/regulator/consumer.h> + +#include <linux/iio/iio.h> +#include <linux/iio/driver.h> +#include <linux/iio/sysfs.h> + +/* ADC register */ +#define IMX7D_REG_ADC_CH_A_CFG1 0x00 +#define IMX7D_REG_ADC_CH_A_CFG2 0x10 +#define IMX7D_REG_ADC_CH_B_CFG1 0x20 +#define IMX7D_REG_ADC_CH_B_CFG2 0x30 +#define IMX7D_REG_ADC_CH_C_CFG1 0x40 +#define IMX7D_REG_ADC_CH_C_CFG2 0x50 +#define IMX7D_REG_ADC_CH_D_CFG1 0x60 +#define IMX7D_REG_ADC_CH_D_CFG2 0x70 +#define IMX7D_REG_ADC_CH_SW_CFG 0x80 +#define IMX7D_REG_ADC_TIMER_UNIT 0x90 +#define IMX7D_REG_ADC_DMA_FIFO 0xa0 +#define IMX7D_REG_ADC_FIFO_STATUS 0xb0 +#define IMX7D_REG_ADC_INT_SIG_EN 0xc0 +#define IMX7D_REG_ADC_INT_EN 0xd0 +#define IMX7D_REG_ADC_INT_STATUS 0xe0 +#define IMX7D_REG_ADC_CHA_B_CNV_RSLT 0xf0 +#define IMX7D_REG_ADC_CHC_D_CNV_RSLT 0x100 +#define IMX7D_REG_ADC_CH_SW_CNV_RSLT 0x110 +#define IMX7D_REG_ADC_DMA_FIFO_DAT 0x120 +#define IMX7D_REG_ADC_ADC_CFG 0x130 + +#define IMX7D_REG_ADC_CHANNEL_CFG2_BASE 0x10 +#define IMX7D_EACH_CHANNEL_REG_OFFSET 0x20 + +#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_EN (0x1 << 31) +#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SINGLE BIT(30) +#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_AVG_EN BIT(29) +#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SEL(x) ((x) << 24) + +#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_4 (0x0 << 12) +#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_8 (0x1 << 12) +#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_16 (0x2 << 12) +#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_32 (0x3 << 12) + +#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_4 (0x0 << 29) +#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_8 (0x1 << 29) +#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_16 (0x2 << 29) +#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_32 (0x3 << 29) +#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_64 (0x4 << 29) +#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_128 (0x5 << 29) + +#define IMX7D_REG_ADC_ADC_CFG_ADC_CLK_DOWN BIT(31) +#define IMX7D_REG_ADC_ADC_CFG_ADC_POWER_DOWN BIT(1) +#define IMX7D_REG_ADC_ADC_CFG_ADC_EN BIT(0) + +#define IMX7D_REG_ADC_INT_CHA_COV_INT_EN BIT(8) +#define IMX7D_REG_ADC_INT_CHB_COV_INT_EN BIT(9) +#define IMX7D_REG_ADC_INT_CHC_COV_INT_EN BIT(10) +#define IMX7D_REG_ADC_INT_CHD_COV_INT_EN BIT(11) +#define IMX7D_REG_ADC_INT_CHANNEL_INT_EN \ + (IMX7D_REG_ADC_INT_CHA_COV_INT_EN | \ + IMX7D_REG_ADC_INT_CHB_COV_INT_EN | \ + IMX7D_REG_ADC_INT_CHC_COV_INT_EN | \ + IMX7D_REG_ADC_INT_CHD_COV_INT_EN) +#define IMX7D_REG_ADC_INT_STATUS_CHANNEL_INT_STATUS 0xf00 +#define IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT 0xf0000 + +#define IMX7D_ADC_TIMEOUT msecs_to_jiffies(100) + +enum imx7d_adc_clk_pre_div { + IMX7D_ADC_ANALOG_CLK_PRE_DIV_4, + IMX7D_ADC_ANALOG_CLK_PRE_DIV_8, + IMX7D_ADC_ANALOG_CLK_PRE_DIV_16, + IMX7D_ADC_ANALOG_CLK_PRE_DIV_32, + IMX7D_ADC_ANALOG_CLK_PRE_DIV_64, + IMX7D_ADC_ANALOG_CLK_PRE_DIV_128, +}; + +enum imx7d_adc_average_num { + IMX7D_ADC_AVERAGE_NUM_4, + IMX7D_ADC_AVERAGE_NUM_8, + IMX7D_ADC_AVERAGE_NUM_16, + IMX7D_ADC_AVERAGE_NUM_32, +}; + +struct imx7d_adc_feature { + enum imx7d_adc_clk_pre_div clk_pre_div; + enum imx7d_adc_average_num avg_num; + + u32 core_time_unit; /* impact the sample rate */ + + bool average_en; +}; + +struct imx7d_adc { + struct device *dev; + void __iomem *regs; + struct clk *clk; + + u32 vref_uv; + u32 value; + u32 channel; + u32 pre_div_num; + + struct regulator *vref; + struct imx7d_adc_feature adc_feature; + + struct completion completion; +}; + +struct imx7d_adc_analogue_core_clk { + u32 pre_div; + u32 reg_config; +}; + +#define IMX7D_ADC_ANALOGUE_CLK_CONFIG(_pre_div, _reg_conf) { \ + .pre_div = (_pre_div), \ + .reg_config = (_reg_conf), \ +} + +static const struct imx7d_adc_analogue_core_clk imx7d_adc_analogue_clk[] = { + IMX7D_ADC_ANALOGUE_CLK_CONFIG(4, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_4), + IMX7D_ADC_ANALOGUE_CLK_CONFIG(8, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_8), + IMX7D_ADC_ANALOGUE_CLK_CONFIG(16, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_16), + IMX7D_ADC_ANALOGUE_CLK_CONFIG(32, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_32), + IMX7D_ADC_ANALOGUE_CLK_CONFIG(64, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_64), + IMX7D_ADC_ANALOGUE_CLK_CONFIG(128, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_128), +}; + +#define IMX7D_ADC_CHAN(_idx) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = (_idx), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ +} + +static const struct iio_chan_spec imx7d_adc_iio_channels[] = { + IMX7D_ADC_CHAN(0), + IMX7D_ADC_CHAN(1), + IMX7D_ADC_CHAN(2), + IMX7D_ADC_CHAN(3), + IMX7D_ADC_CHAN(4), + IMX7D_ADC_CHAN(5), + IMX7D_ADC_CHAN(6), + IMX7D_ADC_CHAN(7), + IMX7D_ADC_CHAN(8), + IMX7D_ADC_CHAN(9), + IMX7D_ADC_CHAN(10), + IMX7D_ADC_CHAN(11), + IMX7D_ADC_CHAN(12), + IMX7D_ADC_CHAN(13), + IMX7D_ADC_CHAN(14), + IMX7D_ADC_CHAN(15), +}; + +static const u32 imx7d_adc_average_num[] = { + IMX7D_REG_ADC_CH_CFG2_AVG_NUM_4, + IMX7D_REG_ADC_CH_CFG2_AVG_NUM_8, + IMX7D_REG_ADC_CH_CFG2_AVG_NUM_16, + IMX7D_REG_ADC_CH_CFG2_AVG_NUM_32, +}; + +static void imx7d_adc_feature_config(struct imx7d_adc *info) +{ + info->adc_feature.clk_pre_div = IMX7D_ADC_ANALOG_CLK_PRE_DIV_4; + info->adc_feature.avg_num = IMX7D_ADC_AVERAGE_NUM_32; + info->adc_feature.core_time_unit = 1; + info->adc_feature.average_en = true; +} + +static void imx7d_adc_sample_rate_set(struct imx7d_adc *info) +{ + struct imx7d_adc_feature *adc_feature = &info->adc_feature; + struct imx7d_adc_analogue_core_clk adc_analogure_clk; + u32 i; + u32 tmp_cfg1; + u32 sample_rate = 0; + + /* + * Before sample set, disable channel A,B,C,D. Here we + * clear the bit 31 of register REG_ADC_CH_A\B\C\D_CFG1. + */ + for (i = 0; i < 4; i++) { + tmp_cfg1 = + readl(info->regs + i * IMX7D_EACH_CHANNEL_REG_OFFSET); + tmp_cfg1 &= ~IMX7D_REG_ADC_CH_CFG1_CHANNEL_EN; + writel(tmp_cfg1, + info->regs + i * IMX7D_EACH_CHANNEL_REG_OFFSET); + } + + adc_analogure_clk = imx7d_adc_analogue_clk[adc_feature->clk_pre_div]; + sample_rate |= adc_analogure_clk.reg_config; + info->pre_div_num = adc_analogure_clk.pre_div; + + sample_rate |= adc_feature->core_time_unit; + writel(sample_rate, info->regs + IMX7D_REG_ADC_TIMER_UNIT); +} + +static void imx7d_adc_hw_init(struct imx7d_adc *info) +{ + u32 cfg; + + /* power up and enable adc analogue core */ + cfg = readl(info->regs + IMX7D_REG_ADC_ADC_CFG); + cfg &= ~(IMX7D_REG_ADC_ADC_CFG_ADC_CLK_DOWN | + IMX7D_REG_ADC_ADC_CFG_ADC_POWER_DOWN); + cfg |= IMX7D_REG_ADC_ADC_CFG_ADC_EN; + writel(cfg, info->regs + IMX7D_REG_ADC_ADC_CFG); + + /* enable channel A,B,C,D interrupt */ + writel(IMX7D_REG_ADC_INT_CHANNEL_INT_EN, + info->regs + IMX7D_REG_ADC_INT_SIG_EN); + writel(IMX7D_REG_ADC_INT_CHANNEL_INT_EN, + info->regs + IMX7D_REG_ADC_INT_EN); + + imx7d_adc_sample_rate_set(info); +} + +static void imx7d_adc_channel_set(struct imx7d_adc *info) +{ + u32 cfg1 = 0; + u32 cfg2; + u32 channel; + + channel = info->channel; + + /* the channel choose single conversion, and enable average mode */ + cfg1 |= (IMX7D_REG_ADC_CH_CFG1_CHANNEL_EN | + IMX7D_REG_ADC_CH_CFG1_CHANNEL_SINGLE); + if (info->adc_feature.average_en) + cfg1 |= IMX7D_REG_ADC_CH_CFG1_CHANNEL_AVG_EN; + + /* + * physical channel 0 chose logical channel A + * physical channel 1 chose logical channel B + * physical channel 2 chose logical channel C + * physical channel 3 chose logical channel D + */ + cfg1 |= IMX7D_REG_ADC_CH_CFG1_CHANNEL_SEL(channel); + + /* + * read register REG_ADC_CH_A\B\C\D_CFG2, according to the + * channel chosen + */ + cfg2 = readl(info->regs + IMX7D_EACH_CHANNEL_REG_OFFSET * channel + + IMX7D_REG_ADC_CHANNEL_CFG2_BASE); + + cfg2 |= imx7d_adc_average_num[info->adc_feature.avg_num]; + + /* + * write the register REG_ADC_CH_A\B\C\D_CFG2, according to + * the channel chosen + */ + writel(cfg2, info->regs + IMX7D_EACH_CHANNEL_REG_OFFSET * channel + + IMX7D_REG_ADC_CHANNEL_CFG2_BASE); + writel(cfg1, info->regs + IMX7D_EACH_CHANNEL_REG_OFFSET * channel); +} + +static u32 imx7d_adc_get_sample_rate(struct imx7d_adc *info) +{ + /* input clock is always 24MHz */ + u32 input_clk = 24000000; + u32 analogue_core_clk; + u32 core_time_unit = info->adc_feature.core_time_unit; + u32 tmp; + + analogue_core_clk = input_clk / info->pre_div_num; + tmp = (core_time_unit + 1) * 6; + + return analogue_core_clk / tmp; +} + +static int imx7d_adc_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, + int *val2, + long mask) +{ + struct imx7d_adc *info = iio_priv(indio_dev); + + u32 channel; + long ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + mutex_lock(&indio_dev->mlock); + reinit_completion(&info->completion); + + channel = chan->channel & 0x03; + info->channel = channel; + imx7d_adc_channel_set(info); + + ret = wait_for_completion_interruptible_timeout + (&info->completion, IMX7D_ADC_TIMEOUT); + if (ret == 0) { + mutex_unlock(&indio_dev->mlock); + return -ETIMEDOUT; + } + if (ret < 0) { + mutex_unlock(&indio_dev->mlock); + return ret; + } + + *val = info->value; + mutex_unlock(&indio_dev->mlock); + return IIO_VAL_INT; + + case IIO_CHAN_INFO_SCALE: + info->vref_uv = regulator_get_voltage(info->vref); + *val = info->vref_uv / 1000; + *val2 = 12; + return IIO_VAL_FRACTIONAL_LOG2; + + case IIO_CHAN_INFO_SAMP_FREQ: + *val = imx7d_adc_get_sample_rate(info); + return IIO_VAL_INT; + + default: + return -EINVAL; + } +} + +static int imx7d_adc_read_data(struct imx7d_adc *info) +{ + u32 channel; + u32 value; + + channel = info->channel & 0x03; + + /* + * channel A and B conversion result share one register, + * bit[27~16] is the channel B conversion result, + * bit[11~0] is the channel A conversion result. + * channel C and D is the same. + */ + if (channel < 2) + value = readl(info->regs + IMX7D_REG_ADC_CHA_B_CNV_RSLT); + else + value = readl(info->regs + IMX7D_REG_ADC_CHC_D_CNV_RSLT); + if (channel & 0x1) /* channel B or D */ + value = (value >> 16) & 0xFFF; + else /* channel A or C */ + value &= 0xFFF; + + return value; +} + +static irqreturn_t imx7d_adc_isr(int irq, void *dev_id) +{ + struct imx7d_adc *info = (struct imx7d_adc *)dev_id; + int status; + + status = readl(info->regs + IMX7D_REG_ADC_INT_STATUS); + if (status & IMX7D_REG_ADC_INT_STATUS_CHANNEL_INT_STATUS) { + info->value = imx7d_adc_read_data(info); + complete(&info->completion); + + /* + * The register IMX7D_REG_ADC_INT_STATUS can't clear + * itself after read operation, need software to write + * 0 to the related bit. Here we clear the channel A/B/C/D + * conversion finished flag. + */ + status &= ~IMX7D_REG_ADC_INT_STATUS_CHANNEL_INT_STATUS; + writel(status, info->regs + IMX7D_REG_ADC_INT_STATUS); + } + + /* + * If the channel A/B/C/D conversion timeout, report it and clear these + * timeout flags. + */ + if (status & IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT) { + pr_err("%s: ADC got conversion time out interrupt: 0x%08x\n", + dev_name(info->dev), status); + status &= ~IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT; + writel(status, info->regs + IMX7D_REG_ADC_INT_STATUS); + } + + return IRQ_HANDLED; +} + +static int imx7d_adc_reg_access(struct iio_dev *indio_dev, + unsigned reg, unsigned writeval, + unsigned *readval) +{ + struct imx7d_adc *info = iio_priv(indio_dev); + + if (!readval || reg % 4 || reg > IMX7D_REG_ADC_ADC_CFG) + return -EINVAL; + + *readval = readl(info->regs + reg); + + return 0; +} + +static const struct iio_info imx7d_adc_iio_info = { + .driver_module = THIS_MODULE, + .read_raw = &imx7d_adc_read_raw, + .debugfs_reg_access = &imx7d_adc_reg_access, +}; + +static const struct of_device_id imx7d_adc_match[] = { + { .compatible = "fsl,imx7d-adc", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, imx7d_adc_match); + +static void imx7d_adc_power_down(struct imx7d_adc *info) +{ + u32 adc_cfg; + + adc_cfg = readl(info->regs + IMX7D_REG_ADC_ADC_CFG); + adc_cfg |= IMX7D_REG_ADC_ADC_CFG_ADC_CLK_DOWN | + IMX7D_REG_ADC_ADC_CFG_ADC_POWER_DOWN; + adc_cfg &= ~IMX7D_REG_ADC_ADC_CFG_ADC_EN; + writel(adc_cfg, info->regs + IMX7D_REG_ADC_ADC_CFG); +} + +static int imx7d_adc_probe(struct platform_device *pdev) +{ + struct imx7d_adc *info; + struct iio_dev *indio_dev; + struct resource *mem; + int irq; + int ret; + + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); + if (!indio_dev) { + dev_err(&pdev->dev, "Failed allocating iio device\n"); + return -ENOMEM; + } + + info = iio_priv(indio_dev); + info->dev = &pdev->dev; + + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + info->regs = devm_ioremap_resource(&pdev->dev, mem); + if (IS_ERR(info->regs)) { + ret = PTR_ERR(info->regs); + dev_err(&pdev->dev, + "Failed to remap adc memory, err = %d\n", ret); + return ret; + } + + irq = platform_get_irq(pdev, 0); + if (irq < 0) { + dev_err(&pdev->dev, "No irq resource?\n"); + return irq; + } + + info->clk = devm_clk_get(&pdev->dev, "adc"); + if (IS_ERR(info->clk)) { + ret = PTR_ERR(info->clk); + dev_err(&pdev->dev, "Failed getting clock, err = %d\n", ret); + return ret; + } + + info->vref = devm_regulator_get(&pdev->dev, "vref"); + if (IS_ERR(info->vref)) { + ret = PTR_ERR(info->vref); + dev_err(&pdev->dev, + "Failed getting reference voltage, err = %d\n", ret); + return ret; + } + + ret = regulator_enable(info->vref); + if (ret) { + dev_err(&pdev->dev, + "Can't enable adc reference top voltage, err = %d\n", + ret); + return ret; + } + + platform_set_drvdata(pdev, indio_dev); + + init_completion(&info->completion); + + indio_dev->name = dev_name(&pdev->dev); + indio_dev->dev.parent = &pdev->dev; + indio_dev->info = &imx7d_adc_iio_info; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = imx7d_adc_iio_channels; + indio_dev->num_channels = ARRAY_SIZE(imx7d_adc_iio_channels); + + ret = clk_prepare_enable(info->clk); + if (ret) { + dev_err(&pdev->dev, + "Could not prepare or enable the clock.\n"); + goto error_adc_clk_enable; + } + + ret = devm_request_irq(info->dev, irq, + imx7d_adc_isr, 0, + dev_name(&pdev->dev), info); + if (ret < 0) { + dev_err(&pdev->dev, "Failed requesting irq, irq = %d\n", irq); + goto error_iio_device_register; + } + + imx7d_adc_feature_config(info); + imx7d_adc_hw_init(info); + + ret = iio_device_register(indio_dev); + if (ret) { + imx7d_adc_power_down(info); + dev_err(&pdev->dev, "Couldn't register the device.\n"); + goto error_iio_device_register; + } + + return 0; + +error_iio_device_register: + clk_disable_unprepare(info->clk); +error_adc_clk_enable: + regulator_disable(info->vref); + + return ret; +} + +static int imx7d_adc_remove(struct platform_device *pdev) +{ + struct iio_dev *indio_dev = platform_get_drvdata(pdev); + struct imx7d_adc *info = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + + imx7d_adc_power_down(info); + + clk_disable_unprepare(info->clk); + regulator_disable(info->vref); + + return 0; +} + +static int __maybe_unused imx7d_adc_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct imx7d_adc *info = iio_priv(indio_dev); + + imx7d_adc_power_down(info); + + clk_disable_unprepare(info->clk); + regulator_disable(info->vref); + + return 0; +} + +static int __maybe_unused imx7d_adc_resume(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct imx7d_adc *info = iio_priv(indio_dev); + int ret; + + ret = regulator_enable(info->vref); + if (ret) { + dev_err(info->dev, + "Can't enable adc reference top voltage, err = %d\n", + ret); + return ret; + } + + ret = clk_prepare_enable(info->clk); + if (ret) { + dev_err(info->dev, + "Could not prepare or enable clock.\n"); + regulator_disable(info->vref); + return ret; + } + + imx7d_adc_hw_init(info); + + return 0; +} + +static SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_suspend, imx7d_adc_resume); + +static struct platform_driver imx7d_adc_driver = { + .probe = imx7d_adc_probe, + .remove = imx7d_adc_remove, + .driver = { + .name = "imx7d_adc", + .of_match_table = imx7d_adc_match, + .pm = &imx7d_adc_pm_ops, + }, +}; + +module_platform_driver(imx7d_adc_driver); + +MODULE_AUTHOR("Haibo Chen <haibo.chen@freescale.com>"); +MODULE_DESCRIPTION("Freeacale IMX7D ADC driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c new file mode 100644 index 000000000000..d803e5018a42 --- /dev/null +++ b/drivers/iio/adc/ina2xx-adc.c @@ -0,0 +1,745 @@ +/* + * INA2XX Current and Power Monitors + * + * Copyright 2015 Baylibre SAS. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Based on linux/drivers/iio/adc/ad7291.c + * Copyright 2010-2011 Analog Devices Inc. + * + * Based on linux/drivers/hwmon/ina2xx.c + * Copyright 2012 Lothar Felten <l-felten@ti.com> + * + * Licensed under the GPL-2 or later. + * + * IIO driver for INA219-220-226-230-231 + * + * Configurable 7-bit I2C slave address from 0x40 to 0x4F + */ +#include <linux/module.h> +#include <linux/kthread.h> +#include <linux/delay.h> +#include <linux/iio/kfifo_buf.h> +#include <linux/iio/sysfs.h> +#include <linux/i2c.h> +#include <linux/regmap.h> +#include <linux/platform_data/ina2xx.h> + +#include <linux/util_macros.h> + +/* INA2XX registers definition */ +#define INA2XX_CONFIG 0x00 +#define INA2XX_SHUNT_VOLTAGE 0x01 /* readonly */ +#define INA2XX_BUS_VOLTAGE 0x02 /* readonly */ +#define INA2XX_POWER 0x03 /* readonly */ +#define INA2XX_CURRENT 0x04 /* readonly */ +#define INA2XX_CALIBRATION 0x05 + +#define INA226_ALERT_MASK 0x06 +#define INA266_CVRF BIT(3) + +#define INA2XX_MAX_REGISTERS 8 + +/* settings - depend on use case */ +#define INA219_CONFIG_DEFAULT 0x399F /* PGA=8 */ +#define INA226_CONFIG_DEFAULT 0x4327 +#define INA226_DEFAULT_AVG 4 +#define INA226_DEFAULT_IT 1110 + +#define INA2XX_RSHUNT_DEFAULT 10000 + +/* + * bit mask for reading the averaging setting in the configuration register + * FIXME: use regmap_fields. + */ +#define INA2XX_MODE_MASK GENMASK(3, 0) + +#define INA226_AVG_MASK GENMASK(11, 9) +#define INA226_SHIFT_AVG(val) ((val) << 9) + +/* Integration time for VBus */ +#define INA226_ITB_MASK GENMASK(8, 6) +#define INA226_SHIFT_ITB(val) ((val) << 6) + +/* Integration time for VShunt */ +#define INA226_ITS_MASK GENMASK(5, 3) +#define INA226_SHIFT_ITS(val) ((val) << 3) + +/* Cosmetic macro giving the sampling period for a full P=UxI cycle */ +#define SAMPLING_PERIOD(c) ((c->int_time_vbus + c->int_time_vshunt) \ + * c->avg) + +static bool ina2xx_is_writeable_reg(struct device *dev, unsigned int reg) +{ + return (reg == INA2XX_CONFIG) || (reg > INA2XX_CURRENT); +} + +static bool ina2xx_is_volatile_reg(struct device *dev, unsigned int reg) +{ + return (reg != INA2XX_CONFIG); +} + +static inline bool is_signed_reg(unsigned int reg) +{ + return (reg == INA2XX_SHUNT_VOLTAGE) || (reg == INA2XX_CURRENT); +} + +static const struct regmap_config ina2xx_regmap_config = { + .reg_bits = 8, + .val_bits = 16, + .max_register = INA2XX_MAX_REGISTERS, + .writeable_reg = ina2xx_is_writeable_reg, + .volatile_reg = ina2xx_is_volatile_reg, +}; + +enum ina2xx_ids { ina219, ina226 }; + +struct ina2xx_config { + u16 config_default; + int calibration_factor; + int shunt_div; + int bus_voltage_shift; + int bus_voltage_lsb; /* uV */ + int power_lsb; /* uW */ +}; + +struct ina2xx_chip_info { + struct regmap *regmap; + struct task_struct *task; + const struct ina2xx_config *config; + struct mutex state_lock; + unsigned int shunt_resistor; + int avg; + s64 prev_ns; /* track buffer capture time, check for underruns*/ + int int_time_vbus; /* Bus voltage integration time uS */ + int int_time_vshunt; /* Shunt voltage integration time uS */ + bool allow_async_readout; +}; + +static const struct ina2xx_config ina2xx_config[] = { + [ina219] = { + .config_default = INA219_CONFIG_DEFAULT, + .calibration_factor = 40960000, + .shunt_div = 100, + .bus_voltage_shift = 3, + .bus_voltage_lsb = 4000, + .power_lsb = 20000, + }, + [ina226] = { + .config_default = INA226_CONFIG_DEFAULT, + .calibration_factor = 5120000, + .shunt_div = 400, + .bus_voltage_shift = 0, + .bus_voltage_lsb = 1250, + .power_lsb = 25000, + }, +}; + +static int ina2xx_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + int ret; + struct ina2xx_chip_info *chip = iio_priv(indio_dev); + unsigned int regval; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = regmap_read(chip->regmap, chan->address, ®val); + if (ret < 0) + return ret; + + if (is_signed_reg(chan->address)) + *val = (s16) regval; + else + *val = regval; + + return IIO_VAL_INT; + + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + *val = chip->avg; + return IIO_VAL_INT; + + case IIO_CHAN_INFO_INT_TIME: + *val = 0; + if (chan->address == INA2XX_SHUNT_VOLTAGE) + *val2 = chip->int_time_vshunt; + else + *val2 = chip->int_time_vbus; + + return IIO_VAL_INT_PLUS_MICRO; + + case IIO_CHAN_INFO_SAMP_FREQ: + /* + * Sample freq is read only, it is a consequence of + * 1/AVG*(CT_bus+CT_shunt). + */ + *val = DIV_ROUND_CLOSEST(1000000, SAMPLING_PERIOD(chip)); + + return IIO_VAL_INT; + + case IIO_CHAN_INFO_SCALE: + switch (chan->address) { + case INA2XX_SHUNT_VOLTAGE: + /* processed (mV) = raw*1000/shunt_div */ + *val2 = chip->config->shunt_div; + *val = 1000; + return IIO_VAL_FRACTIONAL; + + case INA2XX_BUS_VOLTAGE: + /* processed (mV) = raw*lsb (uV) / (1000 << shift) */ + *val = chip->config->bus_voltage_lsb; + *val2 = 1000 << chip->config->bus_voltage_shift; + return IIO_VAL_FRACTIONAL; + + case INA2XX_POWER: + /* processed (mW) = raw*lsb (uW) / 1000 */ + *val = chip->config->power_lsb; + *val2 = 1000; + return IIO_VAL_FRACTIONAL; + + case INA2XX_CURRENT: + /* processed (mA) = raw (mA) */ + *val = 1; + return IIO_VAL_INT; + } + } + + return -EINVAL; +} + +/* + * Available averaging rates for ina226. The indices correspond with + * the bit values expected by the chip (according to the ina226 datasheet, + * table 3 AVG bit settings, found at + * http://www.ti.com/lit/ds/symlink/ina226.pdf. + */ +static const int ina226_avg_tab[] = { 1, 4, 16, 64, 128, 256, 512, 1024 }; + +static int ina226_set_average(struct ina2xx_chip_info *chip, unsigned int val, + unsigned int *config) +{ + int bits; + + if (val > 1024 || val < 1) + return -EINVAL; + + bits = find_closest(val, ina226_avg_tab, + ARRAY_SIZE(ina226_avg_tab)); + + chip->avg = ina226_avg_tab[bits]; + + *config &= ~INA226_AVG_MASK; + *config |= INA226_SHIFT_AVG(bits) & INA226_AVG_MASK; + + return 0; +} + +/* Conversion times in uS */ +static const int ina226_conv_time_tab[] = { 140, 204, 332, 588, 1100, + 2116, 4156, 8244 }; + +static int ina226_set_int_time_vbus(struct ina2xx_chip_info *chip, + unsigned int val_us, unsigned int *config) +{ + int bits; + + if (val_us > 8244 || val_us < 140) + return -EINVAL; + + bits = find_closest(val_us, ina226_conv_time_tab, + ARRAY_SIZE(ina226_conv_time_tab)); + + chip->int_time_vbus = ina226_conv_time_tab[bits]; + + *config &= ~INA226_ITB_MASK; + *config |= INA226_SHIFT_ITB(bits) & INA226_ITB_MASK; + + return 0; +} + +static int ina226_set_int_time_vshunt(struct ina2xx_chip_info *chip, + unsigned int val_us, unsigned int *config) +{ + int bits; + + if (val_us > 8244 || val_us < 140) + return -EINVAL; + + bits = find_closest(val_us, ina226_conv_time_tab, + ARRAY_SIZE(ina226_conv_time_tab)); + + chip->int_time_vshunt = ina226_conv_time_tab[bits]; + + *config &= ~INA226_ITS_MASK; + *config |= INA226_SHIFT_ITS(bits) & INA226_ITS_MASK; + + return 0; +} + +static int ina2xx_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct ina2xx_chip_info *chip = iio_priv(indio_dev); + int ret; + unsigned int config, tmp; + + if (iio_buffer_enabled(indio_dev)) + return -EBUSY; + + mutex_lock(&chip->state_lock); + + ret = regmap_read(chip->regmap, INA2XX_CONFIG, &config); + if (ret < 0) + goto _err; + + tmp = config; + + switch (mask) { + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + ret = ina226_set_average(chip, val, &tmp); + break; + + case IIO_CHAN_INFO_INT_TIME: + if (chan->address == INA2XX_SHUNT_VOLTAGE) + ret = ina226_set_int_time_vshunt(chip, val2, &tmp); + else + ret = ina226_set_int_time_vbus(chip, val2, &tmp); + break; + default: + ret = -EINVAL; + } + + if (!ret && (tmp != config)) + ret = regmap_write(chip->regmap, INA2XX_CONFIG, tmp); +_err: + mutex_unlock(&chip->state_lock); + + return ret; +} + + +static ssize_t ina2xx_allow_async_readout_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct ina2xx_chip_info *chip = iio_priv(dev_to_iio_dev(dev)); + + return sprintf(buf, "%d\n", chip->allow_async_readout); +} + +static ssize_t ina2xx_allow_async_readout_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct ina2xx_chip_info *chip = iio_priv(dev_to_iio_dev(dev)); + bool val; + int ret; + + ret = strtobool((const char *) buf, &val); + if (ret) + return ret; + + chip->allow_async_readout = val; + + return len; +} + +static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val) +{ + if (val <= 0 || val > chip->config->calibration_factor) + return -EINVAL; + + chip->shunt_resistor = val; + return 0; +} + +static ssize_t ina2xx_shunt_resistor_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct ina2xx_chip_info *chip = iio_priv(dev_to_iio_dev(dev)); + + return sprintf(buf, "%d\n", chip->shunt_resistor); +} + +static ssize_t ina2xx_shunt_resistor_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct ina2xx_chip_info *chip = iio_priv(dev_to_iio_dev(dev)); + unsigned long val; + int ret; + + ret = kstrtoul((const char *) buf, 10, &val); + if (ret) + return ret; + + ret = set_shunt_resistor(chip, val); + if (ret) + return ret; + + return len; +} + +#define INA2XX_CHAN(_type, _index, _address) { \ + .type = (_type), \ + .address = (_address), \ + .indexed = 1, \ + .channel = (_index), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) \ + | BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .scan_index = (_index), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = 16, \ + .storagebits = 16, \ + .endianness = IIO_CPU, \ + } \ +} + +/* + * Sampling Freq is a consequence of the integration times of + * the Voltage channels. + */ +#define INA2XX_CHAN_VOLTAGE(_index, _address) { \ + .type = IIO_VOLTAGE, \ + .address = (_address), \ + .indexed = 1, \ + .channel = (_index), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_INT_TIME), \ + .scan_index = (_index), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = 16, \ + .storagebits = 16, \ + .endianness = IIO_LE, \ + } \ +} + +static const struct iio_chan_spec ina2xx_channels[] = { + INA2XX_CHAN_VOLTAGE(0, INA2XX_SHUNT_VOLTAGE), + INA2XX_CHAN_VOLTAGE(1, INA2XX_BUS_VOLTAGE), + INA2XX_CHAN(IIO_POWER, 2, INA2XX_POWER), + INA2XX_CHAN(IIO_CURRENT, 3, INA2XX_CURRENT), + IIO_CHAN_SOFT_TIMESTAMP(4), +}; + +static int ina2xx_work_buffer(struct iio_dev *indio_dev) +{ + struct ina2xx_chip_info *chip = iio_priv(indio_dev); + unsigned short data[8]; + int bit, ret, i = 0; + unsigned long buffer_us, elapsed_us; + s64 time_a, time_b; + unsigned int alert; + + time_a = iio_get_time_ns(); + + /* + * Because the timer thread and the chip conversion clock + * are asynchronous, the period difference will eventually + * result in reading V[k-1] again, or skip V[k] at time Tk. + * In order to resync the timer with the conversion process + * we check the ConVersionReadyFlag. + * On hardware that supports using the ALERT pin to toggle a + * GPIO a triggered buffer could be used instead. + * For now, we pay for that extra read of the ALERT register + */ + if (!chip->allow_async_readout) + do { + ret = regmap_read(chip->regmap, INA226_ALERT_MASK, + &alert); + if (ret < 0) + return ret; + + alert &= INA266_CVRF; + trace_printk("Conversion ready: %d\n", !!alert); + + } while (!alert); + + /* + * Single register reads: bulk_read will not work with ina226 + * as there is no auto-increment of the address register for + * data length longer than 16bits. + */ + for_each_set_bit(bit, indio_dev->active_scan_mask, + indio_dev->masklength) { + unsigned int val; + + ret = regmap_read(chip->regmap, + INA2XX_SHUNT_VOLTAGE + bit, &val); + if (ret < 0) + return ret; + + data[i++] = val; + } + + time_b = iio_get_time_ns(); + + iio_push_to_buffers_with_timestamp(indio_dev, + (unsigned int *)data, time_a); + + buffer_us = (unsigned long)(time_b - time_a) / 1000; + elapsed_us = (unsigned long)(time_a - chip->prev_ns) / 1000; + + trace_printk("uS: elapsed: %lu, buf: %lu\n", elapsed_us, buffer_us); + + chip->prev_ns = time_a; + + return buffer_us; +}; + +static int ina2xx_capture_thread(void *data) +{ + struct iio_dev *indio_dev = (struct iio_dev *)data; + struct ina2xx_chip_info *chip = iio_priv(indio_dev); + unsigned int sampling_us = SAMPLING_PERIOD(chip); + int buffer_us; + + /* + * Poll a bit faster than the chip internal Fs, in case + * we wish to sync with the conversion ready flag. + */ + if (!chip->allow_async_readout) + sampling_us -= 200; + + do { + buffer_us = ina2xx_work_buffer(indio_dev); + if (buffer_us < 0) + return buffer_us; + + if (sampling_us > buffer_us) + udelay(sampling_us - buffer_us); + + } while (!kthread_should_stop()); + + return 0; +} + +static int ina2xx_buffer_enable(struct iio_dev *indio_dev) +{ + struct ina2xx_chip_info *chip = iio_priv(indio_dev); + unsigned int sampling_us = SAMPLING_PERIOD(chip); + + trace_printk("Enabling buffer w/ scan_mask %02x, freq = %d, avg =%u\n", + (unsigned int)(*indio_dev->active_scan_mask), + 1000000/sampling_us, chip->avg); + + trace_printk("Expected work period: %u us\n", sampling_us); + trace_printk("Async readout mode: %d\n", chip->allow_async_readout); + + chip->prev_ns = iio_get_time_ns(); + + chip->task = kthread_run(ina2xx_capture_thread, (void *)indio_dev, + "%s:%d-%uus", indio_dev->name, indio_dev->id, + sampling_us); + + return PTR_ERR_OR_ZERO(chip->task); +} + +static int ina2xx_buffer_disable(struct iio_dev *indio_dev) +{ + struct ina2xx_chip_info *chip = iio_priv(indio_dev); + + if (chip->task) { + kthread_stop(chip->task); + chip->task = NULL; + } + + return 0; +} + +static const struct iio_buffer_setup_ops ina2xx_setup_ops = { + .postenable = &ina2xx_buffer_enable, + .predisable = &ina2xx_buffer_disable, +}; + +static int ina2xx_debug_reg(struct iio_dev *indio_dev, + unsigned reg, unsigned writeval, unsigned *readval) +{ + struct ina2xx_chip_info *chip = iio_priv(indio_dev); + + if (!readval) + return regmap_write(chip->regmap, reg, writeval); + + return regmap_read(chip->regmap, reg, readval); +} + +/* Possible integration times for vshunt and vbus */ +static IIO_CONST_ATTR_INT_TIME_AVAIL \ + ("0.000140 0.000204 0.000332 0.000588 0.001100 0.002116 0.004156 0.008244"); + +static IIO_DEVICE_ATTR(in_allow_async_readout, S_IRUGO | S_IWUSR, + ina2xx_allow_async_readout_show, + ina2xx_allow_async_readout_store, 0); + +static IIO_DEVICE_ATTR(in_shunt_resistor, S_IRUGO | S_IWUSR, + ina2xx_shunt_resistor_show, + ina2xx_shunt_resistor_store, 0); + +static struct attribute *ina2xx_attributes[] = { + &iio_dev_attr_in_allow_async_readout.dev_attr.attr, + &iio_const_attr_integration_time_available.dev_attr.attr, + &iio_dev_attr_in_shunt_resistor.dev_attr.attr, + NULL, +}; + +static const struct attribute_group ina2xx_attribute_group = { + .attrs = ina2xx_attributes, +}; + +static const struct iio_info ina2xx_info = { + .debugfs_reg_access = &ina2xx_debug_reg, + .read_raw = &ina2xx_read_raw, + .write_raw = &ina2xx_write_raw, + .attrs = &ina2xx_attribute_group, + .driver_module = THIS_MODULE, +}; + +/* Initialize the configuration and calibration registers. */ +static int ina2xx_init(struct ina2xx_chip_info *chip, unsigned int config) +{ + u16 regval; + int ret = regmap_write(chip->regmap, INA2XX_CONFIG, config); + + if (ret < 0) + return ret; + /* + * Set current LSB to 1mA, shunt is in uOhms + * (equation 13 in datasheet). We hardcode a Current_LSB + * of 1.0 x10-6. The only remaining parameter is RShunt. + * There is no need to expose the CALIBRATION register + * to the user for now. + */ + regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor, + chip->shunt_resistor); + + return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval); +} + +static int ina2xx_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct ina2xx_chip_info *chip; + struct iio_dev *indio_dev; + struct iio_buffer *buffer; + int ret; + unsigned int val; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); + if (!indio_dev) + return -ENOMEM; + + chip = iio_priv(indio_dev); + + chip->config = &ina2xx_config[id->driver_data]; + + if (of_property_read_u32(client->dev.of_node, + "shunt-resistor", &val) < 0) { + struct ina2xx_platform_data *pdata = + dev_get_platdata(&client->dev); + + if (pdata) + val = pdata->shunt_uohms; + else + val = INA2XX_RSHUNT_DEFAULT; + } + + ret = set_shunt_resistor(chip, val); + if (ret) + return ret; + + mutex_init(&chip->state_lock); + + /* This is only used for device removal purposes. */ + i2c_set_clientdata(client, indio_dev); + + indio_dev->name = id->name; + indio_dev->channels = ina2xx_channels; + indio_dev->num_channels = ARRAY_SIZE(ina2xx_channels); + + indio_dev->dev.parent = &client->dev; + indio_dev->info = &ina2xx_info; + indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; + + chip->regmap = devm_regmap_init_i2c(client, &ina2xx_regmap_config); + if (IS_ERR(chip->regmap)) { + dev_err(&client->dev, "failed to allocate register map\n"); + return PTR_ERR(chip->regmap); + } + + /* Patch the current config register with default. */ + val = chip->config->config_default; + + if (id->driver_data == ina226) { + ina226_set_average(chip, INA226_DEFAULT_AVG, &val); + ina226_set_int_time_vbus(chip, INA226_DEFAULT_IT, &val); + ina226_set_int_time_vshunt(chip, INA226_DEFAULT_IT, &val); + } + + ret = ina2xx_init(chip, val); + if (ret < 0) { + dev_err(&client->dev, "error configuring the device: %d\n", + ret); + return -ENODEV; + } + + buffer = devm_iio_kfifo_allocate(&indio_dev->dev); + if (!buffer) + return -ENOMEM; + + indio_dev->setup_ops = &ina2xx_setup_ops; + + iio_device_attach_buffer(indio_dev, buffer); + + return iio_device_register(indio_dev); +} + + +static int ina2xx_remove(struct i2c_client *client) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(client); + struct ina2xx_chip_info *chip = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + + /* Powerdown */ + return regmap_update_bits(chip->regmap, INA2XX_CONFIG, + INA2XX_MODE_MASK, 0); +} + + +static const struct i2c_device_id ina2xx_id[] = { + {"ina219", ina219}, + {"ina220", ina219}, + {"ina226", ina226}, + {"ina230", ina226}, + {"ina231", ina226}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, ina2xx_id); + +static struct i2c_driver ina2xx_driver = { + .driver = { + .name = KBUILD_MODNAME, + }, + .probe = ina2xx_probe, + .remove = ina2xx_remove, + .id_table = ina2xx_id, +}; + +module_i2c_driver(ina2xx_driver); + +MODULE_AUTHOR("Marc Titinger <marc.titinger@baylibre.com>"); +MODULE_DESCRIPTION("Texas Instruments INA2XX ADC driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c index 8569c8e1f4b2..d1c05f6eed18 100644 --- a/drivers/iio/adc/mcp320x.c +++ b/drivers/iio/adc/mcp320x.c @@ -354,6 +354,7 @@ static int mcp320x_remove(struct spi_device *spi) #if defined(CONFIG_OF) static const struct of_device_id mcp320x_dt_ids[] = { + /* NOTE: The use of compatibles with no vendor prefix is deprecated. */ { .compatible = "mcp3001", .data = &mcp320x_chip_infos[mcp3001], @@ -382,6 +383,33 @@ static const struct of_device_id mcp320x_dt_ids[] = { .compatible = "mcp3301", .data = &mcp320x_chip_infos[mcp3301], }, { + .compatible = "microchip,mcp3001", + .data = &mcp320x_chip_infos[mcp3001], + }, { + .compatible = "microchip,mcp3002", + .data = &mcp320x_chip_infos[mcp3002], + }, { + .compatible = "microchip,mcp3004", + .data = &mcp320x_chip_infos[mcp3004], + }, { + .compatible = "microchip,mcp3008", + .data = &mcp320x_chip_infos[mcp3008], + }, { + .compatible = "microchip,mcp3201", + .data = &mcp320x_chip_infos[mcp3201], + }, { + .compatible = "microchip,mcp3202", + .data = &mcp320x_chip_infos[mcp3202], + }, { + .compatible = "microchip,mcp3204", + .data = &mcp320x_chip_infos[mcp3204], + }, { + .compatible = "microchip,mcp3208", + .data = &mcp320x_chip_infos[mcp3208], + }, { + .compatible = "microchip,mcp3301", + .data = &mcp320x_chip_infos[mcp3301], + }, { } }; MODULE_DEVICE_TABLE(of, mcp320x_dt_ids); diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c index 3555122008b4..6eca7aea8a37 100644 --- a/drivers/iio/adc/mcp3422.c +++ b/drivers/iio/adc/mcp3422.c @@ -305,6 +305,10 @@ static const struct attribute_group mcp3422_attribute_group = { .attrs = mcp3422_attributes, }; +static const struct iio_chan_spec mcp3421_channels[] = { + MCP3422_CHAN(0), +}; + static const struct iio_chan_spec mcp3422_channels[] = { MCP3422_CHAN(0), MCP3422_CHAN(1), @@ -352,6 +356,10 @@ static int mcp3422_probe(struct i2c_client *client, indio_dev->info = &mcp3422_info; switch (adc->id) { + case 1: + indio_dev->channels = mcp3421_channels; + indio_dev->num_channels = ARRAY_SIZE(mcp3421_channels); + break; case 2: case 3: case 6: @@ -383,6 +391,7 @@ static int mcp3422_probe(struct i2c_client *client, } static const struct i2c_device_id mcp3422_id[] = { + { "mcp3421", 1 }, { "mcp3422", 2 }, { "mcp3423", 3 }, { "mcp3424", 4 }, diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c new file mode 100644 index 000000000000..f42eb8a7d21f --- /dev/null +++ b/drivers/iio/adc/palmas_gpadc.c @@ -0,0 +1,859 @@ +/* + * palmas-adc.c -- TI PALMAS GPADC. + * + * Copyright (c) 2013, NVIDIA Corporation. All rights reserved. + * + * Author: Pradeep Goudagunta <pgoudagunta@nvidia.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation version 2. + */ + +#include <linux/module.h> +#include <linux/err.h> +#include <linux/irq.h> +#include <linux/interrupt.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/delay.h> +#include <linux/i2c.h> +#include <linux/pm.h> +#include <linux/mfd/palmas.h> +#include <linux/completion.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/iio/iio.h> +#include <linux/iio/machine.h> +#include <linux/iio/driver.h> + +#define MOD_NAME "palmas-gpadc" +#define PALMAS_ADC_CONVERSION_TIMEOUT (msecs_to_jiffies(5000)) +#define PALMAS_TO_BE_CALCULATED 0 +#define PALMAS_GPADC_TRIMINVALID -1 + +struct palmas_gpadc_info { +/* calibration codes and regs */ + int x1; /* lower ideal code */ + int x2; /* higher ideal code */ + int v1; /* expected lower volt reading */ + int v2; /* expected higher volt reading */ + u8 trim1_reg; /* register number for lower trim */ + u8 trim2_reg; /* register number for upper trim */ + int gain; /* calculated from above (after reading trim regs) */ + int offset; /* calculated from above (after reading trim regs) */ + int gain_error; /* calculated from above (after reading trim regs) */ + bool is_uncalibrated; /* if channel has calibration data */ +}; + +#define PALMAS_ADC_INFO(_chan, _x1, _x2, _v1, _v2, _t1, _t2, _is_uncalibrated) \ + [PALMAS_ADC_CH_##_chan] = { \ + .x1 = _x1, \ + .x2 = _x2, \ + .v1 = _v1, \ + .v2 = _v2, \ + .gain = PALMAS_TO_BE_CALCULATED, \ + .offset = PALMAS_TO_BE_CALCULATED, \ + .gain_error = PALMAS_TO_BE_CALCULATED, \ + .trim1_reg = PALMAS_GPADC_TRIM##_t1, \ + .trim2_reg = PALMAS_GPADC_TRIM##_t2, \ + .is_uncalibrated = _is_uncalibrated \ + } + +static struct palmas_gpadc_info palmas_gpadc_info[] = { + PALMAS_ADC_INFO(IN0, 2064, 3112, 630, 950, 1, 2, false), + PALMAS_ADC_INFO(IN1, 2064, 3112, 630, 950, 1, 2, false), + PALMAS_ADC_INFO(IN2, 2064, 3112, 1260, 1900, 3, 4, false), + PALMAS_ADC_INFO(IN3, 2064, 3112, 630, 950, 1, 2, false), + PALMAS_ADC_INFO(IN4, 2064, 3112, 630, 950, 1, 2, false), + PALMAS_ADC_INFO(IN5, 2064, 3112, 630, 950, 1, 2, false), + PALMAS_ADC_INFO(IN6, 2064, 3112, 2520, 3800, 5, 6, false), + PALMAS_ADC_INFO(IN7, 2064, 3112, 2520, 3800, 7, 8, false), + PALMAS_ADC_INFO(IN8, 2064, 3112, 3150, 4750, 9, 10, false), + PALMAS_ADC_INFO(IN9, 2064, 3112, 5670, 8550, 11, 12, false), + PALMAS_ADC_INFO(IN10, 2064, 3112, 3465, 5225, 13, 14, false), + PALMAS_ADC_INFO(IN11, 0, 0, 0, 0, INVALID, INVALID, true), + PALMAS_ADC_INFO(IN12, 0, 0, 0, 0, INVALID, INVALID, true), + PALMAS_ADC_INFO(IN13, 0, 0, 0, 0, INVALID, INVALID, true), + PALMAS_ADC_INFO(IN14, 2064, 3112, 3645, 5225, 15, 16, false), + PALMAS_ADC_INFO(IN15, 0, 0, 0, 0, INVALID, INVALID, true), +}; + +/** + * struct palmas_gpadc - the palmas_gpadc structure + * @ch0_current: channel 0 current source setting + * 0: 0 uA + * 1: 5 uA + * 2: 15 uA + * 3: 20 uA + * @ch3_current: channel 0 current source setting + * 0: 0 uA + * 1: 10 uA + * 2: 400 uA + * 3: 800 uA + * @extended_delay: enable the gpadc extended delay mode + * @auto_conversion_period: define the auto_conversion_period + * + * This is the palmas_gpadc structure to store run-time information + * and pointers for this driver instance. + */ + +struct palmas_gpadc { + struct device *dev; + struct palmas *palmas; + u8 ch0_current; + u8 ch3_current; + bool extended_delay; + int irq; + int irq_auto_0; + int irq_auto_1; + struct palmas_gpadc_info *adc_info; + struct completion conv_completion; + struct palmas_adc_wakeup_property wakeup1_data; + struct palmas_adc_wakeup_property wakeup2_data; + bool wakeup1_enable; + bool wakeup2_enable; + int auto_conversion_period; +}; + +/* + * GPADC lock issue in AUTO mode. + * Impact: In AUTO mode, GPADC conversion can be locked after disabling AUTO + * mode feature. + * Details: + * When the AUTO mode is the only conversion mode enabled, if the AUTO + * mode feature is disabled with bit GPADC_AUTO_CTRL. AUTO_CONV1_EN = 0 + * or bit GPADC_AUTO_CTRL. AUTO_CONV0_EN = 0 during a conversion, the + * conversion mechanism can be seen as locked meaning that all following + * conversion will give 0 as a result. Bit GPADC_STATUS.GPADC_AVAILABLE + * will stay at 0 meaning that GPADC is busy. An RT conversion can unlock + * the GPADC. + * + * Workaround(s): + * To avoid the lock mechanism, the workaround to follow before any stop + * conversion request is: + * Force the GPADC state machine to be ON by using the GPADC_CTRL1. + * GPADC_FORCE bit = 1 + * Shutdown the GPADC AUTO conversion using + * GPADC_AUTO_CTRL.SHUTDOWN_CONV[01] = 0. + * After 100us, force the GPADC state machine to be OFF by using the + * GPADC_CTRL1. GPADC_FORCE bit = 0 + */ + +static int palmas_disable_auto_conversion(struct palmas_gpadc *adc) +{ + int ret; + + ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_CTRL1, + PALMAS_GPADC_CTRL1_GPADC_FORCE, + PALMAS_GPADC_CTRL1_GPADC_FORCE); + if (ret < 0) { + dev_err(adc->dev, "GPADC_CTRL1 update failed: %d\n", ret); + return ret; + } + + ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_AUTO_CTRL, + PALMAS_GPADC_AUTO_CTRL_SHUTDOWN_CONV1 | + PALMAS_GPADC_AUTO_CTRL_SHUTDOWN_CONV0, + 0); + if (ret < 0) { + dev_err(adc->dev, "AUTO_CTRL update failed: %d\n", ret); + return ret; + } + + udelay(100); + + ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_CTRL1, + PALMAS_GPADC_CTRL1_GPADC_FORCE, 0); + if (ret < 0) + dev_err(adc->dev, "GPADC_CTRL1 update failed: %d\n", ret); + + return ret; +} + +static irqreturn_t palmas_gpadc_irq(int irq, void *data) +{ + struct palmas_gpadc *adc = data; + + complete(&adc->conv_completion); + + return IRQ_HANDLED; +} + +static irqreturn_t palmas_gpadc_irq_auto(int irq, void *data) +{ + struct palmas_gpadc *adc = data; + + dev_dbg(adc->dev, "Threshold interrupt %d occurs\n", irq); + palmas_disable_auto_conversion(adc); + + return IRQ_HANDLED; +} + +static int palmas_gpadc_start_mask_interrupt(struct palmas_gpadc *adc, + bool mask) +{ + int ret; + + if (!mask) + ret = palmas_update_bits(adc->palmas, PALMAS_INTERRUPT_BASE, + PALMAS_INT3_MASK, + PALMAS_INT3_MASK_GPADC_EOC_SW, 0); + else + ret = palmas_update_bits(adc->palmas, PALMAS_INTERRUPT_BASE, + PALMAS_INT3_MASK, + PALMAS_INT3_MASK_GPADC_EOC_SW, + PALMAS_INT3_MASK_GPADC_EOC_SW); + if (ret < 0) + dev_err(adc->dev, "GPADC INT MASK update failed: %d\n", ret); + + return ret; +} + +static int palmas_gpadc_enable(struct palmas_gpadc *adc, int adc_chan, + int enable) +{ + unsigned int mask, val; + int ret; + + if (enable) { + val = (adc->extended_delay + << PALMAS_GPADC_RT_CTRL_EXTEND_DELAY_SHIFT); + ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_RT_CTRL, + PALMAS_GPADC_RT_CTRL_EXTEND_DELAY, val); + if (ret < 0) { + dev_err(adc->dev, "RT_CTRL update failed: %d\n", ret); + return ret; + } + + mask = (PALMAS_GPADC_CTRL1_CURRENT_SRC_CH0_MASK | + PALMAS_GPADC_CTRL1_CURRENT_SRC_CH3_MASK | + PALMAS_GPADC_CTRL1_GPADC_FORCE); + val = (adc->ch0_current + << PALMAS_GPADC_CTRL1_CURRENT_SRC_CH0_SHIFT); + val |= (adc->ch3_current + << PALMAS_GPADC_CTRL1_CURRENT_SRC_CH3_SHIFT); + val |= PALMAS_GPADC_CTRL1_GPADC_FORCE; + ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_CTRL1, mask, val); + if (ret < 0) { + dev_err(adc->dev, + "Failed to update current setting: %d\n", ret); + return ret; + } + + mask = (PALMAS_GPADC_SW_SELECT_SW_CONV0_SEL_MASK | + PALMAS_GPADC_SW_SELECT_SW_CONV_EN); + val = (adc_chan | PALMAS_GPADC_SW_SELECT_SW_CONV_EN); + ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_SW_SELECT, mask, val); + if (ret < 0) { + dev_err(adc->dev, "SW_SELECT update failed: %d\n", ret); + return ret; + } + } else { + ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_SW_SELECT, 0); + if (ret < 0) + dev_err(adc->dev, "SW_SELECT write failed: %d\n", ret); + + ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_CTRL1, + PALMAS_GPADC_CTRL1_GPADC_FORCE, 0); + if (ret < 0) { + dev_err(adc->dev, "CTRL1 update failed: %d\n", ret); + return ret; + } + } + + return ret; +} + +static int palmas_gpadc_read_prepare(struct palmas_gpadc *adc, int adc_chan) +{ + int ret; + + ret = palmas_gpadc_enable(adc, adc_chan, true); + if (ret < 0) + return ret; + + return palmas_gpadc_start_mask_interrupt(adc, 0); +} + +static void palmas_gpadc_read_done(struct palmas_gpadc *adc, int adc_chan) +{ + palmas_gpadc_start_mask_interrupt(adc, 1); + palmas_gpadc_enable(adc, adc_chan, false); +} + +static int palmas_gpadc_calibrate(struct palmas_gpadc *adc, int adc_chan) +{ + int k; + int d1; + int d2; + int ret; + int gain; + int x1 = adc->adc_info[adc_chan].x1; + int x2 = adc->adc_info[adc_chan].x2; + int v1 = adc->adc_info[adc_chan].v1; + int v2 = adc->adc_info[adc_chan].v2; + + ret = palmas_read(adc->palmas, PALMAS_TRIM_GPADC_BASE, + adc->adc_info[adc_chan].trim1_reg, &d1); + if (ret < 0) { + dev_err(adc->dev, "TRIM read failed: %d\n", ret); + goto scrub; + } + + ret = palmas_read(adc->palmas, PALMAS_TRIM_GPADC_BASE, + adc->adc_info[adc_chan].trim2_reg, &d2); + if (ret < 0) { + dev_err(adc->dev, "TRIM read failed: %d\n", ret); + goto scrub; + } + + /* gain error calculation */ + k = (1000 + (1000 * (d2 - d1)) / (x2 - x1)); + + /* gain calculation */ + gain = ((v2 - v1) * 1000) / (x2 - x1); + + adc->adc_info[adc_chan].gain_error = k; + adc->adc_info[adc_chan].gain = gain; + /* offset Calculation */ + adc->adc_info[adc_chan].offset = (d1 * 1000) - ((k - 1000) * x1); + +scrub: + return ret; +} + +static int palmas_gpadc_start_conversion(struct palmas_gpadc *adc, int adc_chan) +{ + unsigned int val; + int ret; + + init_completion(&adc->conv_completion); + ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_SW_SELECT, + PALMAS_GPADC_SW_SELECT_SW_START_CONV0, + PALMAS_GPADC_SW_SELECT_SW_START_CONV0); + if (ret < 0) { + dev_err(adc->dev, "SELECT_SW_START write failed: %d\n", ret); + return ret; + } + + ret = wait_for_completion_timeout(&adc->conv_completion, + PALMAS_ADC_CONVERSION_TIMEOUT); + if (ret == 0) { + dev_err(adc->dev, "conversion not completed\n"); + return -ETIMEDOUT; + } + + ret = palmas_bulk_read(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_SW_CONV0_LSB, &val, 2); + if (ret < 0) { + dev_err(adc->dev, "SW_CONV0_LSB read failed: %d\n", ret); + return ret; + } + + ret = val & 0xFFF; + + return ret; +} + +static int palmas_gpadc_get_calibrated_code(struct palmas_gpadc *adc, + int adc_chan, int val) +{ + if (!adc->adc_info[adc_chan].is_uncalibrated) + val = (val*1000 - adc->adc_info[adc_chan].offset) / + adc->adc_info[adc_chan].gain_error; + + if (val < 0) { + dev_err(adc->dev, "Mismatch with calibration\n"); + return 0; + } + + val = (val * adc->adc_info[adc_chan].gain) / 1000; + + return val; +} + +static int palmas_gpadc_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, int *val2, long mask) +{ + struct palmas_gpadc *adc = iio_priv(indio_dev); + int adc_chan = chan->channel; + int ret = 0; + + if (adc_chan > PALMAS_ADC_CH_MAX) + return -EINVAL; + + mutex_lock(&indio_dev->mlock); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + case IIO_CHAN_INFO_PROCESSED: + ret = palmas_gpadc_read_prepare(adc, adc_chan); + if (ret < 0) + goto out; + + ret = palmas_gpadc_start_conversion(adc, adc_chan); + if (ret < 0) { + dev_err(adc->dev, + "ADC start conversion failed\n"); + goto out; + } + + if (mask == IIO_CHAN_INFO_PROCESSED) + ret = palmas_gpadc_get_calibrated_code( + adc, adc_chan, ret); + + *val = ret; + + ret = IIO_VAL_INT; + goto out; + } + + mutex_unlock(&indio_dev->mlock); + return ret; + +out: + palmas_gpadc_read_done(adc, adc_chan); + mutex_unlock(&indio_dev->mlock); + + return ret; +} + +static const struct iio_info palmas_gpadc_iio_info = { + .read_raw = palmas_gpadc_read_raw, + .driver_module = THIS_MODULE, +}; + +#define PALMAS_ADC_CHAN_IIO(chan, _type, chan_info) \ +{ \ + .datasheet_name = PALMAS_DATASHEET_NAME(chan), \ + .type = _type, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(chan_info), \ + .indexed = 1, \ + .channel = PALMAS_ADC_CH_##chan, \ +} + +static const struct iio_chan_spec palmas_gpadc_iio_channel[] = { + PALMAS_ADC_CHAN_IIO(IN0, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), + PALMAS_ADC_CHAN_IIO(IN1, IIO_TEMP, IIO_CHAN_INFO_RAW), + PALMAS_ADC_CHAN_IIO(IN2, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), + PALMAS_ADC_CHAN_IIO(IN3, IIO_TEMP, IIO_CHAN_INFO_RAW), + PALMAS_ADC_CHAN_IIO(IN4, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), + PALMAS_ADC_CHAN_IIO(IN5, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), + PALMAS_ADC_CHAN_IIO(IN6, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), + PALMAS_ADC_CHAN_IIO(IN7, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), + PALMAS_ADC_CHAN_IIO(IN8, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), + PALMAS_ADC_CHAN_IIO(IN9, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), + PALMAS_ADC_CHAN_IIO(IN10, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), + PALMAS_ADC_CHAN_IIO(IN11, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), + PALMAS_ADC_CHAN_IIO(IN12, IIO_TEMP, IIO_CHAN_INFO_RAW), + PALMAS_ADC_CHAN_IIO(IN13, IIO_TEMP, IIO_CHAN_INFO_RAW), + PALMAS_ADC_CHAN_IIO(IN14, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), + PALMAS_ADC_CHAN_IIO(IN15, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED), +}; + +static int palmas_gpadc_get_adc_dt_data(struct platform_device *pdev, + struct palmas_gpadc_platform_data **gpadc_pdata) +{ + struct device_node *np = pdev->dev.of_node; + struct palmas_gpadc_platform_data *gp_data; + int ret; + u32 pval; + + gp_data = devm_kzalloc(&pdev->dev, sizeof(*gp_data), GFP_KERNEL); + if (!gp_data) + return -ENOMEM; + + ret = of_property_read_u32(np, "ti,channel0-current-microamp", &pval); + if (!ret) + gp_data->ch0_current = pval; + + ret = of_property_read_u32(np, "ti,channel3-current-microamp", &pval); + if (!ret) + gp_data->ch3_current = pval; + + gp_data->extended_delay = of_property_read_bool(np, + "ti,enable-extended-delay"); + + *gpadc_pdata = gp_data; + + return 0; +} + +static int palmas_gpadc_probe(struct platform_device *pdev) +{ + struct palmas_gpadc *adc; + struct palmas_platform_data *pdata; + struct palmas_gpadc_platform_data *gpadc_pdata = NULL; + struct iio_dev *indio_dev; + int ret, i; + + pdata = dev_get_platdata(pdev->dev.parent); + + if (pdata && pdata->gpadc_pdata) + gpadc_pdata = pdata->gpadc_pdata; + + if (!gpadc_pdata && pdev->dev.of_node) { + ret = palmas_gpadc_get_adc_dt_data(pdev, &gpadc_pdata); + if (ret < 0) + return ret; + } + if (!gpadc_pdata) + return -EINVAL; + + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc)); + if (!indio_dev) { + dev_err(&pdev->dev, "iio_device_alloc failed\n"); + return -ENOMEM; + } + + adc = iio_priv(indio_dev); + adc->dev = &pdev->dev; + adc->palmas = dev_get_drvdata(pdev->dev.parent); + adc->adc_info = palmas_gpadc_info; + init_completion(&adc->conv_completion); + dev_set_drvdata(&pdev->dev, indio_dev); + + adc->auto_conversion_period = gpadc_pdata->auto_conversion_period_ms; + adc->irq = palmas_irq_get_virq(adc->palmas, PALMAS_GPADC_EOC_SW_IRQ); + if (adc->irq < 0) { + dev_err(adc->dev, + "get virq failed: %d\n", adc->irq); + ret = adc->irq; + goto out; + } + ret = request_threaded_irq(adc->irq, NULL, + palmas_gpadc_irq, + IRQF_ONESHOT | IRQF_EARLY_RESUME, dev_name(adc->dev), + adc); + if (ret < 0) { + dev_err(adc->dev, + "request irq %d failed: %d\n", adc->irq, ret); + goto out; + } + + if (gpadc_pdata->adc_wakeup1_data) { + memcpy(&adc->wakeup1_data, gpadc_pdata->adc_wakeup1_data, + sizeof(adc->wakeup1_data)); + adc->wakeup1_enable = true; + adc->irq_auto_0 = platform_get_irq(pdev, 1); + ret = request_threaded_irq(adc->irq_auto_0, NULL, + palmas_gpadc_irq_auto, + IRQF_ONESHOT | IRQF_EARLY_RESUME, + "palmas-adc-auto-0", adc); + if (ret < 0) { + dev_err(adc->dev, "request auto0 irq %d failed: %d\n", + adc->irq_auto_0, ret); + goto out_irq_free; + } + } + + if (gpadc_pdata->adc_wakeup2_data) { + memcpy(&adc->wakeup2_data, gpadc_pdata->adc_wakeup2_data, + sizeof(adc->wakeup2_data)); + adc->wakeup2_enable = true; + adc->irq_auto_1 = platform_get_irq(pdev, 2); + ret = request_threaded_irq(adc->irq_auto_1, NULL, + palmas_gpadc_irq_auto, + IRQF_ONESHOT | IRQF_EARLY_RESUME, + "palmas-adc-auto-1", adc); + if (ret < 0) { + dev_err(adc->dev, "request auto1 irq %d failed: %d\n", + adc->irq_auto_1, ret); + goto out_irq_auto0_free; + } + } + + /* set the current source 0 (value 0/5/15/20 uA => 0..3) */ + if (gpadc_pdata->ch0_current <= 1) + adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_0; + else if (gpadc_pdata->ch0_current <= 5) + adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_5; + else if (gpadc_pdata->ch0_current <= 15) + adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_15; + else + adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_20; + + /* set the current source 3 (value 0/10/400/800 uA => 0..3) */ + if (gpadc_pdata->ch3_current <= 1) + adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_0; + else if (gpadc_pdata->ch3_current <= 10) + adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_10; + else if (gpadc_pdata->ch3_current <= 400) + adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_400; + else + adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_800; + + adc->extended_delay = gpadc_pdata->extended_delay; + + indio_dev->name = MOD_NAME; + indio_dev->dev.parent = &pdev->dev; + indio_dev->info = &palmas_gpadc_iio_info; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = palmas_gpadc_iio_channel; + indio_dev->num_channels = ARRAY_SIZE(palmas_gpadc_iio_channel); + + ret = iio_device_register(indio_dev); + if (ret < 0) { + dev_err(adc->dev, "iio_device_register() failed: %d\n", ret); + goto out_irq_auto1_free; + } + + device_set_wakeup_capable(&pdev->dev, 1); + for (i = 0; i < PALMAS_ADC_CH_MAX; i++) { + if (!(adc->adc_info[i].is_uncalibrated)) + palmas_gpadc_calibrate(adc, i); + } + + if (adc->wakeup1_enable || adc->wakeup2_enable) + device_wakeup_enable(&pdev->dev); + + return 0; + +out_irq_auto1_free: + if (gpadc_pdata->adc_wakeup2_data) + free_irq(adc->irq_auto_1, adc); +out_irq_auto0_free: + if (gpadc_pdata->adc_wakeup1_data) + free_irq(adc->irq_auto_0, adc); +out_irq_free: + free_irq(adc->irq, adc); +out: + return ret; +} + +static int palmas_gpadc_remove(struct platform_device *pdev) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(&pdev->dev); + struct palmas_gpadc *adc = iio_priv(indio_dev); + + if (adc->wakeup1_enable || adc->wakeup2_enable) + device_wakeup_disable(&pdev->dev); + iio_device_unregister(indio_dev); + free_irq(adc->irq, adc); + if (adc->wakeup1_enable) + free_irq(adc->irq_auto_0, adc); + if (adc->wakeup2_enable) + free_irq(adc->irq_auto_1, adc); + + return 0; +} + +#ifdef CONFIG_PM_SLEEP +static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc) +{ + int adc_period, conv; + int i; + int ch0 = 0, ch1 = 0; + int thres; + int ret; + + adc_period = adc->auto_conversion_period; + for (i = 0; i < 16; ++i) { + if (((1000 * (1 << i)) / 32) < adc_period) + continue; + } + if (i > 0) + i--; + adc_period = i; + ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_AUTO_CTRL, + PALMAS_GPADC_AUTO_CTRL_COUNTER_CONV_MASK, + adc_period); + if (ret < 0) { + dev_err(adc->dev, "AUTO_CTRL write failed: %d\n", ret); + return ret; + } + + conv = 0; + if (adc->wakeup1_enable) { + int polarity; + + ch0 = adc->wakeup1_data.adc_channel_number; + conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV0_EN; + if (adc->wakeup1_data.adc_high_threshold > 0) { + thres = adc->wakeup1_data.adc_high_threshold; + polarity = 0; + } else { + thres = adc->wakeup1_data.adc_low_threshold; + polarity = PALMAS_GPADC_THRES_CONV0_MSB_THRES_CONV0_POL; + } + + ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_THRES_CONV0_LSB, thres & 0xFF); + if (ret < 0) { + dev_err(adc->dev, + "THRES_CONV0_LSB write failed: %d\n", ret); + return ret; + } + + ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_THRES_CONV0_MSB, + ((thres >> 8) & 0xF) | polarity); + if (ret < 0) { + dev_err(adc->dev, + "THRES_CONV0_MSB write failed: %d\n", ret); + return ret; + } + } + + if (adc->wakeup2_enable) { + int polarity; + + ch1 = adc->wakeup2_data.adc_channel_number; + conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV1_EN; + if (adc->wakeup2_data.adc_high_threshold > 0) { + thres = adc->wakeup2_data.adc_high_threshold; + polarity = 0; + } else { + thres = adc->wakeup2_data.adc_low_threshold; + polarity = PALMAS_GPADC_THRES_CONV1_MSB_THRES_CONV1_POL; + } + + ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_THRES_CONV1_LSB, thres & 0xFF); + if (ret < 0) { + dev_err(adc->dev, + "THRES_CONV1_LSB write failed: %d\n", ret); + return ret; + } + + ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_THRES_CONV1_MSB, + ((thres >> 8) & 0xF) | polarity); + if (ret < 0) { + dev_err(adc->dev, + "THRES_CONV1_MSB write failed: %d\n", ret); + return ret; + } + } + + ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_AUTO_SELECT, (ch1 << 4) | ch0); + if (ret < 0) { + dev_err(adc->dev, "AUTO_SELECT write failed: %d\n", ret); + return ret; + } + + ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_AUTO_CTRL, + PALMAS_GPADC_AUTO_CTRL_AUTO_CONV1_EN | + PALMAS_GPADC_AUTO_CTRL_AUTO_CONV0_EN, conv); + if (ret < 0) + dev_err(adc->dev, "AUTO_CTRL write failed: %d\n", ret); + + return ret; +} + +static int palmas_adc_wakeup_reset(struct palmas_gpadc *adc) +{ + int ret; + + ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_AUTO_SELECT, 0); + if (ret < 0) { + dev_err(adc->dev, "AUTO_SELECT write failed: %d\n", ret); + return ret; + } + + ret = palmas_disable_auto_conversion(adc); + if (ret < 0) + dev_err(adc->dev, "Disable auto conversion failed: %d\n", ret); + + return ret; +} + +static int palmas_gpadc_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct palmas_gpadc *adc = iio_priv(indio_dev); + int wakeup = adc->wakeup1_enable || adc->wakeup2_enable; + int ret; + + if (!device_may_wakeup(dev) || !wakeup) + return 0; + + ret = palmas_adc_wakeup_configure(adc); + if (ret < 0) + return ret; + + if (adc->wakeup1_enable) + enable_irq_wake(adc->irq_auto_0); + + if (adc->wakeup2_enable) + enable_irq_wake(adc->irq_auto_1); + + return 0; +} + +static int palmas_gpadc_resume(struct device *dev) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct palmas_gpadc *adc = iio_priv(indio_dev); + int wakeup = adc->wakeup1_enable || adc->wakeup2_enable; + int ret; + + if (!device_may_wakeup(dev) || !wakeup) + return 0; + + ret = palmas_adc_wakeup_reset(adc); + if (ret < 0) + return ret; + + if (adc->wakeup1_enable) + disable_irq_wake(adc->irq_auto_0); + + if (adc->wakeup2_enable) + disable_irq_wake(adc->irq_auto_1); + + return 0; +}; +#endif + +static const struct dev_pm_ops palmas_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(palmas_gpadc_suspend, + palmas_gpadc_resume) +}; + +static const struct of_device_id of_palmas_gpadc_match_tbl[] = { + { .compatible = "ti,palmas-gpadc", }, + { /* end */ } +}; +MODULE_DEVICE_TABLE(of, of_palmas_gpadc_match_tbl); + +static struct platform_driver palmas_gpadc_driver = { + .probe = palmas_gpadc_probe, + .remove = palmas_gpadc_remove, + .driver = { + .name = MOD_NAME, + .pm = &palmas_pm_ops, + .of_match_table = of_palmas_gpadc_match_tbl, + }, +}; + +static int __init palmas_gpadc_init(void) +{ + return platform_driver_register(&palmas_gpadc_driver); +} +module_init(palmas_gpadc_init); + +static void __exit palmas_gpadc_exit(void) +{ + platform_driver_unregister(&palmas_gpadc_driver); +} +module_exit(palmas_gpadc_exit); + +MODULE_DESCRIPTION("palmas GPADC driver"); +MODULE_AUTHOR("Pradeep Goudagunta<pgoudagunta@nvidia.com>"); +MODULE_ALIAS("platform:palmas-gpadc"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c index ff6f7f63c8d9..bc58867d6e8d 100644 --- a/drivers/iio/adc/ti-adc128s052.c +++ b/drivers/iio/adc/ti-adc128s052.c @@ -1,10 +1,11 @@ /* * Copyright (C) 2014 Angelo Compagnucci <angelo.compagnucci@gmail.com> * - * Driver for Texas Instruments' ADC128S052 and ADC122S021 ADC chip. + * Driver for Texas Instruments' ADC128S052, ADC122S021 and ADC124S021 ADC chip. * Datasheets can be found here: * http://www.ti.com/lit/ds/symlink/adc128s052.pdf * http://www.ti.com/lit/ds/symlink/adc122s021.pdf + * http://www.ti.com/lit/ds/symlink/adc124s021.pdf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -114,9 +115,17 @@ static const struct iio_chan_spec adc122s021_channels[] = { ADC128_VOLTAGE_CHANNEL(1), }; +static const struct iio_chan_spec adc124s021_channels[] = { + ADC128_VOLTAGE_CHANNEL(0), + ADC128_VOLTAGE_CHANNEL(1), + ADC128_VOLTAGE_CHANNEL(2), + ADC128_VOLTAGE_CHANNEL(3), +}; + static const struct adc128_configuration adc128_config[] = { { adc128s052_channels, ARRAY_SIZE(adc128s052_channels) }, { adc122s021_channels, ARRAY_SIZE(adc122s021_channels) }, + { adc124s021_channels, ARRAY_SIZE(adc124s021_channels) }, }; static const struct iio_info adc128_info = { @@ -177,6 +186,7 @@ static int adc128_remove(struct spi_device *spi) static const struct of_device_id adc128_of_match[] = { { .compatible = "ti,adc128s052", }, { .compatible = "ti,adc122s021", }, + { .compatible = "ti,adc124s021", }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, adc128_of_match); @@ -184,6 +194,7 @@ MODULE_DEVICE_TABLE(of, adc128_of_match); static const struct spi_device_id adc128_id[] = { { "adc128s052", 0}, /* index into adc128_config */ { "adc122s021", 1}, + { "adc124s021", 2}, { } }; MODULE_DEVICE_TABLE(spi, adc128_id); diff --git a/drivers/iio/adc/ti-ads8688.c b/drivers/iio/adc/ti-ads8688.c new file mode 100644 index 000000000000..03e907028cb6 --- /dev/null +++ b/drivers/iio/adc/ti-ads8688.c @@ -0,0 +1,486 @@ +/* + * Copyright (C) 2015 Prevas A/S + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/spi/spi.h> +#include <linux/regulator/consumer.h> +#include <linux/err.h> +#include <linux/module.h> +#include <linux/of.h> + +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> + +#define ADS8688_CMD_REG(x) (x << 8) +#define ADS8688_CMD_REG_NOOP 0x00 +#define ADS8688_CMD_REG_RST 0x85 +#define ADS8688_CMD_REG_MAN_CH(chan) (0xC0 | (4 * chan)) +#define ADS8688_CMD_DONT_CARE_BITS 16 + +#define ADS8688_PROG_REG(x) (x << 9) +#define ADS8688_PROG_REG_RANGE_CH(chan) (0x05 + chan) +#define ADS8688_PROG_WR_BIT BIT(8) +#define ADS8688_PROG_DONT_CARE_BITS 8 + +#define ADS8688_REG_PLUSMINUS25VREF 0 +#define ADS8688_REG_PLUSMINUS125VREF 1 +#define ADS8688_REG_PLUSMINUS0625VREF 2 +#define ADS8688_REG_PLUS25VREF 5 +#define ADS8688_REG_PLUS125VREF 6 + +#define ADS8688_VREF_MV 4096 +#define ADS8688_REALBITS 16 + +/* + * enum ads8688_range - ADS8688 reference voltage range + * @ADS8688_PLUSMINUS25VREF: Device is configured for input range ±2.5 * VREF + * @ADS8688_PLUSMINUS125VREF: Device is configured for input range ±1.25 * VREF + * @ADS8688_PLUSMINUS0625VREF: Device is configured for input range ±0.625 * VREF + * @ADS8688_PLUS25VREF: Device is configured for input range 0 - 2.5 * VREF + * @ADS8688_PLUS125VREF: Device is configured for input range 0 - 1.25 * VREF + */ +enum ads8688_range { + ADS8688_PLUSMINUS25VREF, + ADS8688_PLUSMINUS125VREF, + ADS8688_PLUSMINUS0625VREF, + ADS8688_PLUS25VREF, + ADS8688_PLUS125VREF, +}; + +struct ads8688_chip_info { + const struct iio_chan_spec *channels; + unsigned int num_channels; +}; + +struct ads8688_state { + struct mutex lock; + const struct ads8688_chip_info *chip_info; + struct spi_device *spi; + struct regulator *reg; + unsigned int vref_mv; + enum ads8688_range range[8]; + union { + __be32 d32; + u8 d8[4]; + } data[2] ____cacheline_aligned; +}; + +enum ads8688_id { + ID_ADS8684, + ID_ADS8688, +}; + +struct ads8688_ranges { + enum ads8688_range range; + unsigned int scale; + int offset; + u8 reg; +}; + +static const struct ads8688_ranges ads8688_range_def[5] = { + { + .range = ADS8688_PLUSMINUS25VREF, + .scale = 76295, + .offset = -(1 << (ADS8688_REALBITS - 1)), + .reg = ADS8688_REG_PLUSMINUS25VREF, + }, { + .range = ADS8688_PLUSMINUS125VREF, + .scale = 38148, + .offset = -(1 << (ADS8688_REALBITS - 1)), + .reg = ADS8688_REG_PLUSMINUS125VREF, + }, { + .range = ADS8688_PLUSMINUS0625VREF, + .scale = 19074, + .offset = -(1 << (ADS8688_REALBITS - 1)), + .reg = ADS8688_REG_PLUSMINUS0625VREF, + }, { + .range = ADS8688_PLUS25VREF, + .scale = 38148, + .offset = 0, + .reg = ADS8688_REG_PLUS25VREF, + }, { + .range = ADS8688_PLUS125VREF, + .scale = 19074, + .offset = 0, + .reg = ADS8688_REG_PLUS125VREF, + } +}; + +static ssize_t ads8688_show_scales(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct ads8688_state *st = iio_priv(dev_to_iio_dev(dev)); + + return sprintf(buf, "0.%09u 0.%09u 0.%09u\n", + ads8688_range_def[0].scale * st->vref_mv, + ads8688_range_def[1].scale * st->vref_mv, + ads8688_range_def[2].scale * st->vref_mv); +} + +static ssize_t ads8688_show_offsets(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d %d\n", ads8688_range_def[0].offset, + ads8688_range_def[3].offset); +} + +static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO, + ads8688_show_scales, NULL, 0); +static IIO_DEVICE_ATTR(in_voltage_offset_available, S_IRUGO, + ads8688_show_offsets, NULL, 0); + +static struct attribute *ads8688_attributes[] = { + &iio_dev_attr_in_voltage_scale_available.dev_attr.attr, + &iio_dev_attr_in_voltage_offset_available.dev_attr.attr, + NULL, +}; + +static const struct attribute_group ads8688_attribute_group = { + .attrs = ads8688_attributes, +}; + +#define ADS8688_CHAN(index) \ +{ \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = index, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) \ + | BIT(IIO_CHAN_INFO_SCALE) \ + | BIT(IIO_CHAN_INFO_OFFSET), \ +} + +static const struct iio_chan_spec ads8684_channels[] = { + ADS8688_CHAN(0), + ADS8688_CHAN(1), + ADS8688_CHAN(2), + ADS8688_CHAN(3), +}; + +static const struct iio_chan_spec ads8688_channels[] = { + ADS8688_CHAN(0), + ADS8688_CHAN(1), + ADS8688_CHAN(2), + ADS8688_CHAN(3), + ADS8688_CHAN(4), + ADS8688_CHAN(5), + ADS8688_CHAN(6), + ADS8688_CHAN(7), +}; + +static int ads8688_prog_write(struct iio_dev *indio_dev, unsigned int addr, + unsigned int val) +{ + struct ads8688_state *st = iio_priv(indio_dev); + u32 tmp; + + tmp = ADS8688_PROG_REG(addr) | ADS8688_PROG_WR_BIT | val; + tmp <<= ADS8688_PROG_DONT_CARE_BITS; + st->data[0].d32 = cpu_to_be32(tmp); + + return spi_write(st->spi, &st->data[0].d8[1], 3); +} + +static int ads8688_reset(struct iio_dev *indio_dev) +{ + struct ads8688_state *st = iio_priv(indio_dev); + u32 tmp; + + tmp = ADS8688_CMD_REG(ADS8688_CMD_REG_RST); + tmp <<= ADS8688_CMD_DONT_CARE_BITS; + st->data[0].d32 = cpu_to_be32(tmp); + + return spi_write(st->spi, &st->data[0].d8[0], 4); +} + +static int ads8688_read(struct iio_dev *indio_dev, unsigned int chan) +{ + struct ads8688_state *st = iio_priv(indio_dev); + int ret; + u32 tmp; + struct spi_transfer t[] = { + { + .tx_buf = &st->data[0].d8[0], + .len = 4, + .cs_change = 1, + }, { + .tx_buf = &st->data[1].d8[0], + .rx_buf = &st->data[1].d8[0], + .len = 4, + }, + }; + + tmp = ADS8688_CMD_REG(ADS8688_CMD_REG_MAN_CH(chan)); + tmp <<= ADS8688_CMD_DONT_CARE_BITS; + st->data[0].d32 = cpu_to_be32(tmp); + + tmp = ADS8688_CMD_REG(ADS8688_CMD_REG_NOOP); + tmp <<= ADS8688_CMD_DONT_CARE_BITS; + st->data[1].d32 = cpu_to_be32(tmp); + + ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); + if (ret < 0) + return ret; + + return be32_to_cpu(st->data[1].d32) & 0xffff; +} + +static int ads8688_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long m) +{ + int ret, offset; + unsigned long scale_mv; + + struct ads8688_state *st = iio_priv(indio_dev); + + mutex_lock(&st->lock); + switch (m) { + case IIO_CHAN_INFO_RAW: + ret = ads8688_read(indio_dev, chan->channel); + mutex_unlock(&st->lock); + if (ret < 0) + return ret; + *val = ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + scale_mv = st->vref_mv; + scale_mv *= ads8688_range_def[st->range[chan->channel]].scale; + *val = 0; + *val2 = scale_mv; + mutex_unlock(&st->lock); + return IIO_VAL_INT_PLUS_NANO; + case IIO_CHAN_INFO_OFFSET: + offset = ads8688_range_def[st->range[chan->channel]].offset; + *val = offset; + mutex_unlock(&st->lock); + return IIO_VAL_INT; + } + mutex_unlock(&st->lock); + + return -EINVAL; +} + +static int ads8688_write_reg_range(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + enum ads8688_range range) +{ + unsigned int tmp; + int ret; + + tmp = ADS8688_PROG_REG_RANGE_CH(chan->channel); + ret = ads8688_prog_write(indio_dev, tmp, range); + + return ret; +} + +static int ads8688_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct ads8688_state *st = iio_priv(indio_dev); + unsigned int scale = 0; + int ret = -EINVAL, i, offset = 0; + + mutex_lock(&st->lock); + switch (mask) { + case IIO_CHAN_INFO_SCALE: + /* If the offset is 0 the ±2.5 * VREF mode is not available */ + offset = ads8688_range_def[st->range[chan->channel]].offset; + if (offset == 0 && val2 == ads8688_range_def[0].scale * st->vref_mv) { + mutex_unlock(&st->lock); + return -EINVAL; + } + + /* Lookup new mode */ + for (i = 0; i < ARRAY_SIZE(ads8688_range_def); i++) + if (val2 == ads8688_range_def[i].scale * st->vref_mv && + offset == ads8688_range_def[i].offset) { + ret = ads8688_write_reg_range(indio_dev, chan, + ads8688_range_def[i].reg); + break; + } + break; + case IIO_CHAN_INFO_OFFSET: + /* + * There are only two available offsets: + * 0 and -(1 << (ADS8688_REALBITS - 1)) + */ + if (!(ads8688_range_def[0].offset == val || + ads8688_range_def[3].offset == val)) { + mutex_unlock(&st->lock); + return -EINVAL; + } + + /* + * If the device are in ±2.5 * VREF mode, it's not allowed to + * switch to a mode where the offset is 0 + */ + if (val == 0 && + st->range[chan->channel] == ADS8688_PLUSMINUS25VREF) { + mutex_unlock(&st->lock); + return -EINVAL; + } + + scale = ads8688_range_def[st->range[chan->channel]].scale; + + /* Lookup new mode */ + for (i = 0; i < ARRAY_SIZE(ads8688_range_def); i++) + if (val == ads8688_range_def[i].offset && + scale == ads8688_range_def[i].scale) { + ret = ads8688_write_reg_range(indio_dev, chan, + ads8688_range_def[i].reg); + break; + } + break; + } + + if (!ret) + st->range[chan->channel] = ads8688_range_def[i].range; + + mutex_unlock(&st->lock); + + return ret; +} + +static int ads8688_write_raw_get_fmt(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_SCALE: + return IIO_VAL_INT_PLUS_NANO; + case IIO_CHAN_INFO_OFFSET: + return IIO_VAL_INT; + } + + return -EINVAL; +} + +static const struct iio_info ads8688_info = { + .read_raw = &ads8688_read_raw, + .write_raw = &ads8688_write_raw, + .write_raw_get_fmt = &ads8688_write_raw_get_fmt, + .attrs = &ads8688_attribute_group, + .driver_module = THIS_MODULE, +}; + +static const struct ads8688_chip_info ads8688_chip_info_tbl[] = { + [ID_ADS8684] = { + .channels = ads8684_channels, + .num_channels = ARRAY_SIZE(ads8684_channels), + }, + [ID_ADS8688] = { + .channels = ads8688_channels, + .num_channels = ARRAY_SIZE(ads8688_channels), + }, +}; + +static int ads8688_probe(struct spi_device *spi) +{ + struct ads8688_state *st; + struct iio_dev *indio_dev; + int ret; + + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); + if (indio_dev == NULL) + return -ENOMEM; + + st = iio_priv(indio_dev); + + st->reg = devm_regulator_get_optional(&spi->dev, "vref"); + if (!IS_ERR(st->reg)) { + ret = regulator_enable(st->reg); + if (ret) + return ret; + + ret = regulator_get_voltage(st->reg); + if (ret < 0) + goto error_out; + + st->vref_mv = ret / 1000; + } else { + /* Use internal reference */ + st->vref_mv = ADS8688_VREF_MV; + } + + st->chip_info = &ads8688_chip_info_tbl[spi_get_device_id(spi)->driver_data]; + + spi->mode = SPI_MODE_1; + + spi_set_drvdata(spi, indio_dev); + + st->spi = spi; + + indio_dev->name = spi_get_device_id(spi)->name; + indio_dev->dev.parent = &spi->dev; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = st->chip_info->channels; + indio_dev->num_channels = st->chip_info->num_channels; + indio_dev->info = &ads8688_info; + + ads8688_reset(indio_dev); + + mutex_init(&st->lock); + + ret = iio_device_register(indio_dev); + if (ret) + goto error_out; + + return 0; + +error_out: + if (!IS_ERR_OR_NULL(st->reg)) + regulator_disable(st->reg); + + return ret; +} + +static int ads8688_remove(struct spi_device *spi) +{ + struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct ads8688_state *st = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + + if (!IS_ERR_OR_NULL(st->reg)) + regulator_disable(st->reg); + + return 0; +} + +static const struct spi_device_id ads8688_id[] = { + {"ads8684", ID_ADS8684}, + {"ads8688", ID_ADS8688}, + {} +}; +MODULE_DEVICE_TABLE(spi, ads8688_id); + +static const struct of_device_id ads8688_of_match[] = { + { .compatible = "ti,ads8684" }, + { .compatible = "ti,ads8688" }, + { } +}; +MODULE_DEVICE_TABLE(of, ads8688_of_match); + +static struct spi_driver ads8688_driver = { + .driver = { + .name = "ads8688", + .owner = THIS_MODULE, + }, + .probe = ads8688_probe, + .remove = ads8688_remove, + .id_table = ads8688_id, +}; +module_spi_driver(ads8688_driver); + +MODULE_AUTHOR("Sean Nyekjaer <sean.nyekjaer@prevas.dk>"); +MODULE_DESCRIPTION("Texas Instruments ADS8688 driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index 02e636a1c49a..0a6beb3d99cb 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -803,7 +803,7 @@ err: return ret; } -static struct iio_buffer_setup_ops xadc_buffer_ops = { +static const struct iio_buffer_setup_ops xadc_buffer_ops = { .preenable = &xadc_preenable, .postenable = &iio_triggered_buffer_postenable, .predisable = &iio_triggered_buffer_predisable, diff --git a/drivers/iio/buffer/Kconfig b/drivers/iio/buffer/Kconfig index 0a7b2fd3699b..4ffd3db7817f 100644 --- a/drivers/iio/buffer/Kconfig +++ b/drivers/iio/buffer/Kconfig @@ -9,6 +9,26 @@ config IIO_BUFFER_CB Should be selected by any drivers that do in-kernel push usage. That is, those where the data is pushed to the consumer. +config IIO_BUFFER_DMA + tristate + help + Provides the generic IIO DMA buffer infrastructure that can be used by + drivers for devices with DMA support to implement the IIO buffer. + + Should be selected by drivers that want to use the generic DMA buffer + infrastructure. + +config IIO_BUFFER_DMAENGINE + tristate + select IIO_BUFFER_DMA + help + Provides a bonding of the generic IIO DMA buffer infrastructure with the + DMAengine framework. This can be used by converter drivers with a DMA port + connected to an external DMA controller which is supported by the + DMAengine framework. + + Should be selected by drivers that want to use this functionality. + config IIO_KFIFO_BUF tristate "Industrial I/O buffering based on kfifo" help diff --git a/drivers/iio/buffer/Makefile b/drivers/iio/buffer/Makefile index 4d193b9a9123..85beaae831ae 100644 --- a/drivers/iio/buffer/Makefile +++ b/drivers/iio/buffer/Makefile @@ -4,5 +4,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_IIO_BUFFER_CB) += industrialio-buffer-cb.o +obj-$(CONFIG_IIO_BUFFER_DMA) += industrialio-buffer-dma.o +obj-$(CONFIG_IIO_BUFFER_DMAENGINE) += industrialio-buffer-dmaengine.o obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o diff --git a/drivers/iio/buffer/industrialio-buffer-dma.c b/drivers/iio/buffer/industrialio-buffer-dma.c new file mode 100644 index 000000000000..212cbedc7abb --- /dev/null +++ b/drivers/iio/buffer/industrialio-buffer-dma.c @@ -0,0 +1,683 @@ +/* + * Copyright 2013-2015 Analog Devices Inc. + * Author: Lars-Peter Clausen <lars@metafoo.de> + * + * Licensed under the GPL-2. + */ + +#include <linux/slab.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/device.h> +#include <linux/workqueue.h> +#include <linux/mutex.h> +#include <linux/sched.h> +#include <linux/poll.h> +#include <linux/iio/buffer.h> +#include <linux/iio/buffer-dma.h> +#include <linux/dma-mapping.h> +#include <linux/sizes.h> + +/* + * For DMA buffers the storage is sub-divided into so called blocks. Each block + * has its own memory buffer. The size of the block is the granularity at which + * memory is exchanged between the hardware and the application. Increasing the + * basic unit of data exchange from one sample to one block decreases the + * management overhead that is associated with each sample. E.g. if we say the + * management overhead for one exchange is x and the unit of exchange is one + * sample the overhead will be x for each sample. Whereas when using a block + * which contains n samples the overhead per sample is reduced to x/n. This + * allows to achieve much higher samplerates than what can be sustained with + * the one sample approach. + * + * Blocks are exchanged between the DMA controller and the application via the + * means of two queues. The incoming queue and the outgoing queue. Blocks on the + * incoming queue are waiting for the DMA controller to pick them up and fill + * them with data. Block on the outgoing queue have been filled with data and + * are waiting for the application to dequeue them and read the data. + * + * A block can be in one of the following states: + * * Owned by the application. In this state the application can read data from + * the block. + * * On the incoming list: Blocks on the incoming list are queued up to be + * processed by the DMA controller. + * * Owned by the DMA controller: The DMA controller is processing the block + * and filling it with data. + * * On the outgoing list: Blocks on the outgoing list have been successfully + * processed by the DMA controller and contain data. They can be dequeued by + * the application. + * * Dead: A block that is dead has been marked as to be freed. It might still + * be owned by either the application or the DMA controller at the moment. + * But once they are done processing it instead of going to either the + * incoming or outgoing queue the block will be freed. + * + * In addition to this blocks are reference counted and the memory associated + * with both the block structure as well as the storage memory for the block + * will be freed when the last reference to the block is dropped. This means a + * block must not be accessed without holding a reference. + * + * The iio_dma_buffer implementation provides a generic infrastructure for + * managing the blocks. + * + * A driver for a specific piece of hardware that has DMA capabilities need to + * implement the submit() callback from the iio_dma_buffer_ops structure. This + * callback is supposed to initiate the DMA transfer copying data from the + * converter to the memory region of the block. Once the DMA transfer has been + * completed the driver must call iio_dma_buffer_block_done() for the completed + * block. + * + * Prior to this it must set the bytes_used field of the block contains + * the actual number of bytes in the buffer. Typically this will be equal to the + * size of the block, but if the DMA hardware has certain alignment requirements + * for the transfer length it might choose to use less than the full size. In + * either case it is expected that bytes_used is a multiple of the bytes per + * datum, i.e. the block must not contain partial samples. + * + * The driver must call iio_dma_buffer_block_done() for each block it has + * received through its submit_block() callback, even if it does not actually + * perform a DMA transfer for the block, e.g. because the buffer was disabled + * before the block transfer was started. In this case it should set bytes_used + * to 0. + * + * In addition it is recommended that a driver implements the abort() callback. + * It will be called when the buffer is disabled and can be used to cancel + * pending and stop active transfers. + * + * The specific driver implementation should use the default callback + * implementations provided by this module for the iio_buffer_access_funcs + * struct. It may overload some callbacks with custom variants if the hardware + * has special requirements that are not handled by the generic functions. If a + * driver chooses to overload a callback it has to ensure that the generic + * callback is called from within the custom callback. + */ + +static void iio_buffer_block_release(struct kref *kref) +{ + struct iio_dma_buffer_block *block = container_of(kref, + struct iio_dma_buffer_block, kref); + + WARN_ON(block->state != IIO_BLOCK_STATE_DEAD); + + dma_free_coherent(block->queue->dev, PAGE_ALIGN(block->size), + block->vaddr, block->phys_addr); + + iio_buffer_put(&block->queue->buffer); + kfree(block); +} + +static void iio_buffer_block_get(struct iio_dma_buffer_block *block) +{ + kref_get(&block->kref); +} + +static void iio_buffer_block_put(struct iio_dma_buffer_block *block) +{ + kref_put(&block->kref, iio_buffer_block_release); +} + +/* + * dma_free_coherent can sleep, hence we need to take some special care to be + * able to drop a reference from an atomic context. + */ +static LIST_HEAD(iio_dma_buffer_dead_blocks); +static DEFINE_SPINLOCK(iio_dma_buffer_dead_blocks_lock); + +static void iio_dma_buffer_cleanup_worker(struct work_struct *work) +{ + struct iio_dma_buffer_block *block, *_block; + LIST_HEAD(block_list); + + spin_lock_irq(&iio_dma_buffer_dead_blocks_lock); + list_splice_tail_init(&iio_dma_buffer_dead_blocks, &block_list); + spin_unlock_irq(&iio_dma_buffer_dead_blocks_lock); + + list_for_each_entry_safe(block, _block, &block_list, head) + iio_buffer_block_release(&block->kref); +} +static DECLARE_WORK(iio_dma_buffer_cleanup_work, iio_dma_buffer_cleanup_worker); + +static void iio_buffer_block_release_atomic(struct kref *kref) +{ + struct iio_dma_buffer_block *block; + unsigned long flags; + + block = container_of(kref, struct iio_dma_buffer_block, kref); + + spin_lock_irqsave(&iio_dma_buffer_dead_blocks_lock, flags); + list_add_tail(&block->head, &iio_dma_buffer_dead_blocks); + spin_unlock_irqrestore(&iio_dma_buffer_dead_blocks_lock, flags); + + schedule_work(&iio_dma_buffer_cleanup_work); +} + +/* + * Version of iio_buffer_block_put() that can be called from atomic context + */ +static void iio_buffer_block_put_atomic(struct iio_dma_buffer_block *block) +{ + kref_put(&block->kref, iio_buffer_block_release_atomic); +} + +static struct iio_dma_buffer_queue *iio_buffer_to_queue(struct iio_buffer *buf) +{ + return container_of(buf, struct iio_dma_buffer_queue, buffer); +} + +static struct iio_dma_buffer_block *iio_dma_buffer_alloc_block( + struct iio_dma_buffer_queue *queue, size_t size) +{ + struct iio_dma_buffer_block *block; + + block = kzalloc(sizeof(*block), GFP_KERNEL); + if (!block) + return NULL; + + block->vaddr = dma_alloc_coherent(queue->dev, PAGE_ALIGN(size), + &block->phys_addr, GFP_KERNEL); + if (!block->vaddr) { + kfree(block); + return NULL; + } + + block->size = size; + block->state = IIO_BLOCK_STATE_DEQUEUED; + block->queue = queue; + INIT_LIST_HEAD(&block->head); + kref_init(&block->kref); + + iio_buffer_get(&queue->buffer); + + return block; +} + +static void _iio_dma_buffer_block_done(struct iio_dma_buffer_block *block) +{ + struct iio_dma_buffer_queue *queue = block->queue; + + /* + * The buffer has already been freed by the application, just drop the + * reference. + */ + if (block->state != IIO_BLOCK_STATE_DEAD) { + block->state = IIO_BLOCK_STATE_DONE; + list_add_tail(&block->head, &queue->outgoing); + } +} + +/** + * iio_dma_buffer_block_done() - Indicate that a block has been completed + * @block: The completed block + * + * Should be called when the DMA controller has finished handling the block to + * pass back ownership of the block to the queue. + */ +void iio_dma_buffer_block_done(struct iio_dma_buffer_block *block) +{ + struct iio_dma_buffer_queue *queue = block->queue; + unsigned long flags; + + spin_lock_irqsave(&queue->list_lock, flags); + _iio_dma_buffer_block_done(block); + spin_unlock_irqrestore(&queue->list_lock, flags); + + iio_buffer_block_put_atomic(block); + wake_up_interruptible_poll(&queue->buffer.pollq, POLLIN | POLLRDNORM); +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_block_done); + +/** + * iio_dma_buffer_block_list_abort() - Indicate that a list block has been + * aborted + * @queue: Queue for which to complete blocks. + * @list: List of aborted blocks. All blocks in this list must be from @queue. + * + * Typically called from the abort() callback after the DMA controller has been + * stopped. This will set bytes_used to 0 for each block in the list and then + * hand the blocks back to the queue. + */ +void iio_dma_buffer_block_list_abort(struct iio_dma_buffer_queue *queue, + struct list_head *list) +{ + struct iio_dma_buffer_block *block, *_block; + unsigned long flags; + + spin_lock_irqsave(&queue->list_lock, flags); + list_for_each_entry_safe(block, _block, list, head) { + list_del(&block->head); + block->bytes_used = 0; + _iio_dma_buffer_block_done(block); + iio_buffer_block_put_atomic(block); + } + spin_unlock_irqrestore(&queue->list_lock, flags); + + wake_up_interruptible_poll(&queue->buffer.pollq, POLLIN | POLLRDNORM); +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_block_list_abort); + +static bool iio_dma_block_reusable(struct iio_dma_buffer_block *block) +{ + /* + * If the core owns the block it can be re-used. This should be the + * default case when enabling the buffer, unless the DMA controller does + * not support abort and has not given back the block yet. + */ + switch (block->state) { + case IIO_BLOCK_STATE_DEQUEUED: + case IIO_BLOCK_STATE_QUEUED: + case IIO_BLOCK_STATE_DONE: + return true; + default: + return false; + } +} + +/** + * iio_dma_buffer_request_update() - DMA buffer request_update callback + * @buffer: The buffer which to request an update + * + * Should be used as the iio_dma_buffer_request_update() callback for + * iio_buffer_access_ops struct for DMA buffers. + */ +int iio_dma_buffer_request_update(struct iio_buffer *buffer) +{ + struct iio_dma_buffer_queue *queue = iio_buffer_to_queue(buffer); + struct iio_dma_buffer_block *block; + bool try_reuse = false; + size_t size; + int ret = 0; + int i; + + /* + * Split the buffer into two even parts. This is used as a double + * buffering scheme with usually one block at a time being used by the + * DMA and the other one by the application. + */ + size = DIV_ROUND_UP(queue->buffer.bytes_per_datum * + queue->buffer.length, 2); + + mutex_lock(&queue->lock); + + /* Allocations are page aligned */ + if (PAGE_ALIGN(queue->fileio.block_size) == PAGE_ALIGN(size)) + try_reuse = true; + + queue->fileio.block_size = size; + queue->fileio.active_block = NULL; + + spin_lock_irq(&queue->list_lock); + for (i = 0; i < 2; i++) { + block = queue->fileio.blocks[i]; + + /* If we can't re-use it free it */ + if (block && (!iio_dma_block_reusable(block) || !try_reuse)) + block->state = IIO_BLOCK_STATE_DEAD; + } + + /* + * At this point all blocks are either owned by the core or marked as + * dead. This means we can reset the lists without having to fear + * corrution. + */ + INIT_LIST_HEAD(&queue->outgoing); + spin_unlock_irq(&queue->list_lock); + + INIT_LIST_HEAD(&queue->incoming); + + for (i = 0; i < 2; i++) { + if (queue->fileio.blocks[i]) { + block = queue->fileio.blocks[i]; + if (block->state == IIO_BLOCK_STATE_DEAD) { + /* Could not reuse it */ + iio_buffer_block_put(block); + block = NULL; + } else { + block->size = size; + } + } else { + block = NULL; + } + + if (!block) { + block = iio_dma_buffer_alloc_block(queue, size); + if (!block) { + ret = -ENOMEM; + goto out_unlock; + } + queue->fileio.blocks[i] = block; + } + + block->state = IIO_BLOCK_STATE_QUEUED; + list_add_tail(&block->head, &queue->incoming); + } + +out_unlock: + mutex_unlock(&queue->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_request_update); + +static void iio_dma_buffer_submit_block(struct iio_dma_buffer_queue *queue, + struct iio_dma_buffer_block *block) +{ + int ret; + + /* + * If the hardware has already been removed we put the block into + * limbo. It will neither be on the incoming nor outgoing list, nor will + * it ever complete. It will just wait to be freed eventually. + */ + if (!queue->ops) + return; + + block->state = IIO_BLOCK_STATE_ACTIVE; + iio_buffer_block_get(block); + ret = queue->ops->submit(queue, block); + if (ret) { + /* + * This is a bit of a problem and there is not much we can do + * other then wait for the buffer to be disabled and re-enabled + * and try again. But it should not really happen unless we run + * out of memory or something similar. + * + * TODO: Implement support in the IIO core to allow buffers to + * notify consumers that something went wrong and the buffer + * should be disabled. + */ + iio_buffer_block_put(block); + } +} + +/** + * iio_dma_buffer_enable() - Enable DMA buffer + * @buffer: IIO buffer to enable + * @indio_dev: IIO device the buffer is attached to + * + * Needs to be called when the device that the buffer is attached to starts + * sampling. Typically should be the iio_buffer_access_ops enable callback. + * + * This will allocate the DMA buffers and start the DMA transfers. + */ +int iio_dma_buffer_enable(struct iio_buffer *buffer, + struct iio_dev *indio_dev) +{ + struct iio_dma_buffer_queue *queue = iio_buffer_to_queue(buffer); + struct iio_dma_buffer_block *block, *_block; + + mutex_lock(&queue->lock); + queue->active = true; + list_for_each_entry_safe(block, _block, &queue->incoming, head) { + list_del(&block->head); + iio_dma_buffer_submit_block(queue, block); + } + mutex_unlock(&queue->lock); + + return 0; +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_enable); + +/** + * iio_dma_buffer_disable() - Disable DMA buffer + * @buffer: IIO DMA buffer to disable + * @indio_dev: IIO device the buffer is attached to + * + * Needs to be called when the device that the buffer is attached to stops + * sampling. Typically should be the iio_buffer_access_ops disable callback. + */ +int iio_dma_buffer_disable(struct iio_buffer *buffer, + struct iio_dev *indio_dev) +{ + struct iio_dma_buffer_queue *queue = iio_buffer_to_queue(buffer); + + mutex_lock(&queue->lock); + queue->active = false; + + if (queue->ops && queue->ops->abort) + queue->ops->abort(queue); + mutex_unlock(&queue->lock); + + return 0; +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_disable); + +static void iio_dma_buffer_enqueue(struct iio_dma_buffer_queue *queue, + struct iio_dma_buffer_block *block) +{ + if (block->state == IIO_BLOCK_STATE_DEAD) { + iio_buffer_block_put(block); + } else if (queue->active) { + iio_dma_buffer_submit_block(queue, block); + } else { + block->state = IIO_BLOCK_STATE_QUEUED; + list_add_tail(&block->head, &queue->incoming); + } +} + +static struct iio_dma_buffer_block *iio_dma_buffer_dequeue( + struct iio_dma_buffer_queue *queue) +{ + struct iio_dma_buffer_block *block; + + spin_lock_irq(&queue->list_lock); + block = list_first_entry_or_null(&queue->outgoing, struct + iio_dma_buffer_block, head); + if (block != NULL) { + list_del(&block->head); + block->state = IIO_BLOCK_STATE_DEQUEUED; + } + spin_unlock_irq(&queue->list_lock); + + return block; +} + +/** + * iio_dma_buffer_read() - DMA buffer read callback + * @buffer: Buffer to read form + * @n: Number of bytes to read + * @user_buffer: Userspace buffer to copy the data to + * + * Should be used as the read_first_n callback for iio_buffer_access_ops + * struct for DMA buffers. + */ +int iio_dma_buffer_read(struct iio_buffer *buffer, size_t n, + char __user *user_buffer) +{ + struct iio_dma_buffer_queue *queue = iio_buffer_to_queue(buffer); + struct iio_dma_buffer_block *block; + int ret; + + if (n < buffer->bytes_per_datum) + return -EINVAL; + + mutex_lock(&queue->lock); + + if (!queue->fileio.active_block) { + block = iio_dma_buffer_dequeue(queue); + if (block == NULL) { + ret = 0; + goto out_unlock; + } + queue->fileio.pos = 0; + queue->fileio.active_block = block; + } else { + block = queue->fileio.active_block; + } + + n = rounddown(n, buffer->bytes_per_datum); + if (n > block->bytes_used - queue->fileio.pos) + n = block->bytes_used - queue->fileio.pos; + + if (copy_to_user(user_buffer, block->vaddr + queue->fileio.pos, n)) { + ret = -EFAULT; + goto out_unlock; + } + + queue->fileio.pos += n; + + if (queue->fileio.pos == block->bytes_used) { + queue->fileio.active_block = NULL; + iio_dma_buffer_enqueue(queue, block); + } + + ret = n; + +out_unlock: + mutex_unlock(&queue->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_read); + +/** + * iio_dma_buffer_data_available() - DMA buffer data_available callback + * @buf: Buffer to check for data availability + * + * Should be used as the data_available callback for iio_buffer_access_ops + * struct for DMA buffers. + */ +size_t iio_dma_buffer_data_available(struct iio_buffer *buf) +{ + struct iio_dma_buffer_queue *queue = iio_buffer_to_queue(buf); + struct iio_dma_buffer_block *block; + size_t data_available = 0; + + /* + * For counting the available bytes we'll use the size of the block not + * the number of actual bytes available in the block. Otherwise it is + * possible that we end up with a value that is lower than the watermark + * but won't increase since all blocks are in use. + */ + + mutex_lock(&queue->lock); + if (queue->fileio.active_block) + data_available += queue->fileio.active_block->size; + + spin_lock_irq(&queue->list_lock); + list_for_each_entry(block, &queue->outgoing, head) + data_available += block->size; + spin_unlock_irq(&queue->list_lock); + mutex_unlock(&queue->lock); + + return data_available; +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_data_available); + +/** + * iio_dma_buffer_set_bytes_per_datum() - DMA buffer set_bytes_per_datum callback + * @buffer: Buffer to set the bytes-per-datum for + * @bpd: The new bytes-per-datum value + * + * Should be used as the set_bytes_per_datum callback for iio_buffer_access_ops + * struct for DMA buffers. + */ +int iio_dma_buffer_set_bytes_per_datum(struct iio_buffer *buffer, size_t bpd) +{ + buffer->bytes_per_datum = bpd; + + return 0; +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_set_bytes_per_datum); + +/** + * iio_dma_buffer_set_length - DMA buffer set_length callback + * @buffer: Buffer to set the length for + * @length: The new buffer length + * + * Should be used as the set_length callback for iio_buffer_access_ops + * struct for DMA buffers. + */ +int iio_dma_buffer_set_length(struct iio_buffer *buffer, int length) +{ + /* Avoid an invalid state */ + if (length < 2) + length = 2; + buffer->length = length; + buffer->watermark = length / 2; + + return 0; +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_set_length); + +/** + * iio_dma_buffer_init() - Initialize DMA buffer queue + * @queue: Buffer to initialize + * @dev: DMA device + * @ops: DMA buffer queue callback operations + * + * The DMA device will be used by the queue to do DMA memory allocations. So it + * should refer to the device that will perform the DMA to ensure that + * allocations are done from a memory region that can be accessed by the device. + */ +int iio_dma_buffer_init(struct iio_dma_buffer_queue *queue, + struct device *dev, const struct iio_dma_buffer_ops *ops) +{ + iio_buffer_init(&queue->buffer); + queue->buffer.length = PAGE_SIZE; + queue->buffer.watermark = queue->buffer.length / 2; + queue->dev = dev; + queue->ops = ops; + + INIT_LIST_HEAD(&queue->incoming); + INIT_LIST_HEAD(&queue->outgoing); + + mutex_init(&queue->lock); + spin_lock_init(&queue->list_lock); + + return 0; +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_init); + +/** + * iio_dma_buffer_exit() - Cleanup DMA buffer queue + * @queue: Buffer to cleanup + * + * After this function has completed it is safe to free any resources that are + * associated with the buffer and are accessed inside the callback operations. + */ +void iio_dma_buffer_exit(struct iio_dma_buffer_queue *queue) +{ + unsigned int i; + + mutex_lock(&queue->lock); + + spin_lock_irq(&queue->list_lock); + for (i = 0; i < ARRAY_SIZE(queue->fileio.blocks); i++) { + if (!queue->fileio.blocks[i]) + continue; + queue->fileio.blocks[i]->state = IIO_BLOCK_STATE_DEAD; + } + INIT_LIST_HEAD(&queue->outgoing); + spin_unlock_irq(&queue->list_lock); + + INIT_LIST_HEAD(&queue->incoming); + + for (i = 0; i < ARRAY_SIZE(queue->fileio.blocks); i++) { + if (!queue->fileio.blocks[i]) + continue; + iio_buffer_block_put(queue->fileio.blocks[i]); + queue->fileio.blocks[i] = NULL; + } + queue->fileio.active_block = NULL; + queue->ops = NULL; + + mutex_unlock(&queue->lock); +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_exit); + +/** + * iio_dma_buffer_release() - Release final buffer resources + * @queue: Buffer to release + * + * Frees resources that can't yet be freed in iio_dma_buffer_exit(). Should be + * called in the buffers release callback implementation right before freeing + * the memory associated with the buffer. + */ +void iio_dma_buffer_release(struct iio_dma_buffer_queue *queue) +{ + mutex_destroy(&queue->lock); +} +EXPORT_SYMBOL_GPL(iio_dma_buffer_release); + +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); +MODULE_DESCRIPTION("DMA buffer for the IIO framework"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c new file mode 100644 index 000000000000..ebdb838d3a1c --- /dev/null +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c @@ -0,0 +1,213 @@ +/* + * Copyright 2014-2015 Analog Devices Inc. + * Author: Lars-Peter Clausen <lars@metafoo.de> + * + * Licensed under the GPL-2 or later. + */ + +#include <linux/slab.h> +#include <linux/kernel.h> +#include <linux/dmaengine.h> +#include <linux/dma-mapping.h> +#include <linux/spinlock.h> +#include <linux/err.h> + +#include <linux/iio/iio.h> +#include <linux/iio/buffer.h> +#include <linux/iio/buffer-dma.h> +#include <linux/iio/buffer-dmaengine.h> + +/* + * The IIO DMAengine buffer combines the generic IIO DMA buffer infrastructure + * with the DMAengine framework. The generic IIO DMA buffer infrastructure is + * used to manage the buffer memory and implement the IIO buffer operations + * while the DMAengine framework is used to perform the DMA transfers. Combined + * this results in a device independent fully functional DMA buffer + * implementation that can be used by device drivers for peripherals which are + * connected to a DMA controller which has a DMAengine driver implementation. + */ + +struct dmaengine_buffer { + struct iio_dma_buffer_queue queue; + + struct dma_chan *chan; + struct list_head active; + + size_t align; + size_t max_size; +}; + +static struct dmaengine_buffer *iio_buffer_to_dmaengine_buffer( + struct iio_buffer *buffer) +{ + return container_of(buffer, struct dmaengine_buffer, queue.buffer); +} + +static void iio_dmaengine_buffer_block_done(void *data) +{ + struct iio_dma_buffer_block *block = data; + unsigned long flags; + + spin_lock_irqsave(&block->queue->list_lock, flags); + list_del(&block->head); + spin_unlock_irqrestore(&block->queue->list_lock, flags); + iio_dma_buffer_block_done(block); +} + +static int iio_dmaengine_buffer_submit_block(struct iio_dma_buffer_queue *queue, + struct iio_dma_buffer_block *block) +{ + struct dmaengine_buffer *dmaengine_buffer = + iio_buffer_to_dmaengine_buffer(&queue->buffer); + struct dma_async_tx_descriptor *desc; + dma_cookie_t cookie; + + block->bytes_used = min(block->size, dmaengine_buffer->max_size); + block->bytes_used = rounddown(block->bytes_used, + dmaengine_buffer->align); + + desc = dmaengine_prep_slave_single(dmaengine_buffer->chan, + block->phys_addr, block->bytes_used, DMA_DEV_TO_MEM, + DMA_PREP_INTERRUPT); + if (!desc) + return -ENOMEM; + + desc->callback = iio_dmaengine_buffer_block_done; + desc->callback_param = block; + + cookie = dmaengine_submit(desc); + if (dma_submit_error(cookie)) + return dma_submit_error(cookie); + + spin_lock_irq(&dmaengine_buffer->queue.list_lock); + list_add_tail(&block->head, &dmaengine_buffer->active); + spin_unlock_irq(&dmaengine_buffer->queue.list_lock); + + dma_async_issue_pending(dmaengine_buffer->chan); + + return 0; +} + +static void iio_dmaengine_buffer_abort(struct iio_dma_buffer_queue *queue) +{ + struct dmaengine_buffer *dmaengine_buffer = + iio_buffer_to_dmaengine_buffer(&queue->buffer); + + dmaengine_terminate_all(dmaengine_buffer->chan); + /* FIXME: There is a slight chance of a race condition here. + * dmaengine_terminate_all() does not guarantee that all transfer + * callbacks have finished running. Need to introduce a + * dmaengine_terminate_all_sync(). + */ + iio_dma_buffer_block_list_abort(queue, &dmaengine_buffer->active); +} + +static void iio_dmaengine_buffer_release(struct iio_buffer *buf) +{ + struct dmaengine_buffer *dmaengine_buffer = + iio_buffer_to_dmaengine_buffer(buf); + + iio_dma_buffer_release(&dmaengine_buffer->queue); + kfree(dmaengine_buffer); +} + +static const struct iio_buffer_access_funcs iio_dmaengine_buffer_ops = { + .read_first_n = iio_dma_buffer_read, + .set_bytes_per_datum = iio_dma_buffer_set_bytes_per_datum, + .set_length = iio_dma_buffer_set_length, + .request_update = iio_dma_buffer_request_update, + .enable = iio_dma_buffer_enable, + .disable = iio_dma_buffer_disable, + .data_available = iio_dma_buffer_data_available, + .release = iio_dmaengine_buffer_release, + + .modes = INDIO_BUFFER_HARDWARE, + .flags = INDIO_BUFFER_FLAG_FIXED_WATERMARK, +}; + +static const struct iio_dma_buffer_ops iio_dmaengine_default_ops = { + .submit = iio_dmaengine_buffer_submit_block, + .abort = iio_dmaengine_buffer_abort, +}; + +/** + * iio_dmaengine_buffer_alloc() - Allocate new buffer which uses DMAengine + * @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. + * + * Once done using the buffer iio_dmaengine_buffer_free() should be used to + * release it. + */ +struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev, + const char *channel) +{ + struct dmaengine_buffer *dmaengine_buffer; + unsigned int width, src_width, dest_width; + struct dma_slave_caps caps; + struct dma_chan *chan; + int ret; + + dmaengine_buffer = kzalloc(sizeof(*dmaengine_buffer), GFP_KERNEL); + if (!dmaengine_buffer) + return ERR_PTR(-ENOMEM); + + chan = dma_request_slave_channel_reason(dev, channel); + if (IS_ERR(chan)) { + ret = PTR_ERR(chan); + goto err_free; + } + + ret = dma_get_slave_caps(chan, &caps); + if (ret < 0) + goto err_free; + + /* Needs to be aligned to the maximum of the minimums */ + if (caps.src_addr_widths) + src_width = __ffs(caps.src_addr_widths); + else + src_width = 1; + if (caps.dst_addr_widths) + dest_width = __ffs(caps.dst_addr_widths); + else + dest_width = 1; + width = max(src_width, dest_width); + + INIT_LIST_HEAD(&dmaengine_buffer->active); + dmaengine_buffer->chan = chan; + dmaengine_buffer->align = width; + dmaengine_buffer->max_size = dma_get_max_seg_size(chan->device->dev); + + iio_dma_buffer_init(&dmaengine_buffer->queue, chan->device->dev, + &iio_dmaengine_default_ops); + + dmaengine_buffer->queue.buffer.access = &iio_dmaengine_buffer_ops; + + return &dmaengine_buffer->queue.buffer; + +err_free: + kfree(dmaengine_buffer); + return ERR_PTR(ret); +} +EXPORT_SYMBOL(iio_dmaengine_buffer_alloc); + +/** + * iio_dmaengine_buffer_free() - Free dmaengine buffer + * @buffer: Buffer to free + * + * Frees a buffer previously allocated with iio_dmaengine_buffer_alloc(). + */ +void iio_dmaengine_buffer_free(struct iio_buffer *buffer) +{ + struct dmaengine_buffer *dmaengine_buffer = + iio_buffer_to_dmaengine_buffer(buffer); + + iio_dma_buffer_exit(&dmaengine_buffer->queue); + dma_release_channel(dmaengine_buffer->chan); + + iio_buffer_put(buffer); +} +EXPORT_SYMBOL_GPL(iio_dmaengine_buffer_free); diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig index 3061b7299f0f..f16de61be46d 100644 --- a/drivers/iio/chemical/Kconfig +++ b/drivers/iio/chemical/Kconfig @@ -4,6 +4,14 @@ menu "Chemical Sensors" +config IAQCORE + tristate "AMS iAQ-Core VOC sensors" + depends on I2C + help + Say Y here to build I2C interface support for the AMS + iAQ-Core Continuous/Pulsed VOC (Volatile Organic Compounds) + sensors + config VZ89X tristate "SGX Sensortech MiCS VZ89X VOC sensor" depends on I2C diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile index 7292f2ded587..167861fadfab 100644 --- a/drivers/iio/chemical/Makefile +++ b/drivers/iio/chemical/Makefile @@ -3,4 +3,5 @@ # # When adding new entries keep the list in alphabetical order +obj-$(CONFIG_IAQCORE) += ams-iaq-core.o obj-$(CONFIG_VZ89X) += vz89x.o diff --git a/drivers/iio/chemical/ams-iaq-core.c b/drivers/iio/chemical/ams-iaq-core.c new file mode 100644 index 000000000000..41a8e6f2e31d --- /dev/null +++ b/drivers/iio/chemical/ams-iaq-core.c @@ -0,0 +1,200 @@ +/* + * ams-iaq-core.c - Support for AMS iAQ-Core VOC sensors + * + * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/init.h> +#include <linux/i2c.h> +#include <linux/iio/iio.h> + +#define AMS_IAQCORE_DATA_SIZE 9 + +#define AMS_IAQCORE_VOC_CO2_IDX 0 +#define AMS_IAQCORE_VOC_RESISTANCE_IDX 1 +#define AMS_IAQCORE_VOC_TVOC_IDX 2 + +struct ams_iaqcore_reading { + __be16 co2_ppm; + u8 status; + __be32 resistance; + __be16 voc_ppb; +} __attribute__((__packed__)); + +struct ams_iaqcore_data { + struct i2c_client *client; + struct mutex lock; + unsigned long last_update; + + struct ams_iaqcore_reading buffer; +}; + +static const struct iio_chan_spec ams_iaqcore_channels[] = { + { + .type = IIO_CONCENTRATION, + .channel2 = IIO_MOD_CO2, + .modified = 1, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + .address = AMS_IAQCORE_VOC_CO2_IDX, + }, + { + .type = IIO_RESISTANCE, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + .address = AMS_IAQCORE_VOC_RESISTANCE_IDX, + }, + { + .type = IIO_CONCENTRATION, + .channel2 = IIO_MOD_VOC, + .modified = 1, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + .address = AMS_IAQCORE_VOC_TVOC_IDX, + }, +}; + +static int ams_iaqcore_read_measurement(struct ams_iaqcore_data *data) +{ + struct i2c_client *client = data->client; + int ret; + + struct i2c_msg msg = { + .addr = client->addr, + .flags = client->flags | I2C_M_RD, + .len = AMS_IAQCORE_DATA_SIZE, + .buf = (char *) &data->buffer, + }; + + ret = i2c_transfer(client->adapter, &msg, 1); + + return (ret == AMS_IAQCORE_DATA_SIZE) ? 0 : ret; +} + +static int ams_iaqcore_get_measurement(struct ams_iaqcore_data *data) +{ + int ret; + + /* sensor can only be polled once a second max per datasheet */ + if (!time_after(jiffies, data->last_update + HZ)) + return 0; + + ret = ams_iaqcore_read_measurement(data); + if (ret < 0) + return ret; + + data->last_update = jiffies; + + return 0; +} + +static int ams_iaqcore_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + struct ams_iaqcore_data *data = iio_priv(indio_dev); + int ret; + + if (mask != IIO_CHAN_INFO_PROCESSED) + return -EINVAL; + + mutex_lock(&data->lock); + ret = ams_iaqcore_get_measurement(data); + + if (ret) + goto err_out; + + switch (chan->address) { + case AMS_IAQCORE_VOC_CO2_IDX: + *val = 0; + *val2 = be16_to_cpu(data->buffer.co2_ppm); + ret = IIO_VAL_INT_PLUS_MICRO; + break; + case AMS_IAQCORE_VOC_RESISTANCE_IDX: + *val = be32_to_cpu(data->buffer.resistance); + ret = IIO_VAL_INT; + break; + case AMS_IAQCORE_VOC_TVOC_IDX: + *val = 0; + *val2 = be16_to_cpu(data->buffer.voc_ppb); + ret = IIO_VAL_INT_PLUS_NANO; + break; + default: + ret = -EINVAL; + } + +err_out: + mutex_unlock(&data->lock); + + return ret; +} + +static const struct iio_info ams_iaqcore_info = { + .read_raw = ams_iaqcore_read_raw, + .driver_module = THIS_MODULE, +}; + +static int ams_iaqcore_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct iio_dev *indio_dev; + struct ams_iaqcore_data *data; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->client = client; + + /* so initial reading will complete */ + data->last_update = jiffies - HZ; + mutex_init(&data->lock); + + indio_dev->dev.parent = &client->dev; + indio_dev->info = &ams_iaqcore_info, + indio_dev->name = dev_name(&client->dev); + indio_dev->modes = INDIO_DIRECT_MODE; + + indio_dev->channels = ams_iaqcore_channels; + indio_dev->num_channels = ARRAY_SIZE(ams_iaqcore_channels); + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static const struct i2c_device_id ams_iaqcore_id[] = { + { "ams-iaq-core", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ams_iaqcore_id); + +static const struct of_device_id ams_iaqcore_dt_ids[] = { + { .compatible = "ams,iaq-core" }, + { } +}; +MODULE_DEVICE_TABLE(of, ams_iaqcore_dt_ids); + +static struct i2c_driver ams_iaqcore_driver = { + .driver = { + .name = "ams-iaq-core", + .of_match_table = of_match_ptr(ams_iaqcore_dt_ids), + }, + .probe = ams_iaqcore_probe, + .id_table = ams_iaqcore_id, +}; +module_i2c_driver(ams_iaqcore_driver); + +MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>"); +MODULE_DESCRIPTION("AMS iAQ-Core VOC sensors"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c index 11e59a5a5112..b8b804923230 100644 --- a/drivers/iio/chemical/vz89x.c +++ b/drivers/iio/chemical/vz89x.c @@ -34,8 +34,9 @@ struct vz89x_data { struct i2c_client *client; struct mutex lock; - unsigned long last_update; + int (*xfer)(struct vz89x_data *data, u8 cmd); + unsigned long last_update; u8 buffer[VZ89X_REG_MEASUREMENT_SIZE]; }; @@ -100,27 +101,60 @@ static int vz89x_measurement_is_valid(struct vz89x_data *data) return !!(data->buffer[VZ89X_REG_MEASUREMENT_SIZE - 1] > 0); } -static int vz89x_get_measurement(struct vz89x_data *data) +static int vz89x_i2c_xfer(struct vz89x_data *data, u8 cmd) { + struct i2c_client *client = data->client; + struct i2c_msg msg[2]; int ret; - int i; + u8 buf[3] = { cmd, 0, 0}; - /* sensor can only be polled once a second max per datasheet */ - if (!time_after(jiffies, data->last_update + HZ)) - return 0; + msg[0].addr = client->addr; + msg[0].flags = client->flags; + msg[0].len = 3; + msg[0].buf = (char *) &buf; + + msg[1].addr = client->addr; + msg[1].flags = client->flags | I2C_M_RD; + msg[1].len = VZ89X_REG_MEASUREMENT_SIZE; + msg[1].buf = (char *) &data->buffer; + + ret = i2c_transfer(client->adapter, msg, 2); - ret = i2c_smbus_write_word_data(data->client, - VZ89X_REG_MEASUREMENT, 0); + return (ret == 2) ? 0 : ret; +} + +static int vz89x_smbus_xfer(struct vz89x_data *data, u8 cmd) +{ + struct i2c_client *client = data->client; + int ret; + int i; + + ret = i2c_smbus_write_word_data(client, cmd, 0); if (ret < 0) return ret; for (i = 0; i < VZ89X_REG_MEASUREMENT_SIZE; i++) { - ret = i2c_smbus_read_byte(data->client); + ret = i2c_smbus_read_byte(client); if (ret < 0) return ret; data->buffer[i] = ret; } + return 0; +} + +static int vz89x_get_measurement(struct vz89x_data *data) +{ + int ret; + + /* sensor can only be polled once a second max per datasheet */ + if (!time_after(jiffies, data->last_update + HZ)) + return 0; + + ret = data->xfer(data, VZ89X_REG_MEASUREMENT); + if (ret < 0) + return ret; + ret = vz89x_measurement_is_valid(data); if (ret) return -EAGAIN; @@ -204,15 +238,19 @@ static int vz89x_probe(struct i2c_client *client, struct iio_dev *indio_dev; struct vz89x_data *data; - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA | - I2C_FUNC_SMBUS_BYTE)) - return -ENODEV; - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; - data = iio_priv(indio_dev); + + if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + data->xfer = vz89x_i2c_xfer; + else if (i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BYTE)) + data->xfer = vz89x_smbus_xfer; + else + return -ENOTSUPP; + i2c_set_clientdata(client, indio_dev); data->client = client; data->last_update = jiffies - HZ; diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index 25258e2c1a82..8447c31e27f2 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -18,9 +18,6 @@ #include <asm/unaligned.h> #include <linux/iio/common/st_sensors.h> - -#define ST_SENSORS_WAI_ADDRESS 0x0f - static inline u32 st_sensors_get_unaligned_le24(const u8 *p) { return (s32)((p[0] | p[1] << 8 | p[2] << 16) << 8) >> 8; diff --git a/drivers/iio/dummy/Kconfig b/drivers/iio/dummy/Kconfig new file mode 100644 index 000000000000..71805ced1aae --- /dev/null +++ b/drivers/iio/dummy/Kconfig @@ -0,0 +1,36 @@ +# +# Industrial I/O subsystem Dummy Driver configuration +# +menu "IIO dummy driver" + depends on IIO + +config IIO_DUMMY_EVGEN + select IRQ_WORK + tristate + +config IIO_SIMPLE_DUMMY + tristate "An example driver with no hardware requirements" + help + Driver intended mainly as documentation for how to write + a driver. May also be useful for testing userspace code + without hardware. + +if IIO_SIMPLE_DUMMY + +config IIO_SIMPLE_DUMMY_EVENTS + bool "Event generation support" + select IIO_DUMMY_EVGEN + help + Add some dummy events to the simple dummy driver. + +config IIO_SIMPLE_DUMMY_BUFFER + bool "Buffered capture support" + select IIO_BUFFER + select IIO_TRIGGER + select IIO_KFIFO_BUF + help + Add buffered data capture to the simple dummy driver. + +endif # IIO_SIMPLE_DUMMY + +endmenu diff --git a/drivers/iio/dummy/Makefile b/drivers/iio/dummy/Makefile new file mode 100644 index 000000000000..0765e93d7804 --- /dev/null +++ b/drivers/iio/dummy/Makefile @@ -0,0 +1,10 @@ +# +# Makefile for the IIO Dummy Driver +# + +obj-$(CONFIG_IIO_SIMPLE_DUMMY) += iio_dummy.o +iio_dummy-y := iio_simple_dummy.o +iio_dummy-$(CONFIG_IIO_SIMPLE_DUMMY_EVENTS) += iio_simple_dummy_events.o +iio_dummy-$(CONFIG_IIO_SIMPLE_DUMMY_BUFFER) += iio_simple_dummy_buffer.o + +obj-$(CONFIG_IIO_DUMMY_EVGEN) += iio_dummy_evgen.o diff --git a/drivers/staging/iio/iio_dummy_evgen.c b/drivers/iio/dummy/iio_dummy_evgen.c index 9e83f348df51..9e83f348df51 100644 --- a/drivers/staging/iio/iio_dummy_evgen.c +++ b/drivers/iio/dummy/iio_dummy_evgen.c diff --git a/drivers/staging/iio/iio_dummy_evgen.h b/drivers/iio/dummy/iio_dummy_evgen.h index d044b946e74a..d044b946e74a 100644 --- a/drivers/staging/iio/iio_dummy_evgen.h +++ b/drivers/iio/dummy/iio_dummy_evgen.h diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c index 43fe4ba7d0dc..43fe4ba7d0dc 100644 --- a/drivers/staging/iio/iio_simple_dummy.c +++ b/drivers/iio/dummy/iio_simple_dummy.c diff --git a/drivers/staging/iio/iio_simple_dummy.h b/drivers/iio/dummy/iio_simple_dummy.h index b9069a180672..b9069a180672 100644 --- a/drivers/staging/iio/iio_simple_dummy.h +++ b/drivers/iio/dummy/iio_simple_dummy.h diff --git a/drivers/staging/iio/iio_simple_dummy_buffer.c b/drivers/iio/dummy/iio_simple_dummy_buffer.c index cf44a6f79431..cf44a6f79431 100644 --- a/drivers/staging/iio/iio_simple_dummy_buffer.c +++ b/drivers/iio/dummy/iio_simple_dummy_buffer.c diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/iio/dummy/iio_simple_dummy_events.c index 6eb600ff7056..6eb600ff7056 100644 --- a/drivers/staging/iio/iio_simple_dummy_events.c +++ b/drivers/iio/dummy/iio_simple_dummy_events.c diff --git a/drivers/iio/gyro/adis16136.c b/drivers/iio/gyro/adis16136.c index f8d1c2210066..b04faf93e1bc 100644 --- a/drivers/iio/gyro/adis16136.c +++ b/drivers/iio/gyro/adis16136.c @@ -435,7 +435,9 @@ static int adis16136_initial_setup(struct iio_dev *indio_dev) if (ret) return ret; - sscanf(indio_dev->name, "adis%u\n", &device_id); + ret = sscanf(indio_dev->name, "adis%u\n", &device_id); + if (ret != 1) + return -EINVAL; if (prod_id != device_id) dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.", diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c index 02ff789852a0..bbce3b09ac45 100644 --- a/drivers/iio/gyro/bmg160_core.c +++ b/drivers/iio/gyro/bmg160_core.c @@ -1077,25 +1077,23 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, goto err_trigger_unregister; } - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(dev, "unable to register iio device\n"); - goto err_buffer_cleanup; - } - ret = pm_runtime_set_active(dev); if (ret) - goto err_iio_unregister; + goto err_buffer_cleanup; pm_runtime_enable(dev); pm_runtime_set_autosuspend_delay(dev, BMG160_AUTO_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(dev); + ret = iio_device_register(indio_dev); + if (ret < 0) { + dev_err(dev, "unable to register iio device\n"); + goto err_buffer_cleanup; + } + return 0; -err_iio_unregister: - iio_device_unregister(indio_dev); err_buffer_cleanup: iio_triggered_buffer_cleanup(indio_dev); err_trigger_unregister: @@ -1113,11 +1111,12 @@ void bmg160_core_remove(struct device *dev) struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmg160_data *data = iio_priv(indio_dev); + iio_device_unregister(indio_dev); + pm_runtime_disable(dev); pm_runtime_set_suspended(dev); pm_runtime_put_noidle(dev); - iio_device_unregister(indio_dev); iio_triggered_buffer_cleanup(indio_dev); if (data->dready_trig) { diff --git a/drivers/iio/health/Kconfig b/drivers/iio/health/Kconfig new file mode 100644 index 000000000000..a647679da805 --- /dev/null +++ b/drivers/iio/health/Kconfig @@ -0,0 +1,21 @@ +# +# Health sensors +# +# When adding new entries keep the list in alphabetical order + +menu "Health sensors" + +config MAX30100 + tristate "MAX30100 heart rate and pulse oximeter sensor" + depends on I2C + select REGMAP_I2C + select IIO_BUFFER + select IIO_KFIFO_BUF + help + Say Y here to build I2C interface support for the Maxim + MAX30100 heart rate, and pulse oximeter sensor. + + To compile this driver as a module, choose M here: the + module will be called max30100. + +endmenu diff --git a/drivers/iio/health/Makefile b/drivers/iio/health/Makefile new file mode 100644 index 000000000000..7c475d7faad8 --- /dev/null +++ b/drivers/iio/health/Makefile @@ -0,0 +1,7 @@ +# +# Makefile for IIO Health sensors +# + +# When adding new entries keep the list in alphabetical order + +obj-$(CONFIG_MAX30100) += max30100.o diff --git a/drivers/iio/health/max30100.c b/drivers/iio/health/max30100.c new file mode 100644 index 000000000000..9d1c81f91dd7 --- /dev/null +++ b/drivers/iio/health/max30100.c @@ -0,0 +1,453 @@ +/* + * max30100.c - Support for MAX30100 heart rate and pulse oximeter sensor + * + * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * TODO: allow LED current and pulse length controls via device tree properties + */ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/irq.h> +#include <linux/i2c.h> +#include <linux/mutex.h> +#include <linux/regmap.h> +#include <linux/iio/iio.h> +#include <linux/iio/buffer.h> +#include <linux/iio/kfifo_buf.h> + +#define MAX30100_REGMAP_NAME "max30100_regmap" +#define MAX30100_DRV_NAME "max30100" + +#define MAX30100_REG_INT_STATUS 0x00 +#define MAX30100_REG_INT_STATUS_PWR_RDY BIT(0) +#define MAX30100_REG_INT_STATUS_SPO2_RDY BIT(4) +#define MAX30100_REG_INT_STATUS_HR_RDY BIT(5) +#define MAX30100_REG_INT_STATUS_FIFO_RDY BIT(7) + +#define MAX30100_REG_INT_ENABLE 0x01 +#define MAX30100_REG_INT_ENABLE_SPO2_EN BIT(0) +#define MAX30100_REG_INT_ENABLE_HR_EN BIT(1) +#define MAX30100_REG_INT_ENABLE_FIFO_EN BIT(3) +#define MAX30100_REG_INT_ENABLE_MASK 0xf0 +#define MAX30100_REG_INT_ENABLE_MASK_SHIFT 4 + +#define MAX30100_REG_FIFO_WR_PTR 0x02 +#define MAX30100_REG_FIFO_OVR_CTR 0x03 +#define MAX30100_REG_FIFO_RD_PTR 0x04 +#define MAX30100_REG_FIFO_DATA 0x05 +#define MAX30100_REG_FIFO_DATA_ENTRY_COUNT 16 +#define MAX30100_REG_FIFO_DATA_ENTRY_LEN 4 + +#define MAX30100_REG_MODE_CONFIG 0x06 +#define MAX30100_REG_MODE_CONFIG_MODE_SPO2_EN BIT(0) +#define MAX30100_REG_MODE_CONFIG_MODE_HR_EN BIT(1) +#define MAX30100_REG_MODE_CONFIG_MODE_MASK 0x03 +#define MAX30100_REG_MODE_CONFIG_TEMP_EN BIT(3) +#define MAX30100_REG_MODE_CONFIG_PWR BIT(7) + +#define MAX30100_REG_SPO2_CONFIG 0x07 +#define MAX30100_REG_SPO2_CONFIG_100HZ BIT(2) +#define MAX30100_REG_SPO2_CONFIG_HI_RES_EN BIT(6) +#define MAX30100_REG_SPO2_CONFIG_1600US 0x3 + +#define MAX30100_REG_LED_CONFIG 0x09 +#define MAX30100_REG_LED_CONFIG_RED_LED_SHIFT 4 + +#define MAX30100_REG_LED_CONFIG_24MA 0x07 +#define MAX30100_REG_LED_CONFIG_50MA 0x0f + +#define MAX30100_REG_TEMP_INTEGER 0x16 +#define MAX30100_REG_TEMP_FRACTION 0x17 + +struct max30100_data { + struct i2c_client *client; + struct iio_dev *indio_dev; + struct mutex lock; + struct regmap *regmap; + + __be16 buffer[2]; /* 2 16-bit channels */ +}; + +static bool max30100_is_volatile_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case MAX30100_REG_INT_STATUS: + case MAX30100_REG_MODE_CONFIG: + case MAX30100_REG_FIFO_WR_PTR: + case MAX30100_REG_FIFO_OVR_CTR: + case MAX30100_REG_FIFO_RD_PTR: + case MAX30100_REG_FIFO_DATA: + case MAX30100_REG_TEMP_INTEGER: + case MAX30100_REG_TEMP_FRACTION: + return true; + default: + return false; + } +} + +static const struct regmap_config max30100_regmap_config = { + .name = MAX30100_REGMAP_NAME, + + .reg_bits = 8, + .val_bits = 8, + + .max_register = MAX30100_REG_TEMP_FRACTION, + .cache_type = REGCACHE_FLAT, + + .volatile_reg = max30100_is_volatile_reg, +}; + +static const unsigned long max30100_scan_masks[] = {0x3, 0}; + +static const struct iio_chan_spec max30100_channels[] = { + { + .type = IIO_INTENSITY, + .channel2 = IIO_MOD_LIGHT_IR, + .modified = 1, + + .scan_index = 0, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .endianness = IIO_BE, + }, + }, + { + .type = IIO_INTENSITY, + .channel2 = IIO_MOD_LIGHT_RED, + .modified = 1, + + .scan_index = 1, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .endianness = IIO_BE, + }, + }, + { + .type = IIO_TEMP, + .info_mask_separate = + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + .scan_index = -1, + }, +}; + +static int max30100_set_powermode(struct max30100_data *data, bool state) +{ + return regmap_update_bits(data->regmap, MAX30100_REG_MODE_CONFIG, + MAX30100_REG_MODE_CONFIG_PWR, + state ? 0 : MAX30100_REG_MODE_CONFIG_PWR); +} + +static int max30100_clear_fifo(struct max30100_data *data) +{ + int ret; + + ret = regmap_write(data->regmap, MAX30100_REG_FIFO_WR_PTR, 0); + if (ret) + return ret; + + ret = regmap_write(data->regmap, MAX30100_REG_FIFO_OVR_CTR, 0); + if (ret) + return ret; + + return regmap_write(data->regmap, MAX30100_REG_FIFO_RD_PTR, 0); +} + +static int max30100_buffer_postenable(struct iio_dev *indio_dev) +{ + struct max30100_data *data = iio_priv(indio_dev); + int ret; + + ret = max30100_set_powermode(data, true); + if (ret) + return ret; + + return max30100_clear_fifo(data); +} + +static int max30100_buffer_predisable(struct iio_dev *indio_dev) +{ + struct max30100_data *data = iio_priv(indio_dev); + + return max30100_set_powermode(data, false); +} + +static const struct iio_buffer_setup_ops max30100_buffer_setup_ops = { + .postenable = max30100_buffer_postenable, + .predisable = max30100_buffer_predisable, +}; + +static inline int max30100_fifo_count(struct max30100_data *data) +{ + unsigned int val; + int ret; + + ret = regmap_read(data->regmap, MAX30100_REG_INT_STATUS, &val); + if (ret) + return ret; + + /* FIFO is almost full */ + if (val & MAX30100_REG_INT_STATUS_FIFO_RDY) + return MAX30100_REG_FIFO_DATA_ENTRY_COUNT - 1; + + return 0; +} + +static int max30100_read_measurement(struct max30100_data *data) +{ + int ret; + + ret = i2c_smbus_read_i2c_block_data(data->client, + MAX30100_REG_FIFO_DATA, + MAX30100_REG_FIFO_DATA_ENTRY_LEN, + (u8 *) &data->buffer); + + return (ret == MAX30100_REG_FIFO_DATA_ENTRY_LEN) ? 0 : ret; +} + +static irqreturn_t max30100_interrupt_handler(int irq, void *private) +{ + struct iio_dev *indio_dev = private; + struct max30100_data *data = iio_priv(indio_dev); + int ret, cnt = 0; + + mutex_lock(&data->lock); + + while (cnt-- || (cnt = max30100_fifo_count(data) > 0)) { + ret = max30100_read_measurement(data); + if (ret) + break; + + iio_push_to_buffers(data->indio_dev, data->buffer); + } + + mutex_unlock(&data->lock); + + return IRQ_HANDLED; +} + +static int max30100_chip_init(struct max30100_data *data) +{ + int ret; + + /* RED IR LED = 24mA, IR LED = 50mA */ + ret = regmap_write(data->regmap, MAX30100_REG_LED_CONFIG, + (MAX30100_REG_LED_CONFIG_24MA << + MAX30100_REG_LED_CONFIG_RED_LED_SHIFT) | + MAX30100_REG_LED_CONFIG_50MA); + if (ret) + return ret; + + /* enable hi-res SPO2 readings at 100Hz */ + ret = regmap_write(data->regmap, MAX30100_REG_SPO2_CONFIG, + MAX30100_REG_SPO2_CONFIG_HI_RES_EN | + MAX30100_REG_SPO2_CONFIG_100HZ); + if (ret) + return ret; + + /* enable SPO2 mode */ + ret = regmap_update_bits(data->regmap, MAX30100_REG_MODE_CONFIG, + MAX30100_REG_MODE_CONFIG_MODE_MASK, + MAX30100_REG_MODE_CONFIG_MODE_HR_EN | + MAX30100_REG_MODE_CONFIG_MODE_SPO2_EN); + if (ret) + return ret; + + /* enable FIFO interrupt */ + return regmap_update_bits(data->regmap, MAX30100_REG_INT_ENABLE, + MAX30100_REG_INT_ENABLE_MASK, + MAX30100_REG_INT_ENABLE_FIFO_EN + << MAX30100_REG_INT_ENABLE_MASK_SHIFT); +} + +static int max30100_read_temp(struct max30100_data *data, int *val) +{ + int ret; + unsigned int reg; + + ret = regmap_read(data->regmap, MAX30100_REG_TEMP_INTEGER, ®); + if (ret < 0) + return ret; + *val = reg << 4; + + ret = regmap_read(data->regmap, MAX30100_REG_TEMP_FRACTION, ®); + if (ret < 0) + return ret; + + *val |= reg & 0xf; + *val = sign_extend32(*val, 11); + + return 0; +} + +static int max30100_get_temp(struct max30100_data *data, int *val) +{ + int ret; + + /* start acquisition */ + ret = regmap_update_bits(data->regmap, MAX30100_REG_MODE_CONFIG, + MAX30100_REG_MODE_CONFIG_TEMP_EN, + MAX30100_REG_MODE_CONFIG_TEMP_EN); + if (ret) + return ret; + + usleep_range(35000, 50000); + + return max30100_read_temp(data, val); +} + +static int max30100_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct max30100_data *data = iio_priv(indio_dev); + int ret = -EINVAL; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + /* + * Temperature reading can only be acquired while engine + * is running + */ + mutex_lock(&indio_dev->mlock); + + if (!iio_buffer_enabled(indio_dev)) + ret = -EAGAIN; + else { + ret = max30100_get_temp(data, val); + if (!ret) + ret = IIO_VAL_INT; + + } + + mutex_unlock(&indio_dev->mlock); + break; + case IIO_CHAN_INFO_SCALE: + *val = 1; /* 0.0625 */ + *val2 = 16; + ret = IIO_VAL_FRACTIONAL; + break; + } + + return ret; +} + +static const struct iio_info max30100_info = { + .driver_module = THIS_MODULE, + .read_raw = max30100_read_raw, +}; + +static int max30100_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct max30100_data *data; + struct iio_buffer *buffer; + struct iio_dev *indio_dev; + int ret; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + buffer = devm_iio_kfifo_allocate(&client->dev); + if (!buffer) + return -ENOMEM; + + iio_device_attach_buffer(indio_dev, buffer); + + indio_dev->name = MAX30100_DRV_NAME; + indio_dev->channels = max30100_channels; + indio_dev->info = &max30100_info; + indio_dev->num_channels = ARRAY_SIZE(max30100_channels); + indio_dev->available_scan_masks = max30100_scan_masks; + indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE); + indio_dev->setup_ops = &max30100_buffer_setup_ops; + + data = iio_priv(indio_dev); + data->indio_dev = indio_dev; + data->client = client; + + mutex_init(&data->lock); + i2c_set_clientdata(client, indio_dev); + + data->regmap = devm_regmap_init_i2c(client, &max30100_regmap_config); + if (IS_ERR(data->regmap)) { + dev_err(&client->dev, "regmap initialization failed.\n"); + return PTR_ERR(data->regmap); + } + max30100_set_powermode(data, false); + + ret = max30100_chip_init(data); + if (ret) + return ret; + + if (client->irq <= 0) { + dev_err(&client->dev, "no valid irq defined\n"); + return -EINVAL; + } + ret = devm_request_threaded_irq(&client->dev, client->irq, + NULL, max30100_interrupt_handler, + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, + "max30100_irq", indio_dev); + if (ret) { + dev_err(&client->dev, "request irq (%d) failed\n", client->irq); + return ret; + } + + return iio_device_register(indio_dev); +} + +static int max30100_remove(struct i2c_client *client) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(client); + struct max30100_data *data = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + max30100_set_powermode(data, false); + + return 0; +} + +static const struct i2c_device_id max30100_id[] = { + { "max30100", 0 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, max30100_id); + +static const struct of_device_id max30100_dt_ids[] = { + { .compatible = "maxim,max30100" }, + { } +}; +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), + }, + .probe = max30100_probe, + .remove = max30100_remove, + .id_table = max30100_id, +}; +module_i2c_driver(max30100_driver); + +MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>"); +MODULE_DESCRIPTION("MAX30100 heart rate and pulse oximeter sensor"); +MODULE_LICENSE("GPL"); diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c index 0618f831ecd4..fb7c0dbed51c 100644 --- a/drivers/iio/imu/adis16400_core.c +++ b/drivers/iio/imu/adis16400_core.c @@ -288,7 +288,11 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev) if (ret) goto err_ret; - sscanf(indio_dev->name, "adis%u\n", &device_id); + ret = sscanf(indio_dev->name, "adis%u\n", &device_id); + if (ret != 1) { + ret = -EINVAL; + goto err_ret; + } if (prod_id != device_id) dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.", diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c index 2485b88ee1b6..8cf84d3488b2 100644 --- a/drivers/iio/imu/adis16480.c +++ b/drivers/iio/imu/adis16480.c @@ -765,7 +765,9 @@ static int adis16480_initial_setup(struct iio_dev *indio_dev) if (ret) return ret; - sscanf(indio_dev->name, "adis%u\n", &device_id); + ret = sscanf(indio_dev->name, "adis%u\n", &device_id); + if (ret != 1) + return -EINVAL; if (prod_id != device_id) dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.", diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c index dbf5e9936635..e5306b4e020e 100644 --- a/drivers/iio/imu/kmx61.c +++ b/drivers/iio/imu/kmx61.c @@ -1390,6 +1390,14 @@ static int kmx61_probe(struct i2c_client *client, } } + ret = pm_runtime_set_active(&client->dev); + if (ret < 0) + goto err_buffer_cleanup_mag; + + pm_runtime_enable(&client->dev); + pm_runtime_set_autosuspend_delay(&client->dev, KMX61_SLEEP_DELAY_MS); + pm_runtime_use_autosuspend(&client->dev); + ret = iio_device_register(data->acc_indio_dev); if (ret < 0) { dev_err(&client->dev, "Failed to register acc iio device\n"); @@ -1402,18 +1410,8 @@ static int kmx61_probe(struct i2c_client *client, goto err_iio_unregister_acc; } - ret = pm_runtime_set_active(&client->dev); - if (ret < 0) - goto err_iio_unregister_mag; - - pm_runtime_enable(&client->dev); - pm_runtime_set_autosuspend_delay(&client->dev, KMX61_SLEEP_DELAY_MS); - pm_runtime_use_autosuspend(&client->dev); - return 0; -err_iio_unregister_mag: - iio_device_unregister(data->mag_indio_dev); err_iio_unregister_acc: iio_device_unregister(data->acc_indio_dev); err_buffer_cleanup_mag: @@ -1437,13 +1435,13 @@ static int kmx61_remove(struct i2c_client *client) { struct kmx61_data *data = i2c_get_clientdata(client); + iio_device_unregister(data->acc_indio_dev); + iio_device_unregister(data->mag_indio_dev); + pm_runtime_disable(&client->dev); pm_runtime_set_suspended(&client->dev); pm_runtime_put_noidle(&client->dev); - iio_device_unregister(data->acc_indio_dev); - iio_device_unregister(data->mag_indio_dev); - if (client->irq > 0) { iio_triggered_buffer_cleanup(data->acc_indio_dev); iio_triggered_buffer_cleanup(data->mag_indio_dev); diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index 0f6f63b20263..139ae916225f 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -193,7 +193,8 @@ void iio_buffer_init(struct iio_buffer *buffer) INIT_LIST_HEAD(&buffer->buffer_list); init_waitqueue_head(&buffer->pollq); kref_init(&buffer->ref); - buffer->watermark = 1; + if (!buffer->watermark) + buffer->watermark = 1; } EXPORT_SYMBOL(iio_buffer_init); @@ -567,6 +568,22 @@ static void iio_buffer_deactivate_all(struct iio_dev *indio_dev) iio_buffer_deactivate(buffer); } +static int iio_buffer_enable(struct iio_buffer *buffer, + struct iio_dev *indio_dev) +{ + if (!buffer->access->enable) + return 0; + return buffer->access->enable(buffer, indio_dev); +} + +static int iio_buffer_disable(struct iio_buffer *buffer, + struct iio_dev *indio_dev) +{ + if (!buffer->access->disable) + return 0; + return buffer->access->disable(buffer, indio_dev); +} + static void iio_buffer_update_bytes_per_datum(struct iio_dev *indio_dev, struct iio_buffer *buffer) { @@ -610,6 +627,7 @@ static void iio_free_scan_mask(struct iio_dev *indio_dev, struct iio_device_config { unsigned int mode; + unsigned int watermark; const unsigned long *scan_mask; unsigned int scan_bytes; bool scan_timestamp; @@ -642,10 +660,14 @@ static int iio_verify_update(struct iio_dev *indio_dev, if (buffer == remove_buffer) continue; modes &= buffer->access->modes; + config->watermark = min(config->watermark, buffer->watermark); } - if (insert_buffer) + if (insert_buffer) { modes &= insert_buffer->access->modes; + config->watermark = min(config->watermark, + insert_buffer->watermark); + } /* Definitely possible for devices to support both of these. */ if ((modes & INDIO_BUFFER_TRIGGERED) && indio_dev->trig) { @@ -713,6 +735,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, static int iio_enable_buffers(struct iio_dev *indio_dev, struct iio_device_config *config) { + struct iio_buffer *buffer; int ret; indio_dev->active_scan_mask = config->scan_mask; @@ -743,6 +766,16 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, } } + if (indio_dev->info->hwfifo_set_watermark) + indio_dev->info->hwfifo_set_watermark(indio_dev, + config->watermark); + + list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) { + ret = iio_buffer_enable(buffer, indio_dev); + if (ret) + goto err_disable_buffers; + } + indio_dev->currentmode = config->mode; if (indio_dev->setup_ops->postenable) { @@ -750,12 +783,16 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, if (ret) { dev_dbg(&indio_dev->dev, "Buffer not started: postenable failed (%d)\n", ret); - goto err_run_postdisable; + goto err_disable_buffers; } } return 0; +err_disable_buffers: + list_for_each_entry_continue_reverse(buffer, &indio_dev->buffer_list, + buffer_list) + iio_buffer_disable(buffer, indio_dev); err_run_postdisable: indio_dev->currentmode = INDIO_DIRECT_MODE; if (indio_dev->setup_ops->postdisable) @@ -768,6 +805,7 @@ err_undo_config: static int iio_disable_buffers(struct iio_dev *indio_dev) { + struct iio_buffer *buffer; int ret = 0; int ret2; @@ -788,6 +826,12 @@ static int iio_disable_buffers(struct iio_dev *indio_dev) ret = ret2; } + list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) { + ret2 = iio_buffer_disable(buffer, indio_dev); + if (ret2 && !ret) + ret = ret2; + } + indio_dev->currentmode = INDIO_DIRECT_MODE; if (indio_dev->setup_ops->postdisable) { @@ -974,9 +1018,6 @@ static ssize_t iio_buffer_store_watermark(struct device *dev, } buffer->watermark = val; - - if (indio_dev->info->hwfifo_set_watermark) - indio_dev->info->hwfifo_set_watermark(indio_dev, val); out: mutex_unlock(&indio_dev->mlock); @@ -991,6 +1032,8 @@ static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, iio_buffer_show_enable, iio_buffer_store_enable); static DEVICE_ATTR(watermark, S_IRUGO | S_IWUSR, iio_buffer_show_watermark, iio_buffer_store_watermark); +static struct device_attribute dev_attr_watermark_ro = __ATTR(watermark, + S_IRUGO, iio_buffer_show_watermark, NULL); static struct attribute *iio_buffer_attrs[] = { &dev_attr_length.attr, @@ -1033,6 +1076,9 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) if (!buffer->access->set_length) attr[0] = &dev_attr_length_ro.attr; + if (buffer->access->flags & INDIO_BUFFER_FLAG_FIXED_WATERMARK) + attr[2] = &dev_attr_watermark_ro.attr; + if (buffer->attrs) memcpy(&attr[ARRAY_SIZE(iio_buffer_attrs)], buffer->attrs, sizeof(struct attribute *) * attrcount); diff --git a/drivers/iio/industrialio-configfs.c b/drivers/iio/industrialio-configfs.c new file mode 100644 index 000000000000..45ce2bc47180 --- /dev/null +++ b/drivers/iio/industrialio-configfs.c @@ -0,0 +1,51 @@ +/* + * Industrial I/O configfs bits + * + * Copyright (c) 2015 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include <linux/configfs.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/kmod.h> +#include <linux/slab.h> + +#include <linux/iio/iio.h> +#include <linux/iio/configfs.h> + +static struct config_item_type iio_root_group_type = { + .ct_owner = THIS_MODULE, +}; + +struct configfs_subsystem iio_configfs_subsys = { + .su_group = { + .cg_item = { + .ci_namebuf = "iio", + .ci_type = &iio_root_group_type, + }, + }, + .su_mutex = __MUTEX_INITIALIZER(iio_configfs_subsys.su_mutex), +}; +EXPORT_SYMBOL(iio_configfs_subsys); + +static int __init iio_configfs_init(void) +{ + config_group_init(&iio_configfs_subsys.su_group); + + return configfs_register_subsystem(&iio_configfs_subsys); +} +module_init(iio_configfs_init); + +static void __exit iio_configfs_exit(void) +{ + configfs_unregister_subsystem(&iio_configfs_subsys); +} +module_exit(iio_configfs_exit); + +MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>"); +MODULE_DESCRIPTION("Industrial I/O configfs support"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 159ede61f793..fd01f3493fc7 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -470,6 +470,7 @@ ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals) return 0; } } +EXPORT_SYMBOL_GPL(iio_format_value); static ssize_t iio_read_channel_info(struct device *dev, struct device_attribute *attr, @@ -512,6 +513,12 @@ int iio_str_to_fixpoint(const char *str, int fract_mult, int i = 0, f = 0; bool integer_part = true, negative = false; + if (fract_mult == 0) { + *fract = 0; + + return kstrtoint(str, 0, integer); + } + if (str[0] == '-') { negative = true; str++; @@ -571,6 +578,9 @@ static ssize_t iio_write_channel_info(struct device *dev, if (indio_dev->info->write_raw_get_fmt) switch (indio_dev->info->write_raw_get_fmt(indio_dev, this_attr->c, this_attr->address)) { + case IIO_VAL_INT: + fract_mult = 0; + break; case IIO_VAL_INT_PLUS_MICRO: fract_mult = 100000; break; diff --git a/drivers/iio/industrialio-sw-trigger.c b/drivers/iio/industrialio-sw-trigger.c new file mode 100644 index 000000000000..311f9fe5aa34 --- /dev/null +++ b/drivers/iio/industrialio-sw-trigger.c @@ -0,0 +1,184 @@ +/* + * The Industrial I/O core, software trigger functions + * + * Copyright (c) 2015 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/kmod.h> +#include <linux/list.h> +#include <linux/slab.h> + +#include <linux/iio/sw_trigger.h> +#include <linux/iio/configfs.h> +#include <linux/configfs.h> + +static struct config_group *iio_triggers_group; +static struct config_item_type iio_trigger_type_group_type; + +static struct config_item_type iio_triggers_group_type = { + .ct_owner = THIS_MODULE, +}; + +static LIST_HEAD(iio_trigger_types_list); +static DEFINE_MUTEX(iio_trigger_types_lock); + +static +struct iio_sw_trigger_type *__iio_find_sw_trigger_type(const char *name, + unsigned len) +{ + struct iio_sw_trigger_type *t = NULL, *iter; + + list_for_each_entry(iter, &iio_trigger_types_list, list) + if (!strcmp(iter->name, name)) { + t = iter; + break; + } + + return t; +} + +int iio_register_sw_trigger_type(struct iio_sw_trigger_type *t) +{ + struct iio_sw_trigger_type *iter; + int ret = 0; + + mutex_lock(&iio_trigger_types_lock); + iter = __iio_find_sw_trigger_type(t->name, strlen(t->name)); + if (iter) + ret = -EBUSY; + else + list_add_tail(&t->list, &iio_trigger_types_list); + mutex_unlock(&iio_trigger_types_lock); + + if (ret) + return ret; + + t->group = configfs_register_default_group(iio_triggers_group, t->name, + &iio_trigger_type_group_type); + if (IS_ERR(t->group)) + ret = PTR_ERR(t->group); + + return ret; +} +EXPORT_SYMBOL(iio_register_sw_trigger_type); + +void iio_unregister_sw_trigger_type(struct iio_sw_trigger_type *t) +{ + struct iio_sw_trigger_type *iter; + + mutex_lock(&iio_trigger_types_lock); + iter = __iio_find_sw_trigger_type(t->name, strlen(t->name)); + if (iter) + list_del(&t->list); + mutex_unlock(&iio_trigger_types_lock); + + configfs_unregister_default_group(t->group); +} +EXPORT_SYMBOL(iio_unregister_sw_trigger_type); + +static +struct iio_sw_trigger_type *iio_get_sw_trigger_type(const char *name) +{ + struct iio_sw_trigger_type *t; + + mutex_lock(&iio_trigger_types_lock); + t = __iio_find_sw_trigger_type(name, strlen(name)); + if (t && !try_module_get(t->owner)) + t = NULL; + mutex_unlock(&iio_trigger_types_lock); + + return t; +} + +struct iio_sw_trigger *iio_sw_trigger_create(const char *type, const char *name) +{ + struct iio_sw_trigger *t; + struct iio_sw_trigger_type *tt; + + tt = iio_get_sw_trigger_type(type); + if (!tt) { + pr_err("Invalid trigger type: %s\n", type); + return ERR_PTR(-EINVAL); + } + t = tt->ops->probe(name); + if (IS_ERR(t)) + goto out_module_put; + + t->trigger_type = tt; + + return t; +out_module_put: + module_put(tt->owner); + return t; +} +EXPORT_SYMBOL(iio_sw_trigger_create); + +void iio_sw_trigger_destroy(struct iio_sw_trigger *t) +{ + struct iio_sw_trigger_type *tt = t->trigger_type; + + tt->ops->remove(t); + module_put(tt->owner); +} +EXPORT_SYMBOL(iio_sw_trigger_destroy); + +static struct config_group *trigger_make_group(struct config_group *group, + const char *name) +{ + struct iio_sw_trigger *t; + + t = iio_sw_trigger_create(group->cg_item.ci_name, name); + if (IS_ERR(t)) + return ERR_CAST(t); + + config_item_set_name(&t->group.cg_item, "%s", name); + + return &t->group; +} + +static void trigger_drop_group(struct config_group *group, + struct config_item *item) +{ + struct iio_sw_trigger *t = to_iio_sw_trigger(item); + + iio_sw_trigger_destroy(t); + config_item_put(item); +} + +static struct configfs_group_operations trigger_ops = { + .make_group = &trigger_make_group, + .drop_item = &trigger_drop_group, +}; + +static struct config_item_type iio_trigger_type_group_type = { + .ct_group_ops = &trigger_ops, + .ct_owner = THIS_MODULE, +}; + +static int __init iio_sw_trigger_init(void) +{ + iio_triggers_group = + configfs_register_default_group(&iio_configfs_subsys.su_group, + "triggers", + &iio_triggers_group_type); + if (IS_ERR(iio_triggers_group)) + return PTR_ERR(iio_triggers_group); + return 0; +} +module_init(iio_sw_trigger_init); + +static void __exit iio_sw_trigger_exit(void) +{ + configfs_unregister_default_group(iio_triggers_group); +} +module_exit(iio_sw_trigger_exit); + +MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>"); +MODULE_DESCRIPTION("Industrial I/O software triggers support"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index c8bad3cf891d..80fbbfd76faf 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -61,12 +61,10 @@ EXPORT_SYMBOL_GPL(iio_map_array_register); int iio_map_array_unregister(struct iio_dev *indio_dev) { int ret = -ENODEV; - struct iio_map_internal *mapi; - struct list_head *pos, *tmp; + struct iio_map_internal *mapi, *next; mutex_lock(&iio_map_list_lock); - list_for_each_safe(pos, tmp, &iio_map_list) { - mapi = list_entry(pos, struct iio_map_internal, l); + list_for_each_entry_safe(mapi, next, &iio_map_list, l) { if (indio_dev == mapi->indio_dev) { list_del(&mapi->l); kfree(mapi); diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c index 076bc46fad03..e56937c40a18 100644 --- a/drivers/iio/light/lm3533-als.c +++ b/drivers/iio/light/lm3533-als.c @@ -743,8 +743,10 @@ static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val) { int ret; - if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) + if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) { + dev_err(&als->pdev->dev, "invalid resistor value\n"); return -EINVAL; + }; ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val); if (ret) { diff --git a/drivers/iio/light/pa12203001.c b/drivers/iio/light/pa12203001.c index 45f7bde02bbf..76a9e12b46bc 100644 --- a/drivers/iio/light/pa12203001.c +++ b/drivers/iio/light/pa12203001.c @@ -381,17 +381,23 @@ static int pa12203001_probe(struct i2c_client *client, return ret; ret = pm_runtime_set_active(&client->dev); - if (ret < 0) { - pa12203001_power_chip(indio_dev, PA12203001_CHIP_DISABLE); - return ret; - } + if (ret < 0) + goto out_err; pm_runtime_enable(&client->dev); pm_runtime_set_autosuspend_delay(&client->dev, PA12203001_SLEEP_DELAY_MS); pm_runtime_use_autosuspend(&client->dev); - return iio_device_register(indio_dev); + ret = iio_device_register(indio_dev); + if (ret < 0) + goto out_err; + + return 0; + +out_err: + pa12203001_power_chip(indio_dev, PA12203001_CHIP_DISABLE); + return ret; } static int pa12203001_remove(struct i2c_client *client) diff --git a/drivers/iio/light/rpr0521.c b/drivers/iio/light/rpr0521.c index 4b75bb0998b3..7de0f397194b 100644 --- a/drivers/iio/light/rpr0521.c +++ b/drivers/iio/light/rpr0521.c @@ -507,34 +507,28 @@ static int rpr0521_probe(struct i2c_client *client, dev_err(&client->dev, "rpr0521 chip init failed\n"); return ret; } - ret = iio_device_register(indio_dev); - if (ret < 0) - return ret; ret = pm_runtime_set_active(&client->dev); if (ret < 0) - goto err_iio_unregister; + return ret; pm_runtime_enable(&client->dev); pm_runtime_set_autosuspend_delay(&client->dev, RPR0521_SLEEP_DELAY_MS); pm_runtime_use_autosuspend(&client->dev); - return 0; - -err_iio_unregister: - iio_device_unregister(indio_dev); - return ret; + return iio_device_register(indio_dev); } static int rpr0521_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); + iio_device_unregister(indio_dev); + pm_runtime_disable(&client->dev); pm_runtime_set_suspended(&client->dev); pm_runtime_put_noidle(&client->dev); - iio_device_unregister(indio_dev); rpr0521_poweroff(iio_priv(indio_dev)); return 0; diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c index 49dab3cb3e23..45bc2f742f46 100644 --- a/drivers/iio/light/us5182d.c +++ b/drivers/iio/light/us5182d.c @@ -20,14 +20,21 @@ #include <linux/acpi.h> #include <linux/delay.h> #include <linux/i2c.h> +#include <linux/iio/events.h> #include <linux/iio/iio.h> +#include <linux/interrupt.h> +#include <linux/irq.h> #include <linux/iio/sysfs.h> #include <linux/mutex.h> +#include <linux/pm.h> +#include <linux/pm_runtime.h> #define US5182D_REG_CFG0 0x00 #define US5182D_CFG0_ONESHOT_EN BIT(6) #define US5182D_CFG0_SHUTDOWN_EN BIT(7) #define US5182D_CFG0_WORD_ENABLE BIT(0) +#define US5182D_CFG0_PROX BIT(3) +#define US5182D_CFG0_PX_IRQ BIT(2) #define US5182D_REG_CFG1 0x01 #define US5182D_CFG1_ALS_RES16 BIT(4) @@ -39,6 +46,7 @@ #define US5182D_REG_CFG3 0x03 #define US5182D_CFG3_LED_CURRENT100 (BIT(4) | BIT(5)) +#define US5182D_CFG3_INT_SOURCE_PX BIT(3) #define US5182D_REG_CFG4 0x10 @@ -53,6 +61,13 @@ #define US5182D_REG_AUTO_LDARK_GAIN 0x29 #define US5182D_REG_AUTO_HDARK_GAIN 0x2a +/* Thresholds for events: px low (0x08-l, 0x09-h), px high (0x0a-l 0x0b-h) */ +#define US5182D_REG_PXL_TH 0x08 +#define US5182D_REG_PXH_TH 0x0a + +#define US5182D_REG_PXL_TH_DEFAULT 1000 +#define US5182D_REG_PXH_TH_DEFAULT 30000 + #define US5182D_OPMODE_ALS 0x01 #define US5182D_OPMODE_PX 0x02 #define US5182D_OPMODE_SHIFT 4 @@ -81,6 +96,9 @@ #define US5182D_READ_BYTE 1 #define US5182D_READ_WORD 2 #define US5182D_OPSTORE_SLEEP_TIME 20 /* ms */ +#define US5182D_SLEEP_MS 3000 /* ms */ +#define US5182D_PXH_TH_DISABLE 0xffff +#define US5182D_PXL_TH_DISABLE 0x0000 /* Available ranges: [12354, 7065, 3998, 2202, 1285, 498, 256, 138] lux */ static const int us5182d_scales[] = {188500, 107800, 61000, 33600, 19600, 7600, @@ -99,6 +117,11 @@ enum mode { US5182D_PX_ONLY }; +enum pmode { + US5182D_CONTINUOUS, + US5182D_ONESHOT +}; + struct us5182d_data { struct i2c_client *client; struct mutex lock; @@ -111,7 +134,19 @@ struct us5182d_data { u8 upper_dark_gain; u16 *us5182d_dark_ths; + u16 px_low_th; + u16 px_high_th; + + int rising_en; + int falling_en; + u8 opmode; + u8 power_mode; + + bool als_enabled; + bool px_enabled; + + bool default_continuous; }; static IIO_CONST_ATTR(in_illuminance_scale_available, @@ -130,16 +165,30 @@ static const struct { u8 reg; u8 val; } us5182d_regvals[] = { - {US5182D_REG_CFG0, (US5182D_CFG0_SHUTDOWN_EN | - US5182D_CFG0_WORD_ENABLE)}, + {US5182D_REG_CFG0, US5182D_CFG0_WORD_ENABLE}, {US5182D_REG_CFG1, US5182D_CFG1_ALS_RES16}, {US5182D_REG_CFG2, (US5182D_CFG2_PX_RES16 | US5182D_CFG2_PXGAIN_DEFAULT)}, - {US5182D_REG_CFG3, US5182D_CFG3_LED_CURRENT100}, - {US5182D_REG_MODE_STORE, US5182D_STORE_MODE}, + {US5182D_REG_CFG3, US5182D_CFG3_LED_CURRENT100 | + US5182D_CFG3_INT_SOURCE_PX}, {US5182D_REG_CFG4, 0x00}, }; +static const struct iio_event_spec us5182d_events[] = { + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_ENABLE), + }, + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_FALLING, + .mask_separate = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_ENABLE), + }, +}; + static const struct iio_chan_spec us5182d_channels[] = { { .type = IIO_LIGHT, @@ -149,40 +198,39 @@ static const struct iio_chan_spec us5182d_channels[] = { { .type = IIO_PROXIMITY, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .event_spec = us5182d_events, + .num_event_specs = ARRAY_SIZE(us5182d_events), } }; -static int us5182d_get_als(struct us5182d_data *data) +static int us5182d_oneshot_en(struct us5182d_data *data) { int ret; - unsigned long result; - ret = i2c_smbus_read_word_data(data->client, - US5182D_REG_ADL); + ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG0); if (ret < 0) return ret; - result = ret * data->ga / US5182D_GA_RESOLUTION; - if (result > 0xffff) - result = 0xffff; + /* + * In oneshot mode the chip will power itself down after taking the + * required measurement. + */ + ret = ret | US5182D_CFG0_ONESHOT_EN; - return result; + return i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, ret); } static int us5182d_set_opmode(struct us5182d_data *data, u8 mode) { int ret; + if (mode == data->opmode) + return 0; + ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG0); if (ret < 0) return ret; - /* - * In oneshot mode the chip will power itself down after taking the - * required measurement. - */ - ret = ret | US5182D_CFG0_ONESHOT_EN; - /* update mode */ ret = ret & ~US5182D_OPMODE_MASK; ret = ret | (mode << US5182D_OPMODE_SHIFT); @@ -196,9 +244,6 @@ static int us5182d_set_opmode(struct us5182d_data *data, u8 mode) if (ret < 0) return ret; - if (mode == data->opmode) - return 0; - ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_MODE_STORE, US5182D_STORE_MODE); if (ret < 0) @@ -210,6 +255,177 @@ static int us5182d_set_opmode(struct us5182d_data *data, u8 mode) return 0; } +static int us5182d_als_enable(struct us5182d_data *data) +{ + int ret; + u8 mode; + + if (data->power_mode == US5182D_ONESHOT) { + ret = us5182d_set_opmode(data, US5182D_ALS_ONLY); + if (ret < 0) + return ret; + data->px_enabled = false; + } + + if (data->als_enabled) + return 0; + + mode = data->px_enabled ? US5182D_ALS_PX : US5182D_ALS_ONLY; + + ret = us5182d_set_opmode(data, mode); + if (ret < 0) + return ret; + + data->als_enabled = true; + + return 0; +} + +static int us5182d_px_enable(struct us5182d_data *data) +{ + int ret; + u8 mode; + + if (data->power_mode == US5182D_ONESHOT) { + ret = us5182d_set_opmode(data, US5182D_PX_ONLY); + if (ret < 0) + return ret; + data->als_enabled = false; + } + + if (data->px_enabled) + return 0; + + mode = data->als_enabled ? US5182D_ALS_PX : US5182D_PX_ONLY; + + ret = us5182d_set_opmode(data, mode); + if (ret < 0) + return ret; + + data->px_enabled = true; + + return 0; +} + +static int us5182d_get_als(struct us5182d_data *data) +{ + int ret; + unsigned long result; + + ret = us5182d_als_enable(data); + if (ret < 0) + return ret; + + ret = i2c_smbus_read_word_data(data->client, + US5182D_REG_ADL); + if (ret < 0) + return ret; + + result = ret * data->ga / US5182D_GA_RESOLUTION; + if (result > 0xffff) + result = 0xffff; + + return result; +} + +static int us5182d_get_px(struct us5182d_data *data) +{ + int ret; + + ret = us5182d_px_enable(data); + if (ret < 0) + return ret; + + return i2c_smbus_read_word_data(data->client, + US5182D_REG_PDL); +} + +static int us5182d_shutdown_en(struct us5182d_data *data, u8 state) +{ + int ret; + + if (data->power_mode == US5182D_ONESHOT) + return 0; + + ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG0); + if (ret < 0) + return ret; + + ret = ret & ~US5182D_CFG0_SHUTDOWN_EN; + ret = ret | state; + + ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, ret); + if (ret < 0) + return ret; + + if (state & US5182D_CFG0_SHUTDOWN_EN) { + data->als_enabled = false; + data->px_enabled = false; + } + + return ret; +} + + +static int us5182d_set_power_state(struct us5182d_data *data, bool on) +{ + int ret; + + if (data->power_mode == US5182D_ONESHOT) + return 0; + + if (on) { + ret = pm_runtime_get_sync(&data->client->dev); + if (ret < 0) + pm_runtime_put_noidle(&data->client->dev); + } else { + pm_runtime_mark_last_busy(&data->client->dev); + ret = pm_runtime_put_autosuspend(&data->client->dev); + } + + return ret; +} + +static int us5182d_read_value(struct us5182d_data *data, + struct iio_chan_spec const *chan) +{ + int ret, value; + + mutex_lock(&data->lock); + + if (data->power_mode == US5182D_ONESHOT) { + ret = us5182d_oneshot_en(data); + if (ret < 0) + goto out_err; + } + + ret = us5182d_set_power_state(data, true); + if (ret < 0) + goto out_err; + + if (chan->type == IIO_LIGHT) + ret = us5182d_get_als(data); + else + ret = us5182d_get_px(data); + if (ret < 0) + goto out_poweroff; + + value = ret; + + ret = us5182d_set_power_state(data, false); + if (ret < 0) + goto out_err; + + mutex_unlock(&data->lock); + return value; + +out_poweroff: + us5182d_set_power_state(data, false); +out_err: + mutex_unlock(&data->lock); + return ret; +} + static int us5182d_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -219,53 +435,21 @@ static int us5182d_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - switch (chan->type) { - case IIO_LIGHT: - mutex_lock(&data->lock); - ret = us5182d_set_opmode(data, US5182D_OPMODE_ALS); - if (ret < 0) - goto out_err; - - ret = us5182d_get_als(data); - if (ret < 0) - goto out_err; - mutex_unlock(&data->lock); - *val = ret; - return IIO_VAL_INT; - case IIO_PROXIMITY: - mutex_lock(&data->lock); - ret = us5182d_set_opmode(data, US5182D_OPMODE_PX); - if (ret < 0) - goto out_err; - - ret = i2c_smbus_read_word_data(data->client, - US5182D_REG_PDL); - if (ret < 0) - goto out_err; - mutex_unlock(&data->lock); - *val = ret; - return IIO_VAL_INT; - default: - return -EINVAL; - } - + ret = us5182d_read_value(data, chan); + if (ret < 0) + return ret; + *val = ret; + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG1); if (ret < 0) return ret; - *val = 0; *val2 = us5182d_scales[ret & US5182D_AGAIN_MASK]; - return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; } - - return -EINVAL; -out_err: - mutex_unlock(&data->lock); - return ret; } /** @@ -343,11 +527,201 @@ static int us5182d_write_raw(struct iio_dev *indio_dev, return -EINVAL; } +static int us5182d_setup_prox(struct iio_dev *indio_dev, + enum iio_event_direction dir, u16 val) +{ + struct us5182d_data *data = iio_priv(indio_dev); + + if (dir == IIO_EV_DIR_FALLING) + return i2c_smbus_write_word_data(data->client, + US5182D_REG_PXL_TH, val); + else if (dir == IIO_EV_DIR_RISING) + return i2c_smbus_write_word_data(data->client, + US5182D_REG_PXH_TH, val); + + return 0; +} + +static int us5182d_read_thresh(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, enum iio_event_type type, + enum iio_event_direction dir, enum iio_event_info info, int *val, + int *val2) +{ + struct us5182d_data *data = iio_priv(indio_dev); + + switch (dir) { + case IIO_EV_DIR_RISING: + mutex_lock(&data->lock); + *val = data->px_high_th; + mutex_unlock(&data->lock); + break; + case IIO_EV_DIR_FALLING: + mutex_lock(&data->lock); + *val = data->px_low_th; + mutex_unlock(&data->lock); + break; + default: + return -EINVAL; + } + + return IIO_VAL_INT; +} + +static int us5182d_write_thresh(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, enum iio_event_type type, + enum iio_event_direction dir, enum iio_event_info info, int val, + int val2) +{ + struct us5182d_data *data = iio_priv(indio_dev); + int ret; + + if (val < 0 || val > USHRT_MAX || val2 != 0) + return -EINVAL; + + switch (dir) { + case IIO_EV_DIR_RISING: + mutex_lock(&data->lock); + if (data->rising_en) { + ret = us5182d_setup_prox(indio_dev, dir, val); + if (ret < 0) + goto err; + } + data->px_high_th = val; + mutex_unlock(&data->lock); + break; + case IIO_EV_DIR_FALLING: + mutex_lock(&data->lock); + if (data->falling_en) { + ret = us5182d_setup_prox(indio_dev, dir, val); + if (ret < 0) + goto err; + } + data->px_low_th = val; + mutex_unlock(&data->lock); + break; + default: + return -EINVAL; + } + + return 0; +err: + mutex_unlock(&data->lock); + return ret; +} + +static int us5182d_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 us5182d_data *data = iio_priv(indio_dev); + int ret; + + switch (dir) { + case IIO_EV_DIR_RISING: + mutex_lock(&data->lock); + ret = data->rising_en; + mutex_unlock(&data->lock); + break; + case IIO_EV_DIR_FALLING: + mutex_lock(&data->lock); + ret = data->falling_en; + mutex_unlock(&data->lock); + break; + default: + ret = -EINVAL; + break; + } + + return ret; +} + +static int us5182d_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 us5182d_data *data = iio_priv(indio_dev); + int ret; + u16 new_th; + + mutex_lock(&data->lock); + + switch (dir) { + case IIO_EV_DIR_RISING: + if (data->rising_en == state) { + mutex_unlock(&data->lock); + return 0; + } + new_th = US5182D_PXH_TH_DISABLE; + if (state) { + data->power_mode = US5182D_CONTINUOUS; + ret = us5182d_set_power_state(data, true); + if (ret < 0) + goto err; + ret = us5182d_px_enable(data); + if (ret < 0) + goto err_poweroff; + new_th = data->px_high_th; + } + ret = us5182d_setup_prox(indio_dev, dir, new_th); + if (ret < 0) + goto err_poweroff; + data->rising_en = state; + break; + case IIO_EV_DIR_FALLING: + if (data->falling_en == state) { + mutex_unlock(&data->lock); + return 0; + } + new_th = US5182D_PXL_TH_DISABLE; + if (state) { + data->power_mode = US5182D_CONTINUOUS; + ret = us5182d_set_power_state(data, true); + if (ret < 0) + goto err; + ret = us5182d_px_enable(data); + if (ret < 0) + goto err_poweroff; + new_th = data->px_low_th; + } + ret = us5182d_setup_prox(indio_dev, dir, new_th); + if (ret < 0) + goto err_poweroff; + data->falling_en = state; + break; + default: + ret = -EINVAL; + goto err; + } + + if (!state) { + ret = us5182d_set_power_state(data, false); + if (ret < 0) + goto err; + } + + if (!data->falling_en && !data->rising_en && !data->default_continuous) + data->power_mode = US5182D_ONESHOT; + + mutex_unlock(&data->lock); + return 0; + +err_poweroff: + if (state) + us5182d_set_power_state(data, false); +err: + mutex_unlock(&data->lock); + return ret; +} + static const struct iio_info us5182d_info = { .driver_module = THIS_MODULE, .read_raw = us5182d_read_raw, .write_raw = us5182d_write_raw, .attrs = &us5182d_attr_group, + .read_event_value = &us5182d_read_thresh, + .write_event_value = &us5182d_write_thresh, + .read_event_config = &us5182d_read_event_config, + .write_event_config = &us5182d_write_event_config, }; static int us5182d_reset(struct iio_dev *indio_dev) @@ -368,6 +742,10 @@ static int us5182d_init(struct iio_dev *indio_dev) return ret; data->opmode = 0; + data->power_mode = US5182D_CONTINUOUS; + data->px_low_th = US5182D_REG_PXL_TH_DEFAULT; + data->px_high_th = US5182D_REG_PXH_TH_DEFAULT; + for (i = 0; i < ARRAY_SIZE(us5182d_regvals); i++) { ret = i2c_smbus_write_byte_data(data->client, us5182d_regvals[i].reg, @@ -376,7 +754,17 @@ static int us5182d_init(struct iio_dev *indio_dev) return ret; } - return 0; + data->als_enabled = true; + data->px_enabled = true; + + if (!data->default_continuous) { + ret = us5182d_shutdown_en(data, US5182D_CFG0_SHUTDOWN_EN); + if (ret < 0) + return ret; + data->power_mode = US5182D_ONESHOT; + } + + return ret; } static void us5182d_get_platform_data(struct iio_dev *indio_dev) @@ -399,6 +787,8 @@ static void us5182d_get_platform_data(struct iio_dev *indio_dev) "upisemi,lower-dark-gain", &data->lower_dark_gain)) data->lower_dark_gain = US5182D_REG_AUTO_LDARK_GAIN_DEFAULT; + data->default_continuous = device_property_read_bool(&data->client->dev, + "upisemi,continuous"); } static int us5182d_dark_gain_config(struct iio_dev *indio_dev) @@ -426,6 +816,33 @@ static int us5182d_dark_gain_config(struct iio_dev *indio_dev) US5182D_REG_DARK_AUTO_EN_DEFAULT); } +static irqreturn_t us5182d_irq_thread_handler(int irq, void *private) +{ + struct iio_dev *indio_dev = private; + struct us5182d_data *data = iio_priv(indio_dev); + enum iio_event_direction dir; + int ret; + u64 ev; + + ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG0); + if (ret < 0) { + dev_err(&data->client->dev, "i2c transfer error in irq\n"); + return IRQ_HANDLED; + } + + dir = ret & US5182D_CFG0_PROX ? IIO_EV_DIR_RISING : IIO_EV_DIR_FALLING; + ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 1, IIO_EV_TYPE_THRESH, dir); + + iio_push_event(indio_dev, ev, iio_get_time_ns()); + + ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, + ret & ~US5182D_CFG0_PX_IRQ); + if (ret < 0) + dev_err(&data->client->dev, "i2c transfer error in irq\n"); + + return IRQ_HANDLED; +} + static int us5182d_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -457,6 +874,16 @@ static int us5182d_probe(struct i2c_client *client, return (ret < 0) ? ret : -ENODEV; } + if (client->irq > 0) { + ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, + us5182d_irq_thread_handler, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + "us5182d-irq", indio_dev); + if (ret < 0) + return ret; + } else + dev_warn(&client->dev, "no valid irq found\n"); + us5182d_get_platform_data(indio_dev); ret = us5182d_init(indio_dev); if (ret < 0) @@ -464,18 +891,73 @@ static int us5182d_probe(struct i2c_client *client, ret = us5182d_dark_gain_config(indio_dev); if (ret < 0) - return ret; + goto out_err; + + if (data->default_continuous) { + pm_runtime_set_active(&client->dev); + if (ret < 0) + goto out_err; + } + + pm_runtime_enable(&client->dev); + pm_runtime_set_autosuspend_delay(&client->dev, + US5182D_SLEEP_MS); + pm_runtime_use_autosuspend(&client->dev); + + ret = iio_device_register(indio_dev); + if (ret < 0) + goto out_err; + + return 0; + +out_err: + us5182d_shutdown_en(data, US5182D_CFG0_SHUTDOWN_EN); + return ret; - return iio_device_register(indio_dev); } static int us5182d_remove(struct i2c_client *client) { + struct us5182d_data *data = iio_priv(i2c_get_clientdata(client)); + iio_device_unregister(i2c_get_clientdata(client)); - return i2c_smbus_write_byte_data(client, US5182D_REG_CFG0, - US5182D_CFG0_SHUTDOWN_EN); + + pm_runtime_disable(&client->dev); + pm_runtime_set_suspended(&client->dev); + + return us5182d_shutdown_en(data, US5182D_CFG0_SHUTDOWN_EN); +} + +#if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM) +static int us5182d_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct us5182d_data *data = iio_priv(indio_dev); + + if (data->power_mode == US5182D_CONTINUOUS) + return us5182d_shutdown_en(data, US5182D_CFG0_SHUTDOWN_EN); + + return 0; } +static int us5182d_resume(struct device *dev) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct us5182d_data *data = iio_priv(indio_dev); + + if (data->power_mode == US5182D_CONTINUOUS) + return us5182d_shutdown_en(data, + ~US5182D_CFG0_SHUTDOWN_EN & 0xff); + + return 0; +} +#endif + +static const struct dev_pm_ops us5182d_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(us5182d_suspend, us5182d_resume) + SET_RUNTIME_PM_OPS(us5182d_suspend, us5182d_resume, NULL) +}; + static const struct acpi_device_id us5182d_acpi_match[] = { { "USD5182", 0}, {} @@ -493,6 +975,7 @@ MODULE_DEVICE_TABLE(i2c, us5182d_id); static struct i2c_driver us5182d_driver = { .driver = { .name = US5182D_DRV_NAME, + .pm = &us5182d_pm_ops, .acpi_match_table = ACPI_PTR(us5182d_acpi_match), }, .probe = us5182d_probe, diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c index 1615b23d7b2a..ffcb75ea64fb 100644 --- a/drivers/iio/magnetometer/bmc150_magn.c +++ b/drivers/iio/magnetometer/bmc150_magn.c @@ -928,27 +928,24 @@ static int bmc150_magn_probe(struct i2c_client *client, goto err_free_irq; } - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&client->dev, "unable to register iio device\n"); - goto err_buffer_cleanup; - } - ret = pm_runtime_set_active(&client->dev); if (ret) - goto err_iio_unregister; + goto err_buffer_cleanup; pm_runtime_enable(&client->dev); pm_runtime_set_autosuspend_delay(&client->dev, BMC150_MAGN_AUTO_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(&client->dev); - dev_dbg(&indio_dev->dev, "Registered device %s\n", name); + ret = iio_device_register(indio_dev); + if (ret < 0) { + dev_err(&client->dev, "unable to register iio device\n"); + goto err_buffer_cleanup; + } + dev_dbg(&indio_dev->dev, "Registered device %s\n", name); return 0; -err_iio_unregister: - iio_device_unregister(indio_dev); err_buffer_cleanup: iio_triggered_buffer_cleanup(indio_dev); err_free_irq: @@ -967,11 +964,12 @@ static int bmc150_magn_remove(struct i2c_client *client) struct iio_dev *indio_dev = i2c_get_clientdata(client); struct bmc150_magn_data *data = iio_priv(indio_dev); + iio_device_unregister(indio_dev); + pm_runtime_disable(&client->dev); pm_runtime_set_suspended(&client->dev); pm_runtime_put_noidle(&client->dev); - iio_device_unregister(indio_dev); iio_triggered_buffer_cleanup(indio_dev); if (client->irq > 0) diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c index e544fcfd5ced..93e29fb67fa0 100644 --- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c @@ -13,7 +13,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * TODO: runtime pm, interrupt mode, and signal strength reporting + * TODO: interrupt mode, and signal strength reporting */ #include <linux/err.h> @@ -21,6 +21,7 @@ #include <linux/i2c.h> #include <linux/delay.h> #include <linux/module.h> +#include <linux/pm_runtime.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> @@ -35,8 +36,11 @@ #define LIDAR_REG_STATUS_INVALID BIT(3) #define LIDAR_REG_STATUS_READY BIT(0) -#define LIDAR_REG_DATA_HBYTE 0x0f -#define LIDAR_REG_DATA_LBYTE 0x10 +#define LIDAR_REG_DATA_HBYTE 0x0f +#define LIDAR_REG_DATA_LBYTE 0x10 +#define LIDAR_REG_DATA_WORD_READ BIT(7) + +#define LIDAR_REG_PWR_CONTROL 0x65 #define LIDAR_DRV_NAME "lidar" @@ -44,6 +48,9 @@ struct lidar_data { struct iio_dev *indio_dev; struct i2c_client *client; + int (*xfer)(struct lidar_data *data, u8 reg, u8 *val, int len); + int i2c_enabled; + u16 buffer[8]; /* 2 byte distance + 8 byte timestamp */ }; @@ -62,7 +69,28 @@ static const struct iio_chan_spec lidar_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(1), }; -static int lidar_read_byte(struct lidar_data *data, int reg) +static int lidar_i2c_xfer(struct lidar_data *data, u8 reg, u8 *val, int len) +{ + struct i2c_client *client = data->client; + struct i2c_msg msg[2]; + int ret; + + msg[0].addr = client->addr; + msg[0].flags = client->flags | I2C_M_STOP; + msg[0].len = 1; + msg[0].buf = (char *) ® + + msg[1].addr = client->addr; + msg[1].flags = client->flags | I2C_M_RD; + msg[1].len = len; + msg[1].buf = (char *) val; + + ret = i2c_transfer(client->adapter, msg, 2); + + return (ret == 2) ? 0 : ret; +} + +static int lidar_smbus_xfer(struct lidar_data *data, u8 reg, u8 *val, int len) { struct i2c_client *client = data->client; int ret; @@ -72,17 +100,35 @@ static int lidar_read_byte(struct lidar_data *data, int reg) * so in turn i2c_smbus_read_byte_data cannot be used */ - ret = i2c_smbus_write_byte(client, reg); - if (ret < 0) { - dev_err(&client->dev, "cannot write addr value"); - return ret; + while (len--) { + ret = i2c_smbus_write_byte(client, reg++); + if (ret < 0) { + dev_err(&client->dev, "cannot write addr value"); + return ret; + } + + ret = i2c_smbus_read_byte(client); + if (ret < 0) { + dev_err(&client->dev, "cannot read data value"); + return ret; + } + + *(val++) = ret; } - ret = i2c_smbus_read_byte(client); + return 0; +} + +static int lidar_read_byte(struct lidar_data *data, u8 reg) +{ + int ret; + u8 val; + + ret = data->xfer(data, reg, &val, 1); if (ret < 0) - dev_err(&client->dev, "cannot read data value"); + return ret; - return ret; + return val; } static inline int lidar_write_control(struct lidar_data *data, int val) @@ -90,24 +136,22 @@ static inline int lidar_write_control(struct lidar_data *data, int val) return i2c_smbus_write_byte_data(data->client, LIDAR_REG_CONTROL, val); } -static int lidar_read_measurement(struct lidar_data *data, u16 *reg) +static inline int lidar_write_power(struct lidar_data *data, int val) { - int ret; - int val; - - ret = lidar_read_byte(data, LIDAR_REG_DATA_HBYTE); - if (ret < 0) - return ret; - val = ret << 8; + return i2c_smbus_write_byte_data(data->client, + LIDAR_REG_PWR_CONTROL, val); +} - ret = lidar_read_byte(data, LIDAR_REG_DATA_LBYTE); - if (ret < 0) - return ret; +static int lidar_read_measurement(struct lidar_data *data, u16 *reg) +{ + int ret = data->xfer(data, LIDAR_REG_DATA_HBYTE | + (data->i2c_enabled ? LIDAR_REG_DATA_WORD_READ : 0), + (u8 *) reg, 2); - val |= ret; - *reg = val; + if (!ret) + *reg = be16_to_cpu(*reg); - return 0; + return ret; } static int lidar_get_measurement(struct lidar_data *data, u16 *reg) @@ -116,6 +160,8 @@ static int lidar_get_measurement(struct lidar_data *data, u16 *reg) int tries = 10; int ret; + pm_runtime_get_sync(&client->dev); + /* start sample */ ret = lidar_write_control(data, LIDAR_REG_CONTROL_ACQUIRE); if (ret < 0) { @@ -144,6 +190,8 @@ static int lidar_get_measurement(struct lidar_data *data, u16 *reg) } ret = -EIO; } + pm_runtime_mark_last_busy(&client->dev); + pm_runtime_put_autosuspend(&client->dev); return ret; } @@ -221,6 +269,16 @@ static int lidar_probe(struct i2c_client *client, indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; + data = iio_priv(indio_dev); + + if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + data->xfer = lidar_i2c_xfer; + data->i2c_enabled = 1; + } else if (i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BYTE)) + data->xfer = lidar_smbus_xfer; + else + return -ENOTSUPP; indio_dev->info = &lidar_info; indio_dev->name = LIDAR_DRV_NAME; @@ -228,7 +286,6 @@ static int lidar_probe(struct i2c_client *client, indio_dev->num_channels = ARRAY_SIZE(lidar_channels); indio_dev->modes = INDIO_DIRECT_MODE; - data = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); data->client = client; @@ -243,6 +300,17 @@ static int lidar_probe(struct i2c_client *client, if (ret) goto error_unreg_buffer; + pm_runtime_set_autosuspend_delay(&client->dev, 1000); + pm_runtime_use_autosuspend(&client->dev); + + ret = pm_runtime_set_active(&client->dev); + if (ret) + goto error_unreg_buffer; + pm_runtime_enable(&client->dev); + + pm_runtime_mark_last_busy(&client->dev); + pm_runtime_idle(&client->dev); + return 0; error_unreg_buffer: @@ -258,6 +326,9 @@ static int lidar_remove(struct i2c_client *client) iio_device_unregister(indio_dev); iio_triggered_buffer_cleanup(indio_dev); + pm_runtime_disable(&client->dev); + pm_runtime_set_suspended(&client->dev); + return 0; } @@ -273,10 +344,38 @@ static const struct of_device_id lidar_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, lidar_dt_ids); +#ifdef CONFIG_PM +static int lidar_pm_runtime_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct lidar_data *data = iio_priv(indio_dev); + + return lidar_write_power(data, 0x0f); +} + +static int lidar_pm_runtime_resume(struct device *dev) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct lidar_data *data = iio_priv(indio_dev); + int ret = lidar_write_power(data, 0); + + /* regulator and FPGA needs settling time */ + usleep_range(15000, 20000); + + return ret; +} +#endif + +static const struct dev_pm_ops lidar_pm_ops = { + SET_RUNTIME_PM_OPS(lidar_pm_runtime_suspend, + lidar_pm_runtime_resume, NULL) +}; + static struct i2c_driver lidar_driver = { .driver = { .name = LIDAR_DRV_NAME, .of_match_table = of_match_ptr(lidar_dt_ids), + .pm = &lidar_pm_ops, }, .probe = lidar_probe, .remove = lidar_remove, diff --git a/drivers/iio/trigger/Kconfig b/drivers/iio/trigger/Kconfig index 79996123a71b..519e6772f6f5 100644 --- a/drivers/iio/trigger/Kconfig +++ b/drivers/iio/trigger/Kconfig @@ -5,6 +5,16 @@ menu "Triggers - standalone" +config IIO_HRTIMER_TRIGGER + tristate "High resolution timer trigger" + depends on IIO_SW_TRIGGER + help + Provides a frequency based IIO trigger using high resolution + timers as interrupt source. + + To compile this driver as a module, choose M here: the + module will be called iio-trig-hrtimer. + config IIO_INTERRUPT_TRIGGER tristate "Generic interrupt trigger" help diff --git a/drivers/iio/trigger/Makefile b/drivers/iio/trigger/Makefile index 0694daecaf22..fe06eb564367 100644 --- a/drivers/iio/trigger/Makefile +++ b/drivers/iio/trigger/Makefile @@ -3,5 +3,7 @@ # # When adding new entries keep the list in alphabetical order + +obj-$(CONFIG_IIO_HRTIMER_TRIGGER) += iio-trig-hrtimer.o obj-$(CONFIG_IIO_INTERRUPT_TRIGGER) += iio-trig-interrupt.o obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o diff --git a/drivers/iio/trigger/iio-trig-hrtimer.c b/drivers/iio/trigger/iio-trig-hrtimer.c new file mode 100644 index 000000000000..5e6d451febeb --- /dev/null +++ b/drivers/iio/trigger/iio-trig-hrtimer.c @@ -0,0 +1,193 @@ +/** + * The industrial I/O periodic hrtimer trigger driver + * + * Copyright (C) Intuitive Aerial AB + * Written by Marten Svanfeldt, marten@intuitiveaerial.com + * Copyright (C) 2012, Analog Device Inc. + * Author: Lars-Peter Clausen <lars@metafoo.de> + * Copyright (C) 2015, Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + */ +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/hrtimer.h> + +#include <linux/iio/iio.h> +#include <linux/iio/trigger.h> +#include <linux/iio/sw_trigger.h> + +/* default sampling frequency - 100Hz */ +#define HRTIMER_DEFAULT_SAMPLING_FREQUENCY 100 + +struct iio_hrtimer_info { + struct iio_sw_trigger swt; + struct hrtimer timer; + unsigned long sampling_frequency; + ktime_t period; +}; + +static struct config_item_type iio_hrtimer_type = { + .ct_owner = THIS_MODULE, +}; + +static +ssize_t iio_hrtimer_show_sampling_frequency(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_trigger *trig = to_iio_trigger(dev); + struct iio_hrtimer_info *info = iio_trigger_get_drvdata(trig); + + return snprintf(buf, PAGE_SIZE, "%lu\n", info->sampling_frequency); +} + +static +ssize_t iio_hrtimer_store_sampling_frequency(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct iio_trigger *trig = to_iio_trigger(dev); + struct iio_hrtimer_info *info = iio_trigger_get_drvdata(trig); + unsigned long val; + int ret; + + ret = kstrtoul(buf, 10, &val); + if (ret) + return ret; + + if (!val || val > NSEC_PER_SEC) + return -EINVAL; + + info->sampling_frequency = val; + info->period = ktime_set(0, NSEC_PER_SEC / val); + + return len; +} + +static DEVICE_ATTR(sampling_frequency, S_IRUGO | S_IWUSR, + iio_hrtimer_show_sampling_frequency, + iio_hrtimer_store_sampling_frequency); + +static struct attribute *iio_hrtimer_attrs[] = { + &dev_attr_sampling_frequency.attr, + NULL +}; + +static const struct attribute_group iio_hrtimer_attr_group = { + .attrs = iio_hrtimer_attrs, +}; + +static const struct attribute_group *iio_hrtimer_attr_groups[] = { + &iio_hrtimer_attr_group, + NULL +}; + +static enum hrtimer_restart iio_hrtimer_trig_handler(struct hrtimer *timer) +{ + struct iio_hrtimer_info *info; + + info = container_of(timer, struct iio_hrtimer_info, timer); + + hrtimer_forward_now(timer, info->period); + iio_trigger_poll(info->swt.trigger); + + return HRTIMER_RESTART; +} + +static int iio_trig_hrtimer_set_state(struct iio_trigger *trig, bool state) +{ + struct iio_hrtimer_info *trig_info; + + trig_info = iio_trigger_get_drvdata(trig); + + if (state) + hrtimer_start(&trig_info->timer, trig_info->period, + HRTIMER_MODE_REL); + else + hrtimer_cancel(&trig_info->timer); + + return 0; +} + +static const struct iio_trigger_ops iio_hrtimer_trigger_ops = { + .owner = THIS_MODULE, + .set_trigger_state = iio_trig_hrtimer_set_state, +}; + +static struct iio_sw_trigger *iio_trig_hrtimer_probe(const char *name) +{ + struct iio_hrtimer_info *trig_info; + int ret; + + trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL); + if (!trig_info) + return ERR_PTR(-ENOMEM); + + trig_info->swt.trigger = iio_trigger_alloc("%s", name); + if (!trig_info->swt.trigger) { + ret = -ENOMEM; + goto err_free_trig_info; + } + + iio_trigger_set_drvdata(trig_info->swt.trigger, trig_info); + trig_info->swt.trigger->ops = &iio_hrtimer_trigger_ops; + trig_info->swt.trigger->dev.groups = iio_hrtimer_attr_groups; + + hrtimer_init(&trig_info->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + trig_info->timer.function = iio_hrtimer_trig_handler; + + trig_info->sampling_frequency = HRTIMER_DEFAULT_SAMPLING_FREQUENCY; + trig_info->period = ktime_set(0, NSEC_PER_SEC / + trig_info->sampling_frequency); + + ret = iio_trigger_register(trig_info->swt.trigger); + if (ret) + goto err_free_trigger; + + iio_swt_group_init_type_name(&trig_info->swt, name, &iio_hrtimer_type); + return &trig_info->swt; +err_free_trigger: + iio_trigger_free(trig_info->swt.trigger); +err_free_trig_info: + kfree(trig_info); + + return ERR_PTR(ret); +} + +static int iio_trig_hrtimer_remove(struct iio_sw_trigger *swt) +{ + struct iio_hrtimer_info *trig_info; + + trig_info = iio_trigger_get_drvdata(swt->trigger); + + iio_trigger_unregister(swt->trigger); + + /* cancel the timer after unreg to make sure no one rearms it */ + hrtimer_cancel(&trig_info->timer); + iio_trigger_free(swt->trigger); + kfree(trig_info); + + return 0; +} + +static const struct iio_sw_trigger_ops iio_trig_hrtimer_ops = { + .probe = iio_trig_hrtimer_probe, + .remove = iio_trig_hrtimer_remove, +}; + +static struct iio_sw_trigger_type iio_trig_hrtimer = { + .name = "hrtimer", + .owner = THIS_MODULE, + .ops = &iio_trig_hrtimer_ops, +}; + +module_iio_sw_trigger_driver(iio_trig_hrtimer); + +MODULE_AUTHOR("Marten Svanfeldt <marten@intuitiveaerial.com>"); +MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>"); +MODULE_DESCRIPTION("Periodic hrtimer trigger for the IIO subsystem"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/android/TODO b/drivers/staging/android/TODO index 8f3ac37bfe12..64d8c8720960 100644 --- a/drivers/staging/android/TODO +++ b/drivers/staging/android/TODO @@ -25,5 +25,13 @@ ion/ exposes existing cma regions and doesn't reserve unecessarily memory when booting a system which doesn't use ion. +sync framework: + - remove CONFIG_SW_SYNC_USER, it is used only for testing/debugging and + should not be upstreamed. + - port CONFIG_SW_SYNC_USER tests interfaces to use debugfs somehow + - port libsync tests to kselftest + - clean up and ABI check for security issues + - move it to drivers/base/dma-buf + Please send patches to Greg Kroah-Hartman <greg@kroah.com> and Cc: Arve HjønnevÃ¥g <arve@android.com> and Riley Andrews <riandrews@android.com> diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c index 3f2a3d611e4b..5bb1283d19cd 100644 --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -831,14 +831,14 @@ static struct miscdevice ashmem_misc = { static int __init ashmem_init(void) { - int ret; + int ret = -ENOMEM; ashmem_area_cachep = kmem_cache_create("ashmem_area_cache", sizeof(struct ashmem_area), 0, 0, NULL); if (unlikely(!ashmem_area_cachep)) { pr_err("failed to create slab cache\n"); - return -ENOMEM; + goto out; } ashmem_range_cachep = kmem_cache_create("ashmem_range_cache", @@ -846,13 +846,13 @@ static int __init ashmem_init(void) 0, 0, NULL); if (unlikely(!ashmem_range_cachep)) { pr_err("failed to create slab cache\n"); - return -ENOMEM; + goto out_free1; } ret = misc_register(&ashmem_misc); if (unlikely(ret)) { pr_err("failed to register misc device!\n"); - return ret; + goto out_free2; } register_shrinker(&ashmem_shrinker); @@ -860,5 +860,12 @@ static int __init ashmem_init(void) pr_info("initialized\n"); return 0; + +out_free2: + kmem_cache_destroy(ashmem_range_cachep); +out_free1: + kmem_cache_destroy(ashmem_area_cachep); +out: + return ret; } device_initcall(ashmem_init); diff --git a/drivers/staging/android/ion/Kconfig b/drivers/staging/android/ion/Kconfig index 345234624492..19c1572f1525 100644 --- a/drivers/staging/android/ion/Kconfig +++ b/drivers/staging/android/ion/Kconfig @@ -33,3 +33,10 @@ config ION_TEGRA help Choose this option if you wish to use ion on an nVidia Tegra. +config ION_HISI + tristate "Ion for Hisilicon" + depends on ARCH_HISI && ION + help + Choose this option if you wish to use ion on Hisilicon Platform. + +source "drivers/staging/android/ion/hisilicon/Kconfig" diff --git a/drivers/staging/android/ion/Makefile b/drivers/staging/android/ion/Makefile index b56fd2bf2b4f..18cc2aa593c2 100644 --- a/drivers/staging/android/ion/Makefile +++ b/drivers/staging/android/ion/Makefile @@ -7,4 +7,5 @@ endif obj-$(CONFIG_ION_DUMMY) += ion_dummy_driver.o obj-$(CONFIG_ION_TEGRA) += tegra/ +obj-$(CONFIG_ION_HISI) += hisilicon/ diff --git a/drivers/staging/android/ion/compat_ion.c b/drivers/staging/android/ion/compat_ion.c index a402fdaf54ca..9a978d21785e 100644 --- a/drivers/staging/android/ion/compat_ion.c +++ b/drivers/staging/android/ion/compat_ion.c @@ -137,7 +137,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) data32 = compat_ptr(arg); data = compat_alloc_user_space(sizeof(*data)); - if (data == NULL) + if (!data) return -EFAULT; err = compat_get_ion_allocation_data(data32, data); @@ -156,7 +156,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) data32 = compat_ptr(arg); data = compat_alloc_user_space(sizeof(*data)); - if (data == NULL) + if (!data) return -EFAULT; err = compat_get_ion_handle_data(data32, data); @@ -173,7 +173,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) data32 = compat_ptr(arg); data = compat_alloc_user_space(sizeof(*data)); - if (data == NULL) + if (!data) return -EFAULT; err = compat_get_ion_custom_data(data32, data); diff --git a/drivers/staging/android/ion/hisilicon/Kconfig b/drivers/staging/android/ion/hisilicon/Kconfig new file mode 100644 index 000000000000..2b4bd0798290 --- /dev/null +++ b/drivers/staging/android/ion/hisilicon/Kconfig @@ -0,0 +1,5 @@ +config HI6220_ION + bool "Hi6220 ION Driver" + depends on ARCH_HISI && ION + help + Build the Hisilicon Hi6220 ion driver. diff --git a/drivers/staging/android/ion/hisilicon/Makefile b/drivers/staging/android/ion/hisilicon/Makefile new file mode 100644 index 000000000000..2a89414280ac --- /dev/null +++ b/drivers/staging/android/ion/hisilicon/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_HI6220_ION) += hi6220_ion.o diff --git a/drivers/staging/android/ion/hisilicon/hi6220_ion.c b/drivers/staging/android/ion/hisilicon/hi6220_ion.c new file mode 100644 index 000000000000..e3c07b2ba00e --- /dev/null +++ b/drivers/staging/android/ion/hisilicon/hi6220_ion.c @@ -0,0 +1,223 @@ +/* + * Hisilicon Hi6220 ION Driver + * + * Copyright (c) 2015 Hisilicon Limited. + * + * Author: Chen Feng <puck.chen@hisilicon.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#define pr_fmt(fmt) "Ion: " fmt + +#include <linux/err.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/mm.h> +#include "../ion_priv.h" +#include "../ion.h" + +struct hi6220_ion_type_table { + const char *name; + enum ion_heap_type type; +}; + +static struct hi6220_ion_type_table ion_type_table[] = { + {"ion_system", ION_HEAP_TYPE_SYSTEM}, + {"ion_system_contig", ION_HEAP_TYPE_SYSTEM_CONTIG}, + {"ion_carveout", ION_HEAP_TYPE_CARVEOUT}, + {"ion_chunk", ION_HEAP_TYPE_CHUNK}, + {"ion_dma", ION_HEAP_TYPE_DMA}, + {"ion_custom", ION_HEAP_TYPE_CUSTOM}, +}; + +static struct ion_device *idev; +static int num_heaps; +static struct ion_heap **heaps; +static struct ion_platform_heap **heaps_data; + +static int get_type_by_name(const char *name, enum ion_heap_type *type) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(ion_type_table); i++) { + if (strncmp(name, ion_type_table[i].name, strlen(name))) + continue; + + *type = ion_type_table[i].type; + return 0; + } + + return -EINVAL; +} + +static int hi6220_set_platform_data(struct platform_device *pdev) +{ + unsigned int base; + unsigned int size; + unsigned int id; + const char *heap_name; + const char *type_name; + enum ion_heap_type type; + int ret; + struct device_node *np; + struct ion_platform_heap *p_data; + const struct device_node *dt_node = pdev->dev.of_node; + int index = 0; + + for_each_child_of_node(dt_node, np) + num_heaps++; + + heaps_data = devm_kzalloc(&pdev->dev, + sizeof(struct ion_platform_heap *) * + num_heaps, + GFP_KERNEL); + if (!heaps_data) + return -ENOMEM; + + for_each_child_of_node(dt_node, np) { + ret = of_property_read_string(np, "heap-name", &heap_name); + if (ret < 0) { + pr_err("check the name of node %s\n", np->name); + continue; + } + + ret = of_property_read_u32(np, "heap-id", &id); + if (ret < 0) { + pr_err("check the id %s\n", np->name); + continue; + } + + ret = of_property_read_u32(np, "heap-base", &base); + if (ret < 0) { + pr_err("check the base of node %s\n", np->name); + continue; + } + + ret = of_property_read_u32(np, "heap-size", &size); + if (ret < 0) { + pr_err("check the size of node %s\n", np->name); + continue; + } + + ret = of_property_read_string(np, "heap-type", &type_name); + if (ret < 0) { + pr_err("check the type of node %s\n", np->name); + continue; + } + + ret = get_type_by_name(type_name, &type); + if (ret < 0) { + pr_err("type name error %s!\n", type_name); + continue; + } + pr_info("heap index %d : name %s base 0x%x size 0x%x id %d type %d\n", + index, heap_name, base, size, id, type); + + p_data = devm_kzalloc(&pdev->dev, + sizeof(struct ion_platform_heap), + GFP_KERNEL); + if (!p_data) + return -ENOMEM; + + p_data->name = heap_name; + p_data->base = base; + p_data->size = size; + p_data->id = id; + p_data->type = type; + + heaps_data[index] = p_data; + index++; + } + return 0; +} + +static int hi6220_ion_probe(struct platform_device *pdev) +{ + int i; + int err; + static struct ion_platform_heap *p_heap; + + idev = ion_device_create(NULL); + err = hi6220_set_platform_data(pdev); + if (err) { + pr_err("ion set platform data error!\n"); + goto err_free_idev; + } + heaps = devm_kzalloc(&pdev->dev, + sizeof(struct ion_heap *) * num_heaps, + GFP_KERNEL); + if (!heaps) { + err = -ENOMEM; + goto err_free_idev; + } + + /* + * create the heaps as specified in the dts file + */ + for (i = 0; i < num_heaps; i++) { + p_heap = heaps_data[i]; + heaps[i] = ion_heap_create(p_heap); + if (IS_ERR_OR_NULL(heaps[i])) { + err = PTR_ERR(heaps[i]); + goto err_free_heaps; + } + + ion_device_add_heap(idev, heaps[i]); + + pr_info("%s: adding heap %s of type %d with %lx@%lx\n", + __func__, p_heap->name, p_heap->type, + p_heap->base, (unsigned long)p_heap->size); + } + return err; + +err_free_heaps: + for (i = 0; i < num_heaps; ++i) { + ion_heap_destroy(heaps[i]); + heaps[i] = NULL; + } +err_free_idev: + ion_device_destroy(idev); + + return err; +} + +static int hi6220_ion_remove(struct platform_device *pdev) +{ + int i; + + for (i = 0; i < num_heaps; i++) { + ion_heap_destroy(heaps[i]); + heaps[i] = NULL; + } + ion_device_destroy(idev); + + return 0; +} + +static const struct of_device_id hi6220_ion_match_table[] = { + {.compatible = "hisilicon,hi6220-ion"}, + {}, +}; + +static struct platform_driver hi6220_ion_driver = { + .probe = hi6220_ion_probe, + .remove = hi6220_ion_remove, + .driver = { + .name = "ion-hi6220", + .of_match_table = hi6220_ion_match_table, + }, +}; + +static int __init hi6220_ion_init(void) +{ + int ret; + + ret = platform_driver_register(&hi6220_ion_driver); + return ret; +} + +subsys_initcall(hi6220_ion_init); diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c index e679d8432810..8b5a4a82d8b8 100644 --- a/drivers/staging/android/lowmemorykiller.c +++ b/drivers/staging/android/lowmemorykiller.c @@ -43,7 +43,7 @@ #include <linux/profile.h> #include <linux/notifier.h> -static uint32_t lowmem_debug_level = 1; +static u32 lowmem_debug_level = 1; static short lowmem_adj[6] = { 0, 1, @@ -105,8 +105,8 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc) } lowmem_print(3, "lowmem_scan %lu, %x, ofree %d %d, ma %hd\n", - sc->nr_to_scan, sc->gfp_mask, other_free, - other_file, min_score_adj); + sc->nr_to_scan, sc->gfp_mask, other_free, + other_file, min_score_adj); if (min_score_adj == OOM_SCORE_ADJ_MAX + 1) { lowmem_print(5, "lowmem_scan %lu, %x, return 0\n", diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index f83e00c78051..ed43796b5b58 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -43,7 +43,7 @@ struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops, return NULL; obj = kzalloc(size, GFP_KERNEL); - if (obj == NULL) + if (!obj) return NULL; kref_init(&obj->kref); @@ -130,7 +130,7 @@ struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size) return NULL; pt = kzalloc(size, GFP_KERNEL); - if (pt == NULL) + if (!pt) return NULL; spin_lock_irqsave(&obj->child_list_lock, flags); @@ -155,7 +155,7 @@ static struct sync_fence *sync_fence_alloc(int size, const char *name) struct sync_fence *fence; fence = kzalloc(size, GFP_KERNEL); - if (fence == NULL) + if (!fence) return NULL; fence->file = anon_inode_getfile("sync_fence", &sync_fence_fops, @@ -188,34 +188,39 @@ static void fence_check_cb_func(struct fence *f, struct fence_cb *cb) } /* TODO: implement a create which takes more that one sync_pt */ -struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt) +struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt) { struct sync_fence *fence; fence = sync_fence_alloc(offsetof(struct sync_fence, cbs[1]), name); - if (fence == NULL) + if (!fence) return NULL; fence->num_fences = 1; atomic_set(&fence->status, 1); - fence->cbs[0].sync_pt = &pt->base; + fence->cbs[0].sync_pt = pt; fence->cbs[0].fence = fence; - if (fence_add_callback(&pt->base, &fence->cbs[0].cb, - fence_check_cb_func)) + if (fence_add_callback(pt, &fence->cbs[0].cb, fence_check_cb_func)) atomic_dec(&fence->status); sync_fence_debug_add(fence); return fence; } +EXPORT_SYMBOL(sync_fence_create_dma); + +struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt) +{ + return sync_fence_create_dma(name, &pt->base); +} EXPORT_SYMBOL(sync_fence_create); struct sync_fence *sync_fence_fdget(int fd) { struct file *file = fget(fd); - if (file == NULL) + if (!file) return NULL; if (file->f_op != &sync_fence_fops) @@ -262,7 +267,7 @@ struct sync_fence *sync_fence_merge(const char *name, unsigned long size = offsetof(struct sync_fence, cbs[num_fences]); fence = sync_fence_alloc(size, name); - if (fence == NULL) + if (!fence) return NULL; atomic_set(&fence->status, num_fences); @@ -313,7 +318,7 @@ struct sync_fence *sync_fence_merge(const char *name, EXPORT_SYMBOL(sync_fence_merge); int sync_fence_wake_up_wq(wait_queue_t *curr, unsigned mode, - int wake_flags, void *key) + int wake_flags, void *key) { struct sync_fence_waiter *wait; @@ -353,7 +358,7 @@ int sync_fence_wait_async(struct sync_fence *fence, EXPORT_SYMBOL(sync_fence_wait_async); int sync_fence_cancel_async(struct sync_fence *fence, - struct sync_fence_waiter *waiter) + struct sync_fence_waiter *waiter) { unsigned long flags; int ret = 0; @@ -519,12 +524,10 @@ static const struct fence_ops android_fence_ops = { static void sync_fence_free(struct kref *kref) { struct sync_fence *fence = container_of(kref, struct sync_fence, kref); - int i, status = atomic_read(&fence->status); + int i; for (i = 0; i < fence->num_fences; ++i) { - if (status) - fence_remove_callback(fence->cbs[i].sync_pt, - &fence->cbs[i].cb); + fence_remove_callback(fence->cbs[i].sync_pt, &fence->cbs[i].cb); fence_put(fence->cbs[i].sync_pt); } @@ -583,14 +586,14 @@ static long sync_fence_ioctl_merge(struct sync_fence *fence, unsigned long arg) } fence2 = sync_fence_fdget(data.fd2); - if (fence2 == NULL) { + if (!fence2) { err = -ENOENT; goto err_put_fd; } data.name[sizeof(data.name) - 1] = '\0'; fence3 = sync_fence_merge(data.name, fence, fence2); - if (fence3 == NULL) { + if (!fence3) { err = -ENOMEM; goto err_put_fence2; } @@ -666,7 +669,7 @@ static long sync_fence_ioctl_fence_info(struct sync_fence *fence, size = 4096; data = kzalloc(size, GFP_KERNEL); - if (data == NULL) + if (!data) return -ENOMEM; strlcpy(data->name, fence->name, sizeof(data->name)); diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index 61f8a3aede96..afa0752275a7 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -254,6 +254,16 @@ void sync_pt_free(struct sync_pt *pt); */ struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt); +/** + * sync_fence_create_dma() - creates a sync fence from dma-fence + * @name: name of fence to create + * @pt: dma-fence to add to the fence + * + * Creates a fence containg @pt. Once this is called, the fence takes + * ownership of @pt. + */ +struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt); + /* * API for sync_fence consumers */ diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c index 91ed2c4cff45..f45d13cdd42b 100644 --- a/drivers/staging/android/sync_debug.c +++ b/drivers/staging/android/sync_debug.c @@ -82,36 +82,42 @@ static const char *sync_status_str(int status) return "error"; } -static void sync_print_pt(struct seq_file *s, struct sync_pt *pt, bool fence) +static void sync_print_pt(struct seq_file *s, struct fence *pt, bool fence) { int status = 1; - struct sync_timeline *parent = sync_pt_parent(pt); - if (fence_is_signaled_locked(&pt->base)) - status = pt->base.status; + if (fence_is_signaled_locked(pt)) + status = pt->status; seq_printf(s, " %s%spt %s", - fence ? parent->name : "", + fence && pt->ops->get_timeline_name ? + pt->ops->get_timeline_name(pt) : "", fence ? "_" : "", sync_status_str(status)); if (status <= 0) { struct timespec64 ts64 = - ktime_to_timespec64(pt->base.timestamp); + ktime_to_timespec64(pt->timestamp); seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec); } - if (parent->ops->timeline_value_str && - parent->ops->pt_value_str) { + if ((!fence || pt->ops->timeline_value_str) && + pt->ops->fence_value_str) { char value[64]; + bool success; - parent->ops->pt_value_str(pt, value, sizeof(value)); - seq_printf(s, ": %s", value); - if (fence) { - parent->ops->timeline_value_str(parent, value, - sizeof(value)); - seq_printf(s, " / %s", value); + pt->ops->fence_value_str(pt, value, sizeof(value)); + success = strlen(value); + + if (success) + seq_printf(s, ": %s", value); + + if (success && fence) { + pt->ops->timeline_value_str(pt, value, sizeof(value)); + + if (strlen(value)) + seq_printf(s, " / %s", value); } } @@ -138,7 +144,7 @@ static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj) list_for_each(pos, &obj->child_list_head) { struct sync_pt *pt = container_of(pos, struct sync_pt, child_list); - sync_print_pt(s, pt, false); + sync_print_pt(s, &pt->base, false); } spin_unlock_irqrestore(&obj->child_list_lock, flags); } @@ -153,11 +159,7 @@ static void sync_print_fence(struct seq_file *s, struct sync_fence *fence) sync_status_str(atomic_read(&fence->status))); for (i = 0; i < fence->num_fences; ++i) { - struct sync_pt *pt = - container_of(fence->cbs[i].sync_pt, - struct sync_pt, base); - - sync_print_pt(s, pt, true); + sync_print_pt(s, fence->cbs[i].sync_pt, true); } spin_lock_irqsave(&fence->wq.lock, flags); diff --git a/drivers/staging/android/timed_gpio.c b/drivers/staging/android/timed_gpio.c index ce11726f1a6c..bcd9924d4631 100644 --- a/drivers/staging/android/timed_gpio.c +++ b/drivers/staging/android/timed_gpio.c @@ -25,7 +25,6 @@ #include "timed_output.h" #include "timed_gpio.h" - struct timed_gpio_data { struct timed_output_dev dev; struct hrtimer timer; @@ -76,8 +75,8 @@ static void gpio_enable(struct timed_output_dev *dev, int value) value = data->max_timeout; hrtimer_start(&data->timer, - ktime_set(value / 1000, (value % 1000) * 1000000), - HRTIMER_MODE_REL); + ktime_set(value / 1000, (value % 1000) * 1000000), + HRTIMER_MODE_REL); } spin_unlock_irqrestore(&data->lock, flags); @@ -94,8 +93,8 @@ static int timed_gpio_probe(struct platform_device *pdev) return -EBUSY; gpio_data = devm_kzalloc(&pdev->dev, - sizeof(struct timed_gpio_data) * pdata->num_gpios, - GFP_KERNEL); + sizeof(*gpio_data) * pdata->num_gpios, + GFP_KERNEL); if (!gpio_data) return -ENOMEM; @@ -104,7 +103,7 @@ static int timed_gpio_probe(struct platform_device *pdev) gpio_dat = &gpio_data[i]; hrtimer_init(&gpio_dat->timer, CLOCK_MONOTONIC, - HRTIMER_MODE_REL); + HRTIMER_MODE_REL); gpio_dat->timer.function = gpio_timer_func; spin_lock_init(&gpio_dat->lock); diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index ac0f01007abd..e7255f811611 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -737,15 +737,23 @@ config COMEDI_ADL_PCI9118 called adl_pci9118. config COMEDI_ADV_PCI1710 - tristate "Advantech PCI-171x, PCI-1720 and PCI-1731 support" + tristate "Advantech PCI-171x and PCI-1731 support" select COMEDI_8254 ---help--- Enable support for Advantech PCI-1710, PCI-1710HG, PCI-1711, - PCI-1713, PCI-1720 and PCI-1731 + PCI-1713 and PCI-1731 To compile this driver as a module, choose M here: the module will be called adv_pci1710. +config COMEDI_ADV_PCI1720 + tristate "Advantech PCI-1720 support" + ---help--- + Enable support for Advantech PCI-1720 Analog Output board. + + To compile this driver as a module, choose M here: the module will be + called adv_pci1720. + config COMEDI_ADV_PCI1723 tristate "Advantech PCI-1723 support" ---help--- @@ -764,6 +772,14 @@ config COMEDI_ADV_PCI1724 To compile this driver as a module, choose M here: the module will be called adv_pci1724. +config COMEDI_ADV_PCI1760 + tristate "Advantech PCI-1760 support" + ---help--- + Enable support for Advantech PCI-1760 board. + + To compile this driver as a module, choose M here: the module will be + called adv_pci1760. + config COMEDI_ADV_PCI_DIO tristate "Advantech PCI DIO card support" select COMEDI_8254 @@ -771,8 +787,8 @@ config COMEDI_ADV_PCI_DIO ---help--- Enable support for Advantech PCI DIO cards PCI-1730, PCI-1733, PCI-1734, PCI-1735U, PCI-1736UP, PCI-1739U, - PCI-1750, PCI-1751, PCI-1752, PCI-1753/E, PCI-1754, PCI-1756, - PCI-1760 and PCI-1762 + PCI-1750, PCI-1751, PCI-1752, PCI-1753/E, PCI-1754, PCI-1756 and + PCI-1762 To compile this driver as a module, choose M here: the module will be called adv_pci_dio. diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h index 66edda190b75..83bd309d011b 100644 --- a/drivers/staging/comedi/comedi.h +++ b/drivers/staging/comedi/comedi.h @@ -1,20 +1,20 @@ /* - include/comedi.h (installed as /usr/include/comedi.h) - header file for comedi - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 1998-2001 David A. Schleef <ds@schleef.org> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. -*/ + * include/comedi.h (installed as /usr/include/comedi.h) + * header file for comedi + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1998-2001 David A. Schleef <ds@schleef.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ #ifndef _COMEDI_H #define _COMEDI_H @@ -28,9 +28,9 @@ #define COMEDI_MAJOR 98 /* - maximum number of minor devices. This can be increased, although - kernel structures are currently statically allocated, thus you - don't want this to be much more than you actually use. + * maximum number of minor devices. This can be increased, although + * kernel structures are currently statically allocated, thus you + * don't want this to be much more than you actually use. */ #define COMEDI_NDEVICES 16 @@ -63,21 +63,21 @@ /* packs and unpacks a channel/range number */ #define CR_PACK(chan, rng, aref) \ - ((((aref)&0x3)<<24) | (((rng)&0xff)<<16) | (chan)) + ((((aref) & 0x3) << 24) | (((rng) & 0xff) << 16) | (chan)) #define CR_PACK_FLAGS(chan, range, aref, flags) \ (CR_PACK(chan, range, aref) | ((flags) & CR_FLAGS_MASK)) -#define CR_CHAN(a) ((a)&0xffff) -#define CR_RANGE(a) (((a)>>16)&0xff) -#define CR_AREF(a) (((a)>>24)&0x03) +#define CR_CHAN(a) ((a) & 0xffff) +#define CR_RANGE(a) (((a) >> 16) & 0xff) +#define CR_AREF(a) (((a) >> 24) & 0x03) #define CR_FLAGS_MASK 0xfc000000 -#define CR_ALT_FILTER (1<<26) +#define CR_ALT_FILTER (1 << 26) #define CR_DITHER CR_ALT_FILTER #define CR_DEGLITCH CR_ALT_FILTER -#define CR_ALT_SOURCE (1<<27) -#define CR_EDGE (1<<30) -#define CR_INVERT (1<<31) +#define CR_ALT_SOURCE (1 << 27) +#define CR_EDGE (1 << 30) +#define CR_INVERT (1 << 31) #define AREF_GROUND 0x00 /* analog ref = analog ground */ #define AREF_COMMON 0x01 /* analog ref = analog common */ @@ -114,11 +114,11 @@ #define INSN_READ (0 | INSN_MASK_READ) #define INSN_WRITE (1 | INSN_MASK_WRITE) -#define INSN_BITS (2 | INSN_MASK_READ|INSN_MASK_WRITE) -#define INSN_CONFIG (3 | INSN_MASK_READ|INSN_MASK_WRITE) -#define INSN_GTOD (4 | INSN_MASK_READ|INSN_MASK_SPECIAL) -#define INSN_WAIT (5 | INSN_MASK_WRITE|INSN_MASK_SPECIAL) -#define INSN_INTTRIG (6 | INSN_MASK_WRITE|INSN_MASK_SPECIAL) +#define INSN_BITS (2 | INSN_MASK_READ | INSN_MASK_WRITE) +#define INSN_CONFIG (3 | INSN_MASK_READ | INSN_MASK_WRITE) +#define INSN_GTOD (4 | INSN_MASK_READ | INSN_MASK_SPECIAL) +#define INSN_WAIT (5 | INSN_MASK_WRITE | INSN_MASK_SPECIAL) +#define INSN_INTTRIG (6 | INSN_MASK_WRITE | INSN_MASK_SPECIAL) /* trigger flags */ /* These flags are used in comedi_trig structures */ @@ -279,7 +279,8 @@ enum configuration_ids { INSN_CONFIG_SET_OTHER_SRC = 2005, /* Set other source */ /* INSN_CONFIG_GET_OTHER_SRC = 2006,*//* Get other source */ /* Get size in bytes of subdevice's on-board fifos used during - * streaming input/output */ + * streaming input/output + */ INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE = 2006, INSN_CONFIG_SET_COUNTER_MODE = 4097, /* INSN_CONFIG_8254_SET_MODE is deprecated */ @@ -292,7 +293,8 @@ enum configuration_ids { INSN_CONFIG_PWM_GET_PERIOD = 5001, /* gets frequency */ INSN_CONFIG_GET_PWM_STATUS = 5002, /* is it running? */ /* sets H bridge: duty cycle and sign bit for a relay at the - * same time */ + * same time + */ INSN_CONFIG_PWM_SET_H_BRIDGE = 5003, /* gets H bridge data: duty cycle and the sign bit */ INSN_CONFIG_PWM_GET_H_BRIDGE = 5004 @@ -502,13 +504,13 @@ struct comedi_bufinfo { /* range stuff */ -#define __RANGE(a, b) ((((a)&0xffff)<<16)|((b)&0xffff)) +#define __RANGE(a, b) ((((a) & 0xffff) << 16) | ((b) & 0xffff)) -#define RANGE_OFFSET(a) (((a)>>16)&0xffff) -#define RANGE_LENGTH(b) ((b)&0xffff) +#define RANGE_OFFSET(a) (((a) >> 16) & 0xffff) +#define RANGE_LENGTH(b) ((b) & 0xffff) -#define RF_UNIT(flags) ((flags)&0xff) -#define RF_EXTERNAL (1<<8) +#define RF_UNIT(flags) ((flags) & 0xff) +#define RF_EXTERNAL (1 << 8) #define UNIT_volt 0 #define UNIT_mA 1 @@ -521,23 +523,22 @@ struct comedi_bufinfo { /**********************************************************/ /* - 8254 specific configuration. - - It supports two config commands: - - 0 ID: INSN_CONFIG_SET_COUNTER_MODE - 1 8254 Mode - I8254_MODE0, I8254_MODE1, ..., I8254_MODE5 - OR'ed with: - I8254_BCD, I8254_BINARY - - 0 ID: INSN_CONFIG_8254_READ_STATUS - 1 <-- Status byte returned here. - B7 = Output - B6 = NULL Count - B5 - B0 Current mode. - -*/ + * 8254 specific configuration. + * + * It supports two config commands: + * + * 0 ID: INSN_CONFIG_SET_COUNTER_MODE + * 1 8254 Mode + * I8254_MODE0, I8254_MODE1, ..., I8254_MODE5 + * OR'ed with: + * I8254_BCD, I8254_BINARY + * + * 0 ID: INSN_CONFIG_8254_READ_STATUS + * 1 <-- Status byte returned here. + * B7 = Output + * B6 = NULL Count + * B5 - B0 Current mode. + */ enum i8254_mode { I8254_MODE0 = (0 << 1), /* Interrupt on terminal count */ @@ -545,18 +546,20 @@ enum i8254_mode { I8254_MODE2 = (2 << 1), /* Rate generator */ I8254_MODE3 = (3 << 1), /* Square wave mode */ I8254_MODE4 = (4 << 1), /* Software triggered strobe */ - I8254_MODE5 = (5 << 1), /* Hardware triggered strobe - * (retriggerable) */ - I8254_BCD = 1, /* use binary-coded decimal instead of binary - * (pretty useless) */ + /* Hardware triggered strobe (retriggerable) */ + I8254_MODE5 = (5 << 1), + /* Use binary-coded decimal instead of binary (pretty useless) */ + I8254_BCD = 1, I8254_BINARY = 0 }; #define NI_USUAL_PFI_SELECT(x) (((x) < 10) ? (0x1 + (x)) : (0xb + (x))) #define NI_USUAL_RTSI_SELECT(x) (((x) < 7) ? (0xb + (x)) : 0x1b) -/* mode bits for NI general-purpose counters, set with - * INSN_CONFIG_SET_COUNTER_MODE */ +/* + * mode bits for NI general-purpose counters, set with + * INSN_CONFIG_SET_COUNTER_MODE + */ #define NI_GPCT_COUNTING_MODE_SHIFT 16 #define NI_GPCT_INDEX_PHASE_BITSHIFT 20 #define NI_GPCT_COUNTING_DIRECTION_SHIFT 24 @@ -624,8 +627,10 @@ enum ni_gpct_mode_bits { NI_GPCT_INVERT_OUTPUT_BIT = 0x20000000 }; -/* Bits for setting a clock source with - * INSN_CONFIG_SET_CLOCK_SRC when using NI general-purpose counters. */ +/* + * Bits for setting a clock source with + * INSN_CONFIG_SET_CLOCK_SRC when using NI general-purpose counters. + */ enum ni_gpct_clock_source_bits { NI_GPCT_CLOCK_SRC_SELECT_MASK = 0x3f, NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS = 0x0, @@ -656,9 +661,11 @@ enum ni_gpct_clock_source_bits { /* no pfi on NI 660x */ #define NI_GPCT_PFI_CLOCK_SRC_BITS(x) (0x20 + (x)) -/* Possibilities for setting a gate source with -INSN_CONFIG_SET_GATE_SRC when using NI general-purpose counters. -May be bitwise-or'd with CR_EDGE or CR_INVERT. */ +/* + * Possibilities for setting a gate source with + * INSN_CONFIG_SET_GATE_SRC when using NI general-purpose counters. + * May be bitwise-or'd with CR_EDGE or CR_INVERT. + */ enum ni_gpct_gate_select { /* m-series gates */ NI_GPCT_TIMESTAMP_MUX_GATE_SELECT = 0x0, @@ -675,9 +682,11 @@ enum ni_gpct_gate_select { /* more gates for 660x "second gate" */ NI_GPCT_UP_DOWN_PIN_i_GATE_SELECT = 0x201, NI_GPCT_SELECTED_GATE_GATE_SELECT = 0x21e, - /* m-series "second gate" sources are unknown, + /* + * m-series "second gate" sources are unknown, * we should add them here with an offset of 0x300 when - * known. */ + * known. + */ NI_GPCT_DISABLED_GATE_SELECT = 0x8000, }; @@ -686,8 +695,10 @@ enum ni_gpct_gate_select { #define NI_GPCT_PFI_GATE_SELECT(x) NI_USUAL_PFI_SELECT(x) #define NI_GPCT_UP_DOWN_PIN_GATE_SELECT(x) (0x202 + (x)) -/* Possibilities for setting a source with -INSN_CONFIG_SET_OTHER_SRC when using NI general-purpose counters. */ +/* + * Possibilities for setting a source with + * INSN_CONFIG_SET_OTHER_SRC when using NI general-purpose counters. + */ enum ni_gpct_other_index { NI_GPCT_SOURCE_ENCODER_A, NI_GPCT_SOURCE_ENCODER_B, @@ -702,18 +713,24 @@ enum ni_gpct_other_select { #define NI_GPCT_PFI_OTHER_SELECT(x) NI_USUAL_PFI_SELECT(x) -/* start sources for ni general-purpose counters for use with -INSN_CONFIG_ARM */ +/* + * start sources for ni general-purpose counters for use with + * INSN_CONFIG_ARM + */ enum ni_gpct_arm_source { NI_GPCT_ARM_IMMEDIATE = 0x0, - NI_GPCT_ARM_PAIRED_IMMEDIATE = 0x1, /* Start both the counter - * and the adjacent paired - * counter simultaneously */ - /* NI doesn't document bits for selecting hardware arm triggers. + /* + * Start both the counter and the adjacent pared + * counter simultaneously + */ + NI_GPCT_ARM_PAIRED_IMMEDIATE = 0x1, + /* + * NI doesn't document bits for selecting hardware arm triggers. * If the NI_GPCT_ARM_UNKNOWN bit is set, we will pass the least * significant bits (3 bits for 660x or 5 bits for m-series) * through to the hardware. This will at least allow someone to - * figure out what the bits do later. */ + * figure out what the bits do later. + */ NI_GPCT_ARM_UNKNOWN = 0x1000, }; @@ -728,8 +745,10 @@ enum ni_gpct_filter_select { NI_GPCT_FILTER_2x_TIMEBASE_3 = 0x6 }; -/* PFI digital filtering options for ni m-series for use with - * INSN_CONFIG_FILTER. */ +/* + * PFI digital filtering options for ni m-series for use with + * INSN_CONFIG_FILTER. + */ enum ni_pfi_filter_select { NI_PFI_FILTER_OFF = 0x0, NI_PFI_FILTER_125ns = 0x1, @@ -740,9 +759,11 @@ enum ni_pfi_filter_select { /* master clock sources for ni mio boards and INSN_CONFIG_SET_CLOCK_SRC */ enum ni_mio_clock_source { NI_MIO_INTERNAL_CLOCK = 0, - NI_MIO_RTSI_CLOCK = 1, /* doesn't work for m-series, use - NI_MIO_PLL_RTSI_CLOCK() */ - /* the NI_MIO_PLL_* sources are m-series only */ + /* + * Doesn't work for m-series, use NI_MIO_PLL_RTSI_CLOCK() + * the NI_MIO_PLL_* sources are m-series only + */ + NI_MIO_RTSI_CLOCK = 1, NI_MIO_PLL_PXI_STAR_TRIGGER_CLOCK = 2, NI_MIO_PLL_PXI10_CLOCK = 3, NI_MIO_PLL_RTSI0_CLOCK = 4 @@ -750,9 +771,11 @@ enum ni_mio_clock_source { #define NI_MIO_PLL_RTSI_CLOCK(x) (NI_MIO_PLL_RTSI0_CLOCK + (x)) -/* Signals which can be routed to an NI RTSI pin with INSN_CONFIG_SET_ROUTING. - The numbers assigned are not arbitrary, they correspond to the bits required - to program the board. */ +/* + * Signals which can be routed to an NI RTSI pin with INSN_CONFIG_SET_ROUTING. + * The numbers assigned are not arbitrary, they correspond to the bits required + * to program the board. + */ enum ni_rtsi_routing { NI_RTSI_OUTPUT_ADR_START1 = 0, NI_RTSI_OUTPUT_ADR_START2 = 1, @@ -763,17 +786,19 @@ enum ni_rtsi_routing { NI_RTSI_OUTPUT_G_GATE0 = 6, NI_RTSI_OUTPUT_RGOUT0 = 7, NI_RTSI_OUTPUT_RTSI_BRD_0 = 8, - NI_RTSI_OUTPUT_RTSI_OSC = 12 /* pre-m-series always have RTSI - * clock on line 7 */ + /* Pre-m-series always have RTSI clock on line 7 */ + NI_RTSI_OUTPUT_RTSI_OSC = 12 }; #define NI_RTSI_OUTPUT_RTSI_BRD(x) (NI_RTSI_OUTPUT_RTSI_BRD_0 + (x)) -/* Signals which can be routed to an NI PFI pin on an m-series board with +/* + * Signals which can be routed to an NI PFI pin on an m-series board with * INSN_CONFIG_SET_ROUTING. These numbers are also returned by * INSN_CONFIG_GET_ROUTING on pre-m-series boards, even though their routing * cannot be changed. The numbers assigned are not arbitrary, they correspond - * to the bits required to program the board. */ + * to the bits required to program the board. + */ enum ni_pfi_routing { NI_PFI_OUTPUT_PFI_DEFAULT = 0, NI_PFI_OUTPUT_AI_START1 = 1, @@ -803,20 +828,24 @@ enum ni_pfi_routing { #define NI_PFI_OUTPUT_RTSI(x) (NI_PFI_OUTPUT_RTSI0 + (x)) -/* Signals which can be routed to output on a NI PFI pin on a 660x board - with INSN_CONFIG_SET_ROUTING. The numbers assigned are - not arbitrary, they correspond to the bits required - to program the board. Lines 0 to 7 can only be set to - NI_660X_PFI_OUTPUT_DIO. Lines 32 to 39 can only be set to - NI_660X_PFI_OUTPUT_COUNTER. */ +/* + * Signals which can be routed to output on a NI PFI pin on a 660x board + * with INSN_CONFIG_SET_ROUTING. The numbers assigned are + * not arbitrary, they correspond to the bits required + * to program the board. Lines 0 to 7 can only be set to + * NI_660X_PFI_OUTPUT_DIO. Lines 32 to 39 can only be set to + * NI_660X_PFI_OUTPUT_COUNTER. + */ enum ni_660x_pfi_routing { NI_660X_PFI_OUTPUT_COUNTER = 1, /* counter */ NI_660X_PFI_OUTPUT_DIO = 2, /* static digital output */ }; -/* NI External Trigger lines. These values are not arbitrary, but are related +/* + * NI External Trigger lines. These values are not arbitrary, but are related * to the bits required to program the board (offset by 1 for historical - * reasons). */ + * reasons). + */ #define NI_EXT_PFI(x) (NI_USUAL_PFI_SELECT(x) - 1) #define NI_EXT_RTSI(x) (NI_USUAL_RTSI_SELECT(x) - 1) @@ -827,9 +856,11 @@ enum comedi_counter_status_flags { COMEDI_COUNTER_TERMINAL_COUNT = 0x4, }; -/* Clock sources for CDIO subdevice on NI m-series boards. Used as the +/* + * Clock sources for CDIO subdevice on NI m-series boards. Used as the * scan_begin_arg for a comedi_command. These sources may also be bitwise-or'd - * with CR_INVERT to change polarity. */ + * with CR_INVERT to change polarity. + */ enum ni_m_series_cdio_scan_begin_src { NI_CDIO_SCAN_BEGIN_SRC_GROUND = 0, NI_CDIO_SCAN_BEGIN_SRC_AI_START = 18, @@ -846,38 +877,50 @@ enum ni_m_series_cdio_scan_begin_src { #define NI_CDIO_SCAN_BEGIN_SRC_PFI(x) NI_USUAL_PFI_SELECT(x) #define NI_CDIO_SCAN_BEGIN_SRC_RTSI(x) NI_USUAL_RTSI_SELECT(x) -/* scan_begin_src for scan_begin_arg==TRIG_EXT with analog output command on NI +/* + * scan_begin_src for scan_begin_arg==TRIG_EXT with analog output command on NI * boards. These scan begin sources can also be bitwise-or'd with CR_INVERT to - * change polarity. */ + * change polarity. + */ #define NI_AO_SCAN_BEGIN_SRC_PFI(x) NI_USUAL_PFI_SELECT(x) #define NI_AO_SCAN_BEGIN_SRC_RTSI(x) NI_USUAL_RTSI_SELECT(x) -/* Bits for setting a clock source with - * INSN_CONFIG_SET_CLOCK_SRC when using NI frequency output subdevice. */ +/* + * Bits for setting a clock source with + * INSN_CONFIG_SET_CLOCK_SRC when using NI frequency output subdevice. + */ enum ni_freq_out_clock_source_bits { NI_FREQ_OUT_TIMEBASE_1_DIV_2_CLOCK_SRC, /* 10 MHz */ NI_FREQ_OUT_TIMEBASE_2_CLOCK_SRC /* 100 KHz */ }; -/* Values for setting a clock source with INSN_CONFIG_SET_CLOCK_SRC for - * 8254 counter subdevices on Amplicon DIO boards (amplc_dio200 driver). */ +/* + * Values for setting a clock source with INSN_CONFIG_SET_CLOCK_SRC for + * 8254 counter subdevices on Amplicon DIO boards (amplc_dio200 driver). + */ enum amplc_dio_clock_source { - AMPLC_DIO_CLK_CLKN, /* per channel external clock - input/output pin (pin is only an - input when clock source set to this - value, otherwise it is an output) */ + /* + * Per channel external clock + * input/output pin (pin is only an + * input when clock source set to this value, + * otherwise it is an output) + */ + AMPLC_DIO_CLK_CLKN, AMPLC_DIO_CLK_10MHZ, /* 10 MHz internal clock */ AMPLC_DIO_CLK_1MHZ, /* 1 MHz internal clock */ AMPLC_DIO_CLK_100KHZ, /* 100 kHz internal clock */ AMPLC_DIO_CLK_10KHZ, /* 10 kHz internal clock */ AMPLC_DIO_CLK_1KHZ, /* 1 kHz internal clock */ - AMPLC_DIO_CLK_OUTNM1, /* output of preceding counter channel - (for channel 0, preceding counter - channel is channel 2 on preceding - counter subdevice, for first counter - subdevice, preceding counter - subdevice is the last counter - subdevice) */ + /* + * Output of preceding counter channel + * (for channel 0, preceding counter + * channel is channel 2 on preceding + * counter subdevice, for first counter + * subdevice, preceding counter + * subdevice is the last counter + * subdevice) + */ + AMPLC_DIO_CLK_OUTNM1, AMPLC_DIO_CLK_EXT, /* per chip external input pin */ /* the following are "enhanced" clock sources for PCIe models */ AMPLC_DIO_CLK_VCC, /* clock input HIGH */ @@ -886,35 +929,39 @@ enum amplc_dio_clock_source { AMPLC_DIO_CLK_20MHZ /* 20 MHz internal clock */ }; -/* Values for setting a clock source with INSN_CONFIG_SET_CLOCK_SRC for - * timer subdevice on some Amplicon DIO PCIe boards (amplc_dio200 driver). */ +/* + * Values for setting a clock source with INSN_CONFIG_SET_CLOCK_SRC for + * timer subdevice on some Amplicon DIO PCIe boards (amplc_dio200 driver). + */ enum amplc_dio_ts_clock_src { AMPLC_DIO_TS_CLK_1GHZ, /* 1 ns period with 20 ns granularity */ AMPLC_DIO_TS_CLK_1MHZ, /* 1 us period */ AMPLC_DIO_TS_CLK_1KHZ /* 1 ms period */ }; -/* Values for setting a gate source with INSN_CONFIG_SET_GATE_SRC for - * 8254 counter subdevices on Amplicon DIO boards (amplc_dio200 driver). */ +/* + * Values for setting a gate source with INSN_CONFIG_SET_GATE_SRC for + * 8254 counter subdevices on Amplicon DIO boards (amplc_dio200 driver). + */ enum amplc_dio_gate_source { AMPLC_DIO_GAT_VCC, /* internal high logic level */ AMPLC_DIO_GAT_GND, /* internal low logic level */ AMPLC_DIO_GAT_GATN, /* per channel external gate input */ - AMPLC_DIO_GAT_NOUTNM2, /* negated output of counter channel - minus 2 (for channels 0 or 1, - channel minus 2 is channel 1 or 2 on - the preceding counter subdevice, for - the first counter subdevice the - preceding counter subdevice is the - last counter subdevice) */ + /* + * negated output of counter channel minus 2 + * (for channels 0 or 1, channel minus 2 is channel 1 or 2 on + * the preceding counter subdevice, for the first counter subdevice + * the preceding counter subdevice is the last counter subdevice) + */ + AMPLC_DIO_GAT_NOUTNM2, AMPLC_DIO_GAT_RESERVED4, AMPLC_DIO_GAT_RESERVED5, AMPLC_DIO_GAT_RESERVED6, AMPLC_DIO_GAT_RESERVED7, /* the following are "enhanced" gate sources for PCIe models */ AMPLC_DIO_GAT_NGATN = 6, /* negated per channel gate input */ - AMPLC_DIO_GAT_OUTNM2, /* non-negated output of counter - channel minus 2 */ + /* non-negated output of counter channel minus 2 */ + AMPLC_DIO_GAT_OUTNM2, AMPLC_DIO_GAT_PAT_PRESENT, /* "pattern present" signal */ AMPLC_DIO_GAT_PAT_OCCURRED, /* "pattern occurred" latched */ AMPLC_DIO_GAT_PAT_GONE, /* "pattern gone away" latched */ diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 7b4af519e17e..d57fadef47fc 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -2303,11 +2303,13 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, { struct comedi_subdevice *s; struct comedi_async *async; - int n, m, count = 0, retval = 0; + unsigned int n, m; + ssize_t count = 0; + int retval = 0; DECLARE_WAITQUEUE(wait, current); struct comedi_file *cfp = file->private_data; struct comedi_device *dev = cfp->dev; - bool on_wait_queue = false; + bool become_nonbusy = false; bool attach_locked; unsigned int old_detach_count; @@ -2329,74 +2331,33 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, } async = s->async; - - if (!s->busy || !nbytes) - goto out; - if (s->busy != file) { - retval = -EACCES; - goto out; - } - if (!(async->cmd.flags & CMDF_WRITE)) { + if (s->busy != file || !(async->cmd.flags & CMDF_WRITE)) { retval = -EINVAL; goto out; } add_wait_queue(&async->wait_head, &wait); - on_wait_queue = true; - while (nbytes > 0 && !retval) { + while (count == 0 && !retval) { unsigned runflags; + unsigned int wp, n1, n2; set_current_state(TASK_INTERRUPTIBLE); runflags = comedi_get_subdevice_runflags(s); if (!comedi_is_runflags_running(runflags)) { - if (count == 0) { - struct comedi_subdevice *new_s; - - if (comedi_is_runflags_in_error(runflags)) - retval = -EPIPE; - else - retval = 0; - /* - * To avoid deadlock, cannot acquire dev->mutex - * while dev->attach_lock is held. Need to - * remove task from the async wait queue before - * releasing dev->attach_lock, as it might not - * be valid afterwards. - */ - remove_wait_queue(&async->wait_head, &wait); - on_wait_queue = false; - up_read(&dev->attach_lock); - attach_locked = false; - mutex_lock(&dev->mutex); - /* - * Become non-busy unless things have changed - * behind our back. Checking dev->detach_count - * is unchanged ought to be sufficient (unless - * there have been 2**32 detaches in the - * meantime!), but check the subdevice pointer - * as well just in case. - */ - new_s = comedi_file_write_subdevice(file); - if (dev->attached && - old_detach_count == dev->detach_count && - s == new_s && new_s->async == async) - do_become_nonbusy(dev, s); - mutex_unlock(&dev->mutex); - } + if (comedi_is_runflags_in_error(runflags)) + retval = -EPIPE; + if (retval || nbytes) + become_nonbusy = true; break; } + if (nbytes == 0) + break; - n = nbytes; - - m = n; - if (async->buf_write_ptr + m > async->prealloc_bufsz) - m = async->prealloc_bufsz - async->buf_write_ptr; + /* Allocate all free buffer space. */ comedi_buf_write_alloc(s, async->prealloc_bufsz); - if (m > comedi_buf_write_n_allocated(s)) - m = comedi_buf_write_n_allocated(s); - if (m < n) - n = m; + m = comedi_buf_write_n_allocated(s); + n = min_t(size_t, m, nbytes); if (n == 0) { if (file->f_flags & O_NONBLOCK) { @@ -2408,21 +2369,22 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, retval = -ERESTARTSYS; break; } - if (!s->busy) - break; - if (s->busy != file) { - retval = -EACCES; - break; - } - if (!(async->cmd.flags & CMDF_WRITE)) { + if (s->busy != file || + !(async->cmd.flags & CMDF_WRITE)) { retval = -EINVAL; break; } continue; } - m = copy_from_user(async->prealloc_buf + async->buf_write_ptr, - buf, n); + wp = async->buf_write_ptr; + n1 = min(n, async->prealloc_bufsz - wp); + n2 = n - n1; + m = copy_from_user(async->prealloc_buf + wp, buf, n1); + if (m) + m += n2; + else if (n2) + m = copy_from_user(async->prealloc_buf, buf + n1, n2); if (m) { n -= m; retval = -EFAULT; @@ -2433,12 +2395,38 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, nbytes -= n; buf += n; - break; /* makes device work like a pipe */ } -out: - if (on_wait_queue) - remove_wait_queue(&async->wait_head, &wait); + remove_wait_queue(&async->wait_head, &wait); set_current_state(TASK_RUNNING); + if (become_nonbusy && count == 0) { + struct comedi_subdevice *new_s; + + /* + * To avoid deadlock, cannot acquire dev->mutex + * while dev->attach_lock is held. + */ + up_read(&dev->attach_lock); + attach_locked = false; + mutex_lock(&dev->mutex); + /* + * Check device hasn't become detached behind our back. + * Checking dev->detach_count is unchanged ought to be + * sufficient (unless there have been 2**32 detaches in the + * meantime!), but check the subdevice pointer as well just in + * case. + * + * Also check the subdevice is still in a suitable state to + * become non-busy in case it changed behind our back. + */ + new_s = comedi_file_write_subdevice(file); + if (dev->attached && old_detach_count == dev->detach_count && + s == new_s && new_s->async == async && s->busy == file && + (async->cmd.flags & CMDF_WRITE) && + !comedi_is_subdevice_running(s)) + do_become_nonbusy(dev, s); + mutex_unlock(&dev->mutex); + } +out: if (attach_locked) up_read(&dev->attach_lock); diff --git a/drivers/staging/comedi/comedilib.h b/drivers/staging/comedi/comedilib.h index 56baf852ecf5..f9b56396e161 100644 --- a/drivers/staging/comedi/comedilib.h +++ b/drivers/staging/comedi/comedilib.h @@ -1,20 +1,20 @@ /* - linux/include/comedilib.h - header file for kcomedilib - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 1998-2001 David A. Schleef <ds@schleef.org> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. -*/ + * comedilib.h + * Header file for kcomedilib + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1998-2001 David A. Schleef <ds@schleef.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ #ifndef _LINUX_COMEDILIB_H #define _LINUX_COMEDILIB_H diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile index c3b8f2d7611b..0c8cfa738727 100644 --- a/drivers/staging/comedi/drivers/Makefile +++ b/drivers/staging/comedi/drivers/Makefile @@ -78,8 +78,10 @@ obj-$(CONFIG_COMEDI_ADL_PCI8164) += adl_pci8164.o obj-$(CONFIG_COMEDI_ADL_PCI9111) += adl_pci9111.o obj-$(CONFIG_COMEDI_ADL_PCI9118) += adl_pci9118.o obj-$(CONFIG_COMEDI_ADV_PCI1710) += adv_pci1710.o +obj-$(CONFIG_COMEDI_ADV_PCI1720) += adv_pci1720.o obj-$(CONFIG_COMEDI_ADV_PCI1723) += adv_pci1723.o obj-$(CONFIG_COMEDI_ADV_PCI1724) += adv_pci1724.o +obj-$(CONFIG_COMEDI_ADV_PCI1760) += adv_pci1760.o obj-$(CONFIG_COMEDI_ADV_PCI_DIO) += adv_pci_dio.o obj-$(CONFIG_COMEDI_AMPLC_DIO200_PCI) += amplc_dio200_pci.o obj-$(CONFIG_COMEDI_AMPLC_PC236_PCI) += amplc_pci236.o diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c index 0dff1dbb53fb..4437ea3abe8d 100644 --- a/drivers/staging/comedi/drivers/adl_pci9118.c +++ b/drivers/staging/comedi/drivers/adl_pci9118.c @@ -603,10 +603,11 @@ static void pci9118_ai_munge(struct comedi_device *dev, unsigned short *array = data; unsigned int num_samples = comedi_bytes_to_samples(s, num_bytes); unsigned int i; + __be16 *barray = data; for (i = 0; i < num_samples; i++) { if (devpriv->usedma) - array[i] = be16_to_cpu(array[i]); + array[i] = be16_to_cpu(barray[i]); if (s->maxdata == 0xffff) array[i] ^= 0x8000; else diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c index 399c511cfe0a..2c1b6de30da8 100644 --- a/drivers/staging/comedi/drivers/adv_pci1710.c +++ b/drivers/staging/comedi/drivers/adv_pci1710.c @@ -11,8 +11,9 @@ * Driver: adv_pci1710 * Description: Comedi driver for Advantech PCI-1710 series boards * Devices: [Advantech] PCI-1710 (adv_pci1710), PCI-1710HG, PCI-1711, - * PCI-1713, PCI-1720, PCI-1731 + * PCI-1713, PCI-1731 * Author: Michal Dobes <dobes@tesnet.cz> + * Updated: Fri, 29 Oct 2015 17:19:35 -0700 * Status: works * * Configuration options: not applicable, uses PCI auto config @@ -40,7 +41,13 @@ #define PCI171X_AD_DATA_REG 0x00 /* R: A/D data */ #define PCI171X_SOFTTRG_REG 0x00 /* W: soft trigger for A/D */ #define PCI171X_RANGE_REG 0x02 /* W: A/D gain/range register */ +#define PCI171X_RANGE_DIFF BIT(5) +#define PCI171X_RANGE_UNI BIT(4) +#define PCI171X_RANGE_GAIN(x) (((x) & 0x7) << 0) #define PCI171X_MUX_REG 0x04 /* W: A/D multiplexor control */ +#define PCI171X_MUX_CHANH(x) (((x) & 0xf) << 8) +#define PCI171X_MUX_CHANL(x) (((x) & 0xf) << 0) +#define PCI171X_MUX_CHAN(x) (PCI171X_MUX_CHANH(x) | PCI171X_MUX_CHANL(x)) #define PCI171X_STATUS_REG 0x06 /* R: status register */ #define PCI171X_STATUS_IRQ BIT(11) /* 1=IRQ occurred */ #define PCI171X_STATUS_FF BIT(10) /* 1=FIFO is full, fatal error */ @@ -58,83 +65,58 @@ #define PCI171X_CLRFIFO_REG 0x09 /* W: clear FIFO */ #define PCI171X_DA_REG(x) (0x0a + ((x) * 2)) /* W: D/A register */ #define PCI171X_DAREF_REG 0x0e /* W: D/A reference control */ +#define PCI171X_DAREF(c, r) (((r) & 0x3) << ((c) * 2)) +#define PCI171X_DAREF_MASK(c) PCI171X_DAREF((c), 0x3) #define PCI171X_DI_REG 0x10 /* R: digital inputs */ #define PCI171X_DO_REG 0x10 /* W: digital outputs */ #define PCI171X_TIMER_BASE 0x18 /* R/W: 8254 timer */ -/* - * PCI-1720 only has analog outputs and has a different - * register map (dev->iobase) - */ -#define PCI1720_DA_REG(x) (0x00 + ((x) * 2)) /* W: D/A registers */ -#define PCI1720_RANGE_REG 0x08 /* R/W: D/A range register */ -#define PCI1720_SYNC_REG 0x09 /* W: D/A synchronized output */ -#define PCI1720_SYNC_CTRL_REG 0x0f /* R/W: D/A synchronized control */ -#define PCI1720_SYNC_CTRL_SC0 BIT(0) /* set synchronous output mode */ - -static const struct comedi_lrange range_pci1710_3 = { +static const struct comedi_lrange pci1710_ai_range = { 9, { - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625), - BIP_RANGE(10), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25) + BIP_RANGE(5), /* gain 1 (0x00) */ + BIP_RANGE(2.5), /* gain 2 (0x01) */ + BIP_RANGE(1.25), /* gain 4 (0x02) */ + BIP_RANGE(0.625), /* gain 8 (0x03) */ + BIP_RANGE(10), /* gain 0.5 (0x04) */ + UNI_RANGE(10), /* gain 1 (0x00 | UNI) */ + UNI_RANGE(5), /* gain 2 (0x01 | UNI) */ + UNI_RANGE(2.5), /* gain 4 (0x02 | UNI) */ + UNI_RANGE(1.25) /* gain 8 (0x03 | UNI) */ } }; -static const char range_codes_pci1710_3[] = { 0x00, 0x01, 0x02, 0x03, 0x04, - 0x10, 0x11, 0x12, 0x13 }; - -static const struct comedi_lrange range_pci1710hg = { +static const struct comedi_lrange pci1710hg_ai_range = { 12, { - BIP_RANGE(5), - BIP_RANGE(0.5), - BIP_RANGE(0.05), - BIP_RANGE(0.005), - BIP_RANGE(10), - BIP_RANGE(1), - BIP_RANGE(0.1), - BIP_RANGE(0.01), - UNI_RANGE(10), - UNI_RANGE(1), - UNI_RANGE(0.1), - UNI_RANGE(0.01) + BIP_RANGE(5), /* gain 1 (0x00) */ + BIP_RANGE(0.5), /* gain 10 (0x01) */ + BIP_RANGE(0.05), /* gain 100 (0x02) */ + BIP_RANGE(0.005), /* gain 1000 (0x03) */ + BIP_RANGE(10), /* gain 0.5 (0x04) */ + BIP_RANGE(1), /* gain 5 (0x05) */ + BIP_RANGE(0.1), /* gain 50 (0x06) */ + BIP_RANGE(0.01), /* gain 500 (0x07) */ + UNI_RANGE(10), /* gain 1 (0x00 | UNI) */ + UNI_RANGE(1), /* gain 10 (0x01 | UNI) */ + UNI_RANGE(0.1), /* gain 100 (0x02 | UNI) */ + UNI_RANGE(0.01) /* gain 1000 (0x03 | UNI) */ } }; -static const char range_codes_pci1710hg[] = { 0x00, 0x01, 0x02, 0x03, 0x04, - 0x05, 0x06, 0x07, 0x10, 0x11, - 0x12, 0x13 }; - -static const struct comedi_lrange range_pci17x1 = { +static const struct comedi_lrange pci1711_ai_range = { 5, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625) - } -}; - -static const char range_codes_pci17x1[] = { 0x00, 0x01, 0x02, 0x03, 0x04 }; - -static const struct comedi_lrange pci1720_ao_range = { - 4, { - UNI_RANGE(5), - UNI_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(10) + BIP_RANGE(10), /* gain 1 (0x00) */ + BIP_RANGE(5), /* gain 2 (0x01) */ + BIP_RANGE(2.5), /* gain 4 (0x02) */ + BIP_RANGE(1.25), /* gain 8 (0x03) */ + BIP_RANGE(0.625) /* gain 16 (0x04) */ } }; static const struct comedi_lrange pci171x_ao_range = { - 2, { - UNI_RANGE(5), - UNI_RANGE(10) + 3, { + UNI_RANGE(5), /* internal -5V ref */ + UNI_RANGE(10), /* internal -10V ref */ + RANGE_ext(0, 1) /* external -Vref (+/-10V max) */ } }; @@ -143,82 +125,43 @@ enum pci1710_boardid { BOARD_PCI1710HG, BOARD_PCI1711, BOARD_PCI1713, - BOARD_PCI1720, BOARD_PCI1731, }; struct boardtype { - const char *name; /* board name */ - int n_aichan; /* num of A/D chans */ - const struct comedi_lrange *rangelist_ai; /* rangelist for A/D */ - const char *rangecode_ai; /* range codes for programming */ + const char *name; + const struct comedi_lrange *ai_range; + unsigned int is_pci1711:1; unsigned int is_pci1713:1; - unsigned int is_pci1720:1; - unsigned int has_irq:1; - unsigned int has_large_fifo:1; /* 4K or 1K FIFO */ - unsigned int has_diff_ai:1; unsigned int has_ao:1; - unsigned int has_di_do:1; - unsigned int has_counter:1; }; static const struct boardtype boardtypes[] = { [BOARD_PCI1710] = { .name = "pci1710", - .n_aichan = 16, - .rangelist_ai = &range_pci1710_3, - .rangecode_ai = range_codes_pci1710_3, - .has_irq = 1, - .has_large_fifo = 1, - .has_diff_ai = 1, + .ai_range = &pci1710_ai_range, .has_ao = 1, - .has_di_do = 1, - .has_counter = 1, }, [BOARD_PCI1710HG] = { .name = "pci1710hg", - .n_aichan = 16, - .rangelist_ai = &range_pci1710hg, - .rangecode_ai = range_codes_pci1710hg, - .has_irq = 1, - .has_large_fifo = 1, - .has_diff_ai = 1, + .ai_range = &pci1710hg_ai_range, .has_ao = 1, - .has_di_do = 1, - .has_counter = 1, }, [BOARD_PCI1711] = { .name = "pci1711", - .n_aichan = 16, - .rangelist_ai = &range_pci17x1, - .rangecode_ai = range_codes_pci17x1, - .has_irq = 1, + .ai_range = &pci1711_ai_range, + .is_pci1711 = 1, .has_ao = 1, - .has_di_do = 1, - .has_counter = 1, }, [BOARD_PCI1713] = { .name = "pci1713", - .n_aichan = 32, - .rangelist_ai = &range_pci1710_3, - .rangecode_ai = range_codes_pci1710_3, + .ai_range = &pci1710_ai_range, .is_pci1713 = 1, - .has_irq = 1, - .has_large_fifo = 1, - .has_diff_ai = 1, - }, - [BOARD_PCI1720] = { - .name = "pci1720", - .is_pci1720 = 1, - .has_ao = 1, }, [BOARD_PCI1731] = { .name = "pci1731", - .n_aichan = 16, - .rangelist_ai = &range_pci17x1, - .rangecode_ai = range_codes_pci17x1, - .has_irq = 1, - .has_di_do = 1, + .ai_range = &pci1711_ai_range, + .is_pci1711 = 1, }, }; @@ -226,14 +169,15 @@ struct pci1710_private { unsigned int max_samples; unsigned int ctrl; /* control register value */ unsigned int ctrl_ext; /* used to switch from TRIG_EXT to TRIG_xxx */ - unsigned int mux_ext; /* used to set the channel interval to scan */ + unsigned int mux_scan; /* used to set the channel interval to scan */ unsigned char ai_et; unsigned int act_chanlist[32]; /* list of scanned channel */ unsigned char saved_seglen; /* len of the non-repeating chanlist */ unsigned char da_ranges; /* copy of D/A outpit range register */ + unsigned char unipolar_gain; /* adjust for unipolar gain codes */ }; -static int pci171x_ai_check_chanlist(struct comedi_device *dev, +static int pci1710_ai_check_chanlist(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) { @@ -299,13 +243,12 @@ static int pci171x_ai_check_chanlist(struct comedi_device *dev, return 0; } -static void pci171x_ai_setup_chanlist(struct comedi_device *dev, +static void pci1710_ai_setup_chanlist(struct comedi_device *dev, struct comedi_subdevice *s, unsigned int *chanlist, unsigned int n_chan, unsigned int seglen) { - const struct boardtype *board = dev->board_ptr; struct pci1710_private *devpriv = dev->private; unsigned int first_chan = CR_CHAN(chanlist[0]); unsigned int last_chan = CR_CHAN(chanlist[seglen - 1]); @@ -315,14 +258,18 @@ static void pci171x_ai_setup_chanlist(struct comedi_device *dev, unsigned int chan = CR_CHAN(chanlist[i]); unsigned int range = CR_RANGE(chanlist[i]); unsigned int aref = CR_AREF(chanlist[i]); - unsigned int rangeval; + unsigned int rangeval = 0; - rangeval = board->rangecode_ai[range]; if (aref == AREF_DIFF) - rangeval |= 0x0020; + rangeval |= PCI171X_RANGE_DIFF; + if (comedi_range_is_unipolar(s, range)) { + rangeval |= PCI171X_RANGE_UNI; + range -= devpriv->unipolar_gain; + } + rangeval |= PCI171X_RANGE_GAIN(range); /* select channel and set range */ - outw(chan | (chan << 8), dev->iobase + PCI171X_MUX_REG); + outw(PCI171X_MUX_CHAN(chan), dev->iobase + PCI171X_MUX_REG); outw(rangeval, dev->iobase + PCI171X_RANGE_REG); devpriv->act_chanlist[i] = chan; @@ -331,11 +278,12 @@ static void pci171x_ai_setup_chanlist(struct comedi_device *dev, devpriv->act_chanlist[i] = CR_CHAN(chanlist[i]); /* select channel interval to scan */ - devpriv->mux_ext = first_chan | (last_chan << 8); - outw(devpriv->mux_ext, dev->iobase + PCI171X_MUX_REG); + devpriv->mux_scan = PCI171X_MUX_CHANL(first_chan) | + PCI171X_MUX_CHANH(last_chan); + outw(devpriv->mux_scan, dev->iobase + PCI171X_MUX_REG); } -static int pci171x_ai_eoc(struct comedi_device *dev, +static int pci1710_ai_eoc(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned long context) @@ -348,7 +296,7 @@ static int pci171x_ai_eoc(struct comedi_device *dev, return -EBUSY; } -static int pci171x_ai_read_sample(struct comedi_device *dev, +static int pci1710_ai_read_sample(struct comedi_device *dev, struct comedi_subdevice *s, unsigned int cur_chan, unsigned int *val) @@ -377,7 +325,7 @@ static int pci171x_ai_read_sample(struct comedi_device *dev, return 0; } -static int pci171x_ai_insn_read(struct comedi_device *dev, +static int pci1710_ai_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) @@ -386,13 +334,14 @@ static int pci171x_ai_insn_read(struct comedi_device *dev, int ret = 0; int i; - devpriv->ctrl &= PCI171X_CTRL_CNT0; - devpriv->ctrl |= PCI171X_CTRL_SW; /* set software trigger */ + /* enable software trigger */ + devpriv->ctrl |= PCI171X_CTRL_SW; outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); + outb(0, dev->iobase + PCI171X_CLRFIFO_REG); outb(0, dev->iobase + PCI171X_CLRINT_REG); - pci171x_ai_setup_chanlist(dev, s, &insn->chanspec, 1, 1); + pci1710_ai_setup_chanlist(dev, s, &insn->chanspec, 1, 1); for (i = 0; i < insn->n; i++) { unsigned int val; @@ -400,111 +349,40 @@ static int pci171x_ai_insn_read(struct comedi_device *dev, /* start conversion */ outw(0, dev->iobase + PCI171X_SOFTTRG_REG); - ret = comedi_timeout(dev, s, insn, pci171x_ai_eoc, 0); + ret = comedi_timeout(dev, s, insn, pci1710_ai_eoc, 0); if (ret) break; - ret = pci171x_ai_read_sample(dev, s, 0, &val); + ret = pci1710_ai_read_sample(dev, s, 0, &val); if (ret) break; data[i] = val; } + /* disable software trigger */ + devpriv->ctrl &= ~PCI171X_CTRL_SW; + outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); + outb(0, dev->iobase + PCI171X_CLRFIFO_REG); outb(0, dev->iobase + PCI171X_CLRINT_REG); return ret ? ret : insn->n; } -static int pci171x_ao_insn_write(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct pci1710_private *devpriv = dev->private; - unsigned int chan = CR_CHAN(insn->chanspec); - unsigned int range = CR_RANGE(insn->chanspec); - unsigned int val = s->readback[chan]; - int i; - - devpriv->da_ranges &= ~(1 << (chan << 1)); - devpriv->da_ranges |= (range << (chan << 1)); - outw(devpriv->da_ranges, dev->iobase + PCI171X_DAREF_REG); - - for (i = 0; i < insn->n; i++) { - val = data[i]; - outw(val, dev->iobase + PCI171X_DA_REG(chan)); - } - - s->readback[chan] = val; - - return insn->n; -} - -static int pci171x_di_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - data[1] = inw(dev->iobase + PCI171X_DI_REG); - - return insn->n; -} - -static int pci171x_do_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - if (comedi_dio_update_state(s, data)) - outw(s->state, dev->iobase + PCI171X_DO_REG); - - data[1] = s->state; - - return insn->n; -} - -static int pci1720_ao_insn_write(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct pci1710_private *devpriv = dev->private; - unsigned int chan = CR_CHAN(insn->chanspec); - unsigned int range = CR_RANGE(insn->chanspec); - unsigned int val; - int i; - - val = devpriv->da_ranges & (~(0x03 << (chan << 1))); - val |= (range << (chan << 1)); - if (val != devpriv->da_ranges) { - outb(val, dev->iobase + PCI1720_RANGE_REG); - devpriv->da_ranges = val; - } - - val = s->readback[chan]; - for (i = 0; i < insn->n; i++) { - val = data[i]; - outw(val, dev->iobase + PCI1720_DA_REG(chan)); - outb(0, dev->iobase + PCI1720_SYNC_REG); /* update outputs */ - } - - s->readback[chan] = val; - - return insn->n; -} - -static int pci171x_ai_cancel(struct comedi_device *dev, +static int pci1710_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { struct pci1710_private *devpriv = dev->private; - devpriv->ctrl &= PCI171X_CTRL_CNT0; - devpriv->ctrl |= PCI171X_CTRL_SW; - /* reset any operations */ + /* disable A/D triggers and interrupt sources */ + devpriv->ctrl &= PCI171X_CTRL_CNT0; /* preserve counter 0 clk src */ outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); + + /* disable pacer */ comedi_8254_pacer_enable(dev->pacer, 1, 2, false); + + /* clear A/D FIFO and any pending interrutps */ outb(0, dev->iobase + PCI171X_CLRFIFO_REG); outb(0, dev->iobase + PCI171X_CLRINT_REG); @@ -535,7 +413,7 @@ static void pci1710_handle_every_sample(struct comedi_device *dev, outb(0, dev->iobase + PCI171X_CLRINT_REG); for (; !(inw(dev->iobase + PCI171X_STATUS_REG) & PCI171X_STATUS_FE);) { - ret = pci171x_ai_read_sample(dev, s, s->async->cur_chan, &val); + ret = pci1710_ai_read_sample(dev, s, s->async->cur_chan, &val); if (ret) { s->async->events |= COMEDI_CB_ERROR; break; @@ -579,7 +457,7 @@ static void pci1710_handle_fifo(struct comedi_device *dev, unsigned int val; int ret; - ret = pci171x_ai_read_sample(dev, s, s->async->cur_chan, &val); + ret = pci1710_ai_read_sample(dev, s, s->async->cur_chan, &val); if (ret) { s->async->events |= COMEDI_CB_ERROR; break; @@ -598,7 +476,7 @@ static void pci1710_handle_fifo(struct comedi_device *dev, outb(0, dev->iobase + PCI171X_CLRINT_REG); } -static irqreturn_t interrupt_service_pci1710(int irq, void *d) +static irqreturn_t pci1710_irq_handler(int irq, void *d) { struct comedi_device *dev = d; struct pci1710_private *devpriv = dev->private; @@ -624,7 +502,7 @@ static irqreturn_t interrupt_service_pci1710(int irq, void *d) outb(0, dev->iobase + PCI171X_CLRFIFO_REG); outb(0, dev->iobase + PCI171X_CLRINT_REG); /* no sample on this interrupt; reset the channel interval */ - outw(devpriv->mux_ext, dev->iobase + PCI171X_MUX_REG); + outw(devpriv->mux_scan, dev->iobase + PCI171X_MUX_REG); outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); comedi_8254_pacer_enable(dev->pacer, 1, 2, true); return IRQ_HANDLED; @@ -640,12 +518,12 @@ static irqreturn_t interrupt_service_pci1710(int irq, void *d) return IRQ_HANDLED; } -static int pci171x_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) +static int pci1710_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) { struct pci1710_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; - pci171x_ai_setup_chanlist(dev, s, cmd->chanlist, cmd->chanlist_len, + pci1710_ai_setup_chanlist(dev, s, cmd->chanlist, cmd->chanlist_len, devpriv->saved_seglen); outb(0, dev->iobase + PCI171X_CLRFIFO_REG); @@ -681,7 +559,7 @@ static int pci171x_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) return 0; } -static int pci171x_ai_cmdtest(struct comedi_device *dev, +static int pci1710_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) { @@ -745,7 +623,7 @@ static int pci171x_ai_cmdtest(struct comedi_device *dev, /* Step 5: check channel list */ - err |= pci171x_ai_check_chanlist(dev, s, cmd); + err |= pci1710_ai_check_chanlist(dev, s, cmd); if (err) return 5; @@ -753,7 +631,55 @@ static int pci171x_ai_cmdtest(struct comedi_device *dev, return 0; } -static int pci171x_insn_counter_config(struct comedi_device *dev, +static int pci1710_ao_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct pci1710_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int range = CR_RANGE(insn->chanspec); + unsigned int val = s->readback[chan]; + int i; + + devpriv->da_ranges &= ~PCI171X_DAREF_MASK(chan); + devpriv->da_ranges |= PCI171X_DAREF(chan, range); + outw(devpriv->da_ranges, dev->iobase + PCI171X_DAREF_REG); + + for (i = 0; i < insn->n; i++) { + val = data[i]; + outw(val, dev->iobase + PCI171X_DA_REG(chan)); + } + + s->readback[chan] = val; + + return insn->n; +} + +static int pci1710_di_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + data[1] = inw(dev->iobase + PCI171X_DI_REG); + + return insn->n; +} + +static int pci1710_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + if (comedi_dio_update_state(s, data)) + outw(s->state, dev->iobase + PCI171X_DO_REG); + + data[1] = s->state; + + return insn->n; +} + +static int pci1710_counter_insn_config(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) @@ -780,7 +706,7 @@ static int pci171x_insn_counter_config(struct comedi_device *dev, data[2] = 0; } else { data[1] = 0; - data[2] = I8254_OSC_BASE_10MHZ; + data[2] = I8254_OSC_BASE_1MHZ; } break; default: @@ -790,56 +716,29 @@ static int pci171x_insn_counter_config(struct comedi_device *dev, return insn->n; } -static int pci171x_reset(struct comedi_device *dev) +static void pci1710_reset(struct comedi_device *dev) { const struct boardtype *board = dev->board_ptr; - struct pci1710_private *devpriv = dev->private; - /* Software trigger, CNT0=external */ - devpriv->ctrl = PCI171X_CTRL_SW | PCI171X_CTRL_CNT0; - /* reset any operations */ - outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); + /* + * Disable A/D triggers and interrupt sources, set counter 0 + * to use internal 1 MHz clock. + */ + outw(0, dev->iobase + PCI171X_CTRL_REG); + + /* clear A/D FIFO and any pending interrutps */ outb(0, dev->iobase + PCI171X_CLRFIFO_REG); outb(0, dev->iobase + PCI171X_CLRINT_REG); - devpriv->da_ranges = 0; + if (board->has_ao) { /* set DACs to 0..5V and outputs to 0V */ - outb(devpriv->da_ranges, dev->iobase + PCI171X_DAREF_REG); + outb(0, dev->iobase + PCI171X_DAREF_REG); outw(0, dev->iobase + PCI171X_DA_REG(0)); outw(0, dev->iobase + PCI171X_DA_REG(1)); } - outw(0, dev->iobase + PCI171X_DO_REG); /* digital outputs to 0 */ - outb(0, dev->iobase + PCI171X_CLRFIFO_REG); - outb(0, dev->iobase + PCI171X_CLRINT_REG); - return 0; -} - -static int pci1720_reset(struct comedi_device *dev) -{ - struct pci1710_private *devpriv = dev->private; - /* set synchronous output mode */ - outb(PCI1720_SYNC_CTRL_SC0, dev->iobase + PCI1720_SYNC_CTRL_REG); - devpriv->da_ranges = 0xAA; - /* set all ranges to +/-5V and outputs to 0V */ - outb(devpriv->da_ranges, dev->iobase + PCI1720_RANGE_REG); - outw(0x0800, dev->iobase + PCI1720_DA_REG(0)); - outw(0x0800, dev->iobase + PCI1720_DA_REG(1)); - outw(0x0800, dev->iobase + PCI1720_DA_REG(2)); - outw(0x0800, dev->iobase + PCI1720_DA_REG(3)); - outb(0, dev->iobase + PCI1720_SYNC_REG); /* update outputs */ - - return 0; -} - -static int pci1710_reset(struct comedi_device *dev) -{ - const struct boardtype *board = dev->board_ptr; - - if (board->is_pci1720) - return pci1720_reset(dev); - - return pci171x_reset(dev); + /* set digital outputs to 0 */ + outw(0, dev->iobase + PCI171X_DO_REG); } static int pci1710_auto_attach(struct comedi_device *dev, @@ -850,6 +749,7 @@ static int pci1710_auto_attach(struct comedi_device *dev, struct pci1710_private *devpriv; struct comedi_subdevice *s; int ret, subdev, n_subdevices; + int i; if (context < ARRAY_SIZE(boardtypes)) board = &boardtypes[context]; @@ -872,15 +772,16 @@ static int pci1710_auto_attach(struct comedi_device *dev, if (!dev->pacer) return -ENOMEM; - n_subdevices = 0; - if (board->n_aichan) - n_subdevices++; + n_subdevices = 1; /* all boards have analog inputs */ if (board->has_ao) n_subdevices++; - if (board->has_di_do) - n_subdevices += 2; - if (board->has_counter) - n_subdevices++; + if (!board->is_pci1713) { + /* + * All other boards have digital inputs and outputs as + * well as a user counter. + */ + n_subdevices += 3; + } ret = comedi_alloc_subdevices(dev, n_subdevices); if (ret) @@ -888,8 +789,8 @@ static int pci1710_auto_attach(struct comedi_device *dev, pci1710_reset(dev); - if (board->has_irq && pcidev->irq) { - ret = request_irq(pcidev->irq, interrupt_service_pci1710, + if (pcidev->irq) { + ret = request_irq(pcidev->irq, pci1710_irq_handler, IRQF_SHARED, dev->board_name, dev); if (ret == 0) dev->irq = pcidev->irq; @@ -897,109 +798,89 @@ static int pci1710_auto_attach(struct comedi_device *dev, subdev = 0; - if (board->n_aichan) { - s = &dev->subdevices[subdev]; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND; - if (board->has_diff_ai) - s->subdev_flags |= SDF_DIFF; - s->n_chan = board->n_aichan; - s->maxdata = 0x0fff; - s->range_table = board->rangelist_ai; - s->insn_read = pci171x_ai_insn_read; - if (dev->irq) { - dev->read_subdev = s; - s->subdev_flags |= SDF_CMD_READ; - s->len_chanlist = s->n_chan; - s->do_cmdtest = pci171x_ai_cmdtest; - s->do_cmd = pci171x_ai_cmd; - s->cancel = pci171x_ai_cancel; + /* Analog Input subdevice */ + s = &dev->subdevices[subdev++]; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + if (!board->is_pci1711) + s->subdev_flags |= SDF_DIFF; + s->n_chan = board->is_pci1713 ? 32 : 16; + s->maxdata = 0x0fff; + s->range_table = board->ai_range; + s->insn_read = pci1710_ai_insn_read; + if (dev->irq) { + dev->read_subdev = s; + s->subdev_flags |= SDF_CMD_READ; + s->len_chanlist = s->n_chan; + s->do_cmdtest = pci1710_ai_cmdtest; + s->do_cmd = pci1710_ai_cmd; + s->cancel = pci1710_ai_cancel; + } + + /* find the value needed to adjust for unipolar gain codes */ + for (i = 0; i < s->range_table->length; i++) { + if (comedi_range_is_unipolar(s, i)) { + devpriv->unipolar_gain = i; + break; } - subdev++; } if (board->has_ao) { - s = &dev->subdevices[subdev]; + /* Analog Output subdevice */ + s = &dev->subdevices[subdev++]; s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND; + s->n_chan = 2; s->maxdata = 0x0fff; - if (board->is_pci1720) { - s->n_chan = 4; - s->range_table = &pci1720_ao_range; - s->insn_write = pci1720_ao_insn_write; - } else { - s->n_chan = 2; - s->range_table = &pci171x_ao_range; - s->insn_write = pci171x_ao_insn_write; - } + s->range_table = &pci171x_ao_range; + s->insn_write = pci1710_ao_insn_write; ret = comedi_alloc_subdev_readback(s); if (ret) return ret; - - /* initialize the readback values to match the board reset */ - if (board->is_pci1720) { - int i; - - for (i = 0; i < s->n_chan; i++) - s->readback[i] = 0x0800; - } - - subdev++; } - if (board->has_di_do) { - s = &dev->subdevices[subdev]; + if (!board->is_pci1713) { + /* Digital Input subdevice */ + s = &dev->subdevices[subdev++]; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; s->n_chan = 16; s->maxdata = 1; s->range_table = &range_digital; - s->insn_bits = pci171x_di_insn_bits; - subdev++; + s->insn_bits = pci1710_di_insn_bits; - s = &dev->subdevices[subdev]; + /* Digital Output subdevice */ + s = &dev->subdevices[subdev++]; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITABLE; s->n_chan = 16; s->maxdata = 1; s->range_table = &range_digital; - s->insn_bits = pci171x_do_insn_bits; - subdev++; - } + s->insn_bits = pci1710_do_insn_bits; - /* Counter subdevice (8254) */ - if (board->has_counter) { - s = &dev->subdevices[subdev]; + /* Counter subdevice (8254) */ + s = &dev->subdevices[subdev++]; comedi_8254_subdevice_init(s, dev->pacer); - dev->pacer->insn_config = pci171x_insn_counter_config; + dev->pacer->insn_config = pci1710_counter_insn_config; /* counters 1 and 2 are used internally for the pacer */ comedi_8254_set_busy(dev->pacer, 1, true); comedi_8254_set_busy(dev->pacer, 2, true); - - subdev++; } /* max_samples is half the FIFO size (2 bytes/sample) */ - devpriv->max_samples = (board->has_large_fifo) ? 2048 : 512; + devpriv->max_samples = (board->is_pci1711) ? 512 : 2048; return 0; } -static void pci1710_detach(struct comedi_device *dev) -{ - if (dev->iobase) - pci1710_reset(dev); - comedi_pci_detach(dev); -} - static struct comedi_driver adv_pci1710_driver = { .driver_name = "adv_pci1710", .module = THIS_MODULE, .auto_attach = pci1710_auto_attach, - .detach = pci1710_detach, + .detach = comedi_pci_detach, }; static int adv_pci1710_pci_probe(struct pci_dev *dev, @@ -1063,7 +944,6 @@ static const struct pci_device_id adv_pci1710_pci_table[] = { }, { PCI_VDEVICE(ADVANTECH, 0x1711), BOARD_PCI1711 }, { PCI_VDEVICE(ADVANTECH, 0x1713), BOARD_PCI1713 }, - { PCI_VDEVICE(ADVANTECH, 0x1720), BOARD_PCI1720 }, { PCI_VDEVICE(ADVANTECH, 0x1731), BOARD_PCI1731 }, { 0 } }; diff --git a/drivers/staging/comedi/drivers/adv_pci1720.c b/drivers/staging/comedi/drivers/adv_pci1720.c new file mode 100644 index 000000000000..4830a1c93d15 --- /dev/null +++ b/drivers/staging/comedi/drivers/adv_pci1720.c @@ -0,0 +1,195 @@ +/* + * COMEDI driver for Advantech PCI-1720U + * Copyright (c) 2015 H Hartley Sweeten <hsweeten@visionengravers.com> + * + * Separated from the adv_pci1710 driver written by: + * Michal Dobes <dobes@tesnet.cz> + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000 David A. Schleef <ds@schleef.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/* + * Driver: adv_pci1720 + * Description: 4-channel Isolated D/A Output board + * Devices: [Advantech] PCI-7120U (adv_pci1720) + * Author: H Hartley Sweeten <hsweeten@visionengravers.com> + * Updated: Fri, 29 Oct 2015 17:19:35 -0700 + * Status: untested + * + * Configuration options: not applicable, uses PCI auto config + * + * The PCI-1720 has 4 isolated 12-bit analog output channels with multiple + * output ranges. It also has a BoardID switch to allow differentiating + * multiple boards in the system. + * + * The analog outputs can operate in two modes, immediate and synchronized. + * This driver currently does not support the synchronized output mode. + * + * Jumpers JP1 to JP4 are used to set the current sink ranges for each + * analog output channel. In order to use the current sink ranges, the + * unipolar 5V range must be used. The voltage output and sink output for + * each channel is available on the connector as separate pins. + * + * Jumper JP5 controls the "hot" reset state of the analog outputs. + * Depending on its setting, the analog outputs will either keep the + * last settings and output values or reset to the default state after + * a "hot" reset. The default state for all channels is uniploar 5V range + * and all the output values are 0V. To allow this feature to work, the + * analog outputs are not "reset" when the driver attaches. + */ + +#include <linux/module.h> +#include <linux/delay.h> + +#include "../comedi_pci.h" + +/* + * PCI BAR2 Register map (dev->iobase) + */ +#define PCI1720_AO_LSB_REG(x) (0x00 + ((x) * 2)) +#define PCI1720_AO_MSB_REG(x) (0x01 + ((x) * 2)) +#define PCI1720_AO_RANGE_REG 0x08 +#define PCI1720_AO_RANGE(c, r) (((r) & 0x3) << ((c) * 2)) +#define PCI1720_AO_RANGE_MASK(c) PCI1720_AO_RANGE((c), 0x3) +#define PCI1720_SYNC_REG 0x09 +#define PCI1720_SYNC_CTRL_REG 0x0f +#define PCI1720_SYNC_CTRL_SC0 BIT(0) +#define PCI1720_BOARDID_REG 0x14 + +static const struct comedi_lrange pci1720_ao_range = { + 4, { + UNI_RANGE(5), + UNI_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(10) + } +}; + +static int pci1720_ao_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int range = CR_RANGE(insn->chanspec); + unsigned int val; + int i; + + /* set the channel range and polarity */ + val = inb(dev->iobase + PCI1720_AO_RANGE_REG); + val &= ~PCI1720_AO_RANGE_MASK(chan); + val |= PCI1720_AO_RANGE(chan, range); + outb(val, dev->iobase + PCI1720_AO_RANGE_REG); + + val = s->readback[chan]; + for (i = 0; i < insn->n; i++) { + val = data[i]; + + outb(val & 0xff, dev->iobase + PCI1720_AO_LSB_REG(chan)); + outb((val >> 8) & 0xff, dev->iobase + PCI1720_AO_MSB_REG(chan)); + + /* conversion time is 2us (500 kHz throughput) */ + usleep_range(2, 100); + } + + s->readback[chan] = val; + + return insn->n; +} + +static int pci1720_di_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + data[1] = inb(dev->iobase + PCI1720_BOARDID_REG); + + return insn->n; +} + +static int pci1720_auto_attach(struct comedi_device *dev, + unsigned long context) +{ + struct pci_dev *pcidev = comedi_to_pci_dev(dev); + struct comedi_subdevice *s; + int ret; + + ret = comedi_pci_enable(dev); + if (ret) + return ret; + dev->iobase = pci_resource_start(pcidev, 2); + + ret = comedi_alloc_subdevices(dev, 2); + if (ret) + return ret; + + /* Analog Output subdevice */ + s = &dev->subdevices[0]; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 4; + s->maxdata = 0x0fff; + s->range_table = &pci1720_ao_range; + s->insn_write = pci1720_ao_insn_write; + + ret = comedi_alloc_subdev_readback(s); + if (ret) + return ret; + + /* Digital Input subdevice (BoardID SW1) */ + s = &dev->subdevices[1]; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 4; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = pci1720_di_insn_bits; + + /* disable synchronized output, channels update when written */ + outb(0, dev->iobase + PCI1720_SYNC_CTRL_REG); + + return 0; +} + +static struct comedi_driver adv_pci1720_driver = { + .driver_name = "adv_pci1720", + .module = THIS_MODULE, + .auto_attach = pci1720_auto_attach, + .detach = comedi_pci_detach, +}; + +static int adv_pci1720_pci_probe(struct pci_dev *dev, + const struct pci_device_id *id) +{ + return comedi_pci_auto_config(dev, &adv_pci1720_driver, + id->driver_data); +} + +static const struct pci_device_id adv_pci1720_pci_table[] = { + { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1720) }, + { 0 } +}; +MODULE_DEVICE_TABLE(pci, adv_pci1720_pci_table); + +static struct pci_driver adv_pci1720_pci_driver = { + .name = "adv_pci1720", + .id_table = adv_pci1720_pci_table, + .probe = adv_pci1720_pci_probe, + .remove = comedi_pci_auto_unconfig, +}; +module_comedi_pci_driver(adv_pci1720_driver, adv_pci1720_pci_driver); + +MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>"); +MODULE_DESCRIPTION("Comedi driver for Advantech PCI-1720 Analog Output board"); +MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/adv_pci1760.c b/drivers/staging/comedi/drivers/adv_pci1760.c new file mode 100644 index 000000000000..d7dd1e55e347 --- /dev/null +++ b/drivers/staging/comedi/drivers/adv_pci1760.c @@ -0,0 +1,432 @@ +/* + * COMEDI driver for the Advantech PCI-1760 + * Copyright (C) 2015 H Hartley Sweeten <hsweeten@visionengravers.com> + * + * Based on the pci1760 support in the adv_pci_dio driver written by: + * Michal Dobes <dobes@tesnet.cz> + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000 David A. Schleef <ds@schleef.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/* + * Driver: adv_pci1760 + * Description: Advantech PCI-1760 Relay & Isolated Digital Input Card + * Devices: [Advantech] PCI-1760 (adv_pci1760) + * Author: H Hartley Sweeten <hsweeten@visionengravers.com> + * Updated: Fri, 13 Nov 2015 12:34:00 -0700 + * Status: untested + * + * Configuration Options: not applicable, uses PCI auto config + */ + +#include <linux/module.h> + +#include "../comedi_pci.h" + +/* + * PCI-1760 Register Map + * + * Outgoing Mailbox Bytes + * OMB3: Not used (must be 0) + * OMB2: The command code to the PCI-1760 + * OMB1: The hi byte of the parameter for the command in OMB2 + * OMB0: The lo byte of the parameter for the command in OMB2 + * + * Incoming Mailbox Bytes + * IMB3: The Isolated Digital Input status (updated every 100us) + * IMB2: The current command (matches OMB2 when command is successful) + * IMB1: The hi byte of the feedback data for the command in OMB2 + * IMB0: The lo byte of the feedback data for the command in OMB2 + * + * Interrupt Control/Status + * INTCSR3: Not used (must be 0) + * INTCSR2: The interrupt status (read only) + * INTCSR1: Interrupt enable/disable + * INTCSR0: Not used (must be 0) + */ +#define PCI1760_OMB_REG(x) (0x0c + (x)) +#define PCI1760_IMB_REG(x) (0x1c + (x)) +#define PCI1760_INTCSR_REG(x) (0x38 + (x)) +#define PCI1760_INTCSR1_IRQ_ENA BIT(5) +#define PCI1760_INTCSR2_OMB_IRQ BIT(0) +#define PCI1760_INTCSR2_IMB_IRQ BIT(1) +#define PCI1760_INTCSR2_IRQ_STATUS BIT(6) +#define PCI1760_INTCSR2_IRQ_ASSERTED BIT(7) + +/* PCI-1760 command codes */ +#define PCI1760_CMD_CLR_IMB2 0x00 /* Clears IMB2 */ +#define PCI1760_CMD_SET_DO 0x01 /* Set output state */ +#define PCI1760_CMD_GET_DO 0x02 /* Read output status */ +#define PCI1760_CMD_GET_STATUS 0x03 /* Read current status */ +#define PCI1760_CMD_GET_FW_VER 0x0e /* Read firware version */ +#define PCI1760_CMD_GET_HW_VER 0x0f /* Read hardware version */ +#define PCI1760_CMD_SET_PWM_HI(x) (0x10 + (x) * 2) /* Set "hi" period */ +#define PCI1760_CMD_SET_PWM_LO(x) (0x11 + (x) * 2) /* Set "lo" period */ +#define PCI1760_CMD_SET_PWM_CNT(x) (0x14 + (x)) /* Set burst count */ +#define PCI1760_CMD_ENA_PWM 0x1f /* Enable PWM outputs */ +#define PCI1760_CMD_ENA_FILT 0x20 /* Enable input filter */ +#define PCI1760_CMD_ENA_PAT_MATCH 0x21 /* Enable input pattern match */ +#define PCI1760_CMD_SET_PAT_MATCH 0x22 /* Set input pattern match */ +#define PCI1760_CMD_ENA_RISE_EDGE 0x23 /* Enable input rising edge */ +#define PCI1760_CMD_ENA_FALL_EDGE 0x24 /* Enable input falling edge */ +#define PCI1760_CMD_ENA_CNT 0x28 /* Enable counter */ +#define PCI1760_CMD_RST_CNT 0x29 /* Reset counter */ +#define PCI1760_CMD_ENA_CNT_OFLOW 0x2a /* Enable counter overflow */ +#define PCI1760_CMD_ENA_CNT_MATCH 0x2b /* Enable counter match */ +#define PCI1760_CMD_SET_CNT_EDGE 0x2c /* Set counter edge */ +#define PCI1760_CMD_GET_CNT 0x2f /* Reads counter value */ +#define PCI1760_CMD_SET_HI_SAMP(x) (0x30 + (x)) /* Set "hi" sample time */ +#define PCI1760_CMD_SET_LO_SAMP(x) (0x38 + (x)) /* Set "lo" sample time */ +#define PCI1760_CMD_SET_CNT(x) (0x40 + (x)) /* Set counter reset val */ +#define PCI1760_CMD_SET_CNT_MATCH(x) (0x48 + (x)) /* Set counter match val */ +#define PCI1760_CMD_GET_INT_FLAGS 0x60 /* Read interrupt flags */ +#define PCI1760_CMD_GET_INT_FLAGS_MATCH BIT(0) +#define PCI1760_CMD_GET_INT_FLAGS_COS BIT(1) +#define PCI1760_CMD_GET_INT_FLAGS_OFLOW BIT(2) +#define PCI1760_CMD_GET_OS 0x61 /* Read edge change flags */ +#define PCI1760_CMD_GET_CNT_STATUS 0x62 /* Read counter oflow/match */ + +#define PCI1760_CMD_TIMEOUT 250 /* 250 usec timeout */ +#define PCI1760_CMD_RETRIES 3 /* limit number of retries */ + +#define PCI1760_PWM_TIMEBASE 100000 /* 1 unit = 100 usec */ + +static int pci1760_send_cmd(struct comedi_device *dev, + unsigned char cmd, unsigned short val) +{ + unsigned long timeout; + + /* send the command and parameter */ + outb(val & 0xff, dev->iobase + PCI1760_OMB_REG(0)); + outb((val >> 8) & 0xff, dev->iobase + PCI1760_OMB_REG(1)); + outb(cmd, dev->iobase + PCI1760_OMB_REG(2)); + outb(0, dev->iobase + PCI1760_OMB_REG(3)); + + /* datasheet says to allow up to 250 usec for the command to complete */ + timeout = jiffies + usecs_to_jiffies(PCI1760_CMD_TIMEOUT); + do { + if (inb(dev->iobase + PCI1760_IMB_REG(2)) == cmd) { + /* command success; return the feedback data */ + return inb(dev->iobase + PCI1760_IMB_REG(0)) | + (inb(dev->iobase + PCI1760_IMB_REG(1)) << 8); + } + cpu_relax(); + } while (time_before(jiffies, timeout)); + + return -EBUSY; +} + +static int pci1760_cmd(struct comedi_device *dev, + unsigned char cmd, unsigned short val) +{ + int repeats; + int ret; + + /* send PCI1760_CMD_CLR_IMB2 between identical commands */ + if (inb(dev->iobase + PCI1760_IMB_REG(2)) == cmd) { + ret = pci1760_send_cmd(dev, PCI1760_CMD_CLR_IMB2, 0); + if (ret < 0) { + /* timeout? try it once more */ + ret = pci1760_send_cmd(dev, PCI1760_CMD_CLR_IMB2, 0); + if (ret < 0) + return -ETIMEDOUT; + } + } + + /* datasheet says to keep retrying the command */ + for (repeats = 0; repeats < PCI1760_CMD_RETRIES; repeats++) { + ret = pci1760_send_cmd(dev, cmd, val); + if (ret >= 0) + return ret; + } + + /* command failed! */ + return -ETIMEDOUT; +} + +static int pci1760_di_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + data[1] = inb(dev->iobase + PCI1760_IMB_REG(3)); + + return insn->n; +} + +static int pci1760_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + int ret; + + if (comedi_dio_update_state(s, data)) { + ret = pci1760_cmd(dev, PCI1760_CMD_SET_DO, s->state); + if (ret < 0) + return ret; + } + + data[1] = s->state; + + return insn->n; +} + +static int pci1760_pwm_ns_to_div(unsigned int flags, unsigned int ns) +{ + unsigned int divisor; + + switch (flags) { + case CMDF_ROUND_NEAREST: + divisor = DIV_ROUND_CLOSEST(ns, PCI1760_PWM_TIMEBASE); + break; + case CMDF_ROUND_UP: + divisor = DIV_ROUND_UP(ns, PCI1760_PWM_TIMEBASE); + break; + case CMDF_ROUND_DOWN: + divisor = ns / PCI1760_PWM_TIMEBASE; + default: + return -EINVAL; + } + + if (divisor < 1) + divisor = 1; + if (divisor > 0xffff) + divisor = 0xffff; + + return divisor; +} + +static int pci1760_pwm_enable(struct comedi_device *dev, + unsigned int chan, bool enable) +{ + int ret; + + ret = pci1760_cmd(dev, PCI1760_CMD_GET_STATUS, PCI1760_CMD_ENA_PWM); + if (ret < 0) + return ret; + + if (enable) + ret |= BIT(chan); + else + ret &= ~BIT(chan); + + return pci1760_cmd(dev, PCI1760_CMD_ENA_PWM, ret); +} + +static int pci1760_pwm_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int chan = CR_CHAN(insn->chanspec); + int hi_div; + int lo_div; + int ret; + + switch (data[0]) { + case INSN_CONFIG_ARM: + ret = pci1760_pwm_enable(dev, chan, false); + if (ret < 0) + return ret; + + if (data[1] > 0xffff) + return -EINVAL; + ret = pci1760_cmd(dev, PCI1760_CMD_SET_PWM_CNT(chan), data[1]); + if (ret < 0) + return ret; + + ret = pci1760_pwm_enable(dev, chan, true); + if (ret < 0) + return ret; + break; + case INSN_CONFIG_DISARM: + ret = pci1760_pwm_enable(dev, chan, false); + if (ret < 0) + return ret; + break; + case INSN_CONFIG_PWM_OUTPUT: + ret = pci1760_pwm_enable(dev, chan, false); + if (ret < 0) + return ret; + + hi_div = pci1760_pwm_ns_to_div(data[1], data[2]); + lo_div = pci1760_pwm_ns_to_div(data[3], data[4]); + if (hi_div < 0 || lo_div < 0) + return -EINVAL; + if ((hi_div * PCI1760_PWM_TIMEBASE) != data[2] || + (lo_div * PCI1760_PWM_TIMEBASE) != data[4]) { + data[2] = hi_div * PCI1760_PWM_TIMEBASE; + data[4] = lo_div * PCI1760_PWM_TIMEBASE; + return -EAGAIN; + } + ret = pci1760_cmd(dev, PCI1760_CMD_SET_PWM_HI(chan), hi_div); + if (ret < 0) + return ret; + ret = pci1760_cmd(dev, PCI1760_CMD_SET_PWM_LO(chan), lo_div); + if (ret < 0) + return ret; + break; + case INSN_CONFIG_GET_PWM_OUTPUT: + hi_div = pci1760_cmd(dev, PCI1760_CMD_GET_STATUS, + PCI1760_CMD_SET_PWM_HI(chan)); + lo_div = pci1760_cmd(dev, PCI1760_CMD_GET_STATUS, + PCI1760_CMD_SET_PWM_LO(chan)); + if (hi_div < 0 || lo_div < 0) + return -ETIMEDOUT; + + data[1] = hi_div * PCI1760_PWM_TIMEBASE; + data[2] = lo_div * PCI1760_PWM_TIMEBASE; + break; + case INSN_CONFIG_GET_PWM_STATUS: + ret = pci1760_cmd(dev, PCI1760_CMD_GET_STATUS, + PCI1760_CMD_ENA_PWM); + if (ret < 0) + return ret; + + data[1] = (ret & BIT(chan)) ? 1 : 0; + break; + default: + return -EINVAL; + } + + return insn->n; +} + +static void pci1760_reset(struct comedi_device *dev) +{ + int i; + + /* disable interrupts (intcsr2 is read-only) */ + outb(0, dev->iobase + PCI1760_INTCSR_REG(0)); + outb(0, dev->iobase + PCI1760_INTCSR_REG(1)); + outb(0, dev->iobase + PCI1760_INTCSR_REG(3)); + + /* disable counters */ + pci1760_cmd(dev, PCI1760_CMD_ENA_CNT, 0); + + /* disable overflow interrupts */ + pci1760_cmd(dev, PCI1760_CMD_ENA_CNT_OFLOW, 0); + + /* disable match */ + pci1760_cmd(dev, PCI1760_CMD_ENA_CNT_MATCH, 0); + + /* set match and counter reset values */ + for (i = 0; i < 8; i++) { + pci1760_cmd(dev, PCI1760_CMD_SET_CNT_MATCH(i), 0x8000); + pci1760_cmd(dev, PCI1760_CMD_SET_CNT(i), 0x0000); + } + + /* reset counters to reset values */ + pci1760_cmd(dev, PCI1760_CMD_RST_CNT, 0xff); + + /* set counter count edges */ + pci1760_cmd(dev, PCI1760_CMD_SET_CNT_EDGE, 0); + + /* disable input filters */ + pci1760_cmd(dev, PCI1760_CMD_ENA_FILT, 0); + + /* disable pattern matching */ + pci1760_cmd(dev, PCI1760_CMD_ENA_PAT_MATCH, 0); + + /* set pattern match value */ + pci1760_cmd(dev, PCI1760_CMD_SET_PAT_MATCH, 0); +} + +static int pci1760_auto_attach(struct comedi_device *dev, + unsigned long context) +{ + struct pci_dev *pcidev = comedi_to_pci_dev(dev); + struct comedi_subdevice *s; + int ret; + + ret = comedi_pci_enable(dev); + if (ret) + return ret; + dev->iobase = pci_resource_start(pcidev, 0); + + pci1760_reset(dev); + + ret = comedi_alloc_subdevices(dev, 4); + if (ret) + return ret; + + /* Digital Input subdevice */ + s = &dev->subdevices[0]; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = pci1760_di_insn_bits; + + /* Digital Output subdevice */ + s = &dev->subdevices[1]; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = pci1760_do_insn_bits; + + /* get the current state of the outputs */ + ret = pci1760_cmd(dev, PCI1760_CMD_GET_DO, 0); + if (ret < 0) + return ret; + s->state = ret; + + /* PWM subdevice */ + s = &dev->subdevices[2]; + s->type = COMEDI_SUBD_PWM; + s->subdev_flags = SDF_PWM_COUNTER; + s->n_chan = 2; + s->insn_config = pci1760_pwm_insn_config; + + /* Counter subdevice */ + s = &dev->subdevices[3]; + s->type = COMEDI_SUBD_UNUSED; + + return 0; +} + +static struct comedi_driver pci1760_driver = { + .driver_name = "adv_pci1760", + .module = THIS_MODULE, + .auto_attach = pci1760_auto_attach, + .detach = comedi_pci_detach, +}; + +static int pci1760_pci_probe(struct pci_dev *dev, + const struct pci_device_id *id) +{ + return comedi_pci_auto_config(dev, &pci1760_driver, id->driver_data); +} + +static const struct pci_device_id pci1760_pci_table[] = { + { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1760) }, + { 0 } +}; +MODULE_DEVICE_TABLE(pci, pci1760_pci_table); + +static struct pci_driver pci1760_pci_driver = { + .name = "adv_pci1760", + .id_table = pci1760_pci_table, + .probe = pci1760_pci_probe, + .remove = comedi_pci_auto_unconfig, +}; +module_comedi_pci_driver(pci1760_driver, pci1760_pci_driver); + +MODULE_AUTHOR("Comedi http://www.comedi.org"); +MODULE_DESCRIPTION("Comedi driver for Advantech PCI-1760"); +MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c b/drivers/staging/comedi/drivers/adv_pci_dio.c index f1b3c5aa8d79..620cec13d74c 100644 --- a/drivers/staging/comedi/drivers/adv_pci_dio.c +++ b/drivers/staging/comedi/drivers/adv_pci_dio.c @@ -4,30 +4,21 @@ * Author: Michal Dobes <dobes@tesnet.cz> * * Hardware driver for Advantech PCI DIO cards. -*/ -/* -Driver: adv_pci_dio -Description: Advantech PCI-1730, PCI-1733, PCI-1734, PCI-1735U, - PCI-1736UP, PCI-1739U, PCI-1750, PCI-1751, PCI-1752, - PCI-1753/E, PCI-1754, PCI-1756, PCI-1760, PCI-1762 -Author: Michal Dobes <dobes@tesnet.cz> -Devices: [Advantech] PCI-1730 (adv_pci_dio), PCI-1733, - PCI-1734, PCI-1735U, PCI-1736UP, PCI-1739U, PCI-1750, - PCI-1751, PCI-1752, PCI-1753, - PCI-1753+PCI-1753E, PCI-1754, PCI-1756, - PCI-1760, PCI-1762 -Status: untested -Updated: Mon, 09 Jan 2012 12:40:46 +0000 - -This driver supports now only insn interface for DI/DO/DIO. + */ -Configuration options: - [0] - PCI bus of device (optional) - [1] - PCI slot of device (optional) - If bus/slot is not specified, the first available PCI - device will be used. - -*/ +/* + * Driver: adv_pci_dio + * Description: Advantech Digital I/O Cards + * Devices: [Advantech] PCI-1730 (adv_pci_dio), PCI-1733, + * PCI-1734, PCI-1735U, PCI-1736UP, PCI-1739U, PCI-1750, + * PCI-1751, PCI-1752, PCI-1753, PCI-1753+PCI-1753E, + * PCI-1754, PCI-1756, PCI-1762 + * Author: Michal Dobes <dobes@tesnet.cz> + * Updated: Mon, 09 Jan 2012 12:40:46 +0000 + * Status: untested + * + * Configuration Options: not applicable, uses PCI auto config + */ #include <linux/module.h> #include <linux/delay.h> @@ -37,403 +28,199 @@ Configuration options: #include "8255.h" #include "comedi_8254.h" -/* hardware types of the cards */ -enum hw_cards_id { - TYPE_PCI1730, TYPE_PCI1733, TYPE_PCI1734, TYPE_PCI1735, TYPE_PCI1736, - TYPE_PCI1739, - TYPE_PCI1750, - TYPE_PCI1751, - TYPE_PCI1752, - TYPE_PCI1753, TYPE_PCI1753E, - TYPE_PCI1754, TYPE_PCI1756, - TYPE_PCI1760, - TYPE_PCI1762 -}; - -/* which I/O instructions to use */ -enum hw_io_access { - IO_8b, IO_16b -}; - -#define MAX_DI_SUBDEVS 2 /* max number of DI subdevices per card */ -#define MAX_DO_SUBDEVS 2 /* max number of DO subdevices per card */ -#define MAX_DIO_SUBDEVG 2 /* max number of DIO subdevices group per - * card */ - -#define PCIDIO_MAINREG 2 /* main I/O region for all Advantech cards? */ - -/* Register offset definitions */ -/* Advantech PCI-1730/3/4 */ -#define PCI1730_IDI 0 /* R: Isolated digital input 0-15 */ -#define PCI1730_IDO 0 /* W: Isolated digital output 0-15 */ -#define PCI1730_DI 2 /* R: Digital input 0-15 */ -#define PCI1730_DO 2 /* W: Digital output 0-15 */ -#define PCI1733_IDI 0 /* R: Isolated digital input 0-31 */ -#define PCI1730_3_INT_EN 0x08 /* R/W: enable/disable interrupts */ -#define PCI1730_3_INT_RF 0x0c /* R/W: set falling/raising edge for - * interrupts */ -#define PCI1730_3_INT_CLR 0x10 /* R/W: clear interrupts */ -#define PCI1734_IDO 0 /* W: Isolated digital output 0-31 */ -#define PCI173x_BOARDID 4 /* R: Board I/D switch for 1730/3/4 */ - -/* Advantech PCI-1735U */ -#define PCI1735_DI 0 /* R: Digital input 0-31 */ -#define PCI1735_DO 0 /* W: Digital output 0-31 */ -#define PCI1735_C8254 4 /* R/W: 8254 counter */ -#define PCI1735_BOARDID 8 /* R: Board I/D switch for 1735U */ - -/* Advantech PCI-1736UP */ -#define PCI1736_IDI 0 /* R: Isolated digital input 0-15 */ -#define PCI1736_IDO 0 /* W: Isolated digital output 0-15 */ -#define PCI1736_3_INT_EN 0x08 /* R/W: enable/disable interrupts */ -#define PCI1736_3_INT_RF 0x0c /* R/W: set falling/raising edge for - * interrupts */ -#define PCI1736_3_INT_CLR 0x10 /* R/W: clear interrupts */ -#define PCI1736_BOARDID 4 /* R: Board I/D switch for 1736UP */ -#define PCI1736_MAINREG 0 /* Normal register (2) doesn't work */ +/* + * Register offset definitions + */ -/* Advantech PCI-1739U */ -#define PCI1739_DIO 0 /* R/W: begin of 8255 registers block */ -#define PCI1739_ICR 32 /* W: Interrupt control register */ -#define PCI1739_ISR 32 /* R: Interrupt status register */ -#define PCI1739_BOARDID 8 /* R: Board I/D switch for 1739U */ +/* PCI-1730, PCI-1733, PCI-1736 interrupt control registers */ +#define PCI173X_INT_EN_REG 0x08 /* R/W: enable/disable */ +#define PCI173X_INT_RF_REG 0x0c /* R/W: falling/rising edge */ +#define PCI173X_INT_CLR_REG 0x10 /* R/W: clear */ -/* Advantech PCI-1750 */ -#define PCI1750_IDI 0 /* R: Isolated digital input 0-15 */ -#define PCI1750_IDO 0 /* W: Isolated digital output 0-15 */ -#define PCI1750_ICR 32 /* W: Interrupt control register */ -#define PCI1750_ISR 32 /* R: Interrupt status register */ +/* PCI-1739U, PCI-1750, PCI1751 interrupt control registers */ +#define PCI1750_INT_REG 0x20 /* R/W: status/control */ -/* Advantech PCI-1751/3/3E */ -#define PCI1751_DIO 0 /* R/W: begin of 8255 registers block */ -#define PCI1751_CNT 24 /* R/W: begin of 8254 registers block */ -#define PCI1751_ICR 32 /* W: Interrupt control register */ -#define PCI1751_ISR 32 /* R: Interrupt status register */ -#define PCI1753_DIO 0 /* R/W: begin of 8255 registers block */ -#define PCI1753_ICR0 16 /* R/W: Interrupt control register group 0 */ -#define PCI1753_ICR1 17 /* R/W: Interrupt control register group 1 */ -#define PCI1753_ICR2 18 /* R/W: Interrupt control register group 2 */ -#define PCI1753_ICR3 19 /* R/W: Interrupt control register group 3 */ -#define PCI1753E_DIO 32 /* R/W: begin of 8255 registers block */ -#define PCI1753E_ICR0 48 /* R/W: Interrupt control register group 0 */ -#define PCI1753E_ICR1 49 /* R/W: Interrupt control register group 1 */ -#define PCI1753E_ICR2 50 /* R/W: Interrupt control register group 2 */ -#define PCI1753E_ICR3 51 /* R/W: Interrupt control register group 3 */ +/* PCI-1753, PCI-1753E interrupt control registers */ +#define PCI1753_INT_REG(x) (0x10 + (x)) /* R/W: control group 0 to 3 */ +#define PCI1753E_INT_REG(x) (0x30 + (x)) /* R/W: control group 0 to 3 */ -/* Advantech PCI-1752/4/6 */ -#define PCI1752_IDO 0 /* R/W: Digital output 0-31 */ -#define PCI1752_IDO2 4 /* R/W: Digital output 32-63 */ -#define PCI1754_IDI 0 /* R: Digital input 0-31 */ -#define PCI1754_IDI2 4 /* R: Digital input 32-64 */ -#define PCI1756_IDI 0 /* R: Digital input 0-31 */ -#define PCI1756_IDO 4 /* R/W: Digital output 0-31 */ -#define PCI1754_6_ICR0 0x08 /* R/W: Interrupt control register group 0 */ -#define PCI1754_6_ICR1 0x0a /* R/W: Interrupt control register group 1 */ -#define PCI1754_ICR2 0x0c /* R/W: Interrupt control register group 2 */ -#define PCI1754_ICR3 0x0e /* R/W: Interrupt control register group 3 */ -#define PCI1752_6_CFC 0x12 /* R/W: set/read channel freeze function */ -#define PCI175x_BOARDID 0x10 /* R: Board I/D switch for 1752/4/6 */ +/* PCI-1754, PCI-1756 interrupt control registers */ +#define PCI1754_INT_REG(x) (0x08 + (x) * 2) /* R/W: control group 0 to 3 */ -/* Advantech PCI-1762 registers */ -#define PCI1762_RO 0 /* R/W: Relays status/output */ -#define PCI1762_IDI 2 /* R: Isolated input status */ -#define PCI1762_BOARDID 4 /* R: Board I/D switch */ -#define PCI1762_ICR 6 /* W: Interrupt control register */ -#define PCI1762_ISR 6 /* R: Interrupt status register */ +/* PCI-1752, PCI-1756 special registers */ +#define PCI1752_CFC_REG 0x12 /* R/W: channel freeze function */ -/* Advantech PCI-1760 registers */ -#define OMB0 0x0c /* W: Mailbox outgoing registers */ -#define OMB1 0x0d -#define OMB2 0x0e -#define OMB3 0x0f -#define IMB0 0x1c /* R: Mailbox incoming registers */ -#define IMB1 0x1d -#define IMB2 0x1e -#define IMB3 0x1f -#define INTCSR0 0x38 /* R/W: Interrupt control registers */ -#define INTCSR1 0x39 -#define INTCSR2 0x3a -#define INTCSR3 0x3b +/* PCI-1762 interrupt control registers */ +#define PCI1762_INT_REG 0x06 /* R/W: status/control */ -/* PCI-1760 mailbox commands */ -#define CMD_ClearIMB2 0x00 /* Clear IMB2 status and return actual - * DI status in IMB3 */ -#define CMD_SetRelaysOutput 0x01 /* Set relay output from OMB0 */ -#define CMD_GetRelaysStatus 0x02 /* Get relay status to IMB0 */ -#define CMD_ReadCurrentStatus 0x07 /* Read the current status of the - * register in OMB0, result in IMB0 */ -#define CMD_ReadFirmwareVersion 0x0e /* Read the firmware ver., result in - * IMB1.IMB0 */ -#define CMD_ReadHardwareVersion 0x0f /* Read the hardware ver., result in - * IMB1.IMB0 */ -#define CMD_EnableIDIFilters 0x20 /* Enable IDI filters based on bits in - * OMB0 */ -#define CMD_EnableIDIPatternMatch 0x21 /* Enable IDI pattern match based on - * bits in OMB0 */ -#define CMD_SetIDIPatternMatch 0x22 /* Enable IDI pattern match based on - * bits in OMB0 */ -#define CMD_EnableIDICounters 0x28 /* Enable IDI counters based on bits in - * OMB0 */ -#define CMD_ResetIDICounters 0x29 /* Reset IDI counters based on bits in - * OMB0 to its reset values */ -#define CMD_OverflowIDICounters 0x2a /* Enable IDI counters overflow - * interrupts based on bits in OMB0 */ -#define CMD_MatchIntIDICounters 0x2b /* Enable IDI counters match value - * interrupts based on bits in OMB0 */ -#define CMD_EdgeIDICounters 0x2c /* Set IDI up counters count edge (bit=0 - * - rising, =1 - falling) */ -#define CMD_GetIDICntCurValue 0x2f /* Read IDI{OMB0} up counter current - * value */ -#define CMD_SetIDI0CntResetValue 0x40 /* Set IDI0 Counter Reset Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI1CntResetValue 0x41 /* Set IDI1 Counter Reset Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI2CntResetValue 0x42 /* Set IDI2 Counter Reset Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI3CntResetValue 0x43 /* Set IDI3 Counter Reset Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI4CntResetValue 0x44 /* Set IDI4 Counter Reset Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI5CntResetValue 0x45 /* Set IDI5 Counter Reset Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI6CntResetValue 0x46 /* Set IDI6 Counter Reset Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI7CntResetValue 0x47 /* Set IDI7 Counter Reset Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI0CntMatchValue 0x48 /* Set IDI0 Counter Match Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI1CntMatchValue 0x49 /* Set IDI1 Counter Match Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI2CntMatchValue 0x4a /* Set IDI2 Counter Match Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI3CntMatchValue 0x4b /* Set IDI3 Counter Match Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI4CntMatchValue 0x4c /* Set IDI4 Counter Match Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI5CntMatchValue 0x4d /* Set IDI5 Counter Match Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI6CntMatchValue 0x4e /* Set IDI6 Counter Match Value - * 256*OMB1+OMB0 */ -#define CMD_SetIDI7CntMatchValue 0x4f /* Set IDI7 Counter Match Value - * 256*OMB1+OMB0 */ +/* maximum number of subdevice descriptions in the boardinfo */ +#define PCI_DIO_MAX_DI_SUBDEVS 2 /* 2 x 8/16/32 input channels max */ +#define PCI_DIO_MAX_DO_SUBDEVS 2 /* 2 x 8/16/32 output channels max */ +#define PCI_DIO_MAX_DIO_SUBDEVG 2 /* 2 x any number of 8255 devices max */ -#define OMBCMD_RETRY 0x03 /* 3 times try request before error */ +enum pci_dio_boardid { + TYPE_PCI1730, + TYPE_PCI1733, + TYPE_PCI1734, + TYPE_PCI1735, + TYPE_PCI1736, + TYPE_PCI1739, + TYPE_PCI1750, + TYPE_PCI1751, + TYPE_PCI1752, + TYPE_PCI1753, + TYPE_PCI1753E, + TYPE_PCI1754, + TYPE_PCI1756, + TYPE_PCI1762 +}; struct diosubd_data { - int chans; /* num of chans */ - int addr; /* PCI address ofset */ - int regs; /* number of registers to read or 8255 - subdevices */ - unsigned int specflags; /* addon subdevice flags */ + int chans; /* num of chans or 8255 devices */ + unsigned long addr; /* PCI address ofset */ }; struct dio_boardtype { const char *name; /* board name */ - int main_pci_region; /* main I/O PCI region */ - enum hw_cards_id cardtype; int nsubdevs; - struct diosubd_data sdi[MAX_DI_SUBDEVS]; /* DI chans */ - struct diosubd_data sdo[MAX_DO_SUBDEVS]; /* DO chans */ - struct diosubd_data sdio[MAX_DIO_SUBDEVG]; /* DIO 8255 chans */ - struct diosubd_data boardid; /* card supports board ID switch */ + struct diosubd_data sdi[PCI_DIO_MAX_DI_SUBDEVS]; + struct diosubd_data sdo[PCI_DIO_MAX_DO_SUBDEVS]; + struct diosubd_data sdio[PCI_DIO_MAX_DIO_SUBDEVG]; + unsigned long id_reg; unsigned long timer_regbase; - enum hw_io_access io_access; + unsigned int is_16bit:1; }; static const struct dio_boardtype boardtypes[] = { [TYPE_PCI1730] = { .name = "pci1730", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1730, .nsubdevs = 5, - .sdi[0] = { 16, PCI1730_DI, 2, 0, }, - .sdi[1] = { 16, PCI1730_IDI, 2, 0, }, - .sdo[0] = { 16, PCI1730_DO, 2, 0, }, - .sdo[1] = { 16, PCI1730_IDO, 2, 0, }, - .boardid = { 4, PCI173x_BOARDID, 1, SDF_INTERNAL, }, - .io_access = IO_8b, + .sdi[0] = { 16, 0x02, }, /* DI 0-15 */ + .sdi[1] = { 16, 0x00, }, /* ISO DI 0-15 */ + .sdo[0] = { 16, 0x02, }, /* DO 0-15 */ + .sdo[1] = { 16, 0x00, }, /* ISO DO 0-15 */ + .id_reg = 0x04, }, [TYPE_PCI1733] = { .name = "pci1733", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1733, .nsubdevs = 2, - .sdi[1] = { 32, PCI1733_IDI, 4, 0, }, - .boardid = { 4, PCI173x_BOARDID, 1, SDF_INTERNAL, }, - .io_access = IO_8b, + .sdi[1] = { 32, 0x00, }, /* ISO DI 0-31 */ + .id_reg = 0x04, }, [TYPE_PCI1734] = { .name = "pci1734", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1734, .nsubdevs = 2, - .sdo[1] = { 32, PCI1734_IDO, 4, 0, }, - .boardid = { 4, PCI173x_BOARDID, 1, SDF_INTERNAL, }, - .io_access = IO_8b, + .sdo[1] = { 32, 0x00, }, /* ISO DO 0-31 */ + .id_reg = 0x04, }, [TYPE_PCI1735] = { .name = "pci1735", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1735, .nsubdevs = 4, - .sdi[0] = { 32, PCI1735_DI, 4, 0, }, - .sdo[0] = { 32, PCI1735_DO, 4, 0, }, - .boardid = { 4, PCI1735_BOARDID, 1, SDF_INTERNAL, }, - .timer_regbase = PCI1735_C8254, - .io_access = IO_8b, + .sdi[0] = { 32, 0x00, }, /* DI 0-31 */ + .sdo[0] = { 32, 0x00, }, /* DO 0-31 */ + .id_reg = 0x08, + .timer_regbase = 0x04, }, [TYPE_PCI1736] = { .name = "pci1736", - .main_pci_region = PCI1736_MAINREG, - .cardtype = TYPE_PCI1736, .nsubdevs = 3, - .sdi[1] = { 16, PCI1736_IDI, 2, 0, }, - .sdo[1] = { 16, PCI1736_IDO, 2, 0, }, - .boardid = { 4, PCI1736_BOARDID, 1, SDF_INTERNAL, }, - .io_access = IO_8b, + .sdi[1] = { 16, 0x00, }, /* ISO DI 0-15 */ + .sdo[1] = { 16, 0x00, }, /* ISO DO 0-15 */ + .id_reg = 0x04, }, [TYPE_PCI1739] = { .name = "pci1739", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1739, - .nsubdevs = 2, - .sdio[0] = { 48, PCI1739_DIO, 2, 0, }, - .io_access = IO_8b, + .nsubdevs = 3, + .sdio[0] = { 2, 0x00, }, /* 8255 DIO */ + .id_reg = 0x08, }, [TYPE_PCI1750] = { .name = "pci1750", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1750, .nsubdevs = 2, - .sdi[1] = { 16, PCI1750_IDI, 2, 0, }, - .sdo[1] = { 16, PCI1750_IDO, 2, 0, }, - .io_access = IO_8b, + .sdi[1] = { 16, 0x00, }, /* ISO DI 0-15 */ + .sdo[1] = { 16, 0x00, }, /* ISO DO 0-15 */ }, [TYPE_PCI1751] = { .name = "pci1751", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1751, .nsubdevs = 3, - .sdio[0] = { 48, PCI1751_DIO, 2, 0, }, - .timer_regbase = PCI1751_CNT, - .io_access = IO_8b, + .sdio[0] = { 2, 0x00, }, /* 8255 DIO */ + .timer_regbase = 0x18, }, [TYPE_PCI1752] = { .name = "pci1752", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1752, .nsubdevs = 3, - .sdo[0] = { 32, PCI1752_IDO, 2, 0, }, - .sdo[1] = { 32, PCI1752_IDO2, 2, 0, }, - .boardid = { 4, PCI175x_BOARDID, 1, SDF_INTERNAL, }, - .io_access = IO_16b, + .sdo[0] = { 32, 0x00, }, /* DO 0-31 */ + .sdo[1] = { 32, 0x04, }, /* DO 32-63 */ + .id_reg = 0x10, + .is_16bit = 1, }, [TYPE_PCI1753] = { .name = "pci1753", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1753, .nsubdevs = 4, - .sdio[0] = { 96, PCI1753_DIO, 4, 0, }, - .io_access = IO_8b, + .sdio[0] = { 4, 0x00, }, /* 8255 DIO */ }, [TYPE_PCI1753E] = { .name = "pci1753e", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1753E, .nsubdevs = 8, - .sdio[0] = { 96, PCI1753_DIO, 4, 0, }, - .sdio[1] = { 96, PCI1753E_DIO, 4, 0, }, - .io_access = IO_8b, + .sdio[0] = { 4, 0x00, }, /* 8255 DIO */ + .sdio[1] = { 4, 0x20, }, /* 8255 DIO */ }, [TYPE_PCI1754] = { .name = "pci1754", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1754, .nsubdevs = 3, - .sdi[0] = { 32, PCI1754_IDI, 2, 0, }, - .sdi[1] = { 32, PCI1754_IDI2, 2, 0, }, - .boardid = { 4, PCI175x_BOARDID, 1, SDF_INTERNAL, }, - .io_access = IO_16b, + .sdi[0] = { 32, 0x00, }, /* DI 0-31 */ + .sdi[1] = { 32, 0x04, }, /* DI 32-63 */ + .id_reg = 0x10, + .is_16bit = 1, }, [TYPE_PCI1756] = { .name = "pci1756", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1756, .nsubdevs = 3, - .sdi[1] = { 32, PCI1756_IDI, 2, 0, }, - .sdo[1] = { 32, PCI1756_IDO, 2, 0, }, - .boardid = { 4, PCI175x_BOARDID, 1, SDF_INTERNAL, }, - .io_access = IO_16b, - }, - [TYPE_PCI1760] = { - /* This card has its own 'attach' */ - .name = "pci1760", - .main_pci_region = 0, - .cardtype = TYPE_PCI1760, - .nsubdevs = 4, - .io_access = IO_8b, + .sdi[1] = { 32, 0x00, }, /* DI 0-31 */ + .sdo[1] = { 32, 0x04, }, /* DO 0-31 */ + .id_reg = 0x10, + .is_16bit = 1, }, [TYPE_PCI1762] = { .name = "pci1762", - .main_pci_region = PCIDIO_MAINREG, - .cardtype = TYPE_PCI1762, .nsubdevs = 3, - .sdi[1] = { 16, PCI1762_IDI, 1, 0, }, - .sdo[1] = { 16, PCI1762_RO, 1, 0, }, - .boardid = { 4, PCI1762_BOARDID, 1, SDF_INTERNAL, }, - .io_access = IO_16b, + .sdi[1] = { 16, 0x02, }, /* ISO DI 0-15 */ + .sdo[1] = { 16, 0x00, }, /* ISO DO 0-15 */ + .id_reg = 0x04, + .is_16bit = 1, }, }; -struct pci_dio_private { - char GlobalIrqEnabled; /* 1= any IRQ source is enabled */ - /* PCI-1760 specific data */ - unsigned char IDICntEnable; /* counter's counting enable status */ - unsigned char IDICntOverEnable; /* counter's overflow interrupts enable - * status */ - unsigned char IDICntMatchEnable; /* counter's match interrupts - * enable status */ - unsigned char IDICntEdge; /* counter's count edge value - * (bit=0 - rising, =1 - falling) */ - unsigned short CntResValue[8]; /* counters' reset value */ - unsigned short CntMatchValue[8]; /* counters' match interrupt value */ - unsigned char IDIFiltersEn; /* IDI's digital filters enable status */ - unsigned char IDIPatMatchEn; /* IDI's pattern match enable status */ - unsigned char IDIPatMatchValue; /* IDI's pattern match value */ - unsigned short IDIFiltrLow[8]; /* IDI's filter value low signal */ - unsigned short IDIFiltrHigh[8]; /* IDI's filter value high signal */ -}; - -/* -============================================================================== -*/ static int pci_dio_insn_bits_di_b(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { - const struct diosubd_data *d = (const struct diosubd_data *)s->private; - int i; + unsigned long reg = (unsigned long)s->private; + unsigned long iobase = dev->iobase + reg; - data[1] = 0; - for (i = 0; i < d->regs; i++) - data[1] |= inb(dev->iobase + d->addr + i) << (8 * i); + data[1] = inb(iobase); + if (s->n_chan > 8) + data[1] |= (inb(iobase + 1) << 8); + if (s->n_chan > 16) + data[1] |= (inb(iobase + 2) << 16); + if (s->n_chan > 24) + data[1] |= (inb(iobase + 3) << 24); return insn->n; } -/* -============================================================================== -*/ static int pci_dio_insn_bits_di_w(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { - const struct diosubd_data *d = (const struct diosubd_data *)s->private; - int i; + unsigned long reg = (unsigned long)s->private; + unsigned long iobase = dev->iobase + reg; - data[1] = 0; - for (i = 0; i < d->regs; i++) - data[1] |= inw(dev->iobase + d->addr + 2 * i) << (16 * i); + data[1] = inw(iobase); + if (s->n_chan > 16) + data[1] |= (inw(iobase + 2) << 16); return insn->n; } @@ -443,13 +230,17 @@ static int pci_dio_insn_bits_do_b(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - const struct diosubd_data *d = (const struct diosubd_data *)s->private; - int i; + unsigned long reg = (unsigned long)s->private; + unsigned long iobase = dev->iobase + reg; if (comedi_dio_update_state(s, data)) { - for (i = 0; i < d->regs; i++) - outb((s->state >> (8 * i)) & 0xff, - dev->iobase + d->addr + i); + outb(s->state & 0xff, iobase); + if (s->n_chan > 8) + outb((s->state >> 8) & 0xff, iobase + 1); + if (s->n_chan > 16) + outb((s->state >> 16) & 0xff, iobase + 2); + if (s->n_chan > 24) + outb((s->state >> 24) & 0xff, iobase + 3); } data[1] = s->state; @@ -462,13 +253,13 @@ static int pci_dio_insn_bits_do_w(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - const struct diosubd_data *d = (const struct diosubd_data *)s->private; - int i; + unsigned long reg = (unsigned long)s->private; + unsigned long iobase = dev->iobase + reg; if (comedi_dio_update_state(s, data)) { - for (i = 0; i < d->regs; i++) - outw((s->state >> (16 * i)) & 0xffff, - dev->iobase + d->addr + 2 * i); + outw(s->state & 0xffff, iobase); + if (s->n_chan > 16) + outw((s->state >> 16) & 0xffff, iobase + 2); } data[1] = s->state; @@ -476,510 +267,64 @@ static int pci_dio_insn_bits_do_w(struct comedi_device *dev, return insn->n; } -/* -============================================================================== -*/ -static int pci1760_unchecked_mbxrequest(struct comedi_device *dev, - unsigned char *omb, unsigned char *imb, - int repeats) -{ - int cnt, tout, ok = 0; - - for (cnt = 0; cnt < repeats; cnt++) { - outb(omb[0], dev->iobase + OMB0); - outb(omb[1], dev->iobase + OMB1); - outb(omb[2], dev->iobase + OMB2); - outb(omb[3], dev->iobase + OMB3); - for (tout = 0; tout < 251; tout++) { - imb[2] = inb(dev->iobase + IMB2); - if (imb[2] == omb[2]) { - imb[0] = inb(dev->iobase + IMB0); - imb[1] = inb(dev->iobase + IMB1); - imb[3] = inb(dev->iobase + IMB3); - ok = 1; - break; - } - udelay(1); - } - if (ok) - return 0; - } - - dev_err(dev->class_dev, "PCI-1760 mailbox request timeout!\n"); - return -ETIME; -} - -static int pci1760_clear_imb2(struct comedi_device *dev) -{ - unsigned char omb[4] = { 0x0, 0x0, CMD_ClearIMB2, 0x0 }; - unsigned char imb[4]; - /* check if imb2 is already clear */ - if (inb(dev->iobase + IMB2) == CMD_ClearIMB2) - return 0; - return pci1760_unchecked_mbxrequest(dev, omb, imb, OMBCMD_RETRY); -} - -static int pci1760_mbxrequest(struct comedi_device *dev, - unsigned char *omb, unsigned char *imb) -{ - if (omb[2] == CMD_ClearIMB2) { - dev_err(dev->class_dev, - "bug! this function should not be used for CMD_ClearIMB2 command\n"); - return -EINVAL; - } - if (inb(dev->iobase + IMB2) == omb[2]) { - int retval; - - retval = pci1760_clear_imb2(dev); - if (retval < 0) - return retval; - } - return pci1760_unchecked_mbxrequest(dev, omb, imb, OMBCMD_RETRY); -} - -/* -============================================================================== -*/ -static int pci1760_insn_bits_di(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int pci_dio_reset(struct comedi_device *dev, unsigned long cardtype) { - data[1] = inb(dev->iobase + IMB3); + /* disable channel freeze function on the PCI-1752/1756 boards */ + if (cardtype == TYPE_PCI1752 || cardtype == TYPE_PCI1756) + outw(0, dev->iobase + PCI1752_CFC_REG); - return insn->n; -} - -static int pci1760_insn_bits_do(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - int ret; - unsigned char omb[4] = { - 0x00, - 0x00, - CMD_SetRelaysOutput, - 0x00 - }; - unsigned char imb[4]; - - if (comedi_dio_update_state(s, data)) { - omb[0] = s->state; - ret = pci1760_mbxrequest(dev, omb, imb); - if (!ret) - return ret; - } - - data[1] = s->state; - - return insn->n; -} - -/* -============================================================================== -*/ -static int pci1760_insn_cnt_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - int ret, n; - unsigned char omb[4] = { - CR_CHAN(insn->chanspec) & 0x07, - 0x00, - CMD_GetIDICntCurValue, - 0x00 - }; - unsigned char imb[4]; - - for (n = 0; n < insn->n; n++) { - ret = pci1760_mbxrequest(dev, omb, imb); - if (!ret) - return ret; - data[n] = (imb[1] << 8) + imb[0]; - } - - return n; -} - -/* -============================================================================== -*/ -static int pci1760_insn_cnt_write(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - struct pci_dio_private *devpriv = dev->private; - int ret; - unsigned char chan = CR_CHAN(insn->chanspec) & 0x07; - unsigned char bitmask = 1 << chan; - unsigned char omb[4] = { - data[0] & 0xff, - (data[0] >> 8) & 0xff, - CMD_SetIDI0CntResetValue + chan, - 0x00 - }; - unsigned char imb[4]; - - /* Set reset value if different */ - if (devpriv->CntResValue[chan] != (data[0] & 0xffff)) { - ret = pci1760_mbxrequest(dev, omb, imb); - if (!ret) - return ret; - devpriv->CntResValue[chan] = data[0] & 0xffff; - } - - omb[0] = bitmask; /* reset counter to it reset value */ - omb[2] = CMD_ResetIDICounters; - ret = pci1760_mbxrequest(dev, omb, imb); - if (!ret) - return ret; - - /* start counter if it don't run */ - if (!(bitmask & devpriv->IDICntEnable)) { - omb[0] = bitmask; - omb[2] = CMD_EnableIDICounters; - ret = pci1760_mbxrequest(dev, omb, imb); - if (!ret) - return ret; - devpriv->IDICntEnable |= bitmask; - } - return 1; -} - -/* -============================================================================== -*/ -static int pci1760_reset(struct comedi_device *dev) -{ - struct pci_dio_private *devpriv = dev->private; - int i; - unsigned char omb[4] = { 0x00, 0x00, 0x00, 0x00 }; - unsigned char imb[4]; - - outb(0, dev->iobase + INTCSR0); /* disable IRQ */ - outb(0, dev->iobase + INTCSR1); - outb(0, dev->iobase + INTCSR2); - outb(0, dev->iobase + INTCSR3); - devpriv->GlobalIrqEnabled = 0; - - omb[0] = 0x00; - omb[2] = CMD_SetRelaysOutput; /* reset relay outputs */ - pci1760_mbxrequest(dev, omb, imb); - - omb[0] = 0x00; - omb[2] = CMD_EnableIDICounters; /* disable IDI up counters */ - pci1760_mbxrequest(dev, omb, imb); - devpriv->IDICntEnable = 0; - - omb[0] = 0x00; - omb[2] = CMD_OverflowIDICounters; /* disable counters overflow - * interrupts */ - pci1760_mbxrequest(dev, omb, imb); - devpriv->IDICntOverEnable = 0; - - omb[0] = 0x00; - omb[2] = CMD_MatchIntIDICounters; /* disable counters match value - * interrupts */ - pci1760_mbxrequest(dev, omb, imb); - devpriv->IDICntMatchEnable = 0; - - omb[0] = 0x00; - omb[1] = 0x80; - for (i = 0; i < 8; i++) { /* set IDI up counters match value */ - omb[2] = CMD_SetIDI0CntMatchValue + i; - pci1760_mbxrequest(dev, omb, imb); - devpriv->CntMatchValue[i] = 0x8000; - } - - omb[0] = 0x00; - omb[1] = 0x00; - for (i = 0; i < 8; i++) { /* set IDI up counters reset value */ - omb[2] = CMD_SetIDI0CntResetValue + i; - pci1760_mbxrequest(dev, omb, imb); - devpriv->CntResValue[i] = 0x0000; - } - - omb[0] = 0xff; - omb[2] = CMD_ResetIDICounters; /* reset IDI up counters to reset - * values */ - pci1760_mbxrequest(dev, omb, imb); - - omb[0] = 0x00; - omb[2] = CMD_EdgeIDICounters; /* set IDI up counters count edge */ - pci1760_mbxrequest(dev, omb, imb); - devpriv->IDICntEdge = 0x00; - - omb[0] = 0x00; - omb[2] = CMD_EnableIDIFilters; /* disable all digital in filters */ - pci1760_mbxrequest(dev, omb, imb); - devpriv->IDIFiltersEn = 0x00; - - omb[0] = 0x00; - omb[2] = CMD_EnableIDIPatternMatch; /* disable pattern matching */ - pci1760_mbxrequest(dev, omb, imb); - devpriv->IDIPatMatchEn = 0x00; - - omb[0] = 0x00; - omb[2] = CMD_SetIDIPatternMatch; /* set pattern match value */ - pci1760_mbxrequest(dev, omb, imb); - devpriv->IDIPatMatchValue = 0x00; - - return 0; -} - -/* -============================================================================== -*/ -static int pci_dio_reset(struct comedi_device *dev) -{ - const struct dio_boardtype *board = dev->board_ptr; - - switch (board->cardtype) { + /* disable and clear interrupts */ + switch (cardtype) { case TYPE_PCI1730: - outb(0, dev->iobase + PCI1730_DO); /* clear outputs */ - outb(0, dev->iobase + PCI1730_DO + 1); - outb(0, dev->iobase + PCI1730_IDO); - outb(0, dev->iobase + PCI1730_IDO + 1); - /* fallthrough */ case TYPE_PCI1733: - /* disable interrupts */ - outb(0, dev->iobase + PCI1730_3_INT_EN); - /* clear interrupts */ - outb(0x0f, dev->iobase + PCI1730_3_INT_CLR); - /* set rising edge trigger */ - outb(0, dev->iobase + PCI1730_3_INT_RF); - break; - case TYPE_PCI1734: - outb(0, dev->iobase + PCI1734_IDO); /* clear outputs */ - outb(0, dev->iobase + PCI1734_IDO + 1); - outb(0, dev->iobase + PCI1734_IDO + 2); - outb(0, dev->iobase + PCI1734_IDO + 3); - break; - case TYPE_PCI1735: - outb(0, dev->iobase + PCI1735_DO); /* clear outputs */ - outb(0, dev->iobase + PCI1735_DO + 1); - outb(0, dev->iobase + PCI1735_DO + 2); - outb(0, dev->iobase + PCI1735_DO + 3); - break; - case TYPE_PCI1736: - outb(0, dev->iobase + PCI1736_IDO); - outb(0, dev->iobase + PCI1736_IDO + 1); - /* disable interrupts */ - outb(0, dev->iobase + PCI1736_3_INT_EN); - /* clear interrupts */ - outb(0x0f, dev->iobase + PCI1736_3_INT_CLR); - /* set rising edge trigger */ - outb(0, dev->iobase + PCI1736_3_INT_RF); + outb(0, dev->iobase + PCI173X_INT_EN_REG); + outb(0x0f, dev->iobase + PCI173X_INT_CLR_REG); + outb(0, dev->iobase + PCI173X_INT_RF_REG); break; - case TYPE_PCI1739: - /* disable & clear interrupts */ - outb(0x88, dev->iobase + PCI1739_ICR); - break; - case TYPE_PCI1750: case TYPE_PCI1751: - /* disable & clear interrupts */ - outb(0x88, dev->iobase + PCI1750_ICR); - break; - case TYPE_PCI1752: - outw(0, dev->iobase + PCI1752_6_CFC); /* disable channel freeze - * function */ - outw(0, dev->iobase + PCI1752_IDO); /* clear outputs */ - outw(0, dev->iobase + PCI1752_IDO + 2); - outw(0, dev->iobase + PCI1752_IDO2); - outw(0, dev->iobase + PCI1752_IDO2 + 2); + outb(0x88, dev->iobase + PCI1750_INT_REG); break; - case TYPE_PCI1753E: - outb(0x88, dev->iobase + PCI1753E_ICR0); /* disable & clear - * interrupts */ - outb(0x80, dev->iobase + PCI1753E_ICR1); - outb(0x80, dev->iobase + PCI1753E_ICR2); - outb(0x80, dev->iobase + PCI1753E_ICR3); - /* fallthrough */ case TYPE_PCI1753: - outb(0x88, dev->iobase + PCI1753_ICR0); /* disable & clear - * interrupts */ - outb(0x80, dev->iobase + PCI1753_ICR1); - outb(0x80, dev->iobase + PCI1753_ICR2); - outb(0x80, dev->iobase + PCI1753_ICR3); + case TYPE_PCI1753E: + outb(0x88, dev->iobase + PCI1753_INT_REG(0)); + outb(0x80, dev->iobase + PCI1753_INT_REG(1)); + outb(0x80, dev->iobase + PCI1753_INT_REG(2)); + outb(0x80, dev->iobase + PCI1753_INT_REG(3)); + if (cardtype == TYPE_PCI1753E) { + outb(0x88, dev->iobase + PCI1753E_INT_REG(0)); + outb(0x80, dev->iobase + PCI1753E_INT_REG(1)); + outb(0x80, dev->iobase + PCI1753E_INT_REG(2)); + outb(0x80, dev->iobase + PCI1753E_INT_REG(3)); + } break; case TYPE_PCI1754: - outw(0x08, dev->iobase + PCI1754_6_ICR0); /* disable and clear - * interrupts */ - outw(0x08, dev->iobase + PCI1754_6_ICR1); - outw(0x08, dev->iobase + PCI1754_ICR2); - outw(0x08, dev->iobase + PCI1754_ICR3); - break; case TYPE_PCI1756: - outw(0, dev->iobase + PCI1752_6_CFC); /* disable channel freeze - * function */ - outw(0x08, dev->iobase + PCI1754_6_ICR0); /* disable and clear - * interrupts */ - outw(0x08, dev->iobase + PCI1754_6_ICR1); - outw(0, dev->iobase + PCI1756_IDO); /* clear outputs */ - outw(0, dev->iobase + PCI1756_IDO + 2); - break; - case TYPE_PCI1760: - pci1760_reset(dev); + outw(0x08, dev->iobase + PCI1754_INT_REG(0)); + outw(0x08, dev->iobase + PCI1754_INT_REG(1)); + if (cardtype == TYPE_PCI1754) { + outw(0x08, dev->iobase + PCI1754_INT_REG(2)); + outw(0x08, dev->iobase + PCI1754_INT_REG(3)); + } break; case TYPE_PCI1762: - outw(0x0101, dev->iobase + PCI1762_ICR); /* disable & clear - * interrupts */ - break; - } - - return 0; -} - -/* -============================================================================== -*/ -static int pci1760_attach(struct comedi_device *dev) -{ - struct comedi_subdevice *s; - - s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->n_chan = 8; - s->maxdata = 1; - s->len_chanlist = 8; - s->range_table = &range_digital; - s->insn_bits = pci1760_insn_bits_di; - - s = &dev->subdevices[1]; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 8; - s->maxdata = 1; - s->len_chanlist = 8; - s->range_table = &range_digital; - s->state = 0; - s->insn_bits = pci1760_insn_bits_do; - - s = &dev->subdevices[2]; - s->type = COMEDI_SUBD_TIMER; - s->subdev_flags = SDF_WRITABLE | SDF_LSAMPL; - s->n_chan = 2; - s->maxdata = 0xffffffff; - s->len_chanlist = 2; -/* s->insn_config=pci1760_insn_pwm_cfg; */ - - s = &dev->subdevices[3]; - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE; - s->n_chan = 8; - s->maxdata = 0xffff; - s->len_chanlist = 8; - s->insn_read = pci1760_insn_cnt_read; - s->insn_write = pci1760_insn_cnt_write; -/* s->insn_config=pci1760_insn_cnt_cfg; */ - - return 0; -} - -/* -============================================================================== -*/ -static int pci_dio_add_di(struct comedi_device *dev, - struct comedi_subdevice *s, - const struct diosubd_data *d) -{ - const struct dio_boardtype *board = dev->board_ptr; - - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE | d->specflags; - if (d->chans > 16) - s->subdev_flags |= SDF_LSAMPL; - s->n_chan = d->chans; - s->maxdata = 1; - s->len_chanlist = d->chans; - s->range_table = &range_digital; - switch (board->io_access) { - case IO_8b: - s->insn_bits = pci_dio_insn_bits_di_b; - break; - case IO_16b: - s->insn_bits = pci_dio_insn_bits_di_w; - break; - } - s->private = (void *)d; - - return 0; -} - -/* -============================================================================== -*/ -static int pci_dio_add_do(struct comedi_device *dev, - struct comedi_subdevice *s, - const struct diosubd_data *d) -{ - const struct dio_boardtype *board = dev->board_ptr; - - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - if (d->chans > 16) - s->subdev_flags |= SDF_LSAMPL; - s->n_chan = d->chans; - s->maxdata = 1; - s->len_chanlist = d->chans; - s->range_table = &range_digital; - s->state = 0; - switch (board->io_access) { - case IO_8b: - s->insn_bits = pci_dio_insn_bits_do_b; + outw(0x0101, dev->iobase + PCI1762_INT_REG); break; - case IO_16b: - s->insn_bits = pci_dio_insn_bits_do_w; + default: break; } - s->private = (void *)d; return 0; } -static unsigned long pci_dio_override_cardtype(struct pci_dev *pcidev, - unsigned long cardtype) -{ - /* - * Change cardtype from TYPE_PCI1753 to TYPE_PCI1753E if expansion - * board available. Need to enable PCI device and request the main - * registers PCI BAR temporarily to perform the test. - */ - if (cardtype != TYPE_PCI1753) - return cardtype; - if (pci_enable_device(pcidev) < 0) - return cardtype; - if (pci_request_region(pcidev, PCIDIO_MAINREG, "adv_pci_dio") == 0) { - /* - * This test is based on Advantech's "advdaq" driver source - * (which declares its module licence as "GPL" although the - * driver source does not include a "COPYING" file). - */ - unsigned long reg = - pci_resource_start(pcidev, PCIDIO_MAINREG) + 53; - - outb(0x05, reg); - if ((inb(reg) & 0x07) == 0x02) { - outb(0x02, reg); - if ((inb(reg) & 0x07) == 0x05) - cardtype = TYPE_PCI1753E; - } - pci_release_region(pcidev, PCIDIO_MAINREG); - } - pci_disable_device(pcidev); - return cardtype; -} - static int pci_dio_auto_attach(struct comedi_device *dev, unsigned long context) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); const struct dio_boardtype *board = NULL; - struct pci_dio_private *devpriv; + const struct diosubd_data *d; struct comedi_subdevice *s; int ret, subdev, i, j; @@ -990,54 +335,93 @@ static int pci_dio_auto_attach(struct comedi_device *dev, dev->board_ptr = board; dev->board_name = board->name; - devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); - if (!devpriv) - return -ENOMEM; - ret = comedi_pci_enable(dev); if (ret) return ret; - dev->iobase = pci_resource_start(pcidev, board->main_pci_region); + if (context == TYPE_PCI1736) + dev->iobase = pci_resource_start(pcidev, 0); + else + dev->iobase = pci_resource_start(pcidev, 2); + + pci_dio_reset(dev, context); ret = comedi_alloc_subdevices(dev, board->nsubdevs); if (ret) return ret; subdev = 0; - for (i = 0; i < MAX_DI_SUBDEVS; i++) - if (board->sdi[i].chans) { - s = &dev->subdevices[subdev]; - pci_dio_add_di(dev, s, &board->sdi[i]); - subdev++; + for (i = 0; i < PCI_DIO_MAX_DI_SUBDEVS; i++) { + d = &board->sdi[i]; + if (d->chans) { + s = &dev->subdevices[subdev++]; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = d->chans; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = board->is_16bit + ? pci_dio_insn_bits_di_w + : pci_dio_insn_bits_di_b; + s->private = (void *)d->addr; } + } - for (i = 0; i < MAX_DO_SUBDEVS; i++) - if (board->sdo[i].chans) { - s = &dev->subdevices[subdev]; - pci_dio_add_do(dev, s, &board->sdo[i]); - subdev++; + for (i = 0; i < PCI_DIO_MAX_DO_SUBDEVS; i++) { + d = &board->sdo[i]; + if (d->chans) { + s = &dev->subdevices[subdev++]; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = d->chans; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = board->is_16bit + ? pci_dio_insn_bits_do_w + : pci_dio_insn_bits_do_b; + s->private = (void *)d->addr; + + /* reset all outputs to 0 */ + if (board->is_16bit) { + outw(0, dev->iobase + d->addr); + if (s->n_chan > 16) + outw(0, dev->iobase + d->addr + 2); + } else { + outb(0, dev->iobase + d->addr); + if (s->n_chan > 8) + outb(0, dev->iobase + d->addr + 1); + if (s->n_chan > 16) + outb(0, dev->iobase + d->addr + 2); + if (s->n_chan > 24) + outb(0, dev->iobase + d->addr + 3); + } } + } - for (i = 0; i < MAX_DIO_SUBDEVG; i++) - for (j = 0; j < board->sdio[i].regs; j++) { - s = &dev->subdevices[subdev]; + for (i = 0; i < PCI_DIO_MAX_DIO_SUBDEVG; i++) { + d = &board->sdio[i]; + for (j = 0; j < d->chans; j++) { + s = &dev->subdevices[subdev++]; ret = subdev_8255_init(dev, s, NULL, - board->sdio[i].addr + - j * I8255_SIZE); + d->addr + j * I8255_SIZE); if (ret) return ret; - subdev++; } + } - if (board->boardid.chans) { - s = &dev->subdevices[subdev]; - s->type = COMEDI_SUBD_DI; - pci_dio_add_di(dev, s, &board->boardid); - subdev++; + if (board->id_reg) { + s = &dev->subdevices[subdev++]; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE | SDF_INTERNAL; + s->n_chan = 4; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = board->is_16bit ? pci_dio_insn_bits_di_w + : pci_dio_insn_bits_di_b; + s->private = (void *)board->id_reg; } if (board->timer_regbase) { - s = &dev->subdevices[subdev]; + s = &dev->subdevices[subdev++]; dev->pacer = comedi_8254_init(dev->iobase + board->timer_regbase, @@ -1046,32 +430,50 @@ static int pci_dio_auto_attach(struct comedi_device *dev, return -ENOMEM; comedi_8254_subdevice_init(s, dev->pacer); - - subdev++; } - if (board->cardtype == TYPE_PCI1760) - pci1760_attach(dev); - - pci_dio_reset(dev); - return 0; } -static void pci_dio_detach(struct comedi_device *dev) -{ - if (dev->iobase) - pci_dio_reset(dev); - comedi_pci_detach(dev); -} - static struct comedi_driver adv_pci_dio_driver = { .driver_name = "adv_pci_dio", .module = THIS_MODULE, .auto_attach = pci_dio_auto_attach, - .detach = pci_dio_detach, + .detach = comedi_pci_detach, }; +static unsigned long pci_dio_override_cardtype(struct pci_dev *pcidev, + unsigned long cardtype) +{ + /* + * Change cardtype from TYPE_PCI1753 to TYPE_PCI1753E if expansion + * board available. Need to enable PCI device and request the main + * registers PCI BAR temporarily to perform the test. + */ + if (cardtype != TYPE_PCI1753) + return cardtype; + if (pci_enable_device(pcidev) < 0) + return cardtype; + if (pci_request_region(pcidev, 2, "adv_pci_dio") == 0) { + /* + * This test is based on Advantech's "advdaq" driver source + * (which declares its module licence as "GPL" although the + * driver source does not include a "COPYING" file). + */ + unsigned long reg = pci_resource_start(pcidev, 2) + 53; + + outb(0x05, reg); + if ((inb(reg) & 0x07) == 0x02) { + outb(0x02, reg); + if ((inb(reg) & 0x07) == 0x05) + cardtype = TYPE_PCI1753E; + } + pci_release_region(pcidev, 2); + } + pci_disable_device(pcidev); + return cardtype; +} + static int adv_pci_dio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { @@ -1094,7 +496,6 @@ static const struct pci_device_id adv_pci_dio_pci_table[] = { { PCI_VDEVICE(ADVANTECH, 0x1753), TYPE_PCI1753 }, { PCI_VDEVICE(ADVANTECH, 0x1754), TYPE_PCI1754 }, { PCI_VDEVICE(ADVANTECH, 0x1756), TYPE_PCI1756 }, - { PCI_VDEVICE(ADVANTECH, 0x1760), TYPE_PCI1760 }, { PCI_VDEVICE(ADVANTECH, 0x1762), TYPE_PCI1762 }, { 0 } }; @@ -1109,5 +510,5 @@ static struct pci_driver adv_pci_dio_pci_driver = { module_comedi_pci_driver(adv_pci_dio_driver, adv_pci_dio_pci_driver); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_DESCRIPTION("Comedi driver for Advantech Digital I/O Cards"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c index b2f7679a0116..cac011fdd375 100644 --- a/drivers/staging/comedi/drivers/amplc_pci224.c +++ b/drivers/staging/comedi/drivers/amplc_pci224.c @@ -1022,14 +1022,17 @@ pci224_auto_attach(struct comedi_device *dev, unsigned long context_model) irq = pci_dev->irq; /* Allocate buffer to hold values for AO channel scan. */ - devpriv->ao_scan_vals = kmalloc(sizeof(devpriv->ao_scan_vals[0]) * - board->ao_chans, GFP_KERNEL); + devpriv->ao_scan_vals = kmalloc_array(board->ao_chans, + sizeof(devpriv->ao_scan_vals[0]), + GFP_KERNEL); if (!devpriv->ao_scan_vals) return -ENOMEM; /* Allocate buffer to hold AO channel scan order. */ - devpriv->ao_scan_order = kmalloc(sizeof(devpriv->ao_scan_order[0]) * - board->ao_chans, GFP_KERNEL); + devpriv->ao_scan_order = + kmalloc_array(board->ao_chans, + sizeof(devpriv->ao_scan_order[0]), + GFP_KERNEL); if (!devpriv->ao_scan_order) return -ENOMEM; diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c b/drivers/staging/comedi/drivers/cb_pcidda.c index b00a36a5cb36..ccb37d1f0f8e 100644 --- a/drivers/staging/comedi/drivers/cb_pcidda.c +++ b/drivers/staging/comedi/drivers/cb_pcidda.c @@ -51,13 +51,13 @@ /* DAC registers */ #define CB_DDA_DA_CTRL_REG 0x00 /* D/A Control Register */ -#define CB_DDA_DA_CTRL_SU (1 << 0) /* Simultaneous update */ -#define CB_DDA_DA_CTRL_EN (1 << 1) /* Enable specified DAC */ +#define CB_DDA_DA_CTRL_SU BIT(0) /* Simultaneous update */ +#define CB_DDA_DA_CTRL_EN BIT(1) /* Enable specified DAC */ #define CB_DDA_DA_CTRL_DAC(x) ((x) << 2) /* Specify DAC channel */ #define CB_DDA_DA_CTRL_RANGE2V5 (0 << 6) /* 2.5V range */ #define CB_DDA_DA_CTRL_RANGE5V (2 << 6) /* 5V range */ #define CB_DDA_DA_CTRL_RANGE10V (3 << 6) /* 10V range */ -#define CB_DDA_DA_CTRL_UNIP (1 << 8) /* Unipolar range */ +#define CB_DDA_DA_CTRL_UNIP BIT(8) /* Unipolar range */ #define DACALIBRATION1 4 /* D/A CALIBRATION REGISTER 1 */ /* write bits */ diff --git a/drivers/staging/comedi/drivers/comedi_parport.c b/drivers/staging/comedi/drivers/comedi_parport.c index 15a4093efda1..1bf8ddc6f07c 100644 --- a/drivers/staging/comedi/drivers/comedi_parport.c +++ b/drivers/staging/comedi/drivers/comedi_parport.c @@ -75,8 +75,8 @@ #define PARPORT_DATA_REG 0x00 #define PARPORT_STATUS_REG 0x01 #define PARPORT_CTRL_REG 0x02 -#define PARPORT_CTRL_IRQ_ENA (1 << 4) -#define PARPORT_CTRL_BIDIR_ENA (1 << 5) +#define PARPORT_CTRL_IRQ_ENA BIT(4) +#define PARPORT_CTRL_BIDIR_ENA BIT(5) static int parport_data_reg_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c index 056bca9c67d5..fd8e0b76f764 100644 --- a/drivers/staging/comedi/drivers/das16.c +++ b/drivers/staging/comedi/drivers/das16.c @@ -801,9 +801,10 @@ static void das16_ai_munge(struct comedi_device *dev, unsigned short *data = array; unsigned int num_samples = comedi_bytes_to_samples(s, num_bytes); unsigned int i; + __le16 *buf = array; for (i = 0; i < num_samples; i++) { - data[i] = le16_to_cpu(data[i]); + data[i] = le16_to_cpu(buf[i]); if (s->maxdata == 0x0fff) data[i] >>= 4; data[i] &= s->maxdata; diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c index 62a817e4cd64..84c62e256094 100644 --- a/drivers/staging/comedi/drivers/ni_6527.c +++ b/drivers/staging/comedi/drivers/ni_6527.c @@ -42,24 +42,24 @@ #define NI6527_DO_REG(x) (0x03 + (x)) #define NI6527_ID_REG 0x06 #define NI6527_CLR_REG 0x07 -#define NI6527_CLR_EDGE (1 << 3) -#define NI6527_CLR_OVERFLOW (1 << 2) -#define NI6527_CLR_FILT (1 << 1) -#define NI6527_CLR_INTERVAL (1 << 0) +#define NI6527_CLR_EDGE BIT(3) +#define NI6527_CLR_OVERFLOW BIT(2) +#define NI6527_CLR_FILT BIT(1) +#define NI6527_CLR_INTERVAL BIT(0) #define NI6527_CLR_IRQS (NI6527_CLR_EDGE | NI6527_CLR_OVERFLOW) #define NI6527_CLR_RESET_FILT (NI6527_CLR_FILT | NI6527_CLR_INTERVAL) #define NI6527_FILT_INTERVAL_REG(x) (0x08 + (x)) #define NI6527_FILT_ENA_REG(x) (0x0c + (x)) #define NI6527_STATUS_REG 0x14 -#define NI6527_STATUS_IRQ (1 << 2) -#define NI6527_STATUS_OVERFLOW (1 << 1) -#define NI6527_STATUS_EDGE (1 << 0) +#define NI6527_STATUS_IRQ BIT(2) +#define NI6527_STATUS_OVERFLOW BIT(1) +#define NI6527_STATUS_EDGE BIT(0) #define NI6527_CTRL_REG 0x15 -#define NI6527_CTRL_FALLING (1 << 4) -#define NI6527_CTRL_RISING (1 << 3) -#define NI6527_CTRL_IRQ (1 << 2) -#define NI6527_CTRL_OVERFLOW (1 << 1) -#define NI6527_CTRL_EDGE (1 << 0) +#define NI6527_CTRL_FALLING BIT(4) +#define NI6527_CTRL_RISING BIT(3) +#define NI6527_CTRL_IRQ BIT(2) +#define NI6527_CTRL_OVERFLOW BIT(1) +#define NI6527_CTRL_EDGE BIT(0) #define NI6527_CTRL_DISABLE_IRQS 0 #define NI6527_CTRL_ENABLE_IRQS (NI6527_CTRL_FALLING | \ NI6527_CTRL_RISING | \ diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c index 800d57426070..251117be1205 100644 --- a/drivers/staging/comedi/drivers/ni_65xx.c +++ b/drivers/staging/comedi/drivers/ni_65xx.c @@ -68,25 +68,25 @@ /* Non-recurring Registers (8-bit except where noted) */ #define NI_65XX_ID_REG 0x00 #define NI_65XX_CLR_REG 0x01 -#define NI_65XX_CLR_WDOG_INT (1 << 6) -#define NI_65XX_CLR_WDOG_PING (1 << 5) -#define NI_65XX_CLR_WDOG_EXP (1 << 4) -#define NI_65XX_CLR_EDGE_INT (1 << 3) -#define NI_65XX_CLR_OVERFLOW_INT (1 << 2) +#define NI_65XX_CLR_WDOG_INT BIT(6) +#define NI_65XX_CLR_WDOG_PING BIT(5) +#define NI_65XX_CLR_WDOG_EXP BIT(4) +#define NI_65XX_CLR_EDGE_INT BIT(3) +#define NI_65XX_CLR_OVERFLOW_INT BIT(2) #define NI_65XX_STATUS_REG 0x02 -#define NI_65XX_STATUS_WDOG_INT (1 << 5) -#define NI_65XX_STATUS_FALL_EDGE (1 << 4) -#define NI_65XX_STATUS_RISE_EDGE (1 << 3) -#define NI_65XX_STATUS_INT (1 << 2) -#define NI_65XX_STATUS_OVERFLOW_INT (1 << 1) -#define NI_65XX_STATUS_EDGE_INT (1 << 0) +#define NI_65XX_STATUS_WDOG_INT BIT(5) +#define NI_65XX_STATUS_FALL_EDGE BIT(4) +#define NI_65XX_STATUS_RISE_EDGE BIT(3) +#define NI_65XX_STATUS_INT BIT(2) +#define NI_65XX_STATUS_OVERFLOW_INT BIT(1) +#define NI_65XX_STATUS_EDGE_INT BIT(0) #define NI_65XX_CTRL_REG 0x03 -#define NI_65XX_CTRL_WDOG_ENA (1 << 5) -#define NI_65XX_CTRL_FALL_EDGE_ENA (1 << 4) -#define NI_65XX_CTRL_RISE_EDGE_ENA (1 << 3) -#define NI_65XX_CTRL_INT_ENA (1 << 2) -#define NI_65XX_CTRL_OVERFLOW_ENA (1 << 1) -#define NI_65XX_CTRL_EDGE_ENA (1 << 0) +#define NI_65XX_CTRL_WDOG_ENA BIT(5) +#define NI_65XX_CTRL_FALL_EDGE_ENA BIT(4) +#define NI_65XX_CTRL_RISE_EDGE_ENA BIT(3) +#define NI_65XX_CTRL_INT_ENA BIT(2) +#define NI_65XX_CTRL_OVERFLOW_ENA BIT(1) +#define NI_65XX_CTRL_EDGE_ENA BIT(0) #define NI_65XX_REV_REG 0x04 /* 32-bit */ #define NI_65XX_FILTER_REG 0x08 /* 32-bit */ #define NI_65XX_RTSI_ROUTE_REG 0x0c /* 16-bit */ @@ -94,24 +94,24 @@ #define NI_65XX_RTSI_WDOG_REG 0x10 /* 16-bit */ #define NI_65XX_RTSI_TRIG_REG 0x12 /* 16-bit */ #define NI_65XX_AUTO_CLK_SEL_REG 0x14 /* PXI-6528 only */ -#define NI_65XX_AUTO_CLK_SEL_STATUS (1 << 1) -#define NI_65XX_AUTO_CLK_SEL_DISABLE (1 << 0) +#define NI_65XX_AUTO_CLK_SEL_STATUS BIT(1) +#define NI_65XX_AUTO_CLK_SEL_DISABLE BIT(0) #define NI_65XX_WDOG_CTRL_REG 0x15 -#define NI_65XX_WDOG_CTRL_ENA (1 << 0) +#define NI_65XX_WDOG_CTRL_ENA BIT(0) #define NI_65XX_RTSI_CFG_REG 0x16 -#define NI_65XX_RTSI_CFG_RISE_SENSE (1 << 2) -#define NI_65XX_RTSI_CFG_FALL_SENSE (1 << 1) -#define NI_65XX_RTSI_CFG_SYNC_DETECT (1 << 0) +#define NI_65XX_RTSI_CFG_RISE_SENSE BIT(2) +#define NI_65XX_RTSI_CFG_FALL_SENSE BIT(1) +#define NI_65XX_RTSI_CFG_SYNC_DETECT BIT(0) #define NI_65XX_WDOG_STATUS_REG 0x17 -#define NI_65XX_WDOG_STATUS_EXP (1 << 0) +#define NI_65XX_WDOG_STATUS_EXP BIT(0) #define NI_65XX_WDOG_INTERVAL_REG 0x18 /* 32-bit */ /* Recurring port registers (8-bit) */ #define NI_65XX_PORT(x) ((x) * 0x10) #define NI_65XX_IO_DATA_REG(x) (0x40 + NI_65XX_PORT(x)) #define NI_65XX_IO_SEL_REG(x) (0x41 + NI_65XX_PORT(x)) -#define NI_65XX_IO_SEL_OUTPUT (0 << 0) -#define NI_65XX_IO_SEL_INPUT (1 << 0) +#define NI_65XX_IO_SEL_OUTPUT 0 +#define NI_65XX_IO_SEL_INPUT BIT(0) #define NI_65XX_RISE_EDGE_ENA_REG(x) (0x42 + NI_65XX_PORT(x)) #define NI_65XX_FALL_EDGE_ENA_REG(x) (0x43 + NI_65XX_PORT(x)) #define NI_65XX_FILTER_ENA(x) (0x44 + NI_65XX_PORT(x)) @@ -613,7 +613,7 @@ static int ni_65xx_intr_insn_config(struct comedi_device *dev, /* ripped from mite.h and mite_setup2() to avoid mite dependency */ #define MITE_IODWBSR 0xc0 /* IO Device Window Base Size Register */ -#define WENAB (1 << 7) /* window enable */ +#define WENAB BIT(7) /* window enable */ static int ni_65xx_mite_init(struct pci_dev *pcidev) { diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c index f4c580f65a89..3e72718801a9 100644 --- a/drivers/staging/comedi/drivers/ni_670x.c +++ b/drivers/staging/comedi/drivers/ni_670x.c @@ -214,8 +214,9 @@ static int ni_670x_auto_attach(struct comedi_device *dev, if (s->n_chan == 32) { const struct comedi_lrange **range_table_list; - range_table_list = kmalloc(sizeof(struct comedi_lrange *) * 32, - GFP_KERNEL); + range_table_list = kmalloc_array(32, + sizeof(struct comedi_lrange *), + GFP_KERNEL); if (!range_table_list) return -ENOMEM; s->range_table_list = range_table_list; diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c index 6cc304a4c59b..5e8130a7d670 100644 --- a/drivers/staging/comedi/drivers/ni_mio_common.c +++ b/drivers/staging/comedi/drivers/ni_mio_common.c @@ -579,48 +579,54 @@ static inline unsigned ni_stc_dma_channel_select_bitfield(unsigned channel) return 0; } -/* negative channel means no channel */ -static inline void ni_set_ai_dma_channel(struct comedi_device *dev, int channel) +static inline void ni_set_ai_dma_channel(struct comedi_device *dev, + unsigned channel) { - unsigned bits = 0; - - if (channel >= 0) - bits = ni_stc_dma_channel_select_bitfield(channel); + unsigned bits = ni_stc_dma_channel_select_bitfield(channel); ni_set_bitfield(dev, NI_E_DMA_AI_AO_SEL_REG, NI_E_DMA_AI_SEL_MASK, NI_E_DMA_AI_SEL(bits)); } -/* negative channel means no channel */ -static inline void ni_set_ao_dma_channel(struct comedi_device *dev, int channel) +static inline void ni_set_ai_dma_no_channel(struct comedi_device *dev) { - unsigned bits = 0; + ni_set_bitfield(dev, NI_E_DMA_AI_AO_SEL_REG, NI_E_DMA_AI_SEL_MASK, 0); +} - if (channel >= 0) - bits = ni_stc_dma_channel_select_bitfield(channel); +static inline void ni_set_ao_dma_channel(struct comedi_device *dev, + unsigned channel) +{ + unsigned bits = ni_stc_dma_channel_select_bitfield(channel); ni_set_bitfield(dev, NI_E_DMA_AI_AO_SEL_REG, NI_E_DMA_AO_SEL_MASK, NI_E_DMA_AO_SEL(bits)); } -/* negative channel means no channel */ +static inline void ni_set_ao_dma_no_channel(struct comedi_device *dev) +{ + ni_set_bitfield(dev, NI_E_DMA_AI_AO_SEL_REG, NI_E_DMA_AO_SEL_MASK, 0); +} + static inline void ni_set_gpct_dma_channel(struct comedi_device *dev, unsigned gpct_index, - int channel) + unsigned channel) { - unsigned bits = 0; - - if (channel >= 0) - bits = ni_stc_dma_channel_select_bitfield(channel); + unsigned bits = ni_stc_dma_channel_select_bitfield(channel); ni_set_bitfield(dev, NI_E_DMA_G0_G1_SEL_REG, NI_E_DMA_G0_G1_SEL_MASK(gpct_index), NI_E_DMA_G0_G1_SEL(gpct_index, bits)); } -/* negative mite_channel means no channel */ +static inline void ni_set_gpct_dma_no_channel(struct comedi_device *dev, + unsigned gpct_index) +{ + ni_set_bitfield(dev, NI_E_DMA_G0_G1_SEL_REG, + NI_E_DMA_G0_G1_SEL_MASK(gpct_index), 0); +} + static inline void ni_set_cdo_dma_channel(struct comedi_device *dev, - int mite_channel) + unsigned mite_channel) { struct ni_private *devpriv = dev->private; unsigned long flags; @@ -628,16 +634,26 @@ static inline void ni_set_cdo_dma_channel(struct comedi_device *dev, spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags); devpriv->cdio_dma_select_reg &= ~NI_M_CDIO_DMA_SEL_CDO_MASK; - if (mite_channel >= 0) { - /* - * XXX just guessing ni_stc_dma_channel_select_bitfield() - * returns the right bits, under the assumption the cdio dma - * selection works just like ai/ao/gpct. - * Definitely works for dma channels 0 and 1. - */ - bits = ni_stc_dma_channel_select_bitfield(mite_channel); - devpriv->cdio_dma_select_reg |= NI_M_CDIO_DMA_SEL_CDO(bits); - } + /* + * XXX just guessing ni_stc_dma_channel_select_bitfield() + * returns the right bits, under the assumption the cdio dma + * selection works just like ai/ao/gpct. + * Definitely works for dma channels 0 and 1. + */ + bits = ni_stc_dma_channel_select_bitfield(mite_channel); + devpriv->cdio_dma_select_reg |= NI_M_CDIO_DMA_SEL_CDO(bits); + ni_writeb(dev, devpriv->cdio_dma_select_reg, NI_M_CDIO_DMA_SEL_REG); + mmiowb(); + spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags); +} + +static inline void ni_set_cdo_dma_no_channel(struct comedi_device *dev) +{ + struct ni_private *devpriv = dev->private; + unsigned long flags; + + spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags); + devpriv->cdio_dma_select_reg &= ~NI_M_CDIO_DMA_SEL_CDO_MASK; ni_writeb(dev, devpriv->cdio_dma_select_reg, NI_M_CDIO_DMA_SEL_REG); mmiowb(); spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags); @@ -745,7 +761,7 @@ static void ni_release_ai_mite_channel(struct comedi_device *dev) spin_lock_irqsave(&devpriv->mite_channel_lock, flags); if (devpriv->ai_mite_chan) { - ni_set_ai_dma_channel(dev, -1); + ni_set_ai_dma_no_channel(dev); mite_release_channel(devpriv->ai_mite_chan); devpriv->ai_mite_chan = NULL; } @@ -761,7 +777,7 @@ static void ni_release_ao_mite_channel(struct comedi_device *dev) spin_lock_irqsave(&devpriv->mite_channel_lock, flags); if (devpriv->ao_mite_chan) { - ni_set_ao_dma_channel(dev, -1); + ni_set_ao_dma_no_channel(dev); mite_release_channel(devpriv->ao_mite_chan); devpriv->ao_mite_chan = NULL; } @@ -781,7 +797,7 @@ static void ni_release_gpct_mite_channel(struct comedi_device *dev, struct mite_channel *mite_chan = devpriv->counter_dev->counters[gpct_index].mite_chan; - ni_set_gpct_dma_channel(dev, gpct_index, -1); + ni_set_gpct_dma_no_channel(dev, gpct_index); ni_tio_set_mite_channel(&devpriv-> counter_dev->counters[gpct_index], NULL); @@ -799,7 +815,7 @@ static void ni_release_cdo_mite_channel(struct comedi_device *dev) spin_lock_irqsave(&devpriv->mite_channel_lock, flags); if (devpriv->cdo_mite_chan) { - ni_set_cdo_dma_channel(dev, -1); + ni_set_cdo_dma_no_channel(dev); mite_release_channel(devpriv->cdo_mite_chan); devpriv->cdo_mite_chan = NULL; } @@ -1516,13 +1532,17 @@ static void ni_ai_munge(struct comedi_device *dev, struct comedi_subdevice *s, unsigned short *array = data; unsigned int *larray = data; unsigned int i; +#ifdef PCIDMA + __le16 *barray = data; + __le32 *blarray = data; +#endif for (i = 0; i < nsamples; i++) { #ifdef PCIDMA if (s->subdev_flags & SDF_LSAMPL) - larray[i] = le32_to_cpu(larray[i]); + larray[i] = le32_to_cpu(blarray[i]); else - array[i] = le16_to_cpu(array[i]); + array[i] = le16_to_cpu(barray[i]); #endif if (s->subdev_flags & SDF_LSAMPL) larray[i] += devpriv->ai_offset[chan_index]; @@ -2574,6 +2594,9 @@ static void ni_ao_munge(struct comedi_device *dev, struct comedi_subdevice *s, unsigned int nsamples = comedi_bytes_to_samples(s, num_bytes); unsigned short *array = data; unsigned int i; +#ifdef PCIDMA + __le16 buf, *barray = data; +#endif for (i = 0; i < nsamples; i++) { unsigned int range = CR_RANGE(cmd->chanlist[chan_index]); @@ -2586,10 +2609,11 @@ static void ni_ao_munge(struct comedi_device *dev, struct comedi_subdevice *s, if (comedi_range_is_bipolar(s, range)) val = comedi_offset_munge(s, val); #ifdef PCIDMA - val = cpu_to_le16(val); -#endif + buf = cpu_to_le16(val); + barray[i] = buf; +#else array[i] = val; - +#endif chan_index++; chan_index %= cmd->chanlist_len; } diff --git a/drivers/staging/comedi/drivers/plx9080.h b/drivers/staging/comedi/drivers/plx9080.h index 25706531b885..f5cd6d5004bd 100644 --- a/drivers/staging/comedi/drivers/plx9080.h +++ b/drivers/staging/comedi/drivers/plx9080.h @@ -1,4 +1,5 @@ -/* plx9080.h +/* + * plx9080.h * * Copyright (C) 2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net> * @@ -33,8 +34,10 @@ struct plx_dma_desc { __le32 local_start_addr; /* transfer_size is in bytes, only first 23 bits of register are used */ __le32 transfer_size; - /* address of next descriptor (quad word aligned), plus some - * additional bits (see PLX_DMA0_DESCRIPTOR_REG) */ + /* + * address of next descriptor (quad word aligned), plus some + * additional bits (see PLX_DMA0_DESCRIPTOR_REG) + */ __le32 next; }; @@ -46,23 +49,31 @@ struct plx_dma_desc { ** **********************************************************************/ -#define PLX_LAS0RNG_REG 0x0000 /* L, Local Addr Space 0 Range Register */ -#define PLX_LAS1RNG_REG 0x00f0 /* L, Local Addr Space 1 Range Register */ +/* L, Local Addr Space 0 Range Register */ +#define PLX_LAS0RNG_REG 0x0000 +/* L, Local Addr Space 1 Range Register */ +#define PLX_LAS1RNG_REG 0x00f0 #define LRNG_IO 0x00000001 /* Map to: 1=I/O, 0=Mem */ #define LRNG_ANY32 0x00000000 /* Locate anywhere in 32 bit */ #define LRNG_LT1MB 0x00000002 /* Locate in 1st meg */ #define LRNG_ANY64 0x00000004 /* Locate anywhere in 64 bit */ -#define LRNG_MEM_MASK 0xfffffff0 /* bits that specify range for memory io */ -#define LRNG_IO_MASK 0xfffffffa /* bits that specify range for normal io */ - -#define PLX_LAS0MAP_REG 0x0004 /* L, Local Addr Space 0 Remap Register */ -#define PLX_LAS1MAP_REG 0x00f4 /* L, Local Addr Space 1 Remap Register */ +/* bits that specify range for memory io */ +#define LRNG_MEM_MASK 0xfffffff0 +/* bits that specify range for normal io */ +#define LRNG_IO_MASK 0xfffffffa +/* L, Local Addr Space 0 Remap Register */ +#define PLX_LAS0MAP_REG 0x0004 +/* L, Local Addr Space 1 Remap Register */ +#define PLX_LAS1MAP_REG 0x00f4 #define LMAP_EN 0x00000001 /* Enable slave decode */ -#define LMAP_MEM_MASK 0xfffffff0 /* bits that specify decode for memory io */ -#define LMAP_IO_MASK 0xfffffffa /* bits that specify decode bits for normal io */ +/* bits that specify decode for memory io */ +#define LMAP_MEM_MASK 0xfffffff0 +/* bits that specify decode bits for normal io */ +#define LMAP_IO_MASK 0xfffffffa -/* Mode/Arbitration Register. -*/ +/* + * Mode/Arbitration Register. + */ #define PLX_MARB_REG 0x8 /* L, Local Arbitration Register */ #define PLX_DMAARB_REG 0xac enum marb_bits { @@ -72,35 +83,45 @@ enum marb_bits { MARB_LPEN = 0x00020000, /* Pause Timer Enable */ MARB_BREQ = 0x00040000, /* Local Bus BREQ Enable */ MARB_DMA_PRIORITY_MASK = 0x00180000, - MARB_LBDS_GIVE_UP_BUS_MODE = 0x00200000, /* local bus direct slave give up bus mode */ - MARB_DS_LLOCK_ENABLE = 0x00400000, /* direct slave LLOCKo# enable */ + /* local bus direct slave give up bus mode */ + MARB_LBDS_GIVE_UP_BUS_MODE = 0x00200000, + /* direct slave LLOCKo# enable */ + MARB_DS_LLOCK_ENABLE = 0x00400000, MARB_PCI_REQUEST_MODE = 0x00800000, MARB_PCIv21_MODE = 0x01000000, /* pci specification v2.1 mode */ MARB_PCI_READ_NO_WRITE_MODE = 0x02000000, MARB_PCI_READ_WITH_WRITE_FLUSH_MODE = 0x04000000, - MARB_GATE_TIMER_WITH_BREQ = 0x08000000, /* gate local bus latency timer with BREQ */ + /* gate local bus latency timer with BREQ */ + MARB_GATE_TIMER_WITH_BREQ = 0x08000000, MARB_PCI_READ_NO_FLUSH_MODE = 0x10000000, MARB_USE_SUBSYSTEM_IDS = 0x20000000, }; #define PLX_BIGEND_REG 0xc enum bigend_bits { - BIGEND_CONFIG = 0x1, /* use big endian ordering for configuration register accesses */ + /* use big endian ordering for configuration register accesses */ + BIGEND_CONFIG = 0x1, BIGEND_DIRECT_MASTER = 0x2, BIGEND_DIRECT_SLAVE_LOCAL0 = 0x4, BIGEND_ROM = 0x8, - BIGEND_BYTE_LANE = 0x10, /* use byte lane consisting of most significant bits instead of least significant */ + /* + * use byte lane consisting of most significant bits instead of + * least significant + */ + BIGEND_BYTE_LANE = 0x10, BIGEND_DIRECT_SLAVE_LOCAL1 = 0x20, BIGEND_DMA1 = 0x40, BIGEND_DMA0 = 0x80, }; -/* Note: The Expansion ROM stuff is only relevant to the PC environment. +/* +** Note: The Expansion ROM stuff is only relevant to the PC environment. ** This expansion ROM code is executed by the host CPU at boot time. ** For this reason no bit definitions are provided here. -*/ + */ #define PLX_ROMRNG_REG 0x0010 /* L, Expn ROM Space Range Register */ -#define PLX_ROMMAP_REG 0x0014 /* L, Local Addr Space Range Register */ +/* L, Local Addr Space Range Register */ +#define PLX_ROMMAP_REG 0x0014 #define PLX_REGION0_REG 0x0018 /* L, Local Bus Region 0 Descriptor */ #define RGN_WIDTH 0x00000002 /* Local bus width bits */ @@ -190,7 +211,8 @@ enum bigend_bits { #define ICS_TA_DMA0 0x02000000 /* Target Abort - DMA #0 */ #define ICS_TA_DMA1 0x04000000 /* Target Abort - DMA #1 */ #define ICS_TA_RA 0x08000000 /* Target Abort - Retry Timeout */ -#define ICS_MBIA(x) (0x10000000 << ((x) & 0x3)) /* mailbox x is active */ +/* mailbox x is active */ +#define ICS_MBIA(x) (0x10000000 << ((x) & 0x3)) #define PLX_CONTROL_REG 0x006C /* L, EEPROM Cntl & PCI Cmd Codes */ #define CTL_RDMA 0x0000000E /* DMA Read Command */ @@ -221,28 +243,38 @@ enum bigend_bits { #define PLX_EN_BTERM_BIT 0x80 /* enable BTERM# input */ #define PLX_DMA_LOCAL_BURST_EN_BIT 0x100 /* enable local burst mode */ #define PLX_EN_CHAIN_BIT 0x200 /* enables chaining */ -#define PLX_EN_DMA_DONE_INTR_BIT 0x400 /* enables interrupt on dma done */ -#define PLX_LOCAL_ADDR_CONST_BIT 0x800 /* hold local address constant (don't increment) */ -#define PLX_DEMAND_MODE_BIT 0x1000 /* enables demand-mode for dma transfer */ +/* enables interrupt on dma done */ +#define PLX_EN_DMA_DONE_INTR_BIT 0x400 +/* hold local address constant (don't increment) */ +#define PLX_LOCAL_ADDR_CONST_BIT 0x800 +/* enables demand-mode for dma transfer */ +#define PLX_DEMAND_MODE_BIT 0x1000 #define PLX_EOT_ENABLE_BIT 0x4000 #define PLX_STOP_MODE_BIT 0x8000 -#define PLX_DMA_INTR_PCI_BIT 0x20000 /* routes dma interrupt to pci bus (instead of local bus) */ +/* routes dma interrupt to pci bus (instead of local bus) */ +#define PLX_DMA_INTR_PCI_BIT 0x20000 -#define PLX_DMA0_PCI_ADDRESS_REG 0x84 /* pci address that dma transfers start at */ +/* pci address that dma transfers start at */ +#define PLX_DMA0_PCI_ADDRESS_REG 0x84 #define PLX_DMA1_PCI_ADDRESS_REG 0x98 -#define PLX_DMA0_LOCAL_ADDRESS_REG 0x88 /* local address that dma transfers start at */ +/* local address that dma transfers start at */ +#define PLX_DMA0_LOCAL_ADDRESS_REG 0x88 #define PLX_DMA1_LOCAL_ADDRESS_REG 0x9c -#define PLX_DMA0_TRANSFER_SIZE_REG 0x8c /* number of bytes to transfer (first 23 bits) */ +/* number of bytes to transfer (first 23 bits) */ +#define PLX_DMA0_TRANSFER_SIZE_REG 0x8c #define PLX_DMA1_TRANSFER_SIZE_REG 0xa0 #define PLX_DMA0_DESCRIPTOR_REG 0x90 /* descriptor pointer register */ #define PLX_DMA1_DESCRIPTOR_REG 0xa4 -#define PLX_DESC_IN_PCI_BIT 0x1 /* descriptor is located in pci space (not local space) */ +/* descriptor is located in pci space (not local space) */ +#define PLX_DESC_IN_PCI_BIT 0x1 #define PLX_END_OF_CHAIN_BIT 0x2 /* end of chain bit */ -#define PLX_INTR_TERM_COUNT 0x4 /* interrupt when this descriptor's transfer is finished */ -#define PLX_XFER_LOCAL_TO_PCI 0x8 /* transfer from local to pci bus (not pci to local) */ +/* interrupt when this descriptor's transfer is finished */ +#define PLX_INTR_TERM_COUNT 0x4 +/* transfer from local to pci bus (not pci to local) */ +#define PLX_XFER_LOCAL_TO_PCI 0x8 #define PLX_DMA0_CS_REG 0xa8 /* command status register */ #define PLX_DMA1_CS_REG 0xa9 @@ -288,10 +320,11 @@ enum bigend_bits { #define MBX_STS_PCIRESET 0x00000100 /* Host issued PCI reset request */ #define MBX_STS_BUSY 0x00000080 /* PUTS is in progress */ #define MBX_STS_ERROR 0x00000040 /* PUTS has failed */ -#define MBX_STS_RESERVED 0x000000c0 /* Undefined -> status in transition. - We are in process of changing - bits; we SET Error bit before - RESET of Busy bit */ +/* + * Undefined -> status in transition. We are in process of changing bits; + * we SET Error bit before RESET of Busy bit + */ +#define MBX_STS_RESERVED 0x000000c0 #define MBX_RESERVED_5 0x00000020 /* FYI: reserved/unused bit */ #define MBX_RESERVED_4 0x00000010 /* FYI: reserved/unused bit */ @@ -320,12 +353,12 @@ enum bigend_bits { #define MBX_CMD_BSWAP_0 0x8c000000 /* use scheme 0 */ #define MBX_CMD_BSWAP_1 0x8c000001 /* use scheme 1 */ -#define MBX_CMD_SETHMS 0x8d000000 /* setup host memory access window - size */ -#define MBX_CMD_SETHBA 0x8e000000 /* setup host memory access base - address */ -#define MBX_CMD_MGO 0x8f000000 /* perform memory setup and continue - (IE. Done) */ +/* setup host memory access window size */ +#define MBX_CMD_SETHMS 0x8d000000 +/* setup host memory access base address */ +#define MBX_CMD_SETHBA 0x8e000000 +/* perform memory setup and continue (IE. Done) */ +#define MBX_CMD_MGO 0x8f000000 #define MBX_CMD_NOOP 0xFF000000 /* dummy, illegal command */ /*****************************************/ @@ -348,7 +381,8 @@ enum bigend_bits { /***************************************/ #define MBX_BTYPE_MASK 0x0000ffff /* PUTS Board Type Register */ -#define MBX_BTYPE_FAMILY_MASK 0x0000ff00 /* PUTS Board Family Register */ +/* PUTS Board Family Register */ +#define MBX_BTYPE_FAMILY_MASK 0x0000ff00 #define MBX_BTYPE_SUBTYPE_MASK 0x000000ff /* PUTS Board Subtype */ #define MBX_BTYPE_PLX9060 0x00000100 /* PLX family type */ @@ -378,12 +412,12 @@ enum bigend_bits { /* system allocates this many bytes for address mapping mailbox space */ #define MBX_ADDR_SPACE_360 0x80 /* wanXL100s/200/400 */ -#define MBX_ADDR_MASK_360 (MBX_ADDR_SPACE_360-1) +#define MBX_ADDR_MASK_360 (MBX_ADDR_SPACE_360 - 1) static inline int plx9080_abort_dma(void __iomem *iobase, unsigned int channel) { void __iomem *dma_cs_addr; - uint8_t dma_status; + u8 dma_status; const int timeout = 10000; unsigned int i; diff --git a/drivers/staging/comedi/drivers/s526.c b/drivers/staging/comedi/drivers/s526.c index d70c97947627..c80527db9c19 100644 --- a/drivers/staging/comedi/drivers/s526.c +++ b/drivers/staging/comedi/drivers/s526.c @@ -37,7 +37,6 @@ #include <linux/module.h> #include "../comedidev.h" -#include <asm/byteorder.h> /* * Register I/O map @@ -84,7 +83,92 @@ #define S526_GPCT_LSB_REG(x) (0x12 + ((x) * 8)) #define S526_GPCT_MSB_REG(x) (0x14 + ((x) * 8)) #define S526_GPCT_MODE_REG(x) (0x16 + ((x) * 8)) +#define S526_GPCT_MODE_COUT_SRC(x) ((x) << 0) +#define S526_GPCT_MODE_COUT_SRC_MASK S526_GPCT_MODE_COUT_SRC(0x1) +#define S526_GPCT_MODE_COUT_SRC_RCAP S526_GPCT_MODE_COUT_SRC(0) +#define S526_GPCT_MODE_COUT_SRC_RTGL S526_GPCT_MODE_COUT_SRC(1) +#define S526_GPCT_MODE_COUT_POL(x) ((x) << 1) +#define S526_GPCT_MODE_COUT_POL_MASK S526_GPCT_MODE_COUT_POL(0x1) +#define S526_GPCT_MODE_COUT_POL_NORM S526_GPCT_MODE_COUT_POL(0) +#define S526_GPCT_MODE_COUT_POL_INV S526_GPCT_MODE_COUT_POL(1) +#define S526_GPCT_MODE_AUTOLOAD(x) ((x) << 2) +#define S526_GPCT_MODE_AUTOLOAD_MASK S526_GPCT_MODE_AUTOLOAD(0x7) +#define S526_GPCT_MODE_AUTOLOAD_NONE S526_GPCT_MODE_AUTOLOAD(0) +/* these 3 bits can be OR'ed */ +#define S526_GPCT_MODE_AUTOLOAD_RO S526_GPCT_MODE_AUTOLOAD(0x1) +#define S526_GPCT_MODE_AUTOLOAD_IXFALL S526_GPCT_MODE_AUTOLOAD(0x2) +#define S526_GPCT_MODE_AUTOLOAD_IXRISE S526_GPCT_MODE_AUTOLOAD(0x4) +#define S526_GPCT_MODE_HWCTEN_SRC(x) ((x) << 5) +#define S526_GPCT_MODE_HWCTEN_SRC_MASK S526_GPCT_MODE_HWCTEN_SRC(0x3) +#define S526_GPCT_MODE_HWCTEN_SRC_CEN S526_GPCT_MODE_HWCTEN_SRC(0) +#define S526_GPCT_MODE_HWCTEN_SRC_IX S526_GPCT_MODE_HWCTEN_SRC(1) +#define S526_GPCT_MODE_HWCTEN_SRC_IXRF S526_GPCT_MODE_HWCTEN_SRC(2) +#define S526_GPCT_MODE_HWCTEN_SRC_NRCAP S526_GPCT_MODE_HWCTEN_SRC(3) +#define S526_GPCT_MODE_CTEN_CTRL(x) ((x) << 7) +#define S526_GPCT_MODE_CTEN_CTRL_MASK S526_GPCT_MODE_CTEN_CTRL(0x3) +#define S526_GPCT_MODE_CTEN_CTRL_DIS S526_GPCT_MODE_CTEN_CTRL(0) +#define S526_GPCT_MODE_CTEN_CTRL_ENA S526_GPCT_MODE_CTEN_CTRL(1) +#define S526_GPCT_MODE_CTEN_CTRL_HW S526_GPCT_MODE_CTEN_CTRL(2) +#define S526_GPCT_MODE_CTEN_CTRL_INVHW S526_GPCT_MODE_CTEN_CTRL(3) +#define S526_GPCT_MODE_CLK_SRC(x) ((x) << 9) +#define S526_GPCT_MODE_CLK_SRC_MASK S526_GPCT_MODE_CLK_SRC(0x3) +/* if count direction control set to quadrature */ +#define S526_GPCT_MODE_CLK_SRC_QUADX1 S526_GPCT_MODE_CLK_SRC(0) +#define S526_GPCT_MODE_CLK_SRC_QUADX2 S526_GPCT_MODE_CLK_SRC(1) +#define S526_GPCT_MODE_CLK_SRC_QUADX4 S526_GPCT_MODE_CLK_SRC(2) +#define S526_GPCT_MODE_CLK_SRC_QUADX4_ S526_GPCT_MODE_CLK_SRC(3) +/* if count direction control set to software control */ +#define S526_GPCT_MODE_CLK_SRC_ARISE S526_GPCT_MODE_CLK_SRC(0) +#define S526_GPCT_MODE_CLK_SRC_AFALL S526_GPCT_MODE_CLK_SRC(1) +#define S526_GPCT_MODE_CLK_SRC_INT S526_GPCT_MODE_CLK_SRC(2) +#define S526_GPCT_MODE_CLK_SRC_INTHALF S526_GPCT_MODE_CLK_SRC(3) +#define S526_GPCT_MODE_CT_DIR(x) ((x) << 11) +#define S526_GPCT_MODE_CT_DIR_MASK S526_GPCT_MODE_CT_DIR(0x1) +/* if count direction control set to software control */ +#define S526_GPCT_MODE_CT_DIR_UP S526_GPCT_MODE_CT_DIR(0) +#define S526_GPCT_MODE_CT_DIR_DOWN S526_GPCT_MODE_CT_DIR(1) +#define S526_GPCT_MODE_CTDIR_CTRL(x) ((x) << 12) +#define S526_GPCT_MODE_CTDIR_CTRL_MASK S526_GPCT_MODE_CTDIR_CTRL(0x1) +#define S526_GPCT_MODE_CTDIR_CTRL_QUAD S526_GPCT_MODE_CTDIR_CTRL(0) +#define S526_GPCT_MODE_CTDIR_CTRL_SOFT S526_GPCT_MODE_CTDIR_CTRL(1) +#define S526_GPCT_MODE_LATCH_CTRL(x) ((x) << 13) +#define S526_GPCT_MODE_LATCH_CTRL_MASK S526_GPCT_MODE_LATCH_CTRL(0x1) +#define S526_GPCT_MODE_LATCH_CTRL_READ S526_GPCT_MODE_LATCH_CTRL(0) +#define S526_GPCT_MODE_LATCH_CTRL_EVENT S526_GPCT_MODE_LATCH_CTRL(1) +#define S526_GPCT_MODE_PR_SELECT(x) ((x) << 14) +#define S526_GPCT_MODE_PR_SELECT_MASK S526_GPCT_MODE_PR_SELECT(0x1) +#define S526_GPCT_MODE_PR_SELECT_PR0 S526_GPCT_MODE_PR_SELECT(0) +#define S526_GPCT_MODE_PR_SELECT_PR1 S526_GPCT_MODE_PR_SELECT(1) +/* Control/Status - R = readable, W = writeable, C = write 1 to clear */ #define S526_GPCT_CTRL_REG(x) (0x18 + ((x) * 8)) +#define S526_GPCT_CTRL_EV_STATUS(x) ((x) << 0) /* RC */ +#define S526_GPCT_CTRL_EV_STATUS_MASK S526_GPCT_EV_STATUS(0xf) +#define S526_GPCT_CTRL_EV_STATUS_NONE S526_GPCT_EV_STATUS(0) +/* these 4 bits can be OR'ed */ +#define S526_GPCT_CTRL_EV_STATUS_ECAP S526_GPCT_EV_STATUS(0x1) +#define S526_GPCT_CTRL_EV_STATUS_ICAPN S526_GPCT_EV_STATUS(0x2) +#define S526_GPCT_CTRL_EV_STATUS_ICAPP S526_GPCT_EV_STATUS(0x4) +#define S526_GPCT_CTRL_EV_STATUS_RCAP S526_GPCT_EV_STATUS(0x8) +#define S526_GPCT_CTRL_COUT_STATUS BIT(4) /* R */ +#define S526_GPCT_CTRL_INDEX_STATUS BIT(5) /* R */ +#define S525_GPCT_CTRL_INTEN(x) ((x) << 6) /* W */ +#define S525_GPCT_CTRL_INTEN_MASK S526_GPCT_CTRL_INTEN(0xf) +#define S525_GPCT_CTRL_INTEN_NONE S526_GPCT_CTRL_INTEN(0) +/* these 4 bits can be OR'ed */ +#define S525_GPCT_CTRL_INTEN_ERROR S526_GPCT_CTRL_INTEN(0x1) +#define S525_GPCT_CTRL_INTEN_IXFALL S526_GPCT_CTRL_INTEN(0x2) +#define S525_GPCT_CTRL_INTEN_IXRISE S526_GPCT_CTRL_INTEN(0x4) +#define S525_GPCT_CTRL_INTEN_RO S526_GPCT_CTRL_INTEN(0x8) +#define S525_GPCT_CTRL_LATCH_SEL(x) ((x) << 10) /* W */ +#define S525_GPCT_CTRL_LATCH_SEL_MASK S526_GPCT_CTRL_LATCH_SEL(0x7) +#define S525_GPCT_CTRL_LATCH_SEL_NONE S526_GPCT_CTRL_LATCH_SEL(0) +/* these 3 bits can be OR'ed */ +#define S525_GPCT_CTRL_LATCH_SEL_IXFALL S526_GPCT_CTRL_LATCH_SEL(0x1) +#define S525_GPCT_CTRL_LATCH_SEL_IXRISE S526_GPCT_CTRL_LATCH_SEL(0x2) +#define S525_GPCT_CTRL_LATCH_SEL_ITIMER S526_GPCT_CTRL_LATCH_SEL(0x4) +#define S525_GPCT_CTRL_CT_ARM BIT(13) /* W */ +#define S525_GPCT_CTRL_CT_LOAD BIT(14) /* W */ +#define S526_GPCT_CTRL_CT_RESET BIT(15) /* W */ #define S526_EEPROM_DATA_REG 0x32 #define S526_EEPROM_CTRL_REG 0x34 #define S526_EEPROM_CTRL_ADDR(x) (((x) & 0x3f) << 3) @@ -92,41 +176,6 @@ #define S526_EEPROM_CTRL_READ S526_EEPROM_CTRL(2) #define S526_EEPROM_CTRL_START BIT(0) -struct counter_mode_register_t { -#if defined(__LITTLE_ENDIAN_BITFIELD) - unsigned short coutSource:1; - unsigned short coutPolarity:1; - unsigned short autoLoadResetRcap:3; - unsigned short hwCtEnableSource:2; - unsigned short ctEnableCtrl:2; - unsigned short clockSource:2; - unsigned short countDir:1; - unsigned short countDirCtrl:1; - unsigned short outputRegLatchCtrl:1; - unsigned short preloadRegSel:1; - unsigned short reserved:1; - #elif defined(__BIG_ENDIAN_BITFIELD) - unsigned short reserved:1; - unsigned short preloadRegSel:1; - unsigned short outputRegLatchCtrl:1; - unsigned short countDirCtrl:1; - unsigned short countDir:1; - unsigned short clockSource:2; - unsigned short ctEnableCtrl:2; - unsigned short hwCtEnableSource:2; - unsigned short autoLoadResetRcap:3; - unsigned short coutPolarity:1; - unsigned short coutSource:1; -#else -#error Unknown bit field order -#endif -}; - -union cmReg { - struct counter_mode_register_t reg; - unsigned short value; -}; - struct s526_private { unsigned int gpct_config[4]; unsigned short ai_ctrl; @@ -174,7 +223,6 @@ static int s526_gpct_insn_config(struct comedi_device *dev, struct s526_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); unsigned int val; - union cmReg cmReg; /* * Check what type of Counter the user requested @@ -192,28 +240,31 @@ static int s526_gpct_insn_config(struct comedi_device *dev, #if 1 /* Set Counter Mode Register */ - cmReg.value = data[1] & 0xffff; - outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); + val = data[1] & 0xffff; + outw(val, dev->iobase + S526_GPCT_MODE_REG(chan)); /* Reset the counter if it is software preload */ - if (cmReg.reg.autoLoadResetRcap == 0) { + if ((val & S526_GPCT_MODE_AUTOLOAD_MASK) == + S526_GPCT_MODE_AUTOLOAD_NONE) { /* Reset the counter */ - outw(0x8000, dev->iobase + S526_GPCT_CTRL_REG(chan)); - /* Load the counter from PR0 - * outw(0x4000, dev->iobase + S526_GPCT_CTRL_REG(chan)); + outw(S526_GPCT_CTRL_CT_RESET, + dev->iobase + S526_GPCT_CTRL_REG(chan)); + /* + * Load the counter from PR0 + * outw(S526_GPCT_CTRL_CT_LOAD, + * dev->iobase + S526_GPCT_CTRL_REG(chan)); */ } #else - /* 0 quadrature, 1 software control */ - cmReg.reg.countDirCtrl = 0; + val = S526_GPCT_MODE_CTDIR_CTRL_QUAD; /* data[1] contains GPCT_X1, GPCT_X2 or GPCT_X4 */ if (data[1] == GPCT_X2) - cmReg.reg.clockSource = 1; + val |= S526_GPCT_MODE_CLK_SRC_QUADX2; else if (data[1] == GPCT_X4) - cmReg.reg.clockSource = 2; + val |= S526_GPCT_MODE_CLK_SRC_QUADX4; else - cmReg.reg.clockSource = 0; + val |= S526_GPCT_MODE_CLK_SRC_QUADX1; /* When to take into account the indexpulse: */ /* @@ -224,13 +275,14 @@ static int s526_gpct_insn_config(struct comedi_device *dev, * } */ /* Take into account the index pulse? */ - if (data[3] == GPCT_RESET_COUNTER_ON_INDEX) + if (data[3] == GPCT_RESET_COUNTER_ON_INDEX) { /* Auto load with INDEX^ */ - cmReg.reg.autoLoadResetRcap = 4; + val |= S526_GPCT_MODE_AUTOLOAD_IXRISE; + } /* Set Counter Mode Register */ - cmReg.value = data[1] & 0xffff; - outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); + val = data[1] & 0xffff; + outw(val, dev->iobase + S526_GPCT_MODE_REG(chan)); /* Load the pre-load register */ s526_gpct_write(dev, chan, data[2]); @@ -241,11 +293,14 @@ static int s526_gpct_insn_config(struct comedi_device *dev, dev->iobase + S526_GPCT_CTRL_REG(chan)); /* Reset the counter if it is software preload */ - if (cmReg.reg.autoLoadResetRcap == 0) { + if ((val & S526_GPCT_MODE_AUTOLOAD_MASK) == + S526_GPCT_MODE_AUTOLOAD_NONE) { /* Reset the counter */ - outw(0x8000, dev->iobase + S526_GPCT_CTRL_REG(chan)); + outw(S526_GPCT_CTRL_CT_RESET, + dev->iobase + S526_GPCT_CTRL_REG(chan)); /* Load the counter from PR0 */ - outw(0x4000, dev->iobase + S526_GPCT_CTRL_REG(chan)); + outw(S526_GPCT_CTRL_CT_LOAD, + dev->iobase + S526_GPCT_CTRL_REG(chan)); } #endif break; @@ -261,17 +316,21 @@ static int s526_gpct_insn_config(struct comedi_device *dev, devpriv->gpct_config[chan] = data[0]; /* Set Counter Mode Register */ - cmReg.value = data[1] & 0xffff; - cmReg.reg.preloadRegSel = 0; /* PR0 */ - outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); + val = data[1] & 0xffff; + /* Select PR0 */ + val &= ~S526_GPCT_MODE_PR_SELECT_MASK; + val |= S526_GPCT_MODE_PR_SELECT_PR0; + outw(val, dev->iobase + S526_GPCT_MODE_REG(chan)); /* Load the pre-load register 0 */ s526_gpct_write(dev, chan, data[2]); /* Set Counter Mode Register */ - cmReg.value = data[1] & 0xffff; - cmReg.reg.preloadRegSel = 1; /* PR1 */ - outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); + val = data[1] & 0xffff; + /* Select PR1 */ + val &= ~S526_GPCT_MODE_PR_SELECT_MASK; + val |= S526_GPCT_MODE_PR_SELECT_PR1; + outw(val, dev->iobase + S526_GPCT_MODE_REG(chan)); /* Load the pre-load register 1 */ s526_gpct_write(dev, chan, data[3]); @@ -294,17 +353,21 @@ static int s526_gpct_insn_config(struct comedi_device *dev, devpriv->gpct_config[chan] = data[0]; /* Set Counter Mode Register */ - cmReg.value = data[1] & 0xffff; - cmReg.reg.preloadRegSel = 0; /* PR0 */ - outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); + val = data[1] & 0xffff; + /* Select PR0 */ + val &= ~S526_GPCT_MODE_PR_SELECT_MASK; + val |= S526_GPCT_MODE_PR_SELECT_PR0; + outw(val, dev->iobase + S526_GPCT_MODE_REG(chan)); /* Load the pre-load register 0 */ s526_gpct_write(dev, chan, data[2]); /* Set Counter Mode Register */ - cmReg.value = data[1] & 0xffff; - cmReg.reg.preloadRegSel = 1; /* PR1 */ - outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); + val = data[1] & 0xffff; + /* Select PR1 */ + val &= ~S526_GPCT_MODE_PR_SELECT_MASK; + val |= S526_GPCT_MODE_PR_SELECT_PR1; + outw(val, dev->iobase + S526_GPCT_MODE_REG(chan)); /* Load the pre-load register 1 */ s526_gpct_write(dev, chan, data[3]); diff --git a/drivers/staging/dgnc/dgnc_cls.c b/drivers/staging/dgnc/dgnc_cls.c index 75040daa40ce..72f0aaa6911f 100644 --- a/drivers/staging/dgnc/dgnc_cls.c +++ b/drivers/staging/dgnc/dgnc_cls.c @@ -934,7 +934,7 @@ static void cls_flush_uart_write(struct channel_t *ch) writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT), &ch->ch_cls_uart->isr_fcr); - udelay(10); + usleep_range(10, 20); ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); } diff --git a/drivers/staging/dgnc/dgnc_neo.c b/drivers/staging/dgnc/dgnc_neo.c index 8106f5234bf5..39c76e78e56a 100644 --- a/drivers/staging/dgnc/dgnc_neo.c +++ b/drivers/staging/dgnc/dgnc_neo.c @@ -1108,9 +1108,9 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch) * On the other hand, if the UART IS in FIFO mode, then ask * the UART to give us an approximation of data it has RX'ed. */ - if (!(ch->ch_flags & CH_FIFO_ENABLED)) + if (!(ch->ch_flags & CH_FIFO_ENABLED)) { total = 0; - else { + } else { total = readb(&ch->ch_neo_uart->rfifo); /* @@ -1628,7 +1628,7 @@ static void neo_uart_init(struct channel_t *ch) /* Clear out UART and FIFO */ readb(&ch->ch_neo_uart->txrx); - writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr); + writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr); readb(&ch->ch_neo_uart->lsr); readb(&ch->ch_neo_uart->msr); @@ -1779,8 +1779,8 @@ static void neo_vpd(struct dgnc_board *brd) /* Store the VPD into our buffer */ for (i = 0; i < NEO_VPD_IMAGESIZE; i++) { a = neo_read_eeprom(brd->re_map_membase, i); - brd->vpd[i*2] = a & 0xff; - brd->vpd[(i*2)+1] = (a >> 8) & 0xff; + brd->vpd[i * 2] = a & 0xff; + brd->vpd[(i * 2) + 1] = (a >> 8) & 0xff; } if (((brd->vpd[0x08] != 0x82) /* long resource name tag */ diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c index 48e4b90578c1..b79eab084c02 100644 --- a/drivers/staging/dgnc/dgnc_tty.c +++ b/drivers/staging/dgnc/dgnc_tty.c @@ -448,7 +448,7 @@ void dgnc_tty_uninit(struct dgnc_board *brd) * dgnc_wmove - Write data to transmit queue. * * ch - Pointer to channel structure. - * buf - Poiter to characters to be moved. + * buf - Pointer to characters to be moved. * n - Number of characters to move. * *=======================================================================*/ diff --git a/drivers/staging/dgnc/dgnc_utils.c b/drivers/staging/dgnc/dgnc_utils.c index f76de82908d3..95272f4765fc 100644 --- a/drivers/staging/dgnc/dgnc_utils.c +++ b/drivers/staging/dgnc/dgnc_utils.c @@ -1,7 +1,6 @@ #include <linux/tty.h> #include <linux/sched.h> #include "dgnc_utils.h" -#include "digi.h" /* * dgnc_ms_sleep() diff --git a/drivers/staging/emxx_udc/emxx_udc.c b/drivers/staging/emxx_udc/emxx_udc.c index 4e6c16af40fc..beb9411658ba 100644 --- a/drivers/staging/emxx_udc/emxx_udc.c +++ b/drivers/staging/emxx_udc/emxx_udc.c @@ -823,7 +823,7 @@ static int _nbu2ss_out_dma( u32 length ) { - u8 *pBuffer; + dma_addr_t pBuffer; u32 mpkt; u32 lmpkt; u32 dmacnt; @@ -836,7 +836,7 @@ static int _nbu2ss_out_dma( return 1; /* DMA is forwarded */ req->dma_flag = TRUE; - pBuffer = (u8 *)req->req.dma; + pBuffer = req->req.dma; pBuffer += req->req.actual; /* DMA Address */ @@ -1034,7 +1034,7 @@ static int _nbu2ss_in_dma( u32 length ) { - u8 *pBuffer; + dma_addr_t pBuffer; u32 mpkt; /* MaxPacketSize */ u32 lmpkt; /* Last Packet Data Size */ u32 dmacnt; /* IN Data Size */ @@ -1080,7 +1080,7 @@ static int _nbu2ss_in_dma( _nbu2ss_writel(&preg->EP_DCR[num].EP_DCR2, data); /* Address setting */ - pBuffer = (u8 *)req->req.dma; + pBuffer = req->req.dma; pBuffer += req->req.actual; _nbu2ss_writel(&preg->EP_DCR[num].EP_TADR, (u32)pBuffer); @@ -1285,11 +1285,7 @@ static void _nbu2ss_restert_transfer(struct nbu2ss_ep *ep) bool bflag = FALSE; struct nbu2ss_req *req; - if (list_empty(&ep->queue)) - req = NULL; - else - req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - + req = list_first_entry_or_null(&ep->queue, struct nbu2ss_req, queue); if (!req) return; @@ -1784,11 +1780,7 @@ static inline int _nbu2ss_ep0_in_data_stage(struct nbu2ss_udc *udc) struct nbu2ss_req *req; struct nbu2ss_ep *ep = &udc->ep[0]; - if (list_empty(&ep->queue)) - req = NULL; - else - req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - + req = list_first_entry_or_null(&ep->queue, struct nbu2ss_req, queue); if (!req) req = &udc->ep0_req; @@ -1811,11 +1803,7 @@ static inline int _nbu2ss_ep0_out_data_stage(struct nbu2ss_udc *udc) struct nbu2ss_req *req; struct nbu2ss_ep *ep = &udc->ep[0]; - if (list_empty(&ep->queue)) - req = NULL; - else - req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - + req = list_first_entry_or_null(&ep->queue, struct nbu2ss_req, queue); if (!req) req = &udc->ep0_req; @@ -1838,11 +1826,7 @@ static inline int _nbu2ss_ep0_status_stage(struct nbu2ss_udc *udc) struct nbu2ss_req *req; struct nbu2ss_ep *ep = &udc->ep[0]; - if (list_empty(&ep->queue)) - req = NULL; - else - req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - + req = list_first_entry_or_null(&ep->queue, struct nbu2ss_req, queue); if (!req) { req = &udc->ep0_req; if (req->req.complete) @@ -2145,11 +2129,7 @@ static inline void _nbu2ss_epn_int(struct nbu2ss_udc *udc, u32 epnum) /* Interrupt Clear */ _nbu2ss_writel(&udc->p_regs->EP_REGS[num].EP_STATUS, ~(u32)status); - if (list_empty(&ep->queue)) - req = NULL; - else - req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - + req = list_first_entry_or_null(&ep->queue, struct nbu2ss_req, queue); if (!req) { /* pr_warn("=== %s(%d) req == NULL\n", __func__, epnum); */ return; @@ -2728,7 +2708,7 @@ static int nbu2ss_ep_queue( spin_lock_irqsave(&udc->lock, flags); #ifdef USE_DMA - if ((u32)req->req.buf & 0x3) + if ((uintptr_t)req->req.buf & 0x3) req->unaligned = TRUE; else req->unaligned = FALSE; diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index b3ea4bb54e2c..b676c486cb18 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -893,11 +893,10 @@ static void fwserial_destroy(struct kref *kref) kfree(serial); } -void fwtty_port_put(struct fwtty_port *port) +static void fwtty_port_put(struct fwtty_port *port) { kref_put(&port->serial->kref, fwserial_destroy); } -EXPORT_SYMBOL(fwtty_port_put); static void fwtty_port_dtr_rts(struct tty_port *tty_port, int on) { diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h index 787aa4f3a41b..e13fe33a6897 100644 --- a/drivers/staging/fwserial/fwserial.h +++ b/drivers/staging/fwserial/fwserial.h @@ -342,16 +342,6 @@ static const char loop_dev_name[] = "fwloop"; extern struct tty_driver *fwtty_driver; struct fwtty_port *fwtty_port_get(unsigned index); -void fwtty_port_put(struct fwtty_port *port); - -static inline void fwtty_bind_console(struct fwtty_port *port, - struct fwconsole_ops *fwcon_ops, - void *data) -{ - port->con_data = data; - port->fwcon_ops = fwcon_ops; -} - /* * Returns the max send async payload size in bytes based on the unit device * link speed. Self-limiting asynchronous bandwidth (via reducing the payload) diff --git a/drivers/staging/gdm724x/gdm_lte.c b/drivers/staging/gdm724x/gdm_lte.c index 79de678807cc..17d148f6e02c 100644 --- a/drivers/staging/gdm724x/gdm_lte.c +++ b/drivers/staging/gdm724x/gdm_lte.c @@ -555,7 +555,7 @@ int gdm_lte_event_init(void) void gdm_lte_event_exit(void) { if (lte_event.sock && --lte_event.ref_cnt == 0) { - netlink_exit(lte_event.sock); + sock_release(lte_event.sock->sk_socket); lte_event.sock = NULL; } } diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c index e2c0f228f369..eb7e2523c354 100644 --- a/drivers/staging/gdm724x/gdm_tty.c +++ b/drivers/staging/gdm724x/gdm_tty.c @@ -64,7 +64,7 @@ static void gdm_port_destruct(struct tty_port *port) kfree(gdm); } -static struct tty_port_operations gdm_port_ops = { +static const struct tty_port_operations gdm_port_ops = { .destruct = gdm_port_destruct, }; diff --git a/drivers/staging/gdm724x/netlink_k.c b/drivers/staging/gdm724x/netlink_k.c index 92254fdaae1e..9d8347769e88 100644 --- a/drivers/staging/gdm724x/netlink_k.c +++ b/drivers/staging/gdm724x/netlink_k.c @@ -107,11 +107,6 @@ struct sock *netlink_init(int unit, return sock; } -void netlink_exit(struct sock *sock) -{ - sock_release(sock->sk_socket); -} - int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len) { static u32 seq; diff --git a/drivers/staging/gdm724x/netlink_k.h b/drivers/staging/gdm724x/netlink_k.h index 589486d76714..7cf979b3f826 100644 --- a/drivers/staging/gdm724x/netlink_k.h +++ b/drivers/staging/gdm724x/netlink_k.h @@ -19,7 +19,6 @@ struct sock *netlink_init(int unit, void (*cb)(struct net_device *dev, u16 type, void *msg, int len)); -void netlink_exit(struct sock *sock); int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len); #endif /* _NETLINK_K_H_ */ diff --git a/drivers/staging/gdm72xx/gdm_qos.c b/drivers/staging/gdm72xx/gdm_qos.c index 81feffa5784a..cad347a05d18 100644 --- a/drivers/staging/gdm72xx/gdm_qos.c +++ b/drivers/staging/gdm72xx/gdm_qos.c @@ -101,7 +101,7 @@ void gdm_qos_init(void *nic_ptr) } qcb->qos_list_cnt = 0; - qcb->qos_null_idx = QOS_MAX-1; + qcb->qos_null_idx = QOS_MAX - 1; qcb->qos_limit_size = 255; spin_lock_init(&qcb->qos_lock); @@ -128,7 +128,7 @@ void gdm_qos_release_list(void *nic_ptr) } qcb->qos_list_cnt = 0; - qcb->qos_null_idx = QOS_MAX-1; + qcb->qos_null_idx = QOS_MAX - 1; for (i = 0; i < QOS_MAX; i++) { list_for_each_entry_safe(entry, n, &qcb->qos_list[i], list) { @@ -143,18 +143,18 @@ static int chk_ipv4_rule(struct gdm_wimax_csr_s *csr, u8 *stream, u8 *port) { int i; - if (csr->classifier_rule_en&IPTYPEOFSERVICE) { + if (csr->classifier_rule_en & IPTYPEOFSERVICE) { if (((stream[1] & csr->ip2s_mask) < csr->ip2s_lo) || ((stream[1] & csr->ip2s_mask) > csr->ip2s_hi)) return 1; } - if (csr->classifier_rule_en&PROTOCOL) { + if (csr->classifier_rule_en & PROTOCOL) { if (stream[9] != csr->protocol) return 1; } - if (csr->classifier_rule_en&IPMASKEDSRCADDRESS) { + if (csr->classifier_rule_en & IPMASKEDSRCADDRESS) { for (i = 0; i < 4; i++) { if ((stream[12 + i] & csr->ipsrc_addrmask[i]) != (csr->ipsrc_addr[i] & csr->ipsrc_addrmask[i])) @@ -162,7 +162,7 @@ static int chk_ipv4_rule(struct gdm_wimax_csr_s *csr, u8 *stream, u8 *port) } } - if (csr->classifier_rule_en&IPMASKEDDSTADDRESS) { + if (csr->classifier_rule_en & IPMASKEDDSTADDRESS) { for (i = 0; i < 4; i++) { if ((stream[16 + i] & csr->ipdst_addrmask[i]) != (csr->ipdst_addr[i] & csr->ipdst_addrmask[i])) @@ -170,14 +170,14 @@ static int chk_ipv4_rule(struct gdm_wimax_csr_s *csr, u8 *stream, u8 *port) } } - if (csr->classifier_rule_en&PROTOCOLSRCPORTRANGE) { - i = ((port[0]<<8)&0xff00)+port[1]; + if (csr->classifier_rule_en & PROTOCOLSRCPORTRANGE) { + i = ((port[0] << 8) & 0xff00) + port[1]; if ((i < csr->srcport_lo) || (i > csr->srcport_hi)) return 1; } - if (csr->classifier_rule_en&PROTOCOLDSTPORTRANGE) { - i = ((port[2]<<8)&0xff00)+port[3]; + if (csr->classifier_rule_en & PROTOCOLDSTPORTRANGE) { + i = ((port[2] << 8) & 0xff00) + port[3]; if ((i < csr->dstport_lo) || (i > csr->dstport_hi)) return 1; } @@ -193,7 +193,7 @@ static int get_qos_index(struct nic *nic, u8 *iph, u8 *tcpudph) if (!iph || !tcpudph) return -1; - ip_ver = (iph[0]>>4)&0xf; + ip_ver = (iph[0] >> 4) & 0xf; if (ip_ver != 4) return -1; @@ -342,17 +342,17 @@ void gdm_recv_qos_hci_packet(void *nic_ptr, u8 *buf, int size) if (sub_cmd_evt == QOS_REPORT) { spin_lock_irqsave(&qcb->qos_lock, flags); for (i = 0; i < qcb->qos_list_cnt; i++) { - sfid = ((buf[(i*5)+6]<<24)&0xff000000); - sfid += ((buf[(i*5)+7]<<16)&0xff0000); - sfid += ((buf[(i*5)+8]<<8)&0xff00); - sfid += (buf[(i*5)+9]); + sfid = ((buf[(i*5) + 6] << 24) & 0xff000000); + sfid += ((buf[(i*5) + 7] << 16) & 0xff0000); + sfid += ((buf[(i*5) + 8] << 8) & 0xff00); + sfid += (buf[(i*5) + 9]); index = get_csr(qcb, sfid, 0); if (index == -1) { spin_unlock_irqrestore(&qcb->qos_lock, flags); netdev_err(nic->netdev, "QoS ERROR: No SF\n"); return; } - qcb->csr[index].qos_buf_count = buf[(i*5)+10]; + qcb->csr[index].qos_buf_count = buf[(i*5) + 10]; } extract_qos_list(nic, &send_list); @@ -363,9 +363,9 @@ void gdm_recv_qos_hci_packet(void *nic_ptr, u8 *buf, int size) /* sub_cmd_evt == QOS_ADD || sub_cmd_evt == QOS_CHANG_DEL */ pos = 6; - sfid = ((buf[pos++]<<24)&0xff000000); - sfid += ((buf[pos++]<<16)&0xff0000); - sfid += ((buf[pos++]<<8)&0xff00); + sfid = ((buf[pos++] << 24) & 0xff000000); + sfid += ((buf[pos++] << 16) & 0xff0000); + sfid += ((buf[pos++] << 8) & 0xff00); sfid += (buf[pos++]); index = get_csr(qcb, sfid, 1); @@ -382,7 +382,7 @@ void gdm_recv_qos_hci_packet(void *nic_ptr, u8 *buf, int size) spin_lock_irqsave(&qcb->qos_lock, flags); qcb->csr[index].sfid = sfid; - qcb->csr[index].classifier_rule_en = ((buf[pos++]<<8)&0xff00); + qcb->csr[index].classifier_rule_en = ((buf[pos++] << 8) & 0xff00); qcb->csr[index].classifier_rule_en += buf[pos++]; if (qcb->csr[index].classifier_rule_en == 0) qcb->qos_null_idx = index; @@ -406,16 +406,16 @@ void gdm_recv_qos_hci_packet(void *nic_ptr, u8 *buf, int size) qcb->csr[index].ipdst_addr[1] = buf[pos++]; qcb->csr[index].ipdst_addr[2] = buf[pos++]; qcb->csr[index].ipdst_addr[3] = buf[pos++]; - qcb->csr[index].srcport_lo = ((buf[pos++]<<8)&0xff00); + qcb->csr[index].srcport_lo = ((buf[pos++] << 8) & 0xff00); qcb->csr[index].srcport_lo += buf[pos++]; - qcb->csr[index].srcport_hi = ((buf[pos++]<<8)&0xff00); + qcb->csr[index].srcport_hi = ((buf[pos++] << 8) & 0xff00); qcb->csr[index].srcport_hi += buf[pos++]; - qcb->csr[index].dstport_lo = ((buf[pos++]<<8)&0xff00); + qcb->csr[index].dstport_lo = ((buf[pos++] << 8) & 0xff00); qcb->csr[index].dstport_lo += buf[pos++]; - qcb->csr[index].dstport_hi = ((buf[pos++]<<8)&0xff00); + qcb->csr[index].dstport_hi = ((buf[pos++] << 8) & 0xff00); qcb->csr[index].dstport_hi += buf[pos++]; - qcb->qos_limit_size = 254/qcb->qos_list_cnt; + qcb->qos_limit_size = 254 / qcb->qos_list_cnt; spin_unlock_irqrestore(&qcb->qos_lock, flags); } else if (sub_cmd_evt == QOS_CHANGE_DEL) { netdev_dbg(nic->netdev, "QOS_CHANGE_DEL SFID = 0x%x, index=%d\n", @@ -426,7 +426,7 @@ void gdm_recv_qos_hci_packet(void *nic_ptr, u8 *buf, int size) spin_lock_irqsave(&qcb->qos_lock, flags); qcb->csr[index].enabled = false; qcb->qos_list_cnt--; - qcb->qos_limit_size = 254/qcb->qos_list_cnt; + qcb->qos_limit_size = 254 / qcb->qos_list_cnt; list_for_each_entry_safe(entry, n, &qcb->qos_list[index], list) { diff --git a/drivers/staging/gdm72xx/gdm_sdio.c b/drivers/staging/gdm72xx/gdm_sdio.c index b0521da3c793..1f5a087723ba 100644 --- a/drivers/staging/gdm72xx/gdm_sdio.c +++ b/drivers/staging/gdm72xx/gdm_sdio.c @@ -36,7 +36,7 @@ #define RX_BUF_SIZE (25*1024) #define TX_HZ 2000 -#define TX_INTERVAL (1000000/TX_HZ) +#define TX_INTERVAL (NSEC_PER_SEC/TX_HZ) static struct sdio_tx *alloc_tx_struct(struct tx_cxt *tx) { @@ -303,7 +303,7 @@ static void send_sdu(struct sdio_func *func, struct tx_cxt *tx) put_tx_struct(t->tx_cxt, t); } - do_gettimeofday(&tx->sdu_stamp); + tx->sdu_stamp = ktime_get(); spin_unlock_irqrestore(&tx->lock, flags); } @@ -330,7 +330,7 @@ static void do_tx(struct work_struct *work) struct sdio_func *func = sdev->func; struct tx_cxt *tx = &sdev->tx; struct sdio_tx *t = NULL; - struct timeval now, *before; + ktime_t now, before; int is_sdu = 0; long diff; unsigned long flags; @@ -346,11 +346,10 @@ static void do_tx(struct work_struct *work) list_del(&t->list); is_sdu = 0; } else if (!tx->stop_sdu_tx && !list_empty(&tx->sdu_list)) { - do_gettimeofday(&now); - before = &tx->sdu_stamp; + now = ktime_get(); + before = tx->sdu_stamp; - diff = (now.tv_sec - before->tv_sec) * 1000000 + - (now.tv_usec - before->tv_usec); + diff = ktime_to_ns(ktime_sub(now, before)); if (diff >= 0 && diff < TX_INTERVAL) { schedule_work(&sdev->ws); spin_unlock_irqrestore(&tx->lock, flags); diff --git a/drivers/staging/gdm72xx/gdm_sdio.h b/drivers/staging/gdm72xx/gdm_sdio.h index 77ad9d686f8e..aa7dad22a219 100644 --- a/drivers/staging/gdm72xx/gdm_sdio.h +++ b/drivers/staging/gdm72xx/gdm_sdio.h @@ -15,7 +15,7 @@ #define __GDM72XX_GDM_SDIO_H__ #include <linux/types.h> -#include <linux/time.h> +#include <linux/ktime.h> #define MAX_NR_SDU_BUF 64 @@ -32,7 +32,7 @@ struct tx_cxt { struct list_head free_list; struct list_head sdu_list; struct list_head hci_list; - struct timeval sdu_stamp; + ktime_t sdu_stamp; u8 *sdu_buf; spinlock_t lock; int can_send; diff --git a/drivers/staging/gdm72xx/gdm_wimax.c b/drivers/staging/gdm72xx/gdm_wimax.c index d9ddced96e19..ba03f9386567 100644 --- a/drivers/staging/gdm72xx/gdm_wimax.c +++ b/drivers/staging/gdm72xx/gdm_wimax.c @@ -84,11 +84,6 @@ static inline struct evt_entry *alloc_event_entry(void) return kmalloc(sizeof(struct evt_entry), GFP_ATOMIC); } -static inline void free_event_entry(struct evt_entry *e) -{ - kfree(e); -} - static struct evt_entry *get_event_entry(void) { struct evt_entry *e; @@ -180,11 +175,11 @@ static void gdm_wimax_event_exit(void) list_for_each_entry_safe(e, temp, &wm_event.evtq, list) { list_del(&e->list); - free_event_entry(e); + kfree(e); } list_for_each_entry_safe(e, temp, &wm_event.freeq, list) { list_del(&e->list); - free_event_entry(e); + kfree(e); } spin_unlock_irqrestore(&wm_event.evt_lock, flags); @@ -368,7 +363,7 @@ static void kdelete(void **buf) } } -static int gdm_wimax_ioctl_get_data(struct data_s *dst, struct data_s *src) +static int gdm_wimax_ioctl_get_data(struct udata_s *dst, struct data_s *src) { int size; @@ -384,7 +379,7 @@ static int gdm_wimax_ioctl_get_data(struct data_s *dst, struct data_s *src) return 0; } -static int gdm_wimax_ioctl_set_data(struct data_s *dst, struct data_s *src) +static int gdm_wimax_ioctl_set_data(struct data_s *dst, struct udata_s *src) { if (!src->size) { dst->size = 0; @@ -460,6 +455,7 @@ static int gdm_wimax_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) struct wm_req_s *req = (struct wm_req_s *)ifr; struct nic *nic = netdev_priv(dev); int ret; + struct fsm_s fsm_buf; if (cmd != SIOCWMIOCTL) return -EOPNOTSUPP; @@ -482,8 +478,11 @@ static int gdm_wimax_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /* NOTE: gdm_update_fsm should be called * before gdm_wimax_ioctl_set_data is called. */ - gdm_update_fsm(dev, - req->data.buf); + if (copy_from_user(&fsm_buf, req->data.buf, + sizeof(struct fsm_s))) + return -EFAULT; + + gdm_update_fsm(dev, &fsm_buf); } ret = gdm_wimax_ioctl_set_data( &nic->sdk_data[req->data_id], &req->data); diff --git a/drivers/staging/gdm72xx/wm_ioctl.h b/drivers/staging/gdm72xx/wm_ioctl.h index ed8f649c0042..631cb1d23c7e 100644 --- a/drivers/staging/gdm72xx/wm_ioctl.h +++ b/drivers/staging/gdm72xx/wm_ioctl.h @@ -78,13 +78,18 @@ struct data_s { void *buf; }; +struct udata_s { + int size; + void __user *buf; +}; + struct wm_req_s { union { char ifrn_name[IFNAMSIZ]; } ifr_ifrn; unsigned short cmd; unsigned short data_id; - struct data_s data; + struct udata_s data; /* NOTE: sizeof(struct wm_req_s) must be less than sizeof(struct ifreq). */ }; diff --git a/drivers/staging/iio/Kconfig b/drivers/staging/iio/Kconfig index 9d7f0004d2d7..0e044cb0def8 100644 --- a/drivers/staging/iio/Kconfig +++ b/drivers/staging/iio/Kconfig @@ -17,33 +17,4 @@ source "drivers/staging/iio/meter/Kconfig" source "drivers/staging/iio/resolver/Kconfig" source "drivers/staging/iio/trigger/Kconfig" -config IIO_DUMMY_EVGEN - tristate - select IRQ_WORK - -config IIO_SIMPLE_DUMMY - tristate "An example driver with no hardware requirements" - help - Driver intended mainly as documentation for how to write - a driver. May also be useful for testing userspace code - without hardware. - -if IIO_SIMPLE_DUMMY - -config IIO_SIMPLE_DUMMY_EVENTS - bool "Event generation support" - select IIO_DUMMY_EVGEN - help - Add some dummy events to the simple dummy driver. - -config IIO_SIMPLE_DUMMY_BUFFER - bool "Buffered capture support" - select IIO_BUFFER - select IIO_TRIGGER - select IIO_KFIFO_BUF - help - Add buffered data capture to the simple dummy driver. - -endif # IIO_SIMPLE_DUMMY - endmenu diff --git a/drivers/staging/iio/Makefile b/drivers/staging/iio/Makefile index d87106135b27..3e616b4437f5 100644 --- a/drivers/staging/iio/Makefile +++ b/drivers/staging/iio/Makefile @@ -2,13 +2,6 @@ # Makefile for the industrial I/O core. # -obj-$(CONFIG_IIO_SIMPLE_DUMMY) += iio_dummy.o -iio_dummy-y := iio_simple_dummy.o -iio_dummy-$(CONFIG_IIO_SIMPLE_DUMMY_EVENTS) += iio_simple_dummy_events.o -iio_dummy-$(CONFIG_IIO_SIMPLE_DUMMY_BUFFER) += iio_simple_dummy_buffer.o - -obj-$(CONFIG_IIO_DUMMY_EVGEN) += iio_dummy_evgen.o - obj-y += accel/ obj-y += adc/ obj-y += addac/ diff --git a/drivers/staging/iio/accel/sca3000_ring.c b/drivers/staging/iio/accel/sca3000_ring.c index 20b878d35ea2..1920dc60cf3d 100644 --- a/drivers/staging/iio/accel/sca3000_ring.c +++ b/drivers/staging/iio/accel/sca3000_ring.c @@ -48,7 +48,7 @@ static int sca3000_read_data(struct sca3000_state *st, } }; *rx_p = kmalloc(len, GFP_KERNEL); - if (*rx_p == NULL) { + if (!*rx_p) { ret = -ENOMEM; goto error_ret; } diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index bb40f3728742..92211039ffa9 100644 --- a/drivers/staging/iio/adc/ad7192.c +++ b/drivers/staging/iio/adc/ad7192.c @@ -609,7 +609,7 @@ static const struct iio_chan_spec ad7192_channels[] = { static int ad7192_probe(struct spi_device *spi) { - const struct ad7192_platform_data *pdata = spi->dev.platform_data; + const struct ad7192_platform_data *pdata = dev_get_platdata(&spi->dev); struct ad7192_state *st; struct iio_dev *indio_dev; int ret, voltage_uv = 0; diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index 35acb1a4669b..f45ebedb7a05 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -833,7 +833,7 @@ static const struct ad7280_platform_data ad7793_default_pdata = { static int ad7280_probe(struct spi_device *spi) { - const struct ad7280_platform_data *pdata = spi->dev.platform_data; + const struct ad7280_platform_data *pdata = dev_get_platdata(&spi->dev); struct ad7280_state *st; int ret; const unsigned short tACQ_ns[4] = {465, 1010, 1460, 1890}; diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index 3abc7789237f..1439cfdbb09c 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -15,15 +15,13 @@ #include <linux/regulator/consumer.h> #include <linux/err.h> #include <linux/sched.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/module.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/adc/ad_sigma_delta.h> -#include "ad7780.h" - #define AD7780_RDY BIT(7) #define AD7780_FILTER BIT(6) #define AD7780_ERR BIT(5) @@ -42,7 +40,7 @@ struct ad7780_chip_info { struct ad7780_state { const struct ad7780_chip_info *chip_info; struct regulator *reg; - int powerdown_gpio; + struct gpio_desc *powerdown_gpio; unsigned int gain; u16 int_vref_mv; @@ -77,8 +75,7 @@ static int ad7780_set_mode(struct ad_sigma_delta *sigma_delta, break; } - if (gpio_is_valid(st->powerdown_gpio)) - gpio_set_value(st->powerdown_gpio, val); + gpiod_set_value(st->powerdown_gpio, val); return 0; } @@ -163,7 +160,6 @@ static const struct iio_info ad7780_info = { static int ad7780_probe(struct spi_device *spi) { - struct ad7780_platform_data *pdata = spi->dev.platform_data; struct ad7780_state *st; struct iio_dev *indio_dev; int ret, voltage_uv = 0; @@ -189,12 +185,10 @@ static int ad7780_probe(struct spi_device *spi) st->chip_info = &ad7780_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - if (pdata && pdata->vref_mv) - st->int_vref_mv = pdata->vref_mv; - else if (voltage_uv) + if (voltage_uv) st->int_vref_mv = voltage_uv / 1000; else - dev_warn(&spi->dev, "reference voltage unspecified\n"); + dev_warn(&spi->dev, "Reference voltage unspecified\n"); spi_set_drvdata(spi, indio_dev); @@ -205,18 +199,14 @@ static int ad7780_probe(struct spi_device *spi) indio_dev->num_channels = 1; indio_dev->info = &ad7780_info; - if (pdata && gpio_is_valid(pdata->gpio_pdrst)) { - ret = devm_gpio_request_one(&spi->dev, - pdata->gpio_pdrst, - GPIOF_OUT_INIT_LOW, - "AD7780 /PDRST"); - if (ret) { - dev_err(&spi->dev, "failed to request GPIO PDRST\n"); - goto error_disable_reg; - } - st->powerdown_gpio = pdata->gpio_pdrst; - } else { - st->powerdown_gpio = -1; + st->powerdown_gpio = devm_gpiod_get_optional(&spi->dev, + "powerdown", + GPIOD_OUT_LOW); + if (IS_ERR(st->powerdown_gpio)) { + ret = PTR_ERR(st->powerdown_gpio); + dev_err(&spi->dev, "Failed to request powerdown GPIO: %d\n", + ret); + goto error_disable_reg; } ret = ad_sd_setup_buffer_and_trigger(indio_dev); diff --git a/drivers/staging/iio/adc/ad7780.h b/drivers/staging/iio/adc/ad7780.h deleted file mode 100644 index 67e511c3d6f0..000000000000 --- a/drivers/staging/iio/adc/ad7780.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * AD7780/AD7781 SPI ADC driver - * - * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ -#ifndef IIO_ADC_AD7780_H_ -#define IIO_ADC_AD7780_H_ - -/* - * TODO: struct ad7780_platform_data needs to go into include/linux/iio - */ - -/* NOTE: - * The AD7780 doesn't feature a dedicated SPI chip select, in addition it - * features a dual use data out ready DOUT/RDY output. - * In order to avoid contentions on the SPI bus, it's therefore necessary - * to use spi bus locking combined with a dedicated GPIO to control the - * power down reset signal of the AD7780. - * - * The DOUT/RDY output must also be wired to an interrupt capable GPIO. - */ - -struct ad7780_platform_data { - u16 vref_mv; - int gpio_pdrst; -}; - -#endif /* IIO_ADC_AD7780_H_ */ diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index c8e156646528..22260512cf01 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -345,7 +345,7 @@ static int ad7816_probe(struct spi_device *spi_dev) { struct ad7816_chip_info *chip; struct iio_dev *indio_dev; - unsigned short *pins = spi_dev->dev.platform_data; + unsigned short *pins = dev_get_platdata(&spi_dev->dev); int ret = 0; int i; diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c index d997d9c74ca8..bb1f15224ac8 100644 --- a/drivers/staging/iio/adc/mxs-lradc.c +++ b/drivers/staging/iio/adc/mxs-lradc.c @@ -319,12 +319,12 @@ struct mxs_lradc { #define LRADC_CH_VALUE_OFFSET 0 #define LRADC_DELAY(n) (0xd0 + (0x10 * (n))) -#define LRADC_DELAY_TRIGGER_LRADCS_MASK (0xff << 24) +#define LRADC_DELAY_TRIGGER_LRADCS_MASK (0xffUL << 24) #define LRADC_DELAY_TRIGGER_LRADCS_OFFSET 24 #define LRADC_DELAY_TRIGGER(x) \ (((x) << LRADC_DELAY_TRIGGER_LRADCS_OFFSET) & \ LRADC_DELAY_TRIGGER_LRADCS_MASK) -#define LRADC_DELAY_KICK (1 << 20) +#define LRADC_DELAY_KICK BIT(20) #define LRADC_DELAY_TRIGGER_DELAYS_MASK (0xf << 16) #define LRADC_DELAY_TRIGGER_DELAYS_OFFSET 16 #define LRADC_DELAY_TRIGGER_DELAYS(x) \ diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c index 2b65faa6296a..18b27a1984b2 100644 --- a/drivers/staging/iio/frequency/ad9832.c +++ b/drivers/staging/iio/frequency/ad9832.c @@ -201,7 +201,7 @@ static const struct iio_info ad9832_info = { static int ad9832_probe(struct spi_device *spi) { - struct ad9832_platform_data *pdata = spi->dev.platform_data; + struct ad9832_platform_data *pdata = dev_get_platdata(&spi->dev); struct iio_dev *indio_dev; struct ad9832_state *st; struct regulator *reg; diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c index 6464f2cbe94b..6366216e4f37 100644 --- a/drivers/staging/iio/frequency/ad9834.c +++ b/drivers/staging/iio/frequency/ad9834.c @@ -318,7 +318,7 @@ static const struct iio_info ad9833_info = { static int ad9834_probe(struct spi_device *spi) { - struct ad9834_platform_data *pdata = spi->dev.platform_data; + struct ad9834_platform_data *pdata = dev_get_platdata(&spi->dev); struct ad9834_state *st; struct iio_dev *indio_dev; struct regulator *reg; diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c index 9dfd04855a1b..5b1c1650a0e4 100644 --- a/drivers/staging/iio/light/tsl2x7x_core.c +++ b/drivers/staging/iio/light/tsl2x7x_core.c @@ -1898,7 +1898,7 @@ static int tsl2x7x_probe(struct i2c_client *clientp, mutex_init(&chip->prox_mutex); chip->tsl2x7x_chip_status = TSL2X7X_CHIP_UNKNOWN; - chip->pdata = clientp->dev.platform_data; + chip->pdata = dev_get_platdata(&clientp->dev); chip->id = id->driver_data; chip->chip_info = &tsl2x7x_chip_info_tbl[device_channel_config[id->driver_data]]; diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/libcfs.h index 4d74e8af5088..0d8a91ee5ffc 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -42,13 +42,6 @@ #include "curproc.h" -static inline int __is_po2(unsigned long long val) -{ - return !(val & (val - 1)); -} - -#define IS_PO2(val) __is_po2((unsigned long long)(val)) - #define LOWEST_BIT_SET(x) ((x) & ~((x) - 1)) /* diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h index 787867847483..1530b0458a61 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h @@ -22,7 +22,8 @@ */ /* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, Intel Corporation. + * + * Copyright (c) 2012, 2015 Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h index 70b8b29e831c..c3f2332fa043 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015 Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -41,6 +41,9 @@ #ifndef __LIBCFS_HASH_H__ #define __LIBCFS_HASH_H__ + +#include <linux/hash.h> + /* * Knuth recommends primes in approximately golden ratio to the maximum * integer representable by a machine word for multiplicative hashing. @@ -56,22 +59,13 @@ /* 2^63 + 2^61 - 2^57 + 2^54 - 2^51 - 2^18 + 1 */ #define CFS_GOLDEN_RATIO_PRIME_64 0x9e37fffffffc0001ULL -/* - * Ideally we would use HAVE_HASH_LONG for this, but on linux we configure - * the linux kernel and user space at the same time, so we need to differentiate - * between them explicitly. If this is not needed on other architectures, then - * we'll need to move the functions to architecture specific headers. - */ - -#include <linux/hash.h> - /** disable debug */ -#define CFS_HASH_DEBUG_NONE 0 +#define CFS_HASH_DEBUG_NONE 0 /** record hash depth and output to console when it's too deep, * computing overhead is low but consume more memory */ -#define CFS_HASH_DEBUG_1 1 +#define CFS_HASH_DEBUG_1 1 /** expensive, check key validation */ -#define CFS_HASH_DEBUG_2 2 +#define CFS_HASH_DEBUG_2 2 #define CFS_HASH_DEBUG_LEVEL CFS_HASH_DEBUG_NONE @@ -108,16 +102,18 @@ struct cfs_hash_bucket { * cfs_hash bucket descriptor, it's normally in stack of caller */ struct cfs_hash_bd { - struct cfs_hash_bucket *bd_bucket; /**< address of bucket */ - unsigned int bd_offset; /**< offset in bucket */ + /* address of bucket */ + struct cfs_hash_bucket *bd_bucket; + /* offset in bucket */ + unsigned int bd_offset; }; -#define CFS_HASH_NAME_LEN 16 /**< default name length */ -#define CFS_HASH_BIGNAME_LEN 64 /**< bigname for param tree */ +#define CFS_HASH_NAME_LEN 16 /**< default name length */ +#define CFS_HASH_BIGNAME_LEN 64 /**< bigname for param tree */ -#define CFS_HASH_BKT_BITS 3 /**< default bits of bucket */ -#define CFS_HASH_BITS_MAX 30 /**< max bits of bucket */ -#define CFS_HASH_BITS_MIN CFS_HASH_BKT_BITS +#define CFS_HASH_BKT_BITS 3 /**< default bits of bucket */ +#define CFS_HASH_BITS_MAX 30 /**< max bits of bucket */ +#define CFS_HASH_BITS_MIN CFS_HASH_BKT_BITS /** * common hash attributes. @@ -133,41 +129,41 @@ enum cfs_hash_tag { */ CFS_HASH_NO_LOCK = 1 << 0, /** no bucket lock, use one spinlock to protect the whole hash */ - CFS_HASH_NO_BKTLOCK = 1 << 1, + CFS_HASH_NO_BKTLOCK = 1 << 1, /** rwlock to protect bucket */ - CFS_HASH_RW_BKTLOCK = 1 << 2, + CFS_HASH_RW_BKTLOCK = 1 << 2, /** spinlock to protect bucket */ - CFS_HASH_SPIN_BKTLOCK = 1 << 3, + CFS_HASH_SPIN_BKTLOCK = 1 << 3, /** always add new item to tail */ - CFS_HASH_ADD_TAIL = 1 << 4, + CFS_HASH_ADD_TAIL = 1 << 4, /** hash-table doesn't have refcount on item */ - CFS_HASH_NO_ITEMREF = 1 << 5, + CFS_HASH_NO_ITEMREF = 1 << 5, /** big name for param-tree */ CFS_HASH_BIGNAME = 1 << 6, /** track global count */ CFS_HASH_COUNTER = 1 << 7, /** rehash item by new key */ - CFS_HASH_REHASH_KEY = 1 << 8, + CFS_HASH_REHASH_KEY = 1 << 8, /** Enable dynamic hash resizing */ - CFS_HASH_REHASH = 1 << 9, + CFS_HASH_REHASH = 1 << 9, /** can shrink hash-size */ - CFS_HASH_SHRINK = 1 << 10, + CFS_HASH_SHRINK = 1 << 10, /** assert hash is empty on exit */ - CFS_HASH_ASSERT_EMPTY = 1 << 11, + CFS_HASH_ASSERT_EMPTY = 1 << 11, /** record hlist depth */ - CFS_HASH_DEPTH = 1 << 12, + CFS_HASH_DEPTH = 1 << 12, /** * rehash is always scheduled in a different thread, so current * change on hash table is non-blocking */ - CFS_HASH_NBLK_CHANGE = 1 << 13, + CFS_HASH_NBLK_CHANGE = 1 << 13, /** NB, we typed hs_flags as __u16, please change it * if you need to extend >=16 flags */ }; /** most used attributes */ -#define CFS_HASH_DEFAULT (CFS_HASH_RW_BKTLOCK | \ - CFS_HASH_COUNTER | CFS_HASH_REHASH) +#define CFS_HASH_DEFAULT (CFS_HASH_RW_BKTLOCK | \ + CFS_HASH_COUNTER | CFS_HASH_REHASH) /** * cfs_hash is a hash-table implementation for general purpose, it can support: @@ -211,7 +207,7 @@ enum cfs_hash_tag { struct cfs_hash { /** serialize with rehash, or serialize all operations if * the hash-table has CFS_HASH_NO_BKTLOCK */ - union cfs_hash_lock hs_lock; + union cfs_hash_lock hs_lock; /** hash operations */ struct cfs_hash_ops *hs_ops; /** hash lock operations */ @@ -219,57 +215,57 @@ struct cfs_hash { /** hash list operations */ struct cfs_hash_hlist_ops *hs_hops; /** hash buckets-table */ - struct cfs_hash_bucket **hs_buckets; + struct cfs_hash_bucket **hs_buckets; /** total number of items on this hash-table */ - atomic_t hs_count; + atomic_t hs_count; /** hash flags, see cfs_hash_tag for detail */ - __u16 hs_flags; + __u16 hs_flags; /** # of extra-bytes for bucket, for user saving extended attributes */ - __u16 hs_extra_bytes; + __u16 hs_extra_bytes; /** wants to iterate */ - __u8 hs_iterating; + __u8 hs_iterating; /** hash-table is dying */ - __u8 hs_exiting; + __u8 hs_exiting; /** current hash bits */ - __u8 hs_cur_bits; + __u8 hs_cur_bits; /** min hash bits */ - __u8 hs_min_bits; + __u8 hs_min_bits; /** max hash bits */ - __u8 hs_max_bits; + __u8 hs_max_bits; /** bits for rehash */ - __u8 hs_rehash_bits; + __u8 hs_rehash_bits; /** bits for each bucket */ - __u8 hs_bkt_bits; + __u8 hs_bkt_bits; /** resize min threshold */ - __u16 hs_min_theta; + __u16 hs_min_theta; /** resize max threshold */ - __u16 hs_max_theta; + __u16 hs_max_theta; /** resize count */ - __u32 hs_rehash_count; + __u32 hs_rehash_count; /** # of iterators (caller of cfs_hash_for_each_*) */ - __u32 hs_iterators; + __u32 hs_iterators; /** rehash workitem */ - cfs_workitem_t hs_rehash_wi; + cfs_workitem_t hs_rehash_wi; /** refcount on this hash table */ - atomic_t hs_refcount; + atomic_t hs_refcount; /** rehash buckets-table */ - struct cfs_hash_bucket **hs_rehash_buckets; + struct cfs_hash_bucket **hs_rehash_buckets; #if CFS_HASH_DEBUG_LEVEL >= CFS_HASH_DEBUG_1 /** serialize debug members */ spinlock_t hs_dep_lock; /** max depth */ - unsigned int hs_dep_max; + unsigned int hs_dep_max; /** id of the deepest bucket */ - unsigned int hs_dep_bkt; + unsigned int hs_dep_bkt; /** offset in the deepest bucket */ - unsigned int hs_dep_off; + unsigned int hs_dep_off; /** bits when we found the max depth */ - unsigned int hs_dep_bits; + unsigned int hs_dep_bits; /** workitem to output max depth */ - cfs_workitem_t hs_dep_wi; + cfs_workitem_t hs_dep_wi; #endif /** name of htable */ - char hs_name[0]; + char hs_name[0]; }; struct cfs_hash_lock_ops { @@ -324,11 +320,11 @@ struct cfs_hash_ops { }; /** total number of buckets in @hs */ -#define CFS_HASH_NBKT(hs) \ +#define CFS_HASH_NBKT(hs) \ (1U << ((hs)->hs_cur_bits - (hs)->hs_bkt_bits)) /** total number of buckets in @hs while rehashing */ -#define CFS_HASH_RH_NBKT(hs) \ +#define CFS_HASH_RH_NBKT(hs) \ (1U << ((hs)->hs_rehash_bits - (hs)->hs_bkt_bits)) /** number of hlist for in bucket */ @@ -433,19 +429,22 @@ cfs_hash_with_nblk_change(struct cfs_hash *hs) static inline int cfs_hash_is_exiting(struct cfs_hash *hs) -{ /* cfs_hash_destroy is called */ +{ + /* cfs_hash_destroy is called */ return hs->hs_exiting; } static inline int cfs_hash_is_rehashing(struct cfs_hash *hs) -{ /* rehash is launched */ +{ + /* rehash is launched */ return hs->hs_rehash_bits != 0; } static inline int cfs_hash_is_iterating(struct cfs_hash *hs) -{ /* someone is calling cfs_hash_for_each_* */ +{ + /* someone is calling cfs_hash_for_each_* */ return hs->hs_iterating || hs->hs_iterators != 0; } @@ -641,13 +640,6 @@ cfs_hash_bd_lookup_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, struct hlist_node * cfs_hash_bd_peek_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, const void *key); -struct hlist_node * -cfs_hash_bd_findadd_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, - const void *key, struct hlist_node *hnode, - int insist_add); -struct hlist_node * -cfs_hash_bd_finddel_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, - const void *key, struct hlist_node *hnode); /** * operations on cfs_hash bucket (bd: bucket descriptor), @@ -758,7 +750,7 @@ static inline void cfs_hash_bucket_validate(struct cfs_hash *hs, struct cfs_hash_bd *bd, struct hlist_node *hnode) { - struct cfs_hash_bd bds[2]; + struct cfs_hash_bd bds[2]; cfs_hash_dual_bd_get(hs, cfs_hash_key(hs, hnode), bds); LASSERT(bds[0].bd_bucket == bd->bd_bucket || @@ -777,9 +769,9 @@ cfs_hash_bucket_validate(struct cfs_hash *hs, struct cfs_hash_bd *bd, #endif /* CFS_HASH_DEBUG_LEVEL */ -#define CFS_HASH_THETA_BITS 10 -#define CFS_HASH_MIN_THETA (1U << (CFS_HASH_THETA_BITS - 1)) -#define CFS_HASH_MAX_THETA (1U << (CFS_HASH_THETA_BITS + 1)) +#define CFS_HASH_THETA_BITS 10 +#define CFS_HASH_MIN_THETA (1U << (CFS_HASH_THETA_BITS - 1)) +#define CFS_HASH_MAX_THETA (1U << (CFS_HASH_THETA_BITS + 1)) /* Return integer component of theta */ static inline int __cfs_hash_theta_int(int theta) @@ -848,20 +840,20 @@ cfs_hash_u64_hash(const __u64 key, unsigned mask) } /** iterate over all buckets in @bds (array of struct cfs_hash_bd) */ -#define cfs_hash_for_each_bd(bds, n, i) \ +#define cfs_hash_for_each_bd(bds, n, i) \ for (i = 0; i < n && (bds)[i].bd_bucket != NULL; i++) /** iterate over all buckets of @hs */ -#define cfs_hash_for_each_bucket(hs, bd, pos) \ - for (pos = 0; \ - pos < CFS_HASH_NBKT(hs) && \ +#define cfs_hash_for_each_bucket(hs, bd, pos) \ + for (pos = 0; \ + pos < CFS_HASH_NBKT(hs) && \ ((bd)->bd_bucket = (hs)->hs_buckets[pos]) != NULL; pos++) /** iterate over all hlist of bucket @bd */ -#define cfs_hash_bd_for_each_hlist(hs, bd, hlist) \ - for ((bd)->bd_offset = 0; \ - (bd)->bd_offset < CFS_HASH_BKT_NHLIST(hs) && \ - (hlist = cfs_hash_bd_hhead(hs, bd)) != NULL; \ +#define cfs_hash_bd_for_each_hlist(hs, bd, hlist) \ + for ((bd)->bd_offset = 0; \ + (bd)->bd_offset < CFS_HASH_BKT_NHLIST(hs) && \ + (hlist = cfs_hash_bd_hhead(hs, bd)) != NULL; \ (bd)->bd_offset++) /* !__LIBCFS__HASH_H__ */ diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h index a989d2666230..41f3d810aea4 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h @@ -91,7 +91,7 @@ typedef int (*libcfs_kkuc_cb_t)(__u32 data, void *cb_arg); /* Kernel methods */ int libcfs_kkuc_msg_put(struct file *fp, void *payload); int libcfs_kkuc_group_put(int group, void *payload); -int libcfs_kkuc_group_add(struct file *fp, int uid, int group, +int libcfs_kkuc_group_add(struct file *fp, int uid, unsigned int group, __u32 data); int libcfs_kkuc_group_rem(int uid, int group); int libcfs_kkuc_group_foreach(int group, libcfs_kkuc_cb_t cb_func, diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h index f0b0423a716b..d6273e143324 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h @@ -185,8 +185,6 @@ int libcfs_debug_cleanup(void); int libcfs_debug_clear_buffer(void); int libcfs_debug_mark_buffer(const char *text); -void libcfs_debug_set_level(unsigned int debug_level); - /* * allocate per-cpu-partition data, returned value is an array of pointers, * variable can be indexed by CPU ID. diff --git a/drivers/staging/lustre/include/linux/lnet/api.h b/drivers/staging/lustre/include/linux/lnet/api.h index 9493d5e236c5..75285fde15e8 100644 --- a/drivers/staging/lustre/include/linux/lnet/api.h +++ b/drivers/staging/lustre/include/linux/lnet/api.h @@ -161,12 +161,6 @@ int LNetEQAlloc(unsigned int count_in, int LNetEQFree(lnet_handle_eq_t eventq_in); -int LNetEQGet(lnet_handle_eq_t eventq_in, - lnet_event_t *event_out); - -int LNetEQWait(lnet_handle_eq_t eventq_in, - lnet_event_t *event_out); - int LNetEQPoll(lnet_handle_eq_t *eventqs_in, int neq_in, int timeout_ms, diff --git a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h index b61d5045a566..b67a6607bb3b 100644 --- a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h +++ b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h @@ -23,7 +23,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012 - 2015, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/include/linux/lnet/lib-types.h b/drivers/staging/lustre/include/linux/lnet/lib-types.h index d792c4adb0ca..3bb9468e0b9d 100644 --- a/drivers/staging/lustre/include/linux/lnet/lib-types.h +++ b/drivers/staging/lustre/include/linux/lnet/lib-types.h @@ -23,7 +23,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012 - 2015, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/include/linux/lnet/nidstr.h b/drivers/staging/lustre/include/linux/lnet/nidstr.h index 46ad9147ad2a..4fc9ddce829d 100644 --- a/drivers/staging/lustre/include/linux/lnet/nidstr.h +++ b/drivers/staging/lustre/include/linux/lnet/nidstr.h @@ -23,7 +23,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011 - 2015, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ #ifndef _LNET_NIDSTRINGS_H #define _LNET_NIDSTRINGS_H diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 7c730e3f7453..72af486b65df 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -2865,7 +2865,7 @@ static int __init kiblnd_module_init(void) return 0; } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Kernel OpenIB gen2 LND v2.00"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h index 263db37de7c8..025faa9f86b3 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c index 260750354a41..c7b9ccb13f1c 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c index ecfe73302350..05aa90ea597a 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -2621,8 +2621,8 @@ ksocknal_enumerate_interfaces(ksock_net_t *net) net->ksnn_interfaces[j].ksni_ipaddr = ip; net->ksnn_interfaces[j].ksni_netmask = mask; - strncpy(&net->ksnn_interfaces[j].ksni_name[0], - names[i], IFNAMSIZ); + strlcpy(net->ksnn_interfaces[j].ksni_name, + names[i], sizeof(net->ksnn_interfaces[j].ksni_name)); j++; } @@ -2805,8 +2805,9 @@ ksocknal_startup(lnet_ni_t *ni) goto fail_1; } - strncpy(&net->ksnn_interfaces[i].ksni_name[0], - ni->ni_interfaces[i], IFNAMSIZ); + strlcpy(net->ksnn_interfaces[i].ksni_name, + ni->ni_interfaces[i], + sizeof(net->ksnn_interfaces[i].ksni_name)); } net->ksnn_ninterfaces = i; } @@ -2868,7 +2869,7 @@ ksocknal_module_init(void) return 0; } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Kernel TCP Socket LND v3.0.0"); MODULE_LICENSE("GPL"); MODULE_VERSION("3.0.0"); diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h index b349847f9cf9..f4fa72550657 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h @@ -679,6 +679,9 @@ int ksocknal_lib_recv_kiov(ksock_conn_t *conn); int ksocknal_lib_get_conn_tunables(ksock_conn_t *conn, int *txmem, int *rxmem, int *nagle); +void ksocknal_read_callback(ksock_conn_t *conn); +void ksocknal_write_callback(ksock_conn_t *conn); + int ksocknal_tunables_init(void); void ksocknal_lib_csum_tx(ksock_tx_t *tx); diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c index 9de4f23910d8..cf8e43bd3c03 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c @@ -580,8 +580,6 @@ ksocknal_lib_push_conn(ksock_conn_t *conn) ksocknal_connsock_decref(conn); } -extern void ksocknal_read_callback(ksock_conn_t *conn); -extern void ksocknal_write_callback(ksock_conn_t *conn); /* * socket call back in Linux */ diff --git a/drivers/staging/lustre/lnet/lnet/acceptor.c b/drivers/staging/lustre/lnet/lnet/acceptor.c index 92ca1dd64076..fed57d90028d 100644 --- a/drivers/staging/lustre/lnet/lnet/acceptor.c +++ b/drivers/staging/lustre/lnet/lnet/acceptor.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c index 395412639935..362282fa00bf 100644 --- a/drivers/staging/lustre/lnet/lnet/api-ni.c +++ b/drivers/staging/lustre/lnet/lnet/api-ni.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -354,16 +354,6 @@ lnet_counters_reset(void) lnet_net_unlock(LNET_LOCK_EX); } -EXPORT_SYMBOL(lnet_counters_reset); - -static __u64 -lnet_create_interface_cookie(void) -{ - /* NB the interface cookie in wire handles guards against delayed - * replies and ACKs appearing valid after reboot. - */ - return ktime_get_ns(); -} static char * lnet_res_type2str(int type) @@ -553,8 +543,11 @@ lnet_prepare(lnet_pid_t requested_pid) rc = lnet_create_remote_nets_table(); if (rc != 0) goto failed; - - the_lnet.ln_interface_cookie = lnet_create_interface_cookie(); + /* + * NB the interface cookie in wire handles guards against delayed + * replies and ACKs appearing valid after reboot. + */ + the_lnet.ln_interface_cookie = ktime_get_ns(); the_lnet.ln_counters = cfs_percpt_alloc(lnet_cpt_table(), sizeof(lnet_counters_t)); @@ -1159,7 +1152,6 @@ lnet_init(void) lnet_register_lnd(&the_lolnd); return 0; } -EXPORT_SYMBOL(lnet_init); /** * Finalize LNet library. @@ -1183,7 +1175,6 @@ lnet_fini(void) the_lnet.ln_init = 0; } -EXPORT_SYMBOL(lnet_fini); /** * Set LNet PID and start LNet interfaces, routing, and forwarding. diff --git a/drivers/staging/lustre/lnet/lnet/config.c b/drivers/staging/lustre/lnet/lnet/config.c index 1b3bc8386524..284a3c271bc6 100644 --- a/drivers/staging/lustre/lnet/lnet/config.c +++ b/drivers/staging/lustre/lnet/lnet/config.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -650,8 +650,8 @@ lnet_parse_route(char *str, int *im_a_router) INIT_LIST_HEAD(&nets); /* save a copy of the string for error messages */ - strncpy(cmd, str, sizeof(cmd) - 1); - cmd[sizeof(cmd) - 1] = 0; + strncpy(cmd, str, sizeof(cmd)); + cmd[sizeof(cmd) - 1] = '\0'; sep = str; for (;;) { @@ -972,11 +972,13 @@ lnet_splitnets(char *source, struct list_head *nets) return 0; offset += (int)(sep - tb->ltb_text); - tb2 = lnet_new_text_buf(strlen(sep)); + len = strlen(sep); + tb2 = lnet_new_text_buf(len); if (tb2 == NULL) return -ENOMEM; - strcpy(tb2->ltb_text, sep); + strncpy(tb2->ltb_text, sep, len); + tb2->ltb_text[len] = '\0'; list_add_tail(&tb2->ltb_list, nets); tb = tb2; @@ -1021,8 +1023,8 @@ lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip) tb = list_entry(raw_entries.next, struct lnet_text_buf_t, ltb_list); - strncpy(source, tb->ltb_text, sizeof(source)-1); - source[sizeof(source)-1] = 0; + strncpy(source, tb->ltb_text, sizeof(source)); + source[sizeof(source)-1] = '\0'; /* replace ltb_text with the network(s) add on match */ rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip); @@ -1103,12 +1105,6 @@ lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip) return count; } -static void -lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip) -{ - LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); -} - static int lnet_ipaddr_enumerate(__u32 **ipaddrsp) { @@ -1169,7 +1165,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) rc = nip; } } - lnet_ipaddr_free_enumeration(ipaddrs, nif); + LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); } return nip; } @@ -1195,7 +1191,7 @@ lnet_parse_ip2nets(char **networksp, char *ip2nets) } rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip); - lnet_ipaddr_free_enumeration(ipaddrs, nip); + LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); if (rc < 0) { LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc); diff --git a/drivers/staging/lustre/lnet/lnet/lib-eq.c b/drivers/staging/lustre/lnet/lnet/lib-eq.c index 60889ebd2f2b..64f94a690081 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-eq.c +++ b/drivers/staging/lustre/lnet/lnet/lib-eq.c @@ -282,15 +282,6 @@ lnet_eq_dequeue_event(lnet_eq_t *eq, lnet_event_t *ev) * at least one event between this event and the last event obtained from the * EQ has been dropped due to limited space in the EQ. */ -int -LNetEQGet(lnet_handle_eq_t eventq, lnet_event_t *event) -{ - int which; - - return LNetEQPoll(&eventq, 1, 0, - event, &which); -} -EXPORT_SYMBOL(LNetEQGet); /** * Block the calling process until there is an event in the EQ. @@ -308,15 +299,6 @@ EXPORT_SYMBOL(LNetEQGet); * at least one event between this event and the last event obtained from the * EQ has been dropped due to limited space in the EQ. */ -int -LNetEQWait(lnet_handle_eq_t eventq, lnet_event_t *event) -{ - int which; - - return LNetEQPoll(&eventq, 1, LNET_TIME_FOREVER, - event, &which); -} -EXPORT_SYMBOL(LNetEQWait); static int lnet_eq_wait_locked(int *timeout_ms) diff --git a/drivers/staging/lustre/lnet/lnet/lib-move.c b/drivers/staging/lustre/lnet/lnet/lib-move.c index 5631f60a39bc..fb8f7be043ec 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-move.c +++ b/drivers/staging/lustre/lnet/lnet/lib-move.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -1645,7 +1645,6 @@ lnet_msgtyp2str(int type) return "<UNKNOWN>"; } } -EXPORT_SYMBOL(lnet_msgtyp2str); void lnet_print_hdr(lnet_hdr_t *hdr) diff --git a/drivers/staging/lustre/lnet/lnet/lib-ptl.c b/drivers/staging/lustre/lnet/lnet/lib-ptl.c index b4f573ab62cc..bd7b071b2873 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-ptl.c +++ b/drivers/staging/lustre/lnet/lnet/lib-ptl.c @@ -21,7 +21,7 @@ * GPL HEADER END */ /* - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lnet/lnet/lib-socket.c b/drivers/staging/lustre/lnet/lnet/lib-socket.c index 6f7ef4c737cd..589ecc84d1b8 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-socket.c +++ b/drivers/staging/lustre/lnet/lnet/lib-socket.c @@ -23,7 +23,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, 2015 Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lnet/lnet/module.c b/drivers/staging/lustre/lnet/lnet/module.c index 576201a8390c..c93c00752a4c 100644 --- a/drivers/staging/lustre/lnet/lnet/module.c +++ b/drivers/staging/lustre/lnet/lnet/module.c @@ -27,7 +27,7 @@ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -146,7 +146,7 @@ fini_lnet(void) lnet_fini(); } -MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("LNet v3.1"); MODULE_LICENSE("GPL"); MODULE_VERSION("1.0.0"); diff --git a/drivers/staging/lustre/lnet/lnet/router.c b/drivers/staging/lustre/lnet/lnet/router.c index 4ea651c6db3a..f5faa414d250 100644 --- a/drivers/staging/lustre/lnet/lnet/router.c +++ b/drivers/staging/lustre/lnet/lnet/router.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. * * This file is part of Portals * http://sourceforge.net/projects/sandiaportals/ diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c index 0605c651f797..1f04cc1fc31c 100644 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -358,7 +358,7 @@ out: } static void -brw_server_rpc_done(srpc_server_rpc_t *rpc) +brw_server_rpc_done(struct srpc_server_rpc *rpc) { srpc_bulk_t *blk = rpc->srpc_bulk; @@ -378,7 +378,7 @@ brw_server_rpc_done(srpc_server_rpc_t *rpc) } static int -brw_bulk_ready(srpc_server_rpc_t *rpc, int status) +brw_bulk_ready(struct srpc_server_rpc *rpc, int status) { __u64 magic = BRW_MAGIC; srpc_brw_reply_t *reply = &rpc->srpc_replymsg.msg_body.brw_reply; diff --git a/drivers/staging/lustre/lnet/selftest/conctl.c b/drivers/staging/lustre/lnet/selftest/conctl.c index 556c837cf62c..a534665403e5 100644 --- a/drivers/staging/lustre/lnet/selftest/conctl.c +++ b/drivers/staging/lustre/lnet/selftest/conctl.c @@ -925,5 +925,3 @@ out: return rc; } - -EXPORT_SYMBOL(lstcon_ioctl_entry); diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.c b/drivers/staging/lustre/lnet/selftest/conrpc.c index 64a0335934f3..1066c70434b1 100644 --- a/drivers/staging/lustre/lnet/selftest/conrpc.c +++ b/drivers/staging/lustre/lnet/selftest/conrpc.c @@ -612,8 +612,8 @@ lstcon_sesrpc_prep(lstcon_node_t *nd, int transop, msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst; msrq->mksn_sid = console_session.ses_id; msrq->mksn_force = console_session.ses_force; - strncpy(msrq->mksn_name, console_session.ses_name, - strlen(console_session.ses_name)); + strlcpy(msrq->mksn_name, console_session.ses_name, + sizeof(msrq->mksn_name)); break; case LST_TRANS_SESEND: diff --git a/drivers/staging/lustre/lnet/selftest/console.c b/drivers/staging/lustre/lnet/selftest/console.c index d315dd44ae3b..5619fc430e8d 100644 --- a/drivers/staging/lustre/lnet/selftest/console.c +++ b/drivers/staging/lustre/lnet/selftest/console.c @@ -277,12 +277,6 @@ lstcon_group_find(const char *name, lstcon_group_t **grpp) return -ENOENT; } -static void -lstcon_group_put(lstcon_group_t *grp) -{ - lstcon_group_decref(grp); -} - static int lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create) @@ -324,8 +318,6 @@ lstcon_group_ndlink_move(lstcon_group_t *old, list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]); list_add_tail(&ndl->ndl_link, &new->grp_ndl_list); new->grp_nnode++; - - return; } static void @@ -436,7 +428,7 @@ lstcon_group_nodes_add(lstcon_group_t *grp, } if (rc != 0) { - lstcon_group_put(tmp); + lstcon_group_decref(tmp); return rc; } @@ -445,7 +437,7 @@ lstcon_group_nodes_add(lstcon_group_t *grp, tmp, lstcon_sesrpc_condition, &trans); if (rc != 0) { CERROR("Can't create transaction: %d\n", rc); - lstcon_group_put(tmp); + lstcon_group_decref(tmp); return rc; } @@ -460,7 +452,7 @@ lstcon_group_nodes_add(lstcon_group_t *grp, lstcon_rpc_trans_destroy(trans); lstcon_group_move(tmp, grp); - lstcon_group_put(tmp); + lstcon_group_decref(tmp); return rc; } @@ -510,12 +502,12 @@ lstcon_group_nodes_remove(lstcon_group_t *grp, lstcon_rpc_trans_destroy(trans); /* release nodes anyway, because we can't rollback status */ - lstcon_group_put(tmp); + lstcon_group_decref(tmp); return rc; error: lstcon_group_move(tmp, grp); - lstcon_group_put(tmp); + lstcon_group_decref(tmp); return rc; } @@ -529,7 +521,7 @@ lstcon_group_add(char *name) rc = (lstcon_group_find(name, &grp) == 0) ? -EEXIST : 0; if (rc != 0) { /* find a group with same name */ - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } @@ -563,14 +555,14 @@ lstcon_nodes_add(char *name, int count, lnet_process_id_t *ids_up, if (grp->grp_ref > 2) { /* referred by other threads or test */ CDEBUG(D_NET, "Group %s is busy\n", name); - lstcon_group_put(grp); + lstcon_group_decref(grp); return -EBUSY; } rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up); - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } @@ -591,7 +583,7 @@ lstcon_group_del(char *name) if (grp->grp_ref > 2) { /* referred by others threads or test */ CDEBUG(D_NET, "Group %s is busy\n", name); - lstcon_group_put(grp); + lstcon_group_decref(grp); return -EBUSY; } @@ -600,7 +592,7 @@ lstcon_group_del(char *name) grp, lstcon_sesrpc_condition, &trans); if (rc != 0) { CERROR("Can't create transaction: %d\n", rc); - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } @@ -608,10 +600,10 @@ lstcon_group_del(char *name) lstcon_rpc_trans_destroy(trans); - lstcon_group_put(grp); + lstcon_group_decref(grp); /* -ref for session, it's destroyed, * status can't be rolled back, destroy group anyway */ - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } @@ -631,7 +623,7 @@ lstcon_group_clean(char *name, int args) if (grp->grp_ref > 2) { /* referred by test */ CDEBUG(D_NET, "Group %s is busy\n", name); - lstcon_group_put(grp); + lstcon_group_decref(grp); return -EBUSY; } @@ -640,10 +632,10 @@ lstcon_group_clean(char *name, int args) lstcon_group_drain(grp, args); - lstcon_group_put(grp); + lstcon_group_decref(grp); /* release empty group */ if (list_empty(&grp->grp_ndl_list)) - lstcon_group_put(grp); + lstcon_group_decref(grp); return 0; } @@ -664,16 +656,16 @@ lstcon_nodes_remove(char *name, int count, if (grp->grp_ref > 2) { /* referred by test */ CDEBUG(D_NET, "Group %s is busy\n", name); - lstcon_group_put(grp); + lstcon_group_decref(grp); return -EBUSY; } rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up); - lstcon_group_put(grp); + lstcon_group_decref(grp); /* release empty group */ if (list_empty(&grp->grp_ndl_list)) - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } @@ -694,7 +686,7 @@ lstcon_group_refresh(char *name, struct list_head *result_up) if (grp->grp_ref > 2) { /* referred by test */ CDEBUG(D_NET, "Group %s is busy\n", name); - lstcon_group_put(grp); + lstcon_group_decref(grp); return -EBUSY; } @@ -705,7 +697,7 @@ lstcon_group_refresh(char *name, struct list_head *result_up) if (rc != 0) { /* local error, return */ CDEBUG(D_NET, "Can't create transaction: %d\n", rc); - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } @@ -715,7 +707,7 @@ lstcon_group_refresh(char *name, struct list_head *result_up) lstcon_rpc_trans_destroy(trans); /* -ref for me */ - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } @@ -797,7 +789,7 @@ lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p, /* verbose query */ rc = lstcon_nodes_getent(&grp->grp_ndl_list, index_p, count_p, dents_up); - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } @@ -806,7 +798,7 @@ lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p, LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t)); if (gentp == NULL) { CERROR("Can't allocate ndlist_ent\n"); - lstcon_group_put(grp); + lstcon_group_decref(grp); return -ENOMEM; } @@ -819,7 +811,7 @@ lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p, LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t)); - lstcon_group_put(grp); + lstcon_group_decref(grp); return 0; } @@ -1096,8 +1088,8 @@ lstcon_batch_destroy(lstcon_batch_t *bat) list_del(&test->tes_link); - lstcon_group_put(test->tes_src_grp); - lstcon_group_put(test->tes_dst_grp); + lstcon_group_decref(test->tes_src_grp); + lstcon_group_decref(test->tes_dst_grp); LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[test->tes_paramlen])); @@ -1352,10 +1344,10 @@ out: LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen])); if (dst_grp != NULL) - lstcon_group_put(dst_grp); + lstcon_group_decref(dst_grp); if (src_grp != NULL) - lstcon_group_put(src_grp); + lstcon_group_decref(src_grp); return rc; } @@ -1518,7 +1510,7 @@ lstcon_group_stat(char *grp_name, int timeout, struct list_head *result_up) rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up); - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } @@ -1556,13 +1548,13 @@ lstcon_nodes_stat(int count, lnet_process_id_t *ids_up, } if (rc != 0) { - lstcon_group_put(tmp); + lstcon_group_decref(tmp); return rc; } rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up); - lstcon_group_put(tmp); + lstcon_group_decref(tmp); return rc; } @@ -1629,7 +1621,7 @@ lstcon_group_debug(int timeout, char *name, rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL, timeout, result_up); - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } @@ -1666,14 +1658,14 @@ lstcon_nodes_debug(int timeout, } if (rc != 0) { - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL, timeout, result_up); - lstcon_group_put(grp); + lstcon_group_decref(grp); return rc; } @@ -1739,7 +1731,8 @@ lstcon_session_new(char *name, int key, unsigned feats, console_session.ses_feats_updated = 0; console_session.ses_timeout = (timeout <= 0) ? LST_CONSOLE_TIMEOUT : timeout; - strcpy(console_session.ses_name, name); + strlcpy(console_session.ses_name, name, + sizeof(console_session.ses_name)); rc = lstcon_batch_add(LST_DEFAULT_BATCH); if (rc != 0) @@ -1847,7 +1840,7 @@ lstcon_session_end(void) lstcon_group_t, grp_link); LASSERT(grp->grp_ref == 1); - lstcon_group_put(grp); + lstcon_group_decref(grp); } /* all nodes should be released */ @@ -1891,7 +1884,7 @@ lstcon_session_feats_check(unsigned feats) } static int -lstcon_acceptor_handle(srpc_server_rpc_t *rpc) +lstcon_acceptor_handle(struct srpc_server_rpc *rpc) { srpc_msg_t *rep = &rpc->srpc_replymsg; srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg; @@ -1959,14 +1952,15 @@ lstcon_acceptor_handle(srpc_server_rpc_t *rpc) if (grp->grp_userland == 0) grp->grp_userland = 1; - strcpy(jrep->join_session, console_session.ses_name); + strlcpy(jrep->join_session, console_session.ses_name, + sizeof(jrep->join_session)); jrep->join_timeout = console_session.ses_timeout; jrep->join_status = 0; out: rep->msg_ses_feats = console_session.ses_features; if (grp != NULL) - lstcon_group_put(grp); + lstcon_group_decref(grp); mutex_unlock(&console_session.ses_mutex); diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c index f18e50036809..1a2da7430190 100644 --- a/drivers/staging/lustre/lnet/selftest/framework.c +++ b/drivers/staging/lustre/lnet/selftest/framework.c @@ -111,7 +111,7 @@ static struct smoketest_framework { spinlock_t fw_lock; /* serialise */ sfw_session_t *fw_session; /* _the_ session */ int fw_shuttingdown; /* shutdown in progress */ - srpc_server_rpc_t *fw_active_srpc; /* running RPC */ + struct srpc_server_rpc *fw_active_srpc;/* running RPC */ } sfw_data; /* forward ref's */ @@ -722,7 +722,7 @@ sfw_unpack_addtest_req(srpc_msg_t *msg) } static int -sfw_add_test_instance(sfw_batch_t *tsb, srpc_server_rpc_t *rpc) +sfw_add_test_instance(sfw_batch_t *tsb, struct srpc_server_rpc *rpc) { srpc_msg_t *msg = &rpc->srpc_reqstbuf->buf_msg; srpc_test_reqst_t *req = &msg->msg_body.tes_reqst; @@ -1091,7 +1091,7 @@ sfw_query_batch(sfw_batch_t *tsb, int testidx, srpc_batch_reply_t *reply) } void -sfw_free_pages(srpc_server_rpc_t *rpc) +sfw_free_pages(struct srpc_server_rpc *rpc) { srpc_free_bulk(rpc->srpc_bulk); rpc->srpc_bulk = NULL; @@ -1112,7 +1112,7 @@ sfw_alloc_pages(struct srpc_server_rpc *rpc, int cpt, int npages, int len, } static int -sfw_add_test(srpc_server_rpc_t *rpc) +sfw_add_test(struct srpc_server_rpc *rpc) { sfw_session_t *sn = sfw_data.fw_session; srpc_test_reply_t *reply = &rpc->srpc_replymsg.msg_body.tes_reply; diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c index 7005002c15da..2acf6ec717be 100644 --- a/drivers/staging/lustre/lnet/selftest/rpc.c +++ b/drivers/staging/lustre/lnet/selftest/rpc.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -445,15 +445,6 @@ srpc_post_active_rdma(int portal, __u64 matchbits, void *buf, int len, } static int -srpc_post_active_rqtbuf(lnet_process_id_t peer, int service, void *buf, - int len, lnet_handle_md_t *mdh, srpc_event_t *ev) -{ - return srpc_post_active_rdma(srpc_serv_portal(service), service, - buf, len, LNET_MD_OP_PUT, peer, - LNET_NID_ANY, mdh, ev); -} - -static int srpc_post_passive_rqtbuf(int service, int local, void *buf, int len, lnet_handle_md_t *mdh, srpc_event_t *ev) { @@ -798,9 +789,11 @@ srpc_send_request(srpc_client_rpc_t *rpc) ev->ev_data = rpc; ev->ev_type = SRPC_REQUEST_SENT; - rc = srpc_post_active_rqtbuf(rpc->crpc_dest, rpc->crpc_service, - &rpc->crpc_reqstmsg, sizeof(srpc_msg_t), - &rpc->crpc_reqstmdh, ev); + rc = srpc_post_active_rdma(srpc_serv_portal(rpc->crpc_service), + rpc->crpc_service, &rpc->crpc_reqstmsg, + sizeof(srpc_msg_t), LNET_MD_OP_PUT, + rpc->crpc_dest, LNET_NID_ANY, + &rpc->crpc_reqstmdh, ev); if (rc != 0) { LASSERT(rc == -ENOMEM); ev->ev_fired = 1; /* no more event expected */ @@ -866,7 +859,7 @@ srpc_prepare_bulk(srpc_client_rpc_t *rpc) } static int -srpc_do_bulk(srpc_server_rpc_t *rpc) +srpc_do_bulk(struct srpc_server_rpc *rpc) { srpc_event_t *ev = &rpc->srpc_ev; srpc_bulk_t *bk = rpc->srpc_bulk; @@ -894,7 +887,7 @@ srpc_do_bulk(srpc_server_rpc_t *rpc) /* only called from srpc_handle_rpc */ static void -srpc_server_rpc_done(srpc_server_rpc_t *rpc, int status) +srpc_server_rpc_done(struct srpc_server_rpc *rpc, int status) { struct srpc_service_cd *scd = rpc->srpc_scd; struct srpc_service *sv = scd->scd_svc; @@ -1404,7 +1397,7 @@ srpc_lnet_ev_handler(lnet_event_t *ev) struct srpc_service_cd *scd; srpc_event_t *rpcev = ev->md.user_ptr; srpc_client_rpc_t *crpc; - srpc_server_rpc_t *srpc; + struct srpc_server_rpc *srpc; srpc_buffer_t *buffer; srpc_service_t *sv; srpc_msg_t *msg; diff --git a/drivers/staging/lustre/lnet/selftest/selftest.h b/drivers/staging/lustre/lnet/selftest/selftest.h index 8a77d3fdfa54..870498339538 100644 --- a/drivers/staging/lustre/lnet/selftest/selftest.h +++ b/drivers/staging/lustre/lnet/selftest/selftest.h @@ -182,7 +182,7 @@ typedef struct swi_workitem { } swi_workitem_t; /* server-side state of a RPC */ -typedef struct srpc_server_rpc { +struct srpc_server_rpc { /* chain on srpc_service::*_rpcq */ struct list_head srpc_list; struct srpc_service_cd *srpc_scd; @@ -198,7 +198,7 @@ typedef struct srpc_server_rpc { unsigned int srpc_aborted; /* being given up */ int srpc_status; void (*srpc_done)(struct srpc_server_rpc *); -} srpc_server_rpc_t; +}; /* client-side state of a RPC */ typedef struct srpc_client_rpc { @@ -318,8 +318,8 @@ typedef struct srpc_service { * - sv_handler: process incoming RPC request * - sv_bulk_ready: notify bulk data */ - int (*sv_handler) (srpc_server_rpc_t *); - int (*sv_bulk_ready) (srpc_server_rpc_t *, int); + int (*sv_handler)(struct srpc_server_rpc *); + int (*sv_bulk_ready)(struct srpc_server_rpc *, int); } srpc_service_t; typedef struct { @@ -423,9 +423,9 @@ void sfw_abort_rpc(srpc_client_rpc_t *rpc); void sfw_post_rpc(srpc_client_rpc_t *rpc); void sfw_client_rpc_done(srpc_client_rpc_t *rpc); void sfw_unpack_message(srpc_msg_t *msg); -void sfw_free_pages(srpc_server_rpc_t *rpc); +void sfw_free_pages(struct srpc_server_rpc *rpc); void sfw_add_bulk_page(srpc_bulk_t *bk, struct page *pg, int i); -int sfw_alloc_pages(srpc_server_rpc_t *rpc, int cpt, int npages, int len, +int sfw_alloc_pages(struct srpc_server_rpc *rpc, int cpt, int npages, int len, int sink); int sfw_make_session (srpc_mksn_reqst_t *request, srpc_mksn_reply_t *reply); @@ -440,7 +440,7 @@ void srpc_free_bulk(srpc_bulk_t *bk); srpc_bulk_t *srpc_alloc_bulk(int cpt, unsigned bulk_npg, unsigned bulk_len, int sink); int srpc_send_rpc(swi_workitem_t *wi); -int srpc_send_reply(srpc_server_rpc_t *rpc); +int srpc_send_reply(struct srpc_server_rpc *rpc); int srpc_add_service(srpc_service_t *sv); int srpc_remove_service(srpc_service_t *sv); void srpc_shutdown_service(srpc_service_t *sv); @@ -585,7 +585,7 @@ swi_state2str (int state) do { \ int __I = 2; \ while (!(cond)) { \ - CDEBUG(IS_PO2(++__I) ? D_WARNING : D_NET, \ + CDEBUG(is_power_of_2(++__I) ? D_WARNING : D_NET, \ fmt, ## __VA_ARGS__); \ spin_unlock(&(lock)); \ \ diff --git a/drivers/staging/lustre/lustre/fid/fid_internal.h b/drivers/staging/lustre/lustre/fid/fid_internal.h index 84daee1154dc..b79a813977cf 100644 --- a/drivers/staging/lustre/lustre/fid/fid_internal.h +++ b/drivers/staging/lustre/lustre/fid/fid_internal.h @@ -44,8 +44,6 @@ #include "../../include/linux/libcfs/libcfs.h" /* Functions used internally in module. */ -int seq_client_alloc_super(struct lu_client_seq *seq, - const struct lu_env *env); extern struct lprocfs_vars seq_client_debugfs_list[]; diff --git a/drivers/staging/lustre/lustre/fid/fid_request.c b/drivers/staging/lustre/lustre/fid/fid_request.c index 7c45e7479087..ff8f38dc10ce 100644 --- a/drivers/staging/lustre/lustre/fid/fid_request.c +++ b/drivers/staging/lustre/lustre/fid/fid_request.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2013, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -142,27 +142,6 @@ out_req: return rc; } -/* Request sequence-controller node to allocate new super-sequence. */ -int seq_client_alloc_super(struct lu_client_seq *seq, - const struct lu_env *env) -{ - int rc; - - mutex_lock(&seq->lcs_mutex); - - /* Check whether the connection to seq controller has been - * setup (lcs_exp != NULL) */ - if (!seq->lcs_exp) { - mutex_unlock(&seq->lcs_mutex); - return -EINPROGRESS; - } - - rc = seq_client_rpc(seq, &seq->lcs_space, - SEQ_ALLOC_SUPER, "super"); - mutex_unlock(&seq->lcs_mutex); - return rc; -} - /* Request sequence-controller node to allocate new meta-sequence. */ static int seq_client_alloc_meta(const struct lu_env *env, struct lu_client_seq *seq) @@ -483,7 +462,7 @@ static void __exit fid_mod_exit(void) ldebugfs_remove(&seq_debugfs_dir); } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre FID Module"); MODULE_LICENSE("GPL"); MODULE_VERSION("0.1.0"); diff --git a/drivers/staging/lustre/lustre/fid/lproc_fid.c b/drivers/staging/lustre/lustre/fid/lproc_fid.c index ce90c1c54a63..39f2aa32e984 100644 --- a/drivers/staging/lustre/lustre/fid/lproc_fid.c +++ b/drivers/staging/lustre/lustre/fid/lproc_fid.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/fld/fld_cache.c b/drivers/staging/lustre/lustre/fld/fld_cache.c index 446917484637..d9459e58e2ce 100644 --- a/drivers/staging/lustre/lustre/fld/fld_cache.c +++ b/drivers/staging/lustre/lustre/fld/fld_cache.c @@ -121,8 +121,8 @@ void fld_cache_fini(struct fld_cache *cache) /** * delete given node from list. */ -void fld_cache_entry_delete(struct fld_cache *cache, - struct fld_cache_entry *node) +static void fld_cache_entry_delete(struct fld_cache *cache, + struct fld_cache_entry *node) { list_del(&node->fce_list); list_del(&node->fce_lru); @@ -227,7 +227,6 @@ static int fld_cache_shrink(struct fld_cache *cache) while (cache->fci_cache_count + cache->fci_threshold > cache->fci_cache_size && curr != &cache->fci_lru) { - flde = list_entry(curr, struct fld_cache_entry, fce_lru); curr = curr->prev; fld_cache_entry_delete(cache, flde); @@ -377,8 +376,8 @@ struct fld_cache_entry * This function handles all cases of merging and breaking up of * ranges. */ -int fld_cache_insert_nolock(struct fld_cache *cache, - struct fld_cache_entry *f_new) +static int fld_cache_insert_nolock(struct fld_cache *cache, + struct fld_cache_entry *f_new) { struct fld_cache_entry *f_curr; struct fld_cache_entry *n; @@ -444,36 +443,10 @@ int fld_cache_insert(struct fld_cache *cache, return rc; } -void fld_cache_delete_nolock(struct fld_cache *cache, - const struct lu_seq_range *range) -{ - struct fld_cache_entry *flde; - struct fld_cache_entry *tmp; - struct list_head *head; - - head = &cache->fci_entries_head; - list_for_each_entry_safe(flde, tmp, head, fce_list) { - /* add list if next is end of list */ - if (range->lsr_start == flde->fce_range.lsr_start || - (range->lsr_end == flde->fce_range.lsr_end && - range->lsr_flags == flde->fce_range.lsr_flags)) { - fld_cache_entry_delete(cache, flde); - break; - } - } -} - /** * Delete FLD entry in FLD cache. * */ -void fld_cache_delete(struct fld_cache *cache, - const struct lu_seq_range *range) -{ - write_lock(&cache->fci_lock); - fld_cache_delete_nolock(cache, range); - write_unlock(&cache->fci_lock); -} struct fld_cache_entry *fld_cache_entry_lookup_nolock(struct fld_cache *cache, diff --git a/drivers/staging/lustre/lustre/fld/fld_internal.h b/drivers/staging/lustre/lustre/fld/fld_internal.h index fbb232de6c74..12eb1647b4bf 100644 --- a/drivers/staging/lustre/lustre/fld/fld_internal.h +++ b/drivers/staging/lustre/lustre/fld/fld_internal.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, 2013, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -156,20 +156,11 @@ int fld_cache_insert(struct fld_cache *cache, struct fld_cache_entry *fld_cache_entry_create(const struct lu_seq_range *range); -int fld_cache_insert_nolock(struct fld_cache *cache, - struct fld_cache_entry *f_new); -void fld_cache_delete(struct fld_cache *cache, - const struct lu_seq_range *range); -void fld_cache_delete_nolock(struct fld_cache *cache, - const struct lu_seq_range *range); int fld_cache_lookup(struct fld_cache *cache, const u64 seq, struct lu_seq_range *range); struct fld_cache_entry* fld_cache_entry_lookup(struct fld_cache *cache, struct lu_seq_range *range); -void fld_cache_entry_delete(struct fld_cache *cache, - struct fld_cache_entry *node); -void fld_dump_cache_entries(struct fld_cache *cache); struct fld_cache_entry *fld_cache_entry_lookup_nolock(struct fld_cache *cache, diff --git a/drivers/staging/lustre/lustre/fld/fld_request.c b/drivers/staging/lustre/lustre/fld/fld_request.c index 3fd91bc77da5..d92c01b74865 100644 --- a/drivers/staging/lustre/lustre/fld/fld_request.c +++ b/drivers/staging/lustre/lustre/fld/fld_request.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2013, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -501,7 +501,7 @@ static void __exit fld_mod_exit(void) ldebugfs_remove(&fld_debugfs_dir); } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre FLD"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/lustre/lustre/fld/lproc_fld.c b/drivers/staging/lustre/lustre/fld/lproc_fld.c index 603f56e6095b..41ceaa8198a7 100644 --- a/drivers/staging/lustre/lustre/fld/lproc_fld.c +++ b/drivers/staging/lustre/lustre/fld/lproc_fld.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, 2013, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/cl_object.h b/drivers/staging/lustre/lustre/include/cl_object.h index 73564f8e3884..bd7acc2a1219 100644 --- a/drivers/staging/lustre/lustre/include/cl_object.h +++ b/drivers/staging/lustre/lustre/include/cl_object.h @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -3127,7 +3127,6 @@ void cl_page_list_disown (const struct lu_env *env, struct cl_io *io, struct cl_page_list *plist); void cl_2queue_init (struct cl_2queue *queue); -void cl_2queue_add (struct cl_2queue *queue, struct cl_page *page); void cl_2queue_disown (const struct lu_env *env, struct cl_io *io, struct cl_2queue *queue); void cl_2queue_discard (const struct lu_env *env, diff --git a/drivers/staging/lustre/lustre/include/lprocfs_status.h b/drivers/staging/lustre/lustre/include/lprocfs_status.h index 9e654b218ca3..0ac8e0edcc48 100644 --- a/drivers/staging/lustre/lustre/include/lprocfs_status.h +++ b/drivers/staging/lustre/lustre/include/lprocfs_status.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -624,9 +624,6 @@ void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx, int lprocfs_single_release(struct inode *, struct file *); int lprocfs_seq_release(struct inode *, struct file *); -#define LPROCFS_CLIMP_EXIT(obd) \ - up_read(&(obd)->u.cli.cl_sem) - /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only proc entries; otherwise, you will define name##_seq_write function also for a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally, diff --git a/drivers/staging/lustre/lustre/include/lu_object.h b/drivers/staging/lustre/lustre/include/lu_object.h index fa78689748a9..1d79341a495d 100644 --- a/drivers/staging/lustre/lustre/include/lu_object.h +++ b/drivers/staging/lustre/lustre/include/lu_object.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/lustre/ll_fiemap.h b/drivers/staging/lustre/lustre/include/lustre/ll_fiemap.h index 06ce8c9ae9ad..09088f40ba88 100644 --- a/drivers/staging/lustre/lustre/include/lustre/ll_fiemap.h +++ b/drivers/staging/lustre/lustre/include/lustre/ll_fiemap.h @@ -26,6 +26,8 @@ /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2014, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h b/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h index 0b721c65c2a3..b064b5821e3f 100644 --- a/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h +++ b/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/lustre/lustre_user.h b/drivers/staging/lustre/lustre/include/lustre/lustre_user.h index 80f8ec529424..2b4dd656d5f5 100644 --- a/drivers/staging/lustre/lustre/include/lustre/lustre_user.h +++ b/drivers/staging/lustre/lustre/include/lustre/lustre_user.h @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2010, 2012, Intel Corporation. + * Copyright (c) 2010, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/lustre_disk.h b/drivers/staging/lustre/lustre/include/lustre_disk.h index 5e1ac129a681..7c6933ffc9c1 100644 --- a/drivers/staging/lustre/lustre/include/lustre_disk.h +++ b/drivers/staging/lustre/lustre/include/lustre_disk.h @@ -68,6 +68,7 @@ everything as string options */ #define LMD_MAGIC 0xbdacbd03 +#define LMD_PARAMS_MAXLEN 4096 /* gleaned from the mount command - no persistent info here */ struct lustre_mount_data { diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h index 0e75a15fe0d4..9b319f1df025 100644 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2010, 2012, Intel Corporation. + * Copyright (c) 2010, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -872,8 +872,6 @@ struct ldlm_resource { */ struct mutex lr_lvb_mutex; int lr_lvb_len; - /** protected by lr_lock */ - void *lr_lvb_data; /** When the resource was considered as contended. */ unsigned long lr_contention_time; diff --git a/drivers/staging/lustre/lustre/include/lustre_eacl.h b/drivers/staging/lustre/lustre/include/lustre_eacl.h index fee4d2c75506..0b66593a9526 100644 --- a/drivers/staging/lustre/lustre/include/lustre_eacl.h +++ b/drivers/staging/lustre/lustre/include/lustre_eacl.h @@ -76,8 +76,6 @@ extern int lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, size_t size, posix_acl_xattr_header **out); extern void -lustre_posix_acl_xattr_free(posix_acl_xattr_header *header, int size); -extern void lustre_ext_acl_xattr_free(ext_acl_xattr_header *header); extern ext_acl_xattr_header * lustre_acl_xattr_merge2ext(posix_acl_xattr_header *posix_header, int size, diff --git a/drivers/staging/lustre/lustre/include/lustre_export.h b/drivers/staging/lustre/lustre/include/lustre_export.h index 1daf4c572415..311e5aa9b0db 100644 --- a/drivers/staging/lustre/lustre/include/lustre_export.h +++ b/drivers/staging/lustre/lustre/include/lustre_export.h @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/lustre_fid.h b/drivers/staging/lustre/lustre/include/lustre_fid.h index 47c3f3750240..9b1a9c695113 100644 --- a/drivers/staging/lustre/lustre/include/lustre_fid.h +++ b/drivers/staging/lustre/lustre/include/lustre_fid.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/lustre_fld.h b/drivers/staging/lustre/lustre/include/lustre_fld.h index d8b3db9cdeba..551162624974 100644 --- a/drivers/staging/lustre/lustre/include/lustre_fld.h +++ b/drivers/staging/lustre/lustre/include/lustre_fld.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2013, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/lustre_ha.h b/drivers/staging/lustre/lustre/include/lustre_ha.h index 49dfbb14f381..5488a698dabd 100644 --- a/drivers/staging/lustre/lustre/include/lustre_ha.h +++ b/drivers/staging/lustre/lustre/include/lustre_ha.h @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/lustre_log.h b/drivers/staging/lustre/lustre/include/lustre_log.h index 1de0c4d6f7f7..e4fc8b5e1336 100644 --- a/drivers/staging/lustre/lustre/include/lustre_log.h +++ b/drivers/staging/lustre/lustre/include/lustre_log.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -94,9 +94,6 @@ int llog_open(const struct lu_env *env, struct llog_ctxt *ctxt, struct llog_handle **lgh, struct llog_logid *logid, char *name, enum llog_open_param open_param); int llog_close(const struct lu_env *env, struct llog_handle *cathandle); -int llog_backup(const struct lu_env *env, struct obd_device *obd, - struct llog_ctxt *ctxt, struct llog_ctxt *bak_ctxt, - char *name, char *backup); /* llog_process flags */ #define LLOG_FLAG_NODEAMON 0x0001 diff --git a/drivers/staging/lustre/lustre/include/lustre_mds.h b/drivers/staging/lustre/lustre/include/lustre_mds.h index a16eb8b61178..95d27ddecfb3 100644 --- a/drivers/staging/lustre/lustre/include/lustre_mds.h +++ b/drivers/staging/lustre/lustre/include/lustre_mds.h @@ -62,12 +62,6 @@ struct mds_group_info { #define MDD_OBD_NAME "mdd_obd" #define MDD_OBD_UUID "mdd_obd_uuid" -static inline int md_should_create(__u64 flags) -{ - return !(flags & MDS_OPEN_DELAY_CREATE || - !(flags & FMODE_WRITE)); -} - /* these are local flags, used only on the client, private */ #define M_CHECK_STALE 0200000000 diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h index 0127f45ca0c3..d834ddd8183b 100644 --- a/drivers/staging/lustre/lustre/include/lustre_net.h +++ b/drivers/staging/lustre/lustre/include/lustre_net.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2010, 2012, Intel Corporation. + * Copyright (c) 2010, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/lustre_param.h b/drivers/staging/lustre/lustre/include/lustre_param.h index 8f6c0b26cfab..383fe6febe4b 100644 --- a/drivers/staging/lustre/lustre/include/lustre_param.h +++ b/drivers/staging/lustre/lustre/include/lustre_param.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/lustre_req_layout.h b/drivers/staging/lustre/lustre/include/lustre_req_layout.h index df292f6d4a85..46a662f89322 100644 --- a/drivers/staging/lustre/lustre/include/lustre_req_layout.h +++ b/drivers/staging/lustre/lustre/include/lustre_req_layout.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h index 5e93afca3435..bcbe61301713 100644 --- a/drivers/staging/lustre/lustre/include/obd.h +++ b/drivers/staging/lustre/lustre/include/obd.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -963,123 +963,123 @@ struct md_enqueue_info { }; struct obd_ops { - struct module *o_owner; - int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len, - void *karg, void *uarg); - int (*o_get_info)(const struct lu_env *env, struct obd_export *, - __u32 keylen, void *key, __u32 *vallen, void *val, - struct lov_stripe_md *lsm); - int (*o_set_info_async)(const struct lu_env *, struct obd_export *, - __u32 keylen, void *key, - __u32 vallen, void *val, - struct ptlrpc_request_set *set); - int (*o_attach)(struct obd_device *dev, u32 len, void *data); - int (*o_detach)(struct obd_device *dev); - int (*o_setup)(struct obd_device *dev, struct lustre_cfg *cfg); - int (*o_precleanup)(struct obd_device *dev, - enum obd_cleanup_stage cleanup_stage); - int (*o_cleanup)(struct obd_device *dev); - int (*o_process_config)(struct obd_device *dev, u32 len, void *data); - int (*o_postrecov)(struct obd_device *dev); - int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid, - int priority); - int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid); + struct module *owner; + int (*iocontrol)(unsigned int cmd, struct obd_export *exp, int len, + void *karg, void *uarg); + int (*get_info)(const struct lu_env *env, struct obd_export *, + __u32 keylen, void *key, __u32 *vallen, void *val, + struct lov_stripe_md *lsm); + int (*set_info_async)(const struct lu_env *, struct obd_export *, + __u32 keylen, void *key, + __u32 vallen, void *val, + struct ptlrpc_request_set *set); + int (*attach)(struct obd_device *dev, u32 len, void *data); + int (*detach)(struct obd_device *dev); + int (*setup)(struct obd_device *dev, struct lustre_cfg *cfg); + int (*precleanup)(struct obd_device *dev, + enum obd_cleanup_stage cleanup_stage); + int (*cleanup)(struct obd_device *dev); + int (*process_config)(struct obd_device *dev, u32 len, void *data); + int (*postrecov)(struct obd_device *dev); + int (*add_conn)(struct obd_import *imp, struct obd_uuid *uuid, + int priority); + int (*del_conn)(struct obd_import *imp, struct obd_uuid *uuid); /* connect to the target device with given connection * data. @ocd->ocd_connect_flags is modified to reflect flags actually * granted by the target, which are guaranteed to be a subset of flags * asked for. If @ocd == NULL, use default parameters. */ - int (*o_connect)(const struct lu_env *env, - struct obd_export **exp, struct obd_device *src, - struct obd_uuid *cluuid, struct obd_connect_data *ocd, + int (*connect)(const struct lu_env *env, + struct obd_export **exp, struct obd_device *src, + struct obd_uuid *cluuid, struct obd_connect_data *ocd, + void *localdata); + int (*reconnect)(const struct lu_env *env, + struct obd_export *exp, struct obd_device *src, + struct obd_uuid *cluuid, + struct obd_connect_data *ocd, void *localdata); - int (*o_reconnect)(const struct lu_env *env, - struct obd_export *exp, struct obd_device *src, - struct obd_uuid *cluuid, - struct obd_connect_data *ocd, - void *localdata); - int (*o_disconnect)(struct obd_export *exp); + int (*disconnect)(struct obd_export *exp); /* Initialize/finalize fids infrastructure. */ - int (*o_fid_init)(struct obd_device *obd, - struct obd_export *exp, enum lu_cli_type type); - int (*o_fid_fini)(struct obd_device *obd); + int (*fid_init)(struct obd_device *obd, + struct obd_export *exp, enum lu_cli_type type); + int (*fid_fini)(struct obd_device *obd); /* Allocate new fid according to passed @hint. */ - int (*o_fid_alloc)(struct obd_export *exp, struct lu_fid *fid, - struct md_op_data *op_data); + int (*fid_alloc)(struct obd_export *exp, struct lu_fid *fid, + struct md_op_data *op_data); /* * Object with @fid is getting deleted, we may want to do something * about this. */ - int (*o_statfs)(const struct lu_env *, struct obd_export *exp, - struct obd_statfs *osfs, __u64 max_age, __u32 flags); - int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo, - __u64 max_age, struct ptlrpc_request_set *set); - int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt, - struct lov_stripe_md *mem_src); - int (*o_unpackmd)(struct obd_export *exp, - struct lov_stripe_md **mem_tgt, - struct lov_mds_md *disk_src, int disk_len); - int (*o_preallocate)(struct lustre_handle *, u32 *req, u64 *ids); - int (*o_create)(const struct lu_env *env, struct obd_export *exp, - struct obdo *oa, struct lov_stripe_md **ea, - struct obd_trans_info *oti); - int (*o_destroy)(const struct lu_env *env, struct obd_export *exp, - struct obdo *oa, struct lov_stripe_md *ea, - struct obd_trans_info *oti, struct obd_export *md_exp); - int (*o_setattr)(const struct lu_env *, struct obd_export *exp, - struct obd_info *oinfo, struct obd_trans_info *oti); - int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo, - struct obd_trans_info *oti, - struct ptlrpc_request_set *rqset); - int (*o_getattr)(const struct lu_env *env, struct obd_export *exp, - struct obd_info *oinfo); - int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo, - struct ptlrpc_request_set *set); - int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm, - u64 size, int shrink); - int (*o_preprw)(const struct lu_env *env, int cmd, - struct obd_export *exp, struct obdo *oa, int objcount, - struct obd_ioobj *obj, struct niobuf_remote *remote, - int *nr_pages, struct niobuf_local *local, - struct obd_trans_info *oti); - int (*o_commitrw)(const struct lu_env *env, int cmd, - struct obd_export *exp, struct obdo *oa, - int objcount, struct obd_ioobj *obj, - struct niobuf_remote *remote, int pages, - struct niobuf_local *local, - struct obd_trans_info *oti, int rc); - int (*o_find_cbdata)(struct obd_export *, struct lov_stripe_md *, - ldlm_iterator_t it, void *data); - int (*o_init_export)(struct obd_export *exp); - int (*o_destroy_export)(struct obd_export *exp); + int (*statfs)(const struct lu_env *, struct obd_export *exp, + struct obd_statfs *osfs, __u64 max_age, __u32 flags); + int (*statfs_async)(struct obd_export *exp, struct obd_info *oinfo, + __u64 max_age, struct ptlrpc_request_set *set); + int (*packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt, + struct lov_stripe_md *mem_src); + int (*unpackmd)(struct obd_export *exp, + struct lov_stripe_md **mem_tgt, + struct lov_mds_md *disk_src, int disk_len); + int (*preallocate)(struct lustre_handle *, u32 *req, u64 *ids); + int (*create)(const struct lu_env *env, struct obd_export *exp, + struct obdo *oa, struct lov_stripe_md **ea, + struct obd_trans_info *oti); + int (*destroy)(const struct lu_env *env, struct obd_export *exp, + struct obdo *oa, struct lov_stripe_md *ea, + struct obd_trans_info *oti, struct obd_export *md_exp); + int (*setattr)(const struct lu_env *, struct obd_export *exp, + struct obd_info *oinfo, struct obd_trans_info *oti); + int (*setattr_async)(struct obd_export *exp, struct obd_info *oinfo, + struct obd_trans_info *oti, + struct ptlrpc_request_set *rqset); + int (*getattr)(const struct lu_env *env, struct obd_export *exp, + struct obd_info *oinfo); + int (*getattr_async)(struct obd_export *exp, struct obd_info *oinfo, + struct ptlrpc_request_set *set); + int (*adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm, + u64 size, int shrink); + int (*preprw)(const struct lu_env *env, int cmd, + struct obd_export *exp, struct obdo *oa, int objcount, + struct obd_ioobj *obj, struct niobuf_remote *remote, + int *nr_pages, struct niobuf_local *local, + struct obd_trans_info *oti); + int (*commitrw)(const struct lu_env *env, int cmd, + struct obd_export *exp, struct obdo *oa, + int objcount, struct obd_ioobj *obj, + struct niobuf_remote *remote, int pages, + struct niobuf_local *local, + struct obd_trans_info *oti, int rc); + int (*find_cbdata)(struct obd_export *, struct lov_stripe_md *, + ldlm_iterator_t it, void *data); + int (*init_export)(struct obd_export *exp); + int (*destroy_export)(struct obd_export *exp); /* metadata-only methods */ - int (*o_import_event)(struct obd_device *, struct obd_import *, - enum obd_import_event); + int (*import_event)(struct obd_device *, struct obd_import *, + enum obd_import_event); - int (*o_notify)(struct obd_device *obd, struct obd_device *watched, - enum obd_notify_event ev, void *data); + int (*notify)(struct obd_device *obd, struct obd_device *watched, + enum obd_notify_event ev, void *data); - int (*o_health_check)(const struct lu_env *env, struct obd_device *); - struct obd_uuid *(*o_get_uuid)(struct obd_export *exp); + int (*health_check)(const struct lu_env *env, struct obd_device *); + struct obd_uuid *(*get_uuid)(struct obd_export *exp); /* quota methods */ - int (*o_quotacheck)(struct obd_device *, struct obd_export *, - struct obd_quotactl *); - int (*o_quotactl)(struct obd_device *, struct obd_export *, + int (*quotacheck)(struct obd_device *, struct obd_export *, struct obd_quotactl *); + int (*quotactl)(struct obd_device *, struct obd_export *, + struct obd_quotactl *); /* pools methods */ - int (*o_pool_new)(struct obd_device *obd, char *poolname); - int (*o_pool_del)(struct obd_device *obd, char *poolname); - int (*o_pool_add)(struct obd_device *obd, char *poolname, - char *ostname); - int (*o_pool_rem)(struct obd_device *obd, char *poolname, - char *ostname); - void (*o_getref)(struct obd_device *obd); - void (*o_putref)(struct obd_device *obd); + int (*pool_new)(struct obd_device *obd, char *poolname); + int (*pool_del)(struct obd_device *obd, char *poolname); + int (*pool_add)(struct obd_device *obd, char *poolname, + char *ostname); + int (*pool_rem)(struct obd_device *obd, char *poolname, + char *ostname); + void (*getref)(struct obd_device *obd); + void (*putref)(struct obd_device *obd); /* * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c. @@ -1124,89 +1124,89 @@ struct md_open_data { struct lookup_intent; struct md_ops { - int (*m_getstatus)(struct obd_export *, struct lu_fid *); - int (*m_null_inode)(struct obd_export *, const struct lu_fid *); - int (*m_find_cbdata)(struct obd_export *, const struct lu_fid *, - ldlm_iterator_t, void *); - int (*m_close)(struct obd_export *, struct md_op_data *, - struct md_open_data *, struct ptlrpc_request **); - int (*m_create)(struct obd_export *, struct md_op_data *, - const void *, int, int, __u32, __u32, cfs_cap_t, - __u64, struct ptlrpc_request **); - int (*m_done_writing)(struct obd_export *, struct md_op_data *, - struct md_open_data *); - int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *, - struct lookup_intent *, struct md_op_data *, - struct lustre_handle *, void *, int, - struct ptlrpc_request **, __u64); - int (*m_getattr)(struct obd_export *, struct md_op_data *, - struct ptlrpc_request **); - int (*m_getattr_name)(struct obd_export *, struct md_op_data *, - struct ptlrpc_request **); - int (*m_intent_lock)(struct obd_export *, struct md_op_data *, - void *, int, struct lookup_intent *, int, - struct ptlrpc_request **, - ldlm_blocking_callback, __u64); - int (*m_link)(struct obd_export *, struct md_op_data *, + int (*getstatus)(struct obd_export *, struct lu_fid *); + int (*null_inode)(struct obd_export *, const struct lu_fid *); + int (*find_cbdata)(struct obd_export *, const struct lu_fid *, + ldlm_iterator_t, void *); + int (*close)(struct obd_export *, struct md_op_data *, + struct md_open_data *, struct ptlrpc_request **); + int (*create)(struct obd_export *, struct md_op_data *, + const void *, int, int, __u32, __u32, cfs_cap_t, + __u64, struct ptlrpc_request **); + int (*done_writing)(struct obd_export *, struct md_op_data *, + struct md_open_data *); + int (*enqueue)(struct obd_export *, struct ldlm_enqueue_info *, + struct lookup_intent *, struct md_op_data *, + struct lustre_handle *, void *, int, + struct ptlrpc_request **, __u64); + int (*getattr)(struct obd_export *, struct md_op_data *, + struct ptlrpc_request **); + int (*getattr_name)(struct obd_export *, struct md_op_data *, + struct ptlrpc_request **); + int (*intent_lock)(struct obd_export *, struct md_op_data *, + void *, int, struct lookup_intent *, int, + struct ptlrpc_request **, + ldlm_blocking_callback, __u64); + int (*link)(struct obd_export *, struct md_op_data *, + struct ptlrpc_request **); + int (*rename)(struct obd_export *, struct md_op_data *, + const char *, int, const char *, int, struct ptlrpc_request **); - int (*m_rename)(struct obd_export *, struct md_op_data *, - const char *, int, const char *, int, - struct ptlrpc_request **); - int (*m_is_subdir)(struct obd_export *, const struct lu_fid *, - const struct lu_fid *, + int (*is_subdir)(struct obd_export *, const struct lu_fid *, + const struct lu_fid *, struct ptlrpc_request **); - int (*m_setattr)(struct obd_export *, struct md_op_data *, void *, - int, void *, int, struct ptlrpc_request **, + int (*setattr)(struct obd_export *, struct md_op_data *, void *, + int, void *, int, struct ptlrpc_request **, struct md_open_data **mod); - int (*m_sync)(struct obd_export *, const struct lu_fid *, + int (*sync)(struct obd_export *, const struct lu_fid *, + struct ptlrpc_request **); + int (*readpage)(struct obd_export *, struct md_op_data *, + struct page **, struct ptlrpc_request **); + + int (*unlink)(struct obd_export *, struct md_op_data *, struct ptlrpc_request **); - int (*m_readpage)(struct obd_export *, struct md_op_data *, - struct page **, struct ptlrpc_request **); - int (*m_unlink)(struct obd_export *, struct md_op_data *, + int (*setxattr)(struct obd_export *, const struct lu_fid *, + u64, const char *, const char *, int, int, int, __u32, struct ptlrpc_request **); - int (*m_setxattr)(struct obd_export *, const struct lu_fid *, - u64, const char *, const char *, int, int, int, __u32, - struct ptlrpc_request **); - - int (*m_getxattr)(struct obd_export *, const struct lu_fid *, - u64, const char *, const char *, int, int, int, - struct ptlrpc_request **); + int (*getxattr)(struct obd_export *, const struct lu_fid *, + u64, const char *, const char *, int, int, int, + struct ptlrpc_request **); - int (*m_init_ea_size)(struct obd_export *, int, int, int, int); + int (*init_ea_size)(struct obd_export *, int, int, int, int); - int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *, - struct obd_export *, struct obd_export *, - struct lustre_md *); + int (*get_lustre_md)(struct obd_export *, struct ptlrpc_request *, + struct obd_export *, struct obd_export *, + struct lustre_md *); - int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *); + int (*free_lustre_md)(struct obd_export *, struct lustre_md *); - int (*m_set_open_replay_data)(struct obd_export *, - struct obd_client_handle *, - struct lookup_intent *); - int (*m_clear_open_replay_data)(struct obd_export *, - struct obd_client_handle *); - int (*m_set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *); + int (*set_open_replay_data)(struct obd_export *, + struct obd_client_handle *, + struct lookup_intent *); + int (*clear_open_replay_data)(struct obd_export *, + struct obd_client_handle *); + int (*set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *); - ldlm_mode_t (*m_lock_match)(struct obd_export *, __u64, - const struct lu_fid *, ldlm_type_t, - ldlm_policy_data_t *, ldlm_mode_t, - struct lustre_handle *); + ldlm_mode_t (*lock_match)(struct obd_export *, __u64, + const struct lu_fid *, ldlm_type_t, + ldlm_policy_data_t *, ldlm_mode_t, + struct lustre_handle *); - int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *, - ldlm_policy_data_t *, ldlm_mode_t, - ldlm_cancel_flags_t flags, void *opaque); + int (*cancel_unused)(struct obd_export *, const struct lu_fid *, + ldlm_policy_data_t *, ldlm_mode_t, + ldlm_cancel_flags_t flags, void *opaque); - int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *, - __u32, struct ptlrpc_request **); + int (*get_remote_perm)(struct obd_export *, const struct lu_fid *, + __u32, struct ptlrpc_request **); - int (*m_intent_getattr_async)(struct obd_export *, - struct md_enqueue_info *, - struct ldlm_enqueue_info *); + int (*intent_getattr_async)(struct obd_export *, + struct md_enqueue_info *, + struct ldlm_enqueue_info *); - int (*m_revalidate_lock)(struct obd_export *, struct lookup_intent *, - struct lu_fid *, __u64 *bits); + int (*revalidate_lock)(struct obd_export *, struct lookup_intent *, + struct lu_fid *, __u64 *bits); /* * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to diff --git a/drivers/staging/lustre/lustre/include/obd_cksum.h b/drivers/staging/lustre/lustre/include/obd_cksum.h index a0099d71773a..01db60405393 100644 --- a/drivers/staging/lustre/lustre/include/obd_cksum.h +++ b/drivers/staging/lustre/lustre/include/obd_cksum.h @@ -133,29 +133,6 @@ static inline cksum_type_t cksum_types_supported_client(void) return ret; } -/* Server uses algos that perform at 50% or better of the Adler */ -static inline cksum_type_t cksum_types_supported_server(void) -{ - int base_speed; - cksum_type_t ret = OBD_CKSUM_ADLER; - - CDEBUG(D_INFO, "Crypto hash speed: crc %d, crc32c %d, adler %d\n", - cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32)), - cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32C)), - cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_ADLER))); - - base_speed = cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_ADLER)) / 2; - - if (cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32C)) >= - base_speed) - ret |= OBD_CKSUM_CRC32C; - if (cfs_crypto_hash_speed(cksum_obd2cfs(OBD_CKSUM_CRC32)) >= - base_speed) - ret |= OBD_CKSUM_CRC32; - - return ret; -} - /* Select the best checksum algorithm among those supplied in the cksum_types * input. * diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h index fd5f3731db92..97d80397503c 100644 --- a/drivers/staging/lustre/lustre/include/obd_class.h +++ b/drivers/staging/lustre/lustre/include/obd_class.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -270,8 +270,8 @@ void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj); void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid); #define OBT(dev) (dev)->obd_type -#define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op -#define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op +#define OBP(dev, op) (dev)->obd_type->typ_dt_ops->op +#define MDP(dev, op) (dev)->obd_type->typ_md_ops->op #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op /* Ensure obd_setup: used for cleanup which must be called @@ -301,9 +301,9 @@ static inline int obd_check_dev_active(struct obd_device *obd) } #define OBD_COUNTER_OFFSET(op) \ - ((offsetof(struct obd_ops, o_ ## op) - \ - offsetof(struct obd_ops, o_iocontrol)) \ - / sizeof(((struct obd_ops *)(0))->o_iocontrol)) + ((offsetof(struct obd_ops, op) - \ + offsetof(struct obd_ops, iocontrol)) \ + / sizeof(((struct obd_ops *)(0))->iocontrol)) #define OBD_COUNTER_INCREMENT(obdx, op) \ if ((obdx)->obd_stats != NULL) { \ @@ -324,9 +324,9 @@ static inline int obd_check_dev_active(struct obd_device *obd) } #define MD_COUNTER_OFFSET(op) \ - ((offsetof(struct md_ops, m_ ## op) - \ - offsetof(struct md_ops, m_getstatus)) \ - / sizeof(((struct md_ops *)(0))->m_getstatus)) + ((offsetof(struct md_ops, op) - \ + offsetof(struct md_ops, getstatus)) \ + / sizeof(((struct md_ops *)(0))->getstatus)) #define MD_COUNTER_INCREMENT(obdx, op) \ if ((obd)->md_stats != NULL) { \ diff --git a/drivers/staging/lustre/lustre/include/obd_support.h b/drivers/staging/lustre/lustre/include/obd_support.h index a22a5308fb48..d031437c0528 100644 --- a/drivers/staging/lustre/lustre/include/obd_support.h +++ b/drivers/staging/lustre/lustre/include/obd_support.h @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/lclient/lcommon_cl.c b/drivers/staging/lustre/lustre/lclient/lcommon_cl.c index 0b8e4d2175ae..34dde7dede74 100644 --- a/drivers/staging/lustre/lustre/lclient/lcommon_cl.c +++ b/drivers/staging/lustre/lustre/lclient/lcommon_cl.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -427,7 +427,7 @@ static void ccc_object_size_lock(struct cl_object *obj) { struct inode *inode = ccc_object_inode(obj); - cl_isize_lock(inode); + ll_inode_size_lock(inode); cl_object_attr_lock(obj); } @@ -436,7 +436,7 @@ static void ccc_object_size_unlock(struct cl_object *obj) struct inode *inode = ccc_object_inode(obj); cl_object_attr_unlock(obj); - cl_isize_unlock(inode); + ll_inode_size_unlock(inode); } /***************************************************************************** diff --git a/drivers/staging/lustre/lustre/ldlm/interval_tree.c b/drivers/staging/lustre/lustre/ldlm/interval_tree.c index 39b571721881..a2ea8e5b93d8 100644 --- a/drivers/staging/lustre/lustre/ldlm/interval_tree.c +++ b/drivers/staging/lustre/lustre/ldlm/interval_tree.c @@ -96,18 +96,6 @@ static inline int extent_equal(struct interval_node_extent *e1, return (e1->start == e2->start) && (e1->end == e2->end); } -static inline int node_compare(struct interval_node *n1, - struct interval_node *n2) -{ - return extent_compare(&n1->in_extent, &n2->in_extent); -} - -static inline int node_equal(struct interval_node *n1, - struct interval_node *n2) -{ - return extent_equal(&n1->in_extent, &n2->in_extent); -} - static inline __u64 max_u64(__u64 x, __u64 y) { return x > y ? x : y; @@ -278,14 +266,14 @@ struct interval_node *interval_insert(struct interval_node *node, p = root; while (*p) { parent = *p; - if (node_equal(parent, node)) + if (extent_equal(&parent->in_extent, &node->in_extent)) return parent; /* max_high field must be updated after each iteration */ if (parent->in_max_high < interval_high(node)) parent->in_max_high = interval_high(node); - if (node_compare(node, parent) < 0) + if (extent_compare(&node->in_extent, &parent->in_extent) < 0) p = &parent->in_left; else p = &parent->in_right; diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c index c787888eb8af..9c70f31ea56e 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c @@ -149,7 +149,7 @@ static inline int lock_mode_to_index(ldlm_mode_t mode) int index; LASSERT(mode != 0); - LASSERT(IS_PO2(mode)); + LASSERT(is_power_of_2(mode)); for (index = -1; mode; index++) mode >>= 1; LASSERT(index < LCK_MODE_NUM); diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h index db3c9b7af7d5..849cc98df7dd 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c index ccce1e503120..3c8d4413d976 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2010, 2012, Intel Corporation. + * Copyright (c) 2010, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c index 7f8c70056ffd..cf9ec0cfe247 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2010, 2012, Intel Corporation. + * Copyright (c) 2010, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c index ca115119501a..79aeb2bf6c8e 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2010, 2012, Intel Corporation. + * Copyright (c) 2010, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c index 1a4eef64658f..3d7c137d223a 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2010, 2012, Intel Corporation. + * Copyright (c) 2010, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -176,11 +176,6 @@ enum { LDLM_POOL_LAST_STAT }; -static inline struct ldlm_namespace *ldlm_pl2ns(struct ldlm_pool *pl) -{ - return container_of(pl, struct ldlm_namespace, ns_pool); -} - /** * Calculates suggested grant_step in % of available locks for passed * \a period. This is later used in grant_plan calculations. @@ -213,22 +208,6 @@ static inline int ldlm_pool_t2gsp(unsigned int t) } /** - * Returns current \a pl limit. - */ -static __u32 ldlm_pool_get_limit(struct ldlm_pool *pl) -{ - return atomic_read(&pl->pl_limit); -} - -/** - * Sets passed \a limit to \a pl. - */ -static void ldlm_pool_set_limit(struct ldlm_pool *pl, __u32 limit) -{ - atomic_set(&pl->pl_limit, limit); -} - -/** * Recalculates next stats on passed \a pl. * * \pre ->pl_lock is locked. @@ -254,7 +233,8 @@ static void ldlm_pool_recalc_stats(struct ldlm_pool *pl) } /** - * Sets SLV and Limit from ldlm_pl2ns(pl)->ns_obd tp passed \a pl. + * Sets SLV and Limit from container_of(pl, struct ldlm_namespace, + * ns_pool)->ns_obd tp passed \a pl. */ static void ldlm_cli_pool_pop_slv(struct ldlm_pool *pl) { @@ -264,11 +244,12 @@ static void ldlm_cli_pool_pop_slv(struct ldlm_pool *pl) * Get new SLV and Limit from obd which is updated with coming * RPCs. */ - obd = ldlm_pl2ns(pl)->ns_obd; + obd = container_of(pl, struct ldlm_namespace, + ns_pool)->ns_obd; LASSERT(obd != NULL); read_lock(&obd->obd_pool_lock); pl->pl_server_lock_volume = obd->obd_pool_slv; - ldlm_pool_set_limit(pl, obd->obd_pool_limit); + atomic_set(&pl->pl_limit, obd->obd_pool_limit); read_unlock(&obd->obd_pool_lock); } @@ -304,7 +285,8 @@ static int ldlm_cli_pool_recalc(struct ldlm_pool *pl) /* * Do not cancel locks in case lru resize is disabled for this ns. */ - if (!ns_connect_lru_resize(ldlm_pl2ns(pl))) { + if (!ns_connect_lru_resize(container_of(pl, struct ldlm_namespace, + ns_pool))) { ret = 0; goto out; } @@ -315,7 +297,8 @@ static int ldlm_cli_pool_recalc(struct ldlm_pool *pl) * It may be called when SLV has changed much, this is why we do not * take into account pl->pl_recalc_time here. */ - ret = ldlm_cancel_lru(ldlm_pl2ns(pl), 0, LCF_ASYNC, LDLM_CANCEL_LRUR); + ret = ldlm_cancel_lru(container_of(pl, struct ldlm_namespace, ns_pool), + 0, LCF_ASYNC, LDLM_CANCEL_LRUR); out: spin_lock(&pl->pl_lock); @@ -341,7 +324,7 @@ static int ldlm_cli_pool_shrink(struct ldlm_pool *pl, struct ldlm_namespace *ns; int unused; - ns = ldlm_pl2ns(pl); + ns = container_of(pl, struct ldlm_namespace, ns_pool); /* * Do not cancel locks in case lru resize is disabled for this ns. @@ -453,7 +436,7 @@ static int lprocfs_pool_state_seq_show(struct seq_file *m, void *unused) spin_lock(&pl->pl_lock); slv = pl->pl_server_lock_volume; clv = pl->pl_client_lock_volume; - limit = ldlm_pool_get_limit(pl); + limit = atomic_read(&pl->pl_limit); granted = atomic_read(&pl->pl_granted); grant_rate = atomic_read(&pl->pl_grant_rate); cancel_rate = atomic_read(&pl->pl_cancel_rate); @@ -558,7 +541,8 @@ static struct kobj_type ldlm_pl_ktype = { static int ldlm_pool_sysfs_init(struct ldlm_pool *pl) { - struct ldlm_namespace *ns = ldlm_pl2ns(pl); + struct ldlm_namespace *ns = container_of(pl, struct ldlm_namespace, + ns_pool); int err; init_completion(&pl->pl_kobj_unregister); @@ -570,7 +554,8 @@ static int ldlm_pool_sysfs_init(struct ldlm_pool *pl) static int ldlm_pool_debugfs_init(struct ldlm_pool *pl) { - struct ldlm_namespace *ns = ldlm_pl2ns(pl); + struct ldlm_namespace *ns = container_of(pl, struct ldlm_namespace, + ns_pool); struct dentry *debugfs_ns_parent; struct lprocfs_vars pool_vars[2]; char *var_name = NULL; @@ -685,7 +670,7 @@ int ldlm_pool_init(struct ldlm_pool *pl, struct ldlm_namespace *ns, snprintf(pl->pl_name, sizeof(pl->pl_name), "ldlm-pool-%s-%d", ldlm_ns_name(ns), idx); - ldlm_pool_set_limit(pl, 1); + atomic_set(&pl->pl_limit, 1); pl->pl_server_lock_volume = 0; pl->pl_ops = &ldlm_cli_pool_ops; pl->pl_recalc_period = LDLM_POOL_CLI_DEF_RECALC_PERIOD; diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c index fdf81b87aad7..b9eb37762434 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2010, 2012, Intel Corporation. + * Copyright (c) 2010, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c index c0a54bf406ca..0ae610015b7c 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2010, 2012, Intel Corporation. + * Copyright (c) 2010, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -1154,8 +1154,6 @@ ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent, CERROR("%s: lvbo_init failed for resource %#llx:%#llx: rc = %d\n", ns->ns_obd->obd_name, name->name[0], name->name[1], rc); - kfree(res->lr_lvb_data); - res->lr_lvb_data = NULL; res->lr_lvb_len = rc; mutex_unlock(&res->lr_lvb_mutex); ldlm_resource_putref(res); diff --git a/drivers/staging/lustre/lustre/libcfs/debug.c b/drivers/staging/lustre/lustre/libcfs/debug.c index 1d1c67164418..0b38dad13546 100644 --- a/drivers/staging/lustre/lustre/libcfs/debug.c +++ b/drivers/staging/lustre/lustre/libcfs/debug.c @@ -94,17 +94,14 @@ static struct kernel_param_ops param_ops_debugmb = { static unsigned int libcfs_debug_mb; module_param(libcfs_debug_mb, debugmb, 0644); MODULE_PARM_DESC(libcfs_debug_mb, "Total debug buffer size."); -EXPORT_SYMBOL(libcfs_debug_mb); unsigned int libcfs_printk = D_CANTMASK; module_param(libcfs_printk, uint, 0644); MODULE_PARM_DESC(libcfs_printk, "Lustre kernel debug console mask"); -EXPORT_SYMBOL(libcfs_printk); unsigned int libcfs_console_ratelimit = 1; module_param(libcfs_console_ratelimit, uint, 0644); MODULE_PARM_DESC(libcfs_console_ratelimit, "Lustre kernel debug console ratelimit (0 to disable)"); -EXPORT_SYMBOL(libcfs_console_ratelimit); static int param_set_delay_minmax(const char *val, const struct kernel_param *kp, @@ -135,9 +132,7 @@ static int param_get_delay(char *buffer, const struct kernel_param *kp) } unsigned int libcfs_console_max_delay; -EXPORT_SYMBOL(libcfs_console_max_delay); unsigned int libcfs_console_min_delay; -EXPORT_SYMBOL(libcfs_console_min_delay); static int param_set_console_max_delay(const char *val, const struct kernel_param *kp) @@ -207,10 +202,8 @@ static struct kernel_param_ops param_ops_uintpos = { unsigned int libcfs_console_backoff = CDEBUG_DEFAULT_BACKOFF; module_param(libcfs_console_backoff, uintpos, 0644); MODULE_PARM_DESC(libcfs_console_backoff, "Lustre kernel debug console backoff factor"); -EXPORT_SYMBOL(libcfs_console_backoff); unsigned int libcfs_debug_binary = 1; -EXPORT_SYMBOL(libcfs_debug_binary); unsigned int libcfs_stack = 3 * THREAD_SIZE / 4; EXPORT_SYMBOL(libcfs_stack); @@ -221,7 +214,6 @@ EXPORT_SYMBOL(libcfs_catastrophe); unsigned int libcfs_panic_on_lbug = 1; module_param(libcfs_panic_on_lbug, uint, 0644); MODULE_PARM_DESC(libcfs_panic_on_lbug, "Lustre kernel panic on LBUG"); -EXPORT_SYMBOL(libcfs_panic_on_lbug); static wait_queue_head_t debug_ctlwq; @@ -512,9 +504,9 @@ int libcfs_debug_init(unsigned long bufsize) } if (libcfs_debug_file_path != NULL) { - strncpy(libcfs_debug_file_path_arr, - libcfs_debug_file_path, PATH_MAX-1); - libcfs_debug_file_path_arr[PATH_MAX - 1] = '\0'; + strlcpy(libcfs_debug_file_path_arr, + libcfs_debug_file_path, + sizeof(libcfs_debug_file_path_arr)); } /* If libcfs_debug_mb is set to an invalid value or uninitialized @@ -565,12 +557,3 @@ int libcfs_debug_mark_buffer(const char *text) #undef DEBUG_SUBSYSTEM #define DEBUG_SUBSYSTEM S_LNET - -void libcfs_debug_set_level(unsigned int debug_level) -{ - pr_warn("Lustre: Setting portals debug level to %08x\n", - debug_level); - libcfs_debug = debug_level; -} - -EXPORT_SYMBOL(libcfs_debug_set_level); diff --git a/drivers/staging/lustre/lustre/libcfs/fail.c b/drivers/staging/lustre/lustre/libcfs/fail.c index d39fecebd12d..27831432d69a 100644 --- a/drivers/staging/lustre/lustre/libcfs/fail.c +++ b/drivers/staging/lustre/lustre/libcfs/fail.c @@ -26,7 +26,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -126,7 +126,7 @@ int __cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set) int ret; ret = __cfs_fail_check_set(id, value, set); - if (ret) { + if (ret && likely(ms > 0)) { CERROR("cfs_fail_timeout id %x sleeping for %dms\n", id, ms); set_current_state(TASK_UNINTERRUPTIBLE); diff --git a/drivers/staging/lustre/lustre/libcfs/hash.c b/drivers/staging/lustre/lustre/libcfs/hash.c index 030874428952..4d50510434be 100644 --- a/drivers/staging/lustre/lustre/libcfs/hash.c +++ b/drivers/staging/lustre/lustre/libcfs/hash.c @@ -106,9 +106,10 @@ * Now we support both locked iteration & lockless iteration of hash * table. Also, user can break the iteration by return 1 in callback. */ +#include <linux/seq_file.h> +#include <linux/log2.h> #include "../../include/linux/libcfs/libcfs.h" -#include <linux/seq_file.h> #if CFS_HASH_DEBUG_LEVEL >= CFS_HASH_DEBUG_1 static unsigned int warn_on_depth = 8; @@ -161,49 +162,49 @@ cfs_hash_rw_unlock(union cfs_hash_lock *lock, int exclusive) /** No lock hash */ static struct cfs_hash_lock_ops cfs_hash_nl_lops = { .hs_lock = cfs_hash_nl_lock, - .hs_unlock = cfs_hash_nl_unlock, - .hs_bkt_lock = cfs_hash_nl_lock, - .hs_bkt_unlock = cfs_hash_nl_unlock, + .hs_unlock = cfs_hash_nl_unlock, + .hs_bkt_lock = cfs_hash_nl_lock, + .hs_bkt_unlock = cfs_hash_nl_unlock, }; /** no bucket lock, one spinlock to protect everything */ static struct cfs_hash_lock_ops cfs_hash_nbl_lops = { .hs_lock = cfs_hash_spin_lock, - .hs_unlock = cfs_hash_spin_unlock, - .hs_bkt_lock = cfs_hash_nl_lock, - .hs_bkt_unlock = cfs_hash_nl_unlock, + .hs_unlock = cfs_hash_spin_unlock, + .hs_bkt_lock = cfs_hash_nl_lock, + .hs_bkt_unlock = cfs_hash_nl_unlock, }; /** spin bucket lock, rehash is enabled */ static struct cfs_hash_lock_ops cfs_hash_bkt_spin_lops = { .hs_lock = cfs_hash_rw_lock, - .hs_unlock = cfs_hash_rw_unlock, - .hs_bkt_lock = cfs_hash_spin_lock, - .hs_bkt_unlock = cfs_hash_spin_unlock, + .hs_unlock = cfs_hash_rw_unlock, + .hs_bkt_lock = cfs_hash_spin_lock, + .hs_bkt_unlock = cfs_hash_spin_unlock, }; /** rw bucket lock, rehash is enabled */ static struct cfs_hash_lock_ops cfs_hash_bkt_rw_lops = { .hs_lock = cfs_hash_rw_lock, - .hs_unlock = cfs_hash_rw_unlock, - .hs_bkt_lock = cfs_hash_rw_lock, - .hs_bkt_unlock = cfs_hash_rw_unlock, + .hs_unlock = cfs_hash_rw_unlock, + .hs_bkt_lock = cfs_hash_rw_lock, + .hs_bkt_unlock = cfs_hash_rw_unlock, }; /** spin bucket lock, rehash is disabled */ static struct cfs_hash_lock_ops cfs_hash_nr_bkt_spin_lops = { .hs_lock = cfs_hash_nl_lock, - .hs_unlock = cfs_hash_nl_unlock, - .hs_bkt_lock = cfs_hash_spin_lock, - .hs_bkt_unlock = cfs_hash_spin_unlock, + .hs_unlock = cfs_hash_nl_unlock, + .hs_bkt_lock = cfs_hash_spin_lock, + .hs_bkt_unlock = cfs_hash_spin_unlock, }; /** rw bucket lock, rehash is disabled */ static struct cfs_hash_lock_ops cfs_hash_nr_bkt_rw_lops = { .hs_lock = cfs_hash_nl_lock, - .hs_unlock = cfs_hash_nl_unlock, - .hs_bkt_lock = cfs_hash_rw_lock, - .hs_bkt_unlock = cfs_hash_rw_unlock, + .hs_unlock = cfs_hash_nl_unlock, + .hs_bkt_lock = cfs_hash_rw_lock, + .hs_bkt_unlock = cfs_hash_rw_unlock, }; static void @@ -280,7 +281,7 @@ cfs_hash_hh_hnode_del(struct cfs_hash *hs, struct cfs_hash_bd *bd, */ struct cfs_hash_head_dep { struct hlist_head hd_head; /**< entries list */ - unsigned int hd_depth; /**< list length */ + unsigned int hd_depth; /**< list length */ }; static int @@ -328,7 +329,7 @@ cfs_hash_hd_hnode_del(struct cfs_hash *hs, struct cfs_hash_bd *bd, */ struct cfs_hash_dhead { struct hlist_head dh_head; /**< entries list */ - struct hlist_node *dh_tail; /**< the last entry */ + struct hlist_node *dh_tail; /**< the last entry */ }; static int @@ -384,8 +385,8 @@ cfs_hash_dh_hnode_del(struct cfs_hash *hs, struct cfs_hash_bd *bd, */ struct cfs_hash_dhead_dep { struct hlist_head dd_head; /**< entries list */ - struct hlist_node *dd_tail; /**< the last entry */ - unsigned int dd_depth; /**< list length */ + struct hlist_node *dd_tail; /**< the last entry */ + unsigned int dd_depth; /**< list length */ }; static int @@ -436,31 +437,31 @@ cfs_hash_dd_hnode_del(struct cfs_hash *hs, struct cfs_hash_bd *bd, } static struct cfs_hash_hlist_ops cfs_hash_hh_hops = { - .hop_hhead = cfs_hash_hh_hhead, - .hop_hhead_size = cfs_hash_hh_hhead_size, - .hop_hnode_add = cfs_hash_hh_hnode_add, - .hop_hnode_del = cfs_hash_hh_hnode_del, + .hop_hhead = cfs_hash_hh_hhead, + .hop_hhead_size = cfs_hash_hh_hhead_size, + .hop_hnode_add = cfs_hash_hh_hnode_add, + .hop_hnode_del = cfs_hash_hh_hnode_del, }; static struct cfs_hash_hlist_ops cfs_hash_hd_hops = { - .hop_hhead = cfs_hash_hd_hhead, - .hop_hhead_size = cfs_hash_hd_hhead_size, - .hop_hnode_add = cfs_hash_hd_hnode_add, - .hop_hnode_del = cfs_hash_hd_hnode_del, + .hop_hhead = cfs_hash_hd_hhead, + .hop_hhead_size = cfs_hash_hd_hhead_size, + .hop_hnode_add = cfs_hash_hd_hnode_add, + .hop_hnode_del = cfs_hash_hd_hnode_del, }; static struct cfs_hash_hlist_ops cfs_hash_dh_hops = { - .hop_hhead = cfs_hash_dh_hhead, - .hop_hhead_size = cfs_hash_dh_hhead_size, - .hop_hnode_add = cfs_hash_dh_hnode_add, - .hop_hnode_del = cfs_hash_dh_hnode_del, + .hop_hhead = cfs_hash_dh_hhead, + .hop_hhead_size = cfs_hash_dh_hhead_size, + .hop_hnode_add = cfs_hash_dh_hnode_add, + .hop_hnode_del = cfs_hash_dh_hnode_del, }; static struct cfs_hash_hlist_ops cfs_hash_dd_hops = { - .hop_hhead = cfs_hash_dd_hhead, - .hop_hhead_size = cfs_hash_dd_hhead_size, - .hop_hnode_add = cfs_hash_dd_hnode_add, - .hop_hnode_del = cfs_hash_dd_hnode_del, + .hop_hhead = cfs_hash_dd_hhead, + .hop_hhead_size = cfs_hash_dd_hhead_size, + .hop_hnode_add = cfs_hash_dd_hnode_add, + .hop_hnode_del = cfs_hash_dd_hnode_del, }; static void @@ -529,7 +530,7 @@ void cfs_hash_bd_add_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, struct hlist_node *hnode) { - int rc; + int rc; rc = hs->hs_hops->hop_hnode_add(hs, bd, hnode); cfs_hash_bd_dep_record(hs, bd, rc); @@ -572,7 +573,7 @@ cfs_hash_bd_move_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd_old, { struct cfs_hash_bucket *obkt = bd_old->bd_bucket; struct cfs_hash_bucket *nbkt = bd_new->bd_bucket; - int rc; + int rc; if (cfs_hash_bd_compare(bd_old, bd_new) == 0) return; @@ -593,34 +594,33 @@ cfs_hash_bd_move_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd_old, if (unlikely(nbkt->hsb_version == 0)) nbkt->hsb_version++; } -EXPORT_SYMBOL(cfs_hash_bd_move_locked); enum { /** always set, for sanity (avoid ZERO intent) */ - CFS_HS_LOOKUP_MASK_FIND = BIT(0), + CFS_HS_LOOKUP_MASK_FIND = BIT(0), /** return entry with a ref */ - CFS_HS_LOOKUP_MASK_REF = BIT(1), + CFS_HS_LOOKUP_MASK_REF = BIT(1), /** add entry if not existing */ - CFS_HS_LOOKUP_MASK_ADD = BIT(2), + CFS_HS_LOOKUP_MASK_ADD = BIT(2), /** delete entry, ignore other masks */ - CFS_HS_LOOKUP_MASK_DEL = BIT(3), + CFS_HS_LOOKUP_MASK_DEL = BIT(3), }; enum cfs_hash_lookup_intent { /** return item w/o refcount */ - CFS_HS_LOOKUP_IT_PEEK = CFS_HS_LOOKUP_MASK_FIND, + CFS_HS_LOOKUP_IT_PEEK = CFS_HS_LOOKUP_MASK_FIND, /** return item with refcount */ - CFS_HS_LOOKUP_IT_FIND = (CFS_HS_LOOKUP_MASK_FIND | - CFS_HS_LOOKUP_MASK_REF), + CFS_HS_LOOKUP_IT_FIND = (CFS_HS_LOOKUP_MASK_FIND | + CFS_HS_LOOKUP_MASK_REF), /** return item w/o refcount if existed, otherwise add */ - CFS_HS_LOOKUP_IT_ADD = (CFS_HS_LOOKUP_MASK_FIND | - CFS_HS_LOOKUP_MASK_ADD), + CFS_HS_LOOKUP_IT_ADD = (CFS_HS_LOOKUP_MASK_FIND | + CFS_HS_LOOKUP_MASK_ADD), /** return item with refcount if existed, otherwise add */ - CFS_HS_LOOKUP_IT_FINDADD = (CFS_HS_LOOKUP_IT_FIND | - CFS_HS_LOOKUP_MASK_ADD), + CFS_HS_LOOKUP_IT_FINDADD = (CFS_HS_LOOKUP_IT_FIND | + CFS_HS_LOOKUP_MASK_ADD), /** delete if existed */ - CFS_HS_LOOKUP_IT_FINDDEL = (CFS_HS_LOOKUP_MASK_FIND | - CFS_HS_LOOKUP_MASK_DEL) + CFS_HS_LOOKUP_IT_FINDDEL = (CFS_HS_LOOKUP_MASK_FIND | + CFS_HS_LOOKUP_MASK_DEL) }; static struct hlist_node * @@ -629,10 +629,10 @@ cfs_hash_bd_lookup_intent(struct cfs_hash *hs, struct cfs_hash_bd *bd, enum cfs_hash_lookup_intent intent) { - struct hlist_head *hhead = cfs_hash_bd_hhead(hs, bd); - struct hlist_node *ehnode; - struct hlist_node *match; - int intent_add = (intent & CFS_HS_LOOKUP_MASK_ADD) != 0; + struct hlist_head *hhead = cfs_hash_bd_hhead(hs, bd); + struct hlist_node *ehnode; + struct hlist_node *match; + int intent_add = (intent & CFS_HS_LOOKUP_MASK_ADD) != 0; /* with this function, we can avoid a lot of useless refcount ops, * which are expensive atomic operations most time. */ @@ -665,7 +665,8 @@ cfs_hash_bd_lookup_intent(struct cfs_hash *hs, struct cfs_hash_bd *bd, } struct hlist_node * -cfs_hash_bd_lookup_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, const void *key) +cfs_hash_bd_lookup_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, + const void *key) { return cfs_hash_bd_lookup_intent(hs, bd, key, NULL, CFS_HS_LOOKUP_IT_FIND); @@ -673,40 +674,20 @@ cfs_hash_bd_lookup_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, const voi EXPORT_SYMBOL(cfs_hash_bd_lookup_locked); struct hlist_node * -cfs_hash_bd_peek_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, const void *key) +cfs_hash_bd_peek_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, + const void *key) { return cfs_hash_bd_lookup_intent(hs, bd, key, NULL, CFS_HS_LOOKUP_IT_PEEK); } EXPORT_SYMBOL(cfs_hash_bd_peek_locked); -struct hlist_node * -cfs_hash_bd_findadd_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, - const void *key, struct hlist_node *hnode, - int noref) -{ - return cfs_hash_bd_lookup_intent(hs, bd, key, hnode, - (!noref * CFS_HS_LOOKUP_MASK_REF) | - CFS_HS_LOOKUP_IT_ADD); -} -EXPORT_SYMBOL(cfs_hash_bd_findadd_locked); - -struct hlist_node * -cfs_hash_bd_finddel_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd, - const void *key, struct hlist_node *hnode) -{ - /* hnode can be NULL, we find the first item with @key */ - return cfs_hash_bd_lookup_intent(hs, bd, key, hnode, - CFS_HS_LOOKUP_IT_FINDDEL); -} -EXPORT_SYMBOL(cfs_hash_bd_finddel_locked); - static void cfs_hash_multi_bd_lock(struct cfs_hash *hs, struct cfs_hash_bd *bds, unsigned n, int excl) { struct cfs_hash_bucket *prev = NULL; - int i; + int i; /** * bds must be ascendantly ordered by bd->bd_bucket->hsb_index. @@ -729,7 +710,7 @@ cfs_hash_multi_bd_unlock(struct cfs_hash *hs, struct cfs_hash_bd *bds, unsigned n, int excl) { struct cfs_hash_bucket *prev = NULL; - int i; + int i; cfs_hash_for_each_bd(bds, n, i) { if (prev != bds[i].bd_bucket) { @@ -743,8 +724,8 @@ static struct hlist_node * cfs_hash_multi_bd_lookup_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds, unsigned n, const void *key) { - struct hlist_node *ehnode; - unsigned i; + struct hlist_node *ehnode; + unsigned i; cfs_hash_for_each_bd(bds, n, i) { ehnode = cfs_hash_bd_lookup_intent(hs, &bds[i], key, NULL, @@ -756,13 +737,13 @@ cfs_hash_multi_bd_lookup_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds, } static struct hlist_node * -cfs_hash_multi_bd_findadd_locked(struct cfs_hash *hs, - struct cfs_hash_bd *bds, unsigned n, const void *key, +cfs_hash_multi_bd_findadd_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds, + unsigned n, const void *key, struct hlist_node *hnode, int noref) { - struct hlist_node *ehnode; - int intent; - unsigned i; + struct hlist_node *ehnode; + int intent; + unsigned i; LASSERT(hnode != NULL); intent = (!noref * CFS_HS_LOOKUP_MASK_REF) | CFS_HS_LOOKUP_IT_PEEK; @@ -777,7 +758,7 @@ cfs_hash_multi_bd_findadd_locked(struct cfs_hash *hs, if (i == 1) { /* only one bucket */ cfs_hash_bd_add_locked(hs, &bds[0], hnode); } else { - struct cfs_hash_bd mybd; + struct cfs_hash_bd mybd; cfs_hash_bd_get(hs, key, &mybd); cfs_hash_bd_add_locked(hs, &mybd, hnode); @@ -791,8 +772,8 @@ cfs_hash_multi_bd_finddel_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds, unsigned n, const void *key, struct hlist_node *hnode) { - struct hlist_node *ehnode; - unsigned i; + struct hlist_node *ehnode; + unsigned int i; cfs_hash_for_each_bd(bds, n, i) { ehnode = cfs_hash_bd_lookup_intent(hs, &bds[i], key, hnode, @@ -806,7 +787,7 @@ cfs_hash_multi_bd_finddel_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds, static void cfs_hash_bd_order(struct cfs_hash_bd *bd1, struct cfs_hash_bd *bd2) { - int rc; + int rc; if (bd2->bd_bucket == NULL) return; @@ -831,7 +812,8 @@ cfs_hash_bd_order(struct cfs_hash_bd *bd1, struct cfs_hash_bd *bd2) } void -cfs_hash_dual_bd_get(struct cfs_hash *hs, const void *key, struct cfs_hash_bd *bds) +cfs_hash_dual_bd_get(struct cfs_hash *hs, const void *key, + struct cfs_hash_bd *bds) { /* NB: caller should hold hs_lock.rw if REHASH is set */ cfs_hash_bd_from_key(hs, hs->hs_buckets, @@ -848,21 +830,18 @@ cfs_hash_dual_bd_get(struct cfs_hash *hs, const void *key, struct cfs_hash_bd *b cfs_hash_bd_order(&bds[0], &bds[1]); } -EXPORT_SYMBOL(cfs_hash_dual_bd_get); void cfs_hash_dual_bd_lock(struct cfs_hash *hs, struct cfs_hash_bd *bds, int excl) { cfs_hash_multi_bd_lock(hs, bds, 2, excl); } -EXPORT_SYMBOL(cfs_hash_dual_bd_lock); void cfs_hash_dual_bd_unlock(struct cfs_hash *hs, struct cfs_hash_bd *bds, int excl) { cfs_hash_multi_bd_unlock(hs, bds, 2, excl); } -EXPORT_SYMBOL(cfs_hash_dual_bd_unlock); struct hlist_node * cfs_hash_dual_bd_lookup_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds, @@ -870,7 +849,6 @@ cfs_hash_dual_bd_lookup_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds, { return cfs_hash_multi_bd_lookup_locked(hs, bds, 2, key); } -EXPORT_SYMBOL(cfs_hash_dual_bd_lookup_locked); struct hlist_node * cfs_hash_dual_bd_findadd_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds, @@ -880,7 +858,6 @@ cfs_hash_dual_bd_findadd_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds, return cfs_hash_multi_bd_findadd_locked(hs, bds, 2, key, hnode, noref); } -EXPORT_SYMBOL(cfs_hash_dual_bd_findadd_locked); struct hlist_node * cfs_hash_dual_bd_finddel_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds, @@ -888,13 +865,12 @@ cfs_hash_dual_bd_finddel_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds, { return cfs_hash_multi_bd_finddel_locked(hs, bds, 2, key, hnode); } -EXPORT_SYMBOL(cfs_hash_dual_bd_finddel_locked); static void cfs_hash_buckets_free(struct cfs_hash_bucket **buckets, int bkt_size, int prev_size, int size) { - int i; + int i; for (i = prev_size; i < size; i++) { if (buckets[i] != NULL) @@ -914,7 +890,7 @@ cfs_hash_buckets_realloc(struct cfs_hash *hs, struct cfs_hash_bucket **old_bkts, unsigned int old_size, unsigned int new_size) { struct cfs_hash_bucket **new_bkts; - int i; + int i; LASSERT(old_size == 0 || old_bkts != NULL); @@ -932,7 +908,7 @@ cfs_hash_buckets_realloc(struct cfs_hash *hs, struct cfs_hash_bucket **old_bkts, for (i = old_size; i < new_size; i++) { struct hlist_head *hhead; - struct cfs_hash_bd bd; + struct cfs_hash_bd bd; LIBCFS_ALLOC(new_bkts[i], cfs_hash_bkt_size(hs)); if (new_bkts[i] == NULL) { @@ -969,7 +945,7 @@ cfs_hash_buckets_realloc(struct cfs_hash *hs, struct cfs_hash_bucket **old_bkts, * @max_bits - Maximum allowed hash table resize, in bits * @ops - Registered hash table operations * @flags - CFS_HASH_REHASH enable synamic hash resizing - * - CFS_HASH_SORT enable chained hash sort + * - CFS_HASH_SORT enable chained hash sort */ static int cfs_hash_rehash_worker(cfs_workitem_t *wi); @@ -977,10 +953,10 @@ static int cfs_hash_rehash_worker(cfs_workitem_t *wi); static int cfs_hash_dep_print(cfs_workitem_t *wi) { struct cfs_hash *hs = container_of(wi, struct cfs_hash, hs_dep_wi); - int dep; - int bkt; - int off; - int bits; + int dep; + int bkt; + int off; + int bits; spin_lock(&hs->hs_dep_lock); dep = hs->hs_dep_max; @@ -1031,7 +1007,7 @@ cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits, struct cfs_hash_ops *ops, unsigned flags) { struct cfs_hash *hs; - int len; + int len; CLASSERT(CFS_HASH_THETA_BITS < 15); @@ -1062,8 +1038,7 @@ cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits, if (hs == NULL) return NULL; - strncpy(hs->hs_name, name, len); - hs->hs_name[len - 1] = '\0'; + strlcpy(hs->hs_name, name, len); hs->hs_flags = flags; atomic_set(&hs->hs_refcount, 1); @@ -1077,7 +1052,7 @@ cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits, hs->hs_max_bits = (__u8)max_bits; hs->hs_bkt_bits = (__u8)bkt_bits; - hs->hs_ops = ops; + hs->hs_ops = ops; hs->hs_extra_bytes = extra_bytes; hs->hs_rehash_bits = 0; cfs_wi_init(&hs->hs_rehash_wi, hs, cfs_hash_rehash_worker); @@ -1102,10 +1077,10 @@ EXPORT_SYMBOL(cfs_hash_create); static void cfs_hash_destroy(struct cfs_hash *hs) { - struct hlist_node *hnode; - struct hlist_node *pos; - struct cfs_hash_bd bd; - int i; + struct hlist_node *hnode; + struct hlist_node *pos; + struct cfs_hash_bd bd; + int i; LASSERT(hs != NULL); LASSERT(!cfs_hash_is_exiting(hs) && @@ -1223,8 +1198,8 @@ cfs_hash_rehash_inline(struct cfs_hash *hs) void cfs_hash_add(struct cfs_hash *hs, const void *key, struct hlist_node *hnode) { - struct cfs_hash_bd bd; - int bits; + struct cfs_hash_bd bd; + int bits; LASSERT(hlist_unhashed(hnode)); @@ -1248,8 +1223,8 @@ cfs_hash_find_or_add(struct cfs_hash *hs, const void *key, struct hlist_node *hnode, int noref) { struct hlist_node *ehnode; - struct cfs_hash_bd bds[2]; - int bits = 0; + struct cfs_hash_bd bds[2]; + int bits = 0; LASSERT(hlist_unhashed(hnode)); @@ -1261,7 +1236,7 @@ cfs_hash_find_or_add(struct cfs_hash *hs, const void *key, hnode, noref); cfs_hash_dual_bd_unlock(hs, bds, 1); - if (ehnode == hnode) /* new item added */ + if (ehnode == hnode) /* new item added */ bits = cfs_hash_rehash_bits(hs); cfs_hash_unlock(hs, 0); if (bits > 0) @@ -1276,7 +1251,8 @@ cfs_hash_find_or_add(struct cfs_hash *hs, const void *key, * Returns 0 on success or -EALREADY on key collisions. */ int -cfs_hash_add_unique(struct cfs_hash *hs, const void *key, struct hlist_node *hnode) +cfs_hash_add_unique(struct cfs_hash *hs, const void *key, + struct hlist_node *hnode) { return cfs_hash_find_or_add(hs, key, hnode, 1) != hnode ? -EALREADY : 0; @@ -1309,9 +1285,9 @@ EXPORT_SYMBOL(cfs_hash_findadd_unique); void * cfs_hash_del(struct cfs_hash *hs, const void *key, struct hlist_node *hnode) { - void *obj = NULL; - int bits = 0; - struct cfs_hash_bd bds[2]; + void *obj = NULL; + int bits = 0; + struct cfs_hash_bd bds[2]; cfs_hash_lock(hs, 0); cfs_hash_dual_bd_get_and_lock(hs, key, bds, 1); @@ -1364,9 +1340,9 @@ EXPORT_SYMBOL(cfs_hash_del_key); void * cfs_hash_lookup(struct cfs_hash *hs, const void *key) { - void *obj = NULL; - struct hlist_node *hnode; - struct cfs_hash_bd bds[2]; + void *obj = NULL; + struct hlist_node *hnode; + struct cfs_hash_bd bds[2]; cfs_hash_lock(hs, 0); cfs_hash_dual_bd_get_and_lock(hs, key, bds, 0); @@ -1383,7 +1359,8 @@ cfs_hash_lookup(struct cfs_hash *hs, const void *key) EXPORT_SYMBOL(cfs_hash_lookup); static void -cfs_hash_for_each_enter(struct cfs_hash *hs) { +cfs_hash_for_each_enter(struct cfs_hash *hs) +{ LASSERT(!cfs_hash_is_exiting(hs)); if (!cfs_hash_with_rehash(hs)) @@ -1408,7 +1385,8 @@ cfs_hash_for_each_enter(struct cfs_hash *hs) { } static void -cfs_hash_for_each_exit(struct cfs_hash *hs) { +cfs_hash_for_each_exit(struct cfs_hash *hs) +{ int remained; int bits; @@ -1439,14 +1417,15 @@ cfs_hash_for_each_exit(struct cfs_hash *hs) { */ static __u64 cfs_hash_for_each_tight(struct cfs_hash *hs, cfs_hash_for_each_cb_t func, - void *data, int remove_safe) { - struct hlist_node *hnode; - struct hlist_node *pos; - struct cfs_hash_bd bd; - __u64 count = 0; - int excl = !!remove_safe; - int loop = 0; - int i; + void *data, int remove_safe) +{ + struct hlist_node *hnode; + struct hlist_node *pos; + struct cfs_hash_bd bd; + __u64 count = 0; + int excl = !!remove_safe; + int loop = 0; + int i; cfs_hash_for_each_enter(hs); @@ -1514,8 +1493,8 @@ void cfs_hash_cond_del(struct cfs_hash *hs, cfs_hash_cond_opt_cb_t func, void *data) { struct cfs_hash_cond_arg arg = { - .func = func, - .arg = data, + .func = func, + .arg = data, }; cfs_hash_for_each_tight(hs, cfs_hash_cond_del_locked, &arg, 1); @@ -1523,16 +1502,17 @@ cfs_hash_cond_del(struct cfs_hash *hs, cfs_hash_cond_opt_cb_t func, void *data) EXPORT_SYMBOL(cfs_hash_cond_del); void -cfs_hash_for_each(struct cfs_hash *hs, - cfs_hash_for_each_cb_t func, void *data) +cfs_hash_for_each(struct cfs_hash *hs, cfs_hash_for_each_cb_t func, + void *data) { cfs_hash_for_each_tight(hs, func, data, 0); } EXPORT_SYMBOL(cfs_hash_for_each); void -cfs_hash_for_each_safe(struct cfs_hash *hs, - cfs_hash_for_each_cb_t func, void *data) { +cfs_hash_for_each_safe(struct cfs_hash *hs, cfs_hash_for_each_cb_t func, + void *data) +{ cfs_hash_for_each_tight(hs, func, data, 1); } EXPORT_SYMBOL(cfs_hash_for_each_safe); @@ -1581,15 +1561,16 @@ EXPORT_SYMBOL(cfs_hash_size_get); */ static int cfs_hash_for_each_relax(struct cfs_hash *hs, cfs_hash_for_each_cb_t func, - void *data) { + void *data) +{ struct hlist_node *hnode; struct hlist_node *tmp; - struct cfs_hash_bd bd; - __u32 version; - int count = 0; - int stop_on_change; - int rc; - int i; + struct cfs_hash_bd bd; + __u32 version; + int count = 0; + int stop_on_change; + int rc; + int i; stop_on_change = cfs_hash_with_rehash_key(hs) || !cfs_hash_with_no_itemref(hs) || @@ -1645,8 +1626,9 @@ cfs_hash_for_each_relax(struct cfs_hash *hs, cfs_hash_for_each_cb_t func, } int -cfs_hash_for_each_nolock(struct cfs_hash *hs, - cfs_hash_for_each_cb_t func, void *data) { +cfs_hash_for_each_nolock(struct cfs_hash *hs, cfs_hash_for_each_cb_t func, + void *data) +{ if (cfs_hash_with_no_lock(hs) || cfs_hash_with_rehash_key(hs) || !cfs_hash_with_no_itemref(hs)) @@ -1677,9 +1659,10 @@ EXPORT_SYMBOL(cfs_hash_for_each_nolock); * the required locking is in place to prevent concurrent insertions. */ int -cfs_hash_for_each_empty(struct cfs_hash *hs, - cfs_hash_for_each_cb_t func, void *data) { - unsigned i = 0; +cfs_hash_for_each_empty(struct cfs_hash *hs, cfs_hash_for_each_cb_t func, + void *data) +{ + unsigned i = 0; if (cfs_hash_with_no_lock(hs)) return -EOPNOTSUPP; @@ -1703,9 +1686,9 @@ void cfs_hash_hlist_for_each(struct cfs_hash *hs, unsigned hindex, cfs_hash_for_each_cb_t func, void *data) { - struct hlist_head *hhead; - struct hlist_node *hnode; - struct cfs_hash_bd bd; + struct hlist_head *hhead; + struct hlist_node *hnode; + struct cfs_hash_bd bd; cfs_hash_for_each_enter(hs); cfs_hash_lock(hs, 0); @@ -1721,7 +1704,7 @@ cfs_hash_hlist_for_each(struct cfs_hash *hs, unsigned hindex, break; } cfs_hash_bd_unlock(hs, &bd, 0); - out: +out: cfs_hash_unlock(hs, 0); cfs_hash_for_each_exit(hs); } @@ -1736,10 +1719,11 @@ EXPORT_SYMBOL(cfs_hash_hlist_for_each); */ void cfs_hash_for_each_key(struct cfs_hash *hs, const void *key, - cfs_hash_for_each_cb_t func, void *data) { - struct hlist_node *hnode; - struct cfs_hash_bd bds[2]; - unsigned i; + cfs_hash_for_each_cb_t func, void *data) +{ + struct hlist_node *hnode; + struct cfs_hash_bd bds[2]; + unsigned int i; cfs_hash_lock(hs, 0); @@ -1777,7 +1761,7 @@ EXPORT_SYMBOL(cfs_hash_for_each_key); void cfs_hash_rehash_cancel_locked(struct cfs_hash *hs) { - int i; + int i; /* need hold cfs_hash_lock(hs, 1) */ LASSERT(cfs_hash_with_rehash(hs) && @@ -1794,14 +1778,13 @@ cfs_hash_rehash_cancel_locked(struct cfs_hash *hs) for (i = 2; cfs_hash_is_rehashing(hs); i++) { cfs_hash_unlock(hs, 1); /* raise console warning while waiting too long */ - CDEBUG(IS_PO2(i >> 3) ? D_WARNING : D_INFO, + CDEBUG(is_power_of_2(i >> 3) ? D_WARNING : D_INFO, "hash %s is still rehashing, rescheded %d\n", hs->hs_name, i - 1); cond_resched(); cfs_hash_lock(hs, 1); } } -EXPORT_SYMBOL(cfs_hash_rehash_cancel_locked); void cfs_hash_rehash_cancel(struct cfs_hash *hs) @@ -1810,12 +1793,11 @@ cfs_hash_rehash_cancel(struct cfs_hash *hs) cfs_hash_rehash_cancel_locked(hs); cfs_hash_unlock(hs, 1); } -EXPORT_SYMBOL(cfs_hash_rehash_cancel); int cfs_hash_rehash(struct cfs_hash *hs, int do_rehash) { - int rc; + int rc; LASSERT(cfs_hash_with_rehash(hs) && !cfs_hash_with_no_lock(hs)); @@ -1840,17 +1822,16 @@ cfs_hash_rehash(struct cfs_hash *hs, int do_rehash) return cfs_hash_rehash_worker(&hs->hs_rehash_wi); } -EXPORT_SYMBOL(cfs_hash_rehash); static int cfs_hash_rehash_bd(struct cfs_hash *hs, struct cfs_hash_bd *old) { - struct cfs_hash_bd new; - struct hlist_head *hhead; - struct hlist_node *hnode; - struct hlist_node *pos; - void *key; - int c = 0; + struct cfs_hash_bd new; + struct hlist_head *hhead; + struct hlist_node *hnode; + struct hlist_node *pos; + void *key; + int c = 0; /* hold cfs_hash_lock(hs, 1), so don't need any bucket lock */ cfs_hash_bd_for_each_hlist(hs, old, hhead) { @@ -1876,17 +1857,17 @@ cfs_hash_rehash_bd(struct cfs_hash *hs, struct cfs_hash_bd *old) static int cfs_hash_rehash_worker(cfs_workitem_t *wi) { - struct cfs_hash *hs = container_of(wi, struct cfs_hash, hs_rehash_wi); + struct cfs_hash *hs = container_of(wi, struct cfs_hash, hs_rehash_wi); struct cfs_hash_bucket **bkts; - struct cfs_hash_bd bd; - unsigned int old_size; - unsigned int new_size; - int bsize; - int count = 0; - int rc = 0; - int i; + struct cfs_hash_bd bd; + unsigned int old_size; + unsigned int new_size; + int bsize; + int count = 0; + int rc = 0; + int i; - LASSERT (hs != NULL && cfs_hash_with_rehash(hs)); + LASSERT(hs != NULL && cfs_hash_with_rehash(hs)); cfs_hash_lock(hs, 0); LASSERT(cfs_hash_is_rehashing(hs)); @@ -1958,7 +1939,7 @@ cfs_hash_rehash_worker(cfs_workitem_t *wi) hs->hs_rehash_buckets = NULL; hs->hs_cur_bits = hs->hs_rehash_bits; - out: +out: hs->hs_rehash_bits = 0; if (rc == -ESRCH) /* never be scheduled again */ cfs_wi_exit(cfs_sched_rehash, wi); @@ -1986,9 +1967,9 @@ cfs_hash_rehash_worker(cfs_workitem_t *wi) void cfs_hash_rehash_key(struct cfs_hash *hs, const void *old_key, void *new_key, struct hlist_node *hnode) { - struct cfs_hash_bd bds[3]; - struct cfs_hash_bd old_bds[2]; - struct cfs_hash_bd new_bd; + struct cfs_hash_bd bds[3]; + struct cfs_hash_bd old_bds[2]; + struct cfs_hash_bd new_bd; LASSERT(!hlist_unhashed(hnode)); @@ -2014,7 +1995,7 @@ void cfs_hash_rehash_key(struct cfs_hash *hs, const void *old_key, } /* overwrite key inside locks, otherwise may screw up with * other operations, i.e: rehash */ - cfs_hash_keycpy(hs, new_key, hnode); + cfs_hash_keycpy(hs, hnode, new_key); cfs_hash_multi_bd_unlock(hs, bds, 3, 1); cfs_hash_unlock(hs, 0); @@ -2054,12 +2035,12 @@ cfs_hash_full_nbkt(struct cfs_hash *hs) void cfs_hash_debug_str(struct cfs_hash *hs, struct seq_file *m) { - int dist[8] = { 0, }; - int maxdep = -1; - int maxdepb = -1; - int total = 0; - int theta; - int i; + int dist[8] = { 0, }; + int maxdep = -1; + int maxdepb = -1; + int total = 0; + int theta; + int i; cfs_hash_lock(hs, 0); theta = __cfs_hash_theta(hs); @@ -2085,11 +2066,11 @@ void cfs_hash_debug_str(struct cfs_hash *hs, struct seq_file *m) * If you hash function results in a non-uniform hash the will * be observable by outlier bucks in the distribution histogram. * - * Uniform hash distribution: 128/128/0/0/0/0/0/0 - * Non-Uniform hash distribution: 128/125/0/0/0/0/2/1 + * Uniform hash distribution: 128/128/0/0/0/0/0/0 + * Non-Uniform hash distribution: 128/125/0/0/0/0/2/1 */ for (i = 0; i < cfs_hash_full_nbkt(hs); i++) { - struct cfs_hash_bd bd; + struct cfs_hash_bd bd; bd.bd_bucket = cfs_hash_full_bkts(hs)[i]; cfs_hash_bd_lock(hs, &bd, 0); diff --git a/drivers/staging/lustre/lustre/libcfs/kernel_user_comm.c b/drivers/staging/lustre/lustre/libcfs/kernel_user_comm.c index ad661a33a211..d8230aec9a2b 100644 --- a/drivers/staging/lustre/lustre/libcfs/kernel_user_comm.c +++ b/drivers/staging/lustre/lustre/libcfs/kernel_user_comm.c @@ -110,7 +110,8 @@ static DECLARE_RWSEM(kg_sem); * @param uid identifier for this receiver * @param group group number */ -int libcfs_kkuc_group_add(struct file *filp, int uid, int group, __u32 data) +int libcfs_kkuc_group_add(struct file *filp, int uid, unsigned int group, + __u32 data) { struct kkuc_reg *reg; diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c index 94bc00785000..15782d9e6aa9 100644 --- a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c +++ b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c @@ -21,7 +21,7 @@ * GPL HEADER END */ /* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015 Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_mem.c b/drivers/staging/lustre/lustre/libcfs/libcfs_mem.c index f4e08daba4d9..27cf86106363 100644 --- a/drivers/staging/lustre/lustre/libcfs/libcfs_mem.c +++ b/drivers/staging/lustre/lustre/libcfs/libcfs_mem.c @@ -134,7 +134,6 @@ cfs_percpt_current(void *vars) return arr->va_ptrs[cpt]; } -EXPORT_SYMBOL(cfs_percpt_current); void * cfs_percpt_index(void *vars, int idx) @@ -146,7 +145,6 @@ cfs_percpt_index(void *vars, int idx) LASSERT(idx >= 0 && idx < arr->va_count); return arr->va_ptrs[idx]; } -EXPORT_SYMBOL(cfs_percpt_index); /* * free variable array, see more detail in cfs_array_alloc diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_string.c b/drivers/staging/lustre/lustre/libcfs/libcfs_string.c index d40be5396769..205a3ed435a8 100644 --- a/drivers/staging/lustre/lustre/libcfs/libcfs_string.c +++ b/drivers/staging/lustre/lustre/libcfs/libcfs_string.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015 Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-cpu.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-cpu.c index 209736454d06..e52afe35e7ea 100644 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-cpu.c +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-cpu.c @@ -22,7 +22,8 @@ */ /* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, Intel Corporation. + * + * Copyright (c) 2012, 2015 Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -78,23 +79,6 @@ struct cfs_cpt_data { static struct cfs_cpt_data cpt_data; -static void cfs_cpu_core_siblings(int cpu, cpumask_t *mask) -{ - /* return cpumask of cores in the same socket */ - cpumask_copy(mask, topology_core_cpumask(cpu)); -} - -/* return cpumask of HTs in the same core */ -static void cfs_cpu_ht_siblings(int cpu, cpumask_t *mask) -{ - cpumask_copy(mask, topology_sibling_cpumask(cpu)); -} - -static void cfs_node_to_cpumask(int node, cpumask_t *mask) -{ - cpumask_copy(mask, cpumask_of_node(node)); -} - void cfs_cpt_table_free(struct cfs_cpt_table *cptab) { @@ -426,7 +410,7 @@ cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node) mutex_lock(&cpt_data.cpt_mutex); mask = cpt_data.cpt_cpumask; - cfs_node_to_cpumask(node, mask); + cpumask_copy(mask, cpumask_of_node(node)); rc = cfs_cpt_set_cpumask(cptab, cpt, mask); @@ -450,7 +434,7 @@ cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node) mutex_lock(&cpt_data.cpt_mutex); mask = cpt_data.cpt_cpumask; - cfs_node_to_cpumask(node, mask); + cpumask_copy(mask, cpumask_of_node(node)); cfs_cpt_unset_cpumask(cptab, cpt, mask); @@ -643,7 +627,7 @@ cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt, cpu = cpumask_first(node); /* get cpumask for cores in the same socket */ - cfs_cpu_core_siblings(cpu, socket); + cpumask_copy(socket, topology_core_cpumask(cpu)); cpumask_and(socket, socket, node); LASSERT(!cpumask_empty(socket)); @@ -652,7 +636,7 @@ cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt, int i; /* get cpumask for hts in the same core */ - cfs_cpu_ht_siblings(cpu, core); + cpumask_copy(core, topology_sibling_cpumask(cpu)); cpumask_and(core, core, node); LASSERT(!cpumask_empty(core)); @@ -769,7 +753,7 @@ cfs_cpt_table_create(int ncpt) } for_each_online_node(i) { - cfs_node_to_cpumask(i, mask); + cpumask_copy(mask, cpumask_of_node(i)); while (!cpumask_empty(mask)) { struct cfs_cpu_partition *part; @@ -968,7 +952,8 @@ cfs_cpu_notify(struct notifier_block *self, unsigned long action, void *hcpu) mutex_lock(&cpt_data.cpt_mutex); /* if all HTs in a core are offline, it may break affinity */ - cfs_cpu_ht_siblings(cpu, cpt_data.cpt_cpumask); + cpumask_copy(cpt_data.cpt_cpumask, + topology_sibling_cpumask(cpu)); warn = cpumask_any_and(cpt_data.cpt_cpumask, cpu_online_mask) >= nr_cpu_ids; mutex_unlock(&cpt_data.cpt_mutex); diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-crypto-adler.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-crypto-adler.c index 5d8d8b79fa1f..db0572733712 100644 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-crypto-adler.c +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-crypto-adler.c @@ -37,11 +37,6 @@ #define CHKSUM_BLOCK_SIZE 1 #define CHKSUM_DIGEST_SIZE 4 -static u32 __adler32(u32 cksum, unsigned char const *p, size_t len) -{ - return zlib_adler32(cksum, p, len); -} - static int adler32_cra_init(struct crypto_tfm *tfm) { u32 *key = crypto_tfm_ctx(tfm); @@ -79,14 +74,14 @@ static int adler32_update(struct shash_desc *desc, const u8 *data, { u32 *cksump = shash_desc_ctx(desc); - *cksump = __adler32(*cksump, data, len); + *cksump = zlib_adler32(*cksump, data, len); return 0; } static int __adler32_finup(u32 *cksump, const u8 *data, unsigned int len, u8 *out) { - *(u32 *)out = __adler32(*cksump, data, len); + *(u32 *)out = zlib_adler32(*cksump, data, len); return 0; } diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-curproc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-curproc.c index c74c80915dca..68515d9130c1 100644 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-curproc.c +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-curproc.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-debug.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-debug.c index 8689ea757c99..59c7bf3cbc1f 100644 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-debug.c +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-debug.c @@ -195,6 +195,5 @@ void libcfs_unregister_panic_notifier(void) atomic_notifier_chain_unregister(&panic_notifier_list, &libcfs_panic_notifier); } -EXPORT_SYMBOL(libcfs_run_upcall); EXPORT_SYMBOL(libcfs_run_lbug_upcall); EXPORT_SYMBOL(lbug_with_loc); diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.h b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.h deleted file mode 100644 index ba84e4ffddd1..000000000000 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * GPL HEADER START - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License version 2 for more details (a copy is included - * in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - * - * GPL HEADER END - */ -/* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - */ - -#ifndef __LIBCFS_LINUX_TRACEFILE_H__ -#define __LIBCFS_LINUX_TRACEFILE_H__ - -/** - * three types of trace_data in linux - */ -typedef enum { - CFS_TCD_TYPE_PROC = 0, - CFS_TCD_TYPE_SOFTIRQ, - CFS_TCD_TYPE_IRQ, - CFS_TCD_TYPE_MAX -} cfs_trace_buf_type_t; - -#endif diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c index e7c2b26156b9..329d78ce272d 100644 --- a/drivers/staging/lustre/lustre/libcfs/module.c +++ b/drivers/staging/lustre/lustre/libcfs/module.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015 Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -62,7 +62,7 @@ #include "../../include/linux/lnet/lnet.h" #include "tracefile.h" -MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Portals v3.1"); MODULE_LICENSE("GPL"); @@ -375,7 +375,7 @@ static int __proc_dobitmasks(void *data, int write, } else { rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob); if (rc < 0) { - cfs_trace_free_string_buffer(tmpstr, tmpstrlen); + kfree(tmpstr); return rc; } @@ -385,7 +385,7 @@ static int __proc_dobitmasks(void *data, int write, *mask |= D_EMERG; } - cfs_trace_free_string_buffer(tmpstr, tmpstrlen); + kfree(tmpstr); return rc; } diff --git a/drivers/staging/lustre/lustre/libcfs/tracefile.c b/drivers/staging/lustre/lustre/libcfs/tracefile.c index f2d018d7823c..65c4f1ab0de8 100644 --- a/drivers/staging/lustre/lustre/libcfs/tracefile.c +++ b/drivers/staging/lustre/lustre/libcfs/tracefile.c @@ -199,7 +199,6 @@ static void cfs_tcd_shrink(struct cfs_trace_cpu_data *tcd) pgcount + 1, tcd->tcd_cur_pages); INIT_LIST_HEAD(&pc.pc_pages); - spin_lock_init(&pc.pc_lock); list_for_each_entry_safe(tage, tmp, &tcd->tcd_pages, linkage) { if (pgcount-- == 0) @@ -451,7 +450,7 @@ console: cfs_print_to_console(&header, mask, string_buf, needed, file, msgdata->msg_fn); - cfs_trace_put_console_buffer(string_buf); + put_cpu(); } if (cdls != NULL && cdls->cdls_count != 0) { @@ -465,7 +464,7 @@ console: cfs_print_to_console(&header, mask, string_buf, needed, file, msgdata->msg_fn); - cfs_trace_put_console_buffer(string_buf); + put_cpu(); cdls->cdls_count = 0; } @@ -522,7 +521,6 @@ static void collect_pages_on_all_cpus(struct page_collection *pc) struct cfs_trace_cpu_data *tcd; int i, cpu; - spin_lock(&pc->pc_lock); for_each_possible_cpu(cpu) { cfs_tcd_for_each_type_lock(tcd, i, cpu) { list_splice_init(&tcd->tcd_pages, &pc->pc_pages); @@ -534,7 +532,6 @@ static void collect_pages_on_all_cpus(struct page_collection *pc) } } } - spin_unlock(&pc->pc_lock); } static void collect_pages(struct page_collection *pc) @@ -555,7 +552,6 @@ static void put_pages_back_on_all_cpus(struct page_collection *pc) struct cfs_trace_page *tmp; int i, cpu; - spin_lock(&pc->pc_lock); for_each_possible_cpu(cpu) { cfs_tcd_for_each_type_lock(tcd, i, cpu) { cur_head = tcd->tcd_pages.next; @@ -573,7 +569,6 @@ static void put_pages_back_on_all_cpus(struct page_collection *pc) } } } - spin_unlock(&pc->pc_lock); } static void put_pages_back(struct page_collection *pc) @@ -592,7 +587,6 @@ static void put_pages_on_tcd_daemon_list(struct page_collection *pc, struct cfs_trace_page *tage; struct cfs_trace_page *tmp; - spin_lock(&pc->pc_lock); list_for_each_entry_safe(tage, tmp, &pc->pc_pages, linkage) { __LASSERT_TAGE_INVARIANT(tage); @@ -616,7 +610,6 @@ static void put_pages_on_tcd_daemon_list(struct page_collection *pc, tcd->tcd_cur_daemon_pages--; } } - spin_unlock(&pc->pc_lock); } static void put_pages_on_daemon_list(struct page_collection *pc) @@ -636,8 +629,6 @@ void cfs_trace_debug_print(void) struct cfs_trace_page *tage; struct cfs_trace_page *tmp; - spin_lock_init(&pc.pc_lock); - pc.pc_want_daemon_pages = 1; collect_pages(&pc); list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) { @@ -692,7 +683,6 @@ int cfs_tracefile_dump_all_pages(char *filename) goto out; } - spin_lock_init(&pc.pc_lock); pc.pc_want_daemon_pages = 1; collect_pages(&pc); if (list_empty(&pc.pc_pages)) { @@ -739,8 +729,6 @@ void cfs_trace_flush_pages(void) struct cfs_trace_page *tage; struct cfs_trace_page *tmp; - spin_lock_init(&pc.pc_lock); - pc.pc_want_daemon_pages = 1; collect_pages(&pc); list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) { @@ -817,11 +805,6 @@ int cfs_trace_allocate_string_buffer(char **str, int nob) return 0; } -void cfs_trace_free_string_buffer(char *str, int nob) -{ - kfree(str); -} - int cfs_trace_dump_debug_buffer_usrstr(void __user *usr_str, int usr_str_nob) { char *str; @@ -842,7 +825,7 @@ int cfs_trace_dump_debug_buffer_usrstr(void __user *usr_str, int usr_str_nob) } rc = cfs_tracefile_dump_all_pages(str); out: - cfs_trace_free_string_buffer(str, usr_str_nob + 1); + kfree(str); return rc; } @@ -898,7 +881,7 @@ int cfs_trace_daemon_command_usrstr(void __user *usr_str, int usr_str_nob) if (rc == 0) rc = cfs_trace_daemon_command(str); - cfs_trace_free_string_buffer(str, usr_str_nob + 1); + kfree(str); return rc; } @@ -970,7 +953,6 @@ static int tracefiled(void *arg) /* we're started late enough that we pick up init's fs context */ /* this is so broken in uml? what on earth is going on? */ - spin_lock_init(&pc.pc_lock); complete(&tctl->tctl_start); while (1) { @@ -1170,7 +1152,6 @@ static void cfs_trace_cleanup(void) struct page_collection pc; INIT_LIST_HEAD(&pc.pc_pages); - spin_lock_init(&pc.pc_lock); trace_cleanup_on_all_cpus(); diff --git a/drivers/staging/lustre/lustre/libcfs/tracefile.h b/drivers/staging/lustre/lustre/libcfs/tracefile.h index cb7a3963589f..7bf1471a54fb 100644 --- a/drivers/staging/lustre/lustre/libcfs/tracefile.h +++ b/drivers/staging/lustre/lustre/libcfs/tracefile.h @@ -39,7 +39,12 @@ #include "../../include/linux/libcfs/libcfs.h" -#include "linux/linux-tracefile.h" +typedef enum { + CFS_TCD_TYPE_PROC = 0, + CFS_TCD_TYPE_SOFTIRQ, + CFS_TCD_TYPE_IRQ, + CFS_TCD_TYPE_MAX +} cfs_trace_buf_type_t; /* trace file lock routines */ @@ -70,7 +75,6 @@ int cfs_trace_copyin_string(char *knl_buffer, int knl_buffer_nob, int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob, const char *knl_str, char *append); int cfs_trace_allocate_string_buffer(char **str, int nob); -void cfs_trace_free_string_buffer(char *str, int nob); int cfs_trace_dump_debug_buffer_usrstr(void __user *usr_str, int usr_str_nob); int cfs_trace_daemon_command(char *str); int cfs_trace_daemon_command_usrstr(void __user *usr_str, int usr_str_nob); @@ -196,14 +200,6 @@ extern union cfs_trace_data_union (*cfs_trace_data[TCD_MAX_TYPES])[NR_CPUS]; struct page_collection { struct list_head pc_pages; /* - * spin-lock protecting ->pc_pages. It is taken by smp_call_function() - * call-back functions. XXX nikita: Which is horrible: all processors - * receive NMI at the same time only to be serialized by this - * lock. Probably ->pc_pages should be replaced with an array of - * NR_CPUS elements accessed locklessly. - */ - spinlock_t pc_lock; - /* * if this flag is set, collect_pages() will spill both * ->tcd_daemon_pages and ->tcd_pages to the ->pc_pages. Otherwise, * only ->tcd_pages are spilled. @@ -260,13 +256,6 @@ void cfs_print_to_console(struct ptldebug_header *hdr, int mask, int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking); void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking); -/** - * trace_buf_type_t, trace_buf_idx_get() and trace_console_buffers[][] - * are not public libcfs API; they should be defined in - * platform-specific tracefile include files - * (see, for example, linux-tracefile.h). - */ - extern char *cfs_trace_console_buffers[NR_CPUS][CFS_TCD_TYPE_MAX]; cfs_trace_buf_type_t cfs_trace_buf_idx_get(void); @@ -279,12 +268,6 @@ cfs_trace_get_console_buffer(void) return cfs_trace_console_buffers[i][j]; } -static inline void -cfs_trace_put_console_buffer(char *buffer) -{ - put_cpu(); -} - static inline struct cfs_trace_cpu_data * cfs_trace_get_tcd(void) { diff --git a/drivers/staging/lustre/lustre/libcfs/workitem.c b/drivers/staging/lustre/lustre/libcfs/workitem.c index e1143a566ac4..60bb88a00b41 100644 --- a/drivers/staging/lustre/lustre/libcfs/workitem.c +++ b/drivers/staging/lustre/lustre/libcfs/workitem.c @@ -86,32 +86,20 @@ static struct cfs_workitem_data { int wi_stopping; } cfs_wi_data; -static inline void -cfs_wi_sched_lock(struct cfs_wi_sched *sched) -{ - spin_lock(&sched->ws_lock); -} - -static inline void -cfs_wi_sched_unlock(struct cfs_wi_sched *sched) -{ - spin_unlock(&sched->ws_lock); -} - static inline int cfs_wi_sched_cansleep(struct cfs_wi_sched *sched) { - cfs_wi_sched_lock(sched); + spin_lock(&sched->ws_lock); if (sched->ws_stopping) { - cfs_wi_sched_unlock(sched); + spin_unlock(&sched->ws_lock); return 0; } if (!list_empty(&sched->ws_runq)) { - cfs_wi_sched_unlock(sched); + spin_unlock(&sched->ws_lock); return 0; } - cfs_wi_sched_unlock(sched); + spin_unlock(&sched->ws_lock); return 1; } @@ -125,7 +113,7 @@ cfs_wi_exit(struct cfs_wi_sched *sched, cfs_workitem_t *wi) LASSERT(!in_interrupt()); /* because we use plain spinlock */ LASSERT(!sched->ws_stopping); - cfs_wi_sched_lock(sched); + spin_lock(&sched->ws_lock); LASSERT(wi->wi_running); if (wi->wi_scheduled) { /* cancel pending schedules */ @@ -139,7 +127,7 @@ cfs_wi_exit(struct cfs_wi_sched *sched, cfs_workitem_t *wi) LASSERT(list_empty(&wi->wi_list)); wi->wi_scheduled = 1; /* LBUG future schedule attempts */ - cfs_wi_sched_unlock(sched); + spin_unlock(&sched->ws_lock); return; } @@ -161,7 +149,7 @@ cfs_wi_deschedule(struct cfs_wi_sched *sched, cfs_workitem_t *wi) * means the workitem will not be scheduled and will not have * any race with wi_action. */ - cfs_wi_sched_lock(sched); + spin_lock(&sched->ws_lock); rc = !(wi->wi_running); @@ -177,7 +165,7 @@ cfs_wi_deschedule(struct cfs_wi_sched *sched, cfs_workitem_t *wi) LASSERT (list_empty(&wi->wi_list)); - cfs_wi_sched_unlock(sched); + spin_unlock(&sched->ws_lock); return rc; } EXPORT_SYMBOL(cfs_wi_deschedule); @@ -195,7 +183,7 @@ cfs_wi_schedule(struct cfs_wi_sched *sched, cfs_workitem_t *wi) LASSERT(!in_interrupt()); /* because we use plain spinlock */ LASSERT(!sched->ws_stopping); - cfs_wi_sched_lock(sched); + spin_lock(&sched->ws_lock); if (!wi->wi_scheduled) { LASSERT (list_empty(&wi->wi_list)); @@ -211,7 +199,7 @@ cfs_wi_schedule(struct cfs_wi_sched *sched, cfs_workitem_t *wi) } LASSERT (!list_empty(&wi->wi_list)); - cfs_wi_sched_unlock(sched); + spin_unlock(&sched->ws_lock); return; } EXPORT_SYMBOL(cfs_wi_schedule); @@ -225,7 +213,9 @@ cfs_wi_scheduler (void *arg) /* CPT affinity scheduler? */ if (sched->ws_cptab != NULL) - cfs_cpt_bind(sched->ws_cptab, sched->ws_cpt); + if (cfs_cpt_bind(sched->ws_cptab, sched->ws_cpt) != 0) + CWARN("Failed to bind %s on CPT %d\n", + sched->ws_name, sched->ws_cpt); spin_lock(&cfs_wi_data.wi_glock); @@ -235,7 +225,7 @@ cfs_wi_scheduler (void *arg) spin_unlock(&cfs_wi_data.wi_glock); - cfs_wi_sched_lock(sched); + spin_lock(&sched->ws_lock); while (!sched->ws_stopping) { int nloops = 0; @@ -256,12 +246,12 @@ cfs_wi_scheduler (void *arg) wi->wi_running = 1; wi->wi_scheduled = 0; - cfs_wi_sched_unlock(sched); + spin_unlock(&sched->ws_lock); nloops++; rc = (*wi->wi_action) (wi); - cfs_wi_sched_lock(sched); + spin_lock(&sched->ws_lock); if (rc != 0) /* WI should be dead, even be freed! */ continue; @@ -276,21 +266,21 @@ cfs_wi_scheduler (void *arg) } if (!list_empty(&sched->ws_runq)) { - cfs_wi_sched_unlock(sched); + spin_unlock(&sched->ws_lock); /* don't sleep because some workitems still * expect me to come back soon */ cond_resched(); - cfs_wi_sched_lock(sched); + spin_lock(&sched->ws_lock); continue; } - cfs_wi_sched_unlock(sched); + spin_unlock(&sched->ws_lock); rc = wait_event_interruptible_exclusive(sched->ws_waitq, !cfs_wi_sched_cansleep(sched)); - cfs_wi_sched_lock(sched); + spin_lock(&sched->ws_lock); } - cfs_wi_sched_unlock(sched); + spin_unlock(&sched->ws_lock); spin_lock(&cfs_wi_data.wi_glock); sched->ws_nthreads--; @@ -325,7 +315,7 @@ cfs_wi_sched_destroy(struct cfs_wi_sched *sched) spin_lock(&cfs_wi_data.wi_glock); while (sched->ws_nthreads > 0) { - CDEBUG(IS_PO2(++i) ? D_WARNING : D_NET, + CDEBUG(is_power_of_2(++i) ? D_WARNING : D_NET, "waiting for %d threads of WI sched[%s] to terminate\n", sched->ws_nthreads, sched->ws_name); @@ -360,8 +350,8 @@ cfs_wi_sched_create(char *name, struct cfs_cpt_table *cptab, if (sched == NULL) return -ENOMEM; - strncpy(sched->ws_name, name, CFS_WS_NAME_LEN); - sched->ws_name[CFS_WS_NAME_LEN - 1] = '\0'; + strlcpy(sched->ws_name, name, CFS_WS_NAME_LEN); + sched->ws_cptab = cptab; sched->ws_cpt = cpt; diff --git a/drivers/staging/lustre/lustre/llite/dcache.c b/drivers/staging/lustre/lustre/llite/dcache.c index 80cba0448499..3d6745e63fe3 100644 --- a/drivers/staging/lustre/lustre/llite/dcache.c +++ b/drivers/staging/lustre/lustre/llite/dcache.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c index 5c9502b5b358..7b355319079c 100644 --- a/drivers/staging/lustre/lustre/llite/dir.c +++ b/drivers/staging/lustre/lustre/llite/dir.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -239,12 +239,6 @@ static int ll_dir_filler(void *_hash, struct page *page0) return rc; } -static void ll_check_page(struct inode *dir, struct page *page) -{ - /* XXX: check page format later */ - SetPageChecked(page); -} - void ll_release_page(struct page *page, int remove) { kunmap(page); @@ -432,7 +426,8 @@ struct page *ll_get_dir_page(struct inode *dir, __u64 hash, goto fail; } if (!PageChecked(page)) - ll_check_page(dir, page); + /* XXX: check page format later */ + SetPageChecked(page); if (PageError(page)) { CERROR("page error: "DFID" at %llu: rc %d\n", PFID(ll_inode2fid(dir)), hash, -5); @@ -641,7 +636,7 @@ static int ll_send_mgc_param(struct obd_export *mgc, char *string) if (!msp) return -ENOMEM; - strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN); + strlcpy(msp->mgs_param, string, sizeof(msp->mgs_param)); rc = obd_set_info_async(NULL, mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO, sizeof(struct mgs_send_param), msp, NULL); if (rc) diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c index 31cd6b323a39..c92d58b770ec 100644 --- a/drivers/staging/lustre/lustre/llite/file.c +++ b/drivers/staging/lustre/lustre/llite/file.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h index 6102b29dbf30..ee8a1d67d191 100644 --- a/drivers/staging/lustre/lustre/llite/llite_internal.h +++ b/drivers/staging/lustre/lustre/llite/llite_internal.h @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -1285,16 +1285,6 @@ static inline struct ll_file_data *cl_iattr2fd(struct inode *inode, return LUSTRE_FPRIVATE(attr->ia_file); } -static inline void cl_isize_lock(struct inode *inode) -{ - ll_inode_size_lock(inode); -} - -static inline void cl_isize_unlock(struct inode *inode) -{ - ll_inode_size_unlock(inode); -} - static inline void cl_isize_write_nolock(struct inode *inode, loff_t kms) { LASSERT(mutex_is_locked(&ll_i2info(inode)->lli_size_mutex)); diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c index 4a8c759fef42..1db93af62bad 100644 --- a/drivers/staging/lustre/lustre/llite/llite_lib.c +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/llite/llite_mmap.c b/drivers/staging/lustre/lustre/llite/llite_mmap.c index 7df978371c9a..bbae95c9feed 100644 --- a/drivers/staging/lustre/lustre/llite/llite_mmap.c +++ b/drivers/staging/lustre/lustre/llite/llite_mmap.c @@ -27,7 +27,7 @@ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/llite/lloop.c b/drivers/staging/lustre/lustre/llite/lloop.c index fed50d538a41..420d39123877 100644 --- a/drivers/staging/lustre/lustre/llite/lloop.c +++ b/drivers/staging/lustre/lustre/llite/lloop.c @@ -877,6 +877,6 @@ module_exit(lloop_exit); module_param(max_loop, int, 0444); MODULE_PARM_DESC(max_loop, "maximum of lloop_device"); -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre virtual block device"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/lustre/lustre/llite/lproc_llite.c b/drivers/staging/lustre/lustre/llite/lproc_llite.c index 190fc44114e1..f134ad9d23f0 100644 --- a/drivers/staging/lustre/lustre/llite/lproc_llite.c +++ b/drivers/staging/lustre/lustre/llite/lproc_llite.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/llite/namei.c b/drivers/staging/lustre/lustre/llite/namei.c index 64db5e86672f..da5f443a0768 100644 --- a/drivers/staging/lustre/lustre/llite/namei.c +++ b/drivers/staging/lustre/lustre/llite/namei.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -554,7 +554,6 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, retval = NULL; else retval = dentry; - goto out; out: if (req) ptlrpc_req_finished(req); diff --git a/drivers/staging/lustre/lustre/llite/rw.c b/drivers/staging/lustre/lustre/llite/rw.c index f79193fa2fb7..95cdb0c58b04 100644 --- a/drivers/staging/lustre/lustre/llite/rw.c +++ b/drivers/staging/lustre/lustre/llite/rw.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -880,14 +880,6 @@ static void ras_update_stride_detector(struct ll_readahead_state *ras, return; } -static unsigned long -stride_page_count(struct ll_readahead_state *ras, unsigned long len) -{ - return stride_pg_count(ras->ras_stride_offset, ras->ras_stride_length, - ras->ras_stride_pages, ras->ras_stride_offset, - len); -} - /* Stride Read-ahead window will be increased inc_len according to * stride I/O pattern */ static void ras_stride_increase_window(struct ll_readahead_state *ras, @@ -921,7 +913,9 @@ static void ras_stride_increase_window(struct ll_readahead_state *ras, window_len += step * ras->ras_stride_length + left; - if (stride_page_count(ras, window_len) <= ra->ra_max_pages_per_file) + if (stride_pg_count(ras->ras_stride_offset, ras->ras_stride_length, + ras->ras_stride_pages, ras->ras_stride_offset, + window_len) <= ra->ra_max_pages_per_file) ras->ras_window_len = window_len; RAS_CDEBUG(ras); diff --git a/drivers/staging/lustre/lustre/llite/rw26.c b/drivers/staging/lustre/lustre/llite/rw26.c index 3da4c01e2159..39fa13b74cbd 100644 --- a/drivers/staging/lustre/lustre/llite/rw26.c +++ b/drivers/staging/lustre/lustre/llite/rw26.c @@ -298,7 +298,10 @@ ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io, } if (likely(do_io)) { - cl_2queue_add(queue, clp); + /* + * Add a page to the incoming page list of 2-queue. + */ + cl_page_list_add(&queue->c2_qin, clp); /* * Set page clip to tell transfer formation engine diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c index 18f5f2b7e902..88ffd8e3abdb 100644 --- a/drivers/staging/lustre/lustre/llite/statahead.c +++ b/drivers/staging/lustre/lustre/llite/statahead.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -87,11 +87,6 @@ struct ll_sa_entry { static unsigned int sai_generation; static DEFINE_SPINLOCK(sai_generation_lock); -static inline int ll_sa_entry_unhashed(struct ll_sa_entry *entry) -{ - return list_empty(&entry->se_hash); -} - /* * The entry only can be released by the caller, it is necessary to hold lock. */ @@ -138,20 +133,6 @@ static inline int agl_should_run(struct ll_statahead_info *sai, return (inode != NULL && S_ISREG(inode->i_mode) && sai->sai_agl_valid); } -static inline struct ll_sa_entry * -sa_first_received_entry(struct ll_statahead_info *sai) -{ - return list_entry(sai->sai_entries_received.next, - struct ll_sa_entry, se_list); -} - -static inline struct ll_inode_info * -agl_first_entry(struct ll_statahead_info *sai) -{ - return list_entry(sai->sai_entries_agl.next, - struct ll_inode_info, lli_agl_list); -} - static inline int sa_sent_full(struct ll_statahead_info *sai) { return atomic_read(&sai->sai_cache_count) >= sai->sai_max; @@ -331,7 +312,7 @@ static void ll_sa_entry_put(struct ll_statahead_info *sai, LASSERT(list_empty(&entry->se_link)); LASSERT(list_empty(&entry->se_list)); - LASSERT(ll_sa_entry_unhashed(entry)); + LASSERT(list_empty(&entry->se_hash)); ll_sa_entry_cleanup(sai, entry); iput(entry->se_inode); @@ -346,7 +327,7 @@ do_sa_entry_fini(struct ll_statahead_info *sai, struct ll_sa_entry *entry) { struct ll_inode_info *lli = ll_i2info(sai->sai_inode); - LASSERT(!ll_sa_entry_unhashed(entry)); + LASSERT(!list_empty(&entry->se_hash)); LASSERT(!list_empty(&entry->se_link)); ll_sa_entry_unhash(sai, entry); @@ -447,7 +428,7 @@ static void ll_agl_add(struct ll_statahead_info *sai, igrab(inode); spin_lock(&parent->lli_agl_lock); - if (agl_list_empty(sai)) + if (list_empty(&sai->sai_entries_agl)) added = 1; list_add_tail(&child->lli_agl_list, &sai->sai_entries_agl); spin_unlock(&parent->lli_agl_lock); @@ -537,11 +518,11 @@ static void ll_sai_put(struct ll_statahead_info *sai) do_sa_entry_fini(sai, entry); LASSERT(list_empty(&sai->sai_entries)); - LASSERT(sa_received_empty(sai)); + LASSERT(list_empty(&sai->sai_entries_received)); LASSERT(list_empty(&sai->sai_entries_stated)); LASSERT(atomic_read(&sai->sai_cache_count) == 0); - LASSERT(agl_list_empty(sai)); + LASSERT(list_empty(&sai->sai_entries_agl)); iput(inode); kfree(sai); @@ -621,11 +602,12 @@ static void ll_post_statahead(struct ll_statahead_info *sai) int rc = 0; spin_lock(&lli->lli_sa_lock); - if (unlikely(sa_received_empty(sai))) { + if (unlikely(list_empty(&sai->sai_entries_received))) { spin_unlock(&lli->lli_sa_lock); return; } - entry = sa_first_received_entry(sai); + entry = list_entry(sai->sai_entries_received.next, + struct ll_sa_entry, se_list); atomic_inc(&entry->se_refcount); list_del_init(&entry->se_list); spin_unlock(&lli->lli_sa_lock); @@ -756,7 +738,7 @@ static int ll_statahead_interpret(struct ptlrpc_request *req, * for readpage and other tries to enqueue lock on child * with parent's lock held, for example: unlink. */ entry->se_handle = handle; - wakeup = sa_received_empty(sai); + wakeup = list_empty(&sai->sai_entries_received); list_add_tail(&entry->se_list, &sai->sai_entries_received); } @@ -973,7 +955,7 @@ static int ll_agl_thread(void *arg) while (1) { l_wait_event(thread->t_ctl_waitq, - !agl_list_empty(sai) || + !list_empty(&sai->sai_entries_agl) || !thread_is_running(thread), &lwi); @@ -983,8 +965,9 @@ static int ll_agl_thread(void *arg) spin_lock(&plli->lli_agl_lock); /* The statahead thread maybe help to process AGL entries, * so check whether list empty again. */ - if (!agl_list_empty(sai)) { - clli = agl_first_entry(sai); + if (!list_empty(&sai->sai_entries_agl)) { + clli = list_entry(sai->sai_entries_agl.next, + struct ll_inode_info, lli_agl_list); list_del_init(&clli->lli_agl_list); spin_unlock(&plli->lli_agl_lock); ll_agl_trigger(&clli->lli_vfs_inode, sai); @@ -995,8 +978,9 @@ static int ll_agl_thread(void *arg) spin_lock(&plli->lli_agl_lock); sai->sai_agl_valid = 0; - while (!agl_list_empty(sai)) { - clli = agl_first_entry(sai); + while (!list_empty(&sai->sai_entries_agl)) { + clli = list_entry(sai->sai_entries_agl.next, + struct ll_inode_info, lli_agl_list); list_del_init(&clli->lli_agl_list); spin_unlock(&plli->lli_agl_lock); clli->lli_agl_index = 0; @@ -1136,13 +1120,13 @@ static int ll_statahead_thread(void *arg) keep_it: l_wait_event(thread->t_ctl_waitq, !sa_sent_full(sai) || - !sa_received_empty(sai) || - !agl_list_empty(sai) || + !list_empty(&sai->sai_entries_received) || + !list_empty(&sai->sai_entries_agl) || !thread_is_running(thread), &lwi); interpret_it: - while (!sa_received_empty(sai)) + while (!list_empty(&sai->sai_entries_received)) ll_post_statahead(sai); if (unlikely(!thread_is_running(thread))) { @@ -1156,14 +1140,15 @@ interpret_it: * to process the AGL entries. */ if (sa_sent_full(sai)) { spin_lock(&plli->lli_agl_lock); - while (!agl_list_empty(sai)) { - clli = agl_first_entry(sai); + while (!list_empty(&sai->sai_entries_agl)) { + clli = list_entry(sai->sai_entries_agl.next, + struct ll_inode_info, lli_agl_list); list_del_init(&clli->lli_agl_list); spin_unlock(&plli->lli_agl_lock); ll_agl_trigger(&clli->lli_vfs_inode, sai); - if (!sa_received_empty(sai)) + if (!list_empty(&sai->sai_entries_received)) goto interpret_it; if (unlikely( @@ -1194,12 +1179,12 @@ do_it: ll_release_page(page, 0); while (1) { l_wait_event(thread->t_ctl_waitq, - !sa_received_empty(sai) || + !list_empty(&sai->sai_entries_received) || sai->sai_sent == sai->sai_replied || !thread_is_running(thread), &lwi); - while (!sa_received_empty(sai)) + while (!list_empty(&sai->sai_entries_received)) ll_post_statahead(sai); if (unlikely(!thread_is_running(thread))) { @@ -1208,14 +1193,15 @@ do_it: } if (sai->sai_sent == sai->sai_replied && - sa_received_empty(sai)) + list_empty(&sai->sai_entries_received)) break; } spin_lock(&plli->lli_agl_lock); - while (!agl_list_empty(sai) && + while (!list_empty(&sai->sai_entries_agl) && thread_is_running(thread)) { - clli = agl_first_entry(sai); + clli = list_entry(sai->sai_entries_agl.next, + struct ll_inode_info, lli_agl_list); list_del_init(&clli->lli_agl_list); spin_unlock(&plli->lli_agl_lock); ll_agl_trigger(&clli->lli_vfs_inode, sai); @@ -1260,12 +1246,12 @@ out: } ll_dir_chain_fini(&chain); spin_lock(&plli->lli_sa_lock); - if (!sa_received_empty(sai)) { + if (!list_empty(&sai->sai_entries_received)) { thread_set_flags(thread, SVC_STOPPING); spin_unlock(&plli->lli_sa_lock); /* To release the resources held by received entries. */ - while (!sa_received_empty(sai)) + while (!list_empty(&sai->sai_entries_received)) ll_post_statahead(sai); spin_lock(&plli->lli_sa_lock); diff --git a/drivers/staging/lustre/lustre/llite/super25.c b/drivers/staging/lustre/lustre/llite/super25.c index 013136860664..7a9fafc67693 100644 --- a/drivers/staging/lustre/lustre/llite/super25.c +++ b/drivers/staging/lustre/lustre/llite/super25.c @@ -205,7 +205,7 @@ static void __exit exit_lustre_lite(void) kmem_cache_destroy(ll_file_data_slab); } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre Lite Client File System"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/lustre/lustre/llite/vvp_dev.c b/drivers/staging/lustre/lustre/llite/vvp_dev.c index d16d6cfce81a..fdca4ec0555d 100644 --- a/drivers/staging/lustre/lustre/llite/vvp_dev.c +++ b/drivers/staging/lustre/lustre/llite/vvp_dev.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/llite/vvp_internal.h b/drivers/staging/lustre/lustre/llite/vvp_internal.h index b5a6661d47d5..2e39533a45f8 100644 --- a/drivers/staging/lustre/lustre/llite/vvp_internal.h +++ b/drivers/staging/lustre/lustre/llite/vvp_internal.h @@ -26,6 +26,8 @@ /* * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2013, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/llite/vvp_io.c b/drivers/staging/lustre/lustre/llite/vvp_io.c index 37773c181729..f68e972886ca 100644 --- a/drivers/staging/lustre/lustre/llite/vvp_io.c +++ b/drivers/staging/lustre/lustre/llite/vvp_io.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -849,7 +849,7 @@ static int vvp_io_read_page(const struct lu_env *env, * Add page into the queue even when it is marked uptodate above. * this will unlock it automatically as part of cl_page_list_disown(). */ - cl_2queue_add(queue, page); + cl_page_list_add(&queue->c2_qin, page); if (sbi->ll_ra_info.ra_max_pages_per_file && sbi->ll_ra_info.ra_max_pages) ll_readahead(env, io, ras, diff --git a/drivers/staging/lustre/lustre/llite/vvp_lock.c b/drivers/staging/lustre/lustre/llite/vvp_lock.c index f7b1144aadee..ff0948043c7a 100644 --- a/drivers/staging/lustre/lustre/llite/vvp_lock.c +++ b/drivers/staging/lustre/lustre/llite/vvp_lock.c @@ -26,6 +26,8 @@ /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2014, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/llite/vvp_object.c b/drivers/staging/lustre/lustre/llite/vvp_object.c index e13afb7e8dca..c82714ea898e 100644 --- a/drivers/staging/lustre/lustre/llite/vvp_object.c +++ b/drivers/staging/lustre/lustre/llite/vvp_object.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/llite/vvp_page.c b/drivers/staging/lustre/lustre/llite/vvp_page.c index 92f60c350f35..99c0d7aee921 100644 --- a/drivers/staging/lustre/lustre/llite/vvp_page.c +++ b/drivers/staging/lustre/lustre/llite/vvp_page.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c index 660b8ac37ae0..8eb43f192d1f 100644 --- a/drivers/staging/lustre/lustre/llite/xattr.c +++ b/drivers/staging/lustre/lustre/llite/xattr.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -193,7 +193,10 @@ int ll_setxattr_common(struct inode *inode, const char *name, ll_i2suppgid(inode), &req); #ifdef CONFIG_FS_POSIX_ACL if (new_value != NULL) - lustre_posix_acl_xattr_free(new_value, size); + /* + * Release the posix ACL space. + */ + kfree(new_value); if (acl != NULL) lustre_ext_acl_xattr_free(acl); #endif diff --git a/drivers/staging/lustre/lustre/llite/xattr_cache.c b/drivers/staging/lustre/lustre/llite/xattr_cache.c index e1e599ceb173..d1402762a0b2 100644 --- a/drivers/staging/lustre/lustre/llite/xattr_cache.c +++ b/drivers/staging/lustre/lustre/llite/xattr_cache.c @@ -1,6 +1,8 @@ /* * Copyright 2012 Xyratex Technology Limited * + * Copyright (c) 2013, 2015, Intel Corporation. + * * Author: Andrew Perepechko <Andrew_Perepechko@xyratex.com> * */ diff --git a/drivers/staging/lustre/lustre/lmv/lmv_intent.c b/drivers/staging/lustre/lustre/lmv/lmv_intent.c index eebe45bdceb6..66de27f1d289 100644 --- a/drivers/staging/lustre/lustre/lmv/lmv_intent.c +++ b/drivers/staging/lustre/lustre/lmv/lmv_intent.c @@ -27,7 +27,7 @@ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -156,11 +156,11 @@ out: * IT_OPEN is intended to open (and create, possible) an object. Parent (pid) * may be split dir. */ -int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data, - void *lmm, int lmmsize, struct lookup_intent *it, - int flags, struct ptlrpc_request **reqp, - ldlm_blocking_callback cb_blocking, - __u64 extra_lock_flags) +static int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data, + void *lmm, int lmmsize, struct lookup_intent *it, + int flags, struct ptlrpc_request **reqp, + ldlm_blocking_callback cb_blocking, + __u64 extra_lock_flags) { struct obd_device *obd = exp->exp_obd; struct lmv_obd *lmv = &obd->u.lmv; @@ -239,11 +239,12 @@ int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data, /* * Handler for: getattr, lookup and revalidate cases. */ -int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data, - void *lmm, int lmmsize, struct lookup_intent *it, - int flags, struct ptlrpc_request **reqp, - ldlm_blocking_callback cb_blocking, - __u64 extra_lock_flags) +static int lmv_intent_lookup(struct obd_export *exp, + struct md_op_data *op_data, + void *lmm, int lmmsize, struct lookup_intent *it, + int flags, struct ptlrpc_request **reqp, + ldlm_blocking_callback cb_blocking, + __u64 extra_lock_flags) { struct obd_device *obd = exp->exp_obd; struct lmv_obd *lmv = &obd->u.lmv; diff --git a/drivers/staging/lustre/lustre/lmv/lmv_internal.h b/drivers/staging/lustre/lustre/lmv/lmv_internal.h index b808728daee7..eb8e673cbc3f 100644 --- a/drivers/staging/lustre/lustre/lmv/lmv_internal.h +++ b/drivers/staging/lustre/lustre/lmv/lmv_internal.h @@ -27,7 +27,7 @@ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -56,20 +56,6 @@ int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data, ldlm_blocking_callback cb_blocking, __u64 extra_lock_flags); -int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data, - void *lmm, int lmmsize, struct lookup_intent *it, - int flags, struct ptlrpc_request **reqp, - ldlm_blocking_callback cb_blocking, - __u64 extra_lock_flags); - -int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data, - void *lmm, int lmmsize, struct lookup_intent *it, - int flags, struct ptlrpc_request **reqp, - ldlm_blocking_callback cb_blocking, - __u64 extra_lock_flags); - -int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *, - void *, int); int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid, u32 *mds); int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds); int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid, diff --git a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/lustre/lustre/lmv/lmv_obd.c index 635a93cc94de..bbafe0a710d8 100644 --- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c +++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c @@ -27,7 +27,7 @@ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -2744,55 +2744,55 @@ static int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp, } static struct obd_ops lmv_obd_ops = { - .o_owner = THIS_MODULE, - .o_setup = lmv_setup, - .o_cleanup = lmv_cleanup, - .o_precleanup = lmv_precleanup, - .o_process_config = lmv_process_config, - .o_connect = lmv_connect, - .o_disconnect = lmv_disconnect, - .o_statfs = lmv_statfs, - .o_get_info = lmv_get_info, - .o_set_info_async = lmv_set_info_async, - .o_packmd = lmv_packmd, - .o_unpackmd = lmv_unpackmd, - .o_notify = lmv_notify, - .o_get_uuid = lmv_get_uuid, - .o_iocontrol = lmv_iocontrol, - .o_quotacheck = lmv_quotacheck, - .o_quotactl = lmv_quotactl + .owner = THIS_MODULE, + .setup = lmv_setup, + .cleanup = lmv_cleanup, + .precleanup = lmv_precleanup, + .process_config = lmv_process_config, + .connect = lmv_connect, + .disconnect = lmv_disconnect, + .statfs = lmv_statfs, + .get_info = lmv_get_info, + .set_info_async = lmv_set_info_async, + .packmd = lmv_packmd, + .unpackmd = lmv_unpackmd, + .notify = lmv_notify, + .get_uuid = lmv_get_uuid, + .iocontrol = lmv_iocontrol, + .quotacheck = lmv_quotacheck, + .quotactl = lmv_quotactl }; static struct md_ops lmv_md_ops = { - .m_getstatus = lmv_getstatus, - .m_null_inode = lmv_null_inode, - .m_find_cbdata = lmv_find_cbdata, - .m_close = lmv_close, - .m_create = lmv_create, - .m_done_writing = lmv_done_writing, - .m_enqueue = lmv_enqueue, - .m_getattr = lmv_getattr, - .m_getxattr = lmv_getxattr, - .m_getattr_name = lmv_getattr_name, - .m_intent_lock = lmv_intent_lock, - .m_link = lmv_link, - .m_rename = lmv_rename, - .m_setattr = lmv_setattr, - .m_setxattr = lmv_setxattr, - .m_sync = lmv_sync, - .m_readpage = lmv_readpage, - .m_unlink = lmv_unlink, - .m_init_ea_size = lmv_init_ea_size, - .m_cancel_unused = lmv_cancel_unused, - .m_set_lock_data = lmv_set_lock_data, - .m_lock_match = lmv_lock_match, - .m_get_lustre_md = lmv_get_lustre_md, - .m_free_lustre_md = lmv_free_lustre_md, - .m_set_open_replay_data = lmv_set_open_replay_data, - .m_clear_open_replay_data = lmv_clear_open_replay_data, - .m_get_remote_perm = lmv_get_remote_perm, - .m_intent_getattr_async = lmv_intent_getattr_async, - .m_revalidate_lock = lmv_revalidate_lock + .getstatus = lmv_getstatus, + .null_inode = lmv_null_inode, + .find_cbdata = lmv_find_cbdata, + .close = lmv_close, + .create = lmv_create, + .done_writing = lmv_done_writing, + .enqueue = lmv_enqueue, + .getattr = lmv_getattr, + .getxattr = lmv_getxattr, + .getattr_name = lmv_getattr_name, + .intent_lock = lmv_intent_lock, + .link = lmv_link, + .rename = lmv_rename, + .setattr = lmv_setattr, + .setxattr = lmv_setxattr, + .sync = lmv_sync, + .readpage = lmv_readpage, + .unlink = lmv_unlink, + .init_ea_size = lmv_init_ea_size, + .cancel_unused = lmv_cancel_unused, + .set_lock_data = lmv_set_lock_data, + .lock_match = lmv_lock_match, + .get_lustre_md = lmv_get_lustre_md, + .free_lustre_md = lmv_free_lustre_md, + .set_open_replay_data = lmv_set_open_replay_data, + .clear_open_replay_data = lmv_clear_open_replay_data, + .get_remote_perm = lmv_get_remote_perm, + .intent_getattr_async = lmv_intent_getattr_async, + .revalidate_lock = lmv_revalidate_lock }; static int __init lmv_init(void) @@ -2812,7 +2812,7 @@ static void lmv_exit(void) class_unregister_type(LUSTRE_LMV_NAME); } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/lustre/lustre/lov/lov_cl_internal.h b/drivers/staging/lustre/lustre/lov/lov_cl_internal.h index 1c0fe65243e1..66a2492c1cc3 100644 --- a/drivers/staging/lustre/lustre/lov/lov_cl_internal.h +++ b/drivers/staging/lustre/lustre/lov/lov_cl_internal.h @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015 Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/lov/lov_dev.c b/drivers/staging/lustre/lustre/lov/lov_dev.c index 2e8b566458f6..3733fdc88c8c 100644 --- a/drivers/staging/lustre/lustre/lov/lov_dev.c +++ b/drivers/staging/lustre/lustre/lov/lov_dev.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/lov/lov_ea.c b/drivers/staging/lustre/lustre/lov/lov_ea.c index 34c1346f0dc7..b3c9c85aab9d 100644 --- a/drivers/staging/lustre/lustre/lov/lov_ea.c +++ b/drivers/staging/lustre/lustre/lov/lov_ea.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/lov/lov_internal.h b/drivers/staging/lustre/lustre/lov/lov_internal.h index 515a5c147827..2d00bad58e35 100644 --- a/drivers/staging/lustre/lustre/lov/lov_internal.h +++ b/drivers/staging/lustre/lustre/lov/lov_internal.h @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -151,23 +151,10 @@ int lov_stripe_number(struct lov_stripe_md *lsm, u64 lov_off); /* lov_qos.c */ #define LOV_USES_ASSIGNED_STRIPE 0 #define LOV_USES_DEFAULT_STRIPE 1 -int qos_add_tgt(struct obd_device *obd, __u32 index); -int qos_del_tgt(struct obd_device *obd, struct lov_tgt_desc *tgt); -void qos_shrink_lsm(struct lov_request_set *set); -int qos_prep_create(struct obd_export *exp, struct lov_request_set *set); -void qos_update(struct lov_obd *lov); -void qos_statfs_done(struct lov_obd *lov); -void qos_statfs_update(struct obd_device *obd, __u64 max_age, int wait); -int qos_remedy_create(struct lov_request_set *set, struct lov_request *req); /* lov_request.c */ -void lov_set_add_req(struct lov_request *req, struct lov_request_set *set); -int lov_set_finished(struct lov_request_set *set, int idempotent); -void lov_update_set(struct lov_request_set *set, - struct lov_request *req, int rc); int lov_update_common_set(struct lov_request_set *set, struct lov_request *req, int rc); -int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx); int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo, struct lov_request_set **reqset); int lov_fini_getattr_set(struct lov_request_set *set); @@ -184,8 +171,6 @@ int lov_update_setattr_set(struct lov_request_set *set, int lov_fini_setattr_set(struct lov_request_set *set); int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo, struct lov_request_set **reqset); -void lov_update_statfs(struct obd_statfs *osfs, struct obd_statfs *lov_sfs, - int success); int lov_fini_statfs(struct obd_device *obd, struct obd_statfs *osfs, int success); int lov_fini_statfs_set(struct lov_request_set *set); diff --git a/drivers/staging/lustre/lustre/lov/lov_io.c b/drivers/staging/lustre/lustre/lov/lov_io.c index 5e6228b9ca01..93fe69eb2560 100644 --- a/drivers/staging/lustre/lustre/lov/lov_io.c +++ b/drivers/staging/lustre/lustre/lov/lov_io.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/lov/lov_merge.c b/drivers/staging/lustre/lustre/lov/lov_merge.c index dd1cf3d2d039..97115bec7cca 100644 --- a/drivers/staging/lustre/lustre/lov/lov_merge.c +++ b/drivers/staging/lustre/lustre/lov/lov_merge.c @@ -27,7 +27,7 @@ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c index 7abe484c07c0..6c2bdfe9cdcf 100644 --- a/drivers/staging/lustre/lustre/lov/lov_obd.c +++ b/drivers/staging/lustre/lustre/lov/lov_obd.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -2277,35 +2277,35 @@ out: } static struct obd_ops lov_obd_ops = { - .o_owner = THIS_MODULE, - .o_setup = lov_setup, - .o_precleanup = lov_precleanup, - .o_cleanup = lov_cleanup, - /*.o_process_config = lov_process_config,*/ - .o_connect = lov_connect, - .o_disconnect = lov_disconnect, - .o_statfs = lov_statfs, - .o_statfs_async = lov_statfs_async, - .o_packmd = lov_packmd, - .o_unpackmd = lov_unpackmd, - .o_create = lov_create, - .o_destroy = lov_destroy, - .o_getattr_async = lov_getattr_async, - .o_setattr_async = lov_setattr_async, - .o_adjust_kms = lov_adjust_kms, - .o_find_cbdata = lov_find_cbdata, - .o_iocontrol = lov_iocontrol, - .o_get_info = lov_get_info, - .o_set_info_async = lov_set_info_async, - .o_notify = lov_notify, - .o_pool_new = lov_pool_new, - .o_pool_rem = lov_pool_remove, - .o_pool_add = lov_pool_add, - .o_pool_del = lov_pool_del, - .o_getref = lov_getref, - .o_putref = lov_putref, - .o_quotactl = lov_quotactl, - .o_quotacheck = lov_quotacheck, + .owner = THIS_MODULE, + .setup = lov_setup, + .precleanup = lov_precleanup, + .cleanup = lov_cleanup, + /*.process_config = lov_process_config,*/ + .connect = lov_connect, + .disconnect = lov_disconnect, + .statfs = lov_statfs, + .statfs_async = lov_statfs_async, + .packmd = lov_packmd, + .unpackmd = lov_unpackmd, + .create = lov_create, + .destroy = lov_destroy, + .getattr_async = lov_getattr_async, + .setattr_async = lov_setattr_async, + .adjust_kms = lov_adjust_kms, + .find_cbdata = lov_find_cbdata, + .iocontrol = lov_iocontrol, + .get_info = lov_get_info, + .set_info_async = lov_set_info_async, + .notify = lov_notify, + .pool_new = lov_pool_new, + .pool_rem = lov_pool_remove, + .pool_add = lov_pool_add, + .pool_del = lov_pool_del, + .getref = lov_getref, + .putref = lov_putref, + .quotactl = lov_quotactl, + .quotacheck = lov_quotacheck, }; struct kmem_cache *lov_oinfo_slab; @@ -2352,7 +2352,7 @@ static void /*__exit*/ lov_exit(void) lu_kmem_fini(lov_caches); } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver"); MODULE_LICENSE("GPL"); MODULE_VERSION(LUSTRE_VERSION_STRING); diff --git a/drivers/staging/lustre/lustre/lov/lov_object.c b/drivers/staging/lustre/lustre/lov/lov_object.c index c7ff817bb6fb..3b79ebc8eccf 100644 --- a/drivers/staging/lustre/lustre/lov/lov_object.c +++ b/drivers/staging/lustre/lustre/lov/lov_object.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/lov/lov_offset.c b/drivers/staging/lustre/lustre/lov/lov_offset.c index 9c8c77c05a8a..aa520aa76e09 100644 --- a/drivers/staging/lustre/lustre/lov/lov_offset.c +++ b/drivers/staging/lustre/lustre/lov/lov_offset.c @@ -27,7 +27,7 @@ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/lov/lov_pack.c b/drivers/staging/lustre/lustre/lov/lov_pack.c index 2fb1e974cc70..6b2d1007192b 100644 --- a/drivers/staging/lustre/lustre/lov/lov_pack.c +++ b/drivers/staging/lustre/lustre/lov/lov_pack.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -258,22 +258,9 @@ static int lov_verify_lmm(void *lmm, int lmm_bytes, __u16 *stripe_count) int rc; if (lsm_op_find(le32_to_cpu(*(__u32 *)lmm)) == NULL) { - char *buffer; - int sz; - CERROR("bad disk LOV MAGIC: 0x%08X; dumping LMM (size=%d):\n", le32_to_cpu(*(__u32 *)lmm), lmm_bytes); - sz = lmm_bytes * 2 + 1; - buffer = libcfs_kvzalloc(sz, GFP_NOFS); - if (buffer != NULL) { - int i; - - for (i = 0; i < lmm_bytes; i++) - sprintf(buffer+2*i, "%.2X", ((char *)lmm)[i]); - buffer[sz - 1] = '\0'; - CERROR("%s\n", buffer); - kvfree(buffer); - } + CERROR("%*phN\n", lmm_bytes, lmm); return -EINVAL; } rc = lsm_op_find(le32_to_cpu(*(__u32 *)lmm))->lsm_lmm_verify(lmm, diff --git a/drivers/staging/lustre/lustre/lov/lov_page.c b/drivers/staging/lustre/lustre/lov/lov_page.c index 463cadbd9d40..037ae91b74e7 100644 --- a/drivers/staging/lustre/lustre/lov/lov_page.c +++ b/drivers/staging/lustre/lustre/lov/lov_page.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/lov/lov_pool.c b/drivers/staging/lustre/lustre/lov/lov_pool.c index b03827ef6514..b43ce6cd64c2 100644 --- a/drivers/staging/lustre/lustre/lov/lov_pool.c +++ b/drivers/staging/lustre/lustre/lov/lov_pool.c @@ -412,8 +412,7 @@ int lov_pool_new(struct obd_device *obd, char *poolname) if (!new_pool) return -ENOMEM; - strncpy(new_pool->pool_name, poolname, LOV_MAXPOOLNAME); - new_pool->pool_name[LOV_MAXPOOLNAME] = '\0'; + strlcpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name)); new_pool->pool_lobd = obd; /* ref count init to 1 because when created a pool is always used * up to deletion diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c index 1a150c26798d..42deda71f577 100644 --- a/drivers/staging/lustre/lustre/lov/lov_request.c +++ b/drivers/staging/lustre/lustre/lov/lov_request.c @@ -27,7 +27,7 @@ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -74,7 +74,7 @@ void lov_finish_set(struct lov_request_set *set) kfree(set); } -int lov_set_finished(struct lov_request_set *set, int idempotent) +static int lov_set_finished(struct lov_request_set *set, int idempotent) { int completes = atomic_read(&set->set_completes); @@ -89,8 +89,8 @@ int lov_set_finished(struct lov_request_set *set, int idempotent) return 0; } -void lov_update_set(struct lov_request_set *set, - struct lov_request *req, int rc) +static void lov_update_set(struct lov_request_set *set, + struct lov_request *req, int rc) { req->rq_complete = 1; req->rq_rc = rc; @@ -118,7 +118,8 @@ int lov_update_common_set(struct lov_request_set *set, return rc; } -void lov_set_add_req(struct lov_request *req, struct lov_request_set *set) +static void lov_set_add_req(struct lov_request *req, + struct lov_request_set *set) { list_add_tail(&req->rq_link, &set->set_list); set->set_count++; @@ -144,7 +145,7 @@ static int lov_check_set(struct lov_obd *lov, int idx) * If the OSC has not yet had a chance to connect to the OST the first time, * wait once for it to connect instead of returning an error. */ -int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx) +static int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx) { wait_queue_head_t waitq; struct l_wait_info lwi; @@ -591,8 +592,9 @@ int lov_fini_statfs_set(struct lov_request_set *set) return rc; } -void lov_update_statfs(struct obd_statfs *osfs, struct obd_statfs *lov_sfs, - int success) +static void lov_update_statfs(struct obd_statfs *osfs, + struct obd_statfs *lov_sfs, + int success) { int shift = 0, quit = 0; __u64 tmp; diff --git a/drivers/staging/lustre/lustre/lov/lovsub_dev.c b/drivers/staging/lustre/lustre/lov/lovsub_dev.c index 8bc04c8d3d60..f1795c3e2db5 100644 --- a/drivers/staging/lustre/lustre/lov/lovsub_dev.c +++ b/drivers/staging/lustre/lustre/lov/lovsub_dev.c @@ -26,6 +26,8 @@ /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2013, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/lov/lovsub_object.c b/drivers/staging/lustre/lustre/lov/lovsub_object.c index d775e28d4097..5ba5ee1b8681 100644 --- a/drivers/staging/lustre/lustre/lov/lovsub_object.c +++ b/drivers/staging/lustre/lustre/lov/lovsub_object.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015 Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/lov/lproc_lov.c b/drivers/staging/lustre/lustre/lov/lproc_lov.c index a0be15c6b55a..337241d84980 100644 --- a/drivers/staging/lustre/lustre/lov/lproc_lov.c +++ b/drivers/staging/lustre/lustre/lov/lproc_lov.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015 Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/mdc/lproc_mdc.c b/drivers/staging/lustre/lustre/mdc/lproc_mdc.c index 1c95f87a0e2a..38f267a60f59 100644 --- a/drivers/staging/lustre/lustre/mdc/lproc_mdc.c +++ b/drivers/staging/lustre/lustre/mdc/lproc_mdc.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -82,82 +82,6 @@ static ssize_t max_rpcs_in_flight_store(struct kobject *kobj, } LUSTRE_RW_ATTR(max_rpcs_in_flight); -static int mdc_kuc_open(struct inode *inode, struct file *file) -{ - return single_open(file, NULL, inode->i_private); -} - -/* temporary for testing */ -static ssize_t mdc_kuc_write(struct file *file, - const char __user *buffer, - size_t count, loff_t *off) -{ - struct obd_device *obd = - ((struct seq_file *)file->private_data)->private; - struct kuc_hdr *lh; - struct hsm_action_list *hal; - struct hsm_action_item *hai; - int len; - int fd, rc; - - rc = lprocfs_write_helper(buffer, count, &fd); - if (rc) - return rc; - - if (fd < 0) - return -ERANGE; - CWARN("message to fd %d\n", fd); - - len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN + - /* for mockup below */ 2 * cfs_size_round(sizeof(*hai)); - - lh = kzalloc(len, GFP_NOFS); - if (!lh) - return -ENOMEM; - - lh->kuc_magic = KUC_MAGIC; - lh->kuc_transport = KUC_TRANSPORT_HSM; - lh->kuc_msgtype = HMT_ACTION_LIST; - lh->kuc_msglen = len; - - hal = (struct hsm_action_list *)(lh + 1); - hal->hal_version = HAL_VERSION; - hal->hal_archive_id = 1; - hal->hal_flags = 0; - obd_uuid2fsname(hal->hal_fsname, obd->obd_name, MTI_NAME_MAXLEN); - - /* mock up an action list */ - hal->hal_count = 2; - hai = hai_zero(hal); - hai->hai_action = HSMA_ARCHIVE; - hai->hai_fid.f_oid = 5; - hai->hai_len = sizeof(*hai); - hai = hai_next(hai); - hai->hai_action = HSMA_RESTORE; - hai->hai_fid.f_oid = 10; - hai->hai_len = sizeof(*hai); - - /* This works for either broadcast or unicast to a single fd */ - if (fd == 0) { - rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh); - } else { - struct file *fp = fget(fd); - - rc = libcfs_kkuc_msg_put(fp, lh); - fput(fp); - } - kfree(lh); - if (rc < 0) - return rc; - return count; -} - -static struct file_operations mdc_kuc_fops = { - .open = mdc_kuc_open, - .write = mdc_kuc_write, - .release = single_release, -}; - LPROC_SEQ_FOPS_WR_ONLY(mdc, ping); LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags); @@ -196,7 +120,6 @@ static struct lprocfs_vars lprocfs_mdc_obd_vars[] = { { "timeouts", &mdc_timeouts_fops, NULL, 0 }, { "import", &mdc_import_fops, NULL, 0 }, { "state", &mdc_state_fops, NULL, 0 }, - { "hsm_nl", &mdc_kuc_fops, NULL, 0200 }, { "pinger_recov", &mdc_pinger_recov_fops, NULL, 0 }, { NULL } }; diff --git a/drivers/staging/lustre/lustre/mdc/mdc_internal.h b/drivers/staging/lustre/lustre/mdc/mdc_internal.h index 29b46f754726..3d2997a161b6 100644 --- a/drivers/staging/lustre/lustre/mdc/mdc_internal.h +++ b/drivers/staging/lustre/lustre/mdc/mdc_internal.h @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, Intel Corporation. + * Copyright (c) 2011, 2015 Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -44,7 +44,6 @@ void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars); void mdc_pack_body(struct ptlrpc_request *req, const struct lu_fid *fid, __u64 valid, int ea_size, __u32 suppgid, int flags); -int mdc_pack_req(struct ptlrpc_request *req, int version, int opc); void mdc_is_subdir_pack(struct ptlrpc_request *req, const struct lu_fid *pfid, const struct lu_fid *cfid, int flags); void mdc_swap_layouts_pack(struct ptlrpc_request *req, @@ -62,7 +61,6 @@ void mdc_open_pack(struct ptlrpc_request *req, struct md_op_data *op_data, __u32 mode, __u64 rdev, __u64 flags, const void *data, int datalen); void mdc_unlink_pack(struct ptlrpc_request *req, struct md_op_data *op_data); -void mdc_getxattr_pack(struct ptlrpc_request *req, struct md_op_data *op_data); void mdc_link_pack(struct ptlrpc_request *req, struct md_op_data *op_data); void mdc_rename_pack(struct ptlrpc_request *req, struct md_op_data *op_data, const char *old, int oldlen, const char *new, int newlen); @@ -97,25 +95,12 @@ int mdc_resource_get_unused(struct obd_export *exp, const struct lu_fid *fid, /* mdc/mdc_request.c */ int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid, struct md_op_data *op_data); - -int mdc_open(struct obd_export *exp, u64 ino, int type, int flags, - struct lov_mds_md *lmm, int lmm_size, struct lustre_handle *fh, - struct ptlrpc_request **); - struct obd_client_handle; -int mdc_get_lustre_md(struct obd_export *md_exp, struct ptlrpc_request *req, - struct obd_export *dt_exp, struct obd_export *lmv_exp, - struct lustre_md *md); - -int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md); - int mdc_set_open_replay_data(struct obd_export *exp, struct obd_client_handle *och, struct lookup_intent *it); -int mdc_clear_open_replay_data(struct obd_export *exp, - struct obd_client_handle *och); void mdc_commit_open(struct ptlrpc_request *req); void mdc_replay_open(struct ptlrpc_request *req); diff --git a/drivers/staging/lustre/lustre/mdc/mdc_lib.c b/drivers/staging/lustre/lustre/mdc/mdc_lib.c index 227fc9ee0dcf..7218532ffea3 100644 --- a/drivers/staging/lustre/lustre/mdc/mdc_lib.c +++ b/drivers/staging/lustre/lustre/mdc/mdc_lib.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/mdc/mdc_locks.c b/drivers/staging/lustre/lustre/mdc/mdc_locks.c index d4bf34b61f3a..ef9a1e124ea4 100644 --- a/drivers/staging/lustre/lustre/mdc/mdc_locks.c +++ b/drivers/staging/lustre/lustre/mdc/mdc_locks.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/mdc/mdc_reint.c b/drivers/staging/lustre/lustre/mdc/mdc_reint.c index c87c7d8efa07..ac7695a10753 100644 --- a/drivers/staging/lustre/lustre/mdc/mdc_reint.c +++ b/drivers/staging/lustre/lustre/mdc/mdc_reint.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c index 16a5a10d371e..57e0fc1e8549 100644 --- a/drivers/staging/lustre/lustre/mdc/mdc_request.c +++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c @@ -27,7 +27,7 @@ * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -447,9 +447,11 @@ static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md) #define mdc_unpack_acl(req, md) 0 #endif -int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req, - struct obd_export *dt_exp, struct obd_export *md_exp, - struct lustre_md *md) +static int mdc_get_lustre_md(struct obd_export *exp, + struct ptlrpc_request *req, + struct obd_export *dt_exp, + struct obd_export *md_exp, + struct lustre_md *md) { struct req_capsule *pill = &req->rq_pill; int rc; @@ -573,7 +575,7 @@ out: return rc; } -int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md) +static int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md) { return 0; } @@ -737,8 +739,8 @@ static void mdc_free_open(struct md_open_data *mod) ptlrpc_request_committed(mod->mod_close_req, committed); } -int mdc_clear_open_replay_data(struct obd_export *exp, - struct obd_client_handle *och) +static int mdc_clear_open_replay_data(struct obd_export *exp, + struct obd_client_handle *och) { struct md_open_data *mod = och->och_mod; @@ -1179,7 +1181,6 @@ static int mdc_ioc_hsm_progress(struct obd_export *exp, ptlrpc_request_set_replen(req); rc = mdc_queue_wait(req); - goto out; out: ptlrpc_req_finished(req); return rc; @@ -1214,7 +1215,6 @@ static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives) ptlrpc_request_set_replen(req); rc = mdc_queue_wait(req); - goto out; out: ptlrpc_req_finished(req); return rc; @@ -1280,7 +1280,6 @@ static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp) ptlrpc_request_set_replen(req); rc = mdc_queue_wait(req); - goto out; out: ptlrpc_req_finished(req); return rc; @@ -1360,8 +1359,6 @@ static int mdc_ioc_hsm_state_set(struct obd_export *exp, ptlrpc_request_set_replen(req); rc = mdc_queue_wait(req); - goto out; - out: ptlrpc_req_finished(req); return rc; @@ -1425,8 +1422,6 @@ static int mdc_ioc_hsm_request(struct obd_export *exp, ptlrpc_request_set_replen(req); rc = mdc_queue_wait(req); - goto out; - out: ptlrpc_req_finished(req); return rc; @@ -2035,17 +2030,6 @@ static int mdc_hsm_ct_reregister(__u32 data, void *cb_arg) return ((rc != 0) && (rc != -EEXIST)) ? rc : 0; } -/** - * Re-establish all kuc contexts with MDT - * after MDT shutdown/recovery. - */ -static int mdc_kuc_reregister(struct obd_import *imp) -{ - /* re-register HSM agents */ - return libcfs_kkuc_group_foreach(KUC_GRP_HSM, mdc_hsm_ct_reregister, - (void *)imp); -} - static int mdc_set_info_async(const struct lu_env *env, struct obd_export *exp, u32 keylen, void *key, @@ -2208,7 +2192,10 @@ static int mdc_import_event(struct obd_device *obd, struct obd_import *imp, rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL); /* redo the kuc registration after reconnecting */ if (rc == 0) - rc = mdc_kuc_reregister(imp); + /* re-register HSM agents */ + rc = libcfs_kkuc_group_foreach(KUC_GRP_HSM, + mdc_hsm_ct_reregister, + (void *)imp); break; case IMP_EVENT_OCD: rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL); @@ -2460,59 +2447,59 @@ static int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid, } static struct obd_ops mdc_obd_ops = { - .o_owner = THIS_MODULE, - .o_setup = mdc_setup, - .o_precleanup = mdc_precleanup, - .o_cleanup = mdc_cleanup, - .o_add_conn = client_import_add_conn, - .o_del_conn = client_import_del_conn, - .o_connect = client_connect_import, - .o_disconnect = client_disconnect_export, - .o_iocontrol = mdc_iocontrol, - .o_set_info_async = mdc_set_info_async, - .o_statfs = mdc_statfs, - .o_fid_init = client_fid_init, - .o_fid_fini = client_fid_fini, - .o_fid_alloc = mdc_fid_alloc, - .o_import_event = mdc_import_event, - .o_get_info = mdc_get_info, - .o_process_config = mdc_process_config, - .o_get_uuid = mdc_get_uuid, - .o_quotactl = mdc_quotactl, - .o_quotacheck = mdc_quotacheck + .owner = THIS_MODULE, + .setup = mdc_setup, + .precleanup = mdc_precleanup, + .cleanup = mdc_cleanup, + .add_conn = client_import_add_conn, + .del_conn = client_import_del_conn, + .connect = client_connect_import, + .disconnect = client_disconnect_export, + .iocontrol = mdc_iocontrol, + .set_info_async = mdc_set_info_async, + .statfs = mdc_statfs, + .fid_init = client_fid_init, + .fid_fini = client_fid_fini, + .fid_alloc = mdc_fid_alloc, + .import_event = mdc_import_event, + .get_info = mdc_get_info, + .process_config = mdc_process_config, + .get_uuid = mdc_get_uuid, + .quotactl = mdc_quotactl, + .quotacheck = mdc_quotacheck }; static struct md_ops mdc_md_ops = { - .m_getstatus = mdc_getstatus, - .m_null_inode = mdc_null_inode, - .m_find_cbdata = mdc_find_cbdata, - .m_close = mdc_close, - .m_create = mdc_create, - .m_done_writing = mdc_done_writing, - .m_enqueue = mdc_enqueue, - .m_getattr = mdc_getattr, - .m_getattr_name = mdc_getattr_name, - .m_intent_lock = mdc_intent_lock, - .m_link = mdc_link, - .m_is_subdir = mdc_is_subdir, - .m_rename = mdc_rename, - .m_setattr = mdc_setattr, - .m_setxattr = mdc_setxattr, - .m_getxattr = mdc_getxattr, - .m_sync = mdc_sync, - .m_readpage = mdc_readpage, - .m_unlink = mdc_unlink, - .m_cancel_unused = mdc_cancel_unused, - .m_init_ea_size = mdc_init_ea_size, - .m_set_lock_data = mdc_set_lock_data, - .m_lock_match = mdc_lock_match, - .m_get_lustre_md = mdc_get_lustre_md, - .m_free_lustre_md = mdc_free_lustre_md, - .m_set_open_replay_data = mdc_set_open_replay_data, - .m_clear_open_replay_data = mdc_clear_open_replay_data, - .m_get_remote_perm = mdc_get_remote_perm, - .m_intent_getattr_async = mdc_intent_getattr_async, - .m_revalidate_lock = mdc_revalidate_lock + .getstatus = mdc_getstatus, + .null_inode = mdc_null_inode, + .find_cbdata = mdc_find_cbdata, + .close = mdc_close, + .create = mdc_create, + .done_writing = mdc_done_writing, + .enqueue = mdc_enqueue, + .getattr = mdc_getattr, + .getattr_name = mdc_getattr_name, + .intent_lock = mdc_intent_lock, + .link = mdc_link, + .is_subdir = mdc_is_subdir, + .rename = mdc_rename, + .setattr = mdc_setattr, + .setxattr = mdc_setxattr, + .getxattr = mdc_getxattr, + .sync = mdc_sync, + .readpage = mdc_readpage, + .unlink = mdc_unlink, + .cancel_unused = mdc_cancel_unused, + .init_ea_size = mdc_init_ea_size, + .set_lock_data = mdc_set_lock_data, + .lock_match = mdc_lock_match, + .get_lustre_md = mdc_get_lustre_md, + .free_lustre_md = mdc_free_lustre_md, + .set_open_replay_data = mdc_set_open_replay_data, + .clear_open_replay_data = mdc_clear_open_replay_data, + .get_remote_perm = mdc_get_remote_perm, + .intent_getattr_async = mdc_intent_getattr_async, + .revalidate_lock = mdc_revalidate_lock }; static int __init mdc_init(void) @@ -2530,7 +2517,7 @@ static void /*__exit*/ mdc_exit(void) class_unregister_type(LUSTRE_MDC_NAME); } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre Metadata Client"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c index 5f53f3b7ceff..ab4800c20a95 100644 --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -463,7 +463,7 @@ int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data) } spin_unlock(&config_list_lock); - LPROCFS_CLIMP_EXIT(obd); + up_read(&obd->u.cli.cl_sem); return 0; } @@ -1293,7 +1293,7 @@ static int mgc_process_recover_log(struct obd_device *obd, struct page **pages; int nrpages; bool eof = true; - bool mne_swab = false; + bool mne_swab; int i; int ealen; int rc; @@ -1698,20 +1698,20 @@ out: } static struct obd_ops mgc_obd_ops = { - .o_owner = THIS_MODULE, - .o_setup = mgc_setup, - .o_precleanup = mgc_precleanup, - .o_cleanup = mgc_cleanup, - .o_add_conn = client_import_add_conn, - .o_del_conn = client_import_del_conn, - .o_connect = client_connect_import, - .o_disconnect = client_disconnect_export, - /* .o_enqueue = mgc_enqueue, */ - /* .o_iocontrol = mgc_iocontrol, */ - .o_set_info_async = mgc_set_info_async, - .o_get_info = mgc_get_info, - .o_import_event = mgc_import_event, - .o_process_config = mgc_process_config, + .owner = THIS_MODULE, + .setup = mgc_setup, + .precleanup = mgc_precleanup, + .cleanup = mgc_cleanup, + .add_conn = client_import_add_conn, + .del_conn = client_import_del_conn, + .connect = client_connect_import, + .disconnect = client_disconnect_export, + /* .enqueue = mgc_enqueue, */ + /* .iocontrol = mgc_iocontrol, */ + .set_info_async = mgc_set_info_async, + .get_info = mgc_get_info, + .import_event = mgc_import_event, + .process_config = mgc_process_config, }; static int __init mgc_init(void) @@ -1725,7 +1725,7 @@ static void /*__exit*/ mgc_exit(void) class_unregister_type(LUSTRE_MGC_NAME); } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre Management Client"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/lustre/lustre/obdclass/acl.c b/drivers/staging/lustre/lustre/obdclass/acl.c index 2e20cf635b27..49ba8851c8ac 100644 --- a/drivers/staging/lustre/lustre/obdclass/acl.c +++ b/drivers/staging/lustre/lustre/obdclass/acl.c @@ -236,15 +236,6 @@ _out: EXPORT_SYMBOL(lustre_posix_acl_xattr_filter); /* - * Release the posix ACL space. - */ -void lustre_posix_acl_xattr_free(posix_acl_xattr_header *header, int size) -{ - kfree(header); -} -EXPORT_SYMBOL(lustre_posix_acl_xattr_free); - -/* * Release the extended ACL space. */ void lustre_ext_acl_xattr_free(ext_acl_xattr_header *header) diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c index e67cea758405..63246ba36798 100644 --- a/drivers/staging/lustre/lustre/obdclass/cl_io.c +++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -236,16 +236,11 @@ int cl_io_rw_init(const struct lu_env *env, struct cl_io *io, } EXPORT_SYMBOL(cl_io_rw_init); -static inline const struct lu_fid * -cl_lock_descr_fid(const struct cl_lock_descr *descr) -{ - return lu_object_fid(&descr->cld_obj->co_lu); -} - static int cl_lock_descr_sort(const struct cl_lock_descr *d0, const struct cl_lock_descr *d1) { - return lu_fid_cmp(cl_lock_descr_fid(d0), cl_lock_descr_fid(d1)) ?: + return lu_fid_cmp(lu_object_fid(&d0->cld_obj->co_lu), + lu_object_fid(&d1->cld_obj->co_lu)) ?: __diff_normalize(d0->cld_start, d1->cld_start); } @@ -254,7 +249,8 @@ static int cl_lock_descr_cmp(const struct cl_lock_descr *d0, { int ret; - ret = lu_fid_cmp(cl_lock_descr_fid(d0), cl_lock_descr_fid(d1)); + ret = lu_fid_cmp(lu_object_fid(&d0->cld_obj->co_lu), + lu_object_fid(&d1->cld_obj->co_lu)); if (ret) return ret; if (d0->cld_end < d1->cld_start) @@ -1216,15 +1212,6 @@ void cl_2queue_init(struct cl_2queue *queue) EXPORT_SYMBOL(cl_2queue_init); /** - * Add a page to the incoming page list of 2-queue. - */ -void cl_2queue_add(struct cl_2queue *queue, struct cl_page *page) -{ - cl_page_list_add(&queue->c2_qin, page); -} -EXPORT_SYMBOL(cl_2queue_add); - -/** * Disown pages in both lists of a 2-queue. */ void cl_2queue_disown(const struct lu_env *env, @@ -1262,7 +1249,10 @@ EXPORT_SYMBOL(cl_2queue_fini); void cl_2queue_init_page(struct cl_2queue *queue, struct cl_page *page) { cl_2queue_init(queue); - cl_2queue_add(queue, page); + /* + * Add a page to the incoming page list of 2-queue. + */ + cl_page_list_add(&queue->c2_qin, page); } EXPORT_SYMBOL(cl_2queue_init_page); diff --git a/drivers/staging/lustre/lustre/obdclass/cl_lock.c b/drivers/staging/lustre/lustre/obdclass/cl_lock.c index 5621bebf33a9..1836dc01499a 100644 --- a/drivers/staging/lustre/lustre/obdclass/cl_lock.c +++ b/drivers/staging/lustre/lustre/obdclass/cl_lock.c @@ -687,7 +687,7 @@ EXPORT_SYMBOL(cl_lock_mutex_get); * * \see cl_lock_mutex_get() */ -int cl_lock_mutex_try(const struct lu_env *env, struct cl_lock *lock) +static int cl_lock_mutex_try(const struct lu_env *env, struct cl_lock *lock) { int result; @@ -705,7 +705,6 @@ int cl_lock_mutex_try(const struct lu_env *env, struct cl_lock *lock) result = -EBUSY; return result; } -EXPORT_SYMBOL(cl_lock_mutex_try); /** {* Unlocks cl_lock object. diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c index a1a6024220ff..57c8d5412bbd 100644 --- a/drivers/staging/lustre/lustre/obdclass/cl_object.c +++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -704,7 +704,7 @@ static inline struct cl_env *cl_env_container(struct lu_env *env) return container_of(env, struct cl_env, ce_lu); } -struct lu_env *cl_env_peek(int *refcheck) +static struct lu_env *cl_env_peek(int *refcheck) { struct lu_env *env; struct cl_env *cle; @@ -724,7 +724,6 @@ struct lu_env *cl_env_peek(int *refcheck) CDEBUG(D_OTHER, "%d@%p\n", cle ? cle->ce_ref : 0, cle); return env; } -EXPORT_SYMBOL(cl_env_peek); /** * Returns lu_env: if there already is an environment associated with the diff --git a/drivers/staging/lustre/lustre/obdclass/cl_page.c b/drivers/staging/lustre/lustre/obdclass/cl_page.c index 2f569edd0811..61f28ebfc058 100644 --- a/drivers/staging/lustre/lustre/obdclass/cl_page.c +++ b/drivers/staging/lustre/lustre/obdclass/cl_page.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/obdclass/class_obd.c b/drivers/staging/lustre/lustre/obdclass/class_obd.c index 3e9c24684690..0975e443057c 100644 --- a/drivers/staging/lustre/lustre/obdclass/class_obd.c +++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c @@ -27,7 +27,7 @@ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -576,7 +576,7 @@ static void cleanup_obdclass(void) obd_zombie_impexp_stop(); } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre Class Driver Build Version: " BUILD_VERSION); MODULE_LICENSE("GPL"); MODULE_VERSION(LUSTRE_VERSION_STRING); diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c index 6477aeb88028..228c44c37c4a 100644 --- a/drivers/staging/lustre/lustre/obdclass/genops.c +++ b/drivers/staging/lustre/lustre/obdclass/genops.c @@ -27,7 +27,7 @@ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -132,7 +132,7 @@ static struct obd_type *class_get_type(const char *name) if (type) { spin_lock(&type->obd_type_lock); type->typ_refcnt++; - try_module_get(type->typ_dt_ops->o_owner); + try_module_get(type->typ_dt_ops->owner); spin_unlock(&type->obd_type_lock); } return type; @@ -143,7 +143,7 @@ void class_put_type(struct obd_type *type) LASSERT(type); spin_lock(&type->obd_type_lock); type->typ_refcnt--; - module_put(type->typ_dt_ops->o_owner); + module_put(type->typ_dt_ops->owner); spin_unlock(&type->obd_type_lock); } EXPORT_SYMBOL(class_put_type); @@ -155,7 +155,7 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, struct lu_device_type *ldt) { struct obd_type *type; - int rc = 0; + int rc; /* sanity check */ LASSERT(strnlen(name, CLASS_MAX_NAME) < CLASS_MAX_NAME); diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c index 518288df4d53..42fc26f4ae25 100644 --- a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c +++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c @@ -27,7 +27,7 @@ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/obdclass/llog.c b/drivers/staging/lustre/lustre/obdclass/llog.c index 7cb55ef79737..f956d7ed6785 100644 --- a/drivers/staging/lustre/lustre/obdclass/llog.c +++ b/drivers/staging/lustre/lustre/obdclass/llog.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/obdclass/llog_cat.c b/drivers/staging/lustre/lustre/obdclass/llog_cat.c index c442cae5fd37..0f05e9c4a5b2 100644 --- a/drivers/staging/lustre/lustre/obdclass/llog_cat.c +++ b/drivers/staging/lustre/lustre/obdclass/llog_cat.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/obdclass/llog_internal.h b/drivers/staging/lustre/lustre/obdclass/llog_internal.h index b9fe4b01c690..7fb48dda355e 100644 --- a/drivers/staging/lustre/lustre/obdclass/llog_internal.h +++ b/drivers/staging/lustre/lustre/obdclass/llog_internal.h @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/obdclass/llog_obd.c b/drivers/staging/lustre/lustre/obdclass/llog_obd.c index 3900b9d4007e..9bc51998c05c 100644 --- a/drivers/staging/lustre/lustre/obdclass/llog_obd.c +++ b/drivers/staging/lustre/lustre/obdclass/llog_obd.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/obdclass/llog_swab.c b/drivers/staging/lustre/lustre/obdclass/llog_swab.c index 9354f75b5cab..3aa7393b20c3 100644 --- a/drivers/staging/lustre/lustre/obdclass/llog_swab.c +++ b/drivers/staging/lustre/lustre/obdclass/llog_swab.c @@ -27,7 +27,7 @@ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c index 333ac7d269b7..51fe15f5d687 100644 --- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -502,7 +502,7 @@ int lprocfs_rd_server_uuid(struct seq_file *m, void *data) obd2cli_tgt(obd), imp_state_name, imp->imp_deactive ? "\tDEACTIVATED" : ""); - LPROCFS_CLIMP_EXIT(obd); + up_read(&obd->u.cli.cl_sem); return 0; } @@ -526,7 +526,7 @@ int lprocfs_rd_conn_uuid(struct seq_file *m, void *data) else seq_puts(m, "<none>\n"); - LPROCFS_CLIMP_EXIT(obd); + up_read(&obd->u.cli.cl_sem); return 0; } @@ -665,15 +665,18 @@ int lprocfs_rd_import(struct seq_file *m, void *data) seq_printf(m, "%s%s", j ? ", " : "", nidstr); j++; } - libcfs_nid2str_r(imp->imp_connection->c_peer.nid, - nidstr, sizeof(nidstr)); + if (imp->imp_connection != NULL) + libcfs_nid2str_r(imp->imp_connection->c_peer.nid, + nidstr, sizeof(nidstr)); + else + strncpy(nidstr, "<none>", sizeof(nidstr)); seq_printf(m, "]\n" " current_connection: %s\n" " connection_attempts: %u\n" " generation: %u\n" " in-progress_invalidations: %u\n", - imp->imp_connection == NULL ? "<none>" : nidstr, + nidstr, imp->imp_conn_cnt, imp->imp_generation, atomic_read(&imp->imp_inval_count)); @@ -765,7 +768,7 @@ int lprocfs_rd_import(struct seq_file *m, void *data) } out_climp: - LPROCFS_CLIMP_EXIT(obd); + up_read(&obd->u.cli.cl_sem); return 0; } EXPORT_SYMBOL(lprocfs_rd_import); @@ -796,7 +799,7 @@ int lprocfs_rd_state(struct seq_file *m, void *data) ptlrpc_import_state_name(ish->ish_state)); } - LPROCFS_CLIMP_EXIT(obd); + up_read(&obd->u.cli.cl_sem); return 0; } EXPORT_SYMBOL(lprocfs_rd_state); @@ -857,7 +860,7 @@ int lprocfs_rd_timeouts(struct seq_file *m, void *data) lprocfs_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]); } - LPROCFS_CLIMP_EXIT(obd); + up_read(&obd->u.cli.cl_sem); return 0; } EXPORT_SYMBOL(lprocfs_rd_timeouts); @@ -876,7 +879,7 @@ int lprocfs_rd_connect_flags(struct seq_file *m, void *data) seq_printf(m, "flags=%#llx\n", flags); obd_connect_seq_flags2str(m, flags, "\n"); seq_printf(m, "\n"); - LPROCFS_CLIMP_EXIT(obd); + up_read(&obd->u.cli.cl_sem); return 0; } EXPORT_SYMBOL(lprocfs_rd_connect_flags); diff --git a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c index 0193608a930a..ce248f4072c2 100644 --- a/drivers/staging/lustre/lustre/obdclass/lu_object.c +++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -916,7 +916,7 @@ static void lu_obj_hop_put_locked(struct cfs_hash *hs, struct hlist_node *hnode) LBUG(); /* we should never called it */ } -struct cfs_hash_ops lu_site_hash_ops = { +static struct cfs_hash_ops lu_site_hash_ops = { .hs_hash = lu_obj_hop_hash, .hs_key = lu_obj_hop_key, .hs_keycmp = lu_obj_hop_keycmp, diff --git a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c index c231e0da0e2a..49cdc647910c 100644 --- a/drivers/staging/lustre/lustre/obdclass/obd_config.c +++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c index 48003d5325e3..b5aa8168dbff 100644 --- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c +++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -892,7 +892,7 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd) } lmd->lmd_magic = LMD_MAGIC; - lmd->lmd_params = kzalloc(4096, GFP_NOFS); + lmd->lmd_params = kzalloc(LMD_PARAMS_MAXLEN, GFP_NOFS); if (!lmd->lmd_params) return -ENOMEM; lmd->lmd_params[0] = '\0'; @@ -978,7 +978,7 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd) goto invalid; clear++; } else if (strncmp(s1, "param=", 6) == 0) { - int length; + size_t length, params_length; char *tail = strchr(s1 + 6, ','); if (tail == NULL) @@ -986,8 +986,12 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd) else length = tail - s1; length -= 6; + params_length = strlen(lmd->lmd_params); + if (params_length + length + 1 >= LMD_PARAMS_MAXLEN) + return -E2BIG; strncat(lmd->lmd_params, s1 + 6, length); - strcat(lmd->lmd_params, " "); + lmd->lmd_params[params_length + length] = '\0'; + strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN); clear++; } else if (strncmp(s1, "osd=", 4) == 0) { rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4); diff --git a/drivers/staging/lustre/lustre/obdecho/echo_client.c b/drivers/staging/lustre/lustre/obdecho/echo_client.c index a4a9a763ff02..7b53f7dd1797 100644 --- a/drivers/staging/lustre/lustre/obdecho/echo_client.c +++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -1228,8 +1228,10 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, u64 offset, cl_page_put(env, clp); break; } - - cl_2queue_add(queue, clp); + /* + * Add a page to the incoming page list of 2-queue. + */ + cl_page_list_add(&queue->c2_qin, clp); /* drop the reference count for cl_page_find, so that the page * will be freed in cl_2queue_fini. */ @@ -2130,10 +2132,10 @@ static int echo_client_disconnect(struct obd_export *exp) } static struct obd_ops echo_client_obd_ops = { - .o_owner = THIS_MODULE, - .o_iocontrol = echo_client_iocontrol, - .o_connect = echo_client_connect, - .o_disconnect = echo_client_disconnect + .owner = THIS_MODULE, + .iocontrol = echo_client_iocontrol, + .connect = echo_client_connect, + .disconnect = echo_client_disconnect }; static int echo_client_init(void) @@ -2172,7 +2174,7 @@ static void /*__exit*/ obdecho_exit(void) } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre Testing Echo OBD driver"); MODULE_LICENSE("GPL"); MODULE_VERSION(LUSTRE_VERSION_STRING); diff --git a/drivers/staging/lustre/lustre/osc/lproc_osc.c b/drivers/staging/lustre/lustre/osc/lproc_osc.c index c4d44e70f1d7..1091536fc90d 100644 --- a/drivers/staging/lustre/lustre/osc/lproc_osc.c +++ b/drivers/staging/lustre/lustre/osc/lproc_osc.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c index b1d1a87f05e3..2229419b7184 100644 --- a/drivers/staging/lustre/lustre/osc/osc_cache.c +++ b/drivers/staging/lustre/lustre/osc/osc_cache.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. * */ /* @@ -619,9 +619,9 @@ static inline int overlapped(struct osc_extent *ex1, struct osc_extent *ex2) * Find or create an extent which includes @index, core function to manage * extent tree. */ -struct osc_extent *osc_extent_find(const struct lu_env *env, - struct osc_object *obj, pgoff_t index, - int *grants) +static struct osc_extent *osc_extent_find(const struct lu_env *env, + struct osc_object *obj, pgoff_t index, + int *grants) { struct client_obd *cli = osc_cli(obj); @@ -1420,8 +1420,8 @@ static void __osc_unreserve_grant(struct client_obd *cli, } } -void osc_unreserve_grant(struct client_obd *cli, - unsigned int reserved, unsigned int unused) +static void osc_unreserve_grant(struct client_obd *cli, + unsigned int reserved, unsigned int unused) { client_obd_list_lock(&cli->cl_loi_list_lock); __osc_unreserve_grant(cli, reserved, unused); diff --git a/drivers/staging/lustre/lustre/osc/osc_cl_internal.h b/drivers/staging/lustre/lustre/osc/osc_cl_internal.h index d2d68452d382..415c27e4ab66 100644 --- a/drivers/staging/lustre/lustre/osc/osc_cl_internal.h +++ b/drivers/staging/lustre/lustre/osc/osc_cl_internal.h @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/osc/osc_dev.c b/drivers/staging/lustre/lustre/osc/osc_dev.c index 69b523c0f570..7078cc57d8b9 100644 --- a/drivers/staging/lustre/lustre/osc/osc_dev.c +++ b/drivers/staging/lustre/lustre/osc/osc_dev.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/osc/osc_internal.h b/drivers/staging/lustre/lustre/osc/osc_internal.h index 5ed30ecc84e3..a4c61463b1c7 100644 --- a/drivers/staging/lustre/lustre/osc/osc_internal.h +++ b/drivers/staging/lustre/lustre/osc/osc_internal.h @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -89,11 +89,6 @@ struct osc_cache_waiter { int ocw_rc; }; -int osc_create(const struct lu_env *env, struct obd_export *exp, - struct obdo *oa, struct lov_stripe_md **ea, - struct obd_trans_info *oti); -int osc_real_create(struct obd_export *exp, struct obdo *oa, - struct lov_stripe_md **ea, struct obd_trans_info *oti); void osc_wake_cache_waiters(struct client_obd *cli); int osc_shrink_grant_to_target(struct client_obd *cli, __u64 target_bytes); void osc_update_next_shrink(struct client_obd *cli); @@ -137,7 +132,6 @@ int osc_lru_shrink(struct client_obd *cli, int target); extern spinlock_t osc_ast_guard; -int osc_cleanup(struct obd_device *obd); int osc_setup(struct obd_device *obd, struct lustre_cfg *lcfg); int lproc_osc_attach_seqstat(struct obd_device *dev); diff --git a/drivers/staging/lustre/lustre/osc/osc_io.c b/drivers/staging/lustre/lustre/osc/osc_io.c index d413496c0f63..abd0beb483fe 100644 --- a/drivers/staging/lustre/lustre/osc/osc_io.c +++ b/drivers/staging/lustre/lustre/osc/osc_io.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/osc/osc_lock.c b/drivers/staging/lustre/lustre/osc/osc_lock.c index 194490dcaca9..71f2810d18b9 100644 --- a/drivers/staging/lustre/lustre/osc/osc_lock.c +++ b/drivers/staging/lustre/lustre/osc/osc_lock.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/osc/osc_object.c b/drivers/staging/lustre/lustre/osc/osc_object.c index ba57f8df5c7f..fdd6219aacf6 100644 --- a/drivers/staging/lustre/lustre/osc/osc_object.c +++ b/drivers/staging/lustre/lustre/osc/osc_object.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -158,8 +158,8 @@ static int osc_attr_get(const struct lu_env *env, struct cl_object *obj, return 0; } -int osc_attr_set(const struct lu_env *env, struct cl_object *obj, - const struct cl_attr *attr, unsigned valid) +static int osc_attr_set(const struct lu_env *env, struct cl_object *obj, + const struct cl_attr *attr, unsigned valid) { struct lov_oinfo *oinfo = cl2osc(obj)->oo_oinfo; struct ost_lvb *lvb = &oinfo->loi_lvb; diff --git a/drivers/staging/lustre/lustre/osc/osc_page.c b/drivers/staging/lustre/lustre/osc/osc_page.c index 61eaf7172fdf..2439d804fe75 100644 --- a/drivers/staging/lustre/lustre/osc/osc_page.c +++ b/drivers/staging/lustre/lustre/osc/osc_page.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/osc/osc_quota.c b/drivers/staging/lustre/lustre/osc/osc_quota.c index 199783103f71..e70e7961d763 100644 --- a/drivers/staging/lustre/lustre/osc/osc_quota.c +++ b/drivers/staging/lustre/lustre/osc/osc_quota.c @@ -23,7 +23,7 @@ /* * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. * * Code originally extracted from quota directory */ diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c index 367f83af12c0..7034f0a942c5 100644 --- a/drivers/staging/lustre/lustre/osc/osc_request.c +++ b/drivers/staging/lustre/lustre/osc/osc_request.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -104,7 +104,7 @@ struct osc_enqueue_args { static void osc_release_ppga(struct brw_page **ppga, u32 count); static int brw_interpret(const struct lu_env *env, struct ptlrpc_request *req, void *data, int rc); -int osc_cleanup(struct obd_device *obd); +static int osc_cleanup(struct obd_device *obd); /* Pack OSC object metadata for disk storage (LE byte order). */ static int osc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp, @@ -431,8 +431,9 @@ static int osc_setattr_async(struct obd_export *exp, struct obd_info *oinfo, oinfo->oi_cb_up, oinfo, rqset); } -int osc_real_create(struct obd_export *exp, struct obdo *oa, - struct lov_stripe_md **ea, struct obd_trans_info *oti) +static int osc_real_create(struct obd_export *exp, struct obdo *oa, + struct lov_stripe_md **ea, + struct obd_trans_info *oti) { struct ptlrpc_request *req; struct ost_body *body; @@ -689,9 +690,9 @@ static int osc_can_send_destroy(struct client_obd *cli) return 0; } -int osc_create(const struct lu_env *env, struct obd_export *exp, - struct obdo *oa, struct lov_stripe_md **ea, - struct obd_trans_info *oti) +static int osc_create(const struct lu_env *env, struct obd_export *exp, + struct obdo *oa, struct lov_stripe_md **ea, + struct obd_trans_info *oti) { int rc = 0; @@ -2726,7 +2727,7 @@ static int osc_get_info(const struct lu_env *env, struct obd_export *exp, } *((u64 *)val) = *reply; - out: +out: ptlrpc_req_finished(req); return rc; } else if (KEY_IS(KEY_FIEMAP)) { @@ -3255,33 +3256,33 @@ static int osc_process_config(struct obd_device *obd, u32 len, void *buf) } struct obd_ops osc_obd_ops = { - .o_owner = THIS_MODULE, - .o_setup = osc_setup, - .o_precleanup = osc_precleanup, - .o_cleanup = osc_cleanup, - .o_add_conn = client_import_add_conn, - .o_del_conn = client_import_del_conn, - .o_connect = client_connect_import, - .o_reconnect = osc_reconnect, - .o_disconnect = osc_disconnect, - .o_statfs = osc_statfs, - .o_statfs_async = osc_statfs_async, - .o_packmd = osc_packmd, - .o_unpackmd = osc_unpackmd, - .o_create = osc_create, - .o_destroy = osc_destroy, - .o_getattr = osc_getattr, - .o_getattr_async = osc_getattr_async, - .o_setattr = osc_setattr, - .o_setattr_async = osc_setattr_async, - .o_find_cbdata = osc_find_cbdata, - .o_iocontrol = osc_iocontrol, - .o_get_info = osc_get_info, - .o_set_info_async = osc_set_info_async, - .o_import_event = osc_import_event, - .o_process_config = osc_process_config, - .o_quotactl = osc_quotactl, - .o_quotacheck = osc_quotacheck, + .owner = THIS_MODULE, + .setup = osc_setup, + .precleanup = osc_precleanup, + .cleanup = osc_cleanup, + .add_conn = client_import_add_conn, + .del_conn = client_import_del_conn, + .connect = client_connect_import, + .reconnect = osc_reconnect, + .disconnect = osc_disconnect, + .statfs = osc_statfs, + .statfs_async = osc_statfs_async, + .packmd = osc_packmd, + .unpackmd = osc_unpackmd, + .create = osc_create, + .destroy = osc_destroy, + .getattr = osc_getattr, + .getattr_async = osc_getattr_async, + .setattr = osc_setattr, + .setattr_async = osc_setattr_async, + .find_cbdata = osc_find_cbdata, + .iocontrol = osc_iocontrol, + .get_info = osc_get_info, + .set_info_async = osc_set_info_async, + .import_event = osc_import_event, + .process_config = osc_process_config, + .quotactl = osc_quotactl, + .quotacheck = osc_quotacheck, }; extern struct lu_kmem_descr osc_caches[]; @@ -3357,7 +3358,7 @@ static void /*__exit*/ osc_exit(void) ptlrpc_free_rq_pool(osc_rq_pool); } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre Object Storage Client (OSC)"); MODULE_LICENSE("GPL"); MODULE_VERSION(LUSTRE_VERSION_STRING); diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c index a9f1bf536da9..efdda09507bf 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/client.c +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c index 9c2fd34e2eb9..990156986986 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/events.c +++ b/drivers/staging/lustre/lustre/ptlrpc/events.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015 Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c index bfa410f7e773..f752c789bda0 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/import.c +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/layout.c b/drivers/staging/lustre/lustre/ptlrpc/layout.c index d7c4f47808bd..c0e613c23854 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/layout.c +++ b/drivers/staging/lustre/lustre/ptlrpc/layout.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/llog_client.c b/drivers/staging/lustre/lustre/ptlrpc/llog_client.c index 5122205cbb99..e87702073f1f 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/llog_client.c +++ b/drivers/staging/lustre/lustre/ptlrpc/llog_client.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c index afab0dee7a5c..cc55b7973721 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c +++ b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -1197,7 +1197,7 @@ int lprocfs_wr_ping(struct file *file, const char __user *buffer, return rc; req = ptlrpc_prep_ping(obd->u.cli.cl_import); - LPROCFS_CLIMP_EXIT(obd); + up_read(&obd->u.cli.cl_sem); if (req == NULL) return -ENOMEM; @@ -1291,7 +1291,7 @@ int lprocfs_rd_pinger_recov(struct seq_file *m, void *n) return rc; seq_printf(m, "%d\n", !imp->imp_no_pinger_recover); - LPROCFS_CLIMP_EXIT(obd); + up_read(&obd->u.cli.cl_sem); return 0; } @@ -1319,7 +1319,7 @@ int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer, spin_lock(&imp->imp_lock); imp->imp_no_pinger_recover = !val; spin_unlock(&imp->imp_lock); - LPROCFS_CLIMP_EXIT(obd); + up_read(&obd->u.cli.cl_sem); return count; diff --git a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c index 09ddeef6ba48..c5d7ff5cbd73 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c +++ b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/pers.c b/drivers/staging/lustre/lustre/ptlrpc/pers.c index 2a2a9fb6549c..ec3af109a1d7 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/pers.c +++ b/drivers/staging/lustre/lustre/ptlrpc/pers.c @@ -26,6 +26,8 @@ /* * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2014, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c index 5c719f175657..fb2d5236a971 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c +++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h index ab6c4580f91c..8f67e0562b73 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -73,7 +73,6 @@ void ptlrpc_request_handle_notconn(struct ptlrpc_request *); void lustre_assert_wire_constants(void); int ptlrpc_import_in_recovery(struct obd_import *imp); int ptlrpc_set_import_discon(struct obd_import *imp, __u32 conn_cnt); -void ptlrpc_handle_failed_import(struct obd_import *imp); int ptlrpc_replay_next(struct obd_import *imp, int *inflight); void ptlrpc_initiate_recovery(struct obd_import *imp); @@ -88,8 +87,6 @@ void ptlrpc_ldebugfs_register_service(struct dentry *debugfs_entry, struct ptlrpc_service *svc); void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc); void ptlrpc_lprocfs_rpc_sent(struct ptlrpc_request *req, long amount); -void ptlrpc_lprocfs_do_request_stat(struct ptlrpc_request *req, - long q_usec, long work_usec); /* NRS */ diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c index 9deeb244166f..c4f1d0f5deb2 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c @@ -160,7 +160,7 @@ static void __exit ptlrpc_exit(void) ptlrpc_connection_fini(); } -MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); +MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); MODULE_DESCRIPTION("Lustre Request Processor and Lock Management"); MODULE_LICENSE("GPL"); MODULE_VERSION("1.0.0"); diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c index ce036a1ac466..60fb0ced7137 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -422,6 +422,7 @@ static int ptlrpcd(void *arg) complete(&pc->pc_starting); /* + * This mainloop strongly resembles ptlrpc_set_wait() except that our * set never completes. ptlrpcd_check() calls ptlrpc_check_set() when * there are requests in the set. New requests come in on the set's diff --git a/drivers/staging/lustre/lustre/ptlrpc/recover.c b/drivers/staging/lustre/lustre/ptlrpc/recover.c index 7b1d72947330..db6626cab6f2 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/recover.c +++ b/drivers/staging/lustre/lustre/ptlrpc/recover.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c index cd8a9987f7ac..6152c1b766c3 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_config.c b/drivers/staging/lustre/lustre/ptlrpc/sec_config.c index 7ff948fe1424..4b0b81c115ee 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/sec_config.c +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_config.c @@ -27,7 +27,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -83,8 +83,7 @@ int sptlrpc_parse_flavor(const char *str, struct sptlrpc_flavor *flvr) return 0; } - strncpy(buf, str, sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; + strlcpy(buf, str, sizeof(buf)); bulk = strchr(buf, '-'); if (bulk) diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c index f448b4567af0..905a41451ca3 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c index f45898f17793..8598300a61d1 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/service.c +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c @@ -27,7 +27,7 @@ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2010, 2012, Intel Corporation. + * Copyright (c) 2010, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/lustre/lustre/ptlrpc/wiretest.c b/drivers/staging/lustre/lustre/ptlrpc/wiretest.c index 40f720ca3b14..61d9ca93c53a 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/wiretest.c +++ b/drivers/staging/lustre/lustre/ptlrpc/wiretest.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, Intel Corporation. + * Copyright (c) 2011, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ diff --git a/drivers/staging/media/bcm2048/radio-bcm2048.c b/drivers/staging/media/bcm2048/radio-bcm2048.c index 93bffbac8fc7..8fdf0ac4f287 100644 --- a/drivers/staging/media/bcm2048/radio-bcm2048.c +++ b/drivers/staging/media/bcm2048/radio-bcm2048.c @@ -179,14 +179,13 @@ #define BCM2048_DEFAULT_TIMEOUT 1500 #define BCM2048_AUTO_SEARCH_TIMEOUT 3000 - #define BCM2048_FREQDEV_UNIT 10000 #define BCM2048_FREQV4L2_MULTI 625 #define dev_to_v4l2(f) ((f * BCM2048_FREQDEV_UNIT) / BCM2048_FREQV4L2_MULTI) #define v4l2_to_dev(f) ((f * BCM2048_FREQV4L2_MULTI) / BCM2048_FREQDEV_UNIT) -#define msb(x) ((u8)((u16) x >> 8)) -#define lsb(x) ((u8)((u16) x & 0x00FF)) +#define msb(x) ((u8)((u16)x >> 8)) +#define lsb(x) ((u8)((u16)x & 0x00FF)) #define compose_u16(msb, lsb) (((u16)msb << 8) | lsb) #define BCM2048_DEFAULT_POWERING_DELAY 20 @@ -348,7 +347,7 @@ static struct region_info region_configs[] = { * I2C Interface read / write */ static int bcm2048_send_command(struct bcm2048_device *bdev, unsigned int reg, - unsigned int value) + unsigned int value) { struct i2c_client *client = bdev->client; u8 data[2]; @@ -370,7 +369,7 @@ static int bcm2048_send_command(struct bcm2048_device *bdev, unsigned int reg, } static int bcm2048_recv_command(struct bcm2048_device *bdev, unsigned int reg, - u8 *value) + u8 *value) { struct i2c_client *client = bdev->client; @@ -385,7 +384,7 @@ static int bcm2048_recv_command(struct bcm2048_device *bdev, unsigned int reg, } static int bcm2048_recv_duples(struct bcm2048_device *bdev, unsigned int reg, - u8 *value, u8 duples) + u8 *value, u8 duples) { struct i2c_client *client = bdev->client; struct i2c_adapter *adap = client->adapter; @@ -436,7 +435,7 @@ static int bcm2048_set_power_state(struct bcm2048_device *bdev, u8 power) */ if (power) err = bcm2048_send_command(bdev, BCM2048_I2C_FM_RDS_SYSTEM, - bdev->cache_fm_rds_system); + bdev->cache_fm_rds_system); msleep(BCM2048_DEFAULT_POWERING_DELAY); if (!power) @@ -475,17 +474,17 @@ static int bcm2048_set_rds_no_lock(struct bcm2048_device *bdev, u8 rds_on) bdev->rds_state = BCM2048_RDS_ON; flags = BCM2048_RDS_FLAG_FIFO_WLINE; err = bcm2048_send_command(bdev, BCM2048_I2C_FM_RDS_MASK1, - flags); + flags); } else { flags = 0; bdev->rds_state = 0; err = bcm2048_send_command(bdev, BCM2048_I2C_FM_RDS_MASK1, - flags); + flags); memset(&bdev->rds_info, 0, sizeof(bdev->rds_info)); } err = bcm2048_send_command(bdev, BCM2048_I2C_FM_RDS_SYSTEM, - bdev->cache_fm_rds_system); + bdev->cache_fm_rds_system); return err; } @@ -545,14 +544,14 @@ static int bcm2048_set_fm_automatic_stereo_mono(struct bcm2048_device *bdev, bdev->cache_fm_ctrl |= BCM2048_STEREO_MONO_AUTO_SELECT; err = bcm2048_send_command(bdev, BCM2048_I2C_FM_CTRL, - bdev->cache_fm_ctrl); + bdev->cache_fm_ctrl); mutex_unlock(&bdev->mutex); return err; } static int bcm2048_set_fm_hi_lo_injection(struct bcm2048_device *bdev, - u8 hi_lo) + u8 hi_lo) { int err; @@ -564,7 +563,7 @@ static int bcm2048_set_fm_hi_lo_injection(struct bcm2048_device *bdev, bdev->cache_fm_ctrl |= BCM2048_HI_LO_INJECTION; err = bcm2048_send_command(bdev, BCM2048_I2C_FM_CTRL, - bdev->cache_fm_ctrl); + bdev->cache_fm_ctrl); mutex_unlock(&bdev->mutex); return err; @@ -592,7 +591,7 @@ static int bcm2048_set_fm_frequency(struct bcm2048_device *bdev, u32 frequency) int err; if (frequency < bdev->region_info.bottom_frequency || - frequency > bdev->region_info.top_frequency) + frequency > bdev->region_info.top_frequency) return -EDOM; frequency -= BCM2048_FREQUENCY_BASE; @@ -601,7 +600,7 @@ static int bcm2048_set_fm_frequency(struct bcm2048_device *bdev, u32 frequency) err = bcm2048_send_command(bdev, BCM2048_I2C_FM_FREQ0, lsb(frequency)); err |= bcm2048_send_command(bdev, BCM2048_I2C_FM_FREQ1, - msb(frequency)); + msb(frequency)); if (!err) bdev->frequency = frequency; @@ -632,12 +631,12 @@ static int bcm2048_get_fm_frequency(struct bcm2048_device *bdev) } static int bcm2048_set_fm_af_frequency(struct bcm2048_device *bdev, - u32 frequency) + u32 frequency) { int err; if (frequency < bdev->region_info.bottom_frequency || - frequency > bdev->region_info.top_frequency) + frequency > bdev->region_info.top_frequency) return -EDOM; frequency -= BCM2048_FREQUENCY_BASE; @@ -645,9 +644,9 @@ static int bcm2048_set_fm_af_frequency(struct bcm2048_device *bdev, mutex_lock(&bdev->mutex); err = bcm2048_send_command(bdev, BCM2048_I2C_FM_AF_FREQ0, - lsb(frequency)); + lsb(frequency)); err |= bcm2048_send_command(bdev, BCM2048_I2C_FM_AF_FREQ1, - msb(frequency)); + msb(frequency)); if (!err) bdev->frequency = frequency; @@ -692,7 +691,7 @@ static int bcm2048_set_fm_deemphasis(struct bcm2048_device *bdev, int d) bdev->cache_fm_audio_ctrl0 |= deemphasis; err = bcm2048_send_command(bdev, BCM2048_I2C_FM_AUDIO_CTRL0, - bdev->cache_fm_audio_ctrl0); + bdev->cache_fm_audio_ctrl0); if (!err) bdev->region_info.deemphasis = d; @@ -740,7 +739,7 @@ static int bcm2048_set_region(struct bcm2048_device *bdev, u8 region) bdev->cache_fm_ctrl &= ~BCM2048_BAND_SELECT; err = bcm2048_send_command(bdev, BCM2048_I2C_FM_CTRL, - bdev->cache_fm_ctrl); + bdev->cache_fm_ctrl); if (err) { mutex_unlock(&bdev->mutex); goto done; @@ -748,7 +747,7 @@ static int bcm2048_set_region(struct bcm2048_device *bdev, u8 region) mutex_unlock(&bdev->mutex); if (bdev->frequency < region_configs[region].bottom_frequency || - bdev->frequency > region_configs[region].top_frequency) + bdev->frequency > region_configs[region].top_frequency) new_frequency = region_configs[region].bottom_frequency; if (new_frequency > 0) { @@ -759,7 +758,7 @@ static int bcm2048_set_region(struct bcm2048_device *bdev, u8 region) } err = bcm2048_set_fm_deemphasis(bdev, - region_configs[region].deemphasis); + region_configs[region].deemphasis); done: return err; @@ -786,10 +785,10 @@ static int bcm2048_set_mute(struct bcm2048_device *bdev, u16 mute) if (mute) bdev->cache_fm_audio_ctrl0 |= (BCM2048_RF_MUTE | - BCM2048_MANUAL_MUTE); + BCM2048_MANUAL_MUTE); err = bcm2048_send_command(bdev, BCM2048_I2C_FM_AUDIO_CTRL0, - bdev->cache_fm_audio_ctrl0); + bdev->cache_fm_audio_ctrl0); if (!err) bdev->mute_state = mute; @@ -807,7 +806,7 @@ static int bcm2048_get_mute(struct bcm2048_device *bdev) if (bdev->power_state) { err = bcm2048_recv_command(bdev, BCM2048_I2C_FM_AUDIO_CTRL0, - &value); + &value); if (!err) err = value & (BCM2048_RF_MUTE | BCM2048_MANUAL_MUTE); } else { @@ -826,11 +825,11 @@ static int bcm2048_set_audio_route(struct bcm2048_device *bdev, u8 route) route &= (BCM2048_AUDIO_ROUTE_DAC | BCM2048_AUDIO_ROUTE_I2S); bdev->cache_fm_audio_ctrl0 &= ~(BCM2048_AUDIO_ROUTE_DAC | - BCM2048_AUDIO_ROUTE_I2S); + BCM2048_AUDIO_ROUTE_I2S); bdev->cache_fm_audio_ctrl0 |= route; err = bcm2048_send_command(bdev, BCM2048_I2C_FM_AUDIO_CTRL0, - bdev->cache_fm_audio_ctrl0); + bdev->cache_fm_audio_ctrl0); mutex_unlock(&bdev->mutex); return err; @@ -849,7 +848,7 @@ static int bcm2048_get_audio_route(struct bcm2048_device *bdev) if (!err) return value & (BCM2048_AUDIO_ROUTE_DAC | - BCM2048_AUDIO_ROUTE_I2S); + BCM2048_AUDIO_ROUTE_I2S); return err; } @@ -865,7 +864,7 @@ static int bcm2048_set_dac_output(struct bcm2048_device *bdev, u8 channels) bdev->cache_fm_audio_ctrl0 |= channels; err = bcm2048_send_command(bdev, BCM2048_I2C_FM_AUDIO_CTRL0, - bdev->cache_fm_audio_ctrl0); + bdev->cache_fm_audio_ctrl0); mutex_unlock(&bdev->mutex); return err; @@ -884,13 +883,13 @@ static int bcm2048_get_dac_output(struct bcm2048_device *bdev) if (!err) return value & (BCM2048_DAC_OUTPUT_LEFT | - BCM2048_DAC_OUTPUT_RIGHT); + BCM2048_DAC_OUTPUT_RIGHT); return err; } static int bcm2048_set_fm_search_rssi_threshold(struct bcm2048_device *bdev, - u8 threshold) + u8 threshold) { int err; @@ -901,7 +900,7 @@ static int bcm2048_set_fm_search_rssi_threshold(struct bcm2048_device *bdev, bdev->cache_fm_search_ctrl0 |= threshold; err = bcm2048_send_command(bdev, BCM2048_I2C_FM_SEARCH_CTRL0, - bdev->cache_fm_search_ctrl0); + bdev->cache_fm_search_ctrl0); mutex_unlock(&bdev->mutex); return err; @@ -937,7 +936,7 @@ static int bcm2048_set_fm_search_mode_direction(struct bcm2048_device *bdev, bdev->cache_fm_search_ctrl0 |= BCM2048_SEARCH_DIRECTION; err = bcm2048_send_command(bdev, BCM2048_I2C_FM_SEARCH_CTRL0, - bdev->cache_fm_search_ctrl0); + bdev->cache_fm_search_ctrl0); mutex_unlock(&bdev->mutex); return err; @@ -961,7 +960,7 @@ static int bcm2048_get_fm_search_mode_direction(struct bcm2048_device *bdev) } static int bcm2048_set_fm_search_tune_mode(struct bcm2048_device *bdev, - u8 mode) + u8 mode) { int err, timeout, restart_rds = 0; u8 value, flags; @@ -1024,7 +1023,7 @@ static int bcm2048_get_fm_search_tune_mode(struct bcm2048_device *bdev) mutex_lock(&bdev->mutex); err = bcm2048_recv_command(bdev, BCM2048_I2C_FM_SEARCH_TUNE_MODE, - &value); + &value); mutex_unlock(&bdev->mutex); @@ -1040,10 +1039,10 @@ static int bcm2048_set_rds_b_block_mask(struct bcm2048_device *bdev, u16 mask) mutex_lock(&bdev->mutex); - err = bcm2048_send_command(bdev, - BCM2048_I2C_RDS_BLKB_MASK0, lsb(mask)); - err |= bcm2048_send_command(bdev, - BCM2048_I2C_RDS_BLKB_MASK1, msb(mask)); + err = bcm2048_send_command(bdev, BCM2048_I2C_RDS_BLKB_MASK0, + lsb(mask)); + err |= bcm2048_send_command(bdev, BCM2048_I2C_RDS_BLKB_MASK1, + msb(mask)); mutex_unlock(&bdev->mutex); return err; @@ -1056,10 +1055,8 @@ static int bcm2048_get_rds_b_block_mask(struct bcm2048_device *bdev) mutex_lock(&bdev->mutex); - err = bcm2048_recv_command(bdev, - BCM2048_I2C_RDS_BLKB_MASK0, &lsb); - err |= bcm2048_recv_command(bdev, - BCM2048_I2C_RDS_BLKB_MASK1, &msb); + err = bcm2048_recv_command(bdev, BCM2048_I2C_RDS_BLKB_MASK0, &lsb); + err |= bcm2048_recv_command(bdev, BCM2048_I2C_RDS_BLKB_MASK1, &msb); mutex_unlock(&bdev->mutex); @@ -1070,16 +1067,16 @@ static int bcm2048_get_rds_b_block_mask(struct bcm2048_device *bdev) } static int bcm2048_set_rds_b_block_match(struct bcm2048_device *bdev, - u16 match) + u16 match) { int err; mutex_lock(&bdev->mutex); - err = bcm2048_send_command(bdev, - BCM2048_I2C_RDS_BLKB_MATCH0, lsb(match)); - err |= bcm2048_send_command(bdev, - BCM2048_I2C_RDS_BLKB_MATCH1, msb(match)); + err = bcm2048_send_command(bdev, BCM2048_I2C_RDS_BLKB_MATCH0, + lsb(match)); + err |= bcm2048_send_command(bdev, BCM2048_I2C_RDS_BLKB_MATCH1, + msb(match)); mutex_unlock(&bdev->mutex); return err; @@ -1092,10 +1089,8 @@ static int bcm2048_get_rds_b_block_match(struct bcm2048_device *bdev) mutex_lock(&bdev->mutex); - err = bcm2048_recv_command(bdev, - BCM2048_I2C_RDS_BLKB_MATCH0, &lsb); - err |= bcm2048_recv_command(bdev, - BCM2048_I2C_RDS_BLKB_MATCH1, &msb); + err = bcm2048_recv_command(bdev, BCM2048_I2C_RDS_BLKB_MATCH0, &lsb); + err |= bcm2048_recv_command(bdev, BCM2048_I2C_RDS_BLKB_MATCH1, &msb); mutex_unlock(&bdev->mutex); @@ -1111,10 +1106,8 @@ static int bcm2048_set_rds_pi_mask(struct bcm2048_device *bdev, u16 mask) mutex_lock(&bdev->mutex); - err = bcm2048_send_command(bdev, - BCM2048_I2C_RDS_PI_MASK0, lsb(mask)); - err |= bcm2048_send_command(bdev, - BCM2048_I2C_RDS_PI_MASK1, msb(mask)); + err = bcm2048_send_command(bdev, BCM2048_I2C_RDS_PI_MASK0, lsb(mask)); + err |= bcm2048_send_command(bdev, BCM2048_I2C_RDS_PI_MASK1, msb(mask)); mutex_unlock(&bdev->mutex); return err; @@ -1127,10 +1120,8 @@ static int bcm2048_get_rds_pi_mask(struct bcm2048_device *bdev) mutex_lock(&bdev->mutex); - err = bcm2048_recv_command(bdev, - BCM2048_I2C_RDS_PI_MASK0, &lsb); - err |= bcm2048_recv_command(bdev, - BCM2048_I2C_RDS_PI_MASK1, &msb); + err = bcm2048_recv_command(bdev, BCM2048_I2C_RDS_PI_MASK0, &lsb); + err |= bcm2048_recv_command(bdev, BCM2048_I2C_RDS_PI_MASK1, &msb); mutex_unlock(&bdev->mutex); @@ -1146,10 +1137,10 @@ static int bcm2048_set_rds_pi_match(struct bcm2048_device *bdev, u16 match) mutex_lock(&bdev->mutex); - err = bcm2048_send_command(bdev, - BCM2048_I2C_RDS_PI_MATCH0, lsb(match)); - err |= bcm2048_send_command(bdev, - BCM2048_I2C_RDS_PI_MATCH1, msb(match)); + err = bcm2048_send_command(bdev, BCM2048_I2C_RDS_PI_MATCH0, + lsb(match)); + err |= bcm2048_send_command(bdev, BCM2048_I2C_RDS_PI_MATCH1, + msb(match)); mutex_unlock(&bdev->mutex); return err; @@ -1162,10 +1153,8 @@ static int bcm2048_get_rds_pi_match(struct bcm2048_device *bdev) mutex_lock(&bdev->mutex); - err = bcm2048_recv_command(bdev, - BCM2048_I2C_RDS_PI_MATCH0, &lsb); - err |= bcm2048_recv_command(bdev, - BCM2048_I2C_RDS_PI_MATCH1, &msb); + err = bcm2048_recv_command(bdev, BCM2048_I2C_RDS_PI_MATCH0, &lsb); + err |= bcm2048_recv_command(bdev, BCM2048_I2C_RDS_PI_MATCH1, &msb); mutex_unlock(&bdev->mutex); @@ -1181,10 +1170,8 @@ static int bcm2048_set_fm_rds_mask(struct bcm2048_device *bdev, u16 mask) mutex_lock(&bdev->mutex); - err = bcm2048_send_command(bdev, - BCM2048_I2C_FM_RDS_MASK0, lsb(mask)); - err |= bcm2048_send_command(bdev, - BCM2048_I2C_FM_RDS_MASK1, msb(mask)); + err = bcm2048_send_command(bdev, BCM2048_I2C_FM_RDS_MASK0, lsb(mask)); + err |= bcm2048_send_command(bdev, BCM2048_I2C_FM_RDS_MASK1, msb(mask)); mutex_unlock(&bdev->mutex); return err; @@ -1245,13 +1232,13 @@ static int bcm2048_set_fm_best_tune_mode(struct bcm2048_device *bdev, u8 mode) /* Perform read as the manual indicates */ err = bcm2048_recv_command(bdev, BCM2048_I2C_FM_BEST_TUNE_MODE, - &value); + &value); value &= ~BCM2048_BEST_TUNE_MODE; if (mode) value |= BCM2048_BEST_TUNE_MODE; err |= bcm2048_send_command(bdev, BCM2048_I2C_FM_BEST_TUNE_MODE, - value); + value); mutex_unlock(&bdev->mutex); return err; @@ -1265,7 +1252,7 @@ static int bcm2048_get_fm_best_tune_mode(struct bcm2048_device *bdev) mutex_lock(&bdev->mutex); err = bcm2048_recv_command(bdev, BCM2048_I2C_FM_BEST_TUNE_MODE, - &value); + &value); mutex_unlock(&bdev->mutex); @@ -1352,7 +1339,7 @@ static int bcm2048_checkrev(struct bcm2048_device *bdev) if (!err) { dev_info(&bdev->client->dev, "BCM2048 Version 0x%x\n", - version); + version); return version; } @@ -1362,7 +1349,7 @@ static int bcm2048_checkrev(struct bcm2048_device *bdev) static int bcm2048_get_rds_rt(struct bcm2048_device *bdev, char *data) { int err = 0, i, j = 0, ce = 0, cr = 0; - char data_buffer[BCM2048_MAX_RDS_RT+1]; + char data_buffer[BCM2048_MAX_RDS_RT + 1]; mutex_lock(&bdev->mutex); @@ -1412,7 +1399,7 @@ unlock: static int bcm2048_get_rds_ps(struct bcm2048_device *bdev, char *data) { int err = 0, i, j = 0; - char data_buffer[BCM2048_MAX_RDS_PS+1]; + char data_buffer[BCM2048_MAX_RDS_PS + 1]; mutex_lock(&bdev->mutex); @@ -1448,12 +1435,10 @@ static void bcm2048_parse_rds_pi(struct bcm2048_device *bdev) u16 pi; for (i = 0; i < bdev->fifo_size; i += BCM2048_RDS_FIFO_DUPLE_SIZE) { - /* Block A match, only data without crc errors taken */ if (bdev->rds_info.radio_text[i] == BCM2048_RDS_BLOCK_A) { - - pi = (bdev->rds_info.radio_text[i+1] << 8) + - bdev->rds_info.radio_text[i+2]; + pi = (bdev->rds_info.radio_text[i + 1] << 8) + + bdev->rds_info.radio_text[i + 2]; if (!bdev->rds_info.rds_pi) { bdev->rds_info.rds_pi = pi; @@ -1478,20 +1463,21 @@ static int bcm2048_rds_block_crc(struct bcm2048_device *bdev, int i) } static void bcm2048_parse_rds_rt_block(struct bcm2048_device *bdev, int i, - int index, int crc) + int index, int crc) { /* Good data will overwrite poor data */ if (crc) { if (!bdev->rds_info.rds_rt[index]) bdev->rds_info.rds_rt[index] = - bdev->rds_info.radio_text[i+1]; - if (!bdev->rds_info.rds_rt[index+1]) - bdev->rds_info.rds_rt[index+1] = - bdev->rds_info.radio_text[i+2]; + bdev->rds_info.radio_text[i + 1]; + if (!bdev->rds_info.rds_rt[index + 1]) + bdev->rds_info.rds_rt[index + 1] = + bdev->rds_info.radio_text[i + 2]; } else { - bdev->rds_info.rds_rt[index] = bdev->rds_info.radio_text[i+1]; - bdev->rds_info.rds_rt[index+1] = - bdev->rds_info.radio_text[i+2]; + bdev->rds_info.rds_rt[index] = + bdev->rds_info.radio_text[i + 1]; + bdev->rds_info.rds_rt[index + 1] = + bdev->rds_info.radio_text[i + 2]; } } @@ -1505,18 +1491,17 @@ static int bcm2048_parse_rt_match_b(struct bcm2048_device *bdev, int i) return -EIO; if ((bdev->rds_info.radio_text[i] & BCM2048_RDS_BLOCK_MASK) == - BCM2048_RDS_BLOCK_B) { - - rt_id = bdev->rds_info.radio_text[i+1] & + BCM2048_RDS_BLOCK_B) { + rt_id = bdev->rds_info.radio_text[i + 1] & BCM2048_RDS_BLOCK_MASK; - rt_group_b = bdev->rds_info.radio_text[i+1] & + rt_group_b = bdev->rds_info.radio_text[i + 1] & BCM2048_RDS_GROUP_AB_MASK; - rt_ab = bdev->rds_info.radio_text[i+2] & + rt_ab = bdev->rds_info.radio_text[i + 2] & BCM2048_RDS_RT_AB_MASK; if (rt_group_b != bdev->rds_info.rds_rt_group_b) { memset(bdev->rds_info.rds_rt, 0, - sizeof(bdev->rds_info.rds_rt)); + sizeof(bdev->rds_info.rds_rt)); bdev->rds_info.rds_rt_group_b = rt_group_b; } @@ -1524,11 +1509,11 @@ static int bcm2048_parse_rt_match_b(struct bcm2048_device *bdev, int i) /* A to B or (vice versa), means: clear screen */ if (rt_ab != bdev->rds_info.rds_rt_ab) { memset(bdev->rds_info.rds_rt, 0, - sizeof(bdev->rds_info.rds_rt)); + sizeof(bdev->rds_info.rds_rt)); bdev->rds_info.rds_rt_ab = rt_ab; } - index = bdev->rds_info.radio_text[i+2] & + index = bdev->rds_info.radio_text[i + 2] & BCM2048_RDS_RT_INDEX; if (bdev->rds_info.rds_rt_group_b) @@ -1544,7 +1529,7 @@ static int bcm2048_parse_rt_match_b(struct bcm2048_device *bdev, int i) } static int bcm2048_parse_rt_match_c(struct bcm2048_device *bdev, int i, - int index) + int index) { int crc; @@ -1567,7 +1552,7 @@ static int bcm2048_parse_rt_match_c(struct bcm2048_device *bdev, int i, } static void bcm2048_parse_rt_match_d(struct bcm2048_device *bdev, int i, - int index) + int index) { int crc; @@ -1579,8 +1564,8 @@ static void bcm2048_parse_rt_match_d(struct bcm2048_device *bdev, int i, BUG_ON((index+4) >= BCM2048_MAX_RDS_RT); if ((bdev->rds_info.radio_text[i] & BCM2048_RDS_BLOCK_MASK) == - BCM2048_RDS_BLOCK_D) - bcm2048_parse_rds_rt_block(bdev, i, index+2, crc); + BCM2048_RDS_BLOCK_D) + bcm2048_parse_rds_rt_block(bdev, i, index + 2, crc); } static void bcm2048_parse_rds_rt(struct bcm2048_device *bdev) @@ -1588,7 +1573,6 @@ static void bcm2048_parse_rds_rt(struct bcm2048_device *bdev) int i, index = 0, crc, match_b = 0, match_c = 0, match_d = 0; for (i = 0; i < bdev->fifo_size; i += BCM2048_RDS_FIFO_DUPLE_SIZE) { - if (match_b) { match_b = 0; index = bcm2048_parse_rt_match_b(bdev, i); @@ -1607,40 +1591,41 @@ static void bcm2048_parse_rds_rt(struct bcm2048_device *bdev) } /* Skip erroneous blocks due to messed up A block altogether */ - if ((bdev->rds_info.radio_text[i] & BCM2048_RDS_BLOCK_MASK) - == BCM2048_RDS_BLOCK_A) { + if ((bdev->rds_info.radio_text[i] & BCM2048_RDS_BLOCK_MASK) == + BCM2048_RDS_BLOCK_A) { crc = bcm2048_rds_block_crc(bdev, i); if (crc == BCM2048_RDS_CRC_UNRECOVARABLE) continue; - /* Syncronize to a good RDS PI */ - if (((bdev->rds_info.radio_text[i+1] << 8) + - bdev->rds_info.radio_text[i+2]) == - bdev->rds_info.rds_pi) - match_b = 1; + /* Synchronize to a good RDS PI */ + if (((bdev->rds_info.radio_text[i + 1] << 8) + + bdev->rds_info.radio_text[i + 2]) == + bdev->rds_info.rds_pi) + match_b = 1; } } } static void bcm2048_parse_rds_ps_block(struct bcm2048_device *bdev, int i, - int index, int crc) + int index, int crc) { /* Good data will overwrite poor data */ if (crc) { if (!bdev->rds_info.rds_ps[index]) bdev->rds_info.rds_ps[index] = - bdev->rds_info.radio_text[i+1]; - if (!bdev->rds_info.rds_ps[index+1]) - bdev->rds_info.rds_ps[index+1] = - bdev->rds_info.radio_text[i+2]; + bdev->rds_info.radio_text[i + 1]; + if (!bdev->rds_info.rds_ps[index + 1]) + bdev->rds_info.rds_ps[index + 1] = + bdev->rds_info.radio_text[i + 2]; } else { - bdev->rds_info.rds_ps[index] = bdev->rds_info.radio_text[i+1]; - bdev->rds_info.rds_ps[index+1] = - bdev->rds_info.radio_text[i+2]; + bdev->rds_info.rds_ps[index] = + bdev->rds_info.radio_text[i + 1]; + bdev->rds_info.rds_ps[index + 1] = + bdev->rds_info.radio_text[i + 2]; } } static int bcm2048_parse_ps_match_c(struct bcm2048_device *bdev, int i, - int index) + int index) { int crc; @@ -1650,14 +1635,14 @@ static int bcm2048_parse_ps_match_c(struct bcm2048_device *bdev, int i, return 0; if ((bdev->rds_info.radio_text[i] & BCM2048_RDS_BLOCK_MASK) == - BCM2048_RDS_BLOCK_C) + BCM2048_RDS_BLOCK_C) return 1; return 0; } static void bcm2048_parse_ps_match_d(struct bcm2048_device *bdev, int i, - int index) + int index) { int crc; @@ -1667,7 +1652,7 @@ static void bcm2048_parse_ps_match_d(struct bcm2048_device *bdev, int i, return; if ((bdev->rds_info.radio_text[i] & BCM2048_RDS_BLOCK_MASK) == - BCM2048_RDS_BLOCK_D) + BCM2048_RDS_BLOCK_D) bcm2048_parse_rds_ps_block(bdev, i, index, crc); } @@ -1682,10 +1667,10 @@ static int bcm2048_parse_ps_match_b(struct bcm2048_device *bdev, int i) /* Block B Radio PS match */ if ((bdev->rds_info.radio_text[i] & BCM2048_RDS_BLOCK_MASK) == - BCM2048_RDS_BLOCK_B) { - ps_id = bdev->rds_info.radio_text[i+1] & + BCM2048_RDS_BLOCK_B) { + ps_id = bdev->rds_info.radio_text[i + 1] & BCM2048_RDS_BLOCK_MASK; - ps_group = bdev->rds_info.radio_text[i+1] & + ps_group = bdev->rds_info.radio_text[i + 1] & BCM2048_RDS_GROUP_AB_MASK; /* @@ -1709,7 +1694,7 @@ static int bcm2048_parse_ps_match_b(struct bcm2048_device *bdev, int i) } if (ps_id == BCM2048_RDS_PS) { - index = bdev->rds_info.radio_text[i+2] & + index = bdev->rds_info.radio_text[i + 2] & BCM2048_RDS_PS_INDEX; index <<= 1; return index; @@ -1724,7 +1709,6 @@ static void bcm2048_parse_rds_ps(struct bcm2048_device *bdev) int i, index = 0, crc, match_b = 0, match_c = 0, match_d = 0; for (i = 0; i < bdev->fifo_size; i += BCM2048_RDS_FIFO_DUPLE_SIZE) { - if (match_b) { match_b = 0; index = bcm2048_parse_ps_match_b(bdev, i); @@ -1743,16 +1727,16 @@ static void bcm2048_parse_rds_ps(struct bcm2048_device *bdev) } /* Skip erroneous blocks due to messed up A block altogether */ - if ((bdev->rds_info.radio_text[i] & BCM2048_RDS_BLOCK_MASK) - == BCM2048_RDS_BLOCK_A) { + if ((bdev->rds_info.radio_text[i] & BCM2048_RDS_BLOCK_MASK) == + BCM2048_RDS_BLOCK_A) { crc = bcm2048_rds_block_crc(bdev, i); if (crc == BCM2048_RDS_CRC_UNRECOVARABLE) continue; - /* Syncronize to a good RDS PI */ - if (((bdev->rds_info.radio_text[i+1] << 8) + - bdev->rds_info.radio_text[i+2]) == - bdev->rds_info.rds_pi) - match_b = 1; + /* Synchronize to a good RDS PI */ + if (((bdev->rds_info.radio_text[i + 1] << 8) + + bdev->rds_info.radio_text[i + 2]) == + bdev->rds_info.rds_pi) + match_b = 1; } } } @@ -1764,7 +1748,7 @@ static void bcm2048_rds_fifo_receive(struct bcm2048_device *bdev) mutex_lock(&bdev->mutex); err = bcm2048_recv_duples(bdev, BCM2048_I2C_RDS_DATA, - bdev->rds_info.radio_text, bdev->fifo_size); + bdev->rds_info.radio_text, bdev->fifo_size); if (err != 2) { dev_err(&bdev->client->dev, "RDS Read problem\n"); mutex_unlock(&bdev->mutex); @@ -1801,8 +1785,8 @@ static int bcm2048_get_rds_data(struct bcm2048_device *bdev, char *data) } for (i = 0; i < bdev->rds_info.text_len; i++) { - p += sprintf(data_buffer+p, "%x ", - bdev->rds_info.radio_text[i]); + p += sprintf(data_buffer + p, "%x ", + bdev->rds_info.radio_text[i]); } memcpy(data, data_buffer, p); @@ -1829,7 +1813,7 @@ static int bcm2048_init(struct bcm2048_device *bdev) goto exit; err = bcm2048_set_dac_output(bdev, BCM2048_DAC_OUTPUT_LEFT | - BCM2048_DAC_OUTPUT_RIGHT); + BCM2048_DAC_OUTPUT_RIGHT); exit: return err; @@ -1921,7 +1905,6 @@ static void bcm2048_work(struct work_struct *work) if (flag_lsb & (BCM2048_FM_FLAG_SEARCH_TUNE_FINISHED | BCM2048_FM_FLAG_SEARCH_TUNE_FAIL)) { - if (flag_lsb & BCM2048_FM_FLAG_SEARCH_TUNE_FAIL) bdev->scan_state = BCM2048_SCAN_FAIL; else @@ -1935,7 +1918,7 @@ static void bcm2048_work(struct work_struct *work) if (bdev->rds_state) { flags = BCM2048_RDS_FLAG_FIFO_WLINE; bcm2048_send_command(bdev, BCM2048_I2C_FM_RDS_MASK1, - flags); + flags); } bdev->rds_data_available = 1; bdev->rd_index = 0; /* new data, new start */ @@ -2074,7 +2057,7 @@ property_str_read(rds_rt, (BCM2048_MAX_RDS_RT + 1)) property_str_read(rds_ps, (BCM2048_MAX_RDS_PS + 1)) property_read(fm_rds_flags, unsigned int, "%u") -property_str_read(rds_data, BCM2048_MAX_RDS_RADIO_TEXT*5) +property_str_read(rds_data, BCM2048_MAX_RDS_RADIO_TEXT * 5) property_read(region_bottom_frequency, unsigned int, "%u") property_read(region_top_frequency, unsigned int, "%u") @@ -2084,70 +2067,70 @@ DEFINE_SYSFS_PROPERTY(region, unsigned, int, "%u", 0) static struct device_attribute attrs[] = { __ATTR(power_state, S_IRUGO | S_IWUSR, bcm2048_power_state_read, - bcm2048_power_state_write), + bcm2048_power_state_write), __ATTR(mute, S_IRUGO | S_IWUSR, bcm2048_mute_read, - bcm2048_mute_write), + bcm2048_mute_write), __ATTR(audio_route, S_IRUGO | S_IWUSR, bcm2048_audio_route_read, - bcm2048_audio_route_write), + bcm2048_audio_route_write), __ATTR(dac_output, S_IRUGO | S_IWUSR, bcm2048_dac_output_read, - bcm2048_dac_output_write), + bcm2048_dac_output_write), __ATTR(fm_hi_lo_injection, S_IRUGO | S_IWUSR, - bcm2048_fm_hi_lo_injection_read, - bcm2048_fm_hi_lo_injection_write), + bcm2048_fm_hi_lo_injection_read, + bcm2048_fm_hi_lo_injection_write), __ATTR(fm_frequency, S_IRUGO | S_IWUSR, bcm2048_fm_frequency_read, - bcm2048_fm_frequency_write), + bcm2048_fm_frequency_write), __ATTR(fm_af_frequency, S_IRUGO | S_IWUSR, - bcm2048_fm_af_frequency_read, - bcm2048_fm_af_frequency_write), + bcm2048_fm_af_frequency_read, + bcm2048_fm_af_frequency_write), __ATTR(fm_deemphasis, S_IRUGO | S_IWUSR, bcm2048_fm_deemphasis_read, - bcm2048_fm_deemphasis_write), + bcm2048_fm_deemphasis_write), __ATTR(fm_rds_mask, S_IRUGO | S_IWUSR, bcm2048_fm_rds_mask_read, - bcm2048_fm_rds_mask_write), + bcm2048_fm_rds_mask_write), __ATTR(fm_best_tune_mode, S_IRUGO | S_IWUSR, - bcm2048_fm_best_tune_mode_read, - bcm2048_fm_best_tune_mode_write), + bcm2048_fm_best_tune_mode_read, + bcm2048_fm_best_tune_mode_write), __ATTR(fm_search_rssi_threshold, S_IRUGO | S_IWUSR, - bcm2048_fm_search_rssi_threshold_read, - bcm2048_fm_search_rssi_threshold_write), + bcm2048_fm_search_rssi_threshold_read, + bcm2048_fm_search_rssi_threshold_write), __ATTR(fm_search_mode_direction, S_IRUGO | S_IWUSR, - bcm2048_fm_search_mode_direction_read, - bcm2048_fm_search_mode_direction_write), + bcm2048_fm_search_mode_direction_read, + bcm2048_fm_search_mode_direction_write), __ATTR(fm_search_tune_mode, S_IRUGO | S_IWUSR, - bcm2048_fm_search_tune_mode_read, - bcm2048_fm_search_tune_mode_write), + bcm2048_fm_search_tune_mode_read, + bcm2048_fm_search_tune_mode_write), __ATTR(rds, S_IRUGO | S_IWUSR, bcm2048_rds_read, - bcm2048_rds_write), + bcm2048_rds_write), __ATTR(rds_b_block_mask, S_IRUGO | S_IWUSR, - bcm2048_rds_b_block_mask_read, - bcm2048_rds_b_block_mask_write), + bcm2048_rds_b_block_mask_read, + bcm2048_rds_b_block_mask_write), __ATTR(rds_b_block_match, S_IRUGO | S_IWUSR, - bcm2048_rds_b_block_match_read, - bcm2048_rds_b_block_match_write), + bcm2048_rds_b_block_match_read, + bcm2048_rds_b_block_match_write), __ATTR(rds_pi_mask, S_IRUGO | S_IWUSR, bcm2048_rds_pi_mask_read, - bcm2048_rds_pi_mask_write), + bcm2048_rds_pi_mask_write), __ATTR(rds_pi_match, S_IRUGO | S_IWUSR, bcm2048_rds_pi_match_read, - bcm2048_rds_pi_match_write), + bcm2048_rds_pi_match_write), __ATTR(rds_wline, S_IRUGO | S_IWUSR, bcm2048_rds_wline_read, - bcm2048_rds_wline_write), + bcm2048_rds_wline_write), __ATTR(rds_pi, S_IRUGO, bcm2048_rds_pi_read, NULL), __ATTR(rds_rt, S_IRUGO, bcm2048_rds_rt_read, NULL), __ATTR(rds_ps, S_IRUGO, bcm2048_rds_ps_read, NULL), __ATTR(fm_rds_flags, S_IRUGO, bcm2048_fm_rds_flags_read, NULL), __ATTR(region_bottom_frequency, S_IRUGO, - bcm2048_region_bottom_frequency_read, NULL), + bcm2048_region_bottom_frequency_read, NULL), __ATTR(region_top_frequency, S_IRUGO, - bcm2048_region_top_frequency_read, NULL), + bcm2048_region_top_frequency_read, NULL), __ATTR(fm_carrier_error, S_IRUGO, - bcm2048_fm_carrier_error_read, NULL), + bcm2048_fm_carrier_error_read, NULL), __ATTR(fm_rssi, S_IRUGO, - bcm2048_fm_rssi_read, NULL), + bcm2048_fm_rssi_read, NULL), __ATTR(region, S_IRUGO | S_IWUSR, bcm2048_region_read, - bcm2048_region_write), + bcm2048_region_write), __ATTR(rds_data, S_IRUGO, bcm2048_rds_data_read, NULL), }; static int bcm2048_sysfs_unregister_properties(struct bcm2048_device *bdev, - int size) + int size) { int i; @@ -2165,7 +2148,7 @@ static int bcm2048_sysfs_register_properties(struct bcm2048_device *bdev) for (i = 0; i < ARRAY_SIZE(attrs); i++) { if (device_create_file(&bdev->client->dev, &attrs[i]) != 0) { dev_err(&bdev->client->dev, - "could not register sysfs entry\n"); + "could not register sysfs entry\n"); err = -EBUSY; bcm2048_sysfs_unregister_properties(bdev, i); break; @@ -2175,7 +2158,6 @@ static int bcm2048_sysfs_register_properties(struct bcm2048_device *bdev) return err; } - static int bcm2048_fops_open(struct file *file) { struct bcm2048_device *bdev = video_drvdata(file); @@ -2197,7 +2179,7 @@ static int bcm2048_fops_release(struct file *file) } static unsigned int bcm2048_fops_poll(struct file *file, - struct poll_table_struct *pts) + struct poll_table_struct *pts) { struct bcm2048_device *bdev = video_drvdata(file); int retval = 0; @@ -2211,7 +2193,7 @@ static unsigned int bcm2048_fops_poll(struct file *file, } static ssize_t bcm2048_fops_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) + size_t count, loff_t *ppos) { struct bcm2048_device *bdev = video_drvdata(file); int i; @@ -2229,7 +2211,7 @@ static ssize_t bcm2048_fops_read(struct file *file, char __user *buf, } /* interruptible_sleep_on(&bdev->read_queue); */ if (wait_event_interruptible(bdev->read_queue, - bdev->rds_data_available) < 0) { + bdev->rds_data_available) < 0) { retval = -EINTR; goto done; } @@ -2245,13 +2227,16 @@ static ssize_t bcm2048_fops_read(struct file *file, char __user *buf, while (i < count) { unsigned char tmpbuf[3]; - tmpbuf[i] = bdev->rds_info.radio_text[bdev->rd_index+i+2]; - tmpbuf[i+1] = bdev->rds_info.radio_text[bdev->rd_index+i+1]; - tmpbuf[i+2] = (bdev->rds_info.radio_text[bdev->rd_index + i] & 0xf0) >> 4; - if ((bdev->rds_info.radio_text[bdev->rd_index+i] & - BCM2048_RDS_CRC_MASK) == BCM2048_RDS_CRC_UNRECOVARABLE) - tmpbuf[i+2] |= 0x80; - if (copy_to_user(buf+i, tmpbuf, 3)) { + tmpbuf[i] = bdev->rds_info.radio_text[bdev->rd_index + i + 2]; + tmpbuf[i + 1] = + bdev->rds_info.radio_text[bdev->rd_index + i + 1]; + tmpbuf[i + 2] = + (bdev->rds_info.radio_text[bdev->rd_index + i] & + 0xf0) >> 4; + if ((bdev->rds_info.radio_text[bdev->rd_index + i] & + BCM2048_RDS_CRC_MASK) == BCM2048_RDS_CRC_UNRECOVARABLE) + tmpbuf[i + 2] |= 0x80; + if (copy_to_user(buf + i, tmpbuf, 3)) { retval = -EFAULT; break; } @@ -2319,7 +2304,7 @@ static struct v4l2_queryctrl bcm2048_v4l2_queryctrl[] = { }; static int bcm2048_vidioc_querycap(struct file *file, void *priv, - struct v4l2_capability *capability) + struct v4l2_capability *capability) { struct bcm2048_device *bdev = video_get_drvdata(video_devdata(file)); @@ -2337,7 +2322,7 @@ static int bcm2048_vidioc_querycap(struct file *file, void *priv, } static int bcm2048_vidioc_g_input(struct file *filp, void *priv, - unsigned int *i) + unsigned int *i) { *i = 0; @@ -2345,7 +2330,7 @@ static int bcm2048_vidioc_g_input(struct file *filp, void *priv, } static int bcm2048_vidioc_s_input(struct file *filp, void *priv, - unsigned int i) + unsigned int i) { if (i) return -EINVAL; @@ -2354,7 +2339,7 @@ static int bcm2048_vidioc_s_input(struct file *filp, void *priv, } static int bcm2048_vidioc_queryctrl(struct file *file, void *priv, - struct v4l2_queryctrl *qc) + struct v4l2_queryctrl *qc) { int i; @@ -2369,7 +2354,7 @@ static int bcm2048_vidioc_queryctrl(struct file *file, void *priv, } static int bcm2048_vidioc_g_ctrl(struct file *file, void *priv, - struct v4l2_control *ctrl) + struct v4l2_control *ctrl) { struct bcm2048_device *bdev = video_get_drvdata(video_devdata(file)); int err = 0; @@ -2389,7 +2374,7 @@ static int bcm2048_vidioc_g_ctrl(struct file *file, void *priv, } static int bcm2048_vidioc_s_ctrl(struct file *file, void *priv, - struct v4l2_control *ctrl) + struct v4l2_control *ctrl) { struct bcm2048_device *bdev = video_get_drvdata(video_devdata(file)); int err = 0; @@ -2417,7 +2402,7 @@ static int bcm2048_vidioc_s_ctrl(struct file *file, void *priv, } static int bcm2048_vidioc_g_audio(struct file *file, void *priv, - struct v4l2_audio *audio) + struct v4l2_audio *audio) { if (audio->index > 1) return -EINVAL; @@ -2429,7 +2414,7 @@ static int bcm2048_vidioc_g_audio(struct file *file, void *priv, } static int bcm2048_vidioc_s_audio(struct file *file, void *priv, - const struct v4l2_audio *audio) + const struct v4l2_audio *audio) { if (audio->index != 0) return -EINVAL; @@ -2438,7 +2423,7 @@ static int bcm2048_vidioc_s_audio(struct file *file, void *priv, } static int bcm2048_vidioc_g_tuner(struct file *file, void *priv, - struct v4l2_tuner *tuner) + struct v4l2_tuner *tuner) { struct bcm2048_device *bdev = video_get_drvdata(video_devdata(file)); s8 f_error; @@ -2493,7 +2478,7 @@ static int bcm2048_vidioc_g_tuner(struct file *file, void *priv, } static int bcm2048_vidioc_s_tuner(struct file *file, void *priv, - const struct v4l2_tuner *tuner) + const struct v4l2_tuner *tuner) { struct bcm2048_device *bdev = video_get_drvdata(video_devdata(file)); @@ -2507,7 +2492,7 @@ static int bcm2048_vidioc_s_tuner(struct file *file, void *priv, } static int bcm2048_vidioc_g_frequency(struct file *file, void *priv, - struct v4l2_frequency *freq) + struct v4l2_frequency *freq) { struct bcm2048_device *bdev = video_get_drvdata(video_devdata(file)); int err = 0; @@ -2528,7 +2513,7 @@ static int bcm2048_vidioc_g_frequency(struct file *file, void *priv, } static int bcm2048_vidioc_s_frequency(struct file *file, void *priv, - const struct v4l2_frequency *freq) + const struct v4l2_frequency *freq) { struct bcm2048_device *bdev = video_get_drvdata(video_devdata(file)); int err; @@ -2546,7 +2531,7 @@ static int bcm2048_vidioc_s_frequency(struct file *file, void *priv, } static int bcm2048_vidioc_s_hw_freq_seek(struct file *file, void *priv, - const struct v4l2_hw_freq_seek *seek) + const struct v4l2_hw_freq_seek *seek) { struct bcm2048_device *bdev = video_get_drvdata(video_devdata(file)); int err; @@ -2559,7 +2544,7 @@ static int bcm2048_vidioc_s_hw_freq_seek(struct file *file, void *priv, err = bcm2048_set_fm_search_mode_direction(bdev, seek->seek_upward); err |= bcm2048_set_fm_search_tune_mode(bdev, - BCM2048_FM_AUTO_SEARCH_MODE); + BCM2048_FM_AUTO_SEARCH_MODE); return err; } @@ -2594,7 +2579,7 @@ static struct video_device bcm2048_viddev_template = { * I2C driver interface */ static int bcm2048_i2c_driver_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { struct bcm2048_device *bdev; int err; @@ -2613,8 +2598,8 @@ static int bcm2048_i2c_driver_probe(struct i2c_client *client, if (client->irq) { err = request_irq(client->irq, - bcm2048_handler, IRQF_TRIGGER_FALLING, - client->name, bdev); + bcm2048_handler, IRQF_TRIGGER_FALLING, + client->name, bdev); if (err < 0) { dev_err(&client->dev, "Could not request IRQ\n"); goto free_bdev; diff --git a/drivers/staging/most/aim-network/networking.h b/drivers/staging/most/aim-network/networking.h index 1b8b434fabb0..6f346d410525 100644 --- a/drivers/staging/most/aim-network/networking.h +++ b/drivers/staging/most/aim-network/networking.h @@ -15,9 +15,7 @@ #include "mostcore.h" - void most_deliver_netinfo(struct most_interface *iface, unsigned char link_stat, unsigned char *mac_addr); - #endif diff --git a/drivers/staging/most/hdm-dim2/dim2_errors.h b/drivers/staging/most/hdm-dim2/dim2_errors.h index 314f7de2be73..5a713df1d1d4 100644 --- a/drivers/staging/most/hdm-dim2/dim2_errors.h +++ b/drivers/staging/most/hdm-dim2/dim2_errors.h @@ -19,7 +19,6 @@ extern "C" { #endif - /** * MOST DIM errors. */ @@ -59,7 +58,6 @@ enum dim_errors_t { DIM_ERR_OVERFLOW, }; - #ifdef __cplusplus } #endif diff --git a/drivers/staging/most/hdm-dim2/dim2_hal.c b/drivers/staging/most/hdm-dim2/dim2_hal.c index c915c44f025e..172257596f1f 100644 --- a/drivers/staging/most/hdm-dim2/dim2_hal.c +++ b/drivers/staging/most/hdm-dim2/dim2_hal.c @@ -74,7 +74,7 @@ static inline u32 bit_mask(u8 position) static inline bool dim_on_error(u8 error_id, const char *error_message) { - DIMCB_OnError(error_id, error_message); + dimcb_on_error(error_id, error_message); return false; } @@ -151,44 +151,44 @@ static void free_dbr(int offs, int size) static u32 dim2_read_ctr(u32 ctr_addr, u16 mdat_idx) { - DIMCB_IoWrite(&g.dim2->MADR, ctr_addr); + dimcb_io_write(&g.dim2->MADR, ctr_addr); /* wait till transfer is completed */ - while ((DIMCB_IoRead(&g.dim2->MCTL) & 1) != 1) + while ((dimcb_io_read(&g.dim2->MCTL) & 1) != 1) continue; - DIMCB_IoWrite(&g.dim2->MCTL, 0); /* clear transfer complete */ + dimcb_io_write(&g.dim2->MCTL, 0); /* clear transfer complete */ - return DIMCB_IoRead((&g.dim2->MDAT0) + mdat_idx); + return dimcb_io_read((&g.dim2->MDAT0) + mdat_idx); } static void dim2_write_ctr_mask(u32 ctr_addr, const u32 *mask, const u32 *value) { enum { MADR_WNR_BIT = 31 }; - DIMCB_IoWrite(&g.dim2->MCTL, 0); /* clear transfer complete */ + dimcb_io_write(&g.dim2->MCTL, 0); /* clear transfer complete */ if (mask[0] != 0) - DIMCB_IoWrite(&g.dim2->MDAT0, value[0]); + dimcb_io_write(&g.dim2->MDAT0, value[0]); if (mask[1] != 0) - DIMCB_IoWrite(&g.dim2->MDAT1, value[1]); + dimcb_io_write(&g.dim2->MDAT1, value[1]); if (mask[2] != 0) - DIMCB_IoWrite(&g.dim2->MDAT2, value[2]); + dimcb_io_write(&g.dim2->MDAT2, value[2]); if (mask[3] != 0) - DIMCB_IoWrite(&g.dim2->MDAT3, value[3]); + dimcb_io_write(&g.dim2->MDAT3, value[3]); - DIMCB_IoWrite(&g.dim2->MDWE0, mask[0]); - DIMCB_IoWrite(&g.dim2->MDWE1, mask[1]); - DIMCB_IoWrite(&g.dim2->MDWE2, mask[2]); - DIMCB_IoWrite(&g.dim2->MDWE3, mask[3]); + dimcb_io_write(&g.dim2->MDWE0, mask[0]); + dimcb_io_write(&g.dim2->MDWE1, mask[1]); + dimcb_io_write(&g.dim2->MDWE2, mask[2]); + dimcb_io_write(&g.dim2->MDWE3, mask[3]); - DIMCB_IoWrite(&g.dim2->MADR, bit_mask(MADR_WNR_BIT) | ctr_addr); + dimcb_io_write(&g.dim2->MADR, bit_mask(MADR_WNR_BIT) | ctr_addr); /* wait till transfer is completed */ - while ((DIMCB_IoRead(&g.dim2->MCTL) & 1) != 1) + while ((dimcb_io_read(&g.dim2->MCTL) & 1) != 1) continue; - DIMCB_IoWrite(&g.dim2->MCTL, 0); /* clear transfer complete */ + dimcb_io_write(&g.dim2->MCTL, 0); /* clear transfer complete */ } static inline void dim2_write_ctr(u32 ctr_addr, const u32 *value) @@ -341,15 +341,15 @@ static void dim2_configure_channel( dim2_configure_cat(AHB_CAT, ch_addr, type, is_tx ? 0 : 1, sync_mfe); /* unmask interrupt for used channel, enable mlb_sys_int[0] interrupt */ - DIMCB_IoWrite(&g.dim2->ACMR0, - DIMCB_IoRead(&g.dim2->ACMR0) | bit_mask(ch_addr)); + dimcb_io_write(&g.dim2->ACMR0, + dimcb_io_read(&g.dim2->ACMR0) | bit_mask(ch_addr)); } static void dim2_clear_channel(u8 ch_addr) { /* mask interrupt for used channel, disable mlb_sys_int[0] interrupt */ - DIMCB_IoWrite(&g.dim2->ACMR0, - DIMCB_IoRead(&g.dim2->ACMR0) & ~bit_mask(ch_addr)); + dimcb_io_write(&g.dim2->ACMR0, + dimcb_io_read(&g.dim2->ACMR0) & ~bit_mask(ch_addr)); dim2_clear_cat(AHB_CAT, ch_addr); dim2_clear_adt(ch_addr); @@ -455,20 +455,20 @@ static inline u16 norm_sync_buffer_size(u16 buf_size, u16 bytes_per_frame) static void dim2_cleanup(void) { /* disable MediaLB */ - DIMCB_IoWrite(&g.dim2->MLBC0, false << MLBC0_MLBEN_BIT); + dimcb_io_write(&g.dim2->MLBC0, false << MLBC0_MLBEN_BIT); dim2_clear_ctram(); /* disable mlb_int interrupt */ - DIMCB_IoWrite(&g.dim2->MIEN, 0); + dimcb_io_write(&g.dim2->MIEN, 0); /* clear status for all dma channels */ - DIMCB_IoWrite(&g.dim2->ACSR0, 0xFFFFFFFF); - DIMCB_IoWrite(&g.dim2->ACSR1, 0xFFFFFFFF); + dimcb_io_write(&g.dim2->ACSR0, 0xFFFFFFFF); + dimcb_io_write(&g.dim2->ACSR1, 0xFFFFFFFF); /* mask interrupts for all channels */ - DIMCB_IoWrite(&g.dim2->ACMR0, 0); - DIMCB_IoWrite(&g.dim2->ACMR1, 0); + dimcb_io_write(&g.dim2->ACMR0, 0); + dimcb_io_write(&g.dim2->ACMR1, 0); } static void dim2_initialize(bool enable_6pin, u8 mlb_clock) @@ -476,23 +476,23 @@ static void dim2_initialize(bool enable_6pin, u8 mlb_clock) dim2_cleanup(); /* configure and enable MediaLB */ - DIMCB_IoWrite(&g.dim2->MLBC0, - enable_6pin << MLBC0_MLBPEN_BIT | - mlb_clock << MLBC0_MLBCLK_SHIFT | - MLBC0_FCNT_VAL(FRAMES_PER_SUBBUFF) << MLBC0_FCNT_SHIFT | - true << MLBC0_MLBEN_BIT); + dimcb_io_write(&g.dim2->MLBC0, + enable_6pin << MLBC0_MLBPEN_BIT | + mlb_clock << MLBC0_MLBCLK_SHIFT | + MLBC0_FCNT_VAL(FRAMES_PER_SUBBUFF) << MLBC0_FCNT_SHIFT | + true << MLBC0_MLBEN_BIT); /* activate all HBI channels */ - DIMCB_IoWrite(&g.dim2->HCMR0, 0xFFFFFFFF); - DIMCB_IoWrite(&g.dim2->HCMR1, 0xFFFFFFFF); + dimcb_io_write(&g.dim2->HCMR0, 0xFFFFFFFF); + dimcb_io_write(&g.dim2->HCMR1, 0xFFFFFFFF); /* enable HBI */ - DIMCB_IoWrite(&g.dim2->HCTL, bit_mask(HCTL_EN_BIT)); + dimcb_io_write(&g.dim2->HCTL, bit_mask(HCTL_EN_BIT)); /* configure DMA */ - DIMCB_IoWrite(&g.dim2->ACTL, - ACTL_DMA_MODE_VAL_DMA_MODE_1 << ACTL_DMA_MODE_BIT | - true << ACTL_SCE_BIT); + dimcb_io_write(&g.dim2->ACTL, + ACTL_DMA_MODE_VAL_DMA_MODE_1 << ACTL_DMA_MODE_BIT | + true << ACTL_SCE_BIT); } static bool dim2_is_mlb_locked(void) @@ -500,12 +500,12 @@ static bool dim2_is_mlb_locked(void) u32 const mask0 = bit_mask(MLBC0_MLBLK_BIT); u32 const mask1 = bit_mask(MLBC1_CLKMERR_BIT) | bit_mask(MLBC1_LOCKERR_BIT); - u32 const c1 = DIMCB_IoRead(&g.dim2->MLBC1); + u32 const c1 = dimcb_io_read(&g.dim2->MLBC1); u32 const nda_mask = (u32)MLBC1_NDA_MASK << MLBC1_NDA_SHIFT; - DIMCB_IoWrite(&g.dim2->MLBC1, c1 & nda_mask); - return (DIMCB_IoRead(&g.dim2->MLBC1) & mask1) == 0 && - (DIMCB_IoRead(&g.dim2->MLBC0) & mask0) != 0; + dimcb_io_write(&g.dim2->MLBC1, c1 & nda_mask); + return (dimcb_io_read(&g.dim2->MLBC1) & mask1) == 0 && + (dimcb_io_read(&g.dim2->MLBC0) & mask0) != 0; } /* -------------------------------------------------------------------------- */ @@ -531,7 +531,7 @@ static inline bool service_channel(u8 ch_addr, u8 idx) } /* clear channel status bit */ - DIMCB_IoWrite(&g.dim2->ACSR0, bit_mask(ch_addr)); + dimcb_io_write(&g.dim2->ACSR0, bit_mask(ch_addr)); return true; } @@ -650,7 +650,7 @@ static bool channel_detach_buffers(struct dim_channel *ch, u16 buffers_number) /* -------------------------------------------------------------------------- */ /* API */ -u8 DIM_Startup(void *dim_base_address, u32 mlb_clock) +u8 dim_startup(void *dim_base_address, u32 mlb_clock) { g.dim_is_initialized = false; @@ -673,13 +673,13 @@ u8 DIM_Startup(void *dim_base_address, u32 mlb_clock) return DIM_NO_ERROR; } -void DIM_Shutdown(void) +void dim_shutdown(void) { g.dim_is_initialized = false; dim2_cleanup(); } -bool DIM_GetLockState(void) +bool dim_get_lock_state(void) { return dim2_is_mlb_locked(); } @@ -706,7 +706,7 @@ static u8 init_ctrl_async(struct dim_channel *ch, u8 type, u8 is_tx, return DIM_NO_ERROR; } -u16 DIM_NormCtrlAsyncBufferSize(u16 buf_size) +u16 dim_norm_ctrl_async_buffer_size(u16 buf_size) { return norm_ctrl_async_buffer_size(buf_size); } @@ -717,7 +717,7 @@ u16 DIM_NormCtrlAsyncBufferSize(u16 buf_size) * * Returns non-zero correct buffer size or zero by error. */ -u16 DIM_NormIsocBufferSize(u16 buf_size, u16 packet_length) +u16 dim_norm_isoc_buffer_size(u16 buf_size, u16 packet_length) { if (!check_packet_length(packet_length)) return 0; @@ -731,7 +731,7 @@ u16 DIM_NormIsocBufferSize(u16 buf_size, u16 packet_length) * * Returns non-zero correct buffer size or zero by error. */ -u16 DIM_NormSyncBufferSize(u16 buf_size, u16 bytes_per_frame) +u16 dim_norm_sync_buffer_size(u16 buf_size, u16 bytes_per_frame) { if (!check_bytes_per_frame(bytes_per_frame)) return 0; @@ -739,22 +739,22 @@ u16 DIM_NormSyncBufferSize(u16 buf_size, u16 bytes_per_frame) return norm_sync_buffer_size(buf_size, bytes_per_frame); } -u8 DIM_InitControl(struct dim_channel *ch, u8 is_tx, u16 ch_address, - u16 max_buffer_size) +u8 dim_init_control(struct dim_channel *ch, u8 is_tx, u16 ch_address, + u16 max_buffer_size) { return init_ctrl_async(ch, CAT_CT_VAL_CONTROL, is_tx, ch_address, max_buffer_size); } -u8 DIM_InitAsync(struct dim_channel *ch, u8 is_tx, u16 ch_address, - u16 max_buffer_size) +u8 dim_init_async(struct dim_channel *ch, u8 is_tx, u16 ch_address, + u16 max_buffer_size) { return init_ctrl_async(ch, CAT_CT_VAL_ASYNC, is_tx, ch_address, max_buffer_size); } -u8 DIM_InitIsoc(struct dim_channel *ch, u8 is_tx, u16 ch_address, - u16 packet_length) +u8 dim_init_isoc(struct dim_channel *ch, u8 is_tx, u16 ch_address, + u16 packet_length) { if (!g.dim_is_initialized || !ch) return DIM_ERR_DRIVER_NOT_INITIALIZED; @@ -778,8 +778,8 @@ u8 DIM_InitIsoc(struct dim_channel *ch, u8 is_tx, u16 ch_address, return DIM_NO_ERROR; } -u8 DIM_InitSync(struct dim_channel *ch, u8 is_tx, u16 ch_address, - u16 bytes_per_frame) +u8 dim_init_sync(struct dim_channel *ch, u8 is_tx, u16 ch_address, + u16 bytes_per_frame) { if (!g.dim_is_initialized || !ch) return DIM_ERR_DRIVER_NOT_INITIALIZED; @@ -803,7 +803,7 @@ u8 DIM_InitSync(struct dim_channel *ch, u8 is_tx, u16 ch_address, return DIM_NO_ERROR; } -u8 DIM_DestroyChannel(struct dim_channel *ch) +u8 dim_destroy_channel(struct dim_channel *ch) { if (!g.dim_is_initialized || !ch) return DIM_ERR_DRIVER_NOT_INITIALIZED; @@ -816,7 +816,7 @@ u8 DIM_DestroyChannel(struct dim_channel *ch) return DIM_NO_ERROR; } -void DIM_ServiceIrq(struct dim_channel *const *channels) +void dim_service_irq(struct dim_channel *const *channels) { bool state_changed; @@ -850,11 +850,11 @@ void DIM_ServiceIrq(struct dim_channel *const *channels) } while (state_changed); /* clear pending Interrupts */ - DIMCB_IoWrite(&g.dim2->MS0, 0); - DIMCB_IoWrite(&g.dim2->MS1, 0); + dimcb_io_write(&g.dim2->MS0, 0); + dimcb_io_write(&g.dim2->MS1, 0); } -u8 DIM_ServiceChannel(struct dim_channel *ch) +u8 dim_service_channel(struct dim_channel *ch) { if (!g.dim_is_initialized || !ch) return DIM_ERR_DRIVER_NOT_INITIALIZED; @@ -862,8 +862,8 @@ u8 DIM_ServiceChannel(struct dim_channel *ch) return channel_service(ch); } -struct dim_ch_state_t *DIM_GetChannelState(struct dim_channel *ch, - struct dim_ch_state_t *state_ptr) +struct dim_ch_state_t *dim_get_channel_state(struct dim_channel *ch, + struct dim_ch_state_t *state_ptr) { if (!ch || !state_ptr) return NULL; @@ -874,7 +874,8 @@ struct dim_ch_state_t *DIM_GetChannelState(struct dim_channel *ch, return state_ptr; } -bool DIM_EnqueueBuffer(struct dim_channel *ch, u32 buffer_addr, u16 buffer_size) +bool dim_enqueue_buffer(struct dim_channel *ch, u32 buffer_addr, + u16 buffer_size) { if (!ch) return dim_on_error(DIM_ERR_DRIVER_NOT_INITIALIZED, @@ -883,7 +884,7 @@ bool DIM_EnqueueBuffer(struct dim_channel *ch, u32 buffer_addr, u16 buffer_size) return channel_start(ch, buffer_addr, buffer_size); } -bool DIM_DetachBuffers(struct dim_channel *ch, u16 buffers_number) +bool dim_detach_buffers(struct dim_channel *ch, u16 buffers_number) { if (!ch) return dim_on_error(DIM_ERR_DRIVER_NOT_INITIALIZED, diff --git a/drivers/staging/most/hdm-dim2/dim2_hal.h b/drivers/staging/most/hdm-dim2/dim2_hal.h index ebb7d87a45fc..48cdd9c8cde1 100644 --- a/drivers/staging/most/hdm-dim2/dim2_hal.h +++ b/drivers/staging/most/hdm-dim2/dim2_hal.h @@ -17,7 +17,6 @@ #include <linux/types.h> - #ifdef __cplusplus extern "C" { #endif @@ -66,51 +65,49 @@ struct dim_channel { u16 done_sw_buffers_number; /*< Done software buffers number. */ }; +u8 dim_startup(void *dim_base_address, u32 mlb_clock); -u8 DIM_Startup(void *dim_base_address, u32 mlb_clock); - -void DIM_Shutdown(void); - -bool DIM_GetLockState(void); +void dim_shutdown(void); -u16 DIM_NormCtrlAsyncBufferSize(u16 buf_size); +bool dim_get_lock_state(void); -u16 DIM_NormIsocBufferSize(u16 buf_size, u16 packet_length); +u16 dim_norm_ctrl_async_buffer_size(u16 buf_size); -u16 DIM_NormSyncBufferSize(u16 buf_size, u16 bytes_per_frame); +u16 dim_norm_isoc_buffer_size(u16 buf_size, u16 packet_length); -u8 DIM_InitControl(struct dim_channel *ch, u8 is_tx, u16 ch_address, - u16 max_buffer_size); +u16 dim_norm_sync_buffer_size(u16 buf_size, u16 bytes_per_frame); -u8 DIM_InitAsync(struct dim_channel *ch, u8 is_tx, u16 ch_address, - u16 max_buffer_size); +u8 dim_init_control(struct dim_channel *ch, u8 is_tx, u16 ch_address, + u16 max_buffer_size); -u8 DIM_InitIsoc(struct dim_channel *ch, u8 is_tx, u16 ch_address, - u16 packet_length); +u8 dim_init_async(struct dim_channel *ch, u8 is_tx, u16 ch_address, + u16 max_buffer_size); -u8 DIM_InitSync(struct dim_channel *ch, u8 is_tx, u16 ch_address, - u16 bytes_per_frame); +u8 dim_init_isoc(struct dim_channel *ch, u8 is_tx, u16 ch_address, + u16 packet_length); -u8 DIM_DestroyChannel(struct dim_channel *ch); +u8 dim_init_sync(struct dim_channel *ch, u8 is_tx, u16 ch_address, + u16 bytes_per_frame); -void DIM_ServiceIrq(struct dim_channel *const *channels); +u8 dim_destroy_channel(struct dim_channel *ch); -u8 DIM_ServiceChannel(struct dim_channel *ch); +void dim_service_irq(struct dim_channel *const *channels); -struct dim_ch_state_t *DIM_GetChannelState(struct dim_channel *ch, - struct dim_ch_state_t *dim_ch_state_ptr); +u8 dim_service_channel(struct dim_channel *ch); -bool DIM_EnqueueBuffer(struct dim_channel *ch, u32 buffer_addr, - u16 buffer_size); +struct dim_ch_state_t *dim_get_channel_state(struct dim_channel *ch, + struct dim_ch_state_t *state_ptr); -bool DIM_DetachBuffers(struct dim_channel *ch, u16 buffers_number); +bool dim_enqueue_buffer(struct dim_channel *ch, u32 buffer_addr, + u16 buffer_size); -u32 DIMCB_IoRead(u32 *ptr32); +bool dim_detach_buffers(struct dim_channel *ch, u16 buffers_number); -void DIMCB_IoWrite(u32 *ptr32, u32 value); +u32 dimcb_io_read(u32 *ptr32); -void DIMCB_OnError(u8 error_id, const char *error_message); +void dimcb_io_write(u32 *ptr32, u32 value); +void dimcb_on_error(u8 error_id, const char *error_message); #ifdef __cplusplus } diff --git a/drivers/staging/most/hdm-dim2/dim2_hdm.c b/drivers/staging/most/hdm-dim2/dim2_hdm.c index b6fe346f73b0..327d738c7194 100644 --- a/drivers/staging/most/hdm-dim2/dim2_hdm.c +++ b/drivers/staging/most/hdm-dim2/dim2_hdm.c @@ -73,8 +73,8 @@ struct hdm_channel { char name[sizeof "caNNN"]; bool is_initialized; struct dim_channel ch; - struct list_head pending_list; /* before DIM_EnqueueBuffer() */ - struct list_head started_list; /* after DIM_EnqueueBuffer() */ + struct list_head pending_list; /* before dim_enqueue_buffer() */ + struct list_head started_list; /* after dim_enqueue_buffer() */ enum most_channel_direction direction; enum most_channel_data_type data_type; }; @@ -128,40 +128,40 @@ bool dim2_sysfs_get_state_cb(void) unsigned long flags; spin_lock_irqsave(&dim_lock, flags); - state = DIM_GetLockState(); + state = dim_get_lock_state(); spin_unlock_irqrestore(&dim_lock, flags); return state; } /** - * DIMCB_IoRead - callback from HAL to read an I/O register + * dimcb_io_read - callback from HAL to read an I/O register * @ptr32: register address */ -u32 DIMCB_IoRead(u32 *ptr32) +u32 dimcb_io_read(u32 *ptr32) { return __raw_readl(ptr32); } /** - * DIMCB_IoWrite - callback from HAL to write value to an I/O register + * dimcb_io_write - callback from HAL to write value to an I/O register * @ptr32: register address * @value: value to write */ -void DIMCB_IoWrite(u32 *ptr32, u32 value) +void dimcb_io_write(u32 *ptr32, u32 value) { __raw_writel(value, ptr32); } /** - * DIMCB_OnError - callback from HAL to report miscommunication between + * dimcb_on_error - callback from HAL to report miscommunication between * HDM and HAL * @error_id: Error ID * @error_message: Error message. Some text in a free format */ -void DIMCB_OnError(u8 error_id, const char *error_message) +void dimcb_on_error(u8 error_id, const char *error_message) { - pr_err("DIMCB_OnError: error_id - %d, error_message - %s\n", error_id, + pr_err("dimcb_on_error: error_id - %d, error_message - %s\n", error_id, error_message); } @@ -212,9 +212,9 @@ static int startup_dim(struct platform_device *pdev) return ret; } - hal_ret = DIM_Startup(dev->io_base, dev->clk_speed); + hal_ret = dim_startup(dev->io_base, dev->clk_speed); if (hal_ret != DIM_NO_ERROR) { - pr_err("DIM_Startup failed: %d\n", hal_ret); + pr_err("dim_startup failed: %d\n", hal_ret); if (pdata && pdata->destroy) pdata->destroy(pdata); return -ENODEV; @@ -246,7 +246,7 @@ static int try_start_dim_transfer(struct hdm_channel *hdm_ch) return -EAGAIN; } - if (!DIM_GetChannelState(&hdm_ch->ch, &st)->ready) { + if (!dim_get_channel_state(&hdm_ch->ch, &st)->ready) { spin_unlock_irqrestore(&dim_lock, flags); return -EAGAIN; } @@ -255,7 +255,7 @@ static int try_start_dim_transfer(struct hdm_channel *hdm_ch) buf_size = mbo->buffer_length; BUG_ON(mbo->bus_address == 0); - if (!DIM_EnqueueBuffer(&hdm_ch->ch, mbo->bus_address, buf_size)) { + if (!dim_enqueue_buffer(&hdm_ch->ch, mbo->bus_address, buf_size)) { list_del(head->next); spin_unlock_irqrestore(&dim_lock, flags); mbo->processed_length = 0; @@ -340,13 +340,13 @@ static void service_done_flag(struct dim2_hdm *dev, int ch_idx) spin_lock_irqsave(&dim_lock, flags); - done_buffers = DIM_GetChannelState(&hdm_ch->ch, &st)->done_buffers; + done_buffers = dim_get_channel_state(&hdm_ch->ch, &st)->done_buffers; if (!done_buffers) { spin_unlock_irqrestore(&dim_lock, flags); return; } - if (!DIM_DetachBuffers(&hdm_ch->ch, done_buffers)) { + if (!dim_detach_buffers(&hdm_ch->ch, done_buffers)) { spin_unlock_irqrestore(&dim_lock, flags); return; } @@ -371,7 +371,6 @@ static void service_done_flag(struct dim2_hdm *dev, int ch_idx) if (hdm_ch->data_type == MOST_CH_ASYNC && hdm_ch->direction == MOST_CH_RX && PACKET_IS_NET_INFO(data)) { - retrieve_netinfo(dev, mbo); spin_lock_irqsave(&dim_lock, flags); @@ -380,7 +379,6 @@ static void service_done_flag(struct dim2_hdm *dev, int ch_idx) } else { if (hdm_ch->data_type == MOST_CH_CONTROL || hdm_ch->data_type == MOST_CH_ASYNC) { - u32 const data_size = (u32)data[0] * 256 + data[1] + 2; @@ -430,7 +428,7 @@ static void dim2_tasklet_fn(unsigned long data) continue; spin_lock_irqsave(&dim_lock, flags); - DIM_ServiceChannel(&dev->hch[ch_idx].ch); + dim_service_channel(&dev->hch[ch_idx].ch); spin_unlock_irqrestore(&dim_lock, flags); service_done_flag(dev, ch_idx); @@ -454,7 +452,7 @@ static irqreturn_t dim2_ahb_isr(int irq, void *_dev) unsigned long flags; spin_lock_irqsave(&dim_lock, flags); - DIM_ServiceIrq(get_active_channels(dev, buffer)); + dim_service_irq(get_active_channels(dev, buffer)); spin_unlock_irqrestore(&dim_lock, flags); #if !defined(ENABLE_HDM_TEST) @@ -536,7 +534,7 @@ static int configure_channel(struct most_interface *most_iface, int ch_idx, switch (ccfg->data_type) { case MOST_CH_CONTROL: - new_size = DIM_NormCtrlAsyncBufferSize(buf_size); + new_size = dim_norm_ctrl_async_buffer_size(buf_size); if (new_size == 0) { pr_err("%s: too small buffer size\n", hdm_ch->name); return -EINVAL; @@ -546,11 +544,11 @@ static int configure_channel(struct most_interface *most_iface, int ch_idx, pr_warn("%s: fixed buffer size (%d -> %d)\n", hdm_ch->name, buf_size, new_size); spin_lock_irqsave(&dim_lock, flags); - hal_ret = DIM_InitControl(&hdm_ch->ch, is_tx, ch_addr, - buf_size); + hal_ret = dim_init_control(&hdm_ch->ch, is_tx, ch_addr, + buf_size); break; case MOST_CH_ASYNC: - new_size = DIM_NormCtrlAsyncBufferSize(buf_size); + new_size = dim_norm_ctrl_async_buffer_size(buf_size); if (new_size == 0) { pr_err("%s: too small buffer size\n", hdm_ch->name); return -EINVAL; @@ -560,10 +558,10 @@ static int configure_channel(struct most_interface *most_iface, int ch_idx, pr_warn("%s: fixed buffer size (%d -> %d)\n", hdm_ch->name, buf_size, new_size); spin_lock_irqsave(&dim_lock, flags); - hal_ret = DIM_InitAsync(&hdm_ch->ch, is_tx, ch_addr, buf_size); + hal_ret = dim_init_async(&hdm_ch->ch, is_tx, ch_addr, buf_size); break; case MOST_CH_ISOC_AVP: - new_size = DIM_NormIsocBufferSize(buf_size, sub_size); + new_size = dim_norm_isoc_buffer_size(buf_size, sub_size); if (new_size == 0) { pr_err("%s: invalid sub-buffer size or too small buffer size\n", hdm_ch->name); @@ -574,10 +572,10 @@ static int configure_channel(struct most_interface *most_iface, int ch_idx, pr_warn("%s: fixed buffer size (%d -> %d)\n", hdm_ch->name, buf_size, new_size); spin_lock_irqsave(&dim_lock, flags); - hal_ret = DIM_InitIsoc(&hdm_ch->ch, is_tx, ch_addr, sub_size); + hal_ret = dim_init_isoc(&hdm_ch->ch, is_tx, ch_addr, sub_size); break; case MOST_CH_SYNC: - new_size = DIM_NormSyncBufferSize(buf_size, sub_size); + new_size = dim_norm_sync_buffer_size(buf_size, sub_size); if (new_size == 0) { pr_err("%s: invalid sub-buffer size or too small buffer size\n", hdm_ch->name); @@ -588,7 +586,7 @@ static int configure_channel(struct most_interface *most_iface, int ch_idx, pr_warn("%s: fixed buffer size (%d -> %d)\n", hdm_ch->name, buf_size, new_size); spin_lock_irqsave(&dim_lock, flags); - hal_ret = DIM_InitSync(&hdm_ch->ch, is_tx, ch_addr, sub_size); + hal_ret = dim_init_sync(&hdm_ch->ch, is_tx, ch_addr, sub_size); break; default: pr_err("%s: configure failed, bad channel type: %d\n", @@ -708,7 +706,7 @@ static int poison_channel(struct most_interface *most_iface, int ch_idx) return -EPERM; spin_lock_irqsave(&dim_lock, flags); - hal_ret = DIM_DestroyChannel(&hdm_ch->ch); + hal_ret = dim_destroy_channel(&hdm_ch->ch); hdm_ch->is_initialized = false; if (ch_idx == dev->atx_idx) dev->atx_idx = -1; @@ -885,7 +883,7 @@ static int dim2_remove(struct platform_device *pdev) unsigned long flags; spin_lock_irqsave(&dim_lock, flags); - DIM_Shutdown(); + dim_shutdown(); spin_unlock_irqrestore(&dim_lock, flags); if (pdata && pdata->destroy) diff --git a/drivers/staging/most/hdm-dim2/dim2_reg.h b/drivers/staging/most/hdm-dim2/dim2_reg.h index 476f66f4c566..bcf6a79f6744 100644 --- a/drivers/staging/most/hdm-dim2/dim2_reg.h +++ b/drivers/staging/most/hdm-dim2/dim2_reg.h @@ -21,7 +21,6 @@ extern "C" { #endif - struct dim2_regs { /* 0x00 */ u32 MLBC0; /* 0x01 */ u32 rsvd0[1]; @@ -67,8 +66,7 @@ struct dim2_regs { /* 0xF7 */ u32 ACMR1; }; - -#define DIM2_MASK(n) (~((~(u32)0)<<(n))) +#define DIM2_MASK(n) (~((~(u32)0) << (n))) enum { MLBC0_MLBLK_BIT = 7, @@ -168,7 +166,6 @@ enum { CAT_CL_MASK = DIM2_MASK(6) }; - #ifdef __cplusplus } #endif diff --git a/drivers/staging/most/hdm-dim2/dim2_sysfs.h b/drivers/staging/most/hdm-dim2/dim2_sysfs.h index e719691035b0..b71dd027ebc7 100644 --- a/drivers/staging/most/hdm-dim2/dim2_sysfs.h +++ b/drivers/staging/most/hdm-dim2/dim2_sysfs.h @@ -16,10 +16,8 @@ #ifndef DIM2_SYSFS_H #define DIM2_SYSFS_H - #include <linux/kobject.h> - struct medialb_bus { struct kobject kobj_group; }; @@ -35,5 +33,4 @@ void dim2_sysfs_destroy(struct medialb_bus *bus); */ bool dim2_sysfs_get_state_cb(void); - #endif /* DIM2_SYSFS_H */ diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c index 19852ca7e59c..ed1ed25b6d1d 100644 --- a/drivers/staging/most/mostcore/core.c +++ b/drivers/staging/most/mostcore/core.c @@ -1587,8 +1587,7 @@ out: return 0; error: - if (iface->mod) - module_put(iface->mod); + module_put(iface->mod); modref--; mutex_unlock(&c->start_mutex); return ret; diff --git a/drivers/staging/most/mostcore/mostcore.h b/drivers/staging/most/mostcore/mostcore.h index e148b324331a..bda3850d5435 100644 --- a/drivers/staging/most/mostcore/mostcore.h +++ b/drivers/staging/most/mostcore/mostcore.h @@ -60,7 +60,6 @@ enum most_channel_data_type { MOST_CH_SYNC = 1 << 5, }; - enum mbo_status_flags { /* MBO was processed successfully (data was send or received )*/ MBO_SUCCESS = 0, @@ -317,5 +316,4 @@ int most_start_channel(struct most_interface *iface, int channel_idx, int most_stop_channel(struct most_interface *iface, int channel_idx, struct most_aim *); - #endif /* MOST_CORE_H_ */ diff --git a/drivers/staging/nvec/README b/drivers/staging/nvec/README index 9a320b7fdbe6..0e2d5c4c875f 100644 --- a/drivers/staging/nvec/README +++ b/drivers/staging/nvec/README @@ -1,4 +1,4 @@ -NVEC: An NVidia compliant Embedded Controller Protocol Implemenation +NVEC: An NVidia compliant Embedded Controller Protocol Implementation This is an implementation of the NVEC protocol used to communicate with an embedded controller (EC) via I2C bus. The EC is an I2C master while the host diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c index 802c9597d421..4ae44a5168f9 100644 --- a/drivers/staging/nvec/nvec.c +++ b/drivers/staging/nvec/nvec.c @@ -40,18 +40,18 @@ #include "nvec.h" #define I2C_CNFG 0x00 -#define I2C_CNFG_PACKET_MODE_EN (1<<10) -#define I2C_CNFG_NEW_MASTER_SFM (1<<11) +#define I2C_CNFG_PACKET_MODE_EN (1 << 10) +#define I2C_CNFG_NEW_MASTER_SFM (1 << 11) #define I2C_CNFG_DEBOUNCE_CNT_SHIFT 12 #define I2C_SL_CNFG 0x20 -#define I2C_SL_NEWSL (1<<2) -#define I2C_SL_NACK (1<<1) -#define I2C_SL_RESP (1<<0) -#define I2C_SL_IRQ (1<<3) -#define END_TRANS (1<<4) -#define RCVD (1<<2) -#define RNW (1<<1) +#define I2C_SL_NEWSL (1 << 2) +#define I2C_SL_NACK (1 << 1) +#define I2C_SL_RESP (1 << 0) +#define I2C_SL_IRQ (1 << 3) +#define END_TRANS (1 << 4) +#define RCVD (1 << 2) +#define RNW (1 << 1) #define I2C_SL_RCVD 0x24 #define I2C_SL_STATUS 0x28 @@ -740,7 +740,7 @@ static void tegra_init_i2c_slave(struct nvec_chip *nvec) writel(I2C_SL_NEWSL, nvec->base + I2C_SL_CNFG); writel(0x1E, nvec->base + I2C_SL_DELAY_COUNT); - writel(nvec->i2c_addr>>1, nvec->base + I2C_SL_ADDR1); + writel(nvec->i2c_addr >> 1, nvec->base + I2C_SL_ADDR1); writel(0, nvec->base + I2C_SL_ADDR2); enable_irq(nvec->irq); diff --git a/drivers/staging/octeon/ethernet-defines.h b/drivers/staging/octeon/ethernet-defines.h index 13e4cee1f86d..07bd2b87f6a0 100644 --- a/drivers/staging/octeon/ethernet-defines.h +++ b/drivers/staging/octeon/ethernet-defines.h @@ -40,6 +40,6 @@ #define FAU_TOTAL_TX_TO_CLEAN (CVMX_FAU_REG_END - sizeof(u32)) #define FAU_NUM_PACKET_BUFFERS_TO_FREE (FAU_TOTAL_TX_TO_CLEAN - sizeof(u32)) -#define TOTAL_NUMBER_OF_PORTS (CVMX_PIP_NUM_INPUT_PORTS+1) +#define TOTAL_NUMBER_OF_PORTS (CVMX_PIP_NUM_INPUT_PORTS + 1) #endif /* __ETHERNET_DEFINES_H__ */ diff --git a/drivers/staging/rdma/amso1100/c2.c b/drivers/staging/rdma/amso1100/c2.c index 35ac536b2d45..b46ebd1ae15a 100644 --- a/drivers/staging/rdma/amso1100/c2.c +++ b/drivers/staging/rdma/amso1100/c2.c @@ -87,11 +87,6 @@ static struct pci_device_id c2_pci_table[] = { MODULE_DEVICE_TABLE(pci, c2_pci_table); -static void c2_print_macaddr(struct net_device *netdev) -{ - pr_debug("%s: MAC %pM, IRQ %u\n", netdev->name, netdev->dev_addr, netdev->irq); -} - static void c2_set_rxbufsize(struct c2_port *c2_port) { struct net_device *netdev = c2_port->netdev; @@ -116,7 +111,8 @@ static int c2_tx_ring_alloc(struct c2_ring *tx_ring, void *vaddr, struct c2_element *elem; int i; - tx_ring->start = kmalloc(sizeof(*elem) * tx_ring->count, GFP_KERNEL); + tx_ring->start = kmalloc_array(tx_ring->count, sizeof(*elem), + GFP_KERNEL); if (!tx_ring->start) return -ENOMEM; @@ -165,7 +161,8 @@ static int c2_rx_ring_alloc(struct c2_ring *rx_ring, void *vaddr, struct c2_element *elem; int i; - rx_ring->start = kmalloc(sizeof(*elem) * rx_ring->count, GFP_KERNEL); + rx_ring->start = kmalloc_array(rx_ring->count, sizeof(*elem), + GFP_KERNEL); if (!rx_ring->start) return -ENOMEM; @@ -908,7 +905,8 @@ static struct net_device *c2_devinit(struct c2_dev *c2dev, /* Validate the MAC address */ if (!is_valid_ether_addr(netdev->dev_addr)) { pr_debug("Invalid MAC Address\n"); - c2_print_macaddr(netdev); + pr_debug("%s: MAC %pM, IRQ %u\n", netdev->name, + netdev->dev_addr, netdev->irq); free_netdev(netdev); return NULL; } @@ -1142,7 +1140,8 @@ static int c2_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) } /* Print out the MAC address */ - c2_print_macaddr(netdev); + pr_debug("%s: MAC %pM, IRQ %u\n", netdev->name, netdev->dev_addr, + netdev->irq); ret = c2_rnic_init(c2dev); if (ret) { diff --git a/drivers/staging/rdma/amso1100/c2.h b/drivers/staging/rdma/amso1100/c2.h index d619d735838b..21b565a91fd6 100644 --- a/drivers/staging/rdma/amso1100/c2.h +++ b/drivers/staging/rdma/amso1100/c2.h @@ -476,72 +476,72 @@ static inline int c2_errno(void *reply) } /* Device */ -extern int c2_register_device(struct c2_dev *c2dev); -extern void c2_unregister_device(struct c2_dev *c2dev); -extern int c2_rnic_init(struct c2_dev *c2dev); -extern void c2_rnic_term(struct c2_dev *c2dev); -extern void c2_rnic_interrupt(struct c2_dev *c2dev); -extern int c2_del_addr(struct c2_dev *c2dev, __be32 inaddr, __be32 inmask); -extern int c2_add_addr(struct c2_dev *c2dev, __be32 inaddr, __be32 inmask); +int c2_register_device(struct c2_dev *c2dev); +void c2_unregister_device(struct c2_dev *c2dev); +int c2_rnic_init(struct c2_dev *c2dev); +void c2_rnic_term(struct c2_dev *c2dev); +void c2_rnic_interrupt(struct c2_dev *c2dev); +int c2_del_addr(struct c2_dev *c2dev, __be32 inaddr, __be32 inmask); +int c2_add_addr(struct c2_dev *c2dev, __be32 inaddr, __be32 inmask); /* QPs */ -extern int c2_alloc_qp(struct c2_dev *c2dev, struct c2_pd *pd, +int c2_alloc_qp(struct c2_dev *c2dev, struct c2_pd *pd, struct ib_qp_init_attr *qp_attrs, struct c2_qp *qp); -extern void c2_free_qp(struct c2_dev *c2dev, struct c2_qp *qp); -extern struct ib_qp *c2_get_qp(struct ib_device *device, int qpn); -extern int c2_qp_modify(struct c2_dev *c2dev, struct c2_qp *qp, +void c2_free_qp(struct c2_dev *c2dev, struct c2_qp *qp); +struct ib_qp *c2_get_qp(struct ib_device *device, int qpn); +int c2_qp_modify(struct c2_dev *c2dev, struct c2_qp *qp, struct ib_qp_attr *attr, int attr_mask); -extern int c2_qp_set_read_limits(struct c2_dev *c2dev, struct c2_qp *qp, +int c2_qp_set_read_limits(struct c2_dev *c2dev, struct c2_qp *qp, int ord, int ird); -extern int c2_post_send(struct ib_qp *ibqp, struct ib_send_wr *ib_wr, +int c2_post_send(struct ib_qp *ibqp, struct ib_send_wr *ib_wr, struct ib_send_wr **bad_wr); -extern int c2_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *ib_wr, +int c2_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *ib_wr, struct ib_recv_wr **bad_wr); -extern void c2_init_qp_table(struct c2_dev *c2dev); -extern void c2_cleanup_qp_table(struct c2_dev *c2dev); -extern void c2_set_qp_state(struct c2_qp *, int); -extern struct c2_qp *c2_find_qpn(struct c2_dev *c2dev, int qpn); +void c2_init_qp_table(struct c2_dev *c2dev); +void c2_cleanup_qp_table(struct c2_dev *c2dev); +void c2_set_qp_state(struct c2_qp *, int); +struct c2_qp *c2_find_qpn(struct c2_dev *c2dev, int qpn); /* PDs */ -extern int c2_pd_alloc(struct c2_dev *c2dev, int privileged, struct c2_pd *pd); -extern void c2_pd_free(struct c2_dev *c2dev, struct c2_pd *pd); -extern int c2_init_pd_table(struct c2_dev *c2dev); -extern void c2_cleanup_pd_table(struct c2_dev *c2dev); +int c2_pd_alloc(struct c2_dev *c2dev, int privileged, struct c2_pd *pd); +void c2_pd_free(struct c2_dev *c2dev, struct c2_pd *pd); +int c2_init_pd_table(struct c2_dev *c2dev); +void c2_cleanup_pd_table(struct c2_dev *c2dev); /* CQs */ -extern int c2_init_cq(struct c2_dev *c2dev, int entries, +int c2_init_cq(struct c2_dev *c2dev, int entries, struct c2_ucontext *ctx, struct c2_cq *cq); -extern void c2_free_cq(struct c2_dev *c2dev, struct c2_cq *cq); -extern void c2_cq_event(struct c2_dev *c2dev, u32 mq_index); -extern void c2_cq_clean(struct c2_dev *c2dev, struct c2_qp *qp, u32 mq_index); -extern int c2_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry); -extern int c2_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags); +void c2_free_cq(struct c2_dev *c2dev, struct c2_cq *cq); +void c2_cq_event(struct c2_dev *c2dev, u32 mq_index); +void c2_cq_clean(struct c2_dev *c2dev, struct c2_qp *qp, u32 mq_index); +int c2_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry); +int c2_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags); /* CM */ -extern int c2_llp_connect(struct iw_cm_id *cm_id, +int c2_llp_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param); -extern int c2_llp_accept(struct iw_cm_id *cm_id, +int c2_llp_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param); -extern int c2_llp_reject(struct iw_cm_id *cm_id, const void *pdata, +int c2_llp_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len); -extern int c2_llp_service_create(struct iw_cm_id *cm_id, int backlog); -extern int c2_llp_service_destroy(struct iw_cm_id *cm_id); +int c2_llp_service_create(struct iw_cm_id *cm_id, int backlog); +int c2_llp_service_destroy(struct iw_cm_id *cm_id); /* MM */ -extern int c2_nsmr_register_phys_kern(struct c2_dev *c2dev, u64 *addr_list, +int c2_nsmr_register_phys_kern(struct c2_dev *c2dev, u64 *addr_list, int page_size, int pbl_depth, u32 length, u32 off, u64 *va, enum c2_acf acf, struct c2_mr *mr); -extern int c2_stag_dealloc(struct c2_dev *c2dev, u32 stag_index); +int c2_stag_dealloc(struct c2_dev *c2dev, u32 stag_index); /* AE */ -extern void c2_ae_event(struct c2_dev *c2dev, u32 mq_index); +void c2_ae_event(struct c2_dev *c2dev, u32 mq_index); /* MQSP Allocator */ -extern int c2_init_mqsp_pool(struct c2_dev *c2dev, gfp_t gfp_mask, +int c2_init_mqsp_pool(struct c2_dev *c2dev, gfp_t gfp_mask, struct sp_chunk **root); -extern void c2_free_mqsp_pool(struct c2_dev *c2dev, struct sp_chunk *root); -extern __be16 *c2_alloc_mqsp(struct c2_dev *c2dev, struct sp_chunk *head, +void c2_free_mqsp_pool(struct c2_dev *c2dev, struct sp_chunk *root); +__be16 *c2_alloc_mqsp(struct c2_dev *c2dev, struct sp_chunk *head, dma_addr_t *dma_addr, gfp_t gfp_mask); -extern void c2_free_mqsp(__be16* mqsp); +void c2_free_mqsp(__be16* mqsp); #endif diff --git a/drivers/staging/rdma/amso1100/c2_mq.h b/drivers/staging/rdma/amso1100/c2_mq.h index fc1b9a7cec4b..8e1b4d13409e 100644 --- a/drivers/staging/rdma/amso1100/c2_mq.h +++ b/drivers/staging/rdma/amso1100/c2_mq.h @@ -93,14 +93,14 @@ static __inline__ int c2_mq_full(struct c2_mq *q) return q->priv == (be16_to_cpu(*q->shared) + q->q_size - 1) % q->q_size; } -extern void c2_mq_lconsume(struct c2_mq *q, u32 wqe_count); -extern void *c2_mq_alloc(struct c2_mq *q); -extern void c2_mq_produce(struct c2_mq *q); -extern void *c2_mq_consume(struct c2_mq *q); -extern void c2_mq_free(struct c2_mq *q); -extern void c2_mq_req_init(struct c2_mq *q, u32 index, u32 q_size, u32 msg_size, +void c2_mq_lconsume(struct c2_mq *q, u32 wqe_count); +void *c2_mq_alloc(struct c2_mq *q); +void c2_mq_produce(struct c2_mq *q); +void *c2_mq_consume(struct c2_mq *q); +void c2_mq_free(struct c2_mq *q); +void c2_mq_req_init(struct c2_mq *q, u32 index, u32 q_size, u32 msg_size, u8 __iomem *pool_start, u16 __iomem *peer, u32 type); -extern void c2_mq_rep_init(struct c2_mq *q, u32 index, u32 q_size, u32 msg_size, +void c2_mq_rep_init(struct c2_mq *q, u32 index, u32 q_size, u32 msg_size, u8 *pool_start, u16 __iomem *peer, u32 type); #endif /* _C2_MQ_H_ */ diff --git a/drivers/staging/rdma/amso1100/c2_provider.c b/drivers/staging/rdma/amso1100/c2_provider.c index c707e45887c2..a092ac743c72 100644 --- a/drivers/staging/rdma/amso1100/c2_provider.c +++ b/drivers/staging/rdma/amso1100/c2_provider.c @@ -620,12 +620,9 @@ static int c2_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param) static int c2_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len) { - int err; - pr_debug("%s:%u\n", __func__, __LINE__); - err = c2_llp_reject(cm_id, pdata, pdata_len); - return err; + return c2_llp_reject(cm_id, pdata, pdata_len); } static int c2_service_create(struct iw_cm_id *cm_id, int backlog) @@ -642,12 +639,9 @@ static int c2_service_create(struct iw_cm_id *cm_id, int backlog) static int c2_service_destroy(struct iw_cm_id *cm_id) { - int err; pr_debug("%s:%u\n", __func__, __LINE__); - err = c2_llp_service_destroy(cm_id); - - return err; + return c2_llp_service_destroy(cm_id); } static int c2_pseudo_up(struct net_device *netdev) diff --git a/drivers/staging/rdma/amso1100/c2_rnic.c b/drivers/staging/rdma/amso1100/c2_rnic.c index d3c0f77767d9..5e65c6d07ca4 100644 --- a/drivers/staging/rdma/amso1100/c2_rnic.c +++ b/drivers/staging/rdma/amso1100/c2_rnic.c @@ -81,7 +81,6 @@ static int c2_adapter_init(struct c2_dev *c2dev) { struct c2wr_init_req wr; - int err; memset(&wr, 0, sizeof(wr)); c2_wr_set_id(&wr, CCWR_INIT); @@ -94,9 +93,7 @@ static int c2_adapter_init(struct c2_dev *c2dev) wr.q2_host_msg_pool = cpu_to_be64(c2dev->aeq.host_dma); /* Post the init message */ - err = vq_send_wr(c2dev, (union c2wr *) & wr); - - return err; + return vq_send_wr(c2dev, (union c2wr *) & wr); } /* diff --git a/drivers/staging/rdma/amso1100/c2_vq.h b/drivers/staging/rdma/amso1100/c2_vq.h index 33805627a607..c1f6cef60213 100644 --- a/drivers/staging/rdma/amso1100/c2_vq.h +++ b/drivers/staging/rdma/amso1100/c2_vq.h @@ -47,17 +47,17 @@ struct c2_vq_req { struct c2_qp *qp; }; -extern int vq_init(struct c2_dev *c2dev); -extern void vq_term(struct c2_dev *c2dev); +int vq_init(struct c2_dev *c2dev); +void vq_term(struct c2_dev *c2dev); -extern struct c2_vq_req *vq_req_alloc(struct c2_dev *c2dev); -extern void vq_req_free(struct c2_dev *c2dev, struct c2_vq_req *req); -extern void vq_req_get(struct c2_dev *c2dev, struct c2_vq_req *req); -extern void vq_req_put(struct c2_dev *c2dev, struct c2_vq_req *req); -extern int vq_send_wr(struct c2_dev *c2dev, union c2wr * wr); +struct c2_vq_req *vq_req_alloc(struct c2_dev *c2dev); +void vq_req_free(struct c2_dev *c2dev, struct c2_vq_req *req); +void vq_req_get(struct c2_dev *c2dev, struct c2_vq_req *req); +void vq_req_put(struct c2_dev *c2dev, struct c2_vq_req *req); +int vq_send_wr(struct c2_dev *c2dev, union c2wr * wr); -extern void *vq_repbuf_alloc(struct c2_dev *c2dev); -extern void vq_repbuf_free(struct c2_dev *c2dev, void *reply); +void *vq_repbuf_alloc(struct c2_dev *c2dev); +void vq_repbuf_free(struct c2_dev *c2dev, void *reply); -extern int vq_wait_for_reply(struct c2_dev *c2dev, struct c2_vq_req *req); +int vq_wait_for_reply(struct c2_dev *c2dev, struct c2_vq_req *req); #endif /* _C2_VQ_H_ */ diff --git a/drivers/staging/rdma/ehca/ehca_av.c b/drivers/staging/rdma/ehca/ehca_av.c index 465926319f3d..94e088c2d989 100644 --- a/drivers/staging/rdma/ehca/ehca_av.c +++ b/drivers/staging/rdma/ehca/ehca_av.c @@ -105,6 +105,7 @@ struct ib_ah *ehca_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr) if (ehca_static_rate < 0) { u32 ipd; + if (ehca_calc_ipd(shca, ah_attr->port_num, ah_attr->static_rate, &ipd)) { ret = -EINVAL; @@ -128,6 +129,7 @@ struct ib_ah *ehca_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr) int rc; struct ib_port_attr port_attr; union ib_gid gid; + memset(&port_attr, 0, sizeof(port_attr)); rc = ehca_query_port(pd->device, ah_attr->port_num, &port_attr); @@ -192,6 +194,7 @@ int ehca_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr) int rc; struct ib_port_attr port_attr; union ib_gid gid; + memset(&port_attr, 0, sizeof(port_attr)); rc = ehca_query_port(ah->device, ah_attr->port_num, &port_attr); @@ -272,6 +275,5 @@ int ehca_init_av_cache(void) void ehca_cleanup_av_cache(void) { - if (av_cache) - kmem_cache_destroy(av_cache); + kmem_cache_destroy(av_cache); } diff --git a/drivers/staging/rdma/ehca/ehca_cq.c b/drivers/staging/rdma/ehca/ehca_cq.c index ea1b5c1203b4..1aa7931fe860 100644 --- a/drivers/staging/rdma/ehca/ehca_cq.c +++ b/drivers/staging/rdma/ehca/ehca_cq.c @@ -393,6 +393,5 @@ int ehca_init_cq_cache(void) void ehca_cleanup_cq_cache(void) { - if (cq_cache) - kmem_cache_destroy(cq_cache); + kmem_cache_destroy(cq_cache); } diff --git a/drivers/staging/rdma/ehca/ehca_main.c b/drivers/staging/rdma/ehca/ehca_main.c index 8246418cd4e0..860b974e9faa 100644 --- a/drivers/staging/rdma/ehca/ehca_main.c +++ b/drivers/staging/rdma/ehca/ehca_main.c @@ -245,8 +245,7 @@ static void ehca_destroy_slab_caches(void) ehca_cleanup_cq_cache(); ehca_cleanup_pd_cache(); #ifdef CONFIG_PPC_64K_PAGES - if (ctblk_cache) - kmem_cache_destroy(ctblk_cache); + kmem_cache_destroy(ctblk_cache); #endif } diff --git a/drivers/staging/rdma/ehca/ehca_mrmw.c b/drivers/staging/rdma/ehca/ehca_mrmw.c index f914b30999f8..553e883a5718 100644 --- a/drivers/staging/rdma/ehca/ehca_mrmw.c +++ b/drivers/staging/rdma/ehca/ehca_mrmw.c @@ -2251,10 +2251,8 @@ int ehca_init_mrmw_cache(void) void ehca_cleanup_mrmw_cache(void) { - if (mr_cache) - kmem_cache_destroy(mr_cache); - if (mw_cache) - kmem_cache_destroy(mw_cache); + kmem_cache_destroy(mr_cache); + kmem_cache_destroy(mw_cache); } static inline int ehca_init_top_bmap(struct ehca_top_bmap *ehca_top_bmap, diff --git a/drivers/staging/rdma/ehca/ehca_pd.c b/drivers/staging/rdma/ehca/ehca_pd.c index 351577a6670a..2a8aae411941 100644 --- a/drivers/staging/rdma/ehca/ehca_pd.c +++ b/drivers/staging/rdma/ehca/ehca_pd.c @@ -119,6 +119,5 @@ int ehca_init_pd_cache(void) void ehca_cleanup_pd_cache(void) { - if (pd_cache) - kmem_cache_destroy(pd_cache); + kmem_cache_destroy(pd_cache); } diff --git a/drivers/staging/rdma/ehca/ehca_qp.c b/drivers/staging/rdma/ehca/ehca_qp.c index 2e89356c46fa..896c01f810f6 100644 --- a/drivers/staging/rdma/ehca/ehca_qp.c +++ b/drivers/staging/rdma/ehca/ehca_qp.c @@ -2252,6 +2252,5 @@ int ehca_init_qp_cache(void) void ehca_cleanup_qp_cache(void) { - if (qp_cache) - kmem_cache_destroy(qp_cache); + kmem_cache_destroy(qp_cache); } diff --git a/drivers/staging/rdma/hfi1/Makefile b/drivers/staging/rdma/hfi1/Makefile index 2e5daa6cdcc2..68c5a315e557 100644 --- a/drivers/staging/rdma/hfi1/Makefile +++ b/drivers/staging/rdma/hfi1/Makefile @@ -7,7 +7,7 @@ # obj-$(CONFIG_INFINIBAND_HFI1) += hfi1.o -hfi1-y := chip.o cq.o device.o diag.o dma.o driver.o eprom.o file_ops.o firmware.o \ +hfi1-y := chip.o cq.o device.o diag.o dma.o driver.o efivar.o eprom.o file_ops.o firmware.o \ init.o intr.o keys.o mad.o mmap.o mr.o pcie.o pio.o pio_copy.o \ qp.o qsfp.o rc.o ruc.o sdma.o srq.o sysfs.o trace.o twsi.o \ uc.o ud.o user_pages.o user_sdma.o verbs_mcast.o verbs.o diff --git a/drivers/staging/rdma/hfi1/chip.c b/drivers/staging/rdma/hfi1/chip.c index e48981994b10..bbe5ad85cec0 100644 --- a/drivers/staging/rdma/hfi1/chip.c +++ b/drivers/staging/rdma/hfi1/chip.c @@ -63,6 +63,7 @@ #include "pio.h" #include "sdma.h" #include "eprom.h" +#include "efivar.h" #define NUM_IB_PORTS 1 @@ -121,8 +122,8 @@ struct flag_table { #define SEC_SC_HALTED 0x4 /* per-context only */ #define SEC_SPC_FREEZE 0x8 /* per-HFI only */ -#define VL15CTXT 1 #define MIN_KERNEL_KCTXTS 2 +#define FIRST_KERNEL_KCTXT 1 #define NUM_MAP_REGS 32 /* Bit offset into the GUID which carries HFI id information */ @@ -663,7 +664,7 @@ static struct flag_table egress_err_info_flags[] = { */ #define SES(name) SEND_ERR_STATUS_SEND_##name##_ERR_SMASK static struct flag_table send_err_status_flags[] = { -/* 0*/ FLAG_ENTRY0("SDmaRpyTagErr", SES(CSR_PARITY)), +/* 0*/ FLAG_ENTRY0("SendCsrParityErr", SES(CSR_PARITY)), /* 1*/ FLAG_ENTRY0("SendCsrReadBadAddrErr", SES(CSR_READ_BAD_ADDR)), /* 2*/ FLAG_ENTRY0("SendCsrWriteBadAddrErr", SES(CSR_WRITE_BAD_ADDR)) }; @@ -1417,6 +1418,17 @@ static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context, return read_write_sw(ppd->dd, &ppd->link_up, mode, data); } +static u64 access_sw_unknown_frame_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; + + if (vl != CNTR_INVALID_VL) + return 0; + return read_write_sw(ppd->dd, &ppd->unknown_frame_count, mode, data); +} + static u64 access_sw_xmit_discards(const struct cntr_entry *entry, void *context, int vl, int mode, u64 data) { @@ -1538,6 +1550,2336 @@ static u64 access_sw_send_schedule(const struct cntr_entry *entry, return dd->verbs_dev.n_send_schedule; } +/* Software counters for the error status bits within MISC_ERR_STATUS */ +static u64 access_misc_pll_lock_fail_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[12]; +} + +static u64 access_misc_mbist_fail_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[11]; +} + +static u64 access_misc_invalid_eep_cmd_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[10]; +} + +static u64 access_misc_efuse_done_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[9]; +} + +static u64 access_misc_efuse_write_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[8]; +} + +static u64 access_misc_efuse_read_bad_addr_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[7]; +} + +static u64 access_misc_efuse_csr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[6]; +} + +static u64 access_misc_fw_auth_failed_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[5]; +} + +static u64 access_misc_key_mismatch_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[4]; +} + +static u64 access_misc_sbus_write_failed_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[3]; +} + +static u64 access_misc_csr_write_bad_addr_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[2]; +} + +static u64 access_misc_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[1]; +} + +static u64 access_misc_csr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->misc_err_status_cnt[0]; +} + +/* + * Software counter for the aggregate of + * individual CceErrStatus counters + */ +static u64 access_sw_cce_err_status_aggregated_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_cce_err_status_aggregate; +} + +/* + * Software counters corresponding to each of the + * error status bits within CceErrStatus + */ +static u64 access_cce_msix_csr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[40]; +} + +static u64 access_cce_int_map_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[39]; +} + +static u64 access_cce_int_map_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[38]; +} + +static u64 access_cce_msix_table_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[37]; +} + +static u64 access_cce_msix_table_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[36]; +} + +static u64 access_cce_rxdma_conv_fifo_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[35]; +} + +static u64 access_cce_rcpl_async_fifo_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[34]; +} + +static u64 access_cce_seg_write_bad_addr_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[33]; +} + +static u64 access_cce_seg_read_bad_addr_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[32]; +} + +static u64 access_la_triggered_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[31]; +} + +static u64 access_cce_trgt_cpl_timeout_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[30]; +} + +static u64 access_pcic_receive_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[29]; +} + +static u64 access_pcic_transmit_back_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[28]; +} + +static u64 access_pcic_transmit_front_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[27]; +} + +static u64 access_pcic_cpl_dat_q_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[26]; +} + +static u64 access_pcic_cpl_hd_q_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[25]; +} + +static u64 access_pcic_post_dat_q_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[24]; +} + +static u64 access_pcic_post_hd_q_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[23]; +} + +static u64 access_pcic_retry_sot_mem_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[22]; +} + +static u64 access_pcic_retry_mem_unc_err(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[21]; +} + +static u64 access_pcic_n_post_dat_q_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[20]; +} + +static u64 access_pcic_n_post_h_q_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[19]; +} + +static u64 access_pcic_cpl_dat_q_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[18]; +} + +static u64 access_pcic_cpl_hd_q_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[17]; +} + +static u64 access_pcic_post_dat_q_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[16]; +} + +static u64 access_pcic_post_hd_q_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[15]; +} + +static u64 access_pcic_retry_sot_mem_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[14]; +} + +static u64 access_pcic_retry_mem_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[13]; +} + +static u64 access_cce_cli1_async_fifo_dbg_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[12]; +} + +static u64 access_cce_cli1_async_fifo_rxdma_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[11]; +} + +static u64 access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[10]; +} + +static u64 access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[9]; +} + +static u64 access_cce_cli2_async_fifo_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[8]; +} + +static u64 access_cce_csr_cfg_bus_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[7]; +} + +static u64 access_cce_cli0_async_fifo_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[6]; +} + +static u64 access_cce_rspd_data_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[5]; +} + +static u64 access_cce_trgt_access_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[4]; +} + +static u64 access_cce_trgt_async_fifo_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[3]; +} + +static u64 access_cce_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[2]; +} + +static u64 access_cce_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[1]; +} + +static u64 access_ccs_csr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->cce_err_status_cnt[0]; +} + +/* + * Software counters corresponding to each of the + * error status bits within RcvErrStatus + */ +static u64 access_rx_csr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[63]; +} + +static u64 access_rx_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[62]; +} + +static u64 access_rx_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[61]; +} + +static u64 access_rx_dma_csr_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[60]; +} + +static u64 access_rx_dma_dq_fsm_encoding_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[59]; +} + +static u64 access_rx_dma_eq_fsm_encoding_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[58]; +} + +static u64 access_rx_dma_csr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[57]; +} + +static u64 access_rx_rbuf_data_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[56]; +} + +static u64 access_rx_rbuf_data_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[55]; +} + +static u64 access_rx_dma_data_fifo_rd_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[54]; +} + +static u64 access_rx_dma_data_fifo_rd_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[53]; +} + +static u64 access_rx_dma_hdr_fifo_rd_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[52]; +} + +static u64 access_rx_dma_hdr_fifo_rd_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[51]; +} + +static u64 access_rx_rbuf_desc_part2_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[50]; +} + +static u64 access_rx_rbuf_desc_part2_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[49]; +} + +static u64 access_rx_rbuf_desc_part1_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[48]; +} + +static u64 access_rx_rbuf_desc_part1_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[47]; +} + +static u64 access_rx_hq_intr_fsm_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[46]; +} + +static u64 access_rx_hq_intr_csr_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[45]; +} + +static u64 access_rx_lookup_csr_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[44]; +} + +static u64 access_rx_lookup_rcv_array_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[43]; +} + +static u64 access_rx_lookup_rcv_array_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[42]; +} + +static u64 access_rx_lookup_des_part2_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[41]; +} + +static u64 access_rx_lookup_des_part1_unc_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[40]; +} + +static u64 access_rx_lookup_des_part1_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[39]; +} + +static u64 access_rx_rbuf_next_free_buf_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[38]; +} + +static u64 access_rx_rbuf_next_free_buf_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[37]; +} + +static u64 access_rbuf_fl_init_wr_addr_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[36]; +} + +static u64 access_rx_rbuf_fl_initdone_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[35]; +} + +static u64 access_rx_rbuf_fl_write_addr_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[34]; +} + +static u64 access_rx_rbuf_fl_rd_addr_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[33]; +} + +static u64 access_rx_rbuf_empty_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[32]; +} + +static u64 access_rx_rbuf_full_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[31]; +} + +static u64 access_rbuf_bad_lookup_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[30]; +} + +static u64 access_rbuf_ctx_id_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[29]; +} + +static u64 access_rbuf_csr_qeopdw_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[28]; +} + +static u64 access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[27]; +} + +static u64 access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[26]; +} + +static u64 access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[25]; +} + +static u64 access_rx_rbuf_csr_q_vld_bit_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[24]; +} + +static u64 access_rx_rbuf_csr_q_next_buf_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[23]; +} + +static u64 access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[22]; +} + +static u64 access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[21]; +} + +static u64 access_rx_rbuf_block_list_read_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[20]; +} + +static u64 access_rx_rbuf_block_list_read_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[19]; +} + +static u64 access_rx_rbuf_lookup_des_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[18]; +} + +static u64 access_rx_rbuf_lookup_des_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[17]; +} + +static u64 access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[16]; +} + +static u64 access_rx_rbuf_lookup_des_reg_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[15]; +} + +static u64 access_rx_rbuf_free_list_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[14]; +} + +static u64 access_rx_rbuf_free_list_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[13]; +} + +static u64 access_rx_rcv_fsm_encoding_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[12]; +} + +static u64 access_rx_dma_flag_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[11]; +} + +static u64 access_rx_dma_flag_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[10]; +} + +static u64 access_rx_dc_sop_eop_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[9]; +} + +static u64 access_rx_rcv_csr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[8]; +} + +static u64 access_rx_rcv_qp_map_table_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[7]; +} + +static u64 access_rx_rcv_qp_map_table_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[6]; +} + +static u64 access_rx_rcv_data_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[5]; +} + +static u64 access_rx_rcv_data_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[4]; +} + +static u64 access_rx_rcv_hdr_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[3]; +} + +static u64 access_rx_rcv_hdr_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[2]; +} + +static u64 access_rx_dc_intf_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[1]; +} + +static u64 access_rx_dma_csr_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->rcv_err_status_cnt[0]; +} + +/* + * Software counters corresponding to each of the + * error status bits within SendPioErrStatus + */ +static u64 access_pio_pec_sop_head_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[35]; +} + +static u64 access_pio_pcc_sop_head_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[34]; +} + +static u64 access_pio_last_returned_cnt_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[33]; +} + +static u64 access_pio_current_free_cnt_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[32]; +} + +static u64 access_pio_reserved_31_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[31]; +} + +static u64 access_pio_reserved_30_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[30]; +} + +static u64 access_pio_ppmc_sop_len_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[29]; +} + +static u64 access_pio_ppmc_bqc_mem_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[28]; +} + +static u64 access_pio_vl_fifo_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[27]; +} + +static u64 access_pio_vlf_sop_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[26]; +} + +static u64 access_pio_vlf_v1_len_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[25]; +} + +static u64 access_pio_block_qw_count_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[24]; +} + +static u64 access_pio_write_qw_valid_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[23]; +} + +static u64 access_pio_state_machine_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[22]; +} + +static u64 access_pio_write_data_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[21]; +} + +static u64 access_pio_host_addr_mem_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[20]; +} + +static u64 access_pio_host_addr_mem_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[19]; +} + +static u64 access_pio_pkt_evict_sm_or_arb_sm_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[18]; +} + +static u64 access_pio_init_sm_in_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[17]; +} + +static u64 access_pio_ppmc_pbl_fifo_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[16]; +} + +static u64 access_pio_credit_ret_fifo_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[15]; +} + +static u64 access_pio_v1_len_mem_bank1_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[14]; +} + +static u64 access_pio_v1_len_mem_bank0_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[13]; +} + +static u64 access_pio_v1_len_mem_bank1_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[12]; +} + +static u64 access_pio_v1_len_mem_bank0_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[11]; +} + +static u64 access_pio_sm_pkt_reset_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[10]; +} + +static u64 access_pio_pkt_evict_fifo_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[9]; +} + +static u64 access_pio_sbrdctrl_crrel_fifo_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[8]; +} + +static u64 access_pio_sbrdctl_crrel_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[7]; +} + +static u64 access_pio_pec_fifo_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[6]; +} + +static u64 access_pio_pcc_fifo_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[5]; +} + +static u64 access_pio_sb_mem_fifo1_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[4]; +} + +static u64 access_pio_sb_mem_fifo0_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[3]; +} + +static u64 access_pio_csr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[2]; +} + +static u64 access_pio_write_addr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[1]; +} + +static u64 access_pio_write_bad_ctxt_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_pio_err_status_cnt[0]; +} + +/* + * Software counters corresponding to each of the + * error status bits within SendDmaErrStatus + */ +static u64 access_sdma_pcie_req_tracking_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_dma_err_status_cnt[3]; +} + +static u64 access_sdma_pcie_req_tracking_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_dma_err_status_cnt[2]; +} + +static u64 access_sdma_csr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_dma_err_status_cnt[1]; +} + +static u64 access_sdma_rpy_tag_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_dma_err_status_cnt[0]; +} + +/* + * Software counters corresponding to each of the + * error status bits within SendEgressErrStatus + */ +static u64 access_tx_read_pio_memory_csr_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[63]; +} + +static u64 access_tx_read_sdma_memory_csr_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[62]; +} + +static u64 access_tx_egress_fifo_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[61]; +} + +static u64 access_tx_read_pio_memory_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[60]; +} + +static u64 access_tx_read_sdma_memory_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[59]; +} + +static u64 access_tx_sb_hdr_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[58]; +} + +static u64 access_tx_credit_overrun_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[57]; +} + +static u64 access_tx_launch_fifo8_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[56]; +} + +static u64 access_tx_launch_fifo7_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[55]; +} + +static u64 access_tx_launch_fifo6_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[54]; +} + +static u64 access_tx_launch_fifo5_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[53]; +} + +static u64 access_tx_launch_fifo4_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[52]; +} + +static u64 access_tx_launch_fifo3_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[51]; +} + +static u64 access_tx_launch_fifo2_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[50]; +} + +static u64 access_tx_launch_fifo1_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[49]; +} + +static u64 access_tx_launch_fifo0_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[48]; +} + +static u64 access_tx_credit_return_vl_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[47]; +} + +static u64 access_tx_hcrc_insertion_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[46]; +} + +static u64 access_tx_egress_fifo_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[45]; +} + +static u64 access_tx_read_pio_memory_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[44]; +} + +static u64 access_tx_read_sdma_memory_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[43]; +} + +static u64 access_tx_sb_hdr_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[42]; +} + +static u64 access_tx_credit_return_partiy_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[41]; +} + +static u64 access_tx_launch_fifo8_unc_or_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[40]; +} + +static u64 access_tx_launch_fifo7_unc_or_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[39]; +} + +static u64 access_tx_launch_fifo6_unc_or_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[38]; +} + +static u64 access_tx_launch_fifo5_unc_or_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[37]; +} + +static u64 access_tx_launch_fifo4_unc_or_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[36]; +} + +static u64 access_tx_launch_fifo3_unc_or_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[35]; +} + +static u64 access_tx_launch_fifo2_unc_or_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[34]; +} + +static u64 access_tx_launch_fifo1_unc_or_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[33]; +} + +static u64 access_tx_launch_fifo0_unc_or_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[32]; +} + +static u64 access_tx_sdma15_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[31]; +} + +static u64 access_tx_sdma14_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[30]; +} + +static u64 access_tx_sdma13_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[29]; +} + +static u64 access_tx_sdma12_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[28]; +} + +static u64 access_tx_sdma11_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[27]; +} + +static u64 access_tx_sdma10_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[26]; +} + +static u64 access_tx_sdma9_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[25]; +} + +static u64 access_tx_sdma8_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[24]; +} + +static u64 access_tx_sdma7_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[23]; +} + +static u64 access_tx_sdma6_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[22]; +} + +static u64 access_tx_sdma5_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[21]; +} + +static u64 access_tx_sdma4_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[20]; +} + +static u64 access_tx_sdma3_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[19]; +} + +static u64 access_tx_sdma2_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[18]; +} + +static u64 access_tx_sdma1_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[17]; +} + +static u64 access_tx_sdma0_disallowed_packet_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[16]; +} + +static u64 access_tx_config_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[15]; +} + +static u64 access_tx_sbrd_ctl_csr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[14]; +} + +static u64 access_tx_launch_csr_parity_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[13]; +} + +static u64 access_tx_illegal_vl_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[12]; +} + +static u64 access_tx_sbrd_ctl_state_machine_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[11]; +} + +static u64 access_egress_reserved_10_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[10]; +} + +static u64 access_egress_reserved_9_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[9]; +} + +static u64 access_tx_sdma_launch_intf_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[8]; +} + +static u64 access_tx_pio_launch_intf_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[7]; +} + +static u64 access_egress_reserved_6_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[6]; +} + +static u64 access_tx_incorrect_link_state_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[5]; +} + +static u64 access_tx_linkdown_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[4]; +} + +static u64 access_tx_egress_fifi_underrun_or_parity_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[3]; +} + +static u64 access_egress_reserved_2_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[2]; +} + +static u64 access_tx_pkt_integrity_mem_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[1]; +} + +static u64 access_tx_pkt_integrity_mem_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_egress_err_status_cnt[0]; +} + +/* + * Software counters corresponding to each of the + * error status bits within SendErrStatus + */ +static u64 access_send_csr_write_bad_addr_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_err_status_cnt[2]; +} + +static u64 access_send_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_err_status_cnt[1]; +} + +static u64 access_send_csr_parity_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->send_err_status_cnt[0]; +} + +/* + * Software counters corresponding to each of the + * error status bits within SendCtxtErrStatus + */ +static u64 access_pio_write_out_of_bounds_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_ctxt_err_status_cnt[4]; +} + +static u64 access_pio_write_overflow_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_ctxt_err_status_cnt[3]; +} + +static u64 access_pio_write_crosses_boundary_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_ctxt_err_status_cnt[2]; +} + +static u64 access_pio_disallowed_packet_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_ctxt_err_status_cnt[1]; +} + +static u64 access_pio_inconsistent_sop_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_ctxt_err_status_cnt[0]; +} + +/* + * Software counters corresponding to each of the + * error status bits within SendDmaEngErrStatus + */ +static u64 access_sdma_header_request_fifo_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[23]; +} + +static u64 access_sdma_header_storage_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[22]; +} + +static u64 access_sdma_packet_tracking_cor_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[21]; +} + +static u64 access_sdma_assembly_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[20]; +} + +static u64 access_sdma_desc_table_cor_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[19]; +} + +static u64 access_sdma_header_request_fifo_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[18]; +} + +static u64 access_sdma_header_storage_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[17]; +} + +static u64 access_sdma_packet_tracking_unc_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[16]; +} + +static u64 access_sdma_assembly_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[15]; +} + +static u64 access_sdma_desc_table_unc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[14]; +} + +static u64 access_sdma_timeout_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[13]; +} + +static u64 access_sdma_header_length_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[12]; +} + +static u64 access_sdma_header_address_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[11]; +} + +static u64 access_sdma_header_select_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[10]; +} + +static u64 access_sdma_reserved_9_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[9]; +} + +static u64 access_sdma_packet_desc_overflow_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[8]; +} + +static u64 access_sdma_length_mismatch_err_cnt(const struct cntr_entry *entry, + void *context, int vl, + int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[7]; +} + +static u64 access_sdma_halt_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[6]; +} + +static u64 access_sdma_mem_read_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[5]; +} + +static u64 access_sdma_first_desc_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[4]; +} + +static u64 access_sdma_tail_out_of_bounds_err_cnt( + const struct cntr_entry *entry, + void *context, int vl, int mode, u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[3]; +} + +static u64 access_sdma_too_long_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[2]; +} + +static u64 access_sdma_gen_mismatch_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[1]; +} + +static u64 access_sdma_wrong_dw_err_cnt(const struct cntr_entry *entry, + void *context, int vl, int mode, + u64 data) +{ + struct hfi1_devdata *dd = (struct hfi1_devdata *)context; + + return dd->sw_send_dma_eng_err_status_cnt[0]; +} + #define def_access_sw_cpu(cntr) \ static u64 access_sw_cpu_##cntr(const struct cntr_entry *entry, \ void *context, int vl, int mode, u64 data) \ @@ -1587,8 +3929,6 @@ static struct cntr_entry dev_cntrs[DEV_CNTR_LAST] = { [C_RX_TID_FLGMS] = RXE32_DEV_CNTR_ELEM(RxTidFLGMs, RCV_TID_FLOW_GEN_MISMATCH_CNT, CNTR_NORMAL), -[C_RX_CTX_RHQS] = RXE32_DEV_CNTR_ELEM(RxCtxRHQS, RCV_CONTEXT_RHQ_STALL, - CNTR_NORMAL), [C_RX_CTX_EGRS] = RXE32_DEV_CNTR_ELEM(RxCtxEgrS, RCV_CONTEXT_EGR_STALL, CNTR_NORMAL), [C_RCV_TID_FLSMS] = RXE32_DEV_CNTR_ELEM(RxTidFLSMs, @@ -1730,6 +4070,794 @@ static struct cntr_entry dev_cntrs[DEV_CNTR_LAST] = { access_sw_kmem_wait), [C_SW_SEND_SCHED] = CNTR_ELEM("SendSched", 0, 0, CNTR_NORMAL, access_sw_send_schedule), +/* MISC_ERR_STATUS */ +[C_MISC_PLL_LOCK_FAIL_ERR] = CNTR_ELEM("MISC_PLL_LOCK_FAIL_ERR", 0, 0, + CNTR_NORMAL, + access_misc_pll_lock_fail_err_cnt), +[C_MISC_MBIST_FAIL_ERR] = CNTR_ELEM("MISC_MBIST_FAIL_ERR", 0, 0, + CNTR_NORMAL, + access_misc_mbist_fail_err_cnt), +[C_MISC_INVALID_EEP_CMD_ERR] = CNTR_ELEM("MISC_INVALID_EEP_CMD_ERR", 0, 0, + CNTR_NORMAL, + access_misc_invalid_eep_cmd_err_cnt), +[C_MISC_EFUSE_DONE_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_DONE_PARITY_ERR", 0, 0, + CNTR_NORMAL, + access_misc_efuse_done_parity_err_cnt), +[C_MISC_EFUSE_WRITE_ERR] = CNTR_ELEM("MISC_EFUSE_WRITE_ERR", 0, 0, + CNTR_NORMAL, + access_misc_efuse_write_err_cnt), +[C_MISC_EFUSE_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_EFUSE_READ_BAD_ADDR_ERR", 0, + 0, CNTR_NORMAL, + access_misc_efuse_read_bad_addr_err_cnt), +[C_MISC_EFUSE_CSR_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_CSR_PARITY_ERR", 0, 0, + CNTR_NORMAL, + access_misc_efuse_csr_parity_err_cnt), +[C_MISC_FW_AUTH_FAILED_ERR] = CNTR_ELEM("MISC_FW_AUTH_FAILED_ERR", 0, 0, + CNTR_NORMAL, + access_misc_fw_auth_failed_err_cnt), +[C_MISC_KEY_MISMATCH_ERR] = CNTR_ELEM("MISC_KEY_MISMATCH_ERR", 0, 0, + CNTR_NORMAL, + access_misc_key_mismatch_err_cnt), +[C_MISC_SBUS_WRITE_FAILED_ERR] = CNTR_ELEM("MISC_SBUS_WRITE_FAILED_ERR", 0, 0, + CNTR_NORMAL, + access_misc_sbus_write_failed_err_cnt), +[C_MISC_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_WRITE_BAD_ADDR_ERR", 0, 0, + CNTR_NORMAL, + access_misc_csr_write_bad_addr_err_cnt), +[C_MISC_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_READ_BAD_ADDR_ERR", 0, 0, + CNTR_NORMAL, + access_misc_csr_read_bad_addr_err_cnt), +[C_MISC_CSR_PARITY_ERR] = CNTR_ELEM("MISC_CSR_PARITY_ERR", 0, 0, + CNTR_NORMAL, + access_misc_csr_parity_err_cnt), +/* CceErrStatus */ +[C_CCE_ERR_STATUS_AGGREGATED_CNT] = CNTR_ELEM("CceErrStatusAggregatedCnt", 0, 0, + CNTR_NORMAL, + access_sw_cce_err_status_aggregated_cnt), +[C_CCE_MSIX_CSR_PARITY_ERR] = CNTR_ELEM("CceMsixCsrParityErr", 0, 0, + CNTR_NORMAL, + access_cce_msix_csr_parity_err_cnt), +[C_CCE_INT_MAP_UNC_ERR] = CNTR_ELEM("CceIntMapUncErr", 0, 0, + CNTR_NORMAL, + access_cce_int_map_unc_err_cnt), +[C_CCE_INT_MAP_COR_ERR] = CNTR_ELEM("CceIntMapCorErr", 0, 0, + CNTR_NORMAL, + access_cce_int_map_cor_err_cnt), +[C_CCE_MSIX_TABLE_UNC_ERR] = CNTR_ELEM("CceMsixTableUncErr", 0, 0, + CNTR_NORMAL, + access_cce_msix_table_unc_err_cnt), +[C_CCE_MSIX_TABLE_COR_ERR] = CNTR_ELEM("CceMsixTableCorErr", 0, 0, + CNTR_NORMAL, + access_cce_msix_table_cor_err_cnt), +[C_CCE_RXDMA_CONV_FIFO_PARITY_ERR] = CNTR_ELEM("CceRxdmaConvFifoParityErr", 0, + 0, CNTR_NORMAL, + access_cce_rxdma_conv_fifo_parity_err_cnt), +[C_CCE_RCPL_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceRcplAsyncFifoParityErr", 0, + 0, CNTR_NORMAL, + access_cce_rcpl_async_fifo_parity_err_cnt), +[C_CCE_SEG_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceSegWriteBadAddrErr", 0, 0, + CNTR_NORMAL, + access_cce_seg_write_bad_addr_err_cnt), +[C_CCE_SEG_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceSegReadBadAddrErr", 0, 0, + CNTR_NORMAL, + access_cce_seg_read_bad_addr_err_cnt), +[C_LA_TRIGGERED] = CNTR_ELEM("Cce LATriggered", 0, 0, + CNTR_NORMAL, + access_la_triggered_cnt), +[C_CCE_TRGT_CPL_TIMEOUT_ERR] = CNTR_ELEM("CceTrgtCplTimeoutErr", 0, 0, + CNTR_NORMAL, + access_cce_trgt_cpl_timeout_err_cnt), +[C_PCIC_RECEIVE_PARITY_ERR] = CNTR_ELEM("PcicReceiveParityErr", 0, 0, + CNTR_NORMAL, + access_pcic_receive_parity_err_cnt), +[C_PCIC_TRANSMIT_BACK_PARITY_ERR] = CNTR_ELEM("PcicTransmitBackParityErr", 0, 0, + CNTR_NORMAL, + access_pcic_transmit_back_parity_err_cnt), +[C_PCIC_TRANSMIT_FRONT_PARITY_ERR] = CNTR_ELEM("PcicTransmitFrontParityErr", 0, + 0, CNTR_NORMAL, + access_pcic_transmit_front_parity_err_cnt), +[C_PCIC_CPL_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicCplDatQUncErr", 0, 0, + CNTR_NORMAL, + access_pcic_cpl_dat_q_unc_err_cnt), +[C_PCIC_CPL_HD_Q_UNC_ERR] = CNTR_ELEM("PcicCplHdQUncErr", 0, 0, + CNTR_NORMAL, + access_pcic_cpl_hd_q_unc_err_cnt), +[C_PCIC_POST_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicPostDatQUncErr", 0, 0, + CNTR_NORMAL, + access_pcic_post_dat_q_unc_err_cnt), +[C_PCIC_POST_HD_Q_UNC_ERR] = CNTR_ELEM("PcicPostHdQUncErr", 0, 0, + CNTR_NORMAL, + access_pcic_post_hd_q_unc_err_cnt), +[C_PCIC_RETRY_SOT_MEM_UNC_ERR] = CNTR_ELEM("PcicRetrySotMemUncErr", 0, 0, + CNTR_NORMAL, + access_pcic_retry_sot_mem_unc_err_cnt), +[C_PCIC_RETRY_MEM_UNC_ERR] = CNTR_ELEM("PcicRetryMemUncErr", 0, 0, + CNTR_NORMAL, + access_pcic_retry_mem_unc_err), +[C_PCIC_N_POST_DAT_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostDatQParityErr", 0, 0, + CNTR_NORMAL, + access_pcic_n_post_dat_q_parity_err_cnt), +[C_PCIC_N_POST_H_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostHQParityErr", 0, 0, + CNTR_NORMAL, + access_pcic_n_post_h_q_parity_err_cnt), +[C_PCIC_CPL_DAT_Q_COR_ERR] = CNTR_ELEM("PcicCplDatQCorErr", 0, 0, + CNTR_NORMAL, + access_pcic_cpl_dat_q_cor_err_cnt), +[C_PCIC_CPL_HD_Q_COR_ERR] = CNTR_ELEM("PcicCplHdQCorErr", 0, 0, + CNTR_NORMAL, + access_pcic_cpl_hd_q_cor_err_cnt), +[C_PCIC_POST_DAT_Q_COR_ERR] = CNTR_ELEM("PcicPostDatQCorErr", 0, 0, + CNTR_NORMAL, + access_pcic_post_dat_q_cor_err_cnt), +[C_PCIC_POST_HD_Q_COR_ERR] = CNTR_ELEM("PcicPostHdQCorErr", 0, 0, + CNTR_NORMAL, + access_pcic_post_hd_q_cor_err_cnt), +[C_PCIC_RETRY_SOT_MEM_COR_ERR] = CNTR_ELEM("PcicRetrySotMemCorErr", 0, 0, + CNTR_NORMAL, + access_pcic_retry_sot_mem_cor_err_cnt), +[C_PCIC_RETRY_MEM_COR_ERR] = CNTR_ELEM("PcicRetryMemCorErr", 0, 0, + CNTR_NORMAL, + access_pcic_retry_mem_cor_err_cnt), +[C_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERR] = CNTR_ELEM( + "CceCli1AsyncFifoDbgParityError", 0, 0, + CNTR_NORMAL, + access_cce_cli1_async_fifo_dbg_parity_err_cnt), +[C_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERR] = CNTR_ELEM( + "CceCli1AsyncFifoRxdmaParityError", 0, 0, + CNTR_NORMAL, + access_cce_cli1_async_fifo_rxdma_parity_err_cnt + ), +[C_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR] = CNTR_ELEM( + "CceCli1AsyncFifoSdmaHdParityErr", 0, 0, + CNTR_NORMAL, + access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt), +[C_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR] = CNTR_ELEM( + "CceCli1AsyncFifoPioCrdtParityErr", 0, 0, + CNTR_NORMAL, + access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt), +[C_CCE_CLI2_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceCli2AsyncFifoParityErr", 0, + 0, CNTR_NORMAL, + access_cce_cli2_async_fifo_parity_err_cnt), +[C_CCE_CSR_CFG_BUS_PARITY_ERR] = CNTR_ELEM("CceCsrCfgBusParityErr", 0, 0, + CNTR_NORMAL, + access_cce_csr_cfg_bus_parity_err_cnt), +[C_CCE_CLI0_ASYNC_FIFO_PARTIY_ERR] = CNTR_ELEM("CceCli0AsyncFifoParityErr", 0, + 0, CNTR_NORMAL, + access_cce_cli0_async_fifo_parity_err_cnt), +[C_CCE_RSPD_DATA_PARITY_ERR] = CNTR_ELEM("CceRspdDataParityErr", 0, 0, + CNTR_NORMAL, + access_cce_rspd_data_parity_err_cnt), +[C_CCE_TRGT_ACCESS_ERR] = CNTR_ELEM("CceTrgtAccessErr", 0, 0, + CNTR_NORMAL, + access_cce_trgt_access_err_cnt), +[C_CCE_TRGT_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceTrgtAsyncFifoParityErr", 0, + 0, CNTR_NORMAL, + access_cce_trgt_async_fifo_parity_err_cnt), +[C_CCE_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrWriteBadAddrErr", 0, 0, + CNTR_NORMAL, + access_cce_csr_write_bad_addr_err_cnt), +[C_CCE_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrReadBadAddrErr", 0, 0, + CNTR_NORMAL, + access_cce_csr_read_bad_addr_err_cnt), +[C_CCE_CSR_PARITY_ERR] = CNTR_ELEM("CceCsrParityErr", 0, 0, + CNTR_NORMAL, + access_ccs_csr_parity_err_cnt), + +/* RcvErrStatus */ +[C_RX_CSR_PARITY_ERR] = CNTR_ELEM("RxCsrParityErr", 0, 0, + CNTR_NORMAL, + access_rx_csr_parity_err_cnt), +[C_RX_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrWriteBadAddrErr", 0, 0, + CNTR_NORMAL, + access_rx_csr_write_bad_addr_err_cnt), +[C_RX_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrReadBadAddrErr", 0, 0, + CNTR_NORMAL, + access_rx_csr_read_bad_addr_err_cnt), +[C_RX_DMA_CSR_UNC_ERR] = CNTR_ELEM("RxDmaCsrUncErr", 0, 0, + CNTR_NORMAL, + access_rx_dma_csr_unc_err_cnt), +[C_RX_DMA_DQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaDqFsmEncodingErr", 0, 0, + CNTR_NORMAL, + access_rx_dma_dq_fsm_encoding_err_cnt), +[C_RX_DMA_EQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaEqFsmEncodingErr", 0, 0, + CNTR_NORMAL, + access_rx_dma_eq_fsm_encoding_err_cnt), +[C_RX_DMA_CSR_PARITY_ERR] = CNTR_ELEM("RxDmaCsrParityErr", 0, 0, + CNTR_NORMAL, + access_rx_dma_csr_parity_err_cnt), +[C_RX_RBUF_DATA_COR_ERR] = CNTR_ELEM("RxRbufDataCorErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_data_cor_err_cnt), +[C_RX_RBUF_DATA_UNC_ERR] = CNTR_ELEM("RxRbufDataUncErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_data_unc_err_cnt), +[C_RX_DMA_DATA_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaDataFifoRdCorErr", 0, 0, + CNTR_NORMAL, + access_rx_dma_data_fifo_rd_cor_err_cnt), +[C_RX_DMA_DATA_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaDataFifoRdUncErr", 0, 0, + CNTR_NORMAL, + access_rx_dma_data_fifo_rd_unc_err_cnt), +[C_RX_DMA_HDR_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaHdrFifoRdCorErr", 0, 0, + CNTR_NORMAL, + access_rx_dma_hdr_fifo_rd_cor_err_cnt), +[C_RX_DMA_HDR_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaHdrFifoRdUncErr", 0, 0, + CNTR_NORMAL, + access_rx_dma_hdr_fifo_rd_unc_err_cnt), +[C_RX_RBUF_DESC_PART2_COR_ERR] = CNTR_ELEM("RxRbufDescPart2CorErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_desc_part2_cor_err_cnt), +[C_RX_RBUF_DESC_PART2_UNC_ERR] = CNTR_ELEM("RxRbufDescPart2UncErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_desc_part2_unc_err_cnt), +[C_RX_RBUF_DESC_PART1_COR_ERR] = CNTR_ELEM("RxRbufDescPart1CorErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_desc_part1_cor_err_cnt), +[C_RX_RBUF_DESC_PART1_UNC_ERR] = CNTR_ELEM("RxRbufDescPart1UncErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_desc_part1_unc_err_cnt), +[C_RX_HQ_INTR_FSM_ERR] = CNTR_ELEM("RxHqIntrFsmErr", 0, 0, + CNTR_NORMAL, + access_rx_hq_intr_fsm_err_cnt), +[C_RX_HQ_INTR_CSR_PARITY_ERR] = CNTR_ELEM("RxHqIntrCsrParityErr", 0, 0, + CNTR_NORMAL, + access_rx_hq_intr_csr_parity_err_cnt), +[C_RX_LOOKUP_CSR_PARITY_ERR] = CNTR_ELEM("RxLookupCsrParityErr", 0, 0, + CNTR_NORMAL, + access_rx_lookup_csr_parity_err_cnt), +[C_RX_LOOKUP_RCV_ARRAY_COR_ERR] = CNTR_ELEM("RxLookupRcvArrayCorErr", 0, 0, + CNTR_NORMAL, + access_rx_lookup_rcv_array_cor_err_cnt), +[C_RX_LOOKUP_RCV_ARRAY_UNC_ERR] = CNTR_ELEM("RxLookupRcvArrayUncErr", 0, 0, + CNTR_NORMAL, + access_rx_lookup_rcv_array_unc_err_cnt), +[C_RX_LOOKUP_DES_PART2_PARITY_ERR] = CNTR_ELEM("RxLookupDesPart2ParityErr", 0, + 0, CNTR_NORMAL, + access_rx_lookup_des_part2_parity_err_cnt), +[C_RX_LOOKUP_DES_PART1_UNC_COR_ERR] = CNTR_ELEM("RxLookupDesPart1UncCorErr", 0, + 0, CNTR_NORMAL, + access_rx_lookup_des_part1_unc_cor_err_cnt), +[C_RX_LOOKUP_DES_PART1_UNC_ERR] = CNTR_ELEM("RxLookupDesPart1UncErr", 0, 0, + CNTR_NORMAL, + access_rx_lookup_des_part1_unc_err_cnt), +[C_RX_RBUF_NEXT_FREE_BUF_COR_ERR] = CNTR_ELEM("RxRbufNextFreeBufCorErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_next_free_buf_cor_err_cnt), +[C_RX_RBUF_NEXT_FREE_BUF_UNC_ERR] = CNTR_ELEM("RxRbufNextFreeBufUncErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_next_free_buf_unc_err_cnt), +[C_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR] = CNTR_ELEM( + "RxRbufFlInitWrAddrParityErr", 0, 0, + CNTR_NORMAL, + access_rbuf_fl_init_wr_addr_parity_err_cnt), +[C_RX_RBUF_FL_INITDONE_PARITY_ERR] = CNTR_ELEM("RxRbufFlInitdoneParityErr", 0, + 0, CNTR_NORMAL, + access_rx_rbuf_fl_initdone_parity_err_cnt), +[C_RX_RBUF_FL_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlWrAddrParityErr", 0, + 0, CNTR_NORMAL, + access_rx_rbuf_fl_write_addr_parity_err_cnt), +[C_RX_RBUF_FL_RD_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlRdAddrParityErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_fl_rd_addr_parity_err_cnt), +[C_RX_RBUF_EMPTY_ERR] = CNTR_ELEM("RxRbufEmptyErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_empty_err_cnt), +[C_RX_RBUF_FULL_ERR] = CNTR_ELEM("RxRbufFullErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_full_err_cnt), +[C_RX_RBUF_BAD_LOOKUP_ERR] = CNTR_ELEM("RxRBufBadLookupErr", 0, 0, + CNTR_NORMAL, + access_rbuf_bad_lookup_err_cnt), +[C_RX_RBUF_CTX_ID_PARITY_ERR] = CNTR_ELEM("RxRbufCtxIdParityErr", 0, 0, + CNTR_NORMAL, + access_rbuf_ctx_id_parity_err_cnt), +[C_RX_RBUF_CSR_QEOPDW_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEOPDWParityErr", 0, 0, + CNTR_NORMAL, + access_rbuf_csr_qeopdw_parity_err_cnt), +[C_RX_RBUF_CSR_Q_NUM_OF_PKT_PARITY_ERR] = CNTR_ELEM( + "RxRbufCsrQNumOfPktParityErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt), +[C_RX_RBUF_CSR_Q_T1_PTR_PARITY_ERR] = CNTR_ELEM( + "RxRbufCsrQTlPtrParityErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt), +[C_RX_RBUF_CSR_Q_HD_PTR_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQHdPtrParityErr", 0, + 0, CNTR_NORMAL, + access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt), +[C_RX_RBUF_CSR_Q_VLD_BIT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQVldBitParityErr", 0, + 0, CNTR_NORMAL, + access_rx_rbuf_csr_q_vld_bit_parity_err_cnt), +[C_RX_RBUF_CSR_Q_NEXT_BUF_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQNextBufParityErr", + 0, 0, CNTR_NORMAL, + access_rx_rbuf_csr_q_next_buf_parity_err_cnt), +[C_RX_RBUF_CSR_Q_ENT_CNT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEntCntParityErr", 0, + 0, CNTR_NORMAL, + access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt), +[C_RX_RBUF_CSR_Q_HEAD_BUF_NUM_PARITY_ERR] = CNTR_ELEM( + "RxRbufCsrQHeadBufNumParityErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt), +[C_RX_RBUF_BLOCK_LIST_READ_COR_ERR] = CNTR_ELEM("RxRbufBlockListReadCorErr", 0, + 0, CNTR_NORMAL, + access_rx_rbuf_block_list_read_cor_err_cnt), +[C_RX_RBUF_BLOCK_LIST_READ_UNC_ERR] = CNTR_ELEM("RxRbufBlockListReadUncErr", 0, + 0, CNTR_NORMAL, + access_rx_rbuf_block_list_read_unc_err_cnt), +[C_RX_RBUF_LOOKUP_DES_COR_ERR] = CNTR_ELEM("RxRbufLookupDesCorErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_lookup_des_cor_err_cnt), +[C_RX_RBUF_LOOKUP_DES_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesUncErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_lookup_des_unc_err_cnt), +[C_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR] = CNTR_ELEM( + "RxRbufLookupDesRegUncCorErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt), +[C_RX_RBUF_LOOKUP_DES_REG_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesRegUncErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_lookup_des_reg_unc_err_cnt), +[C_RX_RBUF_FREE_LIST_COR_ERR] = CNTR_ELEM("RxRbufFreeListCorErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_free_list_cor_err_cnt), +[C_RX_RBUF_FREE_LIST_UNC_ERR] = CNTR_ELEM("RxRbufFreeListUncErr", 0, 0, + CNTR_NORMAL, + access_rx_rbuf_free_list_unc_err_cnt), +[C_RX_RCV_FSM_ENCODING_ERR] = CNTR_ELEM("RxRcvFsmEncodingErr", 0, 0, + CNTR_NORMAL, + access_rx_rcv_fsm_encoding_err_cnt), +[C_RX_DMA_FLAG_COR_ERR] = CNTR_ELEM("RxDmaFlagCorErr", 0, 0, + CNTR_NORMAL, + access_rx_dma_flag_cor_err_cnt), +[C_RX_DMA_FLAG_UNC_ERR] = CNTR_ELEM("RxDmaFlagUncErr", 0, 0, + CNTR_NORMAL, + access_rx_dma_flag_unc_err_cnt), +[C_RX_DC_SOP_EOP_PARITY_ERR] = CNTR_ELEM("RxDcSopEopParityErr", 0, 0, + CNTR_NORMAL, + access_rx_dc_sop_eop_parity_err_cnt), +[C_RX_RCV_CSR_PARITY_ERR] = CNTR_ELEM("RxRcvCsrParityErr", 0, 0, + CNTR_NORMAL, + access_rx_rcv_csr_parity_err_cnt), +[C_RX_RCV_QP_MAP_TABLE_COR_ERR] = CNTR_ELEM("RxRcvQpMapTableCorErr", 0, 0, + CNTR_NORMAL, + access_rx_rcv_qp_map_table_cor_err_cnt), +[C_RX_RCV_QP_MAP_TABLE_UNC_ERR] = CNTR_ELEM("RxRcvQpMapTableUncErr", 0, 0, + CNTR_NORMAL, + access_rx_rcv_qp_map_table_unc_err_cnt), +[C_RX_RCV_DATA_COR_ERR] = CNTR_ELEM("RxRcvDataCorErr", 0, 0, + CNTR_NORMAL, + access_rx_rcv_data_cor_err_cnt), +[C_RX_RCV_DATA_UNC_ERR] = CNTR_ELEM("RxRcvDataUncErr", 0, 0, + CNTR_NORMAL, + access_rx_rcv_data_unc_err_cnt), +[C_RX_RCV_HDR_COR_ERR] = CNTR_ELEM("RxRcvHdrCorErr", 0, 0, + CNTR_NORMAL, + access_rx_rcv_hdr_cor_err_cnt), +[C_RX_RCV_HDR_UNC_ERR] = CNTR_ELEM("RxRcvHdrUncErr", 0, 0, + CNTR_NORMAL, + access_rx_rcv_hdr_unc_err_cnt), +[C_RX_DC_INTF_PARITY_ERR] = CNTR_ELEM("RxDcIntfParityErr", 0, 0, + CNTR_NORMAL, + access_rx_dc_intf_parity_err_cnt), +[C_RX_DMA_CSR_COR_ERR] = CNTR_ELEM("RxDmaCsrCorErr", 0, 0, + CNTR_NORMAL, + access_rx_dma_csr_cor_err_cnt), +/* SendPioErrStatus */ +[C_PIO_PEC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPecSopHeadParityErr", 0, 0, + CNTR_NORMAL, + access_pio_pec_sop_head_parity_err_cnt), +[C_PIO_PCC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPccSopHeadParityErr", 0, 0, + CNTR_NORMAL, + access_pio_pcc_sop_head_parity_err_cnt), +[C_PIO_LAST_RETURNED_CNT_PARITY_ERR] = CNTR_ELEM("PioLastReturnedCntParityErr", + 0, 0, CNTR_NORMAL, + access_pio_last_returned_cnt_parity_err_cnt), +[C_PIO_CURRENT_FREE_CNT_PARITY_ERR] = CNTR_ELEM("PioCurrentFreeCntParityErr", 0, + 0, CNTR_NORMAL, + access_pio_current_free_cnt_parity_err_cnt), +[C_PIO_RSVD_31_ERR] = CNTR_ELEM("Pio Reserved 31", 0, 0, + CNTR_NORMAL, + access_pio_reserved_31_err_cnt), +[C_PIO_RSVD_30_ERR] = CNTR_ELEM("Pio Reserved 30", 0, 0, + CNTR_NORMAL, + access_pio_reserved_30_err_cnt), +[C_PIO_PPMC_SOP_LEN_ERR] = CNTR_ELEM("PioPpmcSopLenErr", 0, 0, + CNTR_NORMAL, + access_pio_ppmc_sop_len_err_cnt), +[C_PIO_PPMC_BQC_MEM_PARITY_ERR] = CNTR_ELEM("PioPpmcBqcMemParityErr", 0, 0, + CNTR_NORMAL, + access_pio_ppmc_bqc_mem_parity_err_cnt), +[C_PIO_VL_FIFO_PARITY_ERR] = CNTR_ELEM("PioVlFifoParityErr", 0, 0, + CNTR_NORMAL, + access_pio_vl_fifo_parity_err_cnt), +[C_PIO_VLF_SOP_PARITY_ERR] = CNTR_ELEM("PioVlfSopParityErr", 0, 0, + CNTR_NORMAL, + access_pio_vlf_sop_parity_err_cnt), +[C_PIO_VLF_V1_LEN_PARITY_ERR] = CNTR_ELEM("PioVlfVlLenParityErr", 0, 0, + CNTR_NORMAL, + access_pio_vlf_v1_len_parity_err_cnt), +[C_PIO_BLOCK_QW_COUNT_PARITY_ERR] = CNTR_ELEM("PioBlockQwCountParityErr", 0, 0, + CNTR_NORMAL, + access_pio_block_qw_count_parity_err_cnt), +[C_PIO_WRITE_QW_VALID_PARITY_ERR] = CNTR_ELEM("PioWriteQwValidParityErr", 0, 0, + CNTR_NORMAL, + access_pio_write_qw_valid_parity_err_cnt), +[C_PIO_STATE_MACHINE_ERR] = CNTR_ELEM("PioStateMachineErr", 0, 0, + CNTR_NORMAL, + access_pio_state_machine_err_cnt), +[C_PIO_WRITE_DATA_PARITY_ERR] = CNTR_ELEM("PioWriteDataParityErr", 0, 0, + CNTR_NORMAL, + access_pio_write_data_parity_err_cnt), +[C_PIO_HOST_ADDR_MEM_COR_ERR] = CNTR_ELEM("PioHostAddrMemCorErr", 0, 0, + CNTR_NORMAL, + access_pio_host_addr_mem_cor_err_cnt), +[C_PIO_HOST_ADDR_MEM_UNC_ERR] = CNTR_ELEM("PioHostAddrMemUncErr", 0, 0, + CNTR_NORMAL, + access_pio_host_addr_mem_unc_err_cnt), +[C_PIO_PKT_EVICT_SM_OR_ARM_SM_ERR] = CNTR_ELEM("PioPktEvictSmOrArbSmErr", 0, 0, + CNTR_NORMAL, + access_pio_pkt_evict_sm_or_arb_sm_err_cnt), +[C_PIO_INIT_SM_IN_ERR] = CNTR_ELEM("PioInitSmInErr", 0, 0, + CNTR_NORMAL, + access_pio_init_sm_in_err_cnt), +[C_PIO_PPMC_PBL_FIFO_ERR] = CNTR_ELEM("PioPpmcPblFifoErr", 0, 0, + CNTR_NORMAL, + access_pio_ppmc_pbl_fifo_err_cnt), +[C_PIO_CREDIT_RET_FIFO_PARITY_ERR] = CNTR_ELEM("PioCreditRetFifoParityErr", 0, + 0, CNTR_NORMAL, + access_pio_credit_ret_fifo_parity_err_cnt), +[C_PIO_V1_LEN_MEM_BANK1_COR_ERR] = CNTR_ELEM("PioVlLenMemBank1CorErr", 0, 0, + CNTR_NORMAL, + access_pio_v1_len_mem_bank1_cor_err_cnt), +[C_PIO_V1_LEN_MEM_BANK0_COR_ERR] = CNTR_ELEM("PioVlLenMemBank0CorErr", 0, 0, + CNTR_NORMAL, + access_pio_v1_len_mem_bank0_cor_err_cnt), +[C_PIO_V1_LEN_MEM_BANK1_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank1UncErr", 0, 0, + CNTR_NORMAL, + access_pio_v1_len_mem_bank1_unc_err_cnt), +[C_PIO_V1_LEN_MEM_BANK0_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank0UncErr", 0, 0, + CNTR_NORMAL, + access_pio_v1_len_mem_bank0_unc_err_cnt), +[C_PIO_SM_PKT_RESET_PARITY_ERR] = CNTR_ELEM("PioSmPktResetParityErr", 0, 0, + CNTR_NORMAL, + access_pio_sm_pkt_reset_parity_err_cnt), +[C_PIO_PKT_EVICT_FIFO_PARITY_ERR] = CNTR_ELEM("PioPktEvictFifoParityErr", 0, 0, + CNTR_NORMAL, + access_pio_pkt_evict_fifo_parity_err_cnt), +[C_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR] = CNTR_ELEM( + "PioSbrdctrlCrrelFifoParityErr", 0, 0, + CNTR_NORMAL, + access_pio_sbrdctrl_crrel_fifo_parity_err_cnt), +[C_PIO_SBRDCTL_CRREL_PARITY_ERR] = CNTR_ELEM("PioSbrdctlCrrelParityErr", 0, 0, + CNTR_NORMAL, + access_pio_sbrdctl_crrel_parity_err_cnt), +[C_PIO_PEC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPecFifoParityErr", 0, 0, + CNTR_NORMAL, + access_pio_pec_fifo_parity_err_cnt), +[C_PIO_PCC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPccFifoParityErr", 0, 0, + CNTR_NORMAL, + access_pio_pcc_fifo_parity_err_cnt), +[C_PIO_SB_MEM_FIFO1_ERR] = CNTR_ELEM("PioSbMemFifo1Err", 0, 0, + CNTR_NORMAL, + access_pio_sb_mem_fifo1_err_cnt), +[C_PIO_SB_MEM_FIFO0_ERR] = CNTR_ELEM("PioSbMemFifo0Err", 0, 0, + CNTR_NORMAL, + access_pio_sb_mem_fifo0_err_cnt), +[C_PIO_CSR_PARITY_ERR] = CNTR_ELEM("PioCsrParityErr", 0, 0, + CNTR_NORMAL, + access_pio_csr_parity_err_cnt), +[C_PIO_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("PioWriteAddrParityErr", 0, 0, + CNTR_NORMAL, + access_pio_write_addr_parity_err_cnt), +[C_PIO_WRITE_BAD_CTXT_ERR] = CNTR_ELEM("PioWriteBadCtxtErr", 0, 0, + CNTR_NORMAL, + access_pio_write_bad_ctxt_err_cnt), +/* SendDmaErrStatus */ +[C_SDMA_PCIE_REQ_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPcieReqTrackingCorErr", 0, + 0, CNTR_NORMAL, + access_sdma_pcie_req_tracking_cor_err_cnt), +[C_SDMA_PCIE_REQ_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPcieReqTrackingUncErr", 0, + 0, CNTR_NORMAL, + access_sdma_pcie_req_tracking_unc_err_cnt), +[C_SDMA_CSR_PARITY_ERR] = CNTR_ELEM("SDmaCsrParityErr", 0, 0, + CNTR_NORMAL, + access_sdma_csr_parity_err_cnt), +[C_SDMA_RPY_TAG_ERR] = CNTR_ELEM("SDmaRpyTagErr", 0, 0, + CNTR_NORMAL, + access_sdma_rpy_tag_err_cnt), +/* SendEgressErrStatus */ +[C_TX_READ_PIO_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryCsrUncErr", 0, 0, + CNTR_NORMAL, + access_tx_read_pio_memory_csr_unc_err_cnt), +[C_TX_READ_SDMA_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryCsrUncErr", 0, + 0, CNTR_NORMAL, + access_tx_read_sdma_memory_csr_err_cnt), +[C_TX_EGRESS_FIFO_COR_ERR] = CNTR_ELEM("TxEgressFifoCorErr", 0, 0, + CNTR_NORMAL, + access_tx_egress_fifo_cor_err_cnt), +[C_TX_READ_PIO_MEMORY_COR_ERR] = CNTR_ELEM("TxReadPioMemoryCorErr", 0, 0, + CNTR_NORMAL, + access_tx_read_pio_memory_cor_err_cnt), +[C_TX_READ_SDMA_MEMORY_COR_ERR] = CNTR_ELEM("TxReadSdmaMemoryCorErr", 0, 0, + CNTR_NORMAL, + access_tx_read_sdma_memory_cor_err_cnt), +[C_TX_SB_HDR_COR_ERR] = CNTR_ELEM("TxSbHdrCorErr", 0, 0, + CNTR_NORMAL, + access_tx_sb_hdr_cor_err_cnt), +[C_TX_CREDIT_OVERRUN_ERR] = CNTR_ELEM("TxCreditOverrunErr", 0, 0, + CNTR_NORMAL, + access_tx_credit_overrun_err_cnt), +[C_TX_LAUNCH_FIFO8_COR_ERR] = CNTR_ELEM("TxLaunchFifo8CorErr", 0, 0, + CNTR_NORMAL, + access_tx_launch_fifo8_cor_err_cnt), +[C_TX_LAUNCH_FIFO7_COR_ERR] = CNTR_ELEM("TxLaunchFifo7CorErr", 0, 0, + CNTR_NORMAL, + access_tx_launch_fifo7_cor_err_cnt), +[C_TX_LAUNCH_FIFO6_COR_ERR] = CNTR_ELEM("TxLaunchFifo6CorErr", 0, 0, + CNTR_NORMAL, + access_tx_launch_fifo6_cor_err_cnt), +[C_TX_LAUNCH_FIFO5_COR_ERR] = CNTR_ELEM("TxLaunchFifo5CorErr", 0, 0, + CNTR_NORMAL, + access_tx_launch_fifo5_cor_err_cnt), +[C_TX_LAUNCH_FIFO4_COR_ERR] = CNTR_ELEM("TxLaunchFifo4CorErr", 0, 0, + CNTR_NORMAL, + access_tx_launch_fifo4_cor_err_cnt), +[C_TX_LAUNCH_FIFO3_COR_ERR] = CNTR_ELEM("TxLaunchFifo3CorErr", 0, 0, + CNTR_NORMAL, + access_tx_launch_fifo3_cor_err_cnt), +[C_TX_LAUNCH_FIFO2_COR_ERR] = CNTR_ELEM("TxLaunchFifo2CorErr", 0, 0, + CNTR_NORMAL, + access_tx_launch_fifo2_cor_err_cnt), +[C_TX_LAUNCH_FIFO1_COR_ERR] = CNTR_ELEM("TxLaunchFifo1CorErr", 0, 0, + CNTR_NORMAL, + access_tx_launch_fifo1_cor_err_cnt), +[C_TX_LAUNCH_FIFO0_COR_ERR] = CNTR_ELEM("TxLaunchFifo0CorErr", 0, 0, + CNTR_NORMAL, + access_tx_launch_fifo0_cor_err_cnt), +[C_TX_CREDIT_RETURN_VL_ERR] = CNTR_ELEM("TxCreditReturnVLErr", 0, 0, + CNTR_NORMAL, + access_tx_credit_return_vl_err_cnt), +[C_TX_HCRC_INSERTION_ERR] = CNTR_ELEM("TxHcrcInsertionErr", 0, 0, + CNTR_NORMAL, + access_tx_hcrc_insertion_err_cnt), +[C_TX_EGRESS_FIFI_UNC_ERR] = CNTR_ELEM("TxEgressFifoUncErr", 0, 0, + CNTR_NORMAL, + access_tx_egress_fifo_unc_err_cnt), +[C_TX_READ_PIO_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryUncErr", 0, 0, + CNTR_NORMAL, + access_tx_read_pio_memory_unc_err_cnt), +[C_TX_READ_SDMA_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryUncErr", 0, 0, + CNTR_NORMAL, + access_tx_read_sdma_memory_unc_err_cnt), +[C_TX_SB_HDR_UNC_ERR] = CNTR_ELEM("TxSbHdrUncErr", 0, 0, + CNTR_NORMAL, + access_tx_sb_hdr_unc_err_cnt), +[C_TX_CREDIT_RETURN_PARITY_ERR] = CNTR_ELEM("TxCreditReturnParityErr", 0, 0, + CNTR_NORMAL, + access_tx_credit_return_partiy_err_cnt), +[C_TX_LAUNCH_FIFO8_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo8UncOrParityErr", + 0, 0, CNTR_NORMAL, + access_tx_launch_fifo8_unc_or_parity_err_cnt), +[C_TX_LAUNCH_FIFO7_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo7UncOrParityErr", + 0, 0, CNTR_NORMAL, + access_tx_launch_fifo7_unc_or_parity_err_cnt), +[C_TX_LAUNCH_FIFO6_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo6UncOrParityErr", + 0, 0, CNTR_NORMAL, + access_tx_launch_fifo6_unc_or_parity_err_cnt), +[C_TX_LAUNCH_FIFO5_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo5UncOrParityErr", + 0, 0, CNTR_NORMAL, + access_tx_launch_fifo5_unc_or_parity_err_cnt), +[C_TX_LAUNCH_FIFO4_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo4UncOrParityErr", + 0, 0, CNTR_NORMAL, + access_tx_launch_fifo4_unc_or_parity_err_cnt), +[C_TX_LAUNCH_FIFO3_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo3UncOrParityErr", + 0, 0, CNTR_NORMAL, + access_tx_launch_fifo3_unc_or_parity_err_cnt), +[C_TX_LAUNCH_FIFO2_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo2UncOrParityErr", + 0, 0, CNTR_NORMAL, + access_tx_launch_fifo2_unc_or_parity_err_cnt), +[C_TX_LAUNCH_FIFO1_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo1UncOrParityErr", + 0, 0, CNTR_NORMAL, + access_tx_launch_fifo1_unc_or_parity_err_cnt), +[C_TX_LAUNCH_FIFO0_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo0UncOrParityErr", + 0, 0, CNTR_NORMAL, + access_tx_launch_fifo0_unc_or_parity_err_cnt), +[C_TX_SDMA15_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma15DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma15_disallowed_packet_err_cnt), +[C_TX_SDMA14_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma14DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma14_disallowed_packet_err_cnt), +[C_TX_SDMA13_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma13DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma13_disallowed_packet_err_cnt), +[C_TX_SDMA12_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma12DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma12_disallowed_packet_err_cnt), +[C_TX_SDMA11_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma11DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma11_disallowed_packet_err_cnt), +[C_TX_SDMA10_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma10DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma10_disallowed_packet_err_cnt), +[C_TX_SDMA9_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma9DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma9_disallowed_packet_err_cnt), +[C_TX_SDMA8_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma8DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma8_disallowed_packet_err_cnt), +[C_TX_SDMA7_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma7DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma7_disallowed_packet_err_cnt), +[C_TX_SDMA6_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma6DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma6_disallowed_packet_err_cnt), +[C_TX_SDMA5_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma5DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma5_disallowed_packet_err_cnt), +[C_TX_SDMA4_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma4DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma4_disallowed_packet_err_cnt), +[C_TX_SDMA3_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma3DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma3_disallowed_packet_err_cnt), +[C_TX_SDMA2_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma2DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma2_disallowed_packet_err_cnt), +[C_TX_SDMA1_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma1DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma1_disallowed_packet_err_cnt), +[C_TX_SDMA0_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma0DisallowedPacketErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma0_disallowed_packet_err_cnt), +[C_TX_CONFIG_PARITY_ERR] = CNTR_ELEM("TxConfigParityErr", 0, 0, + CNTR_NORMAL, + access_tx_config_parity_err_cnt), +[C_TX_SBRD_CTL_CSR_PARITY_ERR] = CNTR_ELEM("TxSbrdCtlCsrParityErr", 0, 0, + CNTR_NORMAL, + access_tx_sbrd_ctl_csr_parity_err_cnt), +[C_TX_LAUNCH_CSR_PARITY_ERR] = CNTR_ELEM("TxLaunchCsrParityErr", 0, 0, + CNTR_NORMAL, + access_tx_launch_csr_parity_err_cnt), +[C_TX_ILLEGAL_CL_ERR] = CNTR_ELEM("TxIllegalVLErr", 0, 0, + CNTR_NORMAL, + access_tx_illegal_vl_err_cnt), +[C_TX_SBRD_CTL_STATE_MACHINE_PARITY_ERR] = CNTR_ELEM( + "TxSbrdCtlStateMachineParityErr", 0, 0, + CNTR_NORMAL, + access_tx_sbrd_ctl_state_machine_parity_err_cnt), +[C_TX_RESERVED_10] = CNTR_ELEM("Tx Egress Reserved 10", 0, 0, + CNTR_NORMAL, + access_egress_reserved_10_err_cnt), +[C_TX_RESERVED_9] = CNTR_ELEM("Tx Egress Reserved 9", 0, 0, + CNTR_NORMAL, + access_egress_reserved_9_err_cnt), +[C_TX_SDMA_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxSdmaLaunchIntfParityErr", + 0, 0, CNTR_NORMAL, + access_tx_sdma_launch_intf_parity_err_cnt), +[C_TX_PIO_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxPioLaunchIntfParityErr", 0, 0, + CNTR_NORMAL, + access_tx_pio_launch_intf_parity_err_cnt), +[C_TX_RESERVED_6] = CNTR_ELEM("Tx Egress Reserved 6", 0, 0, + CNTR_NORMAL, + access_egress_reserved_6_err_cnt), +[C_TX_INCORRECT_LINK_STATE_ERR] = CNTR_ELEM("TxIncorrectLinkStateErr", 0, 0, + CNTR_NORMAL, + access_tx_incorrect_link_state_err_cnt), +[C_TX_LINK_DOWN_ERR] = CNTR_ELEM("TxLinkdownErr", 0, 0, + CNTR_NORMAL, + access_tx_linkdown_err_cnt), +[C_TX_EGRESS_FIFO_UNDERRUN_OR_PARITY_ERR] = CNTR_ELEM( + "EgressFifoUnderrunOrParityErr", 0, 0, + CNTR_NORMAL, + access_tx_egress_fifi_underrun_or_parity_err_cnt), +[C_TX_RESERVED_2] = CNTR_ELEM("Tx Egress Reserved 2", 0, 0, + CNTR_NORMAL, + access_egress_reserved_2_err_cnt), +[C_TX_PKT_INTEGRITY_MEM_UNC_ERR] = CNTR_ELEM("TxPktIntegrityMemUncErr", 0, 0, + CNTR_NORMAL, + access_tx_pkt_integrity_mem_unc_err_cnt), +[C_TX_PKT_INTEGRITY_MEM_COR_ERR] = CNTR_ELEM("TxPktIntegrityMemCorErr", 0, 0, + CNTR_NORMAL, + access_tx_pkt_integrity_mem_cor_err_cnt), +/* SendErrStatus */ +[C_SEND_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("SendCsrWriteBadAddrErr", 0, 0, + CNTR_NORMAL, + access_send_csr_write_bad_addr_err_cnt), +[C_SEND_CSR_READ_BAD_ADD_ERR] = CNTR_ELEM("SendCsrReadBadAddrErr", 0, 0, + CNTR_NORMAL, + access_send_csr_read_bad_addr_err_cnt), +[C_SEND_CSR_PARITY_ERR] = CNTR_ELEM("SendCsrParityErr", 0, 0, + CNTR_NORMAL, + access_send_csr_parity_cnt), +/* SendCtxtErrStatus */ +[C_PIO_WRITE_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("PioWriteOutOfBoundsErr", 0, 0, + CNTR_NORMAL, + access_pio_write_out_of_bounds_err_cnt), +[C_PIO_WRITE_OVERFLOW_ERR] = CNTR_ELEM("PioWriteOverflowErr", 0, 0, + CNTR_NORMAL, + access_pio_write_overflow_err_cnt), +[C_PIO_WRITE_CROSSES_BOUNDARY_ERR] = CNTR_ELEM("PioWriteCrossesBoundaryErr", + 0, 0, CNTR_NORMAL, + access_pio_write_crosses_boundary_err_cnt), +[C_PIO_DISALLOWED_PACKET_ERR] = CNTR_ELEM("PioDisallowedPacketErr", 0, 0, + CNTR_NORMAL, + access_pio_disallowed_packet_err_cnt), +[C_PIO_INCONSISTENT_SOP_ERR] = CNTR_ELEM("PioInconsistentSopErr", 0, 0, + CNTR_NORMAL, + access_pio_inconsistent_sop_err_cnt), +/* SendDmaEngErrStatus */ +[C_SDMA_HEADER_REQUEST_FIFO_COR_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoCorErr", + 0, 0, CNTR_NORMAL, + access_sdma_header_request_fifo_cor_err_cnt), +[C_SDMA_HEADER_STORAGE_COR_ERR] = CNTR_ELEM("SDmaHeaderStorageCorErr", 0, 0, + CNTR_NORMAL, + access_sdma_header_storage_cor_err_cnt), +[C_SDMA_PACKET_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPacketTrackingCorErr", 0, 0, + CNTR_NORMAL, + access_sdma_packet_tracking_cor_err_cnt), +[C_SDMA_ASSEMBLY_COR_ERR] = CNTR_ELEM("SDmaAssemblyCorErr", 0, 0, + CNTR_NORMAL, + access_sdma_assembly_cor_err_cnt), +[C_SDMA_DESC_TABLE_COR_ERR] = CNTR_ELEM("SDmaDescTableCorErr", 0, 0, + CNTR_NORMAL, + access_sdma_desc_table_cor_err_cnt), +[C_SDMA_HEADER_REQUEST_FIFO_UNC_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoUncErr", + 0, 0, CNTR_NORMAL, + access_sdma_header_request_fifo_unc_err_cnt), +[C_SDMA_HEADER_STORAGE_UNC_ERR] = CNTR_ELEM("SDmaHeaderStorageUncErr", 0, 0, + CNTR_NORMAL, + access_sdma_header_storage_unc_err_cnt), +[C_SDMA_PACKET_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPacketTrackingUncErr", 0, 0, + CNTR_NORMAL, + access_sdma_packet_tracking_unc_err_cnt), +[C_SDMA_ASSEMBLY_UNC_ERR] = CNTR_ELEM("SDmaAssemblyUncErr", 0, 0, + CNTR_NORMAL, + access_sdma_assembly_unc_err_cnt), +[C_SDMA_DESC_TABLE_UNC_ERR] = CNTR_ELEM("SDmaDescTableUncErr", 0, 0, + CNTR_NORMAL, + access_sdma_desc_table_unc_err_cnt), +[C_SDMA_TIMEOUT_ERR] = CNTR_ELEM("SDmaTimeoutErr", 0, 0, + CNTR_NORMAL, + access_sdma_timeout_err_cnt), +[C_SDMA_HEADER_LENGTH_ERR] = CNTR_ELEM("SDmaHeaderLengthErr", 0, 0, + CNTR_NORMAL, + access_sdma_header_length_err_cnt), +[C_SDMA_HEADER_ADDRESS_ERR] = CNTR_ELEM("SDmaHeaderAddressErr", 0, 0, + CNTR_NORMAL, + access_sdma_header_address_err_cnt), +[C_SDMA_HEADER_SELECT_ERR] = CNTR_ELEM("SDmaHeaderSelectErr", 0, 0, + CNTR_NORMAL, + access_sdma_header_select_err_cnt), +[C_SMDA_RESERVED_9] = CNTR_ELEM("SDma Reserved 9", 0, 0, + CNTR_NORMAL, + access_sdma_reserved_9_err_cnt), +[C_SDMA_PACKET_DESC_OVERFLOW_ERR] = CNTR_ELEM("SDmaPacketDescOverflowErr", 0, 0, + CNTR_NORMAL, + access_sdma_packet_desc_overflow_err_cnt), +[C_SDMA_LENGTH_MISMATCH_ERR] = CNTR_ELEM("SDmaLengthMismatchErr", 0, 0, + CNTR_NORMAL, + access_sdma_length_mismatch_err_cnt), +[C_SDMA_HALT_ERR] = CNTR_ELEM("SDmaHaltErr", 0, 0, + CNTR_NORMAL, + access_sdma_halt_err_cnt), +[C_SDMA_MEM_READ_ERR] = CNTR_ELEM("SDmaMemReadErr", 0, 0, + CNTR_NORMAL, + access_sdma_mem_read_err_cnt), +[C_SDMA_FIRST_DESC_ERR] = CNTR_ELEM("SDmaFirstDescErr", 0, 0, + CNTR_NORMAL, + access_sdma_first_desc_err_cnt), +[C_SDMA_TAIL_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("SDmaTailOutOfBoundsErr", 0, 0, + CNTR_NORMAL, + access_sdma_tail_out_of_bounds_err_cnt), +[C_SDMA_TOO_LONG_ERR] = CNTR_ELEM("SDmaTooLongErr", 0, 0, + CNTR_NORMAL, + access_sdma_too_long_err_cnt), +[C_SDMA_GEN_MISMATCH_ERR] = CNTR_ELEM("SDmaGenMismatchErr", 0, 0, + CNTR_NORMAL, + access_sdma_gen_mismatch_err_cnt), +[C_SDMA_WRONG_DW_ERR] = CNTR_ELEM("SDmaWrongDwErr", 0, 0, + CNTR_NORMAL, + access_sdma_wrong_dw_err_cnt), }; static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = { @@ -1762,6 +4890,8 @@ static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = { access_sw_link_dn_cnt), [C_SW_LINK_UP] = CNTR_ELEM("SwLinkUp", 0, 0, CNTR_SYNTH | CNTR_32BIT, access_sw_link_up_cnt), +[C_SW_UNKNOWN_FRAME] = CNTR_ELEM("UnknownFrame", 0, 0, CNTR_NORMAL, + access_sw_unknown_frame_cnt), [C_SW_XMIT_DSCD] = CNTR_ELEM("XmitDscd", 0, 0, CNTR_SYNTH | CNTR_32BIT, access_sw_xmit_discards), [C_SW_XMIT_DSCD_VL] = CNTR_ELEM("XmitDscdVl", 0, 0, @@ -1873,13 +5003,6 @@ static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = { /* ======================================================================== */ -/* return true if this is chip revision revision a0 */ -int is_a0(struct hfi1_devdata *dd) -{ - return ((dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT) - & CCE_REVISION_CHIP_REV_MINOR_MASK) == 0; -} - /* return true if this is chip revision revision a */ int is_ax(struct hfi1_devdata *dd) { @@ -1895,7 +5018,7 @@ int is_bx(struct hfi1_devdata *dd) u8 chip_rev_minor = dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT & CCE_REVISION_CHIP_REV_MINOR_MASK; - return !!(chip_rev_minor & 0x10); + return (chip_rev_minor & 0xF0) == 0x10; } /* @@ -2182,6 +5305,7 @@ static char *send_err_status_string(char *buf, int buf_len, u64 flags) static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg) { char buf[96]; + int i = 0; /* * For most these errors, there is nothing that can be done except @@ -2190,13 +5314,20 @@ static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg) dd_dev_info(dd, "CCE Error: %s\n", cce_err_status_string(buf, sizeof(buf), reg)); - if ((reg & CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK) - && is_a0(dd) - && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) { + if ((reg & CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK) && + is_ax(dd) && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) { /* this error requires a manual drop into SPC freeze mode */ /* then a fix up */ start_freeze_handling(dd->pport, FREEZE_SELF); } + + for (i = 0; i < NUM_CCE_ERR_STATUS_COUNTERS; i++) { + if (reg & (1ull << i)) { + incr_cntr64(&dd->cce_err_status_cnt[i]); + /* maintain a counter over all cce_err_status errors */ + incr_cntr64(&dd->sw_cce_err_status_aggregate); + } + } } /* @@ -2241,6 +5372,7 @@ static void free_rcverr(struct hfi1_devdata *dd) static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg) { char buf[96]; + int i = 0; dd_dev_info(dd, "Receive Error: %s\n", rxe_err_status_string(buf, sizeof(buf), reg)); @@ -2252,41 +5384,63 @@ static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg) * Freeze mode recovery is disabled for the errors * in RXE_FREEZE_ABORT_MASK */ - if (is_a0(dd) && (reg & RXE_FREEZE_ABORT_MASK)) + if (is_ax(dd) && (reg & RXE_FREEZE_ABORT_MASK)) flags = FREEZE_ABORT; start_freeze_handling(dd->pport, flags); } + + for (i = 0; i < NUM_RCV_ERR_STATUS_COUNTERS; i++) { + if (reg & (1ull << i)) + incr_cntr64(&dd->rcv_err_status_cnt[i]); + } } static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg) { char buf[96]; + int i = 0; dd_dev_info(dd, "Misc Error: %s", misc_err_status_string(buf, sizeof(buf), reg)); + for (i = 0; i < NUM_MISC_ERR_STATUS_COUNTERS; i++) { + if (reg & (1ull << i)) + incr_cntr64(&dd->misc_err_status_cnt[i]); + } } static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg) { char buf[96]; + int i = 0; dd_dev_info(dd, "PIO Error: %s\n", pio_err_status_string(buf, sizeof(buf), reg)); if (reg & ALL_PIO_FREEZE_ERR) start_freeze_handling(dd->pport, 0); + + for (i = 0; i < NUM_SEND_PIO_ERR_STATUS_COUNTERS; i++) { + if (reg & (1ull << i)) + incr_cntr64(&dd->send_pio_err_status_cnt[i]); + } } static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg) { char buf[96]; + int i = 0; dd_dev_info(dd, "SDMA Error: %s\n", sdma_err_status_string(buf, sizeof(buf), reg)); if (reg & ALL_SDMA_FREEZE_ERR) start_freeze_handling(dd->pport, 0); + + for (i = 0; i < NUM_SEND_DMA_ERR_STATUS_COUNTERS; i++) { + if (reg & (1ull << i)) + incr_cntr64(&dd->send_dma_err_status_cnt[i]); + } } static void count_port_inactive(struct hfi1_devdata *dd) @@ -2352,10 +5506,11 @@ static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg) { u64 reg_copy = reg, handled = 0; char buf[96]; + int i = 0; if (reg & ALL_TXE_EGRESS_FREEZE_ERR) start_freeze_handling(dd->pport, 0); - if (is_a0(dd) && (reg & + if (is_ax(dd) && (reg & SEND_EGRESS_ERR_STATUS_TX_CREDIT_RETURN_VL_ERR_SMASK) && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) start_freeze_handling(dd->pport, 0); @@ -2383,15 +5538,25 @@ static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg) if (reg) dd_dev_info(dd, "Egress Error: %s\n", egress_err_status_string(buf, sizeof(buf), reg)); + + for (i = 0; i < NUM_SEND_EGRESS_ERR_STATUS_COUNTERS; i++) { + if (reg & (1ull << i)) + incr_cntr64(&dd->send_egress_err_status_cnt[i]); + } } static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg) { char buf[96]; + int i = 0; dd_dev_info(dd, "Send Error: %s\n", send_err_status_string(buf, sizeof(buf), reg)); + for (i = 0; i < NUM_SEND_ERR_STATUS_COUNTERS; i++) { + if (reg & (1ull << i)) + incr_cntr64(&dd->send_err_status_cnt[i]); + } } /* @@ -2483,6 +5648,7 @@ static void is_sendctxt_err_int(struct hfi1_devdata *dd, char flags[96]; u64 status; u32 sw_index; + int i = 0; sw_index = dd->hw_to_sw[hw_context]; if (sw_index >= dd->num_send_contexts) { @@ -2516,12 +5682,23 @@ static void is_sendctxt_err_int(struct hfi1_devdata *dd, */ if (sc->type != SC_USER) queue_work(dd->pport->hfi1_wq, &sc->halt_work); + + /* + * Update the counters for the corresponding status bits. + * Note that these particular counters are aggregated over all + * 160 contexts. + */ + for (i = 0; i < NUM_SEND_CTXT_ERR_STATUS_COUNTERS; i++) { + if (status & (1ull << i)) + incr_cntr64(&dd->sw_ctxt_err_status_cnt[i]); + } } static void handle_sdma_eng_err(struct hfi1_devdata *dd, unsigned int source, u64 status) { struct sdma_engine *sde; + int i = 0; sde = &dd->per_sdma[source]; #ifdef CONFIG_SDMA_VERBOSITY @@ -2531,6 +5708,16 @@ static void handle_sdma_eng_err(struct hfi1_devdata *dd, sde->this_idx, source, (unsigned long long)status); #endif sdma_engine_error(sde, status); + + /* + * Update the counters for the corresponding status bits. + * Note that these particular counters are aggregated over + * all 16 DMA engines. + */ + for (i = 0; i < NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS; i++) { + if (status & (1ull << i)) + incr_cntr64(&dd->sw_send_dma_eng_err_status_cnt[i]); + } } /* @@ -3050,7 +6237,7 @@ static void adjust_lcb_for_fpga_serdes(struct hfi1_devdata *dd) /* else this is _p */ version = emulator_rev(dd); - if (!is_a0(dd)) + if (!is_ax(dd)) version = 0x2d; /* all B0 use 0x2d or higher settings */ if (version <= 0x12) { @@ -3313,7 +6500,6 @@ void handle_freeze(struct work_struct *work) struct hfi1_devdata *dd = ppd->dd; /* wait for freeze indicators on all affected blocks */ - dd_dev_info(dd, "Entering SPC freeze\n"); wait_for_freeze_status(dd, 1); /* SPC is now frozen */ @@ -3336,7 +6522,7 @@ void handle_freeze(struct work_struct *work) write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK); wait_for_freeze_status(dd, 0); - if (is_a0(dd)) { + if (is_ax(dd)) { write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK); wait_for_freeze_status(dd, 1); write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK); @@ -3371,7 +6557,6 @@ void handle_freeze(struct work_struct *work) wake_up(&dd->event_queue); /* no longer frozen */ - dd_dev_err(dd, "Exiting SPC freeze\n"); } /* @@ -3542,10 +6727,10 @@ static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd) { struct hfi1_devdata *dd = ppd->dd; - /* Sanity check - ppd->pkeys[2] should be 0 */ - if (ppd->pkeys[2] != 0) - dd_dev_err(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n", - __func__, ppd->pkeys[2], FULL_MGMT_P_KEY); + /* Sanity check - ppd->pkeys[2] should be 0, or already initalized */ + if (!((ppd->pkeys[2] == 0) || (ppd->pkeys[2] == FULL_MGMT_P_KEY))) + dd_dev_warn(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n", + __func__, ppd->pkeys[2], FULL_MGMT_P_KEY); ppd->pkeys[2] = FULL_MGMT_P_KEY; (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0); } @@ -3864,7 +7049,7 @@ void handle_verify_cap(struct work_struct *work) * REPLAY_BUF_MBE_SMASK * FLIT_INPUT_BUF_MBE_SMASK */ - if (is_a0(dd)) { /* fixed in B0 */ + if (is_ax(dd)) { /* fixed in B0 */ reg = read_csr(dd, DC_LCB_CFG_LINK_KILL_EN); reg |= DC_LCB_CFG_LINK_KILL_EN_REPLAY_BUF_MBE_SMASK | DC_LCB_CFG_LINK_KILL_EN_FLIT_INPUT_BUF_MBE_SMASK; @@ -3907,18 +7092,32 @@ void handle_verify_cap(struct work_struct *work) */ void apply_link_downgrade_policy(struct hfi1_pportdata *ppd, int refresh_widths) { - int skip = 1; int do_bounce = 0; - u16 lwde = ppd->link_width_downgrade_enabled; + int tries; + u16 lwde; u16 tx, rx; + /* use the hls lock to avoid a race with actual link up */ + tries = 0; +retry: mutex_lock(&ppd->hls_lock); /* only apply if the link is up */ - if (ppd->host_link_state & HLS_UP) - skip = 0; - mutex_unlock(&ppd->hls_lock); - if (skip) - return; + if (!(ppd->host_link_state & HLS_UP)) { + /* still going up..wait and retry */ + if (ppd->host_link_state & HLS_GOING_UP) { + if (++tries < 1000) { + mutex_unlock(&ppd->hls_lock); + usleep_range(100, 120); /* arbitrary */ + goto retry; + } + dd_dev_err(ppd->dd, + "%s: giving up waiting for link state change\n", + __func__); + } + goto done; + } + + lwde = ppd->link_width_downgrade_enabled; if (refresh_widths) { get_link_widths(ppd->dd, &tx, &rx); @@ -3956,6 +7155,9 @@ void apply_link_downgrade_policy(struct hfi1_pportdata *ppd, int refresh_widths) do_bounce = 1; } +done: + mutex_unlock(&ppd->hls_lock); + if (do_bounce) { set_link_down_reason(ppd, OPA_LINKDOWN_REASON_WIDTH_POLICY, 0, OPA_LINKDOWN_REASON_WIDTH_POLICY); @@ -4046,6 +7248,11 @@ static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg) } err &= ~(u64)FAILED_LNI; } + /* unknown frames can happen durning LNI, just count */ + if (err & UNKNOWN_FRAME) { + ppd->unknown_frame_count++; + err &= ~(u64)UNKNOWN_FRAME; + } if (err) { /* report remaining errors, but do not do anything */ dd_dev_err(dd, "8051 info error: %s\n", @@ -4774,13 +7981,25 @@ int read_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 *data) */ static int write_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 data) { + u32 regno; + int ret; - if (acquire_lcb_access(dd, 0) == 0) { - write_csr(dd, addr, data); - release_lcb_access(dd, 0); - return 0; + if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR || + (dd->dc8051_ver < dc8051_ver(0, 20))) { + if (acquire_lcb_access(dd, 0) == 0) { + write_csr(dd, addr, data); + release_lcb_access(dd, 0); + return 0; + } + return -EBUSY; } - return -EBUSY; + + /* register is an index of LCB registers: (offset - base) / 8 */ + regno = (addr - DC_LCB_CFG_RUN) >> 3; + ret = do_8051_command(dd, HCMD_WRITE_LCB_CSR, regno, &data); + if (ret != HCMD_SUCCESS) + return -EBUSY; + return 0; } /* @@ -4862,6 +8081,26 @@ static int do_8051_command( */ /* + * When writing a LCB CSR, out_data contains the full value to + * to be written, while in_data contains the relative LCB + * address in 7:0. Do the work here, rather than the caller, + * of distrubting the write data to where it needs to go: + * + * Write data + * 39:00 -> in_data[47:8] + * 47:40 -> DC8051_CFG_EXT_DEV_0.RETURN_CODE + * 63:48 -> DC8051_CFG_EXT_DEV_0.RSP_DATA + */ + if (type == HCMD_WRITE_LCB_CSR) { + in_data |= ((*out_data) & 0xffffffffffull) << 8; + reg = ((((*out_data) >> 40) & 0xff) << + DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT) + | ((((*out_data) >> 48) & 0xffff) << + DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT); + write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, reg); + } + + /* * Do two writes: the first to stabilize the type and req_data, the * second to activate. */ @@ -5856,6 +9095,23 @@ void init_qsfp(struct hfi1_pportdata *ppd) } } +/* + * Do a one-time initialize of the LCB block. + */ +static void init_lcb(struct hfi1_devdata *dd) +{ + /* the DC has been reset earlier in the driver load */ + + /* set LCB for cclk loopback on the port */ + write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x01); + write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0x00); + write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0x00); + write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110); + write_csr(dd, DC_LCB_CFG_CLK_CNTR, 0x08); + write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x02); + write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x00); +} + int bringup_serdes(struct hfi1_pportdata *ppd) { struct hfi1_devdata *dd = ppd->dd; @@ -5877,6 +9133,9 @@ int bringup_serdes(struct hfi1_pportdata *ppd) /* Set linkinit_reason on power up per OPA spec */ ppd->linkinit_reason = OPA_LINKINIT_REASON_LINKUP; + /* one-time init of the LCB */ + init_lcb(dd); + if (loopback) { ret = init_loopback(dd); if (ret < 0) @@ -6148,7 +9407,8 @@ u32 lrh_max_header_bytes(struct hfi1_devdata *dd) static void set_send_length(struct hfi1_pportdata *ppd) { struct hfi1_devdata *dd = ppd->dd; - u32 max_hb = lrh_max_header_bytes(dd), maxvlmtu = 0, dcmtu; + u32 max_hb = lrh_max_header_bytes(dd), dcmtu; + u32 maxvlmtu = dd->vld[15].mtu; u64 len1 = 0, len2 = (((dd->vld[15].mtu + max_hb) >> 2) & SEND_LEN_CHECK1_LEN_VL15_MASK) << SEND_LEN_CHECK1_LEN_VL15_SHIFT; @@ -6319,9 +9579,10 @@ static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason) * depending on how the link went down. The 8051 firmware * will observe the needed wait time and only move to ready * when that is completed. The largest of the quiet timeouts - * is 2.5s, so wait that long and then a bit more. + * is 6s, so wait that long and then at least 0.5s more for + * other transitions, and another 0.5s for a buffer. */ - ret = wait_fm_ready(dd, 3000); + ret = wait_fm_ready(dd, 7000); if (ret) { dd_dev_err(dd, "After going offline, timed out waiting for the 8051 to become ready to accept host requests\n"); @@ -7235,8 +10496,7 @@ static int set_buffer_control(struct hfi1_devdata *dd, new_bc->vl[i].shared = 0; } new_total += be16_to_cpu(new_bc->overall_shared_limit); - if (new_total > (u32)dd->link_credits) - return -EINVAL; + /* fetch the current values */ get_buffer_control(dd, &cur_bc, &cur_total); @@ -7282,8 +10542,8 @@ static int set_buffer_control(struct hfi1_devdata *dd, */ use_all_mask = 0; if ((be16_to_cpu(new_bc->overall_shared_limit) < - be16_to_cpu(cur_bc.overall_shared_limit)) - || (is_a0(dd) && any_shared_limit_changing)) { + be16_to_cpu(cur_bc.overall_shared_limit)) || + (is_ax(dd) && any_shared_limit_changing)) { set_global_shared(dd, 0); cur_bc.overall_shared_limit = 0; use_all_mask = 1; @@ -7457,7 +10717,7 @@ int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t) */ static int disable_data_vls(struct hfi1_devdata *dd) { - if (is_a0(dd)) + if (is_ax(dd)) return 1; pio_send_control(dd, PSC_DATA_VL_DISABLE); @@ -7475,7 +10735,7 @@ static int disable_data_vls(struct hfi1_devdata *dd) */ int open_fill_data_vls(struct hfi1_devdata *dd) { - if (is_a0(dd)) + if (is_ax(dd)) return 1; pio_send_control(dd, PSC_DATA_VL_ENABLE); @@ -7748,11 +11008,22 @@ void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt) & RCV_TID_CTRL_TID_BASE_INDEX_MASK) << RCV_TID_CTRL_TID_BASE_INDEX_SHIFT); write_kctxt_csr(dd, ctxt, RCV_TID_CTRL, reg); - if (ctxt == VL15CTXT) - write_csr(dd, RCV_VL15, VL15CTXT); + if (ctxt == HFI1_CTRL_CTXT) + write_csr(dd, RCV_VL15, HFI1_CTRL_CTXT); } if (op & HFI1_RCVCTRL_CTXT_DIS) { write_csr(dd, RCV_VL15, 0); + /* + * When receive context is being disabled turn on tail + * update with a dummy tail address and then disable + * receive context. + */ + if (dd->rcvhdrtail_dummy_physaddr) { + write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR, + dd->rcvhdrtail_dummy_physaddr); + rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK; + } + rcvctrl &= ~RCV_CTXT_CTRL_ENABLE_SMASK; } if (op & HFI1_RCVCTRL_INTRAVAIL_ENB) @@ -7822,10 +11093,11 @@ void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt) if (op & (HFI1_RCVCTRL_TAILUPD_DIS | HFI1_RCVCTRL_CTXT_DIS)) /* * If the context has been disabled and the Tail Update has - * been cleared, clear the RCV_HDR_TAIL_ADDR CSR so - * it doesn't contain an address that is invalid. + * been cleared, set the RCV_HDR_TAIL_ADDR CSR to dummy address + * so it doesn't contain an address that is invalid. */ - write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR, 0); + write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR, + dd->rcvhdrtail_dummy_physaddr); } u32 hfi1_read_cntrs(struct hfi1_devdata *dd, loff_t pos, char **namep, @@ -8785,7 +12057,7 @@ static void clean_up_interrupts(struct hfi1_devdata *dd) /* turn off interrupts */ if (dd->num_msix_entries) { /* MSI-X */ - hfi1_nomsix(dd); + pci_disable_msix(dd->pcidev); } else { /* INTx */ disable_intx(dd->pcidev); @@ -8840,18 +12112,12 @@ static void remap_sdma_interrupts(struct hfi1_devdata *dd, msix_intr); } -static void remap_receive_available_interrupt(struct hfi1_devdata *dd, - int rx, int msix_intr) -{ - remap_intr(dd, IS_RCVAVAIL_START + rx, msix_intr); -} - static int request_intx_irq(struct hfi1_devdata *dd) { int ret; - snprintf(dd->intx_name, sizeof(dd->intx_name), DRIVER_NAME"_%d", - dd->unit); + snprintf(dd->intx_name, sizeof(dd->intx_name), DRIVER_NAME "_%d", + dd->unit); ret = request_irq(dd->pcidev->irq, general_interrupt, IRQF_SHARED, dd->intx_name, dd); if (ret) @@ -8870,7 +12136,7 @@ static int request_msix_irqs(struct hfi1_devdata *dd) int first_general, last_general; int first_sdma, last_sdma; int first_rx, last_rx; - int first_cpu, restart_cpu, curr_cpu; + int first_cpu, curr_cpu; int rcv_cpu, sdma_cpu; int i, ret = 0, possible; int ht; @@ -8909,22 +12175,19 @@ static int request_msix_irqs(struct hfi1_devdata *dd) topology_sibling_cpumask(cpumask_first(local_mask))); for (i = possible/ht; i < possible; i++) cpumask_clear_cpu(i, def); - /* reset possible */ - possible = cpumask_weight(def); /* def now has full cores on chosen node*/ first_cpu = cpumask_first(def); if (nr_cpu_ids >= first_cpu) first_cpu++; - restart_cpu = first_cpu; - curr_cpu = restart_cpu; + curr_cpu = first_cpu; - for (i = first_cpu; i < dd->n_krcv_queues + first_cpu; i++) { + /* One context is reserved as control context */ + for (i = first_cpu; i < dd->n_krcv_queues + first_cpu - 1; i++) { cpumask_clear_cpu(curr_cpu, def); cpumask_set_cpu(curr_cpu, rcv); - if (curr_cpu >= possible) - curr_cpu = restart_cpu; - else - curr_cpu++; + curr_cpu = cpumask_next(curr_cpu, def); + if (curr_cpu >= nr_cpu_ids) + break; } /* def mask has non-rcv, rcv has recv mask */ rcv_cpu = cpumask_first(rcv); @@ -8953,7 +12216,7 @@ static int request_msix_irqs(struct hfi1_devdata *dd) handler = general_interrupt; arg = dd; snprintf(me->name, sizeof(me->name), - DRIVER_NAME"_%d", dd->unit); + DRIVER_NAME "_%d", dd->unit); err_info = "general"; } else if (first_sdma <= i && i < last_sdma) { idx = i - first_sdma; @@ -8961,7 +12224,7 @@ static int request_msix_irqs(struct hfi1_devdata *dd) handler = sdma_interrupt; arg = sde; snprintf(me->name, sizeof(me->name), - DRIVER_NAME"_%d sdma%d", dd->unit, idx); + DRIVER_NAME "_%d sdma%d", dd->unit, idx); err_info = "sdma"; remap_sdma_interrupts(dd, idx, i); } else if (first_rx <= i && i < last_rx) { @@ -8981,9 +12244,9 @@ static int request_msix_irqs(struct hfi1_devdata *dd) thread = receive_context_thread; arg = rcd; snprintf(me->name, sizeof(me->name), - DRIVER_NAME"_%d kctxt%d", dd->unit, idx); + DRIVER_NAME "_%d kctxt%d", dd->unit, idx); err_info = "receive context"; - remap_receive_available_interrupt(dd, idx, i); + remap_intr(dd, IS_RCVAVAIL_START + idx, i); } else { /* not in our expected range - complain, then ignore it */ @@ -9018,17 +12281,26 @@ static int request_msix_irqs(struct hfi1_devdata *dd) if (handler == sdma_interrupt) { dd_dev_info(dd, "sdma engine %d cpu %d\n", sde->this_idx, sdma_cpu); + sde->cpu = sdma_cpu; cpumask_set_cpu(sdma_cpu, dd->msix_entries[i].mask); sdma_cpu = cpumask_next(sdma_cpu, def); if (sdma_cpu >= nr_cpu_ids) sdma_cpu = cpumask_first(def); } else if (handler == receive_context_interrupt) { - dd_dev_info(dd, "rcv ctxt %d cpu %d\n", - rcd->ctxt, rcv_cpu); - cpumask_set_cpu(rcv_cpu, dd->msix_entries[i].mask); - rcv_cpu = cpumask_next(rcv_cpu, rcv); - if (rcv_cpu >= nr_cpu_ids) - rcv_cpu = cpumask_first(rcv); + dd_dev_info(dd, "rcv ctxt %d cpu %d\n", rcd->ctxt, + (rcd->ctxt == HFI1_CTRL_CTXT) ? + cpumask_first(def) : rcv_cpu); + if (rcd->ctxt == HFI1_CTRL_CTXT) { + /* map to first default */ + cpumask_set_cpu(cpumask_first(def), + dd->msix_entries[i].mask); + } else { + cpumask_set_cpu(rcv_cpu, + dd->msix_entries[i].mask); + rcv_cpu = cpumask_next(rcv_cpu, rcv); + if (rcv_cpu >= nr_cpu_ids) + rcv_cpu = cpumask_first(rcv); + } } else { /* otherwise first def */ dd_dev_info(dd, "%s cpu %d\n", @@ -9153,7 +12425,6 @@ fail: static int set_up_context_variables(struct hfi1_devdata *dd) { int num_kernel_contexts; - int num_user_contexts; int total_contexts; int ret; unsigned ngroups; @@ -9161,11 +12432,18 @@ static int set_up_context_variables(struct hfi1_devdata *dd) /* * Kernel contexts: (to be fixed later): * - min or 2 or 1 context/numa - * - Context 0 - default/errors - * - Context 1 - VL15 + * - Context 0 - control context (VL15/multicast/error) + * - Context 1 - default context */ if (n_krcvqs) - num_kernel_contexts = n_krcvqs + MIN_KERNEL_KCTXTS; + /* + * Don't count context 0 in n_krcvqs since + * is isn't used for normal verbs traffic. + * + * krcvqs will reflect number of kernel + * receive contexts above 0. + */ + num_kernel_contexts = n_krcvqs + MIN_KERNEL_KCTXTS - 1; else num_kernel_contexts = num_online_nodes(); num_kernel_contexts = @@ -9183,12 +12461,10 @@ static int set_up_context_variables(struct hfi1_devdata *dd) } /* * User contexts: (to be fixed later) - * - set to num_rcv_contexts if non-zero - * - default to 1 user context per CPU + * - default to 1 user context per CPU if num_user_contexts is + * negative */ - if (num_rcv_contexts) - num_user_contexts = num_rcv_contexts; - else + if (num_user_contexts < 0) num_user_contexts = num_online_cpus(); total_contexts = num_kernel_contexts + num_user_contexts; @@ -9455,7 +12731,7 @@ static void reset_asic_csrs(struct hfi1_devdata *dd) /* We might want to retain this state across FLR if we ever use it */ write_csr(dd, ASIC_CFG_DRV_STR, 0); - write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0); + /* ASIC_CFG_THERM_POLL_EN leave alone */ /* ASIC_STS_THERM read-only */ /* ASIC_CFG_RESET leave alone */ @@ -9906,7 +13182,7 @@ static void init_chip(struct hfi1_devdata *dd) /* restore command and BARs */ restore_pci_variables(dd); - if (is_a0(dd)) { + if (is_ax(dd)) { dd_dev_info(dd, "Resetting CSRs with FLR\n"); hfi1_pcie_flr(dd); restore_pci_variables(dd); @@ -9925,23 +13201,20 @@ static void init_chip(struct hfi1_devdata *dd) write_csr(dd, CCE_DC_CTRL, 0); /* Set the LED off */ - if (is_a0(dd)) + if (is_ax(dd)) setextled(dd, 0); /* * Clear the QSFP reset. - * A0 leaves the out lines floating on power on, then on an FLR - * enforces a 0 on all out pins. The driver does not touch + * An FLR enforces a 0 on all out pins. The driver does not touch * ASIC_QSFPn_OUT otherwise. This leaves RESET_N low and - * anything plugged constantly in reset, if it pays attention + * anything plugged constantly in reset, if it pays attention * to RESET_N. - * A prime example of this is SiPh. For now, set all pins high. + * Prime examples of this are optical cables. Set all pins high. * I2CCLK and I2CDAT will change per direction, and INT_N and * MODPRS_N are input only and their value is ignored. */ - if (is_a0(dd)) { - write_csr(dd, ASIC_QSFP1_OUT, 0x1f); - write_csr(dd, ASIC_QSFP2_OUT, 0x1f); - } + write_csr(dd, ASIC_QSFP1_OUT, 0x1f); + write_csr(dd, ASIC_QSFP2_OUT, 0x1f); } static void init_early_variables(struct hfi1_devdata *dd) @@ -9951,7 +13224,7 @@ static void init_early_variables(struct hfi1_devdata *dd) /* assign link credit variables */ dd->vau = CM_VAU; dd->link_credits = CM_GLOBAL_CREDITS; - if (is_a0(dd)) + if (is_ax(dd)) dd->link_credits--; dd->vcu = cu_to_vcu(hfi1_cu); /* enough room for 8 MAD packets plus header - 17K */ @@ -10017,12 +13290,6 @@ static void init_qpmap_table(struct hfi1_devdata *dd, u64 ctxt = first_ctxt; for (i = 0; i < 256;) { - if (ctxt == VL15CTXT) { - ctxt++; - if (ctxt > last_ctxt) - ctxt = first_ctxt; - continue; - } reg |= ctxt << (8 * (i % 8)); i++; ctxt++; @@ -10065,7 +13332,7 @@ static void init_qos(struct hfi1_devdata *dd, u32 first_ctxt) unsigned qpns_per_vl, ctxt, i, qpn, n = 1, m; u64 *rsmmap; u64 reg; - u8 rxcontext = is_a0(dd) ? 0 : 0xff; /* 0 is default if a0 ver. */ + u8 rxcontext = is_ax(dd) ? 0 : 0xff; /* 0 is default if a0 ver. */ /* validate */ if (dd->n_krcv_queues <= MIN_KERNEL_KCTXTS || @@ -10087,6 +13354,8 @@ static void init_qos(struct hfi1_devdata *dd, u32 first_ctxt) if (num_vls * qpns_per_vl > dd->chip_rcv_contexts) goto bail; rsmmap = kmalloc_array(NUM_MAP_REGS, sizeof(u64), GFP_KERNEL); + if (!rsmmap) + goto bail; memset(rsmmap, rxcontext, NUM_MAP_REGS * sizeof(u64)); /* init the local copy of the table */ for (i = 0, ctxt = first_ctxt; i < num_vls; i++) { @@ -10135,19 +13404,13 @@ static void init_qos(struct hfi1_devdata *dd, u32 first_ctxt) /* Enable RSM */ add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK); kfree(rsmmap); - /* map everything else (non-VL15) to context 0 */ - init_qpmap_table( - dd, - 0, - 0); + /* map everything else to first context */ + init_qpmap_table(dd, FIRST_KERNEL_KCTXT, MIN_KERNEL_KCTXTS - 1); dd->qos_shift = n + 1; return; bail: dd->qos_shift = 1; - init_qpmap_table( - dd, - dd->n_krcv_queues > MIN_KERNEL_KCTXTS ? MIN_KERNEL_KCTXTS : 0, - dd->n_krcv_queues - 1); + init_qpmap_table(dd, FIRST_KERNEL_KCTXT, dd->n_krcv_queues - 1); } static void init_rxe(struct hfi1_devdata *dd) @@ -10276,7 +13539,7 @@ int hfi1_set_ctxt_jkey(struct hfi1_devdata *dd, unsigned ctxt, u16 jkey) * Enable send-side J_KEY integrity check, unless this is A0 h/w * (due to A0 erratum). */ - if (!is_a0(dd)) { + if (!is_ax(dd)) { reg = read_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE); reg |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK; write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE, reg); @@ -10309,7 +13572,7 @@ int hfi1_clear_ctxt_jkey(struct hfi1_devdata *dd, unsigned ctxt) * This check would not have been enabled for A0 h/w, see * set_ctxt_jkey(). */ - if (!is_a0(dd)) { + if (!is_ax(dd)) { reg = read_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE); reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK; write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE, reg); @@ -10418,6 +13681,32 @@ static void asic_should_init(struct hfi1_devdata *dd) spin_unlock_irqrestore(&hfi1_devs_lock, flags); } +/* + * Set dd->boardname. Use a generic name if a name is not returned from + * EFI variable space. + * + * Return 0 on success, -ENOMEM if space could not be allocated. + */ +static int obtain_boardname(struct hfi1_devdata *dd) +{ + /* generic board description */ + const char generic[] = + "Intel Omni-Path Host Fabric Interface Adapter 100 Series"; + unsigned long size; + int ret; + + ret = read_hfi1_efi_var(dd, "description", &size, + (void **)&dd->boardname); + if (ret) { + dd_dev_err(dd, "Board description not found\n"); + /* use generic description */ + dd->boardname = kstrdup(generic, GFP_KERNEL); + if (!dd->boardname) + return -ENOMEM; + } + return 0; +} + /** * Allocate and initialize the device structure for the hfi. * @dev: the pci_dev for hfi1_ib device @@ -10554,9 +13843,9 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev, /* insure num_vls isn't larger than number of sdma engines */ if (HFI1_CAP_IS_KSET(SDMA) && num_vls > dd->chip_sdma_engines) { dd_dev_err(dd, "num_vls %u too large, using %u VLs\n", - num_vls, HFI1_MAX_VLS_SUPPORTED); - ppd->vls_supported = num_vls = HFI1_MAX_VLS_SUPPORTED; - ppd->vls_operational = ppd->vls_supported; + num_vls, dd->chip_sdma_engines); + num_vls = dd->chip_sdma_engines; + ppd->vls_supported = dd->chip_sdma_engines; } /* @@ -10615,18 +13904,13 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev, parse_platform_config(dd); - /* add board names as they are defined */ - dd->boardname = kmalloc(64, GFP_KERNEL); - if (!dd->boardname) + ret = obtain_boardname(dd); + if (ret) goto bail_cleanup; - snprintf(dd->boardname, 64, "Board ID 0x%llx", - dd->revision >> CCE_REVISION_BOARD_ID_LOWER_NIBBLE_SHIFT - & CCE_REVISION_BOARD_ID_LOWER_NIBBLE_MASK); snprintf(dd->boardversion, BOARD_VERS_MAX, - "ChipABI %u.%u, %s, ChipRev %u.%u, SW Compat %llu\n", + "ChipABI %u.%u, ChipRev %u.%u, SW Compat %llu\n", HFI1_CHIP_VERS_MAJ, HFI1_CHIP_VERS_MIN, - dd->boardname, (u32)dd->majrev, (u32)dd->minrev, (dd->revision >> CCE_REVISION_SW_SHIFT) @@ -10803,7 +14087,9 @@ static int thermal_init(struct hfi1_devdata *dd) acquire_hw_mutex(dd); dd_dev_info(dd, "Initializing thermal sensor\n"); - + /* Disable polling of thermal readings */ + write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0); + msleep(100); /* Thermal Sensor Initialization */ /* Step 1: Reset the Thermal SBus Receiver */ ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0, diff --git a/drivers/staging/rdma/hfi1/chip.h b/drivers/staging/rdma/hfi1/chip.h index ebf9041a1c5e..5b375ddc345d 100644 --- a/drivers/staging/rdma/hfi1/chip.h +++ b/drivers/staging/rdma/hfi1/chip.h @@ -235,6 +235,7 @@ #define HCMD_MISC 0x05 #define HCMD_READ_LCB_IDLE_MSG 0x06 #define HCMD_READ_LCB_CSR 0x07 +#define HCMD_WRITE_LCB_CSR 0x08 #define HCMD_INTERFACE_TEST 0xff /* DC_DC8051_CFG_HOST_CMD_1.RETURN_CODE - 8051 host command return */ @@ -663,7 +664,6 @@ void get_linkup_link_widths(struct hfi1_pportdata *ppd); void read_ltp_rtt(struct hfi1_devdata *dd); void clear_linkup_counters(struct hfi1_devdata *dd); u32 hdrqempty(struct hfi1_ctxtdata *rcd); -int is_a0(struct hfi1_devdata *dd); int is_ax(struct hfi1_devdata *dd); int is_bx(struct hfi1_devdata *dd); u32 read_physical_state(struct hfi1_devdata *dd); @@ -721,7 +721,6 @@ enum { C_RX_TID_FULL, C_RX_TID_INVALID, C_RX_TID_FLGMS, - C_RX_CTX_RHQS, C_RX_CTX_EGRS, C_RCV_TID_FLSMS, C_CCE_PCI_CR_ST, @@ -788,6 +787,275 @@ enum { C_SW_PIO_WAIT, C_SW_KMEM_WAIT, C_SW_SEND_SCHED, +/* MISC_ERR_STATUS */ + C_MISC_PLL_LOCK_FAIL_ERR, + C_MISC_MBIST_FAIL_ERR, + C_MISC_INVALID_EEP_CMD_ERR, + C_MISC_EFUSE_DONE_PARITY_ERR, + C_MISC_EFUSE_WRITE_ERR, + C_MISC_EFUSE_READ_BAD_ADDR_ERR, + C_MISC_EFUSE_CSR_PARITY_ERR, + C_MISC_FW_AUTH_FAILED_ERR, + C_MISC_KEY_MISMATCH_ERR, + C_MISC_SBUS_WRITE_FAILED_ERR, + C_MISC_CSR_WRITE_BAD_ADDR_ERR, + C_MISC_CSR_READ_BAD_ADDR_ERR, + C_MISC_CSR_PARITY_ERR, +/* CceErrStatus */ + /* + * A special counter that is the aggregate count + * of all the cce_err_status errors. The remainder + * are actual bits in the CceErrStatus register. + */ + C_CCE_ERR_STATUS_AGGREGATED_CNT, + C_CCE_MSIX_CSR_PARITY_ERR, + C_CCE_INT_MAP_UNC_ERR, + C_CCE_INT_MAP_COR_ERR, + C_CCE_MSIX_TABLE_UNC_ERR, + C_CCE_MSIX_TABLE_COR_ERR, + C_CCE_RXDMA_CONV_FIFO_PARITY_ERR, + C_CCE_RCPL_ASYNC_FIFO_PARITY_ERR, + C_CCE_SEG_WRITE_BAD_ADDR_ERR, + C_CCE_SEG_READ_BAD_ADDR_ERR, + C_LA_TRIGGERED, + C_CCE_TRGT_CPL_TIMEOUT_ERR, + C_PCIC_RECEIVE_PARITY_ERR, + C_PCIC_TRANSMIT_BACK_PARITY_ERR, + C_PCIC_TRANSMIT_FRONT_PARITY_ERR, + C_PCIC_CPL_DAT_Q_UNC_ERR, + C_PCIC_CPL_HD_Q_UNC_ERR, + C_PCIC_POST_DAT_Q_UNC_ERR, + C_PCIC_POST_HD_Q_UNC_ERR, + C_PCIC_RETRY_SOT_MEM_UNC_ERR, + C_PCIC_RETRY_MEM_UNC_ERR, + C_PCIC_N_POST_DAT_Q_PARITY_ERR, + C_PCIC_N_POST_H_Q_PARITY_ERR, + C_PCIC_CPL_DAT_Q_COR_ERR, + C_PCIC_CPL_HD_Q_COR_ERR, + C_PCIC_POST_DAT_Q_COR_ERR, + C_PCIC_POST_HD_Q_COR_ERR, + C_PCIC_RETRY_SOT_MEM_COR_ERR, + C_PCIC_RETRY_MEM_COR_ERR, + C_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERR, + C_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERR, + C_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR, + C_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR, + C_CCE_CLI2_ASYNC_FIFO_PARITY_ERR, + C_CCE_CSR_CFG_BUS_PARITY_ERR, + C_CCE_CLI0_ASYNC_FIFO_PARTIY_ERR, + C_CCE_RSPD_DATA_PARITY_ERR, + C_CCE_TRGT_ACCESS_ERR, + C_CCE_TRGT_ASYNC_FIFO_PARITY_ERR, + C_CCE_CSR_WRITE_BAD_ADDR_ERR, + C_CCE_CSR_READ_BAD_ADDR_ERR, + C_CCE_CSR_PARITY_ERR, +/* RcvErrStatus */ + C_RX_CSR_PARITY_ERR, + C_RX_CSR_WRITE_BAD_ADDR_ERR, + C_RX_CSR_READ_BAD_ADDR_ERR, + C_RX_DMA_CSR_UNC_ERR, + C_RX_DMA_DQ_FSM_ENCODING_ERR, + C_RX_DMA_EQ_FSM_ENCODING_ERR, + C_RX_DMA_CSR_PARITY_ERR, + C_RX_RBUF_DATA_COR_ERR, + C_RX_RBUF_DATA_UNC_ERR, + C_RX_DMA_DATA_FIFO_RD_COR_ERR, + C_RX_DMA_DATA_FIFO_RD_UNC_ERR, + C_RX_DMA_HDR_FIFO_RD_COR_ERR, + C_RX_DMA_HDR_FIFO_RD_UNC_ERR, + C_RX_RBUF_DESC_PART2_COR_ERR, + C_RX_RBUF_DESC_PART2_UNC_ERR, + C_RX_RBUF_DESC_PART1_COR_ERR, + C_RX_RBUF_DESC_PART1_UNC_ERR, + C_RX_HQ_INTR_FSM_ERR, + C_RX_HQ_INTR_CSR_PARITY_ERR, + C_RX_LOOKUP_CSR_PARITY_ERR, + C_RX_LOOKUP_RCV_ARRAY_COR_ERR, + C_RX_LOOKUP_RCV_ARRAY_UNC_ERR, + C_RX_LOOKUP_DES_PART2_PARITY_ERR, + C_RX_LOOKUP_DES_PART1_UNC_COR_ERR, + C_RX_LOOKUP_DES_PART1_UNC_ERR, + C_RX_RBUF_NEXT_FREE_BUF_COR_ERR, + C_RX_RBUF_NEXT_FREE_BUF_UNC_ERR, + C_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR, + C_RX_RBUF_FL_INITDONE_PARITY_ERR, + C_RX_RBUF_FL_WRITE_ADDR_PARITY_ERR, + C_RX_RBUF_FL_RD_ADDR_PARITY_ERR, + C_RX_RBUF_EMPTY_ERR, + C_RX_RBUF_FULL_ERR, + C_RX_RBUF_BAD_LOOKUP_ERR, + C_RX_RBUF_CTX_ID_PARITY_ERR, + C_RX_RBUF_CSR_QEOPDW_PARITY_ERR, + C_RX_RBUF_CSR_Q_NUM_OF_PKT_PARITY_ERR, + C_RX_RBUF_CSR_Q_T1_PTR_PARITY_ERR, + C_RX_RBUF_CSR_Q_HD_PTR_PARITY_ERR, + C_RX_RBUF_CSR_Q_VLD_BIT_PARITY_ERR, + C_RX_RBUF_CSR_Q_NEXT_BUF_PARITY_ERR, + C_RX_RBUF_CSR_Q_ENT_CNT_PARITY_ERR, + C_RX_RBUF_CSR_Q_HEAD_BUF_NUM_PARITY_ERR, + C_RX_RBUF_BLOCK_LIST_READ_COR_ERR, + C_RX_RBUF_BLOCK_LIST_READ_UNC_ERR, + C_RX_RBUF_LOOKUP_DES_COR_ERR, + C_RX_RBUF_LOOKUP_DES_UNC_ERR, + C_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR, + C_RX_RBUF_LOOKUP_DES_REG_UNC_ERR, + C_RX_RBUF_FREE_LIST_COR_ERR, + C_RX_RBUF_FREE_LIST_UNC_ERR, + C_RX_RCV_FSM_ENCODING_ERR, + C_RX_DMA_FLAG_COR_ERR, + C_RX_DMA_FLAG_UNC_ERR, + C_RX_DC_SOP_EOP_PARITY_ERR, + C_RX_RCV_CSR_PARITY_ERR, + C_RX_RCV_QP_MAP_TABLE_COR_ERR, + C_RX_RCV_QP_MAP_TABLE_UNC_ERR, + C_RX_RCV_DATA_COR_ERR, + C_RX_RCV_DATA_UNC_ERR, + C_RX_RCV_HDR_COR_ERR, + C_RX_RCV_HDR_UNC_ERR, + C_RX_DC_INTF_PARITY_ERR, + C_RX_DMA_CSR_COR_ERR, +/* SendPioErrStatus */ + C_PIO_PEC_SOP_HEAD_PARITY_ERR, + C_PIO_PCC_SOP_HEAD_PARITY_ERR, + C_PIO_LAST_RETURNED_CNT_PARITY_ERR, + C_PIO_CURRENT_FREE_CNT_PARITY_ERR, + C_PIO_RSVD_31_ERR, + C_PIO_RSVD_30_ERR, + C_PIO_PPMC_SOP_LEN_ERR, + C_PIO_PPMC_BQC_MEM_PARITY_ERR, + C_PIO_VL_FIFO_PARITY_ERR, + C_PIO_VLF_SOP_PARITY_ERR, + C_PIO_VLF_V1_LEN_PARITY_ERR, + C_PIO_BLOCK_QW_COUNT_PARITY_ERR, + C_PIO_WRITE_QW_VALID_PARITY_ERR, + C_PIO_STATE_MACHINE_ERR, + C_PIO_WRITE_DATA_PARITY_ERR, + C_PIO_HOST_ADDR_MEM_COR_ERR, + C_PIO_HOST_ADDR_MEM_UNC_ERR, + C_PIO_PKT_EVICT_SM_OR_ARM_SM_ERR, + C_PIO_INIT_SM_IN_ERR, + C_PIO_PPMC_PBL_FIFO_ERR, + C_PIO_CREDIT_RET_FIFO_PARITY_ERR, + C_PIO_V1_LEN_MEM_BANK1_COR_ERR, + C_PIO_V1_LEN_MEM_BANK0_COR_ERR, + C_PIO_V1_LEN_MEM_BANK1_UNC_ERR, + C_PIO_V1_LEN_MEM_BANK0_UNC_ERR, + C_PIO_SM_PKT_RESET_PARITY_ERR, + C_PIO_PKT_EVICT_FIFO_PARITY_ERR, + C_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR, + C_PIO_SBRDCTL_CRREL_PARITY_ERR, + C_PIO_PEC_FIFO_PARITY_ERR, + C_PIO_PCC_FIFO_PARITY_ERR, + C_PIO_SB_MEM_FIFO1_ERR, + C_PIO_SB_MEM_FIFO0_ERR, + C_PIO_CSR_PARITY_ERR, + C_PIO_WRITE_ADDR_PARITY_ERR, + C_PIO_WRITE_BAD_CTXT_ERR, +/* SendDmaErrStatus */ + C_SDMA_PCIE_REQ_TRACKING_COR_ERR, + C_SDMA_PCIE_REQ_TRACKING_UNC_ERR, + C_SDMA_CSR_PARITY_ERR, + C_SDMA_RPY_TAG_ERR, +/* SendEgressErrStatus */ + C_TX_READ_PIO_MEMORY_CSR_UNC_ERR, + C_TX_READ_SDMA_MEMORY_CSR_UNC_ERR, + C_TX_EGRESS_FIFO_COR_ERR, + C_TX_READ_PIO_MEMORY_COR_ERR, + C_TX_READ_SDMA_MEMORY_COR_ERR, + C_TX_SB_HDR_COR_ERR, + C_TX_CREDIT_OVERRUN_ERR, + C_TX_LAUNCH_FIFO8_COR_ERR, + C_TX_LAUNCH_FIFO7_COR_ERR, + C_TX_LAUNCH_FIFO6_COR_ERR, + C_TX_LAUNCH_FIFO5_COR_ERR, + C_TX_LAUNCH_FIFO4_COR_ERR, + C_TX_LAUNCH_FIFO3_COR_ERR, + C_TX_LAUNCH_FIFO2_COR_ERR, + C_TX_LAUNCH_FIFO1_COR_ERR, + C_TX_LAUNCH_FIFO0_COR_ERR, + C_TX_CREDIT_RETURN_VL_ERR, + C_TX_HCRC_INSERTION_ERR, + C_TX_EGRESS_FIFI_UNC_ERR, + C_TX_READ_PIO_MEMORY_UNC_ERR, + C_TX_READ_SDMA_MEMORY_UNC_ERR, + C_TX_SB_HDR_UNC_ERR, + C_TX_CREDIT_RETURN_PARITY_ERR, + C_TX_LAUNCH_FIFO8_UNC_OR_PARITY_ERR, + C_TX_LAUNCH_FIFO7_UNC_OR_PARITY_ERR, + C_TX_LAUNCH_FIFO6_UNC_OR_PARITY_ERR, + C_TX_LAUNCH_FIFO5_UNC_OR_PARITY_ERR, + C_TX_LAUNCH_FIFO4_UNC_OR_PARITY_ERR, + C_TX_LAUNCH_FIFO3_UNC_OR_PARITY_ERR, + C_TX_LAUNCH_FIFO2_UNC_OR_PARITY_ERR, + C_TX_LAUNCH_FIFO1_UNC_OR_PARITY_ERR, + C_TX_LAUNCH_FIFO0_UNC_OR_PARITY_ERR, + C_TX_SDMA15_DISALLOWED_PACKET_ERR, + C_TX_SDMA14_DISALLOWED_PACKET_ERR, + C_TX_SDMA13_DISALLOWED_PACKET_ERR, + C_TX_SDMA12_DISALLOWED_PACKET_ERR, + C_TX_SDMA11_DISALLOWED_PACKET_ERR, + C_TX_SDMA10_DISALLOWED_PACKET_ERR, + C_TX_SDMA9_DISALLOWED_PACKET_ERR, + C_TX_SDMA8_DISALLOWED_PACKET_ERR, + C_TX_SDMA7_DISALLOWED_PACKET_ERR, + C_TX_SDMA6_DISALLOWED_PACKET_ERR, + C_TX_SDMA5_DISALLOWED_PACKET_ERR, + C_TX_SDMA4_DISALLOWED_PACKET_ERR, + C_TX_SDMA3_DISALLOWED_PACKET_ERR, + C_TX_SDMA2_DISALLOWED_PACKET_ERR, + C_TX_SDMA1_DISALLOWED_PACKET_ERR, + C_TX_SDMA0_DISALLOWED_PACKET_ERR, + C_TX_CONFIG_PARITY_ERR, + C_TX_SBRD_CTL_CSR_PARITY_ERR, + C_TX_LAUNCH_CSR_PARITY_ERR, + C_TX_ILLEGAL_CL_ERR, + C_TX_SBRD_CTL_STATE_MACHINE_PARITY_ERR, + C_TX_RESERVED_10, + C_TX_RESERVED_9, + C_TX_SDMA_LAUNCH_INTF_PARITY_ERR, + C_TX_PIO_LAUNCH_INTF_PARITY_ERR, + C_TX_RESERVED_6, + C_TX_INCORRECT_LINK_STATE_ERR, + C_TX_LINK_DOWN_ERR, + C_TX_EGRESS_FIFO_UNDERRUN_OR_PARITY_ERR, + C_TX_RESERVED_2, + C_TX_PKT_INTEGRITY_MEM_UNC_ERR, + C_TX_PKT_INTEGRITY_MEM_COR_ERR, +/* SendErrStatus */ + C_SEND_CSR_WRITE_BAD_ADDR_ERR, + C_SEND_CSR_READ_BAD_ADD_ERR, + C_SEND_CSR_PARITY_ERR, +/* SendCtxtErrStatus */ + C_PIO_WRITE_OUT_OF_BOUNDS_ERR, + C_PIO_WRITE_OVERFLOW_ERR, + C_PIO_WRITE_CROSSES_BOUNDARY_ERR, + C_PIO_DISALLOWED_PACKET_ERR, + C_PIO_INCONSISTENT_SOP_ERR, +/*SendDmaEngErrStatus */ + C_SDMA_HEADER_REQUEST_FIFO_COR_ERR, + C_SDMA_HEADER_STORAGE_COR_ERR, + C_SDMA_PACKET_TRACKING_COR_ERR, + C_SDMA_ASSEMBLY_COR_ERR, + C_SDMA_DESC_TABLE_COR_ERR, + C_SDMA_HEADER_REQUEST_FIFO_UNC_ERR, + C_SDMA_HEADER_STORAGE_UNC_ERR, + C_SDMA_PACKET_TRACKING_UNC_ERR, + C_SDMA_ASSEMBLY_UNC_ERR, + C_SDMA_DESC_TABLE_UNC_ERR, + C_SDMA_TIMEOUT_ERR, + C_SDMA_HEADER_LENGTH_ERR, + C_SDMA_HEADER_ADDRESS_ERR, + C_SDMA_HEADER_SELECT_ERR, + C_SMDA_RESERVED_9, + C_SDMA_PACKET_DESC_OVERFLOW_ERR, + C_SDMA_LENGTH_MISMATCH_ERR, + C_SDMA_HALT_ERR, + C_SDMA_MEM_READ_ERR, + C_SDMA_FIRST_DESC_ERR, + C_SDMA_TAIL_OUT_OF_BOUNDS_ERR, + C_SDMA_TOO_LONG_ERR, + C_SDMA_GEN_MISMATCH_ERR, + C_SDMA_WRONG_DW_ERR, DEV_CNTR_LAST /* Must be kept last */ }; @@ -810,6 +1078,7 @@ enum { C_RX_WORDS, C_SW_LINK_DOWN, C_SW_LINK_UP, + C_SW_UNKNOWN_FRAME, C_SW_XMIT_DSCD, C_SW_XMIT_DSCD_VL, C_SW_XMIT_CSTR_ERR, diff --git a/drivers/staging/rdma/hfi1/chip_registers.h b/drivers/staging/rdma/hfi1/chip_registers.h index bf45de29d8bd..701e9e1012a6 100644 --- a/drivers/staging/rdma/hfi1/chip_registers.h +++ b/drivers/staging/rdma/hfi1/chip_registers.h @@ -318,6 +318,9 @@ #define DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT 0 #define DC_LCB_CFG_TX_FIFOS_RESET (DC_LCB_CSRS + 0x000000000008) #define DC_LCB_CFG_TX_FIFOS_RESET_VAL_SHIFT 0 +#define DC_LCB_CFG_REINIT_AS_SLAVE (DC_LCB_CSRS + 0x000000000030) +#define DC_LCB_CFG_CNT_FOR_SKIP_STALL (DC_LCB_CSRS + 0x000000000040) +#define DC_LCB_CFG_CLK_CNTR (DC_LCB_CSRS + 0x000000000110) #define DC_LCB_ERR_CLR (DC_LCB_CSRS + 0x000000000308) #define DC_LCB_ERR_EN (DC_LCB_CSRS + 0x000000000310) #define DC_LCB_ERR_FLG (DC_LCB_CSRS + 0x000000000300) @@ -379,7 +382,6 @@ #define DC_LCB_STS_ROUND_TRIP_LTP_CNT (DC_LCB_CSRS + 0x0000000004B0) #define RCV_BUF_OVFL_CNT 10 #define RCV_CONTEXT_EGR_STALL 22 -#define RCV_CONTEXT_RHQ_STALL 21 #define RCV_DATA_PKT_CNT 0 #define RCV_DWORD_CNT 1 #define RCV_TID_FLOW_GEN_MISMATCH_CNT 20 diff --git a/drivers/staging/rdma/hfi1/common.h b/drivers/staging/rdma/hfi1/common.h index 5e203239c5b0..5dd92720faae 100644 --- a/drivers/staging/rdma/hfi1/common.h +++ b/drivers/staging/rdma/hfi1/common.h @@ -132,13 +132,14 @@ * HFI1_CAP_RESERVED_MASK bits. */ #define HFI1_CAP_WRITABLE_MASK (HFI1_CAP_SDMA_AHG | \ - HFI1_CAP_HDRSUPP | \ - HFI1_CAP_MULTI_PKT_EGR | \ - HFI1_CAP_NODROP_RHQ_FULL | \ - HFI1_CAP_NODROP_EGR_FULL | \ - HFI1_CAP_ALLOW_PERM_JKEY | \ - HFI1_CAP_STATIC_RATE_CTRL | \ - HFI1_CAP_PRINT_UNIMPL) + HFI1_CAP_HDRSUPP | \ + HFI1_CAP_MULTI_PKT_EGR | \ + HFI1_CAP_NODROP_RHQ_FULL | \ + HFI1_CAP_NODROP_EGR_FULL | \ + HFI1_CAP_ALLOW_PERM_JKEY | \ + HFI1_CAP_STATIC_RATE_CTRL | \ + HFI1_CAP_PRINT_UNIMPL | \ + HFI1_CAP_TID_UNMAP) /* * A set of capability bits that are "global" and are not allowed to be * set in the user bitmask. diff --git a/drivers/staging/rdma/hfi1/diag.c b/drivers/staging/rdma/hfi1/diag.c index 88414d720469..0c8831705664 100644 --- a/drivers/staging/rdma/hfi1/diag.c +++ b/drivers/staging/rdma/hfi1/diag.c @@ -78,8 +78,8 @@ hfi1_cdbg(SNOOP, fmt, ##__VA_ARGS__) /* Snoop option mask */ -#define SNOOP_DROP_SEND (1 << 0) -#define SNOOP_USE_METADATA (1 << 1) +#define SNOOP_DROP_SEND BIT(0) +#define SNOOP_USE_METADATA BIT(1) static u8 snoop_flags; @@ -135,7 +135,7 @@ static struct cdev diagpkt_cdev; static struct device *diagpkt_device; static ssize_t diagpkt_write(struct file *fp, const char __user *data, - size_t count, loff_t *off); + size_t count, loff_t *off); static const struct file_operations diagpkt_file_ops = { .owner = THIS_MODULE, @@ -177,37 +177,37 @@ struct hfi1_link_info { #define HFI1_SNOOP_IOCGETLINKSTATE \ _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ) #define HFI1_SNOOP_IOCSETLINKSTATE \ - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+1) + _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 1) #define HFI1_SNOOP_IOCCLEARQUEUE \ - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+2) + _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 2) #define HFI1_SNOOP_IOCCLEARFILTER \ - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+3) + _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 3) #define HFI1_SNOOP_IOCSETFILTER \ - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+4) + _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 4) #define HFI1_SNOOP_IOCGETVERSION \ - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+5) + _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 5) #define HFI1_SNOOP_IOCSET_OPTS \ - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+6) + _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 6) /* * These offsets +6/+7 could change, but these are already known and used * IOCTL numbers so don't change them without a good reason. */ #define HFI1_SNOOP_IOCGETLINKSTATE_EXTRA \ - _IOWR(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+6, \ + _IOWR(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 6, \ struct hfi1_link_info) #define HFI1_SNOOP_IOCSETLINKSTATE_EXTRA \ - _IOWR(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+7, \ + _IOWR(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 7, \ struct hfi1_link_info) static int hfi1_snoop_open(struct inode *in, struct file *fp); static ssize_t hfi1_snoop_read(struct file *fp, char __user *data, - size_t pkt_len, loff_t *off); + size_t pkt_len, loff_t *off); static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data, - size_t count, loff_t *off); + size_t count, loff_t *off); static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg); static unsigned int hfi1_snoop_poll(struct file *fp, - struct poll_table_struct *wait); + struct poll_table_struct *wait); static int hfi1_snoop_release(struct inode *in, struct file *fp); struct hfi1_packet_filter_command { @@ -323,14 +323,12 @@ static void hfi1_snoop_remove(struct hfi1_devdata *dd) void hfi1_diag_remove(struct hfi1_devdata *dd) { - hfi1_snoop_remove(dd); if (atomic_dec_and_test(&diagpkt_count)) hfi1_cdev_cleanup(&diagpkt_cdev, &diagpkt_device); hfi1_cdev_cleanup(&dd->diag_cdev, &dd->diag_device); } - /* * Allocated structure shared between the credit return mechanism and * diagpkt_send(). @@ -379,6 +377,7 @@ static ssize_t diagpkt_send(struct diag_pkt *dp) pio_release_cb credit_cb = NULL; void *credit_arg = NULL; struct diagpkt_wait *wait = NULL; + int trycount = 0; dd = hfi1_lookup(dp->unit); if (!dd || !(dd->flags & HFI1_PRESENT) || !dd->kregbase) { @@ -393,7 +392,7 @@ static ssize_t diagpkt_send(struct diag_pkt *dp) if (dp->version != _DIAG_PKT_VERS) { dd_dev_err(dd, "Invalid version %u for diagpkt_write\n", - dp->version); + dp->version); ret = -EINVAL; goto bail; } @@ -440,7 +439,7 @@ static ssize_t diagpkt_send(struct diag_pkt *dp) } if (copy_from_user(tmpbuf, - (const void __user *) (unsigned long) dp->data, + (const void __user *)(unsigned long)dp->data, dp->len)) { ret = -EFAULT; goto bail; @@ -493,8 +492,15 @@ static ssize_t diagpkt_send(struct diag_pkt *dp) credit_arg = wait; } +retry: pbuf = sc_buffer_alloc(sc, total_len, credit_cb, credit_arg); if (!pbuf) { + if (trycount == 0) { + /* force a credit return and try again */ + sc_return_credits(sc); + trycount = 1; + goto retry; + } /* * No send buffer means no credit callback. Undo * the wait set-up that was done above. We free wait @@ -530,9 +536,9 @@ static ssize_t diagpkt_send(struct diag_pkt *dp) * NOTE: PRC_FILL_ERR is at best informational and cannot * be depended on. */ - if (!ret && (((wait->code & PRC_STATUS_ERR) - || (wait->code & PRC_FILL_ERR) - || (wait->code & PRC_SC_DISABLE)))) + if (!ret && (((wait->code & PRC_STATUS_ERR) || + (wait->code & PRC_FILL_ERR) || + (wait->code & PRC_SC_DISABLE)))) ret = -EIO; put_diagpkt_wait(wait); /* finished with the structure */ @@ -545,7 +551,7 @@ bail: } static ssize_t diagpkt_write(struct file *fp, const char __user *data, - size_t count, loff_t *off) + size_t count, loff_t *off) { struct hfi1_devdata *dd; struct send_context *sc; @@ -565,7 +571,7 @@ static ssize_t diagpkt_write(struct file *fp, const char __user *data, */ if (dp.pbc) { dd = hfi1_lookup(dp.unit); - if (dd == NULL) + if (!dd) return -ENODEV; vl = (dp.pbc >> PBC_VL_SHIFT) & PBC_VL_MASK; sc = dd->vld[vl].sc; @@ -598,7 +604,7 @@ static int hfi1_snoop_add(struct hfi1_devdata *dd, const char *name) if (ret) { dd_dev_err(dd, "Couldn't create %s device: %d", name, ret); hfi1_cdev_cleanup(&dd->hfi1_snoop.cdev, - &dd->hfi1_snoop.class_dev); + &dd->hfi1_snoop.class_dev); } return ret; @@ -611,7 +617,6 @@ static struct hfi1_devdata *hfi1_dd_from_sc_inode(struct inode *in) dd = hfi1_lookup(unit); return dd; - } /* clear or restore send context integrity checks */ @@ -652,7 +657,7 @@ static int hfi1_snoop_open(struct inode *in, struct file *fp) mutex_lock(&hfi1_mutex); dd = hfi1_dd_from_sc_inode(in); - if (dd == NULL) { + if (!dd) { ret = -ENODEV; goto bail; } @@ -739,7 +744,7 @@ static int hfi1_snoop_release(struct inode *in, struct file *fp) int mode_flag; dd = hfi1_dd_from_sc_inode(in); - if (dd == NULL) + if (!dd) return -ENODEV; spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); @@ -794,7 +799,7 @@ static unsigned int hfi1_snoop_poll(struct file *fp, struct hfi1_devdata *dd; dd = hfi1_dd_from_sc_inode(fp->f_inode); - if (dd == NULL) + if (!dd) return -ENODEV; spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); @@ -805,7 +810,6 @@ static unsigned int hfi1_snoop_poll(struct file *fp, spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); return ret; - } static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data, @@ -822,7 +826,7 @@ static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data, struct hfi1_pportdata *ppd; dd = hfi1_dd_from_sc_inode(fp->f_inode); - if (dd == NULL) + if (!dd) return -ENODEV; ppd = dd->pport; @@ -847,7 +851,7 @@ static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data, if (copy_from_user(&byte_one, data, 1)) return -EINVAL; - if (copy_from_user(&byte_two, data+1, 1)) + if (copy_from_user(&byte_two, data + 1, 1)) return -EINVAL; sc4 = (byte_one >> 4) & 0xf; @@ -920,7 +924,7 @@ static ssize_t hfi1_snoop_read(struct file *fp, char __user *data, struct hfi1_devdata *dd; dd = hfi1_dd_from_sc_inode(fp->f_inode); - if (dd == NULL) + if (!dd) return -ENODEV; spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); @@ -946,16 +950,18 @@ static ssize_t hfi1_snoop_read(struct file *fp, char __user *data, spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); if (pkt_len >= packet->total_len) { if (copy_to_user(data, packet->data, - packet->total_len)) + packet->total_len)) ret = -EFAULT; else ret = packet->total_len; - } else + } else { ret = -EINVAL; + } kfree(packet); - } else + } else { spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); + } return ret; } @@ -966,9 +972,9 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) void *filter_value = NULL; long ret = 0; int value = 0; - u8 physState = 0; - u8 linkState = 0; - u16 devState = 0; + u8 phys_state = 0; + u8 link_state = 0; + u16 dev_state = 0; unsigned long flags = 0; unsigned long *argp = NULL; struct hfi1_packet_filter_command filter_cmd = {0}; @@ -976,237 +982,221 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) struct hfi1_pportdata *ppd = NULL; unsigned int index; struct hfi1_link_info link_info; + int read_cmd, write_cmd, read_ok, write_ok; dd = hfi1_dd_from_sc_inode(fp->f_inode); - if (dd == NULL) + if (!dd) return -ENODEV; - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); - mode_flag = dd->hfi1_snoop.mode_flag; + read_cmd = _IOC_DIR(cmd) & _IOC_READ; + write_cmd = _IOC_DIR(cmd) & _IOC_WRITE; + write_ok = access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd)); + read_ok = access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd)); - if (((_IOC_DIR(cmd) & _IOC_READ) - && !access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd))) - || ((_IOC_DIR(cmd) & _IOC_WRITE) - && !access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd)))) { - ret = -EFAULT; - } else if (!capable(CAP_SYS_ADMIN)) { - ret = -EPERM; - } else if ((mode_flag & HFI1_PORT_CAPTURE_MODE) && - (cmd != HFI1_SNOOP_IOCCLEARQUEUE) && - (cmd != HFI1_SNOOP_IOCCLEARFILTER) && - (cmd != HFI1_SNOOP_IOCSETFILTER)) { + if ((read_cmd && !write_ok) || (write_cmd && !read_ok)) + return -EFAULT; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if ((mode_flag & HFI1_PORT_CAPTURE_MODE) && + (cmd != HFI1_SNOOP_IOCCLEARQUEUE) && + (cmd != HFI1_SNOOP_IOCCLEARFILTER) && + (cmd != HFI1_SNOOP_IOCSETFILTER)) /* Capture devices are allowed only 3 operations * 1.Clear capture queue * 2.Clear capture filter * 3.Set capture filter * Other are invalid. */ - ret = -EINVAL; - } else { - switch (cmd) { - case HFI1_SNOOP_IOCSETLINKSTATE: - snoop_dbg("HFI1_SNOOP_IOCSETLINKSTATE is not valid"); - ret = -EINVAL; - break; + return -EINVAL; - case HFI1_SNOOP_IOCSETLINKSTATE_EXTRA: - memset(&link_info, 0, sizeof(link_info)); + switch (cmd) { + case HFI1_SNOOP_IOCSETLINKSTATE_EXTRA: + memset(&link_info, 0, sizeof(link_info)); - if (copy_from_user(&link_info, - (struct hfi1_link_info __user *)arg, - sizeof(link_info))) - ret = -EFAULT; + if (copy_from_user(&link_info, + (struct hfi1_link_info __user *)arg, + sizeof(link_info))) + return -EFAULT; - value = link_info.port_state; - index = link_info.port_number; - if (index > dd->num_pports - 1) { - ret = -EINVAL; - break; - } + value = link_info.port_state; + index = link_info.port_number; + if (index > dd->num_pports - 1) + return -EINVAL; - ppd = &dd->pport[index]; - if (!ppd) { - ret = -EINVAL; - break; - } + ppd = &dd->pport[index]; + if (!ppd) + return -EINVAL; - /* What we want to transition to */ - physState = (value >> 4) & 0xF; - linkState = value & 0xF; - snoop_dbg("Setting link state 0x%x", value); - - switch (linkState) { - case IB_PORT_NOP: - if (physState == 0) - break; - /* fall through */ - case IB_PORT_DOWN: - switch (physState) { - case 0: - devState = HLS_DN_DOWNDEF; - break; - case 2: - devState = HLS_DN_POLL; - break; - case 3: - devState = HLS_DN_DISABLE; - break; - default: - ret = -EINVAL; - goto done; - } - ret = set_link_state(ppd, devState); - break; - case IB_PORT_ARMED: - ret = set_link_state(ppd, HLS_UP_ARMED); - if (!ret) - send_idle_sma(dd, SMA_IDLE_ARM); - break; - case IB_PORT_ACTIVE: - ret = set_link_state(ppd, HLS_UP_ACTIVE); - if (!ret) - send_idle_sma(dd, SMA_IDLE_ACTIVE); - break; - default: - ret = -EINVAL; - break; - } + /* What we want to transition to */ + phys_state = (value >> 4) & 0xF; + link_state = value & 0xF; + snoop_dbg("Setting link state 0x%x", value); - if (ret) + switch (link_state) { + case IB_PORT_NOP: + if (phys_state == 0) break; - /* fall through */ - case HFI1_SNOOP_IOCGETLINKSTATE: - case HFI1_SNOOP_IOCGETLINKSTATE_EXTRA: - if (cmd == HFI1_SNOOP_IOCGETLINKSTATE_EXTRA) { - memset(&link_info, 0, sizeof(link_info)); - if (copy_from_user(&link_info, - (struct hfi1_link_info __user *)arg, - sizeof(link_info))) - ret = -EFAULT; - index = link_info.port_number; - } else { - ret = __get_user(index, (int __user *) arg); - if (ret != 0) - break; - } - - if (index > dd->num_pports - 1) { - ret = -EINVAL; + /* fall through */ + case IB_PORT_DOWN: + switch (phys_state) { + case 0: + dev_state = HLS_DN_DOWNDEF; break; - } - - ppd = &dd->pport[index]; - if (!ppd) { - ret = -EINVAL; + case 2: + dev_state = HLS_DN_POLL; break; + case 3: + dev_state = HLS_DN_DISABLE; + break; + default: + return -EINVAL; } - value = hfi1_ibphys_portstate(ppd); - value <<= 4; - value |= driver_lstate(ppd); - - snoop_dbg("Link port | Link State: %d", value); - - if ((cmd == HFI1_SNOOP_IOCGETLINKSTATE_EXTRA) || - (cmd == HFI1_SNOOP_IOCSETLINKSTATE_EXTRA)) { - link_info.port_state = value; - link_info.node_guid = cpu_to_be64(ppd->guid); - link_info.link_speed_active = - ppd->link_speed_active; - link_info.link_width_active = - ppd->link_width_active; - if (copy_to_user( - (struct hfi1_link_info __user *)arg, - &link_info, sizeof(link_info))) - ret = -EFAULT; - } else { - ret = __put_user(value, (int __user *)arg); - } + ret = set_link_state(ppd, dev_state); break; - - case HFI1_SNOOP_IOCCLEARQUEUE: - snoop_dbg("Clearing snoop queue"); - drain_snoop_list(&dd->hfi1_snoop.queue); + case IB_PORT_ARMED: + ret = set_link_state(ppd, HLS_UP_ARMED); + if (!ret) + send_idle_sma(dd, SMA_IDLE_ARM); break; - - case HFI1_SNOOP_IOCCLEARFILTER: - snoop_dbg("Clearing filter"); - if (dd->hfi1_snoop.filter_callback) { - /* Drain packets first */ - drain_snoop_list(&dd->hfi1_snoop.queue); - dd->hfi1_snoop.filter_callback = NULL; - } - kfree(dd->hfi1_snoop.filter_value); - dd->hfi1_snoop.filter_value = NULL; + case IB_PORT_ACTIVE: + ret = set_link_state(ppd, HLS_UP_ACTIVE); + if (!ret) + send_idle_sma(dd, SMA_IDLE_ACTIVE); break; + default: + return -EINVAL; + } - case HFI1_SNOOP_IOCSETFILTER: - snoop_dbg("Setting filter"); - /* just copy command structure */ - argp = (unsigned long *)arg; - if (copy_from_user(&filter_cmd, (void __user *)argp, - sizeof(filter_cmd))) { - ret = -EFAULT; - break; - } - if (filter_cmd.opcode >= HFI1_MAX_FILTERS) { - pr_alert("Invalid opcode in request\n"); - ret = -EINVAL; + if (ret) + break; + /* fall through */ + case HFI1_SNOOP_IOCGETLINKSTATE: + case HFI1_SNOOP_IOCGETLINKSTATE_EXTRA: + if (cmd == HFI1_SNOOP_IOCGETLINKSTATE_EXTRA) { + memset(&link_info, 0, sizeof(link_info)); + if (copy_from_user(&link_info, + (struct hfi1_link_info __user *)arg, + sizeof(link_info))) + return -EFAULT; + index = link_info.port_number; + } else { + ret = __get_user(index, (int __user *)arg); + if (ret != 0) break; - } + } - snoop_dbg("Opcode %d Len %d Ptr %p", - filter_cmd.opcode, filter_cmd.length, - filter_cmd.value_ptr); + if (index > dd->num_pports - 1) + return -EINVAL; - filter_value = kcalloc(filter_cmd.length, sizeof(u8), - GFP_KERNEL); - if (!filter_value) { - pr_alert("Not enough memory\n"); - ret = -ENOMEM; - break; - } - /* copy remaining data from userspace */ - if (copy_from_user((u8 *)filter_value, - (void __user *)filter_cmd.value_ptr, - filter_cmd.length)) { - kfree(filter_value); - ret = -EFAULT; - break; - } + ppd = &dd->pport[index]; + if (!ppd) + return -EINVAL; + + value = hfi1_ibphys_portstate(ppd); + value <<= 4; + value |= driver_lstate(ppd); + + snoop_dbg("Link port | Link State: %d", value); + + if ((cmd == HFI1_SNOOP_IOCGETLINKSTATE_EXTRA) || + (cmd == HFI1_SNOOP_IOCSETLINKSTATE_EXTRA)) { + link_info.port_state = value; + link_info.node_guid = cpu_to_be64(ppd->guid); + link_info.link_speed_active = + ppd->link_speed_active; + link_info.link_width_active = + ppd->link_width_active; + if (copy_to_user((struct hfi1_link_info __user *)arg, + &link_info, sizeof(link_info))) + return -EFAULT; + } else { + ret = __put_user(value, (int __user *)arg); + } + break; + + case HFI1_SNOOP_IOCCLEARQUEUE: + snoop_dbg("Clearing snoop queue"); + spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); + drain_snoop_list(&dd->hfi1_snoop.queue); + spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); + break; + + case HFI1_SNOOP_IOCCLEARFILTER: + snoop_dbg("Clearing filter"); + spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); + if (dd->hfi1_snoop.filter_callback) { /* Drain packets first */ drain_snoop_list(&dd->hfi1_snoop.queue); - dd->hfi1_snoop.filter_callback = - hfi1_filters[filter_cmd.opcode].filter; - /* just in case we see back to back sets */ - kfree(dd->hfi1_snoop.filter_value); - dd->hfi1_snoop.filter_value = filter_value; + dd->hfi1_snoop.filter_callback = NULL; + } + kfree(dd->hfi1_snoop.filter_value); + dd->hfi1_snoop.filter_value = NULL; + spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); + break; - break; - case HFI1_SNOOP_IOCGETVERSION: - value = SNOOP_CAPTURE_VERSION; - snoop_dbg("Getting version: %d", value); - ret = __put_user(value, (int __user *)arg); - break; - case HFI1_SNOOP_IOCSET_OPTS: - snoop_flags = 0; - ret = __get_user(value, (int __user *) arg); - if (ret != 0) - break; + case HFI1_SNOOP_IOCSETFILTER: + snoop_dbg("Setting filter"); + /* just copy command structure */ + argp = (unsigned long *)arg; + if (copy_from_user(&filter_cmd, (void __user *)argp, + sizeof(filter_cmd))) + return -EFAULT; - snoop_dbg("Setting snoop option %d", value); - if (value & SNOOP_DROP_SEND) - snoop_flags |= SNOOP_DROP_SEND; - if (value & SNOOP_USE_METADATA) - snoop_flags |= SNOOP_USE_METADATA; - break; - default: - ret = -ENOTTY; - break; + if (filter_cmd.opcode >= HFI1_MAX_FILTERS) { + pr_alert("Invalid opcode in request\n"); + return -EINVAL; + } + + snoop_dbg("Opcode %d Len %d Ptr %p", + filter_cmd.opcode, filter_cmd.length, + filter_cmd.value_ptr); + + filter_value = kcalloc(filter_cmd.length, sizeof(u8), + GFP_KERNEL); + if (!filter_value) + return -ENOMEM; + + /* copy remaining data from userspace */ + if (copy_from_user((u8 *)filter_value, + (void __user *)filter_cmd.value_ptr, + filter_cmd.length)) { + kfree(filter_value); + return -EFAULT; } + /* Drain packets first */ + spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); + drain_snoop_list(&dd->hfi1_snoop.queue); + dd->hfi1_snoop.filter_callback = + hfi1_filters[filter_cmd.opcode].filter; + /* just in case we see back to back sets */ + kfree(dd->hfi1_snoop.filter_value); + dd->hfi1_snoop.filter_value = filter_value; + spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); + break; + case HFI1_SNOOP_IOCGETVERSION: + value = SNOOP_CAPTURE_VERSION; + snoop_dbg("Getting version: %d", value); + ret = __put_user(value, (int __user *)arg); + break; + case HFI1_SNOOP_IOCSET_OPTS: + snoop_flags = 0; + ret = __get_user(value, (int __user *)arg); + if (ret != 0) + break; + + snoop_dbg("Setting snoop option %d", value); + if (value & SNOOP_DROP_SEND) + snoop_flags |= SNOOP_DROP_SEND; + if (value & SNOOP_USE_METADATA) + snoop_flags |= SNOOP_USE_METADATA; + break; + default: + return -ENOTTY; } -done: - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); + return ret; } @@ -1321,7 +1311,6 @@ static int hfi1_filter_mad_mgmt_class(void *ibhdr, void *packet_data, static int hfi1_filter_qp_number(void *ibhdr, void *packet_data, void *value) { - struct hfi1_ib_header *hdr; struct hfi1_other_headers *ohdr = NULL; int ret; @@ -1404,7 +1393,6 @@ static int hfi1_filter_ib_service_level(void *ibhdr, void *packet_data, static int hfi1_filter_ib_pkey(void *ibhdr, void *packet_data, void *value) { - u32 lnh = 0; struct hfi1_ib_header *hdr; struct hfi1_other_headers *ohdr = NULL; @@ -1476,16 +1464,14 @@ static struct snoop_packet *allocate_snoop_packet(u32 hdr_len, u32 data_len, u32 md_len) { - struct snoop_packet *packet; - packet = kzalloc(sizeof(struct snoop_packet) + hdr_len + data_len + packet = kzalloc(sizeof(*packet) + hdr_len + data_len + md_len, GFP_ATOMIC | __GFP_NOWARN); if (likely(packet)) INIT_LIST_HEAD(&packet->list); - return packet; } @@ -1542,12 +1528,11 @@ int snoop_recv_handler(struct hfi1_packet *packet) unlikely(snoop_flags & SNOOP_USE_METADATA)) md_len = sizeof(struct capture_md); - s_packet = allocate_snoop_packet(header_size, tlen - header_size, md_len); - if (unlikely(s_packet == NULL)) { + if (unlikely(!s_packet)) { dd_dev_warn_ratelimited(ppd->dd, "Unable to allocate snoop/capture packet\n"); break; } @@ -1618,14 +1603,12 @@ int snoop_recv_handler(struct hfi1_packet *packet) /* * Handle snooping and capturing packets when sdma is being used. */ -int snoop_send_dma_handler(struct hfi1_qp *qp, struct ahg_ib_header *ibhdr, - u32 hdrwords, struct hfi1_sge_state *ss, u32 len, - u32 plen, u32 dwords, u64 pbc) +int snoop_send_dma_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, + u64 pbc) { - pr_alert("Snooping/Capture of Send DMA Packets Is Not Supported!\n"); + pr_alert("Snooping/Capture of Send DMA Packets Is Not Supported!\n"); snoop_dbg("Unsupported Operation"); - return hfi1_verbs_send_dma(qp, ibhdr, hdrwords, ss, len, plen, dwords, - 0); + return hfi1_verbs_send_dma(qp, ps, 0); } /* @@ -1633,12 +1616,16 @@ int snoop_send_dma_handler(struct hfi1_qp *qp, struct ahg_ib_header *ibhdr, * bypass packets. The only way to send a bypass packet currently is to use the * diagpkt interface. When that interface is enable snoop/capture is not. */ -int snoop_send_pio_handler(struct hfi1_qp *qp, struct ahg_ib_header *ahdr, - u32 hdrwords, struct hfi1_sge_state *ss, u32 len, - u32 plen, u32 dwords, u64 pbc) +int snoop_send_pio_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, + u64 pbc) { - struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); - struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); + struct ahg_ib_header *ahdr = qp->s_hdr; + u32 hdrwords = qp->s_hdrwords; + struct hfi1_sge_state *ss = qp->s_cur_sge; + u32 len = qp->s_cur_size; + u32 dwords = (len + 3) >> 2; + u32 plen = hdrwords + dwords + 2; /* includes pbc */ + struct hfi1_pportdata *ppd = ps->ppd; struct snoop_packet *s_packet = NULL; u32 *hdr = (u32 *)&ahdr->ibh; u32 length = 0; @@ -1666,7 +1653,7 @@ int snoop_send_pio_handler(struct hfi1_qp *qp, struct ahg_ib_header *ahdr, /* not using ss->total_len as arg 2 b/c that does not count CRC */ s_packet = allocate_snoop_packet(hdr_len, tlen - hdr_len, md_len); - if (unlikely(s_packet == NULL)) { + if (unlikely(!s_packet)) { dd_dev_warn_ratelimited(ppd->dd, "Unable to allocate snoop/capture packet\n"); goto out; } @@ -1783,8 +1770,7 @@ int snoop_send_pio_handler(struct hfi1_qp *qp, struct ahg_ib_header *ahdr, break; } out: - return hfi1_verbs_send_pio(qp, ahdr, hdrwords, ss, len, plen, dwords, - md.u.pbc); + return hfi1_verbs_send_pio(qp, ps, md.u.pbc); } /* @@ -1836,7 +1822,7 @@ void snoop_inline_pio_send(struct hfi1_devdata *dd, struct pio_buf *pbuf, s_packet = allocate_snoop_packet(packet_len, 0, md_len); - if (unlikely(s_packet == NULL)) { + if (unlikely(!s_packet)) { dd_dev_warn_ratelimited(dd, "Unable to allocate snoop/capture packet\n"); goto inline_pio_out; } @@ -1868,5 +1854,4 @@ void snoop_inline_pio_send(struct hfi1_devdata *dd, struct pio_buf *pbuf, inline_pio_out: pio_copy(dd, pbuf, pbc, from, count); - } diff --git a/drivers/staging/rdma/hfi1/driver.c b/drivers/staging/rdma/hfi1/driver.c index ce69141b56cb..8485de1fce08 100644 --- a/drivers/staging/rdma/hfi1/driver.c +++ b/drivers/staging/rdma/hfi1/driver.c @@ -158,7 +158,7 @@ const char *get_unit_name(int unit) { static char iname[16]; - snprintf(iname, sizeof(iname), DRIVER_NAME"_%u", unit); + snprintf(iname, sizeof(iname), DRIVER_NAME "_%u", unit); return iname; } @@ -436,59 +436,58 @@ static inline void init_packet(struct hfi1_ctxtdata *rcd, #ifndef CONFIG_PRESCAN_RXQ static void prescan_rxq(struct hfi1_packet *packet) {} -#else /* CONFIG_PRESCAN_RXQ */ +#else /* !CONFIG_PRESCAN_RXQ */ static int prescan_receive_queue; static void process_ecn(struct hfi1_qp *qp, struct hfi1_ib_header *hdr, struct hfi1_other_headers *ohdr, - u64 rhf, struct ib_grh *grh) + u64 rhf, u32 bth1, struct ib_grh *grh) { struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); - u32 bth1; + u32 rqpn = 0; + u16 rlid; u8 sc5, svc_type; - int is_fecn, is_becn; switch (qp->ibqp.qp_type) { + case IB_QPT_SMI: + case IB_QPT_GSI: case IB_QPT_UD: + rlid = be16_to_cpu(hdr->lrh[3]); + rqpn = be32_to_cpu(ohdr->u.ud.deth[1]) & HFI1_QPN_MASK; svc_type = IB_CC_SVCTYPE_UD; break; - case IB_QPT_UC: /* LATER */ - case IB_QPT_RC: /* LATER */ + case IB_QPT_UC: + rlid = qp->remote_ah_attr.dlid; + rqpn = qp->remote_qpn; + svc_type = IB_CC_SVCTYPE_UC; + break; + case IB_QPT_RC: + rlid = qp->remote_ah_attr.dlid; + rqpn = qp->remote_qpn; + svc_type = IB_CC_SVCTYPE_RC; + break; default: return; } - is_fecn = (be32_to_cpu(ohdr->bth[1]) >> HFI1_FECN_SHIFT) & - HFI1_FECN_MASK; - is_becn = (be32_to_cpu(ohdr->bth[1]) >> HFI1_BECN_SHIFT) & - HFI1_BECN_MASK; - sc5 = (be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf; if (rhf_dc_info(rhf)) sc5 |= 0x10; - if (is_fecn) { - u32 src_qpn = be32_to_cpu(ohdr->u.ud.deth[1]) & HFI1_QPN_MASK; + if (bth1 & HFI1_FECN_SMASK) { u16 pkey = (u16)be32_to_cpu(ohdr->bth[0]); u16 dlid = be16_to_cpu(hdr->lrh[1]); - u16 slid = be16_to_cpu(hdr->lrh[3]); - return_cnp(ibp, qp, src_qpn, pkey, dlid, slid, sc5, grh); + return_cnp(ibp, qp, rqpn, pkey, dlid, rlid, sc5, grh); } - if (is_becn) { + if (bth1 & HFI1_BECN_SMASK) { struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); - u32 lqpn = be32_to_cpu(ohdr->bth[1]) & HFI1_QPN_MASK; + u32 lqpn = bth1 & HFI1_QPN_MASK; u8 sl = ibp->sc_to_sl[sc5]; - process_becn(ppd, sl, 0, lqpn, 0, svc_type); + process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type); } - - /* turn off BECN, or FECN */ - bth1 = be32_to_cpu(ohdr->bth[1]); - bth1 &= ~(HFI1_FECN_MASK << HFI1_FECN_SHIFT); - bth1 &= ~(HFI1_BECN_MASK << HFI1_BECN_SHIFT); - ohdr->bth[1] = cpu_to_be32(bth1); } struct ps_mdata { @@ -508,38 +507,51 @@ static inline void init_ps_mdata(struct ps_mdata *mdata, mdata->rcd = rcd; mdata->rsize = packet->rsize; mdata->maxcnt = packet->maxcnt; + mdata->ps_head = packet->rhqoff; - if (rcd->ps_state.initialized == 0) { - mdata->ps_head = packet->rhqoff; - rcd->ps_state.initialized++; - } else - mdata->ps_head = rcd->ps_state.ps_head; - - if (HFI1_CAP_IS_KSET(DMA_RTAIL)) { - mdata->ps_tail = packet->hdrqtail; - mdata->ps_seq = 0; /* not used with DMA_RTAIL */ + if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) { + mdata->ps_tail = get_rcvhdrtail(rcd); + if (rcd->ctxt == HFI1_CTRL_CTXT) + mdata->ps_seq = rcd->seq_cnt; + else + mdata->ps_seq = 0; /* not used with DMA_RTAIL */ } else { mdata->ps_tail = 0; /* used only with DMA_RTAIL*/ mdata->ps_seq = rcd->seq_cnt; } } -static inline int ps_done(struct ps_mdata *mdata, u64 rhf) +static inline int ps_done(struct ps_mdata *mdata, u64 rhf, + struct hfi1_ctxtdata *rcd) { - if (HFI1_CAP_IS_KSET(DMA_RTAIL)) + if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) return mdata->ps_head == mdata->ps_tail; return mdata->ps_seq != rhf_rcv_seq(rhf); } -static inline void update_ps_mdata(struct ps_mdata *mdata) +static inline int ps_skip(struct ps_mdata *mdata, u64 rhf, + struct hfi1_ctxtdata *rcd) { - struct hfi1_ctxtdata *rcd = mdata->rcd; + /* + * Control context can potentially receive an invalid rhf. + * Drop such packets. + */ + if ((rcd->ctxt == HFI1_CTRL_CTXT) && (mdata->ps_head != mdata->ps_tail)) + return mdata->ps_seq != rhf_rcv_seq(rhf); + + return 0; +} +static inline void update_ps_mdata(struct ps_mdata *mdata, + struct hfi1_ctxtdata *rcd) +{ mdata->ps_head += mdata->rsize; - if (mdata->ps_head > mdata->maxcnt) + if (mdata->ps_head >= mdata->maxcnt) mdata->ps_head = 0; - rcd->ps_state.ps_head = mdata->ps_head; - if (!HFI1_CAP_IS_KSET(DMA_RTAIL)) { + + /* Control context must do seq counting */ + if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) || + (rcd->ctxt == HFI1_CTRL_CTXT)) { if (++mdata->ps_seq > 13) mdata->ps_seq = 1; } @@ -571,13 +583,16 @@ static void prescan_rxq(struct hfi1_packet *packet) struct hfi1_other_headers *ohdr; struct ib_grh *grh = NULL; u64 rhf = rhf_to_cpu(rhf_addr); - u32 etype = rhf_rcv_type(rhf), qpn; + u32 etype = rhf_rcv_type(rhf), qpn, bth1; int is_ecn = 0; u8 lnh; - if (ps_done(&mdata, rhf)) + if (ps_done(&mdata, rhf, rcd)) break; + if (ps_skip(&mdata, rhf, rcd)) + goto next; + if (etype != RHF_RCV_TYPE_IB) goto next; @@ -593,15 +608,13 @@ static void prescan_rxq(struct hfi1_packet *packet) } else goto next; /* just in case */ - is_ecn |= be32_to_cpu(ohdr->bth[1]) & - (HFI1_FECN_MASK << HFI1_FECN_SHIFT); - is_ecn |= be32_to_cpu(ohdr->bth[1]) & - (HFI1_BECN_MASK << HFI1_BECN_SHIFT); + bth1 = be32_to_cpu(ohdr->bth[1]); + is_ecn = !!(bth1 & (HFI1_FECN_SMASK | HFI1_BECN_SMASK)); if (!is_ecn) goto next; - qpn = be32_to_cpu(ohdr->bth[1]) & HFI1_QPN_MASK; + qpn = bth1 & HFI1_QPN_MASK; rcu_read_lock(); qp = hfi1_lookup_qpn(ibp, qpn); @@ -610,14 +623,44 @@ static void prescan_rxq(struct hfi1_packet *packet) goto next; } - process_ecn(qp, hdr, ohdr, rhf, grh); + process_ecn(qp, hdr, ohdr, rhf, bth1, grh); rcu_read_unlock(); + + /* turn off BECN, FECN */ + bth1 &= ~(HFI1_FECN_SMASK | HFI1_BECN_SMASK); + ohdr->bth[1] = cpu_to_be32(bth1); next: - update_ps_mdata(&mdata); + update_ps_mdata(&mdata, rcd); } } #endif /* CONFIG_PRESCAN_RXQ */ +static inline int skip_rcv_packet(struct hfi1_packet *packet, int thread) +{ + int ret = RCV_PKT_OK; + + /* Set up for the next packet */ + packet->rhqoff += packet->rsize; + if (packet->rhqoff >= packet->maxcnt) + packet->rhqoff = 0; + + packet->numpkt++; + if (unlikely((packet->numpkt & (MAX_PKT_RECV - 1)) == 0)) { + if (thread) { + cond_resched(); + } else { + ret = RCV_PKT_LIMIT; + this_cpu_inc(*packet->rcd->dd->rcv_limit); + } + } + + packet->rhf_addr = (__le32 *)packet->rcd->rcvhdrq + packet->rhqoff + + packet->rcd->dd->rhf_offset; + packet->rhf = rhf_to_cpu(packet->rhf_addr); + + return ret; +} + static inline int process_rcv_packet(struct hfi1_packet *packet, int thread) { int ret = RCV_PKT_OK; @@ -721,8 +764,8 @@ static inline void process_rcv_qp_work(struct hfi1_packet *packet) */ list_for_each_entry_safe(qp, nqp, &rcd->qp_wait_list, rspwait) { list_del_init(&qp->rspwait); - if (qp->r_flags & HFI1_R_RSP_NAK) { - qp->r_flags &= ~HFI1_R_RSP_NAK; + if (qp->r_flags & HFI1_R_RSP_DEFERED_ACK) { + qp->r_flags &= ~HFI1_R_RSP_DEFERED_ACK; hfi1_send_rc_ack(rcd, qp, 0); } if (qp->r_flags & HFI1_R_RSP_SEND) { @@ -791,7 +834,6 @@ int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *rcd, int thread) while (last == RCV_PKT_OK) { last = process_rcv_packet(&packet, thread); - hdrqtail = get_rcvhdrtail(rcd); if (packet.rhqoff == hdrqtail) last = RCV_PKT_DONE; process_rcv_update(last, &packet); @@ -806,7 +848,7 @@ static inline void set_all_nodma_rtail(struct hfi1_devdata *dd) { int i; - for (i = 0; i < dd->first_user_ctxt; i++) + for (i = HFI1_CTRL_CTXT + 1; i < dd->first_user_ctxt; i++) dd->rcd[i]->do_interrupt = &handle_receive_interrupt_nodma_rtail; } @@ -815,7 +857,7 @@ static inline void set_all_dma_rtail(struct hfi1_devdata *dd) { int i; - for (i = 0; i < dd->first_user_ctxt; i++) + for (i = HFI1_CTRL_CTXT + 1; i < dd->first_user_ctxt; i++) dd->rcd[i]->do_interrupt = &handle_receive_interrupt_dma_rtail; } @@ -831,12 +873,16 @@ int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread) { struct hfi1_devdata *dd = rcd->dd; u32 hdrqtail; - int last = RCV_PKT_OK, needset = 1; + int needset, last = RCV_PKT_OK; struct hfi1_packet packet; + int skip_pkt = 0; + + /* Control context will always use the slow path interrupt handler */ + needset = (rcd->ctxt == HFI1_CTRL_CTXT) ? 0 : 1; init_packet(rcd, &packet); - if (!HFI1_CAP_IS_KSET(DMA_RTAIL)) { + if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) { u32 seq = rhf_rcv_seq(packet.rhf); if (seq != rcd->seq_cnt) { @@ -851,6 +897,17 @@ int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread) goto bail; } smp_rmb(); /* prevent speculative reads of dma'ed hdrq */ + + /* + * Control context can potentially receive an invalid + * rhf. Drop such packets. + */ + if (rcd->ctxt == HFI1_CTRL_CTXT) { + u32 seq = rhf_rcv_seq(packet.rhf); + + if (seq != rcd->seq_cnt) + skip_pkt = 1; + } } prescan_rxq(&packet); @@ -868,11 +925,14 @@ int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread) dd->rhf_offset; packet.rhf = rhf_to_cpu(packet.rhf_addr); + } else if (skip_pkt) { + last = skip_rcv_packet(&packet, thread); + skip_pkt = 0; } else { last = process_rcv_packet(&packet, thread); } - if (!HFI1_CAP_IS_KSET(DMA_RTAIL)) { + if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) { u32 seq = rhf_rcv_seq(packet.rhf); if (++rcd->seq_cnt > 13) @@ -888,6 +948,19 @@ int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread) } else { if (packet.rhqoff == hdrqtail) last = RCV_PKT_DONE; + /* + * Control context can potentially receive an invalid + * rhf. Drop such packets. + */ + if (rcd->ctxt == HFI1_CTRL_CTXT) { + u32 seq = rhf_rcv_seq(packet.rhf); + + if (++rcd->seq_cnt > 13) + rcd->seq_cnt = 1; + if (!last && (seq != rcd->seq_cnt)) + skip_pkt = 1; + } + if (needset) { dd_dev_info(dd, "Switching to DMA_RTAIL\n"); @@ -1163,20 +1236,20 @@ void handle_eflags(struct hfi1_packet *packet) struct hfi1_ctxtdata *rcd = packet->rcd; u32 rte = rhf_rcv_type_err(packet->rhf); - dd_dev_err(rcd->dd, - "receive context %d: rhf 0x%016llx, errs [ %s%s%s%s%s%s%s%s] rte 0x%x\n", - rcd->ctxt, packet->rhf, - packet->rhf & RHF_K_HDR_LEN_ERR ? "k_hdr_len " : "", - packet->rhf & RHF_DC_UNC_ERR ? "dc_unc " : "", - packet->rhf & RHF_DC_ERR ? "dc " : "", - packet->rhf & RHF_TID_ERR ? "tid " : "", - packet->rhf & RHF_LEN_ERR ? "len " : "", - packet->rhf & RHF_ECC_ERR ? "ecc " : "", - packet->rhf & RHF_VCRC_ERR ? "vcrc " : "", - packet->rhf & RHF_ICRC_ERR ? "icrc " : "", - rte); - rcv_hdrerr(rcd, rcd->ppd, packet); + if (rhf_err_flags(packet->rhf)) + dd_dev_err(rcd->dd, + "receive context %d: rhf 0x%016llx, errs [ %s%s%s%s%s%s%s%s] rte 0x%x\n", + rcd->ctxt, packet->rhf, + packet->rhf & RHF_K_HDR_LEN_ERR ? "k_hdr_len " : "", + packet->rhf & RHF_DC_UNC_ERR ? "dc_unc " : "", + packet->rhf & RHF_DC_ERR ? "dc " : "", + packet->rhf & RHF_TID_ERR ? "tid " : "", + packet->rhf & RHF_LEN_ERR ? "len " : "", + packet->rhf & RHF_ECC_ERR ? "ecc " : "", + packet->rhf & RHF_VCRC_ERR ? "vcrc " : "", + packet->rhf & RHF_ICRC_ERR ? "icrc " : "", + rte); } /* diff --git a/drivers/staging/rdma/hfi1/efivar.c b/drivers/staging/rdma/hfi1/efivar.c new file mode 100644 index 000000000000..7dc5bae220e0 --- /dev/null +++ b/drivers/staging/rdma/hfi1/efivar.c @@ -0,0 +1,169 @@ +/* + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2015 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * BSD LICENSE + * + * Copyright(c) 2015 Intel Corporation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * - Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "efivar.h" + +/* GUID for HFI1 variables in EFI */ +#define HFI1_EFIVAR_GUID EFI_GUID(0xc50a953e, 0xa8b2, 0x42a6, \ + 0xbf, 0x89, 0xd3, 0x33, 0xa6, 0xe9, 0xe6, 0xd4) +/* largest EFI data size we expect */ +#define EFI_DATA_SIZE 4096 + +/* + * Read the named EFI variable. Return the size of the actual data in *size + * and a kmalloc'ed buffer in *return_data. The caller must free the + * data. It is guaranteed that *return_data will be NULL and *size = 0 + * if this routine fails. + * + * Return 0 on success, -errno on failure. + */ +static int read_efi_var(const char *name, unsigned long *size, + void **return_data) +{ + efi_status_t status; + efi_char16_t *uni_name; + efi_guid_t guid; + unsigned long temp_size; + void *temp_buffer; + void *data; + int i; + int ret; + + /* set failure return values */ + *size = 0; + *return_data = NULL; + + if (!efi_enabled(EFI_RUNTIME_SERVICES)) + return -EOPNOTSUPP; + + uni_name = kzalloc(sizeof(efi_char16_t) * (strlen(name) + 1), + GFP_KERNEL); + temp_buffer = kzalloc(EFI_DATA_SIZE, GFP_KERNEL); + + if (!uni_name || !temp_buffer) { + ret = -ENOMEM; + goto fail; + } + + /* input: the size of the buffer */ + temp_size = EFI_DATA_SIZE; + + /* convert ASCII to unicode - it is a 1:1 mapping */ + for (i = 0; name[i]; i++) + uni_name[i] = name[i]; + + /* need a variable for our GUID */ + guid = HFI1_EFIVAR_GUID; + + /* call into EFI runtime services */ + status = efi.get_variable( + uni_name, + &guid, + NULL, + &temp_size, + temp_buffer); + + /* + * It would be nice to call efi_status_to_err() here, but that + * is in the EFIVAR_FS code and may not be compiled in. + * However, even that is insufficient since it does not cover + * EFI_BUFFER_TOO_SMALL which could be an important return. + * For now, just split out succces or not found. + */ + ret = status == EFI_SUCCESS ? 0 : + status == EFI_NOT_FOUND ? -ENOENT : + -EINVAL; + if (ret) + goto fail; + + /* + * We have successfully read the EFI variable into our + * temporary buffer. Now allocate a correctly sized + * buffer. + */ + data = kmalloc(temp_size, GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto fail; + } + + memcpy(data, temp_buffer, temp_size); + *size = temp_size; + *return_data = data; + +fail: + kfree(uni_name); + kfree(temp_buffer); + + return ret; +} + +/* + * Read an HFI1 EFI variable of the form: + * <PCIe address>-<kind> + * Return an kalloc'ed array and size of the data. + * + * Returns 0 on success, -errno on failure. + */ +int read_hfi1_efi_var(struct hfi1_devdata *dd, const char *kind, + unsigned long *size, void **return_data) +{ + char name[64]; + + /* create a common prefix */ + snprintf(name, sizeof(name), "%04x:%02x:%02x.%x-%s", + pci_domain_nr(dd->pcidev->bus), + dd->pcidev->bus->number, + PCI_SLOT(dd->pcidev->devfn), + PCI_FUNC(dd->pcidev->devfn), + kind); + + return read_efi_var(name, size, return_data); +} diff --git a/drivers/staging/rdma/hfi1/efivar.h b/drivers/staging/rdma/hfi1/efivar.h new file mode 100644 index 000000000000..070706225c51 --- /dev/null +++ b/drivers/staging/rdma/hfi1/efivar.h @@ -0,0 +1,60 @@ +/* + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2015 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * BSD LICENSE + * + * Copyright(c) 2015 Intel Corporation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * - Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _HFI1_EFIVAR_H +#define _HFI1_EFIVAR_H + +#include <linux/efi.h> + +#include "hfi.h" + +int read_hfi1_efi_var(struct hfi1_devdata *dd, const char *kind, + unsigned long *size, void **return_data); + +#endif /* _HFI1_EFIVAR_H */ diff --git a/drivers/staging/rdma/hfi1/eprom.c b/drivers/staging/rdma/hfi1/eprom.c index b61d3ae93ed1..fb620c97f592 100644 --- a/drivers/staging/rdma/hfi1/eprom.c +++ b/drivers/staging/rdma/hfi1/eprom.c @@ -53,17 +53,26 @@ #include "eprom.h" /* - * The EPROM is logically divided into two partitions: + * The EPROM is logically divided into three partitions: * partition 0: the first 128K, visible from PCI ROM BAR - * partition 1: the rest + * partition 1: 4K config file (sector size) + * partition 2: the rest */ #define P0_SIZE (128 * 1024) +#define P1_SIZE (4 * 1024) #define P1_START P0_SIZE +#define P2_START (P0_SIZE + P1_SIZE) + +/* erase sizes supported by the controller */ +#define SIZE_4KB (4 * 1024) +#define MASK_4KB (SIZE_4KB - 1) -/* largest erase size supported by the controller */ #define SIZE_32KB (32 * 1024) #define MASK_32KB (SIZE_32KB - 1) +#define SIZE_64KB (64 * 1024) +#define MASK_64KB (SIZE_64KB - 1) + /* controller page size, in bytes */ #define EP_PAGE_SIZE 256 #define EEP_PAGE_MASK (EP_PAGE_SIZE - 1) @@ -75,10 +84,12 @@ #define CMD_READ_DATA(addr) ((0x03 << CMD_SHIFT) | addr) #define CMD_READ_SR1 ((0x05 << CMD_SHIFT)) #define CMD_WRITE_ENABLE ((0x06 << CMD_SHIFT)) +#define CMD_SECTOR_ERASE_4KB(addr) ((0x20 << CMD_SHIFT) | addr) #define CMD_SECTOR_ERASE_32KB(addr) ((0x52 << CMD_SHIFT) | addr) #define CMD_CHIP_ERASE ((0x60 << CMD_SHIFT)) #define CMD_READ_MANUF_DEV_ID ((0x90 << CMD_SHIFT)) #define CMD_RELEASE_POWERDOWN_NOID ((0xab << CMD_SHIFT)) +#define CMD_SECTOR_ERASE_64KB(addr) ((0xd8 << CMD_SHIFT) | addr) /* controller interface speeds */ #define EP_SPEED_FULL 0x2 /* full speed */ @@ -188,28 +199,43 @@ static int erase_chip(struct hfi1_devdata *dd) } /* - * Erase a range using the 32KB erase command. + * Erase a range. */ -static int erase_32kb_range(struct hfi1_devdata *dd, u32 start, u32 end) +static int erase_range(struct hfi1_devdata *dd, u32 start, u32 len) { + u32 end = start + len; int ret = 0; if (end < start) return -EINVAL; - if ((start & MASK_32KB) || (end & MASK_32KB)) { + /* check the end points for the minimum erase */ + if ((start & MASK_4KB) || (end & MASK_4KB)) { dd_dev_err(dd, - "%s: non-aligned range (0x%x,0x%x) for a 32KB erase\n", + "%s: non-aligned range (0x%x,0x%x) for a 4KB erase\n", __func__, start, end); return -EINVAL; } write_enable(dd); - for (; start < end; start += SIZE_32KB) { + while (start < end) { write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_WRITE_ENABLE); - write_csr(dd, ASIC_EEP_ADDR_CMD, - CMD_SECTOR_ERASE_32KB(start)); + /* check in order of largest to smallest */ + if (((start & MASK_64KB) == 0) && (start + SIZE_64KB <= end)) { + write_csr(dd, ASIC_EEP_ADDR_CMD, + CMD_SECTOR_ERASE_64KB(start)); + start += SIZE_64KB; + } else if (((start & MASK_32KB) == 0) && + (start + SIZE_32KB <= end)) { + write_csr(dd, ASIC_EEP_ADDR_CMD, + CMD_SECTOR_ERASE_32KB(start)); + start += SIZE_32KB; + } else { /* 4KB will work */ + write_csr(dd, ASIC_EEP_ADDR_CMD, + CMD_SECTOR_ERASE_4KB(start)); + start += SIZE_4KB; + } ret = wait_for_not_busy(dd); if (ret) goto done; @@ -309,6 +335,18 @@ done: return ret; } +/* convert an range composite to a length, in bytes */ +static inline u32 extract_rlen(u32 composite) +{ + return (composite & 0xffff) * EP_PAGE_SIZE; +} + +/* convert an range composite to a start, in bytes */ +static inline u32 extract_rstart(u32 composite) +{ + return (composite >> 16) * EP_PAGE_SIZE; +} + /* * Perform the given operation on the EPROM. Called from user space. The * user credentials have already been checked. @@ -319,6 +357,8 @@ int handle_eprom_command(const struct hfi1_cmd *cmd) { struct hfi1_devdata *dd; u32 dev_id; + u32 rlen; /* range length */ + u32 rstart; /* range start */ int ret = 0; /* @@ -364,54 +404,29 @@ int handle_eprom_command(const struct hfi1_cmd *cmd) sizeof(u32))) ret = -EFAULT; break; + case HFI1_CMD_EP_ERASE_CHIP: ret = erase_chip(dd); break; - case HFI1_CMD_EP_ERASE_P0: - if (cmd->len != P0_SIZE) { - ret = -ERANGE; - break; - } - ret = erase_32kb_range(dd, 0, cmd->len); - break; - case HFI1_CMD_EP_ERASE_P1: - /* check for overflow */ - if (P1_START + cmd->len > ASIC_EEP_ADDR_CMD_EP_ADDR_MASK) { - ret = -ERANGE; - break; - } - ret = erase_32kb_range(dd, P1_START, P1_START + cmd->len); - break; - case HFI1_CMD_EP_READ_P0: - if (cmd->len != P0_SIZE) { - ret = -ERANGE; - break; - } - ret = read_length(dd, 0, cmd->len, cmd->addr); - break; - case HFI1_CMD_EP_READ_P1: - /* check for overflow */ - if (P1_START + cmd->len > ASIC_EEP_ADDR_CMD_EP_ADDR_MASK) { - ret = -ERANGE; - break; - } - ret = read_length(dd, P1_START, cmd->len, cmd->addr); + + case HFI1_CMD_EP_ERASE_RANGE: + rlen = extract_rlen(cmd->len); + rstart = extract_rstart(cmd->len); + ret = erase_range(dd, rstart, rlen); break; - case HFI1_CMD_EP_WRITE_P0: - if (cmd->len > P0_SIZE) { - ret = -ERANGE; - break; - } - ret = write_length(dd, 0, cmd->len, cmd->addr); + + case HFI1_CMD_EP_READ_RANGE: + rlen = extract_rlen(cmd->len); + rstart = extract_rstart(cmd->len); + ret = read_length(dd, rstart, rlen, cmd->addr); break; - case HFI1_CMD_EP_WRITE_P1: - /* check for overflow */ - if (P1_START + cmd->len > ASIC_EEP_ADDR_CMD_EP_ADDR_MASK) { - ret = -ERANGE; - break; - } - ret = write_length(dd, P1_START, cmd->len, cmd->addr); + + case HFI1_CMD_EP_WRITE_RANGE: + rlen = extract_rlen(cmd->len); + rstart = extract_rstart(cmd->len); + ret = write_length(dd, rstart, rlen, cmd->addr); break; + default: dd_dev_err(dd, "%s: unexpected command %d\n", __func__, cmd->type); diff --git a/drivers/staging/rdma/hfi1/file_ops.c b/drivers/staging/rdma/hfi1/file_ops.c index aae9826ec62b..d57d549052c8 100644 --- a/drivers/staging/rdma/hfi1/file_ops.c +++ b/drivers/staging/rdma/hfi1/file_ops.c @@ -47,20 +47,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ -#include <linux/pci.h> #include <linux/poll.h> #include <linux/cdev.h> -#include <linux/swap.h> #include <linux/vmalloc.h> -#include <linux/highmem.h> #include <linux/io.h> -#include <linux/jiffies.h> -#include <asm/pgtable.h> -#include <linux/delay.h> -#include <linux/export.h> -#include <linux/module.h> -#include <linux/cred.h> -#include <linux/uio.h> #include "hfi.h" #include "pio.h" @@ -68,6 +58,7 @@ #include "common.h" #include "trace.h" #include "user_sdma.h" +#include "user_exp_rcv.h" #include "eprom.h" #undef pr_fmt @@ -170,18 +161,6 @@ enum mmap_types { HFI1_MMAP_TOKEN_SET(SUBCTXT, subctxt) | \ HFI1_MMAP_TOKEN_SET(OFFSET, (offset_in_page(addr)))) -#define EXP_TID_SET(field, value) \ - (((value) & EXP_TID_TID##field##_MASK) << \ - EXP_TID_TID##field##_SHIFT) -#define EXP_TID_CLEAR(tid, field) { \ - (tid) &= ~(EXP_TID_TID##field##_MASK << \ - EXP_TID_TID##field##_SHIFT); \ - } -#define EXP_TID_RESET(tid, field, value) do { \ - EXP_TID_CLEAR(tid, field); \ - (tid) |= EXP_TID_SET(field, value); \ - } while (0) - #define dbg(fmt, ...) \ pr_info(fmt, ##__VA_ARGS__) @@ -204,7 +183,8 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data, size_t count, loff_t *offset) { const struct hfi1_cmd __user *ucmd; - struct hfi1_ctxtdata *uctxt = ctxt_fp(fp); + struct hfi1_filedata *fd = fp->private_data; + struct hfi1_ctxtdata *uctxt = fd->uctxt; struct hfi1_cmd cmd; struct hfi1_user_info uinfo; struct hfi1_tid_info tinfo; @@ -254,12 +234,9 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data, break; case HFI1_CMD_EP_INFO: case HFI1_CMD_EP_ERASE_CHIP: - case HFI1_CMD_EP_ERASE_P0: - case HFI1_CMD_EP_ERASE_P1: - case HFI1_CMD_EP_READ_P0: - case HFI1_CMD_EP_READ_P1: - case HFI1_CMD_EP_WRITE_P0: - case HFI1_CMD_EP_WRITE_P1: + case HFI1_CMD_EP_ERASE_RANGE: + case HFI1_CMD_EP_READ_RANGE: + case HFI1_CMD_EP_WRITE_RANGE: uctxt_required = 0; /* assigned user context not required */ must_be_root = 1; /* validate user */ copy = 0; @@ -338,17 +315,17 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data, ret = exp_tid_free(fp, &tinfo); break; case HFI1_CMD_RECV_CTRL: - ret = manage_rcvq(uctxt, subctxt_fp(fp), (int)user_val); + ret = manage_rcvq(uctxt, fd->subctxt, (int)user_val); break; case HFI1_CMD_POLL_TYPE: uctxt->poll_type = (typeof(uctxt->poll_type))user_val; break; case HFI1_CMD_ACK_EVENT: - ret = user_event_ack(uctxt, subctxt_fp(fp), user_val); + ret = user_event_ack(uctxt, fd->subctxt, user_val); break; case HFI1_CMD_SET_PKEY: if (HFI1_CAP_IS_USET(PKEY_CHECK)) - ret = set_ctxt_pkey(uctxt, subctxt_fp(fp), user_val); + ret = set_ctxt_pkey(uctxt, fd->subctxt, user_val); else ret = -EPERM; break; @@ -413,12 +390,9 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data, } case HFI1_CMD_EP_INFO: case HFI1_CMD_EP_ERASE_CHIP: - case HFI1_CMD_EP_ERASE_P0: - case HFI1_CMD_EP_ERASE_P1: - case HFI1_CMD_EP_READ_P0: - case HFI1_CMD_EP_READ_P1: - case HFI1_CMD_EP_WRITE_P0: - case HFI1_CMD_EP_WRITE_P1: + case HFI1_CMD_EP_ERASE_RANGE: + case HFI1_CMD_EP_READ_RANGE: + case HFI1_CMD_EP_WRITE_RANGE: ret = handle_eprom_command(&cmd); break; } @@ -431,13 +405,13 @@ bail: static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from) { - struct hfi1_user_sdma_pkt_q *pq; - struct hfi1_user_sdma_comp_q *cq; + struct hfi1_filedata *fd = kiocb->ki_filp->private_data; + struct hfi1_user_sdma_pkt_q *pq = fd->pq; + struct hfi1_user_sdma_comp_q *cq = fd->cq; int ret = 0, done = 0, reqs = 0; unsigned long dim = from->nr_segs; - if (!user_sdma_comp_fp(kiocb->ki_filp) || - !user_sdma_pkt_fp(kiocb->ki_filp)) { + if (!cq || !pq) { ret = -EIO; goto done; } @@ -448,10 +422,7 @@ static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from) } hfi1_cdbg(SDMA, "SDMA request from %u:%u (%lu)", - ctxt_fp(kiocb->ki_filp)->ctxt, subctxt_fp(kiocb->ki_filp), - dim); - pq = user_sdma_pkt_fp(kiocb->ki_filp); - cq = user_sdma_comp_fp(kiocb->ki_filp); + fd->uctxt->ctxt, fd->subctxt, dim); if (atomic_read(&pq->n_reqs) == pq->n_max_reqs) { ret = -ENOSPC; @@ -476,7 +447,8 @@ done: static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) { - struct hfi1_ctxtdata *uctxt; + struct hfi1_filedata *fd = fp->private_data; + struct hfi1_ctxtdata *uctxt = fd->uctxt; struct hfi1_devdata *dd; unsigned long flags, pfn; u64 token = vma->vm_pgoff << PAGE_SHIFT, @@ -486,7 +458,6 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) int ret = 0; u16 ctxt; - uctxt = ctxt_fp(fp); if (!is_valid_mmap(token) || !uctxt || !(vma->vm_flags & VM_SHARED)) { ret = -EINVAL; @@ -496,7 +467,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) ctxt = HFI1_MMAP_TOKEN_GET(CTXT, token); subctxt = HFI1_MMAP_TOKEN_GET(SUBCTXT, token); type = HFI1_MMAP_TOKEN_GET(TYPE, token); - if (ctxt != uctxt->ctxt || subctxt != subctxt_fp(fp)) { + if (ctxt != uctxt->ctxt || subctxt != fd->subctxt) { ret = -EINVAL; goto done; } @@ -660,13 +631,12 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) vmf = 1; break; case SDMA_COMP: { - struct hfi1_user_sdma_comp_q *cq; + struct hfi1_user_sdma_comp_q *cq = fd->cq; - if (!user_sdma_comp_fp(fp)) { + if (!cq) { ret = -EFAULT; goto done; } - cq = user_sdma_comp_fp(fp); memaddr = (u64)cq->comps; memlen = ALIGN(sizeof(*cq->comps) * cq->nentries, PAGE_SIZE); flags |= VM_IO | VM_DONTEXPAND; @@ -680,16 +650,16 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) if ((vma->vm_end - vma->vm_start) != memlen) { hfi1_cdbg(PROC, "%u:%u Memory size mismatch %lu:%lu", - uctxt->ctxt, subctxt_fp(fp), + uctxt->ctxt, fd->subctxt, (vma->vm_end - vma->vm_start), memlen); ret = -EINVAL; goto done; } vma->vm_flags = flags; - dd_dev_info(dd, - "%s: %u:%u type:%u io/vf:%d/%d, addr:0x%llx, len:%lu(%lu), flags:0x%lx\n", - __func__, ctxt, subctxt, type, mapio, vmf, memaddr, memlen, + hfi1_cdbg(PROC, + "%u:%u type:%u io/vf:%d/%d, addr:0x%llx, len:%lu(%lu), flags:0x%lx\n", + ctxt, subctxt, type, mapio, vmf, memaddr, memlen, vma->vm_end - vma->vm_start, vma->vm_flags); pfn = (unsigned long)(memaddr >> PAGE_SHIFT); if (vmf) { @@ -730,7 +700,7 @@ static unsigned int hfi1_poll(struct file *fp, struct poll_table_struct *pt) struct hfi1_ctxtdata *uctxt; unsigned pollflag; - uctxt = ctxt_fp(fp); + uctxt = ((struct hfi1_filedata *)fp->private_data)->uctxt; if (!uctxt) pollflag = POLLERR; else if (uctxt->poll_type == HFI1_POLL_TYPE_URGENT) @@ -761,8 +731,7 @@ static int hfi1_file_close(struct inode *inode, struct file *fp) flush_wc(); /* drain user sdma queue */ - if (fdata->pq) - hfi1_user_sdma_free_queues(fdata); + hfi1_user_sdma_free_queues(fdata); /* * Clear any left over, unhandled events so the next process that @@ -874,6 +843,14 @@ done: return ret; } +/* return true if the device available for general use */ +static int usable_device(struct hfi1_devdata *dd) +{ + struct hfi1_pportdata *ppd = dd->pport; + + return driver_lstate(ppd) == IB_PORT_ACTIVE; +} + static int get_user_context(struct file *fp, struct hfi1_user_info *uinfo, int devno, unsigned alg) { @@ -903,7 +880,11 @@ static int get_user_context(struct file *fp, struct hfi1_user_info *uinfo, for (dev = 0; dev < devmax; dev++) { pdd = hfi1_lookup(dev); - if (pdd && pdd->freectxts && + if (!pdd) + continue; + if (!usable_device(pdd)) + continue; + if (pdd->freectxts && pdd->freectxts > free) { dd = pdd; free = pdd->freectxts; @@ -912,7 +893,11 @@ static int get_user_context(struct file *fp, struct hfi1_user_info *uinfo, } else { for (dev = 0; dev < devmax; dev++) { pdd = hfi1_lookup(dev); - if (pdd && pdd->freectxts) { + if (!pdd) + continue; + if (!usable_device(pdd)) + continue; + if (pdd->freectxts) { dd = pdd; break; } @@ -930,13 +915,13 @@ static int find_shared_ctxt(struct file *fp, { int devmax, ndev, i; int ret = 0; + struct hfi1_filedata *fd = fp->private_data; devmax = hfi1_count_units(NULL, NULL); for (ndev = 0; ndev < devmax; ndev++) { struct hfi1_devdata *dd = hfi1_lookup(ndev); - /* device portion of usable() */ if (!(dd && (dd->flags & HFI1_PRESENT) && dd->kregbase)) continue; for (i = dd->first_user_ctxt; i < dd->num_rcv_contexts; i++) { @@ -959,10 +944,10 @@ static int find_shared_ctxt(struct file *fp, ret = -EINVAL; goto done; } - ctxt_fp(fp) = uctxt; - subctxt_fp(fp) = uctxt->cnt++; - uctxt->subpid[subctxt_fp(fp)] = current->pid; - uctxt->active_slaves |= 1 << subctxt_fp(fp); + fd->uctxt = uctxt; + fd->subctxt = uctxt->cnt++; + uctxt->subpid[fd->subctxt] = current->pid; + uctxt->active_slaves |= 1 << fd->subctxt; ret = 1; goto done; } @@ -975,6 +960,7 @@ done: static int allocate_ctxt(struct file *fp, struct hfi1_devdata *dd, struct hfi1_user_info *uinfo) { + struct hfi1_filedata *fd = fp->private_data; struct hfi1_ctxtdata *uctxt; unsigned ctxt; int ret; @@ -1011,8 +997,8 @@ static int allocate_ctxt(struct file *fp, struct hfi1_devdata *dd, if (!uctxt->sc) return -ENOMEM; - dbg("allocated send context %u(%u)\n", uctxt->sc->sw_index, - uctxt->sc->hw_context); + hfi1_cdbg(PROC, "allocated send context %u(%u)\n", uctxt->sc->sw_index, + uctxt->sc->hw_context); ret = sc_enable(uctxt->sc); if (ret) return ret; @@ -1022,7 +1008,7 @@ static int allocate_ctxt(struct file *fp, struct hfi1_devdata *dd, * This has to be done here so the rest of the sub-contexts find the * proper master. */ - if (uinfo->subctxt_cnt && !subctxt_fp(fp)) { + if (uinfo->subctxt_cnt && !fd->subctxt) { ret = init_subctxts(uctxt, uinfo); /* * On error, we don't need to disable and de-allocate the @@ -1042,7 +1028,7 @@ static int allocate_ctxt(struct file *fp, struct hfi1_devdata *dd, spin_lock_init(&uctxt->sdma_qlock); hfi1_stats.sps_ctxts++; dd->freectxts--; - ctxt_fp(fp) = uctxt; + fd->uctxt = uctxt; return 0; } @@ -1106,7 +1092,8 @@ static int user_init(struct file *fp) { int ret; unsigned int rcvctrl_ops = 0; - struct hfi1_ctxtdata *uctxt = ctxt_fp(fp); + struct hfi1_filedata *fd = fp->private_data; + struct hfi1_ctxtdata *uctxt = fd->uctxt; /* make sure that the context has already been setup */ if (!test_bit(HFI1_CTXT_SETUP_DONE, &uctxt->event_flags)) { @@ -1118,7 +1105,7 @@ static int user_init(struct file *fp) * Subctxts don't need to initialize anything since master * has done it. */ - if (subctxt_fp(fp)) { + if (fd->subctxt) { ret = wait_event_interruptible(uctxt->wait, !test_bit(HFI1_CTXT_MASTER_UNINIT, &uctxt->event_flags)); @@ -1178,8 +1165,8 @@ done: static int get_ctxt_info(struct file *fp, void __user *ubase, __u32 len) { struct hfi1_ctxt_info cinfo; - struct hfi1_ctxtdata *uctxt = ctxt_fp(fp); struct hfi1_filedata *fd = fp->private_data; + struct hfi1_ctxtdata *uctxt = fd->uctxt; int ret = 0; memset(&cinfo, 0, sizeof(cinfo)); @@ -1189,7 +1176,7 @@ static int get_ctxt_info(struct file *fp, void __user *ubase, __u32 len) cinfo.num_active = hfi1_count_active_units(); cinfo.unit = uctxt->dd->unit; cinfo.ctxt = uctxt->ctxt; - cinfo.subctxt = subctxt_fp(fp); + cinfo.subctxt = fd->subctxt; cinfo.rcvtids = roundup(uctxt->egrbufs.alloced, uctxt->dd->rcv_entries.group_size) + uctxt->expected_count; @@ -1201,10 +1188,10 @@ static int get_ctxt_info(struct file *fp, void __user *ubase, __u32 len) cinfo.egrtids = uctxt->egrbufs.alloced; cinfo.rcvhdrq_cnt = uctxt->rcvhdrq_cnt; cinfo.rcvhdrq_entsize = uctxt->rcvhdrqentsize << 2; - cinfo.sdma_ring_size = user_sdma_comp_fp(fp)->nentries; + cinfo.sdma_ring_size = fd->cq->nentries; cinfo.rcvegr_size = uctxt->egrbufs.rcvtid_size; - trace_hfi1_ctxt_info(uctxt->dd, uctxt->ctxt, subctxt_fp(fp), cinfo); + trace_hfi1_ctxt_info(uctxt->dd, uctxt->ctxt, fd->subctxt, cinfo); if (copy_to_user(ubase, &cinfo, sizeof(cinfo))) ret = -EFAULT; done: @@ -1213,7 +1200,8 @@ done: static int setup_ctxt(struct file *fp) { - struct hfi1_ctxtdata *uctxt = ctxt_fp(fp); + struct hfi1_filedata *fd = fp->private_data; + struct hfi1_ctxtdata *uctxt = fd->uctxt; struct hfi1_devdata *dd = uctxt->dd; int ret = 0; @@ -1222,7 +1210,7 @@ static int setup_ctxt(struct file *fp) * programming of eager buffers. This is done if context sharing * is not requested or by the master process. */ - if (!uctxt->subctxt_cnt || !subctxt_fp(fp)) { + if (!uctxt->subctxt_cnt || !fd->subctxt) { ret = hfi1_init_ctxt(uctxt->sc); if (ret) goto done; @@ -1234,7 +1222,7 @@ static int setup_ctxt(struct file *fp) ret = hfi1_setup_eagerbufs(uctxt); if (ret) goto done; - if (uctxt->subctxt_cnt && !subctxt_fp(fp)) { + if (uctxt->subctxt_cnt && !fd->subctxt) { ret = setup_subctxt(uctxt); if (ret) goto done; @@ -1277,7 +1265,7 @@ static int setup_ctxt(struct file *fp) uctxt->tidusemap[uctxt->tidmapcnt - 1] = ~((1ULL << (uctxt->numtidgroups % BITS_PER_LONG)) - 1); - trace_hfi1_exp_tid_map(uctxt->ctxt, subctxt_fp(fp), 0, + trace_hfi1_exp_tid_map(uctxt->ctxt, fd->subctxt, 0, uctxt->tidusemap, uctxt->tidmapcnt); } ret = hfi1_user_sdma_alloc_queues(uctxt, fp); @@ -1292,7 +1280,8 @@ done: static int get_base_info(struct file *fp, void __user *ubase, __u32 len) { struct hfi1_base_info binfo; - struct hfi1_ctxtdata *uctxt = ctxt_fp(fp); + struct hfi1_filedata *fd = fp->private_data; + struct hfi1_ctxtdata *uctxt = fd->uctxt; struct hfi1_devdata *dd = uctxt->dd; ssize_t sz; unsigned offset; @@ -1314,50 +1303,50 @@ static int get_base_info(struct file *fp, void __user *ubase, __u32 len) offset = ((u64)uctxt->sc->hw_free - (u64)dd->cr_base[uctxt->numa_id].va) % PAGE_SIZE; binfo.sc_credits_addr = HFI1_MMAP_TOKEN(PIO_CRED, uctxt->ctxt, - subctxt_fp(fp), offset); + fd->subctxt, offset); binfo.pio_bufbase = HFI1_MMAP_TOKEN(PIO_BUFS, uctxt->ctxt, - subctxt_fp(fp), + fd->subctxt, uctxt->sc->base_addr); binfo.pio_bufbase_sop = HFI1_MMAP_TOKEN(PIO_BUFS_SOP, uctxt->ctxt, - subctxt_fp(fp), + fd->subctxt, uctxt->sc->base_addr); binfo.rcvhdr_bufbase = HFI1_MMAP_TOKEN(RCV_HDRQ, uctxt->ctxt, - subctxt_fp(fp), + fd->subctxt, uctxt->rcvhdrq); binfo.rcvegr_bufbase = HFI1_MMAP_TOKEN(RCV_EGRBUF, uctxt->ctxt, - subctxt_fp(fp), + fd->subctxt, uctxt->egrbufs.rcvtids[0].phys); binfo.sdma_comp_bufbase = HFI1_MMAP_TOKEN(SDMA_COMP, uctxt->ctxt, - subctxt_fp(fp), 0); + fd->subctxt, 0); /* * user regs are at * (RXE_PER_CONTEXT_USER + (ctxt * RXE_PER_CONTEXT_SIZE)) */ binfo.user_regbase = HFI1_MMAP_TOKEN(UREGS, uctxt->ctxt, - subctxt_fp(fp), 0); + fd->subctxt, 0); offset = offset_in_page((((uctxt->ctxt - dd->first_user_ctxt) * - HFI1_MAX_SHARED_CTXTS) + subctxt_fp(fp)) * + HFI1_MAX_SHARED_CTXTS) + fd->subctxt) * sizeof(*dd->events)); binfo.events_bufbase = HFI1_MMAP_TOKEN(EVENTS, uctxt->ctxt, - subctxt_fp(fp), + fd->subctxt, offset); binfo.status_bufbase = HFI1_MMAP_TOKEN(STATUS, uctxt->ctxt, - subctxt_fp(fp), + fd->subctxt, dd->status); if (HFI1_CAP_IS_USET(DMA_RTAIL)) binfo.rcvhdrtail_base = HFI1_MMAP_TOKEN(RTAIL, uctxt->ctxt, - subctxt_fp(fp), 0); + fd->subctxt, 0); if (uctxt->subctxt_cnt) { binfo.subctxt_uregbase = HFI1_MMAP_TOKEN(SUBCTXT_UREGS, uctxt->ctxt, - subctxt_fp(fp), 0); + fd->subctxt, 0); binfo.subctxt_rcvhdrbuf = HFI1_MMAP_TOKEN(SUBCTXT_RCV_HDRQ, uctxt->ctxt, - subctxt_fp(fp), 0); + fd->subctxt, 0); binfo.subctxt_rcvegrbuf = HFI1_MMAP_TOKEN(SUBCTXT_EGRBUF, uctxt->ctxt, - subctxt_fp(fp), 0); + fd->subctxt, 0); } sz = (len < sizeof(binfo)) ? len : sizeof(binfo); if (copy_to_user(ubase, &binfo, sz)) @@ -1368,7 +1357,8 @@ static int get_base_info(struct file *fp, void __user *ubase, __u32 len) static unsigned int poll_urgent(struct file *fp, struct poll_table_struct *pt) { - struct hfi1_ctxtdata *uctxt = ctxt_fp(fp); + struct hfi1_filedata *fd = fp->private_data; + struct hfi1_ctxtdata *uctxt = fd->uctxt; struct hfi1_devdata *dd = uctxt->dd; unsigned pollflag; @@ -1390,7 +1380,8 @@ static unsigned int poll_urgent(struct file *fp, static unsigned int poll_next(struct file *fp, struct poll_table_struct *pt) { - struct hfi1_ctxtdata *uctxt = ctxt_fp(fp); + struct hfi1_filedata *fd = fp->private_data; + struct hfi1_ctxtdata *uctxt = fd->uctxt; struct hfi1_devdata *dd = uctxt->dd; unsigned pollflag; @@ -1562,7 +1553,8 @@ static inline unsigned num_free_groups(unsigned long map, u16 *start) static int exp_tid_setup(struct file *fp, struct hfi1_tid_info *tinfo) { int ret = 0; - struct hfi1_ctxtdata *uctxt = ctxt_fp(fp); + struct hfi1_filedata *fd = fp->private_data; + struct hfi1_ctxtdata *uctxt = fd->uctxt; struct hfi1_devdata *dd = uctxt->dd; unsigned tid, mapped = 0, npages, ngroups, exp_groups, tidpairs = uctxt->expected_count / 2; @@ -1671,8 +1663,8 @@ static int exp_tid_setup(struct file *fp, struct hfi1_tid_info *tinfo) * Now that we know how many free RcvArray entries we have, * we can pin that many user pages. */ - ret = hfi1_get_user_pages(vaddr + (mapped * PAGE_SIZE), - pinned, pages); + ret = hfi1_acquire_user_pages(vaddr + (mapped * PAGE_SIZE), + pinned, true, pages); if (ret) { /* * We can't continue because the pages array won't be @@ -1718,7 +1710,7 @@ static int exp_tid_setup(struct file *fp, struct hfi1_tid_info *tinfo) pages[pmapped], 0, tidsize, PCI_DMA_FROMDEVICE); trace_hfi1_exp_rcv_set(uctxt->ctxt, - subctxt_fp(fp), + fd->subctxt, tid, vaddr, phys[pmapped], pages[pmapped]); @@ -1763,7 +1755,7 @@ static int exp_tid_setup(struct file *fp, struct hfi1_tid_info *tinfo) (((useidx & 0xffffff) << 16) | ((bitidx + bits_used) & 0xffffff))); } - trace_hfi1_exp_tid_map(uctxt->ctxt, subctxt_fp(fp), 0, uctxt->tidusemap, + trace_hfi1_exp_tid_map(uctxt->ctxt, fd->subctxt, 0, uctxt->tidusemap, uctxt->tidmapcnt); done: @@ -1792,7 +1784,8 @@ bail: static int exp_tid_free(struct file *fp, struct hfi1_tid_info *tinfo) { - struct hfi1_ctxtdata *uctxt = ctxt_fp(fp); + struct hfi1_filedata *fd = fp->private_data; + struct hfi1_ctxtdata *uctxt = fd->uctxt; struct hfi1_devdata *dd = uctxt->dd; unsigned long tidmap[uctxt->tidmapcnt]; struct page **pages; @@ -1828,7 +1821,7 @@ static int exp_tid_free(struct file *fp, struct hfi1_tid_info *tinfo) hfi1_put_tid(dd, tid, PT_INVALID, 0, 0); trace_hfi1_exp_rcv_free(uctxt->ctxt, - subctxt_fp(fp), + fd->subctxt, tid, phys[i], pages[i]); pci_unmap_page(dd->pcidev, phys[i], @@ -1840,12 +1833,12 @@ static int exp_tid_free(struct file *fp, struct hfi1_tid_info *tinfo) } } flush_wc(); - hfi1_release_user_pages(pshadow, pcount); + hfi1_release_user_pages(pshadow, pcount, true); clear_bit(bitidx, &uctxt->tidusemap[idx]); map &= ~(1ULL<<bitidx); } } - trace_hfi1_exp_tid_map(uctxt->ctxt, subctxt_fp(fp), 1, uctxt->tidusemap, + trace_hfi1_exp_tid_map(uctxt->ctxt, fd->subctxt, 1, uctxt->tidusemap, uctxt->tidmapcnt); done: return ret; @@ -1869,7 +1862,7 @@ static void unlock_exp_tids(struct hfi1_ctxtdata *uctxt) uctxt->physshadow[tid] = 0; uctxt->tid_pg_list[tid] = NULL; pci_unmap_page(dd->pcidev, phys, PAGE_SIZE, PCI_DMA_FROMDEVICE); - hfi1_release_user_pages(&p, 1); + hfi1_release_user_pages(&p, 1, true); } } diff --git a/drivers/staging/rdma/hfi1/firmware.c b/drivers/staging/rdma/hfi1/firmware.c index b4bdcf341aac..28ae42faa018 100644 --- a/drivers/staging/rdma/hfi1/firmware.c +++ b/drivers/staging/rdma/hfi1/firmware.c @@ -68,6 +68,10 @@ #define DEFAULT_FW_SBUS_NAME "hfi1_sbus.fw" #define DEFAULT_FW_PCIE_NAME "hfi1_pcie.fw" #define DEFAULT_PLATFORM_CONFIG_NAME "hfi1_platform.dat" +#define ALT_FW_8051_NAME_ASIC "hfi1_dc8051_d.fw" +#define ALT_FW_FABRIC_NAME "hfi1_fabric_d.fw" +#define ALT_FW_SBUS_NAME "hfi1_sbus_d.fw" +#define ALT_FW_PCIE_NAME "hfi1_pcie_d.fw" static uint fw_8051_load = 1; static uint fw_fabric_serdes_load = 1; @@ -158,7 +162,8 @@ struct firmware_details { static DEFINE_MUTEX(fw_mutex); enum fw_state { FW_EMPTY, - FW_ACQUIRED, + FW_TRY, + FW_FINAL, FW_ERR }; static enum fw_state fw_state = FW_EMPTY; @@ -428,8 +433,8 @@ static int obtain_one_firmware(struct hfi1_devdata *dd, const char *name, ret = request_firmware(&fdet->fw, name, &dd->pcidev->dev); if (ret) { - dd_dev_err(dd, "cannot load firmware \"%s\", err %d\n", - name, ret); + dd_dev_err(dd, "cannot find firmware \"%s\", err %d\n", + name, ret); return ret; } @@ -539,28 +544,53 @@ done: static void dispose_one_firmware(struct firmware_details *fdet) { release_firmware(fdet->fw); - fdet->fw = NULL; + /* erase all previous information */ + memset(fdet, 0, sizeof(*fdet)); } /* - * Called by all HFIs when loading their firmware - i.e. device probe time. - * The first one will do the actual firmware load. Use a mutex to resolve - * any possible race condition. + * Obtain the 4 firmwares from the OS. All must be obtained at once or not + * at all. If called with the firmware state in FW_TRY, use alternate names. + * On exit, this routine will have set the firmware state to one of FW_TRY, + * FW_FINAL, or FW_ERR. * - * The call to this routine cannot be moved to driver load because the kernel - * call request_firmware() requires a device which is only available after - * the first device probe. + * Must be holding fw_mutex. */ -static int obtain_firmware(struct hfi1_devdata *dd) +static void __obtain_firmware(struct hfi1_devdata *dd) { int err = 0; - mutex_lock(&fw_mutex); - if (fw_state == FW_ACQUIRED) { - goto done; /* already acquired */ - } else if (fw_state == FW_ERR) { - err = fw_err; - goto done; /* already tried and failed */ + if (fw_state == FW_FINAL) /* nothing more to obtain */ + return; + if (fw_state == FW_ERR) /* already in error */ + return; + + /* fw_state is FW_EMPTY or FW_TRY */ +retry: + if (fw_state == FW_TRY) { + /* + * We tried the original and it failed. Move to the + * alternate. + */ + dd_dev_info(dd, "using alternate firmware names\n"); + /* + * Let others run. Some systems, when missing firmware, does + * something that holds for 30 seconds. If we do that twice + * in a row it triggers task blocked warning. + */ + cond_resched(); + if (fw_8051_load) + dispose_one_firmware(&fw_8051); + if (fw_fabric_serdes_load) + dispose_one_firmware(&fw_fabric); + if (fw_sbus_load) + dispose_one_firmware(&fw_sbus); + if (fw_pcie_serdes_load) + dispose_one_firmware(&fw_pcie); + fw_8051_name = ALT_FW_8051_NAME_ASIC; + fw_fabric_serdes_name = ALT_FW_FABRIC_NAME; + fw_sbus_name = ALT_FW_SBUS_NAME; + fw_pcie_serdes_name = ALT_FW_PCIE_NAME; } if (fw_8051_load) { @@ -588,27 +618,82 @@ static int obtain_firmware(struct hfi1_devdata *dd) goto done; } +done: + if (err) { + /* oops, had problems obtaining a firmware */ + if (fw_state == FW_EMPTY) { + /* retry with alternate */ + fw_state = FW_TRY; + goto retry; + } + fw_state = FW_ERR; + fw_err = -ENOENT; + } else { + /* success */ + if (fw_state == FW_EMPTY) + fw_state = FW_TRY; /* may retry later */ + else + fw_state = FW_FINAL; /* cannot try again */ + } +} + +/* + * Called by all HFIs when loading their firmware - i.e. device probe time. + * The first one will do the actual firmware load. Use a mutex to resolve + * any possible race condition. + * + * The call to this routine cannot be moved to driver load because the kernel + * call request_firmware() requires a device which is only available after + * the first device probe. + */ +static int obtain_firmware(struct hfi1_devdata *dd) +{ + unsigned long timeout; + int err = 0; + + mutex_lock(&fw_mutex); + + /* 40s delay due to long delay on missing firmware on some systems */ + timeout = jiffies + msecs_to_jiffies(40000); + while (fw_state == FW_TRY) { + /* + * Another device is trying the firmware. Wait until it + * decides what works (or not). + */ + if (time_after(jiffies, timeout)) { + /* waited too long */ + dd_dev_err(dd, "Timeout waiting for firmware try"); + fw_state = FW_ERR; + fw_err = -ETIMEDOUT; + break; + } + mutex_unlock(&fw_mutex); + msleep(20); /* arbitrary delay */ + mutex_lock(&fw_mutex); + } + /* not in FW_TRY state */ + + if (fw_state == FW_FINAL) + goto done; /* already acquired */ + else if (fw_state == FW_ERR) + goto done; /* already tried and failed */ + /* fw_state is FW_EMPTY */ + + /* set fw_state to FW_TRY, FW_FINAL, or FW_ERR, and fw_err */ + __obtain_firmware(dd); + if (platform_config_load) { platform_config = NULL; err = request_firmware(&platform_config, platform_config_name, &dd->pcidev->dev); - if (err) { - err = 0; + if (err) platform_config = NULL; - } } - /* success */ - fw_state = FW_ACQUIRED; - done: - if (err) { - fw_err = err; - fw_state = FW_ERR; - } mutex_unlock(&fw_mutex); - return err; + return fw_err; } /* @@ -638,6 +723,38 @@ void dispose_firmware(void) } /* + * Called with the result of a firmware download. + * + * Return 1 to retry loading the firmware, 0 to stop. + */ +static int retry_firmware(struct hfi1_devdata *dd, int load_result) +{ + int retry; + + mutex_lock(&fw_mutex); + + if (load_result == 0) { + /* + * The load succeeded, so expect all others to do the same. + * Do not retry again. + */ + if (fw_state == FW_TRY) + fw_state = FW_FINAL; + retry = 0; /* do NOT retry */ + } else if (fw_state == FW_TRY) { + /* load failed, obtain alternate firmware */ + __obtain_firmware(dd); + retry = (fw_state == FW_FINAL); + } else { + /* else in FW_FINAL or FW_ERR, no retry in either case */ + retry = 0; + } + + mutex_unlock(&fw_mutex); + return retry; +} + +/* * Write a block of data to a given array CSR. All calls will be in * multiples of 8 bytes. */ @@ -951,7 +1068,7 @@ void sbus_request(struct hfi1_devdata *dd, static void turn_off_spicos(struct hfi1_devdata *dd, int flags) { /* only needed on A0 */ - if (!is_a0(dd)) + if (!is_ax(dd)) return; dd_dev_info(dd, "Turning off spicos:%s%s\n", @@ -1248,7 +1365,9 @@ int load_firmware(struct hfi1_devdata *dd) fabric_serdes_addrs[dd->hfi1_id], NUM_FABRIC_SERDES); turn_off_spicos(dd, SPICO_FABRIC); - ret = load_fabric_serdes_firmware(dd, &fw_fabric); + do { + ret = load_fabric_serdes_firmware(dd, &fw_fabric); + } while (retry_firmware(dd, ret)); clear_sbus_fast_mode(dd); release_hw_mutex(dd); @@ -1257,7 +1376,9 @@ int load_firmware(struct hfi1_devdata *dd) } if (fw_8051_load) { - ret = load_8051_firmware(dd, &fw_8051); + do { + ret = load_8051_firmware(dd, &fw_8051); + } while (retry_firmware(dd, ret)); if (ret) return ret; } @@ -1568,9 +1689,11 @@ int load_pcie_firmware(struct hfi1_devdata *dd) /* both firmware loads below use the SBus */ set_sbus_fast_mode(dd); - if (fw_sbus_load && (dd->flags & HFI1_DO_INIT_ASIC)) { + if (fw_sbus_load) { turn_off_spicos(dd, SPICO_SBUS); - ret = load_sbus_firmware(dd, &fw_sbus); + do { + ret = load_sbus_firmware(dd, &fw_sbus); + } while (retry_firmware(dd, ret)); if (ret) goto done; } @@ -1581,7 +1704,9 @@ int load_pcie_firmware(struct hfi1_devdata *dd) pcie_serdes_broadcast[dd->hfi1_id], pcie_serdes_addrs[dd->hfi1_id], NUM_PCIE_SERDES); - ret = load_pcie_serdes_firmware(dd, &fw_pcie); + do { + ret = load_pcie_serdes_firmware(dd, &fw_pcie); + } while (retry_firmware(dd, ret)); if (ret) goto done; } diff --git a/drivers/staging/rdma/hfi1/hfi.h b/drivers/staging/rdma/hfi1/hfi.h index 190f7a2f6773..2611bb2e764d 100644 --- a/drivers/staging/rdma/hfi1/hfi.h +++ b/drivers/staging/rdma/hfi1/hfi.h @@ -100,6 +100,26 @@ extern unsigned long hfi1_cap_mask; HFI1_CAP_MISC_MASK) /* + * Control context is always 0 and handles the error packets. + * It also handles the VL15 and multicast packets. + */ +#define HFI1_CTRL_CTXT 0 + +/* + * Driver context will store software counters for each of the events + * associated with these status registers + */ +#define NUM_CCE_ERR_STATUS_COUNTERS 41 +#define NUM_RCV_ERR_STATUS_COUNTERS 64 +#define NUM_MISC_ERR_STATUS_COUNTERS 13 +#define NUM_SEND_PIO_ERR_STATUS_COUNTERS 36 +#define NUM_SEND_DMA_ERR_STATUS_COUNTERS 4 +#define NUM_SEND_EGRESS_ERR_STATUS_COUNTERS 64 +#define NUM_SEND_ERR_STATUS_COUNTERS 3 +#define NUM_SEND_CTXT_ERR_STATUS_COUNTERS 5 +#define NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS 24 + +/* * per driver stats, either not device nor port-specific, or * summed over all of the devices and ports. * They are described by name via ipathfs filesystem, so layout @@ -139,15 +159,6 @@ extern const struct pci_error_handlers hfi1_pci_err_handler; struct hfi1_opcode_stats_perctx; #endif -/* - * struct ps_state keeps state associated with RX queue "prescanning" - * (prescanning for FECNs, and BECNs), if prescanning is in use. - */ -struct ps_state { - u32 ps_head; - int initialized; -}; - struct ctxt_eager_bufs { ssize_t size; /* total size of eager buffers */ u32 count; /* size of buffers array */ @@ -243,7 +254,7 @@ struct hfi1_ctxtdata { /* chip offset of PIO buffers for this ctxt */ u32 piobufs; /* per-context configuration flags */ - u16 flags; + u32 flags; /* per-context event flags for fileops/intr communication */ unsigned long event_flags; /* WAIT_RCV that timed out, no interrupt */ @@ -302,10 +313,6 @@ struct hfi1_ctxtdata { struct list_head sdma_queues; spinlock_t sdma_qlock; -#ifdef CONFIG_PRESCAN_RXQ - struct ps_state ps_state; -#endif /* CONFIG_PRESCAN_RXQ */ - /* * The interrupt handler for a particular receive context can vary * throughout it's lifetime. This is not a lock protected data member so @@ -706,6 +713,8 @@ struct hfi1_pportdata { u64 link_downed; /* number of times link retrained successfully */ u64 link_up; + /* number of times a link unknown frame was reported */ + u64 unknown_frame_count; /* port_ltp_crc_mode is returned in 'portinfo' MADs */ u16 port_ltp_crc_mode; /* port_crc_mode_enabled is the crc we support */ @@ -1053,6 +1062,26 @@ struct hfi1_devdata { atomic_t drop_packet; u8 do_drop; + /* + * Software counters for the status bits defined by the + * associated error status registers + */ + u64 cce_err_status_cnt[NUM_CCE_ERR_STATUS_COUNTERS]; + u64 rcv_err_status_cnt[NUM_RCV_ERR_STATUS_COUNTERS]; + u64 misc_err_status_cnt[NUM_MISC_ERR_STATUS_COUNTERS]; + u64 send_pio_err_status_cnt[NUM_SEND_PIO_ERR_STATUS_COUNTERS]; + u64 send_dma_err_status_cnt[NUM_SEND_DMA_ERR_STATUS_COUNTERS]; + u64 send_egress_err_status_cnt[NUM_SEND_EGRESS_ERR_STATUS_COUNTERS]; + u64 send_err_status_cnt[NUM_SEND_ERR_STATUS_COUNTERS]; + + /* Software counter that spans all contexts */ + u64 sw_ctxt_err_status_cnt[NUM_SEND_CTXT_ERR_STATUS_COUNTERS]; + /* Software counter that spans all DMA engines */ + u64 sw_send_dma_eng_err_status_cnt[ + NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS]; + /* Software counter that aggregates all cce_err_status errors */ + u64 sw_cce_err_status_aggregate; + /* receive interrupt functions */ rhf_rcv_function_ptr *rhf_rcv_function_map; rhf_rcv_function_ptr normal_rhf_rcv_functions[8]; @@ -1061,12 +1090,10 @@ struct hfi1_devdata { * Handlers for outgoing data so that snoop/capture does not * have to have its hooks in the send path */ - int (*process_pio_send)(struct hfi1_qp *qp, struct ahg_ib_header *ibhdr, - u32 hdrwords, struct hfi1_sge_state *ss, - u32 len, u32 plen, u32 dwords, u64 pbc); - int (*process_dma_send)(struct hfi1_qp *qp, struct ahg_ib_header *ibhdr, - u32 hdrwords, struct hfi1_sge_state *ss, - u32 len, u32 plen, u32 dwords, u64 pbc); + int (*process_pio_send)(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, + u64 pbc); + int (*process_dma_send)(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, + u64 pbc); void (*pio_inline_send)(struct hfi1_devdata *dd, struct pio_buf *pbuf, u64 pbc, const void *from, size_t count); @@ -1084,6 +1111,10 @@ struct hfi1_devdata { /* Save the enabled LCB error bits */ u64 lcb_err_en; u8 dc_shutdown; + + /* receive context tail dummy address */ + __le64 *rcvhdrtail_dummy_kvaddr; + dma_addr_t rcvhdrtail_dummy_physaddr; }; /* 8051 firmware version helper */ @@ -1414,27 +1445,13 @@ void reset_link_credits(struct hfi1_devdata *dd); void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu); int snoop_recv_handler(struct hfi1_packet *packet); -int snoop_send_dma_handler(struct hfi1_qp *qp, struct ahg_ib_header *ibhdr, - u32 hdrwords, struct hfi1_sge_state *ss, u32 len, - u32 plen, u32 dwords, u64 pbc); -int snoop_send_pio_handler(struct hfi1_qp *qp, struct ahg_ib_header *ibhdr, - u32 hdrwords, struct hfi1_sge_state *ss, u32 len, - u32 plen, u32 dwords, u64 pbc); +int snoop_send_dma_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, + u64 pbc); +int snoop_send_pio_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, + u64 pbc); void snoop_inline_pio_send(struct hfi1_devdata *dd, struct pio_buf *pbuf, u64 pbc, const void *from, size_t count); -/* for use in system calls, where we want to know device type, etc. */ -#define ctxt_fp(fp) \ - (((struct hfi1_filedata *)(fp)->private_data)->uctxt) -#define subctxt_fp(fp) \ - (((struct hfi1_filedata *)(fp)->private_data)->subctxt) -#define tidcursor_fp(fp) \ - (((struct hfi1_filedata *)(fp)->private_data)->tidcursor) -#define user_sdma_pkt_fp(fp) \ - (((struct hfi1_filedata *)(fp)->private_data)->pq) -#define user_sdma_comp_fp(fp) \ - (((struct hfi1_filedata *)(fp)->private_data)->cq) - static inline struct hfi1_devdata *dd_from_ppd(struct hfi1_pportdata *ppd) { return ppd->dd; @@ -1570,8 +1587,8 @@ void hfi1_set_led_override(struct hfi1_pportdata *ppd, unsigned int val); */ #define DEFAULT_RCVHDR_ENTSIZE 32 -int hfi1_get_user_pages(unsigned long, size_t, struct page **); -void hfi1_release_user_pages(struct page **, size_t); +int hfi1_acquire_user_pages(unsigned long, size_t, bool, struct page **); +void hfi1_release_user_pages(struct page **, size_t, bool); static inline void clear_rcvhdrtail(const struct hfi1_ctxtdata *rcd) { @@ -1612,7 +1629,6 @@ void hfi1_pcie_flr(struct hfi1_devdata *); int pcie_speeds(struct hfi1_devdata *); void request_msix(struct hfi1_devdata *, u32 *, struct hfi1_msix_entry *); void hfi1_enable_intx(struct pci_dev *); -void hfi1_nomsix(struct hfi1_devdata *); void restore_pci_variables(struct hfi1_devdata *dd); int do_pcie_gen3_transition(struct hfi1_devdata *dd); int parse_platform_config(struct hfi1_devdata *dd); @@ -1649,7 +1665,7 @@ void update_sge(struct hfi1_sge_state *ss, u32 length); extern unsigned int hfi1_max_mtu; extern unsigned int hfi1_cu; extern unsigned int user_credit_return_threshold; -extern uint num_rcv_contexts; +extern int num_user_contexts; extern unsigned n_krcvqs; extern u8 krcvqs[]; extern int krcvqsset; @@ -1713,7 +1729,7 @@ static inline u64 hfi1_pkt_default_send_ctxt_mask(struct hfi1_devdata *dd, else base_sc_integrity |= HFI1_PKT_KERNEL_SC_INTEGRITY; - if (is_a0(dd)) + if (is_ax(dd)) /* turn off send-side job key checks - A0 erratum */ return base_sc_integrity & ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK; @@ -1740,7 +1756,7 @@ static inline u64 hfi1_pkt_base_sdma_integrity(struct hfi1_devdata *dd) | SEND_DMA_CHECK_ENABLE_CHECK_VL_SMASK | SEND_DMA_CHECK_ENABLE_CHECK_ENABLE_SMASK; - if (is_a0(dd)) + if (is_ax(dd)) /* turn off send-side job key checks - A0 erratum */ return base_sdma_integrity & ~SEND_DMA_CHECK_ENABLE_CHECK_JOB_KEY_SMASK; diff --git a/drivers/staging/rdma/hfi1/init.c b/drivers/staging/rdma/hfi1/init.c index 8666f3ad24e9..4dd8051aba7e 100644 --- a/drivers/staging/rdma/hfi1/init.c +++ b/drivers/staging/rdma/hfi1/init.c @@ -60,6 +60,7 @@ #include "hfi.h" #include "device.h" #include "common.h" +#include "trace.h" #include "mad.h" #include "sdma.h" #include "debugfs.h" @@ -81,15 +82,15 @@ * Number of user receive contexts we are configured to use (to allow for more * pio buffers per ctxt, etc.) Zero means use one user context per CPU. */ -uint num_rcv_contexts; -module_param_named(num_rcv_contexts, num_rcv_contexts, uint, S_IRUGO); +int num_user_contexts = -1; +module_param_named(num_user_contexts, num_user_contexts, uint, S_IRUGO); MODULE_PARM_DESC( - num_rcv_contexts, "Set max number of user receive contexts to use"); + num_user_contexts, "Set max number of user contexts to use"); u8 krcvqs[RXE_NUM_DATA_VL]; int krcvqsset; module_param_array(krcvqs, byte, &krcvqsset, S_IRUGO); -MODULE_PARM_DESC(krcvqs, "Array of the number of kernel receive queues by VL"); +MODULE_PARM_DESC(krcvqs, "Array of the number of non-control kernel receive queues by VL"); /* computed based on above array */ unsigned n_krcvqs; @@ -112,7 +113,7 @@ MODULE_PARM_DESC(hdrq_entsize, "Size of header queue entries: 2 - 8B, 16 - 64B ( unsigned int user_credit_return_threshold = 33; /* default is 33% */ module_param(user_credit_return_threshold, uint, S_IRUGO); -MODULE_PARM_DESC(user_credit_return_theshold, "Credit return threshold for user send contexts, return when unreturned credits passes this many blocks (in percent of allocated blocks, 0 is off)"); +MODULE_PARM_DESC(user_credit_return_threshold, "Credit return threshold for user send contexts, return when unreturned credits passes this many blocks (in percent of allocated blocks, 0 is off)"); static inline u64 encode_rcv_header_entry_size(u16); @@ -129,6 +130,9 @@ int hfi1_create_ctxts(struct hfi1_devdata *dd) int ret; int local_node_id = pcibus_to_node(dd->pcidev->bus); + /* Control context has to be always 0 */ + BUILD_BUG_ON(HFI1_CTRL_CTXT != 0); + if (local_node_id < 0) local_node_id = numa_node_id(); dd->assigned_node_id = local_node_id; @@ -158,6 +162,10 @@ int hfi1_create_ctxts(struct hfi1_devdata *dd) HFI1_CAP_KGET(NODROP_RHQ_FULL) | HFI1_CAP_KGET(NODROP_EGR_FULL) | HFI1_CAP_KGET(DMA_RTAIL); + + /* Control context must use DMA_RTAIL */ + if (rcd->ctxt == HFI1_CTRL_CTXT) + rcd->flags |= HFI1_CAP_DMA_RTAIL; rcd->seq_cnt = 1; rcd->sc = sc_alloc(dd, SC_ACK, rcd->rcvhdrqentsize, dd->node); @@ -208,7 +216,7 @@ struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt) if (rcd) { u32 rcvtids, max_entries; - dd_dev_info(dd, "%s: setting up context %u\n", __func__, ctxt); + hfi1_cdbg(PROC, "setting up context %u\n", ctxt); INIT_LIST_HEAD(&rcd->qp_wait_list); rcd->ppd = ppd; @@ -279,8 +287,9 @@ struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt) rcd->ctxt); rcd->egrbufs.count = MAX_EAGER_ENTRIES; } - dd_dev_info(dd, "ctxt%u: max Eager buffer RcvArray entries: %u\n", - rcd->ctxt, rcd->egrbufs.count); + hfi1_cdbg(PROC, + "ctxt%u: max Eager buffer RcvArray entries: %u\n", + rcd->ctxt, rcd->egrbufs.count); /* * Allocate array that will hold the eager buffer accounting @@ -308,8 +317,8 @@ struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt) */ if (rcd->egrbufs.size < hfi1_max_mtu) { rcd->egrbufs.size = __roundup_pow_of_two(hfi1_max_mtu); - dd_dev_info(dd, - "ctxt%u: eager bufs size too small. Adjusting to %zu\n", + hfi1_cdbg(PROC, + "ctxt%u: eager bufs size too small. Adjusting to %zu\n", rcd->ctxt, rcd->egrbufs.size); } rcd->egrbufs.rcvtid_size = HFI1_MAX_EAGER_BUFFER_SIZE; @@ -601,20 +610,19 @@ static int create_workqueues(struct hfi1_devdata *dd) for (pidx = 0; pidx < dd->num_pports; ++pidx) { ppd = dd->pport + pidx; if (!ppd->hfi1_wq) { - char wq_name[8]; /* 3 + 2 + 1 + 1 + 1 */ - - snprintf(wq_name, sizeof(wq_name), "hfi%d_%d", - dd->unit, pidx); ppd->hfi1_wq = - create_singlethread_workqueue(wq_name); + alloc_workqueue( + "hfi%d_%d", + WQ_SYSFS | WQ_HIGHPRI | WQ_CPU_INTENSIVE, + dd->num_sdma, + dd->unit, pidx); if (!ppd->hfi1_wq) goto wq_error; } } return 0; wq_error: - pr_err("create_singlethread_workqueue failed for port %d\n", - pidx + 1); + pr_err("alloc_workqueue failed for port %d\n", pidx + 1); for (pidx = 0; pidx < dd->num_pports; ++pidx) { ppd = dd->pport + pidx; if (ppd->hfi1_wq) { @@ -670,7 +678,7 @@ int hfi1_init(struct hfi1_devdata *dd, int reinit) dd->process_dma_send = hfi1_verbs_send_dma; dd->pio_inline_send = pio_copy; - if (is_a0(dd)) { + if (is_ax(dd)) { atomic_set(&dd->drop_packet, DROP_PACKET_ON); dd->do_drop = 1; } else { @@ -691,6 +699,18 @@ int hfi1_init(struct hfi1_devdata *dd, int reinit) if (ret) goto done; + /* allocate dummy tail memory for all receive contexts */ + dd->rcvhdrtail_dummy_kvaddr = dma_zalloc_coherent( + &dd->pcidev->dev, sizeof(u64), + &dd->rcvhdrtail_dummy_physaddr, + GFP_KERNEL); + + if (!dd->rcvhdrtail_dummy_kvaddr) { + dd_dev_err(dd, "cannot allocate dummy tail memory\n"); + ret = -ENOMEM; + goto done; + } + /* dd->rcd can be NULL if early initialization failed */ for (i = 0; dd->rcd && i < dd->first_user_ctxt; ++i) { /* @@ -1266,6 +1286,14 @@ static void cleanup_device_data(struct hfi1_devdata *dd) tmp = dd->rcd; dd->rcd = NULL; spin_unlock_irqrestore(&dd->uctxt_lock, flags); + + if (dd->rcvhdrtail_dummy_kvaddr) { + dma_free_coherent(&dd->pcidev->dev, sizeof(u64), + (void *)dd->rcvhdrtail_dummy_kvaddr, + dd->rcvhdrtail_dummy_physaddr); + dd->rcvhdrtail_dummy_kvaddr = NULL; + } + for (ctxt = 0; tmp && ctxt < dd->num_rcv_contexts; ctxt++) { struct hfi1_ctxtdata *rcd = tmp[ctxt]; @@ -1308,6 +1336,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { int ret = 0, j, pidx, initfail; struct hfi1_devdata *dd = NULL; + struct hfi1_pportdata *ppd; /* First, lock the non-writable module parameters */ HFI1_CAP_LOCK(); @@ -1322,6 +1351,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (!encode_rcv_header_entry_size(hfi1_hdrq_entsize)) { hfi1_early_err(&pdev->dev, "Invalid HdrQ Entry size %u\n", hfi1_hdrq_entsize); + ret = -EINVAL; goto bail; } @@ -1403,8 +1433,14 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (initfail || ret) { stop_timers(dd); flush_workqueue(ib_wq); - for (pidx = 0; pidx < dd->num_pports; ++pidx) + for (pidx = 0; pidx < dd->num_pports; ++pidx) { hfi1_quiet_serdes(dd->pport + pidx); + ppd = dd->pport + pidx; + if (ppd->hfi1_wq) { + destroy_workqueue(ppd->hfi1_wq); + ppd->hfi1_wq = NULL; + } + } if (!j) hfi1_device_remove(dd); if (!ret) @@ -1521,6 +1557,14 @@ int hfi1_create_rcvhdrq(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd) reg = (dd->rcvhdrsize & RCV_HDR_SIZE_HDR_SIZE_MASK) << RCV_HDR_SIZE_HDR_SIZE_SHIFT; write_kctxt_csr(dd, rcd->ctxt, RCV_HDR_SIZE, reg); + + /* + * Program dummy tail address for every receive context + * before enabling any receive context + */ + write_kctxt_csr(dd, rcd->ctxt, RCV_HDR_TAIL_ADDR, + dd->rcvhdrtail_dummy_physaddr); + return 0; bail_free: @@ -1660,9 +1704,11 @@ int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd) rcd->egrbufs.numbufs = idx; rcd->egrbufs.size = alloced_bytes; - dd_dev_info(dd, "ctxt%u: Alloced %u rcv tid entries @ %uKB, total %zuKB\n", - rcd->ctxt, rcd->egrbufs.alloced, rcd->egrbufs.rcvtid_size, - rcd->egrbufs.size); + hfi1_cdbg(PROC, + "ctxt%u: Alloced %u rcv tid entries @ %uKB, total %zuKB\n", + rcd->ctxt, rcd->egrbufs.alloced, rcd->egrbufs.rcvtid_size, + rcd->egrbufs.size); + /* * Set the contexts rcv array head update threshold to the closest @@ -1683,13 +1729,14 @@ int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd) rcd->expected_count = MAX_TID_PAIR_ENTRIES * 2; rcd->expected_base = rcd->eager_base + egrtop; - dd_dev_info(dd, "ctxt%u: eager:%u, exp:%u, egrbase:%u, expbase:%u\n", - rcd->ctxt, rcd->egrbufs.alloced, rcd->expected_count, - rcd->eager_base, rcd->expected_base); + hfi1_cdbg(PROC, "ctxt%u: eager:%u, exp:%u, egrbase:%u, expbase:%u\n", + rcd->ctxt, rcd->egrbufs.alloced, rcd->expected_count, + rcd->eager_base, rcd->expected_base); if (!hfi1_rcvbuf_validate(rcd->egrbufs.rcvtid_size, PT_EAGER, &order)) { - dd_dev_err(dd, "ctxt%u: current Eager buffer size is invalid %u\n", - rcd->ctxt, rcd->egrbufs.rcvtid_size); + hfi1_cdbg(PROC, + "ctxt%u: current Eager buffer size is invalid %u\n", + rcd->ctxt, rcd->egrbufs.rcvtid_size); ret = -EINVAL; goto bail; } diff --git a/drivers/staging/rdma/hfi1/iowait.h b/drivers/staging/rdma/hfi1/iowait.h index fa361b405851..e8ba5606d08d 100644 --- a/drivers/staging/rdma/hfi1/iowait.h +++ b/drivers/staging/rdma/hfi1/iowait.h @@ -150,12 +150,14 @@ static inline void iowait_init( * iowait_schedule() - initialize wait structure * @wait: wait struct to schedule * @wq: workqueue for schedule + * @cpu: cpu */ static inline void iowait_schedule( struct iowait *wait, - struct workqueue_struct *wq) + struct workqueue_struct *wq, + int cpu) { - queue_work(wq, &wait->iowork); + queue_work_on(cpu, wq, &wait->iowork); } /** diff --git a/drivers/staging/rdma/hfi1/mad.c b/drivers/staging/rdma/hfi1/mad.c index 32f703736185..4f5dbd14b5de 100644 --- a/drivers/staging/rdma/hfi1/mad.c +++ b/drivers/staging/rdma/hfi1/mad.c @@ -84,7 +84,7 @@ static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len) { struct ib_mad_send_buf *send_buf; struct ib_mad_agent *agent; - struct ib_smp *smp; + struct opa_smp *smp; int ret; unsigned long flags; unsigned long timeout; @@ -117,15 +117,15 @@ static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len) return; smp = send_buf->mad; - smp->base_version = IB_MGMT_BASE_VERSION; + smp->base_version = OPA_MGMT_BASE_VERSION; smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED; - smp->class_version = 1; + smp->class_version = OPA_SMI_CLASS_VERSION; smp->method = IB_MGMT_METHOD_TRAP; ibp->tid++; smp->tid = cpu_to_be64(ibp->tid); smp->attr_id = IB_SMP_ATTR_NOTICE; /* o14-1: smp->mkey = 0; */ - memcpy(smp->data, data, len); + memcpy(smp->route.lid.data, data, len); spin_lock_irqsave(&ibp->lock, flags); if (!ibp->sm_ah) { @@ -164,11 +164,16 @@ static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len) * Send a bad [PQ]_Key trap (ch. 14.3.8). */ void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl, - u32 qp1, u32 qp2, __be16 lid1, __be16 lid2) + u32 qp1, u32 qp2, u16 lid1, u16 lid2) { - struct ib_mad_notice_attr data; + struct opa_mad_notice_attr data; + u32 lid = ppd_from_ibp(ibp)->lid; + u32 _lid1 = lid1; + u32 _lid2 = lid2; - if (trap_num == IB_NOTICE_TRAP_BAD_PKEY) + memset(&data, 0, sizeof(data)); + + if (trap_num == OPA_TRAP_BAD_P_KEY) ibp->pkey_violations++; else ibp->qkey_violations++; @@ -176,17 +181,15 @@ void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl, /* Send violation trap */ data.generic_type = IB_NOTICE_TYPE_SECURITY; - data.prod_type_msb = 0; data.prod_type_lsb = IB_NOTICE_PROD_CA; data.trap_num = trap_num; - data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid); - data.toggle_count = 0; - memset(&data.details, 0, sizeof(data.details)); - data.details.ntc_257_258.lid1 = lid1; - data.details.ntc_257_258.lid2 = lid2; - data.details.ntc_257_258.key = cpu_to_be32(key); - data.details.ntc_257_258.sl_qp1 = cpu_to_be32((sl << 28) | qp1); - data.details.ntc_257_258.qp2 = cpu_to_be32(qp2); + data.issuer_lid = cpu_to_be32(lid); + data.ntc_257_258.lid1 = cpu_to_be32(_lid1); + data.ntc_257_258.lid2 = cpu_to_be32(_lid2); + data.ntc_257_258.key = cpu_to_be32(key); + data.ntc_257_258.sl = sl << 3; + data.ntc_257_258.qp1 = cpu_to_be32(qp1); + data.ntc_257_258.qp2 = cpu_to_be32(qp2); send_trap(ibp, &data, sizeof(data)); } @@ -197,32 +200,30 @@ void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl, static void bad_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad, __be64 mkey, __be32 dr_slid, u8 return_path[], u8 hop_cnt) { - struct ib_mad_notice_attr data; + struct opa_mad_notice_attr data; + u32 lid = ppd_from_ibp(ibp)->lid; + memset(&data, 0, sizeof(data)); /* Send violation trap */ data.generic_type = IB_NOTICE_TYPE_SECURITY; - data.prod_type_msb = 0; data.prod_type_lsb = IB_NOTICE_PROD_CA; - data.trap_num = IB_NOTICE_TRAP_BAD_MKEY; - data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid); - data.toggle_count = 0; - memset(&data.details, 0, sizeof(data.details)); - data.details.ntc_256.lid = data.issuer_lid; - data.details.ntc_256.method = mad->method; - data.details.ntc_256.attr_id = mad->attr_id; - data.details.ntc_256.attr_mod = mad->attr_mod; - data.details.ntc_256.mkey = mkey; + data.trap_num = OPA_TRAP_BAD_M_KEY; + data.issuer_lid = cpu_to_be32(lid); + data.ntc_256.lid = data.issuer_lid; + data.ntc_256.method = mad->method; + data.ntc_256.attr_id = mad->attr_id; + data.ntc_256.attr_mod = mad->attr_mod; + data.ntc_256.mkey = mkey; if (mad->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) { - - data.details.ntc_256.dr_slid = (__force __be16)dr_slid; - data.details.ntc_256.dr_trunc_hop = IB_NOTICE_TRAP_DR_NOTICE; - if (hop_cnt > ARRAY_SIZE(data.details.ntc_256.dr_rtn_path)) { - data.details.ntc_256.dr_trunc_hop |= + data.ntc_256.dr_slid = dr_slid; + data.ntc_256.dr_trunc_hop = IB_NOTICE_TRAP_DR_NOTICE; + if (hop_cnt > ARRAY_SIZE(data.ntc_256.dr_rtn_path)) { + data.ntc_256.dr_trunc_hop |= IB_NOTICE_TRAP_DR_TRUNC; - hop_cnt = ARRAY_SIZE(data.details.ntc_256.dr_rtn_path); + hop_cnt = ARRAY_SIZE(data.ntc_256.dr_rtn_path); } - data.details.ntc_256.dr_trunc_hop |= hop_cnt; - memcpy(data.details.ntc_256.dr_rtn_path, return_path, + data.ntc_256.dr_trunc_hop |= hop_cnt; + memcpy(data.ntc_256.dr_rtn_path, return_path, hop_cnt); } @@ -234,17 +235,17 @@ static void bad_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad, */ void hfi1_cap_mask_chg(struct hfi1_ibport *ibp) { - struct ib_mad_notice_attr data; + struct opa_mad_notice_attr data; + u32 lid = ppd_from_ibp(ibp)->lid; + + memset(&data, 0, sizeof(data)); data.generic_type = IB_NOTICE_TYPE_INFO; - data.prod_type_msb = 0; data.prod_type_lsb = IB_NOTICE_PROD_CA; - data.trap_num = IB_NOTICE_TRAP_CAP_MASK_CHG; - data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid); - data.toggle_count = 0; - memset(&data.details, 0, sizeof(data.details)); - data.details.ntc_144.lid = data.issuer_lid; - data.details.ntc_144.new_cap_mask = cpu_to_be32(ibp->port_cap_flags); + data.trap_num = OPA_TRAP_CHANGE_CAPABILITY; + data.issuer_lid = cpu_to_be32(lid); + data.ntc_144.lid = data.issuer_lid; + data.ntc_144.new_cap_mask = cpu_to_be32(ibp->port_cap_flags); send_trap(ibp, &data, sizeof(data)); } @@ -254,17 +255,17 @@ void hfi1_cap_mask_chg(struct hfi1_ibport *ibp) */ void hfi1_sys_guid_chg(struct hfi1_ibport *ibp) { - struct ib_mad_notice_attr data; + struct opa_mad_notice_attr data; + u32 lid = ppd_from_ibp(ibp)->lid; + + memset(&data, 0, sizeof(data)); data.generic_type = IB_NOTICE_TYPE_INFO; - data.prod_type_msb = 0; data.prod_type_lsb = IB_NOTICE_PROD_CA; - data.trap_num = IB_NOTICE_TRAP_SYS_GUID_CHG; - data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid); - data.toggle_count = 0; - memset(&data.details, 0, sizeof(data.details)); - data.details.ntc_145.lid = data.issuer_lid; - data.details.ntc_145.new_sys_guid = ib_hfi1_sys_image_guid; + data.trap_num = OPA_TRAP_CHANGE_SYSGUID; + data.issuer_lid = cpu_to_be32(lid); + data.ntc_145.new_sys_guid = ib_hfi1_sys_image_guid; + data.ntc_145.lid = data.issuer_lid; send_trap(ibp, &data, sizeof(data)); } @@ -274,18 +275,18 @@ void hfi1_sys_guid_chg(struct hfi1_ibport *ibp) */ void hfi1_node_desc_chg(struct hfi1_ibport *ibp) { - struct ib_mad_notice_attr data; + struct opa_mad_notice_attr data; + u32 lid = ppd_from_ibp(ibp)->lid; + + memset(&data, 0, sizeof(data)); data.generic_type = IB_NOTICE_TYPE_INFO; - data.prod_type_msb = 0; data.prod_type_lsb = IB_NOTICE_PROD_CA; - data.trap_num = IB_NOTICE_TRAP_CAP_MASK_CHG; - data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid); - data.toggle_count = 0; - memset(&data.details, 0, sizeof(data.details)); - data.details.ntc_144.lid = data.issuer_lid; - data.details.ntc_144.local_changes = 1; - data.details.ntc_144.change_flags = IB_NOTICE_TRAP_NODE_DESC_CHG; + data.trap_num = OPA_TRAP_CHANGE_CAPABILITY; + data.issuer_lid = cpu_to_be32(lid); + data.ntc_144.lid = data.issuer_lid; + data.ntc_144.change_flags = + cpu_to_be16(OPA_NOTICE_TRAP_NODE_DESC_CHG); send_trap(ibp, &data, sizeof(data)); } @@ -2076,13 +2077,20 @@ struct opa_aggregate { u8 data[0]; }; -/* Request contains first two fields, response contains those plus the rest */ +#define MSK_LLI 0x000000f0 +#define MSK_LLI_SFT 4 +#define MSK_LER 0x0000000f +#define MSK_LER_SFT 0 +#define ADD_LLI 8 +#define ADD_LER 2 + +/* Request contains first three fields, response contains those plus the rest */ struct opa_port_data_counters_msg { __be64 port_select_mask[4]; __be32 vl_select_mask; + __be32 resolution; /* Response fields follow */ - __be32 reserved1; struct _port_dctrs { u8 port_number; u8 reserved2[3]; @@ -2271,34 +2279,8 @@ static void a0_portstatus(struct hfi1_pportdata *ppd, { if (!is_bx(ppd->dd)) { unsigned long vl; - int vfi = 0; u64 max_vl_xmit_wait = 0, tmp; u32 vl_all_mask = VL_MASK_ALL; - u64 rcv_data, rcv_bubble; - - rcv_data = be64_to_cpu(rsp->port_rcv_data); - rcv_bubble = be64_to_cpu(rsp->port_rcv_bubble); - /* In the measured time period, calculate the total number - * of flits that were received. Subtract out one false - * rcv_bubble increment for every 32 received flits but - * don't let the number go negative. - */ - if (rcv_bubble >= (rcv_data>>5)) { - rcv_bubble -= (rcv_data>>5); - rsp->port_rcv_bubble = cpu_to_be64(rcv_bubble); - } - for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), - 8 * sizeof(vl_select_mask)) { - rcv_data = be64_to_cpu(rsp->vls[vfi].port_vl_rcv_data); - rcv_bubble = - be64_to_cpu(rsp->vls[vfi].port_vl_rcv_bubble); - if (rcv_bubble >= (rcv_data>>5)) { - rcv_bubble -= (rcv_data>>5); - rsp->vls[vfi].port_vl_rcv_bubble = - cpu_to_be64(rcv_bubble); - } - vfi++; - } for_each_set_bit(vl, (unsigned long *)&(vl_all_mask), 8 * sizeof(vl_all_mask)) { @@ -2363,8 +2345,6 @@ static int pma_get_opa_portstatus(struct opa_pma_mad *pmp, CNTR_INVALID_VL)); rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS, CNTR_INVALID_VL)); - rsp->port_rcv_bubble = - cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BBL, CNTR_INVALID_VL)); rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS, CNTR_INVALID_VL)); rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS, @@ -2434,9 +2414,6 @@ static int pma_get_opa_portstatus(struct opa_pma_mad *pmp, tmp = read_dev_cntr(dd, C_DC_RX_FLIT_VL, idx_from_vl(vl)); rsp->vls[vfi].port_vl_rcv_data = cpu_to_be64(tmp); - rsp->vls[vfi].port_vl_rcv_bubble = - cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BBL_VL, - idx_from_vl(vl))); rsp->vls[vfi].port_vl_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL, @@ -2474,7 +2451,8 @@ static int pma_get_opa_portstatus(struct opa_pma_mad *pmp, return reply((struct ib_mad_hdr *)pmp); } -static u64 get_error_counter_summary(struct ib_device *ibdev, u8 port) +static u64 get_error_counter_summary(struct ib_device *ibdev, u8 port, + u8 res_lli, u8 res_ler) { struct hfi1_devdata *dd = dd_from_ibdev(ibdev); struct hfi1_ibport *ibp = to_iport(ibdev, port); @@ -2490,14 +2468,14 @@ static u64 get_error_counter_summary(struct ib_device *ibdev, u8 port) CNTR_INVALID_VL); error_counter_summary += read_dev_cntr(dd, C_DC_RMT_PHY_ERR, CNTR_INVALID_VL); - error_counter_summary += read_dev_cntr(dd, C_DC_TX_REPLAY, - CNTR_INVALID_VL); - error_counter_summary += read_dev_cntr(dd, C_DC_RX_REPLAY, - CNTR_INVALID_VL); - error_counter_summary += read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, - CNTR_INVALID_VL); - error_counter_summary += read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, - CNTR_INVALID_VL); + /* local link integrity must be right-shifted by the lli resolution */ + tmp = read_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL); + tmp += read_dev_cntr(dd, C_DC_TX_REPLAY, CNTR_INVALID_VL); + error_counter_summary += (tmp >> res_lli); + /* link error recovery must b right-shifted by the ler resolution */ + tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL); + tmp += read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, CNTR_INVALID_VL); + error_counter_summary += (tmp >> res_ler); error_counter_summary += read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL); error_counter_summary += read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL); @@ -2519,32 +2497,8 @@ static void a0_datacounters(struct hfi1_devdata *dd, struct _port_dctrs *rsp, if (!is_bx(dd)) { unsigned long vl; int vfi = 0; - u64 rcv_data, rcv_bubble, sum_vl_xmit_wait = 0; - - rcv_data = be64_to_cpu(rsp->port_rcv_data); - rcv_bubble = be64_to_cpu(rsp->port_rcv_bubble); - /* In the measured time period, calculate the total number - * of flits that were received. Subtract out one false - * rcv_bubble increment for every 32 received flits but - * don't let the number go negative. - */ - if (rcv_bubble >= (rcv_data>>5)) { - rcv_bubble -= (rcv_data>>5); - rsp->port_rcv_bubble = cpu_to_be64(rcv_bubble); - } - for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), - 8 * sizeof(vl_select_mask)) { - rcv_data = be64_to_cpu(rsp->vls[vfi].port_vl_rcv_data); - rcv_bubble = - be64_to_cpu(rsp->vls[vfi].port_vl_rcv_bubble); - if (rcv_bubble >= (rcv_data>>5)) { - rcv_bubble -= (rcv_data>>5); - rsp->vls[vfi].port_vl_rcv_bubble = - cpu_to_be64(rcv_bubble); - } - vfi++; - } - vfi = 0; + u64 sum_vl_xmit_wait = 0; + for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), 8 * sizeof(vl_select_mask)) { u64 tmp = sum_vl_xmit_wait + @@ -2575,6 +2529,7 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp, u32 num_ports; u8 num_pslm; u8 lq, num_vls; + u8 res_lli, res_ler; u64 port_mask; unsigned long port_num; unsigned long vl; @@ -2585,6 +2540,10 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp, num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3])); num_vls = hweight32(be32_to_cpu(req->vl_select_mask)); vl_select_mask = be32_to_cpu(req->vl_select_mask); + res_lli = (u8)(be32_to_cpu(req->resolution) & MSK_LLI) >> MSK_LLI_SFT; + res_lli = res_lli ? res_lli + ADD_LLI : 0; + res_ler = (u8)(be32_to_cpu(req->resolution) & MSK_LER) >> MSK_LER_SFT; + res_ler = res_ler ? res_ler + ADD_LER : 0; if (num_ports != 1 || (vl_select_mask & ~VL_MASK_ALL)) { pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; @@ -2635,8 +2594,6 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp, CNTR_INVALID_VL)); rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS, CNTR_INVALID_VL)); - rsp->port_rcv_bubble = - cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BBL, CNTR_INVALID_VL)); rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS, CNTR_INVALID_VL)); rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS, @@ -2655,7 +2612,8 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp, cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL)); rsp->port_error_counter_summary = - cpu_to_be64(get_error_counter_summary(ibdev, port)); + cpu_to_be64(get_error_counter_summary(ibdev, port, + res_lli, res_ler)); vlinfo = &(rsp->vls[0]); vfi = 0; @@ -2675,9 +2633,6 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp, rsp->vls[vfi].port_vl_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RX_FLIT_VL, idx_from_vl(vl))); - rsp->vls[vfi].port_vl_rcv_bubble = - cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BBL_VL, - idx_from_vl(vl))); rsp->vls[vfi].port_vl_xmit_pkts = cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL, @@ -3458,7 +3413,7 @@ static int __subn_get_opa_led_info(struct opa_smp *smp, u32 am, u8 *data, u32 nport = OPA_AM_NPORT(am); u64 reg; - if (nport != 1 || OPA_AM_PORTNUM(am)) { + if (nport != 1) { smp->status |= IB_SMP_INVALID_FIELD; return reply((struct ib_mad_hdr *)smp); } @@ -3483,7 +3438,7 @@ static int __subn_set_opa_led_info(struct opa_smp *smp, u32 am, u8 *data, u32 nport = OPA_AM_NPORT(am); int on = !!(be32_to_cpu(p->rsvd_led_mask) & OPA_LED_MASK); - if (nport != 1 || OPA_AM_PORTNUM(am)) { + if (nport != 1) { smp->status |= IB_SMP_INVALID_FIELD; return reply((struct ib_mad_hdr *)smp); } diff --git a/drivers/staging/rdma/hfi1/mad.h b/drivers/staging/rdma/hfi1/mad.h index 47457501c044..f0317750e2fc 100644 --- a/drivers/staging/rdma/hfi1/mad.h +++ b/drivers/staging/rdma/hfi1/mad.h @@ -60,7 +60,121 @@ #endif #include "opa_compat.h" +/* + * OPA Traps + */ +#define OPA_TRAP_GID_NOW_IN_SERVICE cpu_to_be16(64) +#define OPA_TRAP_GID_OUT_OF_SERVICE cpu_to_be16(65) +#define OPA_TRAP_ADD_MULTICAST_GROUP cpu_to_be16(66) +#define OPA_TRAL_DEL_MULTICAST_GROUP cpu_to_be16(67) +#define OPA_TRAP_UNPATH cpu_to_be16(68) +#define OPA_TRAP_REPATH cpu_to_be16(69) +#define OPA_TRAP_PORT_CHANGE_STATE cpu_to_be16(128) +#define OPA_TRAP_LINK_INTEGRITY cpu_to_be16(129) +#define OPA_TRAP_EXCESSIVE_BUFFER_OVERRUN cpu_to_be16(130) +#define OPA_TRAP_FLOW_WATCHDOG cpu_to_be16(131) +#define OPA_TRAP_CHANGE_CAPABILITY cpu_to_be16(144) +#define OPA_TRAP_CHANGE_SYSGUID cpu_to_be16(145) +#define OPA_TRAP_BAD_M_KEY cpu_to_be16(256) +#define OPA_TRAP_BAD_P_KEY cpu_to_be16(257) +#define OPA_TRAP_BAD_Q_KEY cpu_to_be16(258) +#define OPA_TRAP_SWITCH_BAD_PKEY cpu_to_be16(259) +#define OPA_SMA_TRAP_DATA_LINK_WIDTH cpu_to_be16(2048) +/* + * Generic trap/notice other local changes flags (trap 144). + */ +#define OPA_NOTICE_TRAP_LWDE_CHG 0x08 /* Link Width Downgrade Enable + * changed + */ +#define OPA_NOTICE_TRAP_LSE_CHG 0x04 /* Link Speed Enable changed */ +#define OPA_NOTICE_TRAP_LWE_CHG 0x02 /* Link Width Enable changed */ +#define OPA_NOTICE_TRAP_NODE_DESC_CHG 0x01 + +struct opa_mad_notice_attr { + u8 generic_type; + u8 prod_type_msb; + __be16 prod_type_lsb; + __be16 trap_num; + __be16 toggle_count; + __be32 issuer_lid; + __be32 reserved1; + union ib_gid issuer_gid; + + union { + struct { + u8 details[64]; + } raw_data; + + struct { + union ib_gid gid; + } __packed ntc_64_65_66_67; + + struct { + __be32 lid; + } __packed ntc_128; + + struct { + __be32 lid; /* where violation happened */ + u8 port_num; /* where violation happened */ + } __packed ntc_129_130_131; + + struct { + __be32 lid; /* LID where change occurred */ + __be32 new_cap_mask; /* new capability mask */ + __be16 reserved2; + __be16 cap_mask; + __be16 change_flags; /* low 4 bits only */ + } __packed ntc_144; + + struct { + __be64 new_sys_guid; + __be32 lid; /* lid where sys guid changed */ + } __packed ntc_145; + + struct { + __be32 lid; + __be32 dr_slid; + u8 method; + u8 dr_trunc_hop; + __be16 attr_id; + __be32 attr_mod; + __be64 mkey; + u8 dr_rtn_path[30]; + } __packed ntc_256; + + struct { + __be32 lid1; + __be32 lid2; + __be32 key; + u8 sl; /* SL: high 5 bits */ + u8 reserved3[3]; + union ib_gid gid1; + union ib_gid gid2; + __be32 qp1; /* high 8 bits reserved */ + __be32 qp2; /* high 8 bits reserved */ + } __packed ntc_257_258; + + struct { + __be16 flags; /* low 8 bits reserved */ + __be16 pkey; + __be32 lid1; + __be32 lid2; + u8 sl; /* SL: high 5 bits */ + u8 reserved4[3]; + union ib_gid gid1; + union ib_gid gid2; + __be32 qp1; /* high 8 bits reserved */ + __be32 qp2; /* high 8 bits reserved */ + } __packed ntc_259; + + struct { + __be32 lid; + } __packed ntc_2048; + + }; + u8 class_data[0]; +}; #define IB_VLARB_LOWPRI_0_31 1 #define IB_VLARB_LOWPRI_32_63 2 diff --git a/drivers/staging/rdma/hfi1/pcie.c b/drivers/staging/rdma/hfi1/pcie.c index a956044459a2..8317b07d722a 100644 --- a/drivers/staging/rdma/hfi1/pcie.c +++ b/drivers/staging/rdma/hfi1/pcie.c @@ -426,14 +426,6 @@ void request_msix(struct hfi1_devdata *dd, u32 *nent, tune_pcie_caps(dd); } -/* - * Disable MSI-X. - */ -void hfi1_nomsix(struct hfi1_devdata *dd) -{ - pci_disable_msix(dd->pcidev); -} - void hfi1_enable_intx(struct pci_dev *pdev) { /* first, turn on INTx */ @@ -475,8 +467,18 @@ static void tune_pcie_caps(struct hfi1_devdata *dd) { struct pci_dev *parent; u16 rc_mpss, rc_mps, ep_mpss, ep_mps; - u16 rc_mrrs, ep_mrrs, max_mrrs; + u16 rc_mrrs, ep_mrrs, max_mrrs, ectl; + /* + * Turn on extended tags in DevCtl in case the BIOS has turned it off + * to improve WFR SDMA bandwidth + */ + pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL, &ectl); + if (!(ectl & PCI_EXP_DEVCTL_EXT_TAG)) { + dd_dev_info(dd, "Enabling PCIe extended tags\n"); + ectl |= PCI_EXP_DEVCTL_EXT_TAG; + pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL, ectl); + } /* Find out supported and configured values for parent (root) */ parent = dd->pcidev->bus->self; if (!pci_is_root_bus(parent->bus)) { @@ -915,7 +917,7 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd) /* * A0 needs an additional SBR */ - if (is_a0(dd)) + if (is_ax(dd)) nsbr++; /* @@ -947,17 +949,7 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd) } retry: - - if (therm) { - /* - * toggle SPICO_ENABLE to get back to the state - * just after the firmware load - */ - sbus_request(dd, SBUS_MASTER_BROADCAST, 0x01, - WRITE_SBUS_RECEIVER, 0x00000040); - sbus_request(dd, SBUS_MASTER_BROADCAST, 0x01, - WRITE_SBUS_RECEIVER, 0x00000140); - } + /* the SBus download will reset the spico for thermal */ /* step 3: download SBus Master firmware */ /* step 4: download PCIe Gen3 SerDes firmware */ @@ -1201,7 +1193,7 @@ retry: write_csr(dd, CCE_DC_CTRL, 0); /* Set the LED off */ - if (is_a0(dd)) + if (is_ax(dd)) setextled(dd, 0); /* check for any per-lane errors */ diff --git a/drivers/staging/rdma/hfi1/pio.c b/drivers/staging/rdma/hfi1/pio.c index e5c32db4bc67..b51a4416312b 100644 --- a/drivers/staging/rdma/hfi1/pio.c +++ b/drivers/staging/rdma/hfi1/pio.c @@ -660,6 +660,24 @@ void set_pio_integrity(struct send_context *sc) write_kctxt_csr(dd, hw_context, SC(CHECK_ENABLE), reg); } +static u32 get_buffers_allocated(struct send_context *sc) +{ + int cpu; + u32 ret = 0; + + for_each_possible_cpu(cpu) + ret += *per_cpu_ptr(sc->buffers_allocated, cpu); + return ret; +} + +static void reset_buffers_allocated(struct send_context *sc) +{ + int cpu; + + for_each_possible_cpu(cpu) + (*per_cpu_ptr(sc->buffers_allocated, cpu)) = 0; +} + /* * Allocate a NUMA relative send context structure of the given type along * with a HW context. @@ -668,7 +686,7 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type, uint hdrqentsize, int numa) { struct send_context_info *sci; - struct send_context *sc; + struct send_context *sc = NULL; dma_addr_t pa; unsigned long flags; u64 reg; @@ -686,10 +704,20 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type, if (!sc) return NULL; + sc->buffers_allocated = alloc_percpu(u32); + if (!sc->buffers_allocated) { + kfree(sc); + dd_dev_err(dd, + "Cannot allocate buffers_allocated per cpu counters\n" + ); + return NULL; + } + spin_lock_irqsave(&dd->sc_lock, flags); ret = sc_hw_alloc(dd, type, &sw_index, &hw_context); if (ret) { spin_unlock_irqrestore(&dd->sc_lock, flags); + free_percpu(sc->buffers_allocated); kfree(sc); return NULL; } @@ -705,7 +733,6 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type, spin_lock_init(&sc->credit_ctrl_lock); INIT_LIST_HEAD(&sc->piowait); INIT_WORK(&sc->halt_work, sc_halted); - atomic_set(&sc->buffers_allocated, 0); init_waitqueue_head(&sc->halt_wait); /* grouping is always single context for now */ @@ -815,15 +842,16 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type, } } - dd_dev_info(dd, - "Send context %u(%u) %s group %u credits %u credit_ctrl 0x%llx threshold %u\n", - sw_index, - hw_context, - sc_type_name(type), - sc->group, - sc->credits, - sc->credit_ctrl, - thresh); + hfi1_cdbg(PIO, + "Send context %u(%u) %s group %u credits %u credit_ctrl 0x%llx threshold %u\n", + sw_index, + hw_context, + sc_type_name(type), + sc->group, + sc->credits, + sc->credit_ctrl, + thresh); + return sc; } @@ -865,6 +893,7 @@ void sc_free(struct send_context *sc) spin_unlock_irqrestore(&dd->sc_lock, flags); kfree(sc->sr); + free_percpu(sc->buffers_allocated); kfree(sc); } @@ -1028,7 +1057,7 @@ int sc_restart(struct send_context *sc) /* kernel context */ loop = 0; while (1) { - count = atomic_read(&sc->buffers_allocated); + count = get_buffers_allocated(sc); if (count == 0) break; if (loop > 100) { @@ -1196,7 +1225,8 @@ int sc_enable(struct send_context *sc) sc->sr_head = 0; sc->sr_tail = 0; sc->flags = 0; - atomic_set(&sc->buffers_allocated, 0); + /* the alloc lock insures no fast path allocation */ + reset_buffers_allocated(sc); /* * Clear all per-context errors. Some of these will be set when @@ -1372,7 +1402,8 @@ retry: /* there is enough room */ - atomic_inc(&sc->buffers_allocated); + preempt_disable(); + this_cpu_inc(*sc->buffers_allocated); /* read this once */ head = sc->sr_head; @@ -1564,6 +1595,7 @@ void sc_release_update(struct send_context *sc) u64 hw_free; u32 head, tail; unsigned long old_free; + unsigned long free; unsigned long extra; unsigned long flags; int code; @@ -1578,7 +1610,7 @@ void sc_release_update(struct send_context *sc) extra = (((hw_free & CR_COUNTER_SMASK) >> CR_COUNTER_SHIFT) - (old_free & CR_COUNTER_MASK)) & CR_COUNTER_MASK; - sc->free = old_free + extra; + free = old_free + extra; trace_hfi1_piofree(sc, extra); /* call sent buffer callbacks */ @@ -1588,7 +1620,7 @@ void sc_release_update(struct send_context *sc) while (head != tail) { pbuf = &sc->sr[tail].pbuf; - if (sent_before(sc->free, pbuf->sent_at)) { + if (sent_before(free, pbuf->sent_at)) { /* not sent yet */ break; } @@ -1602,8 +1634,10 @@ void sc_release_update(struct send_context *sc) if (tail >= sc->sr_size) tail = 0; } - /* update tail, in case we moved it */ sc->sr_tail = tail; + /* make sure tail is updated before free */ + smp_wmb(); + sc->free = free; spin_unlock_irqrestore(&sc->release_lock, flags); sc_piobufavail(sc); } diff --git a/drivers/staging/rdma/hfi1/pio.h b/drivers/staging/rdma/hfi1/pio.h index 0bb885ca3cfb..53d3e0a79375 100644 --- a/drivers/staging/rdma/hfi1/pio.h +++ b/drivers/staging/rdma/hfi1/pio.h @@ -130,7 +130,7 @@ struct send_context { spinlock_t credit_ctrl_lock ____cacheline_aligned_in_smp; u64 credit_ctrl; /* cache for credit control */ u32 credit_intr_count; /* count of credit intr users */ - atomic_t buffers_allocated; /* count of buffers allocated */ + u32 __percpu *buffers_allocated;/* count of buffers allocated */ wait_queue_head_t halt_wait; /* wait until kernel sees interrupt */ }; diff --git a/drivers/staging/rdma/hfi1/pio_copy.c b/drivers/staging/rdma/hfi1/pio_copy.c index 8972bbc02038..ebb0bafc68cb 100644 --- a/drivers/staging/rdma/hfi1/pio_copy.c +++ b/drivers/staging/rdma/hfi1/pio_copy.c @@ -160,7 +160,8 @@ void pio_copy(struct hfi1_devdata *dd, struct pio_buf *pbuf, u64 pbc, } /* finished with this buffer */ - atomic_dec(&pbuf->sc->buffers_allocated); + this_cpu_dec(*pbuf->sc->buffers_allocated); + preempt_enable(); } /* USE_SHIFTS is faster in user-space tests on a Xeon X5570 @ 2.93GHz */ @@ -854,5 +855,6 @@ void seg_pio_copy_end(struct pio_buf *pbuf) } /* finished with this buffer */ - atomic_dec(&pbuf->sc->buffers_allocated); + this_cpu_dec(*pbuf->sc->buffers_allocated); + preempt_enable(); } diff --git a/drivers/staging/rdma/hfi1/qp.c b/drivers/staging/rdma/hfi1/qp.c index f8c36166962f..ce036810d576 100644 --- a/drivers/staging/rdma/hfi1/qp.c +++ b/drivers/staging/rdma/hfi1/qp.c @@ -378,6 +378,7 @@ static void reset_qp(struct hfi1_qp *qp, enum ib_qp_type type) } qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE; qp->r_nak_state = 0; + qp->r_adefered = 0; qp->r_aflags = 0; qp->r_flags = 0; qp->s_head = 0; @@ -617,7 +618,7 @@ int hfi1_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int mig = 0; int ret; u32 pmtu = 0; /* for gcc warning only */ - struct hfi1_devdata *dd; + struct hfi1_devdata *dd = dd_from_dev(dev); spin_lock_irq(&qp->r_lock); spin_lock(&qp->s_lock); @@ -631,23 +632,35 @@ int hfi1_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, goto inval; if (attr_mask & IB_QP_AV) { + u8 sc; + if (attr->ah_attr.dlid >= HFI1_MULTICAST_LID_BASE) goto inval; if (hfi1_check_ah(qp->ibqp.device, &attr->ah_attr)) goto inval; + sc = ah_to_sc(ibqp->device, &attr->ah_attr); + if (!qp_to_sdma_engine(qp, sc) && + dd->flags & HFI1_HAS_SEND_DMA) + goto inval; } if (attr_mask & IB_QP_ALT_PATH) { + u8 sc; + if (attr->alt_ah_attr.dlid >= HFI1_MULTICAST_LID_BASE) goto inval; if (hfi1_check_ah(qp->ibqp.device, &attr->alt_ah_attr)) goto inval; - if (attr->alt_pkey_index >= hfi1_get_npkeys(dd_from_dev(dev))) + if (attr->alt_pkey_index >= hfi1_get_npkeys(dd)) + goto inval; + sc = ah_to_sc(ibqp->device, &attr->alt_ah_attr); + if (!qp_to_sdma_engine(qp, sc) && + dd->flags & HFI1_HAS_SEND_DMA) goto inval; } if (attr_mask & IB_QP_PKEY_INDEX) - if (attr->pkey_index >= hfi1_get_npkeys(dd_from_dev(dev))) + if (attr->pkey_index >= hfi1_get_npkeys(dd)) goto inval; if (attr_mask & IB_QP_MIN_RNR_TIMER) @@ -792,6 +805,8 @@ int hfi1_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, qp->remote_ah_attr = attr->ah_attr; qp->s_srate = attr->ah_attr.static_rate; qp->srate_mbps = ib_rate_to_mbps(qp->s_srate); + qp->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr); + qp->s_sde = qp_to_sdma_engine(qp, qp->s_sc); } if (attr_mask & IB_QP_ALT_PATH) { @@ -806,6 +821,8 @@ int hfi1_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, qp->port_num = qp->alt_ah_attr.port_num; qp->s_pkey_index = qp->s_alt_pkey_index; qp->s_flags |= HFI1_S_AHG_CLEAR; + qp->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr); + qp->s_sde = qp_to_sdma_engine(qp, qp->s_sc); } } @@ -1528,9 +1545,6 @@ struct sdma_engine *qp_to_sdma_engine(struct hfi1_qp *qp, u8 sc5) if (!(dd->flags & HFI1_HAS_SEND_DMA)) return NULL; switch (qp->ibqp.qp_type) { - case IB_QPT_UC: - case IB_QPT_RC: - break; case IB_QPT_SMI: return NULL; default: @@ -1685,3 +1699,25 @@ void qp_comm_est(struct hfi1_qp *qp) qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); } } + +/* + * Switch to alternate path. + * The QP s_lock should be held and interrupts disabled. + */ +void hfi1_migrate_qp(struct hfi1_qp *qp) +{ + struct ib_event ev; + + qp->s_mig_state = IB_MIG_MIGRATED; + qp->remote_ah_attr = qp->alt_ah_attr; + qp->port_num = qp->alt_ah_attr.port_num; + qp->s_pkey_index = qp->s_alt_pkey_index; + qp->s_flags |= HFI1_S_AHG_CLEAR; + qp->s_sc = ah_to_sc(qp->ibqp.device, &qp->remote_ah_attr); + qp->s_sde = qp_to_sdma_engine(qp, qp->s_sc); + + ev.device = qp->ibqp.device; + ev.element.qp = &qp->ibqp; + ev.event = IB_EVENT_PATH_MIG; + qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); +} diff --git a/drivers/staging/rdma/hfi1/qp.h b/drivers/staging/rdma/hfi1/qp.h index b9c1575990aa..62a94c5d7dca 100644 --- a/drivers/staging/rdma/hfi1/qp.h +++ b/drivers/staging/rdma/hfi1/qp.h @@ -128,7 +128,6 @@ static inline void clear_ahg(struct hfi1_qp *qp) if (qp->s_sde && qp->s_ahgidx >= 0) sdma_ahg_free(qp->s_sde, qp->s_ahgidx); qp->s_ahgidx = -1; - qp->s_sde = NULL; } /** @@ -212,7 +211,7 @@ int hfi1_qp_init(struct hfi1_ibdev *dev); void hfi1_qp_exit(struct hfi1_ibdev *dev); /** - * hfi1_qp_waitup - wake up on the indicated event + * hfi1_qp_wakeup - wake up on the indicated event * @qp: the QP * @flag: flag the qp on which the qp is stalled */ @@ -223,19 +222,19 @@ struct sdma_engine *qp_to_sdma_engine(struct hfi1_qp *qp, u8 sc5); struct qp_iter; /** - * qp_iter_init - wake up on the indicated event + * qp_iter_init - initialize the iterator for the qp hash list * @dev: the hfi1_ibdev */ struct qp_iter *qp_iter_init(struct hfi1_ibdev *dev); /** - * qp_iter_next - wakeup on the indicated event + * qp_iter_next - Find the next qp in the hash list * @iter: the iterator for the qp hash list */ int qp_iter_next(struct qp_iter *iter); /** - * qp_iter_next - wake up on the indicated event + * qp_iter_print - print the qp information to seq_file * @s: the seq_file to emit the qp information on * @iter: the iterator for the qp hash list */ @@ -247,4 +246,41 @@ void qp_iter_print(struct seq_file *s, struct qp_iter *iter); */ void qp_comm_est(struct hfi1_qp *qp); +/** + * _hfi1_schedule_send - schedule progress + * @qp: the QP + * + * This schedules qp progress w/o regard to the s_flags. + * + * It is only used in the post send, which doesn't hold + * the s_lock. + */ +static inline void _hfi1_schedule_send(struct hfi1_qp *qp) +{ + struct hfi1_ibport *ibp = + to_iport(qp->ibqp.device, qp->port_num); + struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); + struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device); + + iowait_schedule(&qp->s_iowait, ppd->hfi1_wq, + qp->s_sde ? + qp->s_sde->cpu : + cpumask_first(cpumask_of_node(dd->assigned_node_id))); +} + +/** + * hfi1_schedule_send - schedule progress + * @qp: the QP + * + * This schedules qp progress and caller should hold + * the s_lock. + */ +static inline void hfi1_schedule_send(struct hfi1_qp *qp) +{ + if (hfi1_send_ok(qp)) + _hfi1_schedule_send(qp); +} + +void hfi1_migrate_qp(struct hfi1_qp *qp); + #endif /* _QP_H */ diff --git a/drivers/staging/rdma/hfi1/qsfp.c b/drivers/staging/rdma/hfi1/qsfp.c index ffdb1d787a80..6326a915d7fd 100644 --- a/drivers/staging/rdma/hfi1/qsfp.c +++ b/drivers/staging/rdma/hfi1/qsfp.c @@ -475,7 +475,7 @@ int qsfp_dump(struct hfi1_pportdata *ppd, char *buf, int len) u8 *cache = &ppd->qsfp_info.cache[0]; u8 bin_buff[QSFP_DUMP_CHUNK]; char lenstr[6]; - int sofar, ret; + int sofar; int bidx = 0; u8 *atten = &cache[QSFP_ATTEN_OFFS]; u8 *vendor_oui = &cache[QSFP_VOUI_OFFS]; @@ -536,6 +536,5 @@ int qsfp_dump(struct hfi1_pportdata *ppd, char *buf, int len) bidx += QSFP_DUMP_CHUNK; } } - ret = sofar; - return ret; + return sofar; } diff --git a/drivers/staging/rdma/hfi1/rc.c b/drivers/staging/rdma/hfi1/rc.c index 5fc93bb312f1..6f4a155f7931 100644 --- a/drivers/staging/rdma/hfi1/rc.c +++ b/drivers/staging/rdma/hfi1/rc.c @@ -1608,6 +1608,27 @@ bail: return; } +static inline void rc_defered_ack(struct hfi1_ctxtdata *rcd, + struct hfi1_qp *qp) +{ + if (list_empty(&qp->rspwait)) { + qp->r_flags |= HFI1_R_RSP_DEFERED_ACK; + atomic_inc(&qp->refcount); + list_add_tail(&qp->rspwait, &rcd->qp_wait_list); + } +} + +static inline void rc_cancel_ack(struct hfi1_qp *qp) +{ + qp->r_adefered = 0; + if (list_empty(&qp->rspwait)) + return; + list_del_init(&qp->rspwait); + qp->r_flags &= ~HFI1_R_RSP_DEFERED_ACK; + if (atomic_dec_and_test(&qp->refcount)) + wake_up(&qp->wait); +} + /** * rc_rcv_error - process an incoming duplicate or error RC packet * @ohdr: the other headers for this packet @@ -1650,11 +1671,7 @@ static noinline int rc_rcv_error(struct hfi1_other_headers *ohdr, void *data, * in the receive queue have been processed. * Otherwise, we end up propagating congestion. */ - if (list_empty(&qp->rspwait)) { - qp->r_flags |= HFI1_R_RSP_NAK; - atomic_inc(&qp->refcount); - list_add_tail(&qp->rspwait, &rcd->qp_wait_list); - } + rc_defered_ack(rcd, qp); } goto done; } @@ -1978,7 +1995,7 @@ void hfi1_rc_rcv(struct hfi1_packet *packet) } psn = be32_to_cpu(ohdr->bth[2]); - opcode = bth0 >> 24; + opcode = (bth0 >> 24) & 0xff; /* * Process responses (ACKs) before anything else. Note that the @@ -2329,19 +2346,29 @@ send_last: qp->r_ack_psn = psn; qp->r_nak_state = 0; /* Send an ACK if requested or required. */ - if (psn & (1 << 31)) - goto send_ack; + if (psn & IB_BTH_REQ_ACK) { + if (packet->numpkt == 0) { + rc_cancel_ack(qp); + goto send_ack; + } + if (qp->r_adefered >= HFI1_PSN_CREDIT) { + rc_cancel_ack(qp); + goto send_ack; + } + if (unlikely(is_fecn)) { + rc_cancel_ack(qp); + goto send_ack; + } + qp->r_adefered++; + rc_defered_ack(rcd, qp); + } return; rnr_nak: qp->r_nak_state = IB_RNR_NAK | qp->r_min_rnr_timer; qp->r_ack_psn = qp->r_psn; /* Queue RNR NAK for later */ - if (list_empty(&qp->rspwait)) { - qp->r_flags |= HFI1_R_RSP_NAK; - atomic_inc(&qp->refcount); - list_add_tail(&qp->rspwait, &rcd->qp_wait_list); - } + rc_defered_ack(rcd, qp); return; nack_op_err: @@ -2349,11 +2376,7 @@ nack_op_err: qp->r_nak_state = IB_NAK_REMOTE_OPERATIONAL_ERROR; qp->r_ack_psn = qp->r_psn; /* Queue NAK for later */ - if (list_empty(&qp->rspwait)) { - qp->r_flags |= HFI1_R_RSP_NAK; - atomic_inc(&qp->refcount); - list_add_tail(&qp->rspwait, &rcd->qp_wait_list); - } + rc_defered_ack(rcd, qp); return; nack_inv_unlck: @@ -2363,11 +2386,7 @@ nack_inv: qp->r_nak_state = IB_NAK_INVALID_REQUEST; qp->r_ack_psn = qp->r_psn; /* Queue NAK for later */ - if (list_empty(&qp->rspwait)) { - qp->r_flags |= HFI1_R_RSP_NAK; - atomic_inc(&qp->refcount); - list_add_tail(&qp->rspwait, &rcd->qp_wait_list); - } + rc_defered_ack(rcd, qp); return; nack_acc_unlck: @@ -2391,19 +2410,19 @@ void hfi1_rc_hdrerr( struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); int diff; u32 opcode; - u32 psn; + u32 psn, bth0; /* Check for GRH */ ohdr = &hdr->u.oth; if (has_grh) ohdr = &hdr->u.l.oth; - opcode = be32_to_cpu(ohdr->bth[0]); - if (hfi1_ruc_check_hdr(ibp, hdr, has_grh, qp, opcode)) + bth0 = be32_to_cpu(ohdr->bth[0]); + if (hfi1_ruc_check_hdr(ibp, hdr, has_grh, qp, bth0)) return; psn = be32_to_cpu(ohdr->bth[2]); - opcode >>= 24; + opcode = (bth0 >> 24) & 0xff; /* Only deal with RDMA Writes for now */ if (opcode < IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST) { @@ -2421,13 +2440,7 @@ void hfi1_rc_hdrerr( * Otherwise, we end up * propagating congestion. */ - if (list_empty(&qp->rspwait)) { - qp->r_flags |= HFI1_R_RSP_NAK; - atomic_inc(&qp->refcount); - list_add_tail( - &qp->rspwait, - &rcd->qp_wait_list); - } + rc_defered_ack(rcd, qp); } /* Out of sequence NAK */ } /* QP Request NAKs */ } diff --git a/drivers/staging/rdma/hfi1/ruc.c b/drivers/staging/rdma/hfi1/ruc.c index 49bc9fd7a51a..4a91975b68d7 100644 --- a/drivers/staging/rdma/hfi1/ruc.c +++ b/drivers/staging/rdma/hfi1/ruc.c @@ -241,26 +241,6 @@ bail: return ret; } -/* - * Switch to alternate path. - * The QP s_lock should be held and interrupts disabled. - */ -void hfi1_migrate_qp(struct hfi1_qp *qp) -{ - struct ib_event ev; - - qp->s_mig_state = IB_MIG_MIGRATED; - qp->remote_ah_attr = qp->alt_ah_attr; - qp->port_num = qp->alt_ah_attr.port_num; - qp->s_pkey_index = qp->s_alt_pkey_index; - qp->s_flags |= HFI1_S_AHG_CLEAR; - - ev.device = qp->ibqp.device; - ev.element.qp = &qp->ibqp; - ev.event = IB_EVENT_PATH_MIG; - qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); -} - static __be64 get_sguid(struct hfi1_ibport *ibp, unsigned index) { if (!index) { @@ -308,11 +288,12 @@ int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_ib_header *hdr, } if (unlikely(rcv_pkey_check(ppd_from_ibp(ibp), (u16)bth0, sc5, be16_to_cpu(hdr->lrh[3])))) { - hfi1_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_PKEY, + hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY, (u16)bth0, (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF, 0, qp->ibqp.qp_num, - hdr->lrh[3], hdr->lrh[1]); + be16_to_cpu(hdr->lrh[3]), + be16_to_cpu(hdr->lrh[1])); goto err; } /* Validate the SLID. See Ch. 9.6.1.5 and 17.2.8 */ @@ -340,11 +321,12 @@ int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_ib_header *hdr, } if (unlikely(rcv_pkey_check(ppd_from_ibp(ibp), (u16)bth0, sc5, be16_to_cpu(hdr->lrh[3])))) { - hfi1_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_PKEY, + hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY, (u16)bth0, (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF, 0, qp->ibqp.qp_num, - hdr->lrh[3], hdr->lrh[1]); + be16_to_cpu(hdr->lrh[3]), + be16_to_cpu(hdr->lrh[1])); goto err; } /* Validate the SLID. See Ch. 9.6.1.5 */ @@ -714,11 +696,8 @@ static inline void build_ahg(struct hfi1_qp *qp, u32 npsn) clear_ahg(qp); if (!(qp->s_flags & HFI1_S_AHG_VALID)) { /* first middle that needs copy */ - if (qp->s_ahgidx < 0) { - if (!qp->s_sde) - qp->s_sde = qp_to_sdma_engine(qp, qp->s_sc); + if (qp->s_ahgidx < 0) qp->s_ahgidx = sdma_ahg_alloc(qp->s_sde); - } if (qp->s_ahgidx >= 0) { qp->s_ahgpsn = npsn; qp->s_hdr->tx_flags |= SDMA_TXREQ_F_AHG_COPY; @@ -761,7 +740,6 @@ void hfi1_make_ruc_header(struct hfi1_qp *qp, struct hfi1_other_headers *ohdr, u16 lrh0; u32 nwords; u32 extra_bytes; - u8 sc5; u32 bth1; /* Construct the header. */ @@ -775,9 +753,7 @@ void hfi1_make_ruc_header(struct hfi1_qp *qp, struct hfi1_other_headers *ohdr, lrh0 = HFI1_LRH_GRH; middle = 0; } - sc5 = ibp->sl_to_sc[qp->remote_ah_attr.sl]; - lrh0 |= (sc5 & 0xf) << 12 | (qp->remote_ah_attr.sl & 0xf) << 4; - qp->s_sc = sc5; + lrh0 |= (qp->s_sc & 0xf) << 12 | (qp->remote_ah_attr.sl & 0xf) << 4; /* * reset s_hdr/AHG fields * @@ -835,16 +811,20 @@ void hfi1_do_send(struct work_struct *work) { struct iowait *wait = container_of(work, struct iowait, iowork); struct hfi1_qp *qp = container_of(wait, struct hfi1_qp, s_iowait); - struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); - struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); + struct hfi1_pkt_state ps; int (*make_req)(struct hfi1_qp *qp); unsigned long flags; unsigned long timeout; + ps.dev = to_idev(qp->ibqp.device); + ps.ibp = to_iport(qp->ibqp.device, qp->port_num); + ps.ppd = ppd_from_ibp(ps.ibp); + if ((qp->ibqp.qp_type == IB_QPT_RC || qp->ibqp.qp_type == IB_QPT_UC) && !loopback && - (qp->remote_ah_attr.dlid & ~((1 << ppd->lmc) - 1)) == ppd->lid) { + (qp->remote_ah_attr.dlid & ~((1 << ps.ppd->lmc) - 1)) == + ps.ppd->lid) { ruc_loopback(qp); return; } @@ -876,8 +856,7 @@ void hfi1_do_send(struct work_struct *work) * If the packet cannot be sent now, return and * the send tasklet will be woken up later. */ - if (hfi1_verbs_send(qp, qp->s_hdr, qp->s_hdrwords, - qp->s_cur_sge, qp->s_cur_size)) + if (hfi1_verbs_send(qp, &ps)) break; /* Record that s_hdr is empty. */ qp->s_hdrwords = 0; @@ -886,7 +865,7 @@ void hfi1_do_send(struct work_struct *work) /* allow other tasks to run */ if (unlikely(time_after(jiffies, timeout))) { cond_resched(); - ppd->dd->verbs_dev.n_send_schedule++; + ps.ppd->dd->verbs_dev.n_send_schedule++; timeout = jiffies + SEND_RESCHED_TIMEOUT; } } while (make_req(qp)); diff --git a/drivers/staging/rdma/hfi1/sdma.c b/drivers/staging/rdma/hfi1/sdma.c index 2a1da2189900..9a15f1f32b45 100644 --- a/drivers/staging/rdma/hfi1/sdma.c +++ b/drivers/staging/rdma/hfi1/sdma.c @@ -236,7 +236,6 @@ static void sdma_hw_clean_up_task(unsigned long); static void sdma_put(struct sdma_state *); static void sdma_set_state(struct sdma_engine *, enum sdma_states); static void sdma_start_hw_clean_up(struct sdma_engine *); -static void sdma_start_sw_clean_up(struct sdma_engine *); static void sdma_sw_clean_up_task(unsigned long); static void sdma_sendctrl(struct sdma_engine *, unsigned); static void init_sdma_regs(struct sdma_engine *, u32, uint); @@ -470,12 +469,6 @@ static void sdma_err_halt_wait(struct work_struct *work) sdma_process_event(sde, sdma_event_e15_hw_halt_done); } -static void sdma_start_err_halt_wait(struct sdma_engine *sde) -{ - schedule_work(&sde->err_halt_worker); -} - - static void sdma_err_progress_check_schedule(struct sdma_engine *sde) { if (!is_bx(sde->dd) && HFI1_CAP_IS_KSET(SDMA_AHG)) { @@ -682,11 +675,6 @@ static void sdma_start_hw_clean_up(struct sdma_engine *sde) tasklet_hi_schedule(&sde->sdma_hw_clean_up_task); } -static void sdma_start_sw_clean_up(struct sdma_engine *sde) -{ - tasklet_hi_schedule(&sde->sdma_sw_clean_up_task); -} - static void sdma_set_state(struct sdma_engine *sde, enum sdma_states next_state) { @@ -777,19 +765,27 @@ struct sdma_engine *sdma_select_engine_vl( struct sdma_map_elem *e; struct sdma_engine *rval; - if (WARN_ON(vl > 8)) - return NULL; + /* NOTE This should only happen if SC->VL changed after the initial + * checks on the QP/AH + * Default will return engine 0 below + */ + if (vl >= num_vls) { + rval = NULL; + goto done; + } rcu_read_lock(); m = rcu_dereference(dd->sdma_map); if (unlikely(!m)) { rcu_read_unlock(); - return NULL; + return &dd->per_sdma[0]; } e = m->map[vl & m->mask]; rval = e->sde[selector & e->mask]; rcu_read_unlock(); +done: + rval = !rval ? &dd->per_sdma[0] : rval; trace_hfi1_sdma_engine_select(dd, selector, vl, rval->this_idx); return rval; } @@ -1874,7 +1870,7 @@ static void dump_sdma_state(struct sdma_engine *sde) } #define SDE_FMT \ - "SDE %u STE %s C 0x%llx S 0x%016llx E 0x%llx T(HW) 0x%llx T(SW) 0x%x H(HW) 0x%llx H(SW) 0x%x H(D) 0x%llx DM 0x%llx GL 0x%llx R 0x%llx LIS 0x%llx AHGI 0x%llx TXT %u TXH %u DT %u DH %u FLNE %d DQF %u SLC 0x%llx\n" + "SDE %u CPU %d STE %s C 0x%llx S 0x%016llx E 0x%llx T(HW) 0x%llx T(SW) 0x%x H(HW) 0x%llx H(SW) 0x%x H(D) 0x%llx DM 0x%llx GL 0x%llx R 0x%llx LIS 0x%llx AHGI 0x%llx TXT %u TXH %u DT %u DH %u FLNE %d DQF %u SLC 0x%llx\n" /** * sdma_seqfile_dump_sde() - debugfs dump of sde * @s: seq file @@ -1894,6 +1890,7 @@ void sdma_seqfile_dump_sde(struct seq_file *s, struct sdma_engine *sde) head = sde->descq_head & sde->sdma_mask; tail = ACCESS_ONCE(sde->descq_tail) & sde->sdma_mask; seq_printf(s, SDE_FMT, sde->this_idx, + sde->cpu, sdma_state_name(sde->state.current_state), (unsigned long long)read_sde_csr(sde, SD(CTRL)), (unsigned long long)read_sde_csr(sde, SD(STATUS)), @@ -2308,7 +2305,7 @@ static void __sdma_process_event(struct sdma_engine *sde, case sdma_event_e50_hw_cleaned: break; case sdma_event_e60_hw_halted: - sdma_start_err_halt_wait(sde); + schedule_work(&sde->err_halt_worker); break; case sdma_event_e70_go_idle: ss->go_s99_running = 0; @@ -2389,7 +2386,7 @@ static void __sdma_process_event(struct sdma_engine *sde, break; case sdma_event_e60_hw_halted: sdma_set_state(sde, sdma_state_s50_hw_halt_wait); - sdma_start_err_halt_wait(sde); + schedule_work(&sde->err_halt_worker); break; case sdma_event_e70_go_idle: break; @@ -2452,7 +2449,7 @@ static void __sdma_process_event(struct sdma_engine *sde, switch (event) { case sdma_event_e00_go_hw_down: sdma_set_state(sde, sdma_state_s00_hw_down); - sdma_start_sw_clean_up(sde); + tasklet_hi_schedule(&sde->sdma_sw_clean_up_task); break; case sdma_event_e10_go_hw_start: break; @@ -2494,13 +2491,13 @@ static void __sdma_process_event(struct sdma_engine *sde, switch (event) { case sdma_event_e00_go_hw_down: sdma_set_state(sde, sdma_state_s00_hw_down); - sdma_start_sw_clean_up(sde); + tasklet_hi_schedule(&sde->sdma_sw_clean_up_task); break; case sdma_event_e10_go_hw_start: break; case sdma_event_e15_hw_halt_done: sdma_set_state(sde, sdma_state_s30_sw_clean_up_wait); - sdma_start_sw_clean_up(sde); + tasklet_hi_schedule(&sde->sdma_sw_clean_up_task); break; case sdma_event_e25_hw_clean_up_done: break; @@ -2512,7 +2509,7 @@ static void __sdma_process_event(struct sdma_engine *sde, case sdma_event_e50_hw_cleaned: break; case sdma_event_e60_hw_halted: - sdma_start_err_halt_wait(sde); + schedule_work(&sde->err_halt_worker); break; case sdma_event_e70_go_idle: ss->go_s99_running = 0; @@ -2535,13 +2532,13 @@ static void __sdma_process_event(struct sdma_engine *sde, switch (event) { case sdma_event_e00_go_hw_down: sdma_set_state(sde, sdma_state_s00_hw_down); - sdma_start_sw_clean_up(sde); + tasklet_hi_schedule(&sde->sdma_sw_clean_up_task); break; case sdma_event_e10_go_hw_start: break; case sdma_event_e15_hw_halt_done: sdma_set_state(sde, sdma_state_s30_sw_clean_up_wait); - sdma_start_sw_clean_up(sde); + tasklet_hi_schedule(&sde->sdma_sw_clean_up_task); break; case sdma_event_e25_hw_clean_up_done: break; @@ -2553,7 +2550,7 @@ static void __sdma_process_event(struct sdma_engine *sde, case sdma_event_e50_hw_cleaned: break; case sdma_event_e60_hw_halted: - sdma_start_err_halt_wait(sde); + schedule_work(&sde->err_halt_worker); break; case sdma_event_e70_go_idle: ss->go_s99_running = 0; @@ -2575,7 +2572,7 @@ static void __sdma_process_event(struct sdma_engine *sde, switch (event) { case sdma_event_e00_go_hw_down: sdma_set_state(sde, sdma_state_s00_hw_down); - sdma_start_sw_clean_up(sde); + tasklet_hi_schedule(&sde->sdma_sw_clean_up_task); break; case sdma_event_e10_go_hw_start: break; @@ -2599,7 +2596,7 @@ static void __sdma_process_event(struct sdma_engine *sde, break; case sdma_event_e81_hw_frozen: sdma_set_state(sde, sdma_state_s82_freeze_sw_clean); - sdma_start_sw_clean_up(sde); + tasklet_hi_schedule(&sde->sdma_sw_clean_up_task); break; case sdma_event_e82_hw_unfreeze: break; @@ -2614,7 +2611,7 @@ static void __sdma_process_event(struct sdma_engine *sde, switch (event) { case sdma_event_e00_go_hw_down: sdma_set_state(sde, sdma_state_s00_hw_down); - sdma_start_sw_clean_up(sde); + tasklet_hi_schedule(&sde->sdma_sw_clean_up_task); break; case sdma_event_e10_go_hw_start: break; @@ -2658,7 +2655,7 @@ static void __sdma_process_event(struct sdma_engine *sde, switch (event) { case sdma_event_e00_go_hw_down: sdma_set_state(sde, sdma_state_s00_hw_down); - sdma_start_sw_clean_up(sde); + tasklet_hi_schedule(&sde->sdma_sw_clean_up_task); break; case sdma_event_e10_go_hw_start: break; @@ -2681,7 +2678,7 @@ static void __sdma_process_event(struct sdma_engine *sde, * progress check */ sdma_set_state(sde, sdma_state_s50_hw_halt_wait); - sdma_start_err_halt_wait(sde); + schedule_work(&sde->err_halt_worker); break; case sdma_event_e70_go_idle: sdma_set_state(sde, sdma_state_s60_idle_halt_wait); @@ -2734,22 +2731,21 @@ static int _extend_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx) tx->coalesce_buf = kmalloc(tx->tlen + sizeof(u32), GFP_ATOMIC); if (!tx->coalesce_buf) - return -ENOMEM; - + goto enomem; tx->coalesce_idx = 0; } return 0; } if (unlikely(tx->num_desc == MAX_DESC)) - return -ENOMEM; + goto enomem; tx->descp = kmalloc_array( MAX_DESC, sizeof(struct sdma_desc), GFP_ATOMIC); if (!tx->descp) - return -ENOMEM; + goto enomem; /* reserve last descriptor for coalescing */ tx->desc_limit = MAX_DESC - 1; @@ -2757,6 +2753,9 @@ static int _extend_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx) for (i = 0; i < tx->num_desc; i++) tx->descp[i] = tx->descs[i]; return 0; +enomem: + sdma_txclean(dd, tx); + return -ENOMEM; } /* diff --git a/drivers/staging/rdma/hfi1/sdma.h b/drivers/staging/rdma/hfi1/sdma.h index cc22d2ee2054..da89e6458162 100644 --- a/drivers/staging/rdma/hfi1/sdma.h +++ b/drivers/staging/rdma/hfi1/sdma.h @@ -410,8 +410,6 @@ struct sdma_engine { u64 idle_mask; u64 progress_mask; /* private: */ - struct workqueue_struct *wq; - /* private: */ volatile __le64 *head_dma; /* DMA'ed by chip */ /* private: */ dma_addr_t head_phys; @@ -426,6 +424,8 @@ struct sdma_engine { u32 sdma_mask; /* private */ struct sdma_state state; + /* private */ + int cpu; /* private: */ u8 sdma_shift; /* private: */ @@ -774,10 +774,13 @@ static inline int _sdma_txadd_daddr( tx->tlen -= len; /* special cases for last */ if (!tx->tlen) { - if (tx->packet_len & (sizeof(u32) - 1)) + if (tx->packet_len & (sizeof(u32) - 1)) { rval = _pad_sdma_tx_descs(dd, tx); - else + if (rval) + return rval; + } else { _sdma_close_tx(dd, tx); + } } tx->num_desc++; return rval; @@ -990,7 +993,9 @@ static inline void sdma_iowait_schedule( struct sdma_engine *sde, struct iowait *wait) { - iowait_schedule(wait, sde->wq); + struct hfi1_pportdata *ppd = sde->dd->pport; + + iowait_schedule(wait, ppd->hfi1_wq, sde->cpu); } /* for use by interrupt handling */ diff --git a/drivers/staging/rdma/hfi1/trace.c b/drivers/staging/rdma/hfi1/trace.c index f55b75194847..10122e84cb2f 100644 --- a/drivers/staging/rdma/hfi1/trace.c +++ b/drivers/staging/rdma/hfi1/trace.c @@ -67,7 +67,7 @@ u8 ibhdr_exhdr_len(struct hfi1_ib_header *hdr) #define IMM_PRN "imm %d" #define RETH_PRN "reth vaddr 0x%.16llx rkey 0x%.8x dlen 0x%.8x" -#define AETH_PRN "aeth syn 0x%.2x msn 0x%.8x" +#define AETH_PRN "aeth syn 0x%.2x %s msn 0x%.8x" #define DETH_PRN "deth qkey 0x%.8x sqpn 0x%.6x" #define ATOMICACKETH_PRN "origdata %lld" #define ATOMICETH_PRN "vaddr 0x%llx rkey 0x%.8x sdata %lld cdata %lld" @@ -79,6 +79,19 @@ static u64 ib_u64_get(__be32 *p) return ((u64)be32_to_cpu(p[0]) << 32) | be32_to_cpu(p[1]); } +static const char *parse_syndrome(u8 syndrome) +{ + switch (syndrome >> 5) { + case 0: + return "ACK"; + case 1: + return "RNRNAK"; + case 3: + return "NAK"; + } + return ""; +} + const char *parse_everbs_hdrs( struct trace_seq *p, u8 opcode, @@ -124,16 +137,18 @@ const char *parse_everbs_hdrs( case OP(RC, RDMA_READ_RESPONSE_LAST): case OP(RC, RDMA_READ_RESPONSE_ONLY): case OP(RC, ACKNOWLEDGE): - trace_seq_printf(p, AETH_PRN, - be32_to_cpu(eh->aeth) >> 24, - be32_to_cpu(eh->aeth) & HFI1_MSN_MASK); + trace_seq_printf(p, AETH_PRN, be32_to_cpu(eh->aeth) >> 24, + parse_syndrome(be32_to_cpu(eh->aeth) >> 24), + be32_to_cpu(eh->aeth) & HFI1_MSN_MASK); break; /* aeth + atomicacketh */ case OP(RC, ATOMIC_ACKNOWLEDGE): trace_seq_printf(p, AETH_PRN " " ATOMICACKETH_PRN, - (be32_to_cpu(eh->at.aeth) >> 24) & 0xff, - be32_to_cpu(eh->at.aeth) & HFI1_MSN_MASK, - (unsigned long long)ib_u64_get(eh->at.atomic_ack_eth)); + be32_to_cpu(eh->at.aeth) >> 24, + parse_syndrome(be32_to_cpu(eh->at.aeth) >> 24), + be32_to_cpu(eh->at.aeth) & HFI1_MSN_MASK, + (unsigned long long) + ib_u64_get(eh->at.atomic_ack_eth)); break; /* atomiceth */ case OP(RC, COMPARE_SWAP): diff --git a/drivers/staging/rdma/hfi1/trace.h b/drivers/staging/rdma/hfi1/trace.h index 57430295c404..86c12ebfd4f0 100644 --- a/drivers/staging/rdma/hfi1/trace.h +++ b/drivers/staging/rdma/hfi1/trace.h @@ -417,7 +417,8 @@ __print_symbolic(opcode, \ ib_opcode_name(UC_RDMA_WRITE_ONLY), \ ib_opcode_name(UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE), \ ib_opcode_name(UD_SEND_ONLY), \ - ib_opcode_name(UD_SEND_ONLY_WITH_IMMEDIATE)) + ib_opcode_name(UD_SEND_ONLY_WITH_IMMEDIATE), \ + ib_opcode_name(CNP)) #define LRH_PRN "vl %d lver %d sl %d lnh %d,%s dlid %.4x len %d slid %.4x" diff --git a/drivers/staging/rdma/hfi1/uc.c b/drivers/staging/rdma/hfi1/uc.c index 6095039c4485..4f2a7889a852 100644 --- a/drivers/staging/rdma/hfi1/uc.c +++ b/drivers/staging/rdma/hfi1/uc.c @@ -268,7 +268,7 @@ void hfi1_uc_rcv(struct hfi1_packet *packet) u32 tlen = packet->tlen; struct hfi1_qp *qp = packet->qp; struct hfi1_other_headers *ohdr = packet->ohdr; - u32 opcode; + u32 bth0, opcode; u32 hdrsize = packet->hlen; u32 psn; u32 pad; @@ -278,10 +278,9 @@ void hfi1_uc_rcv(struct hfi1_packet *packet) int has_grh = rcv_flags & HFI1_HAS_GRH; int ret; u32 bth1; - struct ib_grh *grh = NULL; - opcode = be32_to_cpu(ohdr->bth[0]); - if (hfi1_ruc_check_hdr(ibp, hdr, has_grh, qp, opcode)) + bth0 = be32_to_cpu(ohdr->bth[0]); + if (hfi1_ruc_check_hdr(ibp, hdr, has_grh, qp, bth0)) return; bth1 = be32_to_cpu(ohdr->bth[1]); @@ -303,6 +302,7 @@ void hfi1_uc_rcv(struct hfi1_packet *packet) } if (bth1 & HFI1_FECN_SMASK) { + struct ib_grh *grh = NULL; u16 pkey = (u16)be32_to_cpu(ohdr->bth[0]); u16 slid = be16_to_cpu(hdr->lrh[3]); u16 dlid = be16_to_cpu(hdr->lrh[1]); @@ -310,13 +310,16 @@ void hfi1_uc_rcv(struct hfi1_packet *packet) u8 sc5; sc5 = ibp->sl_to_sc[qp->remote_ah_attr.sl]; + if (has_grh) + grh = &hdr->u.l.grh; - return_cnp(ibp, qp, src_qp, pkey, dlid, slid, sc5, grh); + return_cnp(ibp, qp, src_qp, pkey, dlid, slid, sc5, + grh); } } psn = be32_to_cpu(ohdr->bth[2]); - opcode >>= 24; + opcode = (bth0 >> 24) & 0xff; /* Compare the PSN verses the expected PSN. */ if (unlikely(cmp_psn(psn, qp->r_psn) != 0)) { diff --git a/drivers/staging/rdma/hfi1/ud.c b/drivers/staging/rdma/hfi1/ud.c index 5a9c784bec04..bd1b402c1e14 100644 --- a/drivers/staging/rdma/hfi1/ud.c +++ b/drivers/staging/rdma/hfi1/ud.c @@ -111,11 +111,10 @@ static void ud_loopback(struct hfi1_qp *sqp, struct hfi1_swqe *swqe) ((1 << ppd->lmc) - 1)); if (unlikely(ingress_pkey_check(ppd, pkey, sc5, qp->s_pkey_index, slid))) { - hfi1_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_PKEY, pkey, + hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY, pkey, ah_attr->sl, sqp->ibqp.qp_num, qp->ibqp.qp_num, - cpu_to_be16(slid), - cpu_to_be16(ah_attr->dlid)); + slid, ah_attr->dlid); goto drop; } } @@ -135,11 +134,11 @@ static void ud_loopback(struct hfi1_qp *sqp, struct hfi1_swqe *swqe) lid = ppd->lid | (ah_attr->src_path_bits & ((1 << ppd->lmc) - 1)); - hfi1_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_QKEY, qkey, + hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey, ah_attr->sl, sqp->ibqp.qp_num, qp->ibqp.qp_num, - cpu_to_be16(lid), - cpu_to_be16(ah_attr->dlid)); + lid, + ah_attr->dlid); goto drop; } } @@ -383,6 +382,7 @@ int hfi1_make_ud_req(struct hfi1_qp *qp) lrh0 |= (sc5 & 0xf) << 12; qp->s_sc = sc5; } + qp->s_sde = qp_to_sdma_engine(qp, qp->s_sc); qp->s_hdr->ibh.lrh[0] = cpu_to_be16(lrh0); qp->s_hdr->ibh.lrh[1] = cpu_to_be16(ah_attr->dlid); /* DEST LID */ qp->s_hdr->ibh.lrh[2] = @@ -736,12 +736,13 @@ void hfi1_ud_rcv(struct hfi1_packet *packet) * for invalid pkeys is optional according to * IB spec (release 1.3, section 10.9.4) */ - hfi1_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_PKEY, + hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY, pkey, (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF, src_qp, qp->ibqp.qp_num, - hdr->lrh[3], hdr->lrh[1]); + be16_to_cpu(hdr->lrh[3]), + be16_to_cpu(hdr->lrh[1])); return; } } else { @@ -752,10 +753,11 @@ void hfi1_ud_rcv(struct hfi1_packet *packet) } if (unlikely(qkey != qp->qkey)) { - hfi1_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_QKEY, qkey, + hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey, (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF, src_qp, qp->ibqp.qp_num, - hdr->lrh[3], hdr->lrh[1]); + be16_to_cpu(hdr->lrh[3]), + be16_to_cpu(hdr->lrh[1])); return; } /* Drop invalid MAD packets (see 13.5.3.1). */ diff --git a/drivers/staging/rdma/hfi1/user_exp_rcv.h b/drivers/staging/rdma/hfi1/user_exp_rcv.h new file mode 100644 index 000000000000..4f4876e1d353 --- /dev/null +++ b/drivers/staging/rdma/hfi1/user_exp_rcv.h @@ -0,0 +1,74 @@ +#ifndef _HFI1_USER_EXP_RCV_H +#define _HFI1_USER_EXP_RCV_H +/* + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2015 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * BSD LICENSE + * + * Copyright(c) 2015 Intel Corporation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * - Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define EXP_TID_TIDLEN_MASK 0x7FFULL +#define EXP_TID_TIDLEN_SHIFT 0 +#define EXP_TID_TIDCTRL_MASK 0x3ULL +#define EXP_TID_TIDCTRL_SHIFT 20 +#define EXP_TID_TIDIDX_MASK 0x3FFULL +#define EXP_TID_TIDIDX_SHIFT 22 +#define EXP_TID_GET(tid, field) \ + (((tid) >> EXP_TID_TID##field##_SHIFT) & EXP_TID_TID##field##_MASK) + +#define EXP_TID_SET(field, value) \ + (((value) & EXP_TID_TID##field##_MASK) << \ + EXP_TID_TID##field##_SHIFT) +#define EXP_TID_CLEAR(tid, field) ({ \ + (tid) &= ~(EXP_TID_TID##field##_MASK << \ + EXP_TID_TID##field##_SHIFT); \ + }) +#define EXP_TID_RESET(tid, field, value) do { \ + EXP_TID_CLEAR(tid, field); \ + (tid) |= EXP_TID_SET(field, (value)); \ + } while (0) + +#endif /* _HFI1_USER_EXP_RCV_H */ diff --git a/drivers/staging/rdma/hfi1/user_pages.c b/drivers/staging/rdma/hfi1/user_pages.c index 9071afbd7bf4..692de658f0dc 100644 --- a/drivers/staging/rdma/hfi1/user_pages.c +++ b/drivers/staging/rdma/hfi1/user_pages.c @@ -49,59 +49,11 @@ */ #include <linux/mm.h> +#include <linux/sched.h> #include <linux/device.h> #include "hfi.h" -static void __hfi1_release_user_pages(struct page **p, size_t num_pages, - int dirty) -{ - size_t i; - - for (i = 0; i < num_pages; i++) { - if (dirty) - set_page_dirty_lock(p[i]); - put_page(p[i]); - } -} - -/* - * Call with current->mm->mmap_sem held. - */ -static int __hfi1_get_user_pages(unsigned long start_page, size_t num_pages, - struct page **p) -{ - unsigned long lock_limit; - size_t got; - int ret; - - lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; - - if (num_pages > lock_limit && !capable(CAP_IPC_LOCK)) { - ret = -ENOMEM; - goto bail; - } - - for (got = 0; got < num_pages; got += ret) { - ret = get_user_pages(current, current->mm, - start_page + got * PAGE_SIZE, - num_pages - got, 1, 1, - p + got, NULL); - if (ret < 0) - goto bail_release; - } - - current->mm->pinned_vm += num_pages; - - ret = 0; - goto bail; - -bail_release: - __hfi1_release_user_pages(p, got, 0); -bail: - return ret; -} - /** * hfi1_map_page - a safety wrapper around pci_map_page() * @@ -116,41 +68,44 @@ dma_addr_t hfi1_map_page(struct pci_dev *hwdev, struct page *page, return phys; } -/** - * hfi1_get_user_pages - lock user pages into memory - * @start_page: the start page - * @num_pages: the number of pages - * @p: the output page structures - * - * This function takes a given start page (page aligned user virtual - * address) and pins it and the following specified number of pages. For - * now, num_pages is always 1, but that will probably change at some point - * (because caller is doing expected sends on a single virtually contiguous - * buffer, so we can do all pages at once). - */ -int hfi1_get_user_pages(unsigned long start_page, size_t num_pages, - struct page **p) +int hfi1_acquire_user_pages(unsigned long vaddr, size_t npages, bool writable, + struct page **pages) { + unsigned long pinned, lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; + bool can_lock = capable(CAP_IPC_LOCK); int ret; - down_write(¤t->mm->mmap_sem); + down_read(¤t->mm->mmap_sem); + pinned = current->mm->pinned_vm; + up_read(¤t->mm->mmap_sem); - ret = __hfi1_get_user_pages(start_page, num_pages, p); + if (pinned + npages > lock_limit && !can_lock) + return -ENOMEM; + ret = get_user_pages_fast(vaddr, npages, writable, pages); + if (ret < 0) + return ret; + + down_write(¤t->mm->mmap_sem); + current->mm->pinned_vm += ret; up_write(¤t->mm->mmap_sem); return ret; } -void hfi1_release_user_pages(struct page **p, size_t num_pages) +void hfi1_release_user_pages(struct page **p, size_t npages, bool dirty) { - if (current->mm) /* during close after signal, mm can be NULL */ - down_write(¤t->mm->mmap_sem); + size_t i; - __hfi1_release_user_pages(p, num_pages, 1); + for (i = 0; i < npages; i++) { + if (dirty) + set_page_dirty_lock(p[i]); + put_page(p[i]); + } - if (current->mm) { - current->mm->pinned_vm -= num_pages; + if (current->mm) { /* during close after signal, mm can be NULL */ + down_write(¤t->mm->mmap_sem); + current->mm->pinned_vm -= npages; up_write(¤t->mm->mmap_sem); } } diff --git a/drivers/staging/rdma/hfi1/user_sdma.c b/drivers/staging/rdma/hfi1/user_sdma.c index 36c838dcf023..d3de771a0770 100644 --- a/drivers/staging/rdma/hfi1/user_sdma.c +++ b/drivers/staging/rdma/hfi1/user_sdma.c @@ -146,8 +146,8 @@ MODULE_PARM_DESC(sdma_comp_size, "Size of User SDMA completion ring. Default: 12 #define KDETH_OM_MAX_SIZE (1 << ((KDETH_OM_LARGE / KDETH_OM_SMALL) + 1)) /* Last packet in the request */ -#define TXREQ_FLAGS_REQ_LAST_PKT (1 << 0) -#define TXREQ_FLAGS_IOVEC_LAST_PKT (1 << 0) +#define TXREQ_FLAGS_REQ_LAST_PKT BIT(0) +#define TXREQ_FLAGS_IOVEC_LAST_PKT BIT(0) #define SDMA_REQ_IN_USE 0 #define SDMA_REQ_FOR_THREAD 1 @@ -156,9 +156,9 @@ MODULE_PARM_DESC(sdma_comp_size, "Size of User SDMA completion ring. Default: 12 #define SDMA_REQ_HAS_ERROR 4 #define SDMA_REQ_DONE_ERROR 5 -#define SDMA_PKT_Q_INACTIVE (1 << 0) -#define SDMA_PKT_Q_ACTIVE (1 << 1) -#define SDMA_PKT_Q_DEFERRED (1 << 2) +#define SDMA_PKT_Q_INACTIVE BIT(0) +#define SDMA_PKT_Q_ACTIVE BIT(1) +#define SDMA_PKT_Q_DEFERRED BIT(2) /* * Maximum retry attempts to submit a TX request @@ -214,12 +214,6 @@ struct user_sdma_request { */ u8 omfactor; /* - * pointer to the user's task_struct. We are going to - * get a reference to it so we can process io vectors - * at a later time. - */ - struct task_struct *user_proc; - /* * pointer to the user's mm_struct. We are going to * get a reference to it so it doesn't get freed * since we might not be in process context when we @@ -245,9 +239,13 @@ struct user_sdma_request { u16 tididx; u32 sent; u64 seqnum; - spinlock_t list_lock; struct list_head txps; + spinlock_t txcmp_lock; /* protect txcmp list */ + struct list_head txcmp; unsigned long flags; + /* status of the last txreq completed */ + int status; + struct work_struct worker; }; /* @@ -260,6 +258,7 @@ struct user_sdma_txreq { /* Packet header for the txreq */ struct hfi1_pkt_header hdr; struct sdma_txreq txreq; + struct list_head list; struct user_sdma_request *req; struct { struct user_sdma_iovec *vec; @@ -282,10 +281,12 @@ struct user_sdma_txreq { static int user_sdma_send_pkts(struct user_sdma_request *, unsigned); static int num_user_pages(const struct iovec *); static void user_sdma_txreq_cb(struct sdma_txreq *, int, int); +static void user_sdma_delayed_completion(struct work_struct *); static void user_sdma_free_request(struct user_sdma_request *); static int pin_vector_pages(struct user_sdma_request *, struct user_sdma_iovec *); -static void unpin_vector_pages(struct user_sdma_iovec *); +static void unpin_vector_pages(struct user_sdma_request *, + struct user_sdma_iovec *); static int check_header_template(struct user_sdma_request *, struct hfi1_pkt_header *, u32, u32); static int set_txreq_header(struct user_sdma_request *, @@ -352,6 +353,7 @@ static void sdma_kmem_cache_ctor(void *obj) int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt, struct file *fp) { + struct hfi1_filedata *fd; int ret = 0; unsigned memsize; char buf[64]; @@ -365,6 +367,8 @@ int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt, struct file *fp) goto done; } + fd = fp->private_data; + if (!hfi1_sdma_comp_ring_size) { ret = -EINVAL; goto done; @@ -384,16 +388,17 @@ int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt, struct file *fp) INIT_LIST_HEAD(&pq->list); pq->dd = dd; pq->ctxt = uctxt->ctxt; - pq->subctxt = subctxt_fp(fp); + pq->subctxt = fd->subctxt; pq->n_max_reqs = hfi1_sdma_comp_ring_size; pq->state = SDMA_PKT_Q_INACTIVE; atomic_set(&pq->n_reqs, 0); + init_waitqueue_head(&pq->wait); iowait_init(&pq->busy, 0, NULL, defer_packet_queue, activate_packet_queue); pq->reqidx = 0; snprintf(buf, 64, "txreq-kmem-cache-%u-%u-%u", dd->unit, uctxt->ctxt, - subctxt_fp(fp)); + fd->subctxt); pq->txreq_cache = kmem_cache_create(buf, sizeof(struct user_sdma_txreq), L1_CACHE_BYTES, @@ -404,7 +409,7 @@ int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt, struct file *fp) uctxt->ctxt); goto pq_txreq_nomem; } - user_sdma_pkt_fp(fp) = pq; + fd->pq = pq; cq = kzalloc(sizeof(*cq), GFP_KERNEL); if (!cq) goto cq_nomem; @@ -416,7 +421,7 @@ int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt, struct file *fp) goto cq_comps_nomem; cq->nentries = hfi1_sdma_comp_ring_size; - user_sdma_comp_fp(fp) = cq; + fd->cq = cq; spin_lock_irqsave(&uctxt->sdma_qlock, flags); list_add(&pq->list, &uctxt->sdma_queues); @@ -431,7 +436,7 @@ pq_txreq_nomem: kfree(pq->reqs); pq_reqs_nomem: kfree(pq); - user_sdma_pkt_fp(fp) = NULL; + fd->pq = NULL; pq_nomem: ret = -ENOMEM; done: @@ -448,26 +453,16 @@ int hfi1_user_sdma_free_queues(struct hfi1_filedata *fd) uctxt->ctxt, fd->subctxt); pq = fd->pq; if (pq) { - u16 i, j; - spin_lock_irqsave(&uctxt->sdma_qlock, flags); if (!list_empty(&pq->list)) list_del_init(&pq->list); spin_unlock_irqrestore(&uctxt->sdma_qlock, flags); iowait_sdma_drain(&pq->busy); - if (pq->reqs) { - for (i = 0, j = 0; i < atomic_read(&pq->n_reqs) && - j < pq->n_max_reqs; j++) { - struct user_sdma_request *req = &pq->reqs[j]; - - if (test_bit(SDMA_REQ_IN_USE, &req->flags)) { - set_comp_state(req, ERROR, -ECOMM); - user_sdma_free_request(req); - i++; - } - } - kfree(pq->reqs); - } + /* Wait until all requests have been freed. */ + wait_event_interruptible( + pq->wait, + (ACCESS_ONCE(pq->state) == SDMA_PKT_Q_INACTIVE)); + kfree(pq->reqs); kmem_cache_destroy(pq->txreq_cache); kfree(pq); fd->pq = NULL; @@ -485,9 +480,10 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec, unsigned long dim, unsigned long *count) { int ret = 0, i = 0, sent; - struct hfi1_ctxtdata *uctxt = ctxt_fp(fp); - struct hfi1_user_sdma_pkt_q *pq = user_sdma_pkt_fp(fp); - struct hfi1_user_sdma_comp_q *cq = user_sdma_comp_fp(fp); + struct hfi1_filedata *fd = fp->private_data; + struct hfi1_ctxtdata *uctxt = fd->uctxt; + struct hfi1_user_sdma_pkt_q *pq = fd->pq; + struct hfi1_user_sdma_comp_q *cq = fd->cq; struct hfi1_devdata *dd = pq->dd; unsigned long idx = 0; u8 pcount = initial_pkt_count; @@ -499,40 +495,36 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec, hfi1_cdbg( SDMA, "[%u:%u:%u] First vector not big enough for header %lu/%lu", - dd->unit, uctxt->ctxt, subctxt_fp(fp), + dd->unit, uctxt->ctxt, fd->subctxt, iovec[idx].iov_len, sizeof(info) + sizeof(req->hdr)); - ret = -EINVAL; - goto done; + return -EINVAL; } ret = copy_from_user(&info, iovec[idx].iov_base, sizeof(info)); if (ret) { hfi1_cdbg(SDMA, "[%u:%u:%u] Failed to copy info QW (%d)", - dd->unit, uctxt->ctxt, subctxt_fp(fp), ret); - ret = -EFAULT; - goto done; + dd->unit, uctxt->ctxt, fd->subctxt, ret); + return -EFAULT; } - trace_hfi1_sdma_user_reqinfo(dd, uctxt->ctxt, subctxt_fp(fp), + trace_hfi1_sdma_user_reqinfo(dd, uctxt->ctxt, fd->subctxt, (u16 *)&info); if (cq->comps[info.comp_idx].status == QUEUED) { hfi1_cdbg(SDMA, "[%u:%u:%u] Entry %u is in QUEUED state", - dd->unit, uctxt->ctxt, subctxt_fp(fp), + dd->unit, uctxt->ctxt, fd->subctxt, info.comp_idx); - ret = -EBADSLT; - goto done; + return -EBADSLT; } if (!info.fragsize) { hfi1_cdbg(SDMA, "[%u:%u:%u:%u] Request does not specify fragsize", - dd->unit, uctxt->ctxt, subctxt_fp(fp), info.comp_idx); - ret = -EINVAL; - goto done; + dd->unit, uctxt->ctxt, fd->subctxt, info.comp_idx); + return -EINVAL; } /* * We've done all the safety checks that we can up to this point, * "allocate" the request entry. */ hfi1_cdbg(SDMA, "[%u:%u:%u] Using req/comp entry %u\n", dd->unit, - uctxt->ctxt, subctxt_fp(fp), info.comp_idx); + uctxt->ctxt, fd->subctxt, info.comp_idx); req = pq->reqs + info.comp_idx; memset(req, 0, sizeof(*req)); /* Mark the request as IN_USE before we start filling it in. */ @@ -540,8 +532,12 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec, req->data_iovs = req_iovcnt(info.ctrl) - 1; req->pq = pq; req->cq = cq; + req->status = -1; INIT_LIST_HEAD(&req->txps); - spin_lock_init(&req->list_lock); + INIT_LIST_HEAD(&req->txcmp); + INIT_WORK(&req->worker, user_sdma_delayed_completion); + + spin_lock_init(&req->txcmp_lock); memcpy(&req->info, &info, sizeof(info)); if (req_opcode(info.ctrl) == EXPECTED) @@ -550,8 +546,7 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec, if (!info.npkts || req->data_iovs > MAX_VECTORS_PER_REQ) { SDMA_DBG(req, "Too many vectors (%u/%u)", req->data_iovs, MAX_VECTORS_PER_REQ); - ret = -EINVAL; - goto done; + return -EINVAL; } /* Copy the header from the user buffer */ ret = copy_from_user(&req->hdr, iovec[idx].iov_base + sizeof(info), @@ -659,7 +654,7 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec, /* Have to select the engine */ req->sde = sdma_select_engine_vl(dd, - (u32)(uctxt->ctxt + subctxt_fp(fp)), + (u32)(uctxt->ctxt + fd->subctxt), vl); if (!req->sde || !sdma_running(req->sde)) { ret = -ECOMM; @@ -681,18 +676,16 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec, sent = user_sdma_send_pkts(req, pcount); if (unlikely(sent < 0)) { if (sent != -EBUSY) { - ret = sent; - goto send_err; + req->status = sent; + set_comp_state(req, ERROR, req->status); + return sent; } else sent = 0; } atomic_inc(&pq->n_reqs); + xchg(&pq->state, SDMA_PKT_Q_ACTIVE); if (sent < req->info.npkts) { - /* Take the references to the user's task and mm_struct */ - get_task_struct(current); - req->user_proc = current; - /* * This is a somewhat blocking send implementation. * The driver will block the caller until all packets of the @@ -702,8 +695,10 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec, while (!test_bit(SDMA_REQ_SEND_DONE, &req->flags)) { ret = user_sdma_send_pkts(req, pcount); if (ret < 0) { - if (ret != -EBUSY) - goto send_err; + if (ret != -EBUSY) { + req->status = ret; + return ret; + } wait_event_interruptible_timeout( pq->busy.wait_dma, (pq->state == SDMA_PKT_Q_ACTIVE), @@ -713,14 +708,10 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec, } } - ret = 0; *count += idx; - goto done; -send_err: - set_comp_state(req, ERROR, ret); + return 0; free_req: user_sdma_free_request(req); -done: return ret; } @@ -778,20 +769,24 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts) struct hfi1_user_sdma_pkt_q *pq = NULL; struct user_sdma_iovec *iovec = NULL; - if (!req->pq) { - ret = -EINVAL; - goto done; - } + if (!req->pq) + return -EINVAL; pq = req->pq; + /* If tx completion has reported an error, we are done. */ + if (test_bit(SDMA_REQ_HAS_ERROR, &req->flags)) { + set_bit(SDMA_REQ_DONE_ERROR, &req->flags); + return -EFAULT; + } + /* * Check if we might have sent the entire request already */ if (unlikely(req->seqnum == req->info.npkts)) { if (!list_empty(&req->txps)) goto dosend; - goto done; + return ret; } if (!maxpkts || maxpkts > req->info.npkts - req->seqnum) @@ -808,19 +803,18 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts) */ if (test_bit(SDMA_REQ_HAS_ERROR, &req->flags)) { set_bit(SDMA_REQ_DONE_ERROR, &req->flags); - ret = -EFAULT; - goto done; + return -EFAULT; } tx = kmem_cache_alloc(pq->txreq_cache, GFP_KERNEL); - if (!tx) { - ret = -ENOMEM; - goto done; - } + if (!tx) + return -ENOMEM; + tx->flags = 0; tx->req = req; tx->busycount = 0; tx->idx = -1; + INIT_LIST_HEAD(&tx->list); memset(tx->iovecs, 0, sizeof(tx->iovecs)); if (req->seqnum == req->info.npkts - 1) @@ -945,9 +939,8 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts) if (ret) { int i; - dd_dev_err(pq->dd, - "SDMA txreq add page failed %d\n", - ret); + SDMA_DBG(req, "SDMA txreq add page failed %d\n", + ret); /* Mark all assigned vectors as complete so they * are unpinned in the callback. */ for (i = tx->idx; i >= 0; i--) { @@ -1017,12 +1010,12 @@ dosend: if (test_bit(SDMA_REQ_HAVE_AHG, &req->flags)) sdma_ahg_free(req->sde, req->ahg_idx); } - goto done; + return ret; + free_txreq: sdma_txclean(pq->dd, &tx->txreq); free_tx: kmem_cache_free(pq->txreq_cache, tx); -done: return ret; } @@ -1041,52 +1034,58 @@ static inline int num_user_pages(const struct iovec *iov) static int pin_vector_pages(struct user_sdma_request *req, struct user_sdma_iovec *iovec) { - int ret = 0; - unsigned pinned; + int pinned, npages; - iovec->npages = num_user_pages(&iovec->iov); - iovec->pages = kcalloc(iovec->npages, sizeof(*iovec->pages), - GFP_KERNEL); + npages = num_user_pages(&iovec->iov); + iovec->pages = kcalloc(npages, sizeof(*iovec->pages), GFP_KERNEL); if (!iovec->pages) { SDMA_DBG(req, "Failed page array alloc"); - ret = -ENOMEM; - goto done; + return -ENOMEM; } - /* If called by the kernel thread, use the user's mm */ - if (current->flags & PF_KTHREAD) - use_mm(req->user_proc->mm); - pinned = get_user_pages_fast( - (unsigned long)iovec->iov.iov_base, - iovec->npages, 0, iovec->pages); - /* If called by the kernel thread, unuse the user's mm */ - if (current->flags & PF_KTHREAD) - unuse_mm(req->user_proc->mm); - if (pinned != iovec->npages) { - SDMA_DBG(req, "Failed to pin pages (%u/%u)", pinned, - iovec->npages); - ret = -EFAULT; - goto pfree; + + /* + * Get a reference to the process's mm so we can use it when + * unpinning the io vectors. + */ + req->pq->user_mm = get_task_mm(current); + + pinned = hfi1_acquire_user_pages((unsigned long)iovec->iov.iov_base, + npages, 0, iovec->pages); + + if (pinned < 0) + return pinned; + + iovec->npages = pinned; + if (pinned != npages) { + SDMA_DBG(req, "Failed to pin pages (%d/%u)", pinned, npages); + unpin_vector_pages(req, iovec); + return -EFAULT; } - goto done; -pfree: - unpin_vector_pages(iovec); -done: - return ret; + return 0; } -static void unpin_vector_pages(struct user_sdma_iovec *iovec) +static void unpin_vector_pages(struct user_sdma_request *req, + struct user_sdma_iovec *iovec) { - unsigned i; + /* + * Unpinning is done through the workqueue so use the + * process's mm if we have a reference to it. + */ + if ((current->flags & PF_KTHREAD) && req->pq->user_mm) + use_mm(req->pq->user_mm); - if (ACCESS_ONCE(iovec->offset) != iovec->iov.iov_len) { - hfi1_cdbg(SDMA, - "the complete vector has not been sent yet %llu %zu", - iovec->offset, iovec->iov.iov_len); - return; + hfi1_release_user_pages(iovec->pages, iovec->npages, 0); + + /* + * Unuse the user's mm (see above) and release the + * reference to it. + */ + if (req->pq->user_mm) { + if (current->flags & PF_KTHREAD) + unuse_mm(req->pq->user_mm); + mmput(req->pq->user_mm); } - for (i = 0; i < iovec->npages; i++) - if (iovec->pages[i]) - put_page(iovec->pages[i]); + kfree(iovec->pages); iovec->pages = NULL; iovec->npages = 0; @@ -1354,54 +1353,116 @@ static int set_txreq_header_ahg(struct user_sdma_request *req, return diff; } +/* + * SDMA tx request completion callback. Called when the SDMA progress + * state machine gets notification that the SDMA descriptors for this + * tx request have been processed by the DMA engine. Called in + * interrupt context. + */ static void user_sdma_txreq_cb(struct sdma_txreq *txreq, int status, int drain) { struct user_sdma_txreq *tx = container_of(txreq, struct user_sdma_txreq, txreq); - struct user_sdma_request *req = tx->req; - struct hfi1_user_sdma_pkt_q *pq = req ? req->pq : NULL; - u64 tx_seqnum; + struct user_sdma_request *req; + bool defer; + int i; - if (unlikely(!req || !pq)) + if (!tx->req) return; - /* If we have any io vectors associated with this txreq, - * check whether they need to be 'freed'. */ - if (tx->idx != -1) { - int i; + req = tx->req; + /* + * If this is the callback for the last packet of the request, + * queue up the request for clean up. + */ + defer = (tx->seqnum == req->info.npkts - 1); - for (i = tx->idx; i >= 0; i--) { - if (tx->iovecs[i].flags & TXREQ_FLAGS_IOVEC_LAST_PKT) - unpin_vector_pages(tx->iovecs[i].vec); + /* + * If we have any io vectors associated with this txreq, + * check whether they need to be 'freed'. We can't free them + * here because the unpin function needs to be able to sleep. + */ + for (i = tx->idx; i >= 0; i--) { + if (tx->iovecs[i].flags & TXREQ_FLAGS_IOVEC_LAST_PKT) { + defer = true; + break; } } - tx_seqnum = tx->seqnum; - kmem_cache_free(pq->txreq_cache, tx); - + req->status = status; if (status != SDMA_TXREQ_S_OK) { - dd_dev_err(pq->dd, "SDMA completion with error %d", status); - set_comp_state(req, ERROR, status); + SDMA_DBG(req, "SDMA completion with error %d", + status); set_bit(SDMA_REQ_HAS_ERROR, &req->flags); - /* Do not free the request until the sender loop has ack'ed - * the error and we've seen all txreqs. */ - if (tx_seqnum == ACCESS_ONCE(req->seqnum) && - test_bit(SDMA_REQ_DONE_ERROR, &req->flags)) { - atomic_dec(&pq->n_reqs); - user_sdma_free_request(req); - } + defer = true; + } + + /* + * Defer the clean up of the iovectors and the request until later + * so it can be done outside of interrupt context. + */ + if (defer) { + spin_lock(&req->txcmp_lock); + list_add_tail(&tx->list, &req->txcmp); + spin_unlock(&req->txcmp_lock); + schedule_work(&req->worker); } else { - if (tx_seqnum == req->info.npkts - 1) { - /* We've sent and completed all packets in this - * request. Signal completion to the user */ - atomic_dec(&pq->n_reqs); - set_comp_state(req, COMPLETE, 0); - user_sdma_free_request(req); + kmem_cache_free(req->pq->txreq_cache, tx); + } +} + +static void user_sdma_delayed_completion(struct work_struct *work) +{ + struct user_sdma_request *req = + container_of(work, struct user_sdma_request, worker); + struct hfi1_user_sdma_pkt_q *pq = req->pq; + struct user_sdma_txreq *tx = NULL; + unsigned long flags; + u64 seqnum; + int i; + + while (1) { + spin_lock_irqsave(&req->txcmp_lock, flags); + if (!list_empty(&req->txcmp)) { + tx = list_first_entry(&req->txcmp, + struct user_sdma_txreq, list); + list_del(&tx->list); + } + spin_unlock_irqrestore(&req->txcmp_lock, flags); + if (!tx) + break; + + for (i = tx->idx; i >= 0; i--) + if (tx->iovecs[i].flags & TXREQ_FLAGS_IOVEC_LAST_PKT) + unpin_vector_pages(req, tx->iovecs[i].vec); + + seqnum = tx->seqnum; + kmem_cache_free(pq->txreq_cache, tx); + tx = NULL; + + if (req->status != SDMA_TXREQ_S_OK) { + if (seqnum == ACCESS_ONCE(req->seqnum) && + test_bit(SDMA_REQ_DONE_ERROR, &req->flags)) { + atomic_dec(&pq->n_reqs); + set_comp_state(req, ERROR, req->status); + user_sdma_free_request(req); + break; + } + } else { + if (seqnum == req->info.npkts - 1) { + atomic_dec(&pq->n_reqs); + set_comp_state(req, COMPLETE, 0); + user_sdma_free_request(req); + break; + } } } - if (!atomic_read(&pq->n_reqs)) + + if (!atomic_read(&pq->n_reqs)) { xchg(&pq->state, SDMA_PKT_Q_INACTIVE); + wake_up(&pq->wait); + } } static void user_sdma_free_request(struct user_sdma_request *req) @@ -1422,10 +1483,8 @@ static void user_sdma_free_request(struct user_sdma_request *req) for (i = 0; i < req->data_iovs; i++) if (req->iovs[i].npages && req->iovs[i].pages) - unpin_vector_pages(&req->iovs[i]); + unpin_vector_pages(req, &req->iovs[i]); } - if (req->user_proc) - put_task_struct(req->user_proc); kfree(req->tids); clear_bit(SDMA_REQ_IN_USE, &req->flags); } diff --git a/drivers/staging/rdma/hfi1/user_sdma.h b/drivers/staging/rdma/hfi1/user_sdma.h index fa4422553e23..0afa28508a8a 100644 --- a/drivers/staging/rdma/hfi1/user_sdma.h +++ b/drivers/staging/rdma/hfi1/user_sdma.h @@ -52,15 +52,7 @@ #include "common.h" #include "iowait.h" - -#define EXP_TID_TIDLEN_MASK 0x7FFULL -#define EXP_TID_TIDLEN_SHIFT 0 -#define EXP_TID_TIDCTRL_MASK 0x3ULL -#define EXP_TID_TIDCTRL_SHIFT 20 -#define EXP_TID_TIDIDX_MASK 0x7FFULL -#define EXP_TID_TIDIDX_SHIFT 22 -#define EXP_TID_GET(tid, field) \ - (((tid) >> EXP_TID_TID##field##_SHIFT) & EXP_TID_TID##field##_MASK) +#include "user_exp_rcv.h" extern uint extended_psn; @@ -76,6 +68,8 @@ struct hfi1_user_sdma_pkt_q { struct user_sdma_request *reqs; struct iowait busy; unsigned state; + wait_queue_head_t wait; + struct mm_struct *user_mm; }; struct hfi1_user_sdma_comp_q { diff --git a/drivers/staging/rdma/hfi1/verbs.c b/drivers/staging/rdma/hfi1/verbs.c index 9beb0aa876f0..ef0feaa684a4 100644 --- a/drivers/staging/rdma/hfi1/verbs.c +++ b/drivers/staging/rdma/hfi1/verbs.c @@ -162,6 +162,8 @@ static inline struct hfi1_ucontext *to_iucontext(struct ib_ucontext return container_of(ibucontext, struct hfi1_ucontext, ibucontext); } +static inline void _hfi1_schedule_send(struct hfi1_qp *qp); + /* * Translate ib_wr_opcode into ib_wc_opcode. */ @@ -509,9 +511,9 @@ static int post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, nreq++; } bail: - if (nreq && !call_send) - hfi1_schedule_send(qp); spin_unlock_irqrestore(&qp->s_lock, flags); + if (nreq && !call_send) + _hfi1_schedule_send(qp); if (nreq && call_send) hfi1_do_send(&qp->s_iowait.iowork); return err; @@ -999,17 +1001,19 @@ bail_txadd: return ret; } -int hfi1_verbs_send_dma(struct hfi1_qp *qp, struct ahg_ib_header *ahdr, - u32 hdrwords, struct hfi1_sge_state *ss, u32 len, - u32 plen, u32 dwords, u64 pbc) +int hfi1_verbs_send_dma(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, + u64 pbc) { - struct hfi1_ibdev *dev = to_idev(qp->ibqp.device); - struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); - struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); + struct ahg_ib_header *ahdr = qp->s_hdr; + u32 hdrwords = qp->s_hdrwords; + struct hfi1_sge_state *ss = qp->s_cur_sge; + u32 len = qp->s_cur_size; + u32 plen = hdrwords + ((len + 3) >> 2) + 2; /* includes pbc */ + struct hfi1_ibdev *dev = ps->dev; + struct hfi1_pportdata *ppd = ps->ppd; struct verbs_txreq *tx; struct sdma_txreq *stx; u64 pbc_flags = 0; - struct sdma_engine *sde; u8 sc5 = qp->s_sc; int ret; @@ -1030,12 +1034,7 @@ int hfi1_verbs_send_dma(struct hfi1_qp *qp, struct ahg_ib_header *ahdr, if (IS_ERR(tx)) goto bail_tx; - if (!qp->s_hdr->sde) { - tx->sde = sde = qp_to_sdma_engine(qp, sc5); - if (!sde) - goto bail_no_sde; - } else - tx->sde = sde = qp->s_hdr->sde; + tx->sde = qp->s_sde; if (likely(pbc == 0)) { u32 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5); @@ -1050,17 +1049,15 @@ int hfi1_verbs_send_dma(struct hfi1_qp *qp, struct ahg_ib_header *ahdr, if (qp->s_rdma_mr) qp->s_rdma_mr = NULL; tx->hdr_dwords = hdrwords + 2; - ret = build_verbs_tx_desc(sde, ss, len, tx, ahdr, pbc); + ret = build_verbs_tx_desc(tx->sde, ss, len, tx, ahdr, pbc); if (unlikely(ret)) goto bail_build; trace_output_ibhdr(dd_from_ibdev(qp->ibqp.device), &ahdr->ibh); - ret = sdma_send_txreq(sde, &qp->s_iowait, &tx->txreq); + ret = sdma_send_txreq(tx->sde, &qp->s_iowait, &tx->txreq); if (unlikely(ret == -ECOMM)) goto bail_ecomm; return ret; -bail_no_sde: - hfi1_put_txreq(tx); bail_ecomm: /* The current one got "sent" */ return 0; @@ -1126,12 +1123,16 @@ struct send_context *qp_to_send_context(struct hfi1_qp *qp, u8 sc5) return dd->vld[vl].sc; } -int hfi1_verbs_send_pio(struct hfi1_qp *qp, struct ahg_ib_header *ahdr, - u32 hdrwords, struct hfi1_sge_state *ss, u32 len, - u32 plen, u32 dwords, u64 pbc) +int hfi1_verbs_send_pio(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, + u64 pbc) { - struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); - struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); + struct ahg_ib_header *ahdr = qp->s_hdr; + u32 hdrwords = qp->s_hdrwords; + struct hfi1_sge_state *ss = qp->s_cur_sge; + u32 len = qp->s_cur_size; + u32 dwords = (len + 3) >> 2; + u32 plen = hdrwords + dwords + 2; /* includes pbc */ + struct hfi1_pportdata *ppd = ps->ppd; u32 *hdr = (u32 *)&ahdr->ibh; u64 pbc_flags = 0; u32 sc5; @@ -1303,23 +1304,18 @@ bad: /** * hfi1_verbs_send - send a packet * @qp: the QP to send on - * @ahdr: the packet header - * @hdrwords: the number of 32-bit words in the header - * @ss: the SGE to send - * @len: the length of the packet in bytes + * @ps: the state of the packet to send * * Return zero if packet is sent or queued OK. * Return non-zero and clear qp->s_flags HFI1_S_BUSY otherwise. */ -int hfi1_verbs_send(struct hfi1_qp *qp, struct ahg_ib_header *ahdr, - u32 hdrwords, struct hfi1_sge_state *ss, u32 len) +int hfi1_verbs_send(struct hfi1_qp *qp, struct hfi1_pkt_state *ps) { struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device); - u32 plen; + struct ahg_ib_header *ahdr = qp->s_hdr; int ret; int pio = 0; unsigned long flags = 0; - u32 dwords = (len + 3) >> 2; /* * VL15 packets (IB_QPT_SMI) will always use PIO, so we @@ -1350,23 +1346,16 @@ int hfi1_verbs_send(struct hfi1_qp *qp, struct ahg_ib_header *ahdr, return -EINVAL; } - /* - * Calculate the send buffer trigger address. - * The +2 counts for the pbc control qword - */ - plen = hdrwords + dwords + 2; - if (pio) { - ret = dd->process_pio_send( - qp, ahdr, hdrwords, ss, len, plen, dwords, 0); + ret = dd->process_pio_send(qp, ps, 0); } else { #ifdef CONFIG_SDMA_VERBOSITY dd_dev_err(dd, "CONFIG SDMA %s:%d %s()\n", slashstrip(__FILE__), __LINE__, __func__); - dd_dev_err(dd, "SDMA hdrwords = %u, len = %u\n", hdrwords, len); + dd_dev_err(dd, "SDMA hdrwords = %u, len = %u\n", qp->s_hdrwords, + qp->s_cur_size); #endif - ret = dd->process_dma_send( - qp, ahdr, hdrwords, ss, len, plen, dwords, 0); + ret = dd->process_dma_send(qp, ps, 0); } return ret; @@ -2135,28 +2124,43 @@ void hfi1_unregister_ib_device(struct hfi1_devdata *dd) vfree(dev->lk_table.table); } -/* - * This must be called with s_lock held. - */ -void hfi1_schedule_send(struct hfi1_qp *qp) -{ - if (hfi1_send_ok(qp)) { - struct hfi1_ibport *ibp = - to_iport(qp->ibqp.device, qp->port_num); - struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); - - iowait_schedule(&qp->s_iowait, ppd->hfi1_wq); - } -} - void hfi1_cnp_rcv(struct hfi1_packet *packet) { struct hfi1_ibport *ibp = &packet->rcd->ppd->ibport_data; - - if (packet->qp->ibqp.qp_type == IB_QPT_UC) - hfi1_uc_rcv(packet); - else if (packet->qp->ibqp.qp_type == IB_QPT_UD) - hfi1_ud_rcv(packet); - else + struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); + struct hfi1_ib_header *hdr = packet->hdr; + struct hfi1_qp *qp = packet->qp; + u32 lqpn, rqpn = 0; + u16 rlid = 0; + u8 sl, sc5, sc4_bit, svc_type; + bool sc4_set = has_sc4_bit(packet); + + switch (packet->qp->ibqp.qp_type) { + case IB_QPT_UC: + rlid = qp->remote_ah_attr.dlid; + rqpn = qp->remote_qpn; + svc_type = IB_CC_SVCTYPE_UC; + break; + case IB_QPT_RC: + rlid = qp->remote_ah_attr.dlid; + rqpn = qp->remote_qpn; + svc_type = IB_CC_SVCTYPE_RC; + break; + case IB_QPT_SMI: + case IB_QPT_GSI: + case IB_QPT_UD: + svc_type = IB_CC_SVCTYPE_UD; + break; + default: ibp->n_pkt_drops++; + return; + } + + sc4_bit = sc4_set << 4; + sc5 = (be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf; + sc5 |= sc4_bit; + sl = ibp->sc_to_sl[sc5]; + lqpn = qp->ibqp.qp_num; + + process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type); } diff --git a/drivers/staging/rdma/hfi1/verbs.h b/drivers/staging/rdma/hfi1/verbs.h index 041ad07ee699..72106e5362b9 100644 --- a/drivers/staging/rdma/hfi1/verbs.h +++ b/drivers/staging/rdma/hfi1/verbs.h @@ -120,9 +120,9 @@ struct hfi1_packet; #define HFI1_VENDOR_IPG cpu_to_be16(0xFFA0) -#define IB_BTH_REQ_ACK (1 << 31) -#define IB_BTH_SOLICITED (1 << 23) -#define IB_BTH_MIG_REQ (1 << 22) +#define IB_BTH_REQ_ACK BIT(31) +#define IB_BTH_SOLICITED BIT(23) +#define IB_BTH_MIG_REQ BIT(22) #define IB_GRH_VERSION 6 #define IB_GRH_VERSION_MASK 0xF @@ -441,7 +441,8 @@ struct hfi1_qp { struct hfi1_swqe *s_wq; /* send work queue */ struct hfi1_mmap_info *ip; struct ahg_ib_header *s_hdr; /* next packet header to send */ - u8 s_sc; /* SC[0..4] for next packet */ + /* sc for UC/RC QPs - based on ah for UD */ + u8 s_sc; unsigned long timeout_jiffies; /* computed from timeout */ enum ib_mtu path_mtu; @@ -489,6 +490,7 @@ struct hfi1_qp { u32 r_psn; /* expected rcv packet sequence number */ u32 r_msn; /* message sequence number */ + u8 r_adefered; /* number of acks defered */ u8 r_state; /* opcode of last packet received */ u8 r_flags; u8 r_head_ack_queue; /* index into s_ack_queue[] */ @@ -544,6 +546,16 @@ struct hfi1_qp { }; /* + * This structure is used to hold commonly lookedup and computed values during + * the send engine progress. + */ +struct hfi1_pkt_state { + struct hfi1_ibdev *dev; + struct hfi1_ibport *ibp; + struct hfi1_pportdata *ppd; +}; + +/* * Atomic bit definitions for r_aflags. */ #define HFI1_R_WRID_VALID 0 @@ -552,11 +564,13 @@ struct hfi1_qp { /* * Bit definitions for r_flags. */ -#define HFI1_R_REUSE_SGE 0x01 -#define HFI1_R_RDMAR_SEQ 0x02 -#define HFI1_R_RSP_NAK 0x04 -#define HFI1_R_RSP_SEND 0x08 -#define HFI1_R_COMM_EST 0x10 +#define HFI1_R_REUSE_SGE 0x01 +#define HFI1_R_RDMAR_SEQ 0x02 +/* defer ack until end of interrupt session */ +#define HFI1_R_RSP_DEFERED_ACK 0x04 +/* relay ack to send engine */ +#define HFI1_R_RSP_SEND 0x08 +#define HFI1_R_COMM_EST 0x10 /* * Bit definitions for s_flags. @@ -846,9 +860,8 @@ static inline int hfi1_send_ok(struct hfi1_qp *qp) /* * This must be called with s_lock held. */ -void hfi1_schedule_send(struct hfi1_qp *qp); void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl, - u32 qp1, u32 qp2, __be16 lid1, __be16 lid2); + u32 qp1, u32 qp2, u16 lid1, u16 lid2); void hfi1_cap_mask_chg(struct hfi1_ibport *ibp); void hfi1_sys_guid_chg(struct hfi1_ibport *ibp); void hfi1_node_desc_chg(struct hfi1_ibport *ibp); @@ -927,8 +940,7 @@ int hfi1_mcast_tree_empty(struct hfi1_ibport *ibp); struct verbs_txreq; void hfi1_put_txreq(struct verbs_txreq *tx); -int hfi1_verbs_send(struct hfi1_qp *qp, struct ahg_ib_header *ahdr, - u32 hdrwords, struct hfi1_sge_state *ss, u32 len); +int hfi1_verbs_send(struct hfi1_qp *qp, struct hfi1_pkt_state *ps); void hfi1_copy_sge(struct hfi1_sge_state *ss, void *data, u32 length, int release); @@ -1069,8 +1081,6 @@ int hfi1_mmap(struct ib_ucontext *context, struct vm_area_struct *vma); int hfi1_get_rwqe(struct hfi1_qp *qp, int wr_id_only); -void hfi1_migrate_qp(struct hfi1_qp *qp); - int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_ib_header *hdr, int has_grh, struct hfi1_qp *qp, u32 bth0); @@ -1101,13 +1111,11 @@ void hfi1_ib_rcv(struct hfi1_packet *packet); unsigned hfi1_get_npkeys(struct hfi1_devdata *); -int hfi1_verbs_send_dma(struct hfi1_qp *qp, struct ahg_ib_header *hdr, - u32 hdrwords, struct hfi1_sge_state *ss, u32 len, - u32 plen, u32 dwords, u64 pbc); +int hfi1_verbs_send_dma(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, + u64 pbc); -int hfi1_verbs_send_pio(struct hfi1_qp *qp, struct ahg_ib_header *hdr, - u32 hdrwords, struct hfi1_sge_state *ss, u32 len, - u32 plen, u32 dwords, u64 pbc); +int hfi1_verbs_send_pio(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, + u64 pbc); struct send_context *qp_to_send_context(struct hfi1_qp *qp, u8 sc5); diff --git a/drivers/staging/rdma/ipath/ipath_file_ops.c b/drivers/staging/rdma/ipath/ipath_file_ops.c index 13c3cd11ab92..6187b848b3ca 100644 --- a/drivers/staging/rdma/ipath/ipath_file_ops.c +++ b/drivers/staging/rdma/ipath/ipath_file_ops.c @@ -917,15 +917,15 @@ static int ipath_create_user_egr(struct ipath_portdata *pd) chunk = pd->port_rcvegrbuf_chunks; egrperchunk = pd->port_rcvegrbufs_perchunk; size = pd->port_rcvegrbuf_size; - pd->port_rcvegrbuf = kmalloc(chunk * sizeof(pd->port_rcvegrbuf[0]), - GFP_KERNEL); + pd->port_rcvegrbuf = kmalloc_array(chunk, sizeof(pd->port_rcvegrbuf[0]), + GFP_KERNEL); if (!pd->port_rcvegrbuf) { ret = -ENOMEM; goto bail; } pd->port_rcvegrbuf_phys = - kmalloc(chunk * sizeof(pd->port_rcvegrbuf_phys[0]), - GFP_KERNEL); + kmalloc_array(chunk, sizeof(pd->port_rcvegrbuf_phys[0]), + GFP_KERNEL); if (!pd->port_rcvegrbuf_phys) { ret = -ENOMEM; goto bail_rcvegrbuf; diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c index 3cdb40fea5ee..e5d29fe9d446 100644 --- a/drivers/staging/rtl8188eu/core/rtw_ap.c +++ b/drivers/staging/rtl8188eu/core/rtw_ap.c @@ -1240,11 +1240,6 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr) return 0; } -static void update_bcn_fixed_ie(struct adapter *padapter) -{ - DBG_88E("%s\n", __func__); -} - static void update_bcn_erpinfo_ie(struct adapter *padapter) { struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); @@ -1279,31 +1274,6 @@ static void update_bcn_erpinfo_ie(struct adapter *padapter) } } -static void update_bcn_htcap_ie(struct adapter *padapter) -{ - DBG_88E("%s\n", __func__); -} - -static void update_bcn_htinfo_ie(struct adapter *padapter) -{ - DBG_88E("%s\n", __func__); -} - -static void update_bcn_rsn_ie(struct adapter *padapter) -{ - DBG_88E("%s\n", __func__); -} - -static void update_bcn_wpa_ie(struct adapter *padapter) -{ - DBG_88E("%s\n", __func__); -} - -static void update_bcn_wmm_ie(struct adapter *padapter) -{ - DBG_88E("%s\n", __func__); -} - static void update_bcn_wps_ie(struct adapter *padapter) { u8 *pwps_ie = NULL, *pwps_ie_src; @@ -1354,22 +1324,12 @@ static void update_bcn_wps_ie(struct adapter *padapter) kfree(pbackup_remainder_ie); } -static void update_bcn_p2p_ie(struct adapter *padapter) -{ -} - static void update_bcn_vendor_spec_ie(struct adapter *padapter, u8 *oui) { DBG_88E("%s\n", __func__); - if (!memcmp(RTW_WPA_OUI, oui, 4)) - update_bcn_wpa_ie(padapter); - else if (!memcmp(WMM_OUI, oui, 4)) - update_bcn_wmm_ie(padapter); - else if (!memcmp(WPS_OUI, oui, 4)) + if (!memcmp(WPS_OUI, oui, 4)) update_bcn_wps_ie(padapter); - else if (!memcmp(P2P_OUI, oui, 4)) - update_bcn_p2p_ie(padapter); else DBG_88E("unknown OUI type!\n"); } @@ -1391,24 +1351,12 @@ void update_beacon(struct adapter *padapter, u8 ie_id, u8 *oui, u8 tx) spin_lock_bh(&pmlmepriv->bcn_update_lock); switch (ie_id) { - case 0xFF: - update_bcn_fixed_ie(padapter);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */ - break; case _TIM_IE_: update_BCNTIM(padapter); break; case _ERPINFO_IE_: update_bcn_erpinfo_ie(padapter); break; - case _HT_CAPABILITY_IE_: - update_bcn_htcap_ie(padapter); - break; - case _RSN_IE_2_: - update_bcn_rsn_ie(padapter); - break; - case _HT_ADD_INFO_IE_: - update_bcn_htinfo_ie(padapter); - break; case _VENDOR_SPECIFIC_IE_: update_bcn_vendor_spec_ie(padapter, oui); break; diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c b/drivers/staging/rtl8188eu/core/rtw_cmd.c index 9b7026e7d55b..433b926ceae7 100644 --- a/drivers/staging/rtl8188eu/core/rtw_cmd.c +++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c @@ -201,23 +201,20 @@ _next: if (rtw_cmd_filter(pcmdpriv, pcmd) == _FAIL) { pcmd->res = H2C_DROPPED; - goto post_process; - } - - if (pcmd->cmdcode < ARRAY_SIZE(wlancmds)) { - cmd_hdl = wlancmds[pcmd->cmdcode].h2cfuns; - - if (cmd_hdl) { - ret = cmd_hdl(pcmd->padapter, pcmd->parmbuf); - pcmd->res = ret; - } } else { - pcmd->res = H2C_PARAMETERS_ERROR; - } + if (pcmd->cmdcode < ARRAY_SIZE(wlancmds)) { + cmd_hdl = wlancmds[pcmd->cmdcode].h2cfuns; - cmd_hdl = NULL; + if (cmd_hdl) { + ret = cmd_hdl(pcmd->padapter, pcmd->parmbuf); + pcmd->res = ret; + } + } else { + pcmd->res = H2C_PARAMETERS_ERROR; + } -post_process: + cmd_hdl = NULL; + } /* call callback function for post-processed */ if (pcmd->cmdcode < ARRAY_SIZE(rtw_cmd_callback)) { @@ -242,15 +239,11 @@ post_process: pcmdpriv->cmdthd_running = false; /* free all cmd_obj resources */ - do { - pcmd = rtw_dequeue_cmd(&pcmdpriv->cmd_queue); - if (pcmd == NULL) - break; - + while ((pcmd = rtw_dequeue_cmd(&pcmdpriv->cmd_queue))) { /* DBG_88E("%s: leaving... drop cmdcode:%u\n", __func__, pcmd->cmdcode); */ rtw_free_cmd_obj(pcmd); - } while (1); + } up(&pcmdpriv->terminate_cmdthread_sema); @@ -570,31 +563,19 @@ u8 rtw_setopmode_cmd(struct adapter *padapter, enum ndis_802_11_network_infra n struct setopmode_parm *psetop; struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); - if (ph2c == NULL) { - res = false; - goto exit; - } psetop = kzalloc(sizeof(struct setopmode_parm), GFP_KERNEL); - - if (psetop == NULL) { + if (!ph2c || !psetop) { kfree(ph2c); - res = false; - goto exit; + kfree(psetop); + return false; } init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_); psetop->mode = (u8)networktype; - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - -exit: - - - return res; + return rtw_enqueue_cmd(pcmdpriv, ph2c); } u8 rtw_setstakey_cmd(struct adapter *padapter, u8 *psta, u8 unicast_key) @@ -607,28 +588,16 @@ u8 rtw_setstakey_cmd(struct adapter *padapter, u8 *psta, u8 unicast_key) struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct security_priv *psecuritypriv = &padapter->securitypriv; struct sta_info *sta = (struct sta_info *)psta; - u8 res = _SUCCESS; - ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); - if (ph2c == NULL) { - res = _FAIL; - goto exit; - } - psetstakey_para = kzalloc(sizeof(struct set_stakey_parm), GFP_KERNEL); - if (psetstakey_para == NULL) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - psetstakey_rsp = kzalloc(sizeof(struct set_stakey_rsp), GFP_KERNEL); - if (psetstakey_rsp == NULL) { + + if (!ph2c || !psetstakey_para || !psetstakey_rsp) { kfree(ph2c); kfree(psetstakey_para); - res = _FAIL; - goto exit; + kfree(psetstakey_rsp); + return _FAIL; } init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_); @@ -650,12 +619,7 @@ u8 rtw_setstakey_cmd(struct adapter *padapter, u8 *psta, u8 unicast_key) /* jeff: set this because at least sw key is ready */ padapter->securitypriv.busetkipkey = true; - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - -exit: - - - return res; + return rtw_enqueue_cmd(pcmdpriv, ph2c); } u8 rtw_clearstakey_cmd(struct adapter *padapter, u8 *psta, u8 entry, u8 enqueue) @@ -1086,31 +1050,19 @@ u8 rtw_ps_cmd(struct adapter *padapter) struct drvextra_cmd_parm *pdrvextra_cmd_parm; struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - ppscmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC); - if (ppscmd == NULL) { - res = _FAIL; - goto exit; - } - pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC); - if (pdrvextra_cmd_parm == NULL) { + if (!ppscmd || !pdrvextra_cmd_parm) { kfree(ppscmd); - res = _FAIL; - goto exit; + kfree(pdrvextra_cmd_parm); + return _FAIL; } pdrvextra_cmd_parm->ec_id = POWER_SAVING_CTRL_WK_CID; pdrvextra_cmd_parm->pbuf = NULL; init_h2fwcmd_w_parm_no_rsp(ppscmd, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra)); - res = rtw_enqueue_cmd(pcmdpriv, ppscmd); - -exit: - - - return res; + return rtw_enqueue_cmd(pcmdpriv, ppscmd); } #ifdef CONFIG_88EU_AP_MODE diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c index eb894233a785..2320fb11af24 100644 --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c @@ -224,7 +224,7 @@ static void efuse_read_phymap_from_txpktbuf( ) { u16 dbg_addr = 0; - u32 start = 0, passing_time = 0; + unsigned long start = 0; u8 reg_0x143 = 0; u32 lo32 = 0, hi32 = 0; u16 len = 0, count = 0; @@ -248,7 +248,7 @@ static void efuse_read_phymap_from_txpktbuf( usb_write8(adapter, REG_TXPKTBUF_DBG, 0); start = jiffies; while (!(reg_0x143 = usb_read8(adapter, REG_TXPKTBUF_DBG)) && - (passing_time = rtw_get_passing_time_ms(start)) < 1000) { + jiffies_to_msecs(jiffies - start) < 1000) { DBG_88E("%s polling reg_0x143:0x%02x, reg_0x106:0x%02x\n", __func__, reg_0x143, usb_read8(adapter, 0x106)); usleep_range(1000, 2000); } diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c index 22f5b45f5f7f..cf60717a6c19 100644 --- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c +++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c @@ -27,13 +27,6 @@ extern void indicate_wx_scan_complete_event(struct adapter *padapter); -#define IS_MAC_ADDRESS_BROADCAST(addr) \ -(\ - ((addr[0] == 0xff) && (addr[1] == 0xff) && \ - (addr[2] == 0xff) && (addr[3] == 0xff) && \ - (addr[4] == 0xff) && (addr[5] == 0xff)) ? true : false \ -) - u8 rtw_do_join(struct adapter *padapter) { struct list_head *plist, *phead; diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c b/drivers/staging/rtl8188eu/core/rtw_mlme.c index c1b82f71b682..abab854e6889 100644 --- a/drivers/staging/rtl8188eu/core/rtw_mlme.c +++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c @@ -163,7 +163,8 @@ exit: static void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 isfreeall) { - u32 curr_time, delta_time; + unsigned long curr_time; + u32 delta_time; u32 lifetime = SCANQUEUE_LIFETIME; struct __queue *free_queue = &(pmlmepriv->free_bss_pool); @@ -272,7 +273,7 @@ int rtw_if_up(struct adapter *padapter) void rtw_generate_random_ibss(u8 *pibss) { - u32 curtime = jiffies; + unsigned long curtime = jiffies; pibss[0] = 0x02; /* in ad-hoc mode bit1 must set to 1 */ pibss[1] = 0x11; @@ -365,20 +366,13 @@ struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue) phead = get_list_head(scanned_queue); - plist = phead->next; - - while (1) { - if (phead == plist) - break; - + for (plist = phead->next; plist != phead; plist = plist->next) { pwlan = container_of(plist, struct wlan_network, list); if (!pwlan->fixed) { if (oldest == NULL || time_after(oldest->last_scanned, pwlan->last_scanned)) oldest = pwlan; } - - plist = plist->next; } return oldest; } @@ -878,14 +872,14 @@ inline void rtw_indicate_scan_done(struct adapter *padapter, bool aborted) void rtw_scan_abort(struct adapter *adapter) { - u32 start; + unsigned long start; struct mlme_priv *pmlmepriv = &(adapter->mlmepriv); struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv); start = jiffies; pmlmeext->scan_abort = true; while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) && - rtw_get_passing_time_ms(start) <= 200) { + jiffies_to_msecs(jiffies - start) <= 200) { if (adapter->bDriverStopped || adapter->bSurpriseRemoved) break; DBG_88E(FUNC_NDEV_FMT"fw_state=_FW_UNDER_SURVEY!\n", FUNC_NDEV_ARG(adapter->pnetdev)); @@ -1474,6 +1468,7 @@ static int rtw_check_join_candidate(struct mlme_priv *pmlmepriv , struct wlan_network **candidate, struct wlan_network *competitor) { int updated = false; + unsigned long since_scan; struct adapter *adapter = container_of(pmlmepriv, struct adapter, mlmepriv); @@ -1494,7 +1489,8 @@ static int rtw_check_join_candidate(struct mlme_priv *pmlmepriv goto exit; if (pmlmepriv->to_roaming) { - if (rtw_get_passing_time_ms((u32)competitor->last_scanned) >= RTW_SCAN_RESULT_EXPIRE || + since_scan = jiffies - competitor->last_scanned; + if (jiffies_to_msecs(since_scan) >= RTW_SCAN_RESULT_EXPIRE || is_same_ess(&competitor->network, &pmlmepriv->cur_network.network) == false) goto exit; } diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c index d900546b672f..3eca6874b6df 100644 --- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c @@ -609,7 +609,7 @@ static void issue_probersp(struct adapter *padapter, unsigned char *da) return; } -static int _issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da, int wait_ack) +static int issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da, bool wait_ack) { int ret = _FAIL; struct xmit_frame *pmgntframe; @@ -702,22 +702,16 @@ exit: return ret; } -static inline void issue_probereq(struct adapter *padapter, - struct ndis_802_11_ssid *pssid, u8 *da) -{ - _issue_probereq(padapter, pssid, da, false); -} - static int issue_probereq_ex(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da, int try_cnt, int wait_ms) { int ret; int i = 0; - u32 start = jiffies; + unsigned long start = jiffies; do { - ret = _issue_probereq(padapter, pssid, da, wait_ms > 0 ? true : false); + ret = issue_probereq(padapter, pssid, da, wait_ms > 0 ? true : false); i++; @@ -738,11 +732,13 @@ static int issue_probereq_ex(struct adapter *padapter, if (da) DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n", FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter), - ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start)); + ret == _SUCCESS ? ", acked" : "", i, try_cnt, + jiffies_to_msecs(jiffies - start)); else DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n", FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter), - ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start)); + ret == _SUCCESS ? ", acked" : "", i, try_cnt, + jiffies_to_msecs(jiffies - start)); } exit: return ret; @@ -1299,7 +1295,7 @@ int issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int pow { int ret; int i = 0; - u32 start = jiffies; + unsigned long start = jiffies; struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network); @@ -1329,11 +1325,13 @@ int issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int pow if (da) DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n", FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter), - ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start)); + ret == _SUCCESS ? ", acked" : "", i, try_cnt, + jiffies_to_msecs(jiffies - start)); else DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n", FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter), - ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start)); + ret == _SUCCESS ? ", acked" : "", i, try_cnt, + jiffies_to_msecs(jiffies - start)); } exit: return ret; @@ -1424,7 +1422,7 @@ int issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int { int ret; int i = 0; - u32 start = jiffies; + unsigned long start = jiffies; struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network); @@ -1454,11 +1452,13 @@ int issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int if (da) DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n", FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter), - ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start)); + ret == _SUCCESS ? ", acked" : "", i, try_cnt, + jiffies_to_msecs(jiffies - start)); else DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n", FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter), - ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start)); + ret == _SUCCESS ? ", acked" : "", i, try_cnt, + jiffies_to_msecs(jiffies - start)); } exit: return ret; @@ -1536,7 +1536,7 @@ static int issue_deauth_ex(struct adapter *padapter, u8 *da, { int ret; int i = 0; - u32 start = jiffies; + unsigned long start = jiffies; do { ret = _issue_deauth(padapter, da, reason, wait_ms > 0 ? true : false); @@ -1559,11 +1559,13 @@ static int issue_deauth_ex(struct adapter *padapter, u8 *da, if (da) DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n", FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter), - ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start)); + ret == _SUCCESS ? ", acked" : "", i, try_cnt, + jiffies_to_msecs(jiffies - start)); else DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n", FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter), - ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start)); + ret == _SUCCESS ? ", acked" : "", i, try_cnt, + jiffies_to_msecs(jiffies - start)); } exit: return ret; @@ -1965,7 +1967,7 @@ unsigned int send_beacon(struct adapter *padapter) int issue = 0; int poll = 0; - u32 start = jiffies; + unsigned long start = jiffies; rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL); do { @@ -1981,13 +1983,16 @@ unsigned int send_beacon(struct adapter *padapter) if (padapter->bSurpriseRemoved || padapter->bDriverStopped) return _FAIL; if (!bxmitok) { - DBG_88E("%s fail! %u ms\n", __func__, rtw_get_passing_time_ms(start)); + DBG_88E("%s fail! %u ms\n", __func__, + jiffies_to_msecs(jiffies - start)); return _FAIL; } else { - u32 passing_time = rtw_get_passing_time_ms(start); + u32 passing_time = jiffies_to_msecs(jiffies - start); if (passing_time > 100 || issue > 3) - DBG_88E("%s success, issue:%d, poll:%d, %u ms\n", __func__, issue, poll, rtw_get_passing_time_ms(start)); + DBG_88E("%s success, issue:%d, poll:%d, %u ms\n", + __func__, issue, poll, + jiffies_to_msecs(jiffies - start)); return _SUCCESS; } } @@ -2029,24 +2034,28 @@ static void site_survey(struct adapter *padapter) for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) { if (pmlmeext->sitesurvey_res.ssid[i].SsidLength) { /* todo: to issue two probe req??? */ - issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL); + issue_probereq(padapter, + &(pmlmeext->sitesurvey_res.ssid[i]), + NULL, false); /* msleep(SURVEY_TO>>1); */ - issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL); + issue_probereq(padapter, + &(pmlmeext->sitesurvey_res.ssid[i]), + NULL, false); } } if (pmlmeext->sitesurvey_res.scan_mode == SCAN_ACTIVE) { /* todo: to issue two probe req??? */ - issue_probereq(padapter, NULL, NULL); + issue_probereq(padapter, NULL, NULL, false); /* msleep(SURVEY_TO>>1); */ - issue_probereq(padapter, NULL, NULL); + issue_probereq(padapter, NULL, NULL, false); } if (pmlmeext->sitesurvey_res.scan_mode == SCAN_ACTIVE) { /* todo: to issue two probe req??? */ - issue_probereq(padapter, NULL, NULL); + issue_probereq(padapter, NULL, NULL, false); /* msleep(SURVEY_TO>>1); */ - issue_probereq(padapter, NULL, NULL); + issue_probereq(padapter, NULL, NULL, false); } } @@ -4820,9 +4829,18 @@ void linked_status_chk(struct adapter *padapter) } else { if (rx_chk != _SUCCESS) { if (pmlmeext->retry == 0) { - issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress); - issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress); - issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress); + issue_probereq(padapter, + &pmlmeinfo->network.Ssid, + pmlmeinfo->network.MacAddress, + false); + issue_probereq(padapter, + &pmlmeinfo->network.Ssid, + pmlmeinfo->network.MacAddress, + false); + issue_probereq(padapter, + &pmlmeinfo->network.Ssid, + pmlmeinfo->network.MacAddress, + false); } } diff --git a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c index 9765946466ab..5e1ef9fdcf47 100644 --- a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c +++ b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c @@ -348,7 +348,7 @@ void rtw_set_rpwm(struct adapter *padapter, u8 pslv) static u8 PS_RDY_CHECK(struct adapter *padapter) { - u32 curr_time, delta_time; + unsigned long curr_time, delta_time; struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv; struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); @@ -418,7 +418,7 @@ void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_a */ s32 LPS_RF_ON_check(struct adapter *padapter, u32 delay_ms) { - u32 start_time; + unsigned long start_time; u8 bAwake = false; s32 err = 0; @@ -435,7 +435,7 @@ s32 LPS_RF_ON_check(struct adapter *padapter, u32 delay_ms) break; } - if (rtw_get_passing_time_ms(start_time) > delay_ms) { + if (jiffies_to_msecs(jiffies - start_time) > delay_ms) { err = -1; DBG_88E("%s: Wait for FW LPS leave more than %u ms!!!\n", __func__, delay_ms); break; @@ -561,24 +561,24 @@ int _rtw_pwr_wakeup(struct adapter *padapter, u32 ips_deffer_ms, const char *cal struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv; struct mlme_priv *pmlmepriv = &padapter->mlmepriv; unsigned long expires; + unsigned long start; int ret = _SUCCESS; expires = jiffies + msecs_to_jiffies(ips_deffer_ms); if (time_before(pwrpriv->ips_deny_time, expires)) pwrpriv->ips_deny_time = jiffies + msecs_to_jiffies(ips_deffer_ms); -{ - u32 start = jiffies; + start = jiffies; if (pwrpriv->ps_processing) { DBG_88E("%s wait ps_processing...\n", __func__); - while (pwrpriv->ps_processing && rtw_get_passing_time_ms(start) <= 3000) + while (pwrpriv->ps_processing && + jiffies_to_msecs(jiffies - start) <= 3000) usleep_range(1000, 3000); if (pwrpriv->ps_processing) DBG_88E("%s wait ps_processing timeout\n", __func__); else DBG_88E("%s wait ps_processing done\n", __func__); } -} /* System suspend is not allowed to wakeup */ if ((!pwrpriv->bInternalAutoSuspend) && (pwrpriv->bInSuspend)) { diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c b/drivers/staging/rtl8188eu/core/rtw_xmit.c index cabb810369bd..e778132b73dc 100644 --- a/drivers/staging/rtl8188eu/core/rtw_xmit.c +++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c @@ -641,7 +641,7 @@ static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitfr if (pattrib->psta) stainfo = pattrib->psta; else - stainfo = rtw_get_stainfo(&padapter->stapriv , &pattrib->ra[0]); + stainfo = rtw_get_stainfo(&padapter->stapriv, &pattrib->ra[0]); hw_hdr_offset = TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ); @@ -1702,12 +1702,12 @@ u32 rtw_get_ff_hwaddr(struct xmit_frame *pxmitframe) return addr; } -static void do_queue_select(struct adapter *padapter, struct pkt_attrib *pattrib) +static void do_queue_select(struct adapter *padapter, struct pkt_attrib *pattrib) { u8 qsel; qsel = pattrib->priority; - RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("### do_queue_select priority=%d , qsel = %d\n", pattrib->priority , qsel)); + RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("### do_queue_select priority=%d , qsel = %d\n", pattrib->priority, qsel)); pattrib->qsel = qsel; } @@ -2186,11 +2186,6 @@ void rtw_sctx_done_err(struct submit_ctx **sctx, int status) } } -void rtw_sctx_done(struct submit_ctx **sctx) -{ - rtw_sctx_done_err(sctx, RTW_SCTX_DONE_SUCCESS); -} - int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms) { struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops; diff --git a/drivers/staging/rtl8188eu/hal/fw.c b/drivers/staging/rtl8188eu/hal/fw.c index 23aa6d37acac..4d72537644b3 100644 --- a/drivers/staging/rtl8188eu/hal/fw.c +++ b/drivers/staging/rtl8188eu/hal/fw.c @@ -58,43 +58,31 @@ static void _rtl88e_fw_block_write(struct adapter *adapt, const u8 *buffer, u32 size) { u32 blk_sz = sizeof(u32); - u8 *buf_ptr = (u8 *)buffer; - u32 *pu4BytePtr = (u32 *)buffer; - u32 i, offset, blk_cnt, remain; + const u8 *byte_buffer; + const u32 *dword_buffer = (u32 *)buffer; + u32 i, write_address, blk_cnt, remain; blk_cnt = size / blk_sz; remain = size % blk_sz; - for (i = 0; i < blk_cnt; i++) { - offset = i * blk_sz; - usb_write32(adapt, (FW_8192C_START_ADDRESS + offset), - *(pu4BytePtr + i)); - } + write_address = FW_8192C_START_ADDRESS; - if (remain) { - offset = blk_cnt * blk_sz; - buf_ptr += offset; - for (i = 0; i < remain; i++) { - usb_write8(adapt, (FW_8192C_START_ADDRESS + - offset + i), *(buf_ptr + i)); - } - } + for (i = 0; i < blk_cnt; i++, write_address += blk_sz) + usb_write32(adapt, write_address, dword_buffer[i]); + + byte_buffer = buffer + blk_cnt * blk_sz; + for (i = 0; i < remain; i++, write_address++) + usb_write8(adapt, write_address, byte_buffer[i]); } static void _rtl88e_fill_dummy(u8 *pfwbuf, u32 *pfwlen) { - u32 fwlen = *pfwlen; - u8 remain = (u8)(fwlen % 4); - - remain = (remain == 0) ? 0 : (4 - remain); + u32 i; - while (remain > 0) { - pfwbuf[fwlen] = 0; - fwlen++; - remain--; - } + for (i = *pfwlen; i < roundup(*pfwlen, 4); i++) + pfwbuf[i] = 0; - *pfwlen = fwlen; + *pfwlen = i; } static void _rtl88e_fw_page_write(struct adapter *adapt, diff --git a/drivers/staging/rtl8188eu/hal/hal_com.c b/drivers/staging/rtl8188eu/hal/hal_com.c index 38e9fdc312d3..3871cda2eec2 100644 --- a/drivers/staging/rtl8188eu/hal/hal_com.c +++ b/drivers/staging/rtl8188eu/hal/hal_com.c @@ -32,19 +32,19 @@ void dump_chip_info(struct HAL_VERSION chip_vers) char buf[128]; cnt += sprintf((buf+cnt), "Chip Version Info: CHIP_8188E_"); - cnt += sprintf((buf+cnt), "%s_", IS_NORMAL_CHIP(chip_vers) ? + cnt += sprintf((buf+cnt), "%s_", chip_vers.ChipType == NORMAL_CHIP ? "Normal_Chip" : "Test_Chip"); - cnt += sprintf((buf+cnt), "%s_", IS_CHIP_VENDOR_TSMC(chip_vers) ? + cnt += sprintf((buf+cnt), "%s_", chip_vers.VendorType == CHIP_VENDOR_TSMC ? "TSMC" : "UMC"); - if (IS_A_CUT(chip_vers)) + if (chip_vers.CUTVersion == A_CUT_VERSION) cnt += sprintf((buf+cnt), "A_CUT_"); - else if (IS_B_CUT(chip_vers)) + else if (chip_vers.CUTVersion == B_CUT_VERSION) cnt += sprintf((buf+cnt), "B_CUT_"); - else if (IS_C_CUT(chip_vers)) + else if (chip_vers.CUTVersion == C_CUT_VERSION) cnt += sprintf((buf+cnt), "C_CUT_"); - else if (IS_D_CUT(chip_vers)) + else if (chip_vers.CUTVersion == D_CUT_VERSION) cnt += sprintf((buf+cnt), "D_CUT_"); - else if (IS_E_CUT(chip_vers)) + else if (chip_vers.CUTVersion == E_CUT_VERSION) cnt += sprintf((buf+cnt), "E_CUT_"); else cnt += sprintf((buf+cnt), "UNKNOWN_CUT(%d)_", diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_dm.c b/drivers/staging/rtl8188eu/hal/rtl8188e_dm.c index fca590949409..199a77acd7a9 100644 --- a/drivers/staging/rtl8188eu/hal/rtl8188e_dm.c +++ b/drivers/staging/rtl8188eu/hal/rtl8188e_dm.c @@ -67,7 +67,7 @@ static void Init_ODM_ComInfo_88E(struct adapter *Adapter) ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_FAB_VER, fab_ver); ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_CUT_VER, cut_ver); - ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_MP_TEST_CHIP, IS_NORMAL_CHIP(hal_data->VersionID)); + ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_MP_TEST_CHIP, hal_data->VersionID.ChipType == NORMAL_CHIP ? true : false); ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_PATCH_ID, hal_data->CustomerID); ODM_CmnInfoInit(dm_odm, ODM_CMNINFO_BWIFI_TEST, Adapter->registrypriv.wifi_spec); diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c index e3e5d6f5d4f9..2592bc298f84 100644 --- a/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c +++ b/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c @@ -53,7 +53,7 @@ s32 iol_execute(struct adapter *padapter, u8 control) { s32 status = _FAIL; u8 reg_0x88 = 0; - u32 start = 0, passing_time = 0; + unsigned long start = 0; control = control&0x0f; reg_0x88 = usb_read8(padapter, REG_HMEBOX_E0); @@ -61,8 +61,8 @@ s32 iol_execute(struct adapter *padapter, u8 control) start = jiffies; while ((reg_0x88 = usb_read8(padapter, REG_HMEBOX_E0)) & control && - (passing_time = rtw_get_passing_time_ms(start)) < 1000) { - ; + jiffies_to_msecs(jiffies - start) < 1000) { + udelay(5); } reg_0x88 = usb_read8(padapter, REG_HMEBOX_E0); @@ -242,6 +242,7 @@ static s32 _LLTWrite(struct adapter *padapter, u32 address, u32 data) status = _FAIL; break; } + udelay(5); } while (count++); return status; diff --git a/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c b/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c index 7c5086ecff17..e04303ce80af 100644 --- a/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c +++ b/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c @@ -463,30 +463,26 @@ s32 rtl8188eu_xmitframe_complete(struct adapter *adapt, struct xmit_priv *pxmitp } /* 3 1. pick up first frame */ - do { - rtw_free_xmitframe(pxmitpriv, pxmitframe); - - pxmitframe = rtw_dequeue_xframe(pxmitpriv, pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry); - if (pxmitframe == NULL) { - /* no more xmit frame, release xmit buffer */ - rtw_free_xmitbuf(pxmitpriv, pxmitbuf); - return false; - } + rtw_free_xmitframe(pxmitpriv, pxmitframe); - pxmitframe->pxmitbuf = pxmitbuf; - pxmitframe->buf_addr = pxmitbuf->pbuf; - pxmitbuf->priv_data = pxmitframe; + pxmitframe = rtw_dequeue_xframe(pxmitpriv, pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry); + if (pxmitframe == NULL) { + /* no more xmit frame, release xmit buffer */ + rtw_free_xmitbuf(pxmitpriv, pxmitbuf); + return false; + } - pxmitframe->agg_num = 1; /* alloc xmitframe should assign to 1. */ - pxmitframe->pkt_offset = 1; /* first frame of aggregation, reserve offset */ + pxmitframe->pxmitbuf = pxmitbuf; + pxmitframe->buf_addr = pxmitbuf->pbuf; + pxmitbuf->priv_data = pxmitframe; - rtw_xmitframe_coalesce(adapt, pxmitframe->pkt, pxmitframe); + pxmitframe->agg_num = 1; /* alloc xmitframe should assign to 1. */ + pxmitframe->pkt_offset = 1; /* first frame of aggregation, reserve offset */ - /* always return ndis_packet after rtw_xmitframe_coalesce */ - rtw_os_xmit_complete(adapt, pxmitframe); + rtw_xmitframe_coalesce(adapt, pxmitframe->pkt, pxmitframe); - break; - } while (1); + /* always return ndis_packet after rtw_xmitframe_coalesce */ + rtw_os_xmit_complete(adapt, pxmitframe); /* 3 2. aggregate same priority and same DA(AP or STA) frames */ pfirstframe = pxmitframe; diff --git a/drivers/staging/rtl8188eu/hal/usb_halinit.c b/drivers/staging/rtl8188eu/hal/usb_halinit.c index 7e72259f0e40..5789e1e23f0a 100644 --- a/drivers/staging/rtl8188eu/hal/usb_halinit.c +++ b/drivers/staging/rtl8188eu/hal/usb_halinit.c @@ -684,7 +684,7 @@ static u32 rtl8188eu_hal_init(struct adapter *Adapter) struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter); struct pwrctrl_priv *pwrctrlpriv = &Adapter->pwrctrlpriv; struct registry_priv *pregistrypriv = &Adapter->registrypriv; - u32 init_start_time = jiffies; + unsigned long init_start_time = jiffies; #define HAL_INIT_PROFILE_TAG(stage) do {} while (0) @@ -903,7 +903,8 @@ HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_LCK); exit: HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_END); - DBG_88E("%s in %dms\n", __func__, rtw_get_passing_time_ms(init_start_time)); + DBG_88E("%s in %dms\n", __func__, + jiffies_to_msecs(jiffies - init_start_time)); return status; @@ -1149,14 +1150,15 @@ static void _ReadRFType(struct adapter *Adapter) static void _ReadAdapterInfo8188EU(struct adapter *Adapter) { - u32 start = jiffies; + unsigned long start = jiffies; MSG_88E("====> %s\n", __func__); _ReadRFType(Adapter);/* rf_chip -> _InitRFType() */ _ReadPROMContent(Adapter); - MSG_88E("<==== %s in %d ms\n", __func__, rtw_get_passing_time_ms(start)); + MSG_88E("<==== %s in %d ms\n", __func__, + jiffies_to_msecs(jiffies - start)); } #define GPIO_DEBUG_PORT_NUM 0 diff --git a/drivers/staging/rtl8188eu/include/HalVerDef.h b/drivers/staging/rtl8188eu/include/HalVerDef.h index 56b4ff08e509..6f2b2a436b04 100644 --- a/drivers/staging/rtl8188eu/include/HalVerDef.h +++ b/drivers/staging/rtl8188eu/include/HalVerDef.h @@ -47,37 +47,4 @@ struct HAL_VERSION { enum HAL_VENDOR VendorType; }; -/* Get element */ -#define GET_CVID_CHIP_TYPE(version) (((version).ChipType)) -#define GET_CVID_MANUFACTUER(version) (((version).VendorType)) -#define GET_CVID_CUT_VERSION(version) (((version).CUTVersion)) - -/* Common Macro. -- */ -/* HAL_VERSION VersionID */ - -/* HAL_CHIP_TYPE_E */ -#define IS_TEST_CHIP(version) \ - ((GET_CVID_CHIP_TYPE(version) == TEST_CHIP) ? true : false) -#define IS_NORMAL_CHIP(version) \ - ((GET_CVID_CHIP_TYPE(version) == NORMAL_CHIP) ? true : false) - -/* HAL_CUT_VERSION_E */ -#define IS_A_CUT(version) \ - ((GET_CVID_CUT_VERSION(version) == A_CUT_VERSION) ? true : false) -#define IS_B_CUT(version) \ - ((GET_CVID_CUT_VERSION(version) == B_CUT_VERSION) ? true : false) -#define IS_C_CUT(version) \ - ((GET_CVID_CUT_VERSION(version) == C_CUT_VERSION) ? true : false) -#define IS_D_CUT(version) \ - ((GET_CVID_CUT_VERSION(version) == D_CUT_VERSION) ? true : false) -#define IS_E_CUT(version) \ - ((GET_CVID_CUT_VERSION(version) == E_CUT_VERSION) ? true : false) - - -/* HAL_VENDOR_E */ -#define IS_CHIP_VENDOR_TSMC(version) \ - ((GET_CVID_MANUFACTUER(version) == CHIP_VENDOR_TSMC) ? true : false) -#define IS_CHIP_VENDOR_UMC(version) \ - ((GET_CVID_MANUFACTUER(version) == CHIP_VENDOR_UMC) ? true : false) - #endif diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h index e24fe8cc3d0b..22de53d6539a 100644 --- a/drivers/staging/rtl8188eu/include/osdep_service.h +++ b/drivers/staging/rtl8188eu/include/osdep_service.h @@ -87,8 +87,6 @@ u32 _rtw_down_sema(struct semaphore *sema); void _rtw_init_queue(struct __queue *pqueue); -s32 rtw_get_passing_time_ms(u32 start); - struct rtw_netdev_priv_indicator { void *priv; u32 sizeof_priv; diff --git a/drivers/staging/rtl8188eu/include/rtw_xmit.h b/drivers/staging/rtl8188eu/include/rtw_xmit.h index 62f5db169523..b7c20883d355 100644 --- a/drivers/staging/rtl8188eu/include/rtw_xmit.h +++ b/drivers/staging/rtl8188eu/include/rtw_xmit.h @@ -197,7 +197,6 @@ enum { void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms); int rtw_sctx_wait(struct submit_ctx *sctx); void rtw_sctx_done_err(struct submit_ctx **sctx, int status); -void rtw_sctx_done(struct submit_ctx **sctx); struct xmit_buf { struct list_head list; diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c b/drivers/staging/rtl8188eu/os_dep/os_intfs.c index d063d02db7f0..9201b94d017c 100644 --- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c +++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c @@ -1100,7 +1100,7 @@ netdev_open_error: int rtw_ips_pwr_up(struct adapter *padapter) { int result; - u32 start_time = jiffies; + unsigned long start_time = jiffies; DBG_88E("===> rtw_ips_pwr_up..............\n"); rtw_reset_drv_sw(padapter); @@ -1109,13 +1109,14 @@ int rtw_ips_pwr_up(struct adapter *padapter) rtw_led_control(padapter, LED_CTL_NO_LINK); - DBG_88E("<=== rtw_ips_pwr_up.............. in %dms\n", rtw_get_passing_time_ms(start_time)); + DBG_88E("<=== rtw_ips_pwr_up.............. in %dms\n", + jiffies_to_msecs(jiffies - start_time)); return result; } void rtw_ips_pwr_down(struct adapter *padapter) { - u32 start_time = jiffies; + unsigned long start_time = jiffies; DBG_88E("===> rtw_ips_pwr_down...................\n"); @@ -1124,7 +1125,8 @@ void rtw_ips_pwr_down(struct adapter *padapter) rtw_led_control(padapter, LED_CTL_POWER_OFF); rtw_ips_dev_unload(padapter); - DBG_88E("<=== rtw_ips_pwr_down..................... in %dms\n", rtw_get_passing_time_ms(start_time)); + DBG_88E("<=== rtw_ips_pwr_down..................... in %dms\n", + jiffies_to_msecs(jiffies - start_time)); } void rtw_ips_dev_unload(struct adapter *padapter) diff --git a/drivers/staging/rtl8188eu/os_dep/osdep_service.c b/drivers/staging/rtl8188eu/os_dep/osdep_service.c index 466cd76fc1c4..d87b54711c0d 100644 --- a/drivers/staging/rtl8188eu/os_dep/osdep_service.c +++ b/drivers/staging/rtl8188eu/os_dep/osdep_service.c @@ -77,12 +77,6 @@ void _rtw_init_queue(struct __queue *pqueue) spin_lock_init(&(pqueue->lock)); } -/* the input parameter start must be in jiffies */ -inline s32 rtw_get_passing_time_ms(u32 start) -{ - return jiffies_to_msecs(jiffies-start); -} - struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_priv) { diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c index 82a7c27c517f..01d50f7c1667 100644 --- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c +++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c @@ -227,7 +227,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message) struct net_device *pnetdev = padapter->pnetdev; struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv; - u32 start_time = jiffies; + unsigned long start_time = jiffies; pr_debug("==> %s (%s:%d)\n", __func__, current->comm, current->pid); @@ -282,7 +282,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message) exit: pr_debug("<=== %s .............. in %dms\n", __func__, - rtw_get_passing_time_ms(start_time)); + jiffies_to_msecs(jiffies - start_time)); return 0; } @@ -292,7 +292,7 @@ static int rtw_resume_process(struct adapter *padapter) struct net_device *pnetdev; struct pwrctrl_priv *pwrpriv = NULL; int ret = -1; - u32 start_time = jiffies; + unsigned long start_time = jiffies; pr_debug("==> %s (%s:%d)\n", __func__, current->comm, current->pid); @@ -323,7 +323,7 @@ exit: if (pwrpriv) pwrpriv->bInSuspend = false; pr_debug("<=== %s return %d.............. in %dms\n", __func__, - ret, rtw_get_passing_time_ms(start_time)); + ret, jiffies_to_msecs(jiffies - start_time)); return ret; } diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c index 0b407feb5407..5e3bbe5c3ca4 100644 --- a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c +++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c @@ -90,13 +90,12 @@ void rtl92e_set_bb_reg(struct net_device *dev, u32 dwRegAddr, u32 dwBitMask, u32 rtl92e_get_bb_reg(struct net_device *dev, u32 dwRegAddr, u32 dwBitMask) { - u32 Ret = 0, OriginalValue, BitShift; + u32 OriginalValue, BitShift; OriginalValue = rtl92e_readl(dev, dwRegAddr); BitShift = _rtl92e_calculate_bit_shift(dwBitMask); - Ret = (OriginalValue & dwBitMask) >> BitShift; - return Ret; + return (OriginalValue & dwBitMask) >> BitShift; } static u32 _rtl92e_phy_rf_read(struct net_device *dev, diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index e06864f64beb..f4a4eae72aa4 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -5114,21 +5114,6 @@ static void __exit rtl8192_usb_module_exit(void) RT_TRACE(COMP_DOWN, "Exiting"); } - -void rtl8192_try_wake_queue(struct net_device *dev, int pri) -{ - unsigned long flags; - short enough_desc; - struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); - - spin_lock_irqsave(&priv->tx_lock, flags); - enough_desc = check_nic_enough_desc(dev, pri); - spin_unlock_irqrestore(&priv->tx_lock, flags); - - if (enough_desc) - ieee80211_wake_queue(priv->ieee80211); -} - void EnableHWSecurityConfig8192(struct net_device *dev) { u8 SECR_value = 0x0; diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c index 70656441c145..f264d88364a1 100644 --- a/drivers/staging/rtl8192u/r819xU_phy.c +++ b/drivers/staging/rtl8192u/r819xU_phy.c @@ -38,21 +38,6 @@ static u32 RF_CHANNEL_TABLE_ZEBRA[] = { #define rtl819XAGCTAB_Array Rtl8192UsbAGCTAB_Array /****************************************************************************** - * function: This function reads BB parameters from header file we generate, - * and does register read/write - * input: u32 bitmask //taget bit pos in the addr to be modified - * output: none - * return: u32 return the shift bit position of the mask - ******************************************************************************/ -static u32 rtl8192_CalculateBitShift(u32 bitmask) -{ - u32 i; - - i = ffs(bitmask) - 1; - return i; -} - -/****************************************************************************** * function: This function checks different RF type to execute legal judgement. * If RF Path is illegal, we will return false. * input: net_device *dev @@ -94,7 +79,7 @@ void rtl8192_setBBreg(struct net_device *dev, u32 reg_addr, u32 bitmask, if (bitmask != bMaskDWord) { read_nic_dword(dev, reg_addr, ®); - bitshift = rtl8192_CalculateBitShift(bitmask); + bitshift = ffs(bitmask) - 1; reg &= ~bitmask; reg |= data << bitshift; write_nic_dword(dev, reg_addr, reg); @@ -117,7 +102,7 @@ u32 rtl8192_QueryBBReg(struct net_device *dev, u32 reg_addr, u32 bitmask) u32 reg, bitshift; read_nic_dword(dev, reg_addr, ®); - bitshift = rtl8192_CalculateBitShift(bitmask); + bitshift = ffs(bitmask) - 1; return (reg & bitmask) >> bitshift; } @@ -306,7 +291,7 @@ void rtl8192_phy_SetRFReg(struct net_device *dev, RF90_RADIO_PATH_E eRFPath, if (bitmask != bMask12Bits) { /* RF data is 12 bits only */ reg = phy_FwRFSerialRead(dev, eRFPath, reg_addr); - bitshift = rtl8192_CalculateBitShift(bitmask); + bitshift = ffs(bitmask) - 1; reg &= ~bitmask; reg |= data << bitshift; @@ -321,7 +306,7 @@ void rtl8192_phy_SetRFReg(struct net_device *dev, RF90_RADIO_PATH_E eRFPath, if (bitmask != bMask12Bits) { /* RF data is 12 bits only */ reg = rtl8192_phy_RFSerialRead(dev, eRFPath, reg_addr); - bitshift = rtl8192_CalculateBitShift(bitmask); + bitshift = ffs(bitmask) - 1; reg &= ~bitmask; reg |= data << bitshift; @@ -356,7 +341,7 @@ u32 rtl8192_phy_QueryRFReg(struct net_device *dev, RF90_RADIO_PATH_E eRFPath, } else { reg = rtl8192_phy_RFSerialRead(dev, eRFPath, reg_addr); } - bitshift = rtl8192_CalculateBitShift(bitmask); + bitshift = ffs(bitmask) - 1; reg = (reg & bitmask) >> bitshift; return reg; diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c index a4a002b55128..04f727fc95ea 100644 --- a/drivers/staging/rtl8712/rtl871x_mlme.c +++ b/drivers/staging/rtl8712/rtl871x_mlme.c @@ -123,7 +123,7 @@ static void _free_network(struct mlme_priv *pmlmepriv, spin_unlock_irqrestore(&free_queue->lock, irqL); } -static void _free_network_nolock(struct mlme_priv *pmlmepriv, +static void free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork) { struct __queue *free_queue = &pmlmepriv->free_bss_pool; @@ -234,12 +234,6 @@ static struct wlan_network *alloc_network(struct mlme_priv *pmlmepriv) return _r8712_alloc_network(pmlmepriv); } -static void free_network_nolock(struct mlme_priv *pmlmepriv, - struct wlan_network *pnetwork) -{ - _free_network_nolock(pmlmepriv, pnetwork); -} - void r8712_free_network_queue(struct _adapter *dev) { _free_network_queue(dev); diff --git a/drivers/staging/rtl8723au/core/rtw_efuse.c b/drivers/staging/rtl8723au/core/rtw_efuse.c index 906b5782d165..f174b4d1a018 100644 --- a/drivers/staging/rtl8723au/core/rtw_efuse.c +++ b/drivers/staging/rtl8723au/core/rtw_efuse.c @@ -273,48 +273,6 @@ u8 EFUSE_Read1Byte23a(struct rtw_adapter *Adapter, u16 Address) return 0xFF; } -/* Copy from WMAC fot EFUSE write 1 byte. */ -void EFUSE_Write1Byte(struct rtw_adapter *Adapter, u16 Address, u8 Value) -{ - u8 Bytetemp = {0x00}; - u8 temp = {0x00}; - u32 k = 0; - u16 contentLen = 0; - - EFUSE_GetEfuseDefinition23a(Adapter, EFUSE_WIFI, - TYPE_EFUSE_REAL_CONTENT_LEN, - (void *)&contentLen); - - if (Address < contentLen) { /* E-fuse 512Byte */ - rtl8723au_write8(Adapter, EFUSE_CTRL, Value); - - /* Write E-fuse Register address bit0~7 */ - temp = Address & 0xFF; - rtl8723au_write8(Adapter, EFUSE_CTRL+1, temp); - Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+2); - - /* Write E-fuse Register address bit8~9 */ - temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC); - rtl8723au_write8(Adapter, EFUSE_CTRL+2, temp); - - /* Write 0x30[31]= 1 */ - Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3); - temp = Bytetemp | 0x80; - rtl8723au_write8(Adapter, EFUSE_CTRL+3, temp); - - /* Wait Write-ready (0x30[31]= 0) */ - Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3); - while (Bytetemp & 0x80) { - Bytetemp = rtl8723au_read8(Adapter, EFUSE_CTRL+3); - k++; - if (k == 100) { - k = 0; - break; - } - } - } -} - /* Read one byte from real Efuse. */ int efuse_OneByteRead23a(struct rtw_adapter *pAdapter, u16 addr, u8 *data) { @@ -501,7 +459,8 @@ int rtw_BT_efuse_map_read23a(struct rtw_adapter *padapter, } /* Read All Efuse content */ -void Efuse_ReadAllMap(struct rtw_adapter *pAdapter, u8 efuseType, u8 *Efuse) +static void Efuse_ReadAllMap(struct rtw_adapter *pAdapter, u8 efuseType, + u8 *Efuse) { u16 mapLen = 0; diff --git a/drivers/staging/sm750fb/modedb.h b/drivers/staging/sm750fb/modedb.h deleted file mode 100644 index 83cb2e2ae51a..000000000000 --- a/drivers/staging/sm750fb/modedb.h +++ /dev/null @@ -1,233 +0,0 @@ - -static const struct fb_videomode modedb2[] = { - { - /* 640x400 @ 70 Hz, 31.5 kHz hsync */ - NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2, - 0, FB_VMODE_NONINTERLACED - }, { - /* 640x480 @ 60 Hz, 31.5 kHz hsync */ - NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2, - 0, FB_VMODE_NONINTERLACED - }, { - /* 800x600 @ 56 Hz, 35.15 kHz hsync */ - NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */ - NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8, - 0, FB_VMODE_INTERLACED - }, { - /* 640x400 @ 85 Hz, 37.86 kHz hsync */ - NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3, - FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED - }, { - /* 640x480 @ 72 Hz, 36.5 kHz hsync */ - NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3, - 0, FB_VMODE_NONINTERLACED - }, { - /* 640x480 @ 75 Hz, 37.50 kHz hsync */ - NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3, - 0, FB_VMODE_NONINTERLACED - }, { - /* 800x600 @ 60 Hz, 37.8 kHz hsync */ - NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4, - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED - }, { - /* 640x480 @ 85 Hz, 43.27 kHz hsync */ - NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */ - NULL, 69, 1152, 864, 15384, 96, 16, 110, 1, 216, 10, - 0, FB_VMODE_INTERLACED - }, { - /* 800x600 @ 72 Hz, 48.0 kHz hsync */ - NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6, - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED - }, { - /* 1024x768 @ 60 Hz, 48.4 kHz hsync */ - NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6, - 0, FB_VMODE_NONINTERLACED - }, { - /* 640x480 @ 100 Hz, 53.01 kHz hsync */ - NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1152x864 @ 60 Hz, 53.5 kHz hsync */ - NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8, - 0, FB_VMODE_NONINTERLACED - }, { - /* 800x600 @ 85 Hz, 55.84 kHz hsync */ - NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1024x768 @ 70 Hz, 56.5 kHz hsync */ - NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1280x960-60 VESA */ - NULL, 60, 1280, 960, 9259, 312, 96, 36, 1, 112, 3, - FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA - }, { - /* 1280x1024-60 VESA */ - NULL, 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3, - FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA - }, { - /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */ - NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12, - 0, FB_VMODE_INTERLACED - }, { - /* 800x600 @ 100 Hz, 64.02 kHz hsync */ - NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1024x768 @ 76 Hz, 62.5 kHz hsync */ - NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1152x864 @ 70 Hz, 62.4 kHz hsync */ - NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */ - NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1400x1050 @ 60Hz, 63.9 kHz hsync */ - NULL, 68, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/ - NULL, 75, 1400, 1050, 9271, 120, 56, 13, 0, 112, 3, - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED - }, { - /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/ - NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3, - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED - }, { - /* 1024x768 @ 85 Hz, 70.24 kHz hsync */ - NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1152x864 @ 78 Hz, 70.8 kHz hsync */ - NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */ - NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1600x1200 @ 60Hz, 75.00 kHz hsync */ - NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3, - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED - }, { - /* 1152x864 @ 84 Hz, 76.0 kHz hsync */ - NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */ - NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1024x768 @ 100Hz, 80.21 kHz hsync */ - NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */ - NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */ - NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1152x864 @ 100 Hz, 89.62 kHz hsync */ - NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */ - NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3, - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED - }, { - /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */ - NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3, - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED - }, { - /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */ - NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3, - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED - }, { - /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */ - NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15, - 0, FB_VMODE_NONINTERLACED - }, { - /* 1800x1440 @ 64Hz, 96.15 kHz hsync */ - NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3, - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED - }, { - /* 1800x1440 @ 70Hz, 104.52 kHz hsync */ - NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3, - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, - FB_VMODE_NONINTERLACED - }, { - /* 512x384 @ 78 Hz, 31.50 kHz hsync */ - NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3, - 0, FB_VMODE_NONINTERLACED - }, { - /* 512x384 @ 85 Hz, 34.38 kHz hsync */ - NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3, - 0, FB_VMODE_NONINTERLACED - }, { - /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */ - NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1, - 0, FB_VMODE_DOUBLE - }, { - /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */ - NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1, - 0, FB_VMODE_DOUBLE - }, { - /* 320x240 @ 72 Hz, 36.5 kHz hsync */ - NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2, - 0, FB_VMODE_DOUBLE - }, { - /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */ - NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1, - 0, FB_VMODE_DOUBLE - }, { - /* 400x300 @ 60 Hz, 37.8 kHz hsync */ - NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2, - 0, FB_VMODE_DOUBLE - }, { - /* 400x300 @ 72 Hz, 48.0 kHz hsync */ - NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3, - 0, FB_VMODE_DOUBLE - }, { - /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */ - NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1, - 0, FB_VMODE_DOUBLE - }, { - /* 480x300 @ 60 Hz, 37.8 kHz hsync */ - NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2, - 0, FB_VMODE_DOUBLE - }, { - /* 480x300 @ 63 Hz, 39.6 kHz hsync */ - NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2, - 0, FB_VMODE_DOUBLE - }, { - /* 480x300 @ 72 Hz, 48.0 kHz hsync */ - NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3, - 0, FB_VMODE_DOUBLE - }, -}; -static const int nmodedb2 = sizeof(modedb2); diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c index 860e1c288ad5..c78421b5b0e7 100644 --- a/drivers/staging/sm750fb/sm750.c +++ b/drivers/staging/sm750fb/sm750.c @@ -21,8 +21,6 @@ #include "sm750_accel.h" #include "sm750_cursor.h" -#include "modedb.h" - /* * #ifdef __BIG_ENDIAN * ssize_t lynxfb_ops_write(struct fb_info *info, const char __user *buf, diff --git a/drivers/staging/unisys/include/channel.h b/drivers/staging/unisys/include/channel.h index c6c24423a7f0..5af59a5fce61 100644 --- a/drivers/staging/unisys/include/channel.h +++ b/drivers/staging/unisys/include/channel.h @@ -60,15 +60,19 @@ enum channel_clientstate { CHANNELCLI_DISABLED = 1, /* client can see channel but is NOT * allowed to use it unless given TBD * explicit request (should actually be - * < DETACHED) */ + * < DETACHED) + */ CHANNELCLI_ATTACHING = 2, /* legacy EFI client request - * for EFI server to attach */ + * for EFI server to attach + */ CHANNELCLI_ATTACHED = 3, /* idle, but client may want - * to use channel any time */ + * to use channel any time + */ CHANNELCLI_BUSY = 4, /* client either wants to use or is - * using channel */ - CHANNELCLI_OWNED = 5 /* "no worries" state - client can - * access channel anytime */ + * using channel + */ + CHANNELCLI_OWNED = 5 /* "no worries" state - client can */ + /* access channel anytime */ }; static inline const u8 * @@ -116,11 +120,13 @@ ULTRA_CHANNELCLI_STRING(u32 v) /* Values for ULTRA_CHANNEL_PROTOCOL.CliErrorBoot: */ /* throttling invalid boot channel statetransition error due to client - * disabled */ + * disabled + */ #define ULTRA_CLIERRORBOOT_THROTTLEMSG_DISABLED 0x01 /* throttling invalid boot channel statetransition error due to client - * not attached */ + * not attached + */ #define ULTRA_CLIERRORBOOT_THROTTLEMSG_NOTATTACHED 0x02 /* throttling invalid boot channel statetransition error due to busy channel */ @@ -128,24 +134,28 @@ ULTRA_CHANNELCLI_STRING(u32 v) /* Values for ULTRA_CHANNEL_PROTOCOL.CliErrorOS: */ /* throttling invalid guest OS channel statetransition error due to - * client disabled */ + * client disabled + */ #define ULTRA_CLIERROROS_THROTTLEMSG_DISABLED 0x01 /* throttling invalid guest OS channel statetransition error due to - * client not attached */ + * client not attached + */ #define ULTRA_CLIERROROS_THROTTLEMSG_NOTATTACHED 0x02 /* throttling invalid guest OS channel statetransition error due to - * busy channel */ + * busy channel + */ #define ULTRA_CLIERROROS_THROTTLEMSG_BUSY 0x04 /* Values for ULTRA_CHANNEL_PROTOCOL.Features: This define exists so -* that windows guest can look at the FeatureFlags in the io channel, -* and configure the windows driver to use interrupts or not based on -* this setting. This flag is set in uislib after the -* ULTRA_VHBA_init_channel is called. All feature bits for all -* channels should be defined here. The io channel feature bits are -* defined right here */ + * that windows guest can look at the FeatureFlags in the io channel, + * and configure the windows driver to use interrupts or not based on + * this setting. This flag is set in uislib after the + * ULTRA_VHBA_init_channel is called. All feature bits for all + * channels should be defined here. The io channel feature bits are + * defined right here + */ #define ULTRA_IO_DRIVER_ENABLES_INTS (0x1ULL << 1) #define ULTRA_IO_CHANNEL_IS_POLLING (0x1ULL << 3) #define ULTRA_IO_IOVM_IS_OK_WITH_DRIVER_DISABLING_INTS (0x1ULL << 4) @@ -156,7 +166,7 @@ ULTRA_CHANNELCLI_STRING(u32 v) struct channel_header { u64 signature; /* Signature */ u32 legacy_state; /* DEPRECATED - being replaced by */ - /* / SrvState, CliStateBoot, and CliStateOS below */ + /* SrvState, CliStateBoot, and CliStateOS below */ u32 header_size; /* sizeof(struct channel_header) */ u64 size; /* Total size of this channel in bytes */ u64 features; /* Flags to modify behavior */ @@ -169,25 +179,32 @@ struct channel_header { uuid_le zone_uuid; /* Guid of Channel's zone */ u32 cli_str_offset; /* offset from channel header to * nul-terminated ClientString (0 if - * ClientString not present) */ + * ClientString not present) + */ u32 cli_state_boot; /* CHANNEL_CLIENTSTATE of pre-boot - * EFI client of this channel */ + * EFI client of this channel + */ u32 cmd_state_cli; /* CHANNEL_COMMANDSTATE (overloaded in * Windows drivers, see ServerStateUp, - * ServerStateDown, etc) */ + * ServerStateDown, etc) + */ u32 cli_state_os; /* CHANNEL_CLIENTSTATE of Guest OS - * client of this channel */ + * client of this channel + */ u32 ch_characteristic; /* CHANNEL_CHARACTERISTIC_<xxx> */ u32 cmd_state_srv; /* CHANNEL_COMMANDSTATE (overloaded in * Windows drivers, see ServerStateUp, - * ServerStateDown, etc) */ + * ServerStateDown, etc) + */ u32 srv_state; /* CHANNEL_SERVERSTATE */ u8 cli_error_boot; /* bits to indicate err states for * boot clients, so err messages can - * be throttled */ + * be throttled + */ u8 cli_error_os; /* bits to indicate err states for OS * clients, so err messages can be - * throttled */ + * throttled + */ u8 filler[1]; /* Pad out to 128 byte cacheline */ /* Please add all new single-byte values below here */ u8 recover_channel; @@ -205,29 +222,33 @@ struct signal_queue_header { u64 features; /* Flags to modify behavior */ u64 num_sent; /* Total # of signals placed in this queue */ u64 num_overflows; /* Total # of inserts failed due to - * full queue */ + * full queue + */ u32 signal_size; /* Total size of a signal for this queue */ u32 max_slots; /* Max # of slots in queue, 1 slot is - * always empty */ + * always empty + */ u32 max_signals; /* Max # of signals in queue - * (MaxSignalSlots-1) */ + * (MaxSignalSlots-1) + */ u32 head; /* Queue head signal # */ /* 2nd cache line */ u64 num_received; /* Total # of signals removed from this queue */ - u32 tail; /* Queue tail signal # (on separate - * cache line) */ + u32 tail; /* Queue tail signal */ u32 reserved1; /* Reserved field */ u64 reserved2; /* Reserved field */ u64 client_queue; u64 num_irq_received; /* Total # of Interrupts received. This - * is incremented by the ISR in the - * guest windows driver */ + * is incremented by the ISR in the + * guest windows driver + */ u64 num_empty; /* Number of times that visor_signal_remove - * is called and returned Empty - * Status. */ + * is called and returned Empty Status. + */ u32 errorflags; /* Error bits set during SignalReinit * to denote trouble with client's - * fields */ + * fields + */ u8 filler[12]; /* Pad out to 64 byte cacheline */ } __packed; @@ -272,8 +293,7 @@ spar_check_channel_client(void __iomem *ch, return 0; } } - if (expected_min_bytes > 0) { /* caller wants us to verify - * channel size */ + if (expected_min_bytes > 0) { /* verify channel size */ unsigned long long bytes = readq(&((struct channel_header __iomem *) (ch))->size); @@ -284,8 +304,7 @@ spar_check_channel_client(void __iomem *ch, return 0; } } - if (expected_version > 0) { /* caller wants us to verify - * channel version */ + if (expected_version > 0) { /* verify channel version */ unsigned long ver = readl(&((struct channel_header __iomem *) (ch))->version_id); if (ver != expected_version) { @@ -295,8 +314,7 @@ spar_check_channel_client(void __iomem *ch, return 0; } } - if (expected_signature > 0) { /* caller wants us to verify - * channel signature */ + if (expected_signature > 0) { /* verify channel signature */ unsigned long long sig = readq(&((struct channel_header __iomem *) (ch))->signature); @@ -319,8 +337,7 @@ static inline int spar_check_channel_server(uuid_le typeuuid, char *name, u64 expected_min_bytes, u64 actual_bytes) { - if (expected_min_bytes > 0) /* caller wants us to verify - * channel size */ + if (expected_min_bytes > 0) /* verify channel size */ if (actual_bytes < expected_min_bytes) { pr_err("Channel mismatch on channel=%s(%pUL) field=size expected=0x%-8.8llx actual=0x%-8.8llx\n", name, &typeuuid, expected_min_bytes, @@ -354,7 +371,8 @@ pathname_last_n_nodes(u8 *s, unsigned int n) if (p == s) break; /* should never happen, unless someone * is changing the string while we are - * looking at it!! */ + * looking at it!! + */ if ((*p == '/') || (*p == '\\')) n--; } @@ -395,7 +413,8 @@ spar_channel_client_acquire_os(void __iomem *ch, u8 *id) if (readl(&hdr->cli_state_os) == CHANNELCLI_OWNED) { if (readb(&hdr->cli_error_os) != 0) { /* we are in an error msg throttling state; - * come out of it */ + * come out of it + */ pr_info("%s Channel OS client acquire now successful\n", id); writeb(0, &hdr->cli_error_os); @@ -404,8 +423,9 @@ spar_channel_client_acquire_os(void __iomem *ch, u8 *id) } /* We have to do it the "hard way". We transition to BUSY, - * and can use the channel iff our competitor has not also - * transitioned to BUSY. */ + * and can use the channel iff our competitor has not also + * transitioned to BUSY. + */ if (readl(&hdr->cli_state_os) != CHANNELCLI_ATTACHED) { if ((readb(&hdr->cli_error_os) & ULTRA_CLIERROROS_THROTTLEMSG_NOTATTACHED) == 0) { diff --git a/drivers/staging/unisys/include/iochannel.h b/drivers/staging/unisys/include/iochannel.h index 14e656ff73ec..162ca187a66b 100644 --- a/drivers/staging/unisys/include/iochannel.h +++ b/drivers/staging/unisys/include/iochannel.h @@ -6,7 +6,8 @@ /* * Everything needed for IOPart-GuestPart communication is define in * this file. Note: Everything is OS-independent because this file is - * used by Windows, Linux and possible EFI drivers. */ + * used by Windows, Linux and possible EFI drivers. + */ /* * Communication flow between the IOPart and GuestPart uses the channel headers @@ -66,21 +67,15 @@ * IO Partition is defined below. */ -/* - * Defines and enums. - */ - +/* Defines and enums. */ #define MINNUM(a, b) (((a) < (b)) ? (a) : (b)) #define MAXNUM(a, b) (((a) > (b)) ? (a) : (b)) -/* these define the two queues per data channel between iopart and - * ioguestparts - */ -#define IOCHAN_TO_IOPART 0 /* used by ioguestpart to 'insert' signals to - * iopart */ - -#define IOCHAN_FROM_IOPART 1 /* used by ioguestpart to 'remove' signals from - * iopart - same queue as previous queue */ +/* define the two queues per data channel between iopart and ioguestparts */ +/* used by ioguestpart to 'insert' signals to iopart */ +#define IOCHAN_TO_IOPART 0 +/* used by ioguestpart to 'remove' signals from iopart, same previous queue */ +#define IOCHAN_FROM_IOPART 1 /* size of cdb - i.e., scsi cmnd */ #define MAX_CMND_SIZE 16 @@ -92,26 +87,29 @@ /* various types of network packets that can be sent in cmdrsp */ enum net_types { NET_RCV_POST = 0, /* submit buffer to hold receiving - * incoming packet */ + * incoming packet + */ /* virtnic -> uisnic */ NET_RCV, /* incoming packet received */ /* uisnic -> virtpci */ - NET_XMIT, /* for outgoing net packets */ + NET_XMIT, /* for outgoing net packets */ /* virtnic -> uisnic */ NET_XMIT_DONE, /* outgoing packet xmitted */ /* uisnic -> virtpci */ NET_RCV_ENBDIS, /* enable/disable packet reception */ /* virtnic -> uisnic */ - NET_RCV_ENBDIS_ACK, /* acknowledge enable/disable packet - * reception */ + NET_RCV_ENBDIS_ACK, /* acknowledge enable/disable packet */ + /* reception */ /* uisnic -> virtnic */ NET_RCV_PROMISC, /* enable/disable promiscuous mode */ /* virtnic -> uisnic */ NET_CONNECT_STATUS, /* indicate the loss or restoration of a network - * connection */ + * connection + */ /* uisnic -> virtnic */ NET_MACADDR, /* indicates the client has requested to update - * its MAC addr */ + * its MAC addr + */ NET_MACADDR_ACK, /* MAC address */ }; @@ -170,51 +168,43 @@ struct vhba_wwnn { } __packed; /* WARNING: Values stired in this structure must contain maximum counts (not - * maximum values). */ -struct vhba_config_max { /* 20 bytes */ - u32 max_channel; /* maximum channel for devices attached to this - * bus */ - u32 max_id; /* maximum SCSI ID for devices attached to this - * bus */ - u32 max_lun; /* maximum SCSI LUN for devices attached to this - * bus */ - u32 cmd_per_lun; /* maximum number of outstanding commands per - * lun that are allowed at one time */ - u32 max_io_size; /* maximum io size for devices attached to this - * bus */ + * maximum values). + */ +struct vhba_config_max {/* 20 bytes */ + u32 max_channel;/* maximum channel for devices attached to this bus */ + u32 max_id; /* maximum SCSI ID for devices attached to bus */ + u32 max_lun; /* maximum SCSI LUN for devices attached to bus */ + u32 cmd_per_lun;/* maximum number of outstanding commands per LUN */ + u32 max_io_size;/* maximum io size for devices attached to this bus */ /* max io size is often determined by the resource of the hba. e.g */ /* max scatter gather list length * page size / sector size */ } __packed; struct uiscmdrsp_scsi { - u64 handle; /* the handle to the cmd that was received - - * send it back as is in the rsp packet. */ + u64 handle; /* the handle to the cmd that was received */ + /* send it back as is in the rsp packet. */ u8 cmnd[MAX_CMND_SIZE]; /* the cdb for the command */ u32 bufflen; /* length of data to be transferred out or in */ - u16 guest_phys_entries; /* Number of entries in scatter-gather (sg) - * list */ + u16 guest_phys_entries; /* Number of entries in scatter-gather list */ struct guest_phys_info gpi_list[MAX_PHYS_INFO]; /* physical address * information for each - * fragment */ + * fragment + */ enum dma_data_direction data_dir; /* direction of the data, if any */ - struct uisscsi_dest vdest; /* identifies the virtual hba, id, - * channel, lun to which cmd was sent */ + struct uisscsi_dest vdest; /* identifies the virtual hba, id, */ + /* channel, lun to which cmd was sent */ - /* the following fields are needed to queue the rsp back to cmd - * originator */ - int linuxstat; /* the original Linux status - for use by linux - * vdisk code */ + /* Needed to queue the rsp back to cmd originator */ + int linuxstat; /* original Linux status used by linux vdisk */ u8 scsistat; /* the scsi status */ - u8 addlstat; /* non-scsi status - covers cases like timeout - * needed by windows guests */ + u8 addlstat; /* non-scsi status */ #define ADDL_SEL_TIMEOUT 4 /* the following fields are need to determine the result of command */ u8 sensebuf[MAX_SENSE_SIZE]; /* sense info in case cmd failed; */ /* it holds the sense_data struct; */ /* see that struct for details. */ - void *vdisk; /* contains pointer to the vdisk so that we can clean up - * when the IO completes. */ + void *vdisk; /* pointer to the vdisk to clean up when IO completes. */ int no_disk_result; /* used to return no disk inquiry result * when no_disk_result is set to 1, @@ -258,15 +248,15 @@ struct uiscmdrsp_scsi { */ #define NO_DISK_INQUIRY_RESULT_LEN 36 -#define MIN_INQUIRY_RESULT_LEN 5 /* we need at least 5 bytes minimum for inquiry - * result */ +#define MIN_INQUIRY_RESULT_LEN 5 /* 5 bytes minimum for inquiry result */ /* SCSI device version for no disk inquiry result */ #define SCSI_SPC2_VER 4 /* indicates SCSI SPC2 (SPC3 is 5) */ /* Windows and Linux want different things for a non-existent lun. So, we'll let * caller pass in the peripheral qualifier and type. - * NOTE:[4] SCSI returns (n-4); so we return length-1-4 or length-5. */ + * NOTE:[4] SCSI returns (n-4); so we return length-1-4 or length-5. + */ #define SET_NO_DISK_INQUIRY_RESULT(buf, len, lun, lun0notpresent, notpresent) \ do { \ @@ -305,9 +295,7 @@ struct uiscmdrsp_scsi { } \ } while (0) -/* - * Struct & Defines to support sense information. - */ +/* Struct & Defines to support sense information. */ /* The following struct is returned in sensebuf field in uiscmdrsp_scsi. It is * initialized in exactly the manner that is recommended in Windows (hence the @@ -342,13 +330,11 @@ struct sense_data { struct net_pkt_xmt { int len; /* full length of data in the packet */ int num_frags; /* number of fragments in frags containing data */ - struct phys_info frags[MAX_PHYS_INFO]; /* physical page information for - * each fragment */ + struct phys_info frags[MAX_PHYS_INFO]; /* physical page information */ char ethhdr[ETH_HEADER_SIZE]; /* the ethernet header */ struct { - /* these are needed for csum at uisnic end */ - u8 valid; /* 1 = rest of this struct is valid - else - * ignore */ + /* these are needed for csum at uisnic end */ + u8 valid; /* 1 = struct is valid - else ignore */ u8 hrawoffv; /* 1 = hwrafoff is valid */ u8 nhrawoffv; /* 1 = nhwrafoff is valid */ u16 protocol; /* specifies packet protocol */ @@ -380,16 +366,18 @@ struct net_pkt_xmtdone { */ #define RCVPOST_BUF_SIZE 4032 #define MAX_NET_RCV_CHAIN \ - ((ETH_MAX_MTU+ETH_HEADER_SIZE + RCVPOST_BUF_SIZE-1) / RCVPOST_BUF_SIZE) + ((ETH_MAX_MTU + ETH_HEADER_SIZE + RCVPOST_BUF_SIZE - 1) \ + / RCVPOST_BUF_SIZE) struct net_pkt_rcvpost { /* rcv buf size must be large enough to include ethernet data len + * ethernet header len - we are choosing 2K because it is guaranteed - * to be describable */ - struct phys_info frag; /* physical page information for the - * single fragment 2K rcv buf */ - u64 unique_num; /* This is used to make sure that - * receive posts are returned to */ + * to be describable + */ + struct phys_info frag; /* physical page information for the */ + /* single fragment 2K rcv buf */ + u64 unique_num; + /* unique_num ensure that receive posts are returned to */ /* the Adapter which we sent them originally. */ } __packed; @@ -399,8 +387,7 @@ struct net_pkt_rcv { u32 rcv_done_len; /* length of received data */ u8 numrcvbufs; /* number of receive buffers that contain the */ /* incoming data; guest end MUST chain these together. */ - void *rcvbuf[MAX_NET_RCV_CHAIN]; /* the list of receive buffers - * that must be chained; */ + void *rcvbuf[MAX_NET_RCV_CHAIN]; /* list of chained rcvbufs */ /* each entry is a receive buffer provided by NET_RCV_POST. */ /* NOTE: first rcvbuf in the chain will also be provided in net.buf. */ u64 unique_num; @@ -469,18 +456,17 @@ struct uiscmdrsp_scsitaskmgmt { #define TASK_MGMT_FAILED 0 } __packed; -/* The following is used by uissd to send disk add/remove notifications to - * Guest */ +/* Used by uissd to send disk add/remove notifications to Guest */ /* Note that the vHba pointer is not used by the Client/Guest side. */ struct uiscmdrsp_disknotify { u8 add; /* 0-remove, 1-add */ - void *v_hba; /* Pointer to vhba_info for channel info to - * route msg */ + void *v_hba; /* channel info to route msg */ u32 channel, id, lun; /* SCSI Path of Disk to added or removed */ } __packed; /* The following is used by virthba/vSCSI to send the Acquire/Release commands - * to the IOVM. */ + * to the IOVM. + */ struct uiscmdrsp_vdiskmgmt { enum vdisk_mgmt_types vdisktype; @@ -533,8 +519,8 @@ struct uiscmdrsp { struct uiscmdrsp_disknotify disknotify; struct uiscmdrsp_vdiskmgmt vdiskmgmt; }; - void *private_data; /* used to send the response when the cmd is - * done (scsi & scsittaskmgmt). */ + void *private_data; /* send the response when the cmd is */ + /* done (scsi & scsittaskmgmt). */ struct uiscmdrsp *next; /* General Purpose Queue Link */ struct uiscmdrsp *activeQ_next; /* Used to track active commands */ struct uiscmdrsp *activeQ_prev; /* Used to track active commands */ @@ -564,15 +550,11 @@ struct spar_io_channel_protocol { } __packed; #define MAX_CLIENTSTRING_LEN 1024 - u8 client_string[MAX_CLIENTSTRING_LEN];/* NULL terminated - so holds - * max - 1 bytes */ + /* client_string is NULL termimated so holds max -1 bytes */ + u8 client_string[MAX_CLIENTSTRING_LEN]; } __packed; - -/* - * INLINE functions for initializing and accessing I/O data channels - */ - +/* INLINE functions for initializing and accessing I/O data channels */ #define SIZEOF_PROTOCOL (COVER(sizeof(struct spar_io_channel_protocol), 64)) #define SIZEOF_CMDRSP (COVER(sizeof(struct uiscmdrsp), 64)) @@ -584,8 +566,7 @@ struct spar_io_channel_protocol { * pfn-off-size entires. */ -/* we deal with 4K page sizes when we it comes to passing page information - * between */ +/* use 4K page sizes when we it comes to passing page information between */ /* Guest and IOPartition. */ #define PI_PAGE_SIZE 0x1000 #define PI_PAGE_MASK 0x0FFF @@ -594,18 +575,8 @@ struct spar_io_channel_protocol { * room) */ static inline u16 -add_physinfo_entries(u32 inp_pfn, /* input - specifies the pfn to be used - * to add entries */ - u16 inp_off, /* input - specifies the off to be used - * to add entries */ - u32 inp_len, /* input - specifies the len to be used - * to add entries */ - u16 index, /* input - index in array at which new - * entries are added */ - u16 max_pi_arr_entries, /* input - specifies the maximum - * entries pi_arr can hold */ - struct phys_info pi_arr[]) /* input & output - array to - * which entries are added */ +add_physinfo_entries(u32 inp_pfn, u16 inp_off, u32 inp_len, u16 index, + u16 max_pi_arr_entries, struct phys_info pi_arr[]) { u32 len; u16 i, firstlen; diff --git a/drivers/staging/unisys/include/vbushelper.h b/drivers/staging/unisys/include/vbushelper.h index f272975b2920..f1b6aacb79d7 100644 --- a/drivers/staging/unisys/include/vbushelper.h +++ b/drivers/staging/unisys/include/vbushelper.h @@ -19,7 +19,8 @@ #define __VBUSHELPER_H__ /* TARGET_HOSTNAME specified as -DTARGET_HOSTNAME=\"thename\" on the - * command line */ + * command line + */ #define TARGET_HOSTNAME "linuxguest" diff --git a/drivers/staging/unisys/include/visorbus.h b/drivers/staging/unisys/include/visorbus.h index 9235536fa75f..2a64a9ce0208 100644 --- a/drivers/staging/unisys/include/visorbus.h +++ b/drivers/staging/unisys/include/visorbus.h @@ -140,8 +140,8 @@ struct visor_device { struct { int major, minor; void *attr; /* private use by devmajorminor_attr.c you can - * change this constant to whatever you - * want; */ + * change this constant to whatever you want + */ } devnodes[5]; /* the code will detect and behave appropriately) */ struct semaphore visordriver_callback_lock; diff --git a/drivers/staging/unisys/visorbus/Kconfig b/drivers/staging/unisys/visorbus/Kconfig index 9b299ac86015..511388075ffa 100644 --- a/drivers/staging/unisys/visorbus/Kconfig +++ b/drivers/staging/unisys/visorbus/Kconfig @@ -6,4 +6,9 @@ config UNISYS_VISORBUS tristate "Unisys visorbus driver" depends on UNISYSSPAR ---help--- - If you say Y here, you will enable the Unisys visorbus driver. + The visorbus driver is a virtualized bus for the Unisys s-Par firmware. + Virtualized devices allow Linux guests on a system to share disks and + network cards that do not have SR-IOV support, and to be accessed using + the partition desktop application. The visorbus driver is required to + discover devices on an s-Par guest, and must be present for any other + s-Par guest driver to function correctly. diff --git a/drivers/staging/unisys/visorbus/controlvmcompletionstatus.h b/drivers/staging/unisys/visorbus/controlvmcompletionstatus.h index 3c97ebac4f32..23ad0ea6c9fc 100644 --- a/drivers/staging/unisys/visorbus/controlvmcompletionstatus.h +++ b/drivers/staging/unisys/visorbus/controlvmcompletionstatus.h @@ -39,7 +39,8 @@ #define CONTROLVM_RESP_ERROR_MAX_DEVICES 202 /* DEVICE_CREATE */ /* Payload and Parameter Related------------------------------------[400-499] */ #define CONTROLVM_RESP_ERROR_PAYLOAD_INVALID 400 /* SWITCH_ATTACHEXTPORT, - * DEVICE_CONFIGURE */ + * DEVICE_CONFIGURE + */ #define CONTROLVM_RESP_ERROR_INITIATOR_PARAMETER_INVALID 401 /* Multiple */ #define CONTROLVM_RESP_ERROR_TARGET_PARAMETER_INVALID 402 /* DEVICE_CONFIGURE */ #define CONTROLVM_RESP_ERROR_CLIENT_PARAMETER_INVALID 403 /* DEVICE_CONFIGURE */ @@ -48,36 +49,43 @@ * BUS_CONFIGURE, * DEVICE_CREATE, * DEVICE_CONFIG - * DEVICE_DESTROY */ + * DEVICE_DESTROY + */ #define CONTROLVM_RESP_ERROR_DEVICE_INVALID 501 /* SWITCH_ATTACHINTPORT */ /* DEVICE_CREATE, * DEVICE_CONFIGURE, - * DEVICE_DESTROY */ + * DEVICE_DESTROY + */ #define CONTROLVM_RESP_ERROR_CHANNEL_INVALID 502 /* DEVICE_CREATE, - * DEVICE_CONFIGURE */ + * DEVICE_CONFIGURE + */ /* Partition Driver Callback Interface----------------------[600-699] */ #define CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE 604 /* BUS_CREATE, * BUS_DESTROY, * DEVICE_CREATE, - * DEVICE_DESTROY */ + * DEVICE_DESTROY + */ /* Unable to invoke VIRTPCI callback */ #define CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR 605 /* BUS_CREATE, * BUS_DESTROY, * DEVICE_CREATE, - * DEVICE_DESTROY */ + * DEVICE_DESTROY + */ /* VIRTPCI Callback returned error */ #define CONTROLVM_RESP_ERROR_GENERIC_DRIVER_CALLBACK_ERROR 606 /* SWITCH_ATTACHEXTPORT, * SWITCH_DETACHEXTPORT - * DEVICE_CONFIGURE */ + * DEVICE_CONFIGURE + */ /* generic device callback returned error */ /* Bus Related------------------------------------------------------[700-799] */ #define CONTROLVM_RESP_ERROR_BUS_DEVICE_ATTACHED 700 /* BUS_DESTROY */ /* Channel Related--------------------------------------------------[800-899] */ #define CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN 800 /* GET_CHANNELINFO, - * DEVICE_DESTROY */ + * DEVICE_DESTROY + */ #define CONTROLVM_RESP_ERROR_CHANNEL_SIZE_TOO_SMALL 801 /* DEVICE_CREATE */ /* Chipset Shutdown Related---------------------------------------[1000-1099] */ #define CONTROLVM_RESP_ERROR_CHIPSET_SHUTDOWN_FAILED 1000 diff --git a/drivers/staging/unisys/visorbus/periodic_work.c b/drivers/staging/unisys/visorbus/periodic_work.c index 115b7aa9560a..00b152764f84 100644 --- a/drivers/staging/unisys/visorbus/periodic_work.c +++ b/drivers/staging/unisys/visorbus/periodic_work.c @@ -43,11 +43,12 @@ static void periodic_work_func(struct work_struct *work) (*pw->workfunc)(pw->workfuncarg); } -struct periodic_work *visor_periodic_work_create(ulong jiffy_interval, - struct workqueue_struct *workqueue, - void (*workfunc)(void *), - void *workfuncarg, - const char *devnam) +struct periodic_work +*visor_periodic_work_create(ulong jiffy_interval, + struct workqueue_struct *workqueue, + void (*workfunc)(void *), + void *workfuncarg, + const char *devnam) { struct periodic_work *pw; diff --git a/drivers/staging/unisys/visorbus/vbuschannel.h b/drivers/staging/unisys/visorbus/vbuschannel.h index 80e64477e547..90fa12e62f26 100644 --- a/drivers/staging/unisys/visorbus/vbuschannel.h +++ b/drivers/staging/unisys/visorbus/vbuschannel.h @@ -36,10 +36,11 @@ static const uuid_le spar_vbus_channel_protocol_uuid = #define SPAR_VBUS_CHANNEL_PROTOCOL_SIGNATURE ULTRA_CHANNEL_PROTOCOL_SIGNATURE /* Must increment this whenever you insert or delete fields within this channel -* struct. Also increment whenever you change the meaning of fields within this -* channel struct so as to break pre-existing software. Note that you can -* usually add fields to the END of the channel struct withOUT needing to -* increment this. */ + * struct. Also increment whenever you change the meaning of fields within this + * channel struct so as to break pre-existing software. Note that you can + * usually add fields to the END of the channel struct withOUT needing to + * increment this. + */ #define SPAR_VBUS_CHANNEL_PROTOCOL_VERSIONID 1 #define SPAR_VBUS_CHANNEL_OK_CLIENT(ch) \ diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c b/drivers/staging/unisys/visorbus/visorbus_main.c index a272b48bab28..eac97d22278a 100644 --- a/drivers/staging/unisys/visorbus/visorbus_main.c +++ b/drivers/staging/unisys/visorbus/visorbus_main.c @@ -1078,7 +1078,8 @@ away: } /* Write the contents of <info> to the struct - * spar_vbus_channel_protocol.chp_info. */ + * spar_vbus_channel_protocol.chp_info. + */ static int write_vbus_chp_info(struct visorchannel *chan, @@ -1096,7 +1097,8 @@ write_vbus_chp_info(struct visorchannel *chan, } /* Write the contents of <info> to the struct - * spar_vbus_channel_protocol.bus_info. */ + * spar_vbus_channel_protocol.bus_info. + */ static int write_vbus_bus_info(struct visorchannel *chan, @@ -1370,7 +1372,8 @@ pause_state_change_complete(struct visor_device *dev, int status) /* Notify the chipset driver that the pause is complete, which * will presumably want to send some sort of response to the - * initiator. */ + * initiator. + */ (*chipset_responders.device_pause) (dev, status); } @@ -1390,7 +1393,8 @@ resume_state_change_complete(struct visor_device *dev, int status) /* Notify the chipset driver that the resume is complete, * which will presumably want to send some sort of response to - * the initiator. */ + * the initiator. + */ (*chipset_responders.device_resume) (dev, status); } @@ -1437,7 +1441,8 @@ initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause) * existing problem prevents us from ever getting a bus * resume... This hack would fail to work should we * ever have a bus that contains NO devices, since we - * would never even get here in that case. */ + * would never even get here in that case. + */ fix_vbus_dev_info(dev); if (!drv->resume) goto away; diff --git a/drivers/staging/unisys/visorbus/visorchannel.c b/drivers/staging/unisys/visorbus/visorchannel.c index a4e117f101cf..891b8db7c5ec 100644 --- a/drivers/staging/unisys/visorbus/visorchannel.c +++ b/drivers/staging/unisys/visorbus/visorchannel.c @@ -41,8 +41,8 @@ struct visorchannel { struct channel_header chan_hdr; uuid_le guid; ulong size; - bool needs_lock; /* channel creator knows if more than one - * thread will be inserting or removing */ + bool needs_lock; /* channel creator knows if more than one */ + /* thread will be inserting or removing */ spinlock_t insert_lock; /* protect head writes in chan_hdr */ spinlock_t remove_lock; /* protect tail writes in chan_hdr */ diff --git a/drivers/staging/unisys/visorbus/vmcallinterface.h b/drivers/staging/unisys/visorbus/vmcallinterface.h index c8d8483bd4df..c043fa41ceda 100644 --- a/drivers/staging/unisys/visorbus/vmcallinterface.h +++ b/drivers/staging/unisys/visorbus/vmcallinterface.h @@ -43,20 +43,15 @@ enum vmcall_monitor_interface_method_tuple { /* VMCALL identification tuples */ * - the 0x01 identifies it as the 1st instance of a VMCALL_VIRTPART * type of VMCALL */ - - VMCALL_IO_CONTROLVM_ADDR = 0x0501, /* used by all Guests, not just - * IO */ - VMCALL_QUERY_GUEST_VIRTUAL_TIME_OFFSET = 0x0708, /* Allow caller to - * query virtual time - * offset */ - VMCALL_POST_CODE_LOGEVENT = 0x070B, /* LOGEVENT Post Code (RDX) with - * specified subsystem mask (RCX - * - monitor_subsystems.h) and - * severity (RDX) */ - VMCALL_UPDATE_PHYSICAL_TIME = 0x0a02 /* Allow - * ULTRA_SERVICE_CAPABILITY_TIME - * capable guest to make - * VMCALL */ + /* used by all Guests, not just IO */ + VMCALL_IO_CONTROLVM_ADDR = 0x0501, + /* Allow caller to query virtual time offset */ + VMCALL_QUERY_GUEST_VIRTUAL_TIME_OFFSET = 0x0708, + /* LOGEVENT Post Code (RDX) with specified subsystem mask */ + /* (RCX - monitor_subsystems.h) and severity (RDX) */ + VMCALL_POST_CODE_LOGEVENT = 0x070B, + /* Allow ULTRA_SERVICE_CAPABILITY_TIME capable guest to make VMCALL */ + VMCALL_UPDATE_PHYSICAL_TIME = 0x0a02 }; #define VMCALL_SUCCESS 0 @@ -74,7 +69,8 @@ enum vmcall_monitor_interface_method_tuple { /* VMCALL identification tuples */ unisys_extended_vmcall(method, param1, param2, param3) /* The following uses VMCALL_POST_CODE_LOGEVENT interface but is currently - * not used much */ + * not used much + */ #define ISSUE_IO_VMCALL_POSTCODE_SEVERITY(postcode, severity) \ ISSUE_IO_EXTENDED_VMCALL(VMCALL_POST_CODE_LOGEVENT, severity, \ MDS_APPOS, postcode) @@ -84,11 +80,11 @@ enum vmcall_monitor_interface_method_tuple { /* VMCALL identification tuples */ /* Parameters to VMCALL_IO_CONTROLVM_ADDR interface */ struct vmcall_io_controlvm_addr_params { - /* The Guest-relative physical address of the ControlVm channel. - * This VMCall fills this in with the appropriate address. */ + /* The Guest-relative physical address of the ControlVm channel. */ + /* This VMCall fills this in with the appropriate address. */ u64 address; /* contents provided by this VMCALL (OUT) */ - /* the size of the ControlVm channel in bytes This VMCall fills this - * in with the appropriate address. */ + /* the size of the ControlVm channel in bytes This VMCall fills this */ + /* in with the appropriate address. */ u32 channel_bytes; /* contents provided by this VMCALL (OUT) */ u8 unused[4]; /* Unused Bytes in the 64-Bit Aligned Struct */ } __packed; diff --git a/drivers/staging/unisys/visorhba/visorhba_main.c b/drivers/staging/unisys/visorhba/visorhba_main.c index c119f20dfd44..d5178b44ba8c 100644 --- a/drivers/staging/unisys/visorhba/visorhba_main.c +++ b/drivers/staging/unisys/visorhba/visorhba_main.c @@ -453,7 +453,6 @@ visorhba_queue_command_lck(struct scsi_cmnd *scsicmd, struct uiscmdrsp *cmdrsp; struct scsi_device *scsidev = scsicmd->device; int insert_location; - unsigned char op; unsigned char *cdb = scsicmd->cmnd; struct Scsi_Host *scsihost = scsidev->host; unsigned int i; @@ -461,7 +460,6 @@ visorhba_queue_command_lck(struct scsi_cmnd *scsicmd, (struct visorhba_devdata *)scsihost->hostdata; struct scatterlist *sg = NULL; struct scatterlist *sglist = NULL; - int err = 0; if (devdata->serverdown || devdata->serverchangingstate) return SCSI_MLQUEUE_DEVICE_BUSY; @@ -496,10 +494,8 @@ visorhba_queue_command_lck(struct scsi_cmnd *scsicmd, if (cmdrsp->scsi.bufflen > devdata->max_buff_len) devdata->max_buff_len = cmdrsp->scsi.bufflen; - if (scsi_sg_count(scsicmd) > MAX_PHYS_INFO) { - err = SCSI_MLQUEUE_DEVICE_BUSY; + if (scsi_sg_count(scsicmd) > MAX_PHYS_INFO) goto err_del_scsipending_ent; - } /* convert buffer to phys information */ /* buffer is scatterlist - copy it out */ @@ -511,19 +507,17 @@ visorhba_queue_command_lck(struct scsi_cmnd *scsicmd, } cmdrsp->scsi.guest_phys_entries = scsi_sg_count(scsicmd); - op = cdb[0]; if (!visorchannel_signalinsert(devdata->dev->visorchannel, IOCHAN_TO_IOPART, - cmdrsp)) { + cmdrsp)) /* queue must be full and we aren't going to wait */ - err = SCSI_MLQUEUE_DEVICE_BUSY; goto err_del_scsipending_ent; - } + return 0; err_del_scsipending_ent: del_scsipending_ent(devdata, insert_location); - return err; + return SCSI_MLQUEUE_DEVICE_BUSY; } /** @@ -759,11 +753,9 @@ do_scsi_linuxstat(struct uiscmdrsp *cmdrsp, struct scsi_cmnd *scsicmd) struct visorhba_devdata *devdata; struct visordisk_info *vdisk; struct scsi_device *scsidev; - struct sense_data *sd; scsidev = scsicmd->device; memcpy(scsicmd->sense_buffer, cmdrsp->scsi.sensebuf, MAX_SENSE_SIZE); - sd = (struct sense_data *)scsicmd->sense_buffer; /* Do not log errors for disk-not-present inquiries */ if ((cmdrsp->scsi.cmnd[0] == INQUIRY) && diff --git a/drivers/staging/unisys/visorinput/Kconfig b/drivers/staging/unisys/visorinput/Kconfig index d83deb4137e8..3476d419d32c 100644 --- a/drivers/staging/unisys/visorinput/Kconfig +++ b/drivers/staging/unisys/visorinput/Kconfig @@ -6,5 +6,10 @@ config UNISYS_VISORINPUT tristate "Unisys visorinput driver" depends on UNISYSSPAR && UNISYS_VISORBUS && FB ---help--- - If you say Y here, you will enable the Unisys visorinput driver. + The Unisys s-Par visorinput driver provides a virtualized system + console (keyboard and mouse) that is accessible through the + s-Par firmware's user interface. s-Par provides video using the EFI + GOP protocol, so If this driver is not present, the Linux guest should + still boot with visible output in the partition desktop, but keyboard + and mouse interaction will not be available. diff --git a/drivers/staging/unisys/visorinput/visorinput.c b/drivers/staging/unisys/visorinput/visorinput.c index 5c16f6634368..38d4d5b884df 100644 --- a/drivers/staging/unisys/visorinput/visorinput.c +++ b/drivers/staging/unisys/visorinput/visorinput.c @@ -523,7 +523,7 @@ visorinput_channel_interrupt(struct visor_device *dev) struct ultra_inputreport r; int scancode, keycode; struct input_dev *visorinput_dev; - int xmotion, ymotion, zmotion, button; + int xmotion, ymotion, button; int i; struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device); @@ -604,12 +604,10 @@ visorinput_channel_interrupt(struct visor_device *dev) } break; case inputaction_wheel_rotate_away: - zmotion = r.activity.arg1; input_report_rel(visorinput_dev, REL_WHEEL, 1); input_sync(visorinput_dev); break; case inputaction_wheel_rotate_toward: - zmotion = r.activity.arg1; input_report_rel(visorinput_dev, REL_WHEEL, -1); input_sync(visorinput_dev); break; diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c index 296b11cea247..05194707278a 100644 --- a/drivers/staging/unisys/visornic/visornic_main.c +++ b/drivers/staging/unisys/visornic/visornic_main.c @@ -1742,7 +1742,6 @@ poll_for_irq(unsigned long v) atomic_set(&devdata->interrupt_rcvd, 0); mod_timer(&devdata->irq_poll_timer, msecs_to_jiffies(2)); - } /** diff --git a/drivers/staging/vme/devices/vme_pio2_cntr.c b/drivers/staging/vme/devices/vme_pio2_cntr.c index 6335471faa36..486c30c4956f 100644 --- a/drivers/staging/vme/devices/vme_pio2_cntr.c +++ b/drivers/staging/vme/devices/vme_pio2_cntr.c @@ -61,7 +61,7 @@ int pio2_cntr_reset(struct pio2_card *card) /* Ensure all counter interrupts are cleared */ do { retval = vme_master_read(card->window, ®, 1, - PIO2_REGS_INT_STAT_CNTR); + PIO2_REGS_INT_STAT_CNTR); if (retval < 0) return retval; } while (reg != 0); diff --git a/drivers/staging/vme/devices/vme_pio2_core.c b/drivers/staging/vme/devices/vme_pio2_core.c index 35c6ce5047de..4f3cdbcedb3e 100644 --- a/drivers/staging/vme/devices/vme_pio2_core.c +++ b/drivers/staging/vme/devices/vme_pio2_core.c @@ -90,7 +90,7 @@ static void pio2_int(int level, int vector, void *ptr) case 4: /* Channels 0 to 7 */ retval = vme_master_read(card->window, ®, 1, - PIO2_REGS_INT_STAT[vec - 1]); + PIO2_REGS_INT_STAT[vec - 1]); if (retval < 0) { dev_err(&card->vdev->dev, "Unable to read IRQ status register\n"); @@ -100,8 +100,8 @@ static void pio2_int(int level, int vector, void *ptr) channel = ((vec - 1) * 8) + i; if (reg & PIO2_CHANNEL_BIT[channel]) dev_info(&card->vdev->dev, - "Interrupt on I/O channel %d\n", - channel); + "Interrupt on I/O channel %d\n", + channel); } break; case 5: @@ -215,7 +215,7 @@ static int pio2_probe(struct vme_dev *vdev) u8 reg; int vec; - card = kzalloc(sizeof(struct pio2_card), GFP_KERNEL); + card = kzalloc(sizeof(*card), GFP_KERNEL); if (!card) { retval = -ENOMEM; goto err_struct; @@ -230,7 +230,7 @@ static int pio2_probe(struct vme_dev *vdev) card->vdev = vdev; for (i = 0; i < PIO2_VARIANT_LENGTH; i++) { - if (isdigit(card->variant[i]) == 0) { + if (!isdigit(card->variant[i])) { dev_err(&card->vdev->dev, "Variant invalid\n"); retval = -EINVAL; goto err_variant; @@ -289,7 +289,7 @@ static int pio2_probe(struct vme_dev *vdev) } retval = vme_master_set(card->window, 1, card->base, 0x10000, VME_A24, - (VME_SCT | VME_USER | VME_DATA), VME_D16); + VME_SCT | VME_USER | VME_DATA, VME_D16); if (retval) { dev_err(&card->vdev->dev, "Unable to configure VME master resource\n"); @@ -335,7 +335,7 @@ static int pio2_probe(struct vme_dev *vdev) /* Set VME vector */ retval = vme_master_write(card->window, &card->irq_vector, 1, - PIO2_REGS_VME_VECTOR); + PIO2_REGS_VME_VECTOR); if (retval < 0) return retval; @@ -343,7 +343,7 @@ static int pio2_probe(struct vme_dev *vdev) vec = card->irq_vector | PIO2_VME_VECTOR_SPUR; retval = vme_irq_request(vdev, card->irq_level, vec, - &pio2_int, (void *)card); + &pio2_int, card); if (retval < 0) { dev_err(&card->vdev->dev, "Unable to attach VME interrupt vector0x%x, level 0x%x\n", @@ -356,7 +356,7 @@ static int pio2_probe(struct vme_dev *vdev) vec = card->irq_vector | PIO2_VECTOR_BANK[i]; retval = vme_irq_request(vdev, card->irq_level, vec, - &pio2_int, (void *)card); + &pio2_int, card); if (retval < 0) { dev_err(&card->vdev->dev, "Unable to attach VME interrupt vector0x%x, level 0x%x\n", @@ -370,7 +370,7 @@ static int pio2_probe(struct vme_dev *vdev) vec = card->irq_vector | PIO2_VECTOR_CNTR[i]; retval = vme_irq_request(vdev, card->irq_level, vec, - &pio2_int, (void *)card); + &pio2_int, card); if (retval < 0) { dev_err(&card->vdev->dev, "Unable to attach VME interrupt vector0x%x, level 0x%x\n", @@ -397,7 +397,7 @@ static int pio2_probe(struct vme_dev *vdev) dev_set_drvdata(&card->vdev->dev, card); dev_info(&card->vdev->dev, - "PIO2 (variant %s) configured at 0x%lx\n", card->variant, + "PIO2 (variant %s) configured at 0x%lx\n", card->variant, card->base); return 0; diff --git a/drivers/staging/vme/devices/vme_pio2_gpio.c b/drivers/staging/vme/devices/vme_pio2_gpio.c index 77901b345a71..df992c3cb5ce 100644 --- a/drivers/staging/vme/devices/vme_pio2_gpio.c +++ b/drivers/staging/vme/devices/vme_pio2_gpio.c @@ -37,14 +37,13 @@ static int pio2_gpio_get(struct gpio_chip *chip, unsigned int offset) struct pio2_card *card = gpio_to_pio2_card(chip); if ((card->bank[PIO2_CHANNEL_BANK[offset]].config == OUTPUT) | - (card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) { - + (card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) { dev_err(&card->vdev->dev, "Channel not available as input\n"); return 0; } retval = vme_master_read(card->window, ®, 1, - PIO2_REGS_DATA[PIO2_CHANNEL_BANK[offset]]); + PIO2_REGS_DATA[PIO2_CHANNEL_BANK[offset]]); if (retval < 0) { dev_err(&card->vdev->dev, "Unable to read from GPIO\n"); return 0; @@ -67,16 +66,15 @@ static int pio2_gpio_get(struct gpio_chip *chip, unsigned int offset) return 0; } -static void pio2_gpio_set(struct gpio_chip *chip, unsigned int offset, - int value) +static void pio2_gpio_set(struct gpio_chip *chip, + unsigned int offset, int value) { u8 reg; int retval; struct pio2_card *card = gpio_to_pio2_card(chip); if ((card->bank[PIO2_CHANNEL_BANK[offset]].config == INPUT) | - (card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) { - + (card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) { dev_err(&card->vdev->dev, "Channel not available as output\n"); return; } @@ -89,7 +87,7 @@ static void pio2_gpio_set(struct gpio_chip *chip, unsigned int offset, ~PIO2_CHANNEL_BIT[offset]; retval = vme_master_write(card->window, ®, 1, - PIO2_REGS_DATA[PIO2_CHANNEL_BANK[offset]]); + PIO2_REGS_DATA[PIO2_CHANNEL_BANK[offset]]); if (retval < 0) { dev_err(&card->vdev->dev, "Unable to write to GPIO\n"); return; @@ -105,7 +103,7 @@ static int pio2_gpio_dir_in(struct gpio_chip *chip, unsigned offset) struct pio2_card *card = gpio_to_pio2_card(chip); if ((card->bank[PIO2_CHANNEL_BANK[offset]].config == OUTPUT) | - (card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) { + (card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) { dev_err(&card->vdev->dev, "Channel directionality not configurable at runtime\n"); @@ -124,7 +122,7 @@ static int pio2_gpio_dir_out(struct gpio_chip *chip, unsigned offset, int value) struct pio2_card *card = gpio_to_pio2_card(chip); if ((card->bank[PIO2_CHANNEL_BANK[offset]].config == INPUT) | - (card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) { + (card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) { dev_err(&card->vdev->dev, "Channel directionality not configurable at runtime\n"); @@ -150,7 +148,7 @@ int pio2_gpio_reset(struct pio2_card *card) /* Zero output registers */ for (i = 0; i < 4; i++) { retval = vme_master_write(card->window, &data, 1, - PIO2_REGS_DATA[i]); + PIO2_REGS_DATA[i]); if (retval < 0) return retval; card->bank[i].value = 0; @@ -159,12 +157,12 @@ int pio2_gpio_reset(struct pio2_card *card) /* Set input interrupt masks */ for (i = 0; i < 4; i++) { retval = vme_master_write(card->window, &data, 1, - PIO2_REGS_INT_MASK[i * 2]); + PIO2_REGS_INT_MASK[i * 2]); if (retval < 0) return retval; retval = vme_master_write(card->window, &data, 1, - PIO2_REGS_INT_MASK[(i * 2) + 1]); + PIO2_REGS_INT_MASK[(i * 2) + 1]); if (retval < 0) return retval; @@ -176,7 +174,7 @@ int pio2_gpio_reset(struct pio2_card *card) for (i = 0; i < 4; i++) { do { retval = vme_master_read(card->window, &data, 1, - PIO2_REGS_INT_STAT[i]); + PIO2_REGS_INT_STAT[i]); if (retval < 0) return retval; } while (data != 0); @@ -192,7 +190,7 @@ int pio2_gpio_init(struct pio2_card *card) label = kasprintf(GFP_KERNEL, "%s@%s", driver_name, dev_name(&card->vdev->dev)); - if (label == NULL) + if (!label) return -ENOMEM; card->gc.label = label; @@ -207,7 +205,7 @@ int pio2_gpio_init(struct pio2_card *card) card->gc.set = pio2_gpio_set; /* This function adds a memory mapped GPIO chip */ - retval = gpiochip_add(&(card->gc)); + retval = gpiochip_add(&card->gc); if (retval) { dev_err(&card->vdev->dev, "Unable to register GPIO\n"); kfree(card->gc.label); @@ -220,7 +218,7 @@ void pio2_gpio_exit(struct pio2_card *card) { const char *label = card->gc.label; - gpiochip_remove(&(card->gc)); + gpiochip_remove(&card->gc); kfree(label); } diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c index 8e61a3b3e7e4..b95883bc68fe 100644 --- a/drivers/staging/vme/devices/vme_user.c +++ b/drivers/staging/vme/devices/vme_user.c @@ -308,8 +308,8 @@ static int vme_user_ioctl(struct inode *inode, struct file *file, switch (cmd) { case VME_IRQ_GEN: copied = copy_from_user(&irq_req, argp, - sizeof(struct vme_irq_id)); - if (copied != 0) { + sizeof(irq_req)); + if (copied) { pr_warn("Partial copy from userspace\n"); return -EFAULT; } @@ -322,7 +322,7 @@ static int vme_user_ioctl(struct inode *inode, struct file *file, case MASTER_MINOR: switch (cmd) { case VME_GET_MASTER: - memset(&master, 0, sizeof(struct vme_master)); + memset(&master, 0, sizeof(master)); /* XXX We do not want to push aspace, cycle and width * to userspace as they are @@ -334,8 +334,8 @@ static int vme_user_ioctl(struct inode *inode, struct file *file, &master.cycle, &master.dwidth); copied = copy_to_user(argp, &master, - sizeof(struct vme_master)); - if (copied != 0) { + sizeof(master)); + if (copied) { pr_warn("Partial copy to userspace\n"); return -EFAULT; } @@ -350,7 +350,7 @@ static int vme_user_ioctl(struct inode *inode, struct file *file, } copied = copy_from_user(&master, argp, sizeof(master)); - if (copied != 0) { + if (copied) { pr_warn("Partial copy from userspace\n"); return -EFAULT; } @@ -368,7 +368,7 @@ static int vme_user_ioctl(struct inode *inode, struct file *file, case SLAVE_MINOR: switch (cmd) { case VME_GET_SLAVE: - memset(&slave, 0, sizeof(struct vme_slave)); + memset(&slave, 0, sizeof(slave)); /* XXX We do not want to push aspace, cycle and width * to userspace as they are @@ -379,8 +379,8 @@ static int vme_user_ioctl(struct inode *inode, struct file *file, &slave.aspace, &slave.cycle); copied = copy_to_user(argp, &slave, - sizeof(struct vme_slave)); - if (copied != 0) { + sizeof(slave)); + if (copied) { pr_warn("Partial copy to userspace\n"); return -EFAULT; } @@ -390,7 +390,7 @@ static int vme_user_ioctl(struct inode *inode, struct file *file, case VME_SET_SLAVE: copied = copy_from_user(&slave, argp, sizeof(slave)); - if (copied != 0) { + if (copied) { pr_warn("Partial copy from userspace\n"); return -EFAULT; } @@ -757,7 +757,7 @@ static int __init vme_user_init(void) * we just change the code in vme_user_match(). */ retval = vme_register_driver(&vme_user_driver, VME_MAX_SLOTS); - if (retval != 0) + if (retval) goto err_reg; return retval; diff --git a/drivers/staging/vme/devices/vme_user.h b/drivers/staging/vme/devices/vme_user.h index b8cc7bc78a73..a6cb75686fa4 100644 --- a/drivers/staging/vme/devices/vme_user.h +++ b/drivers/staging/vme/devices/vme_user.h @@ -20,7 +20,6 @@ struct vme_master { #endif } __packed; - /* * IOCTL Commands and structures */ @@ -28,7 +27,6 @@ struct vme_master { /* Magic number for use in ioctls */ #define VME_IOC_MAGIC 0xAE - /* VMEbus Slave Window Configuration Structure */ struct vme_slave { __u32 enable; /* State of Window */ diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c index e5be261f2e69..9417c935fc30 100644 --- a/drivers/staging/vt6656/baseband.c +++ b/drivers/staging/vt6656/baseband.c @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: baseband.c * diff --git a/drivers/staging/vt6656/baseband.h b/drivers/staging/vt6656/baseband.h index 771ea4054174..807a5809b5d9 100644 --- a/drivers/staging/vt6656/baseband.h +++ b/drivers/staging/vt6656/baseband.h @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: baseband.h * diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c index 927243ebcb56..a382fc6aa9d3 100644 --- a/drivers/staging/vt6656/card.c +++ b/drivers/staging/vt6656/card.c @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: card.c * Purpose: Provide functions to setup NIC operation mode diff --git a/drivers/staging/vt6656/card.h b/drivers/staging/vt6656/card.h index 03fc1678896b..c2cde7e92c8f 100644 --- a/drivers/staging/vt6656/card.h +++ b/drivers/staging/vt6656/card.h @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: card.h * diff --git a/drivers/staging/vt6656/channel.c b/drivers/staging/vt6656/channel.c index 8412d0532fb2..a0fe288c1322 100644 --- a/drivers/staging/vt6656/channel.c +++ b/drivers/staging/vt6656/channel.c @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: channel.c * diff --git a/drivers/staging/vt6656/channel.h b/drivers/staging/vt6656/channel.h index 21c080803714..fcea6995fe26 100644 --- a/drivers/staging/vt6656/channel.h +++ b/drivers/staging/vt6656/channel.h @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: channel.h * diff --git a/drivers/staging/vt6656/desc.h b/drivers/staging/vt6656/desc.h index f79af8513ff2..59e3071021bd 100644 --- a/drivers/staging/vt6656/desc.h +++ b/drivers/staging/vt6656/desc.h @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: desc.h * diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h index dec36f296f3d..76b5f4127f95 100644 --- a/drivers/staging/vt6656/device.h +++ b/drivers/staging/vt6656/device.h @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: device.h * diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c index e6367ed3b0bb..6019aac8bdd5 100644 --- a/drivers/staging/vt6656/dpc.c +++ b/drivers/staging/vt6656/dpc.c @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: dpc.c * diff --git a/drivers/staging/vt6656/dpc.h b/drivers/staging/vt6656/dpc.h index 95e0e83a487e..5a92bd86cee2 100644 --- a/drivers/staging/vt6656/dpc.h +++ b/drivers/staging/vt6656/dpc.h @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: dpc.h * diff --git a/drivers/staging/vt6656/firmware.c b/drivers/staging/vt6656/firmware.c index d440f284bf18..1b48f9c86f63 100644 --- a/drivers/staging/vt6656/firmware.c +++ b/drivers/staging/vt6656/firmware.c @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: baseband.c * diff --git a/drivers/staging/vt6656/firmware.h b/drivers/staging/vt6656/firmware.h index d594dbe1c147..e2b54acb8fdb 100644 --- a/drivers/staging/vt6656/firmware.h +++ b/drivers/staging/vt6656/firmware.h @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: firmware.h * diff --git a/drivers/staging/vt6656/int.c b/drivers/staging/vt6656/int.c index 14b8ebc6508d..8d05acbc0e23 100644 --- a/drivers/staging/vt6656/int.c +++ b/drivers/staging/vt6656/int.c @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: int.c * diff --git a/drivers/staging/vt6656/int.h b/drivers/staging/vt6656/int.h index 154605c63947..97e55bacbb7c 100644 --- a/drivers/staging/vt6656/int.h +++ b/drivers/staging/vt6656/int.h @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: int.h * diff --git a/drivers/staging/vt6656/key.c b/drivers/staging/vt6656/key.c index 181745d8e250..0246a8fc47fe 100644 --- a/drivers/staging/vt6656/key.c +++ b/drivers/staging/vt6656/key.c @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: key.c * @@ -163,7 +159,6 @@ int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta, key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; } - if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { vnt_set_keymode(hw, mac_addr, key, VNT_KEY_PAIRWISE, key_dec_mode, true); diff --git a/drivers/staging/vt6656/key.h b/drivers/staging/vt6656/key.h index 3cb1291055ed..7861faf5138f 100644 --- a/drivers/staging/vt6656/key.h +++ b/drivers/staging/vt6656/key.h @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: key.h * diff --git a/drivers/staging/vt6656/mac.c b/drivers/staging/vt6656/mac.c index 5dfac05b9cf1..eeed16e9124e 100644 --- a/drivers/staging/vt6656/mac.c +++ b/drivers/staging/vt6656/mac.c @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: mac.c * diff --git a/drivers/staging/vt6656/mac.h b/drivers/staging/vt6656/mac.h index d53fcef87b4a..4c6e610f1bc1 100644 --- a/drivers/staging/vt6656/mac.h +++ b/drivers/staging/vt6656/mac.h @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: mac.h * diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c index 01e642db311e..ee8d1e1a24c2 100644 --- a/drivers/staging/vt6656/main_usb.c +++ b/drivers/staging/vt6656/main_usb.c @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: main_usb.c * diff --git a/drivers/staging/vt6656/power.c b/drivers/staging/vt6656/power.c index 13afce27951c..c025dab0f62c 100644 --- a/drivers/staging/vt6656/power.c +++ b/drivers/staging/vt6656/power.c @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: power.c * diff --git a/drivers/staging/vt6656/power.h b/drivers/staging/vt6656/power.h index 7696b714850c..9d1ebb695f9d 100644 --- a/drivers/staging/vt6656/power.h +++ b/drivers/staging/vt6656/power.h @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: power.h * diff --git a/drivers/staging/vt6656/rf.c b/drivers/staging/vt6656/rf.c index c4286ccac320..816206c92f57 100644 --- a/drivers/staging/vt6656/rf.c +++ b/drivers/staging/vt6656/rf.c @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: rf.c * diff --git a/drivers/staging/vt6656/rf.h b/drivers/staging/vt6656/rf.h index 3acdc65b1e56..c3d4f06d65f4 100644 --- a/drivers/staging/vt6656/rf.h +++ b/drivers/staging/vt6656/rf.h @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: rf.h * diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c index efb54f53b4f9..a0c69b697901 100644 --- a/drivers/staging/vt6656/rxtx.c +++ b/drivers/staging/vt6656/rxtx.c @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: rxtx.c * diff --git a/drivers/staging/vt6656/rxtx.h b/drivers/staging/vt6656/rxtx.h index 90b34ab2f6ce..4a79c404275b 100644 --- a/drivers/staging/vt6656/rxtx.h +++ b/drivers/staging/vt6656/rxtx.h @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: rxtx.h * diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c index c975c3b87093..351a99f3d684 100644 --- a/drivers/staging/vt6656/usbpipe.c +++ b/drivers/staging/vt6656/usbpipe.c @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: usbpipe.c * diff --git a/drivers/staging/vt6656/usbpipe.h b/drivers/staging/vt6656/usbpipe.h index e74aa0809928..8bafd9aee1fa 100644 --- a/drivers/staging/vt6656/usbpipe.h +++ b/drivers/staging/vt6656/usbpipe.h @@ -12,10 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * * * File: usbpipe.h * diff --git a/drivers/staging/vt6656/wcmd.c b/drivers/staging/vt6656/wcmd.c index 3cbf4791bac1..4846a898d39b 100644 --- a/drivers/staging/vt6656/wcmd.c +++ b/drivers/staging/vt6656/wcmd.c @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: wcmd.c * diff --git a/drivers/staging/vt6656/wcmd.h b/drivers/staging/vt6656/wcmd.h index 2b0ee285eb0b..764c09ccd42d 100644 --- a/drivers/staging/vt6656/wcmd.h +++ b/drivers/staging/vt6656/wcmd.h @@ -12,9 +12,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: wcmd.h * diff --git a/drivers/staging/wilc1000/Kconfig b/drivers/staging/wilc1000/Kconfig index ee51b4278088..dce9cee9134a 100644 --- a/drivers/staging/wilc1000/Kconfig +++ b/drivers/staging/wilc1000/Kconfig @@ -1,41 +1,12 @@ -config WILC1000_DRIVER - bool "WILC1000 support (WiFi only)" - depends on CFG80211 && WEXT_CORE && INET - ---help--- - This module only support IEEE 802.11n WiFi. - -if WILC1000_DRIVER - config WILC1000 tristate - -choice - prompt "Memory Allocation" - default WILC1000_PREALLOCATE_AT_LOADING_DRIVER - -config WILC1000_PREALLOCATE_AT_LOADING_DRIVER - bool "Preallocate memory at loading driver" + select WIRELESS_EXT ---help--- - This choice supports static allocation of the memory - for the receive buffer. The driver will allocate the RX buffer - during initial time. The driver will also free the buffer - by calling network device stop. - -config WILC1000_DYNAMICALLY_ALLOCATE_MEMROY - bool "Dynamically allocate memory in real time" - ---help--- - This choice supports dynamic allocation of the memory - for the receive buffer. The driver will allocate the RX buffer - when it is required. -endchoice - -choice - prompt "Bus Type" - default WILC1000_SDIO + This module only support IEEE 802.11n WiFi. config WILC1000_SDIO - bool "SDIO support" - depends on MMC + tristate "Atmel WILC1000 SDIO (WiFi only)" + depends on CFG80211 && INET && MMC select WILC1000 ---help--- This module adds support for the SDIO interface of adapters using @@ -48,9 +19,9 @@ config WILC1000_SDIO this if your platform is using the SDIO bus. config WILC1000_SPI - depends on SPI + tristate "Atmel WILC1000 SPI (WiFi only)" + depends on CFG80211 && INET && SPI select WILC1000 - bool "SPI support" ---help--- This module adds support for the SPI interface of adapters using WILC1000 chipset. The Atmel WILC1000 has a Serial Peripheral @@ -59,10 +30,9 @@ config WILC1000_SPI full-duplex slave synchronous serial interface that is available immediately following reset when pin 9 (SDIO_SPI_CFG) is tied to VDDIO. Select this if your platform is using the SPI bus. -endchoice config WILC1000_HW_OOB_INTR - bool "Use out of band interrupt" + bool "WILC1000 out of band interrupt" depends on WILC1000_SDIO default n ---help--- @@ -71,5 +41,3 @@ config WILC1000_HW_OOB_INTR mechanism for SDIO host controllers that don't support SDIO interrupt. Select this option If the SDIO host controller in your platform doesn't support SDIO time devision interrupt. - -endif diff --git a/drivers/staging/wilc1000/Makefile b/drivers/staging/wilc1000/Makefile index 64c2f1b83dfb..20a5cb9d4f4c 100644 --- a/drivers/staging/wilc1000/Makefile +++ b/drivers/staging/wilc1000/Makefile @@ -1,28 +1,20 @@ obj-$(CONFIG_WILC1000) += wilc1000.o -ccflags-$(CONFIG_WILC1000_SDIO) += -DWILC_SDIO -DCOMPLEMENT_BOOT -ccflags-$(CONFIG_WILC1000_HW_OOB_INTR) += -DWILC_SDIO_IRQ_GPIO -ccflags-$(CONFIG_WILC1000_SPI) += -DWILC_SPI - ccflags-y += -DSTA_FIRMWARE=\"atmel/wilc1000_fw.bin\" \ -DAP_FIRMWARE=\"atmel/wilc1000_ap_fw.bin\" \ -DP2P_CONCURRENCY_FIRMWARE=\"atmel/wilc1000_p2p_fw.bin\" -ccflags-y += -I$(src)/ -D__CHECK_ENDIAN__ -DWILC_ASIC_A0 \ - -Wno-unused-function -DWILC_DEBUGFS +ccflags-y += -I$(src)/ -DWILC_ASIC_A0 -DWILC_DEBUGFS #ccflags-y += -DTCP_ACK_FILTER -ccflags-$(CONFIG_WILC1000_PREALLOCATE_AT_LOADING_DRIVER) += -DMEMORY_STATIC \ - -DWILC_PREALLOC_AT_INSMOD - -ccflags-$(CONFIG_WILC1000_DYNAMICALLY_ALLOCATE_MEMROY) += -DWILC_NORMAL_ALLOC - - wilc1000-objs := wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \ wilc_msgqueue.o \ coreconfigurator.o host_interface.o \ - wilc_sdio.o wilc_spi.o wilc_wlan_cfg.o wilc_debugfs.o \ + wilc_wlan_cfg.o wilc_debugfs.o \ wilc_wlan.o -wilc1000-$(CONFIG_WILC1000_SDIO) += linux_wlan_sdio.o -wilc1000-$(CONFIG_WILC1000_SPI) += linux_wlan_spi.o +obj-$(CONFIG_WILC1000_SDIO) += wilc1000-sdio.o +wilc1000-sdio-objs += wilc_sdio.o + +obj-$(CONFIG_WILC1000_SPI) += wilc1000-spi.o +wilc1000-spi-objs += wilc_spi.o diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c index 9568bdb6319b..2d4d3f190c01 100644 --- a/drivers/staging/wilc1000/coreconfigurator.c +++ b/drivers/staging/wilc1000/coreconfigurator.c @@ -287,7 +287,7 @@ static inline u16 get_asoc_id(u8 *data) return asoc_id; } -u8 *get_tim_elm(u8 *pu8msa, u16 u16RxLen, u16 u16TagParamOffset) +static u8 *get_tim_elm(u8 *pu8msa, u16 u16RxLen, u16 u16TagParamOffset) { u16 u16index; @@ -315,7 +315,7 @@ u8 *get_tim_elm(u8 *pu8msa, u16 u16RxLen, u16 u16TagParamOffset) /* This function gets the current channel information from * the 802.11n beacon/probe response frame */ -u8 get_current_channel_802_11n(u8 *pu8msa, u16 u16RxLen) +static u8 get_current_channel_802_11n(u8 *pu8msa, u16 u16RxLen) { u16 index; @@ -344,7 +344,7 @@ u8 get_current_channel_802_11n(u8 *pu8msa, u16 u16RxLen) * @date 1 Mar 2012 * @version 1.0 */ -s32 parse_network_info(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo) +s32 wilc_parse_network_info(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo) { tstrNetworkInfo *pstrNetworkInfo = NULL; u8 u8MsgType = 0; @@ -436,7 +436,7 @@ s32 parse_network_info(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo) /* Get DTIM Period */ pu8TimElm = get_tim_elm(pu8msa, u16RxLen + FCS_LEN, u8index); - if (pu8TimElm != NULL) + if (pu8TimElm) pstrNetworkInfo->u8DtimPeriod = pu8TimElm[3]; pu8IEs = &pu8msa[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN]; u16IEsLen = u16RxLen - (MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN); @@ -466,12 +466,12 @@ s32 parse_network_info(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo) * @date 1 Mar 2012 * @version 1.0 */ -s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo) +s32 wilc_dealloc_network_info(tstrNetworkInfo *pstrNetworkInfo) { s32 s32Error = 0; - if (pstrNetworkInfo != NULL) { - if (pstrNetworkInfo->pu8IEs != NULL) { + if (pstrNetworkInfo) { + if (pstrNetworkInfo->pu8IEs) { kfree(pstrNetworkInfo->pu8IEs); pstrNetworkInfo->pu8IEs = NULL; } else { @@ -499,7 +499,7 @@ s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo) * @date 2 Apr 2012 * @version 1.0 */ -s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen, +s32 wilc_parse_assoc_resp_info(u8 *pu8Buffer, u32 u32BufferLen, tstrConnectRespInfo **ppstrConnectRespInfo) { s32 s32Error = 0; @@ -551,12 +551,12 @@ s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen, * @date 2 Apr 2012 * @version 1.0 */ -s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo) +s32 wilc_dealloc_assoc_resp_info(tstrConnectRespInfo *pstrConnectRespInfo) { s32 s32Error = 0; - if (pstrConnectRespInfo != NULL) { - if (pstrConnectRespInfo->pu8RespIEs != NULL) { + if (pstrConnectRespInfo) { + if (pstrConnectRespInfo->pu8RespIEs) { kfree(pstrConnectRespInfo->pu8RespIEs); pstrConnectRespInfo->pu8RespIEs = NULL; } else { @@ -588,7 +588,8 @@ s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo) * @date 1 Mar 2012 * @version 1.0 */ -s32 send_config_pkt(u8 mode, struct wid *wids, u32 count, u32 drv) +s32 wilc_send_config_pkt(struct wilc *wilc, u8 mode, struct wid *wids, + u32 count, u32 drv) { s32 counter = 0, ret = 0; @@ -596,11 +597,11 @@ s32 send_config_pkt(u8 mode, struct wid *wids, u32 count, u32 drv) for (counter = 0; counter < count; counter++) { PRINT_INFO(CORECONFIG_DBG, "Sending CFG packet [%d][%d]\n", !counter, (counter == count - 1)); - if (!wilc_wlan_cfg_get(!counter, + if (!wilc_wlan_cfg_get(wilc, !counter, wids[counter].id, (counter == count - 1), drv)) { - ret = -1; + ret = -ETIMEDOUT; printk("[Sendconfigpkt]Get Timed out\n"); break; } @@ -611,18 +612,17 @@ s32 send_config_pkt(u8 mode, struct wid *wids, u32 count, u32 drv) wids[counter].id, wids[counter].val, wids[counter].size); - } } else if (mode == SET_CFG) { for (counter = 0; counter < count; counter++) { PRINT_D(CORECONFIG_DBG, "Sending config SET PACKET WID:%x\n", wids[counter].id); - if (!wilc_wlan_cfg_set(!counter, + if (!wilc_wlan_cfg_set(wilc, !counter, wids[counter].id, wids[counter].val, wids[counter].size, (counter == count - 1), drv)) { - ret = -1; + ret = -ETIMEDOUT; printk("[Sendconfigpkt]Set Timed out\n"); break; } diff --git a/drivers/staging/wilc1000/coreconfigurator.h b/drivers/staging/wilc1000/coreconfigurator.h index 6294d929a800..fc43d04ca1da 100644 --- a/drivers/staging/wilc1000/coreconfigurator.h +++ b/drivers/staging/wilc1000/coreconfigurator.h @@ -72,7 +72,7 @@ typedef enum { struct wid { u16 id; - enum WID_TYPE type; + enum wid_type type; s32 size; s8 *val; }; @@ -127,16 +127,18 @@ typedef struct { size_t ie_len; } tstrDisconnectNotifInfo; -s32 send_config_pkt(u8 mode, struct wid *wids, u32 count, u32 drv); -s32 parse_network_info(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo); -s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo); +s32 wilc_send_config_pkt(struct wilc *wilc, u8 mode, struct wid *wids, + u32 count, u32 drv); +s32 wilc_parse_network_info(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo); +s32 wilc_dealloc_network_info(tstrNetworkInfo *pstrNetworkInfo); -s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen, +s32 wilc_parse_assoc_resp_info(u8 *pu8Buffer, u32 u32BufferLen, tstrConnectRespInfo **ppstrConnectRespInfo); -s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo); - -void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length); -void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length); -void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length); - +s32 wilc_dealloc_assoc_resp_info(tstrConnectRespInfo *pstrConnectRespInfo); +void wilc_scan_complete_received(struct wilc *wilc, u8 *pu8Buffer, + u32 u32Length); +void wilc_network_info_received(struct wilc *wilc, u8 *pu8Buffer, + u32 u32Length); +void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *pu8Buffer, + u32 u32Length); #endif diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c index dbbe72c7e255..8c7752034032 100644 --- a/drivers/staging/wilc1000/host_interface.c +++ b/drivers/staging/wilc1000/host_interface.c @@ -4,17 +4,12 @@ #include <linux/delay.h> #include "host_interface.h" #include "coreconfigurator.h" +#include "wilc_wlan.h" #include "wilc_wlan_if.h" #include "wilc_msgqueue.h" #include <linux/etherdevice.h> #include "wilc_wfi_netdevice.h" -extern u8 connecting; - -extern struct timer_list hDuringIpTimer; - -extern u8 g_wilc_initialized; - #define HOST_IF_MSG_SCAN 0 #define HOST_IF_MSG_CONNECT 1 #define HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO 2 @@ -48,7 +43,6 @@ extern u8 g_wilc_initialized; #define HOST_IF_MSG_FLUSH_CONNECT 30 #define HOST_IF_MSG_GET_STATISTICS 31 #define HOST_IF_MSG_SET_MULTICAST_FILTER 32 -#define HOST_IF_MSG_ADD_BA_SESSION 33 #define HOST_IF_MSG_DEL_BA_SESSION 34 #define HOST_IF_MSG_Q_IDLE 35 #define HOST_IF_MSG_DEL_ALL_STA 36 @@ -199,7 +193,7 @@ union message_body { struct host_if_msg { u16 id; union message_body body; - struct host_if_drv *drv; + struct wilc_vif *vif; }; struct join_bss_param { @@ -231,10 +225,9 @@ struct join_bss_param { u8 start_time[4]; }; -static struct host_if_drv *wfidrv_list[NUM_CONCURRENT_IFC + 1]; struct host_if_drv *terminated_handle; -bool g_obtainingIP; -u8 P2P_LISTEN_STATE; +bool wilc_optaining_ip; +static u8 P2P_LISTEN_STATE; static struct task_struct *hif_thread_handler; static WILC_MsgQueueHandle hif_msg_q; static struct semaphore hif_sema_thread; @@ -243,7 +236,7 @@ static struct semaphore hif_sema_wait_response; static struct semaphore hif_sema_deinit; static struct timer_list periodic_rssi; -u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN]; +u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN]; static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE]; @@ -259,86 +252,57 @@ static u8 del_beacon; static u32 clients_count; static u8 *join_req; -u8 *info_element; +static u8 *info_element; static u8 mode_11i; -u8 auth_type; -u32 join_req_size; +static u8 auth_type; +static u32 join_req_size; static u32 info_element_size; -static struct host_if_drv *join_req_drv; +static struct wilc_vif *join_req_vif; #define REAL_JOIN_REQ 0 #define FLUSHED_JOIN_REQ 1 #define FLUSHED_BYTE_POS 79 static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo); -extern void chip_sleep_manually(u32 u32SleepTime); -extern int linux_wlan_get_num_conn_ifcs(void); - -static int add_handler_in_list(struct host_if_drv *handler) +/* The u8IfIdx starts from 0 to NUM_CONCURRENT_IFC -1, but 0 index used as + * special purpose in wilc device, so we add 1 to the index to starts from 1. + * As a result, the returned index will be 1 to NUM_CONCURRENT_IFC. + */ +int wilc_get_vif_idx(struct wilc_vif *vif) { - int i; - - for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) { - if (!wfidrv_list[i]) { - wfidrv_list[i] = handler; - return 0; - } - } - - return -ENOBUFS; + return vif->u8IfIdx + 1; } -static int remove_handler_in_list(struct host_if_drv *handler) +/* We need to minus 1 from idx which is from wilc device to get real index + * of wilc->vif[], because we add 1 when pass to wilc device in the function + * wilc_get_vif_idx. + * As a result, the index should be between 0 and NUM_CONCURRENT_IFC -1. + */ +static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx) { - int i; + int index = idx - 1; - for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) { - if (wfidrv_list[i] == handler) { - wfidrv_list[i] = NULL; - return 0; - } - } - - return -EINVAL; -} - -static int get_id_from_handler(struct host_if_drv *handler) -{ - int i; - - if (!handler) - return 0; - - for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) { - if (wfidrv_list[i] == handler) - return i; - } - - return 0; -} - -static struct host_if_drv *get_handler_from_id(int id) -{ - if (id <= 0 || id >= ARRAY_SIZE(wfidrv_list)) + if (index < 0 || index >= NUM_CONCURRENT_IFC) return NULL; - return wfidrv_list[id]; + + return wilc->vif[index]; } -static s32 Handle_SetChannel(struct host_if_drv *hif_drv, - struct channel_attr *pstrHostIFSetChan) +static s32 handle_set_channel(struct wilc_vif *vif, + struct channel_attr *hif_set_ch) { s32 result = 0; struct wid wid; wid.id = (u16)WID_CURRENT_CHANNEL; wid.type = WID_CHAR; - wid.val = (char *)&pstrHostIFSetChan->set_ch; + wid.val = (char *)&hif_set_ch->set_ch; wid.size = sizeof(char); PRINT_D(HOSTINF_DBG, "Setting channel\n"); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("Failed to set channel\n"); @@ -348,21 +312,21 @@ static s32 Handle_SetChannel(struct host_if_drv *hif_drv, return result; } -static s32 Handle_SetWfiDrvHandler(struct host_if_drv *hif_drv, - struct drv_handler *pstrHostIfSetDrvHandler) +static s32 handle_set_wfi_drv_handler(struct wilc_vif *vif, + struct drv_handler *hif_drv_handler) { s32 result = 0; struct wid wid; wid.id = (u16)WID_SET_DRV_HANDLER; wid.type = WID_INT; - wid.val = (s8 *)&pstrHostIfSetDrvHandler->handler; + wid.val = (s8 *)&hif_drv_handler->handler; wid.size = sizeof(u32); - result = send_config_pkt(SET_CFG, &wid, 1, - pstrHostIfSetDrvHandler->handler); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + hif_drv_handler->handler); - if (!hif_drv) + if (!hif_drv_handler->handler) up(&hif_sema_driver); if (result) { @@ -373,21 +337,21 @@ static s32 Handle_SetWfiDrvHandler(struct host_if_drv *hif_drv, return result; } -static s32 Handle_SetOperationMode(struct host_if_drv *hif_drv, - struct op_mode *pstrHostIfSetOperationMode) +static s32 handle_set_operation_mode(struct wilc_vif *vif, + struct op_mode *hif_op_mode) { s32 result = 0; struct wid wid; wid.id = (u16)WID_SET_OPERATION_MODE; wid.type = WID_INT; - wid.val = (s8 *)&pstrHostIfSetOperationMode->mode; + wid.val = (s8 *)&hif_op_mode->mode; wid.size = sizeof(u32); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); - if ((pstrHostIfSetOperationMode->mode) == IDLE_MODE) + if ((hif_op_mode->mode) == IDLE_MODE) up(&hif_sema_driver); if (result) { @@ -398,28 +362,34 @@ static s32 Handle_SetOperationMode(struct host_if_drv *hif_drv, return result; } -s32 Handle_set_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx) +static s32 host_int_get_ipaddress(struct wilc_vif *vif, + struct host_if_drv *hif_drv, + u8 *u16ipadd, u8 idx); + +static s32 handle_set_ip_address(struct wilc_vif *vif, u8 *ip_addr, u8 idx) { s32 result = 0; struct wid wid; - char firmwareIPAddress[4] = {0}; + char firmware_ip_addr[4] = {0}; + struct host_if_drv *hif_drv = vif->hif_drv; - if (pu8IPAddr[0] < 192) - pu8IPAddr[0] = 0; + if (ip_addr[0] < 192) + ip_addr[0] = 0; - PRINT_INFO(HOSTINF_DBG, "Indx = %d, Handling set IP = %pI4\n", idx, pu8IPAddr); + PRINT_INFO(HOSTINF_DBG, "Indx = %d, Handling set IP = %pI4\n", + idx, ip_addr); - memcpy(set_ip[idx], pu8IPAddr, IP_ALEN); + memcpy(set_ip[idx], ip_addr, IP_ALEN); wid.id = (u16)WID_IP_ADDRESS; wid.type = WID_STR; - wid.val = (u8 *)pu8IPAddr; + wid.val = (u8 *)ip_addr; wid.size = IP_ALEN; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); - host_int_get_ipaddress(hif_drv, firmwareIPAddress, idx); + host_int_get_ipaddress(vif, hif_drv, firmware_ip_addr, idx); if (result) { PRINT_ER("Failed to set IP address\n"); @@ -431,7 +401,7 @@ s32 Handle_set_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx) return result; } -s32 Handle_get_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx) +static s32 handle_get_ip_address(struct wilc_vif *vif, u8 idx) { s32 result = 0; struct wid wid; @@ -441,8 +411,8 @@ s32 Handle_get_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx) wid.val = kmalloc(IP_ALEN, GFP_KERNEL); wid.size = IP_ALEN; - result = send_config_pkt(GET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, GET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); PRINT_INFO(HOSTINF_DBG, "%pI4\n", wid.val); @@ -451,7 +421,7 @@ s32 Handle_get_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx) kfree(wid.val); if (memcmp(get_ip[idx], set_ip[idx], IP_ALEN) != 0) - host_int_setup_ipaddress(hif_drv, set_ip[idx], idx); + wilc_setup_ipaddress(vif, set_ip[idx], idx); if (result != 0) { PRINT_ER("Failed to get IP address\n"); @@ -465,8 +435,8 @@ s32 Handle_get_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx) return result; } -static s32 Handle_SetMacAddress(struct host_if_drv *hif_drv, - struct set_mac_addr *pstrHostIfSetMacAddress) +static s32 handle_set_mac_address(struct wilc_vif *vif, + struct set_mac_addr *set_mac_addr) { s32 result = 0; struct wid wid; @@ -476,7 +446,7 @@ static s32 Handle_SetMacAddress(struct host_if_drv *hif_drv, PRINT_ER("No buffer to send mac address\n"); return -EFAULT; } - memcpy(mac_buf, pstrHostIfSetMacAddress->mac_addr, ETH_ALEN); + memcpy(mac_buf, set_mac_addr->mac_addr, ETH_ALEN); wid.id = (u16)WID_MAC_ADDR; wid.type = WID_STR; @@ -484,8 +454,8 @@ static s32 Handle_SetMacAddress(struct host_if_drv *hif_drv, wid.size = ETH_ALEN; PRINT_D(GENERIC_DBG, "mac addr = :%pM\n", wid.val); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("Failed to set mac address\n"); result = -EFAULT; @@ -495,19 +465,19 @@ static s32 Handle_SetMacAddress(struct host_if_drv *hif_drv, return result; } -static s32 Handle_GetMacAddress(struct host_if_drv *hif_drv, - struct get_mac_addr *pstrHostIfGetMacAddress) +static s32 handle_get_mac_address(struct wilc_vif *vif, + struct get_mac_addr *get_mac_addr) { s32 result = 0; struct wid wid; wid.id = (u16)WID_MAC_ADDR; wid.type = WID_STR; - wid.val = pstrHostIfGetMacAddress->mac_addr; + wid.val = get_mac_addr->mac_addr; wid.size = ETH_ALEN; - result = send_config_pkt(GET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, GET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("Failed to get mac address\n"); @@ -518,258 +488,270 @@ static s32 Handle_GetMacAddress(struct host_if_drv *hif_drv, return result; } -static s32 Handle_CfgParam(struct host_if_drv *hif_drv, - struct cfg_param_attr *strHostIFCfgParamAttr) +static s32 handle_cfg_param(struct wilc_vif *vif, + struct cfg_param_attr *cfg_param_attr) { s32 result = 0; - struct wid strWIDList[32]; - u8 u8WidCnt = 0; + struct wid wid_list[32]; + struct host_if_drv *hif_drv = vif->hif_drv; + u8 wid_cnt = 0; - down(&hif_drv->gtOsCfgValuesSem); + down(&hif_drv->sem_cfg_values); PRINT_D(HOSTINF_DBG, "Setting CFG params\n"); - if (strHostIFCfgParamAttr->cfg_attr_info.flag & BSS_TYPE) { - if (strHostIFCfgParamAttr->cfg_attr_info.bss_type < 6) { - strWIDList[u8WidCnt].id = WID_BSS_TYPE; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.bss_type; - strWIDList[u8WidCnt].type = WID_CHAR; - strWIDList[u8WidCnt].size = sizeof(char); - hif_drv->strCfgValues.bss_type = (u8)strHostIFCfgParamAttr->cfg_attr_info.bss_type; + if (cfg_param_attr->cfg_attr_info.flag & BSS_TYPE) { + if (cfg_param_attr->cfg_attr_info.bss_type < 6) { + wid_list[wid_cnt].id = WID_BSS_TYPE; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.bss_type; + wid_list[wid_cnt].type = WID_CHAR; + wid_list[wid_cnt].size = sizeof(char); + hif_drv->cfg_values.bss_type = (u8)cfg_param_attr->cfg_attr_info.bss_type; } else { PRINT_ER("check value 6 over\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & AUTH_TYPE) { - if ((strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 1 || (strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 2 || (strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 5) { - strWIDList[u8WidCnt].id = WID_AUTH_TYPE; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.auth_type; - strWIDList[u8WidCnt].type = WID_CHAR; - strWIDList[u8WidCnt].size = sizeof(char); - hif_drv->strCfgValues.auth_type = (u8)strHostIFCfgParamAttr->cfg_attr_info.auth_type; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & AUTH_TYPE) { + if (cfg_param_attr->cfg_attr_info.auth_type == 1 || + cfg_param_attr->cfg_attr_info.auth_type == 2 || + cfg_param_attr->cfg_attr_info.auth_type == 5) { + wid_list[wid_cnt].id = WID_AUTH_TYPE; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.auth_type; + wid_list[wid_cnt].type = WID_CHAR; + wid_list[wid_cnt].size = sizeof(char); + hif_drv->cfg_values.auth_type = (u8)cfg_param_attr->cfg_attr_info.auth_type; } else { PRINT_ER("Impossible value \n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & AUTHEN_TIMEOUT) { - if (strHostIFCfgParamAttr->cfg_attr_info.auth_timeout > 0 && strHostIFCfgParamAttr->cfg_attr_info.auth_timeout < 65536) { - strWIDList[u8WidCnt].id = WID_AUTH_TIMEOUT; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.auth_timeout; - strWIDList[u8WidCnt].type = WID_SHORT; - strWIDList[u8WidCnt].size = sizeof(u16); - hif_drv->strCfgValues.auth_timeout = strHostIFCfgParamAttr->cfg_attr_info.auth_timeout; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & AUTHEN_TIMEOUT) { + if (cfg_param_attr->cfg_attr_info.auth_timeout > 0 && + cfg_param_attr->cfg_attr_info.auth_timeout < 65536) { + wid_list[wid_cnt].id = WID_AUTH_TIMEOUT; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.auth_timeout; + wid_list[wid_cnt].type = WID_SHORT; + wid_list[wid_cnt].size = sizeof(u16); + hif_drv->cfg_values.auth_timeout = cfg_param_attr->cfg_attr_info.auth_timeout; } else { PRINT_ER("Range(1 ~ 65535) over\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & POWER_MANAGEMENT) { - if (strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode < 5) { - strWIDList[u8WidCnt].id = WID_POWER_MANAGEMENT; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode; - strWIDList[u8WidCnt].type = WID_CHAR; - strWIDList[u8WidCnt].size = sizeof(char); - hif_drv->strCfgValues.power_mgmt_mode = (u8)strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & POWER_MANAGEMENT) { + if (cfg_param_attr->cfg_attr_info.power_mgmt_mode < 5) { + wid_list[wid_cnt].id = WID_POWER_MANAGEMENT; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.power_mgmt_mode; + wid_list[wid_cnt].type = WID_CHAR; + wid_list[wid_cnt].size = sizeof(char); + hif_drv->cfg_values.power_mgmt_mode = (u8)cfg_param_attr->cfg_attr_info.power_mgmt_mode; } else { PRINT_ER("Invalide power mode\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & RETRY_SHORT) { - if ((strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit > 0) && (strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit < 256)) { - strWIDList[u8WidCnt].id = WID_SHORT_RETRY_LIMIT; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit; - strWIDList[u8WidCnt].type = WID_SHORT; - strWIDList[u8WidCnt].size = sizeof(u16); - hif_drv->strCfgValues.short_retry_limit = strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & RETRY_SHORT) { + if (cfg_param_attr->cfg_attr_info.short_retry_limit > 0 && + cfg_param_attr->cfg_attr_info.short_retry_limit < 256) { + wid_list[wid_cnt].id = WID_SHORT_RETRY_LIMIT; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.short_retry_limit; + wid_list[wid_cnt].type = WID_SHORT; + wid_list[wid_cnt].size = sizeof(u16); + hif_drv->cfg_values.short_retry_limit = cfg_param_attr->cfg_attr_info.short_retry_limit; } else { PRINT_ER("Range(1~256) over\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & RETRY_LONG) { - if ((strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit > 0) && (strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit < 256)) { - strWIDList[u8WidCnt].id = WID_LONG_RETRY_LIMIT; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit; - - strWIDList[u8WidCnt].type = WID_SHORT; - strWIDList[u8WidCnt].size = sizeof(u16); - hif_drv->strCfgValues.long_retry_limit = strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & RETRY_LONG) { + if (cfg_param_attr->cfg_attr_info.long_retry_limit > 0 && + cfg_param_attr->cfg_attr_info.long_retry_limit < 256) { + wid_list[wid_cnt].id = WID_LONG_RETRY_LIMIT; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.long_retry_limit; + wid_list[wid_cnt].type = WID_SHORT; + wid_list[wid_cnt].size = sizeof(u16); + hif_drv->cfg_values.long_retry_limit = cfg_param_attr->cfg_attr_info.long_retry_limit; } else { PRINT_ER("Range(1~256) over\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & FRAG_THRESHOLD) { - if (strHostIFCfgParamAttr->cfg_attr_info.frag_threshold > 255 && strHostIFCfgParamAttr->cfg_attr_info.frag_threshold < 7937) { - strWIDList[u8WidCnt].id = WID_FRAG_THRESHOLD; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.frag_threshold; - strWIDList[u8WidCnt].type = WID_SHORT; - strWIDList[u8WidCnt].size = sizeof(u16); - hif_drv->strCfgValues.frag_threshold = strHostIFCfgParamAttr->cfg_attr_info.frag_threshold; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & FRAG_THRESHOLD) { + if (cfg_param_attr->cfg_attr_info.frag_threshold > 255 && + cfg_param_attr->cfg_attr_info.frag_threshold < 7937) { + wid_list[wid_cnt].id = WID_FRAG_THRESHOLD; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.frag_threshold; + wid_list[wid_cnt].type = WID_SHORT; + wid_list[wid_cnt].size = sizeof(u16); + hif_drv->cfg_values.frag_threshold = cfg_param_attr->cfg_attr_info.frag_threshold; } else { PRINT_ER("Threshold Range fail\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & RTS_THRESHOLD) { - if (strHostIFCfgParamAttr->cfg_attr_info.rts_threshold > 255 && strHostIFCfgParamAttr->cfg_attr_info.rts_threshold < 65536) { - strWIDList[u8WidCnt].id = WID_RTS_THRESHOLD; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.rts_threshold; - strWIDList[u8WidCnt].type = WID_SHORT; - strWIDList[u8WidCnt].size = sizeof(u16); - hif_drv->strCfgValues.rts_threshold = strHostIFCfgParamAttr->cfg_attr_info.rts_threshold; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & RTS_THRESHOLD) { + if (cfg_param_attr->cfg_attr_info.rts_threshold > 255 && + cfg_param_attr->cfg_attr_info.rts_threshold < 65536) { + wid_list[wid_cnt].id = WID_RTS_THRESHOLD; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.rts_threshold; + wid_list[wid_cnt].type = WID_SHORT; + wid_list[wid_cnt].size = sizeof(u16); + hif_drv->cfg_values.rts_threshold = cfg_param_attr->cfg_attr_info.rts_threshold; } else { PRINT_ER("Threshold Range fail\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & PREAMBLE) { - if (strHostIFCfgParamAttr->cfg_attr_info.preamble_type < 3) { - strWIDList[u8WidCnt].id = WID_PREAMBLE; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.preamble_type; - strWIDList[u8WidCnt].type = WID_CHAR; - strWIDList[u8WidCnt].size = sizeof(char); - hif_drv->strCfgValues.preamble_type = strHostIFCfgParamAttr->cfg_attr_info.preamble_type; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & PREAMBLE) { + if (cfg_param_attr->cfg_attr_info.preamble_type < 3) { + wid_list[wid_cnt].id = WID_PREAMBLE; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.preamble_type; + wid_list[wid_cnt].type = WID_CHAR; + wid_list[wid_cnt].size = sizeof(char); + hif_drv->cfg_values.preamble_type = cfg_param_attr->cfg_attr_info.preamble_type; } else { PRINT_ER("Preamle Range(0~2) over\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & SHORT_SLOT_ALLOWED) { - if (strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed < 2) { - strWIDList[u8WidCnt].id = WID_SHORT_SLOT_ALLOWED; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed; - strWIDList[u8WidCnt].type = WID_CHAR; - strWIDList[u8WidCnt].size = sizeof(char); - hif_drv->strCfgValues.short_slot_allowed = (u8)strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & SHORT_SLOT_ALLOWED) { + if (cfg_param_attr->cfg_attr_info.short_slot_allowed < 2) { + wid_list[wid_cnt].id = WID_SHORT_SLOT_ALLOWED; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.short_slot_allowed; + wid_list[wid_cnt].type = WID_CHAR; + wid_list[wid_cnt].size = sizeof(char); + hif_drv->cfg_values.short_slot_allowed = (u8)cfg_param_attr->cfg_attr_info.short_slot_allowed; } else { PRINT_ER("Short slot(2) over\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & TXOP_PROT_DISABLE) { - if (strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled < 2) { - strWIDList[u8WidCnt].id = WID_11N_TXOP_PROT_DISABLE; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled; - strWIDList[u8WidCnt].type = WID_CHAR; - strWIDList[u8WidCnt].size = sizeof(char); - hif_drv->strCfgValues.txop_prot_disabled = (u8)strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & TXOP_PROT_DISABLE) { + if (cfg_param_attr->cfg_attr_info.txop_prot_disabled < 2) { + wid_list[wid_cnt].id = WID_11N_TXOP_PROT_DISABLE; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.txop_prot_disabled; + wid_list[wid_cnt].type = WID_CHAR; + wid_list[wid_cnt].size = sizeof(char); + hif_drv->cfg_values.txop_prot_disabled = (u8)cfg_param_attr->cfg_attr_info.txop_prot_disabled; } else { PRINT_ER("TXOP prot disable\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & BEACON_INTERVAL) { - if (strHostIFCfgParamAttr->cfg_attr_info.beacon_interval > 0 && strHostIFCfgParamAttr->cfg_attr_info.beacon_interval < 65536) { - strWIDList[u8WidCnt].id = WID_BEACON_INTERVAL; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.beacon_interval; - strWIDList[u8WidCnt].type = WID_SHORT; - strWIDList[u8WidCnt].size = sizeof(u16); - hif_drv->strCfgValues.beacon_interval = strHostIFCfgParamAttr->cfg_attr_info.beacon_interval; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & BEACON_INTERVAL) { + if (cfg_param_attr->cfg_attr_info.beacon_interval > 0 && + cfg_param_attr->cfg_attr_info.beacon_interval < 65536) { + wid_list[wid_cnt].id = WID_BEACON_INTERVAL; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.beacon_interval; + wid_list[wid_cnt].type = WID_SHORT; + wid_list[wid_cnt].size = sizeof(u16); + hif_drv->cfg_values.beacon_interval = cfg_param_attr->cfg_attr_info.beacon_interval; } else { PRINT_ER("Beacon interval(1~65535) fail\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & DTIM_PERIOD) { - if (strHostIFCfgParamAttr->cfg_attr_info.dtim_period > 0 && strHostIFCfgParamAttr->cfg_attr_info.dtim_period < 256) { - strWIDList[u8WidCnt].id = WID_DTIM_PERIOD; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.dtim_period; - strWIDList[u8WidCnt].type = WID_CHAR; - strWIDList[u8WidCnt].size = sizeof(char); - hif_drv->strCfgValues.dtim_period = strHostIFCfgParamAttr->cfg_attr_info.dtim_period; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & DTIM_PERIOD) { + if (cfg_param_attr->cfg_attr_info.dtim_period > 0 && + cfg_param_attr->cfg_attr_info.dtim_period < 256) { + wid_list[wid_cnt].id = WID_DTIM_PERIOD; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.dtim_period; + wid_list[wid_cnt].type = WID_CHAR; + wid_list[wid_cnt].size = sizeof(char); + hif_drv->cfg_values.dtim_period = cfg_param_attr->cfg_attr_info.dtim_period; } else { PRINT_ER("DTIM range(1~255) fail\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & SITE_SURVEY) { - if (strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled < 3) { - strWIDList[u8WidCnt].id = WID_SITE_SURVEY; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled; - strWIDList[u8WidCnt].type = WID_CHAR; - strWIDList[u8WidCnt].size = sizeof(char); - hif_drv->strCfgValues.site_survey_enabled = (u8)strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & SITE_SURVEY) { + if (cfg_param_attr->cfg_attr_info.site_survey_enabled < 3) { + wid_list[wid_cnt].id = WID_SITE_SURVEY; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.site_survey_enabled; + wid_list[wid_cnt].type = WID_CHAR; + wid_list[wid_cnt].size = sizeof(char); + hif_drv->cfg_values.site_survey_enabled = (u8)cfg_param_attr->cfg_attr_info.site_survey_enabled; } else { PRINT_ER("Site survey disable\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & SITE_SURVEY_SCAN_TIME) { - if (strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time < 65536) { - strWIDList[u8WidCnt].id = WID_SITE_SURVEY_SCAN_TIME; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time; - strWIDList[u8WidCnt].type = WID_SHORT; - strWIDList[u8WidCnt].size = sizeof(u16); - hif_drv->strCfgValues.site_survey_scan_time = strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & SITE_SURVEY_SCAN_TIME) { + if (cfg_param_attr->cfg_attr_info.site_survey_scan_time > 0 && + cfg_param_attr->cfg_attr_info.site_survey_scan_time < 65536) { + wid_list[wid_cnt].id = WID_SITE_SURVEY_SCAN_TIME; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.site_survey_scan_time; + wid_list[wid_cnt].type = WID_SHORT; + wid_list[wid_cnt].size = sizeof(u16); + hif_drv->cfg_values.site_survey_scan_time = cfg_param_attr->cfg_attr_info.site_survey_scan_time; } else { PRINT_ER("Site survey scan time(1~65535) over\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & ACTIVE_SCANTIME) { - if (strHostIFCfgParamAttr->cfg_attr_info.active_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.active_scan_time < 65536) { - strWIDList[u8WidCnt].id = WID_ACTIVE_SCAN_TIME; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.active_scan_time; - strWIDList[u8WidCnt].type = WID_SHORT; - strWIDList[u8WidCnt].size = sizeof(u16); - hif_drv->strCfgValues.active_scan_time = strHostIFCfgParamAttr->cfg_attr_info.active_scan_time; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & ACTIVE_SCANTIME) { + if (cfg_param_attr->cfg_attr_info.active_scan_time > 0 && + cfg_param_attr->cfg_attr_info.active_scan_time < 65536) { + wid_list[wid_cnt].id = WID_ACTIVE_SCAN_TIME; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.active_scan_time; + wid_list[wid_cnt].type = WID_SHORT; + wid_list[wid_cnt].size = sizeof(u16); + hif_drv->cfg_values.active_scan_time = cfg_param_attr->cfg_attr_info.active_scan_time; } else { PRINT_ER("Active scan time(1~65535) over\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; - } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & PASSIVE_SCANTIME) { - if (strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time < 65536) { - strWIDList[u8WidCnt].id = WID_PASSIVE_SCAN_TIME; - strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time; - strWIDList[u8WidCnt].type = WID_SHORT; - strWIDList[u8WidCnt].size = sizeof(u16); - hif_drv->strCfgValues.passive_scan_time = strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time; + wid_cnt++; + } + if (cfg_param_attr->cfg_attr_info.flag & PASSIVE_SCANTIME) { + if (cfg_param_attr->cfg_attr_info.passive_scan_time > 0 && + cfg_param_attr->cfg_attr_info.passive_scan_time < 65536) { + wid_list[wid_cnt].id = WID_PASSIVE_SCAN_TIME; + wid_list[wid_cnt].val = (s8 *)&cfg_param_attr->cfg_attr_info.passive_scan_time; + wid_list[wid_cnt].type = WID_SHORT; + wid_list[wid_cnt].size = sizeof(u16); + hif_drv->cfg_values.passive_scan_time = cfg_param_attr->cfg_attr_info.passive_scan_time; } else { PRINT_ER("Passive scan time(1~65535) over\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; + wid_cnt++; } - if (strHostIFCfgParamAttr->cfg_attr_info.flag & CURRENT_TX_RATE) { - enum CURRENT_TXRATE curr_tx_rate = strHostIFCfgParamAttr->cfg_attr_info.curr_tx_rate; + if (cfg_param_attr->cfg_attr_info.flag & CURRENT_TX_RATE) { + enum CURRENT_TXRATE curr_tx_rate = cfg_param_attr->cfg_attr_info.curr_tx_rate; if (curr_tx_rate == AUTORATE || curr_tx_rate == MBPS_1 || curr_tx_rate == MBPS_2 || curr_tx_rate == MBPS_5_5 @@ -777,38 +759,40 @@ static s32 Handle_CfgParam(struct host_if_drv *hif_drv, || curr_tx_rate == MBPS_9 || curr_tx_rate == MBPS_12 || curr_tx_rate == MBPS_18 || curr_tx_rate == MBPS_24 || curr_tx_rate == MBPS_36 || curr_tx_rate == MBPS_48 || curr_tx_rate == MBPS_54) { - strWIDList[u8WidCnt].id = WID_CURRENT_TX_RATE; - strWIDList[u8WidCnt].val = (s8 *)&curr_tx_rate; - strWIDList[u8WidCnt].type = WID_SHORT; - strWIDList[u8WidCnt].size = sizeof(u16); - hif_drv->strCfgValues.curr_tx_rate = (u8)curr_tx_rate; + wid_list[wid_cnt].id = WID_CURRENT_TX_RATE; + wid_list[wid_cnt].val = (s8 *)&curr_tx_rate; + wid_list[wid_cnt].type = WID_SHORT; + wid_list[wid_cnt].size = sizeof(u16); + hif_drv->cfg_values.curr_tx_rate = (u8)curr_tx_rate; } else { PRINT_ER("out of TX rate\n"); result = -EINVAL; goto ERRORHANDLER; } - u8WidCnt++; + wid_cnt++; } - result = send_config_pkt(SET_CFG, strWIDList, u8WidCnt, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, wid_list, + wid_cnt, wilc_get_vif_idx(vif)); if (result) PRINT_ER("Error in setting CFG params\n"); ERRORHANDLER: - up(&hif_drv->gtOsCfgValuesSem); + up(&hif_drv->sem_cfg_values); return result; } -static s32 Handle_wait_msg_q_empty(void) +static void Handle_wait_msg_q_empty(void) { - g_wilc_initialized = 0; + wilc_initialized = 0; up(&hif_sema_wait_response); - return 0; } -static s32 Handle_Scan(struct host_if_drv *hif_drv, +static s32 Handle_ScanDone(struct wilc_vif *vif, + enum scan_event enuEvent); + +static s32 Handle_Scan(struct wilc_vif *vif, struct scan_attr *pstrHostIFscanAttr) { s32 result = 0; @@ -818,21 +802,24 @@ static s32 Handle_Scan(struct host_if_drv *hif_drv, u8 *pu8Buffer; u8 valuesize = 0; u8 *pu8HdnNtwrksWidVal = NULL; + struct host_if_drv *hif_drv = vif->hif_drv; PRINT_D(HOSTINF_DBG, "Setting SCAN params\n"); - PRINT_D(HOSTINF_DBG, "Scanning: In [%d] state\n", hif_drv->enuHostIFstate); + PRINT_D(HOSTINF_DBG, "Scanning: In [%d] state\n", hif_drv->hif_state); - hif_drv->usr_scan_req.pfUserScanResult = pstrHostIFscanAttr->result; - hif_drv->usr_scan_req.u32UserScanPvoid = pstrHostIFscanAttr->arg; + hif_drv->usr_scan_req.scan_result = pstrHostIFscanAttr->result; + hif_drv->usr_scan_req.arg = pstrHostIFscanAttr->arg; - if ((hif_drv->enuHostIFstate >= HOST_IF_SCANNING) && (hif_drv->enuHostIFstate < HOST_IF_CONNECTED)) { - PRINT_D(GENERIC_DBG, "Don't scan we are already in [%d] state\n", hif_drv->enuHostIFstate); + if ((hif_drv->hif_state >= HOST_IF_SCANNING) && + (hif_drv->hif_state < HOST_IF_CONNECTED)) { + PRINT_D(GENERIC_DBG, "Don't scan already in [%d] state\n", + hif_drv->hif_state); PRINT_ER("Already scan\n"); result = -EBUSY; goto ERRORHANDLER; } - if (g_obtainingIP || connecting) { + if (wilc_optaining_ip || wilc_connecting) { PRINT_D(GENERIC_DBG, "[handle_scan]: Don't do obss scan until IP adresss is obtained\n"); PRINT_ER("Don't do obss scan\n"); result = -EBUSY; @@ -841,7 +828,7 @@ static s32 Handle_Scan(struct host_if_drv *hif_drv, PRINT_D(HOSTINF_DBG, "Setting SCAN params\n"); - hif_drv->usr_scan_req.u32RcvdChCount = 0; + hif_drv->usr_scan_req.rcvd_ch_cnt = 0; strWIDList[u32WidsCount].id = (u16)WID_SSID_PROBE_REQ; strWIDList[u32WidsCount].type = WID_STR; @@ -904,13 +891,14 @@ static s32 Handle_Scan(struct host_if_drv *hif_drv, strWIDList[u32WidsCount].val = (s8 *)&pstrHostIFscanAttr->src; u32WidsCount++; - if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) + if (hif_drv->hif_state == HOST_IF_CONNECTED) scan_while_connected = true; - else if (hif_drv->enuHostIFstate == HOST_IF_IDLE) + else if (hif_drv->hif_state == HOST_IF_IDLE) scan_while_connected = false; - result = send_config_pkt(SET_CFG, strWIDList, u32WidsCount, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, strWIDList, + u32WidsCount, + wilc_get_vif_idx(vif)); if (result) PRINT_ER("Failed to send scan paramters config packet\n"); @@ -919,8 +907,8 @@ static s32 Handle_Scan(struct host_if_drv *hif_drv, ERRORHANDLER: if (result) { - del_timer(&hif_drv->hScanTimer); - Handle_ScanDone(hif_drv, SCAN_EVENT_ABORTED); + del_timer(&hif_drv->scan_timer); + Handle_ScanDone(vif, SCAN_EVENT_ABORTED); } kfree(pstrHostIFscanAttr->ch_freq_list); @@ -936,12 +924,13 @@ ERRORHANDLER: return result; } -static s32 Handle_ScanDone(struct host_if_drv *hif_drv, +static s32 Handle_ScanDone(struct wilc_vif *vif, enum scan_event enuEvent) { s32 result = 0; u8 u8abort_running_scan; struct wid wid; + struct host_if_drv *hif_drv = vif->hif_drv; PRINT_D(HOSTINF_DBG, "in Handle_ScanDone()\n"); @@ -953,8 +942,8 @@ static s32 Handle_ScanDone(struct host_if_drv *hif_drv, wid.val = (s8 *)&u8abort_running_scan; wid.size = sizeof(char); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("Failed to set abort running scan\n"); @@ -967,17 +956,17 @@ static s32 Handle_ScanDone(struct host_if_drv *hif_drv, return result; } - if (hif_drv->usr_scan_req.pfUserScanResult) { - hif_drv->usr_scan_req.pfUserScanResult(enuEvent, NULL, - hif_drv->usr_scan_req.u32UserScanPvoid, NULL); - hif_drv->usr_scan_req.pfUserScanResult = NULL; + if (hif_drv->usr_scan_req.scan_result) { + hif_drv->usr_scan_req.scan_result(enuEvent, NULL, + hif_drv->usr_scan_req.arg, NULL); + hif_drv->usr_scan_req.scan_result = NULL; } return result; } -u8 u8ConnectedSSID[6] = {0}; -static s32 Handle_Connect(struct host_if_drv *hif_drv, +u8 wilc_connected_ssid[6] = {0}; +static s32 Handle_Connect(struct wilc_vif *vif, struct connect_attr *pstrHostIFconnectAttr) { s32 result = 0; @@ -985,10 +974,11 @@ static s32 Handle_Connect(struct host_if_drv *hif_drv, u32 u32WidsCount = 0, dummyval = 0; u8 *pu8CurrByte = NULL; struct join_bss_param *ptstrJoinBssParam; + struct host_if_drv *hif_drv = vif->hif_drv; PRINT_D(GENERIC_DBG, "Handling connect request\n"); - if (memcmp(pstrHostIFconnectAttr->bssid, u8ConnectedSSID, ETH_ALEN) == 0) { + if (memcmp(pstrHostIFconnectAttr->bssid, wilc_connected_ssid, ETH_ALEN) == 0) { result = 0; PRINT_ER("Trying to connect to an already connected AP, Discard connect request\n"); return result; @@ -1008,7 +998,7 @@ static s32 Handle_Connect(struct host_if_drv *hif_drv, memcpy(hif_drv->usr_conn_req.pu8bssid, pstrHostIFconnectAttr->bssid, 6); } - hif_drv->usr_conn_req.ssidLen = pstrHostIFconnectAttr->ssid_len; + hif_drv->usr_conn_req.ssid_len = pstrHostIFconnectAttr->ssid_len; if (pstrHostIFconnectAttr->ssid) { hif_drv->usr_conn_req.pu8ssid = kmalloc(pstrHostIFconnectAttr->ssid_len + 1, GFP_KERNEL); memcpy(hif_drv->usr_conn_req.pu8ssid, @@ -1017,18 +1007,18 @@ static s32 Handle_Connect(struct host_if_drv *hif_drv, hif_drv->usr_conn_req.pu8ssid[pstrHostIFconnectAttr->ssid_len] = '\0'; } - hif_drv->usr_conn_req.ConnReqIEsLen = pstrHostIFconnectAttr->ies_len; + hif_drv->usr_conn_req.ies_len = pstrHostIFconnectAttr->ies_len; if (pstrHostIFconnectAttr->ies) { - hif_drv->usr_conn_req.pu8ConnReqIEs = kmalloc(pstrHostIFconnectAttr->ies_len, GFP_KERNEL); - memcpy(hif_drv->usr_conn_req.pu8ConnReqIEs, + hif_drv->usr_conn_req.ies = kmalloc(pstrHostIFconnectAttr->ies_len, GFP_KERNEL); + memcpy(hif_drv->usr_conn_req.ies, pstrHostIFconnectAttr->ies, pstrHostIFconnectAttr->ies_len); } hif_drv->usr_conn_req.u8security = pstrHostIFconnectAttr->security; - hif_drv->usr_conn_req.tenuAuth_type = pstrHostIFconnectAttr->auth_type; - hif_drv->usr_conn_req.pfUserConnectResult = pstrHostIFconnectAttr->result; - hif_drv->usr_conn_req.u32UserConnectPvoid = pstrHostIFconnectAttr->arg; + hif_drv->usr_conn_req.auth_type = pstrHostIFconnectAttr->auth_type; + hif_drv->usr_conn_req.conn_result = pstrHostIFconnectAttr->result; + hif_drv->usr_conn_req.arg = pstrHostIFconnectAttr->arg; strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT; strWIDList[u32WidsCount].type = WID_INT; @@ -1051,14 +1041,14 @@ static s32 Handle_Connect(struct host_if_drv *hif_drv, { strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_ASSOCIATE; strWIDList[u32WidsCount].type = WID_BIN_DATA; - strWIDList[u32WidsCount].val = hif_drv->usr_conn_req.pu8ConnReqIEs; - strWIDList[u32WidsCount].size = hif_drv->usr_conn_req.ConnReqIEsLen; + strWIDList[u32WidsCount].val = hif_drv->usr_conn_req.ies; + strWIDList[u32WidsCount].size = hif_drv->usr_conn_req.ies_len; u32WidsCount++; if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) { - info_element_size = hif_drv->usr_conn_req.ConnReqIEsLen; + info_element_size = hif_drv->usr_conn_req.ies_len; info_element = kmalloc(info_element_size, GFP_KERNEL); - memcpy(info_element, hif_drv->usr_conn_req.pu8ConnReqIEs, + memcpy(info_element, hif_drv->usr_conn_req.ies, info_element_size); } } @@ -1076,13 +1066,14 @@ static s32 Handle_Connect(struct host_if_drv *hif_drv, strWIDList[u32WidsCount].id = (u16)WID_AUTH_TYPE; strWIDList[u32WidsCount].type = WID_CHAR; strWIDList[u32WidsCount].size = sizeof(char); - strWIDList[u32WidsCount].val = (s8 *)(&hif_drv->usr_conn_req.tenuAuth_type); + strWIDList[u32WidsCount].val = (s8 *)&hif_drv->usr_conn_req.auth_type; u32WidsCount++; if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) - auth_type = (u8)hif_drv->usr_conn_req.tenuAuth_type; + auth_type = (u8)hif_drv->usr_conn_req.auth_type; - PRINT_INFO(HOSTINF_DBG, "Authentication Type = %x\n", hif_drv->usr_conn_req.tenuAuth_type); + PRINT_INFO(HOSTINF_DBG, "Authentication Type = %x\n", + hif_drv->usr_conn_req.auth_type); PRINT_D(HOSTINF_DBG, "Connecting to network of SSID %s on channel %d\n", hif_drv->usr_conn_req.pu8ssid, pstrHostIFconnectAttr->ch); @@ -1141,7 +1132,7 @@ static s32 Handle_Connect(struct host_if_drv *hif_drv, *(pu8CurrByte++) = ptstrJoinBssParam->uapsd_cap; *(pu8CurrByte++) = ptstrJoinBssParam->ht_capable; - hif_drv->usr_conn_req.IsHTCapable = ptstrJoinBssParam->ht_capable; + hif_drv->usr_conn_req.ht_capable = ptstrJoinBssParam->ht_capable; *(pu8CurrByte++) = ptstrJoinBssParam->rsn_found; PRINT_D(HOSTINF_DBG, "* rsn found %d*\n", *(pu8CurrByte - 1)); @@ -1194,36 +1185,38 @@ static s32 Handle_Connect(struct host_if_drv *hif_drv, if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) { memcpy(join_req, pu8CurrByte, join_req_size); - join_req_drv = hif_drv; + join_req_vif = vif; } PRINT_D(GENERIC_DBG, "send HOST_IF_WAITING_CONN_RESP\n"); if (pstrHostIFconnectAttr->bssid) { - memcpy(u8ConnectedSSID, pstrHostIFconnectAttr->bssid, ETH_ALEN); - - PRINT_D(GENERIC_DBG, "save Bssid = %pM\n", pstrHostIFconnectAttr->bssid); - PRINT_D(GENERIC_DBG, "save bssid = %pM\n", u8ConnectedSSID); + memcpy(wilc_connected_ssid, + pstrHostIFconnectAttr->bssid, ETH_ALEN); + PRINT_D(GENERIC_DBG, "save Bssid = %pM\n", + pstrHostIFconnectAttr->bssid); + PRINT_D(GENERIC_DBG, "save bssid = %pM\n", wilc_connected_ssid); } - result = send_config_pkt(SET_CFG, strWIDList, u32WidsCount, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, strWIDList, + u32WidsCount, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("failed to send config packet\n"); result = -EFAULT; goto ERRORHANDLER; } else { PRINT_D(GENERIC_DBG, "set HOST_IF_WAITING_CONN_RESP\n"); - hif_drv->enuHostIFstate = HOST_IF_WAITING_CONN_RESP; + hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP; } ERRORHANDLER: if (result) { tstrConnectInfo strConnectInfo; - del_timer(&hif_drv->hConnectTimer); + del_timer(&hif_drv->connect_timer); - PRINT_D(HOSTINF_DBG, "could not start connecting to the required network\n"); + PRINT_D(HOSTINF_DBG, "could not start wilc_connecting to the required network\n"); memset(&strConnectInfo, 0, sizeof(tstrConnectInfo)); @@ -1244,7 +1237,7 @@ ERRORHANDLER: MAC_DISCONNECTED, NULL, pstrHostIFconnectAttr->arg); - hif_drv->enuHostIFstate = HOST_IF_IDLE; + hif_drv->hif_state = HOST_IF_IDLE; kfree(strConnectInfo.pu8ReqIEs); strConnectInfo.pu8ReqIEs = NULL; @@ -1267,7 +1260,7 @@ ERRORHANDLER: return result; } -static s32 Handle_FlushConnect(struct host_if_drv *hif_drv) +static s32 Handle_FlushConnect(struct wilc_vif *vif) { s32 result = 0; struct wid strWIDList[5]; @@ -1303,8 +1296,9 @@ static s32 Handle_FlushConnect(struct host_if_drv *hif_drv) u32WidsCount++; - result = send_config_pkt(SET_CFG, strWIDList, u32WidsCount, - get_id_from_handler(join_req_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, strWIDList, + u32WidsCount, + wilc_get_vif_idx(join_req_vif)); if (result) { PRINT_ER("failed to send config packet\n"); result = -EINVAL; @@ -1313,43 +1307,44 @@ static s32 Handle_FlushConnect(struct host_if_drv *hif_drv) return result; } -static s32 Handle_ConnectTimeout(struct host_if_drv *hif_drv) +static s32 Handle_ConnectTimeout(struct wilc_vif *vif) { s32 result = 0; tstrConnectInfo strConnectInfo; struct wid wid; u16 u16DummyReasonCode = 0; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("Driver handler is NULL\n"); return result; } - hif_drv->enuHostIFstate = HOST_IF_IDLE; + hif_drv->hif_state = HOST_IF_IDLE; scan_while_connected = false; memset(&strConnectInfo, 0, sizeof(tstrConnectInfo)); - if (hif_drv->usr_conn_req.pfUserConnectResult) { + if (hif_drv->usr_conn_req.conn_result) { if (hif_drv->usr_conn_req.pu8bssid) { memcpy(strConnectInfo.au8bssid, hif_drv->usr_conn_req.pu8bssid, 6); } - if (hif_drv->usr_conn_req.pu8ConnReqIEs) { - strConnectInfo.ReqIEsLen = hif_drv->usr_conn_req.ConnReqIEsLen; - strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->usr_conn_req.ConnReqIEsLen, GFP_KERNEL); + if (hif_drv->usr_conn_req.ies) { + strConnectInfo.ReqIEsLen = hif_drv->usr_conn_req.ies_len; + strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->usr_conn_req.ies_len, GFP_KERNEL); memcpy(strConnectInfo.pu8ReqIEs, - hif_drv->usr_conn_req.pu8ConnReqIEs, - hif_drv->usr_conn_req.ConnReqIEsLen); + hif_drv->usr_conn_req.ies, + hif_drv->usr_conn_req.ies_len); } - hif_drv->usr_conn_req.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP, - &strConnectInfo, - MAC_DISCONNECTED, - NULL, - hif_drv->usr_conn_req.u32UserConnectPvoid); + hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_CONN_RESP, + &strConnectInfo, + MAC_DISCONNECTED, + NULL, + hif_drv->usr_conn_req.arg); kfree(strConnectInfo.pu8ReqIEs); strConnectInfo.pu8ReqIEs = NULL; @@ -1364,25 +1359,28 @@ static s32 Handle_ConnectTimeout(struct host_if_drv *hif_drv) PRINT_D(HOSTINF_DBG, "Sending disconnect request\n"); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) PRINT_ER("Failed to send dissconect config packet\n"); - hif_drv->usr_conn_req.ssidLen = 0; + hif_drv->usr_conn_req.ssid_len = 0; kfree(hif_drv->usr_conn_req.pu8ssid); + hif_drv->usr_conn_req.pu8ssid = NULL; kfree(hif_drv->usr_conn_req.pu8bssid); - hif_drv->usr_conn_req.ConnReqIEsLen = 0; - kfree(hif_drv->usr_conn_req.pu8ConnReqIEs); + hif_drv->usr_conn_req.pu8bssid = NULL; + hif_drv->usr_conn_req.ies_len = 0; + kfree(hif_drv->usr_conn_req.ies); + hif_drv->usr_conn_req.ies = NULL; - eth_zero_addr(u8ConnectedSSID); + eth_zero_addr(wilc_connected_ssid); - if (join_req && join_req_drv == hif_drv) { + if (join_req && join_req_vif == vif) { kfree(join_req); join_req = NULL; } - if (info_element && join_req_drv == hif_drv) { + if (info_element && join_req_vif == vif) { kfree(info_element); info_element = NULL; } @@ -1390,7 +1388,7 @@ static s32 Handle_ConnectTimeout(struct host_if_drv *hif_drv) return result; } -static s32 Handle_RcvdNtwrkInfo(struct host_if_drv *hif_drv, +static s32 Handle_RcvdNtwrkInfo(struct wilc_vif *vif, struct rcvd_net_info *pstrRcvdNetworkInfo) { u32 i; @@ -1398,30 +1396,31 @@ static s32 Handle_RcvdNtwrkInfo(struct host_if_drv *hif_drv, s32 result = 0; tstrNetworkInfo *pstrNetworkInfo = NULL; void *pJoinParams = NULL; + struct host_if_drv *hif_drv = vif->hif_drv; bNewNtwrkFound = true; PRINT_INFO(HOSTINF_DBG, "Handling received network info\n"); - if (hif_drv->usr_scan_req.pfUserScanResult) { + if (hif_drv->usr_scan_req.scan_result) { PRINT_D(HOSTINF_DBG, "State: Scanning, parsing network information received\n"); - parse_network_info(pstrRcvdNetworkInfo->buffer, &pstrNetworkInfo); + wilc_parse_network_info(pstrRcvdNetworkInfo->buffer, &pstrNetworkInfo); if ((!pstrNetworkInfo) || - (!hif_drv->usr_scan_req.pfUserScanResult)) { + (!hif_drv->usr_scan_req.scan_result)) { PRINT_ER("driver is null\n"); result = -EINVAL; goto done; } - for (i = 0; i < hif_drv->usr_scan_req.u32RcvdChCount; i++) { - if ((hif_drv->usr_scan_req.astrFoundNetworkInfo[i].au8bssid) && + for (i = 0; i < hif_drv->usr_scan_req.rcvd_ch_cnt; i++) { + if ((hif_drv->usr_scan_req.net_info[i].au8bssid) && (pstrNetworkInfo->au8bssid)) { - if (memcmp(hif_drv->usr_scan_req.astrFoundNetworkInfo[i].au8bssid, + if (memcmp(hif_drv->usr_scan_req.net_info[i].au8bssid, pstrNetworkInfo->au8bssid, 6) == 0) { - if (pstrNetworkInfo->s8rssi <= hif_drv->usr_scan_req.astrFoundNetworkInfo[i].s8rssi) { + if (pstrNetworkInfo->s8rssi <= hif_drv->usr_scan_req.net_info[i].s8rssi) { PRINT_D(HOSTINF_DBG, "Network previously discovered\n"); goto done; } else { - hif_drv->usr_scan_req.astrFoundNetworkInfo[i].s8rssi = pstrNetworkInfo->s8rssi; + hif_drv->usr_scan_req.net_info[i].s8rssi = pstrNetworkInfo->s8rssi; bNewNtwrkFound = false; break; } @@ -1432,30 +1431,30 @@ static s32 Handle_RcvdNtwrkInfo(struct host_if_drv *hif_drv, if (bNewNtwrkFound) { PRINT_D(HOSTINF_DBG, "New network found\n"); - if (hif_drv->usr_scan_req.u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) { - hif_drv->usr_scan_req.astrFoundNetworkInfo[hif_drv->usr_scan_req.u32RcvdChCount].s8rssi = pstrNetworkInfo->s8rssi; + if (hif_drv->usr_scan_req.rcvd_ch_cnt < MAX_NUM_SCANNED_NETWORKS) { + hif_drv->usr_scan_req.net_info[hif_drv->usr_scan_req.rcvd_ch_cnt].s8rssi = pstrNetworkInfo->s8rssi; - if (hif_drv->usr_scan_req.astrFoundNetworkInfo[hif_drv->usr_scan_req.u32RcvdChCount].au8bssid && + if (hif_drv->usr_scan_req.net_info[hif_drv->usr_scan_req.rcvd_ch_cnt].au8bssid && pstrNetworkInfo->au8bssid) { - memcpy(hif_drv->usr_scan_req.astrFoundNetworkInfo[hif_drv->usr_scan_req.u32RcvdChCount].au8bssid, + memcpy(hif_drv->usr_scan_req.net_info[hif_drv->usr_scan_req.rcvd_ch_cnt].au8bssid, pstrNetworkInfo->au8bssid, 6); - hif_drv->usr_scan_req.u32RcvdChCount++; + hif_drv->usr_scan_req.rcvd_ch_cnt++; pstrNetworkInfo->bNewNetwork = true; pJoinParams = host_int_ParseJoinBssParam(pstrNetworkInfo); - hif_drv->usr_scan_req.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo, - hif_drv->usr_scan_req.u32UserScanPvoid, - pJoinParams); + hif_drv->usr_scan_req.scan_result(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo, + hif_drv->usr_scan_req.arg, + pJoinParams); } } else { PRINT_WRN(HOSTINF_DBG, "Discovered networks exceeded max. limit\n"); } } else { pstrNetworkInfo->bNewNetwork = false; - hif_drv->usr_scan_req.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo, - hif_drv->usr_scan_req.u32UserScanPvoid, NULL); + hif_drv->usr_scan_req.scan_result(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo, + hif_drv->usr_scan_req.arg, NULL); } } @@ -1464,14 +1463,19 @@ done: pstrRcvdNetworkInfo->buffer = NULL; if (pstrNetworkInfo) { - DeallocateNetworkInfo(pstrNetworkInfo); + wilc_dealloc_network_info(pstrNetworkInfo); pstrNetworkInfo = NULL; } return result; } -static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv, +static s32 host_int_get_assoc_res_info(struct wilc_vif *vif, + u8 *pu8AssocRespInfo, + u32 u32MaxAssocRespInfoLen, + u32 *pu32RcvdAssocRespInfoLen); + +static s32 Handle_RcvdGnrlAsyncInfo(struct wilc_vif *vif, struct rcvd_async_info *pstrRcvdGnrlAsyncInfo) { s32 result = 0; @@ -1486,19 +1490,20 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv, tstrConnectInfo strConnectInfo; tstrDisconnectNotifInfo strDisconnectNotifInfo; s32 s32Err = 0; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("Driver handler is NULL\n"); return -ENODEV; } - PRINT_D(GENERIC_DBG, "Current State = %d,Received state = %d\n", hif_drv->enuHostIFstate, - pstrRcvdGnrlAsyncInfo->buffer[7]); + PRINT_D(GENERIC_DBG, "Current State = %d,Received state = %d\n", + hif_drv->hif_state, pstrRcvdGnrlAsyncInfo->buffer[7]); - if ((hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) || - (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) || - hif_drv->usr_scan_req.pfUserScanResult) { + if ((hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) || + (hif_drv->hif_state == HOST_IF_CONNECTED) || + hif_drv->usr_scan_req.scan_result) { if (!pstrRcvdGnrlAsyncInfo->buffer || - !hif_drv->usr_conn_req.pfUserConnectResult) { + !hif_drv->usr_conn_req.conn_result) { PRINT_ER("driver is null\n"); return -EINVAL; } @@ -1518,8 +1523,8 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv, u8MacStatusReasonCode = pstrRcvdGnrlAsyncInfo->buffer[8]; u8MacStatusAdditionalInfo = pstrRcvdGnrlAsyncInfo->buffer[9]; PRINT_INFO(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Info = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo); - if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) { - u32 u32RcvdAssocRespInfoLen; + if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) { + u32 u32RcvdAssocRespInfoLen = 0; tstrConnectRespInfo *pstrConnectRespInfo = NULL; PRINT_D(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Code = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo); @@ -1529,7 +1534,7 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv, if (u8MacStatus == MAC_CONNECTED) { memset(rcv_assoc_resp, 0, MAX_ASSOC_RESP_FRAME_SIZE); - host_int_get_assoc_res_info(hif_drv, + host_int_get_assoc_res_info(vif, rcv_assoc_resp, MAX_ASSOC_RESP_FRAME_SIZE, &u32RcvdAssocRespInfoLen); @@ -1538,10 +1543,10 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv, if (u32RcvdAssocRespInfoLen != 0) { PRINT_D(HOSTINF_DBG, "Parsing association response\n"); - s32Err = ParseAssocRespInfo(rcv_assoc_resp, u32RcvdAssocRespInfoLen, + s32Err = wilc_parse_assoc_resp_info(rcv_assoc_resp, u32RcvdAssocRespInfoLen, &pstrConnectRespInfo); if (s32Err) { - PRINT_ER("ParseAssocRespInfo() returned error %d\n", s32Err); + PRINT_ER("wilc_parse_assoc_resp_info() returned error %d\n", s32Err); } else { strConnectInfo.u16ConnectStatus = pstrConnectRespInfo->u16ConnectStatus; @@ -1556,7 +1561,7 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv, } if (pstrConnectRespInfo) { - DeallocateAssocRespInfo(pstrConnectRespInfo); + wilc_dealloc_assoc_resp_info(pstrConnectRespInfo); pstrConnectRespInfo = NULL; } } @@ -1566,11 +1571,10 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv, if ((u8MacStatus == MAC_CONNECTED) && (strConnectInfo.u16ConnectStatus != SUCCESSFUL_STATUSCODE)) { PRINT_ER("Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE\n"); - eth_zero_addr(u8ConnectedSSID); - + eth_zero_addr(wilc_connected_ssid); } else if (u8MacStatus == MAC_DISCONNECTED) { PRINT_ER("Received MAC status is MAC_DISCONNECTED\n"); - eth_zero_addr(u8ConnectedSSID); + eth_zero_addr(wilc_connected_ssid); } if (hif_drv->usr_conn_req.pu8bssid) { @@ -1579,40 +1583,40 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv, if ((u8MacStatus == MAC_CONNECTED) && (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) { - memcpy(hif_drv->au8AssociatedBSSID, + memcpy(hif_drv->assoc_bssid, hif_drv->usr_conn_req.pu8bssid, ETH_ALEN); } } - if (hif_drv->usr_conn_req.pu8ConnReqIEs) { - strConnectInfo.ReqIEsLen = hif_drv->usr_conn_req.ConnReqIEsLen; - strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->usr_conn_req.ConnReqIEsLen, GFP_KERNEL); + if (hif_drv->usr_conn_req.ies) { + strConnectInfo.ReqIEsLen = hif_drv->usr_conn_req.ies_len; + strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->usr_conn_req.ies_len, GFP_KERNEL); memcpy(strConnectInfo.pu8ReqIEs, - hif_drv->usr_conn_req.pu8ConnReqIEs, - hif_drv->usr_conn_req.ConnReqIEsLen); + hif_drv->usr_conn_req.ies, + hif_drv->usr_conn_req.ies_len); } - del_timer(&hif_drv->hConnectTimer); - hif_drv->usr_conn_req.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP, - &strConnectInfo, - u8MacStatus, - NULL, - hif_drv->usr_conn_req.u32UserConnectPvoid); + del_timer(&hif_drv->connect_timer); + hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_CONN_RESP, + &strConnectInfo, + u8MacStatus, + NULL, + hif_drv->usr_conn_req.arg); if ((u8MacStatus == MAC_CONNECTED) && (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) { - host_int_set_power_mgmt(hif_drv, 0, 0); + wilc_set_power_mgmt(vif, 0, 0); PRINT_D(HOSTINF_DBG, "MAC status : CONNECTED and Connect Status : Successful\n"); - hif_drv->enuHostIFstate = HOST_IF_CONNECTED; + hif_drv->hif_state = HOST_IF_CONNECTED; PRINT_D(GENERIC_DBG, "Obtaining an IP, Disable Scan\n"); - g_obtainingIP = true; - mod_timer(&hDuringIpTimer, + wilc_optaining_ip = true; + mod_timer(&wilc_during_ip_timer, jiffies + msecs_to_jiffies(10000)); } else { PRINT_D(HOSTINF_DBG, "MAC status : %d and Connect Status : %d\n", u8MacStatus, strConnectInfo.u16ConnectStatus); - hif_drv->enuHostIFstate = HOST_IF_IDLE; + hif_drv->hif_state = HOST_IF_IDLE; scan_while_connected = false; } @@ -1621,69 +1625,75 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv, kfree(strConnectInfo.pu8ReqIEs); strConnectInfo.pu8ReqIEs = NULL; - hif_drv->usr_conn_req.ssidLen = 0; + hif_drv->usr_conn_req.ssid_len = 0; kfree(hif_drv->usr_conn_req.pu8ssid); + hif_drv->usr_conn_req.pu8ssid = NULL; kfree(hif_drv->usr_conn_req.pu8bssid); - hif_drv->usr_conn_req.ConnReqIEsLen = 0; - kfree(hif_drv->usr_conn_req.pu8ConnReqIEs); + hif_drv->usr_conn_req.pu8bssid = NULL; + hif_drv->usr_conn_req.ies_len = 0; + kfree(hif_drv->usr_conn_req.ies); + hif_drv->usr_conn_req.ies = NULL; } else if ((u8MacStatus == MAC_DISCONNECTED) && - (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)) { + (hif_drv->hif_state == HOST_IF_CONNECTED)) { PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW\n"); memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo)); - if (hif_drv->usr_scan_req.pfUserScanResult) { + if (hif_drv->usr_scan_req.scan_result) { PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running OBSS Scan >>\n\n"); - del_timer(&hif_drv->hScanTimer); - Handle_ScanDone((void *)hif_drv, SCAN_EVENT_ABORTED); + del_timer(&hif_drv->scan_timer); + Handle_ScanDone(vif, SCAN_EVENT_ABORTED); } strDisconnectNotifInfo.u16reason = 0; strDisconnectNotifInfo.ie = NULL; strDisconnectNotifInfo.ie_len = 0; - if (hif_drv->usr_conn_req.pfUserConnectResult) { - g_obtainingIP = false; - host_int_set_power_mgmt(hif_drv, 0, 0); + if (hif_drv->usr_conn_req.conn_result) { + wilc_optaining_ip = false; + wilc_set_power_mgmt(vif, 0, 0); - hif_drv->usr_conn_req.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF, - NULL, - 0, - &strDisconnectNotifInfo, - hif_drv->usr_conn_req.u32UserConnectPvoid); + hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, + NULL, + 0, + &strDisconnectNotifInfo, + hif_drv->usr_conn_req.arg); } else { PRINT_ER("Connect result callback function is NULL\n"); } - eth_zero_addr(hif_drv->au8AssociatedBSSID); + eth_zero_addr(hif_drv->assoc_bssid); - hif_drv->usr_conn_req.ssidLen = 0; + hif_drv->usr_conn_req.ssid_len = 0; kfree(hif_drv->usr_conn_req.pu8ssid); + hif_drv->usr_conn_req.pu8ssid = NULL; kfree(hif_drv->usr_conn_req.pu8bssid); - hif_drv->usr_conn_req.ConnReqIEsLen = 0; - kfree(hif_drv->usr_conn_req.pu8ConnReqIEs); + hif_drv->usr_conn_req.pu8bssid = NULL; + hif_drv->usr_conn_req.ies_len = 0; + kfree(hif_drv->usr_conn_req.ies); + hif_drv->usr_conn_req.ies = NULL; - if (join_req && join_req_drv == hif_drv) { + if (join_req && join_req_vif == vif) { kfree(join_req); join_req = NULL; } - if (info_element && join_req_drv == hif_drv) { + if (info_element && join_req_vif == vif) { kfree(info_element); info_element = NULL; } - hif_drv->enuHostIFstate = HOST_IF_IDLE; + hif_drv->hif_state = HOST_IF_IDLE; scan_while_connected = false; } else if ((u8MacStatus == MAC_DISCONNECTED) && - (hif_drv->usr_scan_req.pfUserScanResult)) { + (hif_drv->usr_scan_req.scan_result)) { PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW while scanning\n"); PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running Scan >>\n\n"); - del_timer(&hif_drv->hScanTimer); - if (hif_drv->usr_scan_req.pfUserScanResult) - Handle_ScanDone(hif_drv, SCAN_EVENT_ABORTED); + del_timer(&hif_drv->scan_timer); + if (hif_drv->usr_scan_req.scan_result) + Handle_ScanDone(vif, SCAN_EVENT_ABORTED); } } @@ -1693,7 +1703,7 @@ static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv, return result; } -static int Handle_Key(struct host_if_drv *hif_drv, +static int Handle_Key(struct wilc_vif *vif, struct key_attr *pstrHostIFkeyAttr) { s32 result = 0; @@ -1703,6 +1713,7 @@ static int Handle_Key(struct host_if_drv *hif_drv, u8 *pu8keybuf; s8 s8idxarray[1]; s8 ret = 0; + struct host_if_drv *hif_drv = vif->hif_drv; switch (pstrHostIFkeyAttr->type) { case WEP: @@ -1742,12 +1753,11 @@ static int Handle_Key(struct host_if_drv *hif_drv, strWIDList[3].size = pstrHostIFkeyAttr->attr.wep.key_len; strWIDList[3].val = (s8 *)pu8keybuf; - result = send_config_pkt(SET_CFG, strWIDList, 4, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, + strWIDList, 4, + wilc_get_vif_idx(vif)); kfree(pu8keybuf); - } - - if (pstrHostIFkeyAttr->action & ADDKEY) { + } else if (pstrHostIFkeyAttr->action & ADDKEY) { PRINT_D(HOSTINF_DBG, "Handling WEP key\n"); pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len + 2, GFP_KERNEL); if (!pu8keybuf) { @@ -1765,8 +1775,9 @@ static int Handle_Key(struct host_if_drv *hif_drv, wid.val = (s8 *)pu8keybuf; wid.size = pstrHostIFkeyAttr->attr.wep.key_len + 2; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, + &wid, 1, + wilc_get_vif_idx(vif)); kfree(pu8keybuf); } else if (pstrHostIFkeyAttr->action & REMOVEKEY) { PRINT_D(HOSTINF_DBG, "Removing key\n"); @@ -1777,8 +1788,9 @@ static int Handle_Key(struct host_if_drv *hif_drv, wid.val = s8idxarray; wid.size = 1; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, + &wid, 1, + wilc_get_vif_idx(vif)); } else { wid.id = (u16)WID_KEY_ID; wid.type = WID_CHAR; @@ -1787,13 +1799,14 @@ static int Handle_Key(struct host_if_drv *hif_drv, PRINT_D(HOSTINF_DBG, "Setting default key index\n"); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, + &wid, 1, + wilc_get_vif_idx(vif)); } - up(&hif_drv->hSemTestKeyBlock); + up(&hif_drv->sem_test_key_block); break; - case WPARxGtk: + case WPA_RX_GTK: if (pstrHostIFkeyAttr->action & ADDKEY_AP) { pu8keybuf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL); if (!pu8keybuf) { @@ -1820,14 +1833,13 @@ static int Handle_Key(struct host_if_drv *hif_drv, strWIDList[1].val = (s8 *)pu8keybuf; strWIDList[1].size = RX_MIC_KEY_MSG_LEN; - result = send_config_pkt(SET_CFG, strWIDList, 2, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, + strWIDList, 2, + wilc_get_vif_idx(vif)); kfree(pu8keybuf); - up(&hif_drv->hSemTestKeyBlock); - } - - if (pstrHostIFkeyAttr->action & ADDKEY) { + up(&hif_drv->sem_test_key_block); + } else if (pstrHostIFkeyAttr->action & ADDKEY) { PRINT_D(HOSTINF_DBG, "Handling group key(Rx) function\n"); pu8keybuf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL); @@ -1837,10 +1849,10 @@ static int Handle_Key(struct host_if_drv *hif_drv, goto _WPARxGtk_end_case_; } - if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) - memcpy(pu8keybuf, hif_drv->au8AssociatedBSSID, ETH_ALEN); + if (hif_drv->hif_state == HOST_IF_CONNECTED) + memcpy(pu8keybuf, hif_drv->assoc_bssid, ETH_ALEN); else - PRINT_ER("Couldn't handle WPARxGtk while enuHostIFstate is not HOST_IF_CONNECTED\n"); + PRINT_ER("Couldn't handle WPARxGtk while state is not HOST_IF_CONNECTED\n"); memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8); memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1); @@ -1853,11 +1865,12 @@ static int Handle_Key(struct host_if_drv *hif_drv, wid.val = (s8 *)pu8keybuf; wid.size = RX_MIC_KEY_MSG_LEN; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, + &wid, 1, + wilc_get_vif_idx(vif)); kfree(pu8keybuf); - up(&hif_drv->hSemTestKeyBlock); + up(&hif_drv->sem_test_key_block); } _WPARxGtk_end_case_: kfree(pstrHostIFkeyAttr->attr.wpa.key); @@ -1867,7 +1880,7 @@ _WPARxGtk_end_case_: break; - case WPAPtk: + case WPA_PTK: if (pstrHostIFkeyAttr->action & ADDKEY_AP) { pu8keybuf = kmalloc(PTK_KEY_MSG_LEN + 1, GFP_KERNEL); if (!pu8keybuf) { @@ -1892,12 +1905,12 @@ _WPARxGtk_end_case_: strWIDList[1].val = (s8 *)pu8keybuf; strWIDList[1].size = PTK_KEY_MSG_LEN + 1; - result = send_config_pkt(SET_CFG, strWIDList, 2, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, + strWIDList, 2, + wilc_get_vif_idx(vif)); kfree(pu8keybuf); - up(&hif_drv->hSemTestKeyBlock); - } - if (pstrHostIFkeyAttr->action & ADDKEY) { + up(&hif_drv->sem_test_key_block); + } else if (pstrHostIFkeyAttr->action & ADDKEY) { pu8keybuf = kmalloc(PTK_KEY_MSG_LEN, GFP_KERNEL); if (!pu8keybuf) { PRINT_ER("No buffer to send PTK Key\n"); @@ -1915,10 +1928,11 @@ _WPARxGtk_end_case_: wid.val = (s8 *)pu8keybuf; wid.size = PTK_KEY_MSG_LEN; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, + &wid, 1, + wilc_get_vif_idx(vif)); kfree(pu8keybuf); - up(&hif_drv->hSemTestKeyBlock); + up(&hif_drv->sem_test_key_block); } _WPAPtk_end_case_: @@ -1950,8 +1964,8 @@ _WPAPtk_end_case_: wid.val = (s8 *)pu8keybuf; wid.size = (pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); kfree(pu8keybuf); break; @@ -1963,9 +1977,10 @@ _WPAPtk_end_case_: return result; } -static void Handle_Disconnect(struct host_if_drv *hif_drv) +static void Handle_Disconnect(struct wilc_vif *vif) { struct wid wid; + struct host_if_drv *hif_drv = vif->hif_drv; s32 result = 0; u16 u16DummyReasonCode = 0; @@ -1977,13 +1992,13 @@ static void Handle_Disconnect(struct host_if_drv *hif_drv) PRINT_D(HOSTINF_DBG, "Sending disconnect request\n"); - g_obtainingIP = false; - host_int_set_power_mgmt(hif_drv, 0, 0); + wilc_optaining_ip = false; + wilc_set_power_mgmt(vif, 0, 0); - eth_zero_addr(u8ConnectedSSID); + eth_zero_addr(wilc_connected_ssid); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("Failed to send dissconect config packet\n"); @@ -1996,66 +2011,75 @@ static void Handle_Disconnect(struct host_if_drv *hif_drv) strDisconnectNotifInfo.ie = NULL; strDisconnectNotifInfo.ie_len = 0; - if (hif_drv->usr_scan_req.pfUserScanResult) { - del_timer(&hif_drv->hScanTimer); - hif_drv->usr_scan_req.pfUserScanResult(SCAN_EVENT_ABORTED, NULL, - hif_drv->usr_scan_req.u32UserScanPvoid, NULL); - - hif_drv->usr_scan_req.pfUserScanResult = NULL; + if (hif_drv->usr_scan_req.scan_result) { + del_timer(&hif_drv->scan_timer); + hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, + NULL, + hif_drv->usr_scan_req.arg, + NULL); + hif_drv->usr_scan_req.scan_result = NULL; } - if (hif_drv->usr_conn_req.pfUserConnectResult) { - if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) { + if (hif_drv->usr_conn_req.conn_result) { + if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) { PRINT_D(HOSTINF_DBG, "Upper layer requested termination of connection\n"); - del_timer(&hif_drv->hConnectTimer); + del_timer(&hif_drv->connect_timer); } - hif_drv->usr_conn_req.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL, - 0, &strDisconnectNotifInfo, hif_drv->usr_conn_req.u32UserConnectPvoid); + hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, + NULL, + 0, + &strDisconnectNotifInfo, + hif_drv->usr_conn_req.arg); } else { - PRINT_ER("usr_conn_req.pfUserConnectResult = NULL\n"); + PRINT_ER("usr_conn_req.conn_result = NULL\n"); } scan_while_connected = false; - hif_drv->enuHostIFstate = HOST_IF_IDLE; + hif_drv->hif_state = HOST_IF_IDLE; - eth_zero_addr(hif_drv->au8AssociatedBSSID); + eth_zero_addr(hif_drv->assoc_bssid); - hif_drv->usr_conn_req.ssidLen = 0; + hif_drv->usr_conn_req.ssid_len = 0; kfree(hif_drv->usr_conn_req.pu8ssid); + hif_drv->usr_conn_req.pu8ssid = NULL; kfree(hif_drv->usr_conn_req.pu8bssid); - hif_drv->usr_conn_req.ConnReqIEsLen = 0; - kfree(hif_drv->usr_conn_req.pu8ConnReqIEs); + hif_drv->usr_conn_req.pu8bssid = NULL; + hif_drv->usr_conn_req.ies_len = 0; + kfree(hif_drv->usr_conn_req.ies); + hif_drv->usr_conn_req.ies = NULL; - if (join_req && join_req_drv == hif_drv) { + if (join_req && join_req_vif == vif) { kfree(join_req); join_req = NULL; } - if (info_element && join_req_drv == hif_drv) { + if (info_element && join_req_vif == vif) { kfree(info_element); info_element = NULL; } } - up(&hif_drv->hSemTestDisconnectBlock); + up(&hif_drv->sem_test_disconn_block); } -void resolve_disconnect_aberration(struct host_if_drv *hif_drv) +void wilc_resolve_disconnect_aberration(struct wilc_vif *vif) { - if (!hif_drv) + if (!vif->hif_drv) return; - if ((hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) || (hif_drv->enuHostIFstate == HOST_IF_CONNECTING)) { + if ((vif->hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) || + (vif->hif_drv->hif_state == HOST_IF_CONNECTING)) { PRINT_D(HOSTINF_DBG, "\n\n<< correcting Supplicant state machine >>\n\n"); - host_int_disconnect(hif_drv, 1); + wilc_disconnect(vif, 1); } } -static s32 Handle_GetChnl(struct host_if_drv *hif_drv) +static s32 Handle_GetChnl(struct wilc_vif *vif) { s32 result = 0; struct wid wid; + struct host_if_drv *hif_drv = vif->hif_drv; wid.id = (u16)WID_CURRENT_CHANNEL; wid.type = WID_CHAR; @@ -2064,20 +2088,20 @@ static s32 Handle_GetChnl(struct host_if_drv *hif_drv) PRINT_D(HOSTINF_DBG, "Getting channel value\n"); - result = send_config_pkt(GET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, GET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("Failed to get channel number\n"); result = -EFAULT; } - up(&hif_drv->hSemGetCHNL); + up(&hif_drv->sem_get_chnl); return result; } -static void Handle_GetRssi(struct host_if_drv *hif_drv) +static void Handle_GetRssi(struct wilc_vif *vif) { s32 result = 0; struct wid wid; @@ -2089,20 +2113,21 @@ static void Handle_GetRssi(struct host_if_drv *hif_drv) PRINT_D(HOSTINF_DBG, "Getting RSSI value\n"); - result = send_config_pkt(GET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, GET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("Failed to get RSSI value\n"); result = -EFAULT; } - up(&hif_drv->hSemGetRSSI); + up(&vif->hif_drv->sem_get_rssi); } -static void Handle_GetLinkspeed(struct host_if_drv *hif_drv) +static void Handle_GetLinkspeed(struct wilc_vif *vif) { s32 result = 0; struct wid wid; + struct host_if_drv *hif_drv = vif->hif_drv; link_speed = 0; @@ -2113,17 +2138,18 @@ static void Handle_GetLinkspeed(struct host_if_drv *hif_drv) PRINT_D(HOSTINF_DBG, "Getting LINKSPEED value\n"); - result = send_config_pkt(GET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, GET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("Failed to get LINKSPEED value\n"); result = -EFAULT; } - up(&hif_drv->hSemGetLINKSPEED); + up(&hif_drv->sem_get_link_speed); } -s32 Handle_GetStatistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatistics) +static s32 Handle_GetStatistics(struct wilc_vif *vif, + struct rf_info *pstrStatistics) { struct wid strWIDList[5]; u32 u32WidsCount = 0, result = 0; @@ -2131,35 +2157,36 @@ s32 Handle_GetStatistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatis strWIDList[u32WidsCount].id = WID_LINKSPEED; strWIDList[u32WidsCount].type = WID_CHAR; strWIDList[u32WidsCount].size = sizeof(char); - strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->u8LinkSpeed; + strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->link_speed; u32WidsCount++; strWIDList[u32WidsCount].id = WID_RSSI; strWIDList[u32WidsCount].type = WID_CHAR; strWIDList[u32WidsCount].size = sizeof(char); - strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->s8RSSI; + strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->rssi; u32WidsCount++; strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT; strWIDList[u32WidsCount].type = WID_INT; strWIDList[u32WidsCount].size = sizeof(u32); - strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->u32TxCount; + strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->tx_cnt; u32WidsCount++; strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT; strWIDList[u32WidsCount].type = WID_INT; strWIDList[u32WidsCount].size = sizeof(u32); - strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->u32RxCount; + strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->rx_cnt; u32WidsCount++; strWIDList[u32WidsCount].id = WID_FAILED_COUNT; strWIDList[u32WidsCount].type = WID_INT; strWIDList[u32WidsCount].size = sizeof(u32); - strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->u32TxFailureCount; + strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->tx_fail_cnt; u32WidsCount++; - result = send_config_pkt(GET_CFG, strWIDList, u32WidsCount, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, GET_CFG, strWIDList, + u32WidsCount, + wilc_get_vif_idx(vif)); if (result) PRINT_ER("Failed to send scan paramters config packet\n"); @@ -2168,12 +2195,13 @@ s32 Handle_GetStatistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatis return 0; } -static s32 Handle_Get_InActiveTime(struct host_if_drv *hif_drv, +static s32 Handle_Get_InActiveTime(struct wilc_vif *vif, struct sta_inactive_t *strHostIfStaInactiveT) { s32 result = 0; u8 *stamac; struct wid wid; + struct host_if_drv *hif_drv = vif->hif_drv; wid.id = (u16)WID_SET_STA_MAC_INACTIVE_TIME; wid.type = WID_STR; @@ -2185,8 +2213,8 @@ static s32 Handle_Get_InActiveTime(struct host_if_drv *hif_drv, PRINT_D(CFG80211_DBG, "SETING STA inactive time\n"); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("Failed to SET incative time\n"); @@ -2198,8 +2226,8 @@ static s32 Handle_Get_InActiveTime(struct host_if_drv *hif_drv, wid.val = (s8 *)&inactive_time; wid.size = sizeof(u32); - result = send_config_pkt(GET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, GET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("Failed to get incative time\n"); @@ -2208,12 +2236,12 @@ static s32 Handle_Get_InActiveTime(struct host_if_drv *hif_drv, PRINT_D(CFG80211_DBG, "Getting inactive time : %d\n", inactive_time); - up(&hif_drv->hSemInactiveTime); + up(&hif_drv->sem_inactive_time); return result; } -static void Handle_AddBeacon(struct host_if_drv *hif_drv, +static void Handle_AddBeacon(struct wilc_vif *vif, struct beacon_attr *pstrSetBeaconParam) { s32 result = 0; @@ -2253,12 +2281,12 @@ static void Handle_AddBeacon(struct host_if_drv *hif_drv, *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 16) & 0xFF); *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 24) & 0xFF); - if (pstrSetBeaconParam->tail > 0) + if (pstrSetBeaconParam->tail) memcpy(pu8CurrByte, pstrSetBeaconParam->tail, pstrSetBeaconParam->tail_len); pu8CurrByte += pstrSetBeaconParam->tail_len; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) PRINT_ER("Failed to send add beacon config packet\n"); @@ -2268,7 +2296,7 @@ ERRORHANDLER: kfree(pstrSetBeaconParam->tail); } -static void Handle_DelBeacon(struct host_if_drv *hif_drv) +static void Handle_DelBeacon(struct wilc_vif *vif) { s32 result = 0; struct wid wid; @@ -2286,8 +2314,8 @@ static void Handle_DelBeacon(struct host_if_drv *hif_drv) PRINT_D(HOSTINF_DBG, "Deleting BEACON\n"); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) PRINT_ER("Failed to send delete beacon config packet\n"); } @@ -2300,45 +2328,47 @@ static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer, pu8CurrByte = pu8Buffer; PRINT_D(HOSTINF_DBG, "Packing STA params\n"); - memcpy(pu8CurrByte, pstrStationParam->au8BSSID, ETH_ALEN); + memcpy(pu8CurrByte, pstrStationParam->bssid, ETH_ALEN); pu8CurrByte += ETH_ALEN; - *pu8CurrByte++ = pstrStationParam->u16AssocID & 0xFF; - *pu8CurrByte++ = (pstrStationParam->u16AssocID >> 8) & 0xFF; + *pu8CurrByte++ = pstrStationParam->aid & 0xFF; + *pu8CurrByte++ = (pstrStationParam->aid >> 8) & 0xFF; - *pu8CurrByte++ = pstrStationParam->u8NumRates; - if (pstrStationParam->u8NumRates > 0) - memcpy(pu8CurrByte, pstrStationParam->pu8Rates, pstrStationParam->u8NumRates); - pu8CurrByte += pstrStationParam->u8NumRates; + *pu8CurrByte++ = pstrStationParam->rates_len; + if (pstrStationParam->rates_len > 0) + memcpy(pu8CurrByte, pstrStationParam->rates, + pstrStationParam->rates_len); + pu8CurrByte += pstrStationParam->rates_len; - *pu8CurrByte++ = pstrStationParam->bIsHTSupported; - *pu8CurrByte++ = pstrStationParam->u16HTCapInfo & 0xFF; - *pu8CurrByte++ = (pstrStationParam->u16HTCapInfo >> 8) & 0xFF; + *pu8CurrByte++ = pstrStationParam->ht_supported; + *pu8CurrByte++ = pstrStationParam->ht_capa_info & 0xFF; + *pu8CurrByte++ = (pstrStationParam->ht_capa_info >> 8) & 0xFF; - *pu8CurrByte++ = pstrStationParam->u8AmpduParams; - memcpy(pu8CurrByte, pstrStationParam->au8SuppMCsSet, WILC_SUPP_MCS_SET_SIZE); + *pu8CurrByte++ = pstrStationParam->ht_ampdu_params; + memcpy(pu8CurrByte, pstrStationParam->ht_supp_mcs_set, + WILC_SUPP_MCS_SET_SIZE); pu8CurrByte += WILC_SUPP_MCS_SET_SIZE; - *pu8CurrByte++ = pstrStationParam->u16HTExtParams & 0xFF; - *pu8CurrByte++ = (pstrStationParam->u16HTExtParams >> 8) & 0xFF; + *pu8CurrByte++ = pstrStationParam->ht_ext_params & 0xFF; + *pu8CurrByte++ = (pstrStationParam->ht_ext_params >> 8) & 0xFF; - *pu8CurrByte++ = pstrStationParam->u32TxBeamformingCap & 0xFF; - *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 8) & 0xFF; - *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 16) & 0xFF; - *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 24) & 0xFF; + *pu8CurrByte++ = pstrStationParam->ht_tx_bf_cap & 0xFF; + *pu8CurrByte++ = (pstrStationParam->ht_tx_bf_cap >> 8) & 0xFF; + *pu8CurrByte++ = (pstrStationParam->ht_tx_bf_cap >> 16) & 0xFF; + *pu8CurrByte++ = (pstrStationParam->ht_tx_bf_cap >> 24) & 0xFF; - *pu8CurrByte++ = pstrStationParam->u8ASELCap; + *pu8CurrByte++ = pstrStationParam->ht_ante_sel; - *pu8CurrByte++ = pstrStationParam->u16FlagsMask & 0xFF; - *pu8CurrByte++ = (pstrStationParam->u16FlagsMask >> 8) & 0xFF; + *pu8CurrByte++ = pstrStationParam->flags_mask & 0xFF; + *pu8CurrByte++ = (pstrStationParam->flags_mask >> 8) & 0xFF; - *pu8CurrByte++ = pstrStationParam->u16FlagsSet & 0xFF; - *pu8CurrByte++ = (pstrStationParam->u16FlagsSet >> 8) & 0xFF; + *pu8CurrByte++ = pstrStationParam->flags_set & 0xFF; + *pu8CurrByte++ = (pstrStationParam->flags_set >> 8) & 0xFF; return pu8CurrByte - pu8Buffer; } -static void Handle_AddStation(struct host_if_drv *hif_drv, +static void Handle_AddStation(struct wilc_vif *vif, struct add_sta_param *pstrStationParam) { s32 result = 0; @@ -2348,7 +2378,7 @@ static void Handle_AddStation(struct host_if_drv *hif_drv, PRINT_D(HOSTINF_DBG, "Handling add station\n"); wid.id = (u16)WID_ADD_STA; wid.type = WID_BIN; - wid.size = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates; + wid.size = WILC_ADD_STA_LENGTH + pstrStationParam->rates_len; wid.val = kmalloc(wid.size, GFP_KERNEL); if (!wid.val) @@ -2357,17 +2387,17 @@ static void Handle_AddStation(struct host_if_drv *hif_drv, pu8CurrByte = wid.val; pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result != 0) PRINT_ER("Failed to send add station config packet\n"); ERRORHANDLER: - kfree(pstrStationParam->pu8Rates); + kfree(pstrStationParam->rates); kfree(wid.val); } -static void Handle_DelAllSta(struct host_if_drv *hif_drv, +static void Handle_DelAllSta(struct wilc_vif *vif, struct del_all_sta *pstrDelAllStaParam) { s32 result = 0; @@ -2399,8 +2429,8 @@ static void Handle_DelAllSta(struct host_if_drv *hif_drv, pu8CurrByte += ETH_ALEN; } - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) PRINT_ER("Failed to send add station config packet\n"); @@ -2410,7 +2440,7 @@ ERRORHANDLER: up(&hif_sema_wait_response); } -static void Handle_DelStation(struct host_if_drv *hif_drv, +static void Handle_DelStation(struct wilc_vif *vif, struct del_sta *pstrDelStaParam) { s32 result = 0; @@ -2431,8 +2461,8 @@ static void Handle_DelStation(struct host_if_drv *hif_drv, memcpy(pu8CurrByte, pstrDelStaParam->mac_addr, ETH_ALEN); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) PRINT_ER("Failed to send add station config packet\n"); @@ -2440,7 +2470,7 @@ ERRORHANDLER: kfree(wid.val); } -static void Handle_EditStation(struct host_if_drv *hif_drv, +static void Handle_EditStation(struct wilc_vif *vif, struct add_sta_param *pstrStationParam) { s32 result = 0; @@ -2449,7 +2479,7 @@ static void Handle_EditStation(struct host_if_drv *hif_drv, wid.id = (u16)WID_EDIT_STA; wid.type = WID_BIN; - wid.size = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates; + wid.size = WILC_ADD_STA_LENGTH + pstrStationParam->rates_len; PRINT_D(HOSTINF_DBG, "Handling edit station\n"); wid.val = kmalloc(wid.size, GFP_KERNEL); @@ -2459,52 +2489,54 @@ static void Handle_EditStation(struct host_if_drv *hif_drv, pu8CurrByte = wid.val; pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) PRINT_ER("Failed to send edit station config packet\n"); ERRORHANDLER: - kfree(pstrStationParam->pu8Rates); + kfree(pstrStationParam->rates); kfree(wid.val); } -static int Handle_RemainOnChan(struct host_if_drv *hif_drv, +static int Handle_RemainOnChan(struct wilc_vif *vif, struct remain_ch *pstrHostIfRemainOnChan) { s32 result = 0; u8 u8remain_on_chan_flag; struct wid wid; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv->remain_on_ch_pending) { - hif_drv->remain_on_ch.pVoid = pstrHostIfRemainOnChan->pVoid; - hif_drv->remain_on_ch.pRemainOnChanExpired = pstrHostIfRemainOnChan->pRemainOnChanExpired; - hif_drv->remain_on_ch.pRemainOnChanReady = pstrHostIfRemainOnChan->pRemainOnChanReady; - hif_drv->remain_on_ch.u16Channel = pstrHostIfRemainOnChan->u16Channel; - hif_drv->remain_on_ch.u32ListenSessionID = pstrHostIfRemainOnChan->u32ListenSessionID; + hif_drv->remain_on_ch.arg = pstrHostIfRemainOnChan->arg; + hif_drv->remain_on_ch.expired = pstrHostIfRemainOnChan->expired; + hif_drv->remain_on_ch.ready = pstrHostIfRemainOnChan->ready; + hif_drv->remain_on_ch.ch = pstrHostIfRemainOnChan->ch; + hif_drv->remain_on_ch.id = pstrHostIfRemainOnChan->id; } else { - pstrHostIfRemainOnChan->u16Channel = hif_drv->remain_on_ch.u16Channel; + pstrHostIfRemainOnChan->ch = hif_drv->remain_on_ch.ch; } - if (hif_drv->usr_scan_req.pfUserScanResult) { + if (hif_drv->usr_scan_req.scan_result) { PRINT_INFO(GENERIC_DBG, "Required to remain on chan while scanning return\n"); hif_drv->remain_on_ch_pending = 1; result = -EBUSY; goto ERRORHANDLER; } - if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) { + if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) { PRINT_INFO(GENERIC_DBG, "Required to remain on chan while connecting return\n"); result = -EBUSY; goto ERRORHANDLER; } - if (g_obtainingIP || connecting) { + if (wilc_optaining_ip || wilc_connecting) { PRINT_D(GENERIC_DBG, "[handle_scan]: Don't do obss scan until IP adresss is obtained\n"); result = -EBUSY; goto ERRORHANDLER; } - PRINT_D(HOSTINF_DBG, "Setting channel :%d\n", pstrHostIfRemainOnChan->u16Channel); + PRINT_D(HOSTINF_DBG, "Setting channel :%d\n", + pstrHostIfRemainOnChan->ch); u8remain_on_chan_flag = true; wid.id = (u16)WID_REMAIN_ON_CHAN; @@ -2517,23 +2549,23 @@ static int Handle_RemainOnChan(struct host_if_drv *hif_drv, } wid.val[0] = u8remain_on_chan_flag; - wid.val[1] = (s8)pstrHostIfRemainOnChan->u16Channel; + wid.val[1] = (s8)pstrHostIfRemainOnChan->ch; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result != 0) PRINT_ER("Failed to set remain on channel\n"); ERRORHANDLER: { P2P_LISTEN_STATE = 1; - hif_drv->hRemainOnChannel.data = (unsigned long)hif_drv; - mod_timer(&hif_drv->hRemainOnChannel, + hif_drv->remain_on_ch_timer.data = (unsigned long)vif; + mod_timer(&hif_drv->remain_on_ch_timer, jiffies + msecs_to_jiffies(pstrHostIfRemainOnChan->u32duration)); - if (hif_drv->remain_on_ch.pRemainOnChanReady) - hif_drv->remain_on_ch.pRemainOnChanReady(hif_drv->remain_on_ch.pVoid); + if (hif_drv->remain_on_ch.ready) + hif_drv->remain_on_ch.ready(hif_drv->remain_on_ch.arg); if (hif_drv->remain_on_ch_pending) hif_drv->remain_on_ch_pending = 0; @@ -2542,14 +2574,16 @@ ERRORHANDLER: return result; } -static int Handle_RegisterFrame(struct host_if_drv *hif_drv, +static int Handle_RegisterFrame(struct wilc_vif *vif, struct reg_frame *pstrHostIfRegisterFrame) { s32 result = 0; struct wid wid; u8 *pu8CurrByte; - PRINT_D(HOSTINF_DBG, "Handling frame register Flag : %d FrameType: %d\n", pstrHostIfRegisterFrame->bReg, pstrHostIfRegisterFrame->u16FrameType); + PRINT_D(HOSTINF_DBG, "Handling frame register : %d FrameType: %d\n", + pstrHostIfRegisterFrame->reg, + pstrHostIfRegisterFrame->frame_type); wid.id = (u16)WID_REGISTER_FRAME; wid.type = WID_STR; @@ -2559,15 +2593,14 @@ static int Handle_RegisterFrame(struct host_if_drv *hif_drv, pu8CurrByte = wid.val; - *pu8CurrByte++ = pstrHostIfRegisterFrame->bReg; - *pu8CurrByte++ = pstrHostIfRegisterFrame->u8Regid; - memcpy(pu8CurrByte, &pstrHostIfRegisterFrame->u16FrameType, - sizeof(u16)); + *pu8CurrByte++ = pstrHostIfRegisterFrame->reg; + *pu8CurrByte++ = pstrHostIfRegisterFrame->reg_id; + memcpy(pu8CurrByte, &pstrHostIfRegisterFrame->frame_type, sizeof(u16)); wid.size = sizeof(u16) + 2; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { PRINT_ER("Failed to frame register config packet\n"); result = -EINVAL; @@ -2576,12 +2609,13 @@ static int Handle_RegisterFrame(struct host_if_drv *hif_drv, return result; } -static u32 Handle_ListenStateExpired(struct host_if_drv *hif_drv, +static u32 Handle_ListenStateExpired(struct wilc_vif *vif, struct remain_ch *pstrHostIfRemainOnChan) { u8 u8remain_on_chan_flag; struct wid wid; s32 result = 0; + struct host_if_drv *hif_drv = vif->hif_drv; PRINT_D(HOSTINF_DBG, "CANCEL REMAIN ON CHAN\n"); @@ -2592,22 +2626,24 @@ static u32 Handle_ListenStateExpired(struct host_if_drv *hif_drv, wid.size = 2; wid.val = kmalloc(wid.size, GFP_KERNEL); - if (!wid.val) + if (!wid.val) { PRINT_ER("Failed to allocate memory\n"); + return -ENOMEM; + } wid.val[0] = u8remain_on_chan_flag; wid.val[1] = FALSE_FRMWR_CHANNEL; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result != 0) { PRINT_ER("Failed to set remain on channel\n"); goto _done_; } - if (hif_drv->remain_on_ch.pRemainOnChanExpired) { - hif_drv->remain_on_ch.pRemainOnChanExpired(hif_drv->remain_on_ch.pVoid, - pstrHostIfRemainOnChan->u32ListenSessionID); + if (hif_drv->remain_on_ch.expired) { + hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg, + pstrHostIfRemainOnChan->id); } P2P_LISTEN_STATE = 0; } else { @@ -2623,21 +2659,21 @@ static void ListenTimerCB(unsigned long arg) { s32 result = 0; struct host_if_msg msg; - struct host_if_drv *hif_drv = (struct host_if_drv *)arg; + struct wilc_vif *vif = (struct wilc_vif *)arg; - del_timer(&hif_drv->hRemainOnChannel); + del_timer(&vif->hif_drv->remain_on_ch_timer); memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED; - msg.drv = hif_drv; - msg.body.remain_on_ch.u32ListenSessionID = hif_drv->remain_on_ch.u32ListenSessionID; + msg.vif = vif; + msg.body.remain_on_ch.id = vif->hif_drv->remain_on_ch.id; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) PRINT_ER("wilc_mq_send fail\n"); } -static void Handle_PowerManagement(struct host_if_drv *hif_drv, +static void Handle_PowerManagement(struct wilc_vif *vif, struct power_mgmt_param *strPowerMgmtParam) { s32 result = 0; @@ -2656,13 +2692,13 @@ static void Handle_PowerManagement(struct host_if_drv *hif_drv, PRINT_D(HOSTINF_DBG, "Handling Power Management\n"); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) PRINT_ER("Failed to send power management config packet\n"); } -static void Handle_SetMulticastFilter(struct host_if_drv *hif_drv, +static void Handle_SetMulticastFilter(struct wilc_vif *vif, struct set_multicast *strHostIfSetMulti) { s32 result = 0; @@ -2680,9 +2716,9 @@ static void Handle_SetMulticastFilter(struct host_if_drv *hif_drv, pu8CurrByte = wid.val; *pu8CurrByte++ = (strHostIfSetMulti->enabled & 0xFF); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 8) & 0xFF); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 16) & 0xFF); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 24) & 0xFF); + *pu8CurrByte++ = 0; + *pu8CurrByte++ = 0; + *pu8CurrByte++ = 0; *pu8CurrByte++ = (strHostIfSetMulti->cnt & 0xFF); *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 8) & 0xFF); @@ -2690,10 +2726,11 @@ static void Handle_SetMulticastFilter(struct host_if_drv *hif_drv, *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 24) & 0xFF); if ((strHostIfSetMulti->cnt) > 0) - memcpy(pu8CurrByte, gau8MulticastMacAddrList, ((strHostIfSetMulti->cnt) * ETH_ALEN)); + memcpy(pu8CurrByte, wilc_multicast_mac_addr_list, + ((strHostIfSetMulti->cnt) * ETH_ALEN)); - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) PRINT_ER("Failed to send setup multicast config packet\n"); @@ -2701,71 +2738,7 @@ ERRORHANDLER: kfree(wid.val); } -static s32 Handle_AddBASession(struct host_if_drv *hif_drv, - struct ba_session_info *strHostIfBASessionInfo) -{ - s32 result = 0; - struct wid wid; - int AddbaTimeout = 100; - char *ptr = NULL; - - PRINT_D(HOSTINF_DBG, "Opening Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\nBufferSize == %d\nSessionTimeOut = %d\n", - strHostIfBASessionInfo->au8Bssid[0], - strHostIfBASessionInfo->au8Bssid[1], - strHostIfBASessionInfo->au8Bssid[2], - strHostIfBASessionInfo->u16BufferSize, - strHostIfBASessionInfo->u16SessionTimeout, - strHostIfBASessionInfo->u8Ted); - - wid.id = (u16)WID_11E_P_ACTION_REQ; - wid.type = WID_STR; - wid.val = kmalloc(BLOCK_ACK_REQ_SIZE, GFP_KERNEL); - wid.size = BLOCK_ACK_REQ_SIZE; - ptr = wid.val; - *ptr++ = 0x14; - *ptr++ = 0x3; - *ptr++ = 0x0; - memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN); - ptr += ETH_ALEN; - *ptr++ = strHostIfBASessionInfo->u8Ted; - *ptr++ = 1; - *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF); - *ptr++ = ((strHostIfBASessionInfo->u16BufferSize >> 16) & 0xFF); - *ptr++ = (strHostIfBASessionInfo->u16SessionTimeout & 0xFF); - *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF); - *ptr++ = (AddbaTimeout & 0xFF); - *ptr++ = ((AddbaTimeout >> 16) & 0xFF); - *ptr++ = 8; - *ptr++ = 0; - - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); - if (result) - PRINT_D(HOSTINF_DBG, "Couldn't open BA Session\n"); - - wid.id = (u16)WID_11E_P_ACTION_REQ; - wid.type = WID_STR; - wid.size = 15; - ptr = wid.val; - *ptr++ = 15; - *ptr++ = 7; - *ptr++ = 0x2; - memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN); - ptr += ETH_ALEN; - *ptr++ = strHostIfBASessionInfo->u8Ted; - *ptr++ = 8; - *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF); - *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF); - *ptr++ = 3; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); - - kfree(wid.val); - - return result; -} - -static s32 Handle_DelAllRxBASessions(struct host_if_drv *hif_drv, +static s32 Handle_DelAllRxBASessions(struct wilc_vif *vif, struct ba_session_info *strHostIfBASessionInfo) { s32 result = 0; @@ -2773,10 +2746,10 @@ static s32 Handle_DelAllRxBASessions(struct host_if_drv *hif_drv, char *ptr = NULL; PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\n", - strHostIfBASessionInfo->au8Bssid[0], - strHostIfBASessionInfo->au8Bssid[1], - strHostIfBASessionInfo->au8Bssid[2], - strHostIfBASessionInfo->u8Ted); + strHostIfBASessionInfo->bssid[0], + strHostIfBASessionInfo->bssid[1], + strHostIfBASessionInfo->bssid[2], + strHostIfBASessionInfo->tid); wid.id = (u16)WID_DEL_ALL_RX_BA; wid.type = WID_STR; @@ -2786,14 +2759,14 @@ static s32 Handle_DelAllRxBASessions(struct host_if_drv *hif_drv, *ptr++ = 0x14; *ptr++ = 0x3; *ptr++ = 0x2; - memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN); + memcpy(ptr, strHostIfBASessionInfo->bssid, ETH_ALEN); ptr += ETH_ALEN; - *ptr++ = strHostIfBASessionInfo->u8Ted; + *ptr++ = strHostIfBASessionInfo->tid; *ptr++ = 0; *ptr++ = 32; - result = send_config_pkt(SET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, SET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) PRINT_D(HOSTINF_DBG, "Couldn't delete BA Session\n"); @@ -2808,19 +2781,20 @@ static int hostIFthread(void *pvArg) { u32 u32Ret; struct host_if_msg msg; - struct host_if_drv *hif_drv; + struct wilc *wilc = (struct wilc*)pvArg; + struct wilc_vif *vif; memset(&msg, 0, sizeof(struct host_if_msg)); while (1) { wilc_mq_recv(&hif_msg_q, &msg, sizeof(struct host_if_msg), &u32Ret); - hif_drv = (struct host_if_drv *)msg.drv; + vif = msg.vif; if (msg.id == HOST_IF_MSG_EXIT) { PRINT_D(GENERIC_DBG, "THREAD: Exiting HostIfThread\n"); break; } - if ((!g_wilc_initialized)) { + if ((!wilc_initialized)) { PRINT_D(GENERIC_DBG, "--WAIT--"); usleep_range(200 * 1000, 200 * 1000); wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); @@ -2828,7 +2802,7 @@ static int hostIFthread(void *pvArg) } if (msg.id == HOST_IF_MSG_CONNECT && - hif_drv->usr_scan_req.pfUserScanResult) { + vif->hif_drv->usr_scan_req.scan_result) { PRINT_D(HOSTINF_DBG, "Requeue connect request till scan done received\n"); wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); usleep_range(2 * 1000, 2 * 1000); @@ -2841,167 +2815,169 @@ static int hostIFthread(void *pvArg) break; case HOST_IF_MSG_SCAN: - Handle_Scan(msg.drv, &msg.body.scan_info); + Handle_Scan(msg.vif, &msg.body.scan_info); break; case HOST_IF_MSG_CONNECT: - Handle_Connect(msg.drv, &msg.body.con_info); + Handle_Connect(msg.vif, &msg.body.con_info); break; case HOST_IF_MSG_FLUSH_CONNECT: - Handle_FlushConnect(msg.drv); + Handle_FlushConnect(msg.vif); break; case HOST_IF_MSG_RCVD_NTWRK_INFO: - Handle_RcvdNtwrkInfo(msg.drv, &msg.body.net_info); + Handle_RcvdNtwrkInfo(msg.vif, &msg.body.net_info); break; case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO: - Handle_RcvdGnrlAsyncInfo(msg.drv, &msg.body.async_info); + Handle_RcvdGnrlAsyncInfo(vif, + &msg.body.async_info); break; case HOST_IF_MSG_KEY: - Handle_Key(msg.drv, &msg.body.key_info); + Handle_Key(msg.vif, &msg.body.key_info); break; case HOST_IF_MSG_CFG_PARAMS: - - Handle_CfgParam(msg.drv, &msg.body.cfg_info); + handle_cfg_param(msg.vif, &msg.body.cfg_info); break; case HOST_IF_MSG_SET_CHANNEL: - Handle_SetChannel(msg.drv, &msg.body.channel_info); + handle_set_channel(msg.vif, &msg.body.channel_info); break; case HOST_IF_MSG_DISCONNECT: - Handle_Disconnect(msg.drv); + Handle_Disconnect(msg.vif); break; case HOST_IF_MSG_RCVD_SCAN_COMPLETE: - del_timer(&hif_drv->hScanTimer); + del_timer(&vif->hif_drv->scan_timer); PRINT_D(HOSTINF_DBG, "scan completed successfully\n"); - if (!linux_wlan_get_num_conn_ifcs()) - chip_sleep_manually(INFINITE_SLEEP_TIME); + if (!wilc_wlan_get_num_conn_ifcs(wilc)) + wilc_chip_sleep_manually(wilc); - Handle_ScanDone(msg.drv, SCAN_EVENT_DONE); + Handle_ScanDone(msg.vif, SCAN_EVENT_DONE); - if (hif_drv->remain_on_ch_pending) - Handle_RemainOnChan(msg.drv, &msg.body.remain_on_ch); + if (vif->hif_drv->remain_on_ch_pending) + Handle_RemainOnChan(msg.vif, + &msg.body.remain_on_ch); break; case HOST_IF_MSG_GET_RSSI: - Handle_GetRssi(msg.drv); + Handle_GetRssi(msg.vif); break; case HOST_IF_MSG_GET_LINKSPEED: - Handle_GetLinkspeed(msg.drv); + Handle_GetLinkspeed(msg.vif); break; case HOST_IF_MSG_GET_STATISTICS: - Handle_GetStatistics(msg.drv, (struct rf_info *)msg.body.data); + Handle_GetStatistics(msg.vif, + (struct rf_info *)msg.body.data); break; case HOST_IF_MSG_GET_CHNL: - Handle_GetChnl(msg.drv); + Handle_GetChnl(msg.vif); break; case HOST_IF_MSG_ADD_BEACON: - Handle_AddBeacon(msg.drv, &msg.body.beacon_info); + Handle_AddBeacon(msg.vif, &msg.body.beacon_info); break; case HOST_IF_MSG_DEL_BEACON: - Handle_DelBeacon(msg.drv); + Handle_DelBeacon(msg.vif); break; case HOST_IF_MSG_ADD_STATION: - Handle_AddStation(msg.drv, &msg.body.add_sta_info); + Handle_AddStation(msg.vif, &msg.body.add_sta_info); break; case HOST_IF_MSG_DEL_STATION: - Handle_DelStation(msg.drv, &msg.body.del_sta_info); + Handle_DelStation(msg.vif, &msg.body.del_sta_info); break; case HOST_IF_MSG_EDIT_STATION: - Handle_EditStation(msg.drv, &msg.body.edit_sta_info); + Handle_EditStation(msg.vif, &msg.body.edit_sta_info); break; case HOST_IF_MSG_GET_INACTIVETIME: - Handle_Get_InActiveTime(msg.drv, &msg.body.mac_info); + Handle_Get_InActiveTime(msg.vif, &msg.body.mac_info); break; case HOST_IF_MSG_SCAN_TIMER_FIRED: PRINT_D(HOSTINF_DBG, "Scan Timeout\n"); - Handle_ScanDone(msg.drv, SCAN_EVENT_ABORTED); + Handle_ScanDone(msg.vif, SCAN_EVENT_ABORTED); break; case HOST_IF_MSG_CONNECT_TIMER_FIRED: PRINT_D(HOSTINF_DBG, "Connect Timeout\n"); - Handle_ConnectTimeout(msg.drv); + Handle_ConnectTimeout(msg.vif); break; case HOST_IF_MSG_POWER_MGMT: - Handle_PowerManagement(msg.drv, &msg.body.pwr_mgmt_info); + Handle_PowerManagement(msg.vif, + &msg.body.pwr_mgmt_info); break; case HOST_IF_MSG_SET_WFIDRV_HANDLER: - Handle_SetWfiDrvHandler(msg.drv, - &msg.body.drv); + handle_set_wfi_drv_handler(msg.vif, &msg.body.drv); break; case HOST_IF_MSG_SET_OPERATION_MODE: - Handle_SetOperationMode(msg.drv, &msg.body.mode); + handle_set_operation_mode(msg.vif, &msg.body.mode); break; case HOST_IF_MSG_SET_IPADDRESS: PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n"); - Handle_set_IPAddress(msg.drv, msg.body.ip_info.ip_addr, msg.body.ip_info.idx); + handle_set_ip_address(vif, + msg.body.ip_info.ip_addr, + msg.body.ip_info.idx); break; case HOST_IF_MSG_GET_IPADDRESS: PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n"); - Handle_get_IPAddress(msg.drv, msg.body.ip_info.ip_addr, msg.body.ip_info.idx); + handle_get_ip_address(vif, msg.body.ip_info.idx); break; case HOST_IF_MSG_SET_MAC_ADDRESS: - Handle_SetMacAddress(msg.drv, &msg.body.set_mac_info); + handle_set_mac_address(msg.vif, + &msg.body.set_mac_info); break; case HOST_IF_MSG_GET_MAC_ADDRESS: - Handle_GetMacAddress(msg.drv, &msg.body.get_mac_info); + handle_get_mac_address(msg.vif, + &msg.body.get_mac_info); break; case HOST_IF_MSG_REMAIN_ON_CHAN: PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REMAIN_ON_CHAN\n"); - Handle_RemainOnChan(msg.drv, &msg.body.remain_on_ch); + Handle_RemainOnChan(msg.vif, &msg.body.remain_on_ch); break; case HOST_IF_MSG_REGISTER_FRAME: PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REGISTER_FRAME\n"); - Handle_RegisterFrame(msg.drv, &msg.body.reg_frame); + Handle_RegisterFrame(msg.vif, &msg.body.reg_frame); break; case HOST_IF_MSG_LISTEN_TIMER_FIRED: - Handle_ListenStateExpired(msg.drv, &msg.body.remain_on_ch); + Handle_ListenStateExpired(msg.vif, &msg.body.remain_on_ch); break; case HOST_IF_MSG_SET_MULTICAST_FILTER: PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_MULTICAST_FILTER\n"); - Handle_SetMulticastFilter(msg.drv, &msg.body.multicast_info); - break; - - case HOST_IF_MSG_ADD_BA_SESSION: - Handle_AddBASession(msg.drv, &msg.body.session_info); + Handle_SetMulticastFilter(msg.vif, &msg.body.multicast_info); break; case HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS: - Handle_DelAllRxBASessions(msg.drv, &msg.body.session_info); + Handle_DelAllRxBASessions(msg.vif, &msg.body.session_info); break; case HOST_IF_MSG_DEL_ALL_STA: - Handle_DelAllSta(msg.drv, &msg.body.del_all_sta_info); + Handle_DelAllSta(msg.vif, &msg.body.del_all_sta_info); break; default: @@ -3017,11 +2993,11 @@ static int hostIFthread(void *pvArg) static void TimerCB_Scan(unsigned long arg) { - void *pvArg = (void *)arg; + struct wilc_vif *vif = (struct wilc_vif *)arg; struct host_if_msg msg; memset(&msg, 0, sizeof(struct host_if_msg)); - msg.drv = pvArg; + msg.vif = vif; msg.id = HOST_IF_MSG_SCAN_TIMER_FIRED; wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); @@ -3029,17 +3005,17 @@ static void TimerCB_Scan(unsigned long arg) static void TimerCB_Connect(unsigned long arg) { - void *pvArg = (void *)arg; + struct wilc_vif *vif = (struct wilc_vif *)arg; struct host_if_msg msg; memset(&msg, 0, sizeof(struct host_if_msg)); - msg.drv = pvArg; + msg.vif = vif; msg.id = HOST_IF_MSG_CONNECT_TIMER_FIRED; wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); } -s32 host_int_remove_key(struct host_if_drv *hif_drv, const u8 *pu8StaAddress) +s32 wilc_remove_key(struct host_if_drv *hif_drv, const u8 *pu8StaAddress) { struct wid wid; @@ -3051,10 +3027,11 @@ s32 host_int_remove_key(struct host_if_drv *hif_drv, const u8 *pu8StaAddress) return 0; } -int host_int_remove_wep_key(struct host_if_drv *hif_drv, u8 index) +int wilc_remove_wep_key(struct wilc_vif *vif, u8 index) { int result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { result = -EFAULT; @@ -3067,21 +3044,22 @@ int host_int_remove_wep_key(struct host_if_drv *hif_drv, u8 index) msg.id = HOST_IF_MSG_KEY; msg.body.key_info.type = WEP; msg.body.key_info.action = REMOVEKEY; - msg.drv = hif_drv; + msg.vif = vif; msg.body.key_info.attr.wep.index = index; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) PRINT_ER("Error in sending message queue : Request to remove WEP key\n"); - down(&hif_drv->hSemTestKeyBlock); + down(&hif_drv->sem_test_key_block); return result; } -int host_int_set_wep_default_key(struct host_if_drv *hif_drv, u8 index) +int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index) { int result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { result = -EFAULT; @@ -3094,24 +3072,23 @@ int host_int_set_wep_default_key(struct host_if_drv *hif_drv, u8 index) msg.id = HOST_IF_MSG_KEY; msg.body.key_info.type = WEP; msg.body.key_info.action = DEFAULTKEY; - msg.drv = hif_drv; + msg.vif = vif; msg.body.key_info.attr.wep.index = index; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) PRINT_ER("Error in sending message queue : Default key index\n"); - down(&hif_drv->hSemTestKeyBlock); + down(&hif_drv->sem_test_key_block); return result; } -int host_int_add_wep_key_bss_sta(struct host_if_drv *hif_drv, - const u8 *key, - u8 len, - u8 index) +int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len, + u8 index) { int result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -3123,7 +3100,7 @@ int host_int_add_wep_key_bss_sta(struct host_if_drv *hif_drv, msg.id = HOST_IF_MSG_KEY; msg.body.key_info.type = WEP; msg.body.key_info.action = ADDKEY; - msg.drv = hif_drv; + msg.vif = vif; msg.body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL); if (!msg.body.key_info.attr.wep.key) return -ENOMEM; @@ -3134,20 +3111,17 @@ int host_int_add_wep_key_bss_sta(struct host_if_drv *hif_drv, result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) PRINT_ER("Error in sending message queue :WEP Key\n"); - down(&hif_drv->hSemTestKeyBlock); + down(&hif_drv->sem_test_key_block); return result; } -int host_int_add_wep_key_bss_ap(struct host_if_drv *hif_drv, - const u8 *key, - u8 len, - u8 index, - u8 mode, - enum AUTHTYPE auth_type) +int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len, + u8 index, u8 mode, enum AUTHTYPE auth_type) { int result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; int i; if (!hif_drv) { @@ -3164,7 +3138,7 @@ int host_int_add_wep_key_bss_ap(struct host_if_drv *hif_drv, msg.id = HOST_IF_MSG_KEY; msg.body.key_info.type = WEP; msg.body.key_info.action = ADDKEY_AP; - msg.drv = hif_drv; + msg.vif = vif; msg.body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL); if (!msg.body.key_info.attr.wep.key) return -ENOMEM; @@ -3178,85 +3152,86 @@ int host_int_add_wep_key_bss_ap(struct host_if_drv *hif_drv, if (result) PRINT_ER("Error in sending message queue :WEP Key\n"); - down(&hif_drv->hSemTestKeyBlock); + down(&hif_drv->sem_test_key_block); return result; } -s32 host_int_add_ptk(struct host_if_drv *hif_drv, const u8 *pu8Ptk, - u8 u8PtkKeylen, const u8 *mac_addr, - const u8 *pu8RxMic, const u8 *pu8TxMic, - u8 mode, u8 u8Ciphermode, u8 u8Idx) +int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len, + const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic, + u8 mode, u8 cipher_mode, u8 index) { - s32 result = 0; + int result = 0; struct host_if_msg msg; - u8 u8KeyLen = u8PtkKeylen; - u32 i; + struct host_if_drv *hif_drv = vif->hif_drv; + u8 key_len = ptk_key_len; + int i; if (!hif_drv) { PRINT_ER("driver is null\n"); return -EFAULT; } - if (pu8RxMic) - u8KeyLen += RX_MIC_KEY_LEN; + if (rx_mic) + key_len += RX_MIC_KEY_LEN; - if (pu8TxMic) - u8KeyLen += TX_MIC_KEY_LEN; + if (tx_mic) + key_len += TX_MIC_KEY_LEN; memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_KEY; - msg.body.key_info.type = WPAPtk; + msg.body.key_info.type = WPA_PTK; if (mode == AP_MODE) { msg.body.key_info.action = ADDKEY_AP; - msg.body.key_info.attr.wpa.index = u8Idx; + msg.body.key_info.attr.wpa.index = index; } if (mode == STATION_MODE) msg.body.key_info.action = ADDKEY; - msg.body.key_info.attr.wpa.key = kmalloc(u8PtkKeylen, GFP_KERNEL); - memcpy(msg.body.key_info.attr.wpa.key, pu8Ptk, u8PtkKeylen); + msg.body.key_info.attr.wpa.key = kmemdup(ptk, ptk_key_len, GFP_KERNEL); + if (!msg.body.key_info.attr.wpa.key) + return -ENOMEM; - if (pu8RxMic) { - memcpy(msg.body.key_info.attr.wpa.key + 16, pu8RxMic, RX_MIC_KEY_LEN); + if (rx_mic) { + memcpy(msg.body.key_info.attr.wpa.key + 16, rx_mic, RX_MIC_KEY_LEN); if (INFO) { for (i = 0; i < RX_MIC_KEY_LEN; i++) - PRINT_INFO(CFG80211_DBG, "PairwiseRx[%d] = %x\n", i, pu8RxMic[i]); + PRINT_INFO(CFG80211_DBG, "PairwiseRx[%d] = %x\n", i, rx_mic[i]); } } - if (pu8TxMic) { - memcpy(msg.body.key_info.attr.wpa.key + 24, pu8TxMic, TX_MIC_KEY_LEN); + if (tx_mic) { + memcpy(msg.body.key_info.attr.wpa.key + 24, tx_mic, TX_MIC_KEY_LEN); if (INFO) { for (i = 0; i < TX_MIC_KEY_LEN; i++) - PRINT_INFO(CFG80211_DBG, "PairwiseTx[%d] = %x\n", i, pu8TxMic[i]); + PRINT_INFO(CFG80211_DBG, "PairwiseTx[%d] = %x\n", i, tx_mic[i]); } } - msg.body.key_info.attr.wpa.key_len = u8KeyLen; + msg.body.key_info.attr.wpa.key_len = key_len; msg.body.key_info.attr.wpa.mac_addr = mac_addr; - msg.body.key_info.attr.wpa.mode = u8Ciphermode; - msg.drv = hif_drv; + msg.body.key_info.attr.wpa.mode = cipher_mode; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) PRINT_ER("Error in sending message queue: PTK Key\n"); - down(&hif_drv->hSemTestKeyBlock); + down(&hif_drv->sem_test_key_block); return result; } -s32 host_int_add_rx_gtk(struct host_if_drv *hif_drv, const u8 *pu8RxGtk, - u8 u8GtkKeylen, u8 u8KeyIdx, - u32 u32KeyRSClen, const u8 *KeyRSC, - const u8 *pu8RxMic, const u8 *pu8TxMic, - u8 mode, u8 u8Ciphermode) +int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len, + u8 index, u32 key_rsc_len, const u8 *key_rsc, + const u8 *rx_mic, const u8 *tx_mic, u8 mode, + u8 cipher_mode) { - s32 result = 0; + int result = 0; struct host_if_msg msg; - u8 u8KeyLen = u8GtkKeylen; + struct host_if_drv *hif_drv = vif->hif_drv; + u8 key_len = gtk_key_len; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -3264,56 +3239,64 @@ s32 host_int_add_rx_gtk(struct host_if_drv *hif_drv, const u8 *pu8RxGtk, } memset(&msg, 0, sizeof(struct host_if_msg)); - if (pu8RxMic) - u8KeyLen += RX_MIC_KEY_LEN; + if (rx_mic) + key_len += RX_MIC_KEY_LEN; - if (pu8TxMic) - u8KeyLen += TX_MIC_KEY_LEN; + if (tx_mic) + key_len += TX_MIC_KEY_LEN; - if (KeyRSC) { - msg.body.key_info.attr.wpa.seq = kmalloc(u32KeyRSClen, GFP_KERNEL); - memcpy(msg.body.key_info.attr.wpa.seq, KeyRSC, u32KeyRSClen); + if (key_rsc) { + msg.body.key_info.attr.wpa.seq = kmemdup(key_rsc, + key_rsc_len, + GFP_KERNEL); + if (!msg.body.key_info.attr.wpa.seq) + return -ENOMEM; } msg.id = HOST_IF_MSG_KEY; - msg.body.key_info.type = WPARxGtk; - msg.drv = hif_drv; + msg.body.key_info.type = WPA_RX_GTK; + msg.vif = vif; if (mode == AP_MODE) { msg.body.key_info.action = ADDKEY_AP; - msg.body.key_info.attr.wpa.mode = u8Ciphermode; + msg.body.key_info.attr.wpa.mode = cipher_mode; } if (mode == STATION_MODE) msg.body.key_info.action = ADDKEY; - msg.body.key_info.attr.wpa.key = kmalloc(u8KeyLen, GFP_KERNEL); - memcpy(msg.body.key_info.attr.wpa.key, pu8RxGtk, u8GtkKeylen); + msg.body.key_info.attr.wpa.key = kmemdup(rx_gtk, + key_len, + GFP_KERNEL); + if (!msg.body.key_info.attr.wpa.key) + return -ENOMEM; - if (pu8RxMic) - memcpy(msg.body.key_info.attr.wpa.key + 16, pu8RxMic, + if (rx_mic) + memcpy(msg.body.key_info.attr.wpa.key + 16, rx_mic, RX_MIC_KEY_LEN); - if (pu8TxMic) - memcpy(msg.body.key_info.attr.wpa.key + 24, pu8TxMic, + if (tx_mic) + memcpy(msg.body.key_info.attr.wpa.key + 24, tx_mic, TX_MIC_KEY_LEN); - msg.body.key_info.attr.wpa.index = u8KeyIdx; - msg.body.key_info.attr.wpa.key_len = u8KeyLen; - msg.body.key_info.attr.wpa.seq_len = u32KeyRSClen; + msg.body.key_info.attr.wpa.index = index; + msg.body.key_info.attr.wpa.key_len = key_len; + msg.body.key_info.attr.wpa.seq_len = key_rsc_len; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) PRINT_ER("Error in sending message queue: RX GTK\n"); - down(&hif_drv->hSemTestKeyBlock); + down(&hif_drv->sem_test_key_block); return result; } -s32 host_int_set_pmkid_info(struct host_if_drv *hif_drv, struct host_if_pmkid_attr *pu8PmkidInfoArray) +s32 wilc_set_pmkid_info(struct wilc_vif *vif, + struct host_if_pmkid_attr *pu8PmkidInfoArray) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; u32 i; if (!hif_drv) { @@ -3326,7 +3309,7 @@ s32 host_int_set_pmkid_info(struct host_if_drv *hif_drv, struct host_if_pmkid_at msg.id = HOST_IF_MSG_KEY; msg.body.key_info.type = PMKSA; msg.body.key_info.action = ADDKEY; - msg.drv = hif_drv; + msg.vif = vif; for (i = 0; i < pu8PmkidInfoArray->numpmkid; i++) { memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].bssid, @@ -3342,37 +3325,7 @@ s32 host_int_set_pmkid_info(struct host_if_drv *hif_drv, struct host_if_pmkid_at return result; } -s32 host_int_get_pmkid_info(struct host_if_drv *hif_drv, - u8 *pu8PmkidInfoArray, - u32 u32PmkidInfoLen) -{ - struct wid wid; - - wid.id = (u16)WID_PMKID_INFO; - wid.type = WID_STR; - wid.size = u32PmkidInfoLen; - wid.val = pu8PmkidInfoArray; - - return 0; -} - -s32 host_int_set_RSNAConfigPSKPassPhrase(struct host_if_drv *hif_drv, - u8 *pu8PassPhrase, - u8 u8Psklength) -{ - struct wid wid; - - if ((u8Psklength > 7) && (u8Psklength < 65)) { - wid.id = (u16)WID_11I_PSK; - wid.type = WID_STR; - wid.val = pu8PassPhrase; - wid.size = u8Psklength; - } - - return 0; -} - -s32 host_int_get_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress) +s32 wilc_get_mac_address(struct wilc_vif *vif, u8 *pu8MacAddress) { s32 result = 0; struct host_if_msg msg; @@ -3381,7 +3334,7 @@ s32 host_int_get_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress) msg.id = HOST_IF_MSG_GET_MAC_ADDRESS; msg.body.get_mac_info.mac_addr = pu8MacAddress; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) { @@ -3393,7 +3346,7 @@ s32 host_int_get_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress) return result; } -s32 host_int_set_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress) +s32 wilc_set_mac_address(struct wilc_vif *vif, u8 *pu8MacAddress) { s32 result = 0; struct host_if_msg msg; @@ -3403,7 +3356,7 @@ s32 host_int_set_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress) memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_SET_MAC_ADDRESS; memcpy(msg.body.set_mac_info.mac_addr, pu8MacAddress, ETH_ALEN); - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) @@ -3412,52 +3365,15 @@ s32 host_int_set_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress) return result; } -s32 host_int_get_RSNAConfigPSKPassPhrase(struct host_if_drv *hif_drv, - u8 *pu8PassPhrase, u8 u8Psklength) -{ - struct wid wid; - - wid.id = (u16)WID_11I_PSK; - wid.type = WID_STR; - wid.size = u8Psklength; - wid.val = pu8PassPhrase; - - return 0; -} - -s32 host_int_set_start_scan_req(struct host_if_drv *hif_drv, u8 scanSource) -{ - struct wid wid; - - wid.id = (u16)WID_START_SCAN_REQ; - wid.type = WID_CHAR; - wid.val = (s8 *)&scanSource; - wid.size = sizeof(char); - - return 0; -} - -s32 host_int_get_start_scan_req(struct host_if_drv *hif_drv, u8 *pu8ScanSource) -{ - struct wid wid; - - wid.id = (u16)WID_START_SCAN_REQ; - wid.type = WID_CHAR; - wid.val = (s8 *)pu8ScanSource; - wid.size = sizeof(char); - - return 0; -} - -s32 host_int_set_join_req(struct host_if_drv *hif_drv, u8 *pu8bssid, - const u8 *pu8ssid, size_t ssidLen, - const u8 *pu8IEs, size_t IEsLen, - wilc_connect_result pfConnectResult, void *pvUserArg, - u8 u8security, enum AUTHTYPE tenuAuth_type, - u8 u8channel, void *pJoinParams) +s32 wilc_set_join_req(struct wilc_vif *vif, u8 *pu8bssid, const u8 *pu8ssid, + size_t ssidLen, const u8 *pu8IEs, size_t IEsLen, + wilc_connect_result pfConnectResult, void *pvUserArg, + u8 u8security, enum AUTHTYPE tenuAuth_type, + u8 u8channel, void *pJoinParams) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv || !pfConnectResult) { PRINT_ER("Driver is null\n"); @@ -3479,7 +3395,7 @@ s32 host_int_set_join_req(struct host_if_drv *hif_drv, u8 *pu8bssid, msg.body.con_info.result = pfConnectResult; msg.body.con_info.arg = pvUserArg; msg.body.con_info.params = pJoinParams; - msg.drv = hif_drv ; + msg.vif = vif; if (pu8bssid) { msg.body.con_info.bssid = kmalloc(6, GFP_KERNEL); @@ -3497,10 +3413,11 @@ s32 host_int_set_join_req(struct host_if_drv *hif_drv, u8 *pu8bssid, msg.body.con_info.ies = kmalloc(IEsLen, GFP_KERNEL); memcpy(msg.body.con_info.ies, pu8IEs, IEsLen); } - if (hif_drv->enuHostIFstate < HOST_IF_CONNECTING) - hif_drv->enuHostIFstate = HOST_IF_CONNECTING; + if (hif_drv->hif_state < HOST_IF_CONNECTING) + hif_drv->hif_state = HOST_IF_CONNECTING; else - PRINT_D(GENERIC_DBG, "Don't set state to 'connecting' as state is %d\n", hif_drv->enuHostIFstate); + PRINT_D(GENERIC_DBG, "Don't set state to 'connecting' : %d\n", + hif_drv->hif_state); result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) { @@ -3508,17 +3425,18 @@ s32 host_int_set_join_req(struct host_if_drv *hif_drv, u8 *pu8bssid, return -EFAULT; } - hif_drv->hConnectTimer.data = (unsigned long)hif_drv; - mod_timer(&hif_drv->hConnectTimer, + hif_drv->connect_timer.data = (unsigned long)vif; + mod_timer(&hif_drv->connect_timer, jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT)); return result; } -s32 host_int_flush_join_req(struct host_if_drv *hif_drv) +s32 wilc_flush_join_req(struct wilc_vif *vif) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!join_req) return -EFAULT; @@ -3529,7 +3447,7 @@ s32 host_int_flush_join_req(struct host_if_drv *hif_drv) } msg.id = HOST_IF_MSG_FLUSH_CONNECT; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) { @@ -3540,10 +3458,11 @@ s32 host_int_flush_join_req(struct host_if_drv *hif_drv) return result; } -s32 host_int_disconnect(struct host_if_drv *hif_drv, u16 u16ReasonCode) +s32 wilc_disconnect(struct wilc_vif *vif, u16 u16ReasonCode) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("Driver is null\n"); @@ -3553,50 +3472,25 @@ s32 host_int_disconnect(struct host_if_drv *hif_drv, u16 u16ReasonCode) memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_DISCONNECT; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) PRINT_ER("Failed to send message queue: disconnect\n"); - down(&hif_drv->hSemTestDisconnectBlock); + down(&hif_drv->sem_test_disconn_block); return result; } -s32 host_int_disconnect_station(struct host_if_drv *hif_drv, u8 assoc_id) -{ - struct wid wid; - - wid.id = (u16)WID_DISCONNECT; - wid.type = WID_CHAR; - wid.val = (s8 *)&assoc_id; - wid.size = sizeof(char); - - return 0; -} - -s32 host_int_get_assoc_req_info(struct host_if_drv *hif_drv, - u8 *pu8AssocReqInfo, - u32 u32AssocReqInfoLen) -{ - struct wid wid; - - wid.id = (u16)WID_ASSOC_REQ_INFO; - wid.type = WID_STR; - wid.val = pu8AssocReqInfo; - wid.size = u32AssocReqInfoLen; - - return 0; -} - -s32 host_int_get_assoc_res_info(struct host_if_drv *hif_drv, - u8 *pu8AssocRespInfo, - u32 u32MaxAssocRespInfoLen, - u32 *pu32RcvdAssocRespInfoLen) +static s32 host_int_get_assoc_res_info(struct wilc_vif *vif, + u8 *pu8AssocRespInfo, + u32 u32MaxAssocRespInfoLen, + u32 *pu32RcvdAssocRespInfoLen) { s32 result = 0; struct wid wid; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("Driver is null\n"); @@ -3608,8 +3502,8 @@ s32 host_int_get_assoc_res_info(struct host_if_drv *hif_drv, wid.val = pu8AssocRespInfo; wid.size = u32MaxAssocRespInfoLen; - result = send_config_pkt(GET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); + result = wilc_send_config_pkt(vif->wilc, GET_CFG, &wid, 1, + wilc_get_vif_idx(vif)); if (result) { *pu32RcvdAssocRespInfoLen = 0; PRINT_ER("Failed to send association response config packet\n"); @@ -3621,24 +3515,11 @@ s32 host_int_get_assoc_res_info(struct host_if_drv *hif_drv, return result; } -s32 host_int_get_rx_power_level(struct host_if_drv *hif_drv, - u8 *pu8RxPowerLevel, - u32 u32RxPowerLevelLen) -{ - struct wid wid; - - wid.id = (u16)WID_RX_POWER_LEVEL; - wid.type = WID_STR; - wid.val = pu8RxPowerLevel; - wid.size = u32RxPowerLevelLen; - - return 0; -} - -int host_int_set_mac_chnl_num(struct host_if_drv *hif_drv, u8 channel) +int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel) { int result; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -3648,7 +3529,7 @@ int host_int_set_mac_chnl_num(struct host_if_drv *hif_drv, u8 channel) memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_SET_CHANNEL; msg.body.channel_info.set_ch = channel; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) { @@ -3659,7 +3540,7 @@ int host_int_set_mac_chnl_num(struct host_if_drv *hif_drv, u8 channel) return 0; } -int host_int_wait_msg_queue_idle(void) +int wilc_wait_msg_queue_idle(void) { int result = 0; struct host_if_msg msg; @@ -3677,15 +3558,15 @@ int host_int_wait_msg_queue_idle(void) return result; } -int host_int_set_wfi_drv_handler(struct host_if_drv *hif_drv) +int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index) { int result = 0; struct host_if_msg msg; memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_SET_WFIDRV_HANDLER; - msg.body.drv.handler = get_id_from_handler(hif_drv); - msg.drv = hif_drv; + msg.body.drv.handler = index; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) { @@ -3696,7 +3577,7 @@ int host_int_set_wfi_drv_handler(struct host_if_drv *hif_drv) return result; } -int host_int_set_operation_mode(struct host_if_drv *hif_drv, u32 mode) +int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode) { int result = 0; struct host_if_msg msg; @@ -3704,7 +3585,7 @@ int host_int_set_operation_mode(struct host_if_drv *hif_drv, u32 mode) memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_SET_OPERATION_MODE; msg.body.mode.mode = mode; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) { @@ -3715,36 +3596,12 @@ int host_int_set_operation_mode(struct host_if_drv *hif_drv, u32 mode) return result; } -s32 host_int_get_host_chnl_num(struct host_if_drv *hif_drv, u8 *pu8ChNo) -{ - s32 result = 0; - struct host_if_msg msg; - - if (!hif_drv) { - PRINT_ER("driver is null\n"); - return -EFAULT; - } - - memset(&msg, 0, sizeof(struct host_if_msg)); - - msg.id = HOST_IF_MSG_GET_CHNL; - msg.drv = hif_drv; - - result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); - if (result) - PRINT_ER("wilc mq send fail\n"); - down(&hif_drv->hSemGetCHNL); - - *pu8ChNo = ch_no; - - return result; -} - -s32 host_int_get_inactive_time(struct host_if_drv *hif_drv, - const u8 *mac, u32 *pu32InactiveTime) +s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, + u32 *pu32InactiveTime) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -3755,55 +3612,28 @@ s32 host_int_get_inactive_time(struct host_if_drv *hif_drv, memcpy(msg.body.mac_info.mac, mac, ETH_ALEN); msg.id = HOST_IF_MSG_GET_INACTIVETIME; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) PRINT_ER("Failed to send get host channel param's message queue "); - down(&hif_drv->hSemInactiveTime); + down(&hif_drv->sem_inactive_time); *pu32InactiveTime = inactive_time; return result; } -s32 host_int_test_get_int_wid(struct host_if_drv *hif_drv, u32 *pu32TestMemAddr) -{ - s32 result = 0; - struct wid wid; - - if (!hif_drv) { - PRINT_ER("driver is null\n"); - return -EFAULT; - } - - wid.id = (u16)WID_MEMORY_ADDRESS; - wid.type = WID_INT; - wid.val = (s8 *)pu32TestMemAddr; - wid.size = sizeof(u32); - - result = send_config_pkt(GET_CFG, &wid, 1, - get_id_from_handler(hif_drv)); - - if (result) { - PRINT_ER("Failed to get wid value\n"); - return -EINVAL; - } else { - PRINT_D(HOSTINF_DBG, "Successfully got wid value\n"); - } - - return result; -} - -s32 host_int_get_rssi(struct host_if_drv *hif_drv, s8 *ps8Rssi) +s32 wilc_get_rssi(struct wilc_vif *vif, s8 *ps8Rssi) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_GET_RSSI; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) { @@ -3811,7 +3641,7 @@ s32 host_int_get_rssi(struct host_if_drv *hif_drv, s8 *ps8Rssi) return -EFAULT; } - down(&hif_drv->hSemGetRSSI); + down(&hif_drv->sem_get_rssi); if (!ps8Rssi) { PRINT_ER("RSS pointer value is null"); @@ -3823,34 +3653,7 @@ s32 host_int_get_rssi(struct host_if_drv *hif_drv, s8 *ps8Rssi) return result; } -s32 host_int_get_link_speed(struct host_if_drv *hif_drv, s8 *ps8lnkspd) -{ - struct host_if_msg msg; - s32 result = 0; - - memset(&msg, 0, sizeof(struct host_if_msg)); - msg.id = HOST_IF_MSG_GET_LINKSPEED; - msg.drv = hif_drv; - - result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); - if (result) { - PRINT_ER("Failed to send GET_LINKSPEED to message queue "); - return -EFAULT; - } - - down(&hif_drv->hSemGetLINKSPEED); - - if (!ps8lnkspd) { - PRINT_ER("LINKSPEED pointer value is null"); - return -EFAULT; - } - - *ps8lnkspd = link_speed; - - return result; -} - -s32 host_int_get_statistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatistics) +s32 wilc_get_statistics(struct wilc_vif *vif, struct rf_info *pstrStatistics) { s32 result = 0; struct host_if_msg msg; @@ -3858,7 +3661,7 @@ s32 host_int_get_statistics(struct host_if_drv *hif_drv, struct rf_info *pstrSta memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_GET_STATISTICS; msg.body.data = (char *)pstrStatistics; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) { @@ -3870,14 +3673,14 @@ s32 host_int_get_statistics(struct host_if_drv *hif_drv, struct rf_info *pstrSta return result; } -s32 host_int_scan(struct host_if_drv *hif_drv, u8 u8ScanSource, - u8 u8ScanType, u8 *pu8ChnlFreqList, - u8 u8ChnlListLen, const u8 *pu8IEs, - size_t IEsLen, wilc_scan_result ScanResult, - void *pvUserArg, struct hidden_network *pstrHiddenNetwork) +s32 wilc_scan(struct wilc_vif *vif, u8 u8ScanSource, u8 u8ScanType, + u8 *pu8ChnlFreqList, u8 u8ChnlListLen, const u8 *pu8IEs, + size_t IEsLen, wilc_scan_result ScanResult, void *pvUserArg, + struct hidden_network *pstrHiddenNetwork) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv || !ScanResult) { PRINT_ER("hif_drv or ScanResult = NULL\n"); @@ -3895,7 +3698,7 @@ s32 host_int_scan(struct host_if_drv *hif_drv, u8 u8ScanSource, } else PRINT_D(HOSTINF_DBG, "pstrHiddenNetwork IS EQUAL TO NULL\n"); - msg.drv = hif_drv; + msg.vif = vif; msg.body.scan_info.src = u8ScanSource; msg.body.scan_info.type = u8ScanType; msg.body.scan_info.result = ScanResult; @@ -3916,18 +3719,19 @@ s32 host_int_scan(struct host_if_drv *hif_drv, u8 u8ScanSource, } PRINT_D(HOSTINF_DBG, ">> Starting the SCAN timer\n"); - hif_drv->hScanTimer.data = (unsigned long)hif_drv; - mod_timer(&hif_drv->hScanTimer, + hif_drv->scan_timer.data = (unsigned long)vif; + mod_timer(&hif_drv->scan_timer, jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT)); return result; } -s32 hif_set_cfg(struct host_if_drv *hif_drv, - struct cfg_param_val *pstrCfgParamVal) +s32 wilc_hif_set_cfg(struct wilc_vif *vif, + struct cfg_param_val *pstrCfgParamVal) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("hif_drv NULL\n"); @@ -3937,123 +3741,30 @@ s32 hif_set_cfg(struct host_if_drv *hif_drv, memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_CFG_PARAMS; msg.body.cfg_info.cfg_attr_info = *pstrCfgParamVal; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); return result; } -s32 hif_get_cfg(struct host_if_drv *hif_drv, u16 u16WID, u16 *pu16WID_Value) -{ - s32 result = 0; - - down(&hif_drv->gtOsCfgValuesSem); - - if (!hif_drv) { - PRINT_ER("hif_drv NULL\n"); - return -EFAULT; - } - PRINT_D(HOSTINF_DBG, "Getting configuration parameters\n"); - switch (u16WID) { - case WID_BSS_TYPE: - *pu16WID_Value = (u16)hif_drv->strCfgValues.bss_type; - break; - - case WID_AUTH_TYPE: - *pu16WID_Value = (u16)hif_drv->strCfgValues.auth_type; - break; - - case WID_AUTH_TIMEOUT: - *pu16WID_Value = hif_drv->strCfgValues.auth_timeout; - break; - - case WID_POWER_MANAGEMENT: - *pu16WID_Value = (u16)hif_drv->strCfgValues.power_mgmt_mode; - break; - - case WID_SHORT_RETRY_LIMIT: - *pu16WID_Value = hif_drv->strCfgValues.short_retry_limit; - break; - - case WID_LONG_RETRY_LIMIT: - *pu16WID_Value = hif_drv->strCfgValues.long_retry_limit; - break; - - case WID_FRAG_THRESHOLD: - *pu16WID_Value = hif_drv->strCfgValues.frag_threshold; - break; - - case WID_RTS_THRESHOLD: - *pu16WID_Value = hif_drv->strCfgValues.rts_threshold; - break; - - case WID_PREAMBLE: - *pu16WID_Value = (u16)hif_drv->strCfgValues.preamble_type; - break; - - case WID_SHORT_SLOT_ALLOWED: - *pu16WID_Value = (u16) hif_drv->strCfgValues.short_slot_allowed; - break; - - case WID_11N_TXOP_PROT_DISABLE: - *pu16WID_Value = (u16)hif_drv->strCfgValues.txop_prot_disabled; - break; - - case WID_BEACON_INTERVAL: - *pu16WID_Value = hif_drv->strCfgValues.beacon_interval; - break; - - case WID_DTIM_PERIOD: - *pu16WID_Value = (u16)hif_drv->strCfgValues.dtim_period; - break; - - case WID_SITE_SURVEY: - *pu16WID_Value = (u16)hif_drv->strCfgValues.site_survey_enabled; - break; - - case WID_SITE_SURVEY_SCAN_TIME: - *pu16WID_Value = hif_drv->strCfgValues.site_survey_scan_time; - break; - - case WID_ACTIVE_SCAN_TIME: - *pu16WID_Value = hif_drv->strCfgValues.active_scan_time; - break; - - case WID_PASSIVE_SCAN_TIME: - *pu16WID_Value = hif_drv->strCfgValues.passive_scan_time; - break; - - case WID_CURRENT_TX_RATE: - *pu16WID_Value = hif_drv->strCfgValues.curr_tx_rate; - break; - - default: - break; - } - - up(&hif_drv->gtOsCfgValuesSem); - - return result; -} - static void GetPeriodicRSSI(unsigned long arg) { - struct host_if_drv *hif_drv = (struct host_if_drv *)arg; + struct wilc_vif *vif = (struct wilc_vif *)arg; - if (!hif_drv) { + if (!vif->hif_drv) { PRINT_ER("Driver handler is NULL\n"); return; } - if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) { + if (vif->hif_drv->hif_state == HOST_IF_CONNECTED) { s32 result = 0; struct host_if_msg msg; memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_GET_RSSI; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) { @@ -4061,20 +3772,20 @@ static void GetPeriodicRSSI(unsigned long arg) return; } } - periodic_rssi.data = (unsigned long)hif_drv; + periodic_rssi.data = (unsigned long)vif; mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000)); } -s32 host_int_init(struct net_device *dev, struct host_if_drv **hif_drv_handler) +s32 wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler) { s32 result = 0; struct host_if_drv *hif_drv; - int err; - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; + int i; - nic = netdev_priv(dev); - wilc = nic->wilc; + vif = netdev_priv(dev); + wilc = vif->wilc; PRINT_D(HOSTINF_DBG, "Initializing host interface for client %d\n", clients_count + 1); @@ -4088,13 +3799,13 @@ s32 host_int_init(struct net_device *dev, struct host_if_drv **hif_drv_handler) goto _fail_; } *hif_drv_handler = hif_drv; - err = add_handler_in_list(hif_drv); - if (err) { - result = -EFAULT; - goto _fail_timer_2; - } + for (i = 0; i < wilc->vif_num; i++) + if (dev == wilc->vif[i]->ndev) { + wilc->vif[i]->hif_drv = hif_drv; + break; + } - g_obtainingIP = false; + wilc_optaining_ip = false; PRINT_D(HOSTINF_DBG, "Global handle pointer value=%p\n", hif_drv); if (clients_count == 0) { @@ -4103,12 +3814,12 @@ s32 host_int_init(struct net_device *dev, struct host_if_drv **hif_drv_handler) sema_init(&hif_sema_deinit, 1); } - sema_init(&hif_drv->hSemTestKeyBlock, 0); - sema_init(&hif_drv->hSemTestDisconnectBlock, 0); - sema_init(&hif_drv->hSemGetRSSI, 0); - sema_init(&hif_drv->hSemGetLINKSPEED, 0); - sema_init(&hif_drv->hSemGetCHNL, 0); - sema_init(&hif_drv->hSemInactiveTime, 0); + sema_init(&hif_drv->sem_test_key_block, 0); + sema_init(&hif_drv->sem_test_disconn_block, 0); + sema_init(&hif_drv->sem_get_rssi, 0); + sema_init(&hif_drv->sem_get_link_speed, 0); + sema_init(&hif_drv->sem_get_chnl, 0); + sema_init(&hif_drv->sem_inactive_time, 0); PRINT_D(HOSTINF_DBG, "INIT: CLIENT COUNT %d\n", clients_count); @@ -4129,56 +3840,50 @@ s32 host_int_init(struct net_device *dev, struct host_if_drv **hif_drv_handler) goto _fail_mq_; } setup_timer(&periodic_rssi, GetPeriodicRSSI, - (unsigned long)hif_drv); + (unsigned long)vif); mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000)); } - setup_timer(&hif_drv->hScanTimer, TimerCB_Scan, 0); - - setup_timer(&hif_drv->hConnectTimer, TimerCB_Connect, 0); + setup_timer(&hif_drv->scan_timer, TimerCB_Scan, 0); + setup_timer(&hif_drv->connect_timer, TimerCB_Connect, 0); + setup_timer(&hif_drv->remain_on_ch_timer, ListenTimerCB, 0); - setup_timer(&hif_drv->hRemainOnChannel, ListenTimerCB, 0); + sema_init(&hif_drv->sem_cfg_values, 1); + down(&hif_drv->sem_cfg_values); - sema_init(&hif_drv->gtOsCfgValuesSem, 1); - down(&hif_drv->gtOsCfgValuesSem); + hif_drv->hif_state = HOST_IF_IDLE; + hif_drv->cfg_values.site_survey_enabled = SITE_SURVEY_OFF; + hif_drv->cfg_values.scan_source = DEFAULT_SCAN; + hif_drv->cfg_values.active_scan_time = ACTIVE_SCAN_TIME; + hif_drv->cfg_values.passive_scan_time = PASSIVE_SCAN_TIME; + hif_drv->cfg_values.curr_tx_rate = AUTORATE; - hif_drv->enuHostIFstate = HOST_IF_IDLE; - hif_drv->strCfgValues.site_survey_enabled = SITE_SURVEY_OFF; - hif_drv->strCfgValues.scan_source = DEFAULT_SCAN; - hif_drv->strCfgValues.active_scan_time = ACTIVE_SCAN_TIME; - hif_drv->strCfgValues.passive_scan_time = PASSIVE_SCAN_TIME; - hif_drv->strCfgValues.curr_tx_rate = AUTORATE; - - hif_drv->u64P2p_MgmtTimeout = 0; + hif_drv->p2p_timeout = 0; PRINT_INFO(HOSTINF_DBG, "Initialization values, Site survey value: %d\n Scan source: %d\n Active scan time: %d\n Passive scan time: %d\nCurrent tx Rate = %d\n", + hif_drv->cfg_values.site_survey_enabled, + hif_drv->cfg_values.scan_source, + hif_drv->cfg_values.active_scan_time, + hif_drv->cfg_values.passive_scan_time, + hif_drv->cfg_values.curr_tx_rate); - hif_drv->strCfgValues.site_survey_enabled, hif_drv->strCfgValues.scan_source, - hif_drv->strCfgValues.active_scan_time, hif_drv->strCfgValues.passive_scan_time, - hif_drv->strCfgValues.curr_tx_rate); - - up(&hif_drv->gtOsCfgValuesSem); + up(&hif_drv->sem_cfg_values); clients_count++; return result; -_fail_timer_2: - up(&hif_drv->gtOsCfgValuesSem); - del_timer_sync(&hif_drv->hConnectTimer); - del_timer_sync(&hif_drv->hScanTimer); - kthread_stop(hif_thread_handler); _fail_mq_: wilc_mq_destroy(&hif_msg_q); _fail_: return result; } -s32 host_int_deinit(struct host_if_drv *hif_drv) +s32 wilc_deinit(struct wilc_vif *vif) { s32 result = 0; struct host_if_msg msg; - int ret; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("hif_drv = NULL\n"); @@ -4190,28 +3895,27 @@ s32 host_int_deinit(struct host_if_drv *hif_drv) terminated_handle = hif_drv; PRINT_D(HOSTINF_DBG, "De-initializing host interface for client %d\n", clients_count); - if (del_timer_sync(&hif_drv->hScanTimer)) + if (del_timer_sync(&hif_drv->scan_timer)) PRINT_D(HOSTINF_DBG, ">> Scan timer is active\n"); - if (del_timer_sync(&hif_drv->hConnectTimer)) + if (del_timer_sync(&hif_drv->connect_timer)) PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n"); if (del_timer_sync(&periodic_rssi)) PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n"); - del_timer_sync(&hif_drv->hRemainOnChannel); + del_timer_sync(&hif_drv->remain_on_ch_timer); - host_int_set_wfi_drv_handler(NULL); + wilc_set_wfi_drv_handler(vif, 0); down(&hif_sema_driver); - if (hif_drv->usr_scan_req.pfUserScanResult) { - hif_drv->usr_scan_req.pfUserScanResult(SCAN_EVENT_ABORTED, NULL, - hif_drv->usr_scan_req.u32UserScanPvoid, NULL); - - hif_drv->usr_scan_req.pfUserScanResult = NULL; + if (hif_drv->usr_scan_req.scan_result) { + hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL, + hif_drv->usr_scan_req.arg, NULL); + hif_drv->usr_scan_req.scan_result = NULL; } - hif_drv->enuHostIFstate = HOST_IF_IDLE; + hif_drv->hif_state = HOST_IF_IDLE; scan_while_connected = false; @@ -4222,7 +3926,7 @@ s32 host_int_deinit(struct host_if_drv *hif_drv) PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n"); msg.id = HOST_IF_MSG_EXIT; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result != 0) @@ -4233,12 +3937,6 @@ s32 host_int_deinit(struct host_if_drv *hif_drv) wilc_mq_destroy(&hif_msg_q); } - down(&hif_drv->gtOsCfgValuesSem); - - ret = remove_handler_in_list(hif_drv); - if (ret) - result = -ENOENT; - kfree(hif_drv); clients_count--; @@ -4247,15 +3945,20 @@ s32 host_int_deinit(struct host_if_drv *hif_drv) return result; } -void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length) +void wilc_network_info_received(struct wilc *wilc, u8 *pu8Buffer, + u32 u32Length) { s32 result = 0; struct host_if_msg msg; int id; struct host_if_drv *hif_drv = NULL; + struct wilc_vif *vif; id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24)); - hif_drv = get_handler_from_id(id); + vif = wilc_get_vif_from_idx(wilc, id); + if (!vif) + return; + hif_drv = vif->hif_drv; if (!hif_drv || hif_drv == terminated_handle) { PRINT_ER("NetworkInfo received but driver not init[%p]\n", hif_drv); @@ -4265,7 +3968,7 @@ void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length) memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_RCVD_NTWRK_INFO; - msg.drv = hif_drv; + msg.vif = vif; msg.body.net_info.len = u32Length; msg.body.net_info.buffer = kmalloc(u32Length, GFP_KERNEL); @@ -4276,17 +3979,25 @@ void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length) PRINT_ER("Error in sending network info message queue message parameters: Error(%d)\n", result); } -void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length) +void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *pu8Buffer, + u32 u32Length) { s32 result = 0; struct host_if_msg msg; int id; struct host_if_drv *hif_drv = NULL; + struct wilc_vif *vif; down(&hif_sema_deinit); id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24)); - hif_drv = get_handler_from_id(id); + vif = wilc_get_vif_from_idx(wilc, id); + if (!vif) { + up(&hif_sema_deinit); + return; + } + + hif_drv = vif->hif_drv; PRINT_D(HOSTINF_DBG, "General asynchronous info packet received\n"); if (!hif_drv || hif_drv == terminated_handle) { @@ -4295,7 +4006,7 @@ void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length) return; } - if (!hif_drv->usr_conn_req.pfUserConnectResult) { + if (!hif_drv->usr_conn_req.conn_result) { PRINT_ER("Received mac status is not needed when there is no current Connect Reques\n"); up(&hif_sema_deinit); return; @@ -4304,7 +4015,7 @@ void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length) memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO; - msg.drv = hif_drv; + msg.vif = vif; msg.body.async_info.len = u32Length; msg.body.async_info.buffer = kmalloc(u32Length, GFP_KERNEL); @@ -4317,26 +4028,31 @@ void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length) up(&hif_sema_deinit); } -void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length) +void wilc_scan_complete_received(struct wilc *wilc, u8 *pu8Buffer, + u32 u32Length) { s32 result = 0; struct host_if_msg msg; int id; struct host_if_drv *hif_drv = NULL; + struct wilc_vif *vif; id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24)); - hif_drv = get_handler_from_id(id); + vif = wilc_get_vif_from_idx(wilc, id); + if (!vif) + return; + hif_drv = vif->hif_drv; PRINT_D(GENERIC_DBG, "Scan notification received %p\n", hif_drv); if (!hif_drv || hif_drv == terminated_handle) return; - if (hif_drv->usr_scan_req.pfUserScanResult) { + if (hif_drv->usr_scan_req.scan_result) { memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_RCVD_SCAN_COMPLETE; - msg.drv = hif_drv; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) @@ -4346,14 +4062,15 @@ void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length) return; } -s32 host_int_remain_on_channel(struct host_if_drv *hif_drv, u32 u32SessionID, - u32 u32duration, u16 chan, - wilc_remain_on_chan_expired RemainOnChanExpired, - wilc_remain_on_chan_ready RemainOnChanReady, - void *pvUserArg) +s32 wilc_remain_on_channel(struct wilc_vif *vif, u32 u32SessionID, + u32 u32duration, u16 chan, + wilc_remain_on_chan_expired RemainOnChanExpired, + wilc_remain_on_chan_ready RemainOnChanReady, + void *pvUserArg) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -4363,13 +4080,13 @@ s32 host_int_remain_on_channel(struct host_if_drv *hif_drv, u32 u32SessionID, memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_REMAIN_ON_CHAN; - msg.body.remain_on_ch.u16Channel = chan; - msg.body.remain_on_ch.pRemainOnChanExpired = RemainOnChanExpired; - msg.body.remain_on_ch.pRemainOnChanReady = RemainOnChanReady; - msg.body.remain_on_ch.pVoid = pvUserArg; + msg.body.remain_on_ch.ch = chan; + msg.body.remain_on_ch.expired = RemainOnChanExpired; + msg.body.remain_on_ch.ready = RemainOnChanReady; + msg.body.remain_on_ch.arg = pvUserArg; msg.body.remain_on_ch.u32duration = u32duration; - msg.body.remain_on_ch.u32ListenSessionID = u32SessionID; - msg.drv = hif_drv; + msg.body.remain_on_ch.id = u32SessionID; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) @@ -4378,22 +4095,23 @@ s32 host_int_remain_on_channel(struct host_if_drv *hif_drv, u32 u32SessionID, return result; } -s32 host_int_ListenStateExpired(struct host_if_drv *hif_drv, u32 u32SessionID) +s32 wilc_listen_state_expired(struct wilc_vif *vif, u32 u32SessionID) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); return -EFAULT; } - del_timer(&hif_drv->hRemainOnChannel); + del_timer(&hif_drv->remain_on_ch_timer); memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED; - msg.drv = hif_drv; - msg.body.remain_on_ch.u32ListenSessionID = u32SessionID; + msg.vif = vif; + msg.body.remain_on_ch.id = u32SessionID; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) @@ -4402,10 +4120,11 @@ s32 host_int_ListenStateExpired(struct host_if_drv *hif_drv, u32 u32SessionID) return result; } -s32 host_int_frame_register(struct host_if_drv *hif_drv, u16 u16FrameType, bool bReg) +s32 wilc_frame_register(struct wilc_vif *vif, u16 u16FrameType, bool bReg) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -4418,21 +4137,21 @@ s32 host_int_frame_register(struct host_if_drv *hif_drv, u16 u16FrameType, bool switch (u16FrameType) { case ACTION: PRINT_D(HOSTINF_DBG, "ACTION\n"); - msg.body.reg_frame.u8Regid = ACTION_FRM_IDX; + msg.body.reg_frame.reg_id = ACTION_FRM_IDX; break; case PROBE_REQ: PRINT_D(HOSTINF_DBG, "PROBE REQ\n"); - msg.body.reg_frame.u8Regid = PROBE_REQ_IDX; + msg.body.reg_frame.reg_id = PROBE_REQ_IDX; break; default: PRINT_D(HOSTINF_DBG, "Not valid frame type\n"); break; } - msg.body.reg_frame.u16FrameType = u16FrameType; - msg.body.reg_frame.bReg = bReg; - msg.drv = hif_drv; + msg.body.reg_frame.frame_type = u16FrameType; + msg.body.reg_frame.reg = bReg; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) @@ -4441,13 +4160,13 @@ s32 host_int_frame_register(struct host_if_drv *hif_drv, u16 u16FrameType, bool return result; } -s32 host_int_add_beacon(struct host_if_drv *hif_drv, u32 u32Interval, - u32 u32DTIMPeriod, u32 u32HeadLen, u8 *pu8Head, - u32 u32TailLen, u8 *pu8Tail) +s32 wilc_add_beacon(struct wilc_vif *vif, u32 u32Interval, u32 u32DTIMPeriod, + u32 u32HeadLen, u8 *pu8Head, u32 u32TailLen, u8 *pu8Tail) { s32 result = 0; struct host_if_msg msg; struct beacon_attr *pstrSetBeaconParam = &msg.body.beacon_info; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -4459,7 +4178,7 @@ s32 host_int_add_beacon(struct host_if_drv *hif_drv, u32 u32Interval, PRINT_D(HOSTINF_DBG, "Setting adding beacon message queue params\n"); msg.id = HOST_IF_MSG_ADD_BEACON; - msg.drv = hif_drv; + msg.vif = vif; pstrSetBeaconParam->interval = u32Interval; pstrSetBeaconParam->dtim_period = u32DTIMPeriod; pstrSetBeaconParam->head_len = u32HeadLen; @@ -4495,10 +4214,11 @@ ERRORHANDLER: return result; } -s32 host_int_del_beacon(struct host_if_drv *hif_drv) +int wilc_del_beacon(struct wilc_vif *vif) { - s32 result = 0; + int result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -4506,7 +4226,7 @@ s32 host_int_del_beacon(struct host_if_drv *hif_drv) } msg.id = HOST_IF_MSG_DEL_BEACON; - msg.drv = hif_drv; + msg.vif = vif; PRINT_D(HOSTINF_DBG, "Setting deleting beacon message queue params\n"); result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); @@ -4516,12 +4236,12 @@ s32 host_int_del_beacon(struct host_if_drv *hif_drv) return result; } -s32 host_int_add_station(struct host_if_drv *hif_drv, - struct add_sta_param *pstrStaParams) +int wilc_add_station(struct wilc_vif *vif, struct add_sta_param *sta_param) { - s32 result = 0; + int result = 0; struct host_if_msg msg; - struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info; + struct add_sta_param *add_sta_info = &msg.body.add_sta_info; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -4533,17 +4253,15 @@ s32 host_int_add_station(struct host_if_drv *hif_drv, PRINT_D(HOSTINF_DBG, "Setting adding station message queue params\n"); msg.id = HOST_IF_MSG_ADD_STATION; - msg.drv = hif_drv; - - memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param)); - if (pstrAddStationMsg->u8NumRates > 0) { - u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL); - - if (!rates) + msg.vif = vif; + + memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param)); + if (add_sta_info->rates_len > 0) { + add_sta_info->rates = kmemdup(sta_param->rates, + add_sta_info->rates_len, + GFP_KERNEL); + if (!add_sta_info->rates) return -ENOMEM; - - memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates); - pstrAddStationMsg->pu8Rates = rates; } result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); @@ -4552,11 +4270,12 @@ s32 host_int_add_station(struct host_if_drv *hif_drv, return result; } -s32 host_int_del_station(struct host_if_drv *hif_drv, const u8 *pu8MacAddr) +int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr) { - s32 result = 0; + int result = 0; struct host_if_msg msg; - struct del_sta *pstrDelStationMsg = &msg.body.del_sta_info; + struct del_sta *del_sta_info = &msg.body.del_sta_info; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -4568,12 +4287,12 @@ s32 host_int_del_station(struct host_if_drv *hif_drv, const u8 *pu8MacAddr) PRINT_D(HOSTINF_DBG, "Setting deleting station message queue params\n"); msg.id = HOST_IF_MSG_DEL_STATION; - msg.drv = hif_drv; + msg.vif = vif; - if (!pu8MacAddr) - eth_broadcast_addr(pstrDelStationMsg->mac_addr); + if (!mac_addr) + eth_broadcast_addr(del_sta_info->mac_addr); else - memcpy(pstrDelStationMsg->mac_addr, pu8MacAddr, ETH_ALEN); + memcpy(del_sta_info->mac_addr, mac_addr, ETH_ALEN); result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) @@ -4581,12 +4300,12 @@ s32 host_int_del_station(struct host_if_drv *hif_drv, const u8 *pu8MacAddr) return result; } -s32 host_int_del_allstation(struct host_if_drv *hif_drv, - u8 pu8MacAddr[][ETH_ALEN]) +s32 wilc_del_allstation(struct wilc_vif *vif, u8 pu8MacAddr[][ETH_ALEN]) { s32 result = 0; struct host_if_msg msg; struct del_all_sta *pstrDelAllStationMsg = &msg.body.del_all_sta_info; + struct host_if_drv *hif_drv = vif->hif_drv; u8 au8Zero_Buff[ETH_ALEN] = {0}; u32 i; u8 u8AssocNumb = 0; @@ -4601,7 +4320,7 @@ s32 host_int_del_allstation(struct host_if_drv *hif_drv, PRINT_D(HOSTINF_DBG, "Setting deauthenticating station message queue params\n"); msg.id = HOST_IF_MSG_DEL_ALL_STA; - msg.drv = hif_drv; + msg.vif = vif; for (i = 0; i < MAX_NUM_STA; i++) { if (memcmp(pu8MacAddr[i], au8Zero_Buff, ETH_ALEN)) { @@ -4632,12 +4351,13 @@ s32 host_int_del_allstation(struct host_if_drv *hif_drv, return result; } -s32 host_int_edit_station(struct host_if_drv *hif_drv, - struct add_sta_param *pstrStaParams) +s32 wilc_edit_station(struct wilc_vif *vif, + struct add_sta_param *pstrStaParams) { s32 result = 0; struct host_if_msg msg; struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -4649,17 +4369,18 @@ s32 host_int_edit_station(struct host_if_drv *hif_drv, memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_EDIT_STATION; - msg.drv = hif_drv; + msg.vif = vif; memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param)); - if (pstrAddStationMsg->u8NumRates > 0) { - u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL); + if (pstrAddStationMsg->rates_len > 0) { + u8 *rates = kmalloc(pstrAddStationMsg->rates_len, GFP_KERNEL); if (!rates) return -ENOMEM; - memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates); - pstrAddStationMsg->pu8Rates = rates; + memcpy(rates, pstrStaParams->rates, + pstrAddStationMsg->rates_len); + pstrAddStationMsg->rates = rates; } result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); @@ -4669,13 +4390,12 @@ s32 host_int_edit_station(struct host_if_drv *hif_drv, return result; } -s32 host_int_set_power_mgmt(struct host_if_drv *hif_drv, - bool bIsEnabled, - u32 u32Timeout) +s32 wilc_set_power_mgmt(struct wilc_vif *vif, bool bIsEnabled, u32 u32Timeout) { s32 result = 0; struct host_if_msg msg; struct power_mgmt_param *pstrPowerMgmtParam = &msg.body.pwr_mgmt_info; + struct host_if_drv *hif_drv = vif->hif_drv; PRINT_INFO(HOSTINF_DBG, "\n\n>> Setting PS to %d <<\n\n", bIsEnabled); @@ -4689,7 +4409,7 @@ s32 host_int_set_power_mgmt(struct host_if_drv *hif_drv, memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_POWER_MGMT; - msg.drv = hif_drv; + msg.vif = vif; pstrPowerMgmtParam->enabled = bIsEnabled; pstrPowerMgmtParam->timeout = u32Timeout; @@ -4700,13 +4420,13 @@ s32 host_int_set_power_mgmt(struct host_if_drv *hif_drv, return result; } -s32 host_int_setup_multicast_filter(struct host_if_drv *hif_drv, - bool bIsEnabled, - u32 u32count) +s32 wilc_setup_multicast_filter(struct wilc_vif *vif, bool bIsEnabled, + u32 u32count) { s32 result = 0; struct host_if_msg msg; struct set_multicast *pstrMulticastFilterParam = &msg.body.multicast_info; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -4718,7 +4438,7 @@ s32 host_int_setup_multicast_filter(struct host_if_drv *hif_drv, memset(&msg, 0, sizeof(struct host_if_msg)); msg.id = HOST_IF_MSG_SET_MULTICAST_FILTER; - msg.drv = hif_drv; + msg.vif = vif; pstrMulticastFilterParam->enabled = bIsEnabled; pstrMulticastFilterParam->cnt = u32count; @@ -4886,7 +4606,7 @@ static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo) return (void *)pNewJoinBssParam; } -void host_int_freeJoinParams(void *pJoinParams) +void wilc_free_join_params(void *pJoinParams) { if ((struct bss_param *)pJoinParams) kfree((struct bss_param *)pJoinParams); @@ -4894,41 +4614,12 @@ void host_int_freeJoinParams(void *pJoinParams) PRINT_ER("Unable to FREE null pointer\n"); } -s32 host_int_delBASession(struct host_if_drv *hif_drv, char *pBSSID, char TID) -{ - s32 result = 0; - struct host_if_msg msg; - struct ba_session_info *pBASessionInfo = &msg.body.session_info; - - if (!hif_drv) { - PRINT_ER("driver is null\n"); - return -EFAULT; - } - - memset(&msg, 0, sizeof(struct host_if_msg)); - - msg.id = HOST_IF_MSG_DEL_BA_SESSION; - - memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN); - pBASessionInfo->u8Ted = TID; - msg.drv = hif_drv; - - result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); - if (result) - PRINT_ER("wilc_mq_send fail\n"); - - down(&hif_sema_wait_response); - - return result; -} - -s32 host_int_del_All_Rx_BASession(struct host_if_drv *hif_drv, - char *pBSSID, - char TID) +s32 wilc_del_all_rx_ba_session(struct wilc_vif *vif, char *pBSSID, char TID) { s32 result = 0; struct host_if_msg msg; struct ba_session_info *pBASessionInfo = &msg.body.session_info; + struct host_if_drv *hif_drv = vif->hif_drv; if (!hif_drv) { PRINT_ER("driver is null\n"); @@ -4939,9 +4630,9 @@ s32 host_int_del_All_Rx_BASession(struct host_if_drv *hif_drv, msg.id = HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS; - memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN); - pBASessionInfo->u8Ted = TID; - msg.drv = hif_drv; + memcpy(pBASessionInfo->bssid, pBSSID, ETH_ALEN); + pBASessionInfo->tid = TID; + msg.vif = vif; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); if (result) @@ -4952,10 +4643,11 @@ s32 host_int_del_All_Rx_BASession(struct host_if_drv *hif_drv, return result; } -s32 host_int_setup_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx) +s32 wilc_setup_ipaddress(struct wilc_vif *vif, u8 *u16ipadd, u8 idx) { s32 result = 0; struct host_if_msg msg; + struct host_if_drv *hif_drv = vif->hif_drv; return 0; @@ -4969,7 +4661,7 @@ s32 host_int_setup_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx) msg.id = HOST_IF_MSG_SET_IPADDRESS; msg.body.ip_info.ip_addr = u16ipadd; - msg.drv = hif_drv; + msg.vif = vif; msg.body.ip_info.idx = idx; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); @@ -4979,7 +4671,9 @@ s32 host_int_setup_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx) return result; } -s32 host_int_get_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx) +static s32 host_int_get_ipaddress(struct wilc_vif *vif, + struct host_if_drv *hif_drv, + u8 *u16ipadd, u8 idx) { s32 result = 0; struct host_if_msg msg; @@ -4994,7 +4688,7 @@ s32 host_int_get_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx) msg.id = HOST_IF_MSG_GET_IPADDRESS; msg.body.ip_info.ip_addr = u16ipadd; - msg.drv = hif_drv; + msg.vif = vif; msg.body.ip_info.idx = idx; result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg)); diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h index b854db5ac932..8faac27002e9 100644 --- a/drivers/staging/wilc1000/host_interface.h +++ b/drivers/staging/wilc1000/host_interface.h @@ -1,12 +1,3 @@ -/*! - * @file host_interface.h - * @brief File containg host interface APIs - * @author zsalah - * @sa host_interface.c - * @date 8 March 2012 - * @version 1.0 - */ - #ifndef HOST_INT_H #define HOST_INT_H @@ -19,8 +10,12 @@ #define STATION_MODE 0x02 #define GO_MODE 0x03 #define CLIENT_MODE 0x04 +#define ACTION 0xD0 +#define PROBE_REQ 0x40 +#define PROBE_RESP 0x50 - +#define ACTION_FRM_IDX 0 +#define PROBE_REQ_IDX 1 #define MAX_NUM_STA 9 #define ACTIVE_SCAN_TIME 10 #define PASSIVE_SCAN_TIME 1200 @@ -58,11 +53,11 @@ #define NUM_CONCURRENT_IFC 2 struct rf_info { - u8 u8LinkSpeed; - s8 s8RSSI; - u32 u32TxCount; - u32 u32RxCount; - u32 u32TxFailureCount; + u8 link_speed; + s8 rssi; + u32 tx_cnt; + u32 rx_cnt; + u32 tx_fail_cnt; }; enum host_if_state { @@ -168,36 +163,23 @@ enum conn_event { enum KEY_TYPE { WEP, - WPARxGtk, - WPAPtk, + WPA_RX_GTK, + WPA_PTK, PMKSA, }; - -/*Scan callBack function definition*/ typedef void (*wilc_scan_result)(enum scan_event, tstrNetworkInfo *, void *, void *); -/*Connect callBack function definition*/ typedef void (*wilc_connect_result)(enum conn_event, tstrConnectInfo *, u8, tstrDisconnectNotifInfo *, void *); -typedef void (*wilc_remain_on_chan_expired)(void *, u32); /*Remain on channel expiration callback function*/ -typedef void (*wilc_remain_on_chan_ready)(void *); /*Remain on channel callback function*/ +typedef void (*wilc_remain_on_chan_expired)(void *, u32); +typedef void (*wilc_remain_on_chan_ready)(void *); -/*! - * @struct rcvd_net_info - * @brief Structure to hold Received Asynchronous Network info - * @details - * @todo - * @sa - * @author Mostafa Abu Bakr - * @date 25 March 2012 - * @version 1.0 - */ struct rcvd_net_info { u8 *buffer; u32 len; @@ -214,29 +196,23 @@ struct hidden_network { }; struct user_scan_req { - /* Scan user call back function */ - wilc_scan_result pfUserScanResult; - - /* User specific parameter to be delivered through the Scan User Callback function */ - void *u32UserScanPvoid; - - u32 u32RcvdChCount; - struct found_net_info astrFoundNetworkInfo[MAX_NUM_SCANNED_NETWORKS]; + wilc_scan_result scan_result; + void *arg; + u32 rcvd_ch_cnt; + struct found_net_info net_info[MAX_NUM_SCANNED_NETWORKS]; }; struct user_conn_req { u8 *pu8bssid; u8 *pu8ssid; u8 u8security; - enum AUTHTYPE tenuAuth_type; - size_t ssidLen; - u8 *pu8ConnReqIEs; - size_t ConnReqIEsLen; - /* Connect user call back function */ - wilc_connect_result pfUserConnectResult; - bool IsHTCapable; - /* User specific parameter to be delivered through the Connect User Callback function */ - void *u32UserConnectPvoid; + enum AUTHTYPE auth_type; + size_t ssid_len; + u8 *ies; + size_t ies_len; + wilc_connect_result conn_result; + bool ht_capable; + void *arg; }; struct drv_handler { @@ -256,875 +232,155 @@ struct get_mac_addr { }; struct ba_session_info { - u8 au8Bssid[ETH_ALEN]; - u8 u8Ted; - u16 u16BufferSize; - u16 u16SessionTimeout; + u8 bssid[ETH_ALEN]; + u8 tid; + u16 buf_size; + u16 time_out; }; struct remain_ch { - u16 u16Channel; + u16 ch; u32 u32duration; - wilc_remain_on_chan_expired pRemainOnChanExpired; - wilc_remain_on_chan_ready pRemainOnChanReady; - void *pVoid; - u32 u32ListenSessionID; + wilc_remain_on_chan_expired expired; + wilc_remain_on_chan_ready ready; + void *arg; + u32 id; }; struct reg_frame { - bool bReg; - u16 u16FrameType; - u8 u8Regid; + bool reg; + u16 frame_type; + u8 reg_id; }; - -#define ACTION 0xD0 -#define PROBE_REQ 0x40 -#define PROBE_RESP 0x50 -#define ACTION_FRM_IDX 0 -#define PROBE_REQ_IDX 1 - - enum p2p_listen_state { P2P_IDLE, P2P_LISTEN, P2P_GRP_FORMATION }; +struct wilc; struct host_if_drv { struct user_scan_req usr_scan_req; struct user_conn_req usr_conn_req; struct remain_ch remain_on_ch; u8 remain_on_ch_pending; - u64 u64P2p_MgmtTimeout; - u8 u8P2PConnect; + u64 p2p_timeout; + u8 p2p_connect; + + enum host_if_state hif_state; - enum host_if_state enuHostIFstate; + u8 assoc_bssid[ETH_ALEN]; + struct cfg_param_val cfg_values; - u8 au8AssociatedBSSID[ETH_ALEN]; - struct cfg_param_val strCfgValues; -/* semaphores */ - struct semaphore gtOsCfgValuesSem; - struct semaphore hSemTestKeyBlock; + struct semaphore sem_cfg_values; + struct semaphore sem_test_key_block; + struct semaphore sem_test_disconn_block; + struct semaphore sem_get_rssi; + struct semaphore sem_get_link_speed; + struct semaphore sem_get_chnl; + struct semaphore sem_inactive_time; - struct semaphore hSemTestDisconnectBlock; - struct semaphore hSemGetRSSI; - struct semaphore hSemGetLINKSPEED; - struct semaphore hSemGetCHNL; - struct semaphore hSemInactiveTime; -/* timer handlers */ - struct timer_list hScanTimer; - struct timer_list hConnectTimer; - struct timer_list hRemainOnChannel; + struct timer_list scan_timer; + struct timer_list connect_timer; + struct timer_list remain_on_ch_timer; bool IFC_UP; }; struct add_sta_param { - u8 au8BSSID[ETH_ALEN]; - u16 u16AssocID; - u8 u8NumRates; - const u8 *pu8Rates; - bool bIsHTSupported; - u16 u16HTCapInfo; - u8 u8AmpduParams; - u8 au8SuppMCsSet[16]; - u16 u16HTExtParams; - u32 u32TxBeamformingCap; - u8 u8ASELCap; - u16 u16FlagsMask; /*<! Determines which of u16FlagsSet were changed>*/ - u16 u16FlagsSet; /*<! Decoded according to tenuWILC_StaFlag */ + u8 bssid[ETH_ALEN]; + u16 aid; + u8 rates_len; + const u8 *rates; + bool ht_supported; + u16 ht_capa_info; + u8 ht_ampdu_params; + u8 ht_supp_mcs_set[16]; + u16 ht_ext_params; + u32 ht_tx_bf_cap; + u8 ht_ante_sel; + u16 flags_mask; + u16 flags_set; }; -/*****************************************************************************/ -/* */ -/* Host Interface API */ -/* */ -/*****************************************************************************/ - -/** - * @brief removes wpa/wpa2 keys - * @details only in BSS STA mode if External Supplicant support is enabled. - * removes all WPA/WPA2 station key entries from MAC hardware. - * @param[in,out] handle to the wifi driver - * @param[in] 6 bytes of Station Adress in the station entry table - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_remove_key(struct host_if_drv *hWFIDrv, const u8 *pu8StaAddress); -/** - * @brief removes WEP key - * @details valid only in BSS STA mode if External Supplicant support is enabled. - * remove a WEP key entry from MAC HW. - * The BSS Station automatically finds the index of the entry using its - * BSS ID and removes that entry from the MAC hardware. - * @param[in,out] handle to the wifi driver - * @param[in] 6 bytes of Station Adress in the station entry table - * @return Error code indicating success/failure - * @note NO need for the STA add since it is not used for processing - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -int host_int_remove_wep_key(struct host_if_drv *wfi_drv, u8 index); -/** - * @brief sets WEP deafault key - * @details Sets the index of the WEP encryption key in use, - * in the key table - * @param[in,out] handle to the wifi driver - * @param[in] key index ( 0, 1, 2, 3) - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -int host_int_set_wep_default_key(struct host_if_drv *hif_drv, u8 index); - -/** - * @brief sets WEP deafault key - * @details valid only in BSS STA mode if External Supplicant support is enabled. - * sets WEP key entry into MAC hardware when it receives the - * corresponding request from NDIS. - * @param[in,out] handle to the wifi driver - * @param[in] message containing WEP Key in the following format - *|---------------------------------------| - *|Key ID Value | Key Length | Key | - *|-------------|------------|------------| - | 1byte | 1byte | Key Length | - ||---------------------------------------| - | - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -int host_int_add_wep_key_bss_sta(struct host_if_drv *hif_drv, - const u8 *key, u8 len, u8 index); -/** - * @brief host_int_add_wep_key_bss_ap - * @details valid only in AP mode if External Supplicant support is enabled. - * sets WEP key entry into MAC hardware when it receives the - * corresponding request from NDIS. - * @param[in,out] handle to the wifi driver - * - * - * @return Error code indicating success/failure - * @note - * @author mdaftedar - * @date 28 Feb 2013 - * @version 1.0 - */ -int host_int_add_wep_key_bss_ap(struct host_if_drv *hif_drv, - const u8 *key, u8 len, u8 index, u8 mode, - enum AUTHTYPE auth_type); - -/** - * @brief adds ptk Key - * @details - * @param[in,out] handle to the wifi driver - * @param[in] message containing PTK Key in the following format - *|-------------------------------------------------------------------------| - *|Sta Adress | Key Length | Temporal Key | Rx Michael Key |Tx Michael Key | - *|-----------|------------|---------------|----------------|---------------| - | 6 bytes | 1byte | 16 bytes | 8 bytes | 8 bytes | - ||-------------------------------------------------------------------------| - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_add_ptk(struct host_if_drv *hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen, - const u8 *mac_addr, const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode, u8 u8Idx); - -/** - * @brief host_int_get_inactive_time - * @details - * @param[in,out] handle to the wifi driver - * @param[in] message containing inactive time - * - * @return Error code indicating success/failure - * @note - * @author mdaftedar - * @date 15 April 2013 - * @version 1.0 - */ -s32 host_int_get_inactive_time(struct host_if_drv *hWFIDrv, const u8 *mac, u32 *pu32InactiveTime); - -/** - * @brief adds Rx GTk Key - * @details - * @param[in,out] handle to the wifi driver - * @param[in] message containing Rx GTK Key in the following format - *|----------------------------------------------------------------------------| - *|Sta Address | Key RSC | KeyID | Key Length | Temporal Key | Rx Michael Key | - *|------------|---------|-------|------------|---------------|----------------| - | 6 bytes | 8 byte |1 byte | 1 byte | 16 bytes | 8 bytes | - ||----------------------------------------------------------------------------| - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_add_rx_gtk(struct host_if_drv *hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkKeylen, - u8 u8KeyIdx, u32 u32KeyRSClen, const u8 *KeyRSC, - const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode); - - -/** - * @brief adds Tx GTk Key - * @details - * @param[in,out] handle to the wifi driver - * @param[in] message containing Tx GTK Key in the following format - *|----------------------------------------------------| - | KeyID | Key Length | Temporal Key | Tx Michael Key | - ||-------|------------|--------------|----------------| - ||1 byte | 1 byte | 16 bytes | 8 bytes | - ||----------------------------------------------------| - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_add_tx_gtk(struct host_if_drv *hWFIDrv, u8 u8KeyLen, u8 *pu8TxGtk, u8 u8KeyIdx); - -/** - * @brief caches the pmkid - * @details valid only in BSS STA mode if External Supplicant - * support is enabled. This Function sets the PMKID in firmware - * when host drivr receives the corresponding request from NDIS. - * The firmware then includes theset PMKID in the appropriate - * management frames - * @param[in,out] handle to the wifi driver - * @param[in] message containing PMKID Info in the following format - *|-----------------------------------------------------------------| - *|NumEntries | BSSID[1] | PMKID[1] | ... | BSSID[K] | PMKID[K] | - *|-----------|------------|----------|-------|----------|----------| - | 1 | 6 | 16 | ... | 6 | 16 | - ||-----------------------------------------------------------------| - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ - -s32 host_int_set_pmkid_info(struct host_if_drv *hWFIDrv, struct host_if_pmkid_attr *pu8PmkidInfoArray); -/** - * @brief gets the cached the pmkid info - * @details valid only in BSS STA mode if External Supplicant - * support is enabled. This Function sets the PMKID in firmware - * when host drivr receives the corresponding request from NDIS. - * The firmware then includes theset PMKID in the appropriate - * management frames - * @param[in,out] handle to the wifi driver, - * - * message containing PMKID Info in the following format - *|-----------------------------------------------------------------| - *|NumEntries | BSSID[1] | PMKID[1] | ... | BSSID[K] | PMKID[K] | - *|-----------|------------|----------|-------|----------|----------| - | 1 | 6 | 16 | ... | 6 | 16 | - ||-----------------------------------------------------------------| - * @param[in] - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ - -s32 host_int_get_pmkid_info(struct host_if_drv *hWFIDrv, u8 *pu8PmkidInfoArray, - u32 u32PmkidInfoLen); - -/** - * @brief sets the pass phrase - * @details AP/STA mode. This function gives the pass phrase used to - * generate the Pre-Shared Key when WPA/WPA2 is enabled - * The length of the field can vary from 8 to 64 bytes, - * the lower layer should get the - * @param[in,out] handle to the wifi driver, - * @param[in] String containing PSK - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_set_RSNAConfigPSKPassPhrase(struct host_if_drv *hWFIDrv, u8 *pu8PassPhrase, - u8 u8Psklength); -/** - * @brief gets the pass phrase - * @details AP/STA mode. This function gets the pass phrase used to - * generate the Pre-Shared Key when WPA/WPA2 is enabled - * The length of the field can vary from 8 to 64 bytes, - * the lower layer should get the - * @param[in,out] handle to the wifi driver, - * String containing PSK - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_get_RSNAConfigPSKPassPhrase(struct host_if_drv *hWFIDrv, - u8 *pu8PassPhrase, u8 u8Psklength); - -/** - * @brief gets mac address - * @details - * @param[in,out] handle to the wifi driver, - * - * @return Error code indicating success/failure - * @note - * @author mdaftedar - * @date 19 April 2012 - * @version 1.0 - */ -s32 host_int_get_MacAddress(struct host_if_drv *hWFIDrv, u8 *pu8MacAddress); - -/** - * @brief sets mac address - * @details - * @param[in,out] handle to the wifi driver, - * - * @return Error code indicating success/failure - * @note - * @author mabubakr - * @date 16 July 2012 - * @version 1.0 - */ -s32 host_int_set_MacAddress(struct host_if_drv *hWFIDrv, u8 *pu8MacAddress); - -/** - * @brief wait until msg q is empty - * @details - * @param[in,out] - * - * @return Error code indicating success/failure - * @note - * @author asobhy - * @date 19 march 2014 - * @version 1.0 - */ -int host_int_wait_msg_queue_idle(void); - -/** - * @brief sets a start scan request - * @details - * @param[in,out] handle to the wifi driver, - * @param[in] Scan Source one of the following values - * DEFAULT_SCAN 0 - * USER_SCAN BIT0 - * OBSS_PERIODIC_SCAN BIT1 - * OBSS_ONETIME_SCAN BIT2 - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ - -s32 host_int_set_start_scan_req(struct host_if_drv *hWFIDrv, u8 scanSource); -/** - * @brief gets scan source of the last scan - * @details - * @param[in,out] handle to the wifi driver, - * Scan Source one of the following values - * DEFAULT_SCAN 0 - * USER_SCAN BIT0 - * OBSS_PERIODIC_SCAN BIT1 - * OBSS_ONETIME_SCAN BIT2 - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_get_start_scan_req(struct host_if_drv *hWFIDrv, u8 *pu8ScanSource); - -/** - * @brief sets a join request - * @details - * @param[in,out] handle to the wifi driver, - * @param[in] Index of the bss descriptor - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ - -s32 host_int_set_join_req(struct host_if_drv *hWFIDrv, u8 *pu8bssid, - const u8 *pu8ssid, size_t ssidLen, - const u8 *pu8IEs, size_t IEsLen, - wilc_connect_result pfConnectResult, void *pvUserArg, - u8 u8security, enum AUTHTYPE tenuAuth_type, - u8 u8channel, - void *pJoinParams); - -/** - * @brief Flush a join request parameters to FW, but actual connection - * @details The function is called in situation where WILC is connected to AP and - * required to switch to hybrid FW for P2P connection - * @param[in] handle to the wifi driver, - * @return Error code indicating success/failure - * @note - * @author Amr Abdel-Moghny - * @date 19 DEC 2013 - * @version 8.0 - */ - -s32 host_int_flush_join_req(struct host_if_drv *hWFIDrv); - - -/** - * @brief disconnects from the currently associated network - * @details - * @param[in,out] handle to the wifi driver, - * @param[in] Reason Code of the Disconnection - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_disconnect(struct host_if_drv *hWFIDrv, u16 u16ReasonCode); - -/** - * @brief disconnects a sta - * @details - * @param[in,out] handle to the wifi driver, - * @param[in] Association Id of the station to be disconnected - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_disconnect_station(struct host_if_drv *hWFIDrv, u8 assoc_id); -/** - * @brief gets a Association request info - * @details - * @param[in,out] handle to the wifi driver, - * Message containg assoc. req info in the following format - * ------------------------------------------------------------------------ - | Management Frame Format | - ||-------------------------------------------------------------------| - ||Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS | - ||-------------|--------|--|--|-----|----------------|----------|----| - | 2 |2 |6 |6 |6 | 2 |0 - 2312 | 4 | - ||-------------------------------------------------------------------| - | | - | Association Request Frame - Frame Body | - ||-------------------------------------------------------------------| - | Capability Information | Listen Interval | SSID | Supported Rates | - ||------------------------|-----------------|------|-----------------| - | 2 | 2 | 2-34 | 3-10 | - | --------------------------------------------------------------------- - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ - -s32 host_int_get_assoc_req_info(struct host_if_drv *hWFIDrv, u8 *pu8AssocReqInfo, - u32 u32AssocReqInfoLen); -/** - * @brief gets a Association Response info - * @details - * @param[in,out] handle to the wifi driver, - * Message containg assoc. resp info - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ - -s32 host_int_get_assoc_res_info(struct host_if_drv *hWFIDrv, u8 *pu8AssocRespInfo, - u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen); -/** - * @brief gets a Association Response info - * @details Valid only in STA mode. This function gives the RSSI - * values observed in all the channels at the time of scanning. - * The length of the field is 1 greater that the total number of - * channels supported. Byte 0 contains the number of channels while - * each of Byte N contains the observed RSSI value for the channel index N. - * @param[in,out] handle to the wifi driver, - * array of scanned channels' RSSI - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_get_rx_power_level(struct host_if_drv *hWFIDrv, u8 *pu8RxPowerLevel, - u32 u32RxPowerLevelLen); - -/** - * @brief sets a channel - * @details - * @param[in,out] handle to the wifi driver, - * @param[in] Index of the channel to be set - *|-------------------------------------------------------------------| - | CHANNEL1 CHANNEL2 .... CHANNEL14 | - | Input: 1 2 14 | - ||-------------------------------------------------------------------| - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -int host_int_set_mac_chnl_num(struct host_if_drv *wfi_drv, u8 channel); - -/** - * @brief gets the current channel index - * @details - * @param[in,out] handle to the wifi driver, - * current channel index - *|-----------------------------------------------------------------------| - | CHANNEL1 CHANNEL2 .... CHANNEL14 | - | Input: 1 2 14 | - ||-----------------------------------------------------------------------| - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_get_host_chnl_num(struct host_if_drv *hWFIDrv, u8 *pu8ChNo); -/** - * @brief gets the sta rssi - * @details gets the currently maintained RSSI value for the station. - * The received signal strength value in dB. - * The range of valid values is -128 to 0. - * @param[in,out] handle to the wifi driver, - * rssi value in dB - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_get_rssi(struct host_if_drv *hWFIDrv, s8 *ps8Rssi); -s32 host_int_get_link_speed(struct host_if_drv *hWFIDrv, s8 *ps8lnkspd); -/** - * @brief scans a set of channels - * @details - * @param[in,out] handle to the wifi driver, - * @param[in] Scan source - * Scan Type PASSIVE_SCAN = 0, - * ACTIVE_SCAN = 1 - * Channels Array - * Channels Array length - * Scan Callback function - * User Argument to be delivered back through the Scan Cllback function - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_scan(struct host_if_drv *hWFIDrv, u8 u8ScanSource, - u8 u8ScanType, u8 *pu8ChnlFreqList, - u8 u8ChnlListLen, const u8 *pu8IEs, - size_t IEsLen, wilc_scan_result ScanResult, - void *pvUserArg, - struct hidden_network *pstrHiddenNetwork); -/** - * @brief sets configuration wids values - * @details - * @param[in,out] handle to the wifi driver, - * @param[in] WID, WID value - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 hif_set_cfg(struct host_if_drv *hWFIDrv, struct cfg_param_val *pstrCfgParamVal); - -/** - * @brief gets configuration wids values - * @details - * @param[in,out] handle to the wifi driver, - * WID value - * @param[in] WID, - * @return Error code indicating success/failure - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 hif_get_cfg(struct host_if_drv *hWFIDrv, u16 u16WID, u16 *pu16WID_Value); -/*****************************************************************************/ -/* Notification Functions */ -/*****************************************************************************/ -/** - * @brief host interface initialization function - * @details - * @param[in,out] handle to the wifi driver, - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_init(struct net_device *dev, struct host_if_drv **phWFIDrv); - -/** - * @brief host interface initialization function - * @details - * @param[in,out] handle to the wifi driver, - * @note - * @author zsalah - * @date 8 March 2012 - * @version 1.0 - */ -s32 host_int_deinit(struct host_if_drv *hWFIDrv); - - -/*! - * @fn s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv,u8 u8Index) - * @brief Sends a beacon to the firmware to be transmitted over the air - * @details - * @param[in,out] hWFIDrv handle to the wifi driver - * @param[in] u32Interval Beacon Interval. Period between two successive beacons on air - * @param[in] u32DTIMPeriod DTIM Period. Indicates how many Beacon frames - * (including the current frame) appear before the next DTIM - * @param[in] u32Headlen Length of the head buffer in bytes - * @param[in] pu8Head Pointer to the beacon's head buffer. Beacon's head - * is the part from the beacon's start till the TIM element, NOT including the TIM - * @param[in] u32Taillen Length of the tail buffer in bytes - * @param[in] pu8Tail Pointer to the beacon's tail buffer. Beacon's tail - * starts just after the TIM inormation element - * @return 0 for Success, error otherwise - * @todo - * @sa - * @author Adham Abozaeid - * @date 10 Julys 2012 - * @version 1.0 Description - * - */ -s32 host_int_add_beacon(struct host_if_drv *hWFIDrv, u32 u32Interval, - u32 u32DTIMPeriod, - u32 u32HeadLen, u8 *pu8Head, - u32 u32TailLen, u8 *pu8tail); - - -/*! - * @fn s32 host_int_del_beacon(WILC_WFIDrvHandle hWFIDrv) - * @brief Removes the beacon and stops trawilctting it over the air - * @details - * @param[in,out] hWFIDrv handle to the wifi driver - * @return 0 for Success, error otherwise - * @todo - * @sa - * @author Adham Abozaeid - * @date 10 Julys 2012 - * @version 1.0 Description - */ -s32 host_int_del_beacon(struct host_if_drv *hWFIDrv); - -/*! - * @fn s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv, - * struct add_sta_param *pstrStaParams) - * @brief Notifies the firmware with a new associated stations - * @details - * @param[in,out] hWFIDrv handle to the wifi driver - * @param[in] pstrStaParams Station's parameters - * @return 0 for Success, error otherwise - * @todo - * @sa - * @author Adham Abozaeid - * @date 12 July 2012 - * @version 1.0 Description - */ -s32 host_int_add_station(struct host_if_drv *hWFIDrv, - struct add_sta_param *pstrStaParams); - -/*! - * @fn s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, const u8* pu8MacAddr) - * @brief Deauthenticates clients when group is terminating - * @details - * @param[in,out] hWFIDrv handle to the wifi driver - * @param[in] pu8MacAddr Station's mac address - * @return 0 for Success, error otherwise - * @todo - * @sa - * @author Mai Daftedar - * @date 09 April 2014 - * @version 1.0 Description - */ -s32 host_int_del_allstation(struct host_if_drv *hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]); - -/*! - * @fn s32 host_int_del_station(WILC_WFIDrvHandle hWFIDrv, u8* pu8MacAddr) - * @brief Notifies the firmware with a new deleted station - * @details - * @param[in,out] hWFIDrv handle to the wifi driver - * @param[in] pu8MacAddr Station's mac address - * @return 0 for Success, error otherwise - * @todo - * @sa - * @author Adham Abozaeid - * @date 15 July 2012 - * @version 1.0 Description - */ -s32 host_int_del_station(struct host_if_drv *hWFIDrv, const u8 *pu8MacAddr); - -/*! - * @fn s32 host_int_edit_station(WILC_WFIDrvHandle hWFIDrv, - * struct add_sta_param *pstrStaParams) - * @brief Notifies the firmware with new parameters of an already associated station - * @details - * @param[in,out] hWFIDrv handle to the wifi driver - * @param[in] pstrStaParams Station's parameters - * @return 0 for Success, error otherwise - * @todo - * @sa - * @author Adham Abozaeid - * @date 15 July 2012 - * @version 1.0 Description - */ -s32 host_int_edit_station(struct host_if_drv *hWFIDrv, - struct add_sta_param *pstrStaParams); - -/*! - * @fn s32 host_int_set_power_mgmt(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32Timeout) - * @brief Set the power management mode to enabled or disabled - * @details - * @param[in,out] hWFIDrv handle to the wifi driver - * @param[in] bIsEnabled TRUE if enabled, FALSE otherwise - * @param[in] u32Timeout A timeout value of -1 allows the driver to adjust - * the dynamic ps timeout value - * @return 0 for Success, error otherwise - * @todo - * @sa - * @author Adham Abozaeid - * @date 24 November 2012 - * @version 1.0 Description - */ -s32 host_int_set_power_mgmt(struct host_if_drv *hWFIDrv, bool bIsEnabled, u32 u32Timeout); -/* @param[in,out] hWFIDrv handle to the wifi driver - * @param[in] bIsEnabled TRUE if enabled, FALSE otherwise - * @param[in] u8count count of mac address entries in the filter table - * - * @return 0 for Success, error otherwise - * @todo - * @sa - * @author Adham Abozaeid - * @date 24 November 2012 - * @version 1.0 Description - */ -s32 host_int_setup_multicast_filter(struct host_if_drv *hWFIDrv, bool bIsEnabled, u32 u32count); -/** - * @brief host_int_setup_ipaddress - * @details set IP address on firmware - * @param[in] - * @return Error code. - * @author Abdelrahman Sobhy - * @date - * @version 1.0 - */ -s32 host_int_setup_ipaddress(struct host_if_drv *hWFIDrv, u8 *pu8IPAddr, u8 idx); - - -/** - * @brief host_int_delBASession - * @details Delete single Rx BA session - * @param[in] - * @return Error code. - * @author Abdelrahman Sobhy - * @date - * @version 1.0 - */ -s32 host_int_delBASession(struct host_if_drv *hWFIDrv, char *pBSSID, char TID); - -/** - * @brief host_int_delBASession - * @details Delete all Rx BA session - * @param[in] - * @return Error code. - * @author Abdelrahman Sobhy - * @date - * @version 1.0 - */ -s32 host_int_del_All_Rx_BASession(struct host_if_drv *hWFIDrv, char *pBSSID, char TID); - - -/** - * @brief host_int_get_ipaddress - * @details get IP address on firmware - * @param[in] - * @return Error code. - * @author Abdelrahman Sobhy - * @date - * @version 1.0 - */ -s32 host_int_get_ipaddress(struct host_if_drv *hWFIDrv, u8 *pu8IPAddr, u8 idx); - -/** - * @brief host_int_remain_on_channel - * @details - * @param[in] - * @return Error code. - * @author - * @date - * @version 1.0 - */ -s32 host_int_remain_on_channel(struct host_if_drv *hWFIDrv, u32 u32SessionID, u32 u32duration, u16 chan, wilc_remain_on_chan_expired RemainOnChanExpired, wilc_remain_on_chan_ready RemainOnChanReady, void *pvUserArg); - -/** - * @brief host_int_ListenStateExpired - * @details - * @param[in] Handle to wifi driver - * Duration to remain on channel - * Channel to remain on - * Pointer to fn to be called on receive frames in listen state - * Pointer to remain-on-channel expired fn - * Priv - * @return Error code. - * @author - * @date - * @version 1.0 - */ -s32 host_int_ListenStateExpired(struct host_if_drv *hWFIDrv, u32 u32SessionID); - -/** - * @brief host_int_frame_register - * @details - * @param[in] - * @return Error code. - * @author - * @date - * @version 1.0 - */ -s32 host_int_frame_register(struct host_if_drv *hWFIDrv, u16 u16FrameType, bool bReg); -/** - * @brief host_int_set_wfi_drv_handler - * @details - * @param[in] - * @return Error code. - * @author - * @date - * @version 1.0 - */ -int host_int_set_wfi_drv_handler(struct host_if_drv *address); -int host_int_set_operation_mode(struct host_if_drv *wfi_drv, u32 mode); - -static s32 Handle_ScanDone(struct host_if_drv *drvHandler, enum scan_event enuEvent); - -void host_int_freeJoinParams(void *pJoinParams); - -s32 host_int_get_statistics(struct host_if_drv *hWFIDrv, struct rf_info *pstrStatistics); +struct wilc_vif; +s32 wilc_remove_key(struct host_if_drv *hWFIDrv, const u8 *pu8StaAddress); +int wilc_remove_wep_key(struct wilc_vif *vif, u8 index); +int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index); +int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len, + u8 index); +int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len, + u8 index, u8 mode, enum AUTHTYPE auth_type); +s32 wilc_add_ptk(struct wilc_vif *vif, const u8 *pu8Ptk, u8 u8PtkKeylen, + const u8 *mac_addr, const u8 *pu8RxMic, const u8 *pu8TxMic, + u8 mode, u8 u8Ciphermode, u8 u8Idx); +s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, + u32 *pu32InactiveTime); +s32 wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *pu8RxGtk, u8 u8GtkKeylen, + u8 u8KeyIdx, u32 u32KeyRSClen, const u8 *KeyRSC, + const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, + u8 u8Ciphermode); +s32 wilc_add_tx_gtk(struct host_if_drv *hWFIDrv, u8 u8KeyLen, + u8 *pu8TxGtk, u8 u8KeyIdx); +s32 wilc_set_pmkid_info(struct wilc_vif *vif, + struct host_if_pmkid_attr *pu8PmkidInfoArray); +s32 wilc_get_mac_address(struct wilc_vif *vif, u8 *pu8MacAddress); +s32 wilc_set_mac_address(struct wilc_vif *vif, u8 *pu8MacAddress); +int wilc_wait_msg_queue_idle(void); +s32 wilc_set_start_scan_req(struct host_if_drv *hWFIDrv, u8 scanSource); +s32 wilc_set_join_req(struct wilc_vif *vif, u8 *pu8bssid, const u8 *pu8ssid, + size_t ssidLen, const u8 *pu8IEs, size_t IEsLen, + wilc_connect_result pfConnectResult, void *pvUserArg, + u8 u8security, enum AUTHTYPE tenuAuth_type, + u8 u8channel, void *pJoinParams); +s32 wilc_flush_join_req(struct wilc_vif *vif); +s32 wilc_disconnect(struct wilc_vif *vif, u16 u16ReasonCode); +int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel); +s32 wilc_get_rssi(struct wilc_vif *vif, s8 *ps8Rssi); +s32 wilc_scan(struct wilc_vif *vif, u8 u8ScanSource, u8 u8ScanType, + u8 *pu8ChnlFreqList, u8 u8ChnlListLen, const u8 *pu8IEs, + size_t IEsLen, wilc_scan_result ScanResult, void *pvUserArg, + struct hidden_network *pstrHiddenNetwork); +s32 wilc_hif_set_cfg(struct wilc_vif *vif, + struct cfg_param_val *pstrCfgParamVal); +s32 wilc_init(struct net_device *dev, struct host_if_drv **phWFIDrv); +s32 wilc_deinit(struct wilc_vif *vif); +s32 wilc_add_beacon(struct wilc_vif *vif, u32 u32Interval, u32 u32DTIMPeriod, + u32 u32HeadLen, u8 *pu8Head, u32 u32TailLen, u8 *pu8Tail); +int wilc_del_beacon(struct wilc_vif *vif); +int wilc_add_station(struct wilc_vif *vif, struct add_sta_param *sta_param); +s32 wilc_del_allstation(struct wilc_vif *vif, u8 pu8MacAddr[][ETH_ALEN]); +int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr); +s32 wilc_edit_station(struct wilc_vif *vif, + struct add_sta_param *pstrStaParams); +s32 wilc_set_power_mgmt(struct wilc_vif *vif, bool bIsEnabled, u32 u32Timeout); +s32 wilc_setup_multicast_filter(struct wilc_vif *vif, bool bIsEnabled, + u32 u32count); +s32 wilc_setup_ipaddress(struct wilc_vif *vif, u8 *u16ipadd, u8 idx); +s32 wilc_del_all_rx_ba_session(struct wilc_vif *vif, char *pBSSID, char TID); +s32 wilc_remain_on_channel(struct wilc_vif *vif, u32 u32SessionID, + u32 u32duration, u16 chan, + wilc_remain_on_chan_expired RemainOnChanExpired, + wilc_remain_on_chan_ready RemainOnChanReady, + void *pvUserArg); +s32 wilc_listen_state_expired(struct wilc_vif *vif, u32 u32SessionID); +s32 wilc_frame_register(struct wilc_vif *vif, u16 u16FrameType, bool bReg); +int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index); +int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode); + +void wilc_free_join_params(void *pJoinParams); + +s32 wilc_get_statistics(struct wilc_vif *vif, struct rf_info *pstrStatistics); +void wilc_resolve_disconnect_aberration(struct wilc_vif *vif); +int wilc_get_vif_idx(struct wilc_vif *vif); + +extern bool wilc_optaining_ip; +extern u8 wilc_connected_ssid[6]; +extern u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN]; + +extern int wilc_connecting; +extern u8 wilc_initialized; +extern struct timer_list wilc_during_ip_timer; #endif diff --git a/drivers/staging/wilc1000/linux_mon.c b/drivers/staging/wilc1000/linux_mon.c index 450af1b77f99..e550027645b7 100644 --- a/drivers/staging/wilc1000/linux_mon.c +++ b/drivers/staging/wilc1000/linux_mon.c @@ -26,12 +26,9 @@ struct wilc_wfi_radiotap_cb_hdr { static struct net_device *wilc_wfi_mon; /* global monitor netdev */ -extern int mac_xmit(struct sk_buff *skb, struct net_device *dev); - - -u8 srcAdd[6]; -u8 bssid[6]; -u8 broadcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; +static u8 srcAdd[6]; +static u8 bssid[6]; +static u8 broadcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; /** * @brief WILC_WFI_monitor_rx * @details @@ -195,7 +192,7 @@ static int mon_mgmt_tx(struct net_device *dev, const u8 *buf, size_t len) mgmt_tx->size = len; memcpy(mgmt_tx->buff, buf, len); - wilc_wlan_txq_add_mgmt_pkt(mgmt_tx, mgmt_tx->buff, mgmt_tx->size, + wilc_wlan_txq_add_mgmt_pkt(dev, mgmt_tx, mgmt_tx->buff, mgmt_tx->size, mgmt_tx_complete); netif_wake_queue(dev); @@ -298,7 +295,7 @@ static netdev_tx_t WILC_WFI_mon_xmit(struct sk_buff *skb, mon_mgmt_tx(mon_priv->real_ndev, skb->data, skb->len); dev_kfree_skb(skb); } else - ret = mac_xmit(skb, mon_priv->real_ndev); + ret = wilc_mac_xmit(skb, mon_priv->real_ndev); return ret; } diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c index 2a5b36fd8b48..54fe9d74b780 100644 --- a/drivers/staging/wilc1000/linux_wlan.c +++ b/drivers/staging/wilc1000/linux_wlan.c @@ -23,61 +23,8 @@ #include <linux/kernel.h> #include <linux/skbuff.h> -#include <linux/version.h> #include <linux/semaphore.h> -#ifdef WILC_SDIO -#include "linux_wlan_sdio.h" -#else -#include "linux_wlan_spi.h" -#endif - -#if defined(CUSTOMER_PLATFORM) -/* - TODO : Write power control functions as customer platform. - */ -#else - - #define _linux_wlan_device_power_on() {} - #define _linux_wlan_device_power_off() {} - - #define _linux_wlan_device_detection() {} - #define _linux_wlan_device_removal() {} -#endif - -extern bool g_obtainingIP; -extern void resolve_disconnect_aberration(void *drvHandler); -extern u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN]; -extern struct timer_list hDuringIpTimer; - -static int linux_wlan_device_power(int on_off) -{ - PRINT_D(INIT_DBG, "linux_wlan_device_power.. (%d)\n", on_off); - - if (on_off) { - _linux_wlan_device_power_on(); - } else { - _linux_wlan_device_power_off(); - } - - return 0; -} - -static int linux_wlan_device_detection(int on_off) -{ - PRINT_D(INIT_DBG, "linux_wlan_device_detection.. (%d)\n", on_off); - -#ifdef WILC_SDIO - if (on_off) { - _linux_wlan_device_detection(); - } else { - _linux_wlan_device_removal(); - } -#endif - - return 0; -} - static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr); static struct notifier_block g_dev_notifier = { @@ -86,40 +33,24 @@ static struct notifier_block g_dev_notifier = { #define IRQ_WAIT 1 #define IRQ_NO_WAIT 0 -/* - * to sync between mac_close and module exit. - * don't initialize or de-initialize from init/deinitlocks - * to be initialized from module wilc_netdev_init and - * deinitialized from mdoule_exit - */ static struct semaphore close_exit_sync; static int wlan_deinit_locks(struct net_device *dev); static void wlan_deinitialize_threads(struct net_device *dev); -extern void WILC_WFI_monitor_rx(u8 *buff, u32 size); -extern void WILC_WFI_p2p_rx(struct net_device *dev, u8 *buff, u32 size); static void linux_wlan_tx_complete(void *priv, int status); static int mac_init_fn(struct net_device *ndev); -int mac_xmit(struct sk_buff *skb, struct net_device *dev); -int mac_open(struct net_device *ndev); -int mac_close(struct net_device *ndev); static struct net_device_stats *mac_stats(struct net_device *dev); static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd); static void wilc_set_multicast_list(struct net_device *dev); -/* - * for now - in frmw_to_linux there should be private data to be passed to it - * and this data should be pointer to net device - */ -struct wilc *g_linux_wlan; -bool bEnablePS = true; +bool wilc_enable_ps = true; static const struct net_device_ops wilc_netdev_ops = { .ndo_init = mac_init_fn, - .ndo_open = mac_open, - .ndo_stop = mac_close, - .ndo_start_xmit = mac_xmit, + .ndo_open = wilc_mac_open, + .ndo_stop = wilc_mac_close, + .ndo_start_xmit = wilc_mac_xmit, .ndo_do_ioctl = mac_ioctl, .ndo_get_stats = mac_stats, .ndo_set_rx_mode = wilc_set_multicast_list, @@ -130,130 +61,129 @@ static int dev_state_ev_handler(struct notifier_block *this, unsigned long event { struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr; struct wilc_priv *priv; - struct host_if_drv *pstrWFIDrv; + struct host_if_drv *hif_drv; struct net_device *dev; - u8 *pIP_Add_buff; - perInterface_wlan_t *nic; + u8 *ip_addr_buf; + struct wilc_vif *vif; u8 null_ip[4] = {0}; char wlan_dev_name[5] = "wlan0"; - if (dev_iface == NULL || dev_iface->ifa_dev == NULL || dev_iface->ifa_dev->dev == NULL) { + if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev) { PRINT_D(GENERIC_DBG, "dev_iface = NULL\n"); return NOTIFY_DONE; } - if ((memcmp(dev_iface->ifa_label, "wlan0", 5)) && (memcmp(dev_iface->ifa_label, "p2p0", 4))) { + if (memcmp(dev_iface->ifa_label, "wlan0", 5) && + memcmp(dev_iface->ifa_label, "p2p0", 4)) { PRINT_D(GENERIC_DBG, "Interface is neither WLAN0 nor P2P0\n"); return NOTIFY_DONE; } dev = (struct net_device *)dev_iface->ifa_dev->dev; - if (dev->ieee80211_ptr == NULL || dev->ieee80211_ptr->wiphy == NULL) { + if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy) { PRINT_D(GENERIC_DBG, "No Wireless registerd\n"); return NOTIFY_DONE; } priv = wiphy_priv(dev->ieee80211_ptr->wiphy); - if (priv == NULL) { + if (!priv) { PRINT_D(GENERIC_DBG, "No Wireless Priv\n"); return NOTIFY_DONE; } - pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; - nic = netdev_priv(dev); - if (nic == NULL || pstrWFIDrv == NULL) { + hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv; + vif = netdev_priv(dev); + if (!vif || !hif_drv) { PRINT_D(GENERIC_DBG, "No Wireless Priv\n"); return NOTIFY_DONE; } - PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n"); /* tony */ + PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n"); switch (event) { case NETDEV_UP: - PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev); /* tony */ + PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev); PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n"); - /*If we are in station mode or client mode*/ - if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) { - pstrWFIDrv->IFC_UP = 1; - g_obtainingIP = false; - del_timer(&hDuringIpTimer); + if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) { + hif_drv->IFC_UP = 1; + wilc_optaining_ip = false; + del_timer(&wilc_during_ip_timer); PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n"); } - if (bEnablePS) - host_int_set_power_mgmt(pstrWFIDrv, 1, 0); + if (wilc_enable_ps) + wilc_set_power_mgmt(vif, 1, 0); PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label); - pIP_Add_buff = (char *) (&(dev_iface->ifa_address)); - PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]); - host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx); + ip_addr_buf = (char *)&dev_iface->ifa_address; + PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n", + ip_addr_buf[0], ip_addr_buf[1], + ip_addr_buf[2], ip_addr_buf[3]); + wilc_setup_ipaddress(vif, ip_addr_buf, vif->u8IfIdx); break; case NETDEV_DOWN: - PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev); /* tony */ + PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev); PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Released ===============\n\n"); - if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) { - pstrWFIDrv->IFC_UP = 0; - g_obtainingIP = false; + if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) { + hif_drv->IFC_UP = 0; + wilc_optaining_ip = false; } if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0) - host_int_set_power_mgmt(pstrWFIDrv, 0, 0); + wilc_set_power_mgmt(vif, 0, 0); - resolve_disconnect_aberration(pstrWFIDrv); + wilc_resolve_disconnect_aberration(vif); PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label); - pIP_Add_buff = null_ip; - PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]); + ip_addr_buf = null_ip; + PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n", + ip_addr_buf[0], ip_addr_buf[1], + ip_addr_buf[2], ip_addr_buf[3]); - host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx); + wilc_setup_ipaddress(vif, ip_addr_buf, vif->u8IfIdx); break; default: - PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n"); /* tony */ + PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n"); PRINT_INFO(GENERIC_DBG, "[%s] unknown dev event: %lu\n", dev_iface->ifa_label, event); break; } return NOTIFY_DONE; - } -#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) static irqreturn_t isr_uh_routine(int irq, void *user_data) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; struct net_device *dev = (struct net_device *)user_data; - nic = netdev_priv(dev); - wilc = nic->wilc; + vif = netdev_priv(dev); + wilc = vif->wilc; PRINT_D(INT_DBG, "Interrupt received UH\n"); - /*While mac is closing cacncel the handling of any interrupts received*/ if (wilc->close) { PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n"); return IRQ_HANDLED; } return IRQ_WAKE_THREAD; } -#endif -irqreturn_t isr_bh_routine(int irq, void *userdata) +static irqreturn_t isr_bh_routine(int irq, void *userdata) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; - nic = netdev_priv(userdata); - wilc = nic->wilc; + vif = netdev_priv(userdata); + wilc = vif->wilc; - /*While mac is closing cacncel the handling of any interrupts received*/ if (wilc->close) { PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n"); return IRQ_HANDLED; @@ -265,154 +195,131 @@ irqreturn_t isr_bh_routine(int irq, void *userdata) return IRQ_HANDLED; } -#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) static int init_irq(struct net_device *dev) { int ret = 0; - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wl; - nic = netdev_priv(dev); - wl = nic->wilc; - - /*initialize GPIO and register IRQ num*/ - /*GPIO request*/ - if ((gpio_request(GPIO_NUM, "WILC_INTR") == 0) && - (gpio_direction_input(GPIO_NUM) == 0)) { -#if defined(CUSTOMER_PLATFORM) -/* - TODO : save the registerd irq number to the private wilc context in kernel. - * - * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM); - */ -#else - wl->dev_irq_num = gpio_to_irq(GPIO_NUM); -#endif + vif = netdev_priv(dev); + wl = vif->wilc; + + if ((gpio_request(wl->gpio, "WILC_INTR") == 0) && + (gpio_direction_input(wl->gpio) == 0)) { + wl->dev_irq_num = gpio_to_irq(wl->gpio); } else { ret = -1; PRINT_ER("could not obtain gpio for WILC_INTR\n"); } - if ((ret != -1) && (request_threaded_irq(wl->dev_irq_num, isr_uh_routine, isr_bh_routine, - IRQF_TRIGGER_LOW | IRQF_ONESHOT, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/ - "WILC_IRQ", dev)) < 0) { - - PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM); + if (ret != -1 && request_threaded_irq(wl->dev_irq_num, + isr_uh_routine, + isr_bh_routine, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + "WILC_IRQ", dev) < 0) { + PRINT_ER("Failed to request IRQ for GPIO: %d\n", wl->gpio); + gpio_free(wl->gpio); ret = -1; } else { - PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n", - wl->dev_irq_num, GPIO_NUM); + wl->dev_irq_num, wl->gpio); } return ret; } -#endif static void deinit_irq(struct net_device *dev) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; - nic = netdev_priv(dev); - wilc = nic->wilc; + vif = netdev_priv(dev); + wilc = vif->wilc; -#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) /* Deintialize IRQ */ - if (&wilc->dev_irq_num != 0) { + if (wilc->dev_irq_num) { free_irq(wilc->dev_irq_num, wilc); - - gpio_free(GPIO_NUM); + gpio_free(wilc->gpio); } -#endif } -/* - * OS functions - */ -void linux_wlan_dbg(u8 *buff) +void wilc_dbg(u8 *buff) { PRINT_D(INIT_DBG, "%d\n", *buff); } -int linux_wlan_lock_timeout(void *vp, u32 timeout) +int wilc_lock_timeout(struct wilc *nic, void *vp, u32 timeout) { + /* FIXME: replace with mutex_lock or wait_for_completion */ int error = -1; PRINT_D(LOCK_DBG, "Locking %p\n", vp); - if (vp != NULL) - error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout)); + if (vp) + error = down_timeout((struct semaphore *)vp, + msecs_to_jiffies(timeout)); else PRINT_ER("Failed, mutex is NULL\n"); return error; } -void linux_wlan_mac_indicate(struct wilc *wilc, int flag) +void wilc_mac_indicate(struct wilc *wilc, int flag) { - /*I have to do it that way becuase there is no mean to encapsulate device pointer - * as a parameter - */ int status; if (flag == WILC_MAC_INDICATE_STATUS) { - wilc_wlan_cfg_get_val(WID_STATUS, (unsigned char *)&status, 4); + wilc_wlan_cfg_get_val(WID_STATUS, + (unsigned char *)&status, 4); if (wilc->mac_status == WILC_MAC_STATUS_INIT) { wilc->mac_status = status; up(&wilc->sync_event); } else { wilc->mac_status = status; } - - if (wilc->mac_status == WILC_MAC_STATUS_CONNECT) { /* Connect */ - } - } else if (flag == WILC_MAC_INDICATE_SCAN) { PRINT_D(GENERIC_DBG, "Scanning ...\n"); - } - } -struct net_device *GetIfHandler(struct wilc *wilc, u8 *pMacHeader) +static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header) { - u8 *Bssid, *Bssid1; + u8 *bssid, *bssid1; int i = 0; - Bssid = pMacHeader + 10; - Bssid1 = pMacHeader + 4; + bssid = mac_header + 10; + bssid1 = mac_header + 4; for (i = 0; i < wilc->vif_num; i++) - if (!memcmp(Bssid1, wilc->vif[i].bssid, ETH_ALEN) || - !memcmp(Bssid, wilc->vif[i].bssid, ETH_ALEN)) - return wilc->vif[i].ndev; + if (!memcmp(bssid1, wilc->vif[i]->bssid, ETH_ALEN) || + !memcmp(bssid, wilc->vif[i]->bssid, ETH_ALEN)) + return wilc->vif[i]->ndev; PRINT_INFO(INIT_DBG, "Invalide handle\n"); for (i = 0; i < 25; i++) - PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]); - Bssid = pMacHeader + 18; - Bssid1 = pMacHeader + 12; + PRINT_D(INIT_DBG, "%02x ", mac_header[i]); + bssid = mac_header + 18; + bssid1 = mac_header + 12; for (i = 0; i < wilc->vif_num; i++) - if (!memcmp(Bssid1, wilc->vif[i].bssid, ETH_ALEN) || - !memcmp(Bssid, wilc->vif[i].bssid, ETH_ALEN)) - return wilc->vif[i].ndev; + if (!memcmp(bssid1, wilc->vif[i]->bssid, ETH_ALEN) || + !memcmp(bssid, wilc->vif[i]->bssid, ETH_ALEN)) + return wilc->vif[i]->ndev; PRINT_INFO(INIT_DBG, "\n"); return NULL; } -int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID) +int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid) { int i = 0; int ret = -1; - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; - nic = netdev_priv(wilc_netdev); - wilc = nic->wilc; + vif = netdev_priv(wilc_netdev); + wilc = vif->wilc; for (i = 0; i < wilc->vif_num; i++) - if (wilc->vif[i].ndev == wilc_netdev) { - memcpy(wilc->vif[i].bssid, pBSSID, 6); + if (wilc->vif[i]->ndev == wilc_netdev) { + memcpy(wilc->vif[i]->bssid, bssid, 6); ret = 0; break; } @@ -420,15 +327,14 @@ int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID) return ret; } -/*Function to get number of connected interfaces*/ -int linux_wlan_get_num_conn_ifcs(void) +int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc) { u8 i = 0; u8 null_bssid[6] = {0}; u8 ret_val = 0; - for (i = 0; i < g_linux_wlan->vif_num; i++) - if (memcmp(g_linux_wlan->vif[i].bssid, null_bssid, 6)) + for (i = 0; i < wilc->vif_num; i++) + if (memcmp(wilc->vif[i]->bssid, null_bssid, 6)) ret_val++; return ret_val; @@ -439,7 +345,7 @@ int linux_wlan_get_num_conn_ifcs(void) static int linux_wlan_txq_task(void *vp) { int ret, txq_count; - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wl; struct net_device *dev = vp; #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS @@ -451,20 +357,16 @@ static int linux_wlan_txq_task(void *vp) int backoff_weight = TX_BACKOFF_WEIGHT_MIN; #endif - nic = netdev_priv(dev); - wl = nic->wilc; + vif = netdev_priv(dev); + wl = vif->wilc; - /* inform wilc1000_wlan_init that TXQ task is started. */ up(&wl->txq_thread_started); while (1) { - PRINT_D(TX_DBG, "txq_task Taking a nap :)\n"); down(&wl->txq_event); - /* wait_for_completion(&pd->txq_event); */ PRINT_D(TX_DBG, "txq_task Who waked me up :$\n"); if (wl->close) { - /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */ up(&wl->txq_thread_started); while (!kthread_should_stop()) @@ -479,23 +381,19 @@ static int linux_wlan_txq_task(void *vp) #else do { ret = wilc_wlan_handle_txq(dev, &txq_count); - if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD /* && netif_queue_stopped(pd->wilc_netdev)*/) { + if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD) { PRINT_D(TX_DBG, "Waking up queue\n"); - /* netif_wake_queue(pd->wilc_netdev); */ - if (netif_queue_stopped(wl->vif[0].ndev)) - netif_wake_queue(wl->vif[0].ndev); - if (netif_queue_stopped(wl->vif[1].ndev)) - netif_wake_queue(wl->vif[1].ndev); + + if (netif_queue_stopped(wl->vif[0]->ndev)) + netif_wake_queue(wl->vif[0]->ndev); + if (netif_queue_stopped(wl->vif[1]->ndev)) + netif_wake_queue(wl->vif[1]->ndev); } - if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */ + if (ret == WILC_TX_ERR_NO_BUF) { do { - /* Back off from sending packets for some time. */ - /* schedule_timeout will allow RX task to run and free buffers.*/ - /* set_current_state(TASK_UNINTERRUPTIBLE); */ - /* timeout = schedule_timeout(timeout); */ msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight); - } while (/*timeout*/ 0); + } while (0); backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP; if (backoff_weight > TX_BACKOFF_WEIGHT_MAX) backoff_weight = TX_BACKOFF_WEIGHT_MAX; @@ -506,376 +404,326 @@ static int linux_wlan_txq_task(void *vp) backoff_weight = TX_BACKOFF_WEIGHT_MIN; } } - /*TODO: drop packets after a certain time/number of retry count. */ - } while (ret == WILC_TX_ERR_NO_BUF && !wl->close); /* retry sending packets if no more buffers in chip. */ + } while (ret == WILC_TX_ERR_NO_BUF && !wl->close); #endif } return 0; } -void linux_wlan_rx_complete(void) +void wilc_rx_complete(struct wilc *nic) { PRINT_D(RX_DBG, "RX completed\n"); } -int linux_wlan_get_firmware(perInterface_wlan_t *p_nic) +int wilc_wlan_get_firmware(struct net_device *dev) { - - perInterface_wlan_t *nic = p_nic; + struct wilc_vif *vif; + struct wilc *wilc; int ret = 0; const struct firmware *wilc_firmware; char *firmware; - if (nic->iftype == AP_MODE) + vif = netdev_priv(dev); + wilc = vif->wilc; + + if (vif->iftype == AP_MODE) { firmware = AP_FIRMWARE; - else if (nic->iftype == STATION_MODE) + } else if (vif->iftype == STATION_MODE) { firmware = STA_FIRMWARE; - - else { + } else { PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n"); firmware = P2P_CONCURRENCY_FIRMWARE; } - if (nic == NULL) { - PRINT_ER("NIC is NULL\n"); + if (!vif) { + PRINT_ER("vif is NULL\n"); goto _fail_; } - if (&nic->wilc_netdev->dev == NULL) { - PRINT_ER("&nic->wilc_netdev->dev is NULL\n"); + if (!(&vif->ndev->dev)) { + PRINT_ER("&vif->ndev->dev is NULL\n"); goto _fail_; } - /* the firmare should be located in /lib/firmware in - * root file system with the name specified above */ - -#ifdef WILC_SDIO - if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_sdio_func->dev) != 0) { + if (request_firmware(&wilc_firmware, firmware, wilc->dev) != 0) { PRINT_ER("%s - firmare not available\n", firmware); ret = -1; goto _fail_; } -#else - if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_spidev->dev) != 0) { - PRINT_ER("%s - firmare not available\n", firmware); - ret = -1; - goto _fail_; - } -#endif - g_linux_wlan->firmware = wilc_firmware; + wilc->firmware = wilc_firmware; _fail_: return ret; - } -static int linux_wlan_start_firmware(perInterface_wlan_t *nic) +static int linux_wlan_start_firmware(struct net_device *dev) { - + struct wilc_vif *vif; + struct wilc *wilc; int ret = 0; - /* start firmware */ + + vif = netdev_priv(dev); + wilc = vif->wilc; + PRINT_D(INIT_DBG, "Starting Firmware ...\n"); - ret = wilc_wlan_start(); + ret = wilc_wlan_start(wilc); if (ret < 0) { PRINT_ER("Failed to start Firmware\n"); - goto _fail_; + return ret; } - /* wait for mac ready */ PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n"); - ret = linux_wlan_lock_timeout(&g_linux_wlan->sync_event, 5000); + ret = wilc_lock_timeout(wilc, &wilc->sync_event, 5000); if (ret) { PRINT_D(INIT_DBG, "Firmware start timed out"); - goto _fail_; + return ret; } - /* - * TODO: Driver shouoldn't wait forever for firmware to get started - - * in case of timeout this should be handled properly - */ PRINT_D(INIT_DBG, "Firmware successfully started\n"); -_fail_: - return ret; + return 0; } -static int linux_wlan_firmware_download(struct wilc *p_nic) -{ +static int wilc1000_firmware_download(struct net_device *dev) +{ + struct wilc_vif *vif; + struct wilc *wilc; int ret = 0; - if (!g_linux_wlan->firmware) { + vif = netdev_priv(dev); + wilc = vif->wilc; + + if (!wilc->firmware) { PRINT_ER("Firmware buffer is NULL\n"); - ret = -ENOBUFS; - goto _FAIL_; + return -ENOBUFS; } - /** - * do the firmware download - **/ PRINT_D(INIT_DBG, "Downloading Firmware ...\n"); - ret = wilc_wlan_firmware_download(g_linux_wlan->firmware->data, - g_linux_wlan->firmware->size); + ret = wilc_wlan_firmware_download(wilc, wilc->firmware->data, + wilc->firmware->size); if (ret < 0) - goto _FAIL_; + return ret; - /* Freeing FW buffer */ PRINT_D(INIT_DBG, "Freeing FW buffer ...\n"); PRINT_D(INIT_DBG, "Releasing firmware\n"); - release_firmware(g_linux_wlan->firmware); + release_firmware(wilc->firmware); + wilc->firmware = NULL; PRINT_D(INIT_DBG, "Download Succeeded\n"); -_FAIL_: - return ret; + return 0; } -/* startup configuration - could be changed later using iconfig*/ -static int linux_wlan_init_test_config(struct net_device *dev, struct wilc *p_nic) +static int linux_wlan_init_test_config(struct net_device *dev, + struct wilc *wilc) { - unsigned char c_val[64]; unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff}; struct wilc_priv *priv; - struct host_if_drv *pstrWFIDrv; + struct host_if_drv *hif_drv; PRINT_D(TX_DBG, "Start configuring Firmware\n"); get_random_bytes(&mac_add[5], 1); get_random_bytes(&mac_add[4], 1); priv = wiphy_priv(dev->ieee80211_ptr->wiphy); - pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; - PRINT_D(INIT_DBG, "Host = %p\n", pstrWFIDrv); + hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv; + PRINT_D(INIT_DBG, "Host = %p\n", hif_drv); - PRINT_D(INIT_DBG, "MAC address is : %02x-%02x-%02x-%02x-%02x-%02x\n", mac_add[0], mac_add[1], mac_add[2], mac_add[3], mac_add[4], mac_add[5]); - wilc_get_chipid(0); + PRINT_D(INIT_DBG, "MAC address is : %02x-%02x-%02x-%02x-%02x-%02x\n", + mac_add[0], mac_add[1], mac_add[2], + mac_add[3], mac_add[4], mac_add[5]); + wilc_get_chipid(wilc, 0); *(int *)c_val = 1; - if (!wilc_wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0)) goto _fail_; - /*to tell fw that we are going to use PC test - WILC specific*/ c_val[0] = 0; - if (!wilc_wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_PC_TEST_MODE, c_val, 1, 0, 0)) goto _fail_; c_val[0] = INFRASTRUCTURE; - if (!wilc_wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_BSS_TYPE, c_val, 1, 0, 0)) goto _fail_; - /* c_val[0] = RATE_AUTO; */ c_val[0] = RATE_AUTO; - if (!wilc_wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0)) goto _fail_; c_val[0] = G_MIXED_11B_2_MODE; - if (!wilc_wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_11G_OPERATING_MODE, c_val, 1, 0, + 0)) goto _fail_; c_val[0] = 1; - if (!wilc_wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0)) goto _fail_; c_val[0] = G_SHORT_PREAMBLE; - if (!wilc_wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_PREAMBLE, c_val, 1, 0, 0)) goto _fail_; c_val[0] = AUTO_PROT; - if (!wilc_wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_PROT_MECH, c_val, 1, 0, 0)) goto _fail_; c_val[0] = ACTIVE_SCAN; - if (!wilc_wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_SCAN_TYPE, c_val, 1, 0, 0)) goto _fail_; c_val[0] = SITE_SURVEY_OFF; - if (!wilc_wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_SITE_SURVEY, c_val, 1, 0, 0)) goto _fail_; - *((int *)c_val) = 0xffff; /* Never use RTS-CTS */ - if (!wilc_wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0)) + *((int *)c_val) = 0xffff; + if (!wilc_wlan_cfg_set(wilc, 0, WID_RTS_THRESHOLD, c_val, 2, 0, 0)) goto _fail_; *((int *)c_val) = 2346; - if (!wilc_wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0)) goto _fail_; - /* SSID */ - /* -------------------------------------------------------------- */ - /* Configuration : String with length less than 32 bytes */ - /* Values to set : Any string with length less than 32 bytes */ - /* ( In BSS Station Set SSID to "" (null string) */ - /* to enable Broadcast SSID suppport ) */ - /* -------------------------------------------------------------- */ c_val[0] = 0; - if (!wilc_wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_BCAST_SSID, c_val, 1, 0, 0)) goto _fail_; c_val[0] = 1; - if (!wilc_wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_QOS_ENABLE, c_val, 1, 0, 0)) goto _fail_; c_val[0] = NO_POWERSAVE; - if (!wilc_wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0)) goto _fail_; - c_val[0] = NO_ENCRYPT; /* NO_ENCRYPT, 0x79 */ - if (!wilc_wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0)) + c_val[0] = NO_SECURITY; /* NO_ENCRYPT, 0x79 */ + if (!wilc_wlan_cfg_set(wilc, 0, WID_11I_MODE, c_val, 1, 0, 0)) goto _fail_; c_val[0] = OPEN_SYSTEM; - if (!wilc_wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_AUTH_TYPE, c_val, 1, 0, 0)) goto _fail_; - /* WEP/802 11I Configuration */ - /* ------------------------------------------------------------------ */ - /* Configuration : WEP Key */ - /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */ - /* In case more than 5 bytes are passed on for WEP 40 */ - /* only first 5 bytes will be used as the key */ - /* ------------------------------------------------------------------ */ - strcpy(c_val, "123456790abcdef1234567890"); - if (!wilc_wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_WEP_KEY_VALUE, c_val, + (strlen(c_val) + 1), 0, 0)) goto _fail_; - /* WEP/802 11I Configuration */ - /* ------------------------------------------------------------------ */ - /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */ - /* Values to set : Any string with length greater than equal to 8 bytes */ - /* and less than 64 bytes */ - /* ------------------------------------------------------------------ */ strcpy(c_val, "12345678"); - if (!wilc_wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_11I_PSK, c_val, (strlen(c_val)), 0, + 0)) goto _fail_; - /* IEEE802.1X Key Configuration */ - /* ------------------------------------------------------------------ */ - /* Configuration : Radius Server Access Secret Key */ - /* Values to set : Any string with length greater than equal to 8 bytes */ - /* and less than 65 bytes */ - /* ------------------------------------------------------------------ */ strcpy(c_val, "password"); - if (!wilc_wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_1X_KEY, c_val, (strlen(c_val) + 1), + 0, 0)) goto _fail_; - /* IEEE802.1X Server Address Configuration */ - /* ------------------------------------------------------------------ */ - /* Configuration : Radius Server IP Address */ - /* Values to set : Any valid IP Address */ - /* ------------------------------------------------------------------ */ c_val[0] = 192; c_val[1] = 168; c_val[2] = 1; c_val[3] = 112; - if (!wilc_wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_1X_SERV_ADDR, c_val, 4, 0, 0)) goto _fail_; c_val[0] = 3; - if (!wilc_wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0)) goto _fail_; c_val[0] = 3; - if (!wilc_wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_DTIM_PERIOD, c_val, 1, 0, 0)) goto _fail_; c_val[0] = NORMAL_ACK; - if (!wilc_wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_ACK_POLICY, c_val, 1, 0, 0)) goto _fail_; c_val[0] = 0; - if (!wilc_wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, + 0, 0)) goto _fail_; c_val[0] = 48; - if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, + 0)) goto _fail_; c_val[0] = 28; - if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, + 0)) goto _fail_; - /* Beacon Interval */ - /* -------------------------------------------------------------------- */ - /* Configuration : Sets the beacon interval value */ - /* Values to set : Any 16-bit value */ - /* -------------------------------------------------------------------- */ - *((int *)c_val) = 100; - if (!wilc_wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_BEACON_INTERVAL, c_val, 2, 0, 0)) goto _fail_; c_val[0] = REKEY_DISABLE; - if (!wilc_wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_REKEY_POLICY, c_val, 1, 0, 0)) goto _fail_; - /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */ - /* -------------------------------------------------------------------- */ - /* Configuration : Sets the Rekey Time (s) */ - /* Values to set : 32-bit value */ - /* -------------------------------------------------------------------- */ *((int *)c_val) = 84600; - if (!wilc_wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_REKEY_PERIOD, c_val, 4, 0, 0)) goto _fail_; - /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */ - /* -------------------------------------------------------------------- */ - /* Configuration : Sets Rekey Group Packet count */ - /* Values to set : 32-bit Value */ - /* -------------------------------------------------------------------- */ *((int *)c_val) = 500; - if (!wilc_wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, + 0)) goto _fail_; c_val[0] = 1; - if (!wilc_wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, + 0)) goto _fail_; c_val[0] = G_SELF_CTS_PROT; - if (!wilc_wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0)) goto _fail_; - c_val[0] = 1; /* Enable N */ - if (!wilc_wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0)) + c_val[0] = 1; + if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_ENABLE, c_val, 1, 0, 0)) goto _fail_; c_val[0] = HT_MIXED_MODE; - if (!wilc_wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_OPERATING_MODE, c_val, 1, 0, + 0)) goto _fail_; - c_val[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */ - if (!wilc_wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0)) + c_val[0] = 1; + if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, + 0)) goto _fail_; memcpy(c_val, mac_add, 6); - if (!wilc_wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_MAC_ADDR, c_val, 6, 0, 0)) goto _fail_; - /** - * AP only - **/ c_val[0] = DETECT_PROTECT_REPORT; - if (!wilc_wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, + 0, 0)) goto _fail_; c_val[0] = RTS_CTS_NONHT_PROT; - if (!wilc_wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0)) goto _fail_; c_val[0] = 0; - if (!wilc_wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, + 0)) goto _fail_; c_val[0] = MIMO_MODE; - if (!wilc_wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_SMPS_MODE, c_val, 1, 0, 0)) goto _fail_; c_val[0] = 7; - if (!wilc_wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0)) + if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, + 0)) goto _fail_; - c_val[0] = 1; /* Enable N with immediate block ack. */ - if (!wilc_wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, 1)) + c_val[0] = 1; + if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, + 1, 1)) goto _fail_; return 0; @@ -884,14 +732,13 @@ _fail_: return -1; } -/**************************/ void wilc1000_wlan_deinit(struct net_device *dev) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wl; - nic = netdev_priv(dev); - wl = nic->wilc; + vif = netdev_priv(dev); + wl = vif->wilc; if (!wl) { netdev_err(dev, "wl is NULL\n"); @@ -901,20 +748,14 @@ void wilc1000_wlan_deinit(struct net_device *dev) if (wl->initialized) { netdev_info(dev, "Deinitializing wilc1000...\n"); -#if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31) - /* johnny : remove */ - PRINT_D(INIT_DBG, "skip wilc_bus_set_default_speed\n"); -#else - wilc_bus_set_default_speed(); -#endif - PRINT_D(INIT_DBG, "Disabling IRQ\n"); -#ifdef WILC_SDIO - mutex_lock(&wl->hif_cs); - disable_sdio_interrupt(); - mutex_unlock(&wl->hif_cs); -#endif - if (&wl->txq_event != NULL) + if (!wl->dev_irq_num && + wl->hif_func->disable_interrupt) { + mutex_lock(&wl->hif_cs); + wl->hif_func->disable_interrupt(wl); + mutex_unlock(&wl->hif_cs); + } + if (&wl->txq_event) up(&wl->txq_event); PRINT_D(INIT_DBG, "Deinitializing Threads\n"); @@ -923,25 +764,25 @@ void wilc1000_wlan_deinit(struct net_device *dev) PRINT_D(INIT_DBG, "Deinitializing IRQ\n"); deinit_irq(dev); - wilc_wlan_stop(); + wilc_wlan_stop(wl); PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n"); wilc_wlan_cleanup(dev); -#if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) - #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31) - PRINT_D(INIT_DBG, "Disabling IRQ 2\n"); - - mutex_lock(&wl->hif_cs); - disable_sdio_interrupt(); - mutex_unlock(&wl->hif_cs); - #endif +#if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31) + if (!wl->dev_irq_num && + wl->hif_func->disable_interrupt) { + + PRINT_D(INIT_DBG, "Disabling IRQ 2\n"); + + mutex_lock(&wl->hif_cs); + wl->hif_func->disable_interrupt(wl); + mutex_unlock(&wl->hif_cs); + } #endif - /*De-Initialize locks*/ PRINT_D(INIT_DBG, "Deinitializing Locks\n"); wlan_deinit_locks(dev); - /* announce that wilc1000 is not initialized */ wl->initialized = false; PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n"); @@ -951,13 +792,13 @@ void wilc1000_wlan_deinit(struct net_device *dev) } } -int wlan_init_locks(struct net_device *dev) +static int wlan_init_locks(struct net_device *dev) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wl; - nic = netdev_priv(dev); - wl = nic->wilc; + vif = netdev_priv(dev); + wl = vif->wilc; PRINT_D(INIT_DBG, "Initializing Locks ...\n"); @@ -979,105 +820,68 @@ int wlan_init_locks(struct net_device *dev) static int wlan_deinit_locks(struct net_device *dev) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; - nic = netdev_priv(dev); - wilc = nic->wilc; + vif = netdev_priv(dev); + wilc = vif->wilc; PRINT_D(INIT_DBG, "De-Initializing Locks\n"); - if (&wilc->hif_cs != NULL) + if (&wilc->hif_cs) mutex_destroy(&wilc->hif_cs); - if (&wilc->rxq_cs != NULL) + if (&wilc->rxq_cs) mutex_destroy(&wilc->rxq_cs); return 0; } -void linux_to_wlan(wilc_wlan_inp_t *nwi, struct wilc *nic) -{ - - PRINT_D(INIT_DBG, "Linux to Wlan services ...\n"); - - nwi->os_context.os_private = (void *)nic; -#ifdef WILC_SDIO - nwi->io_func.io_type = HIF_SDIO; - nwi->io_func.io_init = linux_sdio_init; - nwi->io_func.io_deinit = linux_sdio_deinit; - nwi->io_func.u.sdio.sdio_cmd52 = linux_sdio_cmd52; - nwi->io_func.u.sdio.sdio_cmd53 = linux_sdio_cmd53; - nwi->io_func.u.sdio.sdio_set_max_speed = linux_sdio_set_max_speed; - nwi->io_func.u.sdio.sdio_set_default_speed = linux_sdio_set_default_speed; -#else - nwi->io_func.io_type = HIF_SPI; - nwi->io_func.io_init = linux_spi_init; - nwi->io_func.io_deinit = linux_spi_deinit; - nwi->io_func.u.spi.spi_tx = linux_spi_write; - nwi->io_func.u.spi.spi_rx = linux_spi_read; - nwi->io_func.u.spi.spi_trx = linux_spi_write_read; - nwi->io_func.u.spi.spi_max_speed = linux_spi_set_max_speed; -#endif -} - -int wlan_initialize_threads(struct net_device *dev) +static int wlan_initialize_threads(struct net_device *dev) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; - int ret = 0; - nic = netdev_priv(dev); - wilc = nic->wilc; + vif = netdev_priv(dev); + wilc = vif->wilc; PRINT_D(INIT_DBG, "Initializing Threads ...\n"); - - /* create tx task */ PRINT_D(INIT_DBG, "Creating kthread for transmission\n"); wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev, "K_TXQ_TASK"); if (!wilc->txq_thread) { PRINT_ER("couldn't create TXQ thread\n"); - ret = -ENOBUFS; - goto _fail_2; + wilc->close = 0; + return -ENOBUFS; } - /* wait for TXQ task to start. */ down(&wilc->txq_thread_started); return 0; - -_fail_2: - /*De-Initialize 2nd thread*/ - wilc->close = 0; - return ret; } static void wlan_deinitialize_threads(struct net_device *dev) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wl; - - nic = netdev_priv(dev); - wl = nic->wilc; + vif = netdev_priv(dev); + wl = vif->wilc; wl->close = 1; PRINT_D(INIT_DBG, "Deinitializing Threads\n"); - if (&wl->txq_event != NULL) + if (&wl->txq_event) up(&wl->txq_event); - if (wl->txq_thread != NULL) { + if (wl->txq_thread) { kthread_stop(wl->txq_thread); wl->txq_thread = NULL; } } -int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic) +int wilc1000_wlan_init(struct net_device *dev, struct wilc_vif *vif) { - wilc_wlan_inp_t nwi; - perInterface_wlan_t *nic = p_nic; int ret = 0; - struct wilc *wl = nic->wilc; + struct wilc *wl = vif->wilc; if (!wl->initialized) { wl->mac_status = WILC_MAC_STATUS_INIT; @@ -1085,22 +889,18 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic) wlan_init_locks(dev); - linux_to_wlan(&nwi, wl); - - ret = wilc_wlan_init(&nwi); + ret = wilc_wlan_init(dev); if (ret < 0) { PRINT_ER("Initializing WILC_Wlan FAILED\n"); ret = -EIO; goto _fail_locks_; } -#if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO) - if (init_irq(dev)) { + if (wl->gpio >= 0 && init_irq(dev)) { PRINT_ER("couldn't initialize IRQ\n"); ret = -EIO; goto _fail_locks_; } -#endif ret = wlan_initialize_threads(dev); if (ret < 0) { @@ -1109,39 +909,35 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic) goto _fail_wilc_wlan_; } -#if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) - if (enable_sdio_interrupt()) { + if (!wl->dev_irq_num && + wl->hif_func->enable_interrupt && + wl->hif_func->enable_interrupt(wl)) { PRINT_ER("couldn't initialize IRQ\n"); ret = -EIO; goto _fail_irq_init_; } -#endif - if (linux_wlan_get_firmware(nic)) { + if (wilc_wlan_get_firmware(dev)) { PRINT_ER("Can't get firmware\n"); ret = -EIO; goto _fail_irq_enable_; } - /*Download firmware*/ - ret = linux_wlan_firmware_download(wl); + ret = wilc1000_firmware_download(dev); if (ret < 0) { PRINT_ER("Failed to download firmware\n"); ret = -EIO; goto _fail_irq_enable_; } - /* Start firmware*/ - ret = linux_wlan_start_firmware(nic); + ret = linux_wlan_start_firmware(dev); if (ret < 0) { PRINT_ER("Failed to start firmware\n"); ret = -EIO; goto _fail_irq_enable_; } - wilc_bus_set_max_speed(); - - if (wilc_wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) { + if (wilc_wlan_cfg_get(wl, 1, WID_FIRMWARE_VERSION, 1, 0)) { int size; char Firmware_ver[20]; @@ -1151,7 +947,6 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic) Firmware_ver[size] = '\0'; PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver); } - /* Initialize firmware with default configuration */ ret = linux_wlan_init_test_config(dev, wl); if (ret < 0) { @@ -1161,20 +956,19 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic) } wl->initialized = true; - return 0; /*success*/ + return 0; _fail_fw_start_: - wilc_wlan_stop(); + wilc_wlan_stop(wl); _fail_irq_enable_: -#if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) - disable_sdio_interrupt(); + if (!wl->dev_irq_num && + wl->hif_func->disable_interrupt) + wl->hif_func->disable_interrupt(wl); _fail_irq_init_: -#endif -#if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO) - deinit_irq(dev); + if (wl->dev_irq_num) + deinit_irq(dev); -#endif wlan_deinitialize_threads(dev); _fail_wilc_wlan_: wilc_wlan_cleanup(dev); @@ -1187,44 +981,36 @@ _fail_locks_: return ret; } -/* - * - this function will be called automatically by OS when module inserted. - */ - -int mac_init_fn(struct net_device *ndev) +static int mac_init_fn(struct net_device *ndev) { - - /*Why we do this !!!*/ - netif_start_queue(ndev); /* ma */ - netif_stop_queue(ndev); /* ma */ + netif_start_queue(ndev); + netif_stop_queue(ndev); return 0; } -/* This fn is called, when this device is setup using ifconfig */ -int mac_open(struct net_device *ndev) +int wilc_mac_open(struct net_device *ndev) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; + struct wilc *wilc; - /*No need for setting mac address here anymore,*/ - /*Just set it in init_test_config()*/ unsigned char mac_add[ETH_ALEN] = {0}; int ret = 0; int i = 0; struct wilc_priv *priv; struct wilc *wl; - nic = netdev_priv(ndev); - wl = nic->wilc; + vif = netdev_priv(ndev); + wl = vif->wilc; -#ifdef WILC_SPI - if (!wl|| !wl->wilc_spidev) { + if (!wl|| !wl->dev) { netdev_err(ndev, "wilc1000: SPI device not ready\n"); return -ENODEV; } -#endif - nic = netdev_priv(ndev); - priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); + + vif = netdev_priv(ndev); + wilc = vif->wilc; + priv = wiphy_priv(vif->ndev->ieee80211_ptr->wiphy); PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev); ret = wilc_init_host_int(ndev); @@ -1234,153 +1020,143 @@ int mac_open(struct net_device *ndev) return ret; } - /*initialize platform*/ PRINT_D(INIT_DBG, "*** re-init ***\n"); - ret = wilc1000_wlan_init(ndev, nic); + ret = wilc1000_wlan_init(ndev, vif); if (ret < 0) { PRINT_ER("Failed to initialize wilc1000\n"); wilc_deinit_host_int(ndev); return ret; } - Set_machw_change_vir_if(ndev, false); + wilc_set_machw_change_vir_if(ndev, false); - host_int_get_MacAddress(priv->hWILCWFIDrv, mac_add); + wilc_get_mac_address(vif, mac_add); PRINT_D(INIT_DBG, "Mac address: %pM\n", mac_add); - /* loop through the NUM of supported devices and set the MAC address */ for (i = 0; i < wl->vif_num; i++) { - if (ndev == wl->vif[i].ndev) { - memcpy(wl->vif[i].src_addr, mac_add, ETH_ALEN); - wl->vif[i].hif_drv = priv->hWILCWFIDrv; + if (ndev == wl->vif[i]->ndev) { + memcpy(wl->vif[i]->src_addr, mac_add, ETH_ALEN); break; } } - /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/ - memcpy(ndev->dev_addr, wl->vif[i].src_addr, ETH_ALEN); + memcpy(ndev->dev_addr, wl->vif[i]->src_addr, ETH_ALEN); if (!is_valid_ether_addr(ndev->dev_addr)) { PRINT_ER("Error: Wrong MAC address\n"); - ret = -EINVAL; - goto _err_; + wilc_deinit_host_int(ndev); + wilc1000_wlan_deinit(ndev); + return -EINVAL; } - wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev->ieee80211_ptr, - nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg); - wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev->ieee80211_ptr, - nic->g_struct_frame_reg[1].frame_type, nic->g_struct_frame_reg[1].reg); + wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy, + vif->ndev->ieee80211_ptr, + vif->g_struct_frame_reg[0].frame_type, + vif->g_struct_frame_reg[0].reg); + wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy, + vif->ndev->ieee80211_ptr, + vif->g_struct_frame_reg[1].frame_type, + vif->g_struct_frame_reg[1].reg); netif_wake_queue(ndev); wl->open_ifcs++; - nic->mac_opened = 1; + vif->mac_opened = 1; return 0; - -_err_: - wilc_deinit_host_int(ndev); - wilc1000_wlan_deinit(ndev); - return ret; } -struct net_device_stats *mac_stats(struct net_device *dev) +static struct net_device_stats *mac_stats(struct net_device *dev) { - perInterface_wlan_t *nic = netdev_priv(dev); + struct wilc_vif *vif= netdev_priv(dev); - return &nic->netstats; + return &vif->netstats; } -/* Setup the multicast filter */ static void wilc_set_multicast_list(struct net_device *dev) { - struct netdev_hw_addr *ha; struct wilc_priv *priv; - struct host_if_drv *pstrWFIDrv; + struct host_if_drv *hif_drv; + struct wilc_vif *vif; int i = 0; priv = wiphy_priv(dev->ieee80211_ptr->wiphy); - pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; + vif = netdev_priv(dev); + hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv; if (!dev) return; - PRINT_D(INIT_DBG, "Setting Multicast List with count = %d.\n", dev->mc.count); + PRINT_D(INIT_DBG, "Setting Multicast List with count = %d.\n", + dev->mc.count); if (dev->flags & IFF_PROMISC) { - /* Normally, we should configure the chip to retrive all packets - * but we don't wanna support this right now */ - /* TODO: add promiscuous mode support */ PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets\n"); return; } - /* If there's more addresses than we handle, get all multicast - * packets and sort them out in software. */ - if ((dev->flags & IFF_ALLMULTI) || (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) { + if ((dev->flags & IFF_ALLMULTI) || + (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) { PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n"); - /* get all multicast packets */ - host_int_setup_multicast_filter(pstrWFIDrv, false, 0); + wilc_setup_multicast_filter(vif, false, 0); return; } - /* No multicast? Just get our own stuff */ if ((dev->mc.count) == 0) { PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n"); - host_int_setup_multicast_filter(pstrWFIDrv, true, 0); + wilc_setup_multicast_filter(vif, true, 0); return; } - /* Store all of the multicast addresses in the hardware filter */ - netdev_for_each_mc_addr(ha, dev) - { - memcpy(gau8MulticastMacAddrList[i], ha->addr, ETH_ALEN); + netdev_for_each_mc_addr(ha, dev) { + memcpy(wilc_multicast_mac_addr_list[i], ha->addr, ETH_ALEN); PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i, - gau8MulticastMacAddrList[i][0], gau8MulticastMacAddrList[i][1], gau8MulticastMacAddrList[i][2], gau8MulticastMacAddrList[i][3], gau8MulticastMacAddrList[i][4], gau8MulticastMacAddrList[i][5]); + wilc_multicast_mac_addr_list[i][0], + wilc_multicast_mac_addr_list[i][1], + wilc_multicast_mac_addr_list[i][2], + wilc_multicast_mac_addr_list[i][3], + wilc_multicast_mac_addr_list[i][4], + wilc_multicast_mac_addr_list[i][5]); i++; } - host_int_setup_multicast_filter(pstrWFIDrv, true, (dev->mc.count)); + wilc_setup_multicast_filter(vif, true, (dev->mc.count)); return; - } static void linux_wlan_tx_complete(void *priv, int status) { - struct tx_complete_data *pv_data = (struct tx_complete_data *)priv; if (status == 1) PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb); else PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb); - /* Free the SK Buffer, its work is done */ dev_kfree_skb(pv_data->skb); kfree(pv_data); } -int mac_xmit(struct sk_buff *skb, struct net_device *ndev) +int wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct tx_complete_data *tx_data = NULL; - int QueueCount; - char *pu8UdpBuffer; + int queue_count; + char *udp_buf; struct iphdr *ih; struct ethhdr *eth_h; struct wilc *wilc; - nic = netdev_priv(ndev); - wilc = nic->wilc; + vif = netdev_priv(ndev); + wilc = vif->wilc; PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n"); - /* Stop the network interface queue */ if (skb->dev != ndev) { PRINT_ER("Packet not destined to this device\n"); return 0; } - tx_data = kmalloc(sizeof(struct tx_complete_data), GFP_ATOMIC); - if (tx_data == NULL) { + tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC); + if (!tx_data) { PRINT_ER("Failed to allocate memory for tx_data structure\n"); dev_kfree_skb(skb); netif_wake_queue(ndev); @@ -1395,59 +1171,55 @@ int mac_xmit(struct sk_buff *skb, struct net_device *ndev) if (eth_h->h_proto == 0x8e88) PRINT_D(INIT_DBG, "EAPOL transmitted\n"); - /*get source and dest ip addresses*/ ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr)); - pu8UdpBuffer = (char *)ih + sizeof(struct iphdr); - if ((pu8UdpBuffer[1] == 68 && pu8UdpBuffer[3] == 67) || (pu8UdpBuffer[1] == 67 && pu8UdpBuffer[3] == 68)) - PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer[248], pu8UdpBuffer[249], pu8UdpBuffer[250]); + udp_buf = (char *)ih + sizeof(struct iphdr); + if ((udp_buf[1] == 68 && udp_buf[3] == 67) || + (udp_buf[1] == 67 && udp_buf[3] == 68)) + PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", + udp_buf[248], udp_buf[249], udp_buf[250]); PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb); - - /* Send packet to MAC HW - for now the tx_complete function will be just status - * indicator. still not sure if I need to suspend host transmission till the tx_complete - * function called or not? - * allocated buffer will be freed in tx_complete function. - */ PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n"); - nic->netstats.tx_packets++; - nic->netstats.tx_bytes += tx_data->size; - tx_data->pBssid = wilc->vif[nic->u8IfIdx].bssid; - QueueCount = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data, - tx_data->buff, tx_data->size, - linux_wlan_tx_complete); - - if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) { - netif_stop_queue(wilc->vif[0].ndev); - netif_stop_queue(wilc->vif[1].ndev); + vif->netstats.tx_packets++; + vif->netstats.tx_bytes += tx_data->size; + tx_data->pBssid = wilc->vif[vif->u8IfIdx]->bssid; + queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data, + tx_data->buff, tx_data->size, + linux_wlan_tx_complete); + + if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) { + netif_stop_queue(wilc->vif[0]->ndev); + netif_stop_queue(wilc->vif[1]->ndev); } return 0; } -int mac_close(struct net_device *ndev) +int wilc_mac_close(struct net_device *ndev) { struct wilc_priv *priv; - perInterface_wlan_t *nic; - struct host_if_drv *pstrWFIDrv; + struct wilc_vif *vif; + struct host_if_drv *hif_drv; struct wilc *wl; - nic = netdev_priv(ndev); + vif = netdev_priv(ndev); - if ((nic == NULL) || (nic->wilc_netdev == NULL) || (nic->wilc_netdev->ieee80211_ptr == NULL) || (nic->wilc_netdev->ieee80211_ptr->wiphy == NULL)) { - PRINT_ER("nic = NULL\n"); + if (!vif || !vif->ndev || !vif->ndev->ieee80211_ptr || + !vif->ndev->ieee80211_ptr->wiphy) { + PRINT_ER("vif = NULL\n"); return 0; } - priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); - wl = nic->wilc; + priv = wiphy_priv(vif->ndev->ieee80211_ptr->wiphy); + wl = vif->wilc; - if (priv == NULL) { + if (!priv) { PRINT_ER("priv = NULL\n"); return 0; } - pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; + hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv; PRINT_D(GENERIC_DBG, "Mac close\n"); @@ -1456,8 +1228,8 @@ int mac_close(struct net_device *ndev) return 0; } - if (pstrWFIDrv == NULL) { - PRINT_ER("pstrWFIDrv = NULL\n"); + if (!hif_drv) { + PRINT_ER("hif_drv = NULL\n"); return 0; } @@ -1468,11 +1240,10 @@ int mac_close(struct net_device *ndev) return 0; } - if (nic->wilc_netdev != NULL) { - /* Stop the network interface queue */ - netif_stop_queue(nic->wilc_netdev); + if (vif->ndev) { + netif_stop_queue(vif->ndev); - wilc_deinit_host_int(nic->wilc_netdev); + wilc_deinit_host_int(vif->ndev); } if (wl->open_ifcs == 0) { @@ -1483,59 +1254,54 @@ int mac_close(struct net_device *ndev) } up(&close_exit_sync); - nic->mac_opened = 0; + vif->mac_opened = 0; return 0; } -int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) +static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) { - u8 *buff = NULL; s8 rssi; u32 size = 0, length = 0; - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc_priv *priv; - s32 s32Error = 0; + s32 ret = 0; struct wilc *wilc; - /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */ - nic = netdev_priv(ndev); - wilc = nic->wilc; + vif = netdev_priv(ndev); + wilc = vif->wilc; if (!wilc->initialized) return 0; switch (cmd) { - - /* ]] 2013-06-24 */ case SIOCSIWPRIV: { - struct iwreq *wrq = (struct iwreq *) req; /* added by tony */ + struct iwreq *wrq = (struct iwreq *) req; size = wrq->u.data.length; if (size && wrq->u.data.pointer) { - - buff = memdup_user(wrq->u.data.pointer, wrq->u.data.length); + buff = memdup_user(wrq->u.data.pointer, + wrq->u.data.length); if (IS_ERR(buff)) return PTR_ERR(buff); if (strncasecmp(buff, "RSSI", length) == 0) { - priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); - s32Error = host_int_get_rssi(priv->hWILCWFIDrv, &(rssi)); - if (s32Error) + priv = wiphy_priv(vif->ndev->ieee80211_ptr->wiphy); + ret = wilc_get_rssi(vif, &rssi); + if (ret) PRINT_ER("Failed to send get rssi param's message queue "); PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi); - /*Rounding up the rssi negative value*/ rssi += 5; snprintf(buff, size, "rssi %d", rssi); if (copy_to_user(wrq->u.data.pointer, buff, size)) { PRINT_ER("%s: failed to copy data to user buffer\n", __func__); - s32Error = -EFAULT; + ret = -EFAULT; goto done; } } @@ -1546,7 +1312,7 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) default: { PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd); - s32Error = -EOPNOTSUPP; + ret = -EOPNOTSUPP; goto done; } } @@ -1555,64 +1321,47 @@ done: kfree(buff); - return s32Error; + return ret; } -void frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset) +void wilc_frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset) { - unsigned int frame_len = 0; int stats; unsigned char *buff_to_send = NULL; struct sk_buff *skb; struct net_device *wilc_netdev; - perInterface_wlan_t *nic; + struct wilc_vif *vif; - wilc_netdev = GetIfHandler(wilc, buff); - if (wilc_netdev == NULL) + wilc_netdev = get_if_handler(wilc, buff); + if (!wilc_netdev) return; buff += pkt_offset; - nic = netdev_priv(wilc_netdev); + vif = netdev_priv(wilc_netdev); if (size > 0) { - frame_len = size; buff_to_send = buff; - /* Need to send the packet up to the host, allocate a skb buffer */ skb = dev_alloc_skb(frame_len); - if (skb == NULL) { + if (!skb) { PRINT_ER("Low memory - packet droped\n"); return; } - if (wilc == NULL || wilc_netdev == NULL) + if (!wilc || !wilc_netdev) PRINT_ER("wilc_netdev in wilc is NULL"); skb->dev = wilc_netdev; - if (skb->dev == NULL) + if (!skb->dev) PRINT_ER("skb->dev is NULL\n"); - /* - * for(i=0;i<40;i++) - * { - * if(i<frame_len) - * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]); - * - * }*/ - - /* skb_put(skb, frame_len); */ memcpy(skb_put(skb, frame_len), buff_to_send, frame_len); - /* WILC_PRINTF("After MEM_CPY\n"); */ - - /* nic = netdev_priv(wilc_netdev); */ - skb->protocol = eth_type_trans(skb, wilc_netdev); - /* Send the packet to the stack by giving it to the bridge */ - nic->netstats.rx_packets++; - nic->netstats.rx_bytes += frame_len; + vif->netstats.rx_packets++; + vif->netstats.rx_bytes += frame_len; skb->ip_summed = CHECKSUM_UNNECESSARY; stats = netif_rx(skb); PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats); @@ -1622,211 +1371,132 @@ void frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset) void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size) { int i = 0; - perInterface_wlan_t *nic; + struct wilc_vif *vif; - /*Pass the frame on the monitor interface, if any.*/ - /*Otherwise, pass it on p2p0 netdev, if registered on it*/ for (i = 0; i < wilc->vif_num; i++) { - nic = netdev_priv(wilc->vif[i].ndev); - if (nic->monitor_flag) { + vif = netdev_priv(wilc->vif[i]->ndev); + if (vif->monitor_flag) { WILC_WFI_monitor_rx(buff, size); return; } } - nic = netdev_priv(wilc->vif[1].ndev); /* p2p0 */ - if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) || - (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg)) - WILC_WFI_p2p_rx(wilc->vif[1].ndev, buff, size); + vif = netdev_priv(wilc->vif[1]->ndev); + if ((buff[0] == vif->g_struct_frame_reg[0].frame_type && vif->g_struct_frame_reg[0].reg) || + (buff[0] == vif->g_struct_frame_reg[1].frame_type && vif->g_struct_frame_reg[1].reg)) + WILC_WFI_p2p_rx(wilc->vif[1]->ndev, buff, size); } -void wl_wlan_cleanup(void) +void wilc_netdev_cleanup(struct wilc *wilc) { int i = 0; - perInterface_wlan_t *nic[NUM_CONCURRENT_IFC]; + struct wilc_vif *vif[NUM_CONCURRENT_IFC]; - if (g_linux_wlan && - (g_linux_wlan->vif[0].ndev || g_linux_wlan->vif[1].ndev)) { + if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) { unregister_inetaddr_notifier(&g_dev_notifier); for (i = 0; i < NUM_CONCURRENT_IFC; i++) - nic[i] = netdev_priv(g_linux_wlan->vif[i].ndev); + vif[i] = netdev_priv(wilc->vif[i]->ndev); } - if (g_linux_wlan && g_linux_wlan->firmware) - release_firmware(g_linux_wlan->firmware); + if (wilc && wilc->firmware) + release_firmware(wilc->firmware); - if (g_linux_wlan && - (g_linux_wlan->vif[0].ndev || g_linux_wlan->vif[1].ndev)) { - linux_wlan_lock_timeout(&close_exit_sync, 12 * 1000); + if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) { + wilc_lock_timeout(wilc, &close_exit_sync, 12 * 1000); for (i = 0; i < NUM_CONCURRENT_IFC; i++) - if (g_linux_wlan->vif[i].ndev) - if (nic[i]->mac_opened) - mac_close(g_linux_wlan->vif[i].ndev); + if (wilc->vif[i]->ndev) + if (vif[i]->mac_opened) + wilc_mac_close(wilc->vif[i]->ndev); for (i = 0; i < NUM_CONCURRENT_IFC; i++) { - unregister_netdev(g_linux_wlan->vif[i].ndev); - wilc_free_wiphy(g_linux_wlan->vif[i].ndev); - free_netdev(g_linux_wlan->vif[i].ndev); + unregister_netdev(wilc->vif[i]->ndev); + wilc_free_wiphy(wilc->vif[i]->ndev); + free_netdev(wilc->vif[i]->ndev); } } - kfree(g_linux_wlan); - -#if defined(WILC_DEBUGFS) - wilc_debugfs_remove(); -#endif - linux_wlan_device_detection(0); - linux_wlan_device_power(0); + kfree(wilc); } +EXPORT_SYMBOL_GPL(wilc_netdev_cleanup); -int wilc_netdev_init(struct wilc **wilc) +int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type, + int gpio, const struct wilc_hif_func *ops) { int i; - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct net_device *ndev; + struct wilc *wl; sema_init(&close_exit_sync, 0); - /*create the common structure*/ - g_linux_wlan = kzalloc(sizeof(*g_linux_wlan), GFP_KERNEL); - if (!g_linux_wlan) + wl = kzalloc(sizeof(*wl), GFP_KERNEL); + if (!wl) return -ENOMEM; - *wilc = g_linux_wlan; + *wilc = wl; + wl->io_type = io_type; + wl->gpio = gpio; + wl->hif_func = ops; register_inetaddr_notifier(&g_dev_notifier); for (i = 0; i < NUM_CONCURRENT_IFC; i++) { - /*allocate first ethernet device with perinterface_wlan_t as its private data*/ - ndev = alloc_etherdev(sizeof(perInterface_wlan_t)); + ndev = alloc_etherdev(sizeof(struct wilc_vif)); if (!ndev) { PRINT_ER("Failed to allocate ethernet dev\n"); return -1; } - nic = netdev_priv(ndev); - memset(nic, 0, sizeof(perInterface_wlan_t)); + vif = netdev_priv(ndev); + memset(vif, 0, sizeof(struct wilc_vif)); - /*Name the Devices*/ - if (i == 0) { - #if defined(NM73131) /* tony, 2012-09-20 */ - strcpy(ndev->name, "wilc_eth%d"); - #elif defined(PLAT_CLM9722) /* rachel */ - strcpy(ndev->name, "eth%d"); - #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */ + if (i == 0) strcpy(ndev->name, "wlan%d"); - #endif - } else + else strcpy(ndev->name, "p2p%d"); - nic->u8IfIdx = g_linux_wlan->vif_num; - nic->wilc_netdev = ndev; - nic->wilc = *wilc; - g_linux_wlan->vif[g_linux_wlan->vif_num].ndev = ndev; - g_linux_wlan->vif_num++; + vif->u8IfIdx = wl->vif_num; + vif->wilc = *wilc; + wl->vif[i] = vif; + wl->vif[wl->vif_num]->ndev = ndev; + wl->vif_num++; ndev->netdev_ops = &wilc_netdev_ops; { struct wireless_dev *wdev; - /*Register WiFi*/ - wdev = wilc_create_wiphy(ndev); + wdev = wilc_create_wiphy(ndev, dev); - #ifdef WILC_SDIO - /* set netdev, tony */ - SET_NETDEV_DEV(ndev, &local_sdio_func->dev); - #endif + if (dev) + SET_NETDEV_DEV(ndev, dev); - if (wdev == NULL) { + if (!wdev) { PRINT_ER("Can't register WILC Wiphy\n"); return -1; } - /*linking the wireless_dev structure with the netdevice*/ - nic->wilc_netdev->ieee80211_ptr = wdev; - nic->wilc_netdev->ml_priv = nic; - wdev->netdev = nic->wilc_netdev; - nic->netstats.rx_packets = 0; - nic->netstats.tx_packets = 0; - nic->netstats.rx_bytes = 0; - nic->netstats.tx_bytes = 0; - + vif->ndev->ieee80211_ptr = wdev; + vif->ndev->ml_priv = vif; + wdev->netdev = vif->ndev; + vif->netstats.rx_packets = 0; + vif->netstats.tx_packets = 0; + vif->netstats.rx_bytes = 0; + vif->netstats.tx_bytes = 0; } if (register_netdev(ndev)) { - PRINT_ER("Device couldn't be registered - %s\n", ndev->name); - return -1; /* ERROR */ + PRINT_ER("Device couldn't be registered - %s\n", + ndev->name); + return -1; } - nic->iftype = STATION_MODE; - nic->mac_opened = 0; - - } - - #ifndef WILC_SDIO - if (!linux_spi_init(&g_linux_wlan->wilc_spidev)) { - PRINT_ER("Can't initialize SPI\n"); - return -1; /* ERROR */ + vif->iftype = STATION_MODE; + vif->mac_opened = 0; } - g_linux_wlan->wilc_spidev = wilc_spi_dev; - #else - g_linux_wlan->wilc_sdio_func = local_sdio_func; - #endif return 0; } - -/*The 1st function called after module inserted*/ -static int __init init_wilc_driver(void) -{ -#ifdef WILC_SPI - struct wilc *wilc; -#endif - -#if defined(WILC_DEBUGFS) - if (wilc_debugfs_init() < 0) { - PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n"); - return -1; - } -#endif - - printk("IN INIT FUNCTION\n"); - printk("*** WILC1000 driver VERSION=[10.2] FW_VER=[10.2] ***\n"); - - linux_wlan_device_power(1); - msleep(100); - linux_wlan_device_detection(1); - -#ifdef WILC_SDIO - { - int ret; - - ret = sdio_register_driver(&wilc_bus); - if (ret < 0) - PRINT_D(INIT_DBG, "init_wilc_driver: Failed register sdio driver\n"); - - return ret; - } -#else - PRINT_D(INIT_DBG, "Initializing netdev\n"); - if (wilc_netdev_init(&wilc)) - PRINT_ER("Couldn't initialize netdev\n"); - return 0; -#endif -} -late_initcall(init_wilc_driver); - -static void __exit exit_wilc_driver(void) -{ -#ifndef WILC_SDIO - PRINT_D(INIT_DBG, "SPI unregister...\n"); - spi_unregister_driver(&wilc_bus); -#else - PRINT_D(INIT_DBG, "SDIO unregister...\n"); - sdio_unregister_driver(&wilc_bus); -#endif -} -module_exit(exit_wilc_driver); +EXPORT_SYMBOL_GPL(wilc_netdev_init); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/wilc1000/linux_wlan_common.h b/drivers/staging/wilc1000/linux_wlan_common.h index 2b76e41ebd4d..5d40f05124c1 100644 --- a/drivers/staging/wilc1000/linux_wlan_common.h +++ b/drivers/staging/wilc1000/linux_wlan_common.h @@ -38,11 +38,8 @@ enum debug_region { #define FIRM_DBG (1 << Firmware_debug) #if defined (WILC_DEBUGFS) -int wilc_debugfs_init(void); -void wilc_debugfs_remove(void); - -extern atomic_t REGION; -extern atomic_t DEBUG_LEVEL; +extern atomic_t WILC_REGION; +extern atomic_t WILC_DEBUG_LEVEL; #define DEBUG BIT(0) #define INFO BIT(1) @@ -51,8 +48,8 @@ extern atomic_t DEBUG_LEVEL; #define PRINT_D(region, ...) \ do { \ - if ((atomic_read(&DEBUG_LEVEL) & DEBUG) && \ - ((atomic_read(®ION)) & (region))) { \ + if ((atomic_read(&WILC_DEBUG_LEVEL) & DEBUG) && \ + ((atomic_read(&WILC_REGION)) & (region))) { \ printk("DBG [%s: %d]", __func__, __LINE__); \ printk(__VA_ARGS__); \ } \ @@ -60,8 +57,8 @@ extern atomic_t DEBUG_LEVEL; #define PRINT_INFO(region, ...) \ do { \ - if ((atomic_read(&DEBUG_LEVEL) & INFO) && \ - ((atomic_read(®ION)) & (region))) { \ + if ((atomic_read(&WILC_DEBUG_LEVEL) & INFO) && \ + ((atomic_read(&WILC_REGION)) & (region))) { \ printk("INFO [%s]", __func__); \ printk(__VA_ARGS__); \ } \ @@ -69,8 +66,8 @@ extern atomic_t DEBUG_LEVEL; #define PRINT_WRN(region, ...) \ do { \ - if ((atomic_read(&DEBUG_LEVEL) & WRN) && \ - ((atomic_read(®ION)) & (region))) { \ + if ((atomic_read(&WILC_DEBUG_LEVEL) & WRN) && \ + ((atomic_read(&WILC_REGION)) & (region))) { \ printk("WRN [%s: %d]", __func__, __LINE__); \ printk(__VA_ARGS__); \ } \ @@ -78,7 +75,7 @@ extern atomic_t DEBUG_LEVEL; #define PRINT_ER(...) \ do { \ - if ((atomic_read(&DEBUG_LEVEL) & ERR)) { \ + if ((atomic_read(&WILC_DEBUG_LEVEL) & ERR)) { \ printk("ERR [%s: %d]", __func__, __LINE__); \ printk(__VA_ARGS__); \ } \ @@ -121,14 +118,13 @@ extern atomic_t DEBUG_LEVEL; printk("ERR [%s: %d]", __func__, __LINE__); \ printk(__VA_ARGS__); \ } while (0) + #endif #define FN_IN /* PRINT_D(">>> \n") */ #define FN_OUT /* PRINT_D("<<<\n") */ -#ifdef MEMORY_STATIC #define LINUX_RX_SIZE (96 * 1024) -#endif #define LINUX_TX_SIZE (64 * 1024) diff --git a/drivers/staging/wilc1000/linux_wlan_sdio.c b/drivers/staging/wilc1000/linux_wlan_sdio.c deleted file mode 100644 index 4aff953a88f1..000000000000 --- a/drivers/staging/wilc1000/linux_wlan_sdio.c +++ /dev/null @@ -1,251 +0,0 @@ -#include "wilc_wfi_netdevice.h" - -#include <linux/mmc/sdio_func.h> -#include <linux/mmc/card.h> -#include <linux/mmc/sdio_ids.h> -#include <linux/mmc/sdio.h> -#include <linux/mmc/host.h> - - - -#define SDIO_MODALIAS "wilc1000_sdio" - -#if defined(CUSTOMER_PLATFORM) -/* TODO : User have to stable bus clock as user's environment. */ - #ifdef MAX_BUS_SPEED - #define MAX_SPEED MAX_BUS_SPEED - #else - #define MAX_SPEED 50000000 - #endif -#else - #define MAX_SPEED (6 * 1000000) /* Max 50M */ -#endif - -struct wilc_sdio { - struct sdio_func *func; - struct wilc *wilc; -}; - -struct sdio_func *local_sdio_func; - -static unsigned int sdio_default_speed; - -#define SDIO_VENDOR_ID_WILC 0x0296 -#define SDIO_DEVICE_ID_WILC 0x5347 - -static const struct sdio_device_id wilc_sdio_ids[] = { - { SDIO_DEVICE(SDIO_VENDOR_ID_WILC, SDIO_DEVICE_ID_WILC) }, - { }, -}; - - -static void wilc_sdio_interrupt(struct sdio_func *func) -{ - struct wilc_sdio *wl_sdio; - - wl_sdio = sdio_get_drvdata(func); - -#ifndef WILC_SDIO_IRQ_GPIO - sdio_release_host(func); - wilc_handle_isr(wl_sdio->wilc); - sdio_claim_host(func); -#endif -} - - -int linux_sdio_cmd52(sdio_cmd52_t *cmd) -{ - struct sdio_func *func = g_linux_wlan->wilc_sdio_func; - int ret; - u8 data; - - sdio_claim_host(func); - - func->num = cmd->function; - if (cmd->read_write) { /* write */ - if (cmd->raw) { - sdio_writeb(func, cmd->data, cmd->address, &ret); - data = sdio_readb(func, cmd->address, &ret); - cmd->data = data; - } else { - sdio_writeb(func, cmd->data, cmd->address, &ret); - } - } else { /* read */ - data = sdio_readb(func, cmd->address, &ret); - cmd->data = data; - } - - sdio_release_host(func); - - if (ret < 0) { - PRINT_ER("wilc_sdio_cmd52..failed, err(%d)\n", ret); - return 0; - } - return 1; -} - - -int linux_sdio_cmd53(sdio_cmd53_t *cmd) -{ - struct sdio_func *func = g_linux_wlan->wilc_sdio_func; - int size, ret; - - sdio_claim_host(func); - - func->num = cmd->function; - func->cur_blksize = cmd->block_size; - if (cmd->block_mode) - size = cmd->count * cmd->block_size; - else - size = cmd->count; - - if (cmd->read_write) { /* write */ - ret = sdio_memcpy_toio(func, cmd->address, (void *)cmd->buffer, size); - } else { /* read */ - ret = sdio_memcpy_fromio(func, (void *)cmd->buffer, cmd->address, size); - } - - sdio_release_host(func); - - - if (ret < 0) { - PRINT_ER("wilc_sdio_cmd53..failed, err(%d)\n", ret); - return 0; - } - - return 1; -} - -static int linux_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id) -{ - struct wilc_sdio *wl_sdio; - struct wilc *wilc; - - PRINT_D(INIT_DBG, "probe function\n"); - wl_sdio = kzalloc(sizeof(struct wilc_sdio), GFP_KERNEL); - if (!wl_sdio) - return -ENOMEM; - - PRINT_D(INIT_DBG, "Initializing netdev\n"); - local_sdio_func = func; - if (wilc_netdev_init(&wilc)) { - PRINT_ER("Couldn't initialize netdev\n"); - kfree(wl_sdio); - return -1; - } - wl_sdio->func = func; - wl_sdio->wilc = wilc; - sdio_set_drvdata(func, wl_sdio); - - printk("Driver Initializing success\n"); - return 0; -} - -static void linux_sdio_remove(struct sdio_func *func) -{ - struct wilc_sdio *wl_sdio; - - wl_sdio = sdio_get_drvdata(func); - wl_wlan_cleanup(); - kfree(wl_sdio); -} - -struct sdio_driver wilc_bus = { - .name = SDIO_MODALIAS, - .id_table = wilc_sdio_ids, - .probe = linux_sdio_probe, - .remove = linux_sdio_remove, -}; - -int enable_sdio_interrupt(void) -{ - int ret = 0; -#ifndef WILC_SDIO_IRQ_GPIO - - sdio_claim_host(local_sdio_func); - ret = sdio_claim_irq(local_sdio_func, wilc_sdio_interrupt); - sdio_release_host(local_sdio_func); - - if (ret < 0) { - PRINT_ER("can't claim sdio_irq, err(%d)\n", ret); - ret = -EIO; - } -#endif - return ret; -} - -void disable_sdio_interrupt(void) -{ - -#ifndef WILC_SDIO_IRQ_GPIO - int ret; - - PRINT_D(INIT_DBG, "disable_sdio_interrupt IN\n"); - - sdio_claim_host(local_sdio_func); - ret = sdio_release_irq(local_sdio_func); - if (ret < 0) { - PRINT_ER("can't release sdio_irq, err(%d)\n", ret); - } - sdio_release_host(local_sdio_func); - - PRINT_D(INIT_DBG, "disable_sdio_interrupt OUT\n"); -#endif -} - -static int linux_sdio_set_speed(int speed) -{ - struct mmc_ios ios; - - sdio_claim_host(local_sdio_func); - - memcpy((void *)&ios, (void *)&local_sdio_func->card->host->ios, sizeof(struct mmc_ios)); - local_sdio_func->card->host->ios.clock = speed; - ios.clock = speed; - local_sdio_func->card->host->ops->set_ios(local_sdio_func->card->host, &ios); - sdio_release_host(local_sdio_func); - PRINT_INFO(INIT_DBG, "@@@@@@@@@@@@ change SDIO speed to %d @@@@@@@@@\n", speed); - - return 1; -} - -static int linux_sdio_get_speed(void) -{ - return local_sdio_func->card->host->ios.clock; -} - -int linux_sdio_init(void *pv) -{ - - /** - * TODO : - **/ - - - sdio_default_speed = linux_sdio_get_speed(); - return 1; -} - -void linux_sdio_deinit(void *pv) -{ - - /** - * TODO : - **/ - - - sdio_unregister_driver(&wilc_bus); -} - -int linux_sdio_set_max_speed(void) -{ - return linux_sdio_set_speed(MAX_SPEED); -} - -int linux_sdio_set_default_speed(void) -{ - return linux_sdio_set_speed(sdio_default_speed); -} - - - diff --git a/drivers/staging/wilc1000/linux_wlan_sdio.h b/drivers/staging/wilc1000/linux_wlan_sdio.h deleted file mode 100644 index 4b515f5108e7..000000000000 --- a/drivers/staging/wilc1000/linux_wlan_sdio.h +++ /dev/null @@ -1,14 +0,0 @@ -extern struct sdio_func *local_sdio_func; -extern struct sdio_driver wilc_bus; - -#include <linux/mmc/sdio_func.h> - -int linux_sdio_init(void *); -void linux_sdio_deinit(void *); -int linux_sdio_cmd52(sdio_cmd52_t *cmd); -int linux_sdio_cmd53(sdio_cmd53_t *cmd); -int enable_sdio_interrupt(void); -void disable_sdio_interrupt(void); -int linux_sdio_set_max_speed(void); -int linux_sdio_set_default_speed(void); - diff --git a/drivers/staging/wilc1000/linux_wlan_spi.c b/drivers/staging/wilc1000/linux_wlan_spi.c deleted file mode 100644 index 039d06192d6b..000000000000 --- a/drivers/staging/wilc1000/linux_wlan_spi.c +++ /dev/null @@ -1,409 +0,0 @@ -#include <linux/module.h> -#include <linux/init.h> -#include <linux/kernel.h> -#include <linux/fs.h> -#include <linux/slab.h> -#include <linux/types.h> -#include <linux/cdev.h> -#include <linux/uaccess.h> -#include <linux/device.h> -#include <linux/spi/spi.h> - -#include "linux_wlan_common.h" -#include "linux_wlan_spi.h" - -#define USE_SPI_DMA 0 /* johnny add */ - -#ifdef WILC_ASIC_A0 - #if defined(PLAT_PANDA_ES_OMAP4460) - #define MIN_SPEED 12000000 - #define MAX_SPEED 24000000 - #elif defined(PLAT_WMS8304) - #define MIN_SPEED 12000000 - #define MAX_SPEED 24000000 /* 4000000 */ - #elif defined(CUSTOMER_PLATFORM) -/* - TODO : define Clock speed under 48M. - * - * ex) - * #define MIN_SPEED 24000000 - * #define MAX_SPEED 48000000 - */ - #else - #define MIN_SPEED 24000000 - #define MAX_SPEED 48000000 - #endif -#else /* WILC_ASIC_A0 */ -/* Limit clk to 6MHz on FPGA. */ - #define MIN_SPEED 6000000 - #define MAX_SPEED 6000000 -#endif /* WILC_ASIC_A0 */ - -static u32 SPEED = MIN_SPEED; - -struct spi_device *wilc_spi_dev; -void linux_spi_deinit(void *vp); - -static int __init wilc_bus_probe(struct spi_device *spi) -{ - - PRINT_D(BUS_DBG, "spiModalias: %s\n", spi->modalias); - PRINT_D(BUS_DBG, "spiMax-Speed: %d\n", spi->max_speed_hz); - wilc_spi_dev = spi; - - printk("Driver Initializing success\n"); - return 0; -} - -static int __exit wilc_bus_remove(struct spi_device *spi) -{ - - return 0; -} - -#ifdef CONFIG_OF -static const struct of_device_id wilc1000_of_match[] = { - { .compatible = "atmel,wilc_spi", }, - {} -}; -MODULE_DEVICE_TABLE(of, wilc1000_of_match); -#endif - -struct spi_driver wilc_bus __refdata = { - .driver = { - .name = MODALIAS, -#ifdef CONFIG_OF - .of_match_table = wilc1000_of_match, -#endif - }, - .probe = wilc_bus_probe, - .remove = __exit_p(wilc_bus_remove), -}; - - -void linux_spi_deinit(void *vp) -{ - - spi_unregister_driver(&wilc_bus); - - SPEED = MIN_SPEED; - PRINT_ER("@@@@@@@@@@@@ restore SPI speed to %d @@@@@@@@@\n", SPEED); - -} - - - -int linux_spi_init(void *vp) -{ - int ret = 1; - static int called; - - - if (called == 0) { - called++; - ret = spi_register_driver(&wilc_bus); - } - - /* change return value to match WILC interface */ - (ret < 0) ? (ret = 0) : (ret = 1); - - return ret; -} - -#if defined(PLAT_WMS8304) -#define TXRX_PHASE_SIZE (4096) -#endif - -#if defined(TXRX_PHASE_SIZE) - -int linux_spi_write(u8 *b, u32 len) -{ - int ret; - - if (len > 0 && b != NULL) { - int i = 0; - int blk = len / TXRX_PHASE_SIZE; - int remainder = len % TXRX_PHASE_SIZE; - - char *r_buffer = kzalloc(TXRX_PHASE_SIZE, GFP_KERNEL); - if (!r_buffer) - return -ENOMEM; - - if (blk) { - while (i < blk) { - struct spi_message msg; - struct spi_transfer tr = { - .tx_buf = b + (i * TXRX_PHASE_SIZE), - .len = TXRX_PHASE_SIZE, - .speed_hz = SPEED, - .bits_per_word = 8, - .delay_usecs = 0, - }; - - tr.rx_buf = r_buffer; - - memset(&msg, 0, sizeof(msg)); - spi_message_init(&msg); - msg.spi = wilc_spi_dev; - msg.is_dma_mapped = USE_SPI_DMA; - - spi_message_add_tail(&tr, &msg); - ret = spi_sync(wilc_spi_dev, &msg); - if (ret < 0) { - PRINT_ER("SPI transaction failed\n"); - } - i++; - - } - } - if (remainder) { - struct spi_message msg; - struct spi_transfer tr = { - .tx_buf = b + (blk * TXRX_PHASE_SIZE), - .len = remainder, - .speed_hz = SPEED, - .bits_per_word = 8, - .delay_usecs = 0, - }; - tr.rx_buf = r_buffer; - - memset(&msg, 0, sizeof(msg)); - spi_message_init(&msg); - msg.spi = wilc_spi_dev; - msg.is_dma_mapped = USE_SPI_DMA; /* rachel */ - - spi_message_add_tail(&tr, &msg); - ret = spi_sync(wilc_spi_dev, &msg); - if (ret < 0) { - PRINT_ER("SPI transaction failed\n"); - } - } - kfree(r_buffer); - } else { - PRINT_ER("can't write data with the following length: %d\n", len); - PRINT_ER("FAILED due to NULL buffer or ZERO length check the following length: %d\n", len); - ret = -1; - } - - /* change return value to match WILC interface */ - (ret < 0) ? (ret = 0) : (ret = 1); - - return ret; - -} - -#else -int linux_spi_write(u8 *b, u32 len) -{ - - int ret; - struct spi_message msg; - - if (len > 0 && b != NULL) { - struct spi_transfer tr = { - .tx_buf = b, - .len = len, - .speed_hz = SPEED, - .delay_usecs = 0, - }; - char *r_buffer = kzalloc(len, GFP_KERNEL); - if (!r_buffer) - return -ENOMEM; - - tr.rx_buf = r_buffer; - PRINT_D(BUS_DBG, "Request writing %d bytes\n", len); - - memset(&msg, 0, sizeof(msg)); - spi_message_init(&msg); -/* [[johnny add */ - msg.spi = wilc_spi_dev; - msg.is_dma_mapped = USE_SPI_DMA; -/* ]] */ - spi_message_add_tail(&tr, &msg); - - ret = spi_sync(wilc_spi_dev, &msg); - if (ret < 0) { - PRINT_ER("SPI transaction failed\n"); - } - - kfree(r_buffer); - } else { - PRINT_ER("can't write data with the following length: %d\n", len); - PRINT_ER("FAILED due to NULL buffer or ZERO length check the following length: %d\n", len); - ret = -1; - } - - /* change return value to match WILC interface */ - (ret < 0) ? (ret = 0) : (ret = 1); - - - return ret; -} - -#endif - -#if defined(TXRX_PHASE_SIZE) - -int linux_spi_read(u8 *rb, u32 rlen) -{ - int ret; - - if (rlen > 0) { - int i = 0; - - int blk = rlen / TXRX_PHASE_SIZE; - int remainder = rlen % TXRX_PHASE_SIZE; - - char *t_buffer = kzalloc(TXRX_PHASE_SIZE, GFP_KERNEL); - if (!t_buffer) - return -ENOMEM; - - if (blk) { - while (i < blk) { - struct spi_message msg; - struct spi_transfer tr = { - .rx_buf = rb + (i * TXRX_PHASE_SIZE), - .len = TXRX_PHASE_SIZE, - .speed_hz = SPEED, - .bits_per_word = 8, - .delay_usecs = 0, - }; - tr.tx_buf = t_buffer; - - memset(&msg, 0, sizeof(msg)); - spi_message_init(&msg); - msg.spi = wilc_spi_dev; - msg.is_dma_mapped = USE_SPI_DMA; - - spi_message_add_tail(&tr, &msg); - ret = spi_sync(wilc_spi_dev, &msg); - if (ret < 0) { - PRINT_ER("SPI transaction failed\n"); - } - i++; - } - } - if (remainder) { - struct spi_message msg; - struct spi_transfer tr = { - .rx_buf = rb + (blk * TXRX_PHASE_SIZE), - .len = remainder, - .speed_hz = SPEED, - .bits_per_word = 8, - .delay_usecs = 0, - }; - tr.tx_buf = t_buffer; - - memset(&msg, 0, sizeof(msg)); - spi_message_init(&msg); - msg.spi = wilc_spi_dev; - msg.is_dma_mapped = USE_SPI_DMA; /* rachel */ - - spi_message_add_tail(&tr, &msg); - ret = spi_sync(wilc_spi_dev, &msg); - if (ret < 0) { - PRINT_ER("SPI transaction failed\n"); - } - } - - kfree(t_buffer); - } else { - PRINT_ER("can't read data with the following length: %u\n", rlen); - ret = -1; - } - /* change return value to match WILC interface */ - (ret < 0) ? (ret = 0) : (ret = 1); - - return ret; -} - -#else -int linux_spi_read(u8 *rb, u32 rlen) -{ - - int ret; - - if (rlen > 0) { - struct spi_message msg; - struct spi_transfer tr = { - .rx_buf = rb, - .len = rlen, - .speed_hz = SPEED, - .delay_usecs = 0, - - }; - char *t_buffer = kzalloc(rlen, GFP_KERNEL); - if (!t_buffer) - return -ENOMEM; - - tr.tx_buf = t_buffer; - - memset(&msg, 0, sizeof(msg)); - spi_message_init(&msg); -/* [[ johnny add */ - msg.spi = wilc_spi_dev; - msg.is_dma_mapped = USE_SPI_DMA; -/* ]] */ - spi_message_add_tail(&tr, &msg); - - ret = spi_sync(wilc_spi_dev, &msg); - if (ret < 0) { - PRINT_ER("SPI transaction failed\n"); - } - kfree(t_buffer); - } else { - PRINT_ER("can't read data with the following length: %u\n", rlen); - ret = -1; - } - /* change return value to match WILC interface */ - (ret < 0) ? (ret = 0) : (ret = 1); - - return ret; -} - -#endif - -int linux_spi_write_read(u8 *wb, u8 *rb, u32 rlen) -{ - - int ret; - - if (rlen > 0) { - struct spi_message msg; - struct spi_transfer tr = { - .rx_buf = rb, - .tx_buf = wb, - .len = rlen, - .speed_hz = SPEED, - .bits_per_word = 8, - .delay_usecs = 0, - - }; - - memset(&msg, 0, sizeof(msg)); - spi_message_init(&msg); - msg.spi = wilc_spi_dev; - msg.is_dma_mapped = USE_SPI_DMA; - - spi_message_add_tail(&tr, &msg); - ret = spi_sync(wilc_spi_dev, &msg); - if (ret < 0) { - PRINT_ER("SPI transaction failed\n"); - } - } else { - PRINT_ER("can't read data with the following length: %u\n", rlen); - ret = -1; - } - /* change return value to match WILC interface */ - (ret < 0) ? (ret = 0) : (ret = 1); - - return ret; -} - -int linux_spi_set_max_speed(void) -{ - SPEED = MAX_SPEED; - - PRINT_INFO(BUS_DBG, "@@@@@@@@@@@@ change SPI speed to %d @@@@@@@@@\n", SPEED); - return 1; -} diff --git a/drivers/staging/wilc1000/linux_wlan_spi.h b/drivers/staging/wilc1000/linux_wlan_spi.h deleted file mode 100644 index 7356785296f9..000000000000 --- a/drivers/staging/wilc1000/linux_wlan_spi.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef LINUX_WLAN_SPI_H -#define LINUX_WLAN_SPI_H - -#include <linux/spi/spi.h> -extern struct spi_device *wilc_spi_dev; -extern struct spi_driver wilc_bus; - -int linux_spi_init(void *vp); -void linux_spi_deinit(void *vp); -int linux_spi_write(u8 *b, u32 len); -int linux_spi_read(u8 *rb, u32 rlen); -int linux_spi_write_read(u8 *wb, u8 *rb, u32 rlen); -int linux_spi_set_max_speed(void); -#endif diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c index ae111862e7a9..27c653a0cdf9 100644 --- a/drivers/staging/wilc1000/wilc_debugfs.c +++ b/drivers/staging/wilc1000/wilc_debugfs.c @@ -26,8 +26,10 @@ static struct dentry *wilc_dir; #define DBG_REGION_ALL (GENERIC_DBG | HOSTAPD_DBG | HOSTINF_DBG | CORECONFIG_DBG | CFG80211_DBG | INT_DBG | TX_DBG | RX_DBG | LOCK_DBG | INIT_DBG | BUS_DBG | MEM_DBG) #define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR) -atomic_t REGION = ATOMIC_INIT(INIT_DBG | GENERIC_DBG | CFG80211_DBG | FIRM_DBG | HOSTAPD_DBG); -atomic_t DEBUG_LEVEL = ATOMIC_INIT(ERR); +atomic_t WILC_REGION = ATOMIC_INIT(INIT_DBG | GENERIC_DBG | CFG80211_DBG | FIRM_DBG | HOSTAPD_DBG); +EXPORT_SYMBOL_GPL(WILC_REGION); +atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR); +EXPORT_SYMBOL_GPL(WILC_DEBUG_LEVEL); /* * -------------------------------------------------------------------------------- @@ -43,7 +45,7 @@ static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf, si if (*ppos > 0) return 0; - res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n", atomic_read(&DEBUG_LEVEL)); + res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n", atomic_read(&WILC_DEBUG_LEVEL)); return simple_read_from_buffer(userbuf, count, ppos, buf, res); } @@ -59,11 +61,11 @@ static ssize_t wilc_debug_level_write(struct file *filp, const char __user *buf, return ret; if (flag > DBG_LEVEL_ALL) { - printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&DEBUG_LEVEL)); + printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&WILC_DEBUG_LEVEL)); return -EINVAL; } - atomic_set(&DEBUG_LEVEL, (int)flag); + atomic_set(&WILC_DEBUG_LEVEL, (int)flag); if (flag == 0) printk("Debug-level disabled\n"); @@ -82,7 +84,7 @@ static ssize_t wilc_debug_region_read(struct file *file, char __user *userbuf, s if (*ppos > 0) return 0; - res = scnprintf(buf, sizeof(buf), "Debug region: %x\n", atomic_read(®ION)); + res = scnprintf(buf, sizeof(buf), "Debug region: %x\n", atomic_read(&WILC_REGION)); return simple_read_from_buffer(userbuf, count, ppos, buf, res); } @@ -102,12 +104,12 @@ static ssize_t wilc_debug_region_write(struct file *filp, const char *buf, size_ flag = buffer[0] - '0'; if (flag > DBG_REGION_ALL) { - printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(®ION)); + printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&WILC_REGION)); return -EFAULT; } - atomic_set(®ION, (int)flag); - printk("new debug-region is %x\n", atomic_read(®ION)); + atomic_set(&WILC_REGION, (int)flag); + printk("new debug-region is %x\n", atomic_read(&WILC_REGION)); return count; } @@ -136,7 +138,7 @@ static struct wilc_debugfs_info_t debugfs_info[] = { { "wilc_debug_region", 0666, (INIT_DBG | GENERIC_DBG | CFG80211_DBG), FOPS(NULL, wilc_debug_region_read, wilc_debug_region_write, NULL), }, }; -int wilc_debugfs_init(void) +static int __init wilc_debugfs_init(void) { int i; @@ -171,11 +173,13 @@ int wilc_debugfs_init(void) } return 0; } +module_init(wilc_debugfs_init); -void wilc_debugfs_remove(void) +static void __exit wilc_debugfs_remove(void) { debugfs_remove_recursive(wilc_dir); } +module_exit(wilc_debugfs_remove); #endif diff --git a/drivers/staging/wilc1000/wilc_msgqueue.c b/drivers/staging/wilc1000/wilc_msgqueue.c index 0eff121b8291..098390cdf319 100644 --- a/drivers/staging/wilc1000/wilc_msgqueue.c +++ b/drivers/staging/wilc1000/wilc_msgqueue.c @@ -115,7 +115,6 @@ int wilc_mq_recv(WILC_MsgQueueHandle *pHandle, u32 *pu32ReceivedLength) { Message *pstrMessage; - int result = 0; unsigned long flags; if ((!pHandle) || (u32RecvBufferSize == 0) @@ -135,12 +134,6 @@ int wilc_mq_recv(WILC_MsgQueueHandle *pHandle, down(&pHandle->hSem); - /* other non-timeout scenarios */ - if (result) { - PRINT_ER("Non-timeout\n"); - return result; - } - if (pHandle->bExiting) { PRINT_ER("pHandle fail\n"); return -EFAULT; @@ -174,5 +167,5 @@ int wilc_mq_recv(WILC_MsgQueueHandle *pHandle, spin_unlock_irqrestore(&pHandle->strCriticalSection, flags); - return result; + return 0; } diff --git a/drivers/staging/wilc1000/wilc_msgqueue.h b/drivers/staging/wilc1000/wilc_msgqueue.h index d231c334ed93..d7e0328bacee 100644 --- a/drivers/staging/wilc1000/wilc_msgqueue.h +++ b/drivers/staging/wilc1000/wilc_msgqueue.h @@ -35,7 +35,7 @@ typedef struct __MessageQueue_struct { * any other message queue having the same name in the system * @param[in,out] pHandle handle to the message queue object * @param[in] pstrAttrs Optional attributes, NULL for default - * @return Error code indicating sucess/failure + * @return Error code indicating success/failure * @author syounan * @date 30 Aug 2010 * @version 1.0 @@ -44,7 +44,7 @@ int wilc_mq_create(WILC_MsgQueueHandle *pHandle); /*! * @brief Sends a message - * @details Sends a message, this API will block unil the message is + * @details Sends a message, this API will block until the message is * actually sent or until it is timedout (as long as the feature * CONFIG_WILC_MSG_QUEUE_TIMEOUT is enabled and pstrAttrs->u32Timeout * is not set to WILC_OS_INFINITY), zero timeout is a valid value @@ -52,7 +52,7 @@ int wilc_mq_create(WILC_MsgQueueHandle *pHandle); * @param[in] pvSendBuffer pointer to the data to send * @param[in] u32SendBufferSize the size of the data to send * @param[in] pstrAttrs Optional attributes, NULL for default - * @return Error code indicating sucess/failure + * @return Error code indicating success/failure * @author syounan * @date 30 Aug 2010 * @version 1.0 @@ -62,7 +62,7 @@ int wilc_mq_send(WILC_MsgQueueHandle *pHandle, /*! * @brief Receives a message - * @details Receives a message, this API will block unil a message is + * @details Receives a message, this API will block until a message is * received or until it is timedout (as long as the feature * CONFIG_WILC_MSG_QUEUE_TIMEOUT is enabled and pstrAttrs->u32Timeout * is not set to WILC_OS_INFINITY), zero timeout is a valid value @@ -71,7 +71,7 @@ int wilc_mq_send(WILC_MsgQueueHandle *pHandle, * @param[in] u32RecvBufferSize the size of the receive buffer * @param[out] pu32ReceivedLength the length of received data * @param[in] pstrAttrs Optional attributes, NULL for default - * @return Error code indicating sucess/failure + * @return Error code indicating success/failure * @author syounan * @date 30 Aug 2010 * @version 1.0 @@ -84,7 +84,7 @@ int wilc_mq_recv(WILC_MsgQueueHandle *pHandle, * @brief Destroys an existing Message queue * @param[in] pHandle handle to the message queue object * @param[in] pstrAttrs Optional attributes, NULL for default - * @return Error code indicating sucess/failure + * @return Error code indicating success/failure * @author syounan * @date 30 Aug 2010 * @version 1.0 diff --git a/drivers/staging/wilc1000/wilc_sdio.c b/drivers/staging/wilc1000/wilc_sdio.c index 300c571e4e2d..e961b5004902 100644 --- a/drivers/staging/wilc1000/wilc_sdio.c +++ b/drivers/staging/wilc1000/wilc_sdio.c @@ -10,17 +10,29 @@ #include <linux/string.h> #include "wilc_wlan_if.h" #include "wilc_wlan.h" +#include "wilc_wfi_netdevice.h" +#include <linux/mmc/sdio_func.h> +#include <linux/mmc/card.h> +#include <linux/mmc/sdio_ids.h> +#include <linux/mmc/sdio.h> +#include <linux/mmc/host.h> +#include <linux/of_gpio.h> + +#define SDIO_MODALIAS "wilc1000_sdio" + +#define SDIO_VENDOR_ID_WILC 0x0296 +#define SDIO_DEVICE_ID_WILC 0x5347 + +static const struct sdio_device_id wilc_sdio_ids[] = { + { SDIO_DEVICE(SDIO_VENDOR_ID_WILC, SDIO_DEVICE_ID_WILC) }, + { }, +}; #define WILC_SDIO_BLOCK_SIZE 512 typedef struct { - void *os_context; + bool irq_gpio; u32 block_size; - int (*sdio_cmd52)(sdio_cmd52_t *); - int (*sdio_cmd53)(sdio_cmd53_t *); - int (*sdio_set_max_speed)(void); - int (*sdio_set_default_speed)(void); - wilc_debug_func dPrint; int nint; #define MAX_NUN_INT_THRPT_ENH2 (5) /* Max num interrupts allowed in registers 0xf7, 0xf8 */ int has_thrpt_enh3; @@ -28,10 +40,155 @@ typedef struct { static wilc_sdio_t g_sdio; -#ifdef WILC_SDIO_IRQ_GPIO -static int sdio_write_reg(u32 addr, u32 data); -static int sdio_read_reg(u32 addr, u32 *data); -#endif +static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data); +static int sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data); + +static void wilc_sdio_interrupt(struct sdio_func *func) +{ + sdio_release_host(func); + wilc_handle_isr(sdio_get_drvdata(func)); + sdio_claim_host(func); +} + +static int wilc_sdio_cmd52(struct wilc *wilc, sdio_cmd52_t *cmd) +{ + struct sdio_func *func = container_of(wilc->dev, struct sdio_func, dev); + int ret; + u8 data; + + sdio_claim_host(func); + + func->num = cmd->function; + if (cmd->read_write) { /* write */ + if (cmd->raw) { + sdio_writeb(func, cmd->data, cmd->address, &ret); + data = sdio_readb(func, cmd->address, &ret); + cmd->data = data; + } else { + sdio_writeb(func, cmd->data, cmd->address, &ret); + } + } else { /* read */ + data = sdio_readb(func, cmd->address, &ret); + cmd->data = data; + } + + sdio_release_host(func); + + if (ret) + dev_err(&func->dev, "wilc_sdio_cmd52..failed, err(%d)\n", ret); + return ret; +} + + +static int wilc_sdio_cmd53(struct wilc *wilc, sdio_cmd53_t *cmd) +{ + struct sdio_func *func = container_of(wilc->dev, struct sdio_func, dev); + int size, ret; + + sdio_claim_host(func); + + func->num = cmd->function; + func->cur_blksize = cmd->block_size; + if (cmd->block_mode) + size = cmd->count * cmd->block_size; + else + size = cmd->count; + + if (cmd->read_write) { /* write */ + ret = sdio_memcpy_toio(func, cmd->address, + (void *)cmd->buffer, size); + } else { /* read */ + ret = sdio_memcpy_fromio(func, (void *)cmd->buffer, + cmd->address, size); + } + + sdio_release_host(func); + + if (ret) + dev_err(&func->dev, "wilc_sdio_cmd53..failed, err(%d)\n", ret); + + return ret; +} + +static int linux_sdio_probe(struct sdio_func *func, + const struct sdio_device_id *id) +{ + struct wilc *wilc; + int gpio, ret; + + gpio = -1; + if (IS_ENABLED(CONFIG_WILC1000_HW_OOB_INTR)) { + gpio = of_get_gpio(func->dev.of_node, 0); + if (gpio < 0) + gpio = GPIO_NUM; + } + + dev_dbg(&func->dev, "Initializing netdev\n"); + ret = wilc_netdev_init(&wilc, &func->dev, HIF_SDIO, gpio, + &wilc_hif_sdio); + if (ret) { + dev_err(&func->dev, "Couldn't initialize netdev\n"); + return ret; + } + sdio_set_drvdata(func, wilc); + wilc->dev = &func->dev; + + dev_info(&func->dev, "Driver Initializing success\n"); + return 0; +} + +static void linux_sdio_remove(struct sdio_func *func) +{ + wilc_netdev_cleanup(sdio_get_drvdata(func)); +} + +static struct sdio_driver wilc1000_sdio_driver = { + .name = SDIO_MODALIAS, + .id_table = wilc_sdio_ids, + .probe = linux_sdio_probe, + .remove = linux_sdio_remove, +}; +module_driver(wilc1000_sdio_driver, + sdio_register_driver, + sdio_unregister_driver); +MODULE_LICENSE("GPL"); + +static int wilc_sdio_enable_interrupt(struct wilc *dev) +{ + struct sdio_func *func = container_of(dev->dev, struct sdio_func, dev); + int ret = 0; + + sdio_claim_host(func); + ret = sdio_claim_irq(func, wilc_sdio_interrupt); + sdio_release_host(func); + + if (ret < 0) { + dev_err(&func->dev, "can't claim sdio_irq, err(%d)\n", ret); + ret = -EIO; + } + return ret; +} + +static void wilc_sdio_disable_interrupt(struct wilc *dev) +{ + struct sdio_func *func = container_of(dev->dev, struct sdio_func, dev); + int ret; + + dev_dbg(&func->dev, "wilc_sdio_disable_interrupt IN\n"); + + sdio_claim_host(func); + ret = sdio_release_irq(func); + if (ret < 0) + dev_err(&func->dev, "can't release sdio_irq, err(%d)\n", ret); + sdio_release_host(func); + + dev_info(&func->dev, "wilc_sdio_disable_interrupt OUT\n"); +} + +static int wilc_sdio_init(void) +{ + return 1; +} /******************************************** * @@ -39,9 +196,11 @@ static int sdio_read_reg(u32 addr, u32 *data); * ********************************************/ -static int sdio_set_func0_csa_address(u32 adr) +static int sdio_set_func0_csa_address(struct wilc *wilc, u32 adr) { + struct sdio_func *func = dev_to_sdio_func(wilc->dev); sdio_cmd52_t cmd; + int ret; /** * Review: BIG ENDIAN @@ -51,22 +210,25 @@ static int sdio_set_func0_csa_address(u32 adr) cmd.raw = 0; cmd.address = 0x10c; cmd.data = (u8)adr; - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x10c data...\n"); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, "Failed cmd52, set 0x10c data...\n"); goto _fail_; } cmd.address = 0x10d; cmd.data = (u8)(adr >> 8); - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x10d data...\n"); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, "Failed cmd52, set 0x10d data...\n"); goto _fail_; } cmd.address = 0x10e; cmd.data = (u8)(adr >> 16); - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x10e data...\n"); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, "Failed cmd52, set 0x10e data...\n"); goto _fail_; } @@ -75,24 +237,28 @@ _fail_: return 0; } -static int sdio_set_func0_block_size(u32 block_size) +static int sdio_set_func0_block_size(struct wilc *wilc, u32 block_size) { + struct sdio_func *func = dev_to_sdio_func(wilc->dev); sdio_cmd52_t cmd; + int ret; cmd.read_write = 1; cmd.function = 0; cmd.raw = 0; cmd.address = 0x10; cmd.data = (u8)block_size; - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x10 data...\n"); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, "Failed cmd52, set 0x10 data...\n"); goto _fail_; } cmd.address = 0x11; cmd.data = (u8)(block_size >> 8); - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x11 data...\n"); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, "Failed cmd52, set 0x11 data...\n"); goto _fail_; } @@ -107,23 +273,27 @@ _fail_: * ********************************************/ -static int sdio_set_func1_block_size(u32 block_size) +static int sdio_set_func1_block_size(struct wilc *wilc, u32 block_size) { + struct sdio_func *func = dev_to_sdio_func(wilc->dev); sdio_cmd52_t cmd; + int ret; cmd.read_write = 1; cmd.function = 0; cmd.raw = 0; cmd.address = 0x110; cmd.data = (u8)block_size; - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x110 data...\n"); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, "Failed cmd52, set 0x110 data...\n"); goto _fail_; } cmd.address = 0x111; cmd.data = (u8)(block_size >> 8); - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x111 data...\n"); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, "Failed cmd52, set 0x111 data...\n"); goto _fail_; } @@ -132,100 +302,17 @@ _fail_: return 0; } -static int sdio_clear_int(void) -{ -#ifndef WILC_SDIO_IRQ_GPIO - /* u32 sts; */ - sdio_cmd52_t cmd; - - cmd.read_write = 0; - cmd.function = 1; - cmd.raw = 0; - cmd.address = 0x4; - cmd.data = 0; - g_sdio.sdio_cmd52(&cmd); - - return cmd.data; -#else - u32 reg; - - if (!sdio_read_reg(WILC_HOST_RX_CTRL_0, ®)) { - g_sdio.dPrint(N_ERR, "[wilc spi]: Failed read reg (%08x)...\n", WILC_HOST_RX_CTRL_0); - return 0; - } - reg &= ~0x1; - sdio_write_reg(WILC_HOST_RX_CTRL_0, reg); - return 1; -#endif - -} - -u32 sdio_xfer_cnt(void) -{ - u32 cnt = 0; - sdio_cmd52_t cmd; - - cmd.read_write = 0; - cmd.function = 1; - cmd.raw = 0; - cmd.address = 0x1C; - cmd.data = 0; - g_sdio.sdio_cmd52(&cmd); - cnt = cmd.data; - - cmd.read_write = 0; - cmd.function = 1; - cmd.raw = 0; - cmd.address = 0x1D; - cmd.data = 0; - g_sdio.sdio_cmd52(&cmd); - cnt |= (cmd.data << 8); - - cmd.read_write = 0; - cmd.function = 1; - cmd.raw = 0; - cmd.address = 0x1E; - cmd.data = 0; - g_sdio.sdio_cmd52(&cmd); - cnt |= (cmd.data << 16); - - return cnt; -} - /******************************************** * * Sdio interfaces * ********************************************/ -int sdio_check_bs(void) +static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data) { - sdio_cmd52_t cmd; - - /** - * poll until BS is 0 - **/ - cmd.read_write = 0; - cmd.function = 0; - cmd.raw = 0; - cmd.address = 0xc; - cmd.data = 0; - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Fail cmd 52, get BS register...\n"); - goto _fail_; - } - - return 1; - -_fail_: - - return 0; -} + struct sdio_func *func = dev_to_sdio_func(wilc->dev); + int ret; -static int sdio_write_reg(u32 addr, u32 data) -{ -#ifdef BIG_ENDIAN - data = BYTE_SWAP(data); -#endif + data = cpu_to_le32(data); if ((addr >= 0xf0) && (addr <= 0xff)) { sdio_cmd52_t cmd; @@ -235,8 +322,10 @@ static int sdio_write_reg(u32 addr, u32 data) cmd.raw = 0; cmd.address = addr; cmd.data = data; - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd 52, read reg (%08x) ...\n", addr); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd 52, read reg (%08x) ...\n", addr); goto _fail_; } } else { @@ -245,7 +334,7 @@ static int sdio_write_reg(u32 addr, u32 data) /** * set the AHB address **/ - if (!sdio_set_func0_csa_address(addr)) + if (!sdio_set_func0_csa_address(wilc, addr)) goto _fail_; cmd.read_write = 1; @@ -256,9 +345,10 @@ static int sdio_write_reg(u32 addr, u32 data) cmd.count = 4; cmd.buffer = (u8 *)&data; cmd.block_size = g_sdio.block_size; /* johnny : prevent it from setting unexpected value */ - - if (!g_sdio.sdio_cmd53(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53, write reg (%08x)...\n", addr); + ret = wilc_sdio_cmd53(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd53, write reg (%08x)...\n", addr); goto _fail_; } } @@ -270,11 +360,12 @@ _fail_: return 0; } -static int sdio_write(u32 addr, u8 *buf, u32 size) +static int sdio_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size) { + struct sdio_func *func = dev_to_sdio_func(wilc->dev); u32 block_size = g_sdio.block_size; sdio_cmd53_t cmd; - int nblk, nleft; + int nblk, nleft, ret; cmd.read_write = 1; if (addr > 0) { @@ -317,11 +408,13 @@ static int sdio_write(u32 addr, u8 *buf, u32 size) cmd.buffer = buf; cmd.block_size = block_size; if (addr > 0) { - if (!sdio_set_func0_csa_address(addr)) + if (!sdio_set_func0_csa_address(wilc, addr)) goto _fail_; } - if (!g_sdio.sdio_cmd53(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53 [%x], block send...\n", addr); + ret = wilc_sdio_cmd53(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd53 [%x], block send...\n", addr); goto _fail_; } if (addr > 0) @@ -338,11 +431,13 @@ static int sdio_write(u32 addr, u8 *buf, u32 size) cmd.block_size = block_size; /* johnny : prevent it from setting unexpected value */ if (addr > 0) { - if (!sdio_set_func0_csa_address(addr)) + if (!sdio_set_func0_csa_address(wilc, addr)) goto _fail_; } - if (!g_sdio.sdio_cmd53(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53 [%x], bytes send...\n", addr); + ret = wilc_sdio_cmd53(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd53 [%x], bytes send...\n", addr); goto _fail_; } } @@ -354,8 +449,11 @@ _fail_: return 0; } -static int sdio_read_reg(u32 addr, u32 *data) +static int sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data) { + struct sdio_func *func = dev_to_sdio_func(wilc->dev); + int ret; + if ((addr >= 0xf0) && (addr <= 0xff)) { sdio_cmd52_t cmd; @@ -363,15 +461,17 @@ static int sdio_read_reg(u32 addr, u32 *data) cmd.function = 0; cmd.raw = 0; cmd.address = addr; - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd 52, read reg (%08x) ...\n", addr); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd 52, read reg (%08x) ...\n", addr); goto _fail_; } *data = cmd.data; } else { sdio_cmd53_t cmd; - if (!sdio_set_func0_csa_address(addr)) + if (!sdio_set_func0_csa_address(wilc, addr)) goto _fail_; cmd.read_write = 0; @@ -383,16 +483,15 @@ static int sdio_read_reg(u32 addr, u32 *data) cmd.buffer = (u8 *)data; cmd.block_size = g_sdio.block_size; /* johnny : prevent it from setting unexpected value */ - - if (!g_sdio.sdio_cmd53(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53, read reg (%08x)...\n", addr); + ret = wilc_sdio_cmd53(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd53, read reg (%08x)...\n", addr); goto _fail_; } } -#ifdef BIG_ENDIAN - *data = BYTE_SWAP(*data); -#endif + *data = cpu_to_le32(*data); return 1; @@ -401,11 +500,12 @@ _fail_: return 0; } -static int sdio_read(u32 addr, u8 *buf, u32 size) +static int sdio_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size) { + struct sdio_func *func = dev_to_sdio_func(wilc->dev); u32 block_size = g_sdio.block_size; sdio_cmd53_t cmd; - int nblk, nleft; + int nblk, nleft, ret; cmd.read_write = 0; if (addr > 0) { @@ -448,11 +548,13 @@ static int sdio_read(u32 addr, u8 *buf, u32 size) cmd.buffer = buf; cmd.block_size = block_size; if (addr > 0) { - if (!sdio_set_func0_csa_address(addr)) + if (!sdio_set_func0_csa_address(wilc, addr)) goto _fail_; } - if (!g_sdio.sdio_cmd53(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53 [%x], block read...\n", addr); + ret = wilc_sdio_cmd53(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd53 [%x], block read...\n", addr); goto _fail_; } if (addr > 0) @@ -469,11 +571,13 @@ static int sdio_read(u32 addr, u8 *buf, u32 size) cmd.block_size = block_size; /* johnny : prevent it from setting unexpected value */ if (addr > 0) { - if (!sdio_set_func0_csa_address(addr)) + if (!sdio_set_func0_csa_address(wilc, addr)) goto _fail_; } - if (!g_sdio.sdio_cmd53(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53 [%x], bytes read...\n", addr); + ret = wilc_sdio_cmd53(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd53 [%x], bytes read...\n", addr); goto _fail_; } } @@ -491,94 +595,29 @@ _fail_: * ********************************************/ -static int sdio_deinit(void *pv) +static int sdio_deinit(struct wilc *wilc) { return 1; } -static int sdio_sync(void) -{ - u32 reg; - - /** - * Disable power sequencer - **/ - if (!sdio_read_reg(WILC_MISC, ®)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed read misc reg...\n"); - return 0; - } - - reg &= ~BIT(8); - if (!sdio_write_reg(WILC_MISC, reg)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed write misc reg...\n"); - return 0; - } - -#ifdef WILC_SDIO_IRQ_GPIO - { - u32 reg; - int ret; - - /** - * interrupt pin mux select - **/ - ret = sdio_read_reg(WILC_PIN_MUX_0, ®); - if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc spi]: Failed read reg (%08x)...\n", WILC_PIN_MUX_0); - return 0; - } - reg |= BIT(8); - ret = sdio_write_reg(WILC_PIN_MUX_0, reg); - if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc spi]: Failed write reg (%08x)...\n", WILC_PIN_MUX_0); - return 0; - } - - /** - * interrupt enable - **/ - ret = sdio_read_reg(WILC_INTR_ENABLE, ®); - if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc spi]: Failed read reg (%08x)...\n", WILC_INTR_ENABLE); - return 0; - } - reg |= BIT(16); - ret = sdio_write_reg(WILC_INTR_ENABLE, reg); - if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc spi]: Failed write reg (%08x)...\n", WILC_INTR_ENABLE); - return 0; - } - } -#endif - - return 1; -} - -static int sdio_init(wilc_wlan_inp_t *inp, wilc_debug_func func) +static int sdio_init(struct wilc *wilc) { + struct sdio_func *func = dev_to_sdio_func(wilc->dev); sdio_cmd52_t cmd; - int loop; + int loop, ret; u32 chipid; memset(&g_sdio, 0, sizeof(wilc_sdio_t)); - g_sdio.dPrint = func; - g_sdio.os_context = inp->os_context.os_private; + g_sdio.irq_gpio = (wilc->dev_irq_num); - if (inp->io_func.io_init) { - if (!inp->io_func.io_init(g_sdio.os_context)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed io init bus...\n"); - return 0; - } + if (!wilc_sdio_init()) { + dev_err(&func->dev, "Failed io init bus...\n"); + return 0; } else { return 0; } - g_sdio.sdio_cmd52 = inp->io_func.u.sdio.sdio_cmd52; - g_sdio.sdio_cmd53 = inp->io_func.u.sdio.sdio_cmd53; - g_sdio.sdio_set_max_speed = inp->io_func.u.sdio.sdio_set_max_speed; - g_sdio.sdio_set_default_speed = inp->io_func.u.sdio.sdio_set_default_speed; - /** * function 0 csa enable **/ @@ -587,16 +626,17 @@ static int sdio_init(wilc_wlan_inp_t *inp, wilc_debug_func func) cmd.raw = 1; cmd.address = 0x100; cmd.data = 0x80; - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Fail cmd 52, enable csa...\n"); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, "Fail cmd 52, enable csa...\n"); goto _fail_; } /** * function 0 block size **/ - if (!sdio_set_func0_block_size(WILC_SDIO_BLOCK_SIZE)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Fail cmd 52, set func 0 block size...\n"); + if (!sdio_set_func0_block_size(wilc, WILC_SDIO_BLOCK_SIZE)) { + dev_err(&func->dev, "Fail cmd 52, set func 0 block size...\n"); goto _fail_; } g_sdio.block_size = WILC_SDIO_BLOCK_SIZE; @@ -609,8 +649,10 @@ static int sdio_init(wilc_wlan_inp_t *inp, wilc_debug_func func) cmd.raw = 1; cmd.address = 0x2; cmd.data = 0x2; - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio] Fail cmd 52, set IOE register...\n"); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Fail cmd 52, set IOE register...\n"); goto _fail_; } @@ -624,8 +666,10 @@ static int sdio_init(wilc_wlan_inp_t *inp, wilc_debug_func func) loop = 3; do { cmd.data = 0; - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Fail cmd 52, get IOR register...\n"); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Fail cmd 52, get IOR register...\n"); goto _fail_; } if (cmd.data == 0x2) @@ -633,15 +677,15 @@ static int sdio_init(wilc_wlan_inp_t *inp, wilc_debug_func func) } while (loop--); if (loop <= 0) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Fail func 1 is not ready...\n"); + dev_err(&func->dev, "Fail func 1 is not ready...\n"); goto _fail_; } /** * func 1 is ready, set func 1 block size **/ - if (!sdio_set_func1_block_size(WILC_SDIO_BLOCK_SIZE)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Fail set func 1 block size...\n"); + if (!sdio_set_func1_block_size(wilc, WILC_SDIO_BLOCK_SIZE)) { + dev_err(&func->dev, "Fail set func 1 block size...\n"); goto _fail_; } @@ -653,24 +697,25 @@ static int sdio_init(wilc_wlan_inp_t *inp, wilc_debug_func func) cmd.raw = 1; cmd.address = 0x4; cmd.data = 0x3; - if (!g_sdio.sdio_cmd52(&cmd)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Fail cmd 52, set IEN register...\n"); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, "Fail cmd 52, set IEN register...\n"); goto _fail_; } /** * make sure can read back chip id correctly **/ - if (!sdio_read_reg(0x1000, &chipid)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Fail cmd read chip id...\n"); + if (!sdio_read_reg(wilc, 0x1000, &chipid)) { + dev_err(&func->dev, "Fail cmd read chip id...\n"); goto _fail_; } - g_sdio.dPrint(N_ERR, "[wilc sdio]: chipid (%08x)\n", chipid); + dev_err(&func->dev, "chipid (%08x)\n", chipid); if ((chipid & 0xfff) > 0x2a0) g_sdio.has_thrpt_enh3 = 1; else g_sdio.has_thrpt_enh3 = 0; - g_sdio.dPrint(N_ERR, "[wilc sdio]: has_thrpt_enh3 = %d...\n", g_sdio.has_thrpt_enh3); + dev_info(&func->dev, "has_thrpt_enh3 = %d...\n", g_sdio.has_thrpt_enh3); return 1; @@ -679,19 +724,8 @@ _fail_: return 0; } -static void sdio_set_max_speed(void) +static int sdio_read_size(struct wilc *wilc, u32 *size) { - g_sdio.sdio_set_max_speed(); -} - -static void sdio_set_default_speed(void) -{ - g_sdio.sdio_set_default_speed(); -} - -static int sdio_read_size(u32 *size) -{ - u32 tmp; sdio_cmd52_t cmd; @@ -703,7 +737,7 @@ static int sdio_read_size(u32 *size) cmd.raw = 0; cmd.address = 0xf2; cmd.data = 0; - g_sdio.sdio_cmd52(&cmd); + wilc_sdio_cmd52(wilc, &cmd); tmp = cmd.data; /* cmd.read_write = 0; */ @@ -711,54 +745,53 @@ static int sdio_read_size(u32 *size) /* cmd.raw = 0; */ cmd.address = 0xf3; cmd.data = 0; - g_sdio.sdio_cmd52(&cmd); + wilc_sdio_cmd52(wilc, &cmd); tmp |= (cmd.data << 8); *size = tmp; return 1; } -static int sdio_read_int(u32 *int_status) +static int sdio_read_int(struct wilc *wilc, u32 *int_status) { - + struct sdio_func *func = dev_to_sdio_func(wilc->dev); u32 tmp; sdio_cmd52_t cmd; - sdio_read_size(&tmp); + sdio_read_size(wilc, &tmp); /** * Read IRQ flags **/ -#ifndef WILC_SDIO_IRQ_GPIO - cmd.function = 1; - cmd.address = 0x04; - cmd.data = 0; - g_sdio.sdio_cmd52(&cmd); - - if (cmd.data & BIT(0)) - tmp |= INT_0; - if (cmd.data & BIT(2)) - tmp |= INT_1; - if (cmd.data & BIT(3)) - tmp |= INT_2; - if (cmd.data & BIT(4)) - tmp |= INT_3; - if (cmd.data & BIT(5)) - tmp |= INT_4; - if (cmd.data & BIT(6)) - tmp |= INT_5; - { + if (!g_sdio.irq_gpio) { int i; + cmd.function = 1; + cmd.address = 0x04; + cmd.data = 0; + wilc_sdio_cmd52(wilc, &cmd); + + if (cmd.data & BIT(0)) + tmp |= INT_0; + if (cmd.data & BIT(2)) + tmp |= INT_1; + if (cmd.data & BIT(3)) + tmp |= INT_2; + if (cmd.data & BIT(4)) + tmp |= INT_3; + if (cmd.data & BIT(5)) + tmp |= INT_4; + if (cmd.data & BIT(6)) + tmp |= INT_5; for (i = g_sdio.nint; i < MAX_NUM_INT; i++) { if ((tmp >> (IRG_FLAGS_OFFSET + i)) & 0x1) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Unexpected interrupt (1) : tmp=%x, data=%x\n", tmp, cmd.data); + dev_err(&func->dev, + "Unexpected interrupt (1) : tmp=%x, data=%x\n", + tmp, cmd.data); break; } } - } -#else - { + } else { u32 irq_flags; cmd.read_write = 0; @@ -766,35 +799,32 @@ static int sdio_read_int(u32 *int_status) cmd.raw = 0; cmd.address = 0xf7; cmd.data = 0; - g_sdio.sdio_cmd52(&cmd); + wilc_sdio_cmd52(wilc, &cmd); irq_flags = cmd.data & 0x1f; tmp |= ((irq_flags >> 0) << IRG_FLAGS_OFFSET); } -#endif - *int_status = tmp; return 1; } -static int sdio_clear_int_ext(u32 val) +static int sdio_clear_int_ext(struct wilc *wilc, u32 val) { + struct sdio_func *func = dev_to_sdio_func(wilc->dev); int ret; if (g_sdio.has_thrpt_enh3) { u32 reg; -#ifdef WILC_SDIO_IRQ_GPIO - { + if (g_sdio.irq_gpio) { u32 flags; flags = val & (BIT(MAX_NUN_INT_THRPT_ENH2) - 1); reg = flags; + } else { + reg = 0; } -#else - reg = 0; -#endif /* select VMM table 0 */ if ((val & SEL_VMM_TBL0) == SEL_VMM_TBL0) reg |= BIT(5); @@ -813,16 +843,17 @@ static int sdio_clear_int_ext(u32 val) cmd.address = 0xf8; cmd.data = reg; - ret = g_sdio.sdio_cmd52(&cmd); - if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0xf8 data (%d) ...\n", __LINE__); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd52, set 0xf8 data (%d) ...\n", + __LINE__); goto _fail_; } } } else { -#ifdef WILC_SDIO_IRQ_GPIO - { + if (g_sdio.irq_gpio) { /* see below. has_thrpt_enh2 uses register 0xf8 to clear interrupts. */ /* Cannot clear multiple interrupts. Must clear each interrupt individually */ u32 flags; @@ -842,9 +873,11 @@ static int sdio_clear_int_ext(u32 val) cmd.address = 0xf8; cmd.data = BIT(i); - ret = g_sdio.sdio_cmd52(&cmd); - if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0xf8 data (%d) ...\n", __LINE__); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd52, set 0xf8 data (%d) ...\n", + __LINE__); goto _fail_; } @@ -857,12 +890,13 @@ static int sdio_clear_int_ext(u32 val) goto _fail_; for (i = g_sdio.nint; i < MAX_NUM_INT; i++) { if (flags & 1) - g_sdio.dPrint(N_ERR, "[wilc sdio]: Unexpected interrupt cleared %d...\n", i); + dev_err(&func->dev, + "Unexpected interrupt cleared %d...\n", + i); flags >>= 1; } } } -#endif /* WILC_SDIO_IRQ_GPIO */ { u32 vmm_ctl; @@ -886,9 +920,11 @@ static int sdio_clear_int_ext(u32 val) cmd.raw = 0; cmd.address = 0xf6; cmd.data = vmm_ctl; - ret = g_sdio.sdio_cmd52(&cmd); - if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0xf6 data (%d) ...\n", __LINE__); + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd52, set 0xf6 data (%d) ...\n", + __LINE__); goto _fail_; } } @@ -900,16 +936,18 @@ _fail_: return 0; } -static int sdio_sync_ext(int nint /* how mant interrupts to enable. */) +static int sdio_sync_ext(struct wilc *wilc, int nint) { + struct sdio_func *func = dev_to_sdio_func(wilc->dev); u32 reg; if (nint > MAX_NUM_INT) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Too many interupts (%d)...\n", nint); + dev_err(&func->dev, "Too many interupts (%d)...\n", nint); return 0; } if (nint > MAX_NUN_INT_THRPT_ENH2) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Error: Cannot support more than 5 interrupts when has_thrpt_enh2=1.\n"); + dev_err(&func->dev, + "Cannot support more than 5 interrupts when has_thrpt_enh2=1.\n"); return 0; } @@ -918,71 +956,77 @@ static int sdio_sync_ext(int nint /* how mant interrupts to enable. */) /** * Disable power sequencer **/ - if (!sdio_read_reg(WILC_MISC, ®)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed read misc reg...\n"); + if (!sdio_read_reg(wilc, WILC_MISC, ®)) { + dev_err(&func->dev, "Failed read misc reg...\n"); return 0; } reg &= ~BIT(8); - if (!sdio_write_reg(WILC_MISC, reg)) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed write misc reg...\n"); + if (!sdio_write_reg(wilc, WILC_MISC, reg)) { + dev_err(&func->dev, "Failed write misc reg...\n"); return 0; } -#ifdef WILC_SDIO_IRQ_GPIO - { + if (g_sdio.irq_gpio) { u32 reg; int ret, i; /** * interrupt pin mux select **/ - ret = sdio_read_reg(WILC_PIN_MUX_0, ®); + ret = sdio_read_reg(wilc, WILC_PIN_MUX_0, ®); if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed read reg (%08x)...\n", WILC_PIN_MUX_0); + dev_err(&func->dev, "Failed read reg (%08x)...\n", + WILC_PIN_MUX_0); return 0; } reg |= BIT(8); - ret = sdio_write_reg(WILC_PIN_MUX_0, reg); + ret = sdio_write_reg(wilc, WILC_PIN_MUX_0, reg); if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed write reg (%08x)...\n", WILC_PIN_MUX_0); + dev_err(&func->dev, "Failed write reg (%08x)...\n", + WILC_PIN_MUX_0); return 0; } /** * interrupt enable **/ - ret = sdio_read_reg(WILC_INTR_ENABLE, ®); + ret = sdio_read_reg(wilc, WILC_INTR_ENABLE, ®); if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed read reg (%08x)...\n", WILC_INTR_ENABLE); + dev_err(&func->dev, "Failed read reg (%08x)...\n", + WILC_INTR_ENABLE); return 0; } for (i = 0; (i < 5) && (nint > 0); i++, nint--) reg |= BIT((27 + i)); - ret = sdio_write_reg(WILC_INTR_ENABLE, reg); + ret = sdio_write_reg(wilc, WILC_INTR_ENABLE, reg); if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed write reg (%08x)...\n", WILC_INTR_ENABLE); + dev_err(&func->dev, "Failed write reg (%08x)...\n", + WILC_INTR_ENABLE); return 0; } if (nint) { - ret = sdio_read_reg(WILC_INTR2_ENABLE, ®); + ret = sdio_read_reg(wilc, WILC_INTR2_ENABLE, ®); if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed read reg (%08x)...\n", WILC_INTR2_ENABLE); + dev_err(&func->dev, + "Failed read reg (%08x)...\n", + WILC_INTR2_ENABLE); return 0; } for (i = 0; (i < 3) && (nint > 0); i++, nint--) reg |= BIT(i); - ret = sdio_read_reg(WILC_INTR2_ENABLE, ®); + ret = sdio_read_reg(wilc, WILC_INTR2_ENABLE, ®); if (!ret) { - g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed write reg (%08x)...\n", WILC_INTR2_ENABLE); + dev_err(&func->dev, + "Failed write reg (%08x)...\n", + WILC_INTR2_ENABLE); return 0; } } } -#endif /* WILC_SDIO_IRQ_GPIO */ return 1; } @@ -992,23 +1036,20 @@ static int sdio_sync_ext(int nint /* how mant interrupts to enable. */) * ********************************************/ -wilc_hif_func_t hif_sdio = { - sdio_init, - sdio_deinit, - sdio_read_reg, - sdio_write_reg, - sdio_read, - sdio_write, - sdio_sync, - sdio_clear_int, - sdio_read_int, - sdio_clear_int_ext, - sdio_read_size, - sdio_write, - sdio_read, - sdio_sync_ext, - - sdio_set_max_speed, - sdio_set_default_speed, +const struct wilc_hif_func wilc_hif_sdio = { + .hif_init = sdio_init, + .hif_deinit = sdio_deinit, + .hif_read_reg = sdio_read_reg, + .hif_write_reg = sdio_write_reg, + .hif_block_rx = sdio_read, + .hif_block_tx = sdio_write, + .hif_read_int = sdio_read_int, + .hif_clear_int_ext = sdio_clear_int_ext, + .hif_read_size = sdio_read_size, + .hif_block_tx_ext = sdio_write, + .hif_block_rx_ext = sdio_read, + .hif_sync_ext = sdio_sync_ext, + .enable_interrupt = wilc_sdio_enable_interrupt, + .disable_interrupt = wilc_sdio_disable_interrupt, }; diff --git a/drivers/staging/wilc1000/wilc_spi.c b/drivers/staging/wilc1000/wilc_spi.c index 599508beabf8..86de50c9f7f5 100644 --- a/drivers/staging/wilc1000/wilc_spi.c +++ b/drivers/staging/wilc1000/wilc_spi.c @@ -6,18 +6,25 @@ /* */ /* */ /* //////////////////////////////////////////////////////////////////////////// */ - +#include <linux/module.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/fs.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/cdev.h> +#include <linux/uaccess.h> +#include <linux/device.h> +#include <linux/spi/spi.h> +#include <linux/of_gpio.h> + +#include "linux_wlan_common.h" #include <linux/string.h> #include "wilc_wlan_if.h" #include "wilc_wlan.h" +#include "wilc_wfi_netdevice.h" typedef struct { - void *os_context; - int (*spi_tx)(u8 *, u32); - int (*spi_rx)(u8 *, u32); - int (*spi_trx)(u8 *, u8 *, u32); - int (*spi_max_speed)(void); - wilc_debug_func dPrint; int crc_off; int nint; int has_thrpt_enh; @@ -25,8 +32,8 @@ typedef struct { static wilc_spi_t g_spi; -static int spi_read(u32, u8 *, u32); -static int spi_write(u32, u8 *, u32); +static int wilc_spi_read(struct wilc *wilc, u32, u8 *, u32); +static int wilc_spi_write(struct wilc *wilc, u32, u8 *, u32); /******************************************** * @@ -111,165 +118,175 @@ static u8 crc7(u8 crc, const u8 *buffer, u32 len) #define DATA_PKT_SZ_8K (8 * 1024) #define DATA_PKT_SZ DATA_PKT_SZ_8K -static int spi_cmd(u8 cmd, u32 adr, u32 data, u32 sz, u8 clockless) +#define USE_SPI_DMA 0 + +static const struct wilc1000_ops wilc1000_spi_ops; + +static int wilc_bus_probe(struct spi_device *spi) { - u8 bc[9]; - int len = 5; - int result = N_OK; + int ret, gpio; + struct wilc *wilc; - bc[0] = cmd; - switch (cmd) { - case CMD_SINGLE_READ: /* single word (4 bytes) read */ - bc[1] = (u8)(adr >> 16); - bc[2] = (u8)(adr >> 8); - bc[3] = (u8)adr; - len = 5; - break; + gpio = of_get_gpio(spi->dev.of_node, 0); + if (gpio < 0) + gpio = GPIO_NUM; - case CMD_INTERNAL_READ: /* internal register read */ - bc[1] = (u8)(adr >> 8); - if (clockless) - bc[1] |= BIT(7); - bc[2] = (u8)adr; - bc[3] = 0x00; - len = 5; - break; + ret = wilc_netdev_init(&wilc, NULL, HIF_SPI, GPIO_NUM, &wilc_hif_spi); + if (ret) + return ret; - case CMD_TERMINATE: /* termination */ - bc[1] = 0x00; - bc[2] = 0x00; - bc[3] = 0x00; - len = 5; - break; + spi_set_drvdata(spi, wilc); + wilc->dev = &spi->dev; - case CMD_REPEAT: /* repeat */ - bc[1] = 0x00; - bc[2] = 0x00; - bc[3] = 0x00; - len = 5; - break; + return 0; +} - case CMD_RESET: /* reset */ - bc[1] = 0xff; - bc[2] = 0xff; - bc[3] = 0xff; - len = 5; - break; +static int wilc_bus_remove(struct spi_device *spi) +{ + wilc_netdev_cleanup(spi_get_drvdata(spi)); + return 0; +} - case CMD_DMA_WRITE: /* dma write */ - case CMD_DMA_READ: /* dma read */ - bc[1] = (u8)(adr >> 16); - bc[2] = (u8)(adr >> 8); - bc[3] = (u8)adr; - bc[4] = (u8)(sz >> 8); - bc[5] = (u8)(sz); - len = 7; - break; +static const struct of_device_id wilc1000_of_match[] = { + { .compatible = "atmel,wilc_spi", }, + {} +}; +MODULE_DEVICE_TABLE(of, wilc1000_of_match); + +struct spi_driver wilc1000_spi_driver = { + .driver = { + .name = MODALIAS, + .of_match_table = wilc1000_of_match, + }, + .probe = wilc_bus_probe, + .remove = wilc_bus_remove, +}; +module_spi_driver(wilc1000_spi_driver); +MODULE_LICENSE("GPL"); - case CMD_DMA_EXT_WRITE: /* dma extended write */ - case CMD_DMA_EXT_READ: /* dma extended read */ - bc[1] = (u8)(adr >> 16); - bc[2] = (u8)(adr >> 8); - bc[3] = (u8)adr; - bc[4] = (u8)(sz >> 16); - bc[5] = (u8)(sz >> 8); - bc[6] = (u8)(sz); - len = 8; - break; +static int wilc_spi_tx(struct wilc *wilc, u8 *b, u32 len) +{ + struct spi_device *spi = to_spi_device(wilc->dev); + int ret; + struct spi_message msg; - case CMD_INTERNAL_WRITE: /* internal register write */ - bc[1] = (u8)(adr >> 8); - if (clockless) - bc[1] |= BIT(7); - bc[2] = (u8)(adr); - bc[3] = (u8)(data >> 24); - bc[4] = (u8)(data >> 16); - bc[5] = (u8)(data >> 8); - bc[6] = (u8)(data); - len = 8; - break; + if (len > 0 && b) { + struct spi_transfer tr = { + .tx_buf = b, + .len = len, + .delay_usecs = 0, + }; + char *r_buffer = kzalloc(len, GFP_KERNEL); - case CMD_SINGLE_WRITE: /* single word write */ - bc[1] = (u8)(adr >> 16); - bc[2] = (u8)(adr >> 8); - bc[3] = (u8)(adr); - bc[4] = (u8)(data >> 24); - bc[5] = (u8)(data >> 16); - bc[6] = (u8)(data >> 8); - bc[7] = (u8)(data); - len = 9; - break; + if (!r_buffer) + return -ENOMEM; - default: - result = N_FAIL; - break; - } + tr.rx_buf = r_buffer; + dev_dbg(&spi->dev, "Request writing %d bytes\n", len); - if (result) { - if (!g_spi.crc_off) - bc[len - 1] = (crc7(0x7f, (const u8 *)&bc[0], len - 1)) << 1; - else - len -= 1; + memset(&msg, 0, sizeof(msg)); + spi_message_init(&msg); + msg.spi = spi; + msg.is_dma_mapped = USE_SPI_DMA; + spi_message_add_tail(&tr, &msg); - if (!g_spi.spi_tx(bc, len)) { - PRINT_ER("[wilc spi]: Failed cmd write, bus error...\n"); - result = N_FAIL; - } + ret = spi_sync(spi, &msg); + if (ret < 0) + dev_err(&spi->dev, "SPI transaction failed\n"); + + kfree(r_buffer); + } else { + dev_err(&spi->dev, + "can't write data with the following length: %d\n", + len); + dev_err(&spi->dev, + "FAILED due to NULL buffer or ZERO length check the following length: %d\n", + len); + ret = -EINVAL; } - return result; + return ret; } -static int spi_cmd_rsp(u8 cmd) +static int wilc_spi_rx(struct wilc *wilc, u8 *rb, u32 rlen) { - u8 rsp; - int result = N_OK; + struct spi_device *spi = to_spi_device(wilc->dev); + int ret; - /** - * Command/Control response - **/ - if ((cmd == CMD_RESET) || - (cmd == CMD_TERMINATE) || - (cmd == CMD_REPEAT)) { - if (!g_spi.spi_rx(&rsp, 1)) { - result = N_FAIL; - goto _fail_; - } - } + if (rlen > 0) { + struct spi_message msg; + struct spi_transfer tr = { + .rx_buf = rb, + .len = rlen, + .delay_usecs = 0, - if (!g_spi.spi_rx(&rsp, 1)) { - PRINT_ER("[wilc spi]: Failed cmd response read, bus error...\n"); - result = N_FAIL; - goto _fail_; - } + }; + char *t_buffer = kzalloc(rlen, GFP_KERNEL); - if (rsp != cmd) { - PRINT_ER("[wilc spi]: Failed cmd response, cmd (%02x), resp (%02x)\n", cmd, rsp); - result = N_FAIL; - goto _fail_; - } + if (!t_buffer) + return -ENOMEM; - /** - * State response - **/ - if (!g_spi.spi_rx(&rsp, 1)) { - PRINT_ER("[wilc spi]: Failed cmd state read, bus error...\n"); - result = N_FAIL; - goto _fail_; - } + tr.tx_buf = t_buffer; - if (rsp != 0x00) { - PRINT_ER("[wilc spi]: Failed cmd state response state (%02x)\n", rsp); - result = N_FAIL; + memset(&msg, 0, sizeof(msg)); + spi_message_init(&msg); + msg.spi = spi; + msg.is_dma_mapped = USE_SPI_DMA; + spi_message_add_tail(&tr, &msg); + + ret = spi_sync(spi, &msg); + if (ret < 0) + dev_err(&spi->dev, "SPI transaction failed\n"); + kfree(t_buffer); + } else { + dev_err(&spi->dev, + "can't read data with the following length: %u\n", + rlen); + ret = -EINVAL; } -_fail_: + return ret; +} - return result; +static int wilc_spi_tx_rx(struct wilc *wilc, u8 *wb, u8 *rb, u32 rlen) +{ + struct spi_device *spi = to_spi_device(wilc->dev); + int ret; + + if (rlen > 0) { + struct spi_message msg; + struct spi_transfer tr = { + .rx_buf = rb, + .tx_buf = wb, + .len = rlen, + .bits_per_word = 8, + .delay_usecs = 0, + + }; + + memset(&msg, 0, sizeof(msg)); + spi_message_init(&msg); + msg.spi = spi; + msg.is_dma_mapped = USE_SPI_DMA; + + spi_message_add_tail(&tr, &msg); + ret = spi_sync(spi, &msg); + if (ret < 0) + dev_err(&spi->dev, "SPI transaction failed\n"); + } else { + dev_err(&spi->dev, + "can't read data with the following length: %u\n", + rlen); + ret = -EINVAL; + } + + return ret; } -static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) +static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz, + u8 clockless) { + struct spi_device *spi = to_spi_device(wilc->dev); u8 wb[32], rb[32]; u8 wix, rix; u32 len2; @@ -398,7 +415,7 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) #undef NUM_DUMMY_BYTES if (len2 > ARRAY_SIZE(wb)) { - PRINT_ER("[wilc spi]: spi buffer size too small (%d) (%zu)\n", + dev_err(&spi->dev, "spi buffer size too small (%d) (%zu)\n", len2, ARRAY_SIZE(wb)); result = N_FAIL; return result; @@ -409,8 +426,8 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) } rix = len; - if (!g_spi.spi_trx(wb, rb, len2)) { - PRINT_ER("[wilc spi]: Failed cmd write, bus error...\n"); + if (wilc_spi_tx_rx(wilc, wb, rb, len2)) { + dev_err(&spi->dev, "Failed cmd write, bus error...\n"); result = N_FAIL; return result; } @@ -430,7 +447,7 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) /* } while(&rptr[1] <= &rb[len2]); */ if (rsp != cmd) { - PRINT_ER("[wilc spi]: Failed cmd response, cmd (%02x)" + dev_err(&spi->dev, "Failed cmd response, cmd (%02x)" ", resp (%02x)\n", cmd, rsp); result = N_FAIL; return result; @@ -441,8 +458,8 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) **/ rsp = rb[rix++]; if (rsp != 0x00) { - PRINT_ER("[wilc spi]: Failed cmd state response " - "state (%02x)\n", rsp); + dev_err(&spi->dev, "Failed cmd state response state (%02x)\n", + rsp); result = N_FAIL; return result; } @@ -469,8 +486,8 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) } while (retry--); if (retry <= 0) { - PRINT_ER("[wilc spi]: Error, data read " - "response (%02x)\n", rsp); + dev_err(&spi->dev, + "Error, data read response (%02x)\n", rsp); result = N_RESET; return result; } @@ -485,7 +502,8 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) b[2] = rb[rix++]; b[3] = rb[rix++]; } else { - PRINT_ER("[wilc spi]: buffer overrun when reading data.\n"); + dev_err(&spi->dev, + "buffer overrun when reading data.\n"); result = N_FAIL; return result; } @@ -498,7 +516,7 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) crc[0] = rb[rix++]; crc[1] = rb[rix++]; } else { - PRINT_ER("[wilc spi]: buffer overrun when reading crc.\n"); + dev_err(&spi->dev,"buffer overrun when reading crc.\n"); result = N_FAIL; return result; } @@ -524,8 +542,8 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) /** * Read bytes **/ - if (!g_spi.spi_rx(&b[ix], nbytes)) { - PRINT_ER("[wilc spi]: Failed data block read, bus error...\n"); + if (wilc_spi_rx(wilc, &b[ix], nbytes)) { + dev_err(&spi->dev, "Failed data block read, bus error...\n"); result = N_FAIL; goto _error_; } @@ -534,8 +552,8 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) * Read Crc **/ if (!g_spi.crc_off) { - if (!g_spi.spi_rx(crc, 2)) { - PRINT_ER("[wilc spi]: Failed data block crc read, bus error...\n"); + if (wilc_spi_rx(wilc, crc, 2)) { + dev_err(&spi->dev, "Failed data block crc read, bus error...\n"); result = N_FAIL; goto _error_; } @@ -565,8 +583,8 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) **/ retry = 10; do { - if (!g_spi.spi_rx(&rsp, 1)) { - PRINT_ER("[wilc spi]: Failed data response read, bus error...\n"); + if (wilc_spi_rx(wilc, &rsp, 1)) { + dev_err(&spi->dev, "Failed data response read, bus error...\n"); result = N_FAIL; break; } @@ -581,8 +599,8 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) /** * Read bytes **/ - if (!g_spi.spi_rx(&b[ix], nbytes)) { - PRINT_ER("[wilc spi]: Failed data block read, bus error...\n"); + if (wilc_spi_rx(wilc, &b[ix], nbytes)) { + dev_err(&spi->dev, "Failed data block read, bus error...\n"); result = N_FAIL; break; } @@ -591,8 +609,8 @@ static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless) * Read Crc **/ if (!g_spi.crc_off) { - if (!g_spi.spi_rx(crc, 2)) { - PRINT_ER("[wilc spi]: Failed data block crc read, bus error...\n"); + if (wilc_spi_rx(wilc, crc, 2)) { + dev_err(&spi->dev, "Failed data block crc read, bus error...\n"); result = N_FAIL; break; } @@ -607,76 +625,9 @@ _error_: return result; } -static int spi_data_read(u8 *b, u32 sz) -{ - int retry, ix, nbytes; - int result = N_OK; - u8 crc[2]; - u8 rsp; - - /** - * Data - **/ - ix = 0; - do { - if (sz <= DATA_PKT_SZ) - nbytes = sz; - else - nbytes = DATA_PKT_SZ; - - /** - * Data Respnose header - **/ - retry = 10; - do { - if (!g_spi.spi_rx(&rsp, 1)) { - PRINT_ER("[wilc spi]: Failed data response read, bus error...\n"); - result = N_FAIL; - break; - } - if (((rsp >> 4) & 0xf) == 0xf) - break; - } while (retry--); - - if (result == N_FAIL) - break; - - if (retry <= 0) { - PRINT_ER("[wilc spi]: Failed data response read...(%02x)\n", rsp); - result = N_FAIL; - break; - } - - /** - * Read bytes - **/ - if (!g_spi.spi_rx(&b[ix], nbytes)) { - PRINT_ER("[wilc spi]: Failed data block read, bus error...\n"); - result = N_FAIL; - break; - } - - /** - * Read Crc - **/ - if (!g_spi.crc_off) { - if (!g_spi.spi_rx(crc, 2)) { - PRINT_ER("[wilc spi]: Failed data block crc read, bus error...\n"); - result = N_FAIL; - break; - } - } - - ix += nbytes; - sz -= nbytes; - - } while (sz); - - return result; -} - -static int spi_data_write(u8 *b, u32 sz) +static int spi_data_write(struct wilc *wilc, u8 *b, u32 sz) { + struct spi_device *spi = to_spi_device(wilc->dev); int ix, nbytes; int result = 1; u8 cmd, order, crc[2] = {0}; @@ -709,8 +660,9 @@ static int spi_data_write(u8 *b, u32 sz) order = 0x2; } cmd |= order; - if (!g_spi.spi_tx(&cmd, 1)) { - PRINT_ER("[wilc spi]: Failed data block cmd write, bus error...\n"); + if (wilc_spi_tx(wilc, &cmd, 1)) { + dev_err(&spi->dev, + "Failed data block cmd write, bus error...\n"); result = N_FAIL; break; } @@ -718,8 +670,9 @@ static int spi_data_write(u8 *b, u32 sz) /** * Write data **/ - if (!g_spi.spi_tx(&b[ix], nbytes)) { - PRINT_ER("[wilc spi]: Failed data block write, bus error...\n"); + if (wilc_spi_tx(wilc, &b[ix], nbytes)) { + dev_err(&spi->dev, + "Failed data block write, bus error...\n"); result = N_FAIL; break; } @@ -728,8 +681,8 @@ static int spi_data_write(u8 *b, u32 sz) * Write Crc **/ if (!g_spi.crc_off) { - if (!g_spi.spi_tx(crc, 2)) { - PRINT_ER("[wilc spi]: Failed data block crc write, bus error...\n"); + if (wilc_spi_tx(wilc, crc, 2)) { + dev_err(&spi->dev,"Failed data block crc write, bus error...\n"); result = N_FAIL; break; } @@ -752,34 +705,34 @@ static int spi_data_write(u8 *b, u32 sz) * ********************************************/ -static int spi_internal_write(u32 adr, u32 dat) +static int spi_internal_write(struct wilc *wilc, u32 adr, u32 dat) { + struct spi_device *spi = to_spi_device(wilc->dev); int result; -#ifdef BIG_ENDIAN - dat = BYTE_SWAP(dat); -#endif - result = spi_cmd_complete(CMD_INTERNAL_WRITE, adr, (u8 *)&dat, 4, 0); + dat = cpu_to_le32(dat); + result = spi_cmd_complete(wilc, CMD_INTERNAL_WRITE, adr, (u8 *)&dat, 4, + 0); if (result != N_OK) { - PRINT_ER("[wilc spi]: Failed internal write cmd...\n"); + dev_err(&spi->dev, "Failed internal write cmd...\n"); } return result; } -static int spi_internal_read(u32 adr, u32 *data) +static int spi_internal_read(struct wilc *wilc, u32 adr, u32 *data) { + struct spi_device *spi = to_spi_device(wilc->dev); int result; - result = spi_cmd_complete(CMD_INTERNAL_READ, adr, (u8 *)data, 4, 0); + result = spi_cmd_complete(wilc, CMD_INTERNAL_READ, adr, (u8 *)data, 4, + 0); if (result != N_OK) { - PRINT_ER("[wilc spi]: Failed internal read cmd...\n"); + dev_err(&spi->dev, "Failed internal read cmd...\n"); return 0; } -#ifdef BIG_ENDIAN - *data = BYTE_SWAP(*data); -#endif + *data = cpu_to_le32(*data); return 1; } @@ -790,31 +743,31 @@ static int spi_internal_read(u32 adr, u32 *data) * ********************************************/ -static int spi_write_reg(u32 addr, u32 data) +static int wilc_spi_write_reg(struct wilc *wilc, u32 addr, u32 data) { + struct spi_device *spi = to_spi_device(wilc->dev); int result = N_OK; u8 cmd = CMD_SINGLE_WRITE; u8 clockless = 0; -#ifdef BIG_ENDIAN - data = BYTE_SWAP(data); -#endif + data = cpu_to_le32(data); if (addr < 0x30) { /* Clockless register*/ cmd = CMD_INTERNAL_WRITE; clockless = 1; } - result = spi_cmd_complete(cmd, addr, (u8 *)&data, 4, clockless); + result = spi_cmd_complete(wilc, cmd, addr, (u8 *)&data, 4, clockless); if (result != N_OK) { - PRINT_ER("[wilc spi]: Failed cmd, write reg (%08x)...\n", addr); + dev_err(&spi->dev, "Failed cmd, write reg (%08x)...\n", addr); } return result; } -static int spi_write(u32 addr, u8 *buf, u32 size) +static int wilc_spi_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size) { + struct spi_device *spi = to_spi_device(wilc->dev); int result; u8 cmd = CMD_DMA_EXT_WRITE; @@ -824,60 +777,61 @@ static int spi_write(u32 addr, u8 *buf, u32 size) if (size <= 4) return 0; - result = spi_cmd_complete(cmd, addr, NULL, size, 0); + result = spi_cmd_complete(wilc, cmd, addr, NULL, size, 0); if (result != N_OK) { - PRINT_ER("[wilc spi]: Failed cmd, write block (%08x)...\n", addr); + dev_err(&spi->dev, + "Failed cmd, write block (%08x)...\n", addr); return 0; } /** * Data **/ - result = spi_data_write(buf, size); + result = spi_data_write(wilc, buf, size); if (result != N_OK) { - PRINT_ER("[wilc spi]: Failed block data write...\n"); + dev_err(&spi->dev, "Failed block data write...\n"); } return 1; } -static int spi_read_reg(u32 addr, u32 *data) +static int wilc_spi_read_reg(struct wilc *wilc, u32 addr, u32 *data) { + struct spi_device *spi = to_spi_device(wilc->dev); int result = N_OK; u8 cmd = CMD_SINGLE_READ; u8 clockless = 0; if (addr < 0x30) { - /* PRINT_ER("***** read addr %d\n\n", addr); */ + /* dev_err(&spi->dev, "***** read addr %d\n\n", addr); */ /* Clockless register*/ cmd = CMD_INTERNAL_READ; clockless = 1; } - result = spi_cmd_complete(cmd, addr, (u8 *)data, 4, clockless); + result = spi_cmd_complete(wilc, cmd, addr, (u8 *)data, 4, clockless); if (result != N_OK) { - PRINT_ER("[wilc spi]: Failed cmd, read reg (%08x)...\n", addr); + dev_err(&spi->dev, "Failed cmd, read reg (%08x)...\n", addr); return 0; } -#ifdef BIG_ENDIAN - *data = BYTE_SWAP(*data); -#endif + *data = cpu_to_le32(*data); return 1; } -static int spi_read(u32 addr, u8 *buf, u32 size) +static int wilc_spi_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size) { + struct spi_device *spi = to_spi_device(wilc->dev); u8 cmd = CMD_DMA_EXT_READ; int result; if (size <= 4) return 0; - result = spi_cmd_complete(cmd, addr, buf, size, 0); + result = spi_cmd_complete(wilc, cmd, addr, buf, size, 0); if (result != N_OK) { - PRINT_ER("[wilc spi]: Failed cmd, read block (%08x)...\n", addr); + dev_err(&spi->dev, "Failed cmd, read block (%08x)...\n", addr); return 0; } @@ -890,20 +844,7 @@ static int spi_read(u32 addr, u8 *buf, u32 size) * ********************************************/ -static int spi_clear_int(void) -{ - u32 reg; - - if (!spi_read_reg(WILC_HOST_RX_CTRL_0, ®)) { - PRINT_ER("[wilc spi]: Failed read reg (%08x)...\n", WILC_HOST_RX_CTRL_0); - return 0; - } - reg &= ~0x1; - spi_write_reg(WILC_HOST_RX_CTRL_0, reg); - return 1; -} - -static int spi_deinit(void *pv) +static int _wilc_spi_deinit(struct wilc *wilc) { /** * TODO: @@ -911,46 +852,9 @@ static int spi_deinit(void *pv) return 1; } -static int spi_sync(void) -{ - u32 reg; - int ret; - - /** - * interrupt pin mux select - **/ - ret = spi_read_reg(WILC_PIN_MUX_0, ®); - if (!ret) { - PRINT_ER("[wilc spi]: Failed read reg (%08x)...\n", WILC_PIN_MUX_0); - return 0; - } - reg |= BIT(8); - ret = spi_write_reg(WILC_PIN_MUX_0, reg); - if (!ret) { - PRINT_ER("[wilc spi]: Failed write reg (%08x)...\n", WILC_PIN_MUX_0); - return 0; - } - - /** - * interrupt enable - **/ - ret = spi_read_reg(WILC_INTR_ENABLE, ®); - if (!ret) { - PRINT_ER("[wilc spi]: Failed read reg (%08x)...\n", WILC_INTR_ENABLE); - return 0; - } - reg |= BIT(16); - ret = spi_write_reg(WILC_INTR_ENABLE, reg); - if (!ret) { - PRINT_ER("[wilc spi]: Failed write reg (%08x)...\n", WILC_INTR_ENABLE); - return 0; - } - - return 1; -} - -static int spi_init(wilc_wlan_inp_t *inp, wilc_debug_func func) +static int wilc_spi_init(struct wilc *wilc) { + struct spi_device *spi = to_spi_device(wilc->dev); u32 reg; u32 chipid; @@ -958,8 +862,8 @@ static int spi_init(wilc_wlan_inp_t *inp, wilc_debug_func func) if (isinit) { - if (!spi_read_reg(0x1000, &chipid)) { - PRINT_ER("[wilc spi]: Fail cmd read chip id...\n"); + if (!wilc_spi_read_reg(wilc, 0x1000, &chipid)) { + dev_err(&spi->dev, "Fail cmd read chip id...\n"); return 0; } return 1; @@ -967,21 +871,6 @@ static int spi_init(wilc_wlan_inp_t *inp, wilc_debug_func func) memset(&g_spi, 0, sizeof(wilc_spi_t)); - g_spi.dPrint = func; - g_spi.os_context = inp->os_context.os_private; - if (inp->io_func.io_init) { - if (!inp->io_func.io_init(g_spi.os_context)) { - PRINT_ER("[wilc spi]: Failed io init bus...\n"); - return 0; - } - } else { - return 0; - } - g_spi.spi_tx = inp->io_func.u.spi.spi_tx; - g_spi.spi_rx = inp->io_func.u.spi.spi_rx; - g_spi.spi_trx = inp->io_func.u.spi.spi_trx; - g_spi.spi_max_speed = inp->io_func.u.spi.spi_max_speed; - /** * configure protocol **/ @@ -989,14 +878,15 @@ static int spi_init(wilc_wlan_inp_t *inp, wilc_debug_func func) /* TODO: We can remove the CRC trials if there is a definite way to reset */ /* the SPI to it's initial value. */ - if (!spi_internal_read(WILC_SPI_PROTOCOL_OFFSET, ®)) { + if (!spi_internal_read(wilc, WILC_SPI_PROTOCOL_OFFSET, ®)) { /* Read failed. Try with CRC off. This might happen when module * is removed but chip isn't reset*/ g_spi.crc_off = 1; - PRINT_ER("[wilc spi]: Failed internal read protocol with CRC on, retyring with CRC off...\n"); - if (!spi_internal_read(WILC_SPI_PROTOCOL_OFFSET, ®)) { + dev_err(&spi->dev, "Failed internal read protocol with CRC on, retyring with CRC off...\n"); + if (!spi_internal_read(wilc, WILC_SPI_PROTOCOL_OFFSET, ®)) { /* Reaad failed with both CRC on and off, something went bad */ - PRINT_ER("[wilc spi]: Failed internal read protocol...\n"); + dev_err(&spi->dev, + "Failed internal read protocol...\n"); return 0; } } @@ -1004,8 +894,8 @@ static int spi_init(wilc_wlan_inp_t *inp, wilc_debug_func func) reg &= ~0xc; /* disable crc checking */ reg &= ~0x70; reg |= (0x5 << 4); - if (!spi_internal_write(WILC_SPI_PROTOCOL_OFFSET, reg)) { - PRINT_ER("[wilc spi %d]: Failed internal write protocol reg...\n", __LINE__); + if (!spi_internal_write(wilc, WILC_SPI_PROTOCOL_OFFSET, reg)) { + dev_err(&spi->dev, "[wilc spi %d]: Failed internal write protocol reg...\n", __LINE__); return 0; } g_spi.crc_off = 1; @@ -1015,11 +905,11 @@ static int spi_init(wilc_wlan_inp_t *inp, wilc_debug_func func) /** * make sure can read back chip id correctly **/ - if (!spi_read_reg(0x1000, &chipid)) { - PRINT_ER("[wilc spi]: Fail cmd read chip id...\n"); + if (!wilc_spi_read_reg(wilc, 0x1000, &chipid)) { + dev_err(&spi->dev, "Fail cmd read chip id...\n"); return 0; } - /* PRINT_ER("[wilc spi]: chipid (%08x)\n", chipid); */ + /* dev_err(&spi->dev, "chipid (%08x)\n", chipid); */ g_spi.has_thrpt_enh = 1; @@ -1028,29 +918,24 @@ static int spi_init(wilc_wlan_inp_t *inp, wilc_debug_func func) return 1; } -static void spi_max_bus_speed(void) -{ - g_spi.spi_max_speed(); -} - -static void spi_default_bus_speed(void) -{ -} - -static int spi_read_size(u32 *size) +static int wilc_spi_read_size(struct wilc *wilc, u32 *size) { + struct spi_device *spi = to_spi_device(wilc->dev); int ret; if (g_spi.has_thrpt_enh) { - ret = spi_internal_read(0xe840 - WILC_SPI_REG_BASE, size); + ret = spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE, + size); *size = *size & IRQ_DMA_WD_CNT_MASK; } else { u32 tmp; u32 byte_cnt; - ret = spi_read_reg(WILC_VMM_TO_HOST_SIZE, &byte_cnt); + ret = wilc_spi_read_reg(wilc, WILC_VMM_TO_HOST_SIZE, + &byte_cnt); if (!ret) { - PRINT_ER("[wilc spi]: Failed read WILC_VMM_TO_HOST_SIZE ...\n"); + dev_err(&spi->dev, + "Failed read WILC_VMM_TO_HOST_SIZE ...\n"); goto _fail_; } tmp = (byte_cnt >> 2) & IRQ_DMA_WD_CNT_MASK; @@ -1065,19 +950,23 @@ _fail_: -static int spi_read_int(u32 *int_status) +static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) { + struct spi_device *spi = to_spi_device(wilc->dev); int ret; if (g_spi.has_thrpt_enh) { - ret = spi_internal_read(0xe840 - WILC_SPI_REG_BASE, int_status); + ret = spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE, + int_status); } else { u32 tmp; u32 byte_cnt; - ret = spi_read_reg(WILC_VMM_TO_HOST_SIZE, &byte_cnt); + ret = wilc_spi_read_reg(wilc, WILC_VMM_TO_HOST_SIZE, + &byte_cnt); if (!ret) { - PRINT_ER("[wilc spi]: Failed read WILC_VMM_TO_HOST_SIZE ...\n"); + dev_err(&spi->dev, + "Failed read WILC_VMM_TO_HOST_SIZE ...\n"); goto _fail_; } tmp = (byte_cnt >> 2) & IRQ_DMA_WD_CNT_MASK; @@ -1091,11 +980,12 @@ static int spi_read_int(u32 *int_status) happended = 0; - spi_read_reg(0x1a90, &irq_flags); + wilc_spi_read_reg(wilc, 0x1a90, &irq_flags); tmp |= ((irq_flags >> 27) << IRG_FLAGS_OFFSET); if (g_spi.nint > 5) { - spi_read_reg(0x1a94, &irq_flags); + wilc_spi_read_reg(wilc, 0x1a94, + &irq_flags); tmp |= (((irq_flags >> 0) & 0x7) << (IRG_FLAGS_OFFSET + 5)); } @@ -1105,7 +995,7 @@ static int spi_read_int(u32 *int_status) unkmown_mask = ~((1ul << g_spi.nint) - 1); if ((tmp >> IRG_FLAGS_OFFSET) & unkmown_mask) { - PRINT_ER("[wilc spi]: Unexpected interrupt (2): j=%d, tmp=%x, mask=%x\n", j, tmp, unkmown_mask); + dev_err(&spi->dev, "Unexpected interrupt (2): j=%d, tmp=%x, mask=%x\n", j, tmp, unkmown_mask); happended = 1; } } @@ -1121,12 +1011,14 @@ _fail_: return ret; } -static int spi_clear_int_ext(u32 val) +static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val) { + struct spi_device *spi = to_spi_device(wilc->dev); int ret; if (g_spi.has_thrpt_enh) { - ret = spi_internal_write(0xe844 - WILC_SPI_REG_BASE, val); + ret = spi_internal_write(wilc, 0xe844 - WILC_SPI_REG_BASE, + val); } else { u32 flags; @@ -1138,18 +1030,22 @@ static int spi_clear_int_ext(u32 val) for (i = 0; i < g_spi.nint; i++) { /* No matter what you write 1 or 0, it will clear interrupt. */ if (flags & 1) - ret = spi_write_reg(0x10c8 + i * 4, 1); + ret = wilc_spi_write_reg(wilc, 0x10c8 + i * 4, 1); if (!ret) break; flags >>= 1; } if (!ret) { - PRINT_ER("[wilc spi]: Failed spi_write_reg, set reg %x ...\n", 0x10c8 + i * 4); + dev_err(&spi->dev, + "Failed wilc_spi_write_reg, set reg %x ...\n", + 0x10c8 + i * 4); goto _fail_; } for (i = g_spi.nint; i < MAX_NUM_INT; i++) { if (flags & 1) - PRINT_ER("[wilc spi]: Unexpected interrupt cleared %d...\n", i); + dev_err(&spi->dev, + "Unexpected interrupt cleared %d...\n", + i); flags >>= 1; } } @@ -1165,9 +1061,11 @@ static int spi_clear_int_ext(u32 val) if ((val & SEL_VMM_TBL1) == SEL_VMM_TBL1) tbl_ctl |= BIT(1); - ret = spi_write_reg(WILC_VMM_TBL_CTL, tbl_ctl); + ret = wilc_spi_write_reg(wilc, WILC_VMM_TBL_CTL, + tbl_ctl); if (!ret) { - PRINT_ER("[wilc spi]: fail write reg vmm_tbl_ctl...\n"); + dev_err(&spi->dev, + "fail write reg vmm_tbl_ctl...\n"); goto _fail_; } @@ -1175,9 +1073,10 @@ static int spi_clear_int_ext(u32 val) /** * enable vmm transfer. **/ - ret = spi_write_reg(WILC_VMM_CORE_CTL, 1); + ret = wilc_spi_write_reg(wilc, + WILC_VMM_CORE_CTL, 1); if (!ret) { - PRINT_ER("[wilc spi]: fail write reg vmm_core_ctl...\n"); + dev_err(&spi->dev,"fail write reg vmm_core_ctl...\n"); goto _fail_; } } @@ -1187,13 +1086,14 @@ _fail_: return ret; } -static int spi_sync_ext(int nint /* how mant interrupts to enable. */) +static int wilc_spi_sync_ext(struct wilc *wilc, int nint) { + struct spi_device *spi = to_spi_device(wilc->dev); u32 reg; int ret, i; if (nint > MAX_NUM_INT) { - PRINT_ER("[wilc spi]: Too many interupts (%d)...\n", nint); + dev_err(&spi->dev, "Too many interupts (%d)...\n", nint); return 0; } @@ -1202,39 +1102,44 @@ static int spi_sync_ext(int nint /* how mant interrupts to enable. */) /** * interrupt pin mux select **/ - ret = spi_read_reg(WILC_PIN_MUX_0, ®); + ret = wilc_spi_read_reg(wilc, WILC_PIN_MUX_0, ®); if (!ret) { - PRINT_ER("[wilc spi]: Failed read reg (%08x)...\n", WILC_PIN_MUX_0); + dev_err(&spi->dev, "Failed read reg (%08x)...\n", + WILC_PIN_MUX_0); return 0; } reg |= BIT(8); - ret = spi_write_reg(WILC_PIN_MUX_0, reg); + ret = wilc_spi_write_reg(wilc, WILC_PIN_MUX_0, reg); if (!ret) { - PRINT_ER("[wilc spi]: Failed write reg (%08x)...\n", WILC_PIN_MUX_0); + dev_err(&spi->dev, "Failed write reg (%08x)...\n", + WILC_PIN_MUX_0); return 0; } /** * interrupt enable **/ - ret = spi_read_reg(WILC_INTR_ENABLE, ®); + ret = wilc_spi_read_reg(wilc, WILC_INTR_ENABLE, ®); if (!ret) { - PRINT_ER("[wilc spi]: Failed read reg (%08x)...\n", WILC_INTR_ENABLE); + dev_err(&spi->dev, "Failed read reg (%08x)...\n", + WILC_INTR_ENABLE); return 0; } for (i = 0; (i < 5) && (nint > 0); i++, nint--) { reg |= (BIT((27 + i))); } - ret = spi_write_reg(WILC_INTR_ENABLE, reg); + ret = wilc_spi_write_reg(wilc, WILC_INTR_ENABLE, reg); if (!ret) { - PRINT_ER("[wilc spi]: Failed write reg (%08x)...\n", WILC_INTR_ENABLE); + dev_err(&spi->dev, "Failed write reg (%08x)...\n", + WILC_INTR_ENABLE); return 0; } if (nint) { - ret = spi_read_reg(WILC_INTR2_ENABLE, ®); + ret = wilc_spi_read_reg(wilc, WILC_INTR2_ENABLE, ®); if (!ret) { - PRINT_ER("[wilc spi]: Failed read reg (%08x)...\n", WILC_INTR2_ENABLE); + dev_err(&spi->dev, "Failed read reg (%08x)...\n", + WILC_INTR2_ENABLE); return 0; } @@ -1242,9 +1147,10 @@ static int spi_sync_ext(int nint /* how mant interrupts to enable. */) reg |= BIT(i); } - ret = spi_read_reg(WILC_INTR2_ENABLE, ®); + ret = wilc_spi_read_reg(wilc, WILC_INTR2_ENABLE, ®); if (!ret) { - PRINT_ER("[wilc spi]: Failed write reg (%08x)...\n", WILC_INTR2_ENABLE); + dev_err(&spi->dev, "Failed write reg (%08x)...\n", + WILC_INTR2_ENABLE); return 0; } } @@ -1256,21 +1162,17 @@ static int spi_sync_ext(int nint /* how mant interrupts to enable. */) * Global spi HIF function table * ********************************************/ -wilc_hif_func_t hif_spi = { - spi_init, - spi_deinit, - spi_read_reg, - spi_write_reg, - spi_read, - spi_write, - spi_sync, - spi_clear_int, - spi_read_int, - spi_clear_int_ext, - spi_read_size, - spi_write, - spi_read, - spi_sync_ext, - spi_max_bus_speed, - spi_default_bus_speed, +const struct wilc_hif_func wilc_hif_spi = { + .hif_init = wilc_spi_init, + .hif_deinit = _wilc_spi_deinit, + .hif_read_reg = wilc_spi_read_reg, + .hif_write_reg = wilc_spi_write_reg, + .hif_block_rx = wilc_spi_read, + .hif_block_tx = wilc_spi_write, + .hif_read_int = wilc_spi_read_int, + .hif_clear_int_ext = wilc_spi_clear_int_ext, + .hif_read_size = wilc_spi_read_size, + .hif_block_tx_ext = wilc_spi_write, + .hif_block_rx_ext = wilc_spi_read, + .hif_sync_ext = wilc_spi_sync_ext, }; diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c index 3e9501727812..53fb2d4bb0bd 100644 --- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c @@ -1,40 +1,101 @@ -/*! - * @file wilc_wfi_cfgopertaions.c - * @brief CFG80211 Function Implementation functionality - * @author aabouzaeid - * mabubakr - * mdaftedar - * zsalah - * @sa wilc_wfi_cfgopertaions.h top level OS wrapper file - * @date 31 Aug 2010 - * @version 1.0 - */ - #include "wilc_wfi_cfgoperations.h" -#ifdef WILC_SDIO -#include "linux_wlan_sdio.h" -#endif +#include "host_interface.h" #include <linux/errno.h> +#define NO_ENCRYPT 0 +#define ENCRYPT_ENABLED BIT(0) +#define WEP BIT(1) +#define WEP_EXTENDED BIT(2) +#define WPA BIT(3) +#define WPA2 BIT(4) +#define AES BIT(5) +#define TKIP BIT(6) + +#define FRAME_TYPE_ID 0 +#define ACTION_CAT_ID 24 +#define ACTION_SUBTYPE_ID 25 +#define P2P_PUB_ACTION_SUBTYPE 30 + +#define ACTION_FRAME 0xd0 +#define GO_INTENT_ATTR_ID 0x04 +#define CHANLIST_ATTR_ID 0x0b +#define OPERCHAN_ATTR_ID 0x11 +#define PUB_ACTION_ATTR_ID 0x04 +#define P2PELEM_ATTR_ID 0xdd + +#define GO_NEG_REQ 0x00 +#define GO_NEG_RSP 0x01 +#define GO_NEG_CONF 0x02 +#define P2P_INV_REQ 0x03 +#define P2P_INV_RSP 0x04 +#define PUBLIC_ACT_VENDORSPEC 0x09 +#define GAS_INTIAL_REQ 0x0a +#define GAS_INTIAL_RSP 0x0b + +#define INVALID_CHANNEL 0 + +#define nl80211_SCAN_RESULT_EXPIRE (3 * HZ) +#define SCAN_RESULT_EXPIRE (40 * HZ) + +static const u32 cipher_suites[] = { + WLAN_CIPHER_SUITE_WEP40, + WLAN_CIPHER_SUITE_WEP104, + WLAN_CIPHER_SUITE_TKIP, + WLAN_CIPHER_SUITE_CCMP, + WLAN_CIPHER_SUITE_AES_CMAC, +}; + +static const struct ieee80211_txrx_stypes + wilc_wfi_cfg80211_mgmt_types[NUM_NL80211_IFTYPES] = { + [NL80211_IFTYPE_STATION] = { + .tx = 0xffff, + .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | + BIT(IEEE80211_STYPE_PROBE_REQ >> 4) + }, + [NL80211_IFTYPE_AP] = { + .tx = 0xffff, + .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | + BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | + BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | + BIT(IEEE80211_STYPE_DISASSOC >> 4) | + BIT(IEEE80211_STYPE_AUTH >> 4) | + BIT(IEEE80211_STYPE_DEAUTH >> 4) | + BIT(IEEE80211_STYPE_ACTION >> 4) + }, + [NL80211_IFTYPE_P2P_CLIENT] = { + .tx = 0xffff, + .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | + BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | + BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | + BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | + BIT(IEEE80211_STYPE_DISASSOC >> 4) | + BIT(IEEE80211_STYPE_AUTH >> 4) | + BIT(IEEE80211_STYPE_DEAUTH >> 4) + } +}; + +#define WILC_WFI_DWELL_PASSIVE 100 +#define WILC_WFI_DWELL_ACTIVE 40 + +#define TCP_ACK_FILTER_LINK_SPEED_THRESH 54 +#define DEFAULT_LINK_SPEED 72 + + #define IS_MANAGMEMENT 0x100 #define IS_MANAGMEMENT_CALLBACK 0x080 #define IS_MGMT_STATUS_SUCCES 0x040 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff) -extern int linux_wlan_get_firmware(perInterface_wlan_t *p_nic); +extern int wilc_mac_open(struct net_device *ndev); +extern int wilc_mac_close(struct net_device *ndev); -extern int mac_open(struct net_device *ndev); -extern int mac_close(struct net_device *ndev); - -tstrNetworkInfo astrLastScannedNtwrksShadow[MAX_NUM_SCANNED_NETWORKS_SHADOW]; -u32 u32LastScannedNtwrksCountShadow; -struct timer_list hDuringIpTimer; -struct timer_list hAgingTimer; +static tstrNetworkInfo last_scanned_shadow[MAX_NUM_SCANNED_NETWORKS_SHADOW]; +static u32 last_scanned_cnt; +struct timer_list wilc_during_ip_timer; +static struct timer_list hAgingTimer; static u8 op_ifcs; -extern u8 u8ConnectedSSID[6]; -u8 g_wilc_initialized = 1; -extern bool g_obtainingIP; +u8 wilc_initialized = 1; #define CHAN2G(_channel, _freq, _flags) { \ .band = IEEE80211_BAND_2GHZ, \ @@ -45,8 +106,7 @@ extern bool g_obtainingIP; .max_power = 30, \ } -/*Frequency range for channels*/ -static struct ieee80211_channel WILC_WFI_2ghz_channels[] = { +static struct ieee80211_channel ieee80211_2ghz_channels[] = { CHAN2G(1, 2412, 0), CHAN2G(2, 2417, 0), CHAN2G(3, 2422, 0), @@ -69,9 +129,7 @@ static struct ieee80211_channel WILC_WFI_2ghz_channels[] = { .flags = (_flags), \ } - -/* Table 6 in section 3.2.1.1 */ -static struct ieee80211_rate WILC_WFI_rates[] = { +static struct ieee80211_rate ieee80211_bitrates[] = { RATETAB_ENT(10, 0, 0), RATETAB_ENT(20, 1, 0), RATETAB_ENT(55, 2, 0), @@ -91,22 +149,19 @@ struct p2p_mgmt_data { u8 *buff; }; -/*Global variable used to state the current connected STA channel*/ -u8 u8WLANChannel = INVALID_CHANNEL; - -u8 curr_channel; - -u8 u8P2P_oui[] = {0x50, 0x6f, 0x9A, 0x09}; -u8 u8P2Plocalrandom = 0x01; -u8 u8P2Precvrandom = 0x00; -u8 u8P2P_vendorspec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03}; -bool bWilc_ie; +static u8 wlan_channel = INVALID_CHANNEL; +static u8 curr_channel; +static u8 p2p_oui[] = {0x50, 0x6f, 0x9A, 0x09}; +static u8 p2p_local_random = 0x01; +static u8 p2p_recv_random = 0x00; +static u8 p2p_vendor_spec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03}; +static bool wilc_ie; static struct ieee80211_supported_band WILC_WFI_band_2ghz = { - .channels = WILC_WFI_2ghz_channels, - .n_channels = ARRAY_SIZE(WILC_WFI_2ghz_channels), - .bitrates = WILC_WFI_rates, - .n_bitrates = ARRAY_SIZE(WILC_WFI_rates), + .channels = ieee80211_2ghz_channels, + .n_channels = ARRAY_SIZE(ieee80211_2ghz_channels), + .bitrates = ieee80211_bitrates, + .n_bitrates = ARRAY_SIZE(ieee80211_bitrates), }; @@ -115,19 +170,19 @@ struct add_key_params { bool pairwise; u8 *mac_addr; }; -struct add_key_params g_add_gtk_key_params; -struct wilc_wfi_key g_key_gtk_params; -struct add_key_params g_add_ptk_key_params; -struct wilc_wfi_key g_key_ptk_params; -struct wilc_wfi_wep_key g_key_wep_params; -bool g_ptk_keys_saved; -bool g_gtk_keys_saved; -bool g_wep_keys_saved; +static struct add_key_params g_add_gtk_key_params; +static struct wilc_wfi_key g_key_gtk_params; +static struct add_key_params g_add_ptk_key_params; +static struct wilc_wfi_key g_key_ptk_params; +static struct wilc_wfi_wep_key g_key_wep_params; +static bool g_ptk_keys_saved; +static bool g_gtk_keys_saved; +static bool g_wep_keys_saved; #define AGING_TIME (9 * 1000) -#define duringIP_TIME 15000 +#define during_ip_time 15000 -void clear_shadow_scan(void *pUserVoid) +static void clear_shadow_scan(void) { int i; @@ -135,34 +190,33 @@ void clear_shadow_scan(void *pUserVoid) del_timer_sync(&hAgingTimer); PRINT_INFO(CORECONFIG_DBG, "destroy aging timer\n"); - for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { - if (astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs != NULL) { - kfree(astrLastScannedNtwrksShadow[i].pu8IEs); - astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs = NULL; + for (i = 0; i < last_scanned_cnt; i++) { + if (last_scanned_shadow[last_scanned_cnt].pu8IEs) { + kfree(last_scanned_shadow[i].pu8IEs); + last_scanned_shadow[last_scanned_cnt].pu8IEs = NULL; } - host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams); - astrLastScannedNtwrksShadow[i].pJoinParams = NULL; + wilc_free_join_params(last_scanned_shadow[i].pJoinParams); + last_scanned_shadow[i].pJoinParams = NULL; } - u32LastScannedNtwrksCountShadow = 0; + last_scanned_cnt = 0; } - } -u32 get_rssi_avg(tstrNetworkInfo *pstrNetworkInfo) +static u32 get_rssi_avg(tstrNetworkInfo *network_info) { u8 i; int rssi_v = 0; - u8 num_rssi = (pstrNetworkInfo->strRssi.u8Full) ? NUM_RSSI : (pstrNetworkInfo->strRssi.u8Index); + u8 num_rssi = (network_info->strRssi.u8Full) ? NUM_RSSI : (network_info->strRssi.u8Index); for (i = 0; i < num_rssi; i++) - rssi_v += pstrNetworkInfo->strRssi.as8RSSI[i]; + rssi_v += network_info->strRssi.as8RSSI[i]; rssi_v /= num_rssi; return rssi_v; } -void refresh_scan(void *pUserVoid, u8 all, bool bDirectScan) +static void refresh_scan(void *user_void, u8 all, bool direct_scan) { struct wilc_priv *priv; struct wiphy *wiphy; @@ -170,55 +224,49 @@ void refresh_scan(void *pUserVoid, u8 all, bool bDirectScan) int i; int rssi = 0; - priv = (struct wilc_priv *)pUserVoid; + priv = (struct wilc_priv *)user_void; wiphy = priv->dev->ieee80211_ptr->wiphy; - for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { - tstrNetworkInfo *pstrNetworkInfo; + for (i = 0; i < last_scanned_cnt; i++) { + tstrNetworkInfo *network_info; - pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]); + network_info = &last_scanned_shadow[i]; - - if ((!pstrNetworkInfo->u8Found) || all) { - s32 s32Freq; + if (!network_info->u8Found || all) { + s32 freq; struct ieee80211_channel *channel; - if (pstrNetworkInfo != NULL) { - - s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ); - channel = ieee80211_get_channel(wiphy, s32Freq); + if (network_info) { + freq = ieee80211_channel_to_frequency((s32)network_info->u8channel, IEEE80211_BAND_2GHZ); + channel = ieee80211_get_channel(wiphy, freq); - rssi = get_rssi_avg(pstrNetworkInfo); - if (memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7) || bDirectScan) { - bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo, - pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs, - (size_t)pstrNetworkInfo->u16IEsLen, (((s32)rssi) * 100), GFP_KERNEL); + rssi = get_rssi_avg(network_info); + if (memcmp("DIRECT-", network_info->au8ssid, 7) || + direct_scan) { + bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, network_info->au8bssid, network_info->u64Tsf, network_info->u16CapInfo, + network_info->u16BeaconPeriod, (const u8 *)network_info->pu8IEs, + (size_t)network_info->u16IEsLen, (((s32)rssi) * 100), GFP_KERNEL); cfg80211_put_bss(wiphy, bss); } } - } } - } -void reset_shadow_found(void *pUserVoid) +static void reset_shadow_found(void) { int i; - for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { - astrLastScannedNtwrksShadow[i].u8Found = 0; - - } + for (i = 0; i < last_scanned_cnt; i++) + last_scanned_shadow[i].u8Found = 0; } -void update_scan_time(void *pUserVoid) +static void update_scan_time(void) { int i; - for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { - astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies; - } + for (i = 0; i < last_scanned_cnt; i++) + last_scanned_shadow[i].u32TimeRcvdInScan = jiffies; } static void remove_network_from_shadow(unsigned long arg) @@ -227,24 +275,25 @@ static void remove_network_from_shadow(unsigned long arg) int i, j; - for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { - if (time_after(now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long)(SCAN_RESULT_EXPIRE))) { - PRINT_D(CFG80211_DBG, "Network expired in ScanShadow: %s\n", astrLastScannedNtwrksShadow[i].au8ssid); + for (i = 0; i < last_scanned_cnt; i++) { + if (time_after(now, last_scanned_shadow[i].u32TimeRcvdInScan + (unsigned long)(SCAN_RESULT_EXPIRE))) { + PRINT_D(CFG80211_DBG, "Network expired in ScanShadow: %s\n", last_scanned_shadow[i].au8ssid); - kfree(astrLastScannedNtwrksShadow[i].pu8IEs); - astrLastScannedNtwrksShadow[i].pu8IEs = NULL; + kfree(last_scanned_shadow[i].pu8IEs); + last_scanned_shadow[i].pu8IEs = NULL; - host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams); + wilc_free_join_params(last_scanned_shadow[i].pJoinParams); - for (j = i; (j < u32LastScannedNtwrksCountShadow - 1); j++) { - astrLastScannedNtwrksShadow[j] = astrLastScannedNtwrksShadow[j + 1]; - } - u32LastScannedNtwrksCountShadow--; + for (j = i; (j < last_scanned_cnt - 1); j++) + last_scanned_shadow[j] = last_scanned_shadow[j + 1]; + + last_scanned_cnt--; } } - PRINT_D(CFG80211_DBG, "Number of cached networks: %d\n", u32LastScannedNtwrksCountShadow); - if (u32LastScannedNtwrksCountShadow != 0) { + PRINT_D(CFG80211_DBG, "Number of cached networks: %d\n", + last_scanned_cnt); + if (last_scanned_cnt != 0) { hAgingTimer.data = arg; mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME)); } else { @@ -255,24 +304,24 @@ static void remove_network_from_shadow(unsigned long arg) static void clear_duringIP(unsigned long arg) { PRINT_D(GENERIC_DBG, "GO:IP Obtained , enable scan\n"); - g_obtainingIP = false; + wilc_optaining_ip = false; } -int is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid) +static int is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, + void *user_void) { int state = -1; int i; - if (u32LastScannedNtwrksCountShadow == 0) { + if (last_scanned_cnt == 0) { PRINT_D(CFG80211_DBG, "Starting Aging timer\n"); - hAgingTimer.data = (unsigned long)pUserVoid; + hAgingTimer.data = (unsigned long)user_void; mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME)); state = -1; } else { - /* Linear search for now */ - for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { - if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid, - pstrNetworkInfo->au8bssid, 6) == 0) { + for (i = 0; i < last_scanned_cnt; i++) { + if (memcmp(last_scanned_shadow[i].au8bssid, + pstrNetworkInfo->au8bssid, 6) == 0) { state = i; break; } @@ -281,78 +330,60 @@ int is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid) return state; } -void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams) +static void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, + void *user_void, void *pJoinParams) { - int ap_found = is_network_in_shadow(pstrNetworkInfo, pUserVoid); + int ap_found = is_network_in_shadow(pstrNetworkInfo, user_void); u32 ap_index = 0; u8 rssi_index = 0; - if (u32LastScannedNtwrksCountShadow >= MAX_NUM_SCANNED_NETWORKS_SHADOW) { + if (last_scanned_cnt >= MAX_NUM_SCANNED_NETWORKS_SHADOW) { PRINT_D(CFG80211_DBG, "Shadow network reached its maximum limit\n"); return; } if (ap_found == -1) { - ap_index = u32LastScannedNtwrksCountShadow; - u32LastScannedNtwrksCountShadow++; - + ap_index = last_scanned_cnt; + last_scanned_cnt++; } else { ap_index = ap_found; } - rssi_index = astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index; - astrLastScannedNtwrksShadow[ap_index].strRssi.as8RSSI[rssi_index++] = pstrNetworkInfo->s8rssi; + rssi_index = last_scanned_shadow[ap_index].strRssi.u8Index; + last_scanned_shadow[ap_index].strRssi.as8RSSI[rssi_index++] = pstrNetworkInfo->s8rssi; if (rssi_index == NUM_RSSI) { rssi_index = 0; - astrLastScannedNtwrksShadow[ap_index].strRssi.u8Full = 1; - } - astrLastScannedNtwrksShadow[ap_index].strRssi.u8Index = rssi_index; - - astrLastScannedNtwrksShadow[ap_index].s8rssi = pstrNetworkInfo->s8rssi; - astrLastScannedNtwrksShadow[ap_index].u16CapInfo = pstrNetworkInfo->u16CapInfo; - - astrLastScannedNtwrksShadow[ap_index].u8SsidLen = pstrNetworkInfo->u8SsidLen; - memcpy(astrLastScannedNtwrksShadow[ap_index].au8ssid, - pstrNetworkInfo->au8ssid, pstrNetworkInfo->u8SsidLen); - - memcpy(astrLastScannedNtwrksShadow[ap_index].au8bssid, - pstrNetworkInfo->au8bssid, ETH_ALEN); - - astrLastScannedNtwrksShadow[ap_index].u16BeaconPeriod = pstrNetworkInfo->u16BeaconPeriod; - astrLastScannedNtwrksShadow[ap_index].u8DtimPeriod = pstrNetworkInfo->u8DtimPeriod; - astrLastScannedNtwrksShadow[ap_index].u8channel = pstrNetworkInfo->u8channel; - - astrLastScannedNtwrksShadow[ap_index].u16IEsLen = pstrNetworkInfo->u16IEsLen; - astrLastScannedNtwrksShadow[ap_index].u64Tsf = pstrNetworkInfo->u64Tsf; + last_scanned_shadow[ap_index].strRssi.u8Full = 1; + } + last_scanned_shadow[ap_index].strRssi.u8Index = rssi_index; + last_scanned_shadow[ap_index].s8rssi = pstrNetworkInfo->s8rssi; + last_scanned_shadow[ap_index].u16CapInfo = pstrNetworkInfo->u16CapInfo; + last_scanned_shadow[ap_index].u8SsidLen = pstrNetworkInfo->u8SsidLen; + memcpy(last_scanned_shadow[ap_index].au8ssid, + pstrNetworkInfo->au8ssid, pstrNetworkInfo->u8SsidLen); + memcpy(last_scanned_shadow[ap_index].au8bssid, + pstrNetworkInfo->au8bssid, ETH_ALEN); + last_scanned_shadow[ap_index].u16BeaconPeriod = pstrNetworkInfo->u16BeaconPeriod; + last_scanned_shadow[ap_index].u8DtimPeriod = pstrNetworkInfo->u8DtimPeriod; + last_scanned_shadow[ap_index].u8channel = pstrNetworkInfo->u8channel; + last_scanned_shadow[ap_index].u16IEsLen = pstrNetworkInfo->u16IEsLen; + last_scanned_shadow[ap_index].u64Tsf = pstrNetworkInfo->u64Tsf; if (ap_found != -1) - kfree(astrLastScannedNtwrksShadow[ap_index].pu8IEs); - astrLastScannedNtwrksShadow[ap_index].pu8IEs = - kmalloc(pstrNetworkInfo->u16IEsLen, GFP_KERNEL); /* will be deallocated by the WILC_WFI_CfgScan() function */ - memcpy(astrLastScannedNtwrksShadow[ap_index].pu8IEs, - pstrNetworkInfo->pu8IEs, pstrNetworkInfo->u16IEsLen); - - astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScan = jiffies; - astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScanCached = jiffies; - astrLastScannedNtwrksShadow[ap_index].u8Found = 1; + kfree(last_scanned_shadow[ap_index].pu8IEs); + last_scanned_shadow[ap_index].pu8IEs = + kmalloc(pstrNetworkInfo->u16IEsLen, GFP_KERNEL); + memcpy(last_scanned_shadow[ap_index].pu8IEs, + pstrNetworkInfo->pu8IEs, pstrNetworkInfo->u16IEsLen); + last_scanned_shadow[ap_index].u32TimeRcvdInScan = jiffies; + last_scanned_shadow[ap_index].u32TimeRcvdInScanCached = jiffies; + last_scanned_shadow[ap_index].u8Found = 1; if (ap_found != -1) - host_int_freeJoinParams(astrLastScannedNtwrksShadow[ap_index].pJoinParams); - astrLastScannedNtwrksShadow[ap_index].pJoinParams = pJoinParams; - + wilc_free_join_params(last_scanned_shadow[ap_index].pJoinParams); + last_scanned_shadow[ap_index].pJoinParams = pJoinParams; } - -/** - * @brief CfgScanResult - * @details Callback function which returns the scan results found - * - * @param[in] tenuScanEvent enuScanEvent: enum, indicating the scan event triggered, whether that is - * SCAN_EVENT_NETWORK_FOUND or SCAN_EVENT_DONE - * tstrNetworkInfo* pstrNetworkInfo: structure holding the scan results information - * void* pUserVoid: Private structure associated with the wireless interface - * @return NONE - * @author mabubakr - * @date - * @version 1.0 - */ -static void CfgScanResult(enum scan_event enuScanEvent, tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams) +static void CfgScanResult(enum scan_event scan_event, + tstrNetworkInfo *network_info, + void *user_void, + void *join_params) { struct wilc_priv *priv; struct wiphy *wiphy; @@ -360,56 +391,45 @@ static void CfgScanResult(enum scan_event enuScanEvent, tstrNetworkInfo *pstrNet struct ieee80211_channel *channel; struct cfg80211_bss *bss = NULL; - priv = (struct wilc_priv *)pUserVoid; + priv = (struct wilc_priv *)user_void; if (priv->bCfgScanning) { - if (enuScanEvent == SCAN_EVENT_NETWORK_FOUND) { + if (scan_event == SCAN_EVENT_NETWORK_FOUND) { wiphy = priv->dev->ieee80211_ptr->wiphy; if (!wiphy) return; - if (wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC - && - ((((s32)pstrNetworkInfo->s8rssi) * 100) < 0 - || - (((s32)pstrNetworkInfo->s8rssi) * 100) > 100) - ) { + if (wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC && + (((s32)network_info->s8rssi * 100) < 0 || + ((s32)network_info->s8rssi * 100) > 100)) { PRINT_ER("wiphy signal type fial\n"); return; } - if (pstrNetworkInfo != NULL) { - s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ); + if (network_info) { + s32Freq = ieee80211_channel_to_frequency((s32)network_info->u8channel, IEEE80211_BAND_2GHZ); channel = ieee80211_get_channel(wiphy, s32Freq); if (!channel) return; PRINT_INFO(CFG80211_DBG, "Network Info:: CHANNEL Frequency: %d, RSSI: %d, CapabilityInfo: %d," - "BeaconPeriod: %d\n", channel->center_freq, (((s32)pstrNetworkInfo->s8rssi) * 100), - pstrNetworkInfo->u16CapInfo, pstrNetworkInfo->u16BeaconPeriod); - - if (pstrNetworkInfo->bNewNetwork) { - if (priv->u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */ - /* max_scan_ssids */ - PRINT_D(CFG80211_DBG, "Network %s found\n", pstrNetworkInfo->au8ssid); - + "BeaconPeriod: %d\n", channel->center_freq, (((s32)network_info->s8rssi) * 100), + network_info->u16CapInfo, network_info->u16BeaconPeriod); + if (network_info->bNewNetwork) { + if (priv->u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) { + PRINT_D(CFG80211_DBG, "Network %s found\n", network_info->au8ssid); priv->u32RcvdChCount++; - - - if (pJoinParams == NULL) { + if (!join_params) PRINT_INFO(CORECONFIG_DBG, ">> Something really bad happened\n"); - } - add_network_to_shadow(pstrNetworkInfo, priv, pJoinParams); - - /*P2P peers are sent to WPA supplicant and added to shadow table*/ + add_network_to_shadow(network_info, priv, join_params); - if (!(memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7))) { - bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo, - pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs, - (size_t)pstrNetworkInfo->u16IEsLen, (((s32)pstrNetworkInfo->s8rssi) * 100), GFP_KERNEL); + if (!(memcmp("DIRECT-", network_info->au8ssid, 7))) { + bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, network_info->au8bssid, network_info->u64Tsf, network_info->u16CapInfo, + network_info->u16BeaconPeriod, (const u8 *)network_info->pu8IEs, + (size_t)network_info->u16IEsLen, (((s32)network_info->s8rssi) * 100), GFP_KERNEL); cfg80211_put_bss(wiphy, bss); } @@ -419,19 +439,19 @@ static void CfgScanResult(enum scan_event enuScanEvent, tstrNetworkInfo *pstrNet } } else { u32 i; - /* So this network is discovered before, we'll just update its RSSI */ + for (i = 0; i < priv->u32RcvdChCount; i++) { - if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid, pstrNetworkInfo->au8bssid, 6) == 0) { - PRINT_D(CFG80211_DBG, "Update RSSI of %s\n", astrLastScannedNtwrksShadow[i].au8ssid); + if (memcmp(last_scanned_shadow[i].au8bssid, network_info->au8bssid, 6) == 0) { + PRINT_D(CFG80211_DBG, "Update RSSI of %s\n", last_scanned_shadow[i].au8ssid); - astrLastScannedNtwrksShadow[i].s8rssi = pstrNetworkInfo->s8rssi; - astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies; + last_scanned_shadow[i].s8rssi = network_info->s8rssi; + last_scanned_shadow[i].u32TimeRcvdInScan = jiffies; break; } } } } - } else if (enuScanEvent == SCAN_EVENT_DONE) { + } else if (scan_event == SCAN_EVENT_DONE) { PRINT_D(CFG80211_DBG, "Scan Done[%p]\n", priv->dev); PRINT_D(CFG80211_DBG, "Refreshing Scan ...\n"); refresh_scan(priv, 1, false); @@ -443,23 +463,19 @@ static void CfgScanResult(enum scan_event enuScanEvent, tstrNetworkInfo *pstrNet down(&(priv->hSemScanReq)); - if (priv->pstrScanReq != NULL) { + if (priv->pstrScanReq) { cfg80211_scan_done(priv->pstrScanReq, false); priv->u32RcvdChCount = 0; priv->bCfgScanning = false; priv->pstrScanReq = NULL; } up(&(priv->hSemScanReq)); - - } - /*Aborting any scan operation during mac close*/ - else if (enuScanEvent == SCAN_EVENT_ABORTED) { + } else if (scan_event == SCAN_EVENT_ABORTED) { down(&(priv->hSemScanReq)); PRINT_D(CFG80211_DBG, "Scan Aborted\n"); - if (priv->pstrScanReq != NULL) { - - update_scan_time(priv); + if (priv->pstrScanReq) { + update_scan_time(); refresh_scan(priv, 1, false); cfg80211_scan_done(priv->pstrScanReq, false); @@ -471,60 +487,7 @@ static void CfgScanResult(enum scan_event enuScanEvent, tstrNetworkInfo *pstrNet } } - -/** - * @brief WILC_WFI_Set_PMKSA - * @details Check if pmksa is cached and set it. - * @param[in] - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ -int WILC_WFI_Set_PMKSA(u8 *bssid, struct wilc_priv *priv) -{ - u32 i; - s32 s32Error = 0; - - - for (i = 0; i < priv->pmkid_list.numpmkid; i++) { - - if (!memcmp(bssid, priv->pmkid_list.pmkidlist[i].bssid, - ETH_ALEN)) { - PRINT_D(CFG80211_DBG, "PMKID successful comparison"); - - /*If bssid is found, set the values*/ - s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list); - - if (s32Error != 0) - PRINT_ER("Error in pmkid\n"); - - break; - } - } - - return s32Error; - - -} -int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID); - - -/** - * @brief CfgConnectResult - * @details - * @param[in] tenuConnDisconnEvent enuConnDisconnEvent: Type of connection response either - * connection response or disconnection notification. - * tstrConnectInfo* pstrConnectInfo: COnnection information. - * u8 u8MacStatus: Mac Status from firmware - * tstrDisconnectNotifInfo* pstrDisconnectNotifInfo: Disconnection Notification - * void* pUserVoid: Private data associated with wireless interface - * @return NONE - * @author mabubakr - * @date 01 MAR 2012 - * @version 1.0 - */ -int connecting; +int wilc_connecting; static void CfgConnectResult(enum conn_event enuConnDisconnEvent, tstrConnectInfo *pstrConnectInfo, @@ -537,18 +500,17 @@ static void CfgConnectResult(enum conn_event enuConnDisconnEvent, struct host_if_drv *pstrWFIDrv; u8 NullBssid[ETH_ALEN] = {0}; struct wilc *wl; - perInterface_wlan_t *nic; + struct wilc_vif *vif; - connecting = 0; + wilc_connecting = 0; priv = (struct wilc_priv *)pUserVoid; dev = priv->dev; - nic = netdev_priv(dev); - wl = nic->wilc; + vif = netdev_priv(dev); + wl = vif->wilc; pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; if (enuConnDisconnEvent == CONN_DISCONN_EVENT_CONN_RESP) { - /*Initialization*/ u16 u16ConnectStatus; u16ConnectStatus = pstrConnectInfo->u16ConnectStatus; @@ -557,15 +519,12 @@ static void CfgConnectResult(enum conn_event enuConnDisconnEvent, if ((u8MacStatus == MAC_DISCONNECTED) && (pstrConnectInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE)) { - /* The case here is that our station was waiting for association response frame and has just received it containing status code - * = SUCCESSFUL_STATUSCODE, while mac status is MAC_DISCONNECTED (which means something wrong happened) */ u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE; - linux_wlan_set_bssid(priv->dev, NullBssid); - eth_zero_addr(u8ConnectedSSID); + wilc_wlan_set_bssid(priv->dev, NullBssid); + eth_zero_addr(wilc_connected_ssid); - /*Invalidate u8WLANChannel value on wlan0 disconnect*/ - if (!pstrWFIDrv->u8P2PConnect) - u8WLANChannel = INVALID_CHANNEL; + if (!pstrWFIDrv->p2p_connect) + wlan_channel = INVALID_CHANNEL; PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d\n", u16ConnectStatus, u8MacStatus); } @@ -579,13 +538,13 @@ static void CfgConnectResult(enum conn_event enuConnDisconnEvent, memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN); - for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { - if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid, - pstrConnectInfo->au8bssid, ETH_ALEN) == 0) { + for (i = 0; i < last_scanned_cnt; i++) { + if (memcmp(last_scanned_shadow[i].au8bssid, + pstrConnectInfo->au8bssid, ETH_ALEN) == 0) { unsigned long now = jiffies; if (time_after(now, - astrLastScannedNtwrksShadow[i].u32TimeRcvdInScanCached + (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) { + last_scanned_shadow[i].u32TimeRcvdInScanCached + (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) { bNeedScanRefresh = true; } @@ -593,12 +552,8 @@ static void CfgConnectResult(enum conn_event enuConnDisconnEvent, } } - if (bNeedScanRefresh) { - /*Also, refrsh DIRECT- results if */ + if (bNeedScanRefresh) refresh_scan(priv, 1, true); - - } - } @@ -609,68 +564,47 @@ static void CfgConnectResult(enum conn_event enuConnDisconnEvent, cfg80211_connect_result(dev, pstrConnectInfo->au8bssid, pstrConnectInfo->pu8ReqIEs, pstrConnectInfo->ReqIEsLen, pstrConnectInfo->pu8RespIEs, pstrConnectInfo->u16RespIEsLen, - u16ConnectStatus, GFP_KERNEL); /* TODO: mostafa: u16ConnectStatus to */ - /* be replaced by pstrConnectInfo->u16ConnectStatus */ + u16ConnectStatus, GFP_KERNEL); } else if (enuConnDisconnEvent == CONN_DISCONN_EVENT_DISCONN_NOTIF) { - g_obtainingIP = false; + wilc_optaining_ip = false; PRINT_ER("Received MAC_DISCONNECTED from firmware with reason %d on dev [%p]\n", pstrDisconnectNotifInfo->u16reason, priv->dev); - u8P2Plocalrandom = 0x01; - u8P2Precvrandom = 0x00; - bWilc_ie = false; + p2p_local_random = 0x01; + p2p_recv_random = 0x00; + wilc_ie = false; eth_zero_addr(priv->au8AssociatedBss); - linux_wlan_set_bssid(priv->dev, NullBssid); - eth_zero_addr(u8ConnectedSSID); - - /*Invalidate u8WLANChannel value on wlan0 disconnect*/ - if (!pstrWFIDrv->u8P2PConnect) - u8WLANChannel = INVALID_CHANNEL; - /*Incase "P2P CLIENT Connected" send deauthentication reason by 3 to force the WPA_SUPPLICANT to directly change - * virtual interface to station*/ - if ((pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) { + wilc_wlan_set_bssid(priv->dev, NullBssid); + eth_zero_addr(wilc_connected_ssid); + + if (!pstrWFIDrv->p2p_connect) + wlan_channel = INVALID_CHANNEL; + if ((pstrWFIDrv->IFC_UP) && (dev == wl->vif[1]->ndev)) { pstrDisconnectNotifInfo->u16reason = 3; - } - /*Incase "P2P CLIENT during connection(not connected)" send deauthentication reason by 1 to force the WPA_SUPPLICANT - * to scan again and retry the connection*/ - else if ((!pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) { + } else if ((!pstrWFIDrv->IFC_UP) && (dev == wl->vif[1]->ndev)) { pstrDisconnectNotifInfo->u16reason = 1; } cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie, pstrDisconnectNotifInfo->ie_len, false, GFP_KERNEL); - } - } - -/** - * @brief set_channel - * @details Set channel for a given wireless interface. Some devices - * may support multi-channel operation (by channel hopping) so cfg80211 - * doesn't verify much. Note, however, that the passed netdev may be - * %NULL as well if the user requested changing the channel for the - * device itself, or for a monitor interface. - * @param[in] - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int set_channel(struct wiphy *wiphy, struct cfg80211_chan_def *chandef) { u32 channelnum = 0; struct wilc_priv *priv; int result = 0; + struct wilc_vif *vif; priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq); PRINT_D(CFG80211_DBG, "Setting channel %d with frequency %d\n", channelnum, chandef->chan->center_freq); curr_channel = channelnum; - result = host_int_set_mac_chnl_num(priv->hWILCWFIDrv, channelnum); + result = wilc_set_mac_chnl_num(vif, channelnum); if (result != 0) PRINT_ER("Error in setting channel %d\n", channelnum); @@ -678,19 +612,6 @@ static int set_channel(struct wiphy *wiphy, return result; } -/** - * @brief scan - * @details Request to do a scan. If returning zero, the scan request is given - * the driver, and will be valid until passed to cfg80211_scan_done(). - * For scan results, call cfg80211_inform_bss(); you can call this outside - * the scan/scan_done bracket too. - * @param[in] - * @return int : Return 0 on Success - * @author mabubakr - * @date 01 MAR 2012 - * @version 1.0 - */ - static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) { struct wilc_priv *priv; @@ -698,21 +619,20 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) s32 s32Error = 0; u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS]; struct hidden_network strHiddenNetwork; + struct wilc_vif *vif; priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); priv->pstrScanReq = request; priv->u32RcvdChCount = 0; - host_int_set_wfi_drv_handler(priv->hWILCWFIDrv); - - - reset_shadow_found(priv); + wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif)); + reset_shadow_found(); priv->bCfgScanning = true; - if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */ - /* max_scan_ssids */ + if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { for (i = 0; i < request->n_channels; i++) { au8ScanChanList[i] = (u8)ieee80211_frequency_to_channel(request->channels[i]->center_freq); PRINT_INFO(CFG80211_DBG, "ScanChannel List[%d] = %d,", i, au8ScanChanList[i]); @@ -724,15 +644,13 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) PRINT_D(CFG80211_DBG, "Number of SSIDs %d\n", request->n_ssids); if (request->n_ssids >= 1) { - - strHiddenNetwork.pstrHiddenNetworkInfo = kmalloc(request->n_ssids * sizeof(struct hidden_network), GFP_KERNEL); strHiddenNetwork.u8ssidnum = request->n_ssids; for (i = 0; i < request->n_ssids; i++) { - - if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) { + if (request->ssids[i].ssid && + request->ssids[i].ssid_len != 0) { strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = kmalloc(request->ssids[i].ssid_len, GFP_KERNEL); memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len); strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len; @@ -742,18 +660,21 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) } } PRINT_D(CFG80211_DBG, "Trigger Scan Request\n"); - s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN, - au8ScanChanList, request->n_channels, - (const u8 *)request->ie, request->ie_len, - CfgScanResult, (void *)priv, &strHiddenNetwork); + s32Error = wilc_scan(vif, USER_SCAN, ACTIVE_SCAN, + au8ScanChanList, + request->n_channels, + (const u8 *)request->ie, + request->ie_len, CfgScanResult, + (void *)priv, &strHiddenNetwork); } else { PRINT_D(CFG80211_DBG, "Trigger Scan Request\n"); - s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN, - au8ScanChanList, request->n_channels, - (const u8 *)request->ie, request->ie_len, - CfgScanResult, (void *)priv, NULL); + s32Error = wilc_scan(vif, USER_SCAN, ACTIVE_SCAN, + au8ScanChanList, + request->n_channels, + (const u8 *)request->ie, + request->ie_len, CfgScanResult, + (void *)priv, NULL); } - } else { PRINT_ER("Requested num of scanned channels is greater than the max, supported" " channels\n"); @@ -767,18 +688,6 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) return s32Error; } -/** - * @brief connect - * @details Connect to the ESS with the specified parameters. When connected, - * call cfg80211_connect_result() with status code %WLAN_STATUS_SUCCESS. - * If the connection fails for some reason, call cfg80211_connect_result() - * with the status from the AP. - * @param[in] - * @return int : Return 0 on Success - * @author mabubakr - * @date 01 MAR 2012 - * @version 1.0 - */ static int connect(struct wiphy *wiphy, struct net_device *dev, struct cfg80211_connect_params *sme) { @@ -793,39 +702,37 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, struct wilc_priv *priv; struct host_if_drv *pstrWFIDrv; tstrNetworkInfo *pstrNetworkInfo = NULL; + struct wilc_vif *vif; - - connecting = 1; + wilc_connecting = 1; priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); pstrWFIDrv = (struct host_if_drv *)(priv->hWILCWFIDrv); - host_int_set_wfi_drv_handler(priv->hWILCWFIDrv); + wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif)); PRINT_D(CFG80211_DBG, "Connecting to SSID [%s] on netdev [%p] host if [%p]\n", sme->ssid, dev, priv->hWILCWFIDrv); if (!(strncmp(sme->ssid, "DIRECT-", 7))) { PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n"); - pstrWFIDrv->u8P2PConnect = 1; - } else - pstrWFIDrv->u8P2PConnect = 0; + pstrWFIDrv->p2p_connect = 1; + } else { + pstrWFIDrv->p2p_connect = 0; + } PRINT_INFO(CFG80211_DBG, "Required SSID = %s\n , AuthType = %d\n", sme->ssid, sme->auth_type); - for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { - if ((sme->ssid_len == astrLastScannedNtwrksShadow[i].u8SsidLen) && - memcmp(astrLastScannedNtwrksShadow[i].au8ssid, - sme->ssid, - sme->ssid_len) == 0) { + for (i = 0; i < last_scanned_cnt; i++) { + if ((sme->ssid_len == last_scanned_shadow[i].u8SsidLen) && + memcmp(last_scanned_shadow[i].au8ssid, + sme->ssid, + sme->ssid_len) == 0) { PRINT_INFO(CFG80211_DBG, "Network with required SSID is found %s\n", sme->ssid); - if (sme->bssid == NULL) { - /* BSSID is not passed from the user, so decision of matching - * is done by SSID only */ + if (!sme->bssid) { PRINT_INFO(CFG80211_DBG, "BSSID is not passed from the user\n"); break; } else { - /* BSSID is also passed from the user, so decision of matching - * should consider also this passed BSSID */ - if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid, - sme->bssid, - ETH_ALEN) == 0) { + if (memcmp(last_scanned_shadow[i].au8bssid, + sme->bssid, + ETH_ALEN) == 0) { PRINT_INFO(CFG80211_DBG, "BSSID is passed from the user and matched\n"); break; } @@ -833,10 +740,10 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, } } - if (i < u32LastScannedNtwrksCountShadow) { + if (i < last_scanned_cnt) { PRINT_D(CFG80211_DBG, "Required bss is in scan results\n"); - pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]); + pstrNetworkInfo = &last_scanned_shadow[i]; PRINT_INFO(CFG80211_DBG, "network BSSID to be associated: %x%x%x%x%x%x\n", pstrNetworkInfo->au8bssid[0], pstrNetworkInfo->au8bssid[1], @@ -844,7 +751,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, pstrNetworkInfo->au8bssid[4], pstrNetworkInfo->au8bssid[5]); } else { s32Error = -ENOENT; - if (u32LastScannedNtwrksCountShadow == 0) + if (last_scanned_cnt == 0) PRINT_D(CFG80211_DBG, "No Scan results yet\n"); else PRINT_D(CFG80211_DBG, "Required bss not in scan results: Error(%d)\n", s32Error); @@ -867,8 +774,6 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, } if (sme->crypto.cipher_group != NO_ENCRYPT) { - /* To determine the u8security value, first we check the group cipher suite then {in case of WPA or WPA2} - * we will add to it the pairwise cipher suite(s) */ pcwpa_version = "Default"; PRINT_D(CORECONFIG_DBG, ">> sme->crypto.wpa_versions: %x\n", sme->crypto.wpa_versions); if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) { @@ -891,8 +796,9 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, g_key_wep_params.key_idx = sme->key_idx; g_wep_keys_saved = true; - host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx); - host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx); + wilc_set_wep_default_keyid(vif, sme->key_idx); + wilc_add_wep_key_bss_sta(vif, sme->key, sme->key_len, + sme->key_idx); } else if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104) { u8security = ENCRYPT_ENABLED | WEP | WEP_EXTENDED; pcgroup_encrypt_val = "WEP104"; @@ -908,15 +814,15 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, g_key_wep_params.key_idx = sme->key_idx; g_wep_keys_saved = true; - host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx); - host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx); + wilc_set_wep_default_keyid(vif, sme->key_idx); + wilc_add_wep_key_bss_sta(vif, sme->key, sme->key_len, + sme->key_idx); } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) { if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) { u8security = ENCRYPT_ENABLED | WPA2 | TKIP; pcgroup_encrypt_val = "WPA2_TKIP"; pccipher_group = "TKIP"; - } else { /* TODO: mostafa: here we assume that any other encryption type is AES */ - /* tenuSecurity_t = WPA2_AES; */ + } else { u8security = ENCRYPT_ENABLED | WPA2 | AES; pcgroup_encrypt_val = "WPA2_AES"; pccipher_group = "AES"; @@ -927,12 +833,10 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, u8security = ENCRYPT_ENABLED | WPA | TKIP; pcgroup_encrypt_val = "WPA_TKIP"; pccipher_group = "TKIP"; - } else { /* TODO: mostafa: here we assume that any other encryption type is AES */ - /* tenuSecurity_t = WPA_AES; */ + } else { u8security = ENCRYPT_ENABLED | WPA | AES; pcgroup_encrypt_val = "WPA_AES"; pccipher_group = "AES"; - } pcwpa_version = "WPA_VERSION_1"; @@ -942,17 +846,14 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, goto done; } - } - /* After we set the u8security value from checking the group cipher suite, {in case of WPA or WPA2} we will - * add to it the pairwise cipher suite(s) */ if ((sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) || (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) { for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++) { if (sme->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP) { u8security = u8security | TKIP; - } else { /* TODO: mostafa: here we assume that any other encryption type is AES */ + } else { u8security = u8security | AES; } } @@ -976,8 +877,6 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, PRINT_D(CFG80211_DBG, "Automatic Authentation type = %d\n", sme->auth_type); } - - /* ai: key_mgmt: enterprise case */ if (sme->crypto.n_akm_suites) { switch (sme->crypto.akm_suites[0]) { case WLAN_AKM_SUITE_8021X: @@ -997,19 +896,19 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, curr_channel = pstrNetworkInfo->u8channel; - if (!pstrWFIDrv->u8P2PConnect) { - u8WLANChannel = pstrNetworkInfo->u8channel; - } + if (!pstrWFIDrv->p2p_connect) + wlan_channel = pstrNetworkInfo->u8channel; - linux_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid); + wilc_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid); - s32Error = host_int_set_join_req(priv->hWILCWFIDrv, pstrNetworkInfo->au8bssid, sme->ssid, - sme->ssid_len, sme->ie, sme->ie_len, - CfgConnectResult, (void *)priv, u8security, - tenuAuth_type, pstrNetworkInfo->u8channel, - pstrNetworkInfo->pJoinParams); + s32Error = wilc_set_join_req(vif, pstrNetworkInfo->au8bssid, sme->ssid, + sme->ssid_len, sme->ie, sme->ie_len, + CfgConnectResult, (void *)priv, + u8security, tenuAuth_type, + pstrNetworkInfo->u8channel, + pstrNetworkInfo->pJoinParams); if (s32Error != 0) { - PRINT_ER("host_int_set_join_req(): Error(%d)\n", s32Error); + PRINT_ER("wilc_set_join_req(): Error(%d)\n", s32Error); s32Error = -ENOENT; goto done; } @@ -1019,40 +918,31 @@ done: return s32Error; } - -/** - * @brief disconnect - * @details Disconnect from the BSS/ESS. - * @param[in] - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code) { s32 s32Error = 0; struct wilc_priv *priv; struct host_if_drv *pstrWFIDrv; + struct wilc_vif *vif; u8 NullBssid[ETH_ALEN] = {0}; - connecting = 0; + wilc_connecting = 0; priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); - /*Invalidate u8WLANChannel value on wlan0 disconnect*/ pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; - if (!pstrWFIDrv->u8P2PConnect) - u8WLANChannel = INVALID_CHANNEL; - linux_wlan_set_bssid(priv->dev, NullBssid); + if (!pstrWFIDrv->p2p_connect) + wlan_channel = INVALID_CHANNEL; + wilc_wlan_set_bssid(priv->dev, NullBssid); PRINT_D(CFG80211_DBG, "Disconnecting with reason code(%d)\n", reason_code); - u8P2Plocalrandom = 0x01; - u8P2Precvrandom = 0x00; - bWilc_ie = false; - pstrWFIDrv->u64P2p_MgmtTimeout = 0; + p2p_local_random = 0x01; + p2p_recv_random = 0x00; + wilc_ie = false; + pstrWFIDrv->p2p_timeout = 0; - s32Error = host_int_disconnect(priv->hWILCWFIDrv, reason_code); + s32Error = wilc_disconnect(vif, reason_code); if (s32Error != 0) { PRINT_ER("Error in disconnecting: Error(%d)\n", s32Error); s32Error = -EINVAL; @@ -1061,16 +951,6 @@ static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_co return s32Error; } -/** - * @brief add_key - * @details Add a key with the given parameters. @mac_addr will be %NULL - * when adding a group key. - * @param[in] key : key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key, 8-byte Rx Mic Key - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, bool pairwise, const u8 *mac_addr, struct key_params *params) @@ -1086,11 +966,11 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, u8 u8pmode = NO_ENCRYPT; enum AUTHTYPE tenuAuth_type = ANY; struct wilc *wl; - perInterface_wlan_t *nic; + struct wilc_vif *vif; priv = wiphy_priv(wiphy); - nic = netdev_priv(netdev); - wl = nic->wilc; + vif = netdev_priv(netdev); + wl = vif->wilc; PRINT_D(CFG80211_DBG, "Adding key with cipher suite = %x\n", params->cipher); @@ -1105,7 +985,6 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, case WLAN_CIPHER_SUITE_WEP40: case WLAN_CIPHER_SUITE_WEP104: if (priv->wdev->iftype == NL80211_IFTYPE_AP) { - priv->WILC_WFI_wep_default = key_index; priv->WILC_WFI_wep_key_len[key_index] = params->key_len; memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len); @@ -1123,7 +1002,9 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, else u8mode = ENCRYPT_ENABLED | WEP | WEP_EXTENDED; - host_int_add_wep_key_bss_ap(priv->hWILCWFIDrv, params->key, params->key_len, key_index, u8mode, tenuAuth_type); + wilc_add_wep_key_bss_ap(vif, params->key, + params->key_len, key_index, + u8mode, tenuAuth_type); break; } if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) { @@ -1137,7 +1018,8 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, for (i = 0; i < params->key_len; i++) PRINT_INFO(CFG80211_DBG, "WEP key value[%d] = %d\n", i, params->key[i]); } - host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, params->key, params->key_len, key_index); + wilc_add_wep_key_bss_sta(vif, params->key, + params->key_len, key_index); } break; @@ -1145,14 +1027,12 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, case WLAN_CIPHER_SUITE_TKIP: case WLAN_CIPHER_SUITE_CCMP: if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) { - - if (priv->wilc_gtk[key_index] == NULL) { + if (!priv->wilc_gtk[key_index]) { priv->wilc_gtk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL); priv->wilc_gtk[key_index]->key = NULL; priv->wilc_gtk[key_index]->seq = NULL; - } - if (priv->wilc_ptk[key_index] == NULL) { + if (!priv->wilc_ptk[key_index]) { priv->wilc_ptk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL); priv->wilc_ptk[key_index]->key = NULL; priv->wilc_ptk[key_index]->seq = NULL; @@ -1169,18 +1049,14 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, priv->wilc_groupkey = u8gmode; if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { - pu8TxMic = params->key + 24; pu8RxMic = params->key + 16; KeyLen = params->key_len - 16; } - /* if there has been previous allocation for the same index through its key, free that memory and allocate again*/ kfree(priv->wilc_gtk[key_index]->key); priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL); memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len); - - /* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/ kfree(priv->wilc_gtk[key_index]->seq); if ((params->seq_len) > 0) { @@ -1200,8 +1076,10 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, } - host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen, - key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, AP_MODE, u8gmode); + wilc_add_rx_gtk(vif, params->key, KeyLen, + key_index, params->seq_len, + params->seq, pu8RxMic, + pu8TxMic, AP_MODE, u8gmode); } else { PRINT_INFO(CFG80211_DBG, "STA Address: %x%x%x%x%x\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4]); @@ -1213,7 +1091,6 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { - pu8TxMic = params->key + 24; pu8RxMic = params->key + 16; KeyLen = params->key_len - 16; @@ -1245,8 +1122,9 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, priv->wilc_ptk[key_index]->key_len = params->key_len; priv->wilc_ptk[key_index]->seq_len = params->seq_len; - host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr, - pu8RxMic, pu8TxMic, AP_MODE, u8pmode, key_index); + wilc_add_ptk(vif, params->key, KeyLen, + mac_addr, pu8RxMic, pu8TxMic, + AP_MODE, u8pmode, key_index); } break; } @@ -1255,14 +1133,12 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, u8mode = 0; if (!pairwise) { if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { - /* swap the tx mic by rx mic */ pu8RxMic = params->key + 24; pu8TxMic = params->key + 16; KeyLen = params->key_len - 16; } - /*save keys only on interface 0 (wifi interface)*/ - if (!g_gtk_keys_saved && netdev == wl->vif[0].ndev) { + if (!g_gtk_keys_saved && netdev == wl->vif[0]->ndev) { g_add_gtk_key_params.key_idx = key_index; g_add_gtk_key_params.pairwise = pairwise; if (!mac_addr) { @@ -1287,18 +1163,19 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, g_gtk_keys_saved = true; } - host_int_add_rx_gtk(priv->hWILCWFIDrv, params->key, KeyLen, - key_index, params->seq_len, params->seq, pu8RxMic, pu8TxMic, STATION_MODE, u8mode); + wilc_add_rx_gtk(vif, params->key, KeyLen, + key_index, params->seq_len, + params->seq, pu8RxMic, + pu8TxMic, STATION_MODE, + u8mode); } else { if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { - /* swap the tx mic by rx mic */ pu8RxMic = params->key + 24; pu8TxMic = params->key + 16; KeyLen = params->key_len - 16; } - /*save keys only on interface 0 (wifi interface)*/ - if (!g_ptk_keys_saved && netdev == wl->vif[0].ndev) { + if (!g_ptk_keys_saved && netdev == wl->vif[0]->ndev) { g_add_ptk_key_params.key_idx = key_index; g_add_ptk_key_params.pairwise = pairwise; if (!mac_addr) { @@ -1323,8 +1200,9 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, g_ptk_keys_saved = true; } - host_int_add_ptk(priv->hWILCWFIDrv, params->key, KeyLen, mac_addr, - pu8RxMic, pu8TxMic, STATION_MODE, u8mode, key_index); + wilc_add_ptk(vif, params->key, KeyLen, + mac_addr, pu8RxMic, pu8TxMic, + STATION_MODE, u8mode, key_index); PRINT_D(CFG80211_DBG, "Adding pairwise key\n"); if (INFO) { for (i = 0; i < params->key_len; i++) @@ -1337,22 +1215,11 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, default: PRINT_ER("Not supported cipher: Error(%d)\n", s32Error); s32Error = -ENOTSUPP; - } return s32Error; } -/** - * @brief del_key - * @details Remove a key given the @mac_addr (%NULL for a group key) - * and @key_index, return -ENOENT if the key doesn't exist. - * @param[in] - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int del_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, bool pairwise, @@ -1360,26 +1227,21 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev, { struct wilc_priv *priv; struct wilc *wl; - perInterface_wlan_t *nic; + struct wilc_vif *vif; priv = wiphy_priv(wiphy); - nic = netdev_priv(netdev); - wl = nic->wilc; + vif = netdev_priv(netdev); + wl = vif->wilc; - /*delete saved keys, if any*/ - if (netdev == wl->vif[0].ndev) { + if (netdev == wl->vif[0]->ndev) { g_ptk_keys_saved = false; g_gtk_keys_saved = false; g_wep_keys_saved = false; - /*Delete saved WEP keys params, if any*/ kfree(g_key_wep_params.key); g_key_wep_params.key = NULL; - /*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/ - if ((priv->wilc_gtk[key_index]) != NULL) { - kfree(priv->wilc_gtk[key_index]->key); priv->wilc_gtk[key_index]->key = NULL; kfree(priv->wilc_gtk[key_index]->seq); @@ -1387,11 +1249,9 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev, kfree(priv->wilc_gtk[key_index]); priv->wilc_gtk[key_index] = NULL; - } if ((priv->wilc_ptk[key_index]) != NULL) { - kfree(priv->wilc_ptk[key_index]->key); priv->wilc_ptk[key_index]->key = NULL; kfree(priv->wilc_ptk[key_index]->seq); @@ -1400,7 +1260,6 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev, priv->wilc_ptk[key_index] = NULL; } - /*Delete saved PTK and GTK keys params, if any*/ kfree(g_key_ptk_params.key); g_key_ptk_params.key = NULL; kfree(g_key_ptk_params.seq); @@ -1411,8 +1270,7 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev, kfree(g_key_gtk_params.seq); g_key_gtk_params.seq = NULL; - /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/ - Set_machw_change_vir_if(netdev, false); + wilc_set_machw_change_vir_if(netdev, false); } if (key_index >= 0 && key_index <= 3) { @@ -1420,28 +1278,15 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev, priv->WILC_WFI_wep_key_len[key_index] = 0; PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index); - host_int_remove_wep_key(priv->hWILCWFIDrv, key_index); + wilc_remove_wep_key(vif, key_index); } else { PRINT_D(CFG80211_DBG, "Removing all installed keys\n"); - host_int_remove_key(priv->hWILCWFIDrv, mac_addr); + wilc_remove_key(priv->hWILCWFIDrv, mac_addr); } return 0; } -/** - * @brief get_key - * @details Get information about the key with the given parameters. - * @mac_addr will be %NULL when requesting information for a group - * key. All pointers given to the @callback function need not be valid - * after it returns. This function should return an error if it is - * not possible to retrieve the key, -ENOENT if it doesn't exist. - * @param[in] - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, bool pairwise, const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *)) @@ -1477,69 +1322,48 @@ static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, callback(cookie, &key_params); - return 0; /* priv->wilc_gtk->key_len ?0 : -ENOENT; */ + return 0; } -/** - * @brief set_default_key - * @details Set the default management frame key on an interface - * @param[in] - * @return int : Return 0 on Success. - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, bool unicast, bool multicast) { struct wilc_priv *priv; - + struct wilc_vif *vif; priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); PRINT_D(CFG80211_DBG, "Setting default key with idx = %d\n", key_index); if (key_index != priv->WILC_WFI_wep_default) { - - host_int_set_wep_default_key(priv->hWILCWFIDrv, key_index); + wilc_set_wep_default_keyid(vif, key_index); } return 0; } -/** - * @brief get_station - * @details Get station information for the station identified by @mac - * @param[in] NONE - * @return int : Return 0 on Success. - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ - static int get_station(struct wiphy *wiphy, struct net_device *dev, const u8 *mac, struct station_info *sinfo) { struct wilc_priv *priv; - perInterface_wlan_t *nic; + struct wilc_vif *vif; u32 i = 0; u32 associatedsta = 0; u32 inactive_time = 0; priv = wiphy_priv(wiphy); - nic = netdev_priv(dev); + vif = netdev_priv(dev); - if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) { + if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) { PRINT_D(HOSTAPD_DBG, "Getting station parameters\n"); PRINT_INFO(HOSTAPD_DBG, ": %x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4]); for (i = 0; i < NUM_STA_ASSOCIATED; i++) { - if (!(memcmp(mac, priv->assoc_stainfo.au8Sta_AssociatedBss[i], ETH_ALEN))) { associatedsta = i; break; } - } if (associatedsta == -1) { @@ -1549,16 +1373,15 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev, sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME); - host_int_get_inactive_time(priv->hWILCWFIDrv, mac, &(inactive_time)); + wilc_get_inactive_time(vif, mac, &inactive_time); sinfo->inactive_time = 1000 * inactive_time; PRINT_D(CFG80211_DBG, "Inactive time %d\n", sinfo->inactive_time); - } - if (nic->iftype == STATION_MODE) { + if (vif->iftype == STATION_MODE) { struct rf_info strStatistics; - host_int_get_statistics(priv->hWILCWFIDrv, &strStatistics); + wilc_get_statistics(vif, &strStatistics); sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) | BIT(NL80211_STA_INFO_RX_PACKETS) | @@ -1566,16 +1389,17 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev, BIT(NL80211_STA_INFO_TX_FAILED) | BIT(NL80211_STA_INFO_TX_BITRATE); - sinfo->signal = strStatistics.s8RSSI; - sinfo->rx_packets = strStatistics.u32RxCount; - sinfo->tx_packets = strStatistics.u32TxCount + strStatistics.u32TxFailureCount; - sinfo->tx_failed = strStatistics.u32TxFailureCount; - sinfo->txrate.legacy = strStatistics.u8LinkSpeed * 10; + sinfo->signal = strStatistics.rssi; + sinfo->rx_packets = strStatistics.rx_cnt; + sinfo->tx_packets = strStatistics.tx_cnt + strStatistics.tx_fail_cnt; + sinfo->tx_failed = strStatistics.tx_fail_cnt; + sinfo->txrate.legacy = strStatistics.link_speed * 10; - if ((strStatistics.u8LinkSpeed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED)) - Enable_TCP_ACK_Filter(true); - else if (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED) - Enable_TCP_ACK_Filter(false); + if ((strStatistics.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && + (strStatistics.link_speed != DEFAULT_LINK_SPEED)) + wilc_enable_tcp_ack_filter(true); + else if (strStatistics.link_speed != DEFAULT_LINK_SPEED) + wilc_enable_tcp_ack_filter(false); PRINT_D(CORECONFIG_DBG, "*** stats[%d][%d][%d][%d][%d]\n", sinfo->signal, sinfo->rx_packets, sinfo->tx_packets, sinfo->tx_failed, sinfo->txrate.legacy); @@ -1583,28 +1407,6 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev, return 0; } - -/** - * @brief change_bss - * @details Modify parameters for a given BSS. - * @param[in] - * -use_cts_prot: Whether to use CTS protection - * (0 = no, 1 = yes, -1 = do not change) - * -use_short_preamble: Whether the use of short preambles is allowed - * (0 = no, 1 = yes, -1 = do not change) - * -use_short_slot_time: Whether the use of short slot time is allowed - * (0 = no, 1 = yes, -1 = do not change) - * -basic_rates: basic rates in IEEE 802.11 format - * (or NULL for no change) - * -basic_rates_len: number of basic rates - * -ap_isolate: do not forward packets between connected stations - * -ht_opmode: HT Operation mode - * (u16 = opmode, -1 = do not change) - * @return int : Return 0 on Success. - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int change_bss(struct wiphy *wiphy, struct net_device *dev, struct bss_parameters *params) { @@ -1612,23 +1414,15 @@ static int change_bss(struct wiphy *wiphy, struct net_device *dev, return 0; } -/** - * @brief set_wiphy_params - * @details Notify that wiphy parameters have changed; - * @param[in] Changed bitfield (see &enum wiphy_params_flags) describes which values - * have changed. - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int set_wiphy_params(struct wiphy *wiphy, u32 changed) { s32 s32Error = 0; struct cfg_param_val pstrCfgParamVal; struct wilc_priv *priv; + struct wilc_vif *vif; priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); pstrCfgParamVal.flag = 0; PRINT_D(CFG80211_DBG, "Setting Wiphy params\n"); @@ -1640,17 +1434,14 @@ static int set_wiphy_params(struct wiphy *wiphy, u32 changed) pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short; } if (changed & WIPHY_PARAM_RETRY_LONG) { - PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_LONG %d\n", priv->dev->ieee80211_ptr->wiphy->retry_long); pstrCfgParamVal.flag |= RETRY_LONG; pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long; - } if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->frag_threshold); pstrCfgParamVal.flag |= FRAG_THRESHOLD; pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold; - } if (changed & WIPHY_PARAM_RTS_THRESHOLD) { @@ -1658,11 +1449,10 @@ static int set_wiphy_params(struct wiphy *wiphy, u32 changed) pstrCfgParamVal.flag |= RTS_THRESHOLD; pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold; - } PRINT_D(CFG80211_DBG, "Setting CFG params in the host interface\n"); - s32Error = hif_set_cfg(priv->hWILCWFIDrv, &pstrCfgParamVal); + s32Error = wilc_hif_set_cfg(vif, &pstrCfgParamVal); if (s32Error) PRINT_ER("Error in setting WIPHY PARAMS\n"); @@ -1670,33 +1460,22 @@ static int set_wiphy_params(struct wiphy *wiphy, u32 changed) return s32Error; } -/** - * @brief set_pmksa - * @details Cache a PMKID for a BSSID. This is mostly useful for fullmac - * devices running firmwares capable of generating the (re) association - * RSN IE. It allows for faster roaming between WPA2 BSSIDs. - * @param[in] - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev, struct cfg80211_pmksa *pmksa) { u32 i; s32 s32Error = 0; u8 flag = 0; - + struct wilc_vif *vif; struct wilc_priv *priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); PRINT_D(CFG80211_DBG, "Setting PMKSA\n"); for (i = 0; i < priv->pmkid_list.numpmkid; i++) { if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid, ETH_ALEN)) { - /*If bssid already exists and pmkid value needs to reset*/ flag = PMKID_FOUND; PRINT_D(CFG80211_DBG, "PMKID already exists\n"); break; @@ -1717,24 +1496,14 @@ static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev, if (!s32Error) { PRINT_D(CFG80211_DBG, "Setting pmkid in the host interface\n"); - s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list); + s32Error = wilc_set_pmkid_info(vif, &priv->pmkid_list); } return s32Error; } -/** - * @brief del_pmksa - * @details Delete a cached PMKID. - * @param[in] - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev, struct cfg80211_pmksa *pmksa) { - u32 i; s32 s32Error = 0; @@ -1745,7 +1514,6 @@ static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev, for (i = 0; i < priv->pmkid_list.numpmkid; i++) { if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid, ETH_ALEN)) { - /*If bssid is found, reset the values*/ PRINT_D(CFG80211_DBG, "Reseting PMKID values\n"); memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(struct host_if_pmkid)); break; @@ -1769,43 +1537,18 @@ static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev, return s32Error; } -/** - * @brief flush_pmksa - * @details Flush all cached PMKIDs. - * @param[in] - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev) { struct wilc_priv *priv = wiphy_priv(wiphy); PRINT_D(CFG80211_DBG, "Flushing PMKID key values\n"); - /*Get cashed Pmkids and set all with zeros*/ memset(&priv->pmkid_list, 0, sizeof(struct host_if_pmkid_attr)); return 0; } - -/** - * @brief WILC_WFI_CfgParseRxAction - * @details Function parses the received frames and modifies the following attributes: - * -GO Intent - * -Channel list - * -Operating Channel - * - * @param[in] u8* Buffer, u32 length - * @return NONE. - * @author mdaftedar - * @date 12 DEC 2012 - * @version - */ - -void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len) +static void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len) { u32 index = 0; u32 i = 0, j = 0; @@ -1822,42 +1565,30 @@ void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len) channel_list_attr_index = index; else if (buf[index] == OPERCHAN_ATTR_ID) op_channel_attr_index = index; - index += buf[index + 1] + 3; /* ID,Length byte */ + index += buf[index + 1] + 3; } - if (u8WLANChannel != INVALID_CHANNEL) { - - /*Modify channel list attribute*/ + if (wlan_channel != INVALID_CHANNEL) { if (channel_list_attr_index) { PRINT_D(GENERIC_DBG, "Modify channel list attribute\n"); for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) { if (buf[i] == 0x51) { for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) { - buf[j] = u8WLANChannel; + buf[j] = wlan_channel; } break; } } } - /*Modify operating channel attribute*/ + if (op_channel_attr_index) { PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n"); buf[op_channel_attr_index + 6] = 0x51; - buf[op_channel_attr_index + 7] = u8WLANChannel; + buf[op_channel_attr_index + 7] = wlan_channel; } } } -/** - * @brief WILC_WFI_CfgParseTxAction - * @details Function parses the transmitted action frames and modifies the - * GO Intent attribute - * @param[in] u8* Buffer, u32 length, bool bOperChan, u8 iftype - * @return NONE. - * @author mdaftedar - * @date 12 DEC 2012 - * @version - */ -void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype) +static void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype) { u32 index = 0; u32 i = 0, j = 0; @@ -1876,44 +1607,31 @@ void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype) channel_list_attr_index = index; else if (buf[index] == OPERCHAN_ATTR_ID) op_channel_attr_index = index; - index += buf[index + 1] + 3; /* ID,Length byte */ + index += buf[index + 1] + 3; } - if (u8WLANChannel != INVALID_CHANNEL && bOperChan) { - - /*Modify channel list attribute*/ + if (wlan_channel != INVALID_CHANNEL && bOperChan) { if (channel_list_attr_index) { PRINT_D(GENERIC_DBG, "Modify channel list attribute\n"); for (i = channel_list_attr_index + 3; i < ((channel_list_attr_index + 3) + buf[channel_list_attr_index + 1]); i++) { if (buf[i] == 0x51) { for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) { - buf[j] = u8WLANChannel; + buf[j] = wlan_channel; } break; } } } - /*Modify operating channel attribute*/ + if (op_channel_attr_index) { PRINT_D(GENERIC_DBG, "Modify operating channel attribute\n"); buf[op_channel_attr_index + 6] = 0x51; - buf[op_channel_attr_index + 7] = u8WLANChannel; + buf[op_channel_attr_index + 7] = wlan_channel; } } } -/* @brief WILC_WFI_p2p_rx - * @details - * @param[in] - * - * @return None - * @author Mai Daftedar - * @date 2 JUN 2013 - * @version 1.0 - */ - void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size) { - struct wilc_priv *priv; u32 header, pkt_offset; struct host_if_drv *pstrWFIDrv; @@ -1923,11 +1641,8 @@ void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size) priv = wiphy_priv(dev->ieee80211_ptr->wiphy); pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; - /* Get WILC header */ memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET); - /* The packet offset field conain info about what type of managment frame */ - /* we are dealing with and ack status */ pkt_offset = GET_PKT_OFFSET(header); if (pkt_offset & IS_MANAGMEMENT_CALLBACK) { @@ -1948,21 +1663,18 @@ void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size) return; } } else { - PRINT_D(GENERIC_DBG, "Rx Frame Type:%x\n", buff[FRAME_TYPE_ID]); - /*Upper layer is informed that the frame is received on this freq*/ s32Freq = ieee80211_channel_to_frequency(curr_channel, IEEE80211_BAND_2GHZ); if (ieee80211_is_action(buff[FRAME_TYPE_ID])) { PRINT_D(GENERIC_DBG, "Rx Action Frame Type: %x %x\n", buff[ACTION_SUBTYPE_ID], buff[P2P_PUB_ACTION_SUBTYPE]); - if (priv->bCfgScanning && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->u64P2p_MgmtTimeout)) { + if (priv->bCfgScanning && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->p2p_timeout)) { PRINT_D(GENERIC_DBG, "Receiving action frames from wrong channels\n"); return; } if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) { - switch (buff[ACTION_SUBTYPE_ID]) { case GAS_INTIAL_REQ: PRINT_D(GENERIC_DBG, "GAS INITIAL REQ %x\n", buff[ACTION_SUBTYPE_ID]); @@ -1973,39 +1685,37 @@ void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size) break; case PUBLIC_ACT_VENDORSPEC: - /*Now we have a public action vendor specific action frame, check if its a p2p public action frame - * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/ - if (!memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) { + if (!memcmp(p2p_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) { if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) { - if (!bWilc_ie) { + if (!wilc_ie) { for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) { - if (!memcmp(u8P2P_vendorspec, &buff[i], 6)) { - u8P2Precvrandom = buff[i + 6]; - bWilc_ie = true; - PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom); + if (!memcmp(p2p_vendor_spec, &buff[i], 6)) { + p2p_recv_random = buff[i + 6]; + wilc_ie = true; + PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", p2p_recv_random); break; } } } } - if (u8P2Plocalrandom > u8P2Precvrandom) { + if (p2p_local_random > p2p_recv_random) { if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) { for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) { - if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buff[i + 2], 4))) { + if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(p2p_oui, &buff[i + 2], 4))) { WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6)); break; } } } - } else - PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom); + } else { + PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", p2p_local_random, p2p_recv_random); + } } - if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP) && (bWilc_ie)) { + if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP) && (wilc_ie)) { PRINT_D(GENERIC_DBG, "Sending P2P to host without extra elemnt\n"); - /* extra attribute for sig_dbm: signal strength in mBm, or 0 if unknown */ cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0); return; } @@ -2022,16 +1732,6 @@ void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size) } } -/** - * @brief WILC_WFI_mgmt_tx_complete - * @details Returns result of writing mgmt frame to VMM (Tx buffers are freed here) - * @param[in] priv - * transmitting status - * @return None - * @author Amr Abdelmoghny - * @date 20 MAY 2013 - * @version 1.0 - */ static void WILC_WFI_mgmt_tx_complete(void *priv, int status) { struct p2p_mgmt_data *pv_data = (struct p2p_mgmt_data *)priv; @@ -2041,16 +1741,6 @@ static void WILC_WFI_mgmt_tx_complete(void *priv, int status) kfree(pv_data); } -/** - * @brief WILC_WFI_RemainOnChannelReady - * @details Callback function, called from handle_remain_on_channel on being ready on channel - * @param - * @return none - * @author Amr abdelmoghny - * @date 9 JUNE 2013 - * @version - */ - static void WILC_WFI_RemainOnChannelReady(void *pUserVoid) { struct wilc_priv *priv; @@ -2068,16 +1758,6 @@ static void WILC_WFI_RemainOnChannelReady(void *pUserVoid) GFP_KERNEL); } -/** - * @brief WILC_WFI_RemainOnChannelExpired - * @details Callback function, called on expiration of remain-on-channel duration - * @param - * @return none - * @author Amr abdelmoghny - * @date 15 MAY 2013 - * @version - */ - static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID) { struct wilc_priv *priv; @@ -2089,7 +1769,6 @@ static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID) priv->bInP2PlistenState = false; - /*Inform wpas of remain-on-channel expiration*/ cfg80211_remain_on_channel_expired(priv->wdev, priv->strRemainOnChanParams.u64ListenCookie, priv->strRemainOnChanParams.pstrListenChan, @@ -2100,20 +1779,6 @@ static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID) } } - -/** - * @brief remain_on_channel - * @details Request the driver to remain awake on the specified - * channel for the specified duration to complete an off-channel - * operation (e.g., public action frame exchange). When the driver is - * ready on the requested channel, it must indicate this with an event - * notification by calling cfg80211_ready_on_channel(). - * @param[in] - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev, struct ieee80211_channel *chan, @@ -2121,8 +1786,10 @@ static int remain_on_channel(struct wiphy *wiphy, { s32 s32Error = 0; struct wilc_priv *priv; + struct wilc_vif *vif; priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); PRINT_D(GENERIC_DBG, "Remaining on channel %d\n", chan->hw_value); @@ -2134,61 +1801,37 @@ static int remain_on_channel(struct wiphy *wiphy, curr_channel = chan->hw_value; - /*Setting params needed by WILC_WFI_RemainOnChannelExpired()*/ priv->strRemainOnChanParams.pstrListenChan = chan; priv->strRemainOnChanParams.u64ListenCookie = *cookie; priv->strRemainOnChanParams.u32ListenDuration = duration; priv->strRemainOnChanParams.u32ListenSessionID++; - s32Error = host_int_remain_on_channel(priv->hWILCWFIDrv - , priv->strRemainOnChanParams.u32ListenSessionID - , duration - , chan->hw_value - , WILC_WFI_RemainOnChannelExpired - , WILC_WFI_RemainOnChannelReady - , (void *)priv); + s32Error = wilc_remain_on_channel(vif, + priv->strRemainOnChanParams.u32ListenSessionID, + duration, chan->hw_value, + WILC_WFI_RemainOnChannelExpired, + WILC_WFI_RemainOnChannelReady, (void *)priv); return s32Error; } -/** - * @brief cancel_remain_on_channel - * @details Cancel an on-going remain-on-channel operation. - * This allows the operation to be terminated prior to timeout based on - * the duration value. - * @param[in] struct wiphy *wiphy, - * @param[in] struct net_device *dev - * @param[in] u64 cookie, - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int cancel_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev, u64 cookie) { s32 s32Error = 0; struct wilc_priv *priv; + struct wilc_vif *vif; priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); PRINT_D(CFG80211_DBG, "Cancel remain on channel\n"); - s32Error = host_int_ListenStateExpired(priv->hWILCWFIDrv, priv->strRemainOnChanParams.u32ListenSessionID); + s32Error = wilc_listen_state_expired(vif, priv->strRemainOnChanParams.u32ListenSessionID); return s32Error; } -/** - * @brief WILC_WFI_mgmt_tx_frame - * @details - * - * @param[in] - * @return NONE. - * @author mdaftedar - * @date 01 JUL 2012 - * @version - */ -extern bool bEnablePS; + static int mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_mgmt_tx_params *params, @@ -2203,10 +1846,10 @@ static int mgmt_tx(struct wiphy *wiphy, struct wilc_priv *priv; struct host_if_drv *pstrWFIDrv; u32 i; - perInterface_wlan_t *nic; - u32 buf_len = len + sizeof(u8P2P_vendorspec) + sizeof(u8P2Plocalrandom); + struct wilc_vif *vif; + u32 buf_len = len + sizeof(p2p_vendor_spec) + sizeof(p2p_local_random); - nic = netdev_priv(wdev->netdev); + vif = netdev_priv(wdev->netdev); priv = wiphy_priv(wiphy); pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; @@ -2215,15 +1858,13 @@ static int mgmt_tx(struct wiphy *wiphy, mgmt = (const struct ieee80211_mgmt *) buf; if (ieee80211_is_mgmt(mgmt->frame_control)) { - - /*mgmt frame allocation*/ mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL); - if (mgmt_tx == NULL) { + if (!mgmt_tx) { PRINT_ER("Failed to allocate memory for mgmt_tx structure\n"); return -EFAULT; } mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL); - if (mgmt_tx->buff == NULL) { + if (!mgmt_tx->buff) { PRINT_ER("Failed to allocate memory for mgmt_tx buff\n"); kfree(mgmt_tx); return -EFAULT; @@ -2235,23 +1876,18 @@ static int mgmt_tx(struct wiphy *wiphy, if (ieee80211_is_probe_resp(mgmt->frame_control)) { PRINT_D(GENERIC_DBG, "TX: Probe Response\n"); PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value); - host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value); - /*Save the current channel after we tune to it*/ + wilc_set_mac_chnl_num(vif, chan->hw_value); curr_channel = chan->hw_value; } else if (ieee80211_is_action(mgmt->frame_control)) { PRINT_D(GENERIC_DBG, "ACTION FRAME:%x\n", (u16)mgmt->frame_control); if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) { - /*Only set the channel, if not a negotiation confirmation frame - * (If Negotiation confirmation frame, force it - * to be transmitted on the same negotiation channel)*/ - if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC || buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) { PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value); - host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value); - /*Save the current channel after we tune to it*/ + wilc_set_mac_chnl_num(vif, + chan->hw_value); curr_channel = chan->hw_value; } switch (buf[ACTION_SUBTYPE_ID]) { @@ -2269,48 +1905,37 @@ static int mgmt_tx(struct wiphy *wiphy, case PUBLIC_ACT_VENDORSPEC: { - /*Now we have a public action vendor specific action frame, check if its a p2p public action frame - * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/ - if (!memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) { - /*For the connection of two WILC's connection generate a rand number to determine who will be a GO*/ + if (!memcmp(p2p_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) { if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) { - if (u8P2Plocalrandom == 1 && u8P2Precvrandom < u8P2Plocalrandom) { - get_random_bytes(&u8P2Plocalrandom, 1); - /*Increment the number to prevent if its 0*/ - u8P2Plocalrandom++; + if (p2p_local_random == 1 && p2p_recv_random < p2p_local_random) { + get_random_bytes(&p2p_local_random, 1); + p2p_local_random++; } } if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) { - if (u8P2Plocalrandom > u8P2Precvrandom) { - PRINT_D(GENERIC_DBG, "LOCAL WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom); + if (p2p_local_random > p2p_recv_random) { + PRINT_D(GENERIC_DBG, "LOCAL WILL BE GO LocaRand=%02x RecvRand %02x\n", p2p_local_random, p2p_recv_random); - /*Search for the p2p information information element , after the Public action subtype theres a byte for teh dialog token, skip that*/ for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) { - if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buf[i + 2], 4))) { + if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(p2p_oui, &buf[i + 2], 4))) { if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP) - WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype); - - /*If using supplicant go intent, no need at all*/ - /*to parse transmitted negotiation frames*/ + WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, vif->iftype); else - WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, nic->iftype); + WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, vif->iftype); break; } } if (buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_REQ && buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_RSP) { - /* - * Adding WILC information element to allow two WILC devices to - * identify each other and connect - */ - memcpy(&mgmt_tx->buff[len], u8P2P_vendorspec, sizeof(u8P2P_vendorspec)); - mgmt_tx->buff[len + sizeof(u8P2P_vendorspec)] = u8P2Plocalrandom; + memcpy(&mgmt_tx->buff[len], p2p_vendor_spec, sizeof(p2p_vendor_spec)); + mgmt_tx->buff[len + sizeof(p2p_vendor_spec)] = p2p_local_random; mgmt_tx->size = buf_len; } - } else - PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", u8P2Plocalrandom, u8P2Precvrandom); + } else { + PRINT_D(GENERIC_DBG, "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", p2p_local_random, p2p_recv_random); + } } } else { @@ -2326,18 +1951,17 @@ static int mgmt_tx(struct wiphy *wiphy, break; } } - } PRINT_D(GENERIC_DBG, "TX: ACTION FRAME Type:%x : Chan:%d\n", buf[ACTION_SUBTYPE_ID], chan->hw_value); - pstrWFIDrv->u64P2p_MgmtTimeout = (jiffies + msecs_to_jiffies(wait)); - - PRINT_D(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n", jiffies, pstrWFIDrv->u64P2p_MgmtTimeout); + pstrWFIDrv->p2p_timeout = (jiffies + msecs_to_jiffies(wait)); + PRINT_D(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n", + jiffies, pstrWFIDrv->p2p_timeout); } - wilc_wlan_txq_add_mgmt_pkt(mgmt_tx, mgmt_tx->buff, - mgmt_tx->size, + wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx, + mgmt_tx->buff, mgmt_tx->size, WILC_WFI_mgmt_tx_complete); } else { PRINT_D(GENERIC_DBG, "This function transmits only management frames\n"); @@ -2357,7 +1981,7 @@ static int mgmt_tx_cancel_wait(struct wiphy *wiphy, PRINT_D(GENERIC_DBG, "Tx Cancel wait :%lu\n", jiffies); - pstrWFIDrv->u64P2p_MgmtTimeout = jiffies; + pstrWFIDrv->p2p_timeout = jiffies; if (!priv->bInP2PlistenState) { cfg80211_remain_on_channel_expired(priv->wdev, @@ -2369,28 +1993,16 @@ static int mgmt_tx_cancel_wait(struct wiphy *wiphy, return 0; } -/** - * @brief wilc_mgmt_frame_register - * @details Notify driver that a management frame type was - * registered. Note that this callback may not sleep, and cannot run - * concurrently with itself. - * @param[in] - * @return NONE. - * @author mdaftedar - * @date 01 JUL 2012 - * @version - */ void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev, u16 frame_type, bool reg) { - struct wilc_priv *priv; - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wl; priv = wiphy_priv(wiphy); - nic = netdev_priv(priv->wdev->netdev); - wl = nic->wilc; + vif = netdev_priv(priv->wdev->netdev); + wl = vif->wilc; if (!frame_type) return; @@ -2399,15 +2011,15 @@ void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev, switch (frame_type) { case PROBE_REQ: { - nic->g_struct_frame_reg[0].frame_type = frame_type; - nic->g_struct_frame_reg[0].reg = reg; + vif->g_struct_frame_reg[0].frame_type = frame_type; + vif->g_struct_frame_reg[0].reg = reg; } break; case ACTION: { - nic->g_struct_frame_reg[1].frame_type = frame_type; - nic->g_struct_frame_reg[1].reg = reg; + vif->g_struct_frame_reg[1].frame_type = frame_type; + vif->g_struct_frame_reg[1].reg = reg; } break; @@ -2415,54 +2027,27 @@ void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev, { break; } - } - /*If mac is closed, then return*/ + if (!wl->initialized) { PRINT_D(GENERIC_DBG, "Return since mac is closed\n"); return; } - host_int_frame_register(priv->hWILCWFIDrv, frame_type, reg); - - + wilc_frame_register(vif, frame_type, reg); } -/** - * @brief set_cqm_rssi_config - * @details Configure connection quality monitor RSSI threshold. - * @param[in] struct wiphy *wiphy: - * @param[in] struct net_device *dev: - * @param[in] s32 rssi_thold: - * @param[in] u32 rssi_hyst: - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev, s32 rssi_thold, u32 rssi_hyst) { PRINT_D(CFG80211_DBG, "Setting CQM RSSi Function\n"); return 0; - } -/** - * @brief dump_station - * @details Configure connection quality monitor RSSI threshold. - * @param[in] struct wiphy *wiphy: - * @param[in] struct net_device *dev - * @param[in] int idx - * @param[in] u8 *mac - * @param[in] struct station_info *sinfo - * @return int : Return 0 on Success - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ + static int dump_station(struct wiphy *wiphy, struct net_device *dev, int idx, u8 *mac, struct station_info *sinfo) { struct wilc_priv *priv; + struct wilc_vif *vif; PRINT_D(CFG80211_DBG, "Dumping station information\n"); @@ -2470,143 +2055,109 @@ static int dump_station(struct wiphy *wiphy, struct net_device *dev, return -ENOENT; priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); - host_int_get_rssi(priv->hWILCWFIDrv, &(sinfo->signal)); + wilc_get_rssi(vif, &sinfo->signal); return 0; - } - -/** - * @brief set_power_mgmt - * @details - * @param[in] - * @return int : Return 0 on Success. - * @author mdaftedar - * @date 01 JUL 2012 - * @version 1.0 - */ static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, bool enabled, int timeout) { struct wilc_priv *priv; + struct wilc_vif *vif; PRINT_D(CFG80211_DBG, " Power save Enabled= %d , TimeOut = %d\n", enabled, timeout); - if (wiphy == NULL) + if (!wiphy) return -ENOENT; priv = wiphy_priv(wiphy); - if (priv->hWILCWFIDrv == NULL) { + vif = netdev_priv(priv->dev); + if (!priv->hWILCWFIDrv) { PRINT_ER("Driver is NULL\n"); return -EIO; } - if (bEnablePS) - host_int_set_power_mgmt(priv->hWILCWFIDrv, enabled, timeout); + if (wilc_enable_ps) + wilc_set_power_mgmt(vif, enabled, timeout); return 0; - } -/** - * @brief change_virtual_intf - * @details Change type/configuration of virtual interface, - * keep the struct wireless_dev's iftype updated. - * @param[in] NONE - * @return int : Return 0 on Success. - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ -int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic); - static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, enum nl80211_iftype type, u32 *flags, struct vif_params *params) { struct wilc_priv *priv; - perInterface_wlan_t *nic; + struct wilc_vif *vif; u8 interface_type; u16 TID = 0; u8 i; struct wilc *wl; - nic = netdev_priv(dev); + vif = netdev_priv(dev); priv = wiphy_priv(wiphy); - wl = nic->wilc; + wl = vif->wilc; PRINT_D(HOSTAPD_DBG, "In Change virtual interface function\n"); PRINT_D(HOSTAPD_DBG, "Wireless interface name =%s\n", dev->name); - u8P2Plocalrandom = 0x01; - u8P2Precvrandom = 0x00; - - bWilc_ie = false; - - g_obtainingIP = false; - del_timer(&hDuringIpTimer); + p2p_local_random = 0x01; + p2p_recv_random = 0x00; + wilc_ie = false; + wilc_optaining_ip = false; + del_timer(&wilc_during_ip_timer); PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n"); - /*Set WILC_CHANGING_VIR_IF register to disallow adding futrue keys to CE H/W*/ + if (g_ptk_keys_saved && g_gtk_keys_saved) { - Set_machw_change_vir_if(dev, true); + wilc_set_machw_change_vir_if(dev, true); } switch (type) { case NL80211_IFTYPE_STATION: - connecting = 0; + wilc_connecting = 0; PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_STATION\n"); - /* send delba over wlan interface */ - - dev->ieee80211_ptr->iftype = type; priv->wdev->iftype = type; - nic->monitor_flag = 0; - nic->iftype = STATION_MODE; + vif->monitor_flag = 0; + vif->iftype = STATION_MODE; - /*Remove the enteries of the previously connected clients*/ memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN); - interface_type = nic->iftype; - nic->iftype = STATION_MODE; + interface_type = vif->iftype; + vif->iftype = STATION_MODE; if (wl->initialized) { - host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, - wl->vif[0].bssid, TID); - /* ensure that the message Q is empty */ - host_int_wait_msg_queue_idle(); + wilc_del_all_rx_ba_session(vif, wl->vif[0]->bssid, + TID); + wilc_wait_msg_queue_idle(); - /*Eliminate host interface blocking state*/ up(&wl->cfg_event); wilc1000_wlan_deinit(dev); - wilc1000_wlan_init(dev, nic); - g_wilc_initialized = 1; - nic->iftype = interface_type; + wilc1000_wlan_init(dev, vif); + wilc_initialized = 1; + vif->iftype = interface_type; - /*Setting interface 1 drv handler and mac address in newly downloaded FW*/ - host_int_set_wfi_drv_handler(wl->vif[0].hif_drv); - host_int_set_MacAddress(wl->vif[0].hif_drv, - wl->vif[0].src_addr); - host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE); + wilc_set_wfi_drv_handler(vif, + wilc_get_vif_idx(wl->vif[0])); + wilc_set_mac_address(wl->vif[0], wl->vif[0]->src_addr); + wilc_set_operation_mode(vif, STATION_MODE); - /*Add saved WEP keys, if any*/ if (g_wep_keys_saved) { - host_int_set_wep_default_key(wl->vif[0].hif_drv, - g_key_wep_params.key_idx); - host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv, - g_key_wep_params.key, - g_key_wep_params.key_len, - g_key_wep_params.key_idx); + wilc_set_wep_default_keyid(wl->vif[0], + g_key_wep_params.key_idx); + wilc_add_wep_key_bss_sta(wl->vif[0], + g_key_wep_params.key, + g_key_wep_params.key_len, + g_key_wep_params.key_idx); } - /*No matter the driver handler passed here, it will be overwriiten*/ - /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/ - host_int_flush_join_req(priv->hWILCWFIDrv); + wilc_flush_join_req(vif); - /*Add saved PTK and GTK keys, if any*/ if (g_ptk_keys_saved && g_gtk_keys_saved) { PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0], g_key_ptk_params.key[1], @@ -2614,15 +2165,15 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0], g_key_gtk_params.key[1], g_key_gtk_params.key[2]); - add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy, - wl->vif[0].ndev, + add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy, + wl->vif[0]->ndev, g_add_ptk_key_params.key_idx, g_add_ptk_key_params.pairwise, g_add_ptk_key_params.mac_addr, (struct key_params *)(&g_key_ptk_params)); - add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy, - wl->vif[0].ndev, + add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy, + wl->vif[0]->ndev, g_add_gtk_key_params.key_idx, g_add_gtk_key_params.pairwise, g_add_gtk_key_params.mac_addr, @@ -2631,64 +2182,58 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, if (wl->initialized) { for (i = 0; i < num_reg_frame; i++) { - PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type, - nic->g_struct_frame_reg[i].reg); - host_int_frame_register(priv->hWILCWFIDrv, - nic->g_struct_frame_reg[i].frame_type, - nic->g_struct_frame_reg[i].reg); + PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", vif->g_struct_frame_reg[i].frame_type, + vif->g_struct_frame_reg[i].reg); + wilc_frame_register(vif, + vif->g_struct_frame_reg[i].frame_type, + vif->g_struct_frame_reg[i].reg); } } - bEnablePS = true; - host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0); + wilc_enable_ps = true; + wilc_set_power_mgmt(vif, 1, 0); } break; case NL80211_IFTYPE_P2P_CLIENT: - bEnablePS = false; - host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0); - connecting = 0; + wilc_enable_ps = false; + wilc_set_power_mgmt(vif, 0, 0); + wilc_connecting = 0; PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n"); - host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, - wl->vif[0].bssid, TID); + wilc_del_all_rx_ba_session(vif, wl->vif[0]->bssid, TID); dev->ieee80211_ptr->iftype = type; priv->wdev->iftype = type; - nic->monitor_flag = 0; + vif->monitor_flag = 0; PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n"); - nic->iftype = CLIENT_MODE; + vif->iftype = CLIENT_MODE; if (wl->initialized) { - /* ensure that the message Q is empty */ - host_int_wait_msg_queue_idle(); + wilc_wait_msg_queue_idle(); wilc1000_wlan_deinit(dev); - wilc1000_wlan_init(dev, nic); - g_wilc_initialized = 1; + wilc1000_wlan_init(dev, vif); + wilc_initialized = 1; - host_int_set_wfi_drv_handler(wl->vif[0].hif_drv); - host_int_set_MacAddress(wl->vif[0].hif_drv, - wl->vif[0].src_addr); - host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE); + wilc_set_wfi_drv_handler(vif, + wilc_get_vif_idx(wl->vif[0])); + wilc_set_mac_address(wl->vif[0], wl->vif[0]->src_addr); + wilc_set_operation_mode(vif, STATION_MODE); - /*Add saved WEP keys, if any*/ if (g_wep_keys_saved) { - host_int_set_wep_default_key(wl->vif[0].hif_drv, - g_key_wep_params.key_idx); - host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv, - g_key_wep_params.key, - g_key_wep_params.key_len, - g_key_wep_params.key_idx); + wilc_set_wep_default_keyid(wl->vif[0], + g_key_wep_params.key_idx); + wilc_add_wep_key_bss_sta(wl->vif[0], + g_key_wep_params.key, + g_key_wep_params.key_len, + g_key_wep_params.key_idx); } - /*No matter the driver handler passed here, it will be overwriiten*/ - /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/ - host_int_flush_join_req(priv->hWILCWFIDrv); + wilc_flush_join_req(vif); - /*Add saved PTK and GTK keys, if any*/ if (g_ptk_keys_saved && g_gtk_keys_saved) { PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0], g_key_ptk_params.key[1], @@ -2696,59 +2241,58 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0], g_key_gtk_params.key[1], g_key_gtk_params.key[2]); - add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy, - wl->vif[0].ndev, + add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy, + wl->vif[0]->ndev, g_add_ptk_key_params.key_idx, g_add_ptk_key_params.pairwise, g_add_ptk_key_params.mac_addr, (struct key_params *)(&g_key_ptk_params)); - add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy, - wl->vif[0].ndev, + add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy, + wl->vif[0]->ndev, g_add_gtk_key_params.key_idx, g_add_gtk_key_params.pairwise, g_add_gtk_key_params.mac_addr, (struct key_params *)(&g_key_gtk_params)); } - /*Refresh scan, to refresh the scan results to the wpa_supplicant. Set MachHw to false to enable further key installments*/ refresh_scan(priv, 1, true); - Set_machw_change_vir_if(dev, false); + wilc_set_machw_change_vir_if(dev, false); if (wl->initialized) { for (i = 0; i < num_reg_frame; i++) { - PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type, - nic->g_struct_frame_reg[i].reg); - host_int_frame_register(priv->hWILCWFIDrv, - nic->g_struct_frame_reg[i].frame_type, - nic->g_struct_frame_reg[i].reg); + PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", vif->g_struct_frame_reg[i].frame_type, + vif->g_struct_frame_reg[i].reg); + wilc_frame_register(vif, + vif->g_struct_frame_reg[i].frame_type, + vif->g_struct_frame_reg[i].reg); } } } break; case NL80211_IFTYPE_AP: - bEnablePS = false; + wilc_enable_ps = false; PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_AP %d\n", type); dev->ieee80211_ptr->iftype = type; priv->wdev->iftype = type; - nic->iftype = AP_MODE; + vif->iftype = AP_MODE; PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv); PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n"); - linux_wlan_get_firmware(nic); - /*If wilc is running, then close-open to actually get new firmware running (serves P2P)*/ + wilc_wlan_get_firmware(dev); + if (wl->initialized) { - nic->iftype = AP_MODE; - mac_close(dev); - mac_open(dev); + vif->iftype = AP_MODE; + wilc_mac_close(dev); + wilc_mac_open(dev); for (i = 0; i < num_reg_frame; i++) { - PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type, - nic->g_struct_frame_reg[i].reg); - host_int_frame_register(priv->hWILCWFIDrv, - nic->g_struct_frame_reg[i].frame_type, - nic->g_struct_frame_reg[i].reg); + PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", vif->g_struct_frame_reg[i].frame_type, + vif->g_struct_frame_reg[i].reg); + wilc_frame_register(vif, + vif->g_struct_frame_reg[i].frame_type, + vif->g_struct_frame_reg[i].reg); } } break; @@ -2756,16 +2300,12 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, case NL80211_IFTYPE_P2P_GO: PRINT_D(GENERIC_DBG, "start duringIP timer\n"); - g_obtainingIP = true; - mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME)); - host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0); - /*Delete block ack has to be the latest config packet*/ - /*sent before downloading new FW. This is because it blocks on*/ - /*hWaitResponse semaphore, which allows previous config*/ - /*packets to actually take action on old FW*/ - host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, - wl->vif[0].bssid, TID); - bEnablePS = false; + wilc_optaining_ip = true; + mod_timer(&wilc_during_ip_timer, + jiffies + msecs_to_jiffies(during_ip_time)); + wilc_set_power_mgmt(vif, 0, 0); + wilc_del_all_rx_ba_session(vif, wl->vif[0]->bssid, TID); + wilc_enable_ps = false; PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n"); dev->ieee80211_ptr->iftype = type; priv->wdev->iftype = type; @@ -2775,36 +2315,28 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n"); - nic->iftype = GO_MODE; + vif->iftype = GO_MODE; - /* ensure that the message Q is empty */ - host_int_wait_msg_queue_idle(); + wilc_wait_msg_queue_idle(); wilc1000_wlan_deinit(dev); - wilc1000_wlan_init(dev, nic); - g_wilc_initialized = 1; - + wilc1000_wlan_init(dev, vif); + wilc_initialized = 1; - /*Setting interface 1 drv handler and mac address in newly downloaded FW*/ - host_int_set_wfi_drv_handler(wl->vif[0].hif_drv); - host_int_set_MacAddress(wl->vif[0].hif_drv, - wl->vif[0].src_addr); - host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE); + wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(wl->vif[0])); + wilc_set_mac_address(wl->vif[0], wl->vif[0]->src_addr); + wilc_set_operation_mode(vif, AP_MODE); - /*Add saved WEP keys, if any*/ if (g_wep_keys_saved) { - host_int_set_wep_default_key(wl->vif[0].hif_drv, - g_key_wep_params.key_idx); - host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv, - g_key_wep_params.key, - g_key_wep_params.key_len, - g_key_wep_params.key_idx); + wilc_set_wep_default_keyid(wl->vif[0], + g_key_wep_params.key_idx); + wilc_add_wep_key_bss_sta(wl->vif[0], + g_key_wep_params.key, + g_key_wep_params.key_len, + g_key_wep_params.key_idx); } - /*No matter the driver handler passed here, it will be overwriiten*/ - /*in Handle_FlushConnect() with gu8FlushedJoinReqDrvHandler*/ - host_int_flush_join_req(priv->hWILCWFIDrv); + wilc_flush_join_req(vif); - /*Add saved PTK and GTK keys, if any*/ if (g_ptk_keys_saved && g_gtk_keys_saved) { PRINT_D(CFG80211_DBG, "ptk %x %x %x cipher %x\n", g_key_ptk_params.key[0], g_key_ptk_params.key[1], @@ -2814,15 +2346,15 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, g_key_gtk_params.key[1], g_key_gtk_params.key[2], g_key_gtk_params.cipher); - add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy, - wl->vif[0].ndev, + add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy, + wl->vif[0]->ndev, g_add_ptk_key_params.key_idx, g_add_ptk_key_params.pairwise, g_add_ptk_key_params.mac_addr, (struct key_params *)(&g_key_ptk_params)); - add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy, - wl->vif[0].ndev, + add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy, + wl->vif[0]->ndev, g_add_gtk_key_params.key_idx, g_add_gtk_key_params.pairwise, g_add_gtk_key_params.mac_addr, @@ -2831,11 +2363,11 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, if (wl->initialized) { for (i = 0; i < num_reg_frame; i++) { - PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type, - nic->g_struct_frame_reg[i].reg); - host_int_frame_register(priv->hWILCWFIDrv, - nic->g_struct_frame_reg[i].frame_type, - nic->g_struct_frame_reg[i].reg); + PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", vif->g_struct_frame_reg[i].frame_type, + vif->g_struct_frame_reg[i].reg); + wilc_frame_register(vif, + vif->g_struct_frame_reg[i].frame_type, + vif->g_struct_frame_reg[i].reg); } } break; @@ -2848,32 +2380,6 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, return 0; } -/* (austin.2013-07-23) - * - * To support revised cfg80211_ops - * - * add_beacon --> start_ap - * set_beacon --> change_beacon - * del_beacon --> stop_ap - * - * beacon_parameters --> cfg80211_ap_settings - * cfg80211_beacon_data - * - * applicable for linux kernel 3.4+ - */ - -/** - * @brief start_ap - * @details Add a beacon with given parameters, @head, @interval - * and @dtim_period will be valid, @tail is optional. - * @param[in] wiphy - * @param[in] dev The net device structure - * @param[in] settings cfg80211_ap_settings parameters for the beacon to be added - * @return int : Return 0 on Success. - * @author austin - * @date 23 JUL 2013 - * @version 1.0 - */ static int start_ap(struct wiphy *wiphy, struct net_device *dev, struct cfg80211_ap_settings *settings) { @@ -2881,11 +2387,11 @@ static int start_ap(struct wiphy *wiphy, struct net_device *dev, struct wilc_priv *priv; s32 s32Error = 0; struct wilc *wl; - perInterface_wlan_t *nic; + struct wilc_vif *vif; priv = wiphy_priv(wiphy); - nic = netdev_priv(dev); - wl = nic->wilc; + vif = netdev_priv(dev); + wl = vif ->wilc; PRINT_D(HOSTAPD_DBG, "Starting ap\n"); PRINT_D(HOSTAPD_DBG, "Interval = %d\n DTIM period = %d\n Head length = %zu Tail length = %zu\n", @@ -2896,73 +2402,53 @@ static int start_ap(struct wiphy *wiphy, struct net_device *dev, if (s32Error != 0) PRINT_ER("Error in setting channel\n"); - linux_wlan_set_bssid(dev, wl->vif[0].src_addr); + wilc_wlan_set_bssid(dev, wl->vif[0]->src_addr); - s32Error = host_int_add_beacon(priv->hWILCWFIDrv, - settings->beacon_interval, - settings->dtim_period, - beacon->head_len, (u8 *)beacon->head, - beacon->tail_len, (u8 *)beacon->tail); + s32Error = wilc_add_beacon(vif, settings->beacon_interval, + settings->dtim_period, beacon->head_len, + (u8 *)beacon->head, beacon->tail_len, + (u8 *)beacon->tail); return s32Error; } -/** - * @brief change_beacon - * @details Add a beacon with given parameters, @head, @interval - * and @dtim_period will be valid, @tail is optional. - * @param[in] wiphy - * @param[in] dev The net device structure - * @param[in] beacon cfg80211_beacon_data for the beacon to be changed - * @return int : Return 0 on Success. - * @author austin - * @date 23 JUL 2013 - * @version 1.0 - */ static int change_beacon(struct wiphy *wiphy, struct net_device *dev, struct cfg80211_beacon_data *beacon) { struct wilc_priv *priv; + struct wilc_vif *vif; s32 s32Error = 0; priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); PRINT_D(HOSTAPD_DBG, "Setting beacon\n"); - s32Error = host_int_add_beacon(priv->hWILCWFIDrv, - 0, - 0, - beacon->head_len, (u8 *)beacon->head, - beacon->tail_len, (u8 *)beacon->tail); + s32Error = wilc_add_beacon(vif, 0, 0, beacon->head_len, + (u8 *)beacon->head, beacon->tail_len, + (u8 *)beacon->tail); return s32Error; } -/** - * @brief stop_ap - * @details Remove beacon configuration and stop sending the beacon. - * @param[in] - * @return int : Return 0 on Success. - * @author austin - * @date 23 JUL 2013 - * @version 1.0 - */ static int stop_ap(struct wiphy *wiphy, struct net_device *dev) { s32 s32Error = 0; struct wilc_priv *priv; + struct wilc_vif *vif; u8 NullBssid[ETH_ALEN] = {0}; if (!wiphy) return -EFAULT; priv = wiphy_priv(wiphy); + vif = netdev_priv(priv->dev); PRINT_D(HOSTAPD_DBG, "Deleting beacon\n"); - linux_wlan_set_bssid(dev, NullBssid); + wilc_wlan_set_bssid(dev, NullBssid); - s32Error = host_int_del_beacon(priv->hWILCWFIDrv); + s32Error = wilc_del_beacon(vif); if (s32Error) PRINT_ER("Host delete beacon fail\n"); @@ -2970,68 +2456,70 @@ static int stop_ap(struct wiphy *wiphy, struct net_device *dev) return s32Error; } -/** - * @brief add_station - * @details Add a new station. - * @param[in] - * @return int : Return 0 on Success. - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int add_station(struct wiphy *wiphy, struct net_device *dev, const u8 *mac, struct station_parameters *params) { s32 s32Error = 0; struct wilc_priv *priv; struct add_sta_param strStaParams = { {0} }; - perInterface_wlan_t *nic; + struct wilc_vif *vif; if (!wiphy) return -EFAULT; priv = wiphy_priv(wiphy); - nic = netdev_priv(dev); + vif = netdev_priv(dev); - if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) { - memcpy(strStaParams.au8BSSID, mac, ETH_ALEN); + if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) { + memcpy(strStaParams.bssid, mac, ETH_ALEN); memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN); - strStaParams.u16AssocID = params->aid; - strStaParams.u8NumRates = params->supported_rates_len; - strStaParams.pu8Rates = params->supported_rates; + strStaParams.aid = params->aid; + strStaParams.rates_len = params->supported_rates_len; + strStaParams.rates = params->supported_rates; PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid); PRINT_D(CFG80211_DBG, "BSSID = %x%x%x%x%x%x\n", priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][0], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][1], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][2], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][3], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][4], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]); - PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID); - PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates); + PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.aid); + PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", + strStaParams.rates_len); - if (params->ht_capa == NULL) { - strStaParams.bIsHTSupported = false; + if (!params->ht_capa) { + strStaParams.ht_supported = false; } else { - strStaParams.bIsHTSupported = true; - strStaParams.u16HTCapInfo = params->ht_capa->cap_info; - strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info; - memcpy(strStaParams.au8SuppMCsSet, ¶ms->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE); - strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info; - strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info; - strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info; + strStaParams.ht_supported = true; + strStaParams.ht_capa_info = params->ht_capa->cap_info; + strStaParams.ht_ampdu_params = params->ht_capa->ampdu_params_info; + memcpy(strStaParams.ht_supp_mcs_set, + ¶ms->ht_capa->mcs, + WILC_SUPP_MCS_SET_SIZE); + strStaParams.ht_ext_params = params->ht_capa->extended_ht_cap_info; + strStaParams.ht_tx_bf_cap = params->ht_capa->tx_BF_cap_info; + strStaParams.ht_ante_sel = params->ht_capa->antenna_selection_info; } - strStaParams.u16FlagsMask = params->sta_flags_mask; - strStaParams.u16FlagsSet = params->sta_flags_set; - - PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported); - PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo); - PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams); - PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams); - PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap); - PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap); - PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask); - PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet); - - s32Error = host_int_add_station(priv->hWILCWFIDrv, &strStaParams); + strStaParams.flags_mask = params->sta_flags_mask; + strStaParams.flags_set = params->sta_flags_set; + + PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", + strStaParams.ht_supported); + PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", + strStaParams.ht_capa_info); + PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", + strStaParams.ht_ampdu_params); + PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", + strStaParams.ht_ext_params); + PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", + strStaParams.ht_tx_bf_cap); + PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", + strStaParams.ht_ante_sel); + PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", + strStaParams.flags_mask); + PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", + strStaParams.flags_set); + + s32Error = wilc_add_station(vif, &strStaParams); if (s32Error) PRINT_ER("Host add station fail\n"); } @@ -3039,41 +2527,33 @@ static int add_station(struct wiphy *wiphy, struct net_device *dev, return s32Error; } -/** - * @brief del_station - * @details Remove a station; @mac may be NULL to remove all stations. - * @param[in] - * @return int : Return 0 on Success. - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int del_station(struct wiphy *wiphy, struct net_device *dev, struct station_del_parameters *params) { const u8 *mac = params->mac; s32 s32Error = 0; struct wilc_priv *priv; - perInterface_wlan_t *nic; + struct wilc_vif *vif; if (!wiphy) return -EFAULT; priv = wiphy_priv(wiphy); - nic = netdev_priv(dev); + vif = netdev_priv(dev); - if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) { + if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) { PRINT_D(HOSTAPD_DBG, "Deleting station\n"); - if (mac == NULL) { + if (!mac) { PRINT_D(HOSTAPD_DBG, "All associated stations\n"); - s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss); + s32Error = wilc_del_allstation(vif, + priv->assoc_stainfo.au8Sta_AssociatedBss); } else { PRINT_D(HOSTAPD_DBG, "With mac address: %x%x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } - s32Error = host_int_del_station(priv->hWILCWFIDrv, mac); + s32Error = wilc_del_station(vif, mac); if (s32Error) PRINT_ER("Host delete station fail\n"); @@ -3081,22 +2561,13 @@ static int del_station(struct wiphy *wiphy, struct net_device *dev, return s32Error; } -/** - * @brief change_station - * @details Modify a given station. - * @param[in] - * @return int : Return 0 on Success. - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ static int change_station(struct wiphy *wiphy, struct net_device *dev, const u8 *mac, struct station_parameters *params) { s32 s32Error = 0; struct wilc_priv *priv; struct add_sta_param strStaParams = { {0} }; - perInterface_wlan_t *nic; + struct wilc_vif *vif; PRINT_D(HOSTAPD_DBG, "Change station paramters\n"); @@ -3105,61 +2576,63 @@ static int change_station(struct wiphy *wiphy, struct net_device *dev, return -EFAULT; priv = wiphy_priv(wiphy); - nic = netdev_priv(dev); - - if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) { - memcpy(strStaParams.au8BSSID, mac, ETH_ALEN); - strStaParams.u16AssocID = params->aid; - strStaParams.u8NumRates = params->supported_rates_len; - strStaParams.pu8Rates = params->supported_rates; - - PRINT_D(HOSTAPD_DBG, "BSSID = %x%x%x%x%x%x\n", strStaParams.au8BSSID[0], strStaParams.au8BSSID[1], strStaParams.au8BSSID[2], strStaParams.au8BSSID[3], strStaParams.au8BSSID[4], - strStaParams.au8BSSID[5]); - PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.u16AssocID); - PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", strStaParams.u8NumRates); - - if (params->ht_capa == NULL) { - strStaParams.bIsHTSupported = false; + vif = netdev_priv(dev); + + if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) { + memcpy(strStaParams.bssid, mac, ETH_ALEN); + strStaParams.aid = params->aid; + strStaParams.rates_len = params->supported_rates_len; + strStaParams.rates = params->supported_rates; + + PRINT_D(HOSTAPD_DBG, "BSSID = %x%x%x%x%x%x\n", + strStaParams.bssid[0], strStaParams.bssid[1], + strStaParams.bssid[2], strStaParams.bssid[3], + strStaParams.bssid[4], strStaParams.bssid[5]); + PRINT_D(HOSTAPD_DBG, "ASSOC ID = %d\n", strStaParams.aid); + PRINT_D(HOSTAPD_DBG, "Number of supported rates = %d\n", + strStaParams.rates_len); + + if (!params->ht_capa) { + strStaParams.ht_supported = false; } else { - strStaParams.bIsHTSupported = true; - strStaParams.u16HTCapInfo = params->ht_capa->cap_info; - strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info; - memcpy(strStaParams.au8SuppMCsSet, ¶ms->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE); - strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info; - strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info; - strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info; - + strStaParams.ht_supported = true; + strStaParams.ht_capa_info = params->ht_capa->cap_info; + strStaParams.ht_ampdu_params = params->ht_capa->ampdu_params_info; + memcpy(strStaParams.ht_supp_mcs_set, + ¶ms->ht_capa->mcs, + WILC_SUPP_MCS_SET_SIZE); + strStaParams.ht_ext_params = params->ht_capa->extended_ht_cap_info; + strStaParams.ht_tx_bf_cap = params->ht_capa->tx_BF_cap_info; + strStaParams.ht_ante_sel = params->ht_capa->antenna_selection_info; } - strStaParams.u16FlagsMask = params->sta_flags_mask; - strStaParams.u16FlagsSet = params->sta_flags_set; - - PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", strStaParams.bIsHTSupported); - PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", strStaParams.u16HTCapInfo); - PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", strStaParams.u8AmpduParams); - PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", strStaParams.u16HTExtParams); - PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", strStaParams.u32TxBeamformingCap); - PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", strStaParams.u8ASELCap); - PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", strStaParams.u16FlagsMask); - PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet); - - s32Error = host_int_edit_station(priv->hWILCWFIDrv, &strStaParams); + strStaParams.flags_mask = params->sta_flags_mask; + strStaParams.flags_set = params->sta_flags_set; + + PRINT_D(HOSTAPD_DBG, "IS HT supported = %d\n", + strStaParams.ht_supported); + PRINT_D(HOSTAPD_DBG, "Capability Info = %d\n", + strStaParams.ht_capa_info); + PRINT_D(HOSTAPD_DBG, "AMPDU Params = %d\n", + strStaParams.ht_ampdu_params); + PRINT_D(HOSTAPD_DBG, "HT Extended params = %d\n", + strStaParams.ht_ext_params); + PRINT_D(HOSTAPD_DBG, "Tx Beamforming Cap = %d\n", + strStaParams.ht_tx_bf_cap); + PRINT_D(HOSTAPD_DBG, "Antenna selection info = %d\n", + strStaParams.ht_ante_sel); + PRINT_D(HOSTAPD_DBG, "Flag Mask = %d\n", + strStaParams.flags_mask); + PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", + strStaParams.flags_set); + + s32Error = wilc_edit_station(vif, &strStaParams); if (s32Error) PRINT_ER("Host edit station fail\n"); } return s32Error; } - -/** - * @brief add_virtual_intf - * @details - * @param[in] - * @return int : Return 0 on Success. - * @author mdaftedar - * @date 01 JUL 2012 - * @version 1.0 - */ static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy, const char *name, unsigned char name_assign_type, @@ -3167,7 +2640,7 @@ static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy, u32 *flags, struct vif_params *params) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc_priv *priv; struct net_device *new_ifc = NULL; @@ -3177,32 +2650,23 @@ static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy, PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", priv->wdev->netdev); - nic = netdev_priv(priv->wdev->netdev); + vif = netdev_priv(priv->wdev->netdev); if (type == NL80211_IFTYPE_MONITOR) { PRINT_D(HOSTAPD_DBG, "Monitor interface mode: Initializing mon interface virtual device driver\n"); - PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", nic->wilc_netdev); - new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev); - if (new_ifc != NULL) { + PRINT_D(HOSTAPD_DBG, "Adding monitor interface[%p]\n", vif->ndev); + new_ifc = WILC_WFI_init_mon_interface(name, vif->ndev); + if (new_ifc) { PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n"); - nic = netdev_priv(priv->wdev->netdev); - nic->monitor_flag = 1; + vif = netdev_priv(priv->wdev->netdev); + vif->monitor_flag = 1; } else PRINT_ER("Error in initializing monitor interface\n "); } return priv->wdev; } -/** - * @brief del_virtual_intf - * @details - * @param[in] - * @return int : Return 0 on Success. - * @author mdaftedar - * @date 01 JUL 2012 - * @version 1.0 - */ static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev) { PRINT_D(HOSTAPD_DBG, "Deleting virtual interface\n"); @@ -3210,7 +2674,6 @@ static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev) } static struct cfg80211_ops wilc_cfg80211_ops = { - .set_monitor_channel = set_channel, .scan = scan, .connect = connect, @@ -3247,27 +2710,12 @@ static struct cfg80211_ops wilc_cfg80211_ops = { }; - - - - -/** - * @brief WILC_WFI_update_stats - * @details Modify parameters for a given BSS. - * @param[in] - * @return int : Return 0 on Success. - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed) { - struct wilc_priv *priv; priv = wiphy_priv(wiphy); switch (changed) { - case WILC_WFI_RX_PKT: { priv->netstats.rx_packets++; @@ -3291,46 +2739,31 @@ int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed) return 0; } -/** - * @brief WILC_WFI_CfgAlloc - * @details Allocation of the wireless device structure and assigning it - * to the cfg80211 operations structure. - * @param[in] NONE - * @return wireless_dev : Returns pointer to wireless_dev structure. - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ -struct wireless_dev *WILC_WFI_CfgAlloc(void) +static struct wireless_dev *WILC_WFI_CfgAlloc(void) { - struct wireless_dev *wdev; PRINT_D(CFG80211_DBG, "Allocating wireless device\n"); - /*Allocating the wireless device structure*/ + wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL); if (!wdev) { PRINT_ER("Cannot allocate wireless device\n"); goto _fail_; } - /*Creating a new wiphy, linking wireless structure with the wiphy structure*/ wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv)); if (!wdev->wiphy) { PRINT_ER("Cannot allocate wiphy\n"); goto _fail_mem_; - } - /* enable 802.11n HT */ WILC_WFI_band_2ghz.ht_cap.ht_supported = 1; WILC_WFI_band_2ghz.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT); WILC_WFI_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff; WILC_WFI_band_2ghz.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K; WILC_WFI_band_2ghz.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; - /*wiphy bands*/ wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &WILC_WFI_band_2ghz; return wdev; @@ -3339,18 +2772,9 @@ _fail_mem_: kfree(wdev); _fail_: return NULL; - } -/** - * @brief wilc_create_wiphy - * @details Registering of the wiphy structure and interface modes - * @param[in] NONE - * @return NONE - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ -struct wireless_dev *wilc_create_wiphy(struct net_device *net) + +struct wireless_dev *wilc_create_wiphy(struct net_device *net, struct device *dev) { struct wilc_priv *priv; struct wireless_dev *wdev; @@ -3359,38 +2783,25 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net) PRINT_D(CFG80211_DBG, "Registering wifi device\n"); wdev = WILC_WFI_CfgAlloc(); - if (wdev == NULL) { + if (!wdev) { PRINT_ER("CfgAlloc Failed\n"); return NULL; } - - /*Return hardware description structure (wiphy)'s priv*/ priv = wdev_priv(wdev); sema_init(&(priv->SemHandleUpdateStats), 1); - - /*Link the wiphy with wireless structure*/ priv->wdev = wdev; - - /*Maximum number of probed ssid to be added by user for the scan request*/ wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID; - /*Maximum number of pmkids to be cashed*/ wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS; PRINT_INFO(CFG80211_DBG, "Max number of PMKIDs = %d\n", wdev->wiphy->max_num_pmkids); wdev->wiphy->max_scan_ie_len = 1000; - - /*signal strength in mBm (100*dBm) */ wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; - - /*Set the availaible cipher suites*/ wdev->wiphy->cipher_suites = cipher_suites; wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); - /*Setting default managment types: for register action frame: */ wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types; wdev->wiphy->max_remain_on_channel_duration = 500; - /*Setting the wiphy interfcae mode and type before registering the wiphy*/ wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT); wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; @@ -3402,36 +2813,21 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net) wdev->wiphy->max_scan_ssids, wdev->wiphy->max_scan_ie_len, wdev->wiphy->signal_type, wdev->wiphy->interface_modes, wdev->iftype); - #ifdef WILC_SDIO - set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev); - #endif + set_wiphy_dev(wdev->wiphy, dev); - /*Register wiphy structure*/ s32Error = wiphy_register(wdev->wiphy); if (s32Error) { PRINT_ER("Cannot register wiphy device\n"); - /*should define what action to be taken in such failure*/ } else { PRINT_D(CFG80211_DBG, "Successful Registering\n"); } priv->dev = net; return wdev; - - } -/** - * @brief WILC_WFI_WiphyFree - * @details Freeing allocation of the wireless device structure - * @param[in] NONE - * @return NONE - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ + int wilc_init_host_int(struct net_device *net) { - int s32Error = 0; struct wilc_priv *priv; @@ -3440,7 +2836,7 @@ int wilc_init_host_int(struct net_device *net) priv = wdev_priv(net->ieee80211_ptr); if (op_ifcs == 0) { setup_timer(&hAgingTimer, remove_network_from_shadow, 0); - setup_timer(&hDuringIpTimer, clear_duringIP, 0); + setup_timer(&wilc_during_ip_timer, clear_duringIP, 0); } op_ifcs++; if (s32Error < 0) { @@ -3453,29 +2849,21 @@ int wilc_init_host_int(struct net_device *net) priv->bInP2PlistenState = false; sema_init(&(priv->hSemScanReq), 1); - s32Error = host_int_init(net, &priv->hWILCWFIDrv); + s32Error = wilc_init(net, &priv->hWILCWFIDrv); if (s32Error) PRINT_ER("Error while initializing hostinterface\n"); return s32Error; } -/** - * @brief WILC_WFI_WiphyFree - * @details Freeing allocation of the wireless device structure - * @param[in] NONE - * @return NONE - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ int wilc_deinit_host_int(struct net_device *net) { int s32Error = 0; - + struct wilc_vif *vif; struct wilc_priv *priv; priv = wdev_priv(net->ieee80211_ptr); + vif = netdev_priv(priv->dev); priv->gbAutoRateAdjusted = false; @@ -3483,13 +2871,12 @@ int wilc_deinit_host_int(struct net_device *net) op_ifcs--; - s32Error = host_int_deinit(priv->hWILCWFIDrv); + s32Error = wilc_deinit(vif); - /* Clear the Shadow scan */ - clear_shadow_scan(priv); + clear_shadow_scan(); if (op_ifcs == 0) { PRINT_D(CORECONFIG_DBG, "destroy during ip\n"); - del_timer_sync(&hDuringIpTimer); + del_timer_sync(&wilc_during_ip_timer); } if (s32Error) @@ -3498,16 +2885,6 @@ int wilc_deinit_host_int(struct net_device *net) return s32Error; } - -/** - * @brief WILC_WFI_WiphyFree - * @details Freeing allocation of the wireless device structure - * @param[in] NONE - * @return NONE - * @author mdaftedar - * @date 01 MAR 2012 - * @version 1.0 - */ void wilc_free_wiphy(struct net_device *net) { PRINT_D(CFG80211_DBG, "Unregistering wiphy\n"); diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h index 39cd8e1b5675..ab53d9d59081 100644 --- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h +++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h @@ -10,88 +10,7 @@ #define NM_WFI_CFGOPERATIONS #include "wilc_wfi_netdevice.h" -/* The following macros describe the bitfield map used by the firmware to determine its 11i mode */ -#define NO_ENCRYPT 0 -#define ENCRYPT_ENABLED BIT(0) -#define WEP BIT(1) -#define WEP_EXTENDED BIT(2) -#define WPA BIT(3) -#define WPA2 BIT(4) -#define AES BIT(5) -#define TKIP BIT(6) - -/*Public action frame index IDs*/ -#define FRAME_TYPE_ID 0 -#define ACTION_CAT_ID 24 -#define ACTION_SUBTYPE_ID 25 -#define P2P_PUB_ACTION_SUBTYPE 30 - -/*Public action frame Attribute IDs*/ -#define ACTION_FRAME 0xd0 -#define GO_INTENT_ATTR_ID 0x04 -#define CHANLIST_ATTR_ID 0x0b -#define OPERCHAN_ATTR_ID 0x11 -#define PUB_ACTION_ATTR_ID 0x04 -#define P2PELEM_ATTR_ID 0xdd - -/*Public action subtype values*/ -#define GO_NEG_REQ 0x00 -#define GO_NEG_RSP 0x01 -#define GO_NEG_CONF 0x02 -#define P2P_INV_REQ 0x03 -#define P2P_INV_RSP 0x04 -#define PUBLIC_ACT_VENDORSPEC 0x09 -#define GAS_INTIAL_REQ 0x0a -#define GAS_INTIAL_RSP 0x0b - -#define INVALID_CHANNEL 0 - -#define nl80211_SCAN_RESULT_EXPIRE (3 * HZ) -#define SCAN_RESULT_EXPIRE (40 * HZ) - -static const u32 cipher_suites[] = { - WLAN_CIPHER_SUITE_WEP40, - WLAN_CIPHER_SUITE_WEP104, - WLAN_CIPHER_SUITE_TKIP, - WLAN_CIPHER_SUITE_CCMP, - WLAN_CIPHER_SUITE_AES_CMAC, -}; - -static const struct ieee80211_txrx_stypes - wilc_wfi_cfg80211_mgmt_types[NUM_NL80211_IFTYPES] = { - [NL80211_IFTYPE_STATION] = { - .tx = 0xffff, - .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | - BIT(IEEE80211_STYPE_PROBE_REQ >> 4) - }, - [NL80211_IFTYPE_AP] = { - .tx = 0xffff, - .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | - BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | - BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | - BIT(IEEE80211_STYPE_DISASSOC >> 4) | - BIT(IEEE80211_STYPE_AUTH >> 4) | - BIT(IEEE80211_STYPE_DEAUTH >> 4) | - BIT(IEEE80211_STYPE_ACTION >> 4) - }, - [NL80211_IFTYPE_P2P_CLIENT] = { - .tx = 0xffff, - .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | - BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | - BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | - BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | - BIT(IEEE80211_STYPE_DISASSOC >> 4) | - BIT(IEEE80211_STYPE_AUTH >> 4) | - BIT(IEEE80211_STYPE_DEAUTH >> 4) - } -}; - -/* Time to stay on the channel */ -#define WILC_WFI_DWELL_PASSIVE 100 -#define WILC_WFI_DWELL_ACTIVE 40 - -struct wireless_dev *WILC_WFI_CfgAlloc(void); -struct wireless_dev *wilc_create_wiphy(struct net_device *net); +struct wireless_dev *wilc_create_wiphy(struct net_device *net, struct device *dev); void wilc_free_wiphy(struct net_device *net); int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed); int wilc_deinit_host_int(struct net_device *net); @@ -102,8 +21,4 @@ struct net_device *WILC_WFI_init_mon_interface(const char *name, struct net_devi void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev, u16 frame_type, bool reg); -#define TCP_ACK_FILTER_LINK_SPEED_THRESH 54 -#define DEFAULT_LINK_SPEED 72 -void Enable_TCP_ACK_Filter(bool value); - #endif diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h index 0bfe7626ad2d..98ac8ed04a06 100644 --- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h +++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h @@ -149,6 +149,13 @@ typedef struct { } struct_frame_reg; struct wilc_vif { + u8 u8IfIdx; + u8 iftype; + int monitor_flag; + int mac_opened; + struct_frame_reg g_struct_frame_reg[num_reg_frame]; + struct net_device_stats netstats; + struct wilc *wilc; u8 src_addr[ETH_ALEN]; u8 bssid[ETH_ALEN]; struct host_if_drv *hif_drv; @@ -156,14 +163,15 @@ struct wilc_vif { }; struct wilc { + const struct wilc_hif_func *hif_func; + int io_type; int mac_status; + int gpio; bool initialized; - #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO) - unsigned short dev_irq_num; - #endif + int dev_irq_num; int close; u8 vif_num; - struct wilc_vif vif[NUM_CONCURRENT_IFC]; + struct wilc_vif *vif[NUM_CONCURRENT_IFC]; u8 open_ifcs; struct semaphore txq_add_to_head_cs; @@ -180,42 +188,54 @@ struct wilc { struct task_struct *txq_thread; + int quit; + int cfg_frame_in_use; + struct wilc_cfg_frame cfg_frame; + u32 cfg_frame_offset; + int cfg_seq_no; + + u8 *rx_buffer; + u32 rx_buffer_offset; + u8 *tx_buffer; + + unsigned long txq_spinlock_flags; + + struct txq_entry_t *txq_head; + struct txq_entry_t *txq_tail; + int txq_entries; + int txq_exit; + + struct rxq_entry_t *rxq_head; + struct rxq_entry_t *rxq_tail; + int rxq_entries; + int rxq_exit; + unsigned char eth_src_address[NUM_CONCURRENT_IFC][6]; const struct firmware *firmware; -#ifdef WILC_SDIO - struct sdio_func *wilc_sdio_func; -#else - struct spi_device *wilc_spidev; -#endif + struct device *dev; }; -typedef struct { - u8 u8IfIdx; - u8 iftype; - int monitor_flag; - int mac_opened; - struct_frame_reg g_struct_frame_reg[num_reg_frame]; - struct net_device *wilc_netdev; - struct net_device_stats netstats; - struct wilc *wilc; -} perInterface_wlan_t; - struct WILC_WFI_mon_priv { struct net_device *real_ndev; }; -extern struct wilc *g_linux_wlan; -extern struct net_device *WILC_WFI_devs[]; -void frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset); -void linux_wlan_mac_indicate(struct wilc *wilc, int flag); -void linux_wlan_rx_complete(void); -void linux_wlan_dbg(u8 *buff); -int linux_wlan_lock_timeout(void *vp, u32 timeout); -void wl_wlan_cleanup(void); -int wilc_netdev_init(struct wilc **wilc); +int wilc1000_wlan_init(struct net_device *dev, struct wilc_vif *vif); + +void wilc_frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset); +void wilc_mac_indicate(struct wilc *wilc, int flag); +void wilc_rx_complete(struct wilc *wilc); +void wilc_dbg(u8 *buff); + +int wilc_lock_timeout(struct wilc *wilc, void *, u32 timeout); +void wilc_netdev_cleanup(struct wilc *wilc); +int wilc_netdev_init(struct wilc **wilc, struct device *, int io_type, int gpio, + const struct wilc_hif_func *ops); void wilc1000_wlan_deinit(struct net_device *dev); void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size); -u16 Set_machw_change_vir_if(struct net_device *dev, bool bValue); +u16 wilc_set_machw_change_vir_if(struct net_device *dev, bool value); +int wilc_wlan_get_firmware(struct net_device *dev); +int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid); + #endif diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c index c02665747705..83af51bb83e8 100644 --- a/drivers/staging/wilc1000/wilc_wlan.c +++ b/drivers/staging/wilc1000/wilc_wlan.c @@ -1,95 +1,15 @@ -/* ////////////////////////////////////////////////////////////////////////// */ -/* */ -/* Copyright (c) Atmel Corporation. All rights reserved. */ -/* */ -/* Module Name: wilc_wlan.c */ -/* */ -/* */ -/* //////////////////////////////////////////////////////////////////////////// */ - #include "wilc_wlan_if.h" +#include "wilc_wlan.h" #include "wilc_wfi_netdevice.h" #include "wilc_wlan_cfg.h" -/******************************************** - * - * Global - * - ********************************************/ -extern wilc_hif_func_t hif_sdio; -extern wilc_hif_func_t hif_spi; -u32 wilc_get_chipid(u8 update); - - - -typedef struct { - int quit; - - /** - * input interface functions - **/ - wilc_wlan_io_func_t io_func; - - /** - * host interface functions - **/ - wilc_hif_func_t hif_func; - - /** - * configuration interface functions - **/ - int cfg_frame_in_use; - wilc_cfg_frame_t cfg_frame; - u32 cfg_frame_offset; - int cfg_seq_no; - - /** - * RX buffer - **/ - #ifdef MEMORY_STATIC - u8 *rx_buffer; - u32 rx_buffer_offset; - #endif - /** - * TX buffer - **/ - u8 *tx_buffer; - u32 tx_buffer_offset; - - /** - * TX queue - **/ - - unsigned long txq_spinlock_flags; - - struct txq_entry_t *txq_head; - struct txq_entry_t *txq_tail; - int txq_entries; - int txq_exit; - - /** - * RX queue - **/ - struct rxq_entry_t *rxq_head; - struct rxq_entry_t *rxq_tail; - int rxq_entries; - int rxq_exit; - - -} wilc_wlan_dev_t; - -static wilc_wlan_dev_t g_wlan; - -static inline void chip_allow_sleep(void); -static inline void chip_wakeup(void); -/******************************************** - * - * Debug - * - ********************************************/ - +#ifdef WILC_OPTIMIZE_SLEEP_INT +static inline void chip_allow_sleep(struct wilc *wilc); +#endif +static inline void chip_wakeup(struct wilc *wilc); static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ; +/* FIXME: replace with dev_debug() */ static void wilc_debug(u32 flag, char *fmt, ...) { char buf[256]; @@ -100,244 +20,214 @@ static void wilc_debug(u32 flag, char *fmt, ...) vsprintf(buf, fmt, args); va_end(args); - linux_wlan_dbg(buf); + wilc_dbg(buf); } } -static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP; +static CHIP_PS_STATE_T chip_ps_state = CHIP_WAKEDUP; -/*acquire_bus() and release_bus() are made static inline functions*/ -/*as a temporary workaround to fix a problem of receiving*/ -/*unknown interrupt from FW*/ -static inline void acquire_bus(BUS_ACQUIRE_T acquire) +static inline void acquire_bus(struct wilc *wilc, BUS_ACQUIRE_T acquire) { - - mutex_lock(&g_linux_wlan->hif_cs); + mutex_lock(&wilc->hif_cs); #ifndef WILC_OPTIMIZE_SLEEP_INT - if (genuChipPSstate != CHIP_WAKEDUP) + if (chip_ps_state != CHIP_WAKEDUP) #endif { if (acquire == ACQUIRE_AND_WAKEUP) - chip_wakeup(); + chip_wakeup(wilc); } - } -static inline void release_bus(BUS_RELEASE_T release) + +static inline void release_bus(struct wilc *wilc, BUS_RELEASE_T release) { #ifdef WILC_OPTIMIZE_SLEEP_INT if (release == RELEASE_ALLOW_SLEEP) - chip_allow_sleep(); + chip_allow_sleep(wilc); #endif - mutex_unlock(&g_linux_wlan->hif_cs); + mutex_unlock(&wilc->hif_cs); } -/******************************************** - * - * Queue - * - ********************************************/ +#ifdef TCP_ACK_FILTER static void wilc_wlan_txq_remove(struct txq_entry_t *tqe) { - wilc_wlan_dev_t *p = &g_wlan; - if (tqe == p->txq_head) { - - p->txq_head = tqe->next; - if (p->txq_head) - p->txq_head->prev = NULL; - - - } else if (tqe == p->txq_tail) { - p->txq_tail = (tqe->prev); - if (p->txq_tail) - p->txq_tail->next = NULL; + if (tqe == wilc->txq_head) { + wilc->txq_head = tqe->next; + if (wilc->txq_head) + wilc->txq_head->prev = NULL; + } else if (tqe == wilc->txq_tail) { + wilc->txq_tail = (tqe->prev); + if (wilc->txq_tail) + wilc->txq_tail->next = NULL; } else { tqe->prev->next = tqe->next; tqe->next->prev = tqe->prev; } - p->txq_entries -= 1; - + wilc->txq_entries -= 1; } +#endif -static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void) +static struct txq_entry_t * +wilc_wlan_txq_remove_from_head(struct net_device *dev) { struct txq_entry_t *tqe; - wilc_wlan_dev_t *p = &g_wlan; unsigned long flags; + struct wilc_vif *vif; + struct wilc *wilc; - spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags); - if (p->txq_head) { - tqe = p->txq_head; - p->txq_head = tqe->next; - if (p->txq_head) - p->txq_head->prev = NULL; - - p->txq_entries -= 1; - - + vif = netdev_priv(dev); + wilc = vif->wilc; + spin_lock_irqsave(&wilc->txq_spinlock, flags); + if (wilc->txq_head) { + tqe = wilc->txq_head; + wilc->txq_head = tqe->next; + if (wilc->txq_head) + wilc->txq_head->prev = NULL; + wilc->txq_entries -= 1; } else { tqe = NULL; } - spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags); + spin_unlock_irqrestore(&wilc->txq_spinlock, flags); return tqe; } -static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe) +static void wilc_wlan_txq_add_to_tail(struct net_device *dev, + struct txq_entry_t *tqe) { - wilc_wlan_dev_t *p = &g_wlan; unsigned long flags; - spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags); + struct wilc_vif *vif; + struct wilc *wilc; + + vif = netdev_priv(dev); + wilc = vif->wilc; - if (p->txq_head == NULL) { + spin_lock_irqsave(&wilc->txq_spinlock, flags); + + if (!wilc->txq_head) { tqe->next = NULL; tqe->prev = NULL; - p->txq_head = tqe; - p->txq_tail = tqe; + wilc->txq_head = tqe; + wilc->txq_tail = tqe; } else { tqe->next = NULL; - tqe->prev = p->txq_tail; - p->txq_tail->next = tqe; - p->txq_tail = tqe; + tqe->prev = wilc->txq_tail; + wilc->txq_tail->next = tqe; + wilc->txq_tail = tqe; } - p->txq_entries += 1; - PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries); + wilc->txq_entries += 1; + PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", wilc->txq_entries); - spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags); + spin_unlock_irqrestore(&wilc->txq_spinlock, flags); - /** - * wake up TX queue - **/ PRINT_D(TX_DBG, "Wake the txq_handling\n"); - up(&g_linux_wlan->txq_event); + up(&wilc->txq_event); } -static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe) +static int wilc_wlan_txq_add_to_head(struct wilc *wilc, struct txq_entry_t *tqe) { - wilc_wlan_dev_t *p = &g_wlan; unsigned long flags; - if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs, + if (wilc_lock_timeout(wilc, &wilc->txq_add_to_head_cs, CFG_PKTS_TIMEOUT)) return -1; - spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags); + spin_lock_irqsave(&wilc->txq_spinlock, flags); - if (p->txq_head == NULL) { + if (!wilc->txq_head) { tqe->next = NULL; tqe->prev = NULL; - p->txq_head = tqe; - p->txq_tail = tqe; + wilc->txq_head = tqe; + wilc->txq_tail = tqe; } else { - tqe->next = p->txq_head; + tqe->next = wilc->txq_head; tqe->prev = NULL; - p->txq_head->prev = tqe; - p->txq_head = tqe; + wilc->txq_head->prev = tqe; + wilc->txq_head = tqe; } - p->txq_entries += 1; - PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries); + wilc->txq_entries += 1; + PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", wilc->txq_entries); - spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags); - up(&g_linux_wlan->txq_add_to_head_cs); - - - /** - * wake up TX queue - **/ - up(&g_linux_wlan->txq_event); + spin_unlock_irqrestore(&wilc->txq_spinlock, flags); + up(&wilc->txq_add_to_head_cs); + up(&wilc->txq_event); PRINT_D(TX_DBG, "Wake up the txq_handler\n"); return 0; - } -u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0; - #ifdef TCP_ACK_FILTER -struct Ack_session_info; -struct Ack_session_info { - u32 Ack_seq_num; - u32 Bigger_Ack_num; +struct ack_session_info; +struct ack_session_info { + u32 seq_num; + u32 bigger_ack_num; u16 src_port; u16 dst_port; u16 status; }; -typedef struct { +struct pending_acks_info { u32 ack_num; - u32 Session_index; + u32 session_index; struct txq_entry_t *txqe; -} Pending_Acks_info_t /*Ack_info_t*/; - - - +}; -struct Ack_session_info *Free_head; -struct Ack_session_info *Alloc_head; #define NOT_TCP_ACK (-1) #define MAX_TCP_SESSION 25 #define MAX_PENDING_ACKS 256 -struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION]; -Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS]; - -u32 PendingAcks_arrBase; -u32 Opened_TCP_session; -u32 Pending_Acks; - +static struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION]; +static struct pending_acks_info pending_acks_info[MAX_PENDING_ACKS]; +static u32 pending_base; +static u32 tcp_session; +static u32 pending_acks; -static inline int Init_TCP_tracking(void) +static inline int init_tcp_tracking(void) { - return 0; - } -static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq) + +static inline int add_tcp_session(u32 src_prt, u32 dst_prt, u32 seq) { - Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq; - Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0; - Acks_keep_track_info[Opened_TCP_session].src_port = src_prt; - Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt; - Opened_TCP_session++; + ack_session_info[tcp_session].seq_num = seq; + ack_session_info[tcp_session].bigger_ack_num = 0; + ack_session_info[tcp_session].src_port = src_prt; + ack_session_info[tcp_session].dst_port = dst_prt; + tcp_session++; - PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq); + PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", tcp_session, seq); return 0; } -static inline int Update_TCP_track_session(u32 index, u32 Ack) +static inline int update_tcp_session(u32 index, u32 ack) { - - if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) - Acks_keep_track_info[index].Bigger_Ack_num = Ack; + if (ack > ack_session_info[index].bigger_ack_num) + ack_session_info[index].bigger_ack_num = ack; return 0; - } -static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe) -{ - Statisitcs_totalAcks++; - if (Pending_Acks < MAX_PENDING_ACKS) { - Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack; - Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe; - Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index; - txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks; - Pending_Acks++; - - } else { +static inline int add_tcp_pending_ack(u32 ack, u32 session_index, + struct txq_entry_t *txqe) +{ + if (pending_acks < MAX_PENDING_ACKS) { + pending_acks_info[pending_base + pending_acks].ack_num = ack; + pending_acks_info[pending_base + pending_acks].txqe = txqe; + pending_acks_info[pending_base + pending_acks].session_index = session_index; + txqe->tcp_pending_ack_idx = pending_base + pending_acks; + pending_acks++; } return 0; } -static inline int remove_TCP_related(void) +static inline int remove_TCP_related(struct wilc *wilc) { - wilc_wlan_dev_t *p = &g_wlan; unsigned long flags; - spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags); + spin_lock_irqsave(&wilc->txq_spinlock, flags); - spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags); + spin_unlock_irqrestore(&wilc->txq_spinlock, flags); return 0; } @@ -348,54 +238,55 @@ static inline int tcp_process(struct net_device *dev, struct txq_entry_t *tqe) u8 *buffer = tqe->buffer; unsigned short h_proto; int i; - wilc_wlan_dev_t *p = &g_wlan; unsigned long flags; - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; - nic = netdev_priv(dev); - wilc = nic->wilc; + vif = netdev_priv(dev); + wilc = vif->wilc; - spin_lock_irqsave(&wilc->txq_spinlock, flags); eth_hdr_ptr = &buffer[0]; h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12])); - if (h_proto == 0x0800) { /* IP */ + if (h_proto == 0x0800) { u8 *ip_hdr_ptr; u8 protocol; ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN]; protocol = ip_hdr_ptr[9]; - if (protocol == 0x06) { u8 *tcp_hdr_ptr; - u32 IHL, Total_Length, Data_offset; + u32 IHL, total_length, data_offset; tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN]; IHL = (ip_hdr_ptr[0] & 0xf) << 2; - Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]); - Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2); - if (Total_Length == (IHL + Data_offset)) { /*we want to recognize the clear Acks(packet only carry Ack infos not with data) so data size must be equal zero*/ - u32 seq_no, Ack_no; - - seq_no = (((u32)tcp_hdr_ptr[4]) << 24) + (((u32)tcp_hdr_ptr[5]) << 16) + (((u32)tcp_hdr_ptr[6]) << 8) + ((u32)tcp_hdr_ptr[7]); - - Ack_no = (((u32)tcp_hdr_ptr[8]) << 24) + (((u32)tcp_hdr_ptr[9]) << 16) + (((u32)tcp_hdr_ptr[10]) << 8) + ((u32)tcp_hdr_ptr[11]); - - - for (i = 0; i < Opened_TCP_session; i++) { - if (Acks_keep_track_info[i].Ack_seq_num == seq_no) { - Update_TCP_track_session(i, Ack_no); + total_length = ((u32)ip_hdr_ptr[2] << 8) + + (u32)ip_hdr_ptr[3]; + data_offset = ((u32)tcp_hdr_ptr[12] & 0xf0) >> 2; + if (total_length == (IHL + data_offset)) { + u32 seq_no, ack_no; + + seq_no = ((u32)tcp_hdr_ptr[4] << 24) + + ((u32)tcp_hdr_ptr[5] << 16) + + ((u32)tcp_hdr_ptr[6] << 8) + + (u32)tcp_hdr_ptr[7]; + + ack_no = ((u32)tcp_hdr_ptr[8] << 24) + + ((u32)tcp_hdr_ptr[9] << 16) + + ((u32)tcp_hdr_ptr[10] << 8) + + (u32)tcp_hdr_ptr[11]; + + for (i = 0; i < tcp_session; i++) { + if (ack_session_info[i].seq_num == seq_no) { + update_tcp_session(i, ack_no); break; } } - if (i == Opened_TCP_session) - add_TCP_track_session(0, 0, seq_no); - - add_TCP_Pending_Ack(Ack_no, i, tqe); - + if (i == tcp_session) + add_tcp_session(0, 0, seq_no); + add_tcp_pending_ack(ack_no, i, tqe); } } else { @@ -408,83 +299,81 @@ static inline int tcp_process(struct net_device *dev, struct txq_entry_t *tqe) return ret; } - static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev) { - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; u32 i = 0; - u32 Dropped = 0; - wilc_wlan_dev_t *p = &g_wlan; + u32 dropped = 0; - nic = netdev_priv(dev); - wilc = nic->wilc; + vif = netdev_priv(dev); + wilc = vif->wilc; - spin_lock_irqsave(&wilc->txq_spinlock, p->txq_spinlock_flags); - for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) { - if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) { + spin_lock_irqsave(&wilc->txq_spinlock, wilc->txq_spinlock_flags); + for (i = pending_base; i < (pending_base + pending_acks); i++) { + if (pending_acks_info[i].ack_num < ack_session_info[pending_acks_info[i].session_index].bigger_ack_num) { struct txq_entry_t *tqe; - PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num); - tqe = Pending_Acks_info[i].txqe; + PRINT_D(TCP_ENH, "DROP ACK: %u\n", + pending_acks_info[i].ack_num); + tqe = pending_acks_info[i].txqe; if (tqe) { wilc_wlan_txq_remove(tqe); - Statisitcs_DroppedAcks++; - tqe->status = 1; /* mark the packet send */ + tqe->status = 1; if (tqe->tx_complete_func) - tqe->tx_complete_func(tqe->priv, tqe->status); + tqe->tx_complete_func(tqe->priv, + tqe->status); kfree(tqe); - Dropped++; + dropped++; } } } - Pending_Acks = 0; - Opened_TCP_session = 0; + pending_acks = 0; + tcp_session = 0; - if (PendingAcks_arrBase == 0) - PendingAcks_arrBase = MAX_TCP_SESSION; + if (pending_base == 0) + pending_base = MAX_TCP_SESSION; else - PendingAcks_arrBase = 0; - + pending_base = 0; - spin_unlock_irqrestore(&wilc->txq_spinlock, p->txq_spinlock_flags); + spin_unlock_irqrestore(&wilc->txq_spinlock, wilc->txq_spinlock_flags); - while (Dropped > 0) { - /*consume the semaphore count of the removed packet*/ - linux_wlan_lock_timeout(&wilc->txq_event, 1); - Dropped--; + while (dropped > 0) { + wilc_lock_timeout(wilc, &wilc->txq_event, 1); + dropped--; } return 1; } #endif -bool EnableTCPAckFilter = false; +static bool enabled = false; -void Enable_TCP_ACK_Filter(bool value) +void wilc_enable_tcp_ack_filter(bool value) { - EnableTCPAckFilter = value; + enabled = value; } -bool is_TCP_ACK_Filter_Enabled(void) +#ifdef TCP_ACK_FILTER +static bool is_tcp_ack_filter_enabled(void) { - return EnableTCPAckFilter; + return enabled; } +#endif -static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size) +static int wilc_wlan_txq_add_cfg_pkt(struct wilc *wilc, u8 *buffer, u32 buffer_size) { - wilc_wlan_dev_t *p = &g_wlan; struct txq_entry_t *tqe; PRINT_D(TX_DBG, "Adding config packet ...\n"); - if (p->quit) { + if (wilc->quit) { PRINT_D(TX_DBG, "Return due to clear function\n"); - up(&g_linux_wlan->cfg_event); + up(&wilc->cfg_event); return 0; } - tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC); - if (tqe == NULL) { + tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC); + if (!tqe) { PRINT_ER("Failed to allocate memory\n"); return 0; } @@ -495,14 +384,11 @@ static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size) tqe->tx_complete_func = NULL; tqe->priv = NULL; #ifdef TCP_ACK_FILTER - tqe->tcp_PendingAck_index = NOT_TCP_ACK; + tqe->tcp_pending_ack_idx = NOT_TCP_ACK; #endif - /** - * Configuration packet always at the front - **/ PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n"); - if (wilc_wlan_txq_add_to_head(tqe)) + if (wilc_wlan_txq_add_to_head(wilc, tqe)) return 0; return 1; } @@ -510,15 +396,18 @@ static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size) int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func) { - wilc_wlan_dev_t *p = &g_wlan; struct txq_entry_t *tqe; + struct wilc_vif *vif = netdev_priv(dev); + struct wilc *wilc; + + wilc = vif->wilc; - if (p->quit) + if (wilc->quit) return 0; - tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC); + tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC); - if (tqe == NULL) + if (!tqe) return 0; tqe->type = WILC_NET_PKT; tqe->buffer = buffer; @@ -528,27 +417,29 @@ int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer, PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n"); #ifdef TCP_ACK_FILTER - tqe->tcp_PendingAck_index = NOT_TCP_ACK; - if (is_TCP_ACK_Filter_Enabled()) + tqe->tcp_pending_ack_idx = NOT_TCP_ACK; + if (is_tcp_ack_filter_enabled()) tcp_process(dev, tqe); #endif - wilc_wlan_txq_add_to_tail(tqe); - /*return number of itemes in the queue*/ - return p->txq_entries; + wilc_wlan_txq_add_to_tail(dev, tqe); + return wilc->txq_entries; } -int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func) +int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer, + u32 buffer_size, wilc_tx_complete_func_t func) { - - wilc_wlan_dev_t *p = &g_wlan; struct txq_entry_t *tqe; + struct wilc_vif *vif = netdev_priv(dev); + struct wilc *wilc; + + wilc = vif->wilc; - if (p->quit) + if (wilc->quit) return 0; - tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL); + tqe = kmalloc(sizeof(*tqe), GFP_KERNEL); - if (tqe == NULL) + if (!tqe) return 0; tqe->type = WILC_MGMT_PKT; tqe->buffer = buffer; @@ -556,25 +447,23 @@ int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_ tqe->tx_complete_func = func; tqe->priv = priv; #ifdef TCP_ACK_FILTER - tqe->tcp_PendingAck_index = NOT_TCP_ACK; + tqe->tcp_pending_ack_idx = NOT_TCP_ACK; #endif PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n"); - wilc_wlan_txq_add_to_tail(tqe); + wilc_wlan_txq_add_to_tail(dev, tqe); return 1; } -static struct txq_entry_t *wilc_wlan_txq_get_first(void) +static struct txq_entry_t *wilc_wlan_txq_get_first(struct wilc *wilc) { - wilc_wlan_dev_t *p = &g_wlan; struct txq_entry_t *tqe; unsigned long flags; - spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags); - - tqe = p->txq_head; + spin_lock_irqsave(&wilc->txq_spinlock, flags); - spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags); + tqe = wilc->txq_head; + spin_unlock_irqrestore(&wilc->txq_spinlock, flags); return tqe; } @@ -583,52 +472,50 @@ static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc, struct txq_entry_t *tqe) { unsigned long flags; + spin_lock_irqsave(&wilc->txq_spinlock, flags); tqe = tqe->next; spin_unlock_irqrestore(&wilc->txq_spinlock, flags); - return tqe; } static int wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe) { - wilc_wlan_dev_t *p = &g_wlan; - if (p->quit) + if (wilc->quit) return 0; mutex_lock(&wilc->rxq_cs); - if (p->rxq_head == NULL) { + if (!wilc->rxq_head) { PRINT_D(RX_DBG, "Add to Queue head\n"); rqe->next = NULL; - p->rxq_head = rqe; - p->rxq_tail = rqe; + wilc->rxq_head = rqe; + wilc->rxq_tail = rqe; } else { PRINT_D(RX_DBG, "Add to Queue tail\n"); - p->rxq_tail->next = rqe; + wilc->rxq_tail->next = rqe; rqe->next = NULL; - p->rxq_tail = rqe; + wilc->rxq_tail = rqe; } - p->rxq_entries += 1; - PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries); + wilc->rxq_entries += 1; + PRINT_D(RX_DBG, "Number of queue entries: %d\n", wilc->rxq_entries); mutex_unlock(&wilc->rxq_cs); - return p->rxq_entries; + return wilc->rxq_entries; } static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc) { - wilc_wlan_dev_t *p = &g_wlan; PRINT_D(RX_DBG, "Getting rxQ element\n"); - if (p->rxq_head) { + if (wilc->rxq_head) { struct rxq_entry_t *rqe; mutex_lock(&wilc->rxq_cs); - rqe = p->rxq_head; - p->rxq_head = p->rxq_head->next; - p->rxq_entries -= 1; + rqe = wilc->rxq_head; + wilc->rxq_head = wilc->rxq_head->next; + wilc->rxq_entries -= 1; PRINT_D(RX_DBG, "RXQ entries decreased\n"); mutex_unlock(&wilc->rxq_cs); return rqe; @@ -637,197 +524,151 @@ static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc) return NULL; } - -/******************************************** - * - * Power Save handle functions - * - ********************************************/ - - - #ifdef WILC_OPTIMIZE_SLEEP_INT -static inline void chip_allow_sleep(void) +static inline void chip_allow_sleep(struct wilc *wilc) { u32 reg = 0; - /* Clear bit 1 */ - g_wlan.hif_func.hif_read_reg(0xf0, ®); + wilc->hif_func->hif_read_reg(wilc, 0xf0, ®); - g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0)); + wilc->hif_func->hif_write_reg(wilc, 0xf0, reg & ~BIT(0)); } -static inline void chip_wakeup(void) +static inline void chip_wakeup(struct wilc *wilc) { u32 reg, clk_status_reg, trials = 0; u32 sleep_time; - if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) { + if ((wilc->io_type & 0x1) == HIF_SPI) { do { - g_wlan.hif_func.hif_read_reg(1, ®); - /* Set bit 1 */ - g_wlan.hif_func.hif_write_reg(1, reg | BIT(1)); - - /* Clear bit 1*/ - g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1)); + wilc->hif_func->hif_read_reg(wilc, 1, ®); + wilc->hif_func->hif_write_reg(wilc, 1, reg | BIT(1)); + wilc->hif_func->hif_write_reg(wilc, 1, reg & ~BIT(1)); do { - /* Wait for the chip to stabilize*/ usleep_range(2 * 1000, 2 * 1000); - /* Make sure chip is awake. This is an extra step that can be removed */ - /* later to avoid the bus access overhead */ - if ((wilc_get_chipid(true) == 0)) + if ((wilc_get_chipid(wilc, true) == 0)) wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n"); - } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0)); + } while ((wilc_get_chipid(wilc, true) == 0) && ((++trials % 3) == 0)); - } while (wilc_get_chipid(true) == 0); - } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) { - g_wlan.hif_func.hif_read_reg(0xf0, ®); + } while (wilc_get_chipid(wilc, true) == 0); + } else if ((wilc->io_type & 0x1) == HIF_SDIO) { + wilc->hif_func->hif_read_reg(wilc, 0xf0, ®); do { - /* Set bit 1 */ - g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0)); + wilc->hif_func->hif_write_reg(wilc, 0xf0, + reg | BIT(0)); + wilc->hif_func->hif_read_reg(wilc, 0xf1, + &clk_status_reg); - /* Check the clock status */ - g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg); - - /* in case of clocks off, wait 2ms, and check it again. */ - /* if still off, wait for another 2ms, for a total wait of 6ms. */ - /* If still off, redo the wake up sequence */ while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) { - /* Wait for the chip to stabilize*/ usleep_range(2 * 1000, 2 * 1000); - /* Make sure chip is awake. This is an extra step that can be removed */ - /* later to avoid the bus access overhead */ - g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg); + wilc->hif_func->hif_read_reg(wilc, 0xf1, + &clk_status_reg); if ((clk_status_reg & 0x1) == 0) wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n"); - } - /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */ if ((clk_status_reg & 0x1) == 0) { - /* Reset bit 0 */ - g_wlan.hif_func.hif_write_reg(0xf0, reg & - (~BIT(0))); + wilc->hif_func->hif_write_reg(wilc, 0xf0, + reg & (~BIT(0))); } } while ((clk_status_reg & 0x1) == 0); } - - if (genuChipPSstate == CHIP_SLEEPING_MANUAL) { - g_wlan.hif_func.hif_read_reg(0x1C0C, ®); + if (chip_ps_state == CHIP_SLEEPING_MANUAL) { + wilc->hif_func->hif_read_reg(wilc, 0x1C0C, ®); reg &= ~BIT(0); - g_wlan.hif_func.hif_write_reg(0x1C0C, reg); + wilc->hif_func->hif_write_reg(wilc, 0x1C0C, reg); - if (wilc_get_chipid(false) >= 0x1002b0) { - /* Enable PALDO back right after wakeup */ + if (wilc_get_chipid(wilc, false) >= 0x1002b0) { u32 val32; - g_wlan.hif_func.hif_read_reg(0x1e1c, &val32); + wilc->hif_func->hif_read_reg(wilc, 0x1e1c, &val32); val32 |= BIT(6); - g_wlan.hif_func.hif_write_reg(0x1e1c, val32); + wilc->hif_func->hif_write_reg(wilc, 0x1e1c, val32); - g_wlan.hif_func.hif_read_reg(0x1e9c, &val32); + wilc->hif_func->hif_read_reg(wilc, 0x1e9c, &val32); val32 |= BIT(6); - g_wlan.hif_func.hif_write_reg(0x1e9c, val32); + wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32); } } - genuChipPSstate = CHIP_WAKEDUP; + chip_ps_state = CHIP_WAKEDUP; } #else -static inline void chip_wakeup(void) +static inline void chip_wakeup(struct wilc *wilc) { u32 reg, trials = 0; do { - if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) { - g_wlan.hif_func.hif_read_reg(1, ®); - /* Make sure bit 1 is 0 before we start. */ - g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1)); - /* Set bit 1 */ - g_wlan.hif_func.hif_write_reg(1, reg | BIT(1)); - /* Clear bit 1*/ - g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1)); - } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) { - /* Make sure bit 0 is 0 before we start. */ - g_wlan.hif_func.hif_read_reg(0xf0, ®); - g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0)); - /* Set bit 1 */ - g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0)); - /* Clear bit 1 */ - g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0)); + if ((wilc->io_type & 0x1) == HIF_SPI) { + wilc->hif_func->hif_read_reg(wilc, 1, ®); + wilc->hif_func->hif_write_reg(wilc, 1, reg & ~BIT(1)); + wilc->hif_func->hif_write_reg(wilc, 1, reg | BIT(1)); + wilc->hif_func->hif_write_reg(wilc, 1, reg & ~BIT(1)); + } else if ((wilc->io_type & 0x1) == HIF_SDIO) { + wilc->hif_func->hif_read_reg(wilc, 0xf0, ®); + wilc->hif_func->hif_write_reg(wilc, 0xf0, + reg & ~BIT(0)); + wilc->hif_func->hif_write_reg(wilc, 0xf0, + reg | BIT(0)); + wilc->hif_func->hif_write_reg(wilc, 0xf0, + reg & ~BIT(0)); } do { - /* Wait for the chip to stabilize*/ mdelay(3); - /* Make sure chip is awake. This is an extra step that can be removed */ - /* later to avoid the bus access overhead */ - if ((wilc_get_chipid(true) == 0)) + if ((wilc_get_chipid(wilc, true) == 0)) wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n"); - } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0)); + } while ((wilc_get_chipid(wilc, true) == 0) && ((++trials % 3) == 0)); - } while (wilc_get_chipid(true) == 0); + } while (wilc_get_chipid(wilc, true) == 0); - if (genuChipPSstate == CHIP_SLEEPING_MANUAL) { - g_wlan.hif_func.hif_read_reg(0x1C0C, ®); + if (chip_ps_state == CHIP_SLEEPING_MANUAL) { + wilc->hif_func->hif_read_reg(wilc, 0x1C0C, ®); reg &= ~BIT(0); - g_wlan.hif_func.hif_write_reg(0x1C0C, reg); + wilc->hif_func->hif_write_reg(wilc, 0x1C0C, reg); - if (wilc_get_chipid(false) >= 0x1002b0) { - /* Enable PALDO back right after wakeup */ + if (wilc_get_chipid(wilc, false) >= 0x1002b0) { u32 val32; - g_wlan.hif_func.hif_read_reg(0x1e1c, &val32); + wilc->hif_func->hif_read_reg(wilc, 0x1e1c, &val32); val32 |= BIT(6); - g_wlan.hif_func.hif_write_reg(0x1e1c, val32); + wilc->hif_func->hif_write_reg(wilc, 0x1e1c, val32); - g_wlan.hif_func.hif_read_reg(0x1e9c, &val32); + wilc->hif_func->hif_read_reg(wilc, 0x1e9c, &val32); val32 |= BIT(6); - g_wlan.hif_func.hif_write_reg(0x1e9c, val32); + wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32); } } - genuChipPSstate = CHIP_WAKEDUP; + chip_ps_state = CHIP_WAKEDUP; } #endif -void chip_sleep_manually(u32 u32SleepTime) +void wilc_chip_sleep_manually(struct wilc *wilc) { - if (genuChipPSstate != CHIP_WAKEDUP) { - /* chip is already sleeping. Do nothing */ + if (chip_ps_state != CHIP_WAKEDUP) return; - } - acquire_bus(ACQUIRE_ONLY); + acquire_bus(wilc, ACQUIRE_ONLY); #ifdef WILC_OPTIMIZE_SLEEP_INT - chip_allow_sleep(); + chip_allow_sleep(wilc); #endif + wilc->hif_func->hif_write_reg(wilc, 0x10a8, 1); - /* Trigger the manual sleep interrupt */ - g_wlan.hif_func.hif_write_reg(0x10a8, 1); - - genuChipPSstate = CHIP_SLEEPING_MANUAL; - release_bus(RELEASE_ONLY); - + chip_ps_state = CHIP_SLEEPING_MANUAL; + release_bus(wilc, RELEASE_ONLY); } - -/******************************************** - * - * Tx, Rx queue handle functions - * - ********************************************/ -int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount) +int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count) { - wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; int i, entries = 0; u32 sum; u32 reg; - u8 *txb = p->tx_buffer; + u8 *txb; u32 offset = 0; int vmm_sz = 0; struct txq_entry_t *tqe; @@ -835,32 +676,29 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount) int counter; int timeout; u32 vmm_table[WILC_VMM_TBL_SIZE]; - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; - nic = netdev_priv(dev); - wilc = nic->wilc; + vif = netdev_priv(dev); + wilc = vif->wilc; - p->txq_exit = 0; + txb = wilc->tx_buffer; + wilc->txq_exit = 0; do { - if (p->quit) + if (wilc->quit) break; - linux_wlan_lock_timeout(&wilc->txq_add_to_head_cs, + wilc_lock_timeout(wilc, &wilc->txq_add_to_head_cs, CFG_PKTS_TIMEOUT); #ifdef TCP_ACK_FILTER wilc_wlan_txq_filter_dup_tcp_ack(dev); #endif - /** - * build the vmm list - **/ PRINT_D(TX_DBG, "Getting the head of the TxQ\n"); - tqe = wilc_wlan_txq_get_first(); + tqe = wilc_wlan_txq_get_first(wilc); i = 0; sum = 0; do { - if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) { - + if (tqe && (i < (WILC_VMM_TBL_SIZE - 1))) { if (tqe->type == WILC_CFG_PKT) vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET; @@ -872,23 +710,22 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount) vmm_sz += tqe->buffer_size; PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz); - if (vmm_sz & 0x3) { /* has to be word aligned */ + if (vmm_sz & 0x3) vmm_sz = (vmm_sz + 4) & ~0x3; - } + if ((sum + vmm_sz) > LINUX_TX_SIZE) break; PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz); - vmm_table[i] = vmm_sz / 4; /* table take the word size */ - PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]); + vmm_table[i] = vmm_sz / 4; + PRINT_D(TX_DBG, "VMMTable entry size = %d\n", + vmm_table[i]); if (tqe->type == WILC_CFG_PKT) { vmm_table[i] |= BIT(10); PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]); } -#ifdef BIG_ENDIAN - vmm_table[i] = BYTE_SWAP(vmm_table[i]); -#endif + vmm_table[i] = cpu_to_le32(vmm_table[i]); i++; sum += vmm_sz; @@ -899,27 +736,24 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount) } } while (1); - if (i == 0) { /* nothing in the queue */ + if (i == 0) { PRINT_D(TX_DBG, "Nothing in TX-Q\n"); break; } else { PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i); - vmm_table[i] = 0x0; /* mark the last element to 0 */ + vmm_table[i] = 0x0; } - acquire_bus(ACQUIRE_AND_WAKEUP); + acquire_bus(wilc, ACQUIRE_AND_WAKEUP); counter = 0; do { - - ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®); + ret = wilc->hif_func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, + ®); if (!ret) { wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n"); break; } if ((reg & 0x1) == 0) { - /** - * write to vmm table - **/ PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4)); break; } else { @@ -927,69 +761,52 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount) if (counter > 200) { counter = 0; PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n"); - ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, 0); break; } - /** - * wait for vmm table is ready - **/ PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n"); - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); usleep_range(3000, 3000); - acquire_bus(ACQUIRE_AND_WAKEUP); + acquire_bus(wilc, ACQUIRE_AND_WAKEUP); } - } while (!p->quit); + } while (!wilc->quit); if (!ret) goto _end_; timeout = 200; do { - - /** - * write to vmm table - **/ - ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4)); + ret = wilc->hif_func->hif_block_tx(wilc, WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4)); if (!ret) { wilc_debug(N_ERR, "ERR block TX of VMM table.\n"); break; } - - /** - * interrupt firmware - **/ - ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, + 0x2); if (!ret) { wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n"); break; } - /** - * wait for confirm... - **/ - do { - ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, ®); + ret = wilc->hif_func->hif_read_reg(wilc, WILC_HOST_VMM_CTL, ®); if (!ret) { wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n"); break; } if ((reg >> 2) & 0x1) { - /** - * Get the entries - **/ entries = ((reg >> 3) & 0x3f); break; } else { - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); usleep_range(3000, 3000); - acquire_bus(ACQUIRE_AND_WAKEUP); + acquire_bus(wilc, ACQUIRE_AND_WAKEUP); PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg); } } while (--timeout); if (timeout <= 0) { - ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, 0x0); break; } @@ -999,14 +816,13 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount) if (entries == 0) { PRINT_WRN(GENERIC_DBG, "[wilc txq]: no more buffer in the chip (reg: %08x), retry later [[ %d, %x ]]\n", reg, i, vmm_table[i - 1]); - /* undo the transaction. */ - ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®); + ret = wilc->hif_func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, ®); if (!ret) { wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n"); break; } reg &= ~BIT(0); - ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, reg); if (!ret) { wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n"); break; @@ -1025,58 +841,50 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount) goto _end_; } - /* since copying data into txb takes some time, then - * allow the bus lock to be released let the RX task go. */ - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); - /** - * Copy data to the TX buffer - **/ offset = 0; i = 0; do { - tqe = wilc_wlan_txq_remove_from_head(); - if (tqe != NULL && (vmm_table[i] != 0)) { + tqe = wilc_wlan_txq_remove_from_head(dev); + if (tqe && (vmm_table[i] != 0)) { u32 header, buffer_offset; -#ifdef BIG_ENDIAN - vmm_table[i] = BYTE_SWAP(vmm_table[i]); -#endif - vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */ + vmm_table[i] = cpu_to_le32(vmm_table[i]); + vmm_sz = (vmm_table[i] & 0x3ff); vmm_sz *= 4; - header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz; + header = (tqe->type << 31) | + (tqe->buffer_size << 15) | + vmm_sz; if (tqe->type == WILC_MGMT_PKT) header |= BIT(30); else header &= ~BIT(30); -#ifdef BIG_ENDIAN - header = BYTE_SWAP(header); -#endif + header = cpu_to_le32(header); memcpy(&txb[offset], &header, 4); if (tqe->type == WILC_CFG_PKT) { buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET; - } - else if (tqe->type == WILC_NET_PKT) { - char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid; + } else if (tqe->type == WILC_NET_PKT) { + char *bssid = ((struct tx_complete_data *)(tqe->priv))->pBssid; buffer_offset = ETH_ETHERNET_HDR_OFFSET; - /* copy the bssid at the sart of the buffer */ - memcpy(&txb[offset + 4], pBSSID, 6); - } - else { + memcpy(&txb[offset + 4], bssid, 6); + } else { buffer_offset = HOST_HDR_OFFSET; } - memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size); + memcpy(&txb[offset + buffer_offset], + tqe->buffer, tqe->buffer_size); offset += vmm_sz; i++; - tqe->status = 1; /* mark the packet send */ + tqe->status = 1; if (tqe->tx_complete_func) - tqe->tx_complete_func(tqe->priv, tqe->status); + tqe->tx_complete_func(tqe->priv, + tqe->status); #ifdef TCP_ACK_FILTER - if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) - Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL; + if (tqe->tcp_pending_ack_idx != NOT_TCP_ACK) + pending_acks_info[tqe->tcp_pending_ack_idx].txqe = NULL; #endif kfree(tqe); } else { @@ -1084,21 +892,15 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount) } } while (--entries); - /** - * lock the bus - **/ - acquire_bus(ACQUIRE_AND_WAKEUP); + acquire_bus(wilc, ACQUIRE_AND_WAKEUP); - ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM); + ret = wilc->hif_func->hif_clear_int_ext(wilc, ENABLE_TX_VMM); if (!ret) { wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n"); goto _end_; } - /** - * transfer - **/ - ret = p->hif_func.hif_block_tx_ext(0, txb, offset); + ret = wilc->hif_func->hif_block_tx_ext(wilc, 0, txb, offset); if (!ret) { wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n"); goto _end_; @@ -1106,49 +908,43 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount) _end_: - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); if (ret != 1) break; } while (0); up(&wilc->txq_add_to_head_cs); - p->txq_exit = 1; + wilc->txq_exit = 1; PRINT_D(TX_DBG, "THREAD: Exiting txq\n"); - /* return tx[]q count */ - *pu32TxqCount = p->txq_entries; + *txq_count = wilc->txq_entries; return ret; } static void wilc_wlan_handle_rxq(struct wilc *wilc) { - wilc_wlan_dev_t *p = &g_wlan; int offset = 0, size, has_packet = 0; u8 *buffer; struct rxq_entry_t *rqe; - p->rxq_exit = 0; - - - + wilc->rxq_exit = 0; do { - if (p->quit) { + if (wilc->quit) { PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n"); up(&wilc->cfg_event); break; } rqe = wilc_wlan_rxq_remove(wilc); - if (rqe == NULL) { + if (!rqe) { PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n"); break; } buffer = rqe->buffer; size = rqe->buffer_size; - PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer); + PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", + size, buffer); offset = 0; - - do { u32 header; u32 pkt_len, pkt_offset, tp_len; @@ -1156,12 +952,9 @@ static void wilc_wlan_handle_rxq(struct wilc *wilc) PRINT_D(RX_DBG, "In the 2nd do-while\n"); memcpy(&header, &buffer[offset], 4); -#ifdef BIG_ENDIAN - header = BYTE_SWAP(header); -#endif - PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset); - - + header = cpu_to_le32(header); + PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", + header, offset); is_cfg_packet = (header >> 31) & 0x1; pkt_offset = (header >> 22) & 0x1ff; @@ -1177,45 +970,34 @@ static void wilc_wlan_handle_rxq(struct wilc *wilc) #define IS_MANAGMEMENT_CALLBACK 0x080 #define IS_MGMT_STATUS_SUCCES 0x040 - if (pkt_offset & IS_MANAGMEMENT) { - /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */ - pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES); + pkt_offset &= ~(IS_MANAGMEMENT | + IS_MANAGMEMENT_CALLBACK | + IS_MGMT_STATUS_SUCCES); WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len); - } - else - { - + } else { if (!is_cfg_packet) { if (pkt_len > 0) { - frmw_to_linux(wilc, + wilc_frmw_to_linux(wilc, &buffer[offset], pkt_len, pkt_offset); has_packet = 1; } } else { - wilc_cfg_rsp_t rsp; - - + struct wilc_cfg_rsp rsp; - wilc_wlan_cfg_indicate_rx(&buffer[pkt_offset + offset], pkt_len, &rsp); + wilc_wlan_cfg_indicate_rx(wilc, &buffer[pkt_offset + offset], pkt_len, &rsp); if (rsp.type == WILC_CFG_RSP) { - /** - * wake up the waiting task... - **/ - PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no); - if (p->cfg_seq_no == rsp.seq_no) + PRINT_D(RX_DBG, "wilc->cfg_seq_no = %d - rsp.seq_no = %d\n", wilc->cfg_seq_no, rsp.seq_no); + if (wilc->cfg_seq_no == rsp.seq_no) up(&wilc->cfg_event); } else if (rsp.type == WILC_CFG_RSP_STATUS) { - /** - * Call back to indicate status... - **/ - linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS); + wilc_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS); } else if (rsp.type == WILC_CFG_RSP_SCAN) { - linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN); + wilc_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN); } } } @@ -1223,224 +1005,163 @@ static void wilc_wlan_handle_rxq(struct wilc *wilc) if (offset >= size) break; } while (1); - - -#ifndef MEMORY_STATIC - kfree(buffer); -#endif kfree(rqe); if (has_packet) - linux_wlan_rx_complete(); + wilc_rx_complete(wilc); } while (1); - p->rxq_exit = 1; + wilc->rxq_exit = 1; PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n"); } -/******************************************** - * - * Fast DMA Isr - * - ********************************************/ -static void wilc_unknown_isr_ext(void) +static void wilc_unknown_isr_ext(struct wilc *wilc) { - g_wlan.hif_func.hif_clear_int_ext(0); + wilc->hif_func->hif_clear_int_ext(wilc, 0); } -static void wilc_pllupdate_isr_ext(u32 int_stats) -{ +static void wilc_pllupdate_isr_ext(struct wilc *wilc, u32 int_stats) +{ int trials = 10; - g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR); + wilc->hif_func->hif_clear_int_ext(wilc, PLL_INT_CLR); - /* Waiting for PLL */ - mdelay(WILC_PLL_TO); + if (wilc->io_type == HIF_SDIO) + mdelay(WILC_PLL_TO_SDIO); + else + mdelay(WILC_PLL_TO_SPI); - /* poll till read a valid data */ - while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) { + while (!(ISWILC1000(wilc_get_chipid(wilc, true)) && --trials)) { PRINT_D(TX_DBG, "PLL update retrying\n"); mdelay(1); } } -static void wilc_sleeptimer_isr_ext(u32 int_stats1) +static void wilc_sleeptimer_isr_ext(struct wilc *wilc, u32 int_stats1) { - g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR); + wilc->hif_func->hif_clear_int_ext(wilc, SLEEP_INT_CLR); #ifndef WILC_OPTIMIZE_SLEEP_INT - genuChipPSstate = CHIP_SLEEPING_AUTO; + chip_ps_state = CHIP_SLEEPING_AUTO; #endif } static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status) { - wilc_wlan_dev_t *p = &g_wlan; -#ifdef MEMORY_STATIC - u32 offset = p->rx_buffer_offset; -#endif + u32 offset = wilc->rx_buffer_offset; u8 *buffer = NULL; u32 size; u32 retries = 0; int ret = 0; struct rxq_entry_t *rqe; - - /** - * Get the rx size - **/ - size = ((int_status & 0x7fff) << 2); while (!size && retries < 10) { u32 time = 0; - /*looping more secure*/ - /*zero size make a crashe because the dma will not happen and that will block the firmware*/ + wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++); - p->hif_func.hif_read_size(&size); + wilc->hif_func->hif_read_size(wilc, &size); size = ((size & 0x7fff) << 2); retries++; - } if (size > 0) { -#ifdef MEMORY_STATIC if (LINUX_RX_SIZE - offset < size) offset = 0; - if (p->rx_buffer) - buffer = &p->rx_buffer[offset]; - else { + if (wilc->rx_buffer) { + buffer = &wilc->rx_buffer[offset]; + } else { wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size); goto _end_; } -#else - buffer = kmalloc(size, GFP_KERNEL); - if (buffer == NULL) { - wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size); - usleep_range(100 * 1000, 100 * 1000); - goto _end_; - } -#endif - - /** - * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt - **/ - p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM); - - - /** - * start transfer - **/ - ret = p->hif_func.hif_block_rx_ext(0, buffer, size); + wilc->hif_func->hif_clear_int_ext(wilc, + DATA_INT_CLR | ENABLE_RX_VMM); + ret = wilc->hif_func->hif_block_rx_ext(wilc, 0, buffer, size); if (!ret) { wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n"); goto _end_; } _end_: - - if (ret) { -#ifdef MEMORY_STATIC offset += size; - p->rx_buffer_offset = offset; -#endif - /** - * add to rx queue - **/ - rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL); - if (rqe != NULL) { + wilc->rx_buffer_offset = offset; + rqe = kmalloc(sizeof(*rqe), GFP_KERNEL); + if (rqe) { rqe->buffer = buffer; rqe->buffer_size = size; PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer); wilc_wlan_rxq_add(wilc, rqe); } - } else { -#ifndef MEMORY_STATIC - kfree(buffer); -#endif } } wilc_wlan_handle_rxq(wilc); } -void wilc_handle_isr(void *wilc) +void wilc_handle_isr(struct wilc *wilc) { u32 int_status; - acquire_bus(ACQUIRE_AND_WAKEUP); - g_wlan.hif_func.hif_read_int(&int_status); + acquire_bus(wilc, ACQUIRE_AND_WAKEUP); + wilc->hif_func->hif_read_int(wilc, &int_status); if (int_status & PLL_INT_EXT) - wilc_pllupdate_isr_ext(int_status); + wilc_pllupdate_isr_ext(wilc, int_status); if (int_status & DATA_INT_EXT) { wilc_wlan_handle_isr_ext(wilc, int_status); #ifndef WILC_OPTIMIZE_SLEEP_INT - /* Chip is up and talking*/ - genuChipPSstate = CHIP_WAKEDUP; + chip_ps_state = CHIP_WAKEDUP; #endif } if (int_status & SLEEP_INT_EXT) - wilc_sleeptimer_isr_ext(int_status); + wilc_sleeptimer_isr_ext(wilc, int_status); if (!(int_status & (ALL_INT_EXT))) { -#ifdef WILC_SDIO - PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status); -#endif - wilc_unknown_isr_ext(); + wilc_unknown_isr_ext(wilc); } - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); } +EXPORT_SYMBOL_GPL(wilc_handle_isr); -/******************************************** - * - * Firmware download - * - ********************************************/ -int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size) +int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer, u32 buffer_size) { - wilc_wlan_dev_t *p = &g_wlan; u32 offset; u32 addr, size, size2, blksz; u8 *dma_buffer; int ret = 0; blksz = BIT(12); - /* Allocate a DMA coherent buffer. */ dma_buffer = kmalloc(blksz, GFP_KERNEL); - if (dma_buffer == NULL) { - /*EIO 5*/ - ret = -5; + if (!dma_buffer) { + ret = -EIO; PRINT_ER("Can't allocate buffer for firmware download IO error\n "); goto _fail_1; } PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size); - /** - * load the firmware - **/ + offset = 0; do { memcpy(&addr, &buffer[offset], 4); memcpy(&size, &buffer[offset + 4], 4); -#ifdef BIG_ENDIAN - addr = BYTE_SWAP(addr); - size = BYTE_SWAP(size); -#endif - acquire_bus(ACQUIRE_ONLY); + addr = cpu_to_le32(addr); + size = cpu_to_le32(size); + acquire_bus(wilc, ACQUIRE_ONLY); offset += 8; while (((int)size) && (offset < buffer_size)) { if (size <= blksz) size2 = size; else size2 = blksz; - /* Copy firmware into a DMA coherent buffer */ + memcpy(dma_buffer, &buffer[offset], size2); - ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2); + ret = wilc->hif_func->hif_block_tx(wilc, addr, dma_buffer, + size2); if (!ret) break; @@ -1448,11 +1169,10 @@ int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size) offset += size2; size -= size2; } - release_bus(RELEASE_ONLY); + release_bus(wilc, RELEASE_ONLY); if (!ret) { - /*EIO 5*/ - ret = -5; + ret = -EIO; PRINT_ER("Can't download firmware IO error\n "); goto _fail_; } @@ -1468,40 +1188,29 @@ _fail_1: return (ret < 0) ? ret : 0; } -/******************************************** - * - * Common - * - ********************************************/ -int wilc_wlan_start(void) +int wilc_wlan_start(struct wilc *wilc) { - wilc_wlan_dev_t *p = &g_wlan; u32 reg = 0; int ret; u32 chipid; - /** - * Set the host interface - **/ - if (p->io_func.io_type == HIF_SDIO) { + if (wilc->io_type == HIF_SDIO) { reg = 0; - reg |= BIT(3); /* bug 4456 and 4557 */ - } else if (p->io_func.io_type == HIF_SPI) { + reg |= BIT(3); + } else if (wilc->io_type == HIF_SPI) { reg = 1; } - acquire_bus(ACQUIRE_ONLY); - ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg); + acquire_bus(wilc, ACQUIRE_ONLY); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_VMM_CORE_CFG, reg); if (!ret) { wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n"); - release_bus(RELEASE_ONLY); - /* EIO 5*/ - ret = -5; + release_bus(wilc, RELEASE_ONLY); + ret = -EIO; return ret; } reg = 0; -#ifdef WILC_SDIO_IRQ_GPIO - reg |= WILC_HAVE_SDIO_IRQ_GPIO; -#endif + if (wilc->io_type == HIF_SDIO && wilc->dev_irq_num) + reg |= WILC_HAVE_SDIO_IRQ_GPIO; #ifdef WILC_DISABLE_PMU #else @@ -1519,123 +1228,103 @@ int wilc_wlan_start(void) #endif reg |= WILC_HAVE_LEGACY_RF_SETTINGS; - - -/*Set oscillator frequency*/ #ifdef XTAL_24 reg |= WILC_HAVE_XTAL_24; #endif - -/*Enable/Disable GPIO configuration for FW logs*/ #ifdef DISABLE_WILC_UART reg |= WILC_HAVE_DISABLE_WILC_UART; #endif - ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_1, reg); if (!ret) { wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n"); - release_bus(RELEASE_ONLY); - /* EIO 5*/ - ret = -5; + release_bus(wilc, RELEASE_ONLY); + ret = -EIO; return ret; } - /** - * Bus related - **/ - p->hif_func.hif_sync_ext(NUM_INT_EXT); + wilc->hif_func->hif_sync_ext(wilc, NUM_INT_EXT); - ret = p->hif_func.hif_read_reg(0x1000, &chipid); + ret = wilc->hif_func->hif_read_reg(wilc, 0x1000, &chipid); if (!ret) { wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n"); - release_bus(RELEASE_ONLY); - /* EIO 5*/ - ret = -5; + release_bus(wilc, RELEASE_ONLY); + ret = -EIO; return ret; } - /** - * Go... - **/ - - - p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); + wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®); if ((reg & BIT(10)) == BIT(10)) { reg &= ~BIT(10); - p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); - p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); + wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg); + wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®); } reg |= BIT(10); - ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); - p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); - release_bus(RELEASE_ONLY); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg); + wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®); + release_bus(wilc, RELEASE_ONLY); return (ret < 0) ? ret : 0; } -void wilc_wlan_global_reset(void) +void wilc_wlan_global_reset(struct wilc *wilc) { - - wilc_wlan_dev_t *p = &g_wlan; - - acquire_bus(ACQUIRE_AND_WAKEUP); - p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0); - release_bus(RELEASE_ONLY); + acquire_bus(wilc, ACQUIRE_AND_WAKEUP); + wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, 0x0); + release_bus(wilc, RELEASE_ONLY); } -int wilc_wlan_stop(void) +int wilc_wlan_stop(struct wilc *wilc) { - wilc_wlan_dev_t *p = &g_wlan; u32 reg = 0; int ret; u8 timeout = 10; - /** - * TODO: stop the firmware, need a re-download - **/ - acquire_bus(ACQUIRE_AND_WAKEUP); + acquire_bus(wilc, ACQUIRE_AND_WAKEUP); - ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); + ret = wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®); if (!ret) { PRINT_ER("Error while reading reg\n"); - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); return ret; } reg &= ~BIT(10); - - - ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg); if (!ret) { PRINT_ER("Error while writing reg\n"); - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); return ret; } - - do { - ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); + ret = wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®); if (!ret) { PRINT_ER("Error while reading reg\n"); - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); return ret; } - PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout); - /*Workaround to ensure that the chip is actually reset*/ + PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", + reg, timeout); + if ((reg & BIT(10))) { - PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout); + PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", + timeout); reg &= ~BIT(10); - ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, + reg); timeout--; } else { - PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout); - ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); + PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", + timeout); + ret = wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, + ®); if (!ret) { PRINT_ER("Error while reading reg\n"); - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); return ret; } - PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout); + PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", + reg, timeout); break; } @@ -1643,33 +1332,32 @@ int wilc_wlan_stop(void) reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) | BIT(29) | BIT(30) | BIT(31)); - p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); + wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg); reg = (u32)~BIT(10); - ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg); - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); return ret; } void wilc_wlan_cleanup(struct net_device *dev) { - wilc_wlan_dev_t *p = &g_wlan; struct txq_entry_t *tqe; struct rxq_entry_t *rqe; u32 reg = 0; int ret; - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; - nic = netdev_priv(dev); - wilc = nic->wilc; + vif = netdev_priv(dev); + wilc = vif->wilc; - p->quit = 1; + wilc->quit = 1; do { - tqe = wilc_wlan_txq_remove_from_head(); - if (tqe == NULL) + tqe = wilc_wlan_txq_remove_from_head(dev); + if (!tqe) break; if (tqe->tx_complete_func) tqe->tx_complete_func(tqe->priv, 0); @@ -1678,157 +1366,133 @@ void wilc_wlan_cleanup(struct net_device *dev) do { rqe = wilc_wlan_rxq_remove(wilc); - if (rqe == NULL) + if (!rqe) break; -#ifndef MEMORY_STATIC - kfree(rqe->buffer); -#endif kfree(rqe); } while (1); - /** - * clean up buffer - **/ - - #ifdef MEMORY_STATIC - kfree(p->rx_buffer); - p->rx_buffer = NULL; - #endif - kfree(p->tx_buffer); + kfree(wilc->rx_buffer); + wilc->rx_buffer = NULL; + kfree(wilc->tx_buffer); + wilc->tx_buffer = NULL; - acquire_bus(ACQUIRE_AND_WAKEUP); + acquire_bus(wilc, ACQUIRE_AND_WAKEUP); - - ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, ®); + ret = wilc->hif_func->hif_read_reg(wilc, WILC_GP_REG_0, ®); if (!ret) { PRINT_ER("Error while reading reg\n"); - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); } PRINT_ER("Writing ABORT reg\n"); - ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT)); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_0, + (reg | ABORT_INT)); if (!ret) { PRINT_ER("Error while writing reg\n"); - release_bus(RELEASE_ALLOW_SLEEP); + release_bus(wilc, RELEASE_ALLOW_SLEEP); } - release_bus(RELEASE_ALLOW_SLEEP); - /** - * io clean up - **/ - p->hif_func.hif_deinit(NULL); - + release_bus(wilc, RELEASE_ALLOW_SLEEP); + wilc->hif_func->hif_deinit(NULL); } -static int wilc_wlan_cfg_commit(int type, u32 drvHandler) +static int wilc_wlan_cfg_commit(struct wilc *wilc, int type, u32 drv_handler) { - wilc_wlan_dev_t *p = &g_wlan; - wilc_cfg_frame_t *cfg = &p->cfg_frame; - int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE; - int seq_no = p->cfg_seq_no % 256; - int driver_handler = (u32)drvHandler; - + struct wilc_cfg_frame *cfg = &wilc->cfg_frame; + int total_len = wilc->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE; + int seq_no = wilc->cfg_seq_no % 256; + int driver_handler = (u32)drv_handler; - /** - * Set up header - **/ - if (type == WILC_CFG_SET) { /* Set */ + if (type == WILC_CFG_SET) cfg->wid_header[0] = 'W'; - } else { /* Query */ + else cfg->wid_header[0] = 'Q'; - } - cfg->wid_header[1] = seq_no; /* sequence number */ + cfg->wid_header[1] = seq_no; cfg->wid_header[2] = (u8)total_len; cfg->wid_header[3] = (u8)(total_len >> 8); cfg->wid_header[4] = (u8)driver_handler; cfg->wid_header[5] = (u8)(driver_handler >> 8); cfg->wid_header[6] = (u8)(driver_handler >> 16); cfg->wid_header[7] = (u8)(driver_handler >> 24); - p->cfg_seq_no = seq_no; - - /** - * Add to TX queue - **/ + wilc->cfg_seq_no = seq_no; - if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len)) + if (!wilc_wlan_txq_add_cfg_pkt(wilc, &cfg->wid_header[0], total_len)) return -1; return 0; } -int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size, - int commit, u32 drvHandler) +int wilc_wlan_cfg_set(struct wilc *wilc, int start, u32 wid, u8 *buffer, + u32 buffer_size, int commit, u32 drv_handler) { - wilc_wlan_dev_t *p = &g_wlan; u32 offset; int ret_size; - - if (p->cfg_frame_in_use) + if (wilc->cfg_frame_in_use) return 0; if (start) - p->cfg_frame_offset = 0; + wilc->cfg_frame_offset = 0; - offset = p->cfg_frame_offset; - ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid, - buffer, buffer_size); + offset = wilc->cfg_frame_offset; + ret_size = wilc_wlan_cfg_set_wid(wilc->cfg_frame.frame, offset, + (u16)wid, buffer, buffer_size); offset += ret_size; - p->cfg_frame_offset = offset; + wilc->cfg_frame_offset = offset; if (commit) { - PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no); + PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", + wilc->cfg_seq_no); PRINT_D(RX_DBG, "Processing cfg_set()\n"); - p->cfg_frame_in_use = 1; + wilc->cfg_frame_in_use = 1; - if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler)) + if (wilc_wlan_cfg_commit(wilc, WILC_CFG_SET, drv_handler)) ret_size = 0; - if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event, + if (wilc_lock_timeout(wilc, &wilc->cfg_event, CFG_PKTS_TIMEOUT)) { PRINT_D(TX_DBG, "Set Timed Out\n"); ret_size = 0; } - p->cfg_frame_in_use = 0; - p->cfg_frame_offset = 0; - p->cfg_seq_no += 1; - + wilc->cfg_frame_in_use = 0; + wilc->cfg_frame_offset = 0; + wilc->cfg_seq_no += 1; } return ret_size; } -int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler) + +int wilc_wlan_cfg_get(struct wilc *wilc, int start, u32 wid, int commit, + u32 drv_handler) { - wilc_wlan_dev_t *p = &g_wlan; u32 offset; int ret_size; - - if (p->cfg_frame_in_use) + if (wilc->cfg_frame_in_use) return 0; if (start) - p->cfg_frame_offset = 0; + wilc->cfg_frame_offset = 0; - offset = p->cfg_frame_offset; - ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid); + offset = wilc->cfg_frame_offset; + ret_size = wilc_wlan_cfg_get_wid(wilc->cfg_frame.frame, offset, + (u16)wid); offset += ret_size; - p->cfg_frame_offset = offset; + wilc->cfg_frame_offset = offset; if (commit) { - p->cfg_frame_in_use = 1; + wilc->cfg_frame_in_use = 1; - if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler)) + if (wilc_wlan_cfg_commit(wilc, WILC_CFG_QUERY, drv_handler)) ret_size = 0; - - if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event, + if (wilc_lock_timeout(wilc, &wilc->cfg_event, CFG_PKTS_TIMEOUT)) { PRINT_D(TX_DBG, "Get Timed Out\n"); ret_size = 0; } PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n"); - p->cfg_frame_in_use = 0; - p->cfg_frame_offset = 0; - p->cfg_seq_no += 1; + wilc->cfg_frame_in_use = 0; + wilc->cfg_frame_offset = 0; + wilc->cfg_seq_no += 1; } return ret_size; @@ -1843,92 +1507,69 @@ int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size) return ret; } -void wilc_bus_set_max_speed(void) -{ - - /* Increase bus speed to max possible. */ - g_wlan.hif_func.hif_set_max_bus_speed(); -} - -void wilc_bus_set_default_speed(void) -{ - - /* Restore bus speed to default. */ - g_wlan.hif_func.hif_set_default_bus_speed(); -} -u32 init_chip(void) +static u32 init_chip(struct net_device *dev) { u32 chipid; u32 reg, ret = 0; + struct wilc_vif *vif; + struct wilc *wilc; - acquire_bus(ACQUIRE_ONLY); - - chipid = wilc_get_chipid(true); + vif = netdev_priv(dev); + wilc = vif->wilc; + acquire_bus(wilc, ACQUIRE_ONLY); + chipid = wilc_get_chipid(wilc, true); if ((chipid & 0xfff) != 0xa0) { - /** - * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform] - * or SD_DAT3 [SPI platform] to ?1? - **/ - /* Set cortus reset register to register control. */ - ret = g_wlan.hif_func.hif_read_reg(0x1118, ®); + ret = wilc->hif_func->hif_read_reg(wilc, 0x1118, ®); if (!ret) { wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n"); return ret; } reg |= BIT(0); - ret = g_wlan.hif_func.hif_write_reg(0x1118, reg); + ret = wilc->hif_func->hif_write_reg(wilc, 0x1118, reg); if (!ret) { wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n"); return ret; } - /** - * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000 - * (Cortus map) or C0000 (AHB map). - **/ - ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71); + ret = wilc->hif_func->hif_write_reg(wilc, 0xc0000, 0x71); if (!ret) { wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n"); return ret; } } - release_bus(RELEASE_ONLY); + release_bus(wilc, RELEASE_ONLY); return ret; - } -u32 wilc_get_chipid(u8 update) +u32 wilc_get_chipid(struct wilc *wilc, u8 update) { static u32 chipid; - /* SDIO can't read into global variables */ - /* Use this variable as a temp, then copy to the global */ u32 tempchipid = 0; u32 rfrevid; if (chipid == 0 || update != 0) { - g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid); - g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid); + wilc->hif_func->hif_read_reg(wilc, 0x1000, &tempchipid); + wilc->hif_func->hif_read_reg(wilc, 0x13f4, &rfrevid); if (!ISWILC1000(tempchipid)) { chipid = 0; goto _fail_; } if (tempchipid == 0x1002a0) { - if (rfrevid == 0x1) { /* 1002A0 */ - } else { /* if (rfrevid == 0x2) */ /* 1002A1 */ + if (rfrevid == 0x1) { + } else { tempchipid = 0x1002a1; } } else if (tempchipid == 0x1002b0) { - if (rfrevid == 3) { /* 1002B0 */ - } else if (rfrevid == 4) { /* 1002B1 */ + if (rfrevid == 3) { + } else if (rfrevid == 4) { tempchipid = 0x1002b1; - } else { /* if(rfrevid == 5) */ /* 1002B2 */ + } else { tempchipid = 0x1002b2; } - } else { } chipid = tempchipid; @@ -1937,129 +1578,88 @@ _fail_: return chipid; } -int wilc_wlan_init(wilc_wlan_inp_t *inp) +int wilc_wlan_init(struct net_device *dev) { - int ret = 0; + struct wilc_vif *vif = netdev_priv(dev); + struct wilc *wilc; + + wilc = vif->wilc; PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n"); - memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t)); - - /** - * store the input - **/ - memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t)); - /*** - * host interface init - **/ - if ((inp->io_func.io_type & 0x1) == HIF_SDIO) { - if (!hif_sdio.hif_init(inp, wilc_debug)) { - /* EIO 5 */ - ret = -5; - goto _fail_; - } - memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t)); - } else { - if ((inp->io_func.io_type & 0x1) == HIF_SPI) { - /** - * TODO: - **/ - if (!hif_spi.hif_init(inp, wilc_debug)) { - /* EIO 5 */ - ret = -5; - goto _fail_; - } - memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t)); - } else { - /* EIO 5 */ - ret = -5; - goto _fail_; - } + if (!wilc->hif_func->hif_init(wilc)) { + ret = -EIO; + goto _fail_; } - /*** - * mac interface init - **/ if (!wilc_wlan_cfg_init(wilc_debug)) { - /* ENOBUFS 105 */ - ret = -105; + ret = -ENOBUFS; goto _fail_; } - /** - * alloc tx, rx buffer - **/ - if (g_wlan.tx_buffer == NULL) - g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL); - PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer); + if (!wilc->tx_buffer) + wilc->tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL); + PRINT_D(TX_DBG, "wilc->tx_buffer = %p\n", wilc->tx_buffer); - if (g_wlan.tx_buffer == NULL) { - /* ENOBUFS 105 */ - ret = -105; + if (!wilc->tx_buffer) { + ret = -ENOBUFS; PRINT_ER("Can't allocate Tx Buffer"); goto _fail_; } -/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/ -#if defined (MEMORY_STATIC) - if (g_wlan.rx_buffer == NULL) - g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL); - PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer); - if (g_wlan.rx_buffer == NULL) { - /* ENOBUFS 105 */ - ret = -105; + if (!wilc->rx_buffer) + wilc->rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL); + PRINT_D(TX_DBG, "wilc->rx_buffer =%p\n", wilc->rx_buffer); + if (!wilc->rx_buffer) { + ret = -ENOBUFS; PRINT_ER("Can't allocate Rx Buffer"); goto _fail_; } -#endif - if (!init_chip()) { - /* EIO 5 */ - ret = -5; + if (!init_chip(dev)) { + ret = -EIO; goto _fail_; } #ifdef TCP_ACK_FILTER - Init_TCP_tracking(); + init_tcp_tracking(); #endif return 1; _fail_: - #ifdef MEMORY_STATIC - kfree(g_wlan.rx_buffer); - g_wlan.rx_buffer = NULL; - #endif - kfree(g_wlan.tx_buffer); - g_wlan.tx_buffer = NULL; + kfree(wilc->rx_buffer); + wilc->rx_buffer = NULL; + kfree(wilc->tx_buffer); + wilc->tx_buffer = NULL; return ret; - } -u16 Set_machw_change_vir_if(struct net_device *dev, bool bValue) +u16 wilc_set_machw_change_vir_if(struct net_device *dev, bool value) { u16 ret; u32 reg; - perInterface_wlan_t *nic; + struct wilc_vif *vif; struct wilc *wilc; - nic = netdev_priv(dev); - wilc = nic->wilc; + vif = netdev_priv(dev); + wilc = vif->wilc; - /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/ mutex_lock(&wilc->hif_cs); - ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, ®); + ret = wilc->hif_func->hif_read_reg(wilc, WILC_CHANGING_VIR_IF, + ®); if (!ret) PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n"); - if (bValue) + if (value) reg |= BIT(31); else reg &= ~BIT(31); - ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg); + ret = wilc->hif_func->hif_write_reg(wilc, WILC_CHANGING_VIR_IF, + reg); if (!ret) PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n"); diff --git a/drivers/staging/wilc1000/wilc_wlan.h b/drivers/staging/wilc1000/wilc_wlan.h index 57e1d5174050..2edd7445f4a3 100644 --- a/drivers/staging/wilc1000/wilc_wlan.h +++ b/drivers/staging/wilc1000/wilc_wlan.h @@ -1,155 +1,131 @@ #ifndef WILC_WLAN_H #define WILC_WLAN_H +#include <linux/types.h> - -#define ISWILC1000(id) (((id & 0xfffff000) == 0x100000) ? 1 : 0) - +#define ISWILC1000(id) ((id & 0xfffff000) == 0x100000 ? 1 : 0) /******************************************** * * Mac eth header length * ********************************************/ -#define DRIVER_HANDLER_SIZE 4 -#define MAX_MAC_HDR_LEN 26 /* QOS_MAC_HDR_LEN */ -#define SUB_MSDU_HEADER_LENGTH 14 -#define SNAP_HDR_LEN 8 -#define ETHERNET_HDR_LEN 14 -#define WORD_ALIGNMENT_PAD 0 - -#define ETH_ETHERNET_HDR_OFFSET (MAX_MAC_HDR_LEN + SUB_MSDU_HEADER_LENGTH + \ - SNAP_HDR_LEN - ETHERNET_HDR_LEN + WORD_ALIGNMENT_PAD) - -#define HOST_HDR_OFFSET 4 -#define ETHERNET_HDR_LEN 14 -#define IP_HDR_LEN 20 -#define IP_HDR_OFFSET ETHERNET_HDR_LEN -#define UDP_HDR_OFFSET (IP_HDR_LEN + IP_HDR_OFFSET) -#define UDP_HDR_LEN 8 -#define UDP_DATA_OFFSET (UDP_HDR_OFFSET + UDP_HDR_LEN) -#define ETH_CONFIG_PKT_HDR_LEN UDP_DATA_OFFSET - -#define ETH_CONFIG_PKT_HDR_OFFSET (ETH_ETHERNET_HDR_OFFSET + \ - ETH_CONFIG_PKT_HDR_LEN) - -/******************************************** - * - * Endian Conversion - * - ********************************************/ - -#define BYTE_SWAP(val) ((((val) & 0x000000FF) << 24) + \ - (((val) & 0x0000FF00) << 8) + \ - (((val) & 0x00FF0000) >> 8) + \ - (((val) & 0xFF000000) >> 24)) +#define DRIVER_HANDLER_SIZE 4 +#define MAX_MAC_HDR_LEN 26 /* QOS_MAC_HDR_LEN */ +#define SUB_MSDU_HEADER_LENGTH 14 +#define SNAP_HDR_LEN 8 +#define ETHERNET_HDR_LEN 14 +#define WORD_ALIGNMENT_PAD 0 + +#define ETH_ETHERNET_HDR_OFFSET (MAX_MAC_HDR_LEN + \ + SUB_MSDU_HEADER_LENGTH + \ + SNAP_HDR_LEN - \ + ETHERNET_HDR_LEN + \ + WORD_ALIGNMENT_PAD) + +#define HOST_HDR_OFFSET 4 +#define ETHERNET_HDR_LEN 14 +#define IP_HDR_LEN 20 +#define IP_HDR_OFFSET ETHERNET_HDR_LEN +#define UDP_HDR_OFFSET (IP_HDR_LEN + IP_HDR_OFFSET) +#define UDP_HDR_LEN 8 +#define UDP_DATA_OFFSET (UDP_HDR_OFFSET + UDP_HDR_LEN) +#define ETH_CONFIG_PKT_HDR_LEN UDP_DATA_OFFSET + +#define ETH_CONFIG_PKT_HDR_OFFSET (ETH_ETHERNET_HDR_OFFSET + \ + ETH_CONFIG_PKT_HDR_LEN) /******************************************** * * Register Defines * ********************************************/ -#define WILC_PERIPH_REG_BASE 0x1000 -#define WILC_CHANGING_VIR_IF (0x108c) -#define WILC_CHIPID (WILC_PERIPH_REG_BASE) -#define WILC_GLB_RESET_0 (WILC_PERIPH_REG_BASE + 0x400) -#define WILC_PIN_MUX_0 (WILC_PERIPH_REG_BASE + 0x408) -#define WILC_HOST_TX_CTRL (WILC_PERIPH_REG_BASE + 0x6c) -#define WILC_HOST_RX_CTRL_0 (WILC_PERIPH_REG_BASE + 0x70) -#define WILC_HOST_RX_CTRL_1 (WILC_PERIPH_REG_BASE + 0x74) -#define WILC_HOST_VMM_CTL (WILC_PERIPH_REG_BASE + 0x78) -#define WILC_HOST_RX_CTRL (WILC_PERIPH_REG_BASE + 0x80) -#define WILC_HOST_RX_EXTRA_SIZE (WILC_PERIPH_REG_BASE + 0x84) -#define WILC_HOST_TX_CTRL_1 (WILC_PERIPH_REG_BASE + 0x88) -#define WILC_MISC (WILC_PERIPH_REG_BASE + 0x428) -#define WILC_INTR_REG_BASE (WILC_PERIPH_REG_BASE + 0xa00) -#define WILC_INTR_ENABLE (WILC_INTR_REG_BASE) -#define WILC_INTR2_ENABLE (WILC_INTR_REG_BASE + 4) - -#define WILC_INTR_POLARITY (WILC_INTR_REG_BASE + 0x10) -#define WILC_INTR_TYPE (WILC_INTR_REG_BASE + 0x20) -#define WILC_INTR_CLEAR (WILC_INTR_REG_BASE + 0x30) -#define WILC_INTR_STATUS (WILC_INTR_REG_BASE + 0x40) - -#define WILC_VMM_TBL_SIZE 64 -#define WILC_VMM_TX_TBL_BASE (0x150400) -#define WILC_VMM_RX_TBL_BASE (0x150500) - -#define WILC_VMM_BASE 0x150000 -#define WILC_VMM_CORE_CTL (WILC_VMM_BASE) -#define WILC_VMM_TBL_CTL (WILC_VMM_BASE + 0x4) -#define WILC_VMM_TBL_ENTRY (WILC_VMM_BASE + 0x8) -#define WILC_VMM_TBL0_SIZE (WILC_VMM_BASE + 0xc) -#define WILC_VMM_TO_HOST_SIZE (WILC_VMM_BASE + 0x10) -#define WILC_VMM_CORE_CFG (WILC_VMM_BASE + 0x14) -#define WILC_VMM_TBL_ACTIVE (WILC_VMM_BASE + 040) -#define WILC_VMM_TBL_STATUS (WILC_VMM_BASE + 0x44) - -#define WILC_SPI_REG_BASE 0xe800 -#define WILC_SPI_CTL (WILC_SPI_REG_BASE) -#define WILC_SPI_MASTER_DMA_ADDR (WILC_SPI_REG_BASE + 0x4) -#define WILC_SPI_MASTER_DMA_COUNT (WILC_SPI_REG_BASE + 0x8) -#define WILC_SPI_SLAVE_DMA_ADDR (WILC_SPI_REG_BASE + 0xc) -#define WILC_SPI_SLAVE_DMA_COUNT (WILC_SPI_REG_BASE + 0x10) -#define WILC_SPI_TX_MODE (WILC_SPI_REG_BASE + 0x20) -#define WILC_SPI_PROTOCOL_CONFIG (WILC_SPI_REG_BASE + 0x24) -#define WILC_SPI_INTR_CTL (WILC_SPI_REG_BASE + 0x2c) - -#define WILC_SPI_PROTOCOL_OFFSET (WILC_SPI_PROTOCOL_CONFIG - WILC_SPI_REG_BASE) - -#define WILC_AHB_DATA_MEM_BASE 0x30000 -#define WILC_AHB_SHARE_MEM_BASE 0xd0000 - -#define WILC_VMM_TBL_RX_SHADOW_BASE WILC_AHB_SHARE_MEM_BASE -#define WILC_VMM_TBL_RX_SHADOW_SIZE (256) - -#define WILC_GP_REG_0 0x149c -#define WILC_GP_REG_1 0x14a0 - -#define rHAVE_SDIO_IRQ_GPIO_BIT (0) -#define rHAVE_USE_PMU_BIT (1) -#define rHAVE_SLEEP_CLK_SRC_RTC_BIT (2) -#define rHAVE_SLEEP_CLK_SRC_XO_BIT (3) -#define rHAVE_EXT_PA_INV_TX_RX_BIT (4) -#define rHAVE_LEGACY_RF_SETTINGS_BIT (5) -#define rHAVE_XTAL_24_BIT (6) -#define rHAVE_DISABLE_WILC_UART_BIT (7) - - -#define WILC_HAVE_SDIO_IRQ_GPIO (1 << rHAVE_SDIO_IRQ_GPIO_BIT) -#define WILC_HAVE_USE_PMU (1 << rHAVE_USE_PMU_BIT) -#define WILC_HAVE_SLEEP_CLK_SRC_RTC (1 << rHAVE_SLEEP_CLK_SRC_RTC_BIT) -#define WILC_HAVE_SLEEP_CLK_SRC_XO (1 << rHAVE_SLEEP_CLK_SRC_XO_BIT) -#define WILC_HAVE_EXT_PA_INV_TX_RX (1 << rHAVE_EXT_PA_INV_TX_RX_BIT) -#define WILC_HAVE_LEGACY_RF_SETTINGS (1 << rHAVE_LEGACY_RF_SETTINGS_BIT) -#define WILC_HAVE_XTAL_24 (1 << rHAVE_XTAL_24_BIT) -#define WILC_HAVE_DISABLE_WILC_UART (1 << rHAVE_DISABLE_WILC_UART_BIT) - +#define WILC_PERIPH_REG_BASE 0x1000 +#define WILC_CHANGING_VIR_IF 0x108c +#define WILC_CHIPID WILC_PERIPH_REG_BASE +#define WILC_GLB_RESET_0 (WILC_PERIPH_REG_BASE + 0x400) +#define WILC_PIN_MUX_0 (WILC_PERIPH_REG_BASE + 0x408) +#define WILC_HOST_TX_CTRL (WILC_PERIPH_REG_BASE + 0x6c) +#define WILC_HOST_RX_CTRL_0 (WILC_PERIPH_REG_BASE + 0x70) +#define WILC_HOST_RX_CTRL_1 (WILC_PERIPH_REG_BASE + 0x74) +#define WILC_HOST_VMM_CTL (WILC_PERIPH_REG_BASE + 0x78) +#define WILC_HOST_RX_CTRL (WILC_PERIPH_REG_BASE + 0x80) +#define WILC_HOST_RX_EXTRA_SIZE (WILC_PERIPH_REG_BASE + 0x84) +#define WILC_HOST_TX_CTRL_1 (WILC_PERIPH_REG_BASE + 0x88) +#define WILC_MISC (WILC_PERIPH_REG_BASE + 0x428) +#define WILC_INTR_REG_BASE (WILC_PERIPH_REG_BASE + 0xa00) +#define WILC_INTR_ENABLE WILC_INTR_REG_BASE +#define WILC_INTR2_ENABLE (WILC_INTR_REG_BASE + 4) + +#define WILC_INTR_POLARITY (WILC_INTR_REG_BASE + 0x10) +#define WILC_INTR_TYPE (WILC_INTR_REG_BASE + 0x20) +#define WILC_INTR_CLEAR (WILC_INTR_REG_BASE + 0x30) +#define WILC_INTR_STATUS (WILC_INTR_REG_BASE + 0x40) + +#define WILC_VMM_TBL_SIZE 64 +#define WILC_VMM_TX_TBL_BASE 0x150400 +#define WILC_VMM_RX_TBL_BASE 0x150500 + +#define WILC_VMM_BASE 0x150000 +#define WILC_VMM_CORE_CTL WILC_VMM_BASE +#define WILC_VMM_TBL_CTL (WILC_VMM_BASE + 0x4) +#define WILC_VMM_TBL_ENTRY (WILC_VMM_BASE + 0x8) +#define WILC_VMM_TBL0_SIZE (WILC_VMM_BASE + 0xc) +#define WILC_VMM_TO_HOST_SIZE (WILC_VMM_BASE + 0x10) +#define WILC_VMM_CORE_CFG (WILC_VMM_BASE + 0x14) +#define WILC_VMM_TBL_ACTIVE (WILC_VMM_BASE + 040) +#define WILC_VMM_TBL_STATUS (WILC_VMM_BASE + 0x44) + +#define WILC_SPI_REG_BASE 0xe800 +#define WILC_SPI_CTL WILC_SPI_REG_BASE +#define WILC_SPI_MASTER_DMA_ADDR (WILC_SPI_REG_BASE + 0x4) +#define WILC_SPI_MASTER_DMA_COUNT (WILC_SPI_REG_BASE + 0x8) +#define WILC_SPI_SLAVE_DMA_ADDR (WILC_SPI_REG_BASE + 0xc) +#define WILC_SPI_SLAVE_DMA_COUNT (WILC_SPI_REG_BASE + 0x10) +#define WILC_SPI_TX_MODE (WILC_SPI_REG_BASE + 0x20) +#define WILC_SPI_PROTOCOL_CONFIG (WILC_SPI_REG_BASE + 0x24) +#define WILC_SPI_INTR_CTL (WILC_SPI_REG_BASE + 0x2c) + +#define WILC_SPI_PROTOCOL_OFFSET (WILC_SPI_PROTOCOL_CONFIG - \ + WILC_SPI_REG_BASE) + +#define WILC_AHB_DATA_MEM_BASE 0x30000 +#define WILC_AHB_SHARE_MEM_BASE 0xd0000 + +#define WILC_VMM_TBL_RX_SHADOW_BASE WILC_AHB_SHARE_MEM_BASE +#define WILC_VMM_TBL_RX_SHADOW_SIZE 256 + +#define WILC_GP_REG_0 0x149c +#define WILC_GP_REG_1 0x14a0 + +#define WILC_HAVE_SDIO_IRQ_GPIO BIT(0) +#define WILC_HAVE_USE_PMU BIT(1) +#define WILC_HAVE_SLEEP_CLK_SRC_RTC BIT(2) +#define WILC_HAVE_SLEEP_CLK_SRC_XO BIT(3) +#define WILC_HAVE_EXT_PA_INV_TX_RX BIT(4) +#define WILC_HAVE_LEGACY_RF_SETTINGS BIT(5) +#define WILC_HAVE_XTAL_24 BIT(6) +#define WILC_HAVE_DISABLE_WILC_UART BIT(7) /******************************************** * * Wlan Defines * ********************************************/ -#define WILC_CFG_PKT 1 -#define WILC_NET_PKT 0 -#define WILC_MGMT_PKT 2 +#define WILC_CFG_PKT 1 +#define WILC_NET_PKT 0 +#define WILC_MGMT_PKT 2 -#define WILC_CFG_SET 1 -#define WILC_CFG_QUERY 0 - -#define WILC_CFG_RSP 1 -#define WILC_CFG_RSP_STATUS 2 -#define WILC_CFG_RSP_SCAN 3 - -#ifdef WILC_SDIO -#define WILC_PLL_TO 4 -#else -#define WILC_PLL_TO 2 -#endif +#define WILC_CFG_SET 1 +#define WILC_CFG_QUERY 0 +#define WILC_CFG_RSP 1 +#define WILC_CFG_RSP_STATUS 2 +#define WILC_CFG_RSP_SCAN 3 -#define ABORT_INT BIT(31) +#define WILC_PLL_TO_SDIO 4 +#define WILC_PLL_TO_SPI 2 +#define ABORT_INT BIT(31) /*******************************************/ /* E0 and later Interrupt flags. */ @@ -165,15 +141,15 @@ /* 20: INT4 flag */ /* 21: INT5 flag */ /*******************************************/ -#define IRG_FLAGS_OFFSET 16 -#define IRQ_DMA_WD_CNT_MASK ((1ul << IRG_FLAGS_OFFSET) - 1) -#define INT_0 (1 << (IRG_FLAGS_OFFSET)) -#define INT_1 (1 << (IRG_FLAGS_OFFSET + 1)) -#define INT_2 (1 << (IRG_FLAGS_OFFSET + 2)) -#define INT_3 (1 << (IRG_FLAGS_OFFSET + 3)) -#define INT_4 (1 << (IRG_FLAGS_OFFSET + 4)) -#define INT_5 (1 << (IRG_FLAGS_OFFSET + 5)) -#define MAX_NUM_INT (6) +#define IRG_FLAGS_OFFSET 16 +#define IRQ_DMA_WD_CNT_MASK ((1ul << IRG_FLAGS_OFFSET) - 1) +#define INT_0 BIT(IRG_FLAGS_OFFSET) +#define INT_1 BIT(IRG_FLAGS_OFFSET + 1) +#define INT_2 BIT(IRG_FLAGS_OFFSET + 2) +#define INT_3 BIT(IRG_FLAGS_OFFSET + 3) +#define INT_4 BIT(IRG_FLAGS_OFFSET + 4) +#define INT_5 BIT(IRG_FLAGS_OFFSET + 5) +#define MAX_NUM_INT 6 /*******************************************/ /* E0 and later Interrupt flags. */ @@ -188,30 +164,28 @@ /* 7: Select VMM table 2 */ /* 8: Enable VMM */ /*******************************************/ -#define CLR_INT0 BIT(0) -#define CLR_INT1 BIT(1) -#define CLR_INT2 BIT(2) -#define CLR_INT3 BIT(3) -#define CLR_INT4 BIT(4) -#define CLR_INT5 BIT(5) -#define SEL_VMM_TBL0 BIT(6) -#define SEL_VMM_TBL1 BIT(7) -#define EN_VMM BIT(8) - -#define DATA_INT_EXT INT_0 -#define PLL_INT_EXT INT_1 -#define SLEEP_INT_EXT INT_2 -#define ALL_INT_EXT (DATA_INT_EXT | PLL_INT_EXT | SLEEP_INT_EXT) -#define NUM_INT_EXT (3) - -#define DATA_INT_CLR CLR_INT0 -#define PLL_INT_CLR CLR_INT1 -#define SLEEP_INT_CLR CLR_INT2 - -#define ENABLE_RX_VMM (SEL_VMM_TBL1 | EN_VMM) -#define ENABLE_TX_VMM (SEL_VMM_TBL0 | EN_VMM) - - +#define CLR_INT0 BIT(0) +#define CLR_INT1 BIT(1) +#define CLR_INT2 BIT(2) +#define CLR_INT3 BIT(3) +#define CLR_INT4 BIT(4) +#define CLR_INT5 BIT(5) +#define SEL_VMM_TBL0 BIT(6) +#define SEL_VMM_TBL1 BIT(7) +#define EN_VMM BIT(8) + +#define DATA_INT_EXT INT_0 +#define PLL_INT_EXT INT_1 +#define SLEEP_INT_EXT INT_2 +#define ALL_INT_EXT (DATA_INT_EXT | PLL_INT_EXT | SLEEP_INT_EXT) +#define NUM_INT_EXT 3 + +#define DATA_INT_CLR CLR_INT0 +#define PLL_INT_CLR CLR_INT1 +#define SLEEP_INT_CLR CLR_INT2 + +#define ENABLE_RX_VMM (SEL_VMM_TBL1 | EN_VMM) +#define ENABLE_TX_VMM (SEL_VMM_TBL0 | EN_VMM) /*time for expiring the semaphores of cfg packets*/ #define CFG_PKTS_TIMEOUT 2000 /******************************************** @@ -231,7 +205,7 @@ struct txq_entry_t { struct txq_entry_t *next; struct txq_entry_t *prev; int type; - int tcp_PendingAck_index; + int tcp_pending_ack_idx; u8 *buffer; int buffer_size; void *priv; @@ -250,25 +224,26 @@ struct rxq_entry_t { * Host IF Structure * ********************************************/ +struct wilc; +struct wilc_hif_func { + int (*hif_init)(struct wilc *); + int (*hif_deinit)(struct wilc *); + int (*hif_read_reg)(struct wilc *, u32, u32 *); + int (*hif_write_reg)(struct wilc *, u32, u32); + int (*hif_block_rx)(struct wilc *, u32, u8 *, u32); + int (*hif_block_tx)(struct wilc *, u32, u8 *, u32); + int (*hif_read_int)(struct wilc *, u32 *); + int (*hif_clear_int_ext)(struct wilc *, u32); + int (*hif_read_size)(struct wilc *, u32 *); + int (*hif_block_tx_ext)(struct wilc *, u32, u8 *, u32); + int (*hif_block_rx_ext)(struct wilc *, u32, u8 *, u32); + int (*hif_sync_ext)(struct wilc *, int); + int (*enable_interrupt)(struct wilc *nic); + void (*disable_interrupt)(struct wilc *nic); +}; -typedef struct { - int (*hif_init)(wilc_wlan_inp_t *, wilc_debug_func); - int (*hif_deinit)(void *); - int (*hif_read_reg)(u32, u32 *); - int (*hif_write_reg)(u32, u32); - int (*hif_block_rx)(u32, u8 *, u32); - int (*hif_block_tx)(u32, u8 *, u32); - int (*hif_sync)(void); - int (*hif_clear_int)(void); - int (*hif_read_int)(u32 *); - int (*hif_clear_int_ext)(u32); - int (*hif_read_size)(u32 *); - int (*hif_block_tx_ext)(u32, u8 *, u32); - int (*hif_block_rx_ext)(u32, u8 *, u32); - int (*hif_sync_ext)(int); - void (*hif_set_max_bus_speed)(void); - void (*hif_set_default_bus_speed)(void); -} wilc_hif_func_t; +extern const struct wilc_hif_func wilc_hif_spi; +extern const struct wilc_hif_func wilc_hif_sdio; /******************************************** * @@ -276,37 +251,50 @@ typedef struct { * ********************************************/ -#define MAX_CFG_FRAME_SIZE 1468 +#define MAX_CFG_FRAME_SIZE 1468 -typedef struct { +struct wilc_cfg_frame { u8 ether_header[14]; u8 ip_header[20]; u8 udp_header[8]; u8 wid_header[8]; u8 frame[MAX_CFG_FRAME_SIZE]; -} wilc_cfg_frame_t; - -typedef struct { - int (*wlan_tx)(u8 *, u32, wilc_tx_complete_func_t); -} wilc_wlan_cfg_func_t; +}; -typedef struct { +struct wilc_cfg_rsp { int type; u32 seq_no; -} wilc_cfg_rsp_t; +}; -int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size); -int wilc_wlan_start(void); -int wilc_wlan_stop(void); +struct wilc; + +int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer, u32 buffer_size); +int wilc_wlan_start(struct wilc *); +int wilc_wlan_stop(struct wilc *); int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func); -int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount); -void wilc_handle_isr(void *wilc); +int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count); +void wilc_handle_isr(struct wilc *wilc); void wilc_wlan_cleanup(struct net_device *dev); -int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size, - int commit, u32 drvHandler); -int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler); +int wilc_wlan_cfg_set(struct wilc *wilc, int start, u32 wid, u8 *buffer, + u32 buffer_size, int commit, u32 drv_handler); +int wilc_wlan_cfg_get(struct wilc *wilc, int start, u32 wid, int commit, + u32 drv_handler); int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size); -int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, - wilc_tx_complete_func_t func); +int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer, + u32 buffer_size, wilc_tx_complete_func_t func); +void wilc_chip_sleep_manually(struct wilc *wilc); + +void wilc_enable_tcp_ack_filter(bool value); +int wilc_wlan_get_num_conn_ifcs(struct wilc *); +int wilc_mac_xmit(struct sk_buff *skb, struct net_device *dev); + +int wilc_mac_open(struct net_device *ndev); +int wilc_mac_close(struct net_device *ndev); + +int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID); +void WILC_WFI_p2p_rx(struct net_device *dev, u8 *buff, u32 size); + +extern bool wilc_enable_ps; + #endif diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c index a34a81cdeb5e..b72c77bb35f1 100644 --- a/drivers/staging/wilc1000/wilc_wlan_cfg.c +++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c @@ -275,9 +275,7 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size) while (size > 0) { i = 0; wid = info[0] | (info[1] << 8); -#ifdef BIG_ENDIAN - wid = BYTE_SWAP(wid); -#endif + wid = cpu_to_le32(wid); PRINT_INFO(GENERIC_DBG, "Processing response for %d seq %d\n", wid, seq++); switch ((wid >> 12) & 0x7) { case WID_CHAR: @@ -300,11 +298,7 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size) break; if (g_cfg_hword[i].id == wid) { -#ifdef BIG_ENDIAN - g_cfg_hword[i].val = (info[3] << 8) | (info[4]); -#else - g_cfg_hword[i].val = info[3] | (info[4] << 8); -#endif + g_cfg_hword[i].val = cpu_to_le16(info[3] | (info[4] << 8)); break; } i++; @@ -318,11 +312,7 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size) break; if (g_cfg_word[i].id == wid) { -#ifdef BIG_ENDIAN - g_cfg_word[i].val = (info[3] << 24) | (info[4] << 16) | (info[5] << 8) | (info[6]); -#else - g_cfg_word[i].val = info[3] | (info[4] << 8) | (info[5] << 16) | (info[6] << 24); -#endif + g_cfg_word[i].val = cpu_to_le32(info[3] | (info[4] << 8) | (info[5] << 16) | (info[6] << 24)); break; } i++; @@ -505,7 +495,8 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size) return ret; } -int wilc_wlan_cfg_indicate_rx(u8 *frame, int size, wilc_cfg_rsp_t *rsp) +int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size, + struct wilc_cfg_rsp *rsp) { int ret = 1; u8 msg_type; @@ -532,17 +523,17 @@ int wilc_wlan_cfg_indicate_rx(u8 *frame, int size, wilc_cfg_rsp_t *rsp) rsp->seq_no = msg_id; /*call host interface info parse as well*/ PRINT_INFO(RX_DBG, "Info message received\n"); - GnrlAsyncInfoReceived(frame - 4, size + 4); + wilc_gnrl_async_info_received(wilc, frame - 4, size + 4); break; case 'N': - NetworkInfoReceived(frame - 4, size + 4); + wilc_network_info_received(wilc, frame - 4, size + 4); rsp->type = 0; break; case 'S': PRINT_INFO(RX_DBG, "Scan Notification Received\n"); - host_int_ScanCompleteReceived(frame - 4, size + 4); + wilc_scan_complete_received(wilc, frame - 4, size + 4); break; default: diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.h b/drivers/staging/wilc1000/wilc_wlan_cfg.h index 30e60ec4d29f..5f74eb83562f 100644 --- a/drivers/staging/wilc1000/wilc_wlan_cfg.h +++ b/drivers/staging/wilc1000/wilc_wlan_cfg.h @@ -30,10 +30,12 @@ typedef struct { u8 *str; } wilc_cfg_str_t; +struct wilc; int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size); int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id); int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size); -int wilc_wlan_cfg_indicate_rx(u8 *frame, int size, wilc_cfg_rsp_t *rsp); +int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size, + struct wilc_cfg_rsp *rsp); int wilc_wlan_cfg_init(wilc_debug_func func); #endif diff --git a/drivers/staging/wilc1000/wilc_wlan_if.h b/drivers/staging/wilc1000/wilc_wlan_if.h index be972afe6e62..618903caff54 100644 --- a/drivers/staging/wilc1000/wilc_wlan_if.h +++ b/drivers/staging/wilc1000/wilc_wlan_if.h @@ -12,6 +12,7 @@ #include <linux/semaphore.h> #include "linux_wlan_common.h" +#include <linux/netdevice.h> /******************************************** * @@ -71,26 +72,6 @@ typedef struct { u32 block_size; } sdio_cmd53_t; -typedef struct { - int io_type; - int (*io_init)(void *); - void (*io_deinit)(void *); - union { - struct { - int (*sdio_cmd52)(sdio_cmd52_t *); - int (*sdio_cmd53)(sdio_cmd53_t *); - int (*sdio_set_max_speed)(void); - int (*sdio_set_default_speed)(void); - } sdio; - struct { - int (*spi_max_speed)(void); - int (*spi_tx)(u8 *, u32); - int (*spi_rx)(u8 *, u32); - int (*spi_trx)(u8 *, u8 *, u32); - } spi; - } u; -} wilc_wlan_io_func_t; - #define WILC_MAC_INDICATE_STATUS 0x1 #define WILC_MAC_STATUS_INIT -1 #define WILC_MAC_STATUS_READY 0 @@ -98,15 +79,6 @@ typedef struct { #define WILC_MAC_INDICATE_SCAN 0x2 -typedef struct { - void *os_private; -} wilc_wlan_os_context_t; - -typedef struct { - wilc_wlan_os_context_t os_context; - wilc_wlan_io_func_t io_func; -} wilc_wlan_inp_t; - struct tx_complete_data { int size; void *buff; @@ -315,7 +287,7 @@ typedef enum { SW_TRIGGER_ABORT, } TX_ABORT_OPTION_T; -enum WID_TYPE { +enum wid_type { WID_CHAR = 0, WID_SHORT = 1, WID_INT = 2, @@ -937,10 +909,10 @@ typedef enum { WID_MAX = 0xFFFF } WID_T; -int wilc_wlan_init(wilc_wlan_inp_t *inp); - +struct wilc; +int wilc_wlan_init(struct net_device *dev); void wilc_bus_set_max_speed(void); void wilc_bus_set_default_speed(void); -u32 wilc_get_chipid(u8 update); +u32 wilc_get_chipid(struct wilc *wilc, u8 update); #endif diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c index 444ebed7313a..7551ac25d89d 100644 --- a/drivers/staging/wlan-ng/hfa384x_usb.c +++ b/drivers/staging/wlan-ng/hfa384x_usb.c @@ -177,9 +177,6 @@ static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb); static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin); -static void -hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout); - static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin, int urb_status); @@ -3504,7 +3501,7 @@ static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb) rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust; rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust; - prism2sta_ev_rx(wlandev, skb); + p80211netdev_rx(wlandev, skb); break; @@ -3628,7 +3625,7 @@ static void hfa384x_int_rxmonitor(wlandevice_t *wlandev, } /* pass it back up */ - prism2sta_ev_rx(wlandev, skb); + p80211netdev_rx(wlandev, skb); } /*---------------------------------------------------------------- @@ -3674,7 +3671,6 @@ static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin) static void hfa384x_usbout_callback(struct urb *urb) { wlandevice_t *wlandev = urb->context; - hfa384x_usbout_t *usbout = urb->transfer_buffer; #ifdef DEBUG_USB dbprint_urb(urb); @@ -3683,7 +3679,7 @@ static void hfa384x_usbout_callback(struct urb *urb) if (wlandev && wlandev->netdev) { switch (urb->status) { case 0: - hfa384x_usbout_tx(wlandev, usbout); + prism2sta_ev_alloc(wlandev); break; case -EPIPE: @@ -4038,30 +4034,6 @@ static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx) } /*---------------------------------------------------------------- -* hfa384x_usbout_tx -* -* At this point we have finished a send of a frame. Mark the URB -* as available and call ev_alloc to notify higher layers we're -* ready for more. -* -* Arguments: -* wlandev wlan device -* usbout ptr to the usb transfer buffer -* -* Returns: -* nothing -* -* Side effects: -* -* Call context: -* interrupt -----------------------------------------------------------------*/ -static void hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout) -{ - prism2sta_ev_alloc(wlandev); -} - -/*---------------------------------------------------------------- * hfa384x_isgood_pdrcore * * Quick check of PDR codes. diff --git a/drivers/staging/wlan-ng/p80211netdev.h b/drivers/staging/wlan-ng/p80211netdev.h index c547e1cb4c0d..810ee68aa18e 100644 --- a/drivers/staging/wlan-ng/p80211netdev.h +++ b/drivers/staging/wlan-ng/p80211netdev.h @@ -141,7 +141,6 @@ typedef struct p80211_frmrx_t { struct iw_statistics *p80211wext_get_wireless_stats(netdevice_t *dev); /* wireless extensions' ioctls */ extern struct iw_handler_def p80211wext_handler_def; -int p80211wext_event_associated(struct wlandevice *wlandev, int assoc); /* WEP stuff */ #define NUM_WEPKEYS 4 diff --git a/drivers/staging/wlan-ng/prism2mgmt.h b/drivers/staging/wlan-ng/prism2mgmt.h index 16f123959104..7a9f424607b7 100644 --- a/drivers/staging/wlan-ng/prism2mgmt.h +++ b/drivers/staging/wlan-ng/prism2mgmt.h @@ -68,7 +68,6 @@ u32 prism2sta_ifstate(wlandevice_t *wlandev, u32 ifstate); void prism2sta_ev_info(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf); void prism2sta_ev_txexc(wlandevice_t *wlandev, u16 status); void prism2sta_ev_tx(wlandevice_t *wlandev, u16 status); -void prism2sta_ev_rx(wlandevice_t *wlandev, struct sk_buff *skb); void prism2sta_ev_alloc(wlandevice_t *wlandev); int prism2mgmt_mibset_mibget(wlandevice_t *wlandev, void *msgp); diff --git a/drivers/staging/wlan-ng/prism2mib.c b/drivers/staging/wlan-ng/prism2mib.c index b4a15ef3a405..cdda07d1c268 100644 --- a/drivers/staging/wlan-ng/prism2mib.c +++ b/drivers/staging/wlan-ng/prism2mib.c @@ -660,7 +660,6 @@ static int prism2mib_fragmentationthreshold(struct mibrec *mib, struct p80211msg_dot11req_mibset *msg, void *data) { - int result; u32 *uint32 = (u32 *) data; if (!isget) @@ -672,9 +671,7 @@ static int prism2mib_fragmentationthreshold(struct mibrec *mib, return 0; } - result = prism2mib_uint32(mib, isget, wlandev, hw, msg, data); - - return result; + return prism2mib_uint32(mib, isget, wlandev, hw, msg, data); } /*---------------------------------------------------------------- diff --git a/drivers/staging/wlan-ng/prism2sta.c b/drivers/staging/wlan-ng/prism2sta.c index c57f48a1d8df..131223afd918 100644 --- a/drivers/staging/wlan-ng/prism2sta.c +++ b/drivers/staging/wlan-ng/prism2sta.c @@ -1837,27 +1837,6 @@ void prism2sta_ev_tx(wlandevice_t *wlandev, u16 status) } /* - * prism2sta_ev_rx - * - * Handles the Rx event. - * - * Arguments: - * wlandev wlan device structure - * - * Returns: - * nothing - * - * Side effects: - * - * Call context: - * interrupt - */ -void prism2sta_ev_rx(wlandevice_t *wlandev, struct sk_buff *skb) -{ - p80211netdev_rx(wlandev, skb); -} - -/* * prism2sta_ev_alloc * * Handles the Alloc event. diff --git a/include/linux/iio/buffer-dma.h b/include/linux/iio/buffer-dma.h new file mode 100644 index 000000000000..767467d886de --- /dev/null +++ b/include/linux/iio/buffer-dma.h @@ -0,0 +1,152 @@ +/* + * Copyright 2013-2015 Analog Devices Inc. + * Author: Lars-Peter Clausen <lars@metafoo.de> + * + * Licensed under the GPL-2. + */ + +#ifndef __INDUSTRIALIO_DMA_BUFFER_H__ +#define __INDUSTRIALIO_DMA_BUFFER_H__ + +#include <linux/list.h> +#include <linux/kref.h> +#include <linux/spinlock.h> +#include <linux/mutex.h> +#include <linux/iio/buffer.h> + +struct iio_dma_buffer_queue; +struct iio_dma_buffer_ops; +struct device; + +struct iio_buffer_block { + u32 size; + u32 bytes_used; +}; + +/** + * enum iio_block_state - State of a struct iio_dma_buffer_block + * @IIO_BLOCK_STATE_DEQUEUED: Block is not queued + * @IIO_BLOCK_STATE_QUEUED: Block is on the incoming queue + * @IIO_BLOCK_STATE_ACTIVE: Block is currently being processed by the DMA + * @IIO_BLOCK_STATE_DONE: Block is on the outgoing queue + * @IIO_BLOCK_STATE_DEAD: Block has been marked as to be freed + */ +enum iio_block_state { + IIO_BLOCK_STATE_DEQUEUED, + IIO_BLOCK_STATE_QUEUED, + IIO_BLOCK_STATE_ACTIVE, + IIO_BLOCK_STATE_DONE, + IIO_BLOCK_STATE_DEAD, +}; + +/** + * struct iio_dma_buffer_block - IIO buffer block + * @head: List head + * @size: Total size of the block in bytes + * @bytes_used: Number of bytes that contain valid data + * @vaddr: Virutal address of the blocks memory + * @phys_addr: Physical address of the blocks memory + * @queue: Parent DMA buffer queue + * @kref: kref used to manage the lifetime of block + * @state: Current state of the block + */ +struct iio_dma_buffer_block { + /* May only be accessed by the owner of the block */ + struct list_head head; + size_t bytes_used; + + /* + * Set during allocation, constant thereafter. May be accessed read-only + * by anybody holding a reference to the block. + */ + void *vaddr; + dma_addr_t phys_addr; + size_t size; + struct iio_dma_buffer_queue *queue; + + /* Must not be accessed outside the core. */ + struct kref kref; + /* + * Must not be accessed outside the core. Access needs to hold + * queue->list_lock if the block is not owned by the core. + */ + enum iio_block_state state; +}; + +/** + * struct iio_dma_buffer_queue_fileio - FileIO state for the DMA buffer + * @blocks: Buffer blocks used for fileio + * @active_block: Block being used in read() + * @pos: Read offset in the active block + * @block_size: Size of each block + */ +struct iio_dma_buffer_queue_fileio { + struct iio_dma_buffer_block *blocks[2]; + struct iio_dma_buffer_block *active_block; + size_t pos; + size_t block_size; +}; + +/** + * struct iio_dma_buffer_queue - DMA buffer base structure + * @buffer: IIO buffer base structure + * @dev: Parent device + * @ops: DMA buffer callbacks + * @lock: Protects the incoming list, active and the fields in the fileio + * substruct + * @list_lock: Protects lists that contain blocks which can be modified in + * atomic context as well as blocks on those lists. This is the outgoing queue + * list and typically also a list of active blocks in the part that handles + * the DMA controller + * @incoming: List of buffers on the incoming queue + * @outgoing: List of buffers on the outgoing queue + * @active: Whether the buffer is currently active + * @fileio: FileIO state + */ +struct iio_dma_buffer_queue { + struct iio_buffer buffer; + struct device *dev; + const struct iio_dma_buffer_ops *ops; + + struct mutex lock; + spinlock_t list_lock; + struct list_head incoming; + struct list_head outgoing; + + bool active; + + struct iio_dma_buffer_queue_fileio fileio; +}; + +/** + * struct iio_dma_buffer_ops - DMA buffer callback operations + * @submit: Called when a block is submitted to the DMA controller + * @abort: Should abort all pending transfers + */ +struct iio_dma_buffer_ops { + int (*submit)(struct iio_dma_buffer_queue *queue, + struct iio_dma_buffer_block *block); + void (*abort)(struct iio_dma_buffer_queue *queue); +}; + +void iio_dma_buffer_block_done(struct iio_dma_buffer_block *block); +void iio_dma_buffer_block_list_abort(struct iio_dma_buffer_queue *queue, + struct list_head *list); + +int iio_dma_buffer_enable(struct iio_buffer *buffer, + struct iio_dev *indio_dev); +int iio_dma_buffer_disable(struct iio_buffer *buffer, + struct iio_dev *indio_dev); +int iio_dma_buffer_read(struct iio_buffer *buffer, size_t n, + char __user *user_buffer); +size_t iio_dma_buffer_data_available(struct iio_buffer *buffer); +int iio_dma_buffer_set_bytes_per_datum(struct iio_buffer *buffer, size_t bpd); +int iio_dma_buffer_set_length(struct iio_buffer *buffer, int length); +int iio_dma_buffer_request_update(struct iio_buffer *buffer); + +int iio_dma_buffer_init(struct iio_dma_buffer_queue *queue, + struct device *dma_dev, const struct iio_dma_buffer_ops *ops); +void iio_dma_buffer_exit(struct iio_dma_buffer_queue *queue); +void iio_dma_buffer_release(struct iio_dma_buffer_queue *queue); + +#endif diff --git a/include/linux/iio/buffer-dmaengine.h b/include/linux/iio/buffer-dmaengine.h new file mode 100644 index 000000000000..5dcddf427bb0 --- /dev/null +++ b/include/linux/iio/buffer-dmaengine.h @@ -0,0 +1,18 @@ +/* + * Copyright 2014-2015 Analog Devices Inc. + * Author: Lars-Peter Clausen <lars@metafoo.de> + * + * Licensed under the GPL-2 or later. + */ + +#ifndef __IIO_DMAENGINE_H__ +#define __IIO_DMAENGINE_H__ + +struct iio_buffer; +struct device; + +struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev, + const char *channel); +void iio_dmaengine_buffer_free(struct iio_buffer *buffer); + +#endif diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h index 1600c55828e0..2ec3ad58e8a0 100644 --- a/include/linux/iio/buffer.h +++ b/include/linux/iio/buffer.h @@ -18,6 +18,12 @@ struct iio_buffer; /** + * INDIO_BUFFER_FLAG_FIXED_WATERMARK - Watermark level of the buffer can not be + * configured. It has a fixed value which will be buffer specific. + */ +#define INDIO_BUFFER_FLAG_FIXED_WATERMARK BIT(0) + +/** * struct iio_buffer_access_funcs - access functions for buffers. * @store_to: actually store stuff to the buffer * @read_first_n: try to get a specified number of bytes (must exist) @@ -27,9 +33,15 @@ struct iio_buffer; * storage. * @set_bytes_per_datum:set number of bytes per datum * @set_length: set number of datums in buffer + * @enable: called if the buffer is attached to a device and the + * device starts sampling. Calls are balanced with + * @disable. + * @disable: called if the buffer is attached to a device and the + * device stops sampling. Calles are balanced with @enable. * @release: called when the last reference to the buffer is dropped, * should free all resources allocated by the buffer. * @modes: Supported operating modes by this buffer type + * @flags: A bitmask combination of INDIO_BUFFER_FLAG_* * * The purpose of this structure is to make the buffer element * modular as event for a given driver, different usecases may require @@ -51,9 +63,13 @@ struct iio_buffer_access_funcs { int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd); int (*set_length)(struct iio_buffer *buffer, int length); + int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); + int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); + void (*release)(struct iio_buffer *buffer); unsigned int modes; + unsigned int flags; }; /** diff --git a/include/linux/iio/configfs.h b/include/linux/iio/configfs.h new file mode 100644 index 000000000000..93befd67c15c --- /dev/null +++ b/include/linux/iio/configfs.h @@ -0,0 +1,15 @@ +/* + * Industrial I/O configfs support + * + * Copyright (c) 2015 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ +#ifndef __IIO_CONFIGFS +#define __IIO_CONFIGFS + +extern struct configfs_subsystem iio_configfs_subsys; + +#endif /* __IIO_CONFIGFS */ diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 19c94c9acc81..b5894118755f 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -636,6 +636,8 @@ static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) } #endif +ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals); + int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer, int *fract); diff --git a/include/linux/iio/sw_trigger.h b/include/linux/iio/sw_trigger.h new file mode 100644 index 000000000000..5198f8ed08a4 --- /dev/null +++ b/include/linux/iio/sw_trigger.h @@ -0,0 +1,70 @@ +/* + * Industrial I/O software trigger interface + * + * Copyright (c) 2015 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#ifndef __IIO_SW_TRIGGER +#define __IIO_SW_TRIGGER + +#include <linux/module.h> +#include <linux/device.h> +#include <linux/iio/iio.h> +#include <linux/configfs.h> + +#define module_iio_sw_trigger_driver(__iio_sw_trigger_type) \ + module_driver(__iio_sw_trigger_type, iio_register_sw_trigger_type, \ + iio_unregister_sw_trigger_type) + +struct iio_sw_trigger_ops; + +struct iio_sw_trigger_type { + const char *name; + struct module *owner; + const struct iio_sw_trigger_ops *ops; + struct list_head list; + struct config_group *group; +}; + +struct iio_sw_trigger { + struct iio_trigger *trigger; + struct iio_sw_trigger_type *trigger_type; + struct config_group group; +}; + +struct iio_sw_trigger_ops { + struct iio_sw_trigger* (*probe)(const char *); + int (*remove)(struct iio_sw_trigger *); +}; + +static inline +struct iio_sw_trigger *to_iio_sw_trigger(struct config_item *item) +{ + return container_of(to_config_group(item), struct iio_sw_trigger, + group); +} + +int iio_register_sw_trigger_type(struct iio_sw_trigger_type *tt); +void iio_unregister_sw_trigger_type(struct iio_sw_trigger_type *tt); + +struct iio_sw_trigger *iio_sw_trigger_create(const char *, const char *); +void iio_sw_trigger_destroy(struct iio_sw_trigger *); + +int iio_sw_trigger_type_configfs_register(struct iio_sw_trigger_type *tt); +void iio_sw_trigger_type_configfs_unregister(struct iio_sw_trigger_type *tt); + +static inline +void iio_swt_group_init_type_name(struct iio_sw_trigger *t, + const char *name, + struct config_item_type *type) +{ +#ifdef CONFIG_CONFIGFS_FS + config_group_init_type_name(&t->group, name, type); +#endif +} + +#endif /* __IIO_SW_TRIGGER */ diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h index 13e1d96935ed..c800dbc42079 100644 --- a/include/linux/mfd/palmas.h +++ b/include/linux/mfd/palmas.h @@ -134,21 +134,32 @@ struct palmas_pmic_driver_data { struct regulator_config config); }; +struct palmas_adc_wakeup_property { + int adc_channel_number; + int adc_high_threshold; + int adc_low_threshold; +}; + struct palmas_gpadc_platform_data { /* Channel 3 current source is only enabled during conversion */ - int ch3_current; + int ch3_current; /* 0: off; 1: 10uA; 2: 400uA; 3: 800 uA */ /* Channel 0 current source can be used for battery detection. * If used for battery detection this will cause a permanent current * consumption depending on current level set here. */ - int ch0_current; + int ch0_current; /* 0: off; 1: 5uA; 2: 15uA; 3: 20 uA */ + bool extended_delay; /* use extended delay for conversion */ /* default BAT_REMOVAL_DAT setting on device probe */ int bat_removal; /* Sets the START_POLARITY bit in the RT_CTRL register */ int start_polarity; + + int auto_conversion_period_ms; + struct palmas_adc_wakeup_property *adc_wakeup1_data; + struct palmas_adc_wakeup_property *adc_wakeup2_data; }; struct palmas_reg_init { @@ -405,28 +416,7 @@ struct palmas_gpadc_calibration { s32 offset_error; }; -struct palmas_gpadc { - struct device *dev; - struct palmas *palmas; - - int ch3_current; - int ch0_current; - - int gpadc_force; - - int bat_removal; - - struct mutex reading_lock; - struct completion irq_complete; - - int eoc_sw_irq; - - struct palmas_gpadc_calibration *palmas_cal_tbl; - - int conv0_channel; - int conv1_channel; - int rt_channel; -}; +#define PALMAS_DATASHEET_NAME(_name) "palmas-gpadc-chan-"#_name struct palmas_gpadc_result { s32 raw_code; @@ -520,6 +510,43 @@ enum palmas_irqs { PALMAS_NUM_IRQ, }; +/* Palmas GPADC Channels */ +enum { + PALMAS_ADC_CH_IN0, + PALMAS_ADC_CH_IN1, + PALMAS_ADC_CH_IN2, + PALMAS_ADC_CH_IN3, + PALMAS_ADC_CH_IN4, + PALMAS_ADC_CH_IN5, + PALMAS_ADC_CH_IN6, + PALMAS_ADC_CH_IN7, + PALMAS_ADC_CH_IN8, + PALMAS_ADC_CH_IN9, + PALMAS_ADC_CH_IN10, + PALMAS_ADC_CH_IN11, + PALMAS_ADC_CH_IN12, + PALMAS_ADC_CH_IN13, + PALMAS_ADC_CH_IN14, + PALMAS_ADC_CH_IN15, + PALMAS_ADC_CH_MAX, +}; + +/* Palmas GPADC Channel0 Current Source */ +enum { + PALMAS_ADC_CH0_CURRENT_SRC_0, + PALMAS_ADC_CH0_CURRENT_SRC_5, + PALMAS_ADC_CH0_CURRENT_SRC_15, + PALMAS_ADC_CH0_CURRENT_SRC_20, +}; + +/* Palmas GPADC Channel3 Current Source */ +enum { + PALMAS_ADC_CH3_CURRENT_SRC_0, + PALMAS_ADC_CH3_CURRENT_SRC_10, + PALMAS_ADC_CH3_CURRENT_SRC_400, + PALMAS_ADC_CH3_CURRENT_SRC_800, +}; + struct palmas_pmic { struct palmas *palmas; struct device *dev; diff --git a/include/uapi/rdma/hfi/hfi1_user.h b/include/uapi/rdma/hfi/hfi1_user.h index 599562fe5d57..288694e422fb 100644 --- a/include/uapi/rdma/hfi/hfi1_user.h +++ b/include/uapi/rdma/hfi/hfi1_user.h @@ -127,35 +127,33 @@ #define HFI1_CMD_TID_UPDATE 4 /* update expected TID entries */ #define HFI1_CMD_TID_FREE 5 /* free expected TID entries */ #define HFI1_CMD_CREDIT_UPD 6 /* force an update of PIO credit */ -#define HFI1_CMD_SDMA_STATUS_UPD 7 /* force update of SDMA status ring */ +#define HFI1_CMD_SDMA_STATUS_UPD 7 /* force update of SDMA status ring */ #define HFI1_CMD_RECV_CTRL 8 /* control receipt of packets */ #define HFI1_CMD_POLL_TYPE 9 /* set the kind of polling we want */ #define HFI1_CMD_ACK_EVENT 10 /* ack & clear user status bits */ -#define HFI1_CMD_SET_PKEY 11 /* set context's pkey */ -#define HFI1_CMD_CTXT_RESET 12 /* reset context's HW send context */ +#define HFI1_CMD_SET_PKEY 11 /* set context's pkey */ +#define HFI1_CMD_CTXT_RESET 12 /* reset context's HW send context */ /* separate EPROM commands from normal PSM commands */ #define HFI1_CMD_EP_INFO 64 /* read EPROM device ID */ #define HFI1_CMD_EP_ERASE_CHIP 65 /* erase whole EPROM */ -#define HFI1_CMD_EP_ERASE_P0 66 /* erase EPROM partition 0 */ -#define HFI1_CMD_EP_ERASE_P1 67 /* erase EPROM partition 1 */ -#define HFI1_CMD_EP_READ_P0 68 /* read EPROM partition 0 */ -#define HFI1_CMD_EP_READ_P1 69 /* read EPROM partition 1 */ -#define HFI1_CMD_EP_WRITE_P0 70 /* write EPROM partition 0 */ -#define HFI1_CMD_EP_WRITE_P1 71 /* write EPROM partition 1 */ - -#define _HFI1_EVENT_FROZEN_BIT 0 -#define _HFI1_EVENT_LINKDOWN_BIT 1 -#define _HFI1_EVENT_LID_CHANGE_BIT 2 -#define _HFI1_EVENT_LMC_CHANGE_BIT 3 -#define _HFI1_EVENT_SL2VL_CHANGE_BIT 4 +/* range 66-74 no longer used */ +#define HFI1_CMD_EP_ERASE_RANGE 75 /* erase EPROM range */ +#define HFI1_CMD_EP_READ_RANGE 76 /* read EPROM range */ +#define HFI1_CMD_EP_WRITE_RANGE 77 /* write EPROM range */ + +#define _HFI1_EVENT_FROZEN_BIT 0 +#define _HFI1_EVENT_LINKDOWN_BIT 1 +#define _HFI1_EVENT_LID_CHANGE_BIT 2 +#define _HFI1_EVENT_LMC_CHANGE_BIT 3 +#define _HFI1_EVENT_SL2VL_CHANGE_BIT 4 #define _HFI1_MAX_EVENT_BIT _HFI1_EVENT_SL2VL_CHANGE_BIT -#define HFI1_EVENT_FROZEN (1UL << _HFI1_EVENT_FROZEN_BIT) -#define HFI1_EVENT_LINKDOWN_BIT (1UL << _HFI1_EVENT_LINKDOWN_BIT) -#define HFI1_EVENT_LID_CHANGE_BIT (1UL << _HFI1_EVENT_LID_CHANGE_BIT) -#define HFI1_EVENT_LMC_CHANGE_BIT (1UL << _HFI1_EVENT_LMC_CHANGE_BIT) -#define HFI1_EVENT_SL2VL_CHANGE_BIT (1UL << _HFI1_EVENT_SL2VL_CHANGE_BIT) +#define HFI1_EVENT_FROZEN (1UL << _HFI1_EVENT_FROZEN_BIT) +#define HFI1_EVENT_LINKDOWN (1UL << _HFI1_EVENT_LINKDOWN_BIT) +#define HFI1_EVENT_LID_CHANGE (1UL << _HFI1_EVENT_LID_CHANGE_BIT) +#define HFI1_EVENT_LMC_CHANGE (1UL << _HFI1_EVENT_LMC_CHANGE_BIT) +#define HFI1_EVENT_SL2VL_CHANGE (1UL << _HFI1_EVENT_SL2VL_CHANGE_BIT) /* * These are the status bits readable (in ASCII form, 64bit value) |