Changes in 4.9.203 ax88172a: fix information leak on short answers slip: Fix memory leak in slip_open error path ALSA: usb-audio: Fix missing error check at mixer resolution test ALSA: usb-audio: not submit urb for stopped endpoint Input: ff-memless - kill timer in destroy() Input: synaptics-rmi4 - fix video buffer size Input: synaptics-rmi4 - clear IRQ enables for F54 Input: synaptics-rmi4 - destroy F54 poller workqueue when removing IB/hfi1: Ensure full Gen3 speed in a Gen4 system ecryptfs_lookup_interpose(): lower_dentry->d_inode is not stable ecryptfs_lookup_interpose(): lower_dentry->d_parent is not stable either iommu/vt-d: Fix QI_DEV_IOTLB_PFSID and QI_DEV_EIOTLB_PFSID macros mm: memcg: switch to css_tryget() in get_mem_cgroup_from_mm() mm: hugetlb: switch to css_tryget() in hugetlb_cgroup_charge_cgroup() mmc: sdhci-of-at91: fix quirk2 overwrite ath10k: fix kernel panic by moving pci flush after napi_disable iio: dac: mcp4922: fix error handling in mcp4922_write_raw ALSA: pcm: signedness bug in snd_pcm_plug_alloc() arm64: dts: tegra210-p2180: Correct sdmmc4 vqmmc-supply ARM: dts: at91/trivial: Fix USART1 definition for at91sam9g45 cfg80211: Avoid regulatory restore when COUNTRY_IE_IGNORE is set ALSA: seq: Do error checks at creating system ports ath9k: fix tx99 with monitor mode interface gfs2: Don't set GFS2_RDF_UPTODATE when the lvb is updated ASoC: dpcm: Properly initialise hw->rate_max MIPS: BCM47XX: Enable USB power on Netgear WNDR3400v3 ARM: dts: exynos: Fix sound in Snow-rev5 Chromebook ARM: dts: exynos: Fix regulators configuration on Peach Pi/Pit Chromebooks i40e: use correct length for strncpy i40e: hold the rtnl lock on clearing interrupt scheme i40e: Prevent deleting MAC address from VF when set by PF IB/rxe: fixes for rdma read retry iwlwifi: mvm: avoid sending too many BARs ARM: dts: pxa: fix power i2c base address rtl8187: Fix warning generated when strncpy() destination length matches the sixe argument net: lan78xx: Bail out if lan78xx_get_endpoints fails ASoC: sgtl5000: avoid division by zero if lo_vag is zero ARM: dts: exynos: Disable pull control for S5M8767 PMIC ath10k: wmi: disable softirq's while calling ieee80211_rx mips: txx9: fix iounmap related issue ASoC: Intel: hdac_hdmi: Limit sampling rates at dai creation of: make PowerMac cache node search conditional on CONFIG_PPC_PMAC ARM: dts: omap3-gta04: give spi_lcd node a label so that we can overwrite in other DTS files ARM: dts: omap3-gta04: fixes for tvout / venc ARM: dts: omap3-gta04: tvout: enable as display1 alias ARM: dts: omap3-gta04: fix touchscreen tsc2007 ARM: dts: omap3-gta04: make NAND partitions compatible with recent U-Boot ARM: dts: omap3-gta04: keep vpll2 always on dmaengine: dma-jz4780: Don't depend on MACH_JZ4780 dmaengine: dma-jz4780: Further residue status fix ath9k: add back support for using active monitor interfaces for tx99 signal: Always ignore SIGKILL and SIGSTOP sent to the global init signal: Properly deliver SIGILL from uprobes signal: Properly deliver SIGSEGV from x86 uprobes f2fs: fix memory leak of percpu counter in fill_super() scsi: sym53c8xx: fix NULL pointer dereference panic in sym_int_sir() ARM: imx6: register pm_power_off handler if "fsl,pmic-stby-poweroff" is set scsi: pm80xx: Corrected dma_unmap_sg() parameter scsi: pm80xx: Fixed system hang issue during kexec boot kprobes: Don't call BUG_ON() if there is a kprobe in use on free list nvmem: core: return error code instead of NULL from nvmem_device_get media: fix: media: pci: meye: validate offset to avoid arbitrary access media: dvb: fix compat ioctl translation ALSA: intel8x0m: Register irq handler after register initializations pinctrl: at91-pio4: fix has_config check in atmel_pctl_dt_subnode_to_map() llc: avoid blocking in llc_sap_close() ARM: dts: qcom: ipq4019: fix cpu0's qcom,saw2 reg value powerpc/vdso: Correct call frame information ARM: dts: socfpga: Fix I2C bus unit-address error pinctrl: at91: don't use the same irqchip with multiple gpiochips cxgb4: Fix endianness issue in t4_fwcache() power: supply: ab8500_fg: silence uninitialized variable warnings power: reset: at91-poweroff: do not procede if at91_shdwc is allocated power: supply: max8998-charger: Fix platform data retrieval component: fix loop condition to call unbind() if bind() fails kernfs: Fix range checks in kernfs_get_target_path ip_gre: fix parsing gre header in ipgre_err ARM: dts: rockchip: Fix erroneous SPI bus dtc warnings on rk3036 ath9k: Fix a locking bug in ath9k_add_interface() s390/qeth: invoke softirqs after napi_schedule() PCI/ACPI: Correct error message for ASPM disabling serial: mxs-auart: Fix potential infinite loop powerpc/iommu: Avoid derefence before pointer check powerpc/64s/hash: Fix stab_rr off by one initialization powerpc/pseries: Disable CPU hotplug across migrations RDMA/i40iw: Fix incorrect iterator type libfdt: Ensure INT_MAX is defined in libfdt_env.h power: supply: twl4030_charger: fix charging current out-of-bounds power: supply: twl4030_charger: disable eoc interrupt on linear charge net: toshiba: fix return type of ndo_start_xmit function net: xilinx: fix return type of ndo_start_xmit function net: broadcom: fix return type of ndo_start_xmit function net: amd: fix return type of ndo_start_xmit function usb: chipidea: imx: enable OTG overcurrent in case USB subsystem is already started usb: chipidea: Fix otg event handler mlxsw: spectrum: Init shaper for TCs 8..15 ARM: dts: am335x-evm: fix number of cpsw f2fs: fix to recover inode's uid/gid during POR ARM: dts: ux500: Correct SCU unit address ARM: dts: ux500: Fix LCDA clock line muxing ARM: dts: ste: Fix SPI controller node names spi: pic32: Use proper enum in dmaengine_prep_slave_rg cpufeature: avoid warning when compiling with clang ARM: dts: marvell: Fix SPI and I2C bus warnings bnx2x: Ignore bandwidth attention in single function mode net: micrel: fix return type of ndo_start_xmit function x86/CPU: Use correct macros for Cyrix calls MIPS: kexec: Relax memory restriction media: pci: ivtv: Fix a sleep-in-atomic-context bug in ivtv_yuv_init() media: au0828: Fix incorrect error messages media: davinci: Fix implicit enum conversion warning usb: gadget: uvc: configfs: Drop leaked references to config items usb: gadget: uvc: configfs: Prevent format changes after linking header phy: phy-twl4030-usb: fix denied runtime access usb: gadget: uvc: Factor out video USB request queueing usb: gadget: uvc: Only halt video streaming endpoint in bulk mode coresight: Fix handling of sinks coresight: etm4x: Configure EL2 exception level when kernel is running in HYP coresight: tmc: Fix byte-address alignment for RRP misc: kgdbts: Fix restrict error misc: genwqe: should return proper error value. vfio/pci: Fix potential memory leak in vfio_msi_cap_len vfio/pci: Mask buggy SR-IOV VF INTx support scsi: libsas: always unregister the old device if going to discover new ARM: dts: tegra30: fix xcvr-setup-use-fuses ARM: tegra: apalis_t30: fix mmc1 cmd pull-up ARM: dts: paz00: fix wakeup gpio keycode net: smsc: fix return type of ndo_start_xmit function EDAC: Raise the maximum number of memory controllers ARM: dts: realview: Fix SPI controller node names Bluetooth: L2CAP: Detect if remote is not able to use the whole MPS crypto: s5p-sss: Fix Fix argument list alignment crypto: fix a memory leak in rsa-kcs1pad's encryption mode scsi: NCR5380: Clear all unissued commands on host reset scsi: NCR5380: Use DRIVER_SENSE to indicate valid sense data scsi: NCR5380: Check for invalid reselection target scsi: NCR5380: Don't clear busy flag when abort fails scsi: NCR5380: Don't call dsprintk() following reselection interrupt scsi: NCR5380: Handle BUS FREE during reselection arm64: dts: amd: Fix SPI bus warnings arm64: dts: lg: Fix SPI controller node names ARM: dts: lpc32xx: Fix SPI controller node names usb: xhci-mtk: fix ISOC error when interval is zero fuse: use READ_ONCE on congestion_threshold and max_background IB/iser: Fix possible NULL deref at iser_inv_desc() memfd: Use radix_tree_deref_slot_protected to avoid the warning. slcan: Fix memory leak in error path net: cdc_ncm: Signedness bug in cdc_ncm_set_dgram_size() x86/atomic: Fix smp_mb__{before,after}_atomic() kprobes/x86: Prohibit probing on exception masking instructions uprobes/x86: Prohibit probing on MOV SS instruction fbdev: Ditch fb_edid_add_monspecs block: introduce blk_rq_is_passthrough libata: have ata_scsi_rw_xlat() fail invalid passthrough requests net: ovs: fix return type of ndo_start_xmit function net: xen-netback: fix return type of ndo_start_xmit function ARM: dts: omap5: enable OTG role for DWC3 controller f2fs: return correct errno in f2fs_gc SUNRPC: Fix priority queue fairness kvm: arm/arm64: Fix stage2_flush_memslot for 4 level page table arm64/numa: Report correct memblock range for the dummy node ath10k: fix vdev-start timeout on error ata: ahci_brcm: Allow using driver or DSL SoCs ath9k: fix reporting calculated new FFT upper max usb: gadget: udc: fotg210-udc: Fix a sleep-in-atomic-context bug in fotg210_get_status() nl80211: Fix a GET_KEY reply attribute dmaengine: ep93xx: Return proper enum in ep93xx_dma_chan_direction dmaengine: timb_dma: Use proper enum in td_prep_slave_sg mei: samples: fix a signedness bug in amt_host_if_call() cxgb4: Use proper enum in cxgb4_dcb_handle_fw_update cxgb4: Use proper enum in IEEE_FAUX_SYNC powerpc/pseries: Fix DTL buffer registration powerpc/pseries: Fix how we iterate over the DTL entries mtd: rawnand: sh_flctl: Use proper enum for flctl_dma_fifo0_transfer ixgbe: Fix crash with VFs and flow director on interface flap IB/mthca: Fix error return code in __mthca_init_one() IB/mlx4: Avoid implicit enumerated type conversion ACPICA: Never run _REG on system_memory and system_IO ata: ep93xx: Use proper enums for directions media: pxa_camera: Fix check for pdev->dev.of_node ALSA: hda/sigmatel - Disable automute for Elo VuPoint KVM: PPC: Book3S PR: Exiting split hack mode needs to fixup both PC and LR USB: serial: cypress_m8: fix interrupt-out transfer length mtd: physmap_of: Release resources on error cpu/SMT: State SMT is disabled even with nosmt and without "=force" brcmfmac: reduce timeout for action frame scan brcmfmac: fix full timeout waiting for action frame on-channel tx clk: samsung: Use clk_hw API for calling clk framework from clk notifiers i2c: brcmstb: Allow enabling the driver on DSL SoCs NFSv4.x: fix lock recovery during delegation recall dmaengine: ioat: fix prototype of ioat_enumerate_channels Input: st1232 - set INPUT_PROP_DIRECT property Input: silead - try firmware reload after unsuccessful resume x86/olpc: Fix build error with CONFIG_MFD_CS5535=m crypto: mxs-dcp - Fix SHA null hashes and output length crypto: mxs-dcp - Fix AES issues ACPI / SBS: Fix rare oops when removing modules iwlwifi: mvm: don't send keys when entering D3 fbdev: sbuslib: use checked version of put_user() fbdev: sbuslib: integer overflow in sbusfb_ioctl_helper() reset: Fix potential use-after-free in __of_reset_control_get() bcache: recal cached_dev_sectors on detach s390/kasan: avoid vdso instrumentation proc/vmcore: Fix i386 build error of missing copy_oldmem_page_encrypted() backlight: lm3639: Unconditionally call led_classdev_unregister mfd: ti_am335x_tscadc: Keep ADC interface on if child is wakeup capable printk: Give error on attempt to set log buffer length to over 2G media: isif: fix a NULL pointer dereference bug GFS2: Flush the GFS2 delete workqueue before stopping the kernel threads media: cx231xx: fix potential sign-extension overflow on large shift x86/kexec: Correct KEXEC_BACKUP_SRC_END off-by-one error gpio: syscon: Fix possible NULL ptr usage spi: spidev: Fix OF tree warning logic ARM: 8802/1: Call syscall_trace_exit even when system call skipped orangefs: rate limit the client not running info message hwmon: (pwm-fan) Silence error on probe deferral hwmon: (ina3221) Fix INA3221_CONFIG_MODE macros misc: cxl: Fix possible null pointer dereference mac80211: minstrel: fix CCK rate group streams value spi: rockchip: initialize dma_slave_config properly ARM: dts: omap5: Fix dual-role mode on Super-Speed port arm64: uaccess: Ensure PAN is re-enabled after unhandled uaccess fault Linux 4.9.203 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
1117 lines
30 KiB
C
1117 lines
30 KiB
C
/*
|
|
* Copyright (c) 2013 Qualcomm Atheros, Inc.
|
|
*
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
#include <linux/relay.h>
|
|
#include <linux/random.h>
|
|
#include "ath9k.h"
|
|
|
|
static s8 fix_rssi_inv_only(u8 rssi_val)
|
|
{
|
|
if (rssi_val == 128)
|
|
rssi_val = 0;
|
|
return (s8) rssi_val;
|
|
}
|
|
|
|
static void ath_debug_send_fft_sample(struct ath_spec_scan_priv *spec_priv,
|
|
struct fft_sample_tlv *fft_sample_tlv)
|
|
{
|
|
int length;
|
|
if (!spec_priv->rfs_chan_spec_scan)
|
|
return;
|
|
|
|
length = __be16_to_cpu(fft_sample_tlv->length) +
|
|
sizeof(*fft_sample_tlv);
|
|
relay_write(spec_priv->rfs_chan_spec_scan, fft_sample_tlv, length);
|
|
}
|
|
|
|
typedef int (ath_cmn_fft_idx_validator) (u8 *sample_end, int bytes_read);
|
|
|
|
static int
|
|
ath_cmn_max_idx_verify_ht20_fft(u8 *sample_end, int bytes_read)
|
|
{
|
|
struct ath_ht20_mag_info *mag_info;
|
|
u8 *sample;
|
|
u16 max_magnitude;
|
|
u8 max_index;
|
|
u8 max_exp;
|
|
|
|
/* Sanity check so that we don't read outside the read
|
|
* buffer
|
|
*/
|
|
if (bytes_read < SPECTRAL_HT20_SAMPLE_LEN - 1)
|
|
return -1;
|
|
|
|
mag_info = (struct ath_ht20_mag_info *) (sample_end -
|
|
sizeof(struct ath_ht20_mag_info) + 1);
|
|
|
|
sample = sample_end - SPECTRAL_HT20_SAMPLE_LEN + 1;
|
|
|
|
max_index = spectral_max_index(mag_info->all_bins,
|
|
SPECTRAL_HT20_NUM_BINS);
|
|
max_magnitude = spectral_max_magnitude(mag_info->all_bins);
|
|
|
|
max_exp = mag_info->max_exp & 0xf;
|
|
|
|
/* Don't try to read something outside the read buffer
|
|
* in case of a missing byte (so bins[0] will be outside
|
|
* the read buffer)
|
|
*/
|
|
if (bytes_read < SPECTRAL_HT20_SAMPLE_LEN && max_index < 1)
|
|
return -1;
|
|
|
|
if (sample[max_index] != (max_magnitude >> max_exp))
|
|
return -1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
ath_cmn_max_idx_verify_ht20_40_fft(u8 *sample_end, int bytes_read)
|
|
{
|
|
struct ath_ht20_40_mag_info *mag_info;
|
|
u8 *sample;
|
|
u16 lower_mag, upper_mag;
|
|
u8 lower_max_index, upper_max_index;
|
|
u8 max_exp;
|
|
int dc_pos = SPECTRAL_HT20_40_NUM_BINS / 2;
|
|
|
|
/* Sanity check so that we don't read outside the read
|
|
* buffer
|
|
*/
|
|
if (bytes_read < SPECTRAL_HT20_40_SAMPLE_LEN - 1)
|
|
return -1;
|
|
|
|
mag_info = (struct ath_ht20_40_mag_info *) (sample_end -
|
|
sizeof(struct ath_ht20_40_mag_info) + 1);
|
|
|
|
sample = sample_end - SPECTRAL_HT20_40_SAMPLE_LEN + 1;
|
|
|
|
lower_mag = spectral_max_magnitude(mag_info->lower_bins);
|
|
lower_max_index = spectral_max_index(mag_info->lower_bins,
|
|
SPECTRAL_HT20_40_NUM_BINS);
|
|
|
|
upper_mag = spectral_max_magnitude(mag_info->upper_bins);
|
|
upper_max_index = spectral_max_index(mag_info->upper_bins,
|
|
SPECTRAL_HT20_40_NUM_BINS);
|
|
|
|
max_exp = mag_info->max_exp & 0xf;
|
|
|
|
/* Don't try to read something outside the read buffer
|
|
* in case of a missing byte (so bins[0] will be outside
|
|
* the read buffer)
|
|
*/
|
|
if (bytes_read < SPECTRAL_HT20_40_SAMPLE_LEN &&
|
|
((upper_max_index < 1) || (lower_max_index < 1)))
|
|
return -1;
|
|
|
|
/* Some time hardware messes up the index and adds
|
|
* the index of the middle point (dc_pos). Try to fix it.
|
|
*/
|
|
if ((upper_max_index - dc_pos > 0) &&
|
|
(sample[upper_max_index] == (upper_mag >> max_exp)))
|
|
upper_max_index -= dc_pos;
|
|
|
|
if ((lower_max_index - dc_pos > 0) &&
|
|
(sample[lower_max_index - dc_pos] == (lower_mag >> max_exp)))
|
|
lower_max_index -= dc_pos;
|
|
|
|
if ((sample[upper_max_index + dc_pos] != (upper_mag >> max_exp)) ||
|
|
(sample[lower_max_index] != (lower_mag >> max_exp)))
|
|
return -1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
typedef int (ath_cmn_fft_sample_handler) (struct ath_rx_status *rs,
|
|
struct ath_spec_scan_priv *spec_priv,
|
|
u8 *sample_buf, u64 tsf, u16 freq, int chan_type);
|
|
|
|
static int
|
|
ath_cmn_process_ht20_fft(struct ath_rx_status *rs,
|
|
struct ath_spec_scan_priv *spec_priv,
|
|
u8 *sample_buf,
|
|
u64 tsf, u16 freq, int chan_type)
|
|
{
|
|
struct fft_sample_ht20 fft_sample_20;
|
|
struct ath_common *common = ath9k_hw_common(spec_priv->ah);
|
|
struct ath_hw *ah = spec_priv->ah;
|
|
struct ath_ht20_mag_info *mag_info;
|
|
struct fft_sample_tlv *tlv;
|
|
int i = 0;
|
|
int ret = 0;
|
|
int dc_pos = SPECTRAL_HT20_NUM_BINS / 2;
|
|
u16 magnitude, tmp_mag, length;
|
|
u8 max_index, bitmap_w, max_exp;
|
|
|
|
length = sizeof(fft_sample_20) - sizeof(struct fft_sample_tlv);
|
|
fft_sample_20.tlv.type = ATH_FFT_SAMPLE_HT20;
|
|
fft_sample_20.tlv.length = __cpu_to_be16(length);
|
|
fft_sample_20.freq = __cpu_to_be16(freq);
|
|
fft_sample_20.rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]);
|
|
fft_sample_20.noise = ah->noise;
|
|
|
|
mag_info = (struct ath_ht20_mag_info *) (sample_buf +
|
|
SPECTRAL_HT20_NUM_BINS);
|
|
|
|
magnitude = spectral_max_magnitude(mag_info->all_bins);
|
|
fft_sample_20.max_magnitude = __cpu_to_be16(magnitude);
|
|
|
|
max_index = spectral_max_index(mag_info->all_bins,
|
|
SPECTRAL_HT20_NUM_BINS);
|
|
fft_sample_20.max_index = max_index;
|
|
|
|
bitmap_w = spectral_bitmap_weight(mag_info->all_bins);
|
|
fft_sample_20.bitmap_weight = bitmap_w;
|
|
|
|
max_exp = mag_info->max_exp & 0xf;
|
|
fft_sample_20.max_exp = max_exp;
|
|
|
|
fft_sample_20.tsf = __cpu_to_be64(tsf);
|
|
|
|
memcpy(fft_sample_20.data, sample_buf, SPECTRAL_HT20_NUM_BINS);
|
|
|
|
ath_dbg(common, SPECTRAL_SCAN, "FFT HT20 frame: max mag 0x%X,"
|
|
"max_mag_idx %i\n",
|
|
magnitude >> max_exp,
|
|
max_index);
|
|
|
|
if (fft_sample_20.data[max_index] != (magnitude >> max_exp)) {
|
|
ath_dbg(common, SPECTRAL_SCAN, "Magnitude mismatch !\n");
|
|
ret = -1;
|
|
}
|
|
|
|
/* DC value (value in the middle) is the blind spot of the spectral
|
|
* sample and invalid, interpolate it.
|
|
*/
|
|
fft_sample_20.data[dc_pos] = (fft_sample_20.data[dc_pos + 1] +
|
|
fft_sample_20.data[dc_pos - 1]) / 2;
|
|
|
|
/* Check if the maximum magnitude is indeed maximum,
|
|
* also if the maximum value was at dc_pos, calculate
|
|
* a new one (since value at dc_pos is invalid).
|
|
*/
|
|
if (max_index == dc_pos) {
|
|
tmp_mag = 0;
|
|
for (i = 0; i < dc_pos; i++) {
|
|
if (fft_sample_20.data[i] > tmp_mag) {
|
|
tmp_mag = fft_sample_20.data[i];
|
|
fft_sample_20.max_index = i;
|
|
}
|
|
}
|
|
|
|
magnitude = tmp_mag << max_exp;
|
|
fft_sample_20.max_magnitude = __cpu_to_be16(magnitude);
|
|
|
|
ath_dbg(common, SPECTRAL_SCAN,
|
|
"Calculated new lower max 0x%X at %i\n",
|
|
tmp_mag, fft_sample_20.max_index);
|
|
} else
|
|
for (i = 0; i < SPECTRAL_HT20_NUM_BINS; i++) {
|
|
if (fft_sample_20.data[i] == (magnitude >> max_exp))
|
|
ath_dbg(common, SPECTRAL_SCAN,
|
|
"Got max: 0x%X at index %i\n",
|
|
fft_sample_20.data[i], i);
|
|
|
|
if (fft_sample_20.data[i] > (magnitude >> max_exp)) {
|
|
ath_dbg(common, SPECTRAL_SCAN,
|
|
"Got bin %i greater than max: 0x%X\n",
|
|
i, fft_sample_20.data[i]);
|
|
ret = -1;
|
|
}
|
|
}
|
|
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
tlv = (struct fft_sample_tlv *)&fft_sample_20;
|
|
|
|
ath_debug_send_fft_sample(spec_priv, tlv);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
ath_cmn_process_ht20_40_fft(struct ath_rx_status *rs,
|
|
struct ath_spec_scan_priv *spec_priv,
|
|
u8 *sample_buf,
|
|
u64 tsf, u16 freq, int chan_type)
|
|
{
|
|
struct fft_sample_ht20_40 fft_sample_40;
|
|
struct ath_common *common = ath9k_hw_common(spec_priv->ah);
|
|
struct ath_hw *ah = spec_priv->ah;
|
|
struct ath9k_hw_cal_data *caldata = ah->caldata;
|
|
struct ath_ht20_40_mag_info *mag_info;
|
|
struct fft_sample_tlv *tlv;
|
|
int dc_pos = SPECTRAL_HT20_40_NUM_BINS / 2;
|
|
int i = 0;
|
|
int ret = 0;
|
|
s16 ext_nf;
|
|
u16 lower_mag, upper_mag, tmp_mag, length;
|
|
s8 lower_rssi, upper_rssi;
|
|
u8 lower_max_index, upper_max_index;
|
|
u8 lower_bitmap_w, upper_bitmap_w, max_exp;
|
|
|
|
if (caldata)
|
|
ext_nf = ath9k_hw_getchan_noise(ah, ah->curchan,
|
|
caldata->nfCalHist[3].privNF);
|
|
else
|
|
ext_nf = ATH_DEFAULT_NOISE_FLOOR;
|
|
|
|
length = sizeof(fft_sample_40) - sizeof(struct fft_sample_tlv);
|
|
fft_sample_40.tlv.type = ATH_FFT_SAMPLE_HT20_40;
|
|
fft_sample_40.tlv.length = __cpu_to_be16(length);
|
|
fft_sample_40.freq = __cpu_to_be16(freq);
|
|
fft_sample_40.channel_type = chan_type;
|
|
|
|
if (chan_type == NL80211_CHAN_HT40PLUS) {
|
|
lower_rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]);
|
|
upper_rssi = fix_rssi_inv_only(rs->rs_rssi_ext[0]);
|
|
|
|
fft_sample_40.lower_noise = ah->noise;
|
|
fft_sample_40.upper_noise = ext_nf;
|
|
} else {
|
|
lower_rssi = fix_rssi_inv_only(rs->rs_rssi_ext[0]);
|
|
upper_rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]);
|
|
|
|
fft_sample_40.lower_noise = ext_nf;
|
|
fft_sample_40.upper_noise = ah->noise;
|
|
}
|
|
|
|
fft_sample_40.lower_rssi = lower_rssi;
|
|
fft_sample_40.upper_rssi = upper_rssi;
|
|
|
|
mag_info = (struct ath_ht20_40_mag_info *) (sample_buf +
|
|
SPECTRAL_HT20_40_NUM_BINS);
|
|
|
|
lower_mag = spectral_max_magnitude(mag_info->lower_bins);
|
|
fft_sample_40.lower_max_magnitude = __cpu_to_be16(lower_mag);
|
|
|
|
upper_mag = spectral_max_magnitude(mag_info->upper_bins);
|
|
fft_sample_40.upper_max_magnitude = __cpu_to_be16(upper_mag);
|
|
|
|
lower_max_index = spectral_max_index(mag_info->lower_bins,
|
|
SPECTRAL_HT20_40_NUM_BINS);
|
|
fft_sample_40.lower_max_index = lower_max_index;
|
|
|
|
upper_max_index = spectral_max_index(mag_info->upper_bins,
|
|
SPECTRAL_HT20_40_NUM_BINS);
|
|
fft_sample_40.upper_max_index = upper_max_index;
|
|
|
|
lower_bitmap_w = spectral_bitmap_weight(mag_info->lower_bins);
|
|
fft_sample_40.lower_bitmap_weight = lower_bitmap_w;
|
|
|
|
upper_bitmap_w = spectral_bitmap_weight(mag_info->upper_bins);
|
|
fft_sample_40.upper_bitmap_weight = upper_bitmap_w;
|
|
|
|
max_exp = mag_info->max_exp & 0xf;
|
|
fft_sample_40.max_exp = max_exp;
|
|
|
|
fft_sample_40.tsf = __cpu_to_be64(tsf);
|
|
|
|
memcpy(fft_sample_40.data, sample_buf, SPECTRAL_HT20_40_NUM_BINS);
|
|
|
|
ath_dbg(common, SPECTRAL_SCAN, "FFT HT20/40 frame: lower mag 0x%X,"
|
|
"lower_mag_idx %i, upper mag 0x%X,"
|
|
"upper_mag_idx %i\n",
|
|
lower_mag >> max_exp,
|
|
lower_max_index,
|
|
upper_mag >> max_exp,
|
|
upper_max_index);
|
|
|
|
/* Some time hardware messes up the index and adds
|
|
* the index of the middle point (dc_pos). Try to fix it.
|
|
*/
|
|
if ((upper_max_index - dc_pos > 0) &&
|
|
(fft_sample_40.data[upper_max_index] == (upper_mag >> max_exp))) {
|
|
upper_max_index -= dc_pos;
|
|
fft_sample_40.upper_max_index = upper_max_index;
|
|
}
|
|
|
|
if ((lower_max_index - dc_pos > 0) &&
|
|
(fft_sample_40.data[lower_max_index - dc_pos] ==
|
|
(lower_mag >> max_exp))) {
|
|
lower_max_index -= dc_pos;
|
|
fft_sample_40.lower_max_index = lower_max_index;
|
|
}
|
|
|
|
/* Check if we got the expected magnitude values at
|
|
* the expected bins
|
|
*/
|
|
if ((fft_sample_40.data[upper_max_index + dc_pos]
|
|
!= (upper_mag >> max_exp)) ||
|
|
(fft_sample_40.data[lower_max_index]
|
|
!= (lower_mag >> max_exp))) {
|
|
ath_dbg(common, SPECTRAL_SCAN, "Magnitude mismatch !\n");
|
|
ret = -1;
|
|
}
|
|
|
|
/* DC value (value in the middle) is the blind spot of the spectral
|
|
* sample and invalid, interpolate it.
|
|
*/
|
|
fft_sample_40.data[dc_pos] = (fft_sample_40.data[dc_pos + 1] +
|
|
fft_sample_40.data[dc_pos - 1]) / 2;
|
|
|
|
/* Check if the maximum magnitudes are indeed maximum,
|
|
* also if the maximum value was at dc_pos, calculate
|
|
* a new one (since value at dc_pos is invalid).
|
|
*/
|
|
if (lower_max_index == dc_pos) {
|
|
tmp_mag = 0;
|
|
for (i = 0; i < dc_pos; i++) {
|
|
if (fft_sample_40.data[i] > tmp_mag) {
|
|
tmp_mag = fft_sample_40.data[i];
|
|
fft_sample_40.lower_max_index = i;
|
|
}
|
|
}
|
|
|
|
lower_mag = tmp_mag << max_exp;
|
|
fft_sample_40.lower_max_magnitude = __cpu_to_be16(lower_mag);
|
|
|
|
ath_dbg(common, SPECTRAL_SCAN,
|
|
"Calculated new lower max 0x%X at %i\n",
|
|
tmp_mag, fft_sample_40.lower_max_index);
|
|
} else
|
|
for (i = 0; i < dc_pos; i++) {
|
|
if (fft_sample_40.data[i] == (lower_mag >> max_exp))
|
|
ath_dbg(common, SPECTRAL_SCAN,
|
|
"Got lower mag: 0x%X at index %i\n",
|
|
fft_sample_40.data[i], i);
|
|
|
|
if (fft_sample_40.data[i] > (lower_mag >> max_exp)) {
|
|
ath_dbg(common, SPECTRAL_SCAN,
|
|
"Got lower bin %i higher than max: 0x%X\n",
|
|
i, fft_sample_40.data[i]);
|
|
ret = -1;
|
|
}
|
|
}
|
|
|
|
if (upper_max_index == dc_pos) {
|
|
tmp_mag = 0;
|
|
for (i = dc_pos; i < SPECTRAL_HT20_40_NUM_BINS; i++) {
|
|
if (fft_sample_40.data[i] > tmp_mag) {
|
|
tmp_mag = fft_sample_40.data[i];
|
|
fft_sample_40.upper_max_index = i;
|
|
}
|
|
}
|
|
upper_mag = tmp_mag << max_exp;
|
|
fft_sample_40.upper_max_magnitude = __cpu_to_be16(upper_mag);
|
|
|
|
ath_dbg(common, SPECTRAL_SCAN,
|
|
"Calculated new upper max 0x%X at %i\n",
|
|
tmp_mag, fft_sample_40.upper_max_index);
|
|
} else
|
|
for (i = dc_pos; i < SPECTRAL_HT20_40_NUM_BINS; i++) {
|
|
if (fft_sample_40.data[i] == (upper_mag >> max_exp))
|
|
ath_dbg(common, SPECTRAL_SCAN,
|
|
"Got upper mag: 0x%X at index %i\n",
|
|
fft_sample_40.data[i], i);
|
|
|
|
if (fft_sample_40.data[i] > (upper_mag >> max_exp)) {
|
|
ath_dbg(common, SPECTRAL_SCAN,
|
|
"Got upper bin %i higher than max: 0x%X\n",
|
|
i, fft_sample_40.data[i]);
|
|
|
|
ret = -1;
|
|
}
|
|
}
|
|
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
tlv = (struct fft_sample_tlv *)&fft_sample_40;
|
|
|
|
ath_debug_send_fft_sample(spec_priv, tlv);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static inline void
|
|
ath_cmn_copy_fft_frame(u8 *in, u8 *out, int sample_len, int sample_bytes)
|
|
{
|
|
switch (sample_bytes - sample_len) {
|
|
case -1:
|
|
/* First byte missing */
|
|
memcpy(&out[1], in,
|
|
sample_len - 1);
|
|
break;
|
|
case 0:
|
|
/* Length correct, nothing to do. */
|
|
memcpy(out, in, sample_len);
|
|
break;
|
|
case 1:
|
|
/* MAC added 2 extra bytes AND first byte
|
|
* is missing.
|
|
*/
|
|
memcpy(&out[1], in, 30);
|
|
out[31] = in[31];
|
|
memcpy(&out[32], &in[33],
|
|
sample_len - 32);
|
|
break;
|
|
case 2:
|
|
/* MAC added 2 extra bytes at bin 30 and 32,
|
|
* remove them.
|
|
*/
|
|
memcpy(out, in, 30);
|
|
out[30] = in[31];
|
|
memcpy(&out[31], &in[33],
|
|
sample_len - 31);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
static int
|
|
ath_cmn_is_fft_buf_full(struct ath_spec_scan_priv *spec_priv)
|
|
{
|
|
int i = 0;
|
|
int ret = 0;
|
|
struct rchan *rc = spec_priv->rfs_chan_spec_scan;
|
|
|
|
for_each_online_cpu(i)
|
|
ret += relay_buf_full(rc->buf[i]);
|
|
|
|
i = num_online_cpus();
|
|
|
|
if (ret == i)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
/* returns 1 if this was a spectral frame, even if not handled. */
|
|
int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr,
|
|
struct ath_rx_status *rs, u64 tsf)
|
|
{
|
|
u8 sample_buf[SPECTRAL_SAMPLE_MAX_LEN] = {0};
|
|
struct ath_hw *ah = spec_priv->ah;
|
|
struct ath_common *common = ath9k_hw_common(spec_priv->ah);
|
|
u8 num_bins, *vdata = (u8 *)hdr;
|
|
struct ath_radar_info *radar_info;
|
|
int len = rs->rs_datalen;
|
|
int i;
|
|
int got_slen = 0;
|
|
u8 *sample_start;
|
|
int sample_bytes = 0;
|
|
int ret = 0;
|
|
u16 fft_len, sample_len, freq = ah->curchan->chan->center_freq;
|
|
enum nl80211_channel_type chan_type;
|
|
ath_cmn_fft_idx_validator *fft_idx_validator;
|
|
ath_cmn_fft_sample_handler *fft_handler;
|
|
|
|
/* AR9280 and before report via ATH9K_PHYERR_RADAR, AR93xx and newer
|
|
* via ATH9K_PHYERR_SPECTRAL. Haven't seen ATH9K_PHYERR_FALSE_RADAR_EXT
|
|
* yet, but this is supposed to be possible as well.
|
|
*/
|
|
if (rs->rs_phyerr != ATH9K_PHYERR_RADAR &&
|
|
rs->rs_phyerr != ATH9K_PHYERR_FALSE_RADAR_EXT &&
|
|
rs->rs_phyerr != ATH9K_PHYERR_SPECTRAL)
|
|
return 0;
|
|
|
|
/* check if spectral scan bit is set. This does not have to be checked
|
|
* if received through a SPECTRAL phy error, but shouldn't hurt.
|
|
*/
|
|
radar_info = ((struct ath_radar_info *)&vdata[len]) - 1;
|
|
if (!(radar_info->pulse_bw_info & SPECTRAL_SCAN_BITMASK))
|
|
return 0;
|
|
|
|
if (!spec_priv->rfs_chan_spec_scan)
|
|
return 1;
|
|
|
|
/* Output buffers are full, no need to process anything
|
|
* since there is no space to put the result anyway
|
|
*/
|
|
ret = ath_cmn_is_fft_buf_full(spec_priv);
|
|
if (ret == 1) {
|
|
ath_dbg(common, SPECTRAL_SCAN, "FFT report ignored, no space "
|
|
"left on output buffers\n");
|
|
return 1;
|
|
}
|
|
|
|
chan_type = cfg80211_get_chandef_type(&common->hw->conf.chandef);
|
|
if ((chan_type == NL80211_CHAN_HT40MINUS) ||
|
|
(chan_type == NL80211_CHAN_HT40PLUS)) {
|
|
fft_len = SPECTRAL_HT20_40_TOTAL_DATA_LEN;
|
|
sample_len = SPECTRAL_HT20_40_SAMPLE_LEN;
|
|
num_bins = SPECTRAL_HT20_40_NUM_BINS;
|
|
fft_idx_validator = &ath_cmn_max_idx_verify_ht20_40_fft;
|
|
fft_handler = &ath_cmn_process_ht20_40_fft;
|
|
} else {
|
|
fft_len = SPECTRAL_HT20_TOTAL_DATA_LEN;
|
|
sample_len = SPECTRAL_HT20_SAMPLE_LEN;
|
|
num_bins = SPECTRAL_HT20_NUM_BINS;
|
|
fft_idx_validator = ath_cmn_max_idx_verify_ht20_fft;
|
|
fft_handler = &ath_cmn_process_ht20_fft;
|
|
}
|
|
|
|
ath_dbg(common, SPECTRAL_SCAN, "Got radar dump bw_info: 0x%X,"
|
|
"len: %i fft_len: %i\n",
|
|
radar_info->pulse_bw_info,
|
|
len,
|
|
fft_len);
|
|
sample_start = vdata;
|
|
for (i = 0; i < len - 2; i++) {
|
|
sample_bytes++;
|
|
|
|
/* Only a single sample received, no need to look
|
|
* for the sample's end, do the correction based
|
|
* on the packet's length instead. Note that hw
|
|
* will always put the radar_info structure on
|
|
* the end.
|
|
*/
|
|
if (len <= fft_len + 2) {
|
|
sample_bytes = len - sizeof(struct ath_radar_info);
|
|
got_slen = 1;
|
|
}
|
|
|
|
/* Search for the end of the FFT frame between
|
|
* sample_len - 1 and sample_len + 2. exp_max is 3
|
|
* bits long and it's the only value on the last
|
|
* byte of the frame so since it'll be smaller than
|
|
* the next byte (the first bin of the next sample)
|
|
* 90% of the time, we can use it as a separator.
|
|
*/
|
|
if (vdata[i] <= 0x7 && sample_bytes >= sample_len - 1) {
|
|
|
|
/* Got a frame length within boundaries, there are
|
|
* four scenarios here:
|
|
*
|
|
* a) sample_len -> We got the correct length
|
|
* b) sample_len + 2 -> 2 bytes added around bin[31]
|
|
* c) sample_len - 1 -> The first byte is missing
|
|
* d) sample_len + 1 -> b + c at the same time
|
|
*
|
|
* When MAC adds 2 extra bytes, bin[31] and bin[32]
|
|
* have the same value, so we can use that for further
|
|
* verification in cases b and d.
|
|
*/
|
|
|
|
/* Did we go too far ? If so we couldn't determine
|
|
* this sample's boundaries, discard any further
|
|
* data
|
|
*/
|
|
if ((sample_bytes > sample_len + 2) ||
|
|
((sample_bytes > sample_len) &&
|
|
(sample_start[31] != sample_start[32])))
|
|
break;
|
|
|
|
/* See if we got a valid frame by checking the
|
|
* consistency of mag_info fields. This is to
|
|
* prevent from "fixing" a correct frame.
|
|
* Failure is non-fatal, later frames may
|
|
* be valid.
|
|
*/
|
|
if (!fft_idx_validator(&vdata[i], i)) {
|
|
ath_dbg(common, SPECTRAL_SCAN,
|
|
"Found valid fft frame at %i\n", i);
|
|
got_slen = 1;
|
|
}
|
|
|
|
/* We expect 1 - 2 more bytes */
|
|
else if ((sample_start[31] == sample_start[32]) &&
|
|
(sample_bytes >= sample_len) &&
|
|
(sample_bytes < sample_len + 2) &&
|
|
(vdata[i + 1] <= 0x7))
|
|
continue;
|
|
|
|
/* Try to distinguish cases a and c */
|
|
else if ((sample_bytes == sample_len - 1) &&
|
|
(vdata[i + 1] <= 0x7))
|
|
continue;
|
|
|
|
got_slen = 1;
|
|
}
|
|
|
|
if (got_slen) {
|
|
ath_dbg(common, SPECTRAL_SCAN, "FFT frame len: %i\n",
|
|
sample_bytes);
|
|
|
|
/* Only try to fix a frame if it's the only one
|
|
* on the report, else just skip it.
|
|
*/
|
|
if (sample_bytes != sample_len && len <= fft_len + 2) {
|
|
ath_cmn_copy_fft_frame(sample_start,
|
|
sample_buf, sample_len,
|
|
sample_bytes);
|
|
|
|
fft_handler(rs, spec_priv, sample_buf,
|
|
tsf, freq, chan_type);
|
|
|
|
memset(sample_buf, 0, SPECTRAL_SAMPLE_MAX_LEN);
|
|
|
|
/* Mix the received bins to the /dev/random
|
|
* pool
|
|
*/
|
|
add_device_randomness(sample_buf, num_bins);
|
|
}
|
|
|
|
/* Process a normal frame */
|
|
if (sample_bytes == sample_len) {
|
|
ret = fft_handler(rs, spec_priv, sample_start,
|
|
tsf, freq, chan_type);
|
|
|
|
/* Mix the received bins to the /dev/random
|
|
* pool
|
|
*/
|
|
add_device_randomness(sample_start, num_bins);
|
|
}
|
|
|
|
/* Short report processed, break out of the
|
|
* loop.
|
|
*/
|
|
if (len <= fft_len + 2)
|
|
break;
|
|
|
|
sample_start = &vdata[i + 1];
|
|
|
|
/* -1 to grab sample_len -1, -2 since
|
|
* they 'll get increased by one. In case
|
|
* of failure try to recover by going byte
|
|
* by byte instead.
|
|
*/
|
|
if (ret == 0) {
|
|
i += num_bins - 2;
|
|
sample_bytes = num_bins - 2;
|
|
}
|
|
got_slen = 0;
|
|
}
|
|
}
|
|
|
|
i -= num_bins - 2;
|
|
if (len - i != sizeof(struct ath_radar_info))
|
|
ath_dbg(common, SPECTRAL_SCAN, "FFT report truncated"
|
|
"(bytes left: %i)\n",
|
|
len - i);
|
|
return 1;
|
|
}
|
|
EXPORT_SYMBOL(ath_cmn_process_fft);
|
|
|
|
/*********************/
|
|
/* spectral_scan_ctl */
|
|
/*********************/
|
|
|
|
static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ath_spec_scan_priv *spec_priv = file->private_data;
|
|
char *mode = "";
|
|
unsigned int len;
|
|
|
|
switch (spec_priv->spectral_mode) {
|
|
case SPECTRAL_DISABLED:
|
|
mode = "disable";
|
|
break;
|
|
case SPECTRAL_BACKGROUND:
|
|
mode = "background";
|
|
break;
|
|
case SPECTRAL_CHANSCAN:
|
|
mode = "chanscan";
|
|
break;
|
|
case SPECTRAL_MANUAL:
|
|
mode = "manual";
|
|
break;
|
|
}
|
|
len = strlen(mode);
|
|
return simple_read_from_buffer(user_buf, count, ppos, mode, len);
|
|
}
|
|
|
|
void ath9k_cmn_spectral_scan_trigger(struct ath_common *common,
|
|
struct ath_spec_scan_priv *spec_priv)
|
|
{
|
|
struct ath_hw *ah = spec_priv->ah;
|
|
u32 rxfilter;
|
|
|
|
if (IS_ENABLED(CONFIG_ATH9K_TX99))
|
|
return;
|
|
|
|
if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
|
|
ath_err(common, "spectrum analyzer not implemented on this hardware\n");
|
|
return;
|
|
}
|
|
|
|
ath_ps_ops(common)->wakeup(common);
|
|
rxfilter = ath9k_hw_getrxfilter(ah);
|
|
ath9k_hw_setrxfilter(ah, rxfilter |
|
|
ATH9K_RX_FILTER_PHYRADAR |
|
|
ATH9K_RX_FILTER_PHYERR);
|
|
|
|
/* TODO: usually this should not be neccesary, but for some reason
|
|
* (or in some mode?) the trigger must be called after the
|
|
* configuration, otherwise the register will have its values reset
|
|
* (on my ar9220 to value 0x01002310)
|
|
*/
|
|
ath9k_cmn_spectral_scan_config(common, spec_priv, spec_priv->spectral_mode);
|
|
ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
|
|
ath_ps_ops(common)->restore(common);
|
|
}
|
|
EXPORT_SYMBOL(ath9k_cmn_spectral_scan_trigger);
|
|
|
|
int ath9k_cmn_spectral_scan_config(struct ath_common *common,
|
|
struct ath_spec_scan_priv *spec_priv,
|
|
enum spectral_mode spectral_mode)
|
|
{
|
|
struct ath_hw *ah = spec_priv->ah;
|
|
|
|
if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
|
|
ath_err(common, "spectrum analyzer not implemented on this hardware\n");
|
|
return -1;
|
|
}
|
|
|
|
switch (spectral_mode) {
|
|
case SPECTRAL_DISABLED:
|
|
spec_priv->spec_config.enabled = 0;
|
|
break;
|
|
case SPECTRAL_BACKGROUND:
|
|
/* send endless samples.
|
|
* TODO: is this really useful for "background"?
|
|
*/
|
|
spec_priv->spec_config.endless = 1;
|
|
spec_priv->spec_config.enabled = 1;
|
|
break;
|
|
case SPECTRAL_CHANSCAN:
|
|
case SPECTRAL_MANUAL:
|
|
spec_priv->spec_config.endless = 0;
|
|
spec_priv->spec_config.enabled = 1;
|
|
break;
|
|
default:
|
|
return -1;
|
|
}
|
|
|
|
ath_ps_ops(common)->wakeup(common);
|
|
ath9k_hw_ops(ah)->spectral_scan_config(ah, &spec_priv->spec_config);
|
|
ath_ps_ops(common)->restore(common);
|
|
|
|
spec_priv->spectral_mode = spectral_mode;
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(ath9k_cmn_spectral_scan_config);
|
|
|
|
static ssize_t write_file_spec_scan_ctl(struct file *file,
|
|
const char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ath_spec_scan_priv *spec_priv = file->private_data;
|
|
struct ath_common *common = ath9k_hw_common(spec_priv->ah);
|
|
char buf[32];
|
|
ssize_t len;
|
|
|
|
if (IS_ENABLED(CONFIG_ATH9K_TX99))
|
|
return -EOPNOTSUPP;
|
|
|
|
len = min(count, sizeof(buf) - 1);
|
|
if (copy_from_user(buf, user_buf, len))
|
|
return -EFAULT;
|
|
|
|
buf[len] = '\0';
|
|
|
|
if (strncmp("trigger", buf, 7) == 0) {
|
|
ath9k_cmn_spectral_scan_trigger(common, spec_priv);
|
|
} else if (strncmp("background", buf, 10) == 0) {
|
|
ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_BACKGROUND);
|
|
ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
|
|
} else if (strncmp("chanscan", buf, 8) == 0) {
|
|
ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_CHANSCAN);
|
|
ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
|
|
} else if (strncmp("manual", buf, 6) == 0) {
|
|
ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_MANUAL);
|
|
ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
|
|
} else if (strncmp("disable", buf, 7) == 0) {
|
|
ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_DISABLED);
|
|
ath_dbg(common, CONFIG, "spectral scan: disabled\n");
|
|
} else {
|
|
return -EINVAL;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
static const struct file_operations fops_spec_scan_ctl = {
|
|
.read = read_file_spec_scan_ctl,
|
|
.write = write_file_spec_scan_ctl,
|
|
.open = simple_open,
|
|
.owner = THIS_MODULE,
|
|
.llseek = default_llseek,
|
|
};
|
|
|
|
/*************************/
|
|
/* spectral_short_repeat */
|
|
/*************************/
|
|
|
|
static ssize_t read_file_spectral_short_repeat(struct file *file,
|
|
char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ath_spec_scan_priv *spec_priv = file->private_data;
|
|
char buf[32];
|
|
unsigned int len;
|
|
|
|
len = sprintf(buf, "%d\n", spec_priv->spec_config.short_repeat);
|
|
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
|
|
}
|
|
|
|
static ssize_t write_file_spectral_short_repeat(struct file *file,
|
|
const char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ath_spec_scan_priv *spec_priv = file->private_data;
|
|
unsigned long val;
|
|
char buf[32];
|
|
ssize_t len;
|
|
|
|
len = min(count, sizeof(buf) - 1);
|
|
if (copy_from_user(buf, user_buf, len))
|
|
return -EFAULT;
|
|
|
|
buf[len] = '\0';
|
|
if (kstrtoul(buf, 0, &val))
|
|
return -EINVAL;
|
|
|
|
if (val > 1)
|
|
return -EINVAL;
|
|
|
|
spec_priv->spec_config.short_repeat = val;
|
|
return count;
|
|
}
|
|
|
|
static const struct file_operations fops_spectral_short_repeat = {
|
|
.read = read_file_spectral_short_repeat,
|
|
.write = write_file_spectral_short_repeat,
|
|
.open = simple_open,
|
|
.owner = THIS_MODULE,
|
|
.llseek = default_llseek,
|
|
};
|
|
|
|
/******************/
|
|
/* spectral_count */
|
|
/******************/
|
|
|
|
static ssize_t read_file_spectral_count(struct file *file,
|
|
char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ath_spec_scan_priv *spec_priv = file->private_data;
|
|
char buf[32];
|
|
unsigned int len;
|
|
|
|
len = sprintf(buf, "%d\n", spec_priv->spec_config.count);
|
|
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
|
|
}
|
|
|
|
static ssize_t write_file_spectral_count(struct file *file,
|
|
const char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ath_spec_scan_priv *spec_priv = file->private_data;
|
|
unsigned long val;
|
|
char buf[32];
|
|
ssize_t len;
|
|
|
|
len = min(count, sizeof(buf) - 1);
|
|
if (copy_from_user(buf, user_buf, len))
|
|
return -EFAULT;
|
|
|
|
buf[len] = '\0';
|
|
if (kstrtoul(buf, 0, &val))
|
|
return -EINVAL;
|
|
|
|
if (val > 255)
|
|
return -EINVAL;
|
|
|
|
spec_priv->spec_config.count = val;
|
|
return count;
|
|
}
|
|
|
|
static const struct file_operations fops_spectral_count = {
|
|
.read = read_file_spectral_count,
|
|
.write = write_file_spectral_count,
|
|
.open = simple_open,
|
|
.owner = THIS_MODULE,
|
|
.llseek = default_llseek,
|
|
};
|
|
|
|
/*******************/
|
|
/* spectral_period */
|
|
/*******************/
|
|
|
|
static ssize_t read_file_spectral_period(struct file *file,
|
|
char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ath_spec_scan_priv *spec_priv = file->private_data;
|
|
char buf[32];
|
|
unsigned int len;
|
|
|
|
len = sprintf(buf, "%d\n", spec_priv->spec_config.period);
|
|
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
|
|
}
|
|
|
|
static ssize_t write_file_spectral_period(struct file *file,
|
|
const char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ath_spec_scan_priv *spec_priv = file->private_data;
|
|
unsigned long val;
|
|
char buf[32];
|
|
ssize_t len;
|
|
|
|
len = min(count, sizeof(buf) - 1);
|
|
if (copy_from_user(buf, user_buf, len))
|
|
return -EFAULT;
|
|
|
|
buf[len] = '\0';
|
|
if (kstrtoul(buf, 0, &val))
|
|
return -EINVAL;
|
|
|
|
if (val > 255)
|
|
return -EINVAL;
|
|
|
|
spec_priv->spec_config.period = val;
|
|
return count;
|
|
}
|
|
|
|
static const struct file_operations fops_spectral_period = {
|
|
.read = read_file_spectral_period,
|
|
.write = write_file_spectral_period,
|
|
.open = simple_open,
|
|
.owner = THIS_MODULE,
|
|
.llseek = default_llseek,
|
|
};
|
|
|
|
/***********************/
|
|
/* spectral_fft_period */
|
|
/***********************/
|
|
|
|
static ssize_t read_file_spectral_fft_period(struct file *file,
|
|
char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ath_spec_scan_priv *spec_priv = file->private_data;
|
|
char buf[32];
|
|
unsigned int len;
|
|
|
|
len = sprintf(buf, "%d\n", spec_priv->spec_config.fft_period);
|
|
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
|
|
}
|
|
|
|
static ssize_t write_file_spectral_fft_period(struct file *file,
|
|
const char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ath_spec_scan_priv *spec_priv = file->private_data;
|
|
unsigned long val;
|
|
char buf[32];
|
|
ssize_t len;
|
|
|
|
len = min(count, sizeof(buf) - 1);
|
|
if (copy_from_user(buf, user_buf, len))
|
|
return -EFAULT;
|
|
|
|
buf[len] = '\0';
|
|
if (kstrtoul(buf, 0, &val))
|
|
return -EINVAL;
|
|
|
|
if (val > 15)
|
|
return -EINVAL;
|
|
|
|
spec_priv->spec_config.fft_period = val;
|
|
return count;
|
|
}
|
|
|
|
static const struct file_operations fops_spectral_fft_period = {
|
|
.read = read_file_spectral_fft_period,
|
|
.write = write_file_spectral_fft_period,
|
|
.open = simple_open,
|
|
.owner = THIS_MODULE,
|
|
.llseek = default_llseek,
|
|
};
|
|
|
|
/*******************/
|
|
/* Relay interface */
|
|
/*******************/
|
|
|
|
static struct dentry *create_buf_file_handler(const char *filename,
|
|
struct dentry *parent,
|
|
umode_t mode,
|
|
struct rchan_buf *buf,
|
|
int *is_global)
|
|
{
|
|
struct dentry *buf_file;
|
|
|
|
buf_file = debugfs_create_file(filename, mode, parent, buf,
|
|
&relay_file_operations);
|
|
*is_global = 1;
|
|
return buf_file;
|
|
}
|
|
|
|
static int remove_buf_file_handler(struct dentry *dentry)
|
|
{
|
|
debugfs_remove(dentry);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct rchan_callbacks rfs_spec_scan_cb = {
|
|
.create_buf_file = create_buf_file_handler,
|
|
.remove_buf_file = remove_buf_file_handler,
|
|
};
|
|
|
|
/*********************/
|
|
/* Debug Init/Deinit */
|
|
/*********************/
|
|
|
|
void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv)
|
|
{
|
|
if (IS_ENABLED(CONFIG_ATH9K_DEBUGFS) && spec_priv->rfs_chan_spec_scan) {
|
|
relay_close(spec_priv->rfs_chan_spec_scan);
|
|
spec_priv->rfs_chan_spec_scan = NULL;
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(ath9k_cmn_spectral_deinit_debug);
|
|
|
|
void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv,
|
|
struct dentry *debugfs_phy)
|
|
{
|
|
spec_priv->rfs_chan_spec_scan = relay_open("spectral_scan",
|
|
debugfs_phy,
|
|
1024, 256, &rfs_spec_scan_cb,
|
|
NULL);
|
|
if (!spec_priv->rfs_chan_spec_scan)
|
|
return;
|
|
|
|
debugfs_create_file("spectral_scan_ctl",
|
|
S_IRUSR | S_IWUSR,
|
|
debugfs_phy, spec_priv,
|
|
&fops_spec_scan_ctl);
|
|
debugfs_create_file("spectral_short_repeat",
|
|
S_IRUSR | S_IWUSR,
|
|
debugfs_phy, spec_priv,
|
|
&fops_spectral_short_repeat);
|
|
debugfs_create_file("spectral_count",
|
|
S_IRUSR | S_IWUSR,
|
|
debugfs_phy, spec_priv,
|
|
&fops_spectral_count);
|
|
debugfs_create_file("spectral_period",
|
|
S_IRUSR | S_IWUSR,
|
|
debugfs_phy, spec_priv,
|
|
&fops_spectral_period);
|
|
debugfs_create_file("spectral_fft_period",
|
|
S_IRUSR | S_IWUSR,
|
|
debugfs_phy, spec_priv,
|
|
&fops_spectral_fft_period);
|
|
}
|
|
EXPORT_SYMBOL(ath9k_cmn_spectral_init_debug);
|