* [PATCH wireless-next v5 1/4] dt-bindings: net: wireless: Add AIC8800D80 SDIO Wi-Fi
2026-11-16 7:23 [PATCH wireless-next v5 0/4] wifi: aic: Add AIC8800D80 and D80N SDIO FullMAC driver Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 3/4] wifi: aic: Add the AIC8800D80 and D80N " Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 2/4] wifi: aic: Add firmware protocol and SDIO chip support Yanli Yang
@ 2026-11-16 7:23 ` Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 4/4] wifi: aic: Integrate the AIC8800 SDIO driver Yanli Yang
3 siblings, 0 replies; 5+ messages in thread
From: Yanli Yang @ 2026-11-16 7:23 UTC (permalink / raw)
To: linux-wireless
Cc: Johannes Berg, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
devicetree, linux-kernel, Zhirun Liu, Dijia Xu, Chunqiu Liu,
Liheng Wei, yanli.yang
From: Zhirun Liu <zhirunliu@aicsemi.com>
Document the SDIO function used by AIC8800D80 and AIC8800D80N Wi-Fi
and register the aicsemi vendor prefix.
Describe the shared compatible, function number and optional host-wakeup
interrupt and device-wakeup GPIO. Chip selection uses the SDIO vendor
and device IDs. Power supplies and enable sequencing are described on
the MMC host through vmmc-supply and mmc-pwrseq.
Include an example for an SDIO function with both wake-up lines.
Signed-off-by: Chunqiu Liu <chunqiuliu@aicsemi.com>
Signed-off-by: Zhirun Liu <zhirunliu@aicsemi.com>
Signed-off-by: Yanli Yang <yanli.yang@bedmex.com>
---
.../net/wireless/aicsemi,aic8800d80-fmac.yaml | 78 +++++++++++++++++++
.../devicetree/bindings/vendor-prefixes.yaml | 2 +
2 files changed, 80 insertions(+)
create mode 100644 Documentation/devicetree/bindings/net/wireless/aicsemi,aic8800d80-fmac.yaml
diff --git a/Documentation/devicetree/bindings/net/wireless/aicsemi,aic8800d80-fmac.yaml b/Documentation/devicetree/bindings/net/wireless/aicsemi,aic8800d80-fmac.yaml
new file mode 100644
index 000000000000..f9ad3cd6e07c
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/wireless/aicsemi,aic8800d80-fmac.yaml
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/wireless/aicsemi,aic8800d80-fmac.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: AICSemi AIC8800D80 and AIC8800D80N SDIO Wi-Fi
+
+maintainers:
+ - Zhirun Liu <zhirunliu@aicsemi.com>
+ - Dijia Xu <dijiaxu@aicsemi.com>
+ - Chunqiu Liu <chunqiuliu@aicsemi.com>
+
+description:
+ The AIC8800D80 and AIC8800D80N are Wi-Fi and Bluetooth combo chips.
+ Wi-Fi is attached over SDIO and the chip variant is identified through
+ the SDIO vendor and device IDs. Both chips use the aicsemi,aic8800d80-fmac
+ compatible and the same device tree properties defined here.
+ The node describes SDIO function 1 and its optional out-of-band wake-up
+ lines, and is a child of the MMC host controller node. The chip supply
+ and enable line are described on the MMC host controller through
+ vmmc-supply and mmc-pwrseq.
+
+allOf:
+ - $ref: ieee80211.yaml#
+
+properties:
+ compatible:
+ const: aicsemi,aic8800d80-fmac
+
+ reg:
+ description: SDIO function number of the Wi-Fi function
+ const: 1
+
+ interrupts:
+ maxItems: 1
+ description:
+ Interrupt connected to the WIFI_WAKE_HOST pin of the chip, raised by
+ the chip when it has data for a sleeping host and used to wake up the
+ host from system suspend.
+
+ interrupt-names:
+ items:
+ - const: host-wakeup
+
+ device-wakeup-gpios:
+ maxItems: 1
+ description:
+ GPIO connected to the HOST_WAKE_WIFI pin of the chip, asserted while
+ the host needs the chip awake.
+
+required:
+ - compatible
+ - reg
+
+dependencies:
+ interrupt-names: [ interrupts ]
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/gpio/gpio.h>
+ #include <dt-bindings/interrupt-controller/irq.h>
+
+ mmc {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ wifi@1 {
+ compatible = "aicsemi,aic8800d80-fmac";
+ reg = <1>;
+ interrupt-parent = <&gpio1>;
+ interrupts = <18 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "host-wakeup";
+ device-wakeup-gpios = <&gpio1 18 GPIO_ACTIVE_HIGH>;
+ };
+ };
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index 539aa1c89ce7..e7c849197dd3 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -76,6 +76,8 @@ patternProperties:
description: Aeroflex Gaisler AB
"^aesop,.*":
description: AESOP Embedded Forum
+ "^aicsemi,.*":
+ description: AIC Semiconductor Co., Ltd.
"^airoha,.*":
description: Airoha
"^al,.*":
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH wireless-next v5 2/4] wifi: aic: Add firmware protocol and SDIO chip support
2026-11-16 7:23 [PATCH wireless-next v5 0/4] wifi: aic: Add AIC8800D80 and D80N SDIO FullMAC driver Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 3/4] wifi: aic: Add the AIC8800D80 and D80N " Yanli Yang
@ 2026-11-16 7:23 ` Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 1/4] dt-bindings: net: wireless: Add AIC8800D80 SDIO Wi-Fi Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 4/4] wifi: aic: Integrate the AIC8800 SDIO driver Yanli Yang
3 siblings, 0 replies; 5+ messages in thread
From: Yanli Yang @ 2026-11-16 7:23 UTC (permalink / raw)
To: linux-wireless
Cc: Johannes Berg, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
devicetree, linux-kernel, Zhirun Liu, Dijia Xu, Chunqiu Liu,
Liheng Wei, yanli.yang
From: Zhirun Liu <zhirunliu@aicsemi.com>
Add the firmware message definitions, command manager and SDIO transport
for the AIC8800D80 U02 and AIC8800D80N FullMAC Wi-Fi devices.
Keep firmware download, transport setup and chip operations in the
FullMAC driver. Select the chip implementation from the SDIO IDs and
provide separate D80 and D80N firmware boot sequences. D80N U02 and U02C
use chip-initialization, RF-calibration, ROM-patch and patch-table images.
Load firmware and user configuration with request_firmware() from the
aic/aic8800d80/ and aic/aic8800d80n/ directories.
Add SDIO interrupt handling, transmit aggregation, firmware event
dispatch and suspend/resume operations. Keep command and transport state
with the device rather than exporting a separate BSP interface.
The build configuration and remaining FullMAC implementation follow in
the next patch; the parent wireless build is connected only after all
driver sources are present.
Signed-off-by: Chunqiu Liu <chunqiuliu@aicsemi.com>
Signed-off-by: Zhirun Liu <zhirunliu@aicsemi.com>
Signed-off-by: Yanli Yang <yanli.yang@bedmex.com>
---
.../net/wireless/aic/aic8800_fdrv/aic_bus.h | 99 +
.../wireless/aic/aic8800_fdrv/aicwf_bfmer.h | 100 +
.../aic/aic8800_fdrv/aicwf_chip_8800d80.c | 96 +
.../aic/aic8800_fdrv/aicwf_chip_8800d80n.c | 74 +
.../aic/aic8800_fdrv/aicwf_chip_ops.c | 197 ++
.../aic/aic8800_fdrv/aicwf_chip_ops.h | 116 +
.../wireless/aic/aic8800_fdrv/aicwf_cmds.c | 629 ++++
.../wireless/aic/aic8800_fdrv/aicwf_cmds.h | 122 +
.../aic/aic8800_fdrv/aicwf_compat_8800d80.c | 281 ++
.../aic/aic8800_fdrv/aicwf_compat_8800d80.h | 17 +
.../aic/aic8800_fdrv/aicwf_compat_8800d80n.c | 402 +++
.../aic/aic8800_fdrv/aicwf_compat_8800d80n.h | 17 +
.../wireless/aic/aic8800_fdrv/aicwf_config.h | 33 +
.../wireless/aic/aic8800_fdrv/aicwf_defs.h | 657 ++++
.../wireless/aic/aic8800_fdrv/aicwf_events.h | 938 +++++
.../wireless/aic/aic8800_fdrv/aicwf_main.h | 22 +
.../wireless/aic/aic8800_fdrv/aicwf_mesh.h | 39 +
.../aic/aic8800_fdrv/aicwf_mod_params.h | 59 +
.../wireless/aic/aic8800_fdrv/aicwf_msg_rx.c | 1412 ++++++++
.../wireless/aic/aic8800_fdrv/aicwf_msg_rx.h | 12 +
.../wireless/aic/aic8800_fdrv/aicwf_msg_tx.c | 2499 +++++++++++++
.../wireless/aic/aic8800_fdrv/aicwf_msg_tx.h | 201 ++
.../aic/aic8800_fdrv/aicwf_mu_group.h | 163 +
.../aic/aic8800_fdrv/aicwf_platform.c | 1507 ++++++++
.../aic/aic8800_fdrv/aicwf_platform.h | 91 +
.../wireless/aic/aic8800_fdrv/aicwf_radar.h | 289 ++
.../aic/aic8800_fdrv/aicwf_resv_mem.h | 54 +
.../net/wireless/aic/aic8800_fdrv/aicwf_rx.h | 363 ++
.../aic/aic8800_fdrv/aicwf_rx_prealloc.h | 39 +
.../wireless/aic/aic8800_fdrv/aicwf_sdio.c | 2439 +++++++++++++
.../wireless/aic/aic8800_fdrv/aicwf_sdio.h | 280 ++
.../wireless/aic/aic8800_fdrv/aicwf_strs.c | 267 ++
.../wireless/aic/aic8800_fdrv/aicwf_strs.h | 31 +
.../net/wireless/aic/aic8800_fdrv/aicwf_tx.h | 165 +
.../net/wireless/aic/aic8800_fdrv/aicwf_txq.h | 353 ++
.../aic/aic8800_fdrv/aicwf_txq_prealloc.h | 31 +
.../wireless/aic/aic8800_fdrv/aicwf_txrxif.c | 666 ++++
.../wireless/aic/aic8800_fdrv/aicwf_txrxif.h | 161 +
.../wireless/aic/aic8800_fdrv/aicwf_utils.c | 32 +
.../wireless/aic/aic8800_fdrv/aicwf_utils.h | 61 +
.../net/wireless/aic/aic8800_fdrv/hal_desc.h | 359 ++
.../wireless/aic/aic8800_fdrv/ipc_shared.h | 767 ++++
.../net/wireless/aic/aic8800_fdrv/lmac_mac.h | 437 +++
.../net/wireless/aic/aic8800_fdrv/lmac_msg.h | 3092 +++++++++++++++++
.../wireless/aic/aic8800_fdrv/lmac_types.h | 21 +
.../net/wireless/aic/aic8800_fdrv/sdio_host.c | 136 +
.../net/wireless/aic/aic8800_fdrv/sdio_host.h | 43 +
47 files changed, 19869 insertions(+)
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aic_bus.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_bfmer.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_8800d80.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_8800d80n.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_ops.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_ops.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_cmds.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_cmds.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80n.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80n.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_config.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_defs.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_events.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_main.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mesh.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mod_params.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_rx.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_rx.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_tx.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_tx.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mu_group.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_platform.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_platform.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_radar.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_resv_mem.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx_prealloc.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_sdio.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_sdio.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_strs.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_strs.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_tx.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq_prealloc.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txrxif.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txrxif.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_utils.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_utils.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/hal_desc.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/ipc_shared.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/lmac_mac.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/lmac_msg.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/lmac_types.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/sdio_host.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/sdio_host.h
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aic_bus.h b/drivers/net/wireless/aic/aic8800_fdrv/aic_bus.h
new file mode 100644
index 000000000000..8e1e0e3d26ec
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aic_bus.h
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 AIC semiconductor.
+ *
+ * @file aic_bus.h
+ * @brief Common bus abstraction layer for AIC8800 series.
+ *
+ * This header defines the bus-level operations that abstract the
+ * underlying transport (currently SDIO) from the upper driver layers.
+ * The design follows the pattern used by silabs/wfx and broadcom/b43.
+ *
+ * Key principles:
+ * - struct aicwf_bus_ops provides the bus primitives the upper layers
+ * need: start/stop and data/message transmission.
+ * - Upper-layer code accesses the bus only through the ops table and
+ * inline wrappers defined here. It MUST NOT dereference the
+ * bus-private structure (aic_sdio_dev etc.) directly.
+ * - When a new transport (e.g. USB) is added, only the bus_ops
+ * implementation needs to change; upper layers are unaffected.
+ */
+
+#ifndef _AIC_BUS_H_
+#define _AIC_BUS_H_
+
+#include <linux/device.h>
+#include <linux/skbuff.h>
+#include <linux/types.h>
+
+/* Bus operational state */
+enum aicwf_bus_state { BUS_DOWN_ST, BUS_UP_ST };
+
+struct aicwf_bus {
+ struct aic_sdio_dev *sdiodev;
+ struct device *dev;
+ const struct aicwf_bus_ops *ops;
+ enum aicwf_bus_state state;
+ u8 *cmd_buf;
+ struct completion bustx_trgg;
+ struct completion busrx_trgg;
+ struct completion busirq_trgg; // new oob feature
+ struct task_struct *bustx_thread;
+ struct task_struct *busrx_thread;
+ struct task_struct *busirq_thread; // new oob feature
+};
+
+/* ================================================================
+ * Bus-level operation vectors
+ *
+ * Every transport provides one instance of this struct. The
+ * bus-private device pointer is carried inside struct aicwf_bus so
+ * that ops callbacks can retrieve it via bus->sdiodev.
+ * ================================================================
+ */
+
+struct aicwf_bus_ops {
+ /* ----- Lifecycle ----- */
+ int (*start)(struct device *dev);
+ void (*stop)(struct device *dev);
+
+ /* ----- Data / message transmission ----- */
+ int (*txdata)(struct device *dev, struct sk_buff *skb);
+ int (*txmsg)(struct device *dev, u8 *msg, uint len);
+};
+
+/* ================================================================
+ * Inline wrappers – upper layers call these instead of touching
+ * the transport internals.
+ * ================================================================
+ */
+
+static inline int aicwf_bus_start(struct aicwf_bus *bus)
+{
+ return bus->ops->start(bus->dev);
+}
+
+static inline void aicwf_bus_stop(struct aicwf_bus *bus)
+{
+ bus->ops->stop(bus->dev);
+}
+
+static inline int aicwf_bus_txdata(struct aicwf_bus *bus, struct sk_buff *skb)
+{
+ return bus->ops->txdata(bus->dev, skb);
+}
+
+static inline int aicwf_bus_txmsg(struct aicwf_bus *bus, u8 *msg, uint len)
+{
+ return bus->ops->txmsg(bus->dev, msg, len);
+}
+
+/* ================================================================
+ * Bus-level init / deinit (shared across transports)
+ * ================================================================
+ */
+
+int aicwf_bus_init(uint bus_hdrlen, struct device *dev);
+void aicwf_bus_deinit(struct device *dev);
+
+#endif /* _AIC_BUS_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_bfmer.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_bfmer.h
new file mode 100644
index 000000000000..5fcf5a81e86d
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_bfmer.h
@@ -0,0 +1,100 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief VHT Beamformer function definitions
+ *
+ ******************************************************************************
+ */
+
+#ifndef _AICWF_BFMER_H_
+#define _AICWF_BFMER_H_
+
+/*
+ * INCLUDE FILES
+ ******************************************************************************
+ */
+
+#include "aicwf_defs.h"
+
+/*
+ * DEFINES
+ ******************************************************************************
+ */
+
+/// Maximal supported report length (in bytes)
+#define AICWF_BFMER_REPORT_MAX_LEN 2048
+
+/// Size of the allocated report space (twice the maximum report length)
+#define AICWF_BFMER_REPORT_SPACE_SIZE (AICWF_BFMER_REPORT_MAX_LEN * 2)
+
+/*
+ * TYPE DEFINITIONS
+ ******************************************************************************
+ */
+
+/*
+ * Structure used to store a beamforming report.
+ */
+struct aicwf_bfmer_report {
+ dma_addr_t dma_addr; /* Virtual address provided to MAC for
+ * DMA transfer of the Beamforming Report
+ */
+ unsigned int length; /* Report Length */
+ u8 report[1]; /* Report to be used for VHT TX Beamforming */
+};
+
+/*
+ * FUNCTION DECLARATIONS
+ ******************************************************************************
+ */
+
+/*
+ ******************************************************************************
+ * @brief Allocate memory aiming to contains the Beamforming Report received
+ * from a Beamformee capable.
+ * The providing length shall be large enough to contain the VHT Compressed
+ * Beaforming Report and the MU Exclusive part.
+ * It also perform a DMA Mapping providing an address to be provided to the HW
+ * responsible for the DMA transfer of the report.
+ * If successful a struct aicwf_bfmer_report object is allocated, it's address
+ * is stored in aicwf_sta->bfm_report.
+ *
+ * @param[in] aicwf_hw PHY Information
+ * @param[in] aicwf_sta Peer STA Information
+ * @param[in] length Memory size to be allocated
+ *
+ * @return 0 if operation is successful, else -1.
+ ******************************************************************************
+ */
+int aicwf_bfmer_report_add(struct aicwf_hw *aicwf_hw, struct aicwf_sta *aicwf_sta,
+ unsigned int length);
+
+/*
+ ******************************************************************************
+ * @brief Free a previously allocated memory intended to be used for
+ * Beamforming Reports.
+ *
+ * @param[in] aicwf_hw PHY Information
+ * @param[in] aicwf_sta Peer STA Information
+ *
+ ******************************************************************************
+ */
+void aicwf_bfmer_report_del(struct aicwf_hw *aicwf_hw, struct aicwf_sta *aicwf_sta);
+
+#ifdef CONFIG_AICWF_FULLMAC
+/*
+ ******************************************************************************
+ * @brief Parse a Rx VHT-MCS map in order to deduce the maximum number of
+ * Spatial Streams supported by a beamformee.
+ *
+ * @param[in] vht_capa Received VHT Capability field.
+ *
+ ******************************************************************************
+ */
+u8 aicwf_bfmer_get_rx_nss(const struct ieee80211_vht_cap *vht_capa);
+#endif /* CONFIG_AICWF_FULLMAC */
+
+#endif /* _AICWF_BFMER_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_8800d80.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_8800d80.c
new file mode 100644
index 000000000000..d283fe410068
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_8800d80.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2024 AIC semiconductor.
+ *
+ * @file aicwf_chip_8800d80.c
+ * @brief Chip operations for AIC8800D80
+ */
+
+#include <linux/types.h>
+#include <linux/ieee80211.h>
+#include "aicwf_chip_ops.h"
+#include "aicwf_defs.h"
+#include "aicwf_sdio.h"
+#include "aicwf_compat_8800d80.h"
+#include "aicwf_txrxif.h"
+
+static int aic8800d80_init_capa(struct aicwf_hw *aicwf_hw)
+{
+ aicwf_hw->mod_params->sgi80 = true;
+ aicwf_hw->mod_params->use_80 = true;
+ return 0;
+}
+
+static int aic8800d80_userconfig_load(struct aicwf_hw *aicwf_hw)
+{
+ return aicwf_plat_userconfig_load_8800d80(aicwf_hw);
+}
+
+static int aic8800d80_set_rf_config(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_cfm *cfm)
+{
+ return aicwf_set_rf_config_8800d80(aicwf_hw, cfm);
+}
+
+static void aic8800d80_set_rf_calib_cfg(struct mm_set_rf_calib_req *rf_calib_req)
+{
+ rf_calib_req->cal_cfg_24g = 0x0f8f;
+ rf_calib_req->cal_cfg_5g = 0x0f0f;
+}
+
+static u8 aic8800d80_cmd_hdr_checksum(u8 *hdr, int len)
+{
+ return crc8_ponl_107(hdr, 3);
+}
+
+static int aic8800d80_set_stack_start(struct aicwf_hw *aicwf_hw,
+ struct mm_set_stack_start_cfm *cfm)
+{
+ return aicwf_send_set_stack_start_req(aicwf_hw, 1, 0, CO_BIT(5), 0, cfm);
+}
+
+static int aic8800d80_get_userconfig_txpwr_ofst2x(struct aicwf_hw *aicwf_hw,
+ struct txpwr_ofst2x_conf *txpwr_ofst2x)
+{
+ get_userconfig_txpwr_ofst2x_in_fdrv(aicwf_hw, txpwr_ofst2x);
+ return 0;
+}
+
+static int aic8800d80_ic_system_init(struct aicwf_hw *aicwf_hw, struct dbg_mem_read_cfm *cfm)
+{
+ u32 memdata_temp = 0x00000006;
+ int ret;
+
+ ret = aicwf_send_dbg_mem_block_write_req(aicwf_hw, 0x40504084, 4,
+ &memdata_temp);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "[0x40504084] write fail: %d\n", ret);
+ return -1;
+ }
+
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, 0x40504084, cfm);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "[0x40504084] rd fail\n");
+ return -1;
+ }
+ dev_dbg(aicwf_hw->dev, "rd [0x40504084] = %x\n", cfm->memdata);
+ return ret;
+}
+
+/* ========== Ops instances ========== */
+
+const struct aic_chip_ops aic_chip_aic8800d80_ops = {
+ .name = "AIC8800D80",
+ .is_old_ic = false,
+ .limit_by_testmode = true,
+ .use_80_bandwidth = true,
+ .init_capa = aic8800d80_init_capa,
+ .userconfig_load = aic8800d80_userconfig_load,
+ .set_rf_calib_cfg = aic8800d80_set_rf_calib_cfg,
+ .set_rf_config = aic8800d80_set_rf_config,
+ .cmd_hdr_checksum = aic8800d80_cmd_hdr_checksum,
+ .set_stack_start = aic8800d80_set_stack_start,
+ .get_userconfig_txpwr_ofst2x = aic8800d80_get_userconfig_txpwr_ofst2x,
+ .ic_system_init = aic8800d80_ic_system_init,
+ .fw_download = aicwf_fw_download_8800d80,
+};
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_8800d80n.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_8800d80n.c
new file mode 100644
index 000000000000..23d7a620123b
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_8800d80n.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2024 AIC semiconductor.
+ *
+ * @file aicwf_chip_8800d80n.c
+ * @brief Chip operations for AIC8800D80N
+ */
+
+#include <linux/types.h>
+#include <linux/ieee80211.h>
+#include "aicwf_chip_ops.h"
+#include "aicwf_defs.h"
+#include "aicwf_sdio.h"
+#include "aicwf_compat_8800d80n.h"
+#include "aicwf_txrxif.h"
+
+static int aic8800d80n_init_capa(struct aicwf_hw *aicwf_hw)
+{
+ aicwf_hw->mod_params->sgi80 = true;
+ aicwf_hw->mod_params->use_80 = true;
+ return 0;
+}
+
+static int aic8800d80n_userconfig_load(struct aicwf_hw *aicwf_hw)
+{
+ return aicwf_plat_userconfig_load_8800d80n(aicwf_hw);
+}
+
+static int aic8800d80n_set_rf_config(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_cfm *cfm)
+{
+ return aicwf_set_rf_config_8800d80n(aicwf_hw, cfm);
+}
+
+static void aic8800d80n_set_rf_calib_cfg(struct mm_set_rf_calib_req *rf_calib_req)
+{
+ rf_calib_req->cal_cfg_24g = 0x0f8f;
+ rf_calib_req->cal_cfg_5g = 0x0f0f;
+}
+
+static u8 aic8800d80n_cmd_hdr_checksum(u8 *hdr, int len)
+{
+ return crc8_ponl_107(hdr, 3);
+}
+
+static int aic8800d80n_set_stack_start(struct aicwf_hw *aicwf_hw,
+ struct mm_set_stack_start_cfm *cfm)
+{
+ return aicwf_send_set_stack_start_req(aicwf_hw, 1, 0, CO_BIT(5), 0, cfm);
+}
+
+static int aic8800d80n_get_userconfig_txpwr_ofst2x(struct aicwf_hw *aicwf_hw,
+ struct txpwr_ofst2x_conf *txpwr_ofst2x)
+{
+ get_userconfig_txpwr_ofst2x_in_fdrv(aicwf_hw, txpwr_ofst2x);
+ return 0;
+}
+
+/* ========== Ops instances ========== */
+
+const struct aic_chip_ops aic_chip_aic8800d80n_ops = {
+ .name = "AIC8800D80N",
+ .is_old_ic = false,
+ .limit_by_testmode = true,
+ .use_80_bandwidth = true,
+ .init_capa = aic8800d80n_init_capa,
+ .userconfig_load = aic8800d80n_userconfig_load,
+ .set_rf_calib_cfg = aic8800d80n_set_rf_calib_cfg,
+ .set_rf_config = aic8800d80n_set_rf_config,
+ .cmd_hdr_checksum = aic8800d80n_cmd_hdr_checksum,
+ .set_stack_start = aic8800d80n_set_stack_start,
+ .get_userconfig_txpwr_ofst2x = aic8800d80n_get_userconfig_txpwr_ofst2x,
+ .fw_download = aicwf_fw_download_8800d80n,
+};
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_ops.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_ops.c
new file mode 100644
index 000000000000..2599b9b75870
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_ops.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2024 AIC semiconductor.
+ *
+ * @file aicwf_chip_ops.c
+ * @brief Wrapper function implementations for chip-specific operations.
+ */
+
+#include <linux/errno.h>
+#include <linux/types.h>
+#include "aicwf_chip_ops.h"
+#include "aicwf_defs.h"
+#include "aicwf_sdio.h"
+#include "lmac_msg.h"
+
+/* ========== SDIO chip properties ========== */
+static const struct aic_sdio_chip_hw aic_sdio_chip_tbl[] = {
+ [PRODUCT_ID_AIC8801] = {
+ .oob_support = false,
+ .use_func2 = true,
+ .use_sdiov3_func = false,
+ .need_flowctrl_mask = true,
+ .use_flowctrl_msg = true,
+ .hdr_cksum = false,
+ .need_func0_intr = false,
+#ifdef CONFIG_AIC8800_AUTO_POWERSAVE
+ .auto_ps_support = false,
+#endif
+ .wakeup_reg_val = 1,
+ .use_hdr_checksum = false,
+ .need_fix_hdr_len = true,
+ .sdio_clock = SDIOWIFI_CLOCK,
+ },
+ [PRODUCT_ID_AIC8800DC] = {
+ .oob_support = true,
+ .use_func2 = true,
+ .use_sdiov3_func = false,
+ .need_flowctrl_mask = true,
+ .use_flowctrl_msg = false,
+ .hdr_cksum = false,
+ .need_func0_intr = false,
+#ifdef CONFIG_AIC8800_AUTO_POWERSAVE
+ .auto_ps_support = false,
+#endif
+ .wakeup_reg_val = 1,
+ .use_hdr_checksum = false,
+ .need_fix_hdr_len = true,
+ .sdio_clock = SDIOWIFI_CLOCK,
+ },
+ [PRODUCT_ID_AIC8800D80] = {
+ .oob_support = true,
+ .use_func2 = false,
+ .use_sdiov3_func = true,
+ .need_flowctrl_mask = false,
+ .use_flowctrl_msg = true,
+ .hdr_cksum = true,
+ .need_func0_intr = true,
+#ifdef CONFIG_AIC8800_AUTO_POWERSAVE
+ .auto_ps_support = true,
+#endif
+ .wakeup_reg_val = 0x11,
+ .use_hdr_checksum = true,
+ .need_fix_hdr_len = false,
+ .sdio_clock = SDIOWIFI_CLOCK_V3,
+ },
+ [PRODUCT_ID_AIC8800D80N] = {
+ .oob_support = true,
+ .use_func2 = false,
+ .use_sdiov3_func = true,
+ .need_flowctrl_mask = false,
+ /* commands are sent without polling the flow control register */
+ .use_flowctrl_msg = false,
+ .hdr_cksum = true,
+ .need_func0_intr = true,
+#ifdef CONFIG_AIC8800_AUTO_POWERSAVE
+ .auto_ps_support = true,
+#endif
+ .wakeup_reg_val = 0x11,
+ .use_hdr_checksum = true,
+ .need_fix_hdr_len = false,
+ .sdio_clock = SDIOWIFI_CLOCK_V3,
+ },
+};
+
+int aicwf_sdio_chipmatch(u16 vid, u16 did, u16 *chipid)
+{
+ if (vid == SDIO_VENDOR_ID_AIC8800D80 &&
+ did == SDIO_DEVICE_ID_AIC8800D80) {
+ *chipid = PRODUCT_ID_AIC8800D80;
+ pr_debug("use AIC8800D80\n");
+ return 0;
+ }
+
+ if (vid == SDIO_VENDOR_ID_AIC8800D80N &&
+ (did == SDIO_DEVICE_ID_AIC8800D80N ||
+ did == SDIO_DEVICE_ID_AIC8800D80LN ||
+ did == SDIO_DEVICE_ID_AIC8800D40N ||
+ did == SDIO_DEVICE_ID_AIC8800D40LN)) {
+ *chipid = PRODUCT_ID_AIC8800D80N;
+ pr_debug("use AIC8800D80N\n");
+ return 0;
+ }
+
+ return -ENODEV;
+}
+
+const struct aic_sdio_chip_hw *aic_sdio_get_props(u16 chipid)
+{
+ if (chipid < ARRAY_SIZE(aic_sdio_chip_tbl))
+ return &aic_sdio_chip_tbl[chipid];
+ return NULL;
+}
+
+/*========== Chip ops wrappers ========== */
+int aic_chip_init_capa(struct aicwf_hw *aicwf_hw)
+{
+ if (aicwf_hw->chip_ops && aicwf_hw->chip_ops->init_capa)
+ return aicwf_hw->chip_ops->init_capa(aicwf_hw);
+ return 0;
+}
+
+int aic_chip_userconfig_load(struct aicwf_hw *aicwf_hw)
+{
+ if (aicwf_hw->chip_ops && aicwf_hw->chip_ops->userconfig_load)
+ return aicwf_hw->chip_ops->userconfig_load(aicwf_hw);
+ return -1;
+}
+
+void aic_chip_set_rf_calib_cfg(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_req *rf_calib_req)
+{
+ if (aicwf_hw->chip_ops && aicwf_hw->chip_ops->set_rf_calib_cfg)
+ aicwf_hw->chip_ops->set_rf_calib_cfg(rf_calib_req);
+}
+
+int aic_chip_set_rf_config(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_cfm *cfm)
+{
+ if (aicwf_hw->chip_ops && aicwf_hw->chip_ops->set_rf_config)
+ return aicwf_hw->chip_ops->set_rf_config(aicwf_hw, cfm);
+ return -1;
+}
+
+u8 aic_chip_cmd_hdr_checksum(struct aicwf_hw *aicwf_hw, u8 *hdr, int len)
+{
+ if (aicwf_hw->chip_ops && aicwf_hw->chip_ops->cmd_hdr_checksum)
+ return aicwf_hw->chip_ops->cmd_hdr_checksum(hdr, len);
+ return 0x00;
+}
+
+int aic_chip_set_stack_start(struct aicwf_hw *aicwf_hw,
+ struct mm_set_stack_start_cfm *cfm)
+{
+ if (aicwf_hw->chip_ops && aicwf_hw->chip_ops->set_stack_start)
+ return aicwf_hw->chip_ops->set_stack_start(aicwf_hw, cfm);
+ return 0;
+}
+
+int aic_chip_get_userconfig_txpwr_ofst2x(struct aicwf_hw *aicwf_hw,
+ struct txpwr_ofst2x_conf *txpwr_ofst2x)
+{
+ if (aicwf_hw->chip_ops && aicwf_hw->chip_ops->get_userconfig_txpwr_ofst2x)
+ return aicwf_hw->chip_ops->get_userconfig_txpwr_ofst2x(aicwf_hw,
+ txpwr_ofst2x);
+ return 0;
+}
+
+int aic_chip_set_rx_gain(struct aicwf_hw *aicwf_hw, u8 aicwf_rx_gain)
+{
+ if (aicwf_hw->chip_ops && aicwf_hw->chip_ops->set_rx_gain)
+ return aicwf_hw->chip_ops->set_rx_gain(aicwf_hw, aicwf_rx_gain);
+ return 0;
+}
+
+int aic_chip_ic_system_init(struct aicwf_hw *aicwf_hw, struct dbg_mem_read_cfm *cfm)
+{
+ if (aicwf_hw->chip_ops && aicwf_hw->chip_ops->ic_system_init)
+ return aicwf_hw->chip_ops->ic_system_init(aicwf_hw, cfm);
+ return 0;
+}
+
+int aic_chip_fw_download(struct aicwf_hw *aicwf_hw)
+{
+ if (aicwf_hw->chip_ops && aicwf_hw->chip_ops->fw_download)
+ return aicwf_hw->chip_ops->fw_download(aicwf_hw);
+ return -ENODEV;
+}
+
+const struct aic_chip_ops *aic_chip_ops_select(u16 chipid)
+{
+ if (chipid == PRODUCT_ID_AIC8800D80)
+ return &aic_chip_aic8800d80_ops;
+ if (chipid == PRODUCT_ID_AIC8800D80N)
+ return &aic_chip_aic8800d80n_ops;
+
+ return NULL;
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_ops.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_ops.h
new file mode 100644
index 000000000000..88df4a6e4356
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_ops.h
@@ -0,0 +1,116 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 AIC semiconductor.
+ *
+ * @file aicwf_chip_ops.h
+ * @brief Chip-specific operation interfaces for AIC8800 series.
+ */
+#ifndef _AICWF_CHIP_OPS_H_
+#define _AICWF_CHIP_OPS_H_
+
+#include <linux/types.h>
+#include "lmac_types.h"
+#include "lmac_msg.h"
+
+struct aicwf_hw;
+struct mm_set_rf_calib_req;
+struct mm_set_rf_calib_cfm;
+struct mm_set_stack_start_cfm;
+struct aic_sdio_dev;
+
+/* SDIO chip hardware properties */
+struct aic_sdio_chip_hw {
+ bool oob_support;
+ bool use_func2;
+ bool use_sdiov3_func;
+ bool need_flowctrl_mask;
+ bool use_flowctrl_msg;
+ bool hdr_cksum;
+ bool need_func0_intr;
+#ifdef CONFIG_AIC8800_AUTO_POWERSAVE
+ bool auto_ps_support;
+#endif
+ u8 wakeup_reg_val;
+ bool use_hdr_checksum;
+ bool need_fix_hdr_len;
+ u32 sdio_clock;
+};
+
+/*
+ * struct aic_chip_ops - Chip-specific operations
+ *
+ * Each chip variant provides an instance of this struct.
+ * Selected at probe time based on chipid, then used to
+ * eliminate chipid-based if-else branching throughout the driver.
+ */
+struct aic_chip_ops {
+ const char *name;
+
+ const bool is_old_ic;
+
+ const bool limit_by_testmode;
+
+ const bool use_80_bandwidth;
+
+ /* Initialize chip-specific capabilities in mod_params */
+ int (*init_capa)(struct aicwf_hw *aicwf_hw);
+
+ /* Load chip-specific user configuration */
+ int (*userconfig_load)(struct aicwf_hw *aicwf_hw);
+
+ /* Set RF calibration config values (cal_cfg_24g / cal_cfg_5g) */
+ void (*set_rf_calib_cfg)(struct mm_set_rf_calib_req *rf_calib_req);
+
+ /* Chip-specific RF init sequence (txpwr, RF config, etc.) */
+ int (*set_rf_config)(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_cfm *cfm);
+
+ /* Compute checksum for firmware command header */
+ u8 (*cmd_hdr_checksum)(u8 *hdr, int len);
+
+ /* Initialize the FW stack start (params differ per chip) */
+ int (*set_stack_start)(struct aicwf_hw *aicwf_hw,
+ struct mm_set_stack_start_cfm *cfm);
+
+ /* Get userconfig TX power offset values */
+ int (*get_userconfig_txpwr_ofst2x)(struct aicwf_hw *aicwf_hw,
+ struct txpwr_ofst2x_conf *txpwr_ofst2x);
+
+ /* Set RX gain */
+ int (*set_rx_gain)(struct aicwf_hw *aicwf_hw, u8 aicwf_rx_gain);
+
+ int (*ic_system_init)(struct aicwf_hw *aicwf_hw, struct dbg_mem_read_cfm *cfm);
+
+ /* Download and start the firmware from the bootrom */
+ int (*fw_download)(struct aicwf_hw *aicwf_hw);
+};
+
+extern const struct aic_chip_ops aic_chip_aic8800d80_ops;
+extern const struct aic_chip_ops aic_chip_aic8800d80n_ops;
+
+/* Match SDIO vendor/device IDs to a chip product ID */
+int aicwf_sdio_chipmatch(u16 vendor, u16 device, u16 *chipid);
+
+/* Get SDIO hardware properties for a given chip product ID */
+const struct aic_sdio_chip_hw *aic_sdio_get_props(u16 chipid);
+
+/* Select the appropriate chip ops based on chip product ID */
+const struct aic_chip_ops *aic_chip_ops_select(u16 chipid);
+
+/* Wrapper function declarations (implemented in aic_chip_ops.c) */
+int aic_chip_init_capa(struct aicwf_hw *aicwf_hw);
+int aic_chip_userconfig_load(struct aicwf_hw *aicwf_hw);
+void aic_chip_set_rf_calib_cfg(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_req *rf_calib_req);
+int aic_chip_set_rf_config(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_cfm *cfm);
+u8 aic_chip_cmd_hdr_checksum(struct aicwf_hw *aicwf_hw, u8 *hdr, int len);
+int aic_chip_set_stack_start(struct aicwf_hw *aicwf_hw,
+ struct mm_set_stack_start_cfm *cfm);
+int aic_chip_get_userconfig_txpwr_ofst2x(struct aicwf_hw *aicwf_hw,
+ struct txpwr_ofst2x_conf *txpwr_ofst2x);
+int aic_chip_set_rx_gain(struct aicwf_hw *aicwf_hw, u8 aicwf_rx_gain);
+int aic_chip_ic_system_init(struct aicwf_hw *aicwf_hw,
+ struct dbg_mem_read_cfm *cfm);
+int aic_chip_fw_download(struct aicwf_hw *aicwf_hw);
+#endif /* _AICWF_CHIP_OPS_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_cmds.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_cmds.c
new file mode 100644
index 000000000000..a2f30152d030
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_cmds.c
@@ -0,0 +1,629 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief Handles queueing (push to IPC, ack/cfm from IPC) of commands issued to
+ * LMAC FW
+ *
+ ******************************************************************************
+ */
+
+#include "aicwf_cmds.h"
+#include "aicwf_txrxif.h"
+#include "aicwf_defs.h"
+#include "aicwf_events.h"
+#include "aicwf_strs.h"
+#include <linux/list.h>
+#include "aicwf_sdio.h"
+
+static bool cmd_mgr_idle(struct aicwf_cmd_mgr *cmd_mgr)
+{
+ unsigned long flags;
+ bool idle;
+
+ spin_lock_irqsave(&cmd_mgr->pool_lock, flags);
+ idle = !cmd_mgr->users;
+ spin_unlock_irqrestore(&cmd_mgr->pool_lock, flags);
+ return idle;
+}
+
+/* Keep the caller alive through its final SDIO activity release. */
+int aicwf_cmd_mgr_get(struct aicwf_cmd_mgr *cmd_mgr)
+{
+ unsigned long flags;
+ int ret = 0;
+
+ if (!READ_ONCE(cmd_mgr->cmd_wq))
+ return -ESHUTDOWN;
+ spin_lock_bh(&cmd_mgr->lock);
+ if (cmd_mgr->state != AICWF_CMD_MGR_STATE_INITED) {
+ ret = cmd_mgr->state == AICWF_CMD_MGR_STATE_CRASHED ?
+ -EPIPE : -ESHUTDOWN;
+ } else {
+ spin_lock_irqsave(&cmd_mgr->pool_lock, flags);
+ cmd_mgr->users++;
+ spin_unlock_irqrestore(&cmd_mgr->pool_lock, flags);
+ }
+ spin_unlock_bh(&cmd_mgr->lock);
+ return ret;
+}
+
+void aicwf_cmd_mgr_put(struct aicwf_cmd_mgr *cmd_mgr)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&cmd_mgr->pool_lock, flags);
+ cmd_mgr->users--;
+ wake_up_all(&cmd_mgr->users_wait);
+ /* The idle predicate takes this lock before teardown can proceed. */
+ spin_unlock_irqrestore(&cmd_mgr->pool_lock, flags);
+}
+
+static void cmd_dump(const struct aicwf_cmd *cmd)
+{
+ if (!cmd) {
+ pr_debug("cmd is null\n");
+ return;
+ }
+ pr_debug("tkn[%d] flags:%04x result:%3d cmd:%4d-%-24s - reqcfm(%4d-%-s)\n",
+ cmd->tkn, cmd->flags, cmd->result, cmd->id, AICWF_ID2STR(cmd->id),
+ cmd->reqid,
+ cmd->reqid != (lmac_msg_id_t)-1 ? AICWF_ID2STR(cmd->reqid) : "none");
+}
+
+/**
+ * aicwf_cmd_malloc - Take a command from the pool of a command manager
+ * @cmd_mgr: Command manager owning the pool
+ *
+ * Return: A free command, or %NULL if the pool is exhausted.
+ */
+struct aicwf_cmd *aicwf_cmd_malloc(struct aicwf_cmd_mgr *cmd_mgr)
+{
+ struct aicwf_cmd *cmd = NULL;
+ unsigned long flags;
+ int i;
+
+ spin_lock_irqsave(&cmd_mgr->pool_lock, flags);
+ for (i = 0; i < AICWF_CMD_ARRAY_SIZE; i++) {
+ if (!cmd_mgr->pool[i].used) {
+ cmd = &cmd_mgr->pool[i];
+ cmd->used = 1;
+ cmd->flags = 0;
+ cmd_mgr->users++;
+ break;
+ }
+ }
+ spin_unlock_irqrestore(&cmd_mgr->pool_lock, flags);
+
+ if (!cmd) {
+ pr_err_ratelimited("cmd array is full\n");
+ return NULL;
+ }
+
+ if (i >= AICWF_CMD_HIGH_WATER_SIZE)
+ pr_debug("cmd array high watermark reached: %d\n", i);
+
+ return cmd;
+}
+
+/**
+ * aicwf_cmd_free - Return a command to the pool of a command manager
+ * @cmd_mgr: Command manager owning the pool
+ * @cmd: Command obtained from aicwf_cmd_malloc()
+ */
+void aicwf_cmd_free(struct aicwf_cmd_mgr *cmd_mgr, struct aicwf_cmd *cmd)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&cmd_mgr->pool_lock, flags);
+ cmd->used = 0;
+ pr_debug("cmd_array[%d]:%p\n", cmd->array_id, cmd);
+ cmd_mgr->users--;
+ wake_up_all(&cmd_mgr->users_wait);
+ spin_unlock_irqrestore(&cmd_mgr->pool_lock, flags);
+}
+
+static void aicwf_cmd_pool_init(struct aicwf_cmd_mgr *cmd_mgr)
+{
+ int i;
+
+ spin_lock_init(&cmd_mgr->pool_lock);
+ cmd_mgr->users = 0;
+ init_waitqueue_head(&cmd_mgr->users_wait);
+ for (i = 0; i < AICWF_CMD_ARRAY_SIZE; i++) {
+ cmd_mgr->pool[i].used = 0;
+ cmd_mgr->pool[i].array_id = i;
+ }
+}
+
+static void cmd_complete(struct aicwf_cmd_mgr *cmd_mgr, struct aicwf_cmd *cmd,
+ int result)
+{
+ lockdep_assert_held(&cmd_mgr->lock);
+
+ list_del_init(&cmd->list);
+ cmd_mgr->queue_sz--;
+ cmd->flags |= AICWF_CMD_FLAG_DONE;
+ cmd->result = result;
+ cmd->e2a_msg = NULL;
+ cmd->e2a_msg_len = 0;
+ /* The sender or deferred worker still owns the command. */
+ complete(&cmd->complete);
+}
+
+static int cmd_mgr_wait_complete(struct aicwf_cmd_mgr *cmd_mgr,
+ struct aicwf_cmd *cmd)
+{
+ struct aic_sdio_dev *sdiodev =
+ container_of(cmd_mgr, struct aic_sdio_dev, cmd_mgr);
+ unsigned long tout = msecs_to_jiffies(AICWF_80211_CMD_TIMEOUT_MS *
+ max_t(u32, READ_ONCE(cmd_mgr->queue_sz), 1));
+ int ret;
+
+ if (!wait_for_completion_timeout(&cmd->complete, tout)) {
+ dev_err(sdiodev->dev, "cmd timed-out\n");
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.wakeup_reg, 2);
+ if (ret < 0)
+ dev_err(sdiodev->dev, "reg:%d write failed!\n",
+ sdiodev->sdio_reg.wakeup_reg);
+ cmd_dump(cmd);
+ spin_lock_bh(&cmd_mgr->lock);
+ /* A confirmation may have arrived at the timeout boundary. */
+ if (!(cmd->flags & AICWF_CMD_FLAG_DONE)) {
+ if (cmd_mgr->state == AICWF_CMD_MGR_STATE_INITED)
+ cmd_mgr->state = AICWF_CMD_MGR_STATE_CRASHED;
+ cmd_complete(cmd_mgr, cmd, -ETIMEDOUT);
+ }
+ spin_unlock_bh(&cmd_mgr->lock);
+ }
+ return cmd->result;
+}
+
+static int cmd_mgr_wait_deferred(struct aicwf_cmd_mgr *cmd_mgr,
+ struct aicwf_cmd *cmd)
+{
+ int ret;
+
+ /* The worker's bounded CFM wait also covers a deferred caller. */
+ wait_for_completion(&cmd->work_complete);
+ ret = cmd->result;
+ aicwf_cmd_free(cmd_mgr, cmd);
+ return ret;
+}
+
+int cmd_mgr_queue_force_defer(struct aicwf_cmd_mgr *cmd_mgr,
+ struct aicwf_cmd *cmd)
+{
+ struct aic_sdio_dev *sdiodev =
+ container_of(cmd_mgr, struct aic_sdio_dev, cmd_mgr);
+ struct device *dev = sdiodev->dev;
+ bool wait = cmd->e2a_msg;
+ int ret;
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_msg_send(cmd->id);
+#endif
+ spin_lock_bh(&cmd_mgr->lock);
+
+ if (cmd_mgr->state != AICWF_CMD_MGR_STATE_INITED) {
+ ret = cmd_mgr->state == AICWF_CMD_MGR_STATE_CRASHED ?
+ -EPIPE : -ESHUTDOWN;
+ cmd->result = ret;
+ spin_unlock_bh(&cmd_mgr->lock);
+ kfree(cmd->a2e_msg);
+ aicwf_cmd_free(cmd_mgr, cmd);
+ return ret;
+ }
+
+ if (!list_empty(&cmd_mgr->cmds)) {
+ if (cmd_mgr->queue_sz == cmd_mgr->max_queue_sz) {
+ dev_err(dev, "too many cmds %d already queued\n",
+ cmd_mgr->max_queue_sz);
+ cmd->result = -ENOMEM;
+ spin_unlock_bh(&cmd_mgr->lock);
+ kfree(cmd->a2e_msg);
+ aicwf_cmd_free(cmd_mgr, cmd);
+ return -ENOMEM;
+ }
+ }
+
+ cmd->flags |= AICWF_CMD_FLAG_WAIT_PUSH;
+ if (!wait)
+ cmd->flags |= AICWF_CMD_FLAG_NONBLOCK;
+
+ if (cmd->flags & AICWF_CMD_FLAG_REQ_CFM)
+ cmd->flags |= AICWF_CMD_FLAG_WAIT_CFM;
+
+ cmd->tkn = cmd_mgr->next_tkn++;
+ cmd->result = -EINPROGRESS;
+
+ init_completion(&cmd->complete);
+ init_completion(&cmd->work_complete);
+
+ list_add_tail(&cmd->list, &cmd_mgr->cmds);
+ cmd_mgr->queue_sz++;
+ WAKE_CMD_WORK(cmd_mgr);
+ spin_unlock_bh(&cmd_mgr->lock);
+ return wait ? cmd_mgr_wait_deferred(cmd_mgr, cmd) : 0;
+}
+
+static int cmd_mgr_queue(struct aicwf_cmd_mgr *cmd_mgr, struct aicwf_cmd *cmd)
+{
+ int ret;
+ struct aic_sdio_dev *sdiodev =
+ container_of(cmd_mgr, struct aic_sdio_dev, cmd_mgr);
+ bool defer_push = false;
+ bool wait = cmd->e2a_msg;
+
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_msg_send(cmd->id);
+#endif
+ spin_lock_bh(&cmd_mgr->lock);
+
+ if (cmd_mgr->state != AICWF_CMD_MGR_STATE_INITED) {
+ ret = cmd_mgr->state == AICWF_CMD_MGR_STATE_CRASHED ?
+ -EPIPE : -ESHUTDOWN;
+ cmd->result = ret;
+ spin_unlock_bh(&cmd_mgr->lock);
+ kfree(cmd->a2e_msg);
+ aicwf_cmd_free(cmd_mgr, cmd);
+ return ret;
+ }
+
+ if (!list_empty(&cmd_mgr->cmds)) {
+ struct aicwf_cmd *last;
+
+ if (cmd_mgr->queue_sz == cmd_mgr->max_queue_sz) {
+ dev_err(sdiodev->dev, "too many cmds %d already queued\n",
+ cmd_mgr->max_queue_sz);
+ cmd->result = -ENOMEM;
+ spin_unlock_bh(&cmd_mgr->lock);
+ kfree(cmd->a2e_msg);
+ aicwf_cmd_free(cmd_mgr, cmd);
+ return -ENOMEM;
+ }
+ last = list_entry(cmd_mgr->cmds.prev, struct aicwf_cmd, list);
+ if (last->flags & (AICWF_CMD_FLAG_WAIT_ACK | AICWF_CMD_FLAG_WAIT_PUSH |
+ AICWF_CMD_FLAG_WAIT_CFM)) {
+ cmd->flags |= AICWF_CMD_FLAG_WAIT_PUSH;
+ defer_push = true;
+ }
+ }
+
+ if (cmd->flags & AICWF_CMD_FLAG_REQ_CFM)
+ cmd->flags |= AICWF_CMD_FLAG_WAIT_CFM;
+
+ cmd->tkn = cmd_mgr->next_tkn++;
+ cmd->result = -EINPROGRESS;
+
+ init_completion(&cmd->complete);
+ init_completion(&cmd->work_complete);
+
+ list_add_tail(&cmd->list, &cmd_mgr->cmds);
+ cmd_mgr->queue_sz++;
+
+#ifdef CONFIG_AIC8800_ARP_OFFLOAD
+ if (cmd->a2e_msg->id == ME_TRAFFIC_IND_REQ ||
+ cmd->a2e_msg->id == MM_SET_ARPOFFLOAD_REQ) {
+#else
+ if (cmd->a2e_msg->id == ME_TRAFFIC_IND_REQ) {
+#endif
+ defer_push = true;
+ cmd->flags |= AICWF_CMD_FLAG_WAIT_PUSH;
+ }
+
+ if (defer_push) {
+ if (!wait)
+ cmd->flags |= AICWF_CMD_FLAG_NONBLOCK;
+ WAKE_CMD_WORK(cmd_mgr);
+ }
+ spin_unlock_bh(&cmd_mgr->lock);
+ if (defer_push)
+ return wait ? cmd_mgr_wait_deferred(cmd_mgr, cmd) : 0;
+
+ aicwf_set_cmd_tx(sdiodev, cmd->a2e_msg, AICWF_CMD_A2EMSG_LEN(cmd->a2e_msg));
+ kfree(cmd->a2e_msg);
+ cmd->a2e_msg = NULL;
+ ret = cmd_mgr_wait_complete(cmd_mgr, cmd);
+ WAKE_CMD_WORK(cmd_mgr);
+ aicwf_cmd_free(cmd_mgr, cmd);
+ return ret;
+}
+
+static int cmd_mgr_llind(struct aicwf_cmd_mgr *cmd_mgr, struct aicwf_cmd *cmd)
+{
+ struct aic_sdio_dev *sdiodev =
+ container_of(cmd_mgr, struct aic_sdio_dev, cmd_mgr);
+ struct device *dev = sdiodev->dev;
+ struct aicwf_cmd *cur, *acked = NULL;
+
+ spin_lock_bh(&cmd_mgr->lock);
+ list_for_each_entry(cur, &cmd_mgr->cmds, list) {
+ if (!acked) {
+ if (cur->tkn == cmd->tkn) {
+ if (WARN_ON_ONCE(cur != cmd))
+ cmd_dump(cmd);
+ acked = cur;
+ continue;
+ }
+ }
+ if (cur->flags & AICWF_CMD_FLAG_WAIT_PUSH)
+ break;
+ }
+ if (!acked) {
+ dev_err(dev, "error: acked cmd not found\n");
+ } else {
+ cmd->flags &= ~AICWF_CMD_FLAG_WAIT_ACK;
+ if (AICWF_CMD_WAIT_COMPLETE(cmd->flags))
+ cmd_complete(cmd_mgr, cmd, 0);
+ }
+ spin_unlock(&cmd_mgr->lock);
+
+ return 0;
+}
+
+void cmd_mgr_task_process(struct work_struct *work)
+{
+ struct aicwf_cmd_mgr *cmd_mgr =
+ container_of(work, struct aicwf_cmd_mgr, cmd_work);
+ struct aic_sdio_dev *sdiodev =
+ container_of(cmd_mgr, struct aic_sdio_dev, cmd_mgr);
+ struct aicwf_cmd *cur, *next;
+ bool nonblock, send;
+
+ while (1) {
+ next = NULL;
+ spin_lock_bh(&cmd_mgr->lock);
+ list_for_each_entry(cur, &cmd_mgr->cmds, list) {
+ if (cur->flags & AICWF_CMD_FLAG_WAIT_PUSH)
+ next = cur;
+ break;
+ }
+ if (!next) {
+ spin_unlock_bh(&cmd_mgr->lock);
+ break;
+ }
+ /* Claim the request before teardown can cancel a pending entry. */
+ next->flags &= ~AICWF_CMD_FLAG_WAIT_PUSH;
+ nonblock = next->flags & AICWF_CMD_FLAG_NONBLOCK;
+ send = cmd_mgr->state == AICWF_CMD_MGR_STATE_INITED;
+ if (!send)
+ cmd_complete(cmd_mgr, next,
+ cmd_mgr->state == AICWF_CMD_MGR_STATE_CRASHED ?
+ -EPIPE : -ESHUTDOWN);
+ spin_unlock_bh(&cmd_mgr->lock);
+
+ if (send)
+ aicwf_set_cmd_tx(sdiodev, next->a2e_msg,
+ AICWF_CMD_A2EMSG_LEN(next->a2e_msg));
+ kfree(next->a2e_msg);
+ next->a2e_msg = NULL;
+ cmd_mgr_wait_complete(cmd_mgr, next);
+
+ if (nonblock)
+ aicwf_cmd_free(cmd_mgr, next);
+ else
+ /* Last worker access; the caller may now return its CFM. */
+ complete(&next->work_complete);
+ }
+}
+
+static int cmd_mgr_run_callback(struct aicwf_hw *aicwf_hw, struct aicwf_cmd *cmd,
+ struct aicwf_cmd_e2amsg *msg, msg_cb_fct cb)
+{
+ int res;
+
+ if (!cb)
+ return 0;
+
+ res = cb(aicwf_hw, cmd, msg);
+
+ return res;
+}
+
+static int cmd_mgr_msgind(struct aicwf_cmd_mgr *cmd_mgr,
+ struct aicwf_cmd_e2amsg *msg, msg_cb_fct cb)
+{
+ struct aic_sdio_dev *sdiodev =
+ container_of(cmd_mgr, struct aic_sdio_dev, cmd_mgr);
+ struct aicwf_hw *aicwf_hw = sdiodev->aicwf_hw;
+ struct aicwf_cmd *cmd, *pos;
+ bool found = false;
+
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_msg_recv(msg->id);
+#endif
+ if (msg->param_len > AICWF_CMD_E2AMSG_LEN_MAX)
+ return -EMSGSIZE;
+
+ spin_lock_bh(&cmd_mgr->lock);
+ if (cmd_mgr->state == AICWF_CMD_MGR_STATE_STOPPING ||
+ cmd_mgr->state == AICWF_CMD_MGR_STATE_DEINIT) {
+ spin_unlock_bh(&cmd_mgr->lock);
+ return 0;
+ }
+ list_for_each_entry_safe(cmd, pos, &cmd_mgr->cmds, list) {
+ if (cmd->reqid == msg->id &&
+ (cmd->flags & AICWF_CMD_FLAG_WAIT_CFM) &&
+ !(cmd->flags & AICWF_CMD_FLAG_WAIT_PUSH)) {
+ if (cmd->e2a_msg && msg->param_len > cmd->e2a_msg_len) {
+ spin_unlock_bh(&cmd_mgr->lock);
+ dev_err_ratelimited(sdiodev->dev,
+ "oversized confirmation %#x: %u bytes\n",
+ msg->id, msg->param_len);
+ return -EMSGSIZE;
+ }
+
+ if (msg->id == MM_GET_MAC_ADDR_CFM &&
+ msg->param_len < sizeof(struct mm_get_mac_addr_cfm)) {
+ cmd_complete(cmd_mgr, cmd, -EBADMSG);
+ spin_unlock_bh(&cmd_mgr->lock);
+ dev_err_ratelimited(sdiodev->dev,
+ "short MAC address confirmation\n");
+ return -EBADMSG;
+ }
+
+ if (msg->id == MM_GET_FW_VERSION_CFM) {
+ const struct mm_get_fw_version_cfm *cfm =
+ (const void *)msg->param;
+ size_t hdr_len = offsetof(struct mm_get_fw_version_cfm,
+ fw_version);
+
+ if (msg->param_len < hdr_len ||
+ cfm->fw_version_len > sizeof(cfm->fw_version) ||
+ cfm->fw_version_len > msg->param_len - hdr_len) {
+ cmd_complete(cmd_mgr, cmd, -EBADMSG);
+ spin_unlock_bh(&cmd_mgr->lock);
+ dev_err_ratelimited(sdiodev->dev,
+ "invalid firmware version confirmation\n");
+ return -EBADMSG;
+ }
+ }
+
+ if (!cmd_mgr_run_callback(aicwf_hw, cmd, msg, cb)) {
+ found = true;
+ cmd->flags &= ~AICWF_CMD_FLAG_WAIT_CFM;
+ if (cmd->e2a_msg && msg->param_len)
+ memcpy(cmd->e2a_msg, &msg->param, msg->param_len);
+
+ if (AICWF_CMD_WAIT_COMPLETE(cmd->flags))
+ cmd_complete(cmd_mgr, cmd, 0);
+
+ break;
+ }
+ }
+ }
+ spin_unlock_bh(&cmd_mgr->lock);
+
+ if (!found)
+ cmd_mgr_run_callback(aicwf_hw, NULL, msg, cb);
+
+ return 0;
+}
+
+static void cmd_mgr_print(struct aicwf_cmd_mgr *cmd_mgr)
+{
+ struct aicwf_cmd *cur;
+
+ spin_lock_bh(&cmd_mgr->lock);
+ pr_debug("q_sz/max: %2d / %2d - next tkn: %d\n", cmd_mgr->queue_sz,
+ cmd_mgr->max_queue_sz, cmd_mgr->next_tkn);
+ list_for_each_entry(cur, &cmd_mgr->cmds, list) {
+ cmd_dump(cur);
+ }
+ spin_unlock_bh(&cmd_mgr->lock);
+}
+
+static void cmd_mgr_drain(struct aicwf_cmd_mgr *cmd_mgr)
+{
+ struct aicwf_cmd *cur, *nxt;
+ bool pending, nonblock;
+
+ spin_lock_bh(&cmd_mgr->lock);
+ list_for_each_entry_safe(cur, nxt, &cmd_mgr->cmds, list) {
+ pending = cur->flags & AICWF_CMD_FLAG_WAIT_PUSH;
+ nonblock = cur->flags & AICWF_CMD_FLAG_NONBLOCK;
+ if (pending) {
+ kfree(cur->a2e_msg);
+ cur->a2e_msg = NULL;
+ }
+ cmd_complete(cmd_mgr, cur, -ESHUTDOWN);
+ if (!pending)
+ continue;
+ /* No worker owns a request still marked WAIT_PUSH. */
+ if (nonblock)
+ aicwf_cmd_free(cmd_mgr, cur);
+ else
+ complete(&cur->work_complete);
+ }
+ spin_unlock_bh(&cmd_mgr->lock);
+}
+
+int aicwf_cmd_mgr_init(struct aicwf_cmd_mgr *cmd_mgr)
+{
+ struct aic_sdio_dev *sdiodev =
+ container_of(cmd_mgr, struct aic_sdio_dev, cmd_mgr);
+ struct device *dev = sdiodev->dev;
+
+ INIT_LIST_HEAD(&cmd_mgr->cmds);
+ cmd_mgr->state = AICWF_CMD_MGR_STATE_DEINIT;
+ spin_lock_init(&cmd_mgr->lock);
+ aicwf_cmd_pool_init(cmd_mgr);
+ cmd_mgr->max_queue_sz = AICWF_CMD_MAX_QUEUED;
+ cmd_mgr->queue = &cmd_mgr_queue;
+ cmd_mgr->print = &cmd_mgr_print;
+ cmd_mgr->drain = &cmd_mgr_drain;
+ cmd_mgr->llind = &cmd_mgr_llind;
+ cmd_mgr->msgind = &cmd_mgr_msgind;
+
+ INIT_WORK(&cmd_mgr->cmd_work, cmd_mgr_task_process);
+ cmd_mgr->cmd_wq = create_singlethread_workqueue("cmd_wq");
+ if (!cmd_mgr->cmd_wq) {
+ dev_err(dev, "insufficient memory to create cmd workqueue\n");
+ return -ENOMEM;
+ }
+ cmd_mgr->state = AICWF_CMD_MGR_STATE_INITED;
+ return 0;
+}
+
+void aicwf_cmd_mgr_stop(struct aicwf_cmd_mgr *cmd_mgr)
+{
+ struct workqueue_struct *wq = READ_ONCE(cmd_mgr->cmd_wq);
+
+ /* Also covers cleanup before init, and repeated teardown. */
+ if (!wq)
+ return;
+ spin_lock_bh(&cmd_mgr->lock);
+ cmd_mgr->state = AICWF_CMD_MGR_STATE_STOPPING;
+ spin_unlock_bh(&cmd_mgr->lock);
+ cmd_mgr->drain(cmd_mgr);
+ /* A direct sender may still submit or queue work before its last put. */
+ wait_event(cmd_mgr->users_wait, cmd_mgr_idle(cmd_mgr));
+ flush_workqueue(wq);
+}
+
+void aicwf_cmd_mgr_deinit(struct aicwf_cmd_mgr *cmd_mgr)
+{
+ struct workqueue_struct *wq = READ_ONCE(cmd_mgr->cmd_wq);
+
+ if (!wq)
+ return;
+ aicwf_cmd_mgr_stop(cmd_mgr);
+ destroy_workqueue(wq);
+ WRITE_ONCE(cmd_mgr->cmd_wq, NULL);
+ cmd_mgr->state = AICWF_CMD_MGR_STATE_DEINIT;
+}
+
+void aicwf_set_cmd_tx(void *dev, struct lmac_msg *msg, uint len)
+{
+ u8 *buffer = NULL;
+ u16 index = 0;
+ struct aic_sdio_dev *sdiodev = (struct aic_sdio_dev *)dev;
+ struct aicwf_bus *bus = sdiodev->bus_if;
+
+ buffer = bus->cmd_buf;
+
+ memset(buffer, 0, CMD_BUF_MAX);
+ buffer[0] = (len + 4) & 0x00ff;
+ buffer[1] = ((len + 4) >> 8) & 0x0f;
+ buffer[2] = 0x11;
+
+ buffer[3] = aic_chip_cmd_hdr_checksum(sdiodev->aicwf_hw, &buffer[0], 3);
+
+ index += 4;
+ // there is a dummy word
+ index += 4;
+
+ // make sure little endian
+ put_u16(&buffer[index], msg->id);
+ index += 2;
+ put_u16(&buffer[index], msg->dest_id);
+ index += 2;
+ put_u16(&buffer[index], msg->src_id);
+ index += 2;
+ put_u16(&buffer[index], msg->param_len);
+ index += 2;
+ memcpy(&buffer[index], (u8 *)msg->param, msg->param_len);
+
+ aicwf_bus_txmsg(bus, buffer, len + 8);
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_cmds.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_cmds.h
new file mode 100644
index 000000000000..e20a2be918fe
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_cmds.h
@@ -0,0 +1,122 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_CMDS_H_
+#define _AICWF_CMDS_H_
+
+#include "lmac_msg.h"
+#include "ipc_shared.h"
+#include <linux/completion.h>
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/wait.h>
+
+#define AICWF_80211_CMD_TIMEOUT_MS 6000
+
+#define AICWF_CMD_FLAG_NONBLOCK BIT(0)
+#define AICWF_CMD_FLAG_REQ_CFM BIT(1)
+#define AICWF_CMD_FLAG_WAIT_PUSH BIT(2)
+#define AICWF_CMD_FLAG_WAIT_ACK BIT(3)
+#define AICWF_CMD_FLAG_WAIT_CFM BIT(4)
+#define AICWF_CMD_FLAG_DONE BIT(5)
+/* ATM IPC design makes it possible to get the CFM before the ACK,
+ * otherwise this could have simply been a state enum
+ */
+#define AICWF_CMD_WAIT_COMPLETE(flags) \
+ (!((flags) & (AICWF_CMD_FLAG_WAIT_ACK | AICWF_CMD_FLAG_WAIT_CFM)))
+
+#define AICWF_CMD_MAX_QUEUED 16
+
+/* Number of commands that can be in flight at the same time */
+#define AICWF_CMD_ARRAY_SIZE 20
+#define AICWF_CMD_HIGH_WATER_SIZE (AICWF_CMD_ARRAY_SIZE / 2)
+
+#define aicwf_cmd_e2amsg ipc_e2a_msg
+#define aicwf_cmd_a2emsg lmac_msg
+#define AICWF_CMD_A2EMSG_LEN(m) (sizeof(struct lmac_msg) + (m)->param_len)
+#define AICWF_CMD_E2AMSG_LEN_MAX (IPC_E2A_MSG_PARAM_SIZE * 4)
+
+#define WAKE_CMD_WORK(_cmd_mgr) \
+ do { \
+ struct aicwf_cmd_mgr *__mgr = (_cmd_mgr); \
+ queue_work((__mgr)->cmd_wq, &__mgr->cmd_work); \
+ } while (0)
+
+struct aicwf_hw;
+struct aicwf_cmd;
+typedef int (*msg_cb_fct)(struct aicwf_hw *aicwf_hw, struct aicwf_cmd *cmd,
+ struct aicwf_cmd_e2amsg *msg);
+
+enum aicwf_cmd_mgr_state {
+ AICWF_CMD_MGR_STATE_DEINIT,
+ AICWF_CMD_MGR_STATE_INITED,
+ AICWF_CMD_MGR_STATE_CRASHED,
+ AICWF_CMD_MGR_STATE_STOPPING,
+};
+
+struct aicwf_cmd {
+ struct list_head list;
+ lmac_msg_id_t id;
+ lmac_msg_id_t reqid;
+ struct aicwf_cmd_a2emsg *a2e_msg;
+ char *e2a_msg;
+ size_t e2a_msg_len;
+ u32 tkn;
+ u16 flags;
+
+ struct completion complete;
+ /* The deferred worker has finished using this command. */
+ struct completion work_complete;
+ int result;
+ u8 used;
+ int array_id;
+};
+
+struct aicwf_cmd_mgr {
+ enum aicwf_cmd_mgr_state state;
+ spinlock_t lock; //
+ u32 next_tkn;
+ u32 queue_sz;
+ u32 max_queue_sz;
+
+ struct list_head cmds;
+
+ int (*queue)(struct aicwf_cmd_mgr *mgr, struct aicwf_cmd *cmd);
+ int (*llind)(struct aicwf_cmd_mgr *mgr, struct aicwf_cmd *cmd);
+ int (*msgind)(struct aicwf_cmd_mgr *mgr, struct aicwf_cmd_e2amsg *msg, msg_cb_fct cb);
+ void (*print)(struct aicwf_cmd_mgr *mgr);
+ void (*drain)(struct aicwf_cmd_mgr *mgr);
+
+ struct work_struct cmd_work;
+ struct workqueue_struct *cmd_wq;
+
+ /* Commands are taken from this pool */
+ struct aicwf_cmd pool[AICWF_CMD_ARRAY_SIZE];
+ /* Protects the @used flag of every entry of @pool and @users. */
+ spinlock_t pool_lock;
+ /* Send callers and borrowed commands must exit before device teardown. */
+ unsigned int users;
+ wait_queue_head_t users_wait;
+};
+
+static inline void put_u16(u8 *buf, u16 data)
+{
+ buf[0] = (u8)(data & 0x00ff);
+ buf[1] = (u8)((data >> 8) & 0x00ff);
+}
+
+int aicwf_cmd_mgr_init(struct aicwf_cmd_mgr *cmd_mgr);
+int aicwf_cmd_mgr_get(struct aicwf_cmd_mgr *cmd_mgr);
+void aicwf_cmd_mgr_put(struct aicwf_cmd_mgr *cmd_mgr);
+void aicwf_cmd_mgr_stop(struct aicwf_cmd_mgr *cmd_mgr);
+void aicwf_cmd_mgr_deinit(struct aicwf_cmd_mgr *cmd_mgr);
+int cmd_mgr_queue_force_defer(struct aicwf_cmd_mgr *cmd_mgr,
+ struct aicwf_cmd *cmd);
+void aicwf_set_cmd_tx(void *dev, struct lmac_msg *msg, uint len);
+void cmd_mgr_task_process(struct work_struct *work);
+struct aicwf_cmd *aicwf_cmd_malloc(struct aicwf_cmd_mgr *cmd_mgr);
+void aicwf_cmd_free(struct aicwf_cmd_mgr *cmd_mgr, struct aicwf_cmd *cmd);
+
+#endif /* _AICWF_CMDS_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80.c
new file mode 100644
index 000000000000..2833cb684303
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80.c
@@ -0,0 +1,281 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief 8800d80 compatibility configuration
+ *
+ ******************************************************************************
+ */
+
+#include <linux/module.h>
+
+#include "aicwf_compat_8800d80.h"
+#include "aicwf_platform.h"
+
+#define FW_USERCONFIG_NAME_8800D80 "aic8800d80/aic_userconfig_8800d80.txt"
+#define FW_NAME_8800D80_U02 "aic8800d80/fmacfw_8800d80_u02.bin"
+
+#define RAM_FMAC_FW_ADDR 0x00120000
+#define CHIP_REV_U02 3
+
+#define AIC_PATCH_MAGIC_NUM 0x48435450 /* "PTCH" */
+#define AIC_PATCH_MAGIC_NUM_2 0x50544348 /* "HCTP" */
+#define AIC_PATCH_BLOCK_MAX 4
+
+struct aic_patch_t {
+ u32 magic_num;
+ u32 pair_start;
+ u32 magic_num_2;
+ u32 pair_count;
+ u32 block_dst[AIC_PATCH_BLOCK_MAX];
+ u32 block_src[AIC_PATCH_BLOCK_MAX];
+ u32 block_size[AIC_PATCH_BLOCK_MAX]; /* word count */
+};
+
+#define AIC_PATCH_ADDR(mem) ((u32)(aic_patch_str_base + offsetof(struct aic_patch_t, mem)))
+
+#define USER_CHAN_MAX_TXPWR_EN_FLAG BIT(1)
+
+static const u32 patch_tbl_8800d80[][2] = {
+#if IS_ENABLED(CONFIG_AIC8800_USE_5G)
+ {0x00b4, 0xf3010001},
+#else
+ {0x00b4, 0xf3010000},
+#endif
+ {0x0188, 0x00000001 | USER_CHAN_MAX_TXPWR_EN_FLAG}, /* user_ext_flags */
+};
+
+#ifdef CONFIG_OOB
+/* map the SDIO data1 interrupt to gpiob1 */
+static const u32 gpio_cfg_tbl_8800d80[][2] = {
+ {0x40504084, 0x00000006}, {0x40500040, 0x00000000},
+ {0x40100030, 0x00000001}, {0x40241020, 0x00000001},
+ {0x40240030, 0x00000004}, {0x40240020, 0x03020700},
+};
+#endif
+
+static int aicwf_chip_rev_check_8800d80(struct aicwf_hw *aicwf_hw)
+{
+ struct dbg_mem_read_cfm cfm;
+ u8 chip_rev;
+ bool is_chip_id_h;
+ int ret;
+
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, 0x40500000, &cfm);
+ if (ret)
+ return ret;
+
+ chip_rev = (u8)((cfm.memdata >> 16) & 0x3F);
+ is_chip_id_h = ((cfm.memdata >> 16) & 0xC0) == 0xC0;
+ if (is_chip_id_h) {
+ dev_err(aicwf_hw->dev, "AIC8800D80 U02 is required (revision %u)\n",
+ chip_rev);
+ return -ENODEV;
+ }
+ dev_dbg(aicwf_hw->dev, "chip rev: %d\n", chip_rev);
+
+ return 0;
+}
+
+static int aicwf_patch_config_8800d80(struct aicwf_hw *aicwf_hw)
+{
+ const u32 rd_patch_addr = RAM_FMAC_FW_ADDR + 0x0198;
+ const u32 patch_cnt = ARRAY_SIZE(patch_tbl_8800d80);
+ struct dbg_mem_read_cfm cfm;
+ u32 config_base, aic_patch_str_base;
+ u32 start_addr = 0x0016F800;
+ u32 version;
+ int ret;
+ int cnt;
+
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, rd_patch_addr, &cfm);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "patch rd fail\n");
+ return ret;
+ }
+ config_base = cfm.memdata;
+
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, rd_patch_addr + 8, &cfm);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "patch str rd fail\n");
+ return ret;
+ }
+ aic_patch_str_base = cfm.memdata;
+
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, RAM_FMAC_FW_ADDR + 0x01C, &cfm);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "version val[0x%x] rd fail: %d\n",
+ RAM_FMAC_FW_ADDR + 0x01C, ret);
+ return ret;
+ }
+ version = cfm.memdata;
+ dev_dbg(aicwf_hw->dev, "rd_version_val=%08X\n", version);
+ if (version > 0x06090100) {
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, rd_patch_addr + 12, &cfm);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "patch buf rd fail\n");
+ return ret;
+ }
+ start_addr = cfm.memdata;
+ }
+
+ ret = aicwf_send_dbg_mem_write_req(aicwf_hw, AIC_PATCH_ADDR(magic_num),
+ AIC_PATCH_MAGIC_NUM);
+ if (ret)
+ goto write_fail;
+ ret = aicwf_send_dbg_mem_write_req(aicwf_hw, AIC_PATCH_ADDR(magic_num_2),
+ AIC_PATCH_MAGIC_NUM_2);
+ if (ret)
+ goto write_fail;
+ ret = aicwf_send_dbg_mem_write_req(aicwf_hw, AIC_PATCH_ADDR(pair_start),
+ start_addr);
+ if (ret)
+ goto write_fail;
+ ret = aicwf_send_dbg_mem_write_req(aicwf_hw, AIC_PATCH_ADDR(pair_count),
+ patch_cnt);
+ if (ret)
+ goto write_fail;
+
+ for (cnt = 0; cnt < patch_cnt; cnt++) {
+ ret = aicwf_send_dbg_mem_write_req(aicwf_hw, start_addr + 8 * cnt,
+ patch_tbl_8800d80[cnt][0] + config_base);
+ if (ret)
+ goto write_fail;
+ ret = aicwf_send_dbg_mem_write_req(aicwf_hw, start_addr + 8 * cnt + 4,
+ patch_tbl_8800d80[cnt][1]);
+ if (ret)
+ goto write_fail;
+ }
+
+ for (cnt = 0; cnt < AIC_PATCH_BLOCK_MAX; cnt++) {
+ ret = aicwf_send_dbg_mem_write_req(aicwf_hw,
+ AIC_PATCH_ADDR(block_size[cnt]), 0);
+ if (ret)
+ goto write_fail;
+ }
+
+ return 0;
+
+write_fail:
+ dev_err(aicwf_hw->dev, "patch config write fail: %d\n", ret);
+ return ret;
+}
+
+static int aicwf_sys_config_8800d80(struct aicwf_hw *aicwf_hw)
+{
+#ifdef CONFIG_OOB
+ int ret, cnt;
+
+ for (cnt = 0; cnt < ARRAY_SIZE(gpio_cfg_tbl_8800d80); cnt++) {
+ ret = aicwf_send_dbg_mem_write_req(aicwf_hw,
+ gpio_cfg_tbl_8800d80[cnt][0],
+ gpio_cfg_tbl_8800d80[cnt][1]);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "%x write fail: %d\n",
+ gpio_cfg_tbl_8800d80[cnt][0], ret);
+ return ret;
+ }
+ }
+#endif
+
+ return 0;
+}
+
+/**
+ * aicwf_fw_download_8800d80() - Boot the AIC8800D80 firmware
+ * @aicwf_hw: Main driver data
+ *
+ * Talk to the bootrom to check the chip revision, upload the firmware,
+ * configure its patch table and start it.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int aicwf_fw_download_8800d80(struct aicwf_hw *aicwf_hw)
+{
+ int ret;
+
+ ret = aicwf_chip_rev_check_8800d80(aicwf_hw);
+ if (ret)
+ return ret;
+
+ dev_dbg(aicwf_hw->dev, "8800d80 u02 wifi firmware: %s\n",
+ FW_NAME_8800D80_U02);
+ ret = aicwf_plat_bin_fw_upload(aicwf_hw, RAM_FMAC_FW_ADDR,
+ FW_NAME_8800D80_U02);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "8800d80 download wifi fw fail\n");
+ return ret;
+ }
+
+ ret = aicwf_patch_config_8800d80(aicwf_hw);
+ if (ret)
+ return ret;
+
+ ret = aicwf_sys_config_8800d80(aicwf_hw);
+ if (ret)
+ return ret;
+
+ ret = aicwf_send_dbg_start_app_req(aicwf_hw, RAM_FMAC_FW_ADDR,
+ HOST_START_APP_AUTO);
+ if (ret)
+ dev_err(aicwf_hw->dev, "8800d80 wifi start fail\n");
+
+ return ret;
+}
+
+int aicwf_set_rf_config_8800d80(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_cfm *cfm)
+{
+ int ret = 0;
+
+ /* Preserve the existing rate-power settings; cfg80211 supplies channel limits. */
+ ret = aicwf_send_txpwr_lvl_v3_req(aicwf_hw, 0);
+ if (ret)
+ return -1;
+
+ ret = aicwf_send_txpwr_lvl_adj_req(aicwf_hw);
+ if (ret)
+ return -1;
+
+ ret = aicwf_send_txpwr_ofst2x_req(aicwf_hw);
+ if (ret)
+ return -1;
+
+ ret = aicwf_send_rf_calib_req(aicwf_hw, cfm);
+ if (ret)
+ return -1;
+
+ return 0;
+}
+
+int aicwf_plat_userconfig_load_8800d80(struct aicwf_hw *aicwf_hw)
+{
+ int size;
+ u32 *dst = NULL;
+ char *filename = FW_USERCONFIG_NAME_8800D80;
+
+ dev_dbg(aicwf_hw->dev, "userconfig file path:%s\n", filename);
+
+ /* load file */
+ size = aicwf_request_firmware_common(aicwf_hw, &dst, filename);
+ if (size <= 0) {
+ dev_err(aicwf_hw->dev, "wrong size of firmware file\n");
+ dst = NULL;
+ return 0;
+ }
+
+ /* Copy the file on the Embedded side */
+ dev_dbg(aicwf_hw->dev, "load file done: %s, size=%d\n", filename, size);
+
+ aicwf_plat_userconfig_parsing3(aicwf_hw, (char *)dst, size);
+
+ aicwf_release_firmware_common(&dst);
+
+ dev_dbg(aicwf_hw->dev, "userconfig download complete\n");
+ return 0;
+}
+
+MODULE_FIRMWARE(AIC8800_FW_DIR FW_USERCONFIG_NAME_8800D80);
+MODULE_FIRMWARE(AIC8800_FW_DIR FW_NAME_8800D80_U02);
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80.h
new file mode 100644
index 000000000000..7b608806ebac
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_COMPAT_8800D80_H_
+#define _AICWF_COMPAT_8800D80_H_
+#include "aicwf_main.h"
+#include "aicwf_msg_tx.h"
+#include <linux/types.h>
+
+int aicwf_set_rf_config_8800d80(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_cfm *cfm);
+int aicwf_plat_userconfig_load_8800d80(struct aicwf_hw *aicwf_hw);
+int aicwf_fw_download_8800d80(struct aicwf_hw *aicwf_hw);
+
+#endif
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80n.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80n.c
new file mode 100644
index 000000000000..53f68b9684e1
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80n.c
@@ -0,0 +1,402 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief 8800d80n compatibility configuration
+ *
+ ******************************************************************************
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/vmalloc.h>
+
+#include "aicwf_compat_8800d80n.h"
+#include "aicwf_platform.h"
+
+#define FW_USERCONFIG_NAME_8800D80N "aic8800d80n/aic_userconfig_8800d80n.txt"
+
+#define FW_CINIT_NAME_8800D80N_U02 "aic8800d80n/fmacfw_cinit_8800d80n_u02.bin"
+#define FW_CALIB_NAME_8800D80N_U02 "aic8800d80n/fmacfw_calib_8800d80n_u02.bin"
+#define FW_PATCH_NAME_8800D80N_U02 "aic8800d80n/fmacfw_patch_8800d80n_u02.bin"
+#define FW_PATCH_TBL_NAME_8800D80N_U02 "aic8800d80n/fmacfw_patch_tbl_8800d80n_u02.bin"
+#define FW_CINIT_NAME_8800D80N_U02C "aic8800d80n/fmacfw_cinit_8800d80n_u02c.bin"
+#define FW_CALIB_NAME_8800D80N_U02C "aic8800d80n/fmacfw_calib_8800d80n_u02c.bin"
+#define FW_PATCH_NAME_8800D80N_U02C "aic8800d80n/fmacfw_patch_8800d80n_u02c.bin"
+#define FW_PATCH_TBL_NAME_8800D80N_U02C "aic8800d80n/fmacfw_patch_tbl_8800d80n_u02c.bin"
+
+#define RAM_FMAC_FW_ADDR 0x00120000
+#define ROM_FMAC_CINIT_ADDR_8800D80N 0x00133000
+#define ROM_FMAC_CALIB_ADDR_8800D80N 0x00138000
+#define ROM_FMAC_PATCH_ADDR_8800D80N 0x00188000
+
+/* the wifisetting block address is stored here by the ROM */
+#define WIFISETTING_CFG_BASE_8800D80N 0x10170
+#define WIFISETTING_XTAL_CAP_OFST 0x1dc
+
+#define CHIP_INFO_ADDR_8800D80N 0x40500184
+#define CHIP_INFO_FLAG_CINIT_BEGIN BIT(12)
+#define CHIP_INFO_FLAG_CINIT_DONE BIT(13)
+#define CINIT_WAIT_RETRY_MAX 2000
+
+#define PATCH_VAR_FLAG_CALIB_BEGIN BIT(0)
+#define PATCH_VAR_FLAG_CALIB_DONE BIT(1)
+
+#define USER_PWROFST_COVER_CALIB_FLAG BIT(0)
+
+static const u32 patch_tbl_wifisetting_8800d80n[][2] = {
+ {0x017c, USER_PWROFST_COVER_CALIB_FLAG}, /* user_ext_flags */
+ {0x0170, 0x50000001}, /* gpio_wakeup_en */
+};
+
+struct aicwf_fw_8800d80n {
+ const char *cinit;
+ const char *calib;
+ const char *patch;
+ const char *patch_tbl;
+};
+
+static const struct aicwf_fw_8800d80n fw_8800d80n_u02 = {
+ .cinit = FW_CINIT_NAME_8800D80N_U02,
+ .calib = FW_CALIB_NAME_8800D80N_U02,
+ .patch = FW_PATCH_NAME_8800D80N_U02,
+ .patch_tbl = FW_PATCH_TBL_NAME_8800D80N_U02,
+};
+
+static const struct aicwf_fw_8800d80n fw_8800d80n_u02c = {
+ .cinit = FW_CINIT_NAME_8800D80N_U02C,
+ .calib = FW_CALIB_NAME_8800D80N_U02C,
+ .patch = FW_PATCH_NAME_8800D80N_U02C,
+ .patch_tbl = FW_PATCH_TBL_NAME_8800D80N_U02C,
+};
+
+static int aicwf_userconfig_parse_8800d80n(struct aicwf_hw *aicwf_hw)
+{
+ u32 *dst = NULL;
+ int size;
+
+ size = aicwf_request_firmware_common(aicwf_hw, &dst,
+ FW_USERCONFIG_NAME_8800D80N);
+ if (size <= 0) {
+ dev_err(aicwf_hw->dev, "failed to load %s: %d\n",
+ FW_USERCONFIG_NAME_8800D80N, size);
+ vfree(dst);
+ return size < 0 ? size : -EINVAL;
+ }
+
+ aicwf_plat_userconfig_parsing3(aicwf_hw, (char *)dst, size);
+ aicwf_release_firmware_common(&dst);
+
+ return 0;
+}
+
+int aicwf_plat_userconfig_load_8800d80n(struct aicwf_hw *aicwf_hw)
+{
+ aicwf_userconfig_parse_8800d80n(aicwf_hw);
+ return 0;
+}
+
+static int aicwf_wifisetting_addr_8800d80n(struct aicwf_hw *aicwf_hw, u32 *addr)
+{
+ struct dbg_mem_read_cfm cfm;
+ int ret;
+
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, WIFISETTING_CFG_BASE_8800D80N,
+ &cfm);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "setting base[0x%x] rd fail: %d\n",
+ WIFISETTING_CFG_BASE_8800D80N, ret);
+ return ret;
+ }
+ *addr = cfm.memdata;
+
+ return 0;
+}
+
+/* Write the default wifi settings and the user xtal cap into the ROM. */
+static int aicwf_patch_config_8800d80n(struct aicwf_hw *aicwf_hw)
+{
+ struct xtal_cap_conf xtal_cap = { 0 };
+ u32 wifisetting_cfg_addr;
+ int ret;
+ int cnt;
+
+ ret = aicwf_wifisetting_addr_8800d80n(aicwf_hw, &wifisetting_cfg_addr);
+ if (ret)
+ return ret;
+ dev_dbg(aicwf_hw->dev, "wifisetting_cfg_addr=%x\n", wifisetting_cfg_addr);
+
+ for (cnt = 0; cnt < ARRAY_SIZE(patch_tbl_wifisetting_8800d80n); cnt++) {
+ ret = aicwf_send_dbg_mem_write_req(aicwf_hw,
+ wifisetting_cfg_addr +
+ patch_tbl_wifisetting_8800d80n[cnt][0],
+ patch_tbl_wifisetting_8800d80n[cnt][1]);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "wifisetting %x write fail\n",
+ patch_tbl_wifisetting_8800d80n[cnt][0]);
+ return ret;
+ }
+ }
+
+ get_userconfig_xtal_cap(aicwf_hw, &xtal_cap);
+ if (xtal_cap.enable) {
+ dev_dbg(aicwf_hw->dev, "user xtal cap: %d, cap_fine: %d\n",
+ xtal_cap.xtal_cap, xtal_cap.xtal_cap_fine);
+ ret = aicwf_send_dbg_mem_write_req(aicwf_hw,
+ wifisetting_cfg_addr +
+ WIFISETTING_XTAL_CAP_OFST,
+ (35 << 16) |
+ (xtal_cap.xtal_cap_fine << 8) |
+ xtal_cap.xtal_cap);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "set user xtal cap fail\n");
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+/* Run the chip init code once, unless the ROM already did it. */
+static int aicwf_cinit_exec_8800d80n(struct aicwf_hw *aicwf_hw,
+ const struct aicwf_fw_8800d80n *fw)
+{
+ struct dbg_mem_read_cfm cfm;
+ int retry = 0;
+ int ret;
+
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, CHIP_INFO_ADDR_8800D80N, &cfm);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "%x rd fail: %d\n", CHIP_INFO_ADDR_8800D80N, ret);
+ return ret;
+ }
+
+ if (cfm.memdata & CHIP_INFO_FLAG_CINIT_BEGIN) {
+ while (!(cfm.memdata & CHIP_INFO_FLAG_CINIT_DONE)) {
+ if (++retry > CINIT_WAIT_RETRY_MAX) {
+ dev_err(aicwf_hw->dev, "cinit wait timeout, chipinfo=%x\n",
+ cfm.memdata);
+ return -ETIMEDOUT;
+ }
+ usleep_range(500, 1000);
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw,
+ CHIP_INFO_ADDR_8800D80N, &cfm);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "%x rd fail: %d\n",
+ CHIP_INFO_ADDR_8800D80N, ret);
+ return ret;
+ }
+ }
+ dev_dbg(aicwf_hw->dev, "cinit executed, chipinfo=%x\n", cfm.memdata);
+ return 0;
+ }
+
+ ret = aicwf_plat_bin_fw_upload(aicwf_hw, ROM_FMAC_CINIT_ADDR_8800D80N,
+ fw->cinit);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "load cinit bin fail: %d\n", ret);
+ return ret;
+ }
+
+ ret = aicwf_send_dbg_start_app_req(aicwf_hw,
+ ROM_FMAC_CINIT_ADDR_8800D80N + 0x0009,
+ HOST_START_APP_FNCALL);
+ if (ret)
+ dev_err(aicwf_hw->dev, "cinit start app fail: %d\n", ret);
+
+ return ret;
+}
+
+static int aicwf_patch_table_load_8800d80n(struct aicwf_hw *aicwf_hw,
+ const char *filename)
+{
+ u32 *dst = NULL;
+ int size;
+ int err = 0;
+ int i;
+
+ size = aicwf_request_firmware_common(aicwf_hw, &dst, filename);
+ if (size <= 0) {
+ dev_err(aicwf_hw->dev, "failed to load %s: %d\n", filename, size);
+ vfree(dst);
+ return size < 0 ? size : -EINVAL;
+ }
+
+ for (i = 0; i + 1 < size / 4; i += 2) {
+ if (dst[i] == 0x0 || dst[i] == 0xFFFFFFFF)
+ break; /* end of table */
+ err = aicwf_send_dbg_mem_write_req(aicwf_hw, dst[i], dst[i + 1]);
+ if (err) {
+ dev_err(aicwf_hw->dev, "patch_tbl %x write fail: %d\n",
+ dst[i], err);
+ break;
+ }
+ }
+
+ aicwf_release_firmware_common(&dst);
+
+ return err;
+}
+
+/* Run the RF calibration once, unless the patch already did it. */
+static int aicwf_calib_exec_8800d80n(struct aicwf_hw *aicwf_hw,
+ const struct aicwf_fw_8800d80n *fw)
+{
+ const u32 patch_var_flags_addr = ROM_FMAC_PATCH_ADDR_8800D80N + 0x08;
+ struct dbg_mem_read_cfm cfm;
+ int ret;
+
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, patch_var_flags_addr, &cfm);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "%x rd fail: %d\n", patch_var_flags_addr, ret);
+ return ret;
+ }
+ if (cfm.memdata & (PATCH_VAR_FLAG_CALIB_BEGIN | PATCH_VAR_FLAG_CALIB_DONE)) {
+ dev_dbg(aicwf_hw->dev, "calib executed, var_flags=%x\n", cfm.memdata);
+ return 0;
+ }
+
+ ret = aicwf_plat_bin_fw_upload(aicwf_hw, ROM_FMAC_CALIB_ADDR_8800D80N,
+ fw->calib);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "load calib bin fail: %d\n", ret);
+ return ret;
+ }
+
+ ret = aicwf_send_dbg_start_app_req(aicwf_hw,
+ ROM_FMAC_CALIB_ADDR_8800D80N + 0x0009,
+ HOST_START_APP_FNCALL);
+ if (ret)
+ dev_err(aicwf_hw->dev, "calib start app fail: %d\n", ret);
+
+ return ret;
+}
+
+/**
+ * aicwf_fw_download_8800d80n() - Boot the AIC8800D80N firmware
+ * @aicwf_hw: Main driver data
+ *
+ * The AIC8800D80N runs its firmware from ROM: configure the ROM settings,
+ * run the chip init code, upload the ROM patch and its table, run the RF
+ * calibration and start the firmware.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int aicwf_fw_download_8800d80n(struct aicwf_hw *aicwf_hw)
+{
+ const struct aicwf_fw_8800d80n *fw;
+ struct dbg_mem_read_cfm cfm;
+ u8 chip_sub_id;
+ int ret;
+
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, 0x40500000, &cfm);
+ if (ret)
+ return ret;
+ dev_dbg(aicwf_hw->dev, "chip rev: %d, mcu id: %d\n",
+ (cfm.memdata >> 16) & 0x3F, !((cfm.memdata >> 25) & 0x01));
+
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, 0x00000020, &cfm);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "[0x00000020] rd fail: %d\n", ret);
+ return ret;
+ }
+ chip_sub_id = (u8)cfm.memdata;
+ fw = chip_sub_id == 1 ? &fw_8800d80n_u02 : &fw_8800d80n_u02c;
+ dev_dbg(aicwf_hw->dev, "chip_sub_id=%x\n", chip_sub_id);
+
+ ret = aicwf_userconfig_parse_8800d80n(aicwf_hw);
+ if (ret)
+ return ret;
+
+ ret = aicwf_patch_config_8800d80n(aicwf_hw);
+ if (ret)
+ return ret;
+
+ ret = aicwf_cinit_exec_8800d80n(aicwf_hw, fw);
+ if (ret)
+ return ret;
+
+ ret = aicwf_plat_bin_fw_upload_chunk(aicwf_hw, ROM_FMAC_PATCH_ADDR_8800D80N,
+ fw->patch, 512);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "load patch bin fail: %d\n", ret);
+ return ret;
+ }
+
+ ret = aicwf_patch_table_load_8800d80n(aicwf_hw, fw->patch_tbl);
+ if (ret)
+ return ret;
+
+ ret = aicwf_calib_exec_8800d80n(aicwf_hw, fw);
+ if (ret)
+ return ret;
+
+ ret = aicwf_send_dbg_mem_read_req(aicwf_hw, RAM_FMAC_FW_ADDR, &cfm);
+ if (ret)
+ return ret;
+
+ ret = aicwf_send_dbg_start_app_req(aicwf_hw, RAM_FMAC_FW_ADDR,
+ HOST_START_APP_DUMMY);
+ if (ret)
+ dev_err(aicwf_hw->dev, "8800d80n wifi start fail\n");
+
+ return ret;
+}
+
+/* Write the user xtal cap into the running firmware. */
+static int aicwf_set_xtal_cap_8800d80n(struct aicwf_hw *aicwf_hw)
+{
+ struct xtal_cap_conf xtal_cap = { 0 };
+ u32 wifisetting_cfg_addr;
+ int ret;
+
+ ret = aicwf_wifisetting_addr_8800d80n(aicwf_hw, &wifisetting_cfg_addr);
+ if (ret)
+ return ret;
+
+ get_userconfig_xtal_cap(aicwf_hw, &xtal_cap);
+ if (!xtal_cap.enable)
+ return 0;
+
+ dev_dbg(aicwf_hw->dev, "user xtal cap: %d, cap_fine: %d\n",
+ xtal_cap.xtal_cap, xtal_cap.xtal_cap_fine);
+ ret = aicwf_send_dbg_mem_write_req(aicwf_hw,
+ wifisetting_cfg_addr + WIFISETTING_XTAL_CAP_OFST,
+ (xtal_cap.xtal_cap_fine << 8) |
+ xtal_cap.xtal_cap);
+ if (ret)
+ dev_err(aicwf_hw->dev, "set user xtal cap fail\n");
+
+ return ret;
+}
+
+int aicwf_set_rf_config_8800d80n(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_cfm *cfm)
+{
+ /* The RF calibration was already run during the firmware boot. */
+ if (aicwf_send_txpwr_lvl_v3_req(aicwf_hw, 0))
+ return -1;
+
+ if (aicwf_send_txpwr_ofst2x_req(aicwf_hw))
+ return -1;
+
+ if (aicwf_set_xtal_cap_8800d80n(aicwf_hw))
+ return -1;
+
+ if (aicwf_send_txpwr_lvl_adj_req(aicwf_hw))
+ return -1;
+
+ return 0;
+}
+
+MODULE_FIRMWARE(AIC8800_FW_DIR FW_USERCONFIG_NAME_8800D80N);
+MODULE_FIRMWARE(AIC8800_FW_DIR FW_CINIT_NAME_8800D80N_U02);
+MODULE_FIRMWARE(AIC8800_FW_DIR FW_CALIB_NAME_8800D80N_U02);
+MODULE_FIRMWARE(AIC8800_FW_DIR FW_PATCH_NAME_8800D80N_U02);
+MODULE_FIRMWARE(AIC8800_FW_DIR FW_PATCH_TBL_NAME_8800D80N_U02);
+MODULE_FIRMWARE(AIC8800_FW_DIR FW_CINIT_NAME_8800D80N_U02C);
+MODULE_FIRMWARE(AIC8800_FW_DIR FW_CALIB_NAME_8800D80N_U02C);
+MODULE_FIRMWARE(AIC8800_FW_DIR FW_PATCH_NAME_8800D80N_U02C);
+MODULE_FIRMWARE(AIC8800_FW_DIR FW_PATCH_TBL_NAME_8800D80N_U02C);
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80n.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80n.h
new file mode 100644
index 000000000000..315c858d102b
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80n.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_COMPAT_8800D80N_H_
+#define _AICWF_COMPAT_8800D80N_H_
+#include "aicwf_main.h"
+#include "aicwf_msg_tx.h"
+#include <linux/types.h>
+
+int aicwf_set_rf_config_8800d80n(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_cfm *cfm);
+int aicwf_plat_userconfig_load_8800d80n(struct aicwf_hw *aicwf_hw);
+int aicwf_fw_download_8800d80n(struct aicwf_hw *aicwf_hw);
+
+#endif
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_config.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_config.h
new file mode 100644
index 000000000000..53c258b2974b
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_config.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * Driver configuration and firmware resource limits.
+ */
+
+#ifndef _AICWF_CONFIG_H_
+#define _AICWF_CONFIG_H_
+
+#ifdef CONFIG_AICWF_MUMIMO_TX
+#define NX_USER_MAX 2
+#else
+#define NX_USER_MAX 1
+#endif
+
+#define NX_VIRT_DEV_MAX 4
+
+#define NX_REMOTE_STA_MAX_FOR_OLD_IC 10
+#define NX_REMOTE_STA_MAX 32
+
+#define NX_MU_GROUP_MAX 62
+#define NX_TXDESC_CNT 64
+#define NX_TX_MAX_RATES 4
+#define NX_CHAN_CTXT_CNT 3
+
+#ifdef CONFIG_AICWF_BCMC
+#define NX_TXQ_CNT 5
+#else
+#define NX_TXQ_CNT 4
+#endif
+
+#endif /* _AICWF_CONFIG_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_defs.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_defs.h
new file mode 100644
index 000000000000..52d0f4a888e1
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_defs.h
@@ -0,0 +1,657 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief Main driver structure declarations for fullmac driver
+ *
+ ******************************************************************************
+ */
+
+#ifndef _AICWF_DEFS_H_
+#define _AICWF_DEFS_H_
+
+#include <linux/device.h>
+#include <linux/interrupt.h>
+#include <linux/skbuff.h>
+#include <linux/slab.h>
+#include <net/cfg80211.h>
+
+#include "aicwf_cmds.h"
+#include "aicwf_mod_params.h"
+#include "aicwf_mu_group.h"
+#include "aicwf_platform.h"
+#include "aicwf_radar.h"
+#include "aicwf_rx.h"
+#include "aicwf_tx.h"
+#include "aicwf_utils.h"
+#include "aicwf_config.h"
+
+#include "aicwf_sdio.h"
+#include "sdio_host.h"
+
+#include "lmac_mac.h"
+#include "aicwf_chip_ops.h"
+
+#define WPI_HDR_LEN 18
+#define WPI_PN_LEN 16
+#define WPI_PN_OFST 2
+#define WPI_MIC_LEN 16
+#define WPI_KEY_LEN 32
+#define WPI_SUBKEY_LEN 16 // WPI key is actually two 16bytes key
+
+#define LEGACY_PS_ID 0
+#define UAPSD_ID 1
+
+#define PS_SP_INTERRUPTED 255
+#define MAC_ADDR_LEN 6
+
+struct wf_bss_info {
+ u32 length;
+ s8 rssi;
+ u16 chan;
+ enum nl80211_band band; /* Band */
+ u8 width; /* Channel width 0/1/2--20/40/80 */
+ u16 center_freq; /* Center frequency */
+ u32 center_freq1; /* Center frequency 1 */
+ u32 center_freq2; /* Center frequency 2 */
+ bool ht;
+ bool vht;
+ u8 bssid[ETH_ALEN];
+ u8 ssid_len;
+ unsigned char ssid[33];
+};
+
+/**
+ * struct aicwf_bcn - Information of the beacon in used (AP mode)
+ *
+ * @head: head portion of beacon (before TIM IE)
+ * @tail: tail portion of beacon (after TIM IE)
+ * @ies: extra IEs (not used ?)
+ * @head_len: length of head data
+ * @tail_len: length of tail data
+ * @ies_len: length of extra IEs data
+ * @tim_len: length of TIM IE
+ * @len: Total beacon len (head + tim + tail + extra)
+ * @dtim: dtim period
+ */
+struct aicwf_bcn {
+ u8 *head;
+ u8 *tail;
+ u8 *ies;
+ size_t head_len;
+ size_t tail_len;
+ size_t ies_len;
+ size_t tim_len;
+ size_t len;
+ u8 dtim;
+};
+
+/**
+ * struct aicwf_key - Key information
+ *
+ * @hw_idx: Idx of the key from hardware point of view
+ */
+struct aicwf_key {
+ u8 hw_idx;
+};
+
+/*
+ * Structure containing information about a Mesh Path
+ */
+struct aicwf_mesh_path {
+ struct list_head list; /* For aicwf_vif.mesh_paths */
+ u8 path_idx; /* Path Index */
+ struct mac_addr tgt_mac_addr; /* Target MAC Address */
+ struct aicwf_sta *p_nhop_sta; /* Pointer to the Next Hop STA */
+};
+
+struct aicwf_mesh_proxy {
+ struct list_head list; /* For aicwf_vif.mesh_proxy */
+ struct mac_addr ext_sta_addr; /* Address of the External STA */
+ struct mac_addr proxy_addr; /* Proxy MAC Address */
+ bool local; /* Indicate if interface is a proxy for the device */
+};
+
+/**
+ * struct aicwf_csa - Information for CSA (Channel Switch Announcement)
+ *
+ * @vif: Pointer to the vif doing the CSA
+ * @bcn: Beacon to use after CSA
+ * @chandef: defines the channel to use after the switch
+ * @count: Current csa counter
+ * @status: Status of the CSA at fw level
+ * @ch_idx: Index of the new channel context
+ * @work: work scheduled at the end of CSA
+ */
+struct aicwf_csa {
+ struct aicwf_vif *vif;
+ struct aicwf_bcn bcn;
+ struct cfg80211_chan_def chandef;
+ int count;
+ int status;
+ int ch_idx;
+ struct work_struct work;
+};
+
+struct apm_probe_sta {
+ u8 sta_mac_addr[6];
+ u8 vif_idx;
+ u64 probe_id;
+ struct work_struct apmprobesta_work;
+ struct workqueue_struct *apmprobesta_wq;
+};
+
+/// Possible States of the TDLS link.
+enum tdls_status_tag {
+ /// TDLS link is not active (no TDLS peer connected)
+ TDLS_LINK_IDLE,
+ /// TDLS Setup Request transmitted
+ TDLS_SETUP_REQ_TX,
+ /// TDLS Setup Response transmitted
+ TDLS_SETUP_RSP_TX,
+ /// TDLS link is active (TDLS peer connected)
+ TDLS_LINK_ACTIVE,
+ /// TDLS Max Number of states.
+ TDLS_STATE_MAX
+};
+
+/*
+ * Structure used to save information relative to the TDLS peer.
+ * This is also linked within the aicwf_hw vifs list.
+ *
+ */
+struct aicwf_tdls {
+ bool active; /* Indicate if TDLS link is active */
+ bool initiator; /* Indicate if TDLS peer is the TDLS initiator */
+ bool chsw_en; /* Indicate if channel switch is enabled */
+ u8 last_tid; /* TID of the latest MPDU transmitted over the
+ * TDLS direct link to the TDLS STA
+ */
+ u16 last_sn; /* Sequence number of the latest MPDU transmitted
+ * over the TDLS direct link to the TDLS STA
+ */
+ bool ps_on; /* Indicate if the power save is enabled on the
+ * TDLS STA
+ */
+ bool chsw_allowed; /* Indicate if TDLS channel switch is allowed */
+};
+
+/**
+ * enum aicwf_ap_flags - AP flags
+ *
+ * @AICWF_AP_ISOLATE: Isolate clients (i.e. don't bridge packets transmitted by
+ * one client for another one)
+ */
+enum aicwf_ap_flags {
+ AICWF_AP_ISOLATE = BIT(0),
+};
+
+/*
+ * Structure used to save information relative to the managed interfaces.
+ * This is also linked within the aicwf_hw vifs list.
+ *
+ */
+struct aicwf_vif {
+ struct list_head list;
+ struct aicwf_hw *aicwf_hw;
+ struct wireless_dev wdev;
+ struct net_device *ndev;
+ struct net_device_stats net_stats;
+ struct aicwf_key key[6];
+ unsigned long drv_flags;
+ atomic_t drv_conn_state;
+ u8 drv_vif_index; /* Identifier of the VIF in driver */
+ u8 vif_index; /* Identifier of the station in FW */
+ u8 ch_index; /* Channel context identifier */
+ bool up; /* Indicate if associated netdev is up
+ * (i.e. Interface is created at fw level)
+ */
+ bool use_4addr; /* Should we use 4addresses mode */
+ bool is_resending; /* Indicate if a frame is being resent on this interface */
+ bool user_mpm; /* In case of Mesh Point VIF, indicate if MPM is handled by
+ * userspace
+ */
+ bool roc_tdls; /* Indicate if the ROC has been called by a
+ * TDLS station
+ */
+ u8 tdls_status; /* Status of the TDLS link */
+ bool tdls_chsw_prohibited; /* Indicate if TDLS Channel Switch is prohibited */
+ bool wep_enabled; /* 1 if WEP is enabled */
+ bool wep_auth_err; /* 1 if auth status code is not supported auth alg when
+ * WEP enabled
+ */
+ enum nl80211_auth_type
+ last_auth_type; /* Authentication type (algorithm) sent in the last
+ * connection when WEP enabled
+ */
+ union {
+ struct {
+ /* Pointer to the peer STA entry allocated for the AP */
+ struct aicwf_sta *ap;
+ struct aicwf_sta *tdls_sta; /* Pointer to the TDLS station */
+ bool external_auth; /* Indicate if external authentication is in
+ * progress
+ */
+ u32 group_cipher_type;
+ u32 paired_cipher_type;
+ // connected network info start
+ char ssid[32];
+ int ssid_len;
+ u8 bssid[ETH_ALEN];
+ u32 conn_owner_nlportid;
+ bool is_roam;
+ unsigned long link_time;
+ u16 b_interval;
+ u8 dtim_peroid;
+ u16 capability;
+ enum nl80211_auth_type auth_type;
+ // connected network info end
+ } sta;
+ struct {
+ u16 flags; /* see aicwf_ap_flags */
+ struct list_head sta_list; /* List of STA connected to the AP */
+ struct aicwf_bcn bcn; /* beacon */
+ u8 bcmc_index; /* Index of the BCMC sta to use */
+ struct aicwf_csa *csa;
+
+ struct list_head
+ mpath_list; /* List of Mesh Paths used on this interface */
+ struct list_head proxy_list; /* List of Proxies Information used on
+ * this interface
+ */
+ bool create_path; /* Indicate if we are waiting for a
+ * MESH_CREATE_PATH_CFM message
+ */
+ int generation; /* Increased each time the list of Mesh Paths is
+ * updated
+ */
+ enum nl80211_mesh_power_mode
+ mesh_pm; /* mesh power save mode currently set in firmware */
+ enum nl80211_mesh_power_mode
+ next_mesh_pm; /* mesh power save mode for next peer */
+ } ap;
+ struct {
+ struct aicwf_vif *master; /* pointer on master interface */
+ struct aicwf_sta *sta_4a;
+ } ap_vlan;
+ };
+
+ u8 key_has_add;
+ /* Set while disconnecting so that key deletions reach the firmware */
+ bool key_flag;
+ u8 is_p2p_vif;
+ struct apm_probe_sta sta_probe;
+
+};
+
+#define AICWF_VIF_TYPE(aicwf_vif) ((aicwf_vif)->wdev.iftype)
+
+/*
+ * Structure used to store information relative to PS mode.
+ *
+ * @active: True when the sta is in PS mode.
+ * If false, other values should be ignored
+ * @pkt_ready: Number of packets buffered for the sta in drv's txq
+ * (1 counter for Legacy PS and 1 for U-APSD)
+ * @sp_cnt: Number of packets that remain to be pushed in the service period.
+ * 0 means that no service period is in progress
+ * (1 counter for Legacy PS and 1 for U-APSD)
+ */
+struct aicwf_sta_ps {
+ bool active;
+ u16 pkt_ready[2];
+ u16 sp_cnt[2];
+};
+
+/**
+ * struct aicwf_rx_rate_stats - Store statistics for RX rates
+ *
+ * @table: Number of received frames for each rate index
+ * @size: Number of entries in @table
+ * @cpt: Total number of received frames
+ * @rate_cnt: Number of rate indexes with at least one received frame
+ */
+struct aicwf_rx_rate_stats {
+ int *table;
+ int size;
+ int cpt;
+ int rate_cnt;
+};
+
+/**
+ * struct aicwf_sta_stats - Structure Used to store statistics specific to a STA
+ *
+ * @last_rx: Hardware vector of the last received frame
+ * @rx_rate: Statistics of the received rates
+ */
+struct aicwf_sta_stats {
+ struct hw_vect last_rx;
+ struct aicwf_rx_rate_stats rx_rate;
+};
+
+/*
+ * Structure used to save information relative to the managed stations.
+ */
+struct aicwf_sta {
+ struct list_head list;
+ u16 aid; /* association ID */
+ u8 sta_idx; /* Identifier of the station */
+ u8 vif_idx; /* Identifier of the VIF (fw id) the station
+ * belongs to
+ */
+ u8 vlan_idx; /* Identifier of the VLAN VIF (fw id) the station
+ * belongs to (= vif_idx if no vlan in used)
+ */
+ enum nl80211_band band; /* Band */
+ enum nl80211_chan_width width; /* Channel width */
+ u16 center_freq; /* Center frequency */
+ u32 center_freq1; /* Center frequency 1 */
+ u32 center_freq2; /* Center frequency 2 */
+ u8 ch_idx; /* Identifier of the channel
+ * context the station belongs to
+ */
+ bool qos; /* Flag indicating if the station
+ * supports QoS
+ */
+ u8 acm; /* Bitfield indicating which queues
+ * have AC mandatory
+ */
+ u16 uapsd_tids; /* Bitfield indicating which tids are subject to
+ * UAPSD
+ */
+ u8 mac_addr[ETH_ALEN]; /* MAC address of the station */
+ struct aicwf_key key;
+ bool valid; /* Flag indicating if the entry is valid */
+ struct aicwf_sta_ps ps; /* Information when STA is in PS (AP only) */
+#ifdef CONFIG_AICWF_BFMER
+ /* Beamforming report to be used for VHT TX Beamforming */
+ struct aicwf_bfmer_report *bfm_report;
+#ifdef CONFIG_AICWF_MUMIMO_TX
+ struct aicwf_sta_group_info
+ group_info; /* MU grouping information for the STA */
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+#endif /* CONFIG_AICWF_BFMER */
+
+ bool ht; /* Flag indicating if the station
+ * supports HT
+ */
+ bool vht; /* Flag indicating if the station
+ * supports VHT
+ */
+ u32 ac_param[AC_MAX]; /* EDCA parameters */
+ struct aicwf_tdls tdls; /* TDLS station information */
+ struct aicwf_sta_stats stats;
+ enum nl80211_mesh_power_mode
+ mesh_pm; /* link-specific mesh power save mode */
+};
+
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+struct aicwf_amsdu_stats {
+ int done;
+ int failed;
+};
+#endif
+
+struct aicwf_stats {
+ int cfm_balance[NX_TXQ_CNT];
+ unsigned long last_rx, last_tx; /* jiffies */
+ int ampdus_tx[IEEE80211_MAX_AMPDU_BUF_HE];
+ int ampdus_rx[IEEE80211_MAX_AMPDU_BUF_HE];
+ int ampdus_rx_map[4];
+ int ampdus_rx_miss;
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+ struct aicwf_amsdu_stats amsdus[NX_TX_PAYLOAD_MAX];
+#endif
+ int amsdus_rx[64];
+};
+
+struct aicwf_sec_phy_chan {
+ u16 prim20_freq;
+ u16 center_freq1;
+ u16 center_freq2;
+ enum nl80211_band band;
+ u8 type;
+};
+
+/* Structure that will contains all RoC information received from cfg80211 */
+struct aicwf_roc_elem {
+ struct wireless_dev *wdev;
+ struct ieee80211_channel *chan;
+ unsigned int duration;
+ u64 cookie;
+ /* Used to avoid call of CFG80211 callback upon expiration of RoC */
+ bool mgmt_roc;
+ /* Indicate if we have switch on the RoC channel */
+ bool on_chan;
+};
+
+/* Structure containing channel survey information received from MAC */
+struct aicwf_survey_info {
+ // Filled
+ u32 filled;
+ // Amount of time in ms the radio spent on the channel
+ u32 chan_time_ms;
+ // Amount of time the primary channel was sensed busy
+ u32 chan_time_busy_ms;
+ // Noise in dbm
+ s8 noise_dbm;
+};
+
+#define AICWF_CH_NOT_SET 0xFF
+#define AICWF_INVALID_VIF 0xFF
+#define AICWF_INVALID_STA 0xFF
+
+/* Structure containing channel context information */
+struct aicwf_chanctx {
+ struct cfg80211_chan_def chan_def; /* channel description */
+ u8 count; /* number of vif using this ctxt */
+};
+
+/**
+ * struct aicwf_phy_info - PHY information
+ *
+ * @cnt: Number of PHY interfaces
+ * @cfg: Configuration sent to the firmware
+ * @sec_chan: Channel configuration of the second PHY interface, when present
+ * @limit_bw: Whether to limit the requested channel bandwidth for legacy PHYs
+ */
+struct aicwf_phy_info {
+ u8 cnt;
+ struct phy_cfg_tag cfg;
+ struct aicwf_sec_phy_chan sec_chan;
+ bool limit_bw;
+};
+
+struct defrag_ctrl_info {
+ struct list_head list;
+ u8 sta_idx;
+ u8 tid;
+ u16 sn;
+ u8 next_fn;
+ u16 frm_len;
+ struct sk_buff *skb;
+ struct timer_list defrag_timer;
+ struct aicwf_hw *aicwf_hw;
+};
+
+struct amsdu_subframe_hdr {
+ u8 da[6];
+ u8 sa[6];
+ u16 sublen;
+};
+
+enum aicwf_drv_connect_status {
+ AICWF_DRV_STATUS_DISCONNECTED = 0,
+ AICWF_DRV_STATUS_DISCONNECTING,
+ AICWF_DRV_STATUS_CONNECTING,
+ AICWF_DRV_STATUS_CONNECTED,
+ AICWF_DRV_STATUS_ROAMING,
+};
+
+struct aicwf_hw {
+ struct aicwf_mod_params *mod_params;
+ struct device *dev;
+ struct aic_sdio_dev *sdiodev;
+ struct wiphy *wiphy;
+ struct list_head vifs;
+ struct aicwf_vif *
+ vif_table[NX_VIRT_DEV_MAX + NX_REMOTE_STA_MAX]; /* indexed with fw id */
+ struct aicwf_sta sta_table[NX_REMOTE_STA_MAX + NX_VIRT_DEV_MAX];
+ struct aicwf_survey_info survey[SCAN_CHANNEL_MAX];
+ /* Serializes scan ownership, completion and the scan activity reference. */
+ spinlock_t scan_lock;
+ struct cfg80211_scan_request *scan_request;
+ /* The normal scan path owns one SDIO activity until its terminal event. */
+ atomic_t scan_activity_held;
+#ifdef CONFIG_AIC8800_SCHED_SCAN
+ struct cfg80211_sched_scan_request *sched_scan_req;
+#endif
+ struct aicwf_chanctx chanctx_table[NX_CHAN_CTXT_CNT];
+ u8 cur_chanctx;
+
+ u8 monitor_vif; /* FW id of the monitor interface, AICWF_INVALID_VIF if no
+ * monitor vif at fw level
+ */
+
+ /* RoC Management */
+ /* Information provided by cfg80211 in its remain on channel request */
+ struct aicwf_roc_elem *roc_elem;
+
+ struct aicwf_cmd_mgr *cmd_mgr;
+
+ struct aicwf_plat *plat;
+
+ spinlock_t tx_lock; //
+ spinlock_t cb_lock; //
+ struct mutex mutex; /* per-device perimeter lock */
+
+ struct tasklet_struct task;
+ struct mm_version_cfm
+ version_cfm; /* Lower layers versions - obtained via MM_VERSION_REQ */
+
+ u32 tcp_pacing_shift;
+
+ struct sdio_host_env_tag sdio_env;
+
+ struct kmem_cache *sw_txhdr_cache;
+
+ struct aicwf_stats stats;
+
+#ifdef CONFIG_PREALLOC_TXQ
+ struct aicwf_txq *txq;
+#else
+ struct aicwf_txq txq[NX_NB_TXQ];
+#endif
+
+ struct aicwf_hwq hwq[NX_TXQ_CNT];
+
+ u64 avail_idx_map;
+ u8 vif_started;
+ bool adding_sta;
+ struct aicwf_phy_info phy;
+
+ struct aicwf_radar radar;
+
+ /* extended capabilities supported */
+ u8 ext_capa[8];
+
+#ifdef CONFIG_AICWF_MUMIMO_TX
+ struct aicwf_mu_info mu;
+#endif
+ u8 is_p2p_alive;
+ u8 is_p2p_connected;
+ struct timer_list p2p_alive_timer;
+ struct aicwf_vif *p2p_dev_vif;
+ atomic_t p2p_alive_timer_count;
+ bool band_5g_support;
+ /* cfg80211 updates these per-device channel and capability copies. */
+ struct ieee80211_supported_band bands[2];
+ struct ieee80211_channel channels_2ghz[MAC_DOMAINCHANNEL_24G_MAX];
+ struct ieee80211_channel channels_5ghz[MAC_DOMAINCHANNEL_5G_MAX];
+ struct ieee80211_sband_iftype_data he_capa[1];
+ /* Serialize channel configuration requests and their confirmations. */
+ struct mutex reg_lock;
+ struct completion chan_config_complete;
+ /* A failed update requires reprobe before transmitting again. */
+ bool regdom_failed;
+ int tx_power_limit;
+ u8 vendor_info;
+ bool fwlog_en;
+ int testmode;
+ u8 scanning;
+ const struct aic_chip_ops *chip_ops;
+ u8 chip_id;
+ u8 chip_sub_id;
+ /* Configuration parsed from the userconfig and nvram files */
+ struct userconfig_info_t userconfig;
+ struct nvram_info_t nvram;
+
+ struct list_head defrag_list;
+ struct list_head defrag_expired_list;
+ /* Protects both lists, their objects and defrag_stopping. */
+ spinlock_t defrag_lock;
+ bool defrag_stopping;
+
+ struct work_struct apm_staloss_work;
+ struct workqueue_struct *apm_staloss_wq;
+ u8 apm_vif_idx;
+ u8 sta_mac_addr[6];
+
+ struct wakeup_source *ws_rx;
+ struct wakeup_source *ws_irqrx;
+ struct wakeup_source *ws_tx;
+ struct wakeup_source *ws_pwrctrl;
+ struct wakeup_source *ws_scan;
+
+#ifdef CONFIG_AIC8800_SCHED_SCAN
+ bool is_sched_scan;
+#endif
+
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+ unsigned long started_jiffies;
+ s8 temp;
+#endif
+ char fw_version[32];
+
+};
+
+static inline const u8 *aicwf_sta_addr(struct aicwf_sta *aicwf_sta)
+{
+ return aicwf_sta->mac_addr;
+}
+
+static inline bool is_multicast_sta(struct aicwf_hw *aicwf_hw, int sta_idx)
+{
+ if (aicwf_hw->chip_ops->is_old_ic)
+ return (sta_idx >= NX_REMOTE_STA_MAX_FOR_OLD_IC);
+ else
+ return (sta_idx >= NX_REMOTE_STA_MAX);
+}
+
+static inline uint8_t master_vif_idx(struct aicwf_vif *vif)
+{
+#if IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ return vif->vif_index;
+#else
+ if (unlikely(vif->wdev.iftype == NL80211_IFTYPE_AP_VLAN))
+ return vif->ap_vlan.master->vif_index;
+ else
+ return vif->vif_index;
+#endif
+}
+
+u8 *aicwf_build_bcn(struct aicwf_bcn *bcn, struct cfg80211_beacon_data *new);
+void aicwf_chanctx_link(struct aicwf_vif *vif, u8 idx,
+ struct cfg80211_chan_def *chandef);
+void aicwf_chanctx_unlink(struct aicwf_vif *vif);
+int aicwf_chanctx_valid(struct aicwf_hw *aicwf_hw, u8 idx);
+void aicwf_set_conn_state(atomic_t *drv_conn_state, int state);
+struct aicwf_sta *aicwf_get_sta(struct aicwf_hw *aicwf_hw, const u8 *mac_addr);
+void aicwf_external_auth_enable(struct aicwf_vif *vif);
+void aicwf_external_auth_disable(struct aicwf_vif *vif);
+bool aicwf_scan_complete(struct aicwf_hw *aicwf_hw, struct wireless_dev *wdev,
+ bool aborted);
+
+#endif /* _AICWF_DEFS_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_events.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_events.h
new file mode 100644
index 000000000000..a0b7787b16a3
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_events.h
@@ -0,0 +1,938 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief Trace events definition
+ *
+ ******************************************************************************
+ */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM aicwf
+
+#if !defined(_AICWF_EVENTS_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _AICWF_EVENTS_H
+
+#include <linux/tracepoint.h>
+#include "aicwf_tx.h"
+
+#include "aicwf_config.h"
+
+/*****************************************************************************
+ * TRACE function for MGMT TX (FULLMAC)
+ ****************************************************************************/
+#ifdef CONFIG_AICWF_FULLMAC
+#include "linux/ieee80211.h"
+#if defined(CONFIG_TRACEPOINTS) && defined(AIC8800_CREATE_TRACE_POINTS) && \
+ !defined(TRACE_HEADER_MULTI_READ)
+#include <linux/trace_seq.h>
+
+/* P2P Public Action Frames Definitions (see WiFi P2P Technical Specification,
+ * section 4.2.8)
+ */
+/* IEEE 802.11 Public Action Usage Category - Define P2P public action frames */
+#define MGMT_ACTION_PUBLIC_CAT (0x04)
+/* Offset of OUI Subtype field in P2P Action Frame format */
+#define MGMT_ACTION_OUI_SUBTYPE_OFFSET (6)
+/* P2P Public Action Frame Types */
+enum p2p_action_type {
+ P2P_ACTION_GO_NEG_REQ = 0, /* GO Negociation Request */
+ P2P_ACTION_GO_NEG_RSP, /* GO Negociation Response */
+ P2P_ACTION_GO_NEG_CFM, /* GO Negociation Confirmation */
+ P2P_ACTION_INVIT_REQ, /* P2P Invitation Request */
+ P2P_ACTION_INVIT_RSP, /* P2P Invitation Response */
+ P2P_ACTION_DEV_DISC_REQ, /* Device Discoverability Request */
+ P2P_ACTION_DEV_DISC_RSP, /* Device Discoverability Response */
+ P2P_ACTION_PROV_DISC_REQ, /* Provision Discovery Request */
+ P2P_ACTION_PROV_DISC_RSP, /* Provision Discovery Response */
+};
+
+static inline const char *ftrace_print_mgmt_info(struct trace_seq *p,
+ u16 frame_control, u8 cat, u8 type,
+ u8 p2p)
+{
+ const char *ret = trace_seq_buffer_ptr(p);
+
+ switch (frame_control & IEEE80211_FCTL_STYPE) {
+ case (IEEE80211_STYPE_ASSOC_REQ):
+ trace_seq_printf(p, "Association Request");
+ break;
+ case (IEEE80211_STYPE_ASSOC_RESP):
+ trace_seq_printf(p, "Association Response");
+ break;
+ case (IEEE80211_STYPE_REASSOC_REQ):
+ trace_seq_printf(p, "Reassociation Request");
+ break;
+ case (IEEE80211_STYPE_REASSOC_RESP):
+ trace_seq_printf(p, "Reassociation Response");
+ break;
+ case (IEEE80211_STYPE_PROBE_REQ):
+ trace_seq_printf(p, "Probe Request");
+ break;
+ case (IEEE80211_STYPE_PROBE_RESP):
+ trace_seq_printf(p, "Probe Response");
+ break;
+ case (IEEE80211_STYPE_BEACON):
+ trace_seq_printf(p, "Beacon");
+ break;
+ case (IEEE80211_STYPE_ATIM):
+ trace_seq_printf(p, "ATIM");
+ break;
+ case (IEEE80211_STYPE_DISASSOC):
+ trace_seq_printf(p, "Disassociation");
+ break;
+ case (IEEE80211_STYPE_AUTH):
+ trace_seq_printf(p, "Authentication");
+ break;
+ case (IEEE80211_STYPE_DEAUTH):
+ trace_seq_printf(p, "Deauthentication");
+ break;
+ case (IEEE80211_STYPE_ACTION):
+ trace_seq_printf(p, "Action");
+ if (cat == MGMT_ACTION_PUBLIC_CAT && type == 0x9) {
+ switch (p2p) {
+ case (P2P_ACTION_GO_NEG_REQ):
+ trace_seq_printf(p, ": GO Negociation Request");
+ break;
+ case (P2P_ACTION_GO_NEG_RSP):
+ trace_seq_printf(p, ": GO Negociation Response");
+ break;
+ case (P2P_ACTION_GO_NEG_CFM):
+ trace_seq_printf(p, ": GO Negociation Confirmation");
+ break;
+ case (P2P_ACTION_INVIT_REQ):
+ trace_seq_printf(p, ": P2P Invitation Request");
+ break;
+ case (P2P_ACTION_INVIT_RSP):
+ trace_seq_printf(p, ": P2P Invitation Response");
+ break;
+ case (P2P_ACTION_DEV_DISC_REQ):
+ trace_seq_printf(p, ": Device Discoverability Request");
+ break;
+ case (P2P_ACTION_DEV_DISC_RSP):
+ trace_seq_printf(p, ": Device Discoverability Response");
+ break;
+ case (P2P_ACTION_PROV_DISC_REQ):
+ trace_seq_printf(p, ": Provision Discovery Request");
+ break;
+ case (P2P_ACTION_PROV_DISC_RSP):
+ trace_seq_printf(p, ": Provision Discovery Response");
+ break;
+ default:
+ trace_seq_printf(p, "Unknown p2p %d", p2p);
+ break;
+ }
+ } else {
+ switch (cat) {
+ case 0:
+ trace_seq_printf(p, ":Spectrum %d", type);
+ break;
+ case 1:
+ trace_seq_printf(p, ":QOS %d", type);
+ break;
+ case 2:
+ trace_seq_printf(p, ":DLS %d", type);
+ break;
+ case 3:
+ trace_seq_printf(p, ":BA %d", type);
+ break;
+ case 4:
+ trace_seq_printf(p, ":Public %d", type);
+ break;
+ case 5:
+ trace_seq_printf(p, ":Radio Measure %d", type);
+ break;
+ case 6:
+ trace_seq_printf(p, ":Fast BSS %d", type);
+ break;
+ case 7:
+ trace_seq_printf(p, ":HT Action %d", type);
+ break;
+ case 8:
+ trace_seq_printf(p, ":SA Query %d", type);
+ break;
+ case 9:
+ trace_seq_printf(p, ":Protected Public %d", type);
+ break;
+ case 10:
+ trace_seq_printf(p, ":WNM %d", type);
+ break;
+ case 11:
+ trace_seq_printf(p, ":Unprotected WNM %d", type);
+ break;
+ case 12:
+ trace_seq_printf(p, ":TDLS %d", type);
+ break;
+ case 13:
+ trace_seq_printf(p, ":Mesh %d", type);
+ break;
+ case 14:
+ trace_seq_printf(p, ":MultiHop %d", type);
+ break;
+ case 15:
+ trace_seq_printf(p, ":Self Protected %d", type);
+ break;
+ case 126:
+ trace_seq_printf(p, ":Vendor protected");
+ break;
+ case 127:
+ trace_seq_printf(p, ":Vendor");
+ break;
+ default:
+ trace_seq_printf(p, ":Unknown category %d", cat);
+ break;
+ }
+ }
+ break;
+ default:
+ trace_seq_printf(p, "Unknown subtype %d",
+ frame_control & IEEE80211_FCTL_STYPE);
+ break;
+ }
+
+ trace_seq_putc(p, 0);
+
+ return ret;
+}
+#endif /* defined(CONFIG_TRACEPOINTS) && defined(AIC8800_CREATE_TRACE_POINTS) */
+
+#undef __print_mgmt_info
+#define __print_mgmt_info(frame_control, cat, type, p2p) \
+ ftrace_print_mgmt_info(p, frame_control, cat, type, p2p)
+
+TRACE_EVENT(roc, TP_PROTO(u8 vif_idx, u16 freq, unsigned int duration),
+ TP_ARGS(vif_idx, freq, duration),
+ TP_STRUCT__entry(__field(u8, vif_idx) __field(u16, freq)
+ __field(unsigned int, duration)),
+ TP_fast_assign(__entry->vif_idx = vif_idx; __entry->freq = freq;
+ __entry->duration = duration;),
+ TP_printk("f=%d vif=%d dur=%d", __entry->freq, __entry->vif_idx,
+ __entry->duration));
+
+TRACE_EVENT(cancel_roc, TP_PROTO(u8 vif_idx), TP_ARGS(vif_idx),
+ TP_STRUCT__entry(__field(u8, vif_idx)),
+ TP_fast_assign(__entry->vif_idx = vif_idx;),
+ TP_printk("vif=%d", __entry->vif_idx));
+
+TRACE_EVENT(roc_exp, TP_PROTO(u8 vif_idx), TP_ARGS(vif_idx),
+ TP_STRUCT__entry(__field(u8, vif_idx)),
+ TP_fast_assign(__entry->vif_idx = vif_idx;),
+ TP_printk("vif=%d", __entry->vif_idx));
+
+TRACE_EVENT(switch_roc, TP_PROTO(u8 vif_idx), TP_ARGS(vif_idx),
+ TP_STRUCT__entry(__field(u8, vif_idx)),
+ TP_fast_assign(__entry->vif_idx = vif_idx;),
+ TP_printk("vif=%d", __entry->vif_idx));
+
+DECLARE_EVENT_CLASS(mgmt_template,
+ TP_PROTO(u16 freq, u8 vif_idx, u8 sta_idx, struct ieee80211_mgmt *mgmt),
+ TP_ARGS(freq, vif_idx, sta_idx, mgmt),
+ TP_STRUCT__entry(__field(u16, freq) __field(u8, vif_idx)
+ __field(u8, sta_idx) __field(u16, frame_control)
+ __field(u8, action_cat) __field(u8, action_type)
+ __field(u8, action_p2p)),
+ TP_fast_assign(__entry->freq = freq; __entry->vif_idx = vif_idx;
+ __entry->sta_idx = sta_idx;
+ __entry->frame_control = le16_to_cpu(mgmt->frame_control);
+ __entry->action_cat = mgmt->u.action.category;
+ __entry->action_type = mgmt->u.action.action_code;
+ __entry->action_p2p = *((u8 *)&mgmt->u.action.category +
+ MGMT_ACTION_OUI_SUBTYPE_OFFSET);),
+ TP_printk("f=%d vif=%d sta=%d -> %s", __entry->freq, __entry->vif_idx,
+ __entry->sta_idx,
+ __print_mgmt_info(__entry->frame_control, __entry->action_cat,
+ __entry->action_type, __entry->action_p2p)));
+
+DEFINE_EVENT(mgmt_template, mgmt_tx,
+ TP_PROTO(u16 freq, u8 vif_idx, u8 sta_idx,
+ struct ieee80211_mgmt *mgmt),
+ TP_ARGS(freq, vif_idx, sta_idx, mgmt));
+
+DEFINE_EVENT(mgmt_template, mgmt_rx,
+ TP_PROTO(u16 freq, u8 vif_idx, u8 sta_idx,
+ struct ieee80211_mgmt *mgmt),
+ TP_ARGS(freq, vif_idx, sta_idx, mgmt));
+
+TRACE_EVENT(mgmt_cfm, TP_PROTO(u8 vif_idx, u8 sta_idx, bool acked),
+ TP_ARGS(vif_idx, sta_idx, acked),
+ TP_STRUCT__entry(__field(u8, vif_idx) __field(u8, sta_idx)
+ __field(bool, acked)),
+ TP_fast_assign(__entry->vif_idx = vif_idx;
+ __entry->sta_idx = sta_idx; __entry->acked = acked;),
+ TP_printk("vif=%d sta=%d ack=%d", __entry->vif_idx,
+ __entry->sta_idx, __entry->acked));
+#endif /* CONFIG_AICWF_FULLMAC */
+
+/*****************************************************************************
+ * TRACE function for TXQ
+ ****************************************************************************/
+
+#if defined(CONFIG_TRACEPOINTS) && defined(AIC8800_CREATE_TRACE_POINTS) && \
+ !defined(TRACE_HEADER_MULTI_READ)
+
+#include <linux/trace_seq.h>
+#include <linux/trace_events.h>
+
+static inline const char *ftrace_print_txq(struct trace_seq *p, int txq_idx)
+{
+ const char *ret = trace_seq_buffer_ptr(p);
+
+ if (txq_idx == TXQ_INACTIVE) {
+ trace_seq_printf(p, "[INACTIVE]");
+ } else if (txq_idx < NX_FIRST_VIF_TXQ_IDX) {
+ trace_seq_printf(p, "[STA %d/%d]", txq_idx / NX_NB_TXQ_PER_STA,
+ txq_idx % NX_NB_TXQ_PER_STA);
+#ifdef CONFIG_AICWF_FULLMAC
+ } else if (txq_idx < NX_FIRST_UNK_TXQ_IDX) {
+ trace_seq_printf(p, "[BC/MC %d]", txq_idx - NX_FIRST_BCMC_TXQ_IDX);
+ } else if (txq_idx < NX_OFF_CHAN_TXQ_IDX) {
+ trace_seq_printf(p, "[UNKNOWN %d]", txq_idx - NX_FIRST_UNK_TXQ_IDX);
+ } else if (txq_idx == NX_OFF_CHAN_TXQ_IDX) {
+ trace_seq_printf(p, "[OFFCHAN]");
+#else
+ } else if (txq_idx < NX_NB_TXQ) {
+ txq_idx -= NX_FIRST_VIF_TXQ_IDX;
+ trace_seq_printf(p, "[VIF %d/%d]", txq_idx / NX_NB_TXQ_PER_VIF,
+ txq_idx % NX_NB_TXQ_PER_VIF);
+#endif
+ } else {
+ trace_seq_printf(p, "[ERROR %d]", txq_idx);
+ }
+
+ trace_seq_putc(p, 0);
+
+ return ret;
+}
+
+static inline const char *ftrace_print_sta(struct trace_seq *p, int sta_idx)
+{
+ const char *ret = trace_seq_buffer_ptr(p);
+
+ if (sta_idx < NX_REMOTE_STA_MAX)
+ trace_seq_printf(p, "[STA %d]", sta_idx);
+ else
+ trace_seq_printf(p, "[BC/MC %d]", sta_idx - NX_REMOTE_STA_MAX);
+
+ trace_seq_putc(p, 0);
+
+ return ret;
+}
+
+static inline const char *ftrace_print_hwq(struct trace_seq *p, int hwq_idx)
+{
+ static const struct trace_print_flags symbols[] = {{AICWF_HWQ_BK, "BK"},
+ {AICWF_HWQ_BE, "BE"},
+ {AICWF_HWQ_VI, "VI"},
+ {AICWF_HWQ_VO, "VO"},
+#ifdef CONFIG_AICWF_FULLMAC
+ {AICWF_HWQ_BCMC, "BCMC"},
+#else
+ {AICWF_HWQ_BCN, "BCN"},
+#endif
+ {-1, NULL}};
+ return trace_print_symbols_seq(p, hwq_idx, symbols, ARRAY_SIZE(symbols));
+}
+
+static inline const char *ftrace_print_hwq_cred(struct trace_seq *p, u8 *cred)
+{
+ const char *ret = trace_seq_buffer_ptr(p);
+
+#if NX_USER_MAX == 1
+ trace_seq_printf(p, "%d", cred[0]);
+#else
+ int i;
+
+ for (i = 0; i < NX_USER_MAX - 1; i++)
+ trace_seq_printf(p, "%d-", cred[i]);
+ trace_seq_printf(p, "%d", cred[i]);
+#endif
+
+ trace_seq_putc(p, 0);
+ return ret;
+}
+
+static inline const char *ftrace_print_mu_info(struct trace_seq *p, u8 mu_info)
+{
+ const char *ret = trace_seq_buffer_ptr(p);
+
+ if (mu_info)
+ trace_seq_printf(p, "MU: %d-%d", (mu_info & 0x3f), (mu_info >> 6));
+
+ trace_seq_putc(p, 0);
+ return ret;
+}
+
+static inline const char *ftrace_print_mu_group(struct trace_seq *p, int nb_user,
+ u8 *users)
+{
+ const char *ret = trace_seq_buffer_ptr(p);
+ int i;
+
+ if (users[0] != 0xff)
+ trace_seq_printf(p, "(%d", users[0]);
+ else
+ trace_seq_printf(p, "(-");
+ for (i = 1; i < NX_USER_MAX; i++) {
+ if (users[i] != 0xff)
+ trace_seq_printf(p, ",%d", users[i]);
+ else
+ trace_seq_printf(p, ",-");
+ }
+
+ trace_seq_printf(p, ")");
+ trace_seq_putc(p, 0);
+ return ret;
+}
+
+static inline const char *ftrace_print_amsdu(struct trace_seq *p, u16 nb_pkt)
+{
+ const char *ret = trace_seq_buffer_ptr(p);
+
+ if (nb_pkt > 1)
+ trace_seq_printf(p, "(AMSDU %d)", nb_pkt);
+
+ trace_seq_putc(p, 0);
+ return ret;
+}
+#endif /* defined(CONFIG_TRACEPOINTS) && defined(AIC8800_CREATE_TRACE_POINTS) */
+
+#undef __print_txq
+#define __print_txq(txq_idx) ftrace_print_txq(p, txq_idx)
+
+#undef __print_sta
+#define __print_sta(sta_idx) ftrace_print_sta(p, sta_idx)
+
+#undef __print_hwq
+#define __print_hwq(hwq) ftrace_print_hwq(p, hwq)
+
+#undef __print_hwq_cred
+#define __print_hwq_cred(cred) ftrace_print_hwq_cred(p, cred)
+
+#undef __print_mu_info
+#define __print_mu_info(mu_info) ftrace_print_mu_info(p, mu_info)
+
+#undef __print_mu_group
+#define __print_mu_group(nb, users) ftrace_print_mu_group(p, nb, users)
+
+#undef __print_amsdu
+#define __print_amsdu(nb_pkt) ftrace_print_amsdu(p, nb_pkt)
+
+#ifdef CONFIG_AICWF_FULLMAC
+
+TRACE_EVENT(txq_select, TP_PROTO(int txq_idx, u16 pkt_ready_up, struct sk_buff *skb),
+ TP_ARGS(txq_idx, pkt_ready_up, skb),
+ TP_STRUCT__entry(__field(u16, txq_idx) __field(u16, pkt_ready)
+ __field(struct sk_buff *, skb)),
+ TP_fast_assign(__entry->txq_idx = txq_idx;
+ __entry->pkt_ready = pkt_ready_up; __entry->skb = skb;),
+ TP_printk("%s pkt_ready_up=%d skb=%p", __print_txq(__entry->txq_idx),
+ __entry->pkt_ready, __entry->skb));
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+DECLARE_EVENT_CLASS(hwq_template, TP_PROTO(u8 hwq_idx), TP_ARGS(hwq_idx),
+ TP_STRUCT__entry(__field(u8, hwq_idx)),
+ TP_fast_assign(__entry->hwq_idx = hwq_idx;),
+ TP_printk("%s", __print_hwq(__entry->hwq_idx)));
+
+DEFINE_EVENT(hwq_template, hwq_flowctrl_stop, TP_PROTO(u8 hwq_idx),
+ TP_ARGS(hwq_idx));
+
+DEFINE_EVENT(hwq_template, hwq_flowctrl_start, TP_PROTO(u8 hwq_idx),
+ TP_ARGS(hwq_idx));
+
+DECLARE_EVENT_CLASS(txq_template, TP_PROTO(struct aicwf_txq *txq), TP_ARGS(txq),
+ TP_STRUCT__entry(__field(u16, txq_idx)),
+ TP_fast_assign(__entry->txq_idx = txq->idx;),
+ TP_printk("%s", __print_txq(__entry->txq_idx)));
+
+DEFINE_EVENT(txq_template, txq_add_to_hw, TP_PROTO(struct aicwf_txq *txq),
+ TP_ARGS(txq));
+
+DEFINE_EVENT(txq_template, txq_del_from_hw, TP_PROTO(struct aicwf_txq *txq),
+ TP_ARGS(txq));
+
+#ifdef CONFIG_AICWF_FULLMAC
+
+DEFINE_EVENT(txq_template, txq_flowctrl_stop, TP_PROTO(struct aicwf_txq *txq),
+ TP_ARGS(txq));
+
+DEFINE_EVENT(txq_template, txq_flowctrl_restart, TP_PROTO(struct aicwf_txq *txq),
+ TP_ARGS(txq));
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+TRACE_EVENT(process_txq, TP_PROTO(struct aicwf_txq *txq), TP_ARGS(txq),
+ TP_STRUCT__entry(__field(u16, txq_idx) __field(u16, len)
+ __field(u16, len_retry) __field(s8, credit)
+#ifdef CONFIG_AICWF_FULLMAC
+ __field(u16, limit)
+#endif /* CONFIG_AICWF_FULLMAC */
+ ),
+ TP_fast_assign(__entry->txq_idx = txq->idx;
+ __entry->len = skb_queue_len(&txq->sk_list);
+#ifdef CONFIG_MAC80211_TXQ
+ __entry->len += txq->nb_ready_mac80211;
+#endif
+ __entry->len_retry = txq->nb_retry;
+ __entry->credit = txq->credits;
+#ifdef CONFIG_AICWF_FULLMAC
+ __entry->limit = txq->push_limit;
+#endif /* CONFIG_AICWF_FULLMAC */
+ ),
+#ifdef CONFIG_AICWF_FULLMAC
+ TP_printk("%s txq_credits=%d, len=%d, retry_len=%d, push_limit=%d",
+ __print_txq(__entry->txq_idx), __entry->credit,
+ __entry->len, __entry->len_retry, __entry->limit)
+#else
+ TP_printk("%s txq_credits=%d, len=%d, retry_len=%d",
+ __print_txq(__entry->txq_idx), __entry->credit,
+ __entry->len, __entry->len_retry)
+#endif /* CONFIG_AICWF_FULLMAC */
+);
+
+DECLARE_EVENT_CLASS(txq_reason_template, TP_PROTO(struct aicwf_txq *txq, u16 reason),
+ TP_ARGS(txq, reason),
+ TP_STRUCT__entry(__field(u16, txq_idx) __field(u16, reason)
+ __field(u16, status)),
+ TP_fast_assign(__entry->txq_idx = txq->idx; __entry->reason = reason;
+ __entry->status = txq->status;),
+ TP_printk("%s reason=%s status=%s", __print_txq(__entry->txq_idx),
+ __print_symbolic(__entry->reason, {AICWF_TXQ_STOP_FULL, "FULL"},
+ {AICWF_TXQ_STOP_CSA, "CSA"},
+ {AICWF_TXQ_STOP_STA_PS, "PS"},
+ {AICWF_TXQ_STOP_VIF_PS, "VPS"},
+ {AICWF_TXQ_STOP_CHAN, "CHAN"},
+ {AICWF_TXQ_STOP_MU_POS, "MU"}),
+ __print_flags(__entry->status, "|",
+ {AICWF_TXQ_IN_HWQ_LIST, "IN LIST"},
+ {AICWF_TXQ_STOP_FULL, "FULL"},
+ {AICWF_TXQ_STOP_CSA, "CSA"},
+ {AICWF_TXQ_STOP_STA_PS, "PS"},
+ {AICWF_TXQ_STOP_VIF_PS, "VPS"},
+ {AICWF_TXQ_STOP_CHAN, "CHAN"},
+ {AICWF_TXQ_STOP_MU_POS, "MU"},
+ {AICWF_TXQ_NDEV_FLOW_CTRL, "FLW_CTRL"})));
+
+DEFINE_EVENT(txq_reason_template, txq_start,
+ TP_PROTO(struct aicwf_txq *txq, u16 reason), TP_ARGS(txq, reason));
+
+DEFINE_EVENT(txq_reason_template, txq_stop,
+ TP_PROTO(struct aicwf_txq *txq, u16 reason), TP_ARGS(txq, reason));
+
+TRACE_EVENT(push_desc,
+ TP_PROTO(struct sk_buff *skb, struct aicwf_sw_txhdr *sw_txhdr, int push_flags),
+ TP_ARGS(skb, sw_txhdr, push_flags),
+ TP_STRUCT__entry(__field(struct sk_buff *, skb) __field(unsigned int, len)
+ __field(u16, tx_queue) __field(u8, hw_queue)
+ __field(u8, push_flag) __field(u32, flag)
+ __field(s8, txq_cred) __field(u8, hwq_cred)
+ __field(u16, pkt_cnt)
+ __field(u8, mu_info)),
+ TP_fast_assign(__entry->skb = skb; __entry->tx_queue = sw_txhdr->txq->idx;
+ __entry->push_flag = push_flags;
+ __entry->hw_queue = sw_txhdr->txq->hwq->id;
+ __entry->txq_cred = sw_txhdr->txq->credits;
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+ __entry->pkt_cnt = sw_txhdr->desc.host.packet_cnt;
+#endif
+#ifdef CONFIG_AICWF_FULLMAC
+ __entry->flag = sw_txhdr->desc.host.flags;
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ if (sw_txhdr->amsdu.len)
+ __entry->len = sw_txhdr->amsdu.len;
+ else
+#endif /* CONFIG_AICWF_AMSDUS_TX */
+ __entry->len = sw_txhdr->desc.host.packet_len[0];
+#else
+ __entry->len = sw_txhdr->desc.host.packet_len;
+#endif /* CONFIG_AICWF_SPLIT_TX_BUF */
+#else /* !CONFIG_AICWF_FULLMAC */
+ __entry->flag = sw_txhdr->desc.umac.flags;
+ __entry->len = sw_txhdr->frame_len;
+ __entry->sn = sw_txhdr->sn;
+#endif /* CONFIG_AICWF_FULLMAC */
+#ifdef CONFIG_AICWF_MUMIMO_TX
+ __entry->mu_info = sw_txhdr->desc.host.mumimo_info;
+#else
+ __entry->mu_info = 0;
+#endif
+ ),
+#ifdef CONFIG_AICWF_FULLMAC
+ TP_printk("%s skb=%p (len=%d) hw_queue=%s cred_txq=%d cred_hwq=%d %s flag=%s %s %s %s",
+ __print_txq(__entry->tx_queue), __entry->skb, __entry->len,
+ __print_hwq(__entry->hw_queue), __entry->txq_cred,
+ __entry->hwq_cred, __print_mu_info(__entry->mu_info),
+ __print_flags(__entry->flag, "|", {TXU_CNTRL_RETRY, "RETRY"},
+ {TXU_CNTRL_MORE_DATA, "MOREDATA"}, {TXU_CNTRL_MGMT, "MGMT"},
+ {TXU_CNTRL_MGMT_NO_CCK, "NO_CCK"},
+ {TXU_CNTRL_MGMT_ROBUST, "ROBUST"}, {TXU_CNTRL_AMSDU, "AMSDU"},
+ {TXU_CNTRL_USE_4ADDR, "4ADDR"}, {TXU_CNTRL_EOSP, "EOSP"},
+ {TXU_CNTRL_MESH_FWD, "MESH_FWD"}, {TXU_CNTRL_TDLS, "TDLS"}),
+ (__entry->push_flag & AICWF_PUSH_IMMEDIATE) ? "(IMMEDIATE)" : "",
+ (!(__entry->flag & TXU_CNTRL_RETRY) &&
+ (__entry->push_flag & AICWF_PUSH_RETRY))
+ ? "(SW_RETRY)" : "",
+ __print_amsdu(__entry->pkt_cnt))
+#else
+ TP_printk("%s skb=%p (len=%d) hw_queue=%s cred_txq=%d cred_hwq=%d %s flag=%x (%s) sn=%d %s",
+ __print_txq(__entry->tx_queue), __entry->skb, __entry->len,
+ __print_hwq(__entry->hw_queue), __entry->txq_cred,
+ __entry->hwq_cred, __print_mu_info(__entry->mu_info),
+ __entry->flag,
+ __print_flags(__entry->push_flag, "|", {AICWF_PUSH_RETRY, "RETRY"},
+ {AICWF_PUSH_IMMEDIATE, "IMMEDIATE"}),
+ __entry->sn, __print_amsdu(__entry->pkt_cnt))
+#endif /* CONFIG_AICWF_FULLMAC */
+);
+
+TRACE_EVENT(txq_queue_skb, TP_PROTO(struct sk_buff *skb, struct aicwf_txq *txq, bool retry),
+ TP_ARGS(skb, txq, retry),
+ TP_STRUCT__entry(__field(struct sk_buff *, skb) __field(u16, txq_idx)
+ __field(s8, credit) __field(u16, q_len)
+ __field(u16, q_len_retry) __field(bool, retry)),
+ TP_fast_assign(__entry->skb = skb; __entry->txq_idx = txq->idx;
+ __entry->credit = txq->credits;
+ __entry->q_len = skb_queue_len(&txq->sk_list);
+ __entry->q_len_retry = txq->nb_retry;
+ __entry->retry = retry;),
+ TP_printk("%s skb=%p retry=%d txq_credits=%d queue_len=%d (retry = %d)",
+ __print_txq(__entry->txq_idx), __entry->skb, __entry->retry,
+ __entry->credit, __entry->q_len, __entry->q_len_retry));
+
+#ifdef CONFIG_MAC80211_TXQ
+TRACE_EVENT(txq_wake, TP_PROTO(struct aicwf_txq *txq), TP_ARGS(txq),
+ TP_STRUCT__entry(__field(u16, txq_idx) __field(u16, q_len)),
+ TP_fast_assign(__entry->txq_idx = txq->idx;
+ __entry->q_len = txq->nb_ready_mac80211;),
+ TP_printk("%s mac80211_queue_len=%d", __print_txq(__entry->txq_idx),
+ __entry->q_len));
+
+TRACE_EVENT(txq_drop, TP_PROTO(struct aicwf_txq *txq, unsigned long nb_drop),
+ TP_ARGS(txq, nb_drop),
+ TP_STRUCT__entry(__field(u16, txq_idx) __field(u16, nb_drop)),
+ TP_fast_assign(__entry->txq_idx = txq->idx;
+ __entry->nb_drop = nb_drop;),
+ TP_printk("%s %u pkt have been dropped by codel in mac80211 txq",
+ __print_txq(__entry->txq_idx), __entry->nb_drop));
+
+#endif
+
+DECLARE_EVENT_CLASS(idx_template, TP_PROTO(u16 idx), TP_ARGS(idx),
+ TP_STRUCT__entry(__field(u16, idx)),
+ TP_fast_assign(__entry->idx = idx;),
+ TP_printk("idx=%d", __entry->idx));
+
+DEFINE_EVENT(idx_template, txq_vif_start, TP_PROTO(u16 idx), TP_ARGS(idx));
+
+DEFINE_EVENT(idx_template, txq_vif_stop, TP_PROTO(u16 idx), TP_ARGS(idx));
+
+TRACE_EVENT(process_hw_queue, TP_PROTO(struct aicwf_hwq *hwq), TP_ARGS(hwq),
+ TP_STRUCT__entry(__field(u16, hwq)
+ __array(u8, credits, NX_USER_MAX)),
+ TP_fast_assign(__entry->hwq = hwq->id;),
+ TP_printk("hw_queue=%s hw_credits=%s", __print_hwq(__entry->hwq),
+ __print_hwq_cred(__entry->credits)));
+
+DECLARE_EVENT_CLASS(sta_idx_template, TP_PROTO(u16 idx), TP_ARGS(idx),
+ TP_STRUCT__entry(__field(u16, idx)),
+ TP_fast_assign(__entry->idx = idx;),
+ TP_printk("%s", __print_sta(__entry->idx)));
+
+DEFINE_EVENT(sta_idx_template, txq_sta_start, TP_PROTO(u16 idx), TP_ARGS(idx));
+
+DEFINE_EVENT(sta_idx_template, txq_sta_stop, TP_PROTO(u16 idx), TP_ARGS(idx));
+
+#ifdef CONFIG_AICWF_FULLMAC
+
+DEFINE_EVENT(sta_idx_template, ps_disable, TP_PROTO(u16 idx), TP_ARGS(idx));
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+TRACE_EVENT(skb_confirm,
+ #ifdef CONFIG_AICWF_FULLMAC
+ TP_PROTO(struct sk_buff *skb, struct aicwf_txq *txq,
+ struct aicwf_hwq *hwq, struct tx_cfm_tag *cfm),
+ #else
+ TP_PROTO(struct sk_buff *skb, struct aicwf_txq *txq,
+ struct aicwf_hwq *hwq, u8 cfm),
+ #endif
+ TP_ARGS(skb, txq, hwq, cfm),
+ TP_STRUCT__entry(__field(struct sk_buff *, skb) __field(u16, txq_idx)
+ __field(u8, hw_queue) __array(u8, hw_credit, NX_USER_MAX)
+ __field(s8, sw_credit) __field(s8, sw_credit_up)
+#ifdef CONFIG_AICWF_FULLMAC
+ __field(u8, ampdu_size)
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+ __field(u16, amsdu)
+#endif /* CONFIG_AICWF_SPLIT_TX_BUF */
+ __field(u16, sn)
+#endif /* CONFIG_AICWF_FULLMAC */
+ ),
+ TP_fast_assign(__entry->skb = skb; __entry->txq_idx = txq->idx;
+ __entry->hw_queue = hwq->id;
+ __entry->sw_credit = txq->credits;
+#if defined CONFIG_AICWF_FULLMAC
+ __entry->sw_credit_up = cfm->credits;
+ __entry->ampdu_size = cfm->ampdu_size;
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+ __entry->amsdu = cfm->amsdu_size; __entry->sn = cfm->sn;
+#endif
+#else
+ __entry->sw_credit_up = cfm
+#endif /* CONFIG_AICWF_FULLMAC */
+ ),
+ TP_printk("%s skb=%p hw_queue=%s, hw_credits=%s, txq_credits=%d (+%d)"
+#ifdef CONFIG_AICWF_FULLMAC
+ " sn=%u ampdu=%d"
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+ " amsdu=%u"
+#endif
+#endif
+ ,
+ __print_txq(__entry->txq_idx), __entry->skb,
+ __print_hwq(__entry->hw_queue),
+ __print_hwq_cred(__entry->hw_credit), __entry->sw_credit,
+ __entry->sw_credit_up
+#ifdef CONFIG_AICWF_FULLMAC
+ ,
+ __entry->sn, __entry->ampdu_size
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+ ,
+ __entry->amsdu
+#endif
+#endif
+ ));
+
+TRACE_EVENT(credit_update, TP_PROTO(struct aicwf_txq *txq, s8 cred_up),
+ TP_ARGS(txq, cred_up),
+ TP_STRUCT__entry(__field(struct sk_buff *, skb)
+ __field(u16, txq_idx) __field(s8, sw_credit)
+ __field(s8, sw_credit_up)),
+ TP_fast_assign(__entry->txq_idx = txq->idx;
+ __entry->sw_credit = txq->credits;
+ __entry->sw_credit_up = cred_up;),
+ TP_printk("%s txq_credits=%d (%+d)", __print_txq(__entry->txq_idx),
+ __entry->sw_credit, __entry->sw_credit_up))
+#ifdef CONFIG_AICWF_FULLMAC
+DECLARE_EVENT_CLASS(ps_template, TP_PROTO(struct aicwf_sta *sta), TP_ARGS(sta),
+ TP_STRUCT__entry(__field(u16, idx) __field(u16, ready_ps)
+ __field(u16, sp_ps) __field(u16, ready_uapsd)
+ __field(u16, sp_uapsd)),
+ TP_fast_assign(__entry->idx = sta->sta_idx;
+ __entry->ready_ps = sta->ps.pkt_ready[LEGACY_PS_ID];
+ __entry->sp_ps = sta->ps.sp_cnt[LEGACY_PS_ID];
+ __entry->ready_uapsd = sta->ps.pkt_ready[UAPSD_ID];
+ __entry->sp_uapsd = sta->ps.sp_cnt[UAPSD_ID];),
+ TP_printk("%s [PS] ready=%d sp=%d [UAPSD] ready=%d sp=%d",
+ __print_sta(__entry->idx), __entry->ready_ps, __entry->sp_ps,
+ __entry->ready_uapsd, __entry->sp_uapsd));
+
+DEFINE_EVENT(ps_template, ps_queue, TP_PROTO(struct aicwf_sta *sta), TP_ARGS(sta));
+
+DEFINE_EVENT(ps_template, ps_push, TP_PROTO(struct aicwf_sta *sta), TP_ARGS(sta));
+
+DEFINE_EVENT(ps_template, ps_enable, TP_PROTO(struct aicwf_sta *sta), TP_ARGS(sta));
+
+TRACE_EVENT(ps_traffic_update, TP_PROTO(u16 sta_idx, u8 traffic, bool uapsd),
+ TP_ARGS(sta_idx, traffic, uapsd),
+ TP_STRUCT__entry(__field(u16, sta_idx) __field(u8, traffic)
+ __field(bool, uapsd)),
+ TP_fast_assign(__entry->sta_idx = sta_idx;
+ __entry->traffic = traffic; __entry->uapsd = uapsd;),
+ TP_printk("%s %s%s traffic available ",
+ __print_sta(__entry->sta_idx),
+ __entry->traffic ? "" : "no more ",
+ __entry->uapsd ? "U-APSD" : "legacy PS"));
+
+TRACE_EVENT(ps_traffic_req, TP_PROTO(struct aicwf_sta *sta, u16 pkt_req, u8 ps_id),
+ TP_ARGS(sta, pkt_req, ps_id),
+ TP_STRUCT__entry(__field(u16, idx) __field(u16, pkt_req)
+ __field(u8, ps_id) __field(u16, ready)
+ __field(u16, sp)),
+ TP_fast_assign(__entry->idx = sta->sta_idx;
+ __entry->pkt_req = pkt_req; __entry->ps_id = ps_id;
+ __entry->ready = sta->ps.pkt_ready[ps_id];
+ __entry->sp = sta->ps.sp_cnt[ps_id];),
+ TP_printk("%s %s traffic request %d pkt (ready=%d, sp=%d)",
+ __print_sta(__entry->idx),
+ __entry->ps_id == UAPSD_ID ? "U-APSD" : "legacy PS",
+ __entry->pkt_req, __entry->ready, __entry->sp));
+
+#ifdef CONFIG_AICWF_AMSDUS_TX
+TRACE_EVENT(amsdu_subframe, TP_PROTO(struct aicwf_sw_txhdr *sw_txhdr),
+ TP_ARGS(sw_txhdr),
+ TP_STRUCT__entry(__field(struct sk_buff *, skb)
+ __field(u16, txq_idx) __field(u8, nb)
+ __field(u32, len)),
+ TP_fast_assign(__entry->skb = sw_txhdr->skb;
+ __entry->nb = sw_txhdr->amsdu.nb;
+ __entry->len = sw_txhdr->amsdu.len;
+ __entry->txq_idx = sw_txhdr->txq->idx;),
+ TP_printk("%s skb=%p %s nb_subframe=%d, len=%u",
+ __print_txq(__entry->txq_idx), __entry->skb,
+ (__entry->nb == 2) ? "Start new AMSDU" : "Add subframe",
+ __entry->nb, __entry->len));
+#endif
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+#ifdef CONFIG_AICWF_MUMIMO_TX
+TRACE_EVENT(mu_group_update, TP_PROTO(struct aicwf_mu_group *group),
+ TP_ARGS(group),
+ TP_STRUCT__entry(__field(u8, nb_user) __field(u8, group_id)
+ __array(u8, users, NX_USER_MAX)),
+ TP_fast_assign(int i; __entry->nb_user = group->user_cnt;
+ for (i = 0; i < NX_USER_MAX; i++) {
+ if (group->users[i])
+ __entry->users[i] = group->users[i]->sta_idx;
+ else
+ __entry->users[i] = 0xff;
+ }
+ __entry->group_id = group->group_id;),
+ TP_printk("Group-id = %d, Users = %s", __entry->group_id,
+ __print_mu_group(__entry->nb_user, __entry->users)));
+
+TRACE_EVENT(mu_group_delete, TP_PROTO(int group_id), TP_ARGS(group_id),
+ TP_STRUCT__entry(__field(u8, group_id)),
+ TP_fast_assign(__entry->group_id = group_id;),
+ TP_printk("Group-id = %d", __entry->group_id));
+
+TRACE_EVENT(mu_group_selection, TP_PROTO(struct aicwf_sta *sta, int group_id),
+ TP_ARGS(sta, group_id),
+ TP_STRUCT__entry(__field(u8, sta_idx) __field(u8, group_id)),
+ TP_fast_assign(__entry->sta_idx = sta->sta_idx;
+ __entry->group_id = group_id;),
+ TP_printk("[Sta %d] Group-id = %d", __entry->sta_idx,
+ __entry->group_id));
+
+TRACE_EVENT(txq_select_mu_group,
+ TP_PROTO(struct aicwf_txq *txq, int group_id, int pos),
+ TP_ARGS(txq, group_id, pos),
+ TP_STRUCT__entry(__field(u16, txq_idx) __field(u8, group_id)
+ __field(u8, pos)),
+ TP_fast_assign(__entry->txq_idx = txq->idx;
+ __entry->group_id = group_id; __entry->pos = pos;),
+ TP_printk("%s: group=%d pos=%d", __print_txq(__entry->txq_idx),
+ __entry->group_id, __entry->pos));
+
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+
+/*****************************************************************************
+ * TRACE functions for MESH
+ ****************************************************************************/
+#ifdef CONFIG_AICWF_FULLMAC
+DECLARE_EVENT_CLASS(mesh_path_template, TP_PROTO(struct aicwf_mesh_path *mesh_path),
+ TP_ARGS(mesh_path),
+ TP_STRUCT__entry(__field(u8, idx) __field(u8, next_hop_sta)
+ __array(u8, tgt_mac, ETH_ALEN)),
+ TP_fast_assign(__entry->idx = mesh_path->path_idx;
+ memcpy(__entry->tgt_mac, &mesh_path->tgt_mac_addr, ETH_ALEN);
+ if (mesh_path->p_nhop_sta)
+ __entry->next_hop_sta = mesh_path->p_nhop_sta->sta_idx;
+ else
+ __entry->next_hop_sta = 0xff;),
+ TP_printk("Mpath(%d): target=%pM next_hop=STA-%d", __entry->idx,
+ __entry->tgt_mac, __entry->next_hop_sta));
+
+DEFINE_EVENT(mesh_path_template, mesh_create_path,
+ TP_PROTO(struct aicwf_mesh_path *mesh_path), TP_ARGS(mesh_path));
+
+DEFINE_EVENT(mesh_path_template, mesh_delete_path,
+ TP_PROTO(struct aicwf_mesh_path *mesh_path), TP_ARGS(mesh_path));
+
+DEFINE_EVENT(mesh_path_template, mesh_update_path,
+ TP_PROTO(struct aicwf_mesh_path *mesh_path), TP_ARGS(mesh_path));
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+/*****************************************************************************
+ * TRACE functions for RADAR
+ ****************************************************************************/
+#ifdef CONFIG_AICWF_RADAR
+TRACE_EVENT(radar_pulse, TP_PROTO(u8 chain, struct radar_pulse *pulse),
+ TP_ARGS(chain, pulse),
+ TP_STRUCT__entry(__field(u8, chain) __field(s16, freq)
+ __field(u16, pri) __field(u8, len)
+ __field(u8, fom)),
+ TP_fast_assign(__entry->freq = pulse->freq * 2;
+ __entry->len = pulse->len * 2;
+ __entry->fom = pulse->fom * 6;
+ __entry->pri = pulse->rep; __entry->chain = chain;),
+ TP_printk("%s: PRI=%.5d LEN=%.3d FOM=%.2d%% freq=%dMHz ",
+ __print_symbolic(__entry->chain, {AICWF_RADAR_RIU, "RIU"},
+ {AICWF_RADAR_FCU, "FCU"}),
+ __entry->pri, __entry->len, __entry->fom, __entry->freq));
+
+TRACE_EVENT(radar_detected, TP_PROTO(u8 chain, u8 region, s16 freq, u8 type, u16 pri),
+ TP_ARGS(chain, region, freq, type, pri),
+ TP_STRUCT__entry(__field(u8, chain) __field(u8, region) __field(s16, freq)
+ __field(u8, type) __field(u16, pri)),
+ TP_fast_assign(__entry->chain = chain; __entry->region = region;
+ __entry->freq = freq; __entry->type = type;
+ __entry->pri = pri;),
+ TP_printk("%s: region=%s type=%d freq=%dMHz (pri=%dus)",
+ __print_symbolic(__entry->chain, {AICWF_RADAR_RIU, "RIU"},
+ {AICWF_RADAR_FCU, "FCU"}),
+ __print_symbolic(__entry->region, {NL80211_DFS_UNSET, "UNSET"},
+ {NL80211_DFS_FCC, "FCC"},
+ {NL80211_DFS_ETSI, "ETSI"},
+ {NL80211_DFS_JP, "JP"}),
+ __entry->type, __entry->freq, __entry->pri));
+
+TRACE_EVENT(radar_set_region, TP_PROTO(u8 region), TP_ARGS(region),
+ TP_STRUCT__entry(__field(u8, region)),
+ TP_fast_assign(__entry->region = region;),
+ TP_printk("region=%s",
+ __print_symbolic(__entry->region,
+ {NL80211_DFS_UNSET, "UNSET"},
+ {NL80211_DFS_FCC, "FCC"},
+ {NL80211_DFS_ETSI, "ETSI"},
+ {NL80211_DFS_JP, "JP"})));
+
+TRACE_EVENT(radar_enable_detection, TP_PROTO(u8 region, u8 enable, u8 chain),
+ TP_ARGS(region, enable, chain),
+ TP_STRUCT__entry(__field(u8, region) __field(u8, chain)
+ __field(u8, enable)),
+ TP_fast_assign(__entry->chain = chain; __entry->enable = enable;
+ __entry->region = region;),
+ TP_printk("%s: %s radar detection %s",
+ __print_symbolic(__entry->chain, {AICWF_RADAR_RIU, "RIU"},
+ {AICWF_RADAR_FCU, "FCU"}),
+ __print_symbolic(__entry->enable,
+ {AICWF_RADAR_DETECT_DISABLE, "Disable"},
+ {AICWF_RADAR_DETECT_ENABLE,
+ "Enable (no report)"},
+ {AICWF_RADAR_DETECT_REPORT, "Enable"}),
+ __entry->enable == AICWF_RADAR_DETECT_DISABLE
+ ? "" : __print_symbolic(__entry->region,
+ {NL80211_DFS_UNSET, "UNSET"},
+ {NL80211_DFS_FCC, "FCC"},
+ {NL80211_DFS_ETSI, "ETSI"},
+ {NL80211_DFS_JP, "JP"})));
+#endif /* CONFIG_AICWF_RADAR */
+
+/*****************************************************************************
+ * TRACE functions for IPC message
+ ****************************************************************************/
+#include "aicwf_strs.h"
+
+DECLARE_EVENT_CLASS(ipc_msg_template, TP_PROTO(u16 id), TP_ARGS(id),
+ TP_STRUCT__entry(__field(u16, id)),
+ TP_fast_assign(__entry->id = id;),
+ TP_printk("%s (%d - %d)", AICWF_ID2STR(__entry->id),
+ MSG_T(__entry->id), MSG_I(__entry->id)));
+
+DEFINE_EVENT(ipc_msg_template, msg_send, TP_PROTO(u16 id), TP_ARGS(id));
+
+DEFINE_EVENT(ipc_msg_template, msg_recv, TP_PROTO(u16 id), TP_ARGS(id));
+
+#endif /* !defined(_AICWF_EVENTS_H) || defined(TRACE_HEADER_MULTI_READ) */
+
+#undef TRACE_INCLUDE_PATH
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_PATH AIC_TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_FILE aicwf_events
+#include <trace/define_trace.h>
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_main.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_main.h
new file mode 100644
index 000000000000..8820a46deb33
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_main.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_MAIN_H_
+#define _AICWF_MAIN_H_
+
+#include <linux/delay.h>
+
+#include "aicwf_defs.h"
+
+int aicwf_cfg80211_init(struct aicwf_plat *aicwf_plat, void **platform_data);
+void aicwf_cfg80211_deinit(struct aicwf_hw *aicwf_hw);
+int aicwf_ic_rf_init(struct aicwf_hw *aicwf_hw);
+int aicwf_ic_system_init(struct aicwf_hw *aicwf_hw);
+void aicwf_update_mesh_power_mode(struct aicwf_vif *vif);
+void aicwf_p2p_alive_timeout(struct timer_list *t);
+void apm_staloss_work_process(struct work_struct *work);
+void apm_probe_sta_work_process(struct work_struct *work);
+
+#endif /* _AICWF_MAIN_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mesh.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mesh.h
new file mode 100644
index 000000000000..80b205d4e880
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mesh.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_MESH_H_
+#define _AICWF_MESH_H_
+
+/*
+ * INCLUDE FILES
+ ****************************************************************************************
+ */
+
+#include "aicwf_defs.h"
+
+/*
+ * DEFINES
+ ****************************************************************************************
+ */
+
+/*
+ * TYPE DEFINITIONS
+ ****************************************************************************************
+ */
+
+/*
+ * FUNCTION DECLARATIONS
+ ****************************************************************************************
+ */
+
+/*
+ ****************************************************************************************
+ * @brief TODO [LT]
+ ****************************************************************************************
+ */
+struct aicwf_mesh_proxy *aicwf_get_mesh_proxy_info(struct aicwf_vif *p_aicwf_vif,
+ u8 *p_sta_addr, bool local);
+
+#endif /* _AICWF_MESH_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mod_params.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mod_params.h
new file mode 100644
index 000000000000..f02fc955aae4
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mod_params.h
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_MOD_PARAM_H_
+#define _AICWF_MOD_PARAM_H_
+
+struct aicwf_mod_params {
+ bool ht_on;
+ bool vht_on;
+ bool he_on;
+ int mcs_map;
+ int he_mcs_map;
+ bool he_ul_on;
+ bool ldpc_on;
+ bool stbc_on;
+ bool gf_rx_on;
+ int phy_cfg;
+ int uapsd_timeout;
+ bool ap_uapsd_on;
+ bool sgi;
+ bool sgi80;
+ bool use_2040;
+ bool use_80;
+ int nss;
+ int amsdu_rx_max;
+ bool bfmee;
+ bool bfmer;
+ bool mesh;
+ bool murx;
+ bool mutx;
+ bool mutx_on;
+ unsigned int roc_dur_max;
+ int listen_itv;
+ bool listen_bcmc;
+ int lp_clk_ppm;
+ bool ps_on;
+ int tx_lft;
+ int amsdu_maxnb;
+ int uapsd_queues;
+ bool tdls;
+ bool uf;
+ bool auto_reply;
+ char *ftl;
+ bool dpsm;
+#ifdef CONFIG_AICWF_FULLMAC
+ bool ant_div;
+#endif /* CONFIG_AICWF_FULLMAC */
+};
+
+extern struct aicwf_mod_params aicwf_mod_params;
+
+struct aicwf_hw;
+struct wiphy;
+int aicwf_handle_dynparams(struct aicwf_hw *aicwf_hw, struct wiphy *wiphy);
+void aicwf_enable_wapi(struct aicwf_hw *aicwf_hw);
+
+#endif /* _AICWF_MOD_PARAM_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_rx.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_rx.c
new file mode 100644
index 000000000000..687b76eb323f
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_rx.c
@@ -0,0 +1,1412 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief RX function definitions
+ *
+ ******************************************************************************
+ */
+
+#include "aicwf_defs.h"
+#include "aicwf_tx.h"
+#include "aicwf_rx.h"
+#include <linux/rtnetlink.h>
+#include <linux/vmalloc.h>
+#ifdef CONFIG_AICWF_BFMER
+#include "aicwf_bfmer.h"
+#endif //(CONFIG_AICWF_BFMER)
+#ifdef CONFIG_AICWF_FULLMAC
+#include "aicwf_msg_tx.h"
+#endif /* CONFIG_AICWF_FULLMAC */
+#include "aicwf_txrxif.h"
+#include "aicwf_sdio.h"
+#include "aicwf_config.h"
+#include "aicwf_events.h"
+#include "aicwf_msg_rx.h"
+#include "aicwf_mod_params.h"
+#include <linux/pm.h>
+
+void aicwf_cfg80211_unlink_bss(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif);
+
+static int aicwf_freq_to_idx(struct aicwf_hw *aicwf_hw, int freq)
+{
+ struct ieee80211_supported_band *sband = NULL;
+ int band, ch, idx = 0;
+
+ for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
+#ifdef CONFIG_AICWF_FULLMAC
+ sband = aicwf_hw->wiphy->bands[band];
+#endif /* CONFIG_AICWF_FULLMAC */
+ if (!sband)
+ continue;
+
+ for (ch = 0; ch < sband->n_channels; ch++, idx++) {
+ if (sband->channels[ch].center_freq == freq)
+ goto exit;
+ }
+ }
+
+ WARN_ON_ONCE(1);
+
+exit:
+ // Channel has been found, return the index
+ return idx;
+}
+
+/***************************************************************************
+ * Messages from MM task
+ **************************************************************************/
+static inline int aicwf_rx_chan_pre_switch_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct aicwf_vif *aicwf_vif;
+ int chan_idx = ((struct mm_channel_pre_switch_ind *)msg->param)->chan_index;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ list_for_each_entry(aicwf_vif, &aicwf_hw->vifs, list) {
+ if (aicwf_vif->up && aicwf_vif->ch_index == chan_idx)
+ aicwf_txq_vif_stop(aicwf_vif, AICWF_TXQ_STOP_CHAN, aicwf_hw);
+ }
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ return 0;
+}
+
+static inline int aicwf_rx_chan_switch_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct aicwf_vif *aicwf_vif;
+ int chan_idx = ((struct mm_channel_switch_ind *)msg->param)->chan_index;
+ bool roc = ((struct mm_channel_switch_ind *)msg->param)->roc;
+ bool roc_tdls = ((struct mm_channel_switch_ind *)msg->param)->roc_tdls;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ if (roc_tdls) {
+ u8 vif_index = ((struct mm_channel_switch_ind *)msg->param)->vif_index;
+
+ list_for_each_entry(aicwf_vif, &aicwf_hw->vifs, list) {
+ if (aicwf_vif->vif_index == vif_index) {
+ aicwf_vif->roc_tdls = true;
+ aicwf_txq_tdls_sta_start(aicwf_vif, AICWF_TXQ_STOP_CHAN, aicwf_hw);
+ }
+ }
+ } else if (!roc) {
+ list_for_each_entry(aicwf_vif, &aicwf_hw->vifs, list) {
+ if (aicwf_vif->up && aicwf_vif->ch_index == chan_idx)
+ aicwf_txq_vif_start(aicwf_vif, AICWF_TXQ_STOP_CHAN, aicwf_hw);
+ }
+ } else {
+ /* Retrieve the allocated RoC element */
+ struct aicwf_roc_elem *roc_elem = aicwf_hw->roc_elem;
+ /* Get VIF on which RoC has been started */
+ // aicwf_vif = netdev_priv(roc_elem->wdev->netdev);
+
+ /* For debug purpose (use ftrace kernel option) */
+ // trace_switch_roc(aicwf_vif->vif_index);
+
+ if (roc_elem) {
+ /* If mgmt_roc is true, remain on channel has been started by
+ * ourself
+ */
+ if (!roc_elem->mgmt_roc) {
+ /* Inform the host that we have switch on the indicated
+ * off-channel
+ */
+ cfg80211_ready_on_channel(roc_elem->wdev,
+ roc_elem->cookie,
+ roc_elem->chan, roc_elem->duration,
+ GFP_ATOMIC);
+ }
+
+ /* Keep in mind that we have switched on the channel */
+ roc_elem->on_chan = true;
+ } else {
+ dev_dbg(aicwf_hw->dev, "roc_elem == null\n");
+ }
+ // Enable traffic on OFF channel queue
+ aicwf_txq_offchan_start(aicwf_hw);
+ }
+
+ tasklet_schedule(&aicwf_hw->task);
+
+ aicwf_hw->cur_chanctx = chan_idx;
+ aicwf_radar_detection_enable_on_cur_channel(aicwf_hw);
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ return 0;
+}
+
+static inline int aicwf_rx_tdls_chan_switch_cfm(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ return 0;
+}
+
+static inline int aicwf_rx_tdls_chan_switch_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+#ifdef CONFIG_AICWF_FULLMAC
+ // Enable traffic on OFF channel queue
+ aicwf_txq_offchan_start(aicwf_hw);
+
+ return 0;
+#endif
+}
+
+static inline int aicwf_rx_tdls_chan_switch_base_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct aicwf_vif *aicwf_vif;
+ u8 vif_index = ((struct tdls_chan_switch_base_ind *)msg->param)->vif_index;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ list_for_each_entry(aicwf_vif, &aicwf_hw->vifs, list) {
+ if (aicwf_vif->vif_index == vif_index) {
+ aicwf_vif->roc_tdls = false;
+ aicwf_txq_tdls_sta_stop(aicwf_vif, AICWF_TXQ_STOP_CHAN, aicwf_hw);
+ }
+ }
+ return 0;
+#endif
+}
+
+static inline int aicwf_rx_tdls_peer_ps_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct aicwf_vif *aicwf_vif;
+ u8 vif_index = ((struct tdls_peer_ps_ind *)msg->param)->vif_index;
+ bool ps_on = ((struct tdls_peer_ps_ind *)msg->param)->ps_on;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ list_for_each_entry(aicwf_vif, &aicwf_hw->vifs, list) {
+ if (aicwf_vif->vif_index == vif_index) {
+ aicwf_vif->sta.tdls_sta->tdls.ps_on = ps_on;
+ // Update PS status for the TDLS station
+ aicwf_ps_bh_enable(aicwf_hw, aicwf_vif->sta.tdls_sta, ps_on);
+ }
+ }
+
+ return 0;
+#endif
+}
+
+static inline int aicwf_rx_remain_on_channel_exp_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+#ifdef CONFIG_AICWF_FULLMAC
+ /* Retrieve the allocated RoC element */
+ struct aicwf_roc_elem *roc_elem = aicwf_hw->roc_elem;
+ /* Get VIF on which RoC has been started */
+ struct aicwf_vif *aicwf_vif;
+
+ if (!roc_elem)
+ return 0;
+
+ aicwf_vif = container_of(roc_elem->wdev, struct aicwf_vif, wdev);
+ /* For debug purpose (use ftrace kernel option) */
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_roc_exp(aicwf_vif->vif_index);
+#endif
+ /* If mgmt_roc is true, remain on channel has been started by ourself */
+ /* If RoC has been cancelled before we switched on channel, do not call
+ * cfg80211
+ */
+ if (!roc_elem->mgmt_roc && roc_elem->on_chan) {
+ /* Inform the host that off-channel period has expired */
+ cfg80211_remain_on_channel_expired(roc_elem->wdev,
+ roc_elem->cookie,
+ roc_elem->chan, GFP_ATOMIC);
+ }
+
+ /* De-init offchannel TX queue */
+ aicwf_txq_offchan_deinit(aicwf_vif);
+
+ /* Free the allocated RoC element */
+ kfree(roc_elem);
+ aicwf_hw->roc_elem = NULL;
+
+#endif /* CONFIG_AICWF_FULLMAC */
+ return 0;
+}
+
+static inline int aicwf_rx_p2p_vif_ps_change_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ int vif_idx = ((struct mm_p2p_vif_ps_change_ind *)msg->param)->vif_index;
+ int ps_state = ((struct mm_p2p_vif_ps_change_ind *)msg->param)->ps_state;
+ struct aicwf_vif *vif_entry;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ vif_entry = aicwf_hw->vif_table[vif_idx];
+
+ if (vif_entry)
+ goto found_vif;
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ goto exit;
+found_vif:
+
+#ifdef CONFIG_AICWF_FULLMAC
+ if (ps_state == MM_PS_MODE_OFF) {
+ // Start TX queues for provided VIF
+ aicwf_txq_vif_start(vif_entry, AICWF_TXQ_STOP_VIF_PS, aicwf_hw);
+ } else {
+ // Stop TX queues for provided VIF
+ aicwf_txq_vif_stop(vif_entry, AICWF_TXQ_STOP_VIF_PS, aicwf_hw);
+ }
+#endif /* CONFIG_AICWF_FULLMAC */
+
+exit:
+ return 0;
+}
+
+static inline int aicwf_rx_channel_survey_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mm_channel_survey_ind *ind =
+ (struct mm_channel_survey_ind *)msg->param;
+ // Get the channel index
+ int idx = aicwf_freq_to_idx(aicwf_hw, ind->freq);
+ // Get the survey
+ struct aicwf_survey_info *aicwf_survey;
+
+ if (idx > ARRAY_SIZE(aicwf_hw->survey))
+ return 0;
+
+ aicwf_survey = &aicwf_hw->survey[idx];
+
+ // Store the received parameters
+ aicwf_survey->chan_time_ms = ind->chan_time_ms;
+ aicwf_survey->chan_time_busy_ms = ind->chan_time_busy_ms;
+ aicwf_survey->noise_dbm = ind->noise_dbm;
+ aicwf_survey->filled = (SURVEY_INFO_TIME | SURVEY_INFO_TIME_BUSY);
+
+ if (ind->noise_dbm != 0)
+ aicwf_survey->filled |= SURVEY_INFO_NOISE_DBM;
+
+ return 0;
+}
+
+static inline int aicwf_rx_p2p_noa_upd_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ return 0;
+}
+
+static inline int aicwf_rx_rssi_status_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mm_rssi_status_ind *ind = (struct mm_rssi_status_ind *)msg->param;
+ int vif_idx = ind->vif_index;
+ bool rssi_status = ind->rssi_status;
+
+ struct aicwf_vif *vif_entry;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ vif_entry = aicwf_hw->vif_table[vif_idx];
+ if (vif_entry) {
+ cfg80211_cqm_rssi_notify(vif_entry->ndev,
+ rssi_status ? NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
+ : NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
+ ind->rssi, GFP_ATOMIC);
+ }
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ return 0;
+}
+
+static inline int aicwf_rx_pktloss_notify_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+#ifdef CONFIG_AICWF_FULLMAC
+ struct mm_pktloss_ind *ind = (struct mm_pktloss_ind *)msg->param;
+ struct aicwf_vif *vif_entry;
+ int vif_idx = ind->vif_index;
+
+ vif_entry = aicwf_hw->vif_table[vif_idx];
+ if (vif_entry) {
+ cfg80211_cqm_pktloss_notify(vif_entry->ndev,
+ (const u8 *)ind->mac_addr.array,
+ ind->num_packets, GFP_ATOMIC);
+ }
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ return 0;
+}
+
+static inline int aicwf_apm_staloss_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mm_apm_staloss_ind *ind = (struct mm_apm_staloss_ind *)msg->param;
+
+ memcpy(aicwf_hw->sta_mac_addr, ind->mac_addr, 6);
+ aicwf_hw->apm_vif_idx = ind->vif_idx;
+
+ queue_work(aicwf_hw->apm_staloss_wq, &aicwf_hw->apm_staloss_work);
+
+ return 0;
+}
+
+static struct sk_buff *arp_80211_to_8023(struct sk_buff *skb, u8 hdrlen)
+{
+ struct ethhdr *eth;
+ size_t payload_len;
+ struct sk_buff *new_skb = NULL;
+ char *llc;
+ u8 da[MAC_ADDR_LEN] = {0};
+ u8 sa[MAC_ADDR_LEN] = {0};
+
+ if (skb->len <= hdrlen) {
+ pr_err("skb_len err1\n");
+ return NULL;
+ }
+
+ memcpy(da, &skb->data[4], 6);
+ memcpy(sa, &skb->data[16], 6);
+
+ skb_pull(skb, hdrlen);
+ llc = skb->data;
+ if (llc[0] == 0xAA && llc[1] == 0xAA && llc[2] == 0x03) {
+ if (skb->len < 8) {
+ pr_err("skb_len err2\n");
+ return NULL;
+ }
+ skb_pull(skb, 8);
+ }
+ payload_len = skb->len;
+
+ new_skb = __dev_alloc_skb(ETH_HLEN + payload_len, GFP_ATOMIC);
+ if (!new_skb)
+ return NULL;
+
+ skb_reserve(new_skb, ETH_HLEN);
+ skb_put(new_skb, payload_len);
+ memcpy(new_skb->data, skb->data, payload_len);
+
+ eth = (struct ethhdr *)skb_push(new_skb, ETH_HLEN);
+
+ memcpy(eth->h_dest, da, ETH_ALEN);
+ memcpy(eth->h_source, sa, ETH_ALEN);
+
+ eth->h_proto = htons(ETH_P_ARP);
+
+ new_skb->protocol = eth->h_proto;
+ new_skb->dev = skb->dev;
+
+ return new_skb;
+}
+
+static inline int aicwf_arp_announcement_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct aicwf_vif *vif;
+ struct sk_buff *skb = NULL;
+ struct sk_buff *new_skb = NULL;
+ struct hw_rxhdr rxhdr;
+ int hdrlen = 24;
+ struct rxu_arp_announcement_ind *ind = (struct rxu_arp_announcement_ind *)msg->param;
+
+ // ind->vif_index, ind->length, ind->offset);
+
+ dev_dbg(aicwf_hw->dev, "vif: %d, length: %d, offset: %d\n",
+ ind->vif_index, ind->length, ind->offset);
+
+ vif = aicwf_hw->vif_table[ind->vif_index];
+ rxhdr.flags_is_amsdu = false;
+ rxhdr.flags_dst_idx = 0xff;
+
+ if (ind->payload[0] & 0x80)
+ hdrlen += 2;
+
+ switch ((ind->rx_status >> 2) & 0x7) {
+ case AICWF_RX_HD_DECR_CCMP128:
+ hdrlen += 8;
+ break;
+ case AICWF_RX_HD_DECR_TKIP:
+ hdrlen += 8;
+ break;
+ case AICWF_RX_HD_DECR_WEP:
+ hdrlen += 4;
+ break;
+ case AICWF_RX_HD_DECR_WAPI:
+ hdrlen += 18;
+ break;
+ default:
+ break;
+ }
+
+ skb = __dev_alloc_skb(ind->length, GFP_ATOMIC);
+ if (!skb)
+ return -1;
+ skb_put(skb, ind->length);
+ memcpy(skb->data, ind->payload, ind->length);
+ skb->dev = vif->ndev;
+
+ new_skb = arp_80211_to_8023(skb, hdrlen);
+ if (!new_skb) {
+ dev_err(aicwf_hw->dev, "arp_80211_to_8023 fail\n");
+ dev_kfree_skb(skb);
+ return -1;
+ }
+ if (!aicwf_rx_data_skb(aicwf_hw, vif, new_skb, &rxhdr)) {
+ dev_err(aicwf_hw->dev, "aicwf_rx_data_skb fail\n");
+ dev_kfree_skb(new_skb);
+ dev_kfree_skb(skb);
+ return -1;
+ }
+
+ dev_kfree_skb(skb);
+ return 0;
+}
+
+static inline int aicwf_rx_csa_counter_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mm_csa_counter_ind *ind = (struct mm_csa_counter_ind *)msg->param;
+ struct aicwf_vif *vif;
+ bool found = false;
+
+ // Look for VIF entry
+ list_for_each_entry(vif, &aicwf_hw->vifs, list) {
+ if (vif->vif_index == ind->vif_index) {
+ found = true;
+ break;
+ }
+ }
+
+ if (found) {
+#ifdef CONFIG_AICWF_FULLMAC
+ if (vif->ap.csa)
+ vif->ap.csa->count = ind->csa_count;
+ else
+ netdev_err(vif->ndev, "csa counter update but no active csa\n");
+
+#endif
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_AICWF_FULLMAC
+static inline int aicwf_rx_csa_finish_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mm_csa_finish_ind *ind = (struct mm_csa_finish_ind *)msg->param;
+ struct aicwf_vif *vif;
+ bool found = false;
+
+ // Look for VIF entry
+ list_for_each_entry(vif, &aicwf_hw->vifs, list) {
+ if (vif->vif_index == ind->vif_index) {
+ found = true;
+ break;
+ }
+ }
+
+ if (found) {
+ if (AICWF_VIF_TYPE(vif) == NL80211_IFTYPE_AP ||
+ AICWF_VIF_TYPE(vif) == NL80211_IFTYPE_P2P_GO) {
+ if (vif->ap.csa) {
+ vif->ap.csa->status = ind->status;
+ vif->ap.csa->ch_idx = ind->chan_idx;
+ schedule_work(&vif->ap.csa->work);
+ } else {
+ netdev_err(vif->ndev,
+ "csa finish indication but no active csa\n");
+ }
+ } else {
+ if (ind->status == 0) {
+ aicwf_chanctx_unlink(vif);
+ aicwf_chanctx_link(vif, ind->chan_idx, NULL);
+ if (aicwf_hw->cur_chanctx == ind->chan_idx) {
+ aicwf_radar_detection_enable_on_cur_channel(aicwf_hw);
+ aicwf_txq_vif_start(vif, AICWF_TXQ_STOP_CHAN, aicwf_hw);
+ } else {
+ aicwf_txq_vif_stop(vif, AICWF_TXQ_STOP_CHAN, aicwf_hw);
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+static inline int aicwf_rx_csa_traffic_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mm_csa_traffic_ind *ind = (struct mm_csa_traffic_ind *)msg->param;
+ struct aicwf_vif *vif;
+ bool found = false;
+
+ // Look for VIF entry
+ list_for_each_entry(vif, &aicwf_hw->vifs, list) {
+ if (vif->vif_index == ind->vif_index) {
+ found = true;
+ break;
+ }
+ }
+
+ if (found) {
+ if (ind->enable)
+ aicwf_txq_vif_start(vif, AICWF_TXQ_STOP_CSA, aicwf_hw);
+ else
+ aicwf_txq_vif_stop(vif, AICWF_TXQ_STOP_CSA, aicwf_hw);
+ }
+
+ return 0;
+}
+
+static inline int aicwf_rx_ps_change_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mm_ps_change_ind *ind = (struct mm_ps_change_ind *)msg->param;
+ struct aicwf_sta *sta = &aicwf_hw->sta_table[ind->sta_idx];
+
+ if (ind->sta_idx >= (NX_REMOTE_STA_MAX + NX_VIRT_DEV_MAX)) {
+ wiphy_err(aicwf_hw->wiphy, "Invalid sta index reported by fw %d\n",
+ ind->sta_idx);
+ return 1;
+ }
+
+ netdev_dbg(aicwf_hw->vif_table[sta->vif_idx]->ndev,
+ "sta %d, change ps mode to %s\n", sta->sta_idx,
+ ind->ps_state ? "on" : "off");
+
+ if (sta->valid) {
+ aicwf_ps_bh_enable(aicwf_hw, sta, ind->ps_state);
+ } else if (aicwf_hw->adding_sta) {
+ sta->ps.active = ind->ps_state ? true : false;
+ } else {
+ if (aicwf_hw->vif_table[sta->vif_idx] &&
+ aicwf_hw->vif_table[sta->vif_idx]->ndev)
+ netdev_err(aicwf_hw->vif_table[sta->vif_idx]->ndev,
+ "ignore ps mode change on invalid sta\n");
+ }
+
+ return 0;
+}
+
+static inline int aicwf_rx_traffic_req_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mm_traffic_req_ind *ind = (struct mm_traffic_req_ind *)msg->param;
+ struct aicwf_sta *sta = &aicwf_hw->sta_table[ind->sta_idx];
+
+ netdev_dbg(aicwf_hw->vif_table[sta->vif_idx]->ndev,
+ "sta %d asked for %d pkt\n", sta->sta_idx, ind->pkt_cnt);
+
+ aicwf_ps_bh_traffic_req(aicwf_hw, sta, ind->pkt_cnt,
+ ind->uapsd ? UAPSD_ID : LEGACY_PS_ID);
+
+ return 0;
+}
+#endif /* CONFIG_AICWF_FULLMAC */
+
+/***************************************************************************
+ * Messages from SCANU task
+ **************************************************************************/
+#ifdef CONFIG_AICWF_FULLMAC
+
+static inline int aicwf_rx_scanu_start_cfm(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ aicwf_scan_complete(aicwf_hw, NULL, false);
+
+ return 0;
+}
+
+static inline int aicwf_rx_scanu_result_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct cfg80211_bss *bss = NULL;
+ struct ieee80211_channel *chan;
+ struct scanu_result_ind *ind = (struct scanu_result_ind *)msg->param;
+ struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)ind->payload;
+ u64 tsf;
+
+ chan = ieee80211_get_channel(aicwf_hw->wiphy, ind->center_freq);
+
+ if (chan) {
+ struct timespec64 ts;
+
+ ts = ktime_to_timespec64(ktime_get_boottime());
+ tsf = (u64)ts.tv_sec * 1000000 + div_u64(ts.tv_nsec, 1000);
+ mgmt->u.probe_resp.timestamp = cpu_to_le64(tsf);
+
+ bss =
+ cfg80211_inform_bss_frame(aicwf_hw->wiphy, chan,
+ (struct ieee80211_mgmt *)ind->payload,
+ ind->length, ind->rssi * 100, GFP_ATOMIC);
+ }
+ if (bss)
+ cfg80211_put_bss(aicwf_hw->wiphy, bss);
+ return 0;
+}
+#endif /* CONFIG_AICWF_FULLMAC */
+
+/***************************************************************************
+ * Messages from ME task
+ **************************************************************************/
+#ifdef CONFIG_AICWF_FULLMAC
+static inline int aicwf_rx_me_tkip_mic_failure_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct me_tkip_mic_failure_ind *ind =
+ (struct me_tkip_mic_failure_ind *)msg->param;
+ struct aicwf_vif *aicwf_vif = aicwf_hw->vif_table[ind->vif_idx];
+ struct net_device *dev = aicwf_vif->ndev;
+
+ cfg80211_michael_mic_failure(dev, (u8 *)&ind->addr,
+ (ind->ga ? NL80211_KEYTYPE_GROUP : NL80211_KEYTYPE_PAIRWISE),
+ ind->keyid, (u8 *)&ind->tsc, GFP_ATOMIC);
+
+ return 0;
+}
+
+static inline int aicwf_rx_me_tx_credits_update_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct me_tx_credits_update_ind *ind =
+ (struct me_tx_credits_update_ind *)msg->param;
+
+ aicwf_txq_credit_update(aicwf_hw, ind->sta_idx, ind->tid, ind->credits);
+
+ return 0;
+}
+#endif /* CONFIG_AICWF_FULLMAC */
+
+/***************************************************************************
+ * Messages from SM task
+ **************************************************************************/
+#ifdef CONFIG_AICWF_FULLMAC
+static inline int aicwf_rx_sm_connect_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct sm_connect_ind *ind = (struct sm_connect_ind *)msg->param;
+ struct aicwf_vif *aicwf_vif = aicwf_hw->vif_table[ind->vif_idx];
+ struct net_device *dev = aicwf_vif->ndev;
+ const u8 *req_ie, *rsp_ie;
+ const struct element *extcap;
+ struct ieee80211_channel *chan;
+ const u8 *ht_ie = NULL;
+ const u8 *vht_ie = NULL;
+
+ /* Retrieve IE addresses and lengths */
+ req_ie = (const u8 *)ind->assoc_ie_buf;
+ rsp_ie = req_ie + ind->assoc_req_ie_len;
+
+ // Fill-in the AP information
+ dev_dbg(aicwf_hw->dev, "ind->status_code:%d\n",
+ ind->status_code);
+
+ if (ind->status_code == 0) {
+ struct aicwf_sta *sta = &aicwf_hw->sta_table[ind->ap_idx];
+ u8 txq_status;
+ struct cfg80211_chan_def chandef;
+
+ sta->valid = true;
+ sta->sta_idx = ind->ap_idx;
+ sta->ch_idx = ind->ch_idx;
+ sta->vif_idx = ind->vif_idx;
+ sta->vlan_idx = sta->vif_idx;
+ sta->qos = ind->qos;
+ sta->acm = ind->acm;
+ sta->ps.active = false;
+ sta->aid = ind->aid;
+ sta->band = ind->band; // ind->chan.band;
+ sta->width = ind->width; // ind->chan.type;
+ sta->center_freq = ind->center_freq; // ind->chan.prim20_freq;
+ sta->center_freq1 = ind->center_freq1; // ind->chan.center1_freq;
+ sta->center_freq2 = ind->center_freq2; // ind->chan.center2_freq;
+ aicwf_vif->sta.ap = sta;
+ // ind->chan.prim20_freq);
+ chan = ieee80211_get_channel(aicwf_hw->wiphy, ind->center_freq);
+ cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
+ if (!aicwf_hw->mod_params->ht_on)
+ chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
+ else
+ chandef.width = chnl2bw[ind->width]; //[ind->chan.type];
+ chandef.center_freq1 = ind->center_freq1; // ind->chan.center1_freq;
+ chandef.center_freq2 = ind->center_freq2; // ind->chan.center2_freq;
+ aicwf_chanctx_link(aicwf_vif, ind->ch_idx, &chandef);
+ memcpy(sta->mac_addr, ind->bssid.array, ETH_ALEN);
+ if (ind->ch_idx == aicwf_hw->cur_chanctx)
+ txq_status = 0;
+ else
+ txq_status = AICWF_TXQ_STOP_CHAN;
+ memcpy(sta->ac_param, ind->ac_param, sizeof(sta->ac_param));
+ aicwf_txq_sta_init(aicwf_hw, sta, txq_status);
+ aicwf_txq_tdls_vif_init(aicwf_vif);
+ aicwf_mu_group_sta_init(sta, NULL);
+ /* Look for TDLS Channel Switch Prohibited flag in the Extended
+ * Capability Information Element
+ */
+ extcap = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, rsp_ie,
+ ind->assoc_rsp_ie_len);
+ if (extcap && extcap->datalen >= 5) {
+ aicwf_vif->tdls_chsw_prohibited =
+ extcap->data[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED;
+ }
+
+ if (aicwf_vif->wep_enabled)
+ aicwf_vif->wep_auth_err = false;
+
+#ifdef CONFIG_AICWF_BFMER
+ /* If Beamformer feature is activated, check if features can be used
+ * with the new peer device
+ */
+ if (aicwf_hw->mod_params->bfmer) {
+ const u8 *vht_capa_ie;
+ const struct ieee80211_vht_cap *vht_cap;
+
+ do {
+ /* Look for VHT Capability Information Element */
+ vht_capa_ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, rsp_ie,
+ ind->assoc_rsp_ie_len);
+
+ /* Stop here if peer device does not support VHT */
+ if (!vht_capa_ie)
+ break;
+
+ vht_cap = (const struct ieee80211_vht_cap *)(vht_capa_ie + 2);
+
+ /* Send MM_BFMER_ENABLE_REQ message if needed */
+ aicwf_send_bfmer_enable(aicwf_hw, sta, vht_cap);
+ } while (0);
+ }
+#endif //(CONFIG_AICWF_BFMER)
+
+ ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, rsp_ie,
+ ind->assoc_rsp_ie_len);
+ if (ht_ie)
+ aicwf_vif->sta.ap->ht = true;
+ vht_ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, rsp_ie,
+ ind->assoc_rsp_ie_len);
+ if (vht_ie)
+ aicwf_vif->sta.ap->vht = true;
+
+#ifdef CONFIG_AICWF_MON_DATA
+ // If there are 1 sta and 1 monitor interface active at the same time
+ // then monitor interface channel context is always the same as the STA
+ // interface. This doesn't work with 2 STA interfaces but we don't want
+ // to support it.
+ if (aicwf_hw->monitor_vif != AICWF_INVALID_VIF) {
+ struct aicwf_vif *aicwf_mon_vif =
+ aicwf_hw->vif_table[aicwf_hw->monitor_vif];
+ aicwf_chanctx_unlink(aicwf_mon_vif);
+ aicwf_chanctx_link(aicwf_mon_vif, ind->ch_idx, NULL);
+ }
+#endif
+ // atomic_set(&aicwf_vif->drv_conn_state,
+ // (int)AICWF_DRV_STATUS_CONNECTED);
+ } else if (ind->status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
+ if (aicwf_vif->wep_enabled) {
+ aicwf_vif->wep_auth_err = true;
+ dev_dbg(aicwf_hw->dev, "con ind wep_auth_err %d\n",
+ aicwf_vif->wep_auth_err);
+ }
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state, (int)AICWF_DRV_STATUS_DISCONNECTED);
+ } else {
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state, (int)AICWF_DRV_STATUS_DISCONNECTED);
+ }
+
+ dev_dbg(aicwf_hw->dev, "ind->roamed:%d ind->status_code:%d aicwf_vif->drv_conn_state:%d\n",
+ ind->roamed, ind->status_code,
+ (int)atomic_read(&aicwf_vif->drv_conn_state));
+
+ if (ind->status_code == 0 &&
+ (int)atomic_read(&aicwf_vif->drv_conn_state) == AICWF_DRV_STATUS_DISCONNECTING) {
+ dev_dbg(aicwf_hw->dev, "the disconnection has been requested, return it\n");
+ goto exit;
+ }
+
+ if (!ind->roamed) { // not roaming
+ cfg80211_connect_result(dev, (const u8 *)ind->bssid.array,
+ req_ie, ind->assoc_req_ie_len,
+ rsp_ie, ind->assoc_rsp_ie_len, ind->status_code,
+ GFP_ATOMIC);
+ if (ind->status_code == 0) {
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state,
+ (int)AICWF_DRV_STATUS_CONNECTED);
+ dev_dbg(aicwf_hw->dev,
+ "cfg80211_connect_result pass, aicwf_vif->drv_conn_state:%d\n",
+ (int)atomic_read(&aicwf_vif->drv_conn_state));
+ aicwf_vif->sta.link_time = jiffies;
+ } else {
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state,
+ (int)AICWF_DRV_STATUS_DISCONNECTED);
+ aicwf_external_auth_disable(aicwf_vif);
+ }
+ } else { // roaming
+ if (ind->status_code != 0) {
+ dev_dbg(aicwf_hw->dev, "roaming fail to notify disconnect\n");
+ cfg80211_disconnected(dev, 0, NULL, 0, 1, GFP_ATOMIC);
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state,
+ (int)AICWF_DRV_STATUS_DISCONNECTED);
+ aicwf_external_auth_disable(aicwf_vif);
+ } else {
+ struct cfg80211_roam_info info;
+
+ memset(&info, 0, sizeof(info));
+ if (aicwf_vif->ch_index < NX_CHAN_CTXT_CNT)
+ info.links[0].channel =
+ aicwf_hw->chanctx_table[aicwf_vif->ch_index].chan_def.chan;
+ info.links[0].bssid = (const u8 *)ind->bssid.array;
+ info.req_ie = req_ie;
+ info.req_ie_len = ind->assoc_req_ie_len;
+ info.resp_ie = rsp_ie;
+ info.resp_ie_len = ind->assoc_rsp_ie_len;
+ cfg80211_roamed(dev, &info, GFP_ATOMIC);
+ aicwf_vif->sta.link_time = jiffies;
+
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state,
+ (int)AICWF_DRV_STATUS_CONNECTED);
+ aicwf_vif->sta.link_time = jiffies;
+ }
+ aicwf_vif->sta.is_roam = false;
+ }
+
+ if (ind->status_code == 0) {
+ netif_tx_start_all_queues(dev);
+ netif_carrier_on(dev);
+ }
+
+exit:
+ aicwf_vif->sta.is_roam = false;
+ return 0;
+}
+
+void aicwf_cfg80211_unlink_bss(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif)
+{
+ struct wiphy *wiphy = aicwf_hw->wiphy;
+ struct cfg80211_bss *bss = NULL;
+
+ bss = cfg80211_get_bss(wiphy, NULL /*notify_channel */, aicwf_vif->sta.bssid,
+ aicwf_vif->sta.ssid, aicwf_vif->sta.ssid_len,
+ IEEE80211_BSS_TYPE_ESS,
+ IEEE80211_PRIVACY(true)); // temp set true
+ if (bss) {
+ cfg80211_unlink_bss(wiphy, bss);
+ dev_dbg(aicwf_hw->dev, "cfg80211_unlink %*pE\n",
+ aicwf_vif->sta.ssid_len, aicwf_vif->sta.ssid);
+ cfg80211_put_bss(wiphy, bss);
+ } else {
+ dev_dbg(aicwf_hw->dev, "cfg80211_unlink error %*pE\n",
+ aicwf_vif->sta.ssid_len, aicwf_vif->sta.ssid);
+ }
+}
+
+static inline int aicwf_rx_sm_disconnect_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct sm_disconnect_ind *ind = (struct sm_disconnect_ind *)msg->param;
+ struct aicwf_vif *aicwf_vif = aicwf_hw->vif_table[ind->vif_idx];
+ struct net_device *dev;
+#ifdef CONFIG_AIC8800_RX_REORDER
+ struct reord_ctrl_info *reord_info, *tmp;
+ u8 *macaddr;
+ struct aicwf_rx_priv *rx_priv;
+#endif
+
+ dev_dbg(aicwf_hw->dev, "reason code:%d\n", ind->reason_code);
+
+ if (!aicwf_vif)
+ return 0;
+
+ if ((int)atomic_read(&aicwf_vif->drv_conn_state) ==
+ (int)AICWF_DRV_STATUS_DISCONNECTED) {
+ dev_dbg(aicwf_hw->dev, "is already disconnected, drop disconnect ind");
+ return 0;
+ }
+
+ dev = aicwf_vif->ndev;
+
+ if (!aicwf_vif->sta.is_roam)
+ aicwf_cfg80211_unlink_bss(aicwf_hw, aicwf_vif);
+ else
+ dev_dbg(aicwf_hw->dev, "roaming no aicwf_cfg80211_unlink_bss\n");
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)
+ aicwf_hw->is_p2p_connected = 0;
+ /* if vif is not up, aicwf_close has already been called */
+ if (aicwf_vif->up) {
+ if (!ind->ft_over_ds && !ind->reassoc) {
+ cfg80211_disconnected(dev, ind->reason_code, NULL, 0,
+ (ind->reason_code < 1), GFP_ATOMIC);
+ }
+ netif_tx_stop_all_queues(dev);
+ netif_carrier_off(dev);
+ }
+
+#ifdef CONFIG_AICWF_BFMER
+ /* Disable Beamformer if supported */
+ aicwf_bfmer_report_del(aicwf_hw, aicwf_vif->sta.ap);
+#endif //(CONFIG_AICWF_BFMER)
+
+#ifdef CONFIG_AIC8800_RX_REORDER
+ rx_priv = aicwf_hw->sdiodev->rx_priv;
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_STATION ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
+ macaddr = (u8 *)aicwf_vif->ndev->dev_addr;
+ dev_dbg(aicwf_hw->dev, "deinit:macaddr:%x,%x,%x,%x,%x,%x\n", macaddr[0], macaddr[1],
+ macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
+
+ // spin_lock_bh(&rx_priv->stas_reord_lock);
+ list_for_each_entry_safe(reord_info, tmp, &rx_priv->stas_reord_list,
+ list) {
+ macaddr = (u8 *)aicwf_vif->ndev->dev_addr;
+ dev_dbg(aicwf_hw->dev, "reord_mac:%x,%x,%x,%x,%x,%x\n",
+ reord_info->mac_addr[0], reord_info->mac_addr[1],
+ reord_info->mac_addr[2], reord_info->mac_addr[3],
+ reord_info->mac_addr[4], reord_info->mac_addr[5]);
+ if (!memcmp(reord_info->mac_addr, macaddr, 6)) {
+ reord_deinit_sta(rx_priv, reord_info);
+ break;
+ }
+ }
+ // spin_unlock_bh(&rx_priv->stas_reord_lock);
+ } else if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_AP ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
+ // WARN_ON_ONCE(); // should be not here: del_sta function
+ }
+#endif
+
+ aicwf_txq_sta_deinit(aicwf_hw, aicwf_vif->sta.ap);
+ aicwf_txq_tdls_vif_deinit(aicwf_vif);
+ aicwf_vif->sta.ap->valid = false;
+ aicwf_vif->sta.ap = NULL;
+ aicwf_external_auth_disable(aicwf_vif);
+ aicwf_chanctx_unlink(aicwf_vif);
+
+ if (!aicwf_vif->sta.is_roam)
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state, (int)AICWF_DRV_STATUS_DISCONNECTED);
+
+ return 0;
+}
+
+static inline int aicwf_rx_sm_external_auth_required_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct sm_external_auth_required_ind *ind =
+ (struct sm_external_auth_required_ind *)msg->param;
+ struct aicwf_vif *aicwf_vif = aicwf_hw->vif_table[ind->vif_idx];
+ struct net_device *dev = aicwf_vif->ndev;
+ struct cfg80211_external_auth_params params;
+ int ret = 0;
+ struct wireless_dev *wdev = dev->ieee80211_ptr;
+ int retry_counter = 10;
+
+ params.action = NL80211_EXTERNAL_AUTH_START;
+ memcpy(params.bssid, ind->bssid.array, ETH_ALEN);
+ params.ssid.ssid_len = ind->ssid.length;
+ memcpy(params.ssid.ssid, ind->ssid.array,
+ min_t(size_t, ind->ssid.length, sizeof(params.ssid.ssid)));
+ params.key_mgmt_suite = ind->akm;
+
+ while (wdev->conn_owner_nlportid == 0) {
+ dev_dbg(aicwf_hw->dev, "conn_owner_nlportid is 0, sleep 100ms\n");
+ msleep(100);
+ retry_counter--;
+ if (retry_counter == 0)
+ break;
+ }
+ dev_dbg(aicwf_hw->dev, "wdev->conn_owner_nlportid:%d\n",
+ (int)wdev->conn_owner_nlportid);
+ ret = cfg80211_external_auth_request(dev, ¶ms, GFP_ATOMIC);
+ if (ind->vif_idx > NX_VIRT_DEV_MAX || !aicwf_vif->up ||
+ AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_STATION ||
+ ret) {
+ wiphy_err(aicwf_hw->wiphy,
+ "Failed to start external auth on vif %d, aicwf_vif->up %d, iftype:%d, ret %d",
+ ind->vif_idx, aicwf_vif->up, AICWF_VIF_TYPE(aicwf_vif), ret);
+ aicwf_send_sm_external_auth_required_rsp(aicwf_hw, aicwf_vif,
+ WLAN_STATUS_UNSPECIFIED_FAILURE);
+ return 0;
+ }
+
+ aicwf_external_auth_enable(aicwf_vif);
+ return 0;
+}
+
+static inline int aicwf_rx_mesh_path_create_cfm(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mesh_path_create_cfm *cfm =
+ (struct mesh_path_create_cfm *)msg->param;
+ struct aicwf_vif *aicwf_vif = aicwf_hw->vif_table[cfm->vif_idx];
+
+ /* Check we well have a Mesh Point Interface */
+ if (aicwf_vif && AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_MESH_POINT)
+ aicwf_vif->ap.create_path = false;
+
+ return 0;
+}
+
+static inline int aicwf_rx_mesh_peer_update_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mesh_peer_update_ind *ind =
+ (struct mesh_peer_update_ind *)msg->param;
+ struct aicwf_vif *aicwf_vif = aicwf_hw->vif_table[ind->vif_idx];
+ struct aicwf_sta *aicwf_sta = &aicwf_hw->sta_table[ind->sta_idx];
+
+ if (ind->vif_idx >= (NX_VIRT_DEV_MAX + NX_REMOTE_STA_MAX) ||
+ (aicwf_vif && AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT) ||
+ ind->sta_idx >= NX_REMOTE_STA_MAX)
+ return 1;
+
+ /* Check we well have a Mesh Point Interface */
+ if (!aicwf_vif->user_mpm) {
+ /* Check if peer link has been established or lost */
+ if (ind->estab) {
+ if (!aicwf_sta->valid) {
+ u8 txq_status;
+
+ aicwf_sta->valid = true;
+ aicwf_sta->sta_idx = ind->sta_idx;
+ aicwf_sta->ch_idx = aicwf_vif->ch_index;
+ aicwf_sta->vif_idx = ind->vif_idx;
+ aicwf_sta->vlan_idx = aicwf_sta->vif_idx;
+ aicwf_sta->ps.active = false;
+ aicwf_sta->qos = true;
+ aicwf_sta->aid = ind->sta_idx + 1;
+ // aicwf_sta->acm = ind->acm;
+ memcpy(aicwf_sta->mac_addr, ind->peer_addr.array, ETH_ALEN);
+
+ aicwf_chanctx_link(aicwf_vif, aicwf_sta->ch_idx, NULL);
+
+ /* Add the station in the list of VIF's stations */
+ INIT_LIST_HEAD(&aicwf_sta->list);
+ list_add_tail(&aicwf_sta->list, &aicwf_vif->ap.sta_list);
+
+ /* Initialize the TX queues */
+ if (aicwf_sta->ch_idx == aicwf_hw->cur_chanctx)
+ txq_status = 0;
+ else
+ txq_status = AICWF_TXQ_STOP_CHAN;
+
+ aicwf_txq_sta_init(aicwf_hw, aicwf_sta, txq_status);
+#ifdef CONFIG_AICWF_BFMER
+ // TODO: update indication to contains vht capabilities
+ if (aicwf_hw->mod_params->bfmer)
+ aicwf_send_bfmer_enable(aicwf_hw, aicwf_sta, NULL);
+
+ aicwf_mu_group_sta_init(aicwf_sta, NULL);
+#endif /* CONFIG_AICWF_BFMER */
+
+ } else {
+ WARN_ON(0);
+ }
+ } else {
+ if (aicwf_sta->valid) {
+ aicwf_sta->ps.active = false;
+ aicwf_sta->valid = false;
+
+ /* Remove the station from the list of VIF's station */
+ list_del_init(&aicwf_sta->list);
+
+ aicwf_txq_sta_deinit(aicwf_hw, aicwf_sta);
+ } else {
+ WARN_ON(0);
+ }
+ }
+ } else {
+ if (!ind->estab && aicwf_sta->valid) {
+ /* There is no way to inform upper layer for lost of peer, still
+ * clean everything in the driver
+ */
+ aicwf_sta->ps.active = false;
+ aicwf_sta->valid = false;
+
+ /* Remove the station from the list of VIF's station */
+ list_del_init(&aicwf_sta->list);
+
+ aicwf_txq_sta_deinit(aicwf_hw, aicwf_sta);
+ } else {
+ WARN_ON(0);
+ }
+ }
+
+ return 0;
+}
+
+static inline int aicwf_rx_mesh_path_update_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mesh_path_update_ind *ind =
+ (struct mesh_path_update_ind *)msg->param;
+ struct aicwf_vif *aicwf_vif = aicwf_hw->vif_table[ind->vif_idx];
+ struct aicwf_mesh_path *mesh_path;
+ bool found = false;
+
+ if (ind->vif_idx >= (NX_VIRT_DEV_MAX + NX_REMOTE_STA_MAX))
+ return 1;
+
+ if (!aicwf_vif || (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT))
+ return 0;
+
+ /* Look for path with provided target address */
+ list_for_each_entry(mesh_path, &aicwf_vif->ap.mpath_list, list) {
+ if (mesh_path->path_idx == ind->path_idx) {
+ found = true;
+ break;
+ }
+ }
+
+ /* Check if element has been deleted */
+ if (ind->delete) {
+ if (found) {
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_mesh_delete_path(mesh_path);
+#endif
+ /* Remove element from list */
+ list_del_init(&mesh_path->list);
+ /* Free the element */
+ kfree(mesh_path);
+ }
+ } else {
+ if (found) {
+ // Update the Next Hop STA
+ mesh_path->p_nhop_sta = &aicwf_hw->sta_table[ind->nhop_sta_idx];
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_mesh_update_path(mesh_path);
+#endif
+ } else {
+ // Allocate a Mesh Path structure
+ mesh_path =
+ kmalloc_obj(struct aicwf_mesh_path, GFP_ATOMIC);
+
+ if (mesh_path) {
+ INIT_LIST_HEAD(&mesh_path->list);
+
+ mesh_path->path_idx = ind->path_idx;
+ mesh_path->p_nhop_sta = &aicwf_hw->sta_table[ind->nhop_sta_idx];
+ memcpy(&mesh_path->tgt_mac_addr, &ind->tgt_mac_addr,
+ MAC_ADDR_LEN);
+
+ // Insert the path in the list of path
+ list_add_tail(&mesh_path->list, &aicwf_vif->ap.mpath_list);
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_mesh_create_path(mesh_path);
+#endif
+ }
+ }
+ }
+
+ return 0;
+}
+
+static inline int aicwf_rx_mesh_proxy_update_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ struct mesh_proxy_update_ind *ind =
+ (struct mesh_proxy_update_ind *)msg->param;
+ struct aicwf_vif *aicwf_vif = aicwf_hw->vif_table[ind->vif_idx];
+ struct aicwf_mesh_proxy *mesh_proxy;
+ bool found = false;
+
+ if (ind->vif_idx >= (NX_VIRT_DEV_MAX + NX_REMOTE_STA_MAX))
+ return 1;
+
+ if (!aicwf_vif || AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return 0;
+
+ /* Look for path with provided external STA address */
+ list_for_each_entry(mesh_proxy, &aicwf_vif->ap.proxy_list, list) {
+ if (!memcmp(&ind->ext_sta_addr, &mesh_proxy->ext_sta_addr, ETH_ALEN)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (ind->delete && found) {
+ /* Delete mesh path */
+ list_del_init(&mesh_proxy->list);
+ kfree(mesh_proxy);
+ } else if (!ind->delete && !found) {
+ /* Allocate a Mesh Path structure */
+ mesh_proxy =
+ kmalloc_obj(*mesh_proxy, GFP_ATOMIC);
+
+ if (mesh_proxy) {
+ INIT_LIST_HEAD(&mesh_proxy->list);
+
+ memcpy(&mesh_proxy->ext_sta_addr, &ind->ext_sta_addr, MAC_ADDR_LEN);
+ mesh_proxy->local = ind->local;
+
+ if (!ind->local)
+ memcpy(&mesh_proxy->proxy_addr, &ind->proxy_mac_addr,
+ MAC_ADDR_LEN);
+
+ /* Insert the path in the list of path */
+ list_add_tail(&mesh_proxy->list, &aicwf_vif->ap.proxy_list);
+ }
+ }
+
+ return 0;
+}
+#endif /* CONFIG_AICWF_FULLMAC */
+
+/***************************************************************************
+ * Messages from DEBUG task
+ **************************************************************************/
+static inline int aicwf_rx_dbg_error_ind(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ return 0;
+}
+
+#ifdef CONFIG_AICWF_FULLMAC
+
+static const msg_cb_fct mm_hdlrs[MSG_I(MM_MAX)] = {
+ [MSG_I(MM_CHANNEL_SWITCH_IND)] = aicwf_rx_chan_switch_ind,
+ [MSG_I(MM_CHANNEL_PRE_SWITCH_IND)] = aicwf_rx_chan_pre_switch_ind,
+ [MSG_I(MM_REMAIN_ON_CHANNEL_EXP_IND)] = aicwf_rx_remain_on_channel_exp_ind,
+ [MSG_I(MM_PS_CHANGE_IND)] = aicwf_rx_ps_change_ind,
+ [MSG_I(MM_TRAFFIC_REQ_IND)] = aicwf_rx_traffic_req_ind,
+ [MSG_I(MM_P2P_VIF_PS_CHANGE_IND)] = aicwf_rx_p2p_vif_ps_change_ind,
+ [MSG_I(MM_CSA_COUNTER_IND)] = aicwf_rx_csa_counter_ind,
+ [MSG_I(MM_CSA_FINISH_IND)] = aicwf_rx_csa_finish_ind,
+ [MSG_I(MM_CSA_TRAFFIC_IND)] = aicwf_rx_csa_traffic_ind,
+ [MSG_I(MM_CHANNEL_SURVEY_IND)] = aicwf_rx_channel_survey_ind,
+ [MSG_I(MM_P2P_NOA_UPD_IND)] = aicwf_rx_p2p_noa_upd_ind,
+ [MSG_I(MM_RSSI_STATUS_IND)] = aicwf_rx_rssi_status_ind,
+ [MSG_I(MM_PKTLOSS_IND)] = aicwf_rx_pktloss_notify_ind,
+ [MSG_I(MM_APM_STALOSS_IND)] = aicwf_apm_staloss_ind,
+ [MSG_I(MM_ARP_ANNOUNCEMENT_IND)] = aicwf_arp_announcement_ind,
+};
+
+static const msg_cb_fct scan_hdlrs[MSG_I(SCANU_MAX)] = {
+ [MSG_I(SCANU_START_CFM)] = aicwf_rx_scanu_start_cfm,
+ [MSG_I(SCANU_RESULT_IND)] = aicwf_rx_scanu_result_ind,
+};
+
+static int aicwf_rx_me_chan_config_cfm(struct aicwf_hw *aicwf_hw,
+ struct aicwf_cmd *cmd,
+ struct ipc_e2a_msg *msg)
+{
+ if (cmd)
+ complete(&aicwf_hw->chan_config_complete);
+ return 0;
+}
+
+static const msg_cb_fct me_hdlrs[MSG_I(ME_MAX)] = {
+ [MSG_I(ME_CHAN_CONFIG_CFM)] = aicwf_rx_me_chan_config_cfm,
+ [MSG_I(ME_TKIP_MIC_FAILURE_IND)] = aicwf_rx_me_tkip_mic_failure_ind,
+ [MSG_I(ME_TX_CREDITS_UPDATE_IND)] = aicwf_rx_me_tx_credits_update_ind,
+};
+
+static const msg_cb_fct sm_hdlrs[MSG_I(SM_MAX)] = {
+ [MSG_I(SM_CONNECT_IND)] = aicwf_rx_sm_connect_ind,
+ [MSG_I(SM_DISCONNECT_IND)] = aicwf_rx_sm_disconnect_ind,
+ [MSG_I(SM_EXTERNAL_AUTH_REQUIRED_IND)] =
+ aicwf_rx_sm_external_auth_required_ind,
+};
+
+static const msg_cb_fct apm_hdlrs[MSG_I(APM_MAX)] = {};
+
+static const msg_cb_fct mesh_hdlrs[MSG_I(MESH_MAX)] = {
+ [MSG_I(MESH_PATH_CREATE_CFM)] = aicwf_rx_mesh_path_create_cfm,
+ [MSG_I(MESH_PEER_UPDATE_IND)] = aicwf_rx_mesh_peer_update_ind,
+ [MSG_I(MESH_PATH_UPDATE_IND)] = aicwf_rx_mesh_path_update_ind,
+ [MSG_I(MESH_PROXY_UPDATE_IND)] = aicwf_rx_mesh_proxy_update_ind,
+};
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+static const msg_cb_fct dbg_hdlrs[MSG_I(DBG_MAX)] = {
+ [MSG_I(DBG_ERROR_IND)] = aicwf_rx_dbg_error_ind,
+};
+
+static const msg_cb_fct tdls_hdlrs[MSG_I(TDLS_MAX)] = {
+ [MSG_I(TDLS_CHAN_SWITCH_CFM)] = aicwf_rx_tdls_chan_switch_cfm,
+ [MSG_I(TDLS_CHAN_SWITCH_IND)] = aicwf_rx_tdls_chan_switch_ind,
+ [MSG_I(TDLS_CHAN_SWITCH_BASE_IND)] = aicwf_rx_tdls_chan_switch_base_ind,
+ [MSG_I(TDLS_PEER_PS_IND)] = aicwf_rx_tdls_peer_ps_ind,
+};
+
+static const struct {
+ const msg_cb_fct *handlers;
+ unsigned int count;
+} msg_hdlrs[] = {
+ [TASK_MM] = { mm_hdlrs, ARRAY_SIZE(mm_hdlrs) },
+ [TASK_DBG] = { dbg_hdlrs, ARRAY_SIZE(dbg_hdlrs) },
+#ifdef CONFIG_AICWF_FULLMAC
+ [TASK_TDLS] = { tdls_hdlrs, ARRAY_SIZE(tdls_hdlrs) },
+ [TASK_SCANU] = { scan_hdlrs, ARRAY_SIZE(scan_hdlrs) },
+ [TASK_ME] = { me_hdlrs, ARRAY_SIZE(me_hdlrs) },
+ [TASK_SM] = { sm_hdlrs, ARRAY_SIZE(sm_hdlrs) },
+ [TASK_APM] = { apm_hdlrs, ARRAY_SIZE(apm_hdlrs) },
+ [TASK_MESH] = { mesh_hdlrs, ARRAY_SIZE(mesh_hdlrs) },
+#endif /* CONFIG_AICWF_FULLMAC */
+};
+
+/*
+ *
+ */
+void aicwf_rx_handle_msg(struct aicwf_hw *aicwf_hw, struct ipc_e2a_msg *msg)
+{
+ unsigned int task = MSG_T(msg->id);
+ unsigned int index = MSG_I(msg->id);
+
+ if (task >= ARRAY_SIZE(msg_hdlrs) ||
+ index >= msg_hdlrs[task].count) {
+ dev_warn_ratelimited(aicwf_hw->dev,
+ "Invalid firmware message ID 0x%04x (task=%u, index=%u)\n",
+ msg->id, task, index);
+ return;
+ }
+
+ aicwf_hw->cmd_mgr->msgind(aicwf_hw->cmd_mgr, msg,
+ msg_hdlrs[task].handlers[index]);
+}
+
+void aicwf_rx_handle_print(struct aicwf_hw *aicwf_hw, u8 *msg, u32 len)
+{
+ if (!aicwf_hw) {
+ pr_err("aicwf_hw is null!\n");
+ return;
+ }
+
+ if (!aicwf_hw->fwlog_en) {
+ dev_err(aicwf_hw->dev, "fwlog overflow: %.*s\n", (int)len, msg);
+ return;
+ }
+
+ dev_dbg(aicwf_hw->dev, "fwlog: %.*s\n", (int)len, msg);
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_rx.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_rx.h
new file mode 100644
index 000000000000..e7c30d6fadda
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_rx.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_MSG_RX_H_
+#define _AICWF_MSG_RX_H_
+
+void aicwf_rx_handle_msg(struct aicwf_hw *aicwf_hw, struct ipc_e2a_msg *msg);
+void aicwf_rx_handle_print(struct aicwf_hw *aicwf_hw, u8 *msg, u32 len);
+
+#endif /* _AICWF_MSG_RX_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_tx.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_tx.c
new file mode 100644
index 000000000000..cbb88c5b86ad
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_tx.c
@@ -0,0 +1,2499 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief TX function definitions
+ *
+ ******************************************************************************
+ */
+
+#include "aicwf_msg_tx.h"
+#include "aicwf_mod_params.h"
+#ifdef CONFIG_AICWF_BFMER
+#include "aicwf_bfmer.h"
+#endif //(CONFIG_AICWF_BFMER)
+#include "aicwf_txrxif.h"
+#include "aicwf_cmds.h"
+#include "aicwf_main.h"
+#include "aicwf_strs.h"
+#include <linux/pm.h>
+#include "aicwf_sdio.h"
+#include "aicwf_chip_ops.h"
+
+static const struct mac_addr mac_addr_bcst = {{0xFFFF, 0xFFFF, 0xFFFF}};
+
+const int bw2chnl[] = {
+ [NL80211_CHAN_WIDTH_20_NOHT] = PHY_CHNL_BW_20,
+ [NL80211_CHAN_WIDTH_20] = PHY_CHNL_BW_20,
+ [NL80211_CHAN_WIDTH_40] = PHY_CHNL_BW_40,
+ [NL80211_CHAN_WIDTH_80] = PHY_CHNL_BW_80,
+ [NL80211_CHAN_WIDTH_160] = PHY_CHNL_BW_160,
+ [NL80211_CHAN_WIDTH_80P80] = PHY_CHNL_BW_80P80,
+};
+
+const int chnl2bw[] = {
+ [PHY_CHNL_BW_20] = NL80211_CHAN_WIDTH_20,
+ [PHY_CHNL_BW_40] = NL80211_CHAN_WIDTH_40,
+ [PHY_CHNL_BW_80] = NL80211_CHAN_WIDTH_80,
+ [PHY_CHNL_BW_160] = NL80211_CHAN_WIDTH_160,
+ [PHY_CHNL_BW_80P80] = NL80211_CHAN_WIDTH_80P80,
+};
+
+/*****************************************************************************/
+
+static inline bool use_pairwise_key(struct cfg80211_crypto_settings *crypto)
+{
+ if (crypto->cipher_group == WLAN_CIPHER_SUITE_WEP40 ||
+ crypto->cipher_group == WLAN_CIPHER_SUITE_WEP104)
+ return false;
+
+ return true;
+}
+
+static inline u8 get_chan_flags(uint32_t flags)
+{
+ u8 chan_flags = 0;
+
+ if (flags & IEEE80211_CHAN_DISABLED)
+ chan_flags |= CHAN_DISABLED;
+
+ if (flags & IEEE80211_CHAN_NO_IR)
+ chan_flags |= CHAN_NO_IR;
+
+ if (flags & IEEE80211_CHAN_RADAR)
+ chan_flags |= CHAN_RADAR;
+ return chan_flags;
+}
+
+static inline s8 chan_to_fw_pwr(struct aicwf_hw *aicwf_hw, int power)
+{
+ power = min(power, READ_ONCE(aicwf_hw->tx_power_limit));
+ return clamp_t(int, power, S8_MIN, S8_MAX);
+}
+
+static inline void limit_chan_bw(u8 *bw, u16 primary, u16 *center1)
+{
+ int oft, new_oft = 10;
+
+ if (*bw <= PHY_CHNL_BW_40)
+ return;
+
+ oft = *center1 - primary;
+ *bw = PHY_CHNL_BW_40;
+
+ if (oft < 0)
+ new_oft = new_oft * -1;
+ if (abs(oft) == 10 || abs(oft) == 50)
+ new_oft = new_oft * -1;
+
+ *center1 = primary + new_oft;
+}
+
+/*
+ ******************************************************************************
+ * @brief Allocate memory for a message
+ *
+ * This primitive allocates memory for a message that has to be sent. The memory
+ * is allocated dynamically on the heap and the length of the variable parameter
+ * structure has to be provided in order to allocate the correct size.
+ *
+ * Several additional parameters are provided which will be preset in the
+ *message and which may be used internally to choose the kind of memory to
+ *allocate.
+ *
+ * The memory allocated will be automatically freed by the kernel, after the
+ * pointer has been sent to ke_msg_send(). If the message is not sent, it must
+ * be freed explicitly with ke_msg_free().
+ *
+ * Allocation failure is considered critical and should not happen.
+ *
+ * @param[in] id Message identifier
+ * @param[in] dest_id Destination Task Identifier
+ * @param[in] src_id Source Task Identifier
+ * @param[in] param_len Size of the message parameters to be allocated
+ *
+ * @return Pointer to the parameter member of the ke_msg. If the parameter
+ * structure is empty, the pointer will point to the end of the message
+ * and should not be used (except to retrieve the message pointer or to
+ * send the message)
+ ******************************************************************************
+ */
+static inline void *aicwf_msg_zalloc(struct aicwf_hw *aicwf_hw, lmac_msg_id_t const id,
+ lmac_task_id_t const dest_id,
+ lmac_task_id_t const src_id,
+ uint16_t const param_len)
+{
+ struct lmac_msg *msg;
+ gfp_t flags;
+
+ // if (is_non_blocking_msg(id) && (in_softirq()||in_atomic()))
+ flags = GFP_ATOMIC;
+ // else
+ // flags = GFP_KERNEL;
+
+ // msg = (struct lmac_msg *)kzalloc(sizeof(struct lmac_msg) + param_len, flags);
+ msg = kzalloc(sizeof(*msg) + param_len, flags);
+ if (!msg)
+ return NULL;
+ msg->id = id;
+ msg->dest_id = dest_id;
+ msg->src_id = src_id;
+ msg->param_len = param_len;
+
+ return msg->param;
+}
+
+static void aicwf_msg_free(struct aicwf_hw *aicwf_hw, const void *msg_params)
+{
+ struct lmac_msg *msg = container_of((void *)msg_params, struct lmac_msg, param);
+
+ /* Free the message */
+ kfree(msg);
+}
+
+// void aicwf_pm_relax(struct aic_sdio_dev *sdiodev);
+// void aicwf_pm_stay_awake(struct aic_sdio_dev *sdiodev);
+
+static int aicwf_send_msg(struct aicwf_hw *aicwf_hw, const void *msg_params,
+ int reqcfm, lmac_msg_id_t reqid, void *cfm,
+ size_t cfm_len)
+{
+ struct lmac_msg *msg;
+ struct aicwf_cmd *cmd;
+ bool nonblock;
+ int ret = 0;
+ u8 empty = 0;
+
+ dev_dbg(aicwf_hw->dev, "%d%s reqcfm:%d in_hardirq:%d in_softirq:%d irqs_disabled:%d\n",
+ reqid, AICWF_ID2STR(reqid), reqcfm, (int)in_hardirq(),
+ (int)in_softirq(), (int)irqs_disabled());
+
+ ret = aicwf_cmd_mgr_get(aicwf_hw->cmd_mgr);
+ if (ret) {
+ aicwf_msg_free(aicwf_hw, msg_params);
+ return ret;
+ }
+ if (!aicwf_sdio_activity_get(aicwf_hw, aicwf_hw->ws_tx)) {
+ aicwf_msg_free(aicwf_hw, msg_params);
+ aicwf_cmd_mgr_put(aicwf_hw->cmd_mgr);
+ return -EBUSY;
+ }
+ if (aicwf_hw->sdiodev->bus_if->state == BUS_DOWN_ST) {
+ aicwf_msg_free(aicwf_hw, msg_params);
+ dev_err(aicwf_hw->dev, "bus is down\n");
+ aicwf_sdio_activity_put(aicwf_hw, aicwf_hw->ws_tx);
+ aicwf_cmd_mgr_put(aicwf_hw->cmd_mgr);
+ return -ENODEV;
+ }
+
+ msg = container_of((void *)msg_params, struct lmac_msg, param);
+
+ nonblock = 0;
+ cmd = aicwf_cmd_malloc(aicwf_hw->cmd_mgr);
+ if (!cmd) {
+ aicwf_msg_free(aicwf_hw, msg_params);
+ aicwf_sdio_activity_put(aicwf_hw, aicwf_hw->ws_tx);
+ aicwf_cmd_mgr_put(aicwf_hw->cmd_mgr);
+ return -ENOMEM;
+ }
+ cmd->result = -EINTR;
+ cmd->id = msg->id;
+ cmd->reqid = reqid;
+ cmd->a2e_msg = msg;
+ cmd->e2a_msg = cfm;
+ cmd->e2a_msg_len = cfm_len;
+ if (nonblock)
+ cmd->flags = AICWF_CMD_FLAG_NONBLOCK;
+ if (reqcfm)
+ cmd->flags |= AICWF_CMD_FLAG_REQ_CFM;
+
+ if (cfm) {
+ do {
+ if (READ_ONCE(aicwf_hw->cmd_mgr->state) != AICWF_CMD_MGR_STATE_INITED)
+ break;
+ spin_lock_bh(&aicwf_hw->cmd_mgr->lock);
+ empty = list_empty(&aicwf_hw->cmd_mgr->cmds);
+ spin_unlock_bh(&aicwf_hw->cmd_mgr->lock);
+ if (!empty) {
+ if (in_softirq()) {
+ dev_dbg(aicwf_hw->dev, "in_softirq:check cmdqueue empty\n");
+ mdelay(10);
+ } else {
+ dev_dbg(aicwf_hw->dev, "check cmdqueue empty\n");
+ msleep(50);
+ }
+ }
+ } while (!empty); // wait for cmd queue empty
+ }
+
+ if (reqcfm) {
+ cmd->flags &= ~AICWF_CMD_FLAG_WAIT_ACK; // we don't need ack any more
+ ret = aicwf_hw->cmd_mgr->queue(aicwf_hw->cmd_mgr, cmd);
+ } else {
+ aicwf_set_cmd_tx((void *)(aicwf_hw->sdiodev), cmd->a2e_msg,
+ sizeof(struct lmac_msg) + cmd->a2e_msg->param_len);
+ }
+
+ /* The queue owns both the request and command, also on rejection. */
+ if (!reqcfm) {
+ aicwf_msg_free(aicwf_hw, msg_params);
+ aicwf_cmd_free(aicwf_hw->cmd_mgr, cmd);
+ }
+
+ aicwf_sdio_activity_put(aicwf_hw, aicwf_hw->ws_tx);
+ aicwf_cmd_mgr_put(aicwf_hw->cmd_mgr);
+ return ret;
+}
+
+static int aicwf_send_msg1(struct aicwf_hw *aicwf_hw, const void *msg_params,
+ int reqcfm, lmac_msg_id_t reqid, void *cfm,
+ size_t cfm_len, bool defer)
+{
+ struct lmac_msg *msg;
+ struct aicwf_cmd *cmd;
+ bool nonblock;
+ int ret = 0;
+
+ dev_dbg(aicwf_hw->dev, "%d%s reqcfm:%d in_hardirq:%d in_softirq:%d irqs_disabled:%d\n",
+ reqid, AICWF_ID2STR(reqid), reqcfm, (int)in_hardirq(),
+ (int)in_softirq(), (int)irqs_disabled());
+
+ ret = aicwf_cmd_mgr_get(aicwf_hw->cmd_mgr);
+ if (ret) {
+ aicwf_msg_free(aicwf_hw, msg_params);
+ return ret;
+ }
+ if (!aicwf_sdio_activity_get(aicwf_hw, aicwf_hw->ws_tx)) {
+ aicwf_msg_free(aicwf_hw, msg_params);
+ aicwf_cmd_mgr_put(aicwf_hw->cmd_mgr);
+ return -EBUSY;
+ }
+ msg = container_of((void *)msg_params, struct lmac_msg, param);
+
+ nonblock = 0;
+ cmd = aicwf_cmd_malloc(aicwf_hw->cmd_mgr);
+ if (!cmd) {
+ aicwf_msg_free(aicwf_hw, msg_params);
+ aicwf_sdio_activity_put(aicwf_hw, aicwf_hw->ws_tx);
+ aicwf_cmd_mgr_put(aicwf_hw->cmd_mgr);
+ return -ENOMEM;
+ }
+ cmd->result = -EINTR;
+ cmd->id = msg->id;
+ cmd->reqid = reqid;
+ cmd->a2e_msg = msg;
+ cmd->e2a_msg = cfm;
+ cmd->e2a_msg_len = cfm_len;
+ if (nonblock)
+ cmd->flags = AICWF_CMD_FLAG_NONBLOCK;
+ if (reqcfm)
+ cmd->flags |= AICWF_CMD_FLAG_REQ_CFM;
+
+ if (reqcfm) {
+ cmd->flags &= ~AICWF_CMD_FLAG_WAIT_ACK; // we don't need ack any more
+ if (!defer)
+ ret = aicwf_hw->cmd_mgr->queue(aicwf_hw->cmd_mgr, cmd);
+ else
+ ret = cmd_mgr_queue_force_defer(aicwf_hw->cmd_mgr, cmd);
+ }
+
+ /* Do not read cmd after queue(): it may already be back in the pool. */
+ if (!reqcfm) {
+ aicwf_msg_free(aicwf_hw, msg_params);
+ aicwf_cmd_free(aicwf_hw->cmd_mgr, cmd);
+ }
+
+ aicwf_sdio_activity_put(aicwf_hw, aicwf_hw->ws_tx);
+ aicwf_cmd_mgr_put(aicwf_hw->cmd_mgr);
+ return ret;
+}
+
+/******************************************************************************
+ * Control messages handling functions (FULLMAC)
+ *****************************************************************************/
+int aicwf_send_reset(struct aicwf_hw *aicwf_hw)
+{
+ void *void_param;
+
+ /* RESET REQ has no parameter */
+ void_param = aicwf_msg_zalloc(aicwf_hw, MM_RESET_REQ, TASK_MM, DRV_TASK_ID, 0);
+ if (!void_param)
+ return -ENOMEM;
+
+ return aicwf_send_msg(aicwf_hw, void_param, 1, MM_RESET_CFM, NULL, 0);
+}
+
+int aicwf_send_start(struct aicwf_hw *aicwf_hw)
+{
+ struct mm_start_req *start_req_param;
+
+ /* Build the START REQ message */
+ start_req_param = aicwf_msg_zalloc(aicwf_hw, MM_START_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_start_req));
+ if (!start_req_param)
+ return -ENOMEM;
+
+ /* Set parameters for the START message */
+ memcpy(&start_req_param->phy_cfg, &aicwf_hw->phy.cfg,
+ sizeof(aicwf_hw->phy.cfg));
+ start_req_param->uapsd_timeout = (u32)aicwf_hw->mod_params->uapsd_timeout;
+ start_req_param->lp_clk_accuracy = (u16)aicwf_hw->mod_params->lp_clk_ppm;
+
+ /* Send the START REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, start_req_param, 1, MM_START_CFM, NULL, 0);
+}
+
+int aicwf_send_version_req(struct aicwf_hw *aicwf_hw, struct mm_version_cfm *cfm)
+{
+ void *void_param;
+
+ /* VERSION REQ has no parameter */
+ void_param = aicwf_msg_zalloc(aicwf_hw, MM_VERSION_REQ, TASK_MM, DRV_TASK_ID, 0);
+ if (!void_param)
+ return -ENOMEM;
+
+ return aicwf_send_msg(aicwf_hw, void_param, 1, MM_VERSION_CFM, cfm, sizeof(*cfm));
+}
+
+int aicwf_send_add_if(struct aicwf_hw *aicwf_hw, const unsigned char *mac,
+ enum nl80211_iftype iftype, bool p2p,
+ struct mm_add_if_cfm *cfm)
+{
+ struct mm_add_if_req *add_if_req_param;
+
+ /* Build the ADD_IF_REQ message */
+ add_if_req_param = aicwf_msg_zalloc(aicwf_hw, MM_ADD_IF_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_add_if_req));
+ if (!add_if_req_param)
+ return -ENOMEM;
+
+ /* Set parameters for the ADD_IF_REQ message */
+ memcpy(&add_if_req_param->addr.array[0], mac, ETH_ALEN);
+ switch (iftype) {
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+#ifdef CONFIG_AICWF_FULLMAC
+ // case NL80211_IFTYPE_P2P_DEVICE:
+ case NL80211_IFTYPE_P2P_CLIENT:
+ add_if_req_param->p2p = true;
+ fallthrough;
+ // no break
+#endif /* CONFIG_AICWF_FULLMAC */
+#endif
+ case NL80211_IFTYPE_STATION:
+ add_if_req_param->type = MM_STA;
+ break;
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ case NL80211_IFTYPE_ADHOC:
+ add_if_req_param->type = MM_IBSS;
+ break;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ case NL80211_IFTYPE_P2P_GO:
+ add_if_req_param->p2p = true;
+ fallthrough;
+ // no break
+#endif /* CONFIG_AICWF_FULLMAC */
+ case NL80211_IFTYPE_AP:
+ add_if_req_param->type = MM_AP;
+ break;
+ case NL80211_IFTYPE_MESH_POINT:
+ add_if_req_param->type = MM_MESH_POINT;
+ break;
+ case NL80211_IFTYPE_AP_VLAN:
+ return -1;
+ case NL80211_IFTYPE_MONITOR:
+ add_if_req_param->type = MM_MONITOR;
+ break;
+#endif
+ default:
+ aicwf_msg_free(aicwf_hw, add_if_req_param);
+ return -EOPNOTSUPP;
+ }
+
+ /* Send the ADD_IF_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, add_if_req_param, 1, MM_ADD_IF_CFM, cfm, sizeof(*cfm));
+}
+
+int aicwf_send_remove_if(struct aicwf_hw *aicwf_hw, u8 vif_index, bool defer)
+{
+ struct mm_remove_if_req *remove_if_req;
+
+ /* Build the MM_REMOVE_IF_REQ message */
+ remove_if_req = aicwf_msg_zalloc(aicwf_hw, MM_REMOVE_IF_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_remove_if_req));
+ if (!remove_if_req)
+ return -ENOMEM;
+
+ /* Set parameters for the MM_REMOVE_IF_REQ message */
+ remove_if_req->inst_nbr = vif_index;
+
+ /* Send the MM_REMOVE_IF_REQ message to LMAC FW */
+ return aicwf_send_msg1(aicwf_hw, remove_if_req, 1, MM_REMOVE_IF_CFM, NULL, 0,
+ defer);
+}
+
+int aicwf_send_key_add(struct aicwf_hw *aicwf_hw, u8 vif_idx, u8 sta_idx,
+ bool pairwise, u8 *key, u8 key_len, u8 key_idx,
+ u8 cipher_suite, struct mm_key_add_cfm *cfm)
+{
+ struct mm_key_add_req *key_add_req;
+
+ /* Build the MM_KEY_ADD_REQ message */
+ key_add_req = aicwf_msg_zalloc(aicwf_hw, MM_KEY_ADD_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_key_add_req));
+ if (!key_add_req)
+ return -ENOMEM;
+
+ /* Set parameters for the MM_KEY_ADD_REQ message */
+ if (sta_idx != 0xFF) {
+ /* Pairwise key */
+ key_add_req->sta_idx = sta_idx;
+ } else {
+ /* Default key */
+ key_add_req->sta_idx = sta_idx;
+ key_add_req->key_idx = (u8)key_idx; /* only useful for default keys */
+ }
+ key_add_req->pairwise = pairwise;
+ key_add_req->inst_nbr = vif_idx;
+ key_add_req->key.length = key_len;
+ memcpy(&key_add_req->key.array[0], key, key_len);
+
+ key_add_req->cipher_suite = cipher_suite;
+
+ dev_dbg(aicwf_hw->dev, "sta_idx:%d key_idx:%d inst_nbr:%d cipher:%d key_len:%d\n",
+ key_add_req->sta_idx, key_add_req->key_idx,
+ key_add_req->inst_nbr, key_add_req->cipher_suite,
+ key_add_req->key.length);
+#if defined(CONFIG_AICWF_DBG) || defined(CONFIG_DYNAMIC_DEBUG)
+ print_hex_dump_bytes("key: ", DUMP_PREFIX_OFFSET, key_add_req->key.array,
+ key_add_req->key.length);
+#endif
+
+ /* Send the MM_KEY_ADD_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, key_add_req, 1, MM_KEY_ADD_CFM, cfm, sizeof(*cfm));
+}
+
+int aicwf_send_key_del(struct aicwf_hw *aicwf_hw, uint8_t hw_key_idx)
+{
+ struct mm_key_del_req *key_del_req;
+
+ /* Build the MM_KEY_DEL_REQ message */
+ key_del_req = aicwf_msg_zalloc(aicwf_hw, MM_KEY_DEL_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_key_del_req));
+ if (!key_del_req)
+ return -ENOMEM;
+
+ /* Set parameters for the MM_KEY_DEL_REQ message */
+ key_del_req->hw_key_idx = hw_key_idx;
+
+ /* Send the MM_KEY_DEL_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, key_del_req, 1, MM_KEY_DEL_CFM, NULL, 0);
+}
+
+int aicwf_send_bcn(struct aicwf_hw *aicwf_hw, u8 *buf, u8 vif_idx, u16 bcn_len)
+{
+ struct apm_set_bcn_ie_req *bcn_ie_req;
+
+ bcn_ie_req = aicwf_msg_zalloc(aicwf_hw, APM_SET_BEACON_IE_REQ, TASK_APM, DRV_TASK_ID,
+ sizeof(struct apm_set_bcn_ie_req));
+ if (!bcn_ie_req)
+ return -ENOMEM;
+
+ bcn_ie_req->vif_idx = vif_idx;
+ bcn_ie_req->bcn_ie_len = bcn_len;
+ memcpy(bcn_ie_req->bcn_ie, (u8 *)buf, bcn_len);
+ kfree(buf);
+
+ return aicwf_send_msg(aicwf_hw, bcn_ie_req, 1, APM_SET_BEACON_IE_CFM, NULL, 0);
+}
+
+int aicwf_send_bcn_change(struct aicwf_hw *aicwf_hw, u8 vif_idx, u32 bcn_addr,
+ u16 bcn_len, u16 tim_oft, u16 tim_len, u16 *csa_oft)
+{
+ struct mm_bcn_change_req *req;
+
+ /* Build the MM_BCN_CHANGE_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MM_BCN_CHANGE_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_bcn_change_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the MM_BCN_CHANGE_REQ message */
+ req->bcn_ptr = bcn_addr;
+ req->bcn_len = bcn_len;
+ req->tim_oft = tim_oft;
+ req->tim_len = tim_len;
+ req->inst_nbr = vif_idx;
+
+ if (csa_oft) {
+ int i;
+
+ for (i = 0; i < BCN_MAX_CSA_CPT; i++)
+ req->csa_oft[i] = csa_oft[i];
+ }
+
+ /* Send the MM_BCN_CHANGE_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, MM_BCN_CHANGE_CFM, NULL, 0);
+}
+
+int aicwf_send_roc(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ struct ieee80211_channel *chan, unsigned int duration,
+ struct mm_remain_on_channel_cfm *roc_cfm)
+{
+ struct mm_remain_on_channel_req *req;
+ struct cfg80211_chan_def chandef;
+
+ if (READ_ONCE(aicwf_hw->regdom_failed))
+ return -EIO;
+
+ /* Create channel definition structure */
+ cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
+
+ /* Build the MM_REMAIN_ON_CHANNEL_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MM_REMAIN_ON_CHANNEL_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_remain_on_channel_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the MM_REMAIN_ON_CHANNEL_REQ message */
+ req->op_code = MM_ROC_OP_START;
+ req->vif_index = vif->vif_index;
+ req->duration_ms = duration;
+ req->band = chan->band;
+ req->type = bw2chnl[chandef.width];
+ req->prim20_freq = chan->center_freq;
+ req->center1_freq = chandef.center_freq1;
+ req->center2_freq = chandef.center_freq2;
+ req->tx_power = chan_to_fw_pwr(aicwf_hw, chan->max_power);
+
+ /* Send the MM_REMAIN_ON_CHANNEL_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, MM_REMAIN_ON_CHANNEL_CFM, roc_cfm, sizeof(*roc_cfm));
+}
+
+int aicwf_send_cancel_roc(struct aicwf_hw *aicwf_hw)
+{
+ struct mm_remain_on_channel_req *req;
+
+ /* Build the MM_REMAIN_ON_CHANNEL_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MM_REMAIN_ON_CHANNEL_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_remain_on_channel_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the MM_REMAIN_ON_CHANNEL_REQ message */
+ req->op_code = MM_ROC_OP_CANCEL;
+
+ /* Send the MM_REMAIN_ON_CHANNEL_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, MM_REMAIN_ON_CHANNEL_CFM, NULL, 0);
+}
+
+int aicwf_send_set_edca(struct aicwf_hw *aicwf_hw, u8 hw_queue, u32 param,
+ bool uapsd, u8 inst_nbr)
+{
+ struct mm_set_edca_req *set_edca_req;
+
+ /* Build the MM_SET_EDCA_REQ message */
+ set_edca_req = aicwf_msg_zalloc(aicwf_hw, MM_SET_EDCA_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_set_edca_req));
+ if (!set_edca_req)
+ return -ENOMEM;
+
+ /* Set parameters for the MM_SET_EDCA_REQ message */
+ set_edca_req->ac_param = param;
+ set_edca_req->uapsd = uapsd;
+ set_edca_req->hw_queue = hw_queue;
+ set_edca_req->inst_nbr = inst_nbr;
+
+ /* Send the MM_SET_EDCA_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, set_edca_req, 1, MM_SET_EDCA_CFM, NULL, 0);
+}
+
+#ifdef CONFIG_AIC8800_ARP_OFFLOAD
+int aicwf_send_arpoffload_en_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif, u32 ipaddr,
+ u8 enable)
+{
+ struct mm_set_arpoffload_en_req *arp_offload_req;
+ int error;
+
+ /* Build the MM_SET_P2P_NOA_REQ message */
+ arp_offload_req =
+ aicwf_msg_zalloc(aicwf_hw, MM_SET_ARPOFFLOAD_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_set_arpoffload_en_req));
+
+ if (!arp_offload_req)
+ return -ENOMEM;
+
+ /* Fill the message parameters */
+ arp_offload_req->enable = enable;
+ arp_offload_req->vif_idx = aicwf_vif->vif_index;
+ arp_offload_req->ipaddr = ipaddr;
+
+ /* Send the MM_ARPOFFLOAD_EN_REQ message to UMAC FW */
+ error =
+ aicwf_send_msg(aicwf_hw, arp_offload_req, 1, MM_SET_ARPOFFLOAD_CFM, NULL, 0);
+
+ return error;
+}
+#endif
+
+int aicwf_send_rf_calib_req(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_cfm *cfm)
+{
+ struct mm_set_rf_calib_req *rf_calib_req;
+ struct xtal_cap_conf xtal_cap = {
+ 0,
+ };
+ int error;
+
+ /* Build the MM_SET_P2P_NOA_REQ message */
+ rf_calib_req = aicwf_msg_zalloc(aicwf_hw, MM_SET_RF_CALIB_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_set_rf_calib_req));
+
+ if (!rf_calib_req)
+ return -ENOMEM;
+
+ aic_chip_set_rf_calib_cfg(aicwf_hw, rf_calib_req);
+
+ rf_calib_req->param_alpha = 0x0c34c008;
+ rf_calib_req->bt_calib_en = 0;
+ rf_calib_req->bt_calib_param = 0x264203;
+
+ get_userconfig_xtal_cap(aicwf_hw, &xtal_cap);
+
+ if (xtal_cap.enable) {
+ dev_dbg(aicwf_hw->dev, "user xtal cap: %d, cap_fine: %d\n", xtal_cap.xtal_cap,
+ xtal_cap.xtal_cap_fine);
+ rf_calib_req->xtal_cap = xtal_cap.xtal_cap;
+ rf_calib_req->xtal_cap_fine = xtal_cap.xtal_cap_fine;
+ } else {
+ rf_calib_req->xtal_cap = 0;
+ rf_calib_req->xtal_cap_fine = 0;
+ }
+
+ /* Send the MM_SET_RF_CALIB_REQ message to UMAC FW */
+ error = aicwf_send_msg(aicwf_hw, rf_calib_req, 1, MM_SET_RF_CALIB_CFM, cfm, sizeof(*cfm));
+
+ return error;
+};
+
+int aicwf_send_get_macaddr_req(struct aicwf_hw *aicwf_hw,
+ struct mm_get_mac_addr_cfm *cfm)
+{
+ struct mm_get_mac_addr_req *get_macaddr_req;
+ int error;
+
+ /* Build the MM_GET_MAC_ADDR_REQ message */
+ get_macaddr_req = aicwf_msg_zalloc(aicwf_hw, MM_GET_MAC_ADDR_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_get_mac_addr_req));
+
+ if (!get_macaddr_req)
+ return -ENOMEM;
+
+ get_macaddr_req->get = 1;
+
+ /* Send the MM_GET_MAC_ADDR_REQ message to UMAC FW */
+ error =
+ aicwf_send_msg(aicwf_hw, get_macaddr_req, 1, MM_GET_MAC_ADDR_CFM, cfm, sizeof(*cfm));
+
+ return error;
+};
+
+int aicwf_send_get_sta_info_req(struct aicwf_hw *aicwf_hw, u8 sta_idx,
+ struct mm_get_sta_info_cfm *cfm)
+{
+ struct mm_get_sta_info_req *get_info_req;
+ int error;
+
+ /* Build the MM_GET_STA_INFO_REQ message */
+ get_info_req = aicwf_msg_zalloc(aicwf_hw, MM_GET_STA_INFO_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_get_sta_info_req));
+
+ if (!get_info_req)
+ return -ENOMEM;
+
+ get_info_req->sta_idx = sta_idx;
+
+ /* Send the MM_GET_STA_INFO_REQ message to UMAC FW */
+ error = aicwf_send_msg(aicwf_hw, get_info_req, 1, MM_GET_STA_INFO_CFM, cfm, sizeof(*cfm));
+
+ return error;
+};
+
+int aicwf_send_set_stack_start_req(struct aicwf_hw *aicwf_hw, u8 on,
+ u8 efuse_valid, u8 set_vendor_info,
+ u8 fwtrace_redir_en,
+ struct mm_set_stack_start_cfm *cfm)
+{
+ struct mm_set_stack_start_req *req;
+ int error;
+
+ /* Build the MM_SET_STACK_START_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MM_SET_STACK_START_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_set_stack_start_req));
+
+ if (!req)
+ return -ENOMEM;
+
+ req->is_stack_start = on;
+ req->efuse_valid = efuse_valid;
+ req->set_vendor_info = set_vendor_info;
+ req->fwtrace_redir = fwtrace_redir_en;
+ /* Send the MM_SET_STACK_START_REQ message to UMAC FW */
+ error = aicwf_send_msg(aicwf_hw, req, 1, MM_SET_STACK_START_CFM, cfm, sizeof(*cfm));
+
+ return error;
+}
+
+int aicwf_send_get_temp_req(struct aicwf_hw *aicwf_hw,
+ struct mm_set_vendor_swconfig_cfm *cfm)
+{
+ struct mm_set_vendor_swconfig_req *req;
+ int ret;
+
+ /* Build the TEMP_COMP_GET_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MM_SET_VENDOR_SWCONFIG_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_set_vendor_swconfig_req));
+ if (!req) {
+ dev_dbg(aicwf_hw->dev, "msg_alloc fail\n");
+ return -ENOMEM;
+ }
+ req->swconfig_id = TEMP_COMP_GET_REQ;
+
+ ret = aicwf_send_msg(aicwf_hw, req, 1, MM_SET_VENDOR_SWCONFIG_CFM, cfm, sizeof(*cfm));
+ if (!ret) {
+ dev_dbg(aicwf_hw->dev, "status=%d, temp=%d\n", cfm->temp_comp_get_cfm.status,
+ cfm->temp_comp_get_cfm.degree);
+ } else {
+ dev_dbg(aicwf_hw->dev, "msg_fail\n");
+ return ret;
+ }
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+ // aicwf_hw->started_jiffies = jiffies;
+ aicwf_hw->temp = cfm->temp_comp_get_cfm.degree;
+#endif
+
+ return ret;
+}
+
+int aicwf_send_set_temp_comp_req(struct aicwf_hw *aicwf_hw,
+ struct mm_set_vendor_swconfig_cfm *cfm)
+{
+ struct mm_set_vendor_swconfig_req *req;
+ int ret;
+
+ /* Build the TEMP_COMP_SET_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MM_SET_VENDOR_SWCONFIG_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_set_vendor_swconfig_req));
+ if (!req) {
+ dev_err(aicwf_hw->dev, "msg_alloc fail\n");
+ return -ENOMEM;
+ }
+ req->swconfig_id = TEMP_COMP_SET_REQ;
+ req->temp_comp_set_req.enable = 1;
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+ req->temp_comp_set_req.tmr_period_ms = TEMP_GET_INTERVAL;
+#else
+ req->temp_comp_set_req.tmr_period_ms = 15 * 1000;
+#endif
+
+ ret = aicwf_send_msg(aicwf_hw, req, 1, MM_SET_VENDOR_SWCONFIG_CFM, cfm, sizeof(*cfm));
+ if (!ret) {
+ dev_dbg(aicwf_hw->dev, "temp_comp status: %d\n", cfm->temp_comp_set_cfm.status);
+ } else {
+ dev_dbg(aicwf_hw->dev, "msg_fail\n");
+ return ret;
+ }
+ return ret;
+}
+
+int aicwf_send_get_fw_version_req(struct aicwf_hw *aicwf_hw,
+ struct mm_get_fw_version_cfm *cfm)
+{
+ void *req;
+ int error;
+
+ /* Build the MM_GET_FW_VERSION_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MM_GET_FW_VERSION_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(u8));
+
+ if (!req)
+ return -ENOMEM;
+
+ /* Send the MM_GET_FW_VERSION_REQ message to UMAC FW */
+ error = aicwf_send_msg(aicwf_hw, req, 1, MM_GET_FW_VERSION_CFM, cfm, sizeof(*cfm));
+
+ return error;
+}
+
+int aicwf_send_txpwr_lvl_v3_req(struct aicwf_hw *aicwf_hw, int index_reg)
+{
+ struct mm_set_txpwr_lvl_req *txpwr_lvl_req;
+ struct txpwr_lvl_conf_v3 txpwr_lvl_v3_tmp;
+ struct txpwr_lvl_conf_v3 *txpwr_lvl_v3;
+ struct txpwr_loss_conf txpwr_loss_tmp;
+ struct txpwr_loss_conf *txpwr_loss;
+ int error;
+ int i;
+
+ /* Build the MM_SET_TXPWR_LVL_REQ message */
+ txpwr_lvl_req =
+ aicwf_msg_zalloc(aicwf_hw, MM_SET_TXPWR_IDX_LVL_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_set_txpwr_lvl_req));
+
+ if (!txpwr_lvl_req)
+ return -ENOMEM;
+
+ txpwr_lvl_v3 = &txpwr_lvl_v3_tmp;
+ txpwr_loss = &txpwr_loss_tmp;
+ txpwr_loss->loss_enable_2g4 = 0;
+ txpwr_loss->loss_enable_5g = 0;
+
+ //get_userconfig_txpwr_lvl_v3_in_fdrv(txpwr_lvl_v3);
+ get_userconfig_txpwr_lvl_group_in_fdrv(aicwf_hw, txpwr_lvl_v3, index_reg);
+ get_userconfig_txpwr_loss(aicwf_hw, txpwr_loss);
+
+ if (txpwr_loss->loss_enable_2g4 == 1) {
+ dev_dbg(aicwf_hw->dev, "loss_value_2g4: %d\n",
+ txpwr_loss->loss_value_2g4);
+
+ for (i = 0; i <= 11; i++)
+ txpwr_lvl_v3->pwrlvl_11b_11ag_2g4[i] -= txpwr_loss->loss_value_2g4;
+ for (i = 0; i <= 9; i++)
+ txpwr_lvl_v3->pwrlvl_11n_11ac_2g4[i] -= txpwr_loss->loss_value_2g4;
+ for (i = 0; i <= 11; i++)
+ txpwr_lvl_v3->pwrlvl_11ax_2g4[i] -= txpwr_loss->loss_value_2g4;
+ }
+
+ if (txpwr_loss->loss_enable_5g == 1) {
+ dev_dbg(aicwf_hw->dev, "loss_value_5g: %d\n",
+ txpwr_loss->loss_value_5g);
+
+ for (i = 0; i <= 11; i++)
+ txpwr_lvl_v3->pwrlvl_11a_5g[i] -= txpwr_loss->loss_value_5g;
+ for (i = 0; i <= 9; i++)
+ txpwr_lvl_v3->pwrlvl_11n_11ac_5g[i] -= txpwr_loss->loss_value_5g;
+ for (i = 0; i <= 11; i++)
+ txpwr_lvl_v3->pwrlvl_11ax_5g[i] -= txpwr_loss->loss_value_5g;
+ }
+
+ if (txpwr_lvl_v3->enable == 0) {
+ aicwf_msg_free(aicwf_hw, txpwr_lvl_req);
+ return 0;
+ }
+
+ dev_dbg(aicwf_hw->dev, "dump\n");
+ dev_dbg(aicwf_hw->dev, "txpwr_lvl_v3->enable: %d\n", txpwr_lvl_v3->enable);
+ dev_dbg(aicwf_hw->dev, "lvl_11b_11ag_1m_2g4:%d\n",
+ txpwr_lvl_v3->pwrlvl_11b_11ag_2g4[0]);
+
+ txpwr_lvl_req->txpwr_lvl_v3 = *txpwr_lvl_v3;
+
+ /* Send the MM_SET_TXPWR_LVL_REQ message to UMAC FW */
+ error = aicwf_send_msg(aicwf_hw, txpwr_lvl_req, 1,
+ MM_SET_TXPWR_IDX_LVL_CFM, NULL, 0);
+
+ return error;
+}
+
+int aicwf_send_txpwr_lvl_adj_req(struct aicwf_hw *aicwf_hw)
+{
+ struct mm_set_txpwr_lvl_adj_req *txpwr_lvl_adj_req;
+ struct txpwr_lvl_adj_conf txpwr_lvl_adj_tmp;
+ struct txpwr_lvl_adj_conf *txpwr_lvl_adj;
+ int error;
+
+ /* Build the MM_SET_TXPWR_LVL_REQ message */
+ txpwr_lvl_adj_req =
+ aicwf_msg_zalloc(aicwf_hw, MM_SET_TXPWR_LVL_ADJ_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_set_txpwr_lvl_adj_req));
+
+ if (!txpwr_lvl_adj_req)
+ return -ENOMEM;
+
+ txpwr_lvl_adj = &txpwr_lvl_adj_tmp;
+
+ get_userconfig_txpwr_lvl_adj_in_fdrv(aicwf_hw, txpwr_lvl_adj);
+
+ if (txpwr_lvl_adj->enable == 0) {
+ aicwf_msg_free(aicwf_hw, txpwr_lvl_adj_req);
+ return 0;
+ }
+
+ dev_dbg(aicwf_hw->dev, "enable:%d\n", txpwr_lvl_adj->enable);
+ dev_dbg(aicwf_hw->dev, "lvl_adj_2g4_chan_1_4:%d\n",
+ txpwr_lvl_adj->pwrlvl_adj_tbl_2g4[0]);
+ dev_dbg(aicwf_hw->dev, "lvl_adj_2g4_chan_5_9:%d\n",
+ txpwr_lvl_adj->pwrlvl_adj_tbl_2g4[1]);
+ dev_dbg(aicwf_hw->dev, "lvl_adj_2g4_chan_10_13:%d\n",
+ txpwr_lvl_adj->pwrlvl_adj_tbl_2g4[2]);
+ dev_dbg(aicwf_hw->dev, "lvl_adj_5g_chan_42:%d\n",
+ txpwr_lvl_adj->pwrlvl_adj_tbl_5g[0]);
+ dev_dbg(aicwf_hw->dev, "lvl_adj_5g_chan_58:%d\n",
+ txpwr_lvl_adj->pwrlvl_adj_tbl_5g[1]);
+ dev_dbg(aicwf_hw->dev, "lvl_adj_5g_chan_106:%d\n",
+ txpwr_lvl_adj->pwrlvl_adj_tbl_5g[2]);
+ dev_dbg(aicwf_hw->dev, "lvl_adj_5g_chan_122:%d\n",
+ txpwr_lvl_adj->pwrlvl_adj_tbl_5g[3]);
+ dev_dbg(aicwf_hw->dev, "lvl_adj_5g_chan_138:%d\n",
+ txpwr_lvl_adj->pwrlvl_adj_tbl_5g[4]);
+ dev_dbg(aicwf_hw->dev, "lvl_adj_5g_chan_155:%d\n",
+ txpwr_lvl_adj->pwrlvl_adj_tbl_5g[5]);
+
+ txpwr_lvl_adj_req->txpwr_lvl_adj = *txpwr_lvl_adj;
+
+ /* Send the MM_SET_TXPWR_LVL_REQ message to UMAC FW */
+ error = aicwf_send_msg(aicwf_hw, txpwr_lvl_adj_req, 1,
+ MM_SET_TXPWR_LVL_ADJ_CFM, NULL, 0);
+
+ return error;
+}
+
+int aicwf_send_txpwr_ofst2x_req(struct aicwf_hw *aicwf_hw)
+{
+ struct mm_set_txpwr_ofst_req *txpwr_ofst_req;
+ struct txpwr_ofst2x_conf *txpwr_ofst2x;
+ int error = 0;
+ int type, ch_grp;
+
+ /* Build the MM_SET_TXPWR_OFST_REQ message */
+ txpwr_ofst_req =
+ aicwf_msg_zalloc(aicwf_hw, MM_SET_TXPWR_OFST_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_set_txpwr_ofst_req));
+
+ if (!txpwr_ofst_req)
+ return -ENOMEM;
+
+ txpwr_ofst2x = &txpwr_ofst_req->txpwr_ofst2x;
+ txpwr_ofst2x->enable = 0;
+ for (type = 0; type < 3; type++) {
+ for (ch_grp = 0; ch_grp < 6; ch_grp++) {
+ if (ch_grp < 3)
+ txpwr_ofst2x->pwrofst2x_tbl_2g4[type][ch_grp] = 0;
+ txpwr_ofst2x->pwrofst2x_tbl_5g[type][ch_grp] = 0;
+ }
+ }
+
+ aic_chip_get_userconfig_txpwr_ofst2x(aicwf_hw, txpwr_ofst2x);
+
+ if (txpwr_ofst2x->enable) {
+ dev_dbg(aicwf_hw->dev, "enable:%d\n", txpwr_ofst2x->enable);
+ dev_dbg(aicwf_hw->dev, "pwrofst2x 2.4g: [0]:11b, [1]:ofdm_highrate, [2]:ofdm_lowrate\n chan=\t1-4\t5-9\t10-13");
+ for (type = 0; type < 3; type++) {
+ dev_dbg(aicwf_hw->dev, "\n [%d] =", type);
+ for (ch_grp = 0; ch_grp < 3; ch_grp++) {
+ dev_dbg(aicwf_hw->dev, "\t%d",
+ txpwr_ofst2x->pwrofst2x_tbl_2g4[type][ch_grp]);
+ }
+ }
+ dev_dbg(aicwf_hw->dev, "\npwrofst2x 5g: [0]:ofdm_lowrate, [1]:ofdm_highrate, [2]:ofdm_midrate\n chan=\t36-50\t51-64\t98-114\t115-130\t131-146\t147-166");
+ for (type = 0; type < 3; type++) {
+ dev_dbg(aicwf_hw->dev, "\n [%d] =", type);
+ for (ch_grp = 0; ch_grp < 6; ch_grp++)
+ dev_dbg(aicwf_hw->dev, "\t%d",
+ txpwr_ofst2x->pwrofst2x_tbl_5g[type][ch_grp]);
+ }
+ dev_dbg(aicwf_hw->dev, "\n");
+
+ /* Send the MM_SET_TXPWR_OFST_REQ message to UMAC FW */
+ error = aicwf_send_msg(aicwf_hw, txpwr_ofst_req, 1, MM_SET_TXPWR_OFST_CFM,
+ NULL, 0);
+ } else {
+ dev_dbg(aicwf_hw->dev, "do not use txpwr_ofst2x\n");
+ aicwf_msg_free(aicwf_hw, txpwr_ofst_req);
+ }
+
+ return error;
+}
+
+/******************************************************************************
+ * Control messages handling functions (FULLMAC only)
+ *****************************************************************************/
+#ifdef CONFIG_AICWF_FULLMAC
+int aicwf_send_me_config_req(struct aicwf_hw *aicwf_hw)
+{
+ struct me_config_req *req;
+ struct wiphy *wiphy = aicwf_hw->wiphy;
+ struct ieee80211_supported_band *band_2ghz =
+ wiphy->bands[NL80211_BAND_2GHZ];
+ struct ieee80211_sta_ht_cap *ht_cap;
+ struct ieee80211_sta_vht_cap *vht_cap;
+ struct ieee80211_sta_he_cap const *he_cap = NULL;
+
+ u8 *ht_mcs;
+ int i;
+
+ if (aicwf_hw->chip_ops->use_80_bandwidth)
+ aicwf_hw->mod_params->use_80 = true;
+
+ if (aicwf_hw->band_5g_support) {
+ ht_cap = &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap;
+ vht_cap = &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap;
+ } else {
+ ht_cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap;
+ vht_cap = &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap;
+ }
+
+ ht_mcs = (u8 *)&ht_cap->mcs;
+
+ /* Build the ME_CONFIG_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, ME_CONFIG_REQ, TASK_ME, DRV_TASK_ID,
+ sizeof(struct me_config_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the ME_CONFIG_REQ message */
+ req->ht_supp = ht_cap->ht_supported;
+ req->vht_supp = vht_cap->vht_supported;
+ req->ht_cap.ht_capa_info =
+ cpu_to_le16(ht_cap->cap | IEEE80211_HT_CAP_LDPC_CODING);
+ req->ht_cap.a_mpdu_param =
+ ht_cap->ampdu_factor |
+ (ht_cap->ampdu_density << IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
+ for (i = 0; i < sizeof(ht_cap->mcs); i++)
+ req->ht_cap.mcs_rate[i] = ht_mcs[i];
+ req->ht_cap.ht_extended_capa = 0;
+ req->ht_cap.tx_beamforming_capa = 0;
+ req->ht_cap.asel_capa = 0;
+
+ if (req->vht_supp) {
+ req->vht_cap.vht_capa_info = cpu_to_le32(vht_cap->cap);
+ req->vht_cap.rx_highest = vht_cap->vht_mcs.rx_highest;
+ req->vht_cap.rx_mcs_map = vht_cap->vht_mcs.rx_mcs_map;
+ req->vht_cap.tx_highest = vht_cap->vht_mcs.tx_highest;
+ req->vht_cap.tx_mcs_map = vht_cap->vht_mcs.tx_mcs_map;
+ }
+
+ he_cap = ieee80211_get_he_iftype_cap(band_2ghz, NL80211_IFTYPE_STATION);
+ if (he_cap) {
+ req->he_supp = he_cap->has_he;
+ for (i = 0; i < ARRAY_SIZE(he_cap->he_cap_elem.mac_cap_info); i++)
+ req->he_cap.mac_cap_info[i] = he_cap->he_cap_elem.mac_cap_info[i];
+
+ for (i = 0; i < ARRAY_SIZE(he_cap->he_cap_elem.phy_cap_info); i++)
+ req->he_cap.phy_cap_info[i] = he_cap->he_cap_elem.phy_cap_info[i];
+
+ req->he_cap.mcs_supp.rx_mcs_80 = he_cap->he_mcs_nss_supp.rx_mcs_80;
+ req->he_cap.mcs_supp.tx_mcs_80 = he_cap->he_mcs_nss_supp.tx_mcs_80;
+ req->he_cap.mcs_supp.rx_mcs_160 = he_cap->he_mcs_nss_supp.rx_mcs_160;
+ req->he_cap.mcs_supp.tx_mcs_160 = he_cap->he_mcs_nss_supp.tx_mcs_160;
+ req->he_cap.mcs_supp.rx_mcs_80p80 =
+ he_cap->he_mcs_nss_supp.rx_mcs_80p80;
+ req->he_cap.mcs_supp.tx_mcs_80p80 =
+ he_cap->he_mcs_nss_supp.tx_mcs_80p80;
+ for (i = 0; i < MAC_HE_PPE_THRES_MAX_LEN; i++)
+ req->he_cap.ppe_thres[i] = he_cap->ppe_thres[i];
+
+ req->he_ul_on = aicwf_hw->mod_params->he_ul_on;
+ }
+ req->ps_on = aicwf_hw->mod_params->ps_on;
+ req->dpsm = aicwf_hw->mod_params->dpsm;
+ req->tx_lft = aicwf_hw->mod_params->tx_lft;
+ req->ant_div_on = aicwf_hw->mod_params->ant_div;
+ if (aicwf_hw->mod_params->use_80)
+ req->phy_bw_max = PHY_CHNL_BW_80;
+ else if (aicwf_hw->mod_params->use_2040)
+ req->phy_bw_max = PHY_CHNL_BW_40;
+ else
+ req->phy_bw_max = PHY_CHNL_BW_20;
+
+ wiphy_info(wiphy, "HT supp %d, VHT supp %d, HE supp %d\n", req->ht_supp,
+ req->vht_supp, req->he_supp);
+ /* Send the ME_CONFIG_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, ME_CONFIG_CFM, NULL, 0);
+}
+
+static int aicwf_send_me_chan_config(struct aicwf_hw *aicwf_hw)
+{
+ struct me_chan_config_req *req;
+ struct wiphy *wiphy = aicwf_hw->wiphy;
+ enum nl80211_band band;
+ int i;
+
+ for (band = NL80211_BAND_2GHZ; band <= NL80211_BAND_5GHZ; band++) {
+ struct ieee80211_supported_band *b = wiphy->bands[band];
+
+ if (!b)
+ continue;
+ for (i = 0; i < b->n_channels; i++) {
+ if (!(b->channels[i].flags & IEEE80211_CHAN_DISABLED) &&
+ b->channels[i].max_power < S8_MIN)
+ return -ERANGE;
+ }
+ }
+
+ /* Build the ME_CHAN_CONFIG_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, ME_CHAN_CONFIG_REQ, TASK_ME, DRV_TASK_ID,
+ sizeof(struct me_chan_config_req));
+ if (!req)
+ return -ENOMEM;
+
+ req->chan2G4_cnt = 0;
+ if (wiphy->bands[NL80211_BAND_2GHZ]) {
+ struct ieee80211_supported_band *b = wiphy->bands[NL80211_BAND_2GHZ];
+
+ for (i = 0; i < b->n_channels; i++) {
+ req->chan2G4[req->chan2G4_cnt].flags =
+ get_chan_flags(b->channels[i].flags);
+ req->chan2G4[req->chan2G4_cnt].band = NL80211_BAND_2GHZ;
+ req->chan2G4[req->chan2G4_cnt].freq = b->channels[i].center_freq;
+ req->chan2G4[req->chan2G4_cnt].tx_power =
+ chan_to_fw_pwr(aicwf_hw, b->channels[i].max_power);
+ req->chan2G4_cnt++;
+ if (req->chan2G4_cnt == MAC_DOMAINCHANNEL_24G_MAX)
+ break;
+ }
+ }
+
+ req->chan5G_cnt = 0;
+ if (wiphy->bands[NL80211_BAND_5GHZ]) {
+ struct ieee80211_supported_band *b = wiphy->bands[NL80211_BAND_5GHZ];
+
+ for (i = 0; i < b->n_channels; i++) {
+ req->chan5G[req->chan5G_cnt].flags =
+ get_chan_flags(b->channels[i].flags);
+ req->chan5G[req->chan5G_cnt].band = NL80211_BAND_5GHZ;
+ req->chan5G[req->chan5G_cnt].freq = b->channels[i].center_freq;
+ req->chan5G[req->chan5G_cnt].tx_power =
+ chan_to_fw_pwr(aicwf_hw, b->channels[i].max_power);
+ req->chan5G_cnt++;
+ if (req->chan5G_cnt == MAC_DOMAINCHANNEL_5G_MAX)
+ break;
+ }
+ }
+
+ /* Send the ME_CHAN_CONFIG_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, ME_CHAN_CONFIG_CFM, NULL, 0);
+}
+
+int aicwf_send_me_chan_config_req(struct aicwf_hw *aicwf_hw)
+{
+ int ret;
+
+ mutex_lock(&aicwf_hw->reg_lock);
+ if (READ_ONCE(aicwf_hw->regdom_failed)) {
+ ret = -EIO;
+ goto out;
+ }
+
+ /* The command queue can defer a request without waiting for its CFM. */
+ reinit_completion(&aicwf_hw->chan_config_complete);
+ ret = aicwf_send_me_chan_config(aicwf_hw);
+ if (!ret &&
+ !wait_for_completion_timeout(&aicwf_hw->chan_config_complete,
+ msecs_to_jiffies(AICWF_80211_CMD_TIMEOUT_MS)))
+ ret = -ETIMEDOUT;
+ if (ret) {
+ WRITE_ONCE(aicwf_hw->regdom_failed, true);
+ wiphy_err(aicwf_hw->wiphy,
+ "Failed to apply channel limits: %d; reprobe required\n",
+ ret);
+ }
+out:
+ mutex_unlock(&aicwf_hw->reg_lock);
+ return ret;
+}
+
+int aicwf_send_me_set_control_port_req(struct aicwf_hw *aicwf_hw, bool opened,
+ u8 sta_idx)
+{
+ struct me_set_control_port_req *req;
+
+ /* Build the ME_SET_CONTROL_PORT_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, ME_SET_CONTROL_PORT_REQ, TASK_ME, DRV_TASK_ID,
+ sizeof(struct me_set_control_port_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the ME_SET_CONTROL_PORT_REQ message */
+ req->sta_idx = sta_idx;
+ req->control_port_open = opened;
+
+ /* Send the ME_SET_CONTROL_PORT_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, ME_SET_CONTROL_PORT_CFM, NULL, 0);
+}
+
+int aicwf_send_me_sta_add(struct aicwf_hw *aicwf_hw,
+ struct station_parameters *params, const u8 *mac,
+ u8 inst_nbr, struct me_sta_add_cfm *cfm)
+{
+ struct me_sta_add_req *req;
+ struct link_station_parameters *link_sta_params = ¶ms->link_sta_params;
+ struct aicwf_vif *aicwf_vif = aicwf_hw->vif_table[inst_nbr];
+
+ u8 *ht_mcs = (u8 *)&link_sta_params->ht_capa->mcs;
+
+ int i;
+
+ /* Build the MM_STA_ADD_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, ME_STA_ADD_REQ, TASK_ME, DRV_TASK_ID,
+ sizeof(struct me_sta_add_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the MM_STA_ADD_REQ message */
+ memcpy(&req->mac_addr.array[0], mac, ETH_ALEN);
+
+ req->rate_set.length = link_sta_params->supported_rates_len;
+ for (i = 0; i < link_sta_params->supported_rates_len; i++)
+ req->rate_set.array[i] = link_sta_params->supported_rates[i];
+
+ req->flags = 0;
+ if (link_sta_params->ht_capa) {
+ const struct ieee80211_ht_cap *ht_capa = link_sta_params->ht_capa;
+
+ req->flags |= STA_HT_CAPA;
+ req->ht_cap.ht_capa_info = ht_capa->cap_info;
+ req->ht_cap.a_mpdu_param = ht_capa->ampdu_params_info;
+ for (i = 0; i < sizeof(ht_capa->mcs); i++)
+ req->ht_cap.mcs_rate[i] = ht_mcs[i];
+ req->ht_cap.ht_extended_capa = ht_capa->extended_ht_cap_info;
+ req->ht_cap.tx_beamforming_capa = ht_capa->tx_BF_cap_info;
+ req->ht_cap.asel_capa = ht_capa->antenna_selection_info;
+ }
+
+ if (link_sta_params->vht_capa) {
+ const struct ieee80211_vht_cap *vht_capa = link_sta_params->vht_capa;
+
+ req->flags |= STA_VHT_CAPA;
+ req->vht_cap.vht_capa_info = vht_capa->vht_cap_info;
+ req->vht_cap.rx_highest = vht_capa->supp_mcs.rx_highest;
+ req->vht_cap.rx_mcs_map = vht_capa->supp_mcs.rx_mcs_map;
+ req->vht_cap.tx_highest = vht_capa->supp_mcs.tx_highest;
+ req->vht_cap.tx_mcs_map = vht_capa->supp_mcs.tx_mcs_map;
+ }
+
+ if (link_sta_params->he_capa) {
+ const struct ieee80211_he_cap_elem *he_capa = link_sta_params->he_capa;
+ struct ieee80211_he_mcs_nss_supp *mcs_nss_supp =
+ (struct ieee80211_he_mcs_nss_supp *)(he_capa + 1);
+
+ req->flags |= STA_HE_CAPA;
+ for (i = 0; i < ARRAY_SIZE(he_capa->mac_cap_info); i++)
+ req->he_cap.mac_cap_info[i] = he_capa->mac_cap_info[i];
+ for (i = 0; i < ARRAY_SIZE(he_capa->phy_cap_info); i++)
+ req->he_cap.phy_cap_info[i] = he_capa->phy_cap_info[i];
+ req->he_cap.mcs_supp.rx_mcs_80 = mcs_nss_supp->rx_mcs_80;
+ req->he_cap.mcs_supp.tx_mcs_80 = mcs_nss_supp->tx_mcs_80;
+ req->he_cap.mcs_supp.rx_mcs_160 = mcs_nss_supp->rx_mcs_160;
+ req->he_cap.mcs_supp.tx_mcs_160 = mcs_nss_supp->tx_mcs_160;
+ req->he_cap.mcs_supp.rx_mcs_80p80 = mcs_nss_supp->rx_mcs_80p80;
+ req->he_cap.mcs_supp.tx_mcs_80p80 = mcs_nss_supp->tx_mcs_80p80;
+ }
+
+ if (params->sta_flags_set & BIT(NL80211_STA_FLAG_WME))
+ req->flags |= STA_QOS_CAPA;
+
+ if (params->sta_flags_set & BIT(NL80211_STA_FLAG_MFP))
+ req->flags |= STA_MFP_CAPA;
+
+ if (link_sta_params->opmode_notif_used) {
+ req->flags |= STA_OPMOD_NOTIF;
+ req->opmode = link_sta_params->opmode_notif_used;
+ }
+
+ req->aid = cpu_to_le16(params->aid);
+ req->uapsd_queues = params->uapsd_queues;
+ req->max_sp_len = params->max_sp * 2;
+ req->vif_idx = inst_nbr;
+
+ if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
+ req->tdls_sta = true;
+ if ((params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH) &&
+ !aicwf_vif->tdls_chsw_prohibited)
+ req->tdls_chsw_allowed = true;
+ if (aicwf_vif->tdls_status == TDLS_SETUP_RSP_TX)
+ req->tdls_sta_initiator = true;
+ }
+
+ /* Send the ME_STA_ADD_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, ME_STA_ADD_CFM, cfm, sizeof(*cfm));
+}
+
+int aicwf_send_me_sta_del(struct aicwf_hw *aicwf_hw, u8 sta_idx, bool tdls_sta)
+{
+ struct me_sta_del_req *req;
+
+ /* Build the MM_STA_DEL_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, ME_STA_DEL_REQ, TASK_ME, DRV_TASK_ID,
+ sizeof(struct me_sta_del_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the MM_STA_DEL_REQ message */
+ req->sta_idx = sta_idx;
+ req->tdls_sta = tdls_sta;
+
+ /* Send the ME_STA_DEL_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, ME_STA_DEL_CFM, NULL, 0);
+}
+
+int aicwf_send_me_traffic_ind(struct aicwf_hw *aicwf_hw, u8 sta_idx, bool uapsd,
+ u8 tx_status)
+{
+ struct me_traffic_ind_req *req;
+
+ /* Build the ME_UTRAFFIC_IND_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, ME_TRAFFIC_IND_REQ, TASK_ME, DRV_TASK_ID,
+ sizeof(struct me_traffic_ind_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the ME_TRAFFIC_IND_REQ message */
+ req->sta_idx = sta_idx;
+ req->tx_avail = tx_status;
+ req->uapsd = uapsd;
+
+ /* Send the ME_TRAFFIC_IND_REQ to UMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, ME_TRAFFIC_IND_CFM, NULL, 0);
+}
+
+int aicwf_send_me_set_lp_level(struct aicwf_hw *aicwf_hw, u8 lp_level, u8 disable_filter)
+{
+ struct me_set_lp_level_req *req;
+
+ dev_dbg(aicwf_hw->dev, "lp_lvl: %d %d\n", lp_level, disable_filter);
+ /* Build the ME_SET_LP_LEVEL_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, ME_SET_LP_LEVEL_REQ, TASK_ME, DRV_TASK_ID,
+ sizeof(struct me_set_lp_level_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the ME_SET_LP_LEVEL_REQ message */
+ req->lp_level = lp_level;
+ req->disable_filter = disable_filter;
+
+ /* Send the ME_SET_LP_LEVEL_REQ message to FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, ME_SET_LP_LEVEL_CFM, NULL, 0);
+}
+
+int aicwf_send_sm_connect_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ struct cfg80211_connect_params *sme,
+ struct sm_connect_cfm *cfm)
+{
+ struct sm_connect_req *req;
+ int i;
+ u32 flags = 0;
+ bool gval = false;
+ bool pval = false;
+
+ if (READ_ONCE(aicwf_hw->regdom_failed))
+ return -EIO;
+
+ aicwf_vif->wep_enabled = false;
+ aicwf_vif->wep_auth_err = false;
+ aicwf_vif->last_auth_type = 0;
+
+ /* Build the SM_CONNECT_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, SM_CONNECT_REQ, TASK_SM, DRV_TASK_ID,
+ sizeof(struct sm_connect_req));
+ if (!req)
+ return -ENOMEM;
+
+ if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40 ||
+ sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104)
+ gval = true;
+
+ if (sme->crypto.n_ciphers_pairwise &&
+ (sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_WEP40 ||
+ sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_WEP104))
+ pval = true;
+
+ /* Set parameters for the SM_CONNECT_REQ message */
+ if (sme->crypto.n_ciphers_pairwise &&
+ (sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_WEP40 ||
+ sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_TKIP ||
+ sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_WEP104))
+ flags |= DISABLE_HT;
+
+ if (sme->crypto.control_port)
+ flags |= CONTROL_PORT_HOST;
+
+ if (sme->crypto.control_port_no_encrypt)
+ flags |= CONTROL_PORT_NO_ENC;
+
+ if (use_pairwise_key(&sme->crypto))
+ flags |= WPA_WPA2_IN_USE;
+
+ if (sme->mfp == NL80211_MFP_REQUIRED)
+ flags |= MFP_IN_USE;
+
+ if (aicwf_vif->sta.ap)
+ flags |= REASSOCIATION;
+
+ req->ctrl_port_ethertype = sme->crypto.control_port_ethertype;
+
+ if (sme->bssid)
+ memcpy(&req->bssid, sme->bssid, ETH_ALEN);
+ else
+ req->bssid = mac_addr_bcst;
+ req->vif_idx = aicwf_vif->vif_index;
+ if (sme->channel) {
+ req->chan.band = sme->channel->band;
+ req->chan.freq = sme->channel->center_freq;
+ req->chan.flags = get_chan_flags(sme->channel->flags);
+ } else {
+ req->chan.freq = (u16)-1;
+ }
+ if (sme->ssid_len > sizeof(aicwf_vif->sta.ssid))
+ goto invalid_param;
+
+ for (i = 0; i < sme->ssid_len; i++)
+ req->ssid.array[i] = sme->ssid[i];
+ req->ssid.length = sme->ssid_len;
+ req->flags = flags;
+ if (WARN_ON(sme->ie_len > sizeof(req->ie_buf)))
+ goto invalid_param;
+ if (sme->ie_len)
+ memcpy(req->ie_buf, sme->ie, sme->ie_len);
+ req->ie_len = sme->ie_len;
+ req->listen_interval = aicwf_mod_params.listen_itv;
+ req->dont_wait_bcmc = !aicwf_mod_params.listen_bcmc;
+
+ /* Set auth_type */
+ if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC)
+ req->auth_type = WLAN_AUTH_OPEN;
+ else if (sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM)
+ req->auth_type = WLAN_AUTH_OPEN;
+ else if (sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY)
+ req->auth_type = WLAN_AUTH_SHARED_KEY;
+ else if (sme->auth_type == NL80211_AUTHTYPE_FT)
+ req->auth_type = WLAN_AUTH_FT;
+ else if (sme->auth_type == NL80211_AUTHTYPE_SAE)
+ req->auth_type = WLAN_AUTH_SAE;
+ else
+ goto invalid_param;
+
+ aicwf_vif->sta.auth_type = sme->auth_type;
+
+ /* Set UAPSD queues */
+ req->uapsd_queues = aicwf_mod_params.uapsd_queues;
+
+ aicwf_vif->wep_enabled = pval & gval;
+
+ if (aicwf_vif->wep_enabled)
+ aicwf_vif->last_auth_type = sme->auth_type;
+
+ memset(aicwf_vif->sta.ssid, 0, sizeof(aicwf_vif->sta.ssid));
+ memcpy(aicwf_vif->sta.ssid, sme->ssid, sme->ssid_len);
+ aicwf_vif->sta.ssid_len = sme->ssid_len;
+ if (sme->bssid)
+ memcpy(aicwf_vif->sta.bssid, sme->bssid, ETH_ALEN);
+
+ dev_dbg(aicwf_hw->dev,
+ "vif %d connect to %*pE channel %d auth_type %d\n",
+ aicwf_vif->drv_vif_index, aicwf_vif->sta.ssid_len,
+ aicwf_vif->sta.ssid, req->chan.freq, req->auth_type);
+
+ /* Send the SM_CONNECT_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, SM_CONNECT_CFM, cfm, sizeof(*cfm));
+
+invalid_param:
+ aicwf_msg_free(aicwf_hw, req);
+ return -EINVAL;
+}
+
+int aicwf_send_sm_disconnect_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif, u16 reason)
+{
+ struct sm_disconnect_req *req;
+
+ /* Build the SM_DISCONNECT_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, SM_DISCONNECT_REQ, TASK_SM, DRV_TASK_ID,
+ sizeof(struct sm_disconnect_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the SM_DISCONNECT_REQ message */
+ req->reason_code = reason;
+ req->vif_idx = aicwf_vif->vif_index;
+
+ /* Send the SM_DISCONNECT_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, SM_DISCONNECT_CFM, NULL, 0);
+}
+
+int aicwf_send_sm_external_auth_required_rsp(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif,
+ u16 status)
+{
+ struct sm_external_auth_required_rsp *rsp;
+
+ /* Build the SM_EXTERNAL_AUTH_CFM message */
+ rsp = aicwf_msg_zalloc(aicwf_hw, SM_EXTERNAL_AUTH_REQUIRED_RSP, TASK_SM, DRV_TASK_ID,
+ sizeof(struct sm_external_auth_required_rsp));
+ if (!rsp)
+ return -ENOMEM;
+
+ rsp->status = status;
+ rsp->vif_idx = aicwf_vif->vif_index;
+
+ /* send the SM_EXTERNAL_AUTH_REQUIRED_RSP message UMAC FW */
+ return aicwf_send_msg(aicwf_hw, rsp, 1, SM_EXTERNAL_AUTH_REQUIRED_RSP_CFM,
+ NULL, 0);
+}
+
+int aicwf_send_apm_start_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ struct cfg80211_ap_settings *settings,
+ struct apm_start_cfm *cfm,
+ struct aicwf_ipc_elem_var *elem)
+{
+ struct apm_start_req *req;
+ struct aicwf_bcn *bcn = &vif->ap.bcn;
+ u8 *buf;
+ u32 flags = 0;
+ const u8 *rate_ie;
+ u8 rate_len = 0;
+ int var_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
+ const u8 *var_pos;
+ int len, i;
+
+ /* Build the APM_START_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, APM_START_REQ, TASK_APM, DRV_TASK_ID,
+ sizeof(struct apm_start_req));
+ if (!req)
+ return -ENOMEM;
+
+ // Build the beacon
+ bcn->dtim = (u8)settings->dtim_period;
+ buf = aicwf_build_bcn(bcn, &settings->beacon);
+ if (!buf) {
+ aicwf_msg_free(aicwf_hw, req);
+ return -ENOMEM;
+ }
+
+ // Retrieve the basic rate set from the beacon buffer
+ len = bcn->len - var_offset;
+ var_pos = buf + var_offset;
+
+// Assume that rate higher that 54 Mbps are BSS membership
+
+ rate_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
+ if (rate_ie) {
+ const u8 *rates = rate_ie + 2;
+ u8 rate1 = 0;
+ bool is_basic1;
+
+ for (i = 0; i < rate_ie[1] && rate_len < MAC_RATESET_LEN; i++) {
+ rate1 = rates[i];
+ is_basic1 = ((rate1 & 0x80) && ((rate1 & ~0x80) <= (54 * 2)));
+ if (is_basic1)
+ req->basic_rates.array[rate_len++] = rate1;
+ }
+ }
+ rate_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, var_pos, len);
+ if (rate_ie) {
+ const u8 *rates = rate_ie + 2;
+ u8 rate2 = 0;
+ bool is_basic2;
+
+ for (i = 0; i < rate_ie[1] && rate_len < MAC_RATESET_LEN; i++) {
+ rate2 = rates[i];
+ is_basic2 = ((rate2 & 0x80) && ((rate2 & ~0x80) <= (54 * 2)));
+ if (is_basic2)
+ req->basic_rates.array[rate_len++] = rate2;
+ }
+ }
+ req->basic_rates.length = rate_len;
+
+ aicwf_send_bcn(aicwf_hw, buf, vif->vif_index, bcn->len);
+
+ /* Set parameters for the APM_START_REQ message */
+ req->vif_idx = vif->vif_index;
+ req->bcn_addr = elem->dma_addr;
+ req->bcn_len = bcn->len;
+ req->tim_oft = bcn->head_len;
+ req->tim_len = bcn->tim_len;
+ req->chan.band = settings->chandef.chan->band;
+ req->chan.freq = settings->chandef.chan->center_freq;
+ req->chan.flags = 0;
+ req->chan.tx_power = chan_to_fw_pwr(aicwf_hw, settings->chandef.chan->max_power);
+ req->center_freq1 = settings->chandef.center_freq1;
+ req->center_freq2 = settings->chandef.center_freq2;
+ req->ch_width = bw2chnl[settings->chandef.width];
+ req->bcn_int = settings->beacon_interval;
+
+ if (settings->crypto.control_port)
+ flags |= CONTROL_PORT_HOST;
+
+ if (settings->crypto.control_port_no_encrypt)
+ flags |= CONTROL_PORT_NO_ENC;
+
+ if (use_pairwise_key(&settings->crypto))
+ flags |= WPA_WPA2_IN_USE;
+
+ if (settings->crypto.control_port_ethertype)
+ req->ctrl_port_ethertype = settings->crypto.control_port_ethertype;
+ else
+ req->ctrl_port_ethertype = cpu_to_be16(ETH_P_PAE);
+ req->flags = flags;
+
+ /* Send the APM_START_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, APM_START_CFM, cfm, sizeof(*cfm));
+}
+
+int aicwf_send_apm_stop_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif)
+{
+ struct apm_stop_req *req;
+
+ /* Build the APM_STOP_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, APM_STOP_REQ, TASK_APM, DRV_TASK_ID,
+ sizeof(struct apm_stop_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the APM_STOP_REQ message */
+ req->vif_idx = vif->vif_index;
+
+ /* Send the APM_STOP_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, APM_STOP_CFM, NULL, 0);
+}
+
+#define P2P_WILDCARD_SSID "DIRECT-"
+#define P2P_WILDCARD_SSID_LEN (sizeof(P2P_WILDCARD_SSID) - 1)
+
+#ifdef CONFIG_AIC8800_SET_VENDOR_EXTENSION_IE
+u8 vendor_extension_data[256];
+u8 vendor_extension_len;
+
+static void aicwf_insert_vendor_extension_data(struct scanu_vendor_ie_req *ie_req)
+{
+ u8 temp_ie[256];
+ u8 vendor_extension_subelement[3] = {0x00, 0x37, 0x2A};
+ u8 vendor_extension_id[2] = {0x10, 0x49};
+ int index = 0;
+ int vendor_extension_subelement_len = 0;
+
+ memset(temp_ie, 0, 256);
+
+ // find vendor_extension_subelement
+ for (index = 0; index < ie_req->add_ie_len; index++) {
+ if (ie_req->ie[index] == vendor_extension_id[0]) {
+ index++;
+ if (index == ie_req->add_ie_len)
+ return;
+
+ if (ie_req->ie[index] == vendor_extension_id[1] &&
+ ie_req->ie[index + 3] == vendor_extension_subelement[0] &&
+ ie_req->ie[index + 4] == vendor_extension_subelement[1] &&
+ ie_req->ie[index + 5] == vendor_extension_subelement[2]) {
+ index = index + 2;
+ vendor_extension_subelement_len = ie_req->ie[index];
+ pr_debug("find vendor_extension_subelement,index:%d len:%d\n",
+ index, ie_req->ie[index]);
+ break;
+ }
+ }
+ }
+ index = index + vendor_extension_subelement_len;
+
+ // insert vendor extension
+ memcpy(&temp_ie[0], ie_req->ie, index + 1);
+ memcpy(&temp_ie[index + 1], vendor_extension_data,
+ vendor_extension_len /*sizeof(vendor_extension_data) */);
+ memcpy(&temp_ie[index + 1 +
+ vendor_extension_len /*sizeof(vendor_extension_data) */],
+ &ie_req->ie[index + 1], ie_req->add_ie_len - index);
+
+ memcpy(ie_req->ie, temp_ie,
+ ie_req->add_ie_len +
+ vendor_extension_len /*sizeof(vendor_extension_data) */);
+ ie_req->add_ie_len =
+ ie_req->add_ie_len +
+ vendor_extension_len /*sizeof(vendor_extension_data) */;
+ ie_req->ie[1] =
+ ie_req->ie[1] + vendor_extension_len /*sizeof(vendor_extension_data) */;
+
+ // ie_req->add_ie_len);
+}
+#endif // CONFIG_AIC8800_SET_VENDOR_EXTENSION_IE
+
+int aicwf_send_scanu_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ struct cfg80211_scan_request *param)
+{
+ struct scanu_start_req *req = NULL;
+ struct scanu_vendor_ie_req *ie_req = NULL;
+ struct mm_add_if_cfm add_if_cfm;
+ int i;
+ u8 chan_flags = 0;
+ int err;
+
+ if (READ_ONCE(aicwf_hw->regdom_failed))
+ return -EIO;
+
+ /* Build the SCANU_START_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, SCANU_START_REQ, TASK_SCANU, DRV_TASK_ID,
+ sizeof(struct scanu_start_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters */
+ req->vif_idx = aicwf_vif->vif_index;
+ req->chan_cnt = (u8)min_t(int, SCAN_CHANNEL_MAX, param->n_channels);
+
+ req->ssid_cnt = (u8)min_t(int, SCAN_SSID_MAX, param->n_ssids);
+
+ req->bssid = mac_addr_bcst;
+ req->no_cck = param->no_cck;
+ if (param->duration_mandatory)
+ // req->duration = ieee80211_tu_to_usec(param->duration);
+ req->duration = 0;
+
+ if (req->ssid_cnt == 0)
+ chan_flags |= CHAN_NO_IR;
+ for (i = 0; i < req->ssid_cnt; i++) {
+ int j;
+
+ for (j = 0; j < param->ssids[i].ssid_len; j++)
+ req->ssid[i].array[j] = param->ssids[i].ssid[j];
+ req->ssid[i].length = param->ssids[i].ssid_len;
+
+ if (!memcmp(P2P_WILDCARD_SSID, param->ssids[i].ssid,
+ P2P_WILDCARD_SSID_LEN)) {
+ dev_dbg(aicwf_hw->dev, "p2p scanu:%d,%d,%d\n", aicwf_vif->vif_index,
+ aicwf_vif->is_p2p_vif, aicwf_hw->is_p2p_alive);
+#ifdef CONFIG_AIC8800_USE_P2P0
+ if (aicwf_vif->is_p2p_vif && !aicwf_hw->is_p2p_alive) {
+#else
+ if (aicwf_vif == aicwf_hw->p2p_dev_vif && !aicwf_vif->up) {
+#endif
+ err = aicwf_send_add_if(aicwf_hw, aicwf_vif->wdev.address,
+ AICWF_VIF_TYPE(aicwf_vif), false,
+ &add_if_cfm);
+ if (err)
+ goto error;
+
+ if (add_if_cfm.status != 0) {
+ err = -EIO;
+ goto error;
+ }
+
+ /* Save the index retrieved from LMAC */
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_vif->vif_index = add_if_cfm.inst_nbr;
+ aicwf_vif->up = true;
+ aicwf_hw->vif_started++;
+ aicwf_hw->vif_table[add_if_cfm.inst_nbr] = aicwf_vif;
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ }
+ aicwf_hw->is_p2p_alive = 1;
+#ifndef CONFIG_AIC8800_USE_P2P0
+ mod_timer(&aicwf_hw->p2p_alive_timer,
+ jiffies + msecs_to_jiffies(1000));
+ atomic_set(&aicwf_hw->p2p_alive_timer_count, 0);
+#endif
+ dev_dbg(aicwf_hw->dev, "p2p scan start\n");
+ }
+ }
+
+ if (param->ie) {
+ ie_req = aicwf_msg_zalloc(aicwf_hw, SCANU_VENDOR_IE_REQ, TASK_SCANU, DRV_TASK_ID,
+ sizeof(struct scanu_vendor_ie_req));
+ if (!ie_req) {
+ err = -ENOMEM;
+ goto error;
+ }
+
+ ie_req->add_ie_len = param->ie_len;
+ ie_req->vif_idx = aicwf_vif->vif_index;
+ memcpy(ie_req->ie, param->ie, param->ie_len);
+#ifdef CONFIG_AIC8800_SET_VENDOR_EXTENSION_IE
+ aicwf_insert_vendor_extension_data(ie_req);
+#endif // CONFIG_AIC8800_SET_VENDOR_EXTENSION_IE
+ req->add_ie_len = 0;
+ req->add_ies = 0;
+
+ err = aicwf_send_msg(aicwf_hw, ie_req, 1, SCANU_VENDOR_IE_CFM, NULL, 0);
+ ie_req = NULL;
+ if (err)
+ goto error;
+ } else {
+ req->add_ie_len = 0;
+ req->add_ies = 0;
+ }
+
+ for (i = 0; i < req->chan_cnt; i++) {
+ struct ieee80211_channel *chan = param->channels[i];
+
+ dev_dbg(aicwf_hw->dev, "scan channel:%d%d\n",
+ ieee80211_frequency_to_channel(chan->center_freq),
+ chan->center_freq);
+ req->chan[i].band = chan->band;
+ req->chan[i].freq = chan->center_freq;
+ req->chan[i].flags = chan_flags | get_chan_flags(chan->flags);
+ req->chan[i].tx_power = chan_to_fw_pwr(aicwf_hw, chan->max_power);
+ }
+
+ /* Send the SCANU_START_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, SCANU_START_CFM_ADDTIONAL, NULL, 0);
+error:
+ if (req)
+ aicwf_msg_free(aicwf_hw, req);
+ if (ie_req)
+ aicwf_msg_free(aicwf_hw, ie_req);
+ return err;
+}
+
+int aicwf_send_scanu_cancel_req(struct aicwf_hw *aicwf_hw,
+ struct scan_cancel_cfm *cfm)
+{
+ struct scan_cancel_req *req;
+
+ /* Build the SCAN_CANCEL_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, SCANU_CANCEL_REQ, TASK_SCANU, DRV_TASK_ID,
+ sizeof(struct scan_cancel_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Send the SCAN_CANCEL_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, SCANU_CANCEL_CFM, cfm, sizeof(*cfm));
+}
+
+int aicwf_send_apm_start_cac_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ struct cfg80211_chan_def *chandef,
+ struct apm_start_cac_cfm *cfm)
+{
+ struct apm_start_cac_req *req;
+
+ /* Build the APM_START_CAC_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, APM_START_CAC_REQ, TASK_APM, DRV_TASK_ID,
+ sizeof(struct apm_start_cac_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the APM_START_CAC_REQ message */
+ req->vif_idx = vif->vif_index;
+ req->chan.band = chandef->chan->band;
+ req->chan.freq = chandef->chan->center_freq;
+ req->chan.flags = 0;
+ req->center_freq1 = chandef->center_freq1;
+ req->center_freq2 = chandef->center_freq2;
+ req->ch_width = bw2chnl[chandef->width];
+
+ /* Send the APM_START_CAC_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, APM_START_CAC_CFM, cfm, sizeof(*cfm));
+}
+
+int aicwf_send_apm_stop_cac_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif)
+{
+ struct apm_stop_cac_req *req;
+
+ /* Build the APM_STOP_CAC_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, APM_STOP_CAC_REQ, TASK_APM, DRV_TASK_ID,
+ sizeof(struct apm_stop_cac_req));
+ if (!req)
+ return -ENOMEM;
+
+ /* Set parameters for the APM_STOP_CAC_REQ message */
+ req->vif_idx = vif->vif_index;
+
+ /* Send the APM_STOP_CAC_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, APM_STOP_CAC_CFM, NULL, 0);
+}
+
+int aicwf_send_mesh_start_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ const struct mesh_config *conf,
+ const struct mesh_setup *setup,
+ struct mesh_start_cfm *cfm)
+{
+ // Message to send
+ struct mesh_start_req *req;
+ // Supported basic rates
+ struct ieee80211_supported_band *band_2ghz =
+ aicwf_hw->wiphy->bands[NL80211_BAND_2GHZ];
+ /* Counter */
+ int i;
+ /* Return status */
+ int status;
+ /* DMA Address to be unmapped after confirmation reception */
+ u32 dma_addr = 0;
+
+ /* Build the MESH_START_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MESH_START_REQ, TASK_MESH, DRV_TASK_ID,
+ sizeof(struct mesh_start_req));
+ if (!req)
+ return -ENOMEM;
+
+ req->vif_index = vif->vif_index;
+ req->bcn_int = setup->beacon_interval;
+ req->dtim_period = setup->dtim_period;
+ req->mesh_id_len = setup->mesh_id_len;
+
+ for (i = 0; i < setup->mesh_id_len; i++)
+ req->mesh_id[i] = *(setup->mesh_id + i);
+
+ req->user_mpm = setup->user_mpm;
+ req->is_auth = setup->is_authenticated;
+ req->auth_id = setup->auth_id;
+ req->ie_len = setup->ie_len;
+
+ if (setup->ie_len) {
+ /*
+ * Need to provide a Virtual Address to the MAC so that it can
+ * download the additional information elements.
+ */
+ req->ie_addr = dma_map_single(aicwf_hw->dev, (void *)setup->ie,
+ setup->ie_len, DMA_FROM_DEVICE);
+
+ /* Check DMA mapping result */
+ if (dma_mapping_error(aicwf_hw->dev, req->ie_addr)) {
+ dev_dbg(aicwf_hw->dev, "- DMA Mapping error on additional IEs\n");
+
+ /* Consider there is no Additional IEs */
+ req->ie_len = 0;
+ } else {
+ /* Store DMA Address so that we can unmap the memory section
+ * once MESH_START_CFM is received
+ */
+ dma_addr = req->ie_addr;
+ }
+ }
+
+ /* Provide rate information */
+ req->basic_rates.length = 0;
+ for (i = 0; i < band_2ghz->n_bitrates; i++) {
+ u16 rate = band_2ghz->bitrates[i].bitrate;
+
+ /* Read value is in units of 100 Kbps, provided value is in units
+ * of 1Mbps, and multiplied by 2 so that 5.5 becomes 11
+ */
+ rate = (rate << 1) / 10;
+
+ if (setup->basic_rates & CO_BIT(i))
+ rate |= 0x80;
+
+ req->basic_rates.array[i] = (u8)rate;
+ req->basic_rates.length++;
+ }
+
+ /* Provide channel information */
+ req->chan.band = setup->chandef.chan->band;
+ req->chan.freq = setup->chandef.chan->center_freq;
+ req->chan.flags = 0;
+ req->chan.tx_power = chan_to_fw_pwr(aicwf_hw, setup->chandef.chan->max_power);
+ req->center_freq1 = setup->chandef.center_freq1;
+ req->center_freq2 = setup->chandef.center_freq2;
+ req->ch_width = bw2chnl[setup->chandef.width];
+
+ /* Send the MESH_START_REQ message to UMAC FW */
+ status = aicwf_send_msg(aicwf_hw, req, 1, MESH_START_CFM, cfm, sizeof(*cfm));
+
+ /* Unmap DMA area */
+ if (setup->ie_len)
+ dma_unmap_single(aicwf_hw->dev, dma_addr, setup->ie_len, DMA_TO_DEVICE);
+
+ /* Return the status */
+ return status;
+}
+
+int aicwf_send_mesh_stop_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ struct mesh_stop_cfm *cfm)
+{
+ // Message to send
+ struct mesh_stop_req *req;
+
+ /* Build the MESH_STOP_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MESH_STOP_REQ, TASK_MESH, DRV_TASK_ID,
+ sizeof(struct mesh_stop_req));
+ if (!req)
+ return -ENOMEM;
+
+ req->vif_idx = vif->vif_index;
+
+ /* Send the MESH_STOP_REQ message to UMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, MESH_STOP_CFM, cfm, sizeof(*cfm));
+}
+
+int aicwf_send_mesh_update_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ u32 mask, const struct mesh_config *p_mconf,
+ struct mesh_update_cfm *cfm)
+{
+ // Message to send
+ struct mesh_update_req *req;
+ // Keep only bit for fields which can be updated
+ u32 supp_mask = (mask << 1) & (CO_BIT(NL80211_MESHCONF_GATE_ANNOUNCEMENTS) |
+ CO_BIT(NL80211_MESHCONF_HWMP_ROOTMODE) |
+ CO_BIT(NL80211_MESHCONF_FORWARDING) |
+ CO_BIT(NL80211_MESHCONF_POWER_MODE));
+
+ if (!supp_mask)
+ return -ENOENT;
+
+ /* Build the MESH_UPDATE_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MESH_UPDATE_REQ, TASK_MESH, DRV_TASK_ID,
+ sizeof(struct mesh_update_req));
+
+ if (!req)
+ return -ENOMEM;
+
+ req->vif_idx = vif->vif_index;
+
+ if (supp_mask & CO_BIT(NL80211_MESHCONF_GATE_ANNOUNCEMENTS)) {
+ req->flags |= CO_BIT(MESH_UPDATE_FLAGS_GATE_MODE_BIT);
+ req->gate_announ = p_mconf->dot11MeshGateAnnouncementProtocol;
+ }
+
+ if (supp_mask & CO_BIT(NL80211_MESHCONF_HWMP_ROOTMODE)) {
+ req->flags |= CO_BIT(MESH_UPDATE_FLAGS_ROOT_MODE_BIT);
+ req->root_mode = p_mconf->dot11MeshHWMPRootMode;
+ }
+
+ if (supp_mask & CO_BIT(NL80211_MESHCONF_FORWARDING)) {
+ req->flags |= CO_BIT(MESH_UPDATE_FLAGS_MESH_FWD_BIT);
+ req->mesh_forward = p_mconf->dot11MeshForwarding;
+ }
+
+ if (supp_mask & CO_BIT(NL80211_MESHCONF_POWER_MODE)) {
+ req->flags |= CO_BIT(MESH_UPDATE_FLAGS_LOCAL_PSM_BIT);
+ req->local_ps_mode = p_mconf->power_mode;
+ }
+
+ /* Send the MESH_UPDATE_REQ message to UMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, MESH_UPDATE_CFM, cfm, sizeof(*cfm));
+}
+
+int aicwf_send_mesh_peer_info_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ u8 sta_idx, struct mesh_peer_info_cfm *cfm)
+{
+ // Message to send
+ struct mesh_peer_info_req *req;
+
+ /* Build the MESH_PEER_INFO_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MESH_PEER_INFO_REQ, TASK_MESH, DRV_TASK_ID,
+ sizeof(struct mesh_peer_info_req));
+ if (!req)
+ return -ENOMEM;
+
+ req->sta_idx = sta_idx;
+
+ /* Send the MESH_PEER_INFO_REQ message to UMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, MESH_PEER_INFO_CFM, cfm, sizeof(*cfm));
+}
+
+void aicwf_send_mesh_peer_update_ntf(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *vif, u8 sta_idx,
+ u8 mlink_state)
+{
+ // Message to send
+ struct mesh_peer_update_ntf *ntf;
+
+ /* Build the MESH_PEER_UPDATE_NTF message */
+ ntf = aicwf_msg_zalloc(aicwf_hw, MESH_PEER_UPDATE_NTF, TASK_MESH, DRV_TASK_ID,
+ sizeof(struct mesh_peer_update_ntf));
+
+ if (ntf) {
+ ntf->vif_idx = vif->vif_index;
+ ntf->sta_idx = sta_idx;
+ ntf->state = mlink_state;
+
+ /* Send the MESH_PEER_INFO_REQ message to UMAC FW */
+ aicwf_send_msg(aicwf_hw, ntf, 0, 0, NULL, 0);
+ }
+}
+
+void aicwf_send_mesh_path_create_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *vif, u8 *tgt_addr)
+{
+ /* Check if we are already waiting for a confirmation */
+ if (!vif->ap.create_path) {
+ // Message to send
+ struct mesh_path_create_req *req;
+
+ /* Build the MESH_PATH_CREATE_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MESH_PATH_CREATE_REQ, TASK_MESH, DRV_TASK_ID,
+ sizeof(struct mesh_path_create_req));
+
+ if (req) {
+ req->vif_idx = vif->vif_index;
+ memcpy(&req->tgt_mac_addr, tgt_addr, ETH_ALEN);
+
+ vif->ap.create_path = true;
+
+ /* Send the MESH_PATH_CREATE_REQ message to UMAC FW */
+ aicwf_send_msg(aicwf_hw, req, 0, 0, NULL, 0);
+ }
+ }
+}
+
+int aicwf_send_mesh_path_update_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *vif, const u8 *tgt_addr,
+ const u8 *p_nhop_addr,
+ struct mesh_path_update_cfm *cfm)
+{
+ // Message to send
+ struct mesh_path_update_req *req;
+
+ /* Build the MESH_PATH_UPDATE_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MESH_PATH_UPDATE_REQ, TASK_MESH, DRV_TASK_ID,
+ sizeof(struct mesh_path_update_req));
+ if (!req)
+ return -ENOMEM;
+
+ req->delete = (!p_nhop_addr);
+ req->vif_idx = vif->vif_index;
+ memcpy(&req->tgt_mac_addr, tgt_addr, ETH_ALEN);
+
+ if (p_nhop_addr)
+ memcpy(&req->nhop_mac_addr, p_nhop_addr, ETH_ALEN);
+
+ /* Send the MESH_PATH_UPDATE_REQ message to UMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, MESH_PATH_UPDATE_CFM, cfm, sizeof(*cfm));
+}
+
+void aicwf_send_mesh_proxy_add_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ u8 *ext_addr)
+{
+ // Message to send
+ struct mesh_proxy_add_req *req;
+
+ /* Build the MESH_PROXY_ADD_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MESH_PROXY_ADD_REQ, TASK_MESH, DRV_TASK_ID,
+ sizeof(struct mesh_proxy_add_req));
+
+ if (req) {
+ req->vif_idx = vif->vif_index;
+ memcpy(&req->ext_sta_addr, ext_addr, ETH_ALEN);
+
+ /* Send the MESH_PROXY_ADD_REQ message to UMAC FW */
+ aicwf_send_msg(aicwf_hw, req, 0, 0, NULL, 0);
+ }
+}
+
+int aicwf_send_tdls_peer_traffic_ind_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif)
+{
+ struct tdls_peer_traffic_ind_req *tdls_peer_traffic_ind_req;
+
+ if (!aicwf_vif->sta.tdls_sta)
+ return -ENOLINK;
+
+ /* Build the TDLS_PEER_TRAFFIC_IND_REQ message */
+ tdls_peer_traffic_ind_req =
+ aicwf_msg_zalloc(aicwf_hw, TDLS_PEER_TRAFFIC_IND_REQ, TASK_TDLS, DRV_TASK_ID,
+ sizeof(struct tdls_peer_traffic_ind_req));
+
+ if (!tdls_peer_traffic_ind_req)
+ return -ENOMEM;
+
+ /* Set parameters for the TDLS_PEER_TRAFFIC_IND_REQ message */
+ tdls_peer_traffic_ind_req->vif_index = aicwf_vif->vif_index;
+ tdls_peer_traffic_ind_req->sta_idx = aicwf_vif->sta.tdls_sta->sta_idx;
+ memcpy(&tdls_peer_traffic_ind_req->peer_mac_addr.array[0],
+ aicwf_vif->sta.tdls_sta->mac_addr, ETH_ALEN);
+ tdls_peer_traffic_ind_req->dialog_token = 0; // check dialog token value
+ tdls_peer_traffic_ind_req->last_tid = aicwf_vif->sta.tdls_sta->tdls.last_tid;
+ tdls_peer_traffic_ind_req->last_sn = aicwf_vif->sta.tdls_sta->tdls.last_sn;
+
+ /* Send the TDLS_PEER_TRAFFIC_IND_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, tdls_peer_traffic_ind_req, 0, 0, NULL, 0);
+}
+
+int aicwf_send_config_monitor_req(struct aicwf_hw *aicwf_hw,
+ struct cfg80211_chan_def *chandef,
+ struct me_config_monitor_cfm *cfm)
+{
+ struct me_config_monitor_req *req;
+
+ /* Build the ME_CONFIG_MONITOR_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, ME_CONFIG_MONITOR_REQ, TASK_ME, DRV_TASK_ID,
+ sizeof(struct me_config_monitor_req));
+ if (!req)
+ return -ENOMEM;
+
+ if (chandef) {
+ req->chan_set = true;
+
+ req->chan.band = chandef->chan->band;
+ req->chan.type = bw2chnl[chandef->width];
+ req->chan.prim20_freq = chandef->chan->center_freq;
+ req->chan.center1_freq = chandef->center_freq1;
+ req->chan.center2_freq = chandef->center_freq2;
+ req->chan.tx_power = chan_to_fw_pwr(aicwf_hw, chandef->chan->max_power);
+
+ if (aicwf_hw->phy.limit_bw)
+ limit_chan_bw(&req->chan.type, req->chan.prim20_freq,
+ &req->chan.center1_freq);
+ } else {
+ req->chan_set = false;
+ }
+
+ req->uf = aicwf_hw->mod_params->uf;
+ req->auto_reply = aicwf_hw->mod_params->auto_reply;
+
+ /* Send the ME_CONFIG_MONITOR_REQ message to FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, ME_CONFIG_MONITOR_CFM, cfm, sizeof(*cfm));
+}
+#endif /* CONFIG_AICWF_FULLMAC */
+
+int aicwf_send_tdls_chan_switch_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif,
+ struct aicwf_sta *aicwf_sta,
+ bool sta_initiator, u8 oper_class,
+ struct cfg80211_chan_def *chandef,
+ struct tdls_chan_switch_cfm *cfm)
+{
+ struct tdls_chan_switch_req *tdls_chan_switch_req;
+
+ /* Build the TDLS_CHAN_SWITCH_REQ message */
+ tdls_chan_switch_req =
+ aicwf_msg_zalloc(aicwf_hw, TDLS_CHAN_SWITCH_REQ, TASK_TDLS, DRV_TASK_ID,
+ sizeof(struct tdls_chan_switch_req));
+
+ if (!tdls_chan_switch_req)
+ return -ENOMEM;
+
+ /* Set parameters for the TDLS_CHAN_SWITCH_REQ message */
+ tdls_chan_switch_req->vif_index = aicwf_vif->vif_index;
+ tdls_chan_switch_req->sta_idx = aicwf_sta->sta_idx;
+ memcpy(&tdls_chan_switch_req->peer_mac_addr.array[0],
+ aicwf_sta_addr(aicwf_sta), ETH_ALEN);
+ tdls_chan_switch_req->initiator = sta_initiator;
+ tdls_chan_switch_req->band = chandef->chan->band;
+ tdls_chan_switch_req->type = bw2chnl[chandef->width];
+ tdls_chan_switch_req->prim20_freq = chandef->chan->center_freq;
+ tdls_chan_switch_req->center1_freq = chandef->center_freq1;
+ tdls_chan_switch_req->center2_freq = chandef->center_freq2;
+ tdls_chan_switch_req->tx_power = chan_to_fw_pwr(aicwf_hw, chandef->chan->max_power);
+ tdls_chan_switch_req->op_class = oper_class;
+
+ /* Send the TDLS_CHAN_SWITCH_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, tdls_chan_switch_req, 1, TDLS_CHAN_SWITCH_CFM,
+ cfm, sizeof(*cfm));
+}
+
+int aicwf_send_tdls_cancel_chan_switch_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif,
+ struct aicwf_sta *aicwf_sta,
+ struct tdls_cancel_chan_switch_cfm *cfm)
+{
+ struct tdls_cancel_chan_switch_req *tdls_cancel_chan_switch_req;
+
+ /* Build the TDLS_CHAN_SWITCH_REQ message */
+ tdls_cancel_chan_switch_req =
+ aicwf_msg_zalloc(aicwf_hw, TDLS_CANCEL_CHAN_SWITCH_REQ, TASK_TDLS, DRV_TASK_ID,
+ sizeof(struct tdls_cancel_chan_switch_req));
+ if (!tdls_cancel_chan_switch_req)
+ return -ENOMEM;
+
+ /* Set parameters for the TDLS_CHAN_SWITCH_REQ message */
+ tdls_cancel_chan_switch_req->vif_index = aicwf_vif->vif_index;
+ tdls_cancel_chan_switch_req->sta_idx = aicwf_sta->sta_idx;
+ memcpy(&tdls_cancel_chan_switch_req->peer_mac_addr.array[0],
+ aicwf_sta_addr(aicwf_sta), ETH_ALEN);
+
+ /* Send the TDLS_CHAN_SWITCH_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, tdls_cancel_chan_switch_req, 1,
+ TDLS_CANCEL_CHAN_SWITCH_CFM, cfm, sizeof(*cfm));
+}
+
+#ifdef CONFIG_AICWF_BFMER
+#ifdef CONFIG_AICWF_FULLMAC
+void aicwf_send_bfmer_enable(struct aicwf_hw *aicwf_hw, struct aicwf_sta *aicwf_sta,
+ const struct ieee80211_vht_cap *vht_cap)
+#endif /* CONFIG_AICWF_FULLMAC */
+{
+ struct mm_bfmer_enable_req *bfmer_en_req;
+#ifdef CONFIG_AICWF_FULLMAC
+ u32 vht_capability;
+ u8 rx_nss = 0;
+#endif /* CONFIG_AICWF_FULLMAC */
+
+#ifdef CONFIG_AICWF_FULLMAC
+ if (!vht_cap) {
+#endif /* CONFIG_AICWF_FULLMAC */
+ goto end;
+ }
+
+#ifdef CONFIG_AICWF_FULLMAC
+ vht_capability = le32_to_cpu(vht_cap->vht_cap_info);
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ if (!(vht_capability & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE))
+ goto end;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ rx_nss = aicwf_bfmer_get_rx_nss(vht_cap);
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ /* Allocate a structure that will contain the beamforming report */
+ if (aicwf_bfmer_report_add(aicwf_hw, aicwf_sta,
+ AICWF_BFMER_REPORT_SPACE_SIZE))
+ goto end;
+
+ /* Build the MM_BFMER_ENABLE_REQ message */
+ bfmer_en_req = aicwf_msg_zalloc(aicwf_hw, MM_BFMER_ENABLE_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_bfmer_enable_req));
+
+ /* Check message allocation */
+ if (!bfmer_en_req) {
+ /* Free memory allocated for the report */
+ aicwf_bfmer_report_del(aicwf_hw, aicwf_sta);
+ /* Do not use beamforming */
+ goto end;
+ }
+
+ /* Provide DMA address to the MAC */
+ bfmer_en_req->host_bfr_addr = aicwf_sta->bfm_report->dma_addr;
+ bfmer_en_req->host_bfr_size = AICWF_BFMER_REPORT_SPACE_SIZE;
+ bfmer_en_req->sta_idx = aicwf_sta->sta_idx;
+#ifdef CONFIG_AICWF_FULLMAC
+ bfmer_en_req->aid = aicwf_sta->aid;
+ bfmer_en_req->rx_nss = rx_nss;
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ if (vht_capability & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
+ bfmer_en_req->vht_mu_bfmee = true;
+ else
+ bfmer_en_req->vht_mu_bfmee = false;
+
+ /* Send the MM_BFMER_EN_REQ message to LMAC FW */
+ aicwf_send_msg(aicwf_hw, bfmer_en_req, 0, 0, NULL, 0);
+
+end:
+ return;
+}
+
+#ifdef CONFIG_AICWF_MUMIMO_TX
+int aicwf_send_mu_group_update_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_sta *aicwf_sta)
+{
+ struct mm_mu_group_update_req *req;
+ int group_id, i = 0;
+ u64 map;
+
+ /* Build the MM_MU_GROUP_UPDATE_REQ message */
+ req =
+ aicwf_msg_zalloc(aicwf_hw, MM_MU_GROUP_UPDATE_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_mu_group_update_req) +
+ aicwf_sta->group_info.cnt * sizeof(req->groups[0]));
+
+ /* Check message allocation */
+ if (!req)
+ return -ENOMEM;
+
+ map = aicwf_sta->group_info.map & AICWF_MU_GROUP_MASK;
+ for (group_id = (fls64(map) - 1); group_id > 0;
+ map &= ~(u64)BIT_ULL(group_id), group_id = (fls64(map) - 1)) {
+ int user_pos = aicwf_mu_group_sta_get_pos(aicwf_hw, aicwf_sta, group_id);
+
+ if (WARN(i >= aicwf_sta->group_info.cnt,
+ "STA%d: Too much group %d\n", aicwf_sta->sta_idx, i + 1))
+ break;
+
+ req->groups[i].group_id = group_id;
+ req->groups[i].user_pos = user_pos;
+
+ i++;
+ }
+
+ req->group_cnt = aicwf_sta->group_info.cnt;
+ req->sta_idx = aicwf_sta->sta_idx;
+
+ /* Send the MM_MU_GROUP_UPDATE_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, MM_MU_GROUP_UPDATE_CFM, NULL, 0);
+}
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+#endif /* CONFIG_AICWF_BFMER */
+
+int aicwf_send_dbg_mem_read_req(struct aicwf_hw *aicwf_hw, u32 mem_addr,
+ struct dbg_mem_read_cfm *cfm)
+{
+ struct dbg_mem_read_req *mem_read_req;
+
+ /* Build the DBG_MEM_READ_REQ message */
+ mem_read_req = aicwf_msg_zalloc(aicwf_hw, DBG_MEM_READ_REQ, TASK_DBG, DRV_TASK_ID,
+ sizeof(struct dbg_mem_read_req));
+ if (!mem_read_req)
+ return -ENOMEM;
+
+ /* Set parameters for the DBG_MEM_READ_REQ message */
+ mem_read_req->memaddr = mem_addr;
+
+ /* Send the DBG_MEM_READ_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, mem_read_req, 1, DBG_MEM_READ_CFM, cfm, sizeof(*cfm));
+}
+
+int aicwf_send_dbg_mem_write_req(struct aicwf_hw *aicwf_hw, u32 mem_addr,
+ u32 mem_data)
+{
+ struct dbg_mem_write_req *mem_write_req;
+
+ /* Build the DBG_MEM_WRITE_REQ message */
+ mem_write_req = aicwf_msg_zalloc(aicwf_hw, DBG_MEM_WRITE_REQ, TASK_DBG, DRV_TASK_ID,
+ sizeof(struct dbg_mem_write_req));
+ if (!mem_write_req)
+ return -ENOMEM;
+
+ /* Set parameters for the DBG_MEM_WRITE_REQ message */
+ mem_write_req->memaddr = mem_addr;
+ mem_write_req->memdata = mem_data;
+
+ /* Send the DBG_MEM_WRITE_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, mem_write_req, 1, DBG_MEM_WRITE_CFM, NULL, 0);
+}
+
+int aicwf_send_dbg_mem_block_write_req(struct aicwf_hw *aicwf_hw, u32 mem_addr,
+ u32 mem_size, u32 *mem_data)
+{
+ struct dbg_mem_block_write_req *mem_blk_write_req;
+
+ /* Build the DBG_MEM_BLOCK_WRITE_REQ message */
+ mem_blk_write_req =
+ aicwf_msg_zalloc(aicwf_hw, DBG_MEM_BLOCK_WRITE_REQ, TASK_DBG, DRV_TASK_ID,
+ sizeof(struct dbg_mem_block_write_req));
+ if (!mem_blk_write_req)
+ return -ENOMEM;
+
+ /* Set parameters for the DBG_MEM_BLOCK_WRITE_REQ message */
+ mem_blk_write_req->memaddr = mem_addr;
+ mem_blk_write_req->memsize = mem_size;
+ memcpy(mem_blk_write_req->memdata, mem_data, mem_size);
+
+ /* Send the DBG_MEM_BLOCK_WRITE_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, mem_blk_write_req, 1, DBG_MEM_BLOCK_WRITE_CFM,
+ NULL, 0);
+}
+
+int aicwf_send_dbg_start_app_req(struct aicwf_hw *aicwf_hw, u32 boot_addr,
+ u32 boot_type)
+{
+ struct dbg_start_app_req *start_app_req;
+
+ /* Build the DBG_START_APP_REQ message */
+ start_app_req = aicwf_msg_zalloc(aicwf_hw, DBG_START_APP_REQ, TASK_DBG, DRV_TASK_ID,
+ sizeof(struct dbg_start_app_req));
+ if (!start_app_req)
+ return -ENOMEM;
+
+ /* Set parameters for the DBG_START_APP_REQ message */
+ start_app_req->bootaddr = boot_addr;
+ start_app_req->boottype = boot_type;
+
+ /* Send the DBG_START_APP_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, start_app_req, 1, DBG_START_APP_CFM, NULL, 0);
+}
+
+int aicwf_send_cfg_rssi_req(struct aicwf_hw *aicwf_hw, u8 vif_index,
+ int rssi_thold, u32 rssi_hyst)
+{
+ struct mm_cfg_rssi_req *req;
+
+ /* Build the MM_CFG_RSSI_REQ message */
+ req = aicwf_msg_zalloc(aicwf_hw, MM_CFG_RSSI_REQ, TASK_MM, DRV_TASK_ID,
+ sizeof(struct mm_cfg_rssi_req));
+ if (!req)
+ return -ENOMEM;
+
+ if (!aicwf_hw->vif_table[vif_index])
+ return 0;
+
+ /* Set parameters for the MM_CFG_RSSI_REQ message */
+ req->vif_index = vif_index;
+ req->rssi_thold = (s8)rssi_thold;
+ req->rssi_hyst = (u8)rssi_hyst;
+
+ /* Send the MM_CFG_RSSI_REQ message to LMAC FW */
+ return aicwf_send_msg(aicwf_hw, req, 1, MM_CFG_RSSI_CFM, NULL, 0);
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_tx.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_tx.h
new file mode 100644
index 000000000000..1c3212be0be2
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_tx.h
@@ -0,0 +1,201 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_MSG_TX_H_
+#define _AICWF_MSG_TX_H_
+
+#include "lmac_types.h"
+#include "aicwf_defs.h"
+
+int aicwf_send_reset(struct aicwf_hw *aicwf_hw);
+
+int aicwf_send_start(struct aicwf_hw *aicwf_hw);
+
+int aicwf_send_version_req(struct aicwf_hw *aicwf_hw, struct mm_version_cfm *cfm);
+
+int aicwf_send_add_if(struct aicwf_hw *aicwf_hw, const unsigned char *mac,
+ enum nl80211_iftype iftype, bool p2p,
+ struct mm_add_if_cfm *cfm);
+
+int aicwf_send_remove_if(struct aicwf_hw *aicwf_hw, u8 vif_index, bool defer);
+
+int aicwf_send_key_add(struct aicwf_hw *aicwf_hw, u8 vif_idx, u8 sta_idx,
+ bool pairwise, u8 *key, u8 key_len, u8 key_idx,
+ u8 cipher_suite, struct mm_key_add_cfm *cfm);
+
+int aicwf_send_key_del(struct aicwf_hw *aicwf_hw, uint8_t hw_key_idx);
+
+int aicwf_send_bcn(struct aicwf_hw *aicwf_hw, u8 *buf, u8 vif_idx, u16 bcn_len);
+
+int aicwf_send_bcn_change(struct aicwf_hw *aicwf_hw, u8 vif_idx, u32 bcn_addr,
+ u16 bcn_len, u16 tim_oft, u16 tim_len, u16 *csa_oft);
+
+int aicwf_send_roc(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ struct ieee80211_channel *chan, unsigned int duration,
+ struct mm_remain_on_channel_cfm *roc_cfm);
+
+int aicwf_send_cancel_roc(struct aicwf_hw *aicwf_hw);
+
+int aicwf_send_set_edca(struct aicwf_hw *aicwf_hw, u8 hw_queue, u32 param,
+ bool uapsd, u8 inst_nbr);
+
+int aicwf_send_tdls_chan_switch_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif,
+ struct aicwf_sta *aicwf_sta,
+ bool sta_initiator, u8 oper_class,
+ struct cfg80211_chan_def *chandef,
+ struct tdls_chan_switch_cfm *cfm);
+
+int aicwf_send_tdls_cancel_chan_switch_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ struct aicwf_sta *aicwf_sta,
+ struct tdls_cancel_chan_switch_cfm *cfm);
+
+#ifdef CONFIG_AIC8800_ARP_OFFLOAD
+int aicwf_send_arpoffload_en_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif, u32 ipaddr,
+ u8 enable);
+#endif
+
+int aicwf_send_rf_calib_req(struct aicwf_hw *aicwf_hw,
+ struct mm_set_rf_calib_cfm *cfm);
+
+int aicwf_send_get_macaddr_req(struct aicwf_hw *aicwf_hw,
+ struct mm_get_mac_addr_cfm *cfm);
+
+#ifdef CONFIG_AICWF_FULLMAC
+int aicwf_send_me_config_req(struct aicwf_hw *aicwf_hw);
+
+int aicwf_send_me_chan_config_req(struct aicwf_hw *aicwf_hw);
+
+int aicwf_send_me_set_control_port_req(struct aicwf_hw *aicwf_hw, bool opened,
+ u8 sta_idx);
+
+int aicwf_send_me_sta_add(struct aicwf_hw *aicwf_hw,
+ struct station_parameters *params, const u8 *mac,
+ u8 inst_nbr, struct me_sta_add_cfm *cfm);
+
+int aicwf_send_me_sta_del(struct aicwf_hw *aicwf_hw, u8 sta_idx, bool tdls_sta);
+
+int aicwf_send_me_traffic_ind(struct aicwf_hw *aicwf_hw, u8 sta_idx, bool uapsd,
+ u8 tx_status);
+
+int aicwf_send_me_set_lp_level(struct aicwf_hw *aicwf_hw, u8 lp_level, u8 disable_filter);
+
+int aicwf_send_sm_connect_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ struct cfg80211_connect_params *sme, struct sm_connect_cfm *cfm);
+
+int aicwf_send_sm_disconnect_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif, u16 reason);
+
+int aicwf_send_sm_external_auth_required_rsp(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif, u16 status);
+
+int aicwf_send_apm_start_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ struct cfg80211_ap_settings *settings, struct apm_start_cfm *cfm,
+ struct aicwf_ipc_elem_var *elem);
+
+int aicwf_send_apm_stop_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif);
+
+int aicwf_send_scanu_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ struct cfg80211_scan_request *param);
+
+int aicwf_send_scanu_cancel_req(struct aicwf_hw *aicwf_hw,
+ struct scan_cancel_cfm *cfm);
+
+int aicwf_send_apm_start_cac_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ struct cfg80211_chan_def *chandef,
+ struct apm_start_cac_cfm *cfm);
+
+int aicwf_send_apm_stop_cac_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif);
+
+int aicwf_send_tdls_peer_traffic_ind_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif);
+
+int aicwf_send_config_monitor_req(struct aicwf_hw *aicwf_hw,
+ struct cfg80211_chan_def *chandef,
+ struct me_config_monitor_cfm *cfm);
+
+int aicwf_send_mesh_start_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ const struct mesh_config *conf, const struct mesh_setup *setup,
+ struct mesh_start_cfm *cfm);
+
+int aicwf_send_mesh_stop_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ struct mesh_stop_cfm *cfm);
+
+int aicwf_send_mesh_update_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ u32 mask, const struct mesh_config *p_mconf,
+ struct mesh_update_cfm *cfm);
+
+int aicwf_send_mesh_peer_info_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ u8 sta_idx, struct mesh_peer_info_cfm *cfm);
+
+void aicwf_send_mesh_peer_update_ntf(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *vif, u8 sta_idx,
+ u8 mlink_state);
+
+void aicwf_send_mesh_path_create_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *vif, u8 *tgt_addr);
+
+int aicwf_send_mesh_path_update_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *vif, const u8 *tgt_addr,
+ const u8 *p_nhop_addr,
+ struct mesh_path_update_cfm *cfm);
+
+void aicwf_send_mesh_proxy_add_req(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ u8 *ext_addr);
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+#ifdef CONFIG_AICWF_BFMER
+#ifdef CONFIG_AICWF_FULLMAC
+void aicwf_send_bfmer_enable(struct aicwf_hw *aicwf_hw, struct aicwf_sta *aicwf_sta,
+ const struct ieee80211_vht_cap *vht_cap);
+
+#endif /* CONFIG_AICWF_FULLMAC */
+#ifdef CONFIG_AICWF_MUMIMO_TX
+int aicwf_send_mu_group_update_req(struct aicwf_hw *aicwf_hw,
+ struct aicwf_sta *aicwf_sta);
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+#endif /* CONFIG_AICWF_BFMER */
+
+int aicwf_send_dbg_mem_read_req(struct aicwf_hw *aicwf_hw, u32 mem_addr,
+ struct dbg_mem_read_cfm *cfm);
+
+int aicwf_send_dbg_mem_write_req(struct aicwf_hw *aicwf_hw, u32 mem_addr,
+ u32 mem_data);
+
+int aicwf_send_dbg_mem_block_write_req(struct aicwf_hw *aicwf_hw, u32 mem_addr,
+ u32 mem_size, u32 *mem_data);
+
+int aicwf_send_dbg_start_app_req(struct aicwf_hw *aicwf_hw, u32 boot_addr,
+ u32 boot_type);
+
+int aicwf_send_cfg_rssi_req(struct aicwf_hw *aicwf_hw, u8 vif_index,
+ int rssi_thold, u32 rssi_hyst);
+
+int aicwf_send_get_sta_info_req(struct aicwf_hw *aicwf_hw, u8 sta_idx,
+ struct mm_get_sta_info_cfm *cfm);
+
+int aicwf_send_set_stack_start_req(struct aicwf_hw *aicwf_hw, u8 on,
+ u8 efuse_valid, u8 set_vendor_info,
+ u8 fwtrace_redir_en,
+ struct mm_set_stack_start_cfm *cfm);
+
+int aicwf_send_get_temp_req(struct aicwf_hw *aicwf_hw,
+ struct mm_set_vendor_swconfig_cfm *cfm);
+
+int aicwf_send_set_temp_comp_req(struct aicwf_hw *aicwf_hw,
+ struct mm_set_vendor_swconfig_cfm *cfm);
+
+int aicwf_send_get_fw_version_req(struct aicwf_hw *aicwf_hw,
+ struct mm_get_fw_version_cfm *cfm);
+
+int aicwf_send_txpwr_ofst2x_req(struct aicwf_hw *aicwf_hw);
+
+int aicwf_send_txpwr_lvl_v3_req(struct aicwf_hw *aicwf_hw, int index_reg);
+
+int aicwf_send_txpwr_lvl_adj_req(struct aicwf_hw *aicwf_hw);
+
+#endif /* _AICWF_MSG_TX_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mu_group.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mu_group.h
new file mode 100644
index 000000000000..9233eb9e58b5
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mu_group.h
@@ -0,0 +1,163 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_MU_GROUP_H_
+#define _AICWF_MU_GROUP_H_
+
+#include <linux/semaphore.h>
+#include <linux/workqueue.h>
+
+struct aicwf_hw;
+struct aicwf_sta;
+
+#ifdef CONFIG_AICWF_MUMIMO_TX
+
+/**
+ * struct aicwf_sta_group_info - Group information for a STA
+ *
+ * @active: Node in the active-STA list
+ * @update: Node in the STA-update list
+ * @last_update: Identifier of the last group update applied to the STA
+ * @cnt: Number of groups the STA belongs to
+ * @map: Bitfield of groups the STA belongs to
+ * @traffic: Number of buffers sent since previous group selection
+ * @group: Id of the group selected by previous group selection
+ * (cf @aicwf_mu_group_sta_select)
+ */
+struct aicwf_sta_group_info {
+ struct list_head active;
+ struct list_head update;
+ u16 last_update;
+ int cnt;
+ u64 map;
+ int traffic;
+ u8 group;
+};
+
+/**
+ * struct aicwf_mu_group - Information about the users of a group
+ *
+ * @list: node for mu->active_groups
+ * @group_id: Group identifier
+ * @user_cnt: Number of the users in the group
+ * @users: Pointer to the sta, ordered by user position
+ */
+struct aicwf_mu_group {
+ struct list_head list;
+ int group_id;
+ int user_cnt;
+ struct aicwf_sta *users[NX_USER_MAX];
+};
+
+/**
+ * struct aicwf_mu_info - Information about all MU groups
+ *
+ * @active_groups: List of all possible groups. Ordered from the most recently
+ * used one to the least one (and possibly never used)
+ * @active_sta: List of MU beamformee sta that have been active (since previous
+ * group update). Ordered from the most recently active.
+ * @update_sta: List of sta whose group information has changed and need to be
+ * updated in the firmware
+ * @groups: Table of all groups
+ * @group_work: Work item used to schedule group update
+ * @update_count: Counter used to identify the last group formation update.
+ * (cf aicwf_sta_group_info.last_update)
+ * @lock: Lock held during group updates; TX does not use MU while it is held
+ * @next_group_select: Next time the group selection should be run
+ * (ref aicwf_mu_group_sta_select())
+ * @group_cnt: Number of group created
+ */
+struct aicwf_mu_info {
+ struct list_head active_groups;
+ struct list_head active_sta;
+ struct list_head update_sta;
+ struct aicwf_mu_group groups[NX_MU_GROUP_MAX];
+ struct delayed_work group_work;
+ u16 update_count;
+ struct semaphore lock;
+ unsigned long next_group_select;
+ u8 group_cnt;
+};
+
+#define AICWF_SU_GROUP BIT_ULL(0)
+#define AICWF_MU_GROUP_MASK 0x7ffffffffffffffeULL
+#define AICWF_MU_GROUP_INTERVAL 200 /* in ms */
+#define AICWF_MU_GROUP_SELECT_INTERVAL 100 /* in ms */
+// minimum traffic in a AICWF_MU_GROUP_SELECT_INTERVAL to consider the sta
+#define AICWF_MU_GROUP_MIN_TRAFFIC 50 /* in number of packet */
+
+#define AICWF_GET_FIRST_GROUP_ID(map) (fls64(map) - 1)
+
+#define AICWF_MUMIMO_INFO_POS_ID(info) (((info) >> 6) & 0x3)
+#define AICWF_MUMIMO_INFO_GROUP_ID(info) ((info) & 0x3f)
+
+static inline struct aicwf_mu_group *
+aicwf_mu_group_from_id(struct aicwf_mu_info *mu, int id)
+{
+ if (id > NX_MU_GROUP_MAX)
+ return NULL;
+
+ return &mu->groups[id - 1];
+}
+
+void aicwf_mu_group_sta_init(struct aicwf_sta *sta,
+ const struct ieee80211_vht_cap *vht_cap);
+void aicwf_mu_group_sta_del(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta);
+u64 aicwf_mu_group_sta_get_map(struct aicwf_sta *sta);
+int aicwf_mu_group_sta_get_pos(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta,
+ int group_id);
+
+void aicwf_mu_group_init(struct aicwf_hw *aicwf_hw);
+
+void aicwf_mu_set_active_sta(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta,
+ int traffic);
+void aicwf_mu_set_active_group(struct aicwf_hw *aicwf_hw, int group_id);
+void aicwf_mu_group_sta_select(struct aicwf_hw *aicwf_hw);
+
+#else /* ! CONFIG_AICWF_MUMIMO_TX */
+
+static inline void
+aicwf_mu_group_sta_init(struct aicwf_sta *sta,
+ const struct ieee80211_vht_cap *vht_cap)
+{
+}
+
+static inline void aicwf_mu_group_sta_del(struct aicwf_hw *aicwf_hw,
+ struct aicwf_sta *sta)
+{
+}
+
+static inline u64 aicwf_mu_group_sta_get_map(struct aicwf_sta *sta)
+{
+ return 0;
+}
+
+static inline int aicwf_mu_group_sta_get_pos(struct aicwf_hw *aicwf_hw,
+ struct aicwf_sta *sta, int group_id)
+{
+ return 0;
+}
+
+static inline void aicwf_mu_group_init(struct aicwf_hw *aicwf_hw)
+{
+}
+
+static inline void aicwf_mu_set_active_sta(struct aicwf_hw *aicwf_hw,
+ struct aicwf_sta *sta, int traffic)
+{
+}
+
+static inline void aicwf_mu_set_active_group(struct aicwf_hw *aicwf_hw,
+ int group_id)
+{
+}
+
+static inline void aicwf_mu_group_sta_select(struct aicwf_hw *aicwf_hw)
+{
+}
+
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+
+#endif /* _AICWF_MU_GROUP_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_platform.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_platform.c
new file mode 100644
index 000000000000..2845d6117a6f
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_platform.c
@@ -0,0 +1,1507 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file aicwf_platform.c
+ *
+ * @brief Platform profile
+ *
+ ******************************************************************************
+ */
+
+#include <linux/delay.h>
+#include <crypto/md5.h>
+#include <linux/firmware.h>
+#include <linux/kstrtox.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sprintf.h>
+#include <linux/string.h>
+#include <linux/vmalloc.h>
+
+#include "hal_desc.h"
+#include "aicwf_main.h"
+#include "aicwf_platform.h"
+#include "aicwf_msg_tx.h"
+
+#include "aicwf_sdio.h"
+
+#include "aicwf_compat_8800d80.h"
+#include "aicwf_chip_ops.h"
+
+// Parser state
+#define INIT 0
+#define CMD 1
+#define PRINT 2
+#define GET_VALUE 3
+
+static const struct userconfig_info_t userconfig_defaults = {
+ .txpwr_lvl = { .enable = 1,
+ .dsss = 9,
+ .ofdmlowrate_2g4 = 8,
+ .ofdm64qam_2g4 = 8,
+ .ofdm256qam_2g4 = 8,
+ .ofdm1024qam_2g4 = 8,
+ .ofdmlowrate_5g = 11,
+ .ofdm64qam_5g = 10,
+ .ofdm256qam_5g = 9,
+ .ofdm1024qam_5g = 9},
+ .txpwr_lvl_v2 = { .enable = 1,
+ .pwrlvl_11b_11ag_2g4 =
+ // 1M, 2M, 5M5, 11M, 6M, 9M, 12M, 18M, 24M, 36M,
+ // 48M, 54M
+ {20, 20, 20, 20, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_2g4 =
+ // MCS0, MCS1, MCS2, MCS3, MCS4, MCS5, MCS6, MCS7, MCS8, MCS9
+ {20, 20, 20, 20, 18, 18, 16, 16, 16, 16},
+ .pwrlvl_11ax_2g4 =
+ // MCS0, MCS1, MCS2, MCS3, MCS4, MCS5, MCS6, MCS7, MCS8, MCS9,
+ // MCS10,MCS11
+ {20, 20, 20, 20, 18, 18, 16, 16, 16, 16, 15, 15},
+ },
+ .txpwr_lvl_v3 = { .enable = 1,
+ .pwrlvl_11b_11ag_2g4 =
+ // 1M, 2M, 5M5, 11M, 6M, 9M, 12M, 18M, 24M, 36M,
+ // 48M, 54M
+ {20, 20, 20, 20, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_2g4 =
+ // MCS0, MCS1, MCS2, MCS3, MCS4, MCS5, MCS6, MCS7, MCS8, MCS9
+ {20, 20, 20, 20, 18, 18, 16, 16, 16, 16},
+ .pwrlvl_11ax_2g4 =
+ // MCS0, MCS1, MCS2, MCS3, MCS4, MCS5, MCS6, MCS7, MCS8, MCS9,
+ // MCS10,MCS11
+ {20, 20, 20, 20, 18, 18, 16, 16, 16, 16, 15, 15},
+ .pwrlvl_11a_5g =
+ // NA, NA, NA, NA, 6M, 9M, 12M, 18M, 24M, 36M,
+ // 48M, 54M
+ {0x80, 0x80, 0x80, 0x80, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_5g =
+ // MCS0, MCS1, MCS2, MCS3, MCS4, MCS5, MCS6, MCS7, MCS8, MCS9
+ {20, 20, 20, 20, 18, 18, 16, 16, 16, 15},
+ .pwrlvl_11ax_5g =
+ // MCS0, MCS1, MCS2, MCS3, MCS4, MCS5, MCS6, MCS7, MCS8, MCS9,
+ // MCS10,MCS11
+ {20, 20, 20, 20, 18, 18, 16, 16, 16, 15, 14, 14},
+ },
+ .txpwr_lvl_v3_gp[0] = { .enable = 1,
+ .pwrlvl_11b_11ag_2g4 =
+ // 1M, 2M, 5M5, 11M, 6M, 9M, 12M, 18M, 24M, 36M,
+ // 48M, 54M
+ {20, 20, 20, 20, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_2g4 =
+ // MCS0, MCS1, MCS2, MCS3, MCS4, MCS5, MCS6, MCS7, MCS8, MCS9
+ {20, 20, 20, 20, 18, 18, 16, 16, 16, 16},
+ .pwrlvl_11ax_2g4 =
+ // MCS0, MCS1, MCS2, MCS3, MCS4, MCS5, MCS6, MCS7, MCS8, MCS9,
+ // MCS10,MCS11
+ {20, 20, 20, 20, 18, 18, 16, 16, 16, 16, 15, 15},
+ .pwrlvl_11a_5g =
+ // NA, NA, NA, NA, 6M, 9M, 12M, 18M, 24M, 36M,
+ // 48M, 54M
+ {0x80, 0x80, 0x80, 0x80, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_5g =
+ // MCS0, MCS1, MCS2, MCS3, MCS4, MCS5, MCS6, MCS7, MCS8, MCS9
+ {20, 20, 20, 20, 18, 18, 16, 16, 16, 15},
+ .pwrlvl_11ax_5g =
+ // MCS0, MCS1, MCS2, MCS3, MCS4, MCS5, MCS6, MCS7, MCS8, MCS9,
+ // MCS10,MCS11
+ {20, 20, 20, 20, 18, 18, 16, 16, 16, 15, 14, 14},
+ },
+ .txpwr_lvl_v3_gp[1] = { .enable = 1,
+ .pwrlvl_11b_11ag_2g4 = {20, 20, 20, 20, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_2g4 = {20, 20, 20, 20, 18, 18, 16, 16, 16, 16},
+ .pwrlvl_11ax_2g4 = {20, 20, 20, 20, 18, 18, 16, 16, 16, 16, 15, 15},
+ .pwrlvl_11a_5g = {0x80, 0x80, 0x80, 0x80, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_5g = {20, 20, 20, 20, 18, 18, 16, 16, 16, 15},
+ .pwrlvl_11ax_5g = {20, 20, 20, 20, 18, 18, 16, 16, 16, 15, 14, 14},
+ },
+ .txpwr_lvl_v3_gp[2] = { .enable = 1,
+ .pwrlvl_11b_11ag_2g4 = {20, 20, 20, 20, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_2g4 = {20, 20, 20, 20, 18, 18, 16, 16, 16, 16},
+ .pwrlvl_11ax_2g4 = {20, 20, 20, 20, 18, 18, 16, 16, 16, 16, 15, 15},
+ .pwrlvl_11a_5g = {0x80, 0x80, 0x80, 0x80, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_5g = {20, 20, 20, 20, 18, 18, 16, 16, 16, 15},
+ .pwrlvl_11ax_5g = {20, 20, 20, 20, 18, 18, 16, 16, 16, 15, 14, 14},
+ },
+ .txpwr_lvl_v3_gp[3] = { .enable = 1,
+ .pwrlvl_11b_11ag_2g4 = {20, 20, 20, 20, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_2g4 = {20, 20, 20, 20, 18, 18, 16, 16, 16, 16},
+ .pwrlvl_11ax_2g4 = {20, 20, 20, 20, 18, 18, 16, 16, 16, 16, 15, 15},
+ .pwrlvl_11a_5g = {0x80, 0x80, 0x80, 0x80, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_5g = {20, 20, 20, 20, 18, 18, 16, 16, 16, 15},
+ .pwrlvl_11ax_5g = {20, 20, 20, 20, 18, 18, 16, 16, 16, 15, 14, 14},
+ },
+ .txpwr_lvl_v3_gp[4] = { .enable = 1,
+ .pwrlvl_11b_11ag_2g4 = {20, 20, 20, 20, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_2g4 = {20, 20, 20, 20, 18, 18, 16, 16, 16, 16},
+ .pwrlvl_11ax_2g4 = {20, 20, 20, 20, 18, 18, 16, 16, 16, 16, 15, 15},
+ .pwrlvl_11a_5g = {0x80, 0x80, 0x80, 0x80, 20, 20, 20, 20, 18, 18, 16, 16},
+ .pwrlvl_11n_11ac_5g = {20, 20, 20, 20, 18, 18, 16, 16, 16, 15},
+ .pwrlvl_11ax_5g = {20, 20, 20, 20, 18, 18, 16, 16, 16, 15, 14, 14},
+ },
+ .txpwr_loss = { .loss_enable_2g4 = 1,
+ .loss_value_2g4 = 0,
+ .loss_enable_5g = 1,
+ .loss_value_5g = 0,
+ },
+ .txpwr_ofst = { .enable = 1,
+ .chan_1_4 = 0,
+ .chan_5_9 = 0,
+ .chan_10_13 = 0,
+ .chan_36_64 = 0,
+ .chan_100_120 = 0,
+ .chan_122_140 = 0,
+ .chan_142_165 = 0,
+ },
+ .txpwr_ofst2x = { .enable = 0,
+ .pwrofst2x_tbl_2g4 = {
+ // ch1-4, ch5-9, ch10-13
+ {0, 0, 0}, // 11b
+ {0, 0, 0}, // ofdm_highrate
+ {0, 0, 0}, // ofdm_lowrate
+ },
+ .pwrofst2x_tbl_5g = {
+ // ch42, ch58, ch106,ch122,ch138,ch155
+ {0, 0, 0, 0, 0, 0}, // ofdm_lowrate
+ {0, 0, 0, 0, 0, 0}, // ofdm_highrate
+ {0, 0, 0, 0, 0, 0}, // ofdm_midrate
+ },
+ },
+ .xtal_cap = { .enable = 0,
+ .xtal_cap = 24,
+ .xtal_cap_fine = 31,
+ },
+};
+
+int aicwf_request_firmware(const struct firmware **fw, const char *name,
+ struct device *dev)
+{
+ char *fw_name;
+ int ret;
+
+ if (!name || !name[0])
+ return -EINVAL;
+
+ fw_name = kasprintf(GFP_KERNEL, AIC8800_FW_DIR "%s", name);
+ if (!fw_name)
+ return -ENOMEM;
+
+ ret = request_firmware(fw, fw_name, dev);
+ kfree(fw_name);
+
+ return ret;
+}
+
+#define MD5PINRT \
+ "file " \
+ "md5:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n"
+
+static int aicwf_load_firmware(u32 **fw_buf, const char *name,
+ struct device *device)
+{
+ const struct firmware *fw = NULL;
+ u32 *dst = NULL;
+ void *buffer = NULL;
+ u8 digest[MD5_DIGEST_SIZE];
+ int size = 0;
+ int ret = 0;
+
+ dev_dbg(device, "request firmware = %s\n", name);
+
+ ret = aicwf_request_firmware(&fw, name, device);
+
+ if (ret < 0) {
+ dev_dbg(device, "load %s fail\n", name);
+ return ret;
+ }
+
+ size = fw->size;
+ dst = (u32 *)fw->data;
+
+ if (size <= 0) {
+ dev_dbg(device, "wrong size of firmware file\n");
+ release_firmware(fw);
+ return -1;
+ }
+
+ buffer = vmalloc(size);
+ if (!buffer) {
+ release_firmware(fw);
+ return -ENOMEM;
+ }
+ memset(buffer, 0, size);
+ memcpy(buffer, dst, size);
+
+ *fw_buf = buffer;
+
+ md5(buffer, size, digest);
+ dev_dbg(device, MD5PINRT, digest[0], digest[1], digest[2], digest[3],
+ digest[4], digest[5], digest[6], digest[7], digest[8], digest[9],
+ digest[10], digest[11], digest[12], digest[13], digest[14], digest[15]);
+
+ release_firmware(fw);
+
+ return size;
+}
+
+/* buffer is allocated by kzalloc */
+int aicwf_request_firmware_common(struct aicwf_hw *aicwf_hw, u32 **buffer,
+ const char *filename)
+{
+ int size;
+
+ dev_dbg(aicwf_hw->dev, "load file %s\n", filename);
+
+ size = aicwf_load_firmware(buffer, filename, aicwf_hw->dev);
+
+ return size;
+}
+
+static void aicwf_restore_firmware(u32 **fw_buf)
+{
+ vfree(*fw_buf);
+ *fw_buf = NULL;
+}
+
+void aicwf_release_firmware_common(u32 **buffer)
+{
+ aicwf_restore_firmware(buffer);
+}
+
+/**
+ * aicwf_plat_bin_fw_upload_chunk - Load the requested binary FW into embedded
+ * side.
+ *
+ * @aicwf_hw: Main driver data
+ * @fw_addr: Address where the fw must be loaded
+ * @filename: Name of the fw.
+ * @chunk: Number of bytes written per DBG_MEM_BLOCK_WRITE_REQ (at most 1024)
+ *
+ * Load a fw, stored as a binary file, into the specified address.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int aicwf_plat_bin_fw_upload_chunk(struct aicwf_hw *aicwf_hw, u32 fw_addr,
+ const char *filename, int chunk)
+{
+ u32 *dst = NULL;
+ int i;
+ int size;
+ int err = 0;
+
+ dev_dbg(aicwf_hw->dev, "upload %s firmware, @ = %x\n", filename, fw_addr);
+
+ size = aicwf_request_firmware_common(aicwf_hw, &dst, filename);
+ if (size <= 0) {
+ dev_err(aicwf_hw->dev, "failed to load %s: %d\n", filename, size);
+ vfree(dst);
+ return size < 0 ? size : -EINVAL;
+ }
+
+ for (i = 0; i < size; i += chunk) {
+ err = aicwf_send_dbg_mem_block_write_req(aicwf_hw, fw_addr + i,
+ min(size - i, chunk),
+ dst + i / 4);
+ if (err) {
+ dev_err(aicwf_hw->dev, "bin upload fail: %x, err:%d\n",
+ fw_addr + i, err);
+ break;
+ }
+ }
+
+ aicwf_release_firmware_common(&dst);
+
+ return err;
+}
+
+/**
+ * aicwf_plat_bin_fw_upload - Load the requested binary FW into embedded
+ * side, 1KB at a time.
+ *
+ * @aicwf_hw: Main driver data
+ * @fw_addr: Address where the fw must be loaded
+ * @filename: Name of the fw.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int aicwf_plat_bin_fw_upload(struct aicwf_hw *aicwf_hw, u32 fw_addr,
+ const char *filename)
+{
+ return aicwf_plat_bin_fw_upload_chunk(aicwf_hw, fw_addr, filename, 1024);
+}
+
+static const struct nvram_info_t nvram_defaults = {
+ .txpwr_idx = {.enable = 1,
+ .dsss = 9,
+ .ofdmlowrate_2g4 = 8,
+ .ofdm64qam_2g4 = 8,
+ .ofdm256qam_2g4 = 8,
+ .ofdm1024qam_2g4 = 8,
+ .ofdmlowrate_5g = 11,
+ .ofdm64qam_5g = 10,
+ .ofdm256qam_5g = 9,
+ .ofdm1024qam_5g = 9},
+ .txpwr_ofst = { .enable = 1,
+ .chan_1_4 = 0,
+ .chan_5_9 = 0,
+ .chan_10_13 = 0,
+ .chan_36_64 = 0,
+ .chan_100_120 = 0,
+ .chan_122_140 = 0,
+ .chan_142_165 = 0,
+ },
+ .xtal_cap = { .enable = 0,
+ .xtal_cap = 24,
+ .xtal_cap_fine = 31,
+ },
+};
+
+/**
+ * aicwf_plat_userconfig_init - Start from the built-in configuration
+ * @aicwf_hw: Main driver data
+ *
+ * The userconfig and nvram files parsed later only override these values.
+ */
+void aicwf_plat_userconfig_init(struct aicwf_hw *aicwf_hw)
+{
+ aicwf_hw->userconfig = userconfig_defaults;
+ aicwf_hw->nvram = nvram_defaults;
+}
+
+void get_userconfig_txpwr_ofst2x_in_fdrv(struct aicwf_hw *aicwf_hw,
+ struct txpwr_ofst2x_conf *txpwr_ofst2x)
+{
+ struct userconfig_info_t *uc = &aicwf_hw->userconfig;
+ int type, ch_grp;
+ *txpwr_ofst2x = uc->txpwr_ofst2x;
+ pr_debug("enable :%d\n", txpwr_ofst2x->enable);
+ pr_debug("pwrofst2x 2.4g: [0]:11b, [1]:ofdm_highrate, [2]:ofdm_lowrate\n chan=\t1-4\t5-9\t10-13");
+
+ for (type = 0; type < 3; type++) {
+ pr_debug("\n [%d] =", type);
+ for (ch_grp = 0; ch_grp < 3; ch_grp++) {
+ pr_debug("\t%d",
+ txpwr_ofst2x->pwrofst2x_tbl_2g4[type][ch_grp]);
+ }
+ }
+ pr_debug("\npwrofst2x 5g: [0]:ofdm_lowrate, [1]:ofdm_highrate, [2]:ofdm_midrate\n chan=\t36-50\t51-64\t98-114\t115-130\t131-146\t147-166");
+ for (type = 0; type < 3; type++) {
+ pr_debug("\n [%d] =", type);
+ for (ch_grp = 0; ch_grp < 6; ch_grp++) {
+ pr_debug("\t%d",
+ txpwr_ofst2x->pwrofst2x_tbl_5g[type][ch_grp]);
+ }
+ }
+ pr_debug("\n");
+}
+
+void get_userconfig_xtal_cap(struct aicwf_hw *aicwf_hw,
+ struct xtal_cap_conf *xtal_cap)
+{
+ struct userconfig_info_t *uc = &aicwf_hw->userconfig;
+
+ if (aicwf_hw->nvram.xtal_cap.enable)
+ *xtal_cap = aicwf_hw->nvram.xtal_cap;
+
+ if (uc->xtal_cap.enable)
+ *xtal_cap = uc->xtal_cap;
+
+ pr_debug("enable :%d\n", xtal_cap->enable);
+ pr_debug("xtal_cap :%d\n", xtal_cap->xtal_cap);
+ pr_debug("xtal_cap_fine:%d\n",
+ xtal_cap->xtal_cap_fine);
+}
+
+int aicwf_atoi(char *value)
+{
+ int result;
+
+ if (kstrtoint(value, 10, &result))
+ return 0;
+
+ return result;
+}
+
+static int aicwf_parse_mul_value(char *line, char *val[])
+{
+ int nargs = 0;
+
+ while (nargs < 10) {
+ while ((*line == ' ') || (*line == '\t'))
+ ++line;
+
+ if (*line == '\0') { /* end of line, no more args */
+ return nargs;
+ }
+
+ val[nargs++] = line; /* begin of argument string */
+
+ /* find end of string */
+ while (*line && (*line != ' ') && (*line != '\t'))
+ ++line;
+
+ if (*line == '\0') { /* end of line, no more args */
+ return nargs;
+ }
+
+ *line++ = '\0'; /* terminate current arg */
+ }
+
+ pr_debug("nargs: %d\n", nargs);
+ return nargs;
+}
+
+static void aicwf_plat_nvram_set_value_group(struct aicwf_hw *aicwf_hw,
+ char *command, char *value)
+{
+ struct userconfig_info_t *uc = &aicwf_hw->userconfig;
+ char *mul_val[10];
+ int i;
+
+ // TODO send command
+ pr_debug("command=%s value=%s\n", command, value);
+ if (!strcmp(command, "enable")) {
+ uc->txpwr_lvl.enable = aicwf_atoi(value);
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].enable = aicwf_atoi(value);
+ } else if (!strcmp(command, "dsss")) {
+ uc->txpwr_lvl.dsss = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdmlowrate_2g4")) {
+ uc->txpwr_lvl.ofdmlowrate_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm64qam_2g4")) {
+ uc->txpwr_lvl.ofdm64qam_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm256qam_2g4")) {
+ uc->txpwr_lvl.ofdm256qam_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm1024qam_2g4")) {
+ uc->txpwr_lvl.ofdm1024qam_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdmlowrate_5g")) {
+ uc->txpwr_lvl.ofdmlowrate_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm64qam_5g")) {
+ uc->txpwr_lvl.ofdm64qam_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm256qam_5g")) {
+ uc->txpwr_lvl.ofdm256qam_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm1024qam_5g")) {
+ uc->txpwr_lvl.ofdm1024qam_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_1m_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[0] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11b_11ag_2m_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[1] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11b_11ag_5m5_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[2] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11b_11ag_11m_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[3] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11b_11ag_6m_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[4] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11b_11ag_9m_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[5] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11b_11ag_12m_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[6] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11b_11ag_18m_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[7] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11b_11ag_24m_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[8] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11b_11ag_36m_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[9] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11b_11ag_48m_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[10] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11b_11ag_54m_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11b_11ag_2g4[11] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs0_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_2g4[0] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs1_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_2g4[1] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs2_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_2g4[2] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs3_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_2g4[3] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs4_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_2g4[4] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs5_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_2g4[5] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs6_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_2g4[6] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs7_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_2g4[7] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs8_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_2g4[8] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs9_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_2g4[9] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs0_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[0] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs1_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[1] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs2_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[2] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs3_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[3] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs4_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[4] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs5_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[5] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs6_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[6] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs7_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[7] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs8_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[8] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs9_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[9] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs10_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[10] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs11_2g4")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_2g4[11] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_1m_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[0] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_2m_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[1] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_5m5_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[2] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_11m_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[3] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_6m_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[4] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_9m_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[5] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_12m_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[6] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_18m_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[7] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_24m_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[8] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_36m_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[9] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_48m_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[10] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11a_54m_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11a_5g[11] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs0_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_5g[0] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs1_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_5g[1] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs2_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_5g[2] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs3_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_5g[3] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs4_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_5g[4] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs5_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_5g[5] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs6_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_5g[6] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs7_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_5g[7] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs8_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_5g[8] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs9_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11n_11ac_5g[9] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs0_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[0] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs1_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[1] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs2_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[2] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs3_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[3] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs4_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[4] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs5_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[5] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs6_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[6] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs7_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[7] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs8_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[8] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs9_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[9] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs10_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[10] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_11ax_mcs11_5g")) {
+ if (aicwf_parse_mul_value(value, mul_val) < REGION_NUM_MAX)
+ return;
+ for (i = 0; i < REGION_NUM_MAX; i++)
+ uc->txpwr_lvl_v3_gp[i].pwrlvl_11ax_5g[11] =
+ aicwf_atoi(mul_val[i]);
+ } else if (!strcmp(command, "lvl_adj_enable")) {
+ uc->txpwr_lvl_adj.enable = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_2g4_chan_1_4")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_2g4[0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_2g4_chan_5_9")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_2g4[1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_2g4_chan_10_13")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_2g4[2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_42")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_58")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_106")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_122")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_138")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_155")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "loss_enable_2g4")) {
+ uc->txpwr_loss.loss_enable_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "loss_value_2g4")) {
+ uc->txpwr_loss.loss_value_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "loss_enable_5g")) {
+ uc->txpwr_loss.loss_enable_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "loss_value_5g")) {
+ uc->txpwr_loss.loss_value_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_enable")) {
+ uc->txpwr_ofst.enable = aicwf_atoi(value);
+ uc->txpwr_ofst2x.enable = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_1_4")) {
+ uc->txpwr_ofst.chan_1_4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_5_9")) {
+ uc->txpwr_ofst.chan_5_9 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_10_13")) {
+ uc->txpwr_ofst.chan_10_13 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_36_64")) {
+ uc->txpwr_ofst.chan_36_64 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_100_120")) {
+ uc->txpwr_ofst.chan_100_120 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_122_140")) {
+ uc->txpwr_ofst.chan_122_140 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_142_165")) {
+ uc->txpwr_ofst.chan_142_165 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_11b_chan_1_4")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[0][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_11b_chan_5_9")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[0][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_11b_chan_10_13")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[0][2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_highrate_chan_1_4")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[1][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_highrate_chan_5_9")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[1][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_highrate_chan_10_13")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[1][2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_lowrate_chan_1_4")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[2][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_lowrate_chan_5_9")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[2][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_lowrate_chan_10_13")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[2][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_42")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_58")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_106")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_122")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_138")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_155")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_42")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_58")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_106")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_122")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_138")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_155")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_42")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_58")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_106")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_122")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_138")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_155")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "xtal_enable")) {
+ uc->xtal_cap.enable = aicwf_atoi(value);
+ } else if (!strcmp(command, "xtal_cap")) {
+ uc->xtal_cap.xtal_cap = aicwf_atoi(value);
+ } else if (!strcmp(command, "xtal_cap_fine")) {
+ uc->xtal_cap.xtal_cap_fine = aicwf_atoi(value);
+ } else {
+ pr_err("invalid cmd: %s\n", command);
+ }
+}
+
+static void aicwf_plat_nvram_set_value_v3(struct aicwf_hw *aicwf_hw,
+ char *command, char *value)
+{
+ struct userconfig_info_t *uc = &aicwf_hw->userconfig;
+
+ // TODO send command
+ pr_debug("command=%s value=%s\n", command, value);
+ if (!strcmp(command, "enable")) {
+ uc->txpwr_lvl.enable = aicwf_atoi(value);
+ uc->txpwr_lvl_v3.enable = aicwf_atoi(value);
+ } else if (!strcmp(command, "dsss")) {
+ uc->txpwr_lvl.dsss = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdmlowrate_2g4")) {
+ uc->txpwr_lvl.ofdmlowrate_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm64qam_2g4")) {
+ uc->txpwr_lvl.ofdm64qam_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm256qam_2g4")) {
+ uc->txpwr_lvl.ofdm256qam_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm1024qam_2g4")) {
+ uc->txpwr_lvl.ofdm1024qam_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdmlowrate_5g")) {
+ uc->txpwr_lvl.ofdmlowrate_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm64qam_5g")) {
+ uc->txpwr_lvl.ofdm64qam_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm256qam_5g")) {
+ uc->txpwr_lvl.ofdm256qam_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofdm1024qam_5g")) {
+ uc->txpwr_lvl.ofdm1024qam_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_1m_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_2m_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_5m5_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_11m_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_6m_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_9m_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_12m_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[6] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_18m_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[7] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_24m_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[8] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_36m_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[9] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_48m_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[10] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11b_11ag_54m_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11b_11ag_2g4[11] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs0_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_2g4[0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs1_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_2g4[1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs2_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_2g4[2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs3_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_2g4[3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs4_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_2g4[4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs5_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_2g4[5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs6_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_2g4[6] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs7_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_2g4[7] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs8_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_2g4[8] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs9_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_2g4[9] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs0_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs1_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs2_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs3_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs4_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs5_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs6_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[6] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs7_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[7] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs8_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[8] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs9_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[9] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs10_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[10] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs11_2g4")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_2g4[11] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_1m_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_2m_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_5m5_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_11m_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_6m_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_9m_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_12m_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[6] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_18m_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[7] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_24m_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[8] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_36m_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[9] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_48m_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[10] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11a_54m_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11a_5g[11] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs0_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_5g[0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs1_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_5g[1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs2_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_5g[2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs3_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_5g[3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs4_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_5g[4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs5_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_5g[5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs6_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_5g[6] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs7_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_5g[7] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs8_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_5g[8] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11n_11ac_mcs9_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11n_11ac_5g[9] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs0_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs1_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs2_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs3_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs4_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs5_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs6_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[6] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs7_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[7] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs8_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[8] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs9_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[9] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs10_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[10] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_11ax_mcs11_5g")) {
+ uc->txpwr_lvl_v3.pwrlvl_11ax_5g[11] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_enable")) {
+ uc->txpwr_lvl_adj.enable = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_2g4_chan_1_4")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_2g4[0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_2g4_chan_5_9")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_2g4[1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_2g4_chan_10_13")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_2g4[2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_42")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_58")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_106")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_122")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_138")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "lvl_adj_5g_chan_155")) {
+ uc->txpwr_lvl_adj.pwrlvl_adj_tbl_5g[5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "loss_enable_2g4")) {
+ uc->txpwr_loss.loss_enable_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "loss_value_2g4")) {
+ uc->txpwr_loss.loss_value_2g4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "loss_enable_5g")) {
+ uc->txpwr_loss.loss_enable_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "loss_value_5g")) {
+ uc->txpwr_loss.loss_value_5g = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_enable")) {
+ uc->txpwr_ofst.enable = aicwf_atoi(value);
+ uc->txpwr_ofst2x.enable = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_1_4")) {
+ uc->txpwr_ofst.chan_1_4 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_5_9")) {
+ uc->txpwr_ofst.chan_5_9 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_10_13")) {
+ uc->txpwr_ofst.chan_10_13 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_36_64")) {
+ uc->txpwr_ofst.chan_36_64 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_100_120")) {
+ uc->txpwr_ofst.chan_100_120 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_122_140")) {
+ uc->txpwr_ofst.chan_122_140 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_chan_142_165")) {
+ uc->txpwr_ofst.chan_142_165 = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_11b_chan_1_4")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[0][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_11b_chan_5_9")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[0][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_11b_chan_10_13")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[0][2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_highrate_chan_1_4")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[1][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_highrate_chan_5_9")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[1][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_highrate_chan_10_13")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[1][2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_lowrate_chan_1_4")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[2][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_lowrate_chan_5_9")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[2][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_2g4_ofdm_lowrate_chan_10_13")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_2g4[2][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_42")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_58")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_106")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_122")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_138")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_lowrate_chan_155")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[0][5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_42")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_58")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_106")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_122")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_138")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_highrate_chan_155")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[1][5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_42")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][0] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_58")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][1] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_106")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][2] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_122")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][3] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_138")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][4] = aicwf_atoi(value);
+ } else if (!strcmp(command, "ofst_5g_ofdm_midrate_chan_155")) {
+ uc->txpwr_ofst2x.pwrofst2x_tbl_5g[2][5] = aicwf_atoi(value);
+ } else if (!strcmp(command, "xtal_enable")) {
+ uc->xtal_cap.enable = aicwf_atoi(value);
+ } else if (!strcmp(command, "xtal_cap")) {
+ uc->xtal_cap.xtal_cap = aicwf_atoi(value);
+ } else if (!strcmp(command, "xtal_cap_fine")) {
+ uc->xtal_cap.xtal_cap_fine = aicwf_atoi(value);
+ } else {
+ pr_err("invalid cmd: %s\n", command);
+ }
+}
+
+void aicwf_plat_userconfig_parsing3(struct aicwf_hw *aicwf_hw, char *buffer,
+ int size)
+{
+ int i = 0;
+ int parse_state = 0;
+ char command[64];
+ char value[100];
+ int char_counter = 0;
+ u8 area_pw = 0;
+ bool skip_line = false;
+
+ memset(command, 0, 64);
+ memset(value, 0, 100);
+
+ for (i = 0; i < size; i++) {
+ // Send command or print nvram log when char is \r or \n
+ if (buffer[i] == 0x0a || buffer[i] == 0x0d) {
+ if (!skip_line && command[0] != 0 && value[0] != 0) {
+ if (parse_state == PRINT) {
+ if (area_pw == 0 &&
+ strnstr(value, "SRRC", strlen(value))) {
+ area_pw = 1;
+ pr_debug("use diff_area_power userconfig\n");
+ }
+ pr_debug("%s\n", value);
+ } else if (parse_state == GET_VALUE) {
+ if (area_pw)
+ aicwf_plat_nvram_set_value_group(aicwf_hw, command,
+ value);
+ else
+ aicwf_plat_nvram_set_value_v3(aicwf_hw, command,
+ value);
+ }
+ }
+ // Reset command value and char_counter
+ memset(command, 0, 64);
+ memset(value, 0, 100);
+ char_counter = 0;
+ parse_state = INIT;
+ skip_line = false;
+ continue;
+ }
+
+ if (skip_line)
+ continue;
+
+ // Switch parser state
+ if (parse_state == INIT) {
+ if (buffer[i] == '#') {
+ parse_state = PRINT;
+ continue;
+ } else if (buffer[i] == 0x0a || buffer[i] == 0x0d) {
+ parse_state = INIT;
+ continue;
+ } else {
+ parse_state = CMD;
+ }
+ }
+
+ // Fill data to command and value
+ if (parse_state == PRINT) {
+ command[0] = 0x01;
+ if (char_counter >= sizeof(value) - 1) {
+ skip_line = true;
+ continue;
+ }
+ value[char_counter] = buffer[i];
+ char_counter++;
+ } else if (parse_state == CMD) {
+ if (command[0] != 0 && buffer[i] == '=') {
+ parse_state = GET_VALUE;
+ char_counter = 0;
+ continue;
+ }
+ if (char_counter >= sizeof(command) - 1) {
+ skip_line = true;
+ continue;
+ }
+ command[char_counter] = buffer[i];
+ char_counter++;
+ } else if (parse_state == GET_VALUE) {
+ if (buffer[i] != 0x2D &&
+ (buffer[i] < 0x30 || buffer[i] > 0x39) &&
+ buffer[i] != 0x20)
+ continue;
+ if (char_counter >= sizeof(value) - 1) {
+ skip_line = true;
+ continue;
+ }
+ value[char_counter] = buffer[i];
+ char_counter++;
+ }
+ }
+}
+
+void get_userconfig_txpwr_lvl_group_in_fdrv(struct aicwf_hw *aicwf_hw,
+ struct txpwr_lvl_conf_v3 *txpwr_lvl_v3,
+ int index_reg)
+{
+ struct userconfig_info_t *uc = &aicwf_hw->userconfig;
+
+ *txpwr_lvl_v3 = uc->txpwr_lvl_v3_gp[index_reg];
+
+ pr_debug("enable:%d\n", txpwr_lvl_v3->enable);
+ pr_debug("lvl_11b_11ag_1m_2g4:%d\n", txpwr_lvl_v3->pwrlvl_11b_11ag_2g4[0]);
+}
+
+void get_userconfig_txpwr_lvl_adj_in_fdrv(struct aicwf_hw *aicwf_hw,
+ struct txpwr_lvl_adj_conf *txpwr_lvl_adj)
+{
+ struct userconfig_info_t *uc = &aicwf_hw->userconfig;
+
+ *txpwr_lvl_adj = uc->txpwr_lvl_adj;
+
+ pr_debug("enable:%d\n", txpwr_lvl_adj->enable);
+ pr_debug("lvl_adj_2g4_chan_1_4:%d\n", txpwr_lvl_adj->pwrlvl_adj_tbl_2g4[0]);
+}
+
+/*
+ * aicwf_plat_userconfig_load ---Load aic_userconfig.txt
+ *@filename name of config
+ */
+static int aicwf_plat_userconfig_load(struct aicwf_hw *aicwf_hw)
+{
+ aic_chip_userconfig_load(aicwf_hw);
+ return 0;
+}
+
+void get_userconfig_txpwr_loss(struct aicwf_hw *aicwf_hw,
+ struct txpwr_loss_conf *txpwr_loss)
+{
+ struct userconfig_info_t *uc = &aicwf_hw->userconfig;
+
+ txpwr_loss->loss_enable_2g4 = uc->txpwr_loss.loss_enable_2g4;
+ txpwr_loss->loss_value_2g4 = uc->txpwr_loss.loss_value_2g4;
+ txpwr_loss->loss_enable_5g = uc->txpwr_loss.loss_enable_5g;
+ txpwr_loss->loss_value_5g = uc->txpwr_loss.loss_value_5g;
+
+ pr_debug("loss_enable_2g4: %d, val_2g4: %d, loss_enable_5g: %d, val_5g: %d\n",
+ txpwr_loss->loss_enable_2g4, txpwr_loss->loss_value_2g4,
+ txpwr_loss->loss_enable_5g, txpwr_loss->loss_value_5g);
+}
+
+/**
+ * aicwf_platform_on - Start the platform
+ *
+ * @aicwf_hw: Main driver data
+ * @config: Config to restore (NULL if nothing to restore)
+ *
+ * It starts the platform :
+ * - load fw and ucodes
+ * - initialize IPC
+ * - boot the fw
+ * - enable link communication/IRQ
+ *
+ * Called by 802.11 part
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int aicwf_platform_on(struct aicwf_hw *aicwf_hw, void *config)
+{
+ int ret;
+ struct aicwf_plat *aicwf_plat = aicwf_hw->plat;
+ (void)ret;
+
+ if (aicwf_plat->enabled)
+ return 0;
+
+ aicwf_plat_userconfig_load(aicwf_hw);
+ // aicwf_plat->enabled = true;
+ return 0;
+}
+
+/**
+ * aicwf_platform_off() - Stop the platform
+ *
+ * @aicwf_hw: Main driver data
+ * @config: Updated with pointer to config, to be able to restore it with
+ * aicwf_platform_on(). It's up to the caller to free the config. Set to NULL
+ * if configuration is not needed.
+ *
+ * Called by 802.11 part
+ */
+void aicwf_platform_off(struct aicwf_hw *aicwf_hw, void **config)
+{
+ tasklet_kill(&aicwf_hw->task);
+ aicwf_hw->plat->enabled = false;
+}
+
+/**
+ * aicwf_platform_init() - Initialize the platform
+ *
+ * @aicwf_plat: platform data (already updated by platform driver)
+ * @platform_data: Pointer to store the main driver data pointer (aka aicwf_hw)
+ * That will be set as driver data for the platform driver
+ * Return: 0 on success, < 0 otherwise
+ *
+ * Called by the platform driver after it has been probed
+ */
+int aicwf_platform_init(struct aicwf_plat *aicwf_plat, void **platform_data)
+{
+ int ret;
+
+ aicwf_plat->enabled = false;
+
+ ret = aicwf_cfg80211_init(aicwf_plat, platform_data);
+ if (ret)
+ return ret;
+
+ aicwf_plat->enabled = true;
+ return 0;
+}
+
+/**
+ * aicwf_platform_deinit() - Deinitialize the platform
+ *
+ * @aicwf_hw: main driver data
+ *
+ * Called by the platform driver after it is removed
+ */
+void aicwf_platform_deinit(struct aicwf_hw *aicwf_hw)
+{
+ aicwf_cfg80211_deinit(aicwf_hw);
+}
+
+struct device *aicwf_platform_get_dev(struct aicwf_plat *aicwf_plat)
+{
+ return aicwf_plat->sdiodev->dev;
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_platform.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_platform.h
new file mode 100644
index 000000000000..269058765e99
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_platform.h
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_PLATFORM_H_
+#define _AICWF_PLATFORM_H_
+
+#include "lmac_msg.h"
+
+#define AIC8800_FW_DIR "aic/"
+#if (defined(CONFIG_DPD) && !defined(CONFIG_FORCE_DPD_CALIB))
+#define FW_DPDRESULT_NAME_8800DC "aic_dpdresult_lite_8800dc.bin"
+#endif
+
+#define POWER_LEVEL_INVALID_VAL (127)
+
+struct aicwf_hw;
+struct device;
+struct firmware;
+
+/* Transmit power and crystal settings parsed from the userconfig file */
+struct userconfig_info_t {
+ struct txpwr_lvl_conf txpwr_lvl;
+ struct txpwr_lvl_conf_v2 txpwr_lvl_v2;
+ struct txpwr_lvl_conf_v3 txpwr_lvl_v3;
+ struct txpwr_lvl_conf_v3 txpwr_lvl_v3_gp[REGION_NUM_MAX];
+ struct txpwr_lvl_adj_conf txpwr_lvl_adj;
+ struct txpwr_loss_conf txpwr_loss;
+ struct txpwr_ofst_conf txpwr_ofst;
+ struct txpwr_ofst2x_conf txpwr_ofst2x;
+ struct xtal_cap_conf xtal_cap;
+};
+
+/* Settings parsed from the nvram file */
+struct nvram_info_t {
+ struct txpwr_idx_conf txpwr_idx;
+ struct txpwr_ofst_conf txpwr_ofst;
+ struct xtal_cap_conf xtal_cap;
+};
+
+/**
+ * struct aicwf_plat - State of the platform the firmware runs on
+ *
+ * @sdiodev: SDIO device data
+ * @enabled: Set if embedded platform has been enabled (i.e. fw loaded and
+ * ipc started)
+ */
+struct aicwf_plat {
+ struct aic_sdio_dev *sdiodev;
+ bool enabled;
+};
+
+int aicwf_request_firmware(const struct firmware **fw, const char *name,
+ struct device *dev);
+
+int aicwf_platform_init(struct aicwf_plat *aicwf_plat, void **platform_data);
+void aicwf_platform_deinit(struct aicwf_hw *aicwf_hw);
+
+int aicwf_platform_on(struct aicwf_hw *aicwf_hw, void *config);
+void aicwf_platform_off(struct aicwf_hw *aicwf_hw, void **config);
+
+struct device *aicwf_platform_get_dev(struct aicwf_plat *aicwf_plat);
+
+void aicwf_release_firmware_common(u32 **buffer);
+int aicwf_request_firmware_common(struct aicwf_hw *aicwf_hw, u32 **buffer,
+ const char *filename);
+int aicwf_plat_bin_fw_upload_chunk(struct aicwf_hw *aicwf_hw, u32 fw_addr,
+ const char *filename, int chunk);
+int aicwf_plat_bin_fw_upload(struct aicwf_hw *aicwf_hw, u32 fw_addr,
+ const char *filename);
+
+int aicwf_atoi(char *value);
+void aicwf_plat_userconfig_init(struct aicwf_hw *aicwf_hw);
+void aicwf_plat_userconfig_parsing3(struct aicwf_hw *aicwf_hw, char *buffer,
+ int size);
+
+void get_userconfig_xtal_cap(struct aicwf_hw *aicwf_hw,
+ struct xtal_cap_conf *xtal_cap);
+
+void get_userconfig_txpwr_lvl_group_in_fdrv(struct aicwf_hw *aicwf_hw,
+ struct txpwr_lvl_conf_v3 *txpwr_lvl_v3,
+ int index_reg);
+void get_userconfig_txpwr_lvl_adj_in_fdrv(struct aicwf_hw *aicwf_hw,
+ struct txpwr_lvl_adj_conf *txpwr_lvl_adj);
+void get_userconfig_txpwr_ofst2x_in_fdrv(struct aicwf_hw *aicwf_hw,
+ struct txpwr_ofst2x_conf *txpwr_ofst2x);
+void get_userconfig_txpwr_loss(struct aicwf_hw *aicwf_hw,
+ struct txpwr_loss_conf *txpwr_loss);
+
+#endif /* _AICWF_PLATFORM_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_radar.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_radar.h
new file mode 100644
index 000000000000..ff42630e3f36
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_radar.h
@@ -0,0 +1,289 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_RADAR_H_
+#define _AICWF_RADAR_H_
+
+#include <linux/nl80211.h>
+
+struct aicwf_vif;
+struct aicwf_hw;
+
+enum aicwf_radar_chain { AICWF_RADAR_RIU = 0, AICWF_RADAR_FCU, AICWF_RADAR_LAST };
+
+enum aicwf_radar_detector {
+ /* Ignore radar pulses */
+ AICWF_RADAR_DETECT_DISABLE = 0,
+ /*
+ * Process pattern detection but do not
+ * report radar to upper layer (for test)
+ */
+ AICWF_RADAR_DETECT_ENABLE = 1,
+ /*
+ * Process pattern detection and report
+ * radar to upper layer.
+ */
+ AICWF_RADAR_DETECT_REPORT = 2
+};
+
+#ifdef CONFIG_AICWF_RADAR
+#include <linux/spinlock.h>
+#include <linux/workqueue.h>
+
+#define AICWF_RADAR_PULSE_MAX 32
+
+/**
+ * struct aicwf_radar_pulses - List of pulses reported by HW
+ * @index: write index
+ * @count: number of valid pulses
+ * @buffer: buffer of pulses
+ */
+struct aicwf_radar_pulses {
+ /* Last radar pulses received */
+ int index;
+ int count;
+ u32 buffer[AICWF_RADAR_PULSE_MAX];
+};
+
+/**
+ * struct dfs_pattern_detector - DFS pattern detector
+ * @enabled: whether radar detection is enabled
+ * @region: active DFS region, NL80211_DFS_UNSET until set
+ * @num_radar_types: number of different radar types
+ * @last_pulse_ts: time stamp of last valid pulse in usecs
+ * @prev_jiffies: jiffies value recorded for the previous pulse
+ * @radar_spec: array of radar detection specifications
+ * @detectors: per-channel detector pointers
+ */
+struct dfs_pattern_detector {
+ u8 enabled;
+ enum nl80211_dfs_regions region;
+ u8 num_radar_types;
+ u64 last_pulse_ts;
+ u32 prev_jiffies;
+ const struct radar_detector_specs *radar_spec;
+ struct list_head detectors[];
+};
+
+#define NX_NB_RADAR_DETECTED 4
+
+/**
+ * struct aicwf_radar_detected - List of radar detected
+ * @index: next entry to replace
+ * @count: number of valid entries
+ * @time: detection timestamps
+ * @freq: detection frequencies
+ */
+struct aicwf_radar_detected {
+ u16 index;
+ u16 count;
+ s64 time[NX_NB_RADAR_DETECTED];
+ s16 freq[NX_NB_RADAR_DETECTED];
+};
+
+struct aicwf_radar {
+ struct aicwf_radar_pulses pulses[AICWF_RADAR_LAST];
+ struct dfs_pattern_detector *dpd[AICWF_RADAR_LAST];
+ struct aicwf_radar_detected detected[AICWF_RADAR_LAST];
+ struct work_struct detection_work; /* Work used to process radar pulses */
+ spinlock_t lock; /* lock for pulses processing */
+
+ /* In softmac cac is handled by mac80211 */
+#ifdef CONFIG_AICWF_FULLMAC
+ struct delayed_work cac_work; /* Work used to handle CAC */
+ struct aicwf_vif *cac_vif; /* vif on which we started CAC */
+#endif
+};
+
+/*
+ * Type of radar waveform:
+ * RADAR_WAVEFORM_SHORT : waveform defined by
+ * - pulse width
+ * - pulse interval in a burst (pri)
+ * - number of pulses in a burst (ppb)
+ *
+ * RADAR_WAVEFORM_WEATHER :
+ * same than SHORT except that ppb is dependent of pri
+ *
+ * RADAR_WAVEFORM_INTERLEAVED :
+ * same than SHORT except there are several value of pri (interleaved)
+ *
+ * RADAR_WAVEFORM_LONG :
+ *
+ */
+enum radar_waveform_type {
+ RADAR_WAVEFORM_SHORT,
+ RADAR_WAVEFORM_WEATHER,
+ RADAR_WAVEFORM_INTERLEAVED,
+ RADAR_WAVEFORM_LONG
+};
+
+/**
+ * struct radar_detector_specs - detector specs for a radar pattern type
+ * @type_id: pattern type, as defined by regulatory
+ * @width_min: minimum radar pulse width in [us]
+ * @width_max: maximum radar pulse width in [us]
+ * @pri_min: minimum pulse repetition interval in [us] (including tolerance)
+ * @pri_max: minimum pri in [us] (including tolerance)
+ * @num_pri: maximum number of different pri for this type
+ * @ppb: pulses per bursts for this type
+ * @ppb_thresh: number of pulses required to trigger detection
+ * @max_pri_tolerance: pulse time stamp tolerance on both sides [us]
+ * @type: Type of radar waveform
+ */
+struct radar_detector_specs {
+ u8 type_id;
+ u8 width_min;
+ u8 width_max;
+ u16 pri_min;
+ u16 pri_max;
+ u8 num_pri;
+ u8 ppb;
+ u8 ppb_thresh;
+ u8 max_pri_tolerance;
+ enum radar_waveform_type type;
+};
+
+/**
+ * struct pri_sequence - sequence of pulses matching one PRI
+ * @head: list_head
+ * @pri: pulse repetition interval (PRI) in usecs
+ * @dur: duration of sequence in usecs
+ * @count: number of pulses in this sequence
+ * @count_falses: number of not matching pulses in this sequence
+ * @first_ts: time stamp of first pulse in usecs
+ * @last_ts: time stamp of last pulse in usecs
+ * @deadline_ts: deadline when this sequence becomes invalid (first_ts + dur)
+ * @ppb_thresh: Number of pulses to validate detection
+ * (need for weather radar whose value depends of pri)
+ */
+struct pri_sequence {
+ struct list_head head;
+ u32 pri;
+ u32 dur;
+ u32 count;
+ u32 count_falses;
+ u64 first_ts;
+ u64 last_ts;
+ u64 deadline_ts;
+ u8 ppb_thresh;
+};
+
+/**
+ * struct pulse_elem - elements in pulse queue
+ * @head: list node
+ * @ts: time stamp in usecs
+ */
+struct pulse_elem {
+ struct list_head head;
+ u64 ts;
+};
+
+/**
+ * struct pri_detector - PRI detector element for a dedicated radar type
+ * @head: list node
+ * @rs: detector specs for this detector element
+ * @last_ts: last pulse time stamp considered for this element in usecs
+ * @sequences: list_head holding potential pulse sequences
+ * @pulses: list connecting pulse_elem objects
+ * @count: number of pulses in queue
+ * @max_count: maximum number of pulses to be queued
+ * @window_size: window size back from newest pulse time stamp in usecs
+ * @ops: detector operations
+ * @freq: channel frequency in MHz
+ */
+struct pri_detector {
+ struct list_head head;
+ const struct radar_detector_specs *rs;
+ u64 last_ts;
+ struct list_head sequences;
+ struct list_head pulses;
+ u32 count;
+ u32 max_count;
+ u32 window_size;
+ struct pri_detector_ops *ops;
+ u16 freq;
+};
+
+struct pri_detector *pri_detector_init(struct dfs_pattern_detector *dpd,
+ u16 radar_type, u16 freq);
+
+bool aicwf_radar_detection_init(struct aicwf_radar *radar);
+void aicwf_radar_detection_deinit(struct aicwf_radar *radar);
+bool aicwf_radar_set_domain(struct aicwf_radar *radar,
+ enum nl80211_dfs_regions region);
+void aicwf_radar_detection_enable(struct aicwf_radar *radar, u8 enable, u8 chain);
+bool aicwf_radar_detection_is_enable(struct aicwf_radar *radar, u8 chain);
+void aicwf_radar_start_cac(struct aicwf_radar *radar, u32 cac_time_ms,
+ struct aicwf_vif *vif);
+void aicwf_radar_cancel_cac(struct aicwf_radar *radar);
+void aicwf_radar_detection_enable_on_cur_channel(struct aicwf_hw *aicwf_hw);
+int aicwf_radar_dump_pattern_detector(char *buf, size_t len,
+ struct aicwf_radar *radar, u8 chain);
+int aicwf_radar_dump_radar_detected(char *buf, size_t len,
+ struct aicwf_radar *radar, u8 chain);
+
+#else
+
+struct aicwf_radar {
+};
+
+static inline bool aicwf_radar_detection_init(struct aicwf_radar *radar)
+{
+ return true;
+}
+
+static inline void aicwf_radar_detection_deinit(struct aicwf_radar *radar)
+{
+}
+
+static inline bool aicwf_radar_set_domain(struct aicwf_radar *radar,
+ enum nl80211_dfs_regions region)
+{
+ return true;
+}
+
+static inline void aicwf_radar_detection_enable(struct aicwf_radar *radar,
+ u8 enable, u8 chain)
+{
+}
+
+static inline bool aicwf_radar_detection_is_enable(struct aicwf_radar *radar,
+ u8 chain)
+{
+ return false;
+}
+
+static inline void aicwf_radar_start_cac(struct aicwf_radar *radar,
+ u32 cac_time_ms, struct aicwf_vif *vif)
+{
+}
+
+static inline void aicwf_radar_cancel_cac(struct aicwf_radar *radar)
+{
+}
+
+static inline void
+aicwf_radar_detection_enable_on_cur_channel(struct aicwf_hw *aicwf_hw)
+{
+}
+
+static inline int aicwf_radar_dump_pattern_detector(char *buf, size_t len,
+ struct aicwf_radar *radar,
+ u8 chain)
+{
+ return 0;
+}
+
+static inline int aicwf_radar_dump_radar_detected(char *buf, size_t len,
+ struct aicwf_radar *radar,
+ u8 chain)
+{
+ return 0;
+}
+
+#endif /* CONFIG_AICWF_RADAR */
+
+#endif // _AICWF_RADAR_H_
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_resv_mem.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_resv_mem.h
new file mode 100644
index 000000000000..aeae5f1ac833
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_resv_mem.h
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_RESV_MEM_H_
+#define _AICWF_RESV_MEM_H_
+
+#include <linux/types.h>
+
+struct sk_buff;
+
+enum aicwf_resv_mem_id {
+ AIC_RESV_MEM_TXDATA,
+ AIC_RESV_MEM_NUM,
+};
+
+/**
+ * struct aicwf_resv_mem_entry - one reserved buffer
+ * @used: Whether the buffer is currently handed out
+ * @skb: The reserved buffer, %NULL until it could be allocated
+ */
+struct aicwf_resv_mem_entry {
+ bool used;
+ struct sk_buff *skb;
+};
+
+/**
+ * struct aicwf_resv_mem - buffers reserved for the lifetime of a device
+ * @entry: One entry per &enum aicwf_resv_mem_id
+ */
+struct aicwf_resv_mem {
+ struct aicwf_resv_mem_entry entry[AIC_RESV_MEM_NUM];
+};
+
+#ifdef CONFIG_RESV_MEM_SUPPORT
+void aicwf_resv_mem_init(struct aicwf_resv_mem *pool);
+void aicwf_resv_mem_deinit(struct aicwf_resv_mem *pool);
+struct sk_buff *aicwf_resv_mem_alloc_skb(struct aicwf_resv_mem *pool,
+ unsigned int length,
+ enum aicwf_resv_mem_id id);
+void aicwf_resv_mem_kfree_skb(struct aicwf_resv_mem *pool, struct sk_buff *skb,
+ enum aicwf_resv_mem_id id);
+#else
+static inline void aicwf_resv_mem_init(struct aicwf_resv_mem *pool)
+{
+}
+
+static inline void aicwf_resv_mem_deinit(struct aicwf_resv_mem *pool)
+{
+}
+#endif
+
+#endif /* _AICWF_RESV_MEM_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx.h
new file mode 100644
index 000000000000..145215156ddb
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx.h
@@ -0,0 +1,363 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_RX_H_
+#define _AICWF_RX_H_
+
+#include "aicwf_txrxif.h"
+
+struct aicwf_hw;
+struct aicwf_vif;
+
+#define SERVER_PORT 67
+#define CLIENT_PORT 68
+#define DHCP_MAGIC 0x63825363
+#define DHCP_ACK 5
+#define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
+#define DHCP_OPTION_END 255
+
+enum rx_status_bits {
+ /// The buffer can be forwarded to the networking stack
+ RX_STAT_FORWARD = 1 << 0,
+ /// A new buffer has to be allocated
+ RX_STAT_ALLOC = 1 << 1,
+ /// The buffer has to be deleted
+ RX_STAT_DELETE = 1 << 2,
+ /// The length of the buffer has to be updated
+ RX_STAT_LEN_UPDATE = 1 << 3,
+ /// The length in the Ethernet header has to be updated
+ RX_STAT_ETH_LEN_UPDATE = 1 << 4,
+ /// Simple copy
+ RX_STAT_COPY = 1 << 5,
+ /// Spurious frame (inform upper layer and discard)
+ RX_STAT_SPURIOUS = 1 << 6,
+ /// packet for monitor interface
+ RX_STAT_MONITOR = 1 << 7,
+};
+
+/*
+ * Decryption status subfields.
+ * {
+ */
+#define AICWF_RX_HD_DECR_UNENC 0 // ENCRYPTION TYPE NONE
+#define AICWF_RX_HD_DECR_WEP 1 // ENCRYPTION TYPE WEP
+#define AICWF_RX_HD_DECR_TKIP 2 // ENCRYPTION TYPE TKIP
+#define AICWF_RX_HD_DECR_CCMP128 3 // ENCRYPTION TYPE CCMP128
+#define AICWF_RX_HD_DECR_CCMP256 4 // ENCRYPTION TYPE CCMP256
+#define AICWF_RX_HD_DECR_GCMP128 5 // ENCRYPTION TYPE GCMP128
+#define AICWF_RX_HD_DECR_GCMP256 6 // ENCRYPTION TYPE GCMP256
+#define AICWF_RX_HD_DECR_WAPI 7 // ENCRYPTION TYPE WAPI
+// @}
+
+struct rx_vector_1_old {
+ /** Receive Vector 1a */
+ u32 leg_length : 12;
+ u32 leg_rate : 4;
+ u32 ht_length : 16;
+
+ /** Receive Vector 1b */
+ u32 _ht_length : 4; // FIXME
+ u32 short_gi : 1;
+ u32 stbc : 2;
+ u32 smoothing : 1;
+ u32 mcs : 7;
+ u32 pre_type : 1;
+ u32 format_mod : 3;
+ u32 ch_bw : 2;
+ u32 n_sts : 3;
+ u32 lsig_valid : 1;
+ u32 sounding : 1;
+ u32 num_extn_ss : 2;
+ u32 aggregation : 1;
+ u32 fec_coding : 1;
+ u32 dyn_bw : 1;
+ u32 doze_not_allowed : 1;
+
+ /** Receive Vector 1c */
+ u32 antenna_set : 8;
+ u32 partial_aid : 9;
+ u32 group_id : 6;
+ u32 first_user : 1;
+ s32 rssi1 : 8;
+
+ /** Receive Vector 1d */
+ s32 rssi2 : 8;
+ s32 rssi3 : 8;
+ s32 rssi4 : 8;
+ u32 reserved_1d : 8;
+};
+
+struct rx_leg_vect {
+ u8 dyn_bw_in_non_ht : 1;
+ u8 chn_bw_in_non_ht : 2;
+ u8 rsvd_nht : 4;
+ u8 lsig_valid : 1;
+} __packed;
+
+struct rx_ht_vect {
+ u16 sounding : 1;
+ u16 smoothing : 1;
+ u16 short_gi : 1;
+ u16 aggregation : 1;
+ u16 stbc : 1;
+ u16 num_extn_ss : 2;
+ u16 lsig_valid : 1;
+ u16 mcs : 7;
+ u16 fec : 1;
+ u16 length : 16;
+} __packed;
+
+struct rx_vht_vect {
+ u8 sounding : 1;
+ u8 beamformed : 1;
+ u8 short_gi : 1;
+ u8 rsvd_vht1 : 1;
+ u8 stbc : 1;
+ u8 doze_not_allowed : 1;
+ u8 first_user : 1;
+ u8 rsvd_vht2 : 1;
+ u16 partial_aid : 9;
+ u16 group_id : 6;
+ u16 rsvd_vht3 : 1;
+ u32 mcs : 4;
+ u32 nss : 3;
+ u32 fec : 1;
+ u32 length : 20;
+ u32 rsvd_vht4 : 4;
+} __packed;
+
+struct rx_he_vect {
+ u8 sounding : 1;
+ u8 beamformed : 1;
+ u8 gi_type : 2;
+ u8 stbc : 1;
+ u8 rsvd_he1 : 3;
+
+ u8 uplink_flag : 1;
+ u8 beam_change : 1;
+ u8 dcm : 1;
+ u8 he_ltf_type : 2;
+ u8 doppler : 1;
+ u8 rsvd_he2 : 2;
+
+ u8 bss_color : 6;
+ u8 rsvd_he3 : 2;
+
+ u8 txop_duration : 7;
+ u8 rsvd_he4 : 1;
+
+ u8 pe_duration : 4;
+ u8 spatial_reuse : 4;
+
+ u8 sig_b_comp_mode : 1;
+ u8 dcm_sig_b : 1;
+ u8 mcs_sig_b : 3;
+ u8 ru_size : 3;
+
+ u32 mcs : 4;
+ u32 nss : 3;
+ u32 fec : 1;
+ u32 length : 20;
+ u32 rsvd_he6 : 4;
+} __packed;
+
+struct rx_vector_1 {
+ u8 format_mod : 4;
+ u8 ch_bw : 3;
+ u8 pre_type : 1;
+ u8 antenna_set : 8;
+ s32 rssi_leg : 8;
+ u32 leg_length : 12;
+ u32 leg_rate : 4;
+ s32 rssi1 : 8;
+
+ union {
+ struct rx_leg_vect leg;
+ struct rx_ht_vect ht;
+ struct rx_vht_vect vht;
+ struct rx_he_vect he;
+ };
+} __packed;
+
+struct rx_vector_2_old {
+ /** Receive Vector 2a */
+ u32 rcpi : 8;
+ u32 evm1 : 8;
+ u32 evm2 : 8;
+ u32 evm3 : 8;
+
+ /** Receive Vector 2b */
+ u32 evm4 : 8;
+ u32 reserved2b_1 : 8;
+ u32 reserved2b_2 : 8;
+ u32 reserved2b_3 : 8;
+};
+
+struct rx_vector_2 {
+ /** Receive Vector 2a */
+ u32 rcpi1 : 8;
+ u32 rcpi2 : 8;
+ u32 rcpi3 : 8;
+ u32 rcpi4 : 8;
+
+ /** Receive Vector 2b */
+ u32 evm1 : 8;
+ u32 evm2 : 8;
+ u32 evm3 : 8;
+ u32 evm4 : 8;
+};
+
+struct phy_channel_info_desc {
+ /** PHY channel information 1 */
+ u32 phy_band : 8;
+ u32 phy_channel_type : 8;
+ u32 phy_prim20_freq : 16;
+ /** PHY channel information 2 */
+ u32 phy_center1_freq : 16;
+ u32 phy_center2_freq : 16;
+};
+
+struct hw_vect {
+ /** Total length for the MPDU transfer */
+ u32 len : 16;
+
+ u32 reserved : 8; // data type is included
+ /** AMPDU Status Information */
+ u32 mpdu_cnt : 6;
+ u32 ampdu_cnt : 2;
+
+ /** TSF Low */
+ __le32 tsf_lo;
+ /** TSF High */
+ __le32 tsf_hi;
+
+ /** Receive Vector 1 */
+ struct rx_vector_1 rx_vect1;
+ /** Receive Vector 2 */
+ struct rx_vector_2 rx_vect2;
+
+ /** Status **/
+ u32 rx_vect2_valid : 1;
+ u32 resp_frame : 1;
+ /** Decryption Status */
+ u32 decr_status : 3;
+ u32 rx_fifo_oflow : 1;
+
+ /** Frame Unsuccessful */
+ u32 undef_err : 1;
+ u32 phy_err : 1;
+ u32 fcs_err : 1;
+ u32 addr_mismatch : 1;
+ u32 ga_frame : 1;
+ u32 current_ac : 2;
+
+ u32 frm_successful_rx : 1;
+ /** Descriptor Done */
+ u32 desc_done_rx : 1;
+ /** Key Storage RAM Index */
+ u32 key_sram_index : 10;
+ /** Key Storage RAM Index Valid */
+ u32 key_sram_v : 1;
+ u32 type : 2;
+ u32 subtype : 4;
+};
+
+struct hw_rxhdr {
+ /** RX vector */
+ struct hw_vect hwvect;
+
+ /** PHY channel information */
+ struct phy_channel_info_desc phy_info;
+
+ /** RX flags */
+ u32 flags_is_amsdu : 1;
+ u32 flags_is_80211_mpdu : 1;
+ u32 flags_is_4addr : 1;
+ u32 flags_new_peer : 1;
+ u32 flags_user_prio : 1; // aic: fw not fill any more
+ u32 flags_need_reord : 1;
+ u32 flags_upload : 1;
+#ifndef CONFIG_AIC8800_RX_REORDER
+ u32 flags_rsvd0 : 1;
+#else
+ u32 is_monitor_vif : 1;
+#endif
+ u32 flags_vif_idx : 8; // 0xFF if invalid VIF index
+ u32 flags_sta_idx : 8; // 0xFF if invalid STA index
+ u32 flags_dst_idx : 8; // 0xFF if unknown destination STA
+ /** Pattern indicating if the buffer is available for the driver */
+ u32 pattern;
+};
+
+struct aicwf_legrate {
+ int idx;
+ int rate;
+};
+
+extern const struct aicwf_legrate legrates_lut[];
+extern const u16 tx_legrates_lut_rate[];
+
+struct dhcpinfo {
+ u8 op;
+ u8 htype;
+ u8 hlen;
+ u8 hops;
+ u32 xid;
+ u16 secs;
+ u16 flags;
+ u32 ciaddr;
+ u32 yiaddr;
+ u32 siaddr;
+ u32 giaddr;
+ u8 chaddr[16];
+ u8 sname[64];
+ u8 file[128];
+ __be32 cookie;
+ u8 options[308]; /* 312 - cookie */
+};
+
+bool aicwf_rx_data_skb(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ struct sk_buff *skb, struct hw_rxhdr *rxhdr);
+u8 aicwf_rxdataind(struct aicwf_hw *aicwf_hw, void *hostid, void *rx_priv);
+int aicwf_process_rxframes(struct aicwf_rx_priv *rx_priv);
+
+#ifdef CONFIG_AIC8800_ARP_OFFLOAD
+void arpoffload_proc(struct sk_buff *skb, struct aicwf_vif *aicwf_vif);
+#endif
+#ifdef CONFIG_AIC8800_RX_REORDER
+struct recv_msdu *reord_rxframe_alloc(spinlock_t *lock, struct list_head *q);
+void reord_rxframe_free(spinlock_t *lock, struct list_head *q,
+ struct list_head *list);
+struct reord_ctrl_info *reord_init_sta(struct aicwf_rx_priv *rx_priv,
+ const u8 *mac_addr);
+void reord_deinit_sta(struct aicwf_rx_priv *rx_priv,
+ struct reord_ctrl_info *reord_info);
+int reord_need_check(struct reord_ctrl *preorder_ctrl, u16 seq_num);
+int reord_rxframe_enqueue(struct reord_ctrl *preorder_ctrl,
+ struct recv_msdu *prframe);
+void reord_timeout_worker(struct work_struct *work);
+int reord_single_frame_ind(struct aicwf_rx_priv *rx_priv,
+ struct recv_msdu *prframe);
+void reord_timeout_handler(struct timer_list *t);
+
+#endif
+void aicwf_rxdata_process_amsdu(struct aicwf_hw *aicwf_hw, struct sk_buff *skb,
+ u8 vif_idx, struct sk_buff_head *list);
+
+void aicwf_rx_data_skb_resend(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ struct sk_buff *skb, struct hw_rxhdr *rxhdr);
+int reord_flush_tid(struct aicwf_rx_priv *rx_priv, struct sk_buff *skb, u8 tid);
+bool reord_rxframes_process(struct aicwf_rx_priv *rx_priv,
+ struct reord_ctrl *preorder_ctrl, int bforced);
+void reord_rxframes_ind(struct aicwf_rx_priv *rx_priv, struct reord_ctrl *preorder_ctrl);
+int reord_process_unit(struct aicwf_rx_priv *rx_priv, struct sk_buff *skb,
+ u16 seq_num, u8 tid, u8 forward, u8 is_amsdu);
+void remove_sec_hdr_mgmt_frame(struct hw_rxhdr *hw_rxhdr, struct sk_buff *skb);
+
+void defrag_timeout_cb(struct timer_list *t);
+void aicwf_defrag_init(struct aicwf_hw *aicwf_hw);
+void aicwf_defrag_deinit(struct aicwf_hw *aicwf_hw);
+
+#endif /* _AICWF_RX_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx_prealloc.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx_prealloc.h
new file mode 100644
index 000000000000..77114a28e342
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx_prealloc.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_RX_PREALLOC_H_
+#define _AICWF_RX_PREALLOC_H_
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/atomic.h>
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+#define AICWF_RXBUFF_SIZE (64 * 512)
+
+struct rx_buff {
+ struct list_head queue;
+ unsigned char *data;
+ u32 len;
+ u8 *start;
+ u8 *end;
+ u8 *read;
+};
+
+struct aicwf_rx_buff_list {
+ struct list_head rxbuff_list;
+ atomic_t rxbuff_list_len;
+};
+
+extern struct aicwf_rx_buff_list aic_rx_buff_list;
+
+struct rx_buff *aicwf_prealloc_rxbuff_alloc(spinlock_t *lock);
+void aicwf_prealloc_rxbuff_free(struct rx_buff *rxbuff, spinlock_t *lock);
+int aicwf_prealloc_init(void);
+void aicwf_prealloc_exit(void);
+#endif
+#endif /* _AICWF_RX_PREALLOC_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_sdio.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_sdio.c
new file mode 100644
index 000000000000..4dc8b040e9c8
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_sdio.c
@@ -0,0 +1,2439 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief SDIO function declarations
+ *
+ ******************************************************************************
+ */
+
+#include <linux/completion.h>
+#include <linux/kthread.h>
+#include <linux/pm.h>
+#include <linux/semaphore.h>
+
+#include "aicwf_sdio.h"
+#include "aicwf_txrxif.h"
+#include "aicwf_defs.h"
+#include "aicwf_msg_tx.h"
+#include "aicwf_main.h"
+#include "aicwf_platform.h"
+#include "sdio_host.h"
+#include "aicwf_chip_ops.h"
+
+/*
+ * Wakeup sources report PM events; they are not a driver-side completion
+ * mechanism. Track SDIO work explicitly so suspend can quiesce it without
+ * inspecting wakeup-source internals.
+ */
+bool aicwf_sdio_activity_get(struct aicwf_hw *aicwf_hw,
+ struct wakeup_source *ws)
+{
+ struct aic_sdio_dev *sdiodev;
+
+ if (!aicwf_hw || (IS_ENABLED(CONFIG_PM_SLEEP) && !ws))
+ return false;
+
+ sdiodev = aicwf_hw->sdiodev;
+ if (!sdiodev || READ_ONCE(sdiodev->quiesced) ||
+ unlikely(atomic_read(&sdiodev->suspending)))
+ return false;
+
+ atomic_inc(&sdiodev->activity_count);
+ /* Order the activity increment before checking the suspend gate. */
+ smp_mb__after_atomic();
+ if (READ_ONCE(sdiodev->quiesced) ||
+ unlikely(atomic_read(&sdiodev->suspending))) {
+ if (atomic_dec_and_test(&sdiodev->activity_count))
+ wake_up_all(&sdiodev->activity_waitq);
+ return false;
+ }
+
+ __pm_stay_awake(ws);
+ return true;
+}
+
+void aicwf_sdio_activity_put(struct aicwf_hw *aicwf_hw,
+ struct wakeup_source *ws)
+{
+ struct aic_sdio_dev *sdiodev;
+
+ if (!aicwf_hw || (IS_ENABLED(CONFIG_PM_SLEEP) && !ws))
+ return;
+
+ sdiodev = aicwf_hw->sdiodev;
+ if (!sdiodev)
+ return;
+
+ __pm_relax(ws);
+ /*
+ * Keep the PM release before exposing count == 0 to a suspend waiter.
+ * atomic_add_unless() prevents a bad duplicate put from underflowing the
+ * accounting and making all later suspend attempts time out.
+ */
+ if (WARN_ON_ONCE(!atomic_add_unless(&sdiodev->activity_count, -1, 0)))
+ return;
+
+ if (atomic_read(&sdiodev->activity_count) == 0)
+ wake_up_all(&sdiodev->activity_waitq);
+}
+
+bool aicwf_sdio_scan_activity_get(struct aicwf_hw *aicwf_hw)
+{
+ if (!aicwf_hw)
+ return false;
+
+ /* Reserve the terminal put before taking the shared wakeup source. */
+ if (WARN_ON_ONCE(atomic_cmpxchg(&aicwf_hw->scan_activity_held, 0, 1)))
+ return false;
+
+ if (!aicwf_sdio_activity_get(aicwf_hw, aicwf_hw->ws_scan)) {
+ atomic_set(&aicwf_hw->scan_activity_held, 0);
+ return false;
+ }
+
+ return true;
+}
+
+void aicwf_sdio_scan_activity_put(struct aicwf_hw *aicwf_hw)
+{
+ if (aicwf_hw && atomic_xchg(&aicwf_hw->scan_activity_held, 0))
+ aicwf_sdio_activity_put(aicwf_hw, aicwf_hw->ws_scan);
+}
+
+#define AICWF_SDIO_TX_AGGR_MAX 32
+
+int aicwf_sdio_readb(struct aic_sdio_dev *sdiodev, uint regaddr, u8 *val)
+{
+ int ret;
+
+ if (!sdiodev->func) {
+ dev_warn(sdiodev->dev, "null sdio func\n");
+ return 0;
+ }
+ sdio_claim_host(sdiodev->func);
+ *val = sdio_readb(sdiodev->func, regaddr, &ret);
+ sdio_release_host(sdiodev->func);
+ return ret;
+}
+
+int aicwf_sdio_writeb(struct aic_sdio_dev *sdiodev, uint regaddr, u8 val)
+{
+ int ret;
+
+ if (!sdiodev->func) {
+ dev_warn(sdiodev->dev, "null sdio func\n");
+ return 0;
+ }
+ sdio_claim_host(sdiodev->func);
+ sdio_writeb(sdiodev->func, val, regaddr, &ret);
+ sdio_release_host(sdiodev->func);
+ return ret;
+}
+
+int aicwf_sdio_func2_readb(struct aic_sdio_dev *sdiodev, uint regaddr, u8 *val)
+{
+ int ret;
+
+ sdio_claim_host(sdiodev->func2);
+ *val = sdio_readb(sdiodev->func2, regaddr, &ret);
+ sdio_release_host(sdiodev->func2);
+ return ret;
+}
+
+int aicwf_sdio_func2_writeb(struct aic_sdio_dev *sdiodev, uint regaddr, u8 val)
+{
+ int ret;
+
+ sdio_claim_host(sdiodev->func2);
+ sdio_writeb(sdiodev->func2, val, regaddr, &ret);
+ sdio_release_host(sdiodev->func2);
+ return ret;
+}
+
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+void aicwf_sdio_tx_netif_flowctrl(struct aicwf_hw *aicwf_hw, bool state)
+{
+ struct aicwf_vif *aicwf_vif;
+
+ list_for_each_entry(aicwf_vif, &aicwf_hw->vifs, list) {
+ if (!aicwf_vif->up)
+ continue;
+ if (state)
+ netif_tx_stop_all_queues(aicwf_vif->ndev);
+ else
+ netif_tx_wake_all_queues(aicwf_vif->ndev);
+ }
+}
+#endif
+
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+static int update_state(struct aic_sdio_dev *sdiodev)
+{
+ s8 value = sdiodev->tp_ctrl.cur_temp;
+ u8 current_state = sdiodev->tp_ctrl.cur_stat;
+ s8 thd_1 = sdiodev->tp_ctrl.tp_thd_1;
+ s8 thd_2 = sdiodev->tp_ctrl.tp_thd_2;
+
+ if (value > thd_2)
+ return 2;
+ else if (value > (thd_2 - BUFFERING_V2) && (current_state == 2))
+ return 2;
+ else if (value > thd_1 && current_state != 2)
+ return 1;
+ else if (value > (thd_1 - BUFFERING_V1) && current_state == 1)
+ return 1;
+ else if (current_state == 0)
+ return 0;
+ else
+ return 1;
+}
+
+void aicwf_netif_ctrl(struct aic_sdio_dev *sdiodev, int val)
+{
+ unsigned long flags;
+ struct aicwf_vif *aicwf_vif;
+
+ if (sdiodev->tp_ctrl.net_stop)
+ return;
+
+ spin_lock_irqsave(&sdiodev->tx_tp_lock, flags);
+ list_for_each_entry(aicwf_vif, &sdiodev->aicwf_hw->vifs, list) {
+ if (!aicwf_vif || !aicwf_vif->ndev || !aicwf_vif->up)
+ continue;
+ netif_tx_stop_all_queues(aicwf_vif->ndev);
+ }
+ spin_unlock_irqrestore(&sdiodev->tx_tp_lock, flags);
+ sdiodev->tp_ctrl.net_stop = true;
+ mod_timer(&sdiodev->tp_ctrl.netif_timer, jiffies + msecs_to_jiffies(val));
+}
+
+void aicwf_temp_ctrl(struct aic_sdio_dev *sdiodev)
+{
+ if (sdiodev->tp_ctrl.set_level) {
+ if (sdiodev->tp_ctrl.set_level == 1) {
+ sdiodev->tp_ctrl.get_level = 1;
+ aicwf_netif_ctrl(sdiodev,
+ sdiodev->tp_ctrl.interval_t1 /* TMR_INTERVAL_1 */);
+ } else if (sdiodev->tp_ctrl.set_level == 2) {
+ sdiodev->tp_ctrl.get_level = 2;
+ aicwf_netif_ctrl(sdiodev,
+ sdiodev->tp_ctrl.interval_t2 /* TMR_INTERVAL_2 */);
+ }
+ return;
+ }
+ if (sdiodev->tp_ctrl.cur_temp >
+ (sdiodev->tp_ctrl.tp_thd_1 - BUFFERING_V1)) {
+ if (update_state(sdiodev) == 1) {
+ sdiodev->tp_ctrl.get_level = 1;
+ sdiodev->tp_ctrl.cur_stat = 1;
+ aicwf_netif_ctrl(sdiodev,
+ sdiodev->tp_ctrl.interval_t1 /*TMR_INTERVAL_1 */);
+ } else if (update_state(sdiodev) == 2) {
+ sdiodev->tp_ctrl.get_level = 2;
+ sdiodev->tp_ctrl.cur_stat = 2;
+ aicwf_netif_ctrl(sdiodev,
+ sdiodev->tp_ctrl.interval_t2 /*TMR_INTERVAL_2 */);
+ }
+ return;
+ }
+
+ if (sdiodev->tp_ctrl.cur_stat) {
+ dev_dbg(sdiodev->dev, "reset cur_stat");
+ sdiodev->tp_ctrl.cur_stat = 0;
+ sdiodev->tp_ctrl.get_level = 0;
+ }
+}
+
+void aicwf_netif_worker(struct work_struct *work)
+{
+ struct temp_ctrl *tc = container_of(work, struct temp_ctrl, netif_work);
+ struct aic_sdio_dev *sdiodev =
+ container_of(tc, struct aic_sdio_dev, tp_ctrl);
+ unsigned long flags;
+ struct aicwf_vif *aicwf_vif;
+
+ if (sdiodev->bus_if->state == BUS_DOWN_ST) {
+ dev_err(sdiodev->dev, "bus down\n");
+ return;
+ }
+
+ spin_lock_irqsave(&sdiodev->tx_tp_lock, flags);
+ list_for_each_entry(aicwf_vif, &sdiodev->aicwf_hw->vifs, list) {
+ if (!aicwf_vif || !aicwf_vif->ndev || !aicwf_vif->up)
+ continue;
+ netif_tx_wake_all_queues(aicwf_vif->ndev);
+ }
+ spin_unlock_irqrestore(&sdiodev->tx_tp_lock, flags);
+ sdiodev->tp_ctrl.net_stop = false;
+}
+
+static void aicwf_netif_timer(struct timer_list *t)
+{
+ struct temp_ctrl *tc = container_of(t, struct temp_ctrl, netif_timer);
+ struct aic_sdio_dev *sdiodev =
+ container_of(tc, struct aic_sdio_dev, tp_ctrl);
+
+ if (sdiodev->bus_if->state == BUS_DOWN_ST) {
+ dev_err(sdiodev->dev, "bus down\n");
+ return;
+ }
+
+ if (!work_pending(&sdiodev->tp_ctrl.netif_work))
+ schedule_work(&sdiodev->tp_ctrl.netif_work);
+}
+
+void aicwf_temp_ctrl_worker(struct work_struct *work)
+{
+ struct aicwf_hw *aicwf_hw;
+ struct mm_set_vendor_swconfig_cfm cfm;
+ struct temp_ctrl *tc = container_of(work, struct temp_ctrl, tp_ctrl_work);
+ struct aic_sdio_dev *sdiodev =
+ container_of(tc, struct aic_sdio_dev, tp_ctrl);
+
+ if (sdiodev->bus_if->state == BUS_DOWN_ST) {
+ dev_err(sdiodev->dev, "bus down\n");
+ return;
+ }
+
+ spin_lock_bh(&sdiodev->tp_ctrl.tm_lock);
+ if (!sdiodev->tp_ctrl.tm_start) {
+ spin_unlock_bh(&sdiodev->tp_ctrl.tm_lock);
+ dev_err(sdiodev->dev, "tp_timer should stop_1\n");
+ return;
+ }
+ spin_unlock_bh(&sdiodev->tp_ctrl.tm_lock);
+
+ aicwf_hw = sdiodev->aicwf_hw;
+ aicwf_hw->started_jiffies = jiffies;
+
+ aicwf_send_get_temp_req(aicwf_hw, &cfm);
+ sdiodev->tp_ctrl.cur_temp = cfm.temp_comp_get_cfm.degree;
+
+ spin_lock_bh(&sdiodev->tp_ctrl.tm_lock);
+ if (sdiodev->tp_ctrl.tm_start)
+ mod_timer(&sdiodev->tp_ctrl.tp_ctrl_timer,
+ jiffies + msecs_to_jiffies(TEMP_GET_INTERVAL));
+ else
+ dev_err(sdiodev->dev, "tp_timer should stop_2\n");
+ spin_unlock_bh(&sdiodev->tp_ctrl.tm_lock);
+}
+
+static void aicwf_temp_ctrl_timer(struct timer_list *t)
+{
+ struct temp_ctrl *tc = container_of(t, struct temp_ctrl, tp_ctrl_timer);
+ struct aic_sdio_dev *sdiodev =
+ container_of(tc, struct aic_sdio_dev, tp_ctrl);
+
+ if (sdiodev->bus_if->state == BUS_DOWN_ST) {
+ dev_err(sdiodev->dev, "bus down\n");
+ return;
+ }
+
+ if (!work_pending(&sdiodev->tp_ctrl.tp_ctrl_work))
+ schedule_work(&sdiodev->tp_ctrl.tp_ctrl_work);
+}
+
+void aicwf_tp_ctrl_init(struct aic_sdio_dev *sdiodev)
+{
+ spin_lock_init(&sdiodev->tp_ctrl.tm_lock);
+ sdiodev->tp_ctrl.net_stop = false;
+ sdiodev->tp_ctrl.on_off = true;
+ sdiodev->tp_ctrl.cur_temp = 0;
+ sdiodev->tp_ctrl.get_level = 0;
+ sdiodev->tp_ctrl.set_level = 0;
+ sdiodev->tp_ctrl.interval_t1 = TMR_INTERVAL_1;
+ sdiodev->tp_ctrl.interval_t2 = TMR_INTERVAL_2;
+ sdiodev->tp_ctrl.cur_stat = 0;
+ sdiodev->tp_ctrl.tp_thd_1 = TEMP_THD_1;
+ sdiodev->tp_ctrl.tp_thd_2 = TEMP_THD_2;
+ sdiodev->tp_ctrl.tm_start = 1;
+
+ timer_setup(&sdiodev->tp_ctrl.tp_ctrl_timer, aicwf_temp_ctrl_timer, 0);
+ timer_setup(&sdiodev->tp_ctrl.netif_timer, aicwf_netif_timer, 0);
+
+ INIT_WORK(&sdiodev->tp_ctrl.tp_ctrl_work, aicwf_temp_ctrl_worker);
+ INIT_WORK(&sdiodev->tp_ctrl.netif_work, aicwf_netif_worker);
+ mod_timer(&sdiodev->tp_ctrl.tp_ctrl_timer,
+ jiffies + msecs_to_jiffies(TEMP_GET_INTERVAL));
+}
+
+void aicwf_tp_ctrl_deinit(struct aic_sdio_dev *sdiodev)
+{
+ spin_lock_bh(&sdiodev->tp_ctrl.tm_lock);
+ sdiodev->tp_ctrl.tm_start = 0;
+ if (timer_pending(&sdiodev->tp_ctrl.tp_ctrl_timer)) {
+ dev_dbg(sdiodev->dev, "del tp_ctrl_timer\n");
+ timer_delete_sync(&sdiodev->tp_ctrl.tp_ctrl_timer);
+ }
+ spin_unlock_bh(&sdiodev->tp_ctrl.tm_lock);
+
+ cancel_work_sync(&sdiodev->tp_ctrl.tp_ctrl_work);
+
+ if (timer_pending(&sdiodev->tp_ctrl.netif_timer)) {
+ dev_dbg(sdiodev->dev, "del netif_timer\n");
+ timer_delete_sync(&sdiodev->tp_ctrl.netif_timer);
+ }
+
+ cancel_work_sync(&sdiodev->tp_ctrl.netif_work);
+}
+
+#endif
+
+int aicwf_sdio_flow_ctrl_msg(struct aic_sdio_dev *sdiodev)
+{
+ int ret = -1;
+ u8 fc_reg = 0;
+ u32 count = 0;
+
+ while (true) {
+ ret =
+ aicwf_sdio_readb(sdiodev, sdiodev->sdio_reg.flow_ctrl_reg, &fc_reg);
+ if (ret)
+ return -1;
+
+ if (sdiodev->chip_hw->need_flowctrl_mask)
+ fc_reg &= SDIOWIFI_FLOWCTRL_MASK_REG;
+
+ if (fc_reg != 0) {
+ ret = fc_reg;
+ if (ret > AICWF_SDIO_TX_AGGR_MAX)
+ ret = AICWF_SDIO_TX_AGGR_MAX;
+ return ret;
+ }
+ if (count >= FLOW_CTRL_RETRY_COUNT) {
+ ret = -fc_reg;
+ break;
+ }
+ count++;
+ if (count < 30)
+ usleep_range(50, 100);
+ else if (count < 40)
+ usleep_range(2000, 2500);
+ else
+ usleep_range(10000, 12000);
+ }
+
+ return ret;
+}
+
+int aicwf_sdio_flow_ctrl(struct aic_sdio_dev *sdiodev)
+{
+ int ret = -1;
+ u8 fc_reg = 0;
+ u32 count = 0;
+
+ while (true) {
+ ret =
+ aicwf_sdio_readb(sdiodev, sdiodev->sdio_reg.flow_ctrl_reg, &fc_reg);
+ if (ret)
+ return -1;
+
+ if (sdiodev->chip_hw->need_flowctrl_mask)
+ fc_reg &= SDIOWIFI_FLOWCTRL_MASK_REG;
+
+ if (fc_reg > DATA_FLOW_CTRL_THRESH) {
+ ret = fc_reg;
+ if (ret > AICWF_SDIO_TX_AGGR_MAX)
+ ret = AICWF_SDIO_TX_AGGR_MAX;
+ return ret;
+ }
+ if (count >= FLOW_CTRL_RETRY_COUNT) {
+ ret = -fc_reg;
+ break;
+ }
+ count++;
+ if (count < 30)
+ usleep_range(50, 50);
+ else if (count < 40)
+ usleep_range(2000, 2500);
+ else
+ usleep_range(10000, 12000);
+ }
+
+ return ret;
+}
+
+int aicwf_sdio_send_pkt(struct aic_sdio_dev *sdiodev, u8 *buf, uint count)
+{
+ int ret = 0;
+
+ if (!sdiodev->func) {
+ dev_warn(sdiodev->dev, "null sdio func\n");
+ return 0;
+ }
+
+ sdio_claim_host(sdiodev->func);
+ ret =
+ sdio_writesb(sdiodev->func, sdiodev->sdio_reg.wr_fifo_addr, buf, count);
+ sdio_release_host(sdiodev->func);
+
+ return ret;
+}
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+int aicwf_sdio_recv_pkt(struct aic_sdio_dev *sdiodev, struct rx_buff *rxbuff,
+ u32 size)
+{
+ int ret;
+
+ if (!rxbuff->data || !size || size > AICWF_RXBUFF_SIZE)
+ return -EINVAL;
+ if (!sdiodev->func) {
+ dev_warn(sdiodev->dev, "null sdio func\n");
+ return -ENODEV;
+ }
+
+ sdio_claim_host(sdiodev->func);
+ ret = sdio_readsb(sdiodev->func, rxbuff->data,
+ sdiodev->sdio_reg.rd_fifo_addr, size);
+ sdio_release_host(sdiodev->func);
+
+ if (ret < 0)
+ return ret;
+ rxbuff->len = size;
+
+ return ret;
+}
+#else
+int aicwf_sdio_recv_pkt(struct aic_sdio_dev *sdiodev, struct sk_buff *skbbuf,
+ u32 size)
+{
+ int ret;
+
+ if (!skbbuf || !size || size > skb_tailroom(skbbuf))
+ return -EINVAL;
+ if (!sdiodev->func) {
+ dev_warn(sdiodev->dev, "null sdio func\n");
+ return -ENODEV;
+ }
+
+ sdio_claim_host(sdiodev->func);
+ ret = sdio_readsb(sdiodev->func, skb_tail_pointer(skbbuf),
+ sdiodev->sdio_reg.rd_fifo_addr, size);
+ sdio_release_host(sdiodev->func);
+
+ if (ret < 0)
+ return ret;
+ skb_put(skbbuf, size);
+
+ return ret;
+}
+#endif
+
+/*
+ * Power-cycle the chip through the host's mmc-pwrseq so the firmware stops
+ * and the chip is back in bootrom for the next probe. Only function 1 is
+ * bound, so the MMC core resets the card directly instead of rescanning it.
+ *
+ * mmc-pwrseq-simple takes a single reset GPIO as a shared reset control, so
+ * when the Bluetooth driver holds the same line deasserted the chip is not
+ * actually reset or powered off here.
+ */
+static void aicwf_sdio_hw_reset(struct sdio_func *func)
+{
+ int ret;
+
+ sdio_claim_host(func);
+ ret = mmc_hw_reset(func->card);
+ sdio_release_host(func);
+ if (ret < 0)
+ dev_warn(&func->dev, "chip reset failed: %d\n", ret);
+}
+
+static int aicwf_sdio_probe(struct sdio_func *func,
+ const struct sdio_device_id *id)
+{
+ struct aic_sdio_dev *sdiodev;
+ struct aicwf_bus *bus_if;
+ int err = -ENODEV;
+ u16 chipid;
+
+ dev_dbg(&func->dev, "%d\n", func->num);
+ dev_dbg(&func->dev, "class=%x\n", func->class);
+ dev_dbg(&func->dev, "sdio vendor ID: 0x%04x\n", func->vendor);
+ dev_dbg(&func->dev, "sdio device ID: 0x%04x\n", func->device);
+ dev_dbg(&func->dev, "function#: %d\n", func->num);
+
+ if (func->num != 1)
+ return err;
+
+ bus_if =
+ kzalloc_obj(*bus_if, GFP_KERNEL);
+ if (!bus_if) {
+ dev_err(&func->dev, "alloc bus fail\n");
+ return -ENOMEM;
+ }
+
+ sdiodev =
+ kzalloc_obj(*sdiodev, GFP_KERNEL);
+ if (!sdiodev) {
+ dev_err(&func->dev, "alloc sdiodev fail\n");
+ kfree(bus_if);
+ return -ENOMEM;
+ }
+
+ err = aicwf_sdio_chipmatch(func->vendor, func->device, &chipid);
+ if (err) {
+ dev_err(&func->dev, "unsupported SDIO device %04x:%04x\n",
+ func->vendor, func->device);
+ kfree(sdiodev);
+ kfree(bus_if);
+ return err;
+ }
+ sdiodev->chipid = chipid;
+ sdiodev->chip_hw = aic_sdio_get_props(chipid);
+
+ sdiodev->func = func;
+ sdiodev->bus_if = bus_if;
+
+#ifdef CONFIG_OOB
+ sdiodev->oob_enable = sdiodev->chip_hw->oob_support;
+#else
+ sdiodev->oob_enable = false;
+#endif
+
+ atomic_set(&sdiodev->is_bus_suspend, 0);
+ bus_if->sdiodev = sdiodev;
+
+ dev_set_drvdata(&func->dev, bus_if);
+ sdiodev->dev = &func->dev;
+
+ if (sdiodev->chip_hw->use_func2)
+ sdiodev->func2 = func->card->sdio_func[1];
+
+ aicwf_resv_mem_init(&sdiodev->resv_mem);
+
+ //sdio func init start
+ if (!sdiodev->chip_hw->use_sdiov3_func)
+ err = aicwf_sdio_func_init(sdiodev);
+ else
+ err = aicwf_sdiov3_func_init(sdiodev);
+
+ if (err < 0) {
+ dev_err(&func->dev, "sdio func init fail\n");
+ goto fail;
+ }
+ // sdio func init end
+
+ if (!aicwf_sdio_bus_init(sdiodev)) {
+ dev_err(&func->dev, "sdio bus init fail\n");
+ err = -ENODEV;
+ goto fail;
+ }
+
+ err = aicwf_sdio_platform_init(sdiodev);
+ if (err) {
+ dev_err_probe(&func->dev, err, "platform init fail\n");
+ goto fail_release;
+ }
+ device_disable_async_suspend(sdiodev->dev);
+
+ return 0;
+fail_release:
+ aicwf_sdio_release(sdiodev);
+ aicwf_sdio_func_deinit(sdiodev);
+ aicwf_sdio_hw_reset(func);
+ goto fail_free;
+fail:
+ aicwf_sdio_func_deinit(sdiodev);
+fail_free:
+ aicwf_prealloc_txq_free(&sdiodev->prealloc_txq);
+ aicwf_resv_mem_deinit(&sdiodev->resv_mem);
+ dev_set_drvdata(&func->dev, NULL);
+ kfree(sdiodev);
+ kfree(bus_if);
+ return err;
+}
+
+static void aicwf_sdio_remove(struct sdio_func *func)
+{
+ struct aicwf_bus *bus_if = NULL;
+ struct aic_sdio_dev *sdiodev = NULL;
+
+ bus_if = dev_get_drvdata(&func->dev);
+ if (!bus_if)
+ return;
+
+ sdiodev = bus_if->sdiodev;
+ if (!sdiodev)
+ return;
+
+ aicwf_sdio_release(sdiodev);
+ aicwf_sdio_func_deinit(sdiodev);
+ aicwf_sdio_hw_reset(func);
+ aicwf_prealloc_txq_free(&sdiodev->prealloc_txq);
+ aicwf_resv_mem_deinit(&sdiodev->resv_mem);
+ kfree(sdiodev->plat);
+ dev_set_drvdata(&sdiodev->func->dev, NULL);
+ kfree(sdiodev);
+ kfree(bus_if);
+}
+
+static int aicwf_sdio_suspend(struct device *dev)
+{
+ int ret = 0;
+ struct aicwf_bus *bus_if = dev_get_drvdata(dev);
+ struct aic_sdio_dev *sdiodev = bus_if->sdiodev;
+ mmc_pm_flag_t sdio_flags;
+ struct aicwf_vif *aicwf_vif, *tmp;
+#ifdef CONFIG_AIC8800_NO_WAKE_COUNT
+ int cnt = 0;
+#endif
+ int sus_abort = 0;
+
+ /* Check host PM support before changing network or chip state. */
+ sdio_flags = sdio_get_host_pm_caps(sdiodev->func);
+ if (!(sdio_flags & MMC_PM_KEEP_POWER))
+ return -EINVAL;
+ ret = sdio_set_host_pm_flags(sdiodev->func, MMC_PM_KEEP_POWER);
+ if (ret)
+ return ret;
+
+ list_for_each_entry_safe(aicwf_vif, tmp, &sdiodev->aicwf_hw->vifs, list) {
+ if (aicwf_vif->ndev)
+ netif_device_detach(aicwf_vif->ndev);
+ }
+
+ if (sdiodev->aicwf_hw->testmode == 1)
+ dev_err(dev, "sleep cmd is not supported in RF test mode\n");
+#ifdef CONFIG_AIC8800_NO_WAKE_COUNT //move to when set supend is received
+ else
+ aicwf_send_me_set_lp_level(sdiodev->aicwf_hw, 1, 0); //dynamic switch
+#endif
+
+#if (defined(CONFIG_AIC8800_AUTO_POWERSAVE) && defined(CONFIG_AIC8800_SDIO_PWRCTRL))
+ aicwf_sdio_pwr_stctl(sdiodev, SDIO_ACTIVE_ST);
+ if (sdiodev->chip_hw->auto_ps_support) {
+ dev_dbg(dev, "auto_ps enter\n");
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.wakeup_reg, 0x8);
+ if (ret)
+ dev_err(dev, "sdio enter auto_ps fail\n");
+ }
+#endif
+
+#ifdef CONFIG_AIC8800_NO_WAKE_COUNT
+ while (&sdiodev->aicwf_hw->scan_request && aicwf_hw->scanning) {
+ /* move to when set supend is received, the theory does not enforce this condition,
+ * and the code is retained for now
+ */
+ dev_dbg(dev, "wait scan_cfm\n");
+ if (cnt == 0) {
+ aicwf_send_scanu_cancel_req(sdiodev->aicwf_hw, NULL);
+ continue;
+ }
+ msleep(20);
+ cnt += 1;
+ if (cnt >= 40)
+ break;
+ }
+#endif
+
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+ timer_delete_sync(&sdiodev->tp_ctrl.tp_ctrl_timer);
+ cancel_work_sync(&sdiodev->tp_ctrl.tp_ctrl_work);
+#endif
+
+ atomic_set(&sdiodev->suspending, 1);
+ /* Publish the suspend gate before checking outstanding activity. */
+ smp_mb__after_atomic();
+ if (!wait_event_timeout(sdiodev->activity_waitq,
+ atomic_read(&sdiodev->activity_count) == 0,
+ msecs_to_jiffies(600)))
+ sus_abort = 1;
+ if (sus_abort) {
+ atomic_set(&sdiodev->suspending, 0);
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+ mod_timer(&sdiodev->tp_ctrl.tp_ctrl_timer,
+ jiffies + msecs_to_jiffies(TEMP_GET_INTERVAL));
+#endif
+ dev_dbg(dev, "ws active dont suspend\n");
+
+#if defined(CONFIG_AIC8800_AUTO_POWERSAVE)
+ aicwf_sdio_pwr_stctl(sdiodev, SDIO_ACTIVE_ST);
+ if (sdiodev->chip_hw->auto_ps_support) {
+ dev_dbg(dev, "auto_ps abort\n");
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.wakeup_reg, 0x8);
+ if (ret)
+ dev_err(dev, "sdio exit auto_ps fail\n");
+ }
+#elif defined(CONFIG_AIC8800_NO_WAKE_COUNT)
+ if (sdiodev->aicwf_hw->testmode == 0)
+ aicwf_send_me_set_lp_level(sdiodev->aicwf_hw, 0, 1); //dynamic switch
+#endif
+ list_for_each_entry_safe(aicwf_vif, tmp, &sdiodev->aicwf_hw->vifs, list) {
+ if (aicwf_vif->ndev) {
+ dev_dbg(dev, "suspend restore\n");
+ netif_device_attach(aicwf_vif->ndev);
+ }
+ }
+ return -EBUSY;
+ }
+
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+ timer_delete_sync(&sdiodev->tp_ctrl.netif_timer);
+ cancel_work_sync(&sdiodev->tp_ctrl.netif_work);
+#endif
+
+#ifndef CONFIG_AIC8800_AUTO_POWERSAVE
+ while (sdiodev->state == SDIO_ACTIVE_ST) {
+ if (down_interruptible(&sdiodev->tx_priv->txctl_sema))
+ continue;
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ aicwf_sdio_pwr_stctl(sdiodev, SDIO_SLEEP_ST);
+#endif
+ up(&sdiodev->tx_priv->txctl_sema);
+ break;
+ }
+#else
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ aicwf_sdio_pwr_stctl(sdiodev, SDIO_SLEEP_ST);
+#endif
+#endif
+
+ atomic_set(&sdiodev->is_bus_suspend, 1);
+
+ return 0;
+}
+
+static int aicwf_sdio_resume(struct device *dev)
+{
+#if defined(CONFIG_AIC8800_AUTO_POWERSAVE) && defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ int ret;
+#endif
+ struct aicwf_bus *bus_if = dev_get_drvdata(dev);
+ struct aic_sdio_dev *sdiodev = bus_if->sdiodev;
+ struct aicwf_vif *aicwf_vif, *tmp;
+
+#ifdef CONFIG_AIC8800_NO_WAKE_COUNT
+ if (sdiodev->aicwf_hw->testmode == 0)
+ aicwf_send_me_set_lp_level(sdiodev->aicwf_hw, 0, 1); //dynamic switch
+#endif
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+ mod_timer(&sdiodev->tp_ctrl.tp_ctrl_timer,
+ jiffies + msecs_to_jiffies(TEMP_GET_INTERVAL));
+#endif
+ list_for_each_entry_safe(aicwf_vif, tmp, &sdiodev->aicwf_hw->vifs, list) {
+ if (aicwf_vif->ndev) {
+ dev_dbg(dev, "resume netif_attach\n");
+ netif_device_attach(aicwf_vif->ndev);
+ }
+ }
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ aicwf_sdio_pwr_stctl(sdiodev, SDIO_ACTIVE_ST);
+#endif
+
+#if defined(CONFIG_AIC8800_AUTO_POWERSAVE) && defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ if (sdiodev->chip_hw->auto_ps_support) {
+ dev_dbg(dev, "auto_ps exit\n");
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.wakeup_reg, 0x8);
+ if (ret)
+ dev_err(dev, "sdio exit auto_ps fail\n");
+ }
+#endif
+
+ atomic_set(&sdiodev->is_bus_suspend, 0);
+ atomic_set(&sdiodev->suspending, 0);
+
+ return 0;
+}
+
+static const struct sdio_device_id aicwf_sdmmc_ids[] = {
+ {SDIO_DEVICE(SDIO_VENDOR_ID_AIC8800D80, SDIO_DEVICE_ID_AIC8800D80)},
+ {SDIO_DEVICE(SDIO_VENDOR_ID_AIC8800D80N, SDIO_DEVICE_ID_AIC8800D80N)},
+ {SDIO_DEVICE(SDIO_VENDOR_ID_AIC8800D80N, SDIO_DEVICE_ID_AIC8800D80LN)},
+ {SDIO_DEVICE(SDIO_VENDOR_ID_AIC8800D80N, SDIO_DEVICE_ID_AIC8800D40N)},
+ {SDIO_DEVICE(SDIO_VENDOR_ID_AIC8800D80N, SDIO_DEVICE_ID_AIC8800D40LN)},
+ {},
+};
+
+MODULE_DEVICE_TABLE(sdio, aicwf_sdmmc_ids);
+
+static DEFINE_SIMPLE_DEV_PM_OPS(aicwf_sdio_pm_ops, aicwf_sdio_suspend,
+ aicwf_sdio_resume);
+
+static struct sdio_driver aicwf_sdio_driver = {
+ .probe = aicwf_sdio_probe,
+ .remove = aicwf_sdio_remove,
+ .name = AICWF_SDIO_NAME,
+ .id_table = aicwf_sdmmc_ids,
+ .drv = {
+ .pm = pm_sleep_ptr(&aicwf_sdio_pm_ops),
+ },
+};
+
+int aicwf_sdio_register(void)
+{
+ return sdio_register_driver(&aicwf_sdio_driver);
+}
+
+void aicwf_sdio_exit(void)
+{
+ sdio_unregister_driver(&aicwf_sdio_driver);
+}
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+/*
+ * Until the firmware is running the bootrom answers the power handshake:
+ * it acknowledges a wakeup request in the sleep register and is put back
+ * to sleep through the same register.
+ */
+static int aicwf_sdio_bootrom_wakeup(struct aic_sdio_dev *sdiodev)
+{
+ int ret = 0;
+ int read_retry;
+ int write_retry = 20;
+ u8 val;
+
+ while (write_retry) {
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.wakeup_reg,
+ sdiodev->chip_hw->wakeup_reg_val);
+ if (ret) {
+ dev_err(sdiodev->dev, "sdio wakeup fail\n");
+ ret = -1;
+ } else {
+ read_retry = 10;
+ while (read_retry) {
+ ret = aicwf_sdio_readb(sdiodev, sdiodev->sdio_reg.sleep_reg,
+ &val);
+ if (ret == 0 && val & 0x10)
+ break;
+ read_retry--;
+ usleep_range(30, 50);
+ }
+ if (read_retry != 0)
+ break;
+ }
+ dev_dbg(sdiodev->dev, "write retry: %d\n", write_retry);
+ write_retry--;
+ usleep_range(30, 50);
+ }
+
+ sdiodev->state = SDIO_ACTIVE_ST;
+ aicwf_sdio_pwrctl_timer(sdiodev, sdiodev->active_duration);
+
+ return ret;
+}
+
+static int aicwf_sdio_bootrom_sleep_allow(struct aic_sdio_dev *sdiodev)
+{
+ int ret = 0;
+
+ if (sdiodev->state == SDIO_ACTIVE_ST) {
+ dev_dbg(sdiodev->dev, "s\n");
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.sleep_reg, 0x10);
+ if (ret)
+ dev_err(sdiodev->dev, "write sleep fail\n");
+ sdiodev->state = SDIO_SLEEP_ST;
+ aicwf_sdio_pwrctl_timer(sdiodev, 0);
+ } else {
+ aicwf_sdio_pwrctl_timer(sdiodev, sdiodev->active_duration);
+ }
+
+ return ret;
+}
+
+int aicwf_sdio_wakeup(struct aic_sdio_dev *sdiodev)
+{
+ int ret = 0;
+ int read_retry;
+ int write_retry = 1;
+ int wakeup_reg_val = 0;
+
+ if (!sdiodev->fw_running)
+ return aicwf_sdio_bootrom_wakeup(sdiodev);
+
+ wakeup_reg_val = sdiodev->chip_hw->wakeup_reg_val;
+
+ if (sdiodev->state == SDIO_SLEEP_ST) {
+ dev_dbg(sdiodev->dev, "w\n");
+
+ while (write_retry) {
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.wakeup_reg,
+ wakeup_reg_val);
+ if (ret) {
+ dev_err(sdiodev->dev, "sdio wakeup fail\n");
+ ret = -1;
+ } else {
+ read_retry = 50;
+ while (read_retry) {
+ u8 val;
+
+ ret = aicwf_sdio_readb(sdiodev,
+ sdiodev->sdio_reg.wakeup_reg,
+ &val);
+ if (ret < 0)
+ dev_err(sdiodev->dev, "sdio wakeup read fail\n");
+ else if ((val & 0x1) == 0)
+ break;
+ read_retry--;
+ usleep_range(50, 60);
+ }
+ if (read_retry != 0)
+ break;
+ }
+ dev_dbg(sdiodev->dev, "write retry: %d\n", write_retry);
+ write_retry--;
+ usleep_range(40, 50);
+ }
+
+ sdiodev->state = SDIO_ACTIVE_ST;
+ aicwf_sdio_pwrctl_timer(sdiodev, sdiodev->active_duration);
+ }
+ return ret;
+}
+
+int aicwf_sdio_sleep_allow(struct aic_sdio_dev *sdiodev)
+{
+ int ret = 0;
+ struct aicwf_bus *bus_if = sdiodev->bus_if;
+ struct aicwf_hw *aicwf_hw = sdiodev->aicwf_hw;
+ u8 read_retry;
+ u8 val;
+
+ if (bus_if->state == BUS_DOWN_ST) {
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.sleep_reg, 0x10);
+ if (ret)
+ dev_err(sdiodev->dev, "write sleep fail\n");
+ aicwf_sdio_pwrctl_timer(sdiodev, 0);
+ return ret;
+ }
+
+ if (!sdiodev->fw_running)
+ return aicwf_sdio_bootrom_sleep_allow(sdiodev);
+
+ dev_dbg(sdiodev->dev, "sleep: %d, %d\n", sdiodev->state, aicwf_hw->scanning);
+ if (sdiodev->state == SDIO_ACTIVE_ST && !aicwf_hw->scanning && !aicwf_hw->is_p2p_alive &&
+ !aicwf_hw->is_p2p_connected &&
+ (int)(atomic_read(&sdiodev->tx_priv->tx_pktcnt) <= 0) &&
+ !sdiodev->tx_priv->cmd_txstate &&
+ (int)(atomic_read(&sdiodev->rx_priv->rx_cnt) == 0)) {
+ dev_dbg(sdiodev->dev, "s\n");
+ if (!sdiodev->chip_hw->use_func2) {
+ if (aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.wakeup_reg, 0x02) < 0)
+ dev_err(sdiodev->dev, "reg:%d write failed\n",
+ sdiodev->sdio_reg.wakeup_reg);
+ } else {
+ if (aicwf_sdio_func2_writeb(sdiodev, sdiodev->sdio_reg.wakeup_reg, 0x2) < 0)
+ dev_err(sdiodev->dev, "reg:%d write failed\n",
+ sdiodev->sdio_reg.wakeup_reg);
+ read_retry = 100;
+ while (read_retry) {
+ val = 0;
+ if (aicwf_sdio_func2_readb(sdiodev,
+ sdiodev->sdio_reg.wakeup_reg,
+ &val) < 0)
+ dev_err(sdiodev->dev, "reg %d read fail\n",
+ sdiodev->sdio_reg.wakeup_reg);
+ else if ((val & 0x2) == 0)
+ break;
+ dev_err(sdiodev->dev, "val:%d\n", val);
+ read_retry--;
+ if (read_retry < 90)
+ dev_dbg(sdiodev->dev, "warning: read cnt %d\n", read_retry);
+ usleep_range(50, 60);
+ }
+ }
+ sdiodev->state = SDIO_SLEEP_ST;
+ aicwf_sdio_pwrctl_timer(sdiodev, 0);
+ } else {
+ aicwf_sdio_pwrctl_timer(sdiodev, sdiodev->active_duration);
+ }
+
+ return ret;
+}
+
+int aicwf_sdio_pwr_stctl(struct aic_sdio_dev *sdiodev, uint target)
+{
+ int ret = 0;
+
+ if (!IS_ENABLED(CONFIG_AIC8800_SDIO_PWRCTRL))
+ return 0;
+
+ if (sdiodev->bus_if->state == BUS_DOWN_ST)
+ return -1;
+
+ down(&sdiodev->pwrctl_wakeup_sema);
+
+ if (sdiodev->state == target) {
+ if (target == SDIO_ACTIVE_ST)
+ aicwf_sdio_pwrctl_timer(sdiodev, sdiodev->active_duration);
+ up(&sdiodev->pwrctl_wakeup_sema);
+ return ret;
+ }
+
+ switch (target) {
+ case SDIO_ACTIVE_ST:
+ aicwf_sdio_wakeup(sdiodev);
+ break;
+ case SDIO_SLEEP_ST:
+ aicwf_sdio_sleep_allow(sdiodev);
+ break;
+ }
+
+ up(&sdiodev->pwrctl_wakeup_sema);
+ return ret;
+}
+#endif
+
+int aicwf_sdio_txpkt(struct aic_sdio_dev *sdiodev, struct sk_buff *pkt)
+{
+ int ret = 0;
+ u32 len = 0;
+ struct aicwf_bus *bus_if = dev_get_drvdata(sdiodev->dev);
+
+ if (bus_if->state == BUS_DOWN_ST) {
+ dev_dbg(sdiodev->dev, "tx bus is down\n");
+ return -EINVAL;
+ }
+
+ len = pkt->len;
+ len = (len + SDIOWIFI_FUNC_BLOCKSIZE - 1) / SDIOWIFI_FUNC_BLOCKSIZE *
+ SDIOWIFI_FUNC_BLOCKSIZE;
+
+ ret = aicwf_sdio_send_pkt(sdiodev, pkt->data, len);
+ if (ret)
+ dev_err(sdiodev->dev, "aicwf_sdio_send_pkt fail%d\n", ret);
+ return ret;
+}
+
+static int aicwf_sdio_intr_get_len_bytemode(struct aic_sdio_dev *sdiodev,
+ u8 *byte_len)
+{
+ int ret = 0;
+
+ if (!byte_len)
+ return -EBADE;
+
+ if (sdiodev->bus_if->state == BUS_DOWN_ST) {
+ *byte_len = 0;
+ } else {
+ ret = aicwf_sdio_readb(sdiodev, sdiodev->sdio_reg.bytemode_len_reg,
+ byte_len);
+ sdiodev->rx_priv->data_len = (*byte_len) * 4;
+ }
+
+ return ret;
+}
+
+static void aicwf_sdio_bus_stop(struct device *dev)
+{
+ struct aicwf_bus *bus_if = dev_get_drvdata(dev);
+ struct aic_sdio_dev *sdiodev = bus_if->sdiodev;
+ int ret = 0;
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ aicwf_sdio_pwrctl_timer(sdiodev, 0);
+#endif
+
+ bus_if->state = BUS_DOWN_ST;
+ if (sdiodev->tx_priv) {
+ ret = down_interruptible(&sdiodev->tx_priv->txctl_sema);
+ if (ret)
+ dev_err(dev, "down txctl_sema fail\n");
+ }
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ aicwf_sdio_pwr_stctl(sdiodev, SDIO_SLEEP_ST);
+#endif
+
+ if (sdiodev->tx_priv) {
+ if (!ret)
+ up(&sdiodev->tx_priv->txctl_sema);
+ aicwf_frame_queue_flush(&sdiodev->tx_priv->txq);
+ }
+}
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+struct rx_buff *aicwf_sdio_readframes(struct aic_sdio_dev *sdiodev)
+{
+ int ret = 0;
+ u32 size = 0;
+ struct aicwf_bus *bus_if = dev_get_drvdata(sdiodev->dev);
+ struct rx_buff *rxbuff;
+
+ if (bus_if->state == BUS_DOWN_ST) {
+ dev_dbg(sdiodev->dev, "bus down\n");
+ return NULL;
+ }
+
+ size = sdiodev->rx_priv->data_len;
+ if (!size || size > AICWF_RXBUFF_SIZE)
+ return NULL;
+ rxbuff = aicwf_prealloc_rxbuff_alloc(&sdiodev->rx_priv->rxbuff_lock);
+ if (!rxbuff) {
+ dev_err(sdiodev->dev, "failed to alloc rxbuff\n");
+ return NULL;
+ }
+ rxbuff->len = 0;
+ rxbuff->start = rxbuff->data;
+ rxbuff->read = rxbuff->start;
+ rxbuff->end = rxbuff->data + size;
+
+ ret = aicwf_sdio_recv_pkt(sdiodev, rxbuff, size);
+ if (ret) {
+ dev_err(sdiodev->dev, "%d, sdio recv pkt fail\n", __LINE__);
+ aicwf_prealloc_rxbuff_free(rxbuff, &sdiodev->rx_priv->rxbuff_lock);
+ return NULL;
+ }
+
+ return rxbuff;
+}
+#else
+struct sk_buff *aicwf_sdio_readframes(struct aic_sdio_dev *sdiodev)
+{
+ int ret = 0;
+ u32 size = 0;
+ struct sk_buff *skb = NULL;
+ struct aicwf_bus *bus_if = dev_get_drvdata(sdiodev->dev);
+
+ if (bus_if->state == BUS_DOWN_ST) {
+ dev_dbg(sdiodev->dev, "bus down\n");
+ return NULL;
+ }
+
+ size = sdiodev->rx_priv->data_len;
+ skb = __dev_alloc_skb(size, GFP_KERNEL);
+ if (!skb)
+ return NULL;
+
+ ret = aicwf_sdio_recv_pkt(sdiodev, skb, size);
+ if (ret) {
+ dev_kfree_skb(skb);
+ skb = NULL;
+ }
+
+ return skb;
+}
+#endif
+
+static int aicwf_sdio_tx_msg(struct aic_sdio_dev *sdiodev)
+{
+ int err = 0;
+ u16 len;
+ u8 *payload = sdiodev->tx_priv->cmd_buf;
+ u16 payload_len = sdiodev->tx_priv->cmd_len;
+ u8 adjust_str[4] = {0, 0, 0, 0};
+ int adjust_len = 0;
+ int buffer_cnt = 0;
+ u8 retry = 0;
+
+ len = payload_len;
+ if ((len % TX_ALIGNMENT) != 0) {
+ adjust_len = roundup(len, TX_ALIGNMENT);
+ memcpy(payload + payload_len, adjust_str, (adjust_len - len));
+ payload_len += (adjust_len - len);
+ }
+ len = payload_len;
+
+ // link tail is necessary
+ if ((len % SDIOWIFI_FUNC_BLOCKSIZE) != 0) {
+ memset(payload + payload_len, 0, TAIL_LEN);
+ payload_len += TAIL_LEN;
+ len = (payload_len / SDIOWIFI_FUNC_BLOCKSIZE + 1) *
+ SDIOWIFI_FUNC_BLOCKSIZE;
+ } else {
+ len = payload_len;
+ }
+
+ if (sdiodev->chip_hw->use_flowctrl_msg) {
+ buffer_cnt = aicwf_sdio_flow_ctrl_msg(sdiodev);
+ while ((buffer_cnt <= 0 ||
+ (buffer_cnt > 0 && len > (buffer_cnt * BUFFER_SIZE))) &&
+ retry < 10) {
+ retry++;
+ buffer_cnt = aicwf_sdio_flow_ctrl_msg(sdiodev);
+ dev_dbg(sdiodev->dev, "buffer_cnt = %d\n", buffer_cnt);
+ }
+ }
+ down(&sdiodev->tx_priv->cmd_txsema);
+
+ if (sdiodev->chip_hw->use_flowctrl_msg) {
+ if (buffer_cnt > 0 && len < (buffer_cnt * BUFFER_SIZE)) {
+ err = aicwf_sdio_send_pkt(sdiodev, payload, len);
+ if (err)
+ dev_err(sdiodev->dev, "aicwf_sdio_send_pkt fail%d\n", err);
+ } else {
+ dev_err(sdiodev->dev, "tx msg fc retry fail:%d, %d\n", buffer_cnt, len);
+ up(&sdiodev->tx_priv->cmd_txsema);
+ return -1;
+ }
+ } else {
+ err = aicwf_sdio_send_pkt(sdiodev, payload, len);
+ if (err)
+ dev_err(sdiodev->dev, "aicwf_sdio_send_pkt fail%d\n", err);
+ }
+
+ sdiodev->tx_priv->cmd_txstate = false;
+ if (!err)
+ sdiodev->tx_priv->cmd_tx_succ = true;
+ else
+ sdiodev->tx_priv->cmd_tx_succ = false;
+
+ up(&sdiodev->tx_priv->cmd_txsema);
+
+ return err;
+}
+
+static void aicwf_sdio_tx_process(struct aic_sdio_dev *sdiodev)
+{
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+ unsigned long flags;
+#endif
+
+ if (sdiodev->bus_if->state == BUS_DOWN_ST) {
+ dev_err(sdiodev->dev, "bus is down\n");
+ return;
+ }
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ aicwf_sdio_pwr_stctl(sdiodev, SDIO_ACTIVE_ST);
+#endif
+
+ // config
+ if (sdiodev->tx_priv->cmd_txstate) {
+ if (down_interruptible(&sdiodev->tx_priv->txctl_sema)) {
+ dev_err(sdiodev->dev, "txctl down bus->txctl_sema fail\n");
+ return;
+ }
+ if (sdiodev->state != SDIO_ACTIVE_ST) {
+ dev_err(sdiodev->dev, "state err\n");
+ up(&sdiodev->tx_priv->txctl_sema);
+ dev_err(sdiodev->dev, "txctl up bus->txctl_sema fail\n");
+ return;
+ }
+
+ if (aicwf_sdio_tx_msg(sdiodev))
+ dev_err(sdiodev->dev, "failed to send command\n");
+ up(&sdiodev->tx_priv->txctl_sema);
+ // Only wake up if someone is actually waiting
+ if (waitqueue_active(&sdiodev->tx_priv->cmd_txdone_wait))
+ wake_up(&sdiodev->tx_priv->cmd_txdone_wait);
+ }
+
+ // data
+ if (down_interruptible(&sdiodev->tx_priv->txctl_sema)) {
+ dev_err(sdiodev->dev, "txdata down bus->txctl_sema\n");
+ return;
+ }
+
+ if (sdiodev->state != SDIO_ACTIVE_ST) {
+ dev_err(sdiodev->dev, "sdio state err\n");
+ up(&sdiodev->tx_priv->txctl_sema);
+ return;
+ }
+
+ if (!aicwf_is_framequeue_empty(&sdiodev->tx_priv->txq))
+ sdiodev->tx_priv->fw_avail_bufcnt = aicwf_sdio_flow_ctrl(sdiodev);
+ while (!aicwf_is_framequeue_empty(&sdiodev->tx_priv->txq)) {
+ if (sdiodev->bus_if->state == BUS_DOWN_ST)
+ break;
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+ if (sdiodev->tp_ctrl.on_off)
+ aicwf_temp_ctrl(sdiodev);
+#endif
+ if (sdiodev->tx_priv->fw_avail_bufcnt <= DATA_FLOW_CTRL_THRESH) {
+ if (sdiodev->tx_priv->cmd_txstate)
+ break;
+ sdiodev->tx_priv->fw_avail_bufcnt = aicwf_sdio_flow_ctrl(sdiodev);
+ } else {
+ if (sdiodev->tx_priv->cmd_txstate) {
+ aicwf_sdio_send(sdiodev->tx_priv, 1);
+ break;
+ }
+ aicwf_sdio_send(sdiodev->tx_priv, 0);
+ }
+ }
+
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+ spin_lock_irqsave(&sdiodev->tx_flow_lock, flags);
+ if (atomic_read(&sdiodev->tx_priv->tx_pktcnt) < AICWF_SDIO_TX_LOW_WATER) {
+ if (sdiodev->flowctrl) {
+ sdiodev->flowctrl = 0;
+ aicwf_sdio_tx_netif_flowctrl(sdiodev->aicwf_hw, false);
+ }
+ }
+ spin_unlock_irqrestore(&sdiodev->tx_flow_lock, flags);
+#endif
+
+ up(&sdiodev->tx_priv->txctl_sema);
+}
+
+static int aicwf_sdio_bus_txdata(struct device *dev, struct sk_buff *pkt)
+{
+ uint prio;
+ int ret = -EBADE;
+ struct aicwf_txhdr *txhdr = NULL;
+ int headroom = 0;
+ struct aicwf_bus *bus_if = dev_get_drvdata(dev);
+ struct aic_sdio_dev *sdiodev = bus_if->sdiodev;
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+ unsigned long flags;
+#endif
+
+ if (bus_if->state == BUS_DOWN_ST) {
+ dev_err(dev, "bus_if stopped\n");
+ txhdr = (struct aicwf_txhdr *)pkt->data;
+ headroom = txhdr->sw_hdr->headroom;
+ kmem_cache_free(txhdr->sw_hdr->aicwf_vif->aicwf_hw->sw_txhdr_cache,
+ txhdr->sw_hdr);
+ skb_pull(pkt, headroom);
+ consume_skb(pkt);
+ return -1;
+ }
+
+ prio = (pkt->priority & 0x7);
+ spin_lock_bh(&sdiodev->tx_priv->txqlock);
+ if (!aicwf_frame_enq(sdiodev->dev, &sdiodev->tx_priv->txq, pkt, prio)) {
+ txhdr = (struct aicwf_txhdr *)pkt->data;
+ headroom = txhdr->sw_hdr->headroom;
+ kmem_cache_free(txhdr->sw_hdr->aicwf_vif->aicwf_hw->sw_txhdr_cache,
+ txhdr->sw_hdr);
+ skb_pull(pkt, headroom);
+ consume_skb(pkt);
+ spin_unlock_bh(&sdiodev->tx_priv->txqlock);
+ return -ENOSR;
+ goto flowctrl;
+ } else {
+ ret = 0;
+ }
+
+ atomic_inc(&sdiodev->tx_priv->tx_pktcnt);
+ spin_unlock_bh(&sdiodev->tx_priv->txqlock);
+ complete(&bus_if->bustx_trgg);
+
+flowctrl:
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+ spin_lock_irqsave(&sdiodev->tx_flow_lock, flags);
+ if (atomic_read(&sdiodev->tx_priv->tx_pktcnt) >= AICWF_SDIO_TX_HIGH_WATER) {
+ if (!sdiodev->flowctrl) {
+ sdiodev->flowctrl = 1;
+ aicwf_sdio_tx_netif_flowctrl(sdiodev->aicwf_hw, true);
+ }
+ }
+ spin_unlock_irqrestore(&sdiodev->tx_flow_lock, flags);
+#endif
+
+ return ret;
+}
+
+static int aicwf_sdio_bus_txmsg(struct device *dev, u8 *msg, uint msglen)
+{
+ struct aicwf_bus *bus_if = dev_get_drvdata(dev);
+ struct aic_sdio_dev *sdiodev = bus_if->sdiodev;
+
+ down(&sdiodev->tx_priv->cmd_txsema);
+ sdiodev->tx_priv->cmd_txstate = true;
+ sdiodev->tx_priv->cmd_tx_succ = false;
+ sdiodev->tx_priv->cmd_buf = msg;
+ sdiodev->tx_priv->cmd_len = msglen;
+ up(&sdiodev->tx_priv->cmd_txsema);
+
+ if (bus_if->state != BUS_UP_ST) {
+ dev_err(dev, "bus has stop\n");
+ return -1;
+ }
+
+ complete(&bus_if->bustx_trgg);
+ return 0;
+}
+
+int aicwf_sdio_send(struct aicwf_tx_priv *tx_priv, u8 txnow)
+{
+ struct sk_buff *pkt;
+ struct aic_sdio_dev *sdiodev = tx_priv->sdiodev;
+ u32 aggr_len = 0;
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+ unsigned long flags;
+#endif
+
+ aggr_len = (tx_priv->tail - tx_priv->head);
+ if (((atomic_read(&tx_priv->aggr_count) == 0) && aggr_len != 0) ||
+ ((atomic_read(&tx_priv->aggr_count) != 0) && aggr_len == 0)) {
+ if (aggr_len > 0)
+ aicwf_sdio_aggrbuf_reset(tx_priv);
+ return 0;
+ }
+
+ if (atomic_read(&tx_priv->aggr_count) ==
+ (tx_priv->fw_avail_bufcnt - DATA_FLOW_CTRL_THRESH)) {
+ if (atomic_read(&tx_priv->aggr_count) > 0) {
+ tx_priv->fw_avail_bufcnt -= atomic_read(&tx_priv->aggr_count);
+ aicwf_sdio_aggr_send(tx_priv); // send and check the next pkt;
+ }
+ return 0;
+ }
+ spin_lock_bh(&sdiodev->tx_priv->txqlock);
+ pkt = aicwf_frame_dequeue(&sdiodev->tx_priv->txq);
+ if (!pkt) {
+ dev_err(sdiodev->dev, "txq no pkt\n");
+ spin_unlock_bh(&sdiodev->tx_priv->txqlock);
+ return 0;
+ }
+ spin_unlock_bh(&sdiodev->tx_priv->txqlock);
+
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+ spin_lock_irqsave(&sdiodev->tx_flow_lock, flags);
+ if (atomic_read(&sdiodev->tx_priv->tx_pktcnt) < AICWF_SDIO_TX_LOW_WATER) {
+ if (sdiodev->flowctrl) {
+ sdiodev->flowctrl = 0;
+ aicwf_sdio_tx_netif_flowctrl(sdiodev->aicwf_hw, false);
+ }
+ }
+ spin_unlock_irqrestore(&sdiodev->tx_flow_lock, flags);
+#endif
+
+ if (!tx_priv || !tx_priv->tail || !pkt)
+ dev_err(sdiodev->dev, "null error\n");
+ if (aicwf_sdio_aggr(tx_priv, pkt)) {
+ aicwf_sdio_aggrbuf_reset(tx_priv);
+ dev_err(sdiodev->dev, "add aggr pkts failed\n");
+ atomic_dec(&sdiodev->tx_priv->tx_pktcnt);
+ return 0;
+ }
+
+ //when aggr finish or there is cmd to send, just send this aggr pkt to fw
+ if ((int)atomic_read(&sdiodev->tx_priv->tx_pktcnt) == 1 ||
+ txnow || (atomic_read(&tx_priv->aggr_count) ==
+ (tx_priv->fw_avail_bufcnt - DATA_FLOW_CTRL_THRESH))) {
+ tx_priv->fw_avail_bufcnt -= atomic_read(&tx_priv->aggr_count);
+ aicwf_sdio_aggr_send(tx_priv);
+ atomic_dec(&sdiodev->tx_priv->tx_pktcnt);
+ return 0;
+ }
+ atomic_dec(&sdiodev->tx_priv->tx_pktcnt);
+ return 0;
+}
+
+int aicwf_sdio_aggr(struct aicwf_tx_priv *tx_priv, struct sk_buff *pkt)
+{
+ struct aicwf_txhdr *txhdr = (struct aicwf_txhdr *)pkt->data;
+ u8 *start_ptr = tx_priv->tail;
+ u8 sdio_header[4];
+ u8 adjust_str[4] = {0, 0, 0, 0};
+ u32 curr_len = 0;
+ int allign_len = 0;
+ int headroom;
+
+ sdio_header[0] =
+ ((pkt->len - txhdr->sw_hdr->headroom + sizeof(struct txdesc_api)) &
+ 0xff);
+ sdio_header[1] =
+ (((pkt->len - txhdr->sw_hdr->headroom + sizeof(struct txdesc_api)) >>
+ 8) &
+ 0x0f);
+ sdio_header[2] = 0x01; // data
+ if (!tx_priv->sdiodev->chip_hw->use_hdr_checksum)
+ sdio_header[3] = 0; // reserved
+ else if (tx_priv->sdiodev->chip_hw->use_hdr_checksum)
+ sdio_header[3] = crc8_ponl_107(&sdio_header[0], 3); // crc8
+
+ memcpy(tx_priv->tail, (u8 *)&sdio_header, sizeof(sdio_header));
+ tx_priv->tail += sizeof(sdio_header);
+ // payload
+ memcpy(tx_priv->tail, (u8 *)(long)&txhdr->sw_hdr->desc,
+ sizeof(struct txdesc_api));
+ tx_priv->tail += sizeof(struct txdesc_api); // hostdesc
+ memcpy(tx_priv->tail, (u8 *)((u8 *)txhdr + txhdr->sw_hdr->headroom),
+ pkt->len - txhdr->sw_hdr->headroom);
+ tx_priv->tail += (pkt->len - txhdr->sw_hdr->headroom);
+
+ // word alignment
+ curr_len = tx_priv->tail - tx_priv->head;
+ if (curr_len & (TX_ALIGNMENT - 1)) {
+ allign_len = roundup(curr_len, TX_ALIGNMENT) - curr_len;
+ memcpy(tx_priv->tail, adjust_str, allign_len);
+ tx_priv->tail += allign_len;
+ }
+
+ if (tx_priv->sdiodev->chip_hw->need_fix_hdr_len) {
+ start_ptr[0] = ((tx_priv->tail - start_ptr - 4) & 0xff);
+ start_ptr[1] = (((tx_priv->tail - start_ptr - 4) >> 8) & 0x0f);
+ }
+ tx_priv->aggr_buf->dev = pkt->dev;
+
+ if (!txhdr->sw_hdr->need_cfm) {
+ headroom = txhdr->sw_hdr->headroom;
+ kmem_cache_free(txhdr->sw_hdr->aicwf_vif->aicwf_hw->sw_txhdr_cache,
+ txhdr->sw_hdr);
+ skb_pull(pkt, headroom);
+ consume_skb(pkt);
+ }
+
+ atomic_inc(&tx_priv->aggr_count);
+ return 0;
+}
+
+void aicwf_sdio_aggr_send(struct aicwf_tx_priv *tx_priv)
+{
+ struct sk_buff *tx_buf = tx_priv->aggr_buf;
+ int ret = 0;
+ int curr_len = 0;
+
+ // link tail is necessary
+ curr_len = tx_priv->tail - tx_priv->head;
+ if ((curr_len % TXPKT_BLOCKSIZE) != 0) {
+ memset(tx_priv->tail, 0, TAIL_LEN);
+ tx_priv->tail += TAIL_LEN;
+ }
+
+ tx_buf->len = tx_priv->tail - tx_priv->head;
+ ret = aicwf_sdio_txpkt(tx_priv->sdiodev, tx_buf);
+ if (ret < 0)
+ dev_err(tx_priv->sdiodev->dev, "fail to send aggr pkt\n");
+
+ aicwf_sdio_aggrbuf_reset(tx_priv);
+}
+
+void aicwf_sdio_aggrbuf_reset(struct aicwf_tx_priv *tx_priv)
+{
+ struct sk_buff *aggr_buf = tx_priv->aggr_buf;
+
+ tx_priv->tail = tx_priv->head;
+ aggr_buf->len = 0;
+ atomic_set(&tx_priv->aggr_count, 0);
+}
+
+static int aicwf_sdio_bus_start(struct device *dev)
+{
+ struct aicwf_bus *bus_if = dev_get_drvdata(dev);
+ struct aic_sdio_dev *sdiodev = bus_if->sdiodev;
+ int ret = 0;
+
+ if (!sdiodev->func) {
+ dev_warn(sdiodev->dev, "null sdio func\n");
+ return 0;
+ }
+
+ sdio_claim_host(sdiodev->func);
+ ret = sdio_claim_irq(sdiodev->func, aicwf_sdio_hal_irqhandler);
+ if (ret) {
+ sdio_release_host(sdiodev->func);
+ dev_err(dev, "claim irq fail %d\n", ret);
+ return ret;
+ }
+ sdiodev->irq_claimed = true;
+ if (sdiodev->chip_hw->need_func0_intr) {
+ sdio_f0_writeb(sdiodev->func, 0x07, 0x04, &ret);
+ if (ret)
+ dev_err(dev, "set func0 int en fail %d\n", ret);
+ }
+ sdio_release_host(sdiodev->func);
+
+ // enable sdio interrupt
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.intr_config_reg, 0x07);
+ if (ret != 0) {
+ dev_err(dev, "intr register failed:%d\n", ret);
+ return ret;
+ }
+
+ bus_if->state = BUS_UP_ST;
+
+ return ret;
+}
+
+#ifdef CONFIG_AIC8800_TXRX_THREAD_PRIO
+
+#include "uapi/linux/sched/types.h"
+#endif
+
+#ifdef CONFIG_OOB
+#define AICWF_SDIO_RX_THREAD_WAIT_MS 1000
+
+// new oob feature
+int sdio_busirq_thread(void *data)
+{
+ struct aicwf_rx_priv *rx_priv = (struct aicwf_rx_priv *)data;
+ struct aicwf_bus *bus_if = rx_priv->sdiodev->bus_if;
+
+#ifdef CONFIG_AIC8800_TXRX_THREAD_PRIO
+ sched_set_fifo_low(current);
+#endif
+
+ pr_debug("the policy of current thread is:%d\n",
+ current->policy);
+ pr_debug("the rt_priority of current thread is:%d\n",
+ current->rt_priority);
+ pr_debug("the current pid is:%d\n", current->pid);
+
+ while (1) {
+ if (kthread_should_stop()) {
+ dev_err(bus_if->dev, "sdio busirq thread stop\n");
+ break;
+ }
+
+ if (!wait_for_completion_timeout(&bus_if->busirq_trgg,
+ msecs_to_jiffies(AICWF_SDIO_RX_THREAD_WAIT_MS))) {
+ pr_debug("wait for completion timeout\n");
+ }
+
+ if (bus_if->state == BUS_DOWN_ST)
+ continue;
+
+#ifdef CONFIG_AIC8800_SDIO_PWRCTRL
+ while (atomic_read(&bus_if->sdiodev->is_bus_suspend) == 1 &&
+ !kthread_should_stop() &&
+ READ_ONCE(bus_if->state) != BUS_DOWN_ST)
+ msleep(100);
+ if (kthread_should_stop() ||
+ READ_ONCE(bus_if->state) == BUS_DOWN_ST)
+ continue;
+ aicwf_sdio_pwr_stctl(bus_if->sdiodev, SDIO_ACTIVE_ST);
+#endif // CONFIG_AIC8800_SDIO_PWRCTRL
+ aicwf_sdio_hal_irqhandler(bus_if->sdiodev->func);
+ }
+
+ return 0;
+}
+
+#endif // CONFIG_OOB
+
+int sdio_bustx_thread(void *data)
+{
+ struct aicwf_bus *bus = (struct aicwf_bus *)data;
+ struct aic_sdio_dev *sdiodev = bus->sdiodev;
+
+#ifdef CONFIG_AIC8800_TXRX_THREAD_PRIO
+ sched_set_fifo_low(current);
+#endif
+
+ pr_debug("the policy of current thread is:%d\n",
+ current->policy);
+ pr_debug("the rt_priority of current thread is:%d\n",
+ current->rt_priority);
+ pr_debug("the current pid is:%d\n", current->pid);
+
+ while (1) {
+ if (kthread_should_stop()) {
+ dev_err(sdiodev->dev, "sdio bustx thread stop\n");
+ break;
+ }
+
+ if (!wait_for_completion_interruptible(&bus->bustx_trgg)) {
+ if (sdiodev->bus_if->state == BUS_DOWN_ST)
+ continue;
+
+ if (!aicwf_sdio_activity_get(sdiodev->aicwf_hw,
+ sdiodev->aicwf_hw->ws_tx))
+ continue;
+ if ((int)(atomic_read(&sdiodev->tx_priv->tx_pktcnt) > 0) ||
+ sdiodev->tx_priv->cmd_txstate)
+ aicwf_sdio_tx_process(sdiodev);
+ aicwf_sdio_activity_put(sdiodev->aicwf_hw,
+ sdiodev->aicwf_hw->ws_tx);
+ }
+ }
+
+ return 0;
+}
+
+int sdio_busrx_thread(void *data)
+{
+ struct aicwf_rx_priv *rx_priv = (struct aicwf_rx_priv *)data;
+ struct aicwf_bus *bus_if = rx_priv->sdiodev->bus_if;
+
+#ifdef CONFIG_AIC8800_TXRX_THREAD_PRIO
+ sched_set_fifo_low(current);
+#endif
+
+ pr_debug("the policy of current thread is:%d\n",
+ current->policy);
+ pr_debug("the rt_priority of current thread is:%d\n",
+ current->rt_priority);
+ pr_debug("the current pid is:%d\n", current->pid);
+
+ while (1) {
+ if (kthread_should_stop()) {
+ dev_err(bus_if->dev, "sdio busrx thread stop\n");
+ break;
+ }
+ if (!wait_for_completion_interruptible(&bus_if->busrx_trgg)) {
+ if (bus_if->state == BUS_DOWN_ST)
+ continue;
+ if (!aicwf_sdio_activity_get(rx_priv->sdiodev->aicwf_hw,
+ rx_priv->sdiodev->aicwf_hw->ws_rx))
+ continue;
+ aicwf_process_rxframes(rx_priv);
+ aicwf_sdio_activity_put(rx_priv->sdiodev->aicwf_hw,
+ rx_priv->sdiodev->aicwf_hw->ws_rx);
+ }
+ }
+ return 0;
+}
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+static int aicwf_sdio_pwrctl_thread(void *data)
+{
+ struct aic_sdio_dev *sdiodev = (struct aic_sdio_dev *)data;
+
+ while (1) {
+ if (kthread_should_stop()) {
+ pr_debug("sdio pwrctl thread stop\n");
+ break;
+ }
+ if (!wait_for_completion_interruptible(&sdiodev->pwrctrl_trgg)) {
+ if (sdiodev->bus_if->state == BUS_DOWN_ST)
+ continue;
+
+ if (!aicwf_sdio_activity_get(sdiodev->aicwf_hw,
+ sdiodev->aicwf_hw->ws_pwrctrl))
+ continue;
+
+ if ((int)(atomic_read(&sdiodev->tx_priv->tx_pktcnt) <= 0) &&
+ !sdiodev->tx_priv->cmd_txstate &&
+ atomic_read(&sdiodev->rx_priv->rx_cnt) == 0)
+ aicwf_sdio_pwr_stctl(sdiodev, SDIO_SLEEP_ST);
+ else
+ aicwf_sdio_pwrctl_timer(sdiodev, sdiodev->active_duration);
+
+ aicwf_sdio_activity_put(sdiodev->aicwf_hw,
+ sdiodev->aicwf_hw->ws_pwrctrl);
+ }
+ }
+
+ return 0;
+}
+
+static void aicwf_sdio_bus_pwrctl(struct timer_list *t)
+{
+ struct aic_sdio_dev *sdiodev = timer_container_of(sdiodev, t, timer);
+
+ if (sdiodev->bus_if->state == BUS_DOWN_ST) {
+ dev_err(sdiodev->dev, "bus down\n");
+ return;
+ }
+
+ if (sdiodev->pwrctl_tsk)
+ complete(&sdiodev->pwrctrl_trgg);
+}
+#endif
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+static void aicwf_sdio_enq_rxpkt(struct aic_sdio_dev *sdiodev,
+ struct rx_buff *pkt)
+#else
+static void aicwf_sdio_enq_rxpkt(struct aic_sdio_dev *sdiodev,
+ struct sk_buff *pkt)
+#endif
+{
+ struct aicwf_rx_priv *rx_priv = sdiodev->rx_priv;
+ unsigned long flags = 0;
+
+ spin_lock_irqsave(&rx_priv->rxqlock, flags);
+#ifdef CONFIG_PREALLOC_RX_SKB
+ if (!aicwf_rxbuff_enqueue(sdiodev->dev, &rx_priv->rxq, pkt)) {
+ spin_unlock_irqrestore(&rx_priv->rxqlock, flags);
+ dev_err(sdiodev->dev, "%d, enqueue rxq fail\n", __LINE__);
+ aicwf_prealloc_rxbuff_free(pkt, &rx_priv->rxbuff_lock);
+ return;
+ }
+#else
+ if (!aicwf_rxframe_enqueue(sdiodev->dev, &rx_priv->rxq, pkt)) {
+ spin_unlock_irqrestore(&rx_priv->rxqlock, flags);
+ aicwf_dev_skb_free(pkt);
+ return;
+ }
+#endif
+ spin_unlock_irqrestore(&rx_priv->rxqlock, flags);
+
+ atomic_inc(&rx_priv->rx_cnt);
+}
+
+#define SDIO_OTHER_INTERRUPT (0x1ul << 7)
+
+void aicwf_sdio_hal_irqhandler(struct sdio_func *func)
+{
+ struct aicwf_bus *bus_if = NULL;
+ struct aic_sdio_dev *sdiodev = NULL;
+ u8 intstatus = 0;
+ u8 byte_len = 0;
+#ifdef CONFIG_PREALLOC_RX_SKB
+ struct rx_buff *pkt = NULL;
+#else
+ struct sk_buff *pkt = NULL;
+#endif
+ int ret;
+ unsigned int retries;
+
+ if (!func) {
+ pr_err("func is null\n");
+ return;
+ }
+
+ bus_if = dev_get_drvdata(&func->dev);
+ if (!bus_if || READ_ONCE(bus_if->state) != BUS_UP_ST)
+ return;
+ sdiodev = bus_if->sdiodev;
+ if (!sdiodev || !sdiodev->aicwf_hw)
+ return;
+ if (!aicwf_sdio_activity_get(sdiodev->aicwf_hw,
+ sdiodev->aicwf_hw->ws_irqrx))
+ return;
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+ if (list_empty(&aic_rx_buff_list.rxbuff_list)) {
+ dev_warn(sdiodev->dev, "%d, rxbuff list is empty\n", __LINE__);
+ aicwf_sdio_activity_put(sdiodev->aicwf_hw,
+ sdiodev->aicwf_hw->ws_irqrx);
+ return;
+ }
+#endif
+
+ if (sdiodev->chip_hw->use_func2) {
+ for (retries = 0; retries < 16; retries++) {
+ ret = aicwf_sdio_readb(sdiodev, sdiodev->sdio_reg.block_cnt_reg,
+ &intstatus);
+ if (!ret && !(intstatus & SDIO_OTHER_INTERRUPT))
+ break;
+ }
+ if (ret || (intstatus & SDIO_OTHER_INTERRUPT)) {
+ dev_err_ratelimited(&func->dev, "IRQ status unavailable: %d/%#x\n",
+ ret, intstatus);
+ goto out_activity;
+ }
+ sdiodev->rx_priv->data_len = intstatus * SDIOWIFI_FUNC_BLOCKSIZE;
+
+ if (intstatus > 0) {
+ if (intstatus < 64) {
+ pkt = aicwf_sdio_readframes(sdiodev);
+ } else {
+ // byte_len must<= 128
+ aicwf_sdio_intr_get_len_bytemode(sdiodev, &byte_len);
+ dev_dbg(&func->dev, "byte mode len=%d\n", byte_len);
+ pkt = aicwf_sdio_readframes(sdiodev);
+ }
+ }
+
+ if (pkt)
+ aicwf_sdio_enq_rxpkt(sdiodev, pkt);
+
+ if (atomic_read(&sdiodev->rx_priv->rx_cnt) == 1)
+ complete(&bus_if->busrx_trgg);
+
+ } else {
+ for (retries = 0; retries < 16; retries++) {
+ ret = aicwf_sdio_readb(sdiodev,
+ sdiodev->sdio_reg.misc_int_status_reg,
+ &intstatus);
+ if (!ret)
+ break;
+ }
+ if (ret) {
+ dev_err_ratelimited(&func->dev, "IRQ status read failed: %d\n", ret);
+ goto out_activity;
+ }
+ if (intstatus & SDIO_OTHER_INTERRUPT) {
+ u8 int_pending;
+
+ ret = aicwf_sdio_readb(sdiodev, sdiodev->sdio_reg.sleep_reg,
+ &int_pending);
+ if (ret < 0)
+ goto out_activity;
+ int_pending &= ~0x01; // dev to host soft irq
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.sleep_reg,
+ int_pending);
+ if (ret < 0)
+ dev_err(&func->dev, "reg:%d write failed\n",
+ sdiodev->sdio_reg.sleep_reg);
+ }
+
+ if (intstatus > 0) {
+ u8 intmaskf2 = intstatus | (0x1UL << 3);
+
+ if (intmaskf2 > 120U) { // func2
+ if (intmaskf2 == 127U) { // byte mode
+ // byte_len must<= 128
+ aicwf_sdio_intr_get_len_bytemode(sdiodev,
+ &byte_len);
+ dev_dbg(&func->dev, "byte mode len=%d\n", byte_len);
+ pkt = aicwf_sdio_readframes(sdiodev);
+ } else { // block mode
+ sdiodev->rx_priv->data_len =
+ (intstatus & 0x7U) * SDIOWIFI_FUNC_BLOCKSIZE;
+ pkt = aicwf_sdio_readframes(sdiodev);
+ }
+ } else { // func1
+ if (intstatus == 120U) { // byte mode
+ // byte_len must<= 128
+ aicwf_sdio_intr_get_len_bytemode(sdiodev, &byte_len);
+ dev_dbg(&func->dev, "byte mode len=%d\n", byte_len);
+ pkt = aicwf_sdio_readframes(sdiodev);
+ } else { // block mode
+ sdiodev->rx_priv->data_len =
+ (intstatus & 0x7FU) * SDIOWIFI_FUNC_BLOCKSIZE;
+ pkt = aicwf_sdio_readframes(sdiodev);
+ }
+ }
+ }
+
+ if (pkt)
+ aicwf_sdio_enq_rxpkt(sdiodev, pkt);
+
+ if (atomic_read(&sdiodev->rx_priv->rx_cnt) == 1)
+ complete(&bus_if->busrx_trgg);
+ }
+
+out_activity:
+ aicwf_sdio_activity_put(sdiodev->aicwf_hw,
+ sdiodev->aicwf_hw->ws_irqrx);
+}
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+void aicwf_sdio_pwrctl_timer(struct aic_sdio_dev *sdiodev, uint duration)
+{
+ uint timeout;
+
+ if (!IS_ENABLED(CONFIG_AIC8800_SDIO_PWRCTRL))
+ return;
+
+ if (sdiodev->bus_if->state == BUS_DOWN_ST && duration)
+ return;
+
+ spin_lock_bh(&sdiodev->pwrctl_lock);
+ if (!duration) {
+ if (timer_pending(&sdiodev->timer))
+ timer_delete_sync(&sdiodev->timer);
+ } else {
+ sdiodev->active_duration = duration;
+ timeout = msecs_to_jiffies(sdiodev->active_duration);
+ mod_timer(&sdiodev->timer, jiffies + timeout);
+ }
+ spin_unlock_bh(&sdiodev->pwrctl_lock);
+}
+#endif
+
+static const struct aicwf_bus_ops aicwf_sdio_bus_ops = {
+ .start = aicwf_sdio_bus_start,
+ .stop = aicwf_sdio_bus_stop,
+ .txdata = aicwf_sdio_bus_txdata,
+ .txmsg = aicwf_sdio_bus_txmsg,
+};
+
+/* Called with hardware state alive, after interfaces have been closed. */
+void aicwf_sdio_quiesce(struct aic_sdio_dev *sdiodev)
+{
+ struct aicwf_bus *bus_if = sdiodev->bus_if;
+ int ret;
+
+ if (sdiodev->quiesced)
+ return;
+ WRITE_ONCE(sdiodev->quiesced, true);
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ if (sdiodev->aicwf_hw && bus_if->state == BUS_UP_ST)
+ aicwf_sdio_pwr_stctl(sdiodev, SDIO_SLEEP_ST);
+#endif
+ aicwf_cmd_mgr_stop(&sdiodev->cmd_mgr);
+ WRITE_ONCE(bus_if->state, BUS_DOWN_ST);
+
+ if (sdiodev->irq_claimed) {
+ sdio_claim_host(sdiodev->func);
+ ret = aicwf_sdio_writeb(sdiodev,
+ sdiodev->sdio_reg.intr_config_reg, 0);
+ if (ret)
+ dev_err(sdiodev->dev, "failed to disable SDIO interrupt: %d\n",
+ ret);
+ sdio_release_irq(sdiodev->func);
+ sdio_release_host(sdiodev->func);
+ sdiodev->irq_claimed = false;
+ }
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ timer_shutdown_sync(&sdiodev->timer);
+ if (sdiodev->pwrctl_tsk) {
+ complete_all(&sdiodev->pwrctrl_trgg);
+ kthread_stop(sdiodev->pwrctl_tsk);
+ sdiodev->pwrctl_tsk = NULL;
+ }
+#endif
+
+ /* No MMC host claim may be held while waiting for the bus threads. */
+ if (bus_if->bustx_thread) {
+ sched_set_normal(bus_if->bustx_thread, 0);
+ complete_all(&bus_if->bustx_trgg);
+ kthread_stop(bus_if->bustx_thread);
+ bus_if->bustx_thread = NULL;
+ }
+ if (sdiodev->rx_priv) {
+ aicwf_rx_deinit(sdiodev->rx_priv);
+ sdiodev->rx_priv = NULL;
+ }
+ aicwf_bus_stop(bus_if);
+}
+
+void aicwf_sdio_release(struct aic_sdio_dev *sdiodev)
+{
+ if (sdiodev->aicwf_hw && sdiodev->aicwf_hw->plat->enabled)
+ aicwf_platform_deinit(sdiodev->aicwf_hw);
+
+ aicwf_sdio_quiesce(sdiodev);
+ aicwf_cmd_mgr_deinit(&sdiodev->cmd_mgr);
+ aicwf_bus_deinit(sdiodev->dev);
+ aicwf_tx_deinit(sdiodev->tx_priv);
+ sdiodev->tx_priv = NULL;
+}
+
+void aicwf_sdio_reg_init(struct aic_sdio_dev *sdiodev)
+{
+ if (sdiodev->chip_hw->use_func2) {
+ sdiodev->sdio_reg.bytemode_len_reg = SDIOWIFI_BYTEMODE_LEN_REG;
+ sdiodev->sdio_reg.intr_config_reg = SDIOWIFI_INTR_CONFIG_REG;
+ sdiodev->sdio_reg.sleep_reg = SDIOWIFI_SLEEP_REG;
+ sdiodev->sdio_reg.wakeup_reg = SDIOWIFI_WAKEUP_REG;
+ sdiodev->sdio_reg.flow_ctrl_reg = SDIOWIFI_FLOW_CTRL_REG;
+ sdiodev->sdio_reg.register_block = SDIOWIFI_REGISTER_BLOCK;
+ sdiodev->sdio_reg.bytemode_enable_reg = SDIOWIFI_BYTEMODE_ENABLE_REG;
+ sdiodev->sdio_reg.block_cnt_reg = SDIOWIFI_BLOCK_CNT_REG;
+ sdiodev->sdio_reg.rd_fifo_addr = SDIOWIFI_RD_FIFO_ADDR;
+ sdiodev->sdio_reg.wr_fifo_addr = SDIOWIFI_WR_FIFO_ADDR;
+ } else {
+ sdiodev->sdio_reg.bytemode_len_reg = SDIOWIFI_BYTEMODE_LEN_REG_V3;
+ sdiodev->sdio_reg.intr_config_reg = SDIOWIFI_INTR_ENABLE_REG_V3;
+ sdiodev->sdio_reg.sleep_reg = SDIOWIFI_INTR_PENDING_REG_V3;
+ sdiodev->sdio_reg.wakeup_reg = SDIOWIFI_INTR_TO_DEVICE_REG_V3;
+ sdiodev->sdio_reg.flow_ctrl_reg = SDIOWIFI_FLOW_CTRL_Q1_REG_V3;
+ sdiodev->sdio_reg.bytemode_enable_reg = SDIOWIFI_BYTEMODE_ENABLE_REG_V3;
+ sdiodev->sdio_reg.misc_int_status_reg = SDIOWIFI_MISC_INT_STATUS_REG_V3;
+ sdiodev->sdio_reg.rd_fifo_addr = SDIOWIFI_RD_FIFO_ADDR_V3;
+ sdiodev->sdio_reg.wr_fifo_addr = SDIOWIFI_WR_FIFO_ADDR_V3;
+ }
+}
+
+int aicwf_sdio_func_init(struct aic_sdio_dev *sdiodev)
+{
+ struct mmc_host *host;
+ u8 block_bit0 = 0x1;
+ u8 byte_mode_disable = 0x1; // 1: no byte mode
+ int ret = 0;
+
+ aicwf_sdio_reg_init(sdiodev);
+ if (!sdiodev->func) {
+ dev_warn(sdiodev->dev, "null sdio func\n");
+ return 0;
+ }
+
+ host = sdiodev->func->card->host;
+
+ sdio_claim_host(sdiodev->func);
+ ret = sdio_set_block_size(sdiodev->func, SDIOWIFI_FUNC_BLOCKSIZE);
+ if (ret < 0) {
+ dev_err(sdiodev->dev, "set blocksize fail %d\n", ret);
+ sdio_release_host(sdiodev->func);
+ return ret;
+ }
+ ret = sdio_enable_func(sdiodev->func);
+ if (ret < 0) {
+ sdio_release_host(sdiodev->func);
+ dev_err(sdiodev->dev, "enable func fail %d\n", ret);
+ return ret;
+ }
+
+ if (sdiodev->chip_hw->sdio_clock > 0) {
+ host->ios.clock = sdiodev->chip_hw->sdio_clock;
+ host->ops->set_ios(host, &host->ios);
+ dev_dbg(sdiodev->dev, "set SDIO Clock %d MHz\n", host->ios.clock / 1000000);
+ }
+
+ sdio_release_host(sdiodev->func);
+
+ if (sdiodev->chip_hw->use_func2) {
+ sdio_claim_host(sdiodev->func2);
+ //set sdio blocksize
+ ret = sdio_set_block_size(sdiodev->func2, SDIOWIFI_FUNC_BLOCKSIZE);
+ if (ret < 0) {
+ dev_err(sdiodev->dev, "set func2 blocksize fail %d\n", ret);
+ sdio_release_host(sdiodev->func2);
+ return ret;
+ }
+
+ //set sdio enable func
+ ret = sdio_enable_func(sdiodev->func2);
+ if (ret < 0) {
+ sdio_release_host(sdiodev->func2);
+ dev_err(sdiodev->dev, "enable func2 fail %d\n", ret);
+ return ret;
+ }
+
+ sdio_release_host(sdiodev->func2);
+
+ ret = aicwf_sdio_func2_writeb(sdiodev,
+ sdiodev->sdio_reg.register_block, block_bit0);
+ if (ret < 0) {
+ dev_err(sdiodev->dev, "reg:%d write failed\n",
+ sdiodev->sdio_reg.register_block);
+ return ret;
+ }
+
+ //1: no byte mode
+ ret = aicwf_sdio_func2_writeb(sdiodev, sdiodev->sdio_reg.bytemode_enable_reg,
+ byte_mode_disable);
+ if (ret < 0) {
+ dev_err(sdiodev->dev, "reg:%d write failed\n",
+ sdiodev->sdio_reg.bytemode_enable_reg);
+ return ret;
+ }
+ }
+
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.register_block, block_bit0);
+ if (ret < 0) {
+ dev_err(sdiodev->dev, "reg:%d write failed\n", sdiodev->sdio_reg.register_block);
+ return ret;
+ }
+
+ //1: no byte mode
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.bytemode_enable_reg, byte_mode_disable);
+ if (ret < 0) {
+ dev_err(sdiodev->dev, "reg:%d write failed\n", sdiodev->sdio_reg.bytemode_enable_reg);
+ return ret;
+ }
+
+ mdelay(10);
+ return ret;
+}
+
+int aicwf_sdiov3_func_init(struct aic_sdio_dev *sdiodev)
+{
+ struct mmc_host *host;
+ u8 byte_mode_disable = 0x1; // 1: no byte mode
+ int ret = 0;
+ u8 val1 = 0;
+ int val;
+
+ aicwf_sdio_reg_init(sdiodev);
+
+ if (!sdiodev->func) {
+ dev_warn(sdiodev->dev, "null sdio func\n");
+ return 0;
+ }
+
+ host = sdiodev->func->card->host;
+
+ sdio_claim_host(sdiodev->func);
+ sdiodev->func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
+
+ ret = sdio_set_block_size(sdiodev->func, SDIOWIFI_FUNC_BLOCKSIZE);
+ if (ret < 0) {
+ dev_err(sdiodev->dev, "set blocksize fail %d\n", ret);
+ sdio_release_host(sdiodev->func);
+ return ret;
+ }
+ ret = sdio_enable_func(sdiodev->func);
+ if (ret < 0) {
+ sdio_release_host(sdiodev->func);
+ dev_err(sdiodev->dev, "enable func fail %d\n", ret);
+ return ret;
+ }
+
+ sdio_f0_writeb(sdiodev->func, 0x7F, 0xF2, &ret);
+ if (ret) {
+ dev_err(sdiodev->dev, "set fn0 0xF2 fail %d\n", ret);
+ sdio_release_host(sdiodev->func);
+ return ret;
+ }
+ if (host->ios.timing == MMC_TIMING_UHS_DDR50)
+ val = 0x20;
+ else
+ val = 0x00;
+ val |= SDIOCLK_FREE_RUNNING_BIT;
+ sdio_f0_writeb(sdiodev->func, val, 0xF0, &ret);
+ if (ret) {
+ dev_err(sdiodev->dev, "set iopad ctrl fail %d\n", ret);
+ sdio_release_host(sdiodev->func);
+ return ret;
+ }
+ sdio_f0_writeb(sdiodev->func, 0x0, 0xF8, &ret);
+ if (ret) {
+ dev_err(sdiodev->dev, "set iopad delay2 fail %d\n", ret);
+ sdio_release_host(sdiodev->func);
+ return ret;
+ }
+ sdio_f0_writeb(sdiodev->func, 0x00, 0xF1, &ret);
+ if (ret) {
+ dev_err(sdiodev->dev, "set iopad delay1 fail %d\n", ret);
+ sdio_release_host(sdiodev->func);
+ return ret;
+ }
+ usleep_range(1000, 1500);
+ sdio_release_host(sdiodev->func);
+
+ // 1: no byte mode
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.bytemode_enable_reg,
+ byte_mode_disable);
+ if (ret < 0) {
+ dev_err(sdiodev->dev, "reg:%d write failed\n",
+ sdiodev->sdio_reg.bytemode_enable_reg);
+ return ret;
+ }
+
+ ret = aicwf_sdio_writeb(sdiodev, sdiodev->sdio_reg.wakeup_reg, 0x11);
+ if (ret < 0) {
+ dev_err(sdiodev->dev, "reg:%d write failed\n",
+ sdiodev->sdio_reg.wakeup_reg);
+ return ret;
+ }
+
+ mdelay(5);
+ ret = aicwf_sdio_readb(sdiodev, sdiodev->sdio_reg.sleep_reg, &val1);
+ if (ret < 0) {
+ dev_err(sdiodev->dev, "reg:%d read failed\n",
+ sdiodev->sdio_reg.sleep_reg);
+ return ret;
+ }
+
+ if (!(val1 & 0x10))
+ dev_err(sdiodev->dev, "wakeup fail\n");
+ else
+ dev_dbg(sdiodev->dev, "sdio ready\n");
+
+ return ret;
+}
+
+/**
+ * aicwf_sdio_fw_started() - Hand the SDIO function over to the firmware
+ * @sdiodev: SDIO device whose firmware has just been started
+ *
+ * Redo the SDIO function setup against the running firmware and switch the
+ * power control from the bootrom handshake to the firmware one. The next
+ * transfer wakes the firmware up again.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int aicwf_sdio_fw_started(struct aic_sdio_dev *sdiodev)
+{
+ int ret;
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ down(&sdiodev->pwrctl_wakeup_sema);
+#endif
+ if (sdiodev->chip_hw->use_sdiov3_func)
+ ret = aicwf_sdiov3_func_init(sdiodev);
+ else
+ ret = aicwf_sdio_func_init(sdiodev);
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ sdiodev->fw_running = true;
+ sdiodev->state = SDIO_SLEEP_ST;
+ up(&sdiodev->pwrctl_wakeup_sema);
+#endif
+
+ return ret;
+}
+
+void aicwf_sdio_func_deinit(struct aic_sdio_dev *sdiodev)
+{
+ if (!sdiodev->func) {
+ dev_warn(sdiodev->dev, "null sdio func\n");
+ return;
+ }
+
+ sdio_claim_host(sdiodev->func);
+ sdio_disable_func(sdiodev->func);
+ sdio_release_host(sdiodev->func);
+
+ if (sdiodev->chip_hw->use_func2) {
+ sdio_claim_host(sdiodev->func2);
+ sdio_disable_func(sdiodev->func2);
+ sdio_release_host(sdiodev->func2);
+ }
+}
+
+void *aicwf_sdio_bus_init(struct aic_sdio_dev *sdiodev)
+{
+ int ret;
+ struct aicwf_bus *bus_if;
+ struct aicwf_rx_priv *rx_priv;
+ struct aicwf_tx_priv *tx_priv;
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ spin_lock_init(&sdiodev->pwrctl_lock);
+ sema_init(&sdiodev->pwrctl_wakeup_sema, 1);
+ timer_setup(&sdiodev->timer, aicwf_sdio_bus_pwrctl, 0);
+ init_completion(&sdiodev->pwrctrl_trgg);
+#endif
+
+ bus_if = sdiodev->bus_if;
+ bus_if->dev = sdiodev->dev;
+ bus_if->ops = &aicwf_sdio_bus_ops;
+ bus_if->state = BUS_DOWN_ST;
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ sdiodev->state = SDIO_SLEEP_ST;
+ sdiodev->active_duration = SDIOWIFI_PWR_CTRL_INTERVAL;
+#else
+ sdiodev->state = SDIO_ACTIVE_ST;
+#endif
+
+ rx_priv = aicwf_rx_init(sdiodev);
+ if (!rx_priv) {
+ dev_err(sdiodev->dev, "rx init fail\n");
+ goto fail;
+ }
+ sdiodev->rx_priv = rx_priv;
+
+ tx_priv = aicwf_tx_init(sdiodev);
+ if (!tx_priv) {
+ dev_err(sdiodev->dev, "tx init fail\n");
+ goto fail;
+ }
+ sdiodev->tx_priv = tx_priv;
+ aicwf_frame_queue_init(&tx_priv->txq, 8, TXQLEN);
+ spin_lock_init(&tx_priv->txqlock);
+ sema_init(&tx_priv->txctl_sema, 1);
+ sema_init(&tx_priv->cmd_txsema, 1);
+ init_waitqueue_head(&tx_priv->cmd_txdone_wait);
+ atomic_set(&tx_priv->tx_pktcnt, 0);
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ sdiodev->pwrctl_tsk =
+ kthread_run(aicwf_sdio_pwrctl_thread, sdiodev, "aicwf_pwrctl");
+ if (IS_ERR(sdiodev->pwrctl_tsk)) {
+ sdiodev->pwrctl_tsk = NULL;
+ goto fail;
+ }
+#endif
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+ sdiodev->flowctrl = 0;
+ spin_lock_init(&sdiodev->tx_flow_lock);
+#endif
+
+ spin_lock_init(&sdiodev->tx_tp_lock);
+ atomic_set(&sdiodev->suspending, 0);
+ atomic_set(&sdiodev->activity_count, 0);
+ init_waitqueue_head(&sdiodev->activity_waitq);
+ ret = aicwf_bus_init(0, sdiodev->dev);
+ if (ret < 0) {
+ dev_err(sdiodev->dev, "bus init fail\n");
+ goto fail;
+ }
+
+ return sdiodev;
+
+fail:
+ aicwf_sdio_release(sdiodev);
+ return NULL;
+}
+
+u8 crc8_ponl_107(u8 *p_buffer, uint16_t cal_size)
+{
+ u8 i;
+ u8 crc = 0;
+
+ if (cal_size == 0)
+ return crc;
+ while (cal_size--) {
+ for (i = 0x80; i > 0; i /= 2) {
+ if (crc & 0x80) {
+ crc *= 2;
+ crc ^= 0x07; // polynomial X8 + X2 + X + 1,(0x107)
+ } else {
+ crc *= 2;
+ }
+ if ((*p_buffer) & i)
+ crc ^= 0x07;
+ }
+ p_buffer++;
+ }
+
+ return crc;
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_sdio.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_sdio.h
new file mode 100644
index 000000000000..21881a2e6af5
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_sdio.h
@@ -0,0 +1,280 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_SDMMC_H_
+#define _AICWF_SDMMC_H_
+
+#include "aicwf_resv_mem.h"
+#include "aicwf_rx_prealloc.h"
+#include "aicwf_txq_prealloc.h"
+#include "aicwf_cmds.h"
+#include <linux/ieee80211.h>
+#include <linux/if_ether.h>
+#include <linux/semaphore.h>
+#include <linux/skbuff.h>
+#include <linux/mmc/card.h>
+#include <linux/mmc/host.h>
+#include <linux/mmc/sdio.h>
+#include <linux/mmc/sdio_func.h>
+#include <linux/mmc/sdio_ids.h>
+#include <linux/wait.h>
+
+#define AICWF_SDIO_NAME "aicwf_sdio"
+#define SDIOWIFI_FUNC_BLOCKSIZE 512
+
+#define SDIOWIFI_BYTEMODE_LEN_REG 0x02
+#define SDIOWIFI_INTR_CONFIG_REG 0x04
+#define SDIOWIFI_SLEEP_REG 0x05
+#define SDIOWIFI_WAKEUP_REG 0x09
+#define SDIOWIFI_FLOW_CTRL_REG 0x0A
+#define SDIOWIFI_REGISTER_BLOCK 0x0B
+#define SDIOWIFI_BYTEMODE_ENABLE_REG 0x11
+#define SDIOWIFI_BLOCK_CNT_REG 0x12
+#define SDIOWIFI_FLOWCTRL_MASK_REG 0x7F
+#define SDIOWIFI_WR_FIFO_ADDR 0x07
+#define SDIOWIFI_RD_FIFO_ADDR 0x08
+
+#define SDIOWIFI_INTR_ENABLE_REG_V3 0x00
+#define SDIOWIFI_INTR_PENDING_REG_V3 0x01
+#define SDIOWIFI_INTR_TO_DEVICE_REG_V3 0x02
+#define SDIOWIFI_FLOW_CTRL_Q1_REG_V3 0x03
+#define SDIOWIFI_MISC_INT_STATUS_REG_V3 0x04
+#define SDIOWIFI_BYTEMODE_LEN_REG_V3 0x05
+#define SDIOWIFI_BYTEMODE_LEN_MSB_REG_V3 0x06
+#define SDIOWIFI_BYTEMODE_ENABLE_REG_V3 0x07
+#define SDIOWIFI_MISC_CTRL_REG_V3 0x08
+#define SDIOWIFI_FLOW_CTRL_Q2_REG_V3 0x09
+#define SDIOWIFI_CLK_TEST_RESULT_REG_V3 0x0A
+#define SDIOWIFI_RD_FIFO_ADDR_V3 0x0F
+#define SDIOWIFI_WR_FIFO_ADDR_V3 0x10
+
+#define SDIOCLK_FREE_RUNNING_BIT BIT(6)
+
+#define SDIOWIFI_CLOCK 50000000 /* target SDIO clock rate */
+#define SDIOWIFI_CLOCK_V3 150000000 /* target SDIO clock rate, SDIO v3 chips */
+
+#define SDIOWIFI_PWR_CTRL_INTERVAL 30
+#define FLOW_CTRL_RETRY_COUNT 50
+#define BUFFER_SIZE 1536
+#define TAIL_LEN 4
+#define TXQLEN (2048 * 4)
+
+#define SDIO_SLEEP_ST 0
+#define SDIO_ACTIVE_ST 1
+
+#define DATA_FLOW_CTRL_THRESH 2
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+#define AICWF_SDIO_TX_LOW_WATER 100
+#define AICWF_SDIO_TX_HIGH_WATER 500
+#endif
+
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+#define TEMP_GET_INTERVAL (10 * 1000)
+#define TEMP_THD_1 92 // temperature 1 (celsius)
+#define TEMP_THD_2 103 // temperature 2 (celsius)
+#define BUFFERING_V1 8
+#define BUFFERING_V2 8
+#define TMR_INTERVAL_1 60 // timer_1 60ms
+#define TMR_INTERVAL_2 180 // timer_2 130ms
+#endif
+
+/* SDIO Device ID */
+#define SDIO_VENDOR_ID_AIC8801 0x5449
+#define SDIO_VENDOR_ID_AIC8800DC 0xc8a1
+#define SDIO_VENDOR_ID_AIC8800D80 0xc8a1
+#define SDIO_VENDOR_ID_AIC8800D80N 0xc8a1
+
+#define SDIO_DEVICE_ID_AIC8801 0x0145
+#define SDIO_DEVICE_ID_AIC8800DC 0xc08d
+#define SDIO_DEVICE_ID_AIC8800D80 0x0082
+#define SDIO_DEVICE_ID_AIC8800D80N 0x9081
+#define SDIO_DEVICE_ID_AIC8800D80LN 0x9082
+#define SDIO_DEVICE_ID_AIC8800D40N 0x9084
+#define SDIO_DEVICE_ID_AIC8800D40LN 0x9085
+
+enum sdio_type {
+ SDIO_TYPE_DATA = 0X00,
+ SDIO_TYPE_CFG = 0X10,
+ SDIO_TYPE_CFG_CMD_RSP = 0X11,
+ SDIO_TYPE_CFG_DATA_CFM = 0X12,
+ SDIO_TYPE_CFG_PRINT = 0X13
+};
+
+enum AICWF_IC {
+ PRODUCT_ID_AIC8801 = 0,
+ PRODUCT_ID_AIC8800DC,
+ PRODUCT_ID_AIC8800DW,
+ PRODUCT_ID_AIC8800D80,
+ PRODUCT_ID_AIC8800D80N,
+};
+
+struct aicwf_hw;
+struct wakeup_source;
+struct aic_sdio_chip_hw;
+
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+struct temp_ctrl {
+ struct timer_list netif_timer;
+ struct timer_list tp_ctrl_timer;
+ struct work_struct tp_ctrl_work;
+ struct work_struct netif_work;
+ /* lock for temp */
+ spinlock_t tm_lock;
+ s8 cur_temp;
+ bool net_stop;
+ bool on_off; // for command, 0 - off, 1 - on
+ s8 get_level; // for command, 0 - 100%, 1 - 12%, 2 - 3%
+ s8 set_level; // for command, 0 - driver auto, 1 - 12%, 2 - 3%
+ int interval_t1;
+ int interval_t2;
+ u8 cur_stat; // 0--normal temp, 1/2--buffering temp
+ s8 tp_thd_1; // temperature threshold 1
+ s8 tp_thd_2; // temperature threshold 2
+ s8 tm_start; //timer start flag
+};
+#endif
+
+struct aic_sdio_reg {
+ u8 bytemode_len_reg;
+ u8 intr_config_reg;
+ u8 sleep_reg;
+ u8 wakeup_reg;
+ u8 flow_ctrl_reg;
+ u8 register_block;
+ u8 bytemode_enable_reg;
+ u8 block_cnt_reg;
+ u8 misc_int_status_reg;
+ u8 rd_fifo_addr;
+ u8 wr_fifo_addr;
+};
+
+struct aic_sdio_dev {
+ struct aicwf_hw *aicwf_hw;
+ /* Platform of this device, %NULL until platform init has succeeded */
+ struct aicwf_plat *plat;
+ struct sdio_func *func;
+ struct sdio_func *func2;
+ struct device *dev;
+ struct aicwf_bus *bus_if;
+ struct aicwf_cmd_mgr cmd_mgr;
+
+ struct aicwf_rx_priv *rx_priv;
+ struct aicwf_tx_priv *tx_priv;
+ /* Buffers kept for the lifetime of this device */
+ struct aicwf_resv_mem resv_mem;
+ struct aicwf_prealloc_txq prealloc_txq;
+ u32 state;
+ bool irq_claimed;
+ bool quiesced;
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+ u8 flowctrl;
+ /* lock for tx flow */
+ spinlock_t tx_flow_lock;
+#endif
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ // for sdio pwr ctrl
+ struct timer_list timer;
+ uint active_duration;
+ struct completion pwrctrl_trgg;
+ struct task_struct *pwrctl_tsk;
+ /* lock for pwrctl */
+ spinlock_t pwrctl_lock;
+ struct semaphore pwrctl_wakeup_sema;
+ /* The firmware has been booted; until then the bootrom answers. */
+ bool fw_running;
+#endif
+ u16 chipid;
+ /* Properties of the chip, selected from @chipid at probe time */
+ const struct aic_sdio_chip_hw *chip_hw;
+ struct aic_sdio_reg sdio_reg;
+
+ /* lock for ws */
+ spinlock_t wslock;
+ bool oob_enable;
+ atomic_t is_bus_suspend;
+ atomic_t suspending;
+ atomic_t activity_count;
+ wait_queue_head_t activity_waitq;
+ /* lock for tx tp */
+ spinlock_t tx_tp_lock;
+
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+ struct temp_ctrl tp_ctrl;
+#endif
+};
+
+int aicwf_sdio_readb(struct aic_sdio_dev *sdiodev, uint regaddr, u8 *val);
+int aicwf_sdio_writeb(struct aic_sdio_dev *sdiodev, uint regaddr, u8 val);
+void aicwf_sdio_hal_irqhandler(struct sdio_func *func);
+bool aicwf_sdio_activity_get(struct aicwf_hw *aicwf_hw,
+ struct wakeup_source *ws);
+void aicwf_sdio_activity_put(struct aicwf_hw *aicwf_hw,
+ struct wakeup_source *ws);
+bool aicwf_sdio_scan_activity_get(struct aicwf_hw *aicwf_hw);
+void aicwf_sdio_scan_activity_put(struct aicwf_hw *aicwf_hw);
+int aicwf_sdio_func2_readb(struct aic_sdio_dev *sdiodev, uint regaddr, u8 *val);
+int aicwf_sdio_func2_writeb(struct aic_sdio_dev *sdiodev, uint regaddr, u8 val);
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+struct rx_buff *aicwf_sdio_readframes(struct aic_sdio_dev *sdiodev);
+#else
+struct sk_buff *aicwf_sdio_readframes(struct aic_sdio_dev *sdiodev);
+#endif
+
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+void aicwf_netif_worker(struct work_struct *work);
+void aicwf_temp_ctrl_worker(struct work_struct *work);
+void aicwf_temp_ctrl(struct aic_sdio_dev *sdiodev);
+void aicwf_netif_ctrl(struct aic_sdio_dev *sdiodev, int val);
+void aicwf_tp_ctrl_init(struct aic_sdio_dev *sdiodev);
+void aicwf_tp_ctrl_deinit(struct aic_sdio_dev *sdiodev);
+#endif
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+void aicwf_sdio_pwrctl_timer(struct aic_sdio_dev *sdiodev, uint duration);
+int aicwf_sdio_pwr_stctl(struct aic_sdio_dev *sdiodev, uint target);
+int aicwf_sdio_sleep_allow(struct aic_sdio_dev *sdiodev);
+int aicwf_sdio_wakeup(struct aic_sdio_dev *sdiodev);
+#endif
+
+void aicwf_sdio_reg_init(struct aic_sdio_dev *sdiodev);
+int aicwf_sdio_func_init(struct aic_sdio_dev *sdiodev);
+int aicwf_sdiov3_func_init(struct aic_sdio_dev *sdiodev);
+int aicwf_sdio_fw_started(struct aic_sdio_dev *sdiodev);
+void aicwf_sdio_func_deinit(struct aic_sdio_dev *sdiodev);
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+void aicwf_sdio_tx_netif_flowctrl(struct aicwf_hw *aicwf_hw, bool state);
+#endif
+int aicwf_sdio_flow_ctrl(struct aic_sdio_dev *sdiodev);
+int aicwf_sdio_flow_ctrl_msg(struct aic_sdio_dev *sdiodev);
+#ifdef CONFIG_PREALLOC_RX_SKB
+int aicwf_sdio_recv_pkt(struct aic_sdio_dev *sdiodev, struct rx_buff *rxbbuf,
+ u32 size);
+#else
+int aicwf_sdio_recv_pkt(struct aic_sdio_dev *sdiodev, struct sk_buff *skbbuf,
+ u32 size);
+#endif
+int aicwf_sdio_send_pkt(struct aic_sdio_dev *sdiodev, u8 *buf, uint count);
+void *aicwf_sdio_bus_init(struct aic_sdio_dev *sdiodev);
+void aicwf_sdio_quiesce(struct aic_sdio_dev *sdiodev);
+void aicwf_sdio_release(struct aic_sdio_dev *sdiodev);
+void aicwf_sdio_exit(void);
+int aicwf_sdio_register(void);
+int aicwf_sdio_txpkt(struct aic_sdio_dev *sdiodev, struct sk_buff *pkt);
+int sdio_bustx_thread(void *data);
+int sdio_busrx_thread(void *data);
+#ifdef CONFIG_OOB
+// new oob feature
+int sdio_busirq_thread(void *data);
+#endif // CONFIG_OOB
+int aicwf_sdio_aggr(struct aicwf_tx_priv *tx_priv, struct sk_buff *pkt);
+int aicwf_sdio_send(struct aicwf_tx_priv *tx_priv, u8 txnow);
+void aicwf_sdio_aggr_send(struct aicwf_tx_priv *tx_priv);
+void aicwf_sdio_aggrbuf_reset(struct aicwf_tx_priv *tx_priv);
+
+u8 crc8_ponl_107(u8 *p_buffer, uint16_t cal_size);
+
+#endif /*_AICWF_SDMMC_H_*/
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_strs.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_strs.c
new file mode 100644
index 000000000000..79fc28f2872d
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_strs.c
@@ -0,0 +1,267 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ****************************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file aicwf_strs.c
+ *
+ * @brief Miscellaneous debug strings
+ *
+ ****************************************************************************************
+ */
+
+#include "lmac_msg.h"
+#include "aicwf_strs.h"
+static const char *const aicwf_mmid2str[MSG_I(MM_MAX)] = {
+ [MSG_I(MM_RESET_REQ)] = "MM_RESET_REQ",
+ [MSG_I(MM_RESET_CFM)] = "MM_RESET_CFM",
+ [MSG_I(MM_START_REQ)] = "MM_START_REQ",
+ [MSG_I(MM_START_CFM)] = "MM_START_CFM",
+ [MSG_I(MM_VERSION_REQ)] = "MM_VERSION_REQ",
+ [MSG_I(MM_VERSION_CFM)] = "MM_VERSION_CFM",
+ [MSG_I(MM_ADD_IF_REQ)] = "MM_ADD_IF_REQ",
+ [MSG_I(MM_ADD_IF_CFM)] = "MM_ADD_IF_CFM",
+ [MSG_I(MM_REMOVE_IF_REQ)] = "MM_REMOVE_IF_REQ",
+ [MSG_I(MM_REMOVE_IF_CFM)] = "MM_REMOVE_IF_CFM",
+ [MSG_I(MM_STA_ADD_REQ)] = "MM_STA_ADD_REQ",
+ [MSG_I(MM_STA_ADD_CFM)] = "MM_STA_ADD_CFM",
+ [MSG_I(MM_STA_DEL_REQ)] = "MM_STA_DEL_REQ",
+ [MSG_I(MM_STA_DEL_CFM)] = "MM_STA_DEL_CFM",
+ [MSG_I(MM_SET_FILTER_REQ)] = "MM_SET_FILTER_REQ",
+ [MSG_I(MM_SET_FILTER_CFM)] = "MM_SET_FILTER_CFM",
+ [MSG_I(MM_SET_CHANNEL_REQ)] = "MM_SET_CHANNEL_REQ",
+ [MSG_I(MM_SET_CHANNEL_CFM)] = "MM_SET_CHANNEL_CFM",
+ [MSG_I(MM_SET_DTIM_REQ)] = "MM_SET_DTIM_REQ",
+ [MSG_I(MM_SET_DTIM_CFM)] = "MM_SET_DTIM_CFM",
+ [MSG_I(MM_SET_BEACON_INT_REQ)] = "MM_SET_BEACON_INT_REQ",
+ [MSG_I(MM_SET_BEACON_INT_CFM)] = "MM_SET_BEACON_INT_CFM",
+ [MSG_I(MM_SET_BASIC_RATES_REQ)] = "MM_SET_BASIC_RATES_REQ",
+ [MSG_I(MM_SET_BASIC_RATES_CFM)] = "MM_SET_BASIC_RATES_CFM",
+ [MSG_I(MM_SET_BSSID_REQ)] = "MM_SET_BSSID_REQ",
+ [MSG_I(MM_SET_BSSID_CFM)] = "MM_SET_BSSID_CFM",
+ [MSG_I(MM_SET_EDCA_REQ)] = "MM_SET_EDCA_REQ",
+ [MSG_I(MM_SET_EDCA_CFM)] = "MM_SET_EDCA_CFM",
+ [MSG_I(MM_SET_MODE_REQ)] = "MM_SET_MODE_REQ",
+ [MSG_I(MM_SET_MODE_CFM)] = "MM_SET_MODE_CFM",
+ [MSG_I(MM_SET_VIF_STATE_REQ)] = "MM_SET_VIF_STATE_REQ",
+ [MSG_I(MM_SET_VIF_STATE_CFM)] = "MM_SET_VIF_STATE_CFM",
+ [MSG_I(MM_SET_SLOTTIME_REQ)] = "MM_SET_SLOTTIME_REQ",
+ [MSG_I(MM_SET_SLOTTIME_CFM)] = "MM_SET_SLOTTIME_CFM",
+ [MSG_I(MM_SET_IDLE_REQ)] = "MM_SET_IDLE_REQ",
+ [MSG_I(MM_SET_IDLE_CFM)] = "MM_SET_IDLE_CFM",
+ [MSG_I(MM_KEY_ADD_REQ)] = "MM_KEY_ADD_REQ",
+ [MSG_I(MM_KEY_ADD_CFM)] = "MM_KEY_ADD_CFM",
+ [MSG_I(MM_KEY_DEL_REQ)] = "MM_KEY_DEL_REQ",
+ [MSG_I(MM_KEY_DEL_CFM)] = "MM_KEY_DEL_CFM",
+ [MSG_I(MM_BA_ADD_REQ)] = "MM_BA_ADD_REQ",
+ [MSG_I(MM_BA_ADD_CFM)] = "MM_BA_ADD_CFM",
+ [MSG_I(MM_BA_DEL_REQ)] = "MM_BA_DEL_REQ",
+ [MSG_I(MM_BA_DEL_CFM)] = "MM_BA_DEL_CFM",
+ [MSG_I(MM_PRIMARY_TBTT_IND)] = "MM_PRIMARY_TBTT_IND",
+ [MSG_I(MM_SECONDARY_TBTT_IND)] = "MM_SECONDARY_TBTT_IND",
+ [MSG_I(MM_SET_POWER_REQ)] = "MM_SET_POWER_REQ",
+ [MSG_I(MM_SET_POWER_CFM)] = "MM_SET_POWER_CFM",
+ [MSG_I(MM_DBG_TRIGGER_REQ)] = "MM_DBG_TRIGGER_REQ",
+ [MSG_I(MM_SET_PS_MODE_REQ)] = "MM_SET_PS_MODE_REQ",
+ [MSG_I(MM_SET_PS_MODE_CFM)] = "MM_SET_PS_MODE_CFM",
+ [MSG_I(MM_CHAN_CTXT_ADD_REQ)] = "MM_CHAN_CTXT_ADD_REQ",
+ [MSG_I(MM_CHAN_CTXT_ADD_CFM)] = "MM_CHAN_CTXT_ADD_CFM",
+ [MSG_I(MM_CHAN_CTXT_DEL_REQ)] = "MM_CHAN_CTXT_DEL_REQ",
+ [MSG_I(MM_CHAN_CTXT_DEL_CFM)] = "MM_CHAN_CTXT_DEL_CFM",
+ [MSG_I(MM_CHAN_CTXT_LINK_REQ)] = "MM_CHAN_CTXT_LINK_REQ",
+ [MSG_I(MM_CHAN_CTXT_LINK_CFM)] = "MM_CHAN_CTXT_LINK_CFM",
+ [MSG_I(MM_CHAN_CTXT_UNLINK_REQ)] = "MM_CHAN_CTXT_UNLINK_REQ",
+ [MSG_I(MM_CHAN_CTXT_UNLINK_CFM)] = "MM_CHAN_CTXT_UNLINK_CFM",
+ [MSG_I(MM_CHAN_CTXT_UPDATE_REQ)] = "MM_CHAN_CTXT_UPDATE_REQ",
+ [MSG_I(MM_CHAN_CTXT_UPDATE_CFM)] = "MM_CHAN_CTXT_UPDATE_CFM",
+ [MSG_I(MM_CHAN_CTXT_SCHED_REQ)] = "MM_CHAN_CTXT_SCHED_REQ",
+ [MSG_I(MM_CHAN_CTXT_SCHED_CFM)] = "MM_CHAN_CTXT_SCHED_CFM",
+ [MSG_I(MM_BCN_CHANGE_REQ)] = "MM_BCN_CHANGE_REQ",
+ [MSG_I(MM_BCN_CHANGE_CFM)] = "MM_BCN_CHANGE_CFM",
+ [MSG_I(MM_TIM_UPDATE_REQ)] = "MM_TIM_UPDATE_REQ",
+ [MSG_I(MM_TIM_UPDATE_CFM)] = "MM_TIM_UPDATE_CFM",
+ [MSG_I(MM_CONNECTION_LOSS_IND)] = "MM_CONNECTION_LOSS_IND",
+ [MSG_I(MM_CHANNEL_SWITCH_IND)] = "MM_CHANNEL_SWITCH_IND",
+ [MSG_I(MM_CHANNEL_PRE_SWITCH_IND)] = "MM_CHANNEL_PRE_SWITCH_IND",
+ [MSG_I(MM_REMAIN_ON_CHANNEL_REQ)] = "MM_REMAIN_ON_CHANNEL_REQ",
+ [MSG_I(MM_REMAIN_ON_CHANNEL_CFM)] = "MM_REMAIN_ON_CHANNEL_CFM",
+ [MSG_I(MM_REMAIN_ON_CHANNEL_EXP_IND)] = "MM_REMAIN_ON_CHANNEL_EXP_IND",
+ [MSG_I(MM_PS_CHANGE_IND)] = "MM_PS_CHANGE_IND",
+ [MSG_I(MM_TRAFFIC_REQ_IND)] = "MM_TRAFFIC_REQ_IND",
+ [MSG_I(MM_SET_PS_OPTIONS_REQ)] = "MM_SET_PS_OPTIONS_REQ",
+ [MSG_I(MM_SET_PS_OPTIONS_CFM)] = "MM_SET_PS_OPTIONS_CFM",
+ [MSG_I(MM_P2P_VIF_PS_CHANGE_IND)] = "MM_P2P_VIF_PS_CHANGE_IND",
+ [MSG_I(MM_CSA_COUNTER_IND)] = "MM_CSA_COUNTER_IND",
+ [MSG_I(MM_CHANNEL_SURVEY_IND)] = "MM_CHANNEL_SURVEY_IND",
+ [MSG_I(MM_SET_P2P_NOA_REQ)] = "MM_SET_P2P_NOA_REQ",
+ [MSG_I(MM_SET_P2P_OPPPS_REQ)] = "MM_SET_P2P_OPPPS_REQ",
+ [MSG_I(MM_SET_P2P_NOA_CFM)] = "MM_SET_P2P_NOA_CFM",
+ [MSG_I(MM_SET_P2P_OPPPS_CFM)] = "MM_SET_P2P_OPPPS_CFM",
+ [MSG_I(MM_CFG_RSSI_REQ)] = "MM_CFG_RSSI_REQ",
+ [MSG_I(MM_RSSI_STATUS_IND)] = "MM_RSSI_STATUS_IND",
+ [MSG_I(MM_CSA_FINISH_IND)] = "MM_CSA_FINISH_IND",
+ [MSG_I(MM_CSA_TRAFFIC_IND)] = "MM_CSA_TRAFFIC_IND",
+ [MSG_I(MM_MU_GROUP_UPDATE_REQ)] = "MM_MU_GROUP_UPDATE_REQ",
+ [MSG_I(MM_MU_GROUP_UPDATE_CFM)] = "MM_MU_GROUP_UPDATE_CFM",
+
+ [MSG_I(MM_SET_ARPOFFLOAD_REQ)] = "MM_SET_ARPOFFLOAD_REQ",
+ [MSG_I(MM_SET_ARPOFFLOAD_CFM)] = "MM_SET_ARPOFFLOAD_CFM",
+ [MSG_I(MM_SET_AGG_DISABLE_REQ)] = "MM_SET_AGG_DISABLE_REQ",
+ [MSG_I(MM_SET_AGG_DISABLE_CFM)] = "MM_SET_AGG_DISABLE_CFM",
+ [MSG_I(MM_SET_RF_CONFIG_REQ)] = "MM_SET_RF_CONFIG_REQ",
+ [MSG_I(MM_SET_RF_CONFIG_CFM)] = "MM_SET_RF_CONFIG_CFM",
+ [MSG_I(MM_SET_RF_CALIB_REQ)] = "MM_SET_RF_CALIB_REQ",
+ [MSG_I(MM_SET_RF_CALIB_CFM)] = "MM_SET_RF_CALIB_CFM",
+
+ [MSG_I(MM_GET_MAC_ADDR_REQ)] = "MM_GET_MAC_ADDR_REQ",
+ [MSG_I(MM_GET_MAC_ADDR_CFM)] = "MM_GET_MAC_ADDR_CFM",
+ [MSG_I(MM_GET_STA_INFO_REQ)] = "MM_GET_STA_INFO_REQ",
+ [MSG_I(MM_GET_STA_INFO_CFM)] = "MM_GET_STA_INFO_CFM",
+ [MSG_I(MM_SET_TXPWR_IDX_LVL_REQ)] = "MM_SET_TXPWR_IDX_LVL_REQ",
+ [MSG_I(MM_SET_TXPWR_IDX_LVL_CFM)] = "MM_SET_TXPWR_IDX_LVL_CFM",
+ [MSG_I(MM_SET_TXPWR_OFST_REQ)] = "MM_SET_TXPWR_OFST_REQ",
+ [MSG_I(MM_SET_TXPWR_OFST_CFM)] = "MM_SET_TXPWR_OFST_CFM",
+ [MSG_I(MM_SET_STACK_START_REQ)] = "MM_SET_STACK_START_REQ",
+ [MSG_I(MM_SET_STACK_START_CFM)] = "MM_SET_STACK_START_CFM",
+ [MSG_I(MM_APM_STALOSS_IND)] = "MM_APM_STALOSS_IND",
+ [MSG_I(MM_SET_VENDOR_HWCONFIG_REQ)] = "MM_SET_VENDOR_HWCONFIG_REQ",
+ [MSG_I(MM_SET_VENDOR_HWCONFIG_CFM)] = "MM_SET_VENDOR_HWCONFIG_CFM",
+ [MSG_I(MM_GET_FW_VERSION_REQ)] = "MM_GET_FW_VERSION_REQ",
+ [MSG_I(MM_GET_FW_VERSION_CFM)] = "MM_GET_FW_VERSION_CFM",
+ [MSG_I(MM_SET_RESUME_RESTORE_REQ)] = "MM_SET_RESUME_RESTORE_REQ",
+ [MSG_I(MM_SET_RESUME_RESTORE_CFM)] = "MM_SET_RESUME_RESTORE_CFM",
+ [MSG_I(MM_GET_WIFI_DISABLE_REQ)] = "MM_GET_WIFI_DISABLE_REQ",
+ [MSG_I(MM_GET_WIFI_DISABLE_CFM)] = "MM_GET_WIFI_DISABLE_CFM",
+ [MSG_I(MM_CFG_RSSI_CFM)] = "MM_CFG_RSSI_CFM",
+ [MSG_I(MM_SET_VENDOR_SWCONFIG_REQ)] = "MM_SET_VENDOR_SWCONFIG_REQ",
+ [MSG_I(MM_SET_VENDOR_SWCONFIG_CFM)] = "MM_SET_VENDOR_SWCONFIG_CFM",
+};
+
+static const char *const aicwf_dbgid2str[MSG_I(DBG_MAX)] = {
+ [MSG_I(DBG_MEM_READ_REQ)] = "DBG_MEM_READ_REQ",
+ [MSG_I(DBG_MEM_READ_CFM)] = "DBG_MEM_READ_CFM",
+ [MSG_I(DBG_MEM_WRITE_REQ)] = "DBG_MEM_WRITE_REQ",
+ [MSG_I(DBG_MEM_WRITE_CFM)] = "DBG_MEM_WRITE_CFM",
+ [MSG_I(DBG_SET_MOD_FILTER_REQ)] = "DBG_SET_MOD_FILTER_REQ",
+ [MSG_I(DBG_SET_MOD_FILTER_CFM)] = "DBG_SET_MOD_FILTER_CFM",
+ [MSG_I(DBG_SET_SEV_FILTER_REQ)] = "DBG_SET_SEV_FILTER_REQ",
+ [MSG_I(DBG_SET_SEV_FILTER_CFM)] = "DBG_SET_SEV_FILTER_CFM",
+ [MSG_I(DBG_ERROR_IND)] = "DBG_ERROR_IND",
+ [MSG_I(DBG_GET_SYS_STAT_REQ)] = "DBG_GET_SYS_STAT_REQ",
+ [MSG_I(DBG_GET_SYS_STAT_CFM)] = "DBG_GET_SYS_STAT_CFM",
+};
+
+static const char *const aicwf_scanid2str[MSG_I(SCAN_MAX)] = {
+ [MSG_I(SCAN_START_REQ)] = "SCAN_START_REQ",
+ [MSG_I(SCAN_START_CFM)] = "SCAN_START_CFM",
+ [MSG_I(SCAN_DONE_IND)] = "SCAN_DONE_IND",
+};
+
+static const char *const aicwf_tdlsid2str[MSG_I(TDLS_MAX)] = {
+ [MSG_I(TDLS_CHAN_SWITCH_CFM)] = "TDLS_CHAN_SWITCH_CFM",
+ [MSG_I(TDLS_CHAN_SWITCH_REQ)] = "TDLS_CHAN_SWITCH_REQ",
+ [MSG_I(TDLS_CHAN_SWITCH_IND)] = "TDLS_CHAN_SWITCH_IND",
+ [MSG_I(TDLS_CHAN_SWITCH_BASE_IND)] = "TDLS_CHAN_SWITCH_BASE_IND",
+ [MSG_I(TDLS_CANCEL_CHAN_SWITCH_REQ)] = "TDLS_CANCEL_CHAN_SWITCH_REQ",
+ [MSG_I(TDLS_CANCEL_CHAN_SWITCH_CFM)] = "TDLS_CANCEL_CHAN_SWITCH_CFM",
+ [MSG_I(TDLS_PEER_PS_IND)] = "TDLS_PEER_PS_IND",
+ [MSG_I(TDLS_PEER_TRAFFIC_IND_REQ)] = "TDLS_PEER_TRAFFIC_IND_REQ",
+ [MSG_I(TDLS_PEER_TRAFFIC_IND_CFM)] = "TDLS_PEER_TRAFFIC_IND_CFM",
+};
+
+#ifdef CONFIG_AICWF_FULLMAC
+
+static const char *const aicwf_scanuid2str[MSG_I(SCANU_MAX)] = {
+ [MSG_I(SCANU_START_REQ)] = "SCANU_START_REQ",
+ [MSG_I(SCANU_START_CFM)] = "SCANU_START_CFM",
+ [MSG_I(SCANU_JOIN_REQ)] = "SCANU_JOIN_REQ",
+ [MSG_I(SCANU_JOIN_CFM)] = "SCANU_JOIN_CFM",
+ [MSG_I(SCANU_RESULT_IND)] = "SCANU_RESULT_IND",
+ [MSG_I(SCANU_FAST_REQ)] = "SCANU_FAST_REQ",
+ [MSG_I(SCANU_FAST_CFM)] = "SCANU_FAST_CFM",
+ [MSG_I(SCANU_VENDOR_IE_REQ)] = "SCANU_VENDOR_IE_REQ",
+ [MSG_I(SCANU_VENDOR_IE_CFM)] = "SCANU_VENDOR_IE_CFM",
+ [MSG_I(SCANU_START_CFM_ADDTIONAL)] = "SCANU_START_CFM_ADDTIONAL",
+ [MSG_I(SCANU_CANCEL_REQ)] = "SCANU_CANCEL_REQ",
+ [MSG_I(SCANU_CANCEL_CFM)] = "SCANU_CANCEL_CFM",
+};
+
+static const char *const aicwf_meid2str[MSG_I(ME_MAX)] = {
+ [MSG_I(ME_CONFIG_REQ)] = "ME_CONFIG_REQ",
+ [MSG_I(ME_CONFIG_CFM)] = "ME_CONFIG_CFM",
+ [MSG_I(ME_CHAN_CONFIG_REQ)] = "ME_CHAN_CONFIG_REQ",
+ [MSG_I(ME_CHAN_CONFIG_CFM)] = "ME_CHAN_CONFIG_CFM",
+ [MSG_I(ME_SET_CONTROL_PORT_REQ)] = "ME_SET_CONTROL_PORT_REQ",
+ [MSG_I(ME_SET_CONTROL_PORT_CFM)] = "ME_SET_CONTROL_PORT_CFM",
+ [MSG_I(ME_TKIP_MIC_FAILURE_IND)] = "ME_TKIP_MIC_FAILURE_IND",
+ [MSG_I(ME_STA_ADD_REQ)] = "ME_STA_ADD_REQ",
+ [MSG_I(ME_STA_ADD_CFM)] = "ME_STA_ADD_CFM",
+ [MSG_I(ME_STA_DEL_REQ)] = "ME_STA_DEL_REQ",
+ [MSG_I(ME_STA_DEL_CFM)] = "ME_STA_DEL_CFM",
+ [MSG_I(ME_TX_CREDITS_UPDATE_IND)] = "ME_TX_CREDITS_UPDATE_IND",
+ [MSG_I(ME_RC_STATS_REQ)] = "ME_RC_STATS_REQ",
+ [MSG_I(ME_RC_STATS_CFM)] = "ME_RC_STATS_CFM",
+ [MSG_I(ME_RC_SET_RATE_REQ)] = "ME_RC_SET_RATE_REQ",
+ [MSG_I(ME_TRAFFIC_IND_REQ)] = "ME_TRAFFIC_IND_REQ",
+ [MSG_I(ME_TRAFFIC_IND_CFM)] = "ME_TRAFFIC_IND_CFM",
+ [MSG_I(ME_SET_PS_MODE_REQ)] = "ME_SET_PS_MODE_REQ",
+ [MSG_I(ME_SET_PS_MODE_CFM)] = "ME_SET_PS_MODE_CFM",
+ [MSG_I(ME_SET_LP_LEVEL_REQ)] = "ME_SET_LP_LEVEL_REQ",
+ [MSG_I(ME_SET_LP_LEVEL_CFM)] = "ME_SET_LP_LEVEL_CFM",
+};
+
+static const char *const aicwf_smid2str[MSG_I(SM_MAX)] = {
+ [MSG_I(SM_CONNECT_REQ)] = "SM_CONNECT_REQ",
+ [MSG_I(SM_CONNECT_CFM)] = "SM_CONNECT_CFM",
+ [MSG_I(SM_CONNECT_IND)] = "SM_CONNECT_IND",
+ [MSG_I(SM_DISCONNECT_REQ)] = "SM_DISCONNECT_REQ",
+ [MSG_I(SM_DISCONNECT_CFM)] = "SM_DISCONNECT_CFM",
+ [MSG_I(SM_DISCONNECT_IND)] = "SM_DISCONNECT_IND",
+ [MSG_I(SM_EXTERNAL_AUTH_REQUIRED_IND)] = "SM_EXTERNAL_AUTH_REQUIRED_IND",
+ [MSG_I(SM_EXTERNAL_AUTH_REQUIRED_RSP)] = "SM_EXTERNAL_AUTH_REQUIRED_RSP",
+ [MSG_I(SM_EXTERNAL_AUTH_REQUIRED_RSP_CFM)] =
+ "SM_EXTERNAL_AUTH_REQUIRED_RSP_CFM",
+};
+
+static const char *const aicwf_apmid2str[MSG_I(APM_MAX)] = {
+ [MSG_I(APM_START_REQ)] = "APM_START_REQ",
+ [MSG_I(APM_START_CFM)] = "APM_START_CFM",
+ [MSG_I(APM_STOP_REQ)] = "APM_STOP_REQ",
+ [MSG_I(APM_STOP_CFM)] = "APM_STOP_CFM",
+ [MSG_I(APM_START_CAC_REQ)] = "APM_START_CAC_REQ",
+ [MSG_I(APM_START_CAC_CFM)] = "APM_START_CAC_CFM",
+ [MSG_I(APM_STOP_CAC_REQ)] = "APM_STOP_CAC_REQ",
+ [MSG_I(APM_STOP_CAC_CFM)] = "APM_STOP_CAC_CFM",
+ [MSG_I(APM_SET_BEACON_IE_REQ)] = "APM_SET_BEACON_IE_REQ",
+ [MSG_I(APM_SET_BEACON_IE_CFM)] = "APM_SET_BEACON_IE_CFM",
+};
+
+static const char *const aicwf_meshid2str[MSG_I(MESH_MAX)] = {
+ [MSG_I(MESH_START_REQ)] = "MESH_START_REQ",
+ [MSG_I(MESH_START_CFM)] = "MESH_START_CFM",
+ [MSG_I(MESH_STOP_REQ)] = "MESH_STOP_REQ",
+ [MSG_I(MESH_STOP_CFM)] = "MESH_STOP_CFM",
+ [MSG_I(MESH_UPDATE_REQ)] = "MESH_UPDATE_REQ",
+ [MSG_I(MESH_UPDATE_CFM)] = "MESH_UPDATE_CFM",
+ [MSG_I(MESH_PATH_CREATE_REQ)] = "MESH_PATH_CREATE_REQ",
+ [MSG_I(MESH_PATH_CREATE_CFM)] = "MESH_PATH_CREATE_CFM",
+ [MSG_I(MESH_PATH_UPDATE_REQ)] = "MESH_PATH_UPDATE_REQ",
+ [MSG_I(MESH_PATH_UPDATE_CFM)] = "MESH_PATH_UPDATE_CFM",
+ [MSG_I(MESH_PROXY_ADD_REQ)] = "MESH_PROXY_ADD_REQ",
+ [MSG_I(MESH_PEER_UPDATE_IND)] = "MESH_PEER_UPDATE_IND",
+ [MSG_I(MESH_PATH_UPDATE_IND)] = "MESH_PATH_UPDATE_IND",
+ [MSG_I(MESH_PROXY_UPDATE_IND)] = "MESH_PROXY_UPDATE_IND",
+};
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+const char *const *const aicwf_id2str[TASK_LAST_EMB + 1] = {
+ [TASK_MM] = aicwf_mmid2str, [TASK_DBG] = aicwf_dbgid2str,
+ [TASK_SCAN] = aicwf_scanid2str, [TASK_TDLS] = aicwf_tdlsid2str,
+#ifdef CONFIG_AICWF_FULLMAC
+ [TASK_SCANU] = aicwf_scanuid2str, [TASK_ME] = aicwf_meid2str,
+ [TASK_SM] = aicwf_smid2str, [TASK_APM] = aicwf_apmid2str,
+ [TASK_MESH] = aicwf_meshid2str,
+#endif
+};
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_strs.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_strs.h
new file mode 100644
index 000000000000..71c69b288bb2
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_strs.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ****************************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file aicwf_strs.h
+ *
+ * @brief Miscellaneous debug strings
+ *
+ ****************************************************************************************
+ */
+
+#ifndef _AICWF_STRS_H_
+#define _AICWF_STRS_H_
+
+#include "lmac_msg.h"
+
+#define AICWF_ID2STR(tag) \
+ ({ \
+ const typeof(tag) __tag = (tag); \
+ ((MSG_T(__tag) < ARRAY_SIZE(aicwf_id2str)) && \
+ (aicwf_id2str[MSG_T(__tag)]) && \
+ ((aicwf_id2str[MSG_T(__tag)])[MSG_I(__tag)])) \
+ ? (aicwf_id2str[MSG_T(__tag)])[MSG_I(__tag)] \
+ : "unknown"; \
+ })
+
+extern const char *const *const aicwf_id2str[TASK_LAST_EMB + 1];
+
+#endif /* _AICWF_STRS_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_tx.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_tx.h
new file mode 100644
index 000000000000..4622dd725183
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_tx.h
@@ -0,0 +1,165 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file aicwf_tx.h
+ *
+ * @brief tx handle
+ *
+ ******************************************************************************
+ */
+#ifndef _AICWF_TX_H_
+#define _AICWF_TX_H_
+
+#include "hal_desc.h"
+#include "ipc_shared.h"
+#include "lmac_types.h"
+#include "aicwf_txq.h"
+#include <linux/ieee80211.h>
+#include <linux/netdevice.h>
+#include <net/cfg80211.h>
+
+#define AICWF_HWQ_BK 0
+#define AICWF_HWQ_BE 1
+#define AICWF_HWQ_VI 2
+#define AICWF_HWQ_VO 3
+#define AICWF_HWQ_BCMC 4
+#define AICWF_HWQ_NB NX_TXQ_CNT
+#define AICWF_HWQ_ALL_ACS (AICWF_HWQ_BK | AICWF_HWQ_BE | AICWF_HWQ_VI | AICWF_HWQ_VO)
+#define AICWF_HWQ_ALL_ACS_BIT \
+ (BIT(AICWF_HWQ_BK) | BIT(AICWF_HWQ_BE) | BIT(AICWF_HWQ_VI) | BIT(AICWF_HWQ_VO))
+
+#define AICWF_TX_LIFETIME_MS 1000
+#define AICWF_TX_MAX_RATES NX_TX_MAX_RATES
+
+#define AICWF_SWTXHDR_ALIGN_SZ 4
+#define AICWF_SWTXHDR_ALIGN_MSK (AICWF_SWTXHDR_ALIGN_SZ - 1)
+#define AICWF_SWTXHDR_ALIGN_PADS(x) \
+ ((AICWF_SWTXHDR_ALIGN_SZ - ((x) & AICWF_SWTXHDR_ALIGN_MSK)) & \
+ AICWF_SWTXHDR_ALIGN_MSK)
+#if AICWF_SWTXHDR_ALIGN_SZ & AICWF_SWTXHDR_ALIGN_MSK
+#error bad AICWF_SWTXHDR_ALIGN_SZ
+#endif
+
+#define AMSDU_PADDING(x) ((4 - ((x) & 0x3)) & 0x3)
+
+#define TXU_CNTRL_RETRY BIT(0)
+#define TXU_CNTRL_MORE_DATA BIT(2)
+#define TXU_CNTRL_MGMT BIT(3)
+#define TXU_CNTRL_MGMT_NO_CCK BIT(4)
+#define TXU_CNTRL_AMSDU BIT(6)
+#define TXU_CNTRL_MGMT_ROBUST BIT(7)
+#define TXU_CNTRL_USE_4ADDR BIT(8)
+#define TXU_CNTRL_EOSP BIT(9)
+#define TXU_CNTRL_MESH_FWD BIT(10)
+#define TXU_CNTRL_TDLS BIT(11)
+
+/**
+ * struct aicwf_amsdu_txhdr - Header for a noninitial A-MSDU subframe
+ *
+ * @list: Node in the list of additional A-MSDU subframes
+ * @map_len: Number of bytes mapped for this subframe
+ * @dma_addr: DMA address of the mapped subframe
+ * @skb: Socket buffer containing the subframe
+ * @pad: Padding before this subframe when dismantling the A-MSDU
+ * @msdu_len: MSDU size in bytes, excluding padding and the A-MSDU header
+ */
+struct aicwf_amsdu_txhdr {
+ struct list_head list;
+ size_t map_len;
+ dma_addr_t dma_addr;
+ struct sk_buff *skb;
+ u16 pad;
+ u16 msdu_len;
+};
+
+/**
+ * struct aicwf_amsdu - State used while building an A-MSDU
+ *
+ * @hdrs: List of additional subframes
+ * @len: Current A-MSDU size excluding padding, or 0 when none is in progress
+ * @nb: Number of subframes in the A-MSDU
+ * @pad: Padding required before the next subframe
+ */
+struct aicwf_amsdu {
+ struct list_head hdrs;
+ u16 len;
+ u8 nb;
+ u8 pad;
+};
+
+/**
+ * struct aicwf_sw_txhdr - Software part of tx header
+ *
+ * @aicwf_sta: Destination STA
+ * @aicwf_vif: VIF transmitting the buffer
+ * @txq: TX queue used to send the buffer
+ * @hw_queue: Hardware queue index used to push the buffer
+ * @frame_len: Frame size excluding the MAC header
+ * @cookie: cfg80211 management TX cookie
+ * @headroom: Headroom added for &struct aicwf_txhdr
+ * @amsdu: A-MSDU state when this buffer contains the first subframe
+ * @need_cfm: Whether the firmware must confirm this transmission
+ * @skb: Socket buffer being transmitted
+ * @desc: Descriptor copied to firmware-visible shared memory
+ */
+struct aicwf_sw_txhdr {
+ struct aicwf_sta *aicwf_sta;
+ struct aicwf_vif *aicwf_vif;
+ struct aicwf_txq *txq;
+ u8 hw_queue;
+ u16 frame_len;
+ u64 cookie;
+ u16 headroom;
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ struct aicwf_amsdu amsdu;
+#endif
+ u32 need_cfm;
+ struct sk_buff *skb;
+ struct txdesc_api desc;
+};
+
+/**
+ * struct aicwf_txhdr - Structure to control transimission of packet
+ * (Added in skb headroom)
+ *
+ * @sw_hdr: Information from driver
+ * @cache_guard:
+ * @hw_hdr: Information for/from hardware
+ */
+struct aicwf_txhdr {
+ struct aicwf_sw_txhdr *sw_hdr;
+ char cache_guard[L1_CACHE_BYTES];
+ struct aicwf_hw_txhdr hw_hdr;
+};
+
+extern const int aicwf_tid2hwq[IEEE80211_NUM_TIDS];
+
+u16 aicwf_select_txq(struct aicwf_vif *aicwf_vif, struct sk_buff *skb);
+netdev_tx_t aicwf_start_xmit(struct sk_buff *skb, struct net_device *dev);
+
+int aicwf_start_mgmt_xmit(struct aicwf_vif *vif, struct aicwf_sta *sta,
+ struct cfg80211_mgmt_tx_params *params, bool offchan,
+ u64 cookie);
+
+int aicwf_txdatacfm(void *pthis, void *host_id);
+
+struct aicwf_hw;
+struct aicwf_sta;
+void aicwf_set_traffic_status(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta,
+ bool available, u8 ps_id);
+
+void aicwf_ps_bh_enable(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta,
+ bool enable);
+
+void aicwf_ps_bh_traffic_req(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta,
+ u16 pkt_req, u8 ps_id);
+
+void aicwf_txq_credit_update(struct aicwf_hw *aicwf_hw, int sta_idx, u8 tid,
+ s8 update);
+
+void aicwf_tx_push(struct aicwf_hw *aicwf_hw, struct aicwf_txhdr *txhdr, int flags);
+
+#endif /* _AICWF_TX_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq.h
new file mode 100644
index 000000000000..9286aed3e870
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq.h
@@ -0,0 +1,353 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ****************************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file aicwf_txq.h
+ *
+ * @brief tx queue function
+ *
+ ****************************************************************************************
+ */
+#ifndef _AICWF_TXQ_H_
+#define _AICWF_TXQ_H_
+
+#include <linux/bitops.h>
+#include <linux/ieee80211.h>
+#include <linux/types.h>
+#include "aicwf_config.h"
+
+#ifdef CONFIG_AICWF_FULLMAC
+/*
+ * Fullmac TXQ configuration:
+ * - STA: 1 TXQ per TID (limited to 8)
+ * 1 TXQ for bufferable MGT frames
+ * - VIF: 1 TXQ for Multi/Broadcast +
+ * 1 TXQ for MGT for unknown STAs or non-bufferable MGT frames
+ * - 1 TXQ for offchannel transmissions
+ *
+ *
+ * Txq mapping looks like
+ * for NX_REMOTE_STA_MAX=10 and NX_VIRT_DEV_MAX=4
+ *
+ * | TXQ | NDEV_ID | VIF | STA | TID | HWQ |
+ * |-----+---------+-----+-------+------+-----|-
+ * | 0 | 0 | | 0 | 0 | 1 | 9 TXQ per STA
+ * | 1 | 1 | | 0 | 1 | 0 | (8 data + 1 mgmt)
+ * | 2 | 2 | | 0 | 2 | 0 |
+ * | 3 | 3 | | 0 | 3 | 1 |
+ * | 4 | 4 | | 0 | 4 | 2 |
+ * | 5 | 5 | | 0 | 5 | 2 |
+ * | 6 | 6 | | 0 | 6 | 3 |
+ * | 7 | 7 | | 0 | 7 | 3 |
+ * | 8 | N/A | | 0 | MGMT | 3 |
+ * |-----+---------+-----+-------+------+-----|-
+ * | ... | | | | | | Same for all STAs
+ * |-----+---------+-----+-------+------+-----|-
+ * | 90 | 80 | 0 | BC/MC | 0 | 1/4 | 1 TXQ for BC/MC per VIF
+ * | ... | | | | | |
+ * | 93 | 80 | 3 | BC/MC | 0 | 1/4 |
+ * |-----+---------+-----+-------+------+-----|-
+ * | 94 | N/A | 0 | N/A | MGMT | 3 | 1 TXQ for unknown STA per VIF
+ * | ... | | | | | |
+ * | 97 | N/A | 3 | N/A | MGMT | 3 |
+ * |-----+---------+-----+-------+------+-----|-
+ * | 98 | N/A | | N/A | MGMT | 3 | 1 TXQ for offchannel frame
+ */
+
+#define NX_NB_TID_PER_STA 8
+#define NX_NB_TXQ_PER_STA (NX_NB_TID_PER_STA + 1)
+#define NX_NB_TXQ_PER_VIF 2
+#define NX_NB_TXQ \
+ ((NX_NB_TXQ_PER_STA * NX_REMOTE_STA_MAX) + \
+ (NX_NB_TXQ_PER_VIF * NX_VIRT_DEV_MAX) + 1)
+
+#define NX_FIRST_VIF_TXQ_IDX (NX_REMOTE_STA_MAX * NX_NB_TXQ_PER_STA)
+#define NX_FIRST_BCMC_TXQ_IDX NX_FIRST_VIF_TXQ_IDX
+#define NX_FIRST_UNK_TXQ_IDX (NX_FIRST_BCMC_TXQ_IDX + NX_VIRT_DEV_MAX)
+
+#define NX_OFF_CHAN_TXQ_IDX \
+ (NX_FIRST_VIF_TXQ_IDX + (NX_VIRT_DEV_MAX * NX_NB_TXQ_PER_VIF))
+
+#define NX_FIRST_VIF_TXQ_IDX_FOR_OLD_IC \
+ (NX_REMOTE_STA_MAX_FOR_OLD_IC * NX_NB_TXQ_PER_STA)
+#define NX_FIRST_BCMC_TXQ_IDX_FOR_OLD_IC NX_FIRST_VIF_TXQ_IDX_FOR_OLD_IC
+#define NX_FIRST_UNK_TXQ_IDX_FOR_OLD_IC \
+ (NX_FIRST_BCMC_TXQ_IDX_FOR_OLD_IC + NX_VIRT_DEV_MAX)
+
+#define NX_OFF_CHAN_TXQ_IDX_FOR_OLD_IC \
+ (NX_FIRST_VIF_TXQ_IDX_FOR_OLD_IC + (NX_VIRT_DEV_MAX * NX_NB_TXQ_PER_VIF))
+
+#define NX_BCMC_TXQ_TYPE 0
+#define NX_UNK_TXQ_TYPE 1
+
+/*
+ * Each data TXQ is a netdev queue. TXQ to send MGT are not data TXQ as
+ * they did not received buffer from netdev interface.
+ * Need to allocate the maximum case.
+ * AP : all STAs + 1 BC/MC
+ */
+#define NX_NB_NDEV_TXQ ((NX_NB_TID_PER_STA * NX_REMOTE_STA_MAX) + 1)
+#define NX_NB_NDEV_TXQ_FOR_OLD_IC \
+ ((NX_NB_TID_PER_STA * NX_REMOTE_STA_MAX_FOR_OLD_IC) + 1)
+
+#define NX_BCMC_TXQ_NDEV_IDX (NX_NB_TID_PER_STA * NX_REMOTE_STA_MAX)
+#define NX_BCMC_TXQ_NDEV_IDX_FOR_OLD_IC \
+ (NX_NB_TID_PER_STA * NX_REMOTE_STA_MAX_FOR_OLD_IC)
+#define NX_STA_NDEV_IDX(tid, sta_idx) ((tid) + (sta_idx) * NX_NB_TID_PER_STA)
+#define NDEV_NO_TXQ 0xffff
+#if (NX_NB_NDEV_TXQ >= NDEV_NO_TXQ)
+#error("Need to increase struct aicwf_txq->ndev_idx size")
+#endif
+
+/* stop netdev queue when number of queued buffers if greater than this */
+#define AICWF_NDEV_FLOW_CTRL_STOP 64
+/* restart netdev queue when number of queued buffers is lower than this */
+#define AICWF_NDEV_FLOW_CTRL_RESTART 64
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+#define TXQ_INACTIVE 0xffff
+#if (NX_NB_TXQ >= TXQ_INACTIVE)
+#error("Need to increase struct aicwf_txq->idx size")
+#endif
+
+#define NX_TXQ_INITIAL_CREDITS 64
+
+/*
+ * TXQ tid sorted by decreasing priority
+ */
+extern const int nx_tid_prio[NX_NB_TID_PER_STA];
+
+/**
+ * struct aicwf_hwq - Structure used to save information relative to
+ * an AC TX queue (aka HW queue)
+ * @list: TX queues with buffers ready for this hardware queue
+ * @size: Queue capacity
+ * @id: Hardware queue identifier
+ * @need_processing: Whether the queue needs processing
+ */
+struct aicwf_hwq {
+ struct list_head list;
+ u8 size;
+ u8 id;
+ bool need_processing;
+};
+
+/**
+ * enum aicwf_push_flags - Flags of pushed buffer
+ *
+ * @AICWF_PUSH_RETRY: Push a buffer for retry
+ * @AICWF_PUSH_IMMEDIATE: Push a buffer without queuing it first
+ */
+enum aicwf_push_flags {
+ AICWF_PUSH_RETRY = BIT(0),
+ AICWF_PUSH_IMMEDIATE = BIT(1),
+};
+
+/**
+ * enum aicwf_txq_flags - TXQ status flag
+ *
+ * @AICWF_TXQ_IN_HWQ_LIST: The queue is scheduled for transmission
+ * @AICWF_TXQ_STOP_FULL: No more credits for the queue
+ * @AICWF_TXQ_STOP_CSA: CSA is in progress
+ * @AICWF_TXQ_STOP_STA_PS: Destiniation sta is currently in power save mode
+ * @AICWF_TXQ_STOP_VIF_PS: Vif owning this queue is currently in power save mode
+ * @AICWF_TXQ_STOP_CHAN: Channel of this queue is not the current active channel
+ * @AICWF_TXQ_STOP_MU_POS: TXQ is stopped waiting for all the buffers pushed to
+ * fw to be confirmed
+ * @AICWF_TXQ_STOP: All possible reason to have a txq stopped
+ * @AICWF_TXQ_NDEV_FLOW_CTRL: associated netdev queue is currently stopped.
+ * Note: when a TXQ is flowctrl it is NOT stopped
+ */
+enum aicwf_txq_flags {
+ AICWF_TXQ_IN_HWQ_LIST = BIT(0),
+ AICWF_TXQ_STOP_FULL = BIT(1),
+ AICWF_TXQ_STOP_CSA = BIT(2),
+ AICWF_TXQ_STOP_STA_PS = BIT(3),
+ AICWF_TXQ_STOP_VIF_PS = BIT(4),
+ AICWF_TXQ_STOP_CHAN = BIT(5),
+ AICWF_TXQ_STOP_MU_POS = BIT(6),
+ AICWF_TXQ_STOP =
+ (AICWF_TXQ_STOP_FULL | AICWF_TXQ_STOP_CSA | AICWF_TXQ_STOP_STA_PS |
+ AICWF_TXQ_STOP_VIF_PS | AICWF_TXQ_STOP_CHAN),
+ AICWF_TXQ_NDEV_FLOW_CTRL = BIT(7),
+};
+
+/**
+ * struct aicwf_txq - Structure used to save information relative to
+ * a RA/TID TX queue
+ *
+ * @idx: Unique txq idx. Set to TXQ_INACTIVE if txq is not used.
+ * @status: Bitfield of &enum aicwf_txq_flags
+ * @credits: Number of buffers that can be pushed to the firmware
+ * @pkt_sent: Number of consecutive packets sent while on the HW queue list
+ * @pkt_pushed: Number of packets awaiting transmission confirmation per user
+ * @sched_list: Node in the hardware queue scheduling list
+ * @sk_list: Buffers waiting to be pushed to the firmware
+ * @last_retry_skb: Last retry buffer in @sk_list, or %NULL when none is queued
+ * @nb_retry: Number of queued retry packets
+ * @hwq: Associated hardware queue
+ * @push_limit: Maximum packets to push before leaving the hardware queue list
+ * @tid: TID
+ *
+ * @nb_ready_mac80211: Number of buffers ready in the mac80211 TX queue
+ *
+ * FULLMAC specific
+ * @sta: STA associated with the queue
+ * @ps_id: Power-save queue identifier (legacy or U-APSD)
+ * @ndev_idx: Netdev queue index, or 0xff for a non-netdev queue
+ * @ndev: Net device of the corresponding VIF
+ * @amsdu: TX header of the first A-MSDU subframe, or %NULL
+ * @amsdu_len: Maximum A-MSDU size, or 0 when A-MSDU is disabled
+ * @mumimo_info: MU-MIMO group and user-position information
+ */
+struct aicwf_txq {
+ u16 idx;
+ u8 status;
+ s8 credits;
+ u8 pkt_sent;
+ u8 pkt_pushed[NX_USER_MAX];
+ struct list_head sched_list;
+ struct sk_buff_head sk_list;
+ struct sk_buff *last_retry_skb;
+ struct aicwf_hwq *hwq;
+ int nb_retry;
+ u8 push_limit;
+ u8 tid;
+#ifdef CONFIG_MAC80211_TXQ
+ unsigned long nb_ready_mac80211;
+#endif
+#ifdef CONFIG_AICWF_FULLMAC
+ struct aicwf_sta *sta;
+ u8 ps_id;
+ u16 ndev_idx;
+ struct net_device *ndev;
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ struct aicwf_sw_txhdr *amsdu;
+ u16 amsdu_len;
+#endif /* CONFIG_AICWF_AMSDUS_TX */
+#endif /* CONFIG_AICWF_FULLMAC */
+#ifdef CONFIG_AICWF_MUMIMO_TX
+ u8 mumimo_info;
+#endif
+};
+
+struct aicwf_sta;
+struct aicwf_vif;
+struct aicwf_hw;
+struct aicwf_sw_txhdr;
+
+#ifdef CONFIG_AICWF_MUMIMO_TX
+#define AICWF_TXQ_GROUP_ID(txq) ((txq)->mumimo_info & 0x3f)
+#define AICWF_TXQ_POS_ID(txq) (((txq)->mumimo_info >> 6) & 0x3)
+#else
+#define AICWF_TXQ_GROUP_ID(txq) 0
+#define AICWF_TXQ_POS_ID(txq) 0
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+
+static inline bool aicwf_txq_is_stopped(struct aicwf_txq *txq)
+{
+ return (txq->status & AICWF_TXQ_STOP);
+}
+
+static inline bool aicwf_txq_is_full(struct aicwf_txq *txq)
+{
+ return (txq->status & AICWF_TXQ_STOP_FULL);
+}
+
+static inline bool aicwf_txq_is_scheduled(struct aicwf_txq *txq)
+{
+ return (txq->status & AICWF_TXQ_IN_HWQ_LIST);
+}
+
+/*
+ * foreach_vif_txq - Macro to iterate over all TXQ of a VIF (in AC order)
+ *
+ * @vif: pointer to aicwf_vif
+ * @txq: pointer to aicwf_txq updated with the next TXQ at each iteration
+ * @ac: int updated with the TXQ ac at each iteration
+ */
+/*
+ *#ifdef CONFIG_MAC80211_TXQ
+ *#define foreach_vif_txq(vif, txq, ac) \
+ * for (ac = AICWF_HWQ_BK, txq = aicwf_txq_vif_get(vif, ac); \
+ * ac < NX_NB_TXQ_PER_VIF; ac++, txq = aicwf_txq_vif_get(vif, ac))
+ *#else
+ *#define foreach_vif_txq(vif, txq, ac) \
+ * for (ac = AICWF_HWQ_BK, txq = &vif->txqs[0]; ac < NX_NB_TXQ_PER_VIF; \
+ * ac++, txq++)
+ *#endif
+ */
+
+#ifdef CONFIG_AICWF_FULLMAC
+struct aicwf_txq *aicwf_txq_sta_get(struct aicwf_sta *sta, u8 tid,
+ struct aicwf_hw *aicwf_hw);
+struct aicwf_txq *aicwf_txq_vif_get(struct aicwf_vif *vif, u8 type);
+#endif /* CONFIG_AICWF_FULLMAC */
+
+/**
+ * aicwf_txq_vif_get_status - return status bits related to the vif
+ *
+ * @aicwf_vif: Pointer to vif structure
+ *
+ * Return: VIF-related stop-reason bits from the first VIF TX queue.
+ */
+static inline u8 aicwf_txq_vif_get_status(struct aicwf_vif *aicwf_vif)
+{
+ struct aicwf_txq *txq = aicwf_txq_vif_get(aicwf_vif, 0);
+
+ return (txq->status & (AICWF_TXQ_STOP_CHAN | AICWF_TXQ_STOP_VIF_PS));
+}
+
+void aicwf_txq_vif_init(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif,
+ u8 status);
+void aicwf_txq_vif_deinit(struct aicwf_hw *aicwf_hw, struct aicwf_vif *vif);
+void aicwf_txq_sta_init(struct aicwf_hw *aicwf_hw, struct aicwf_sta *aicwf_sta,
+ u8 status);
+void aicwf_txq_sta_deinit(struct aicwf_hw *aicwf_hw, struct aicwf_sta *aicwf_sta);
+#ifdef CONFIG_AICWF_FULLMAC
+void aicwf_txq_unk_vif_init(struct aicwf_vif *aicwf_vif);
+void aicwf_txq_unk_vif_deinit(struct aicwf_vif *vif);
+void aicwf_txq_offchan_init(struct aicwf_vif *aicwf_vif);
+void aicwf_txq_offchan_deinit(struct aicwf_vif *aicwf_vif);
+void aicwf_txq_tdls_vif_init(struct aicwf_vif *aicwf_vif);
+void aicwf_txq_tdls_vif_deinit(struct aicwf_vif *vif);
+void aicwf_txq_tdls_sta_start(struct aicwf_vif *aicwf_vif, u16 reason,
+ struct aicwf_hw *aicwf_hw);
+void aicwf_txq_tdls_sta_stop(struct aicwf_vif *aicwf_vif, u16 reason,
+ struct aicwf_hw *aicwf_hw);
+#endif
+
+void aicwf_txq_add_to_hw_list(struct aicwf_txq *txq);
+void aicwf_txq_del_from_hw_list(struct aicwf_txq *txq);
+void aicwf_txq_stop(struct aicwf_txq *txq, u16 reason);
+void aicwf_txq_start(struct aicwf_txq *txq, u16 reason);
+void aicwf_txq_vif_start(struct aicwf_vif *vif, u16 reason,
+ struct aicwf_hw *aicwf_hw);
+void aicwf_txq_vif_stop(struct aicwf_vif *vif, u16 reason,
+ struct aicwf_hw *aicwf_hw);
+
+#ifdef CONFIG_AICWF_FULLMAC
+void aicwf_txq_sta_start(struct aicwf_sta *sta, u16 reason,
+ struct aicwf_hw *aicwf_hw);
+void aicwf_txq_sta_stop(struct aicwf_sta *sta, u16 reason,
+ struct aicwf_hw *aicwf_hw);
+void aicwf_txq_offchan_start(struct aicwf_hw *aicwf_hw);
+void aicwf_txq_sta_switch_vif(struct aicwf_sta *sta, struct aicwf_vif *old_vif,
+ struct aicwf_vif *new_vif);
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+int aicwf_txq_queue_skb(struct sk_buff *skb, struct aicwf_txq *txq,
+ struct aicwf_hw *aicwf_hw, bool retry);
+void aicwf_txq_confirm_any(struct aicwf_hw *aicwf_hw, struct aicwf_txq *txq,
+ struct aicwf_hwq *hwq, struct aicwf_sw_txhdr *sw_txhdr);
+
+void aicwf_hwq_init(struct aicwf_hw *aicwf_hw);
+void aicwf_hwq_process(struct aicwf_hw *aicwf_hw, struct aicwf_hwq *hwq);
+void aicwf_hwq_process_all(struct aicwf_hw *aicwf_hw);
+void aicwf_txq_flush(struct aicwf_hw *aicwf_hw, struct aicwf_txq *txq);
+
+#endif /* _AICWF_TXQ_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq_prealloc.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq_prealloc.h
new file mode 100644
index 000000000000..ec84a51691a6
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq_prealloc.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_TXQ_PREALLOC_H_
+#define _AICWF_TXQ_PREALLOC_H_
+
+#include <linux/types.h>
+
+/**
+ * struct aicwf_prealloc_txq - TX queue array kept for the lifetime of a device
+ * @txq: The array, %NULL until first requested
+ * @size: Size of @txq in bytes
+ */
+struct aicwf_prealloc_txq {
+ void *txq;
+ size_t size;
+};
+
+#ifdef CONFIG_PREALLOC_TXQ
+void *aicwf_prealloc_txq_alloc(struct aicwf_prealloc_txq *prealloc,
+ size_t size);
+void aicwf_prealloc_txq_free(struct aicwf_prealloc_txq *prealloc);
+#else
+static inline void aicwf_prealloc_txq_free(struct aicwf_prealloc_txq *prealloc)
+{
+}
+#endif
+
+#endif /* _AICWF_TXQ_PREALLOC_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txrxif.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txrxif.c
new file mode 100644
index 000000000000..87e0fe7953f3
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txrxif.c
@@ -0,0 +1,666 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief tx/rx bus function declarations
+ *
+ ******************************************************************************
+ */
+
+#include "aicwf_txrxif.h"
+#include "aicwf_resv_mem.h"
+#include "aicwf_rx_prealloc.h"
+#include "lmac_msg.h"
+#include "aicwf_defs.h"
+#include "aicwf_msg_rx.h"
+#include "aicwf_platform.h"
+#include "aicwf_rx.h"
+#include <linux/atomic.h>
+#include <linux/completion.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/kthread.h>
+#include <linux/netdevice.h>
+#include <linux/printk.h>
+#include <linux/sched.h>
+#include <linux/semaphore.h>
+#include <linux/types.h>
+#include <linux/unaligned.h>
+#include <linux/unistd.h>
+#include <linux/vmalloc.h>
+#include <uapi/linux/sched/types.h>
+#include "aicwf_main.h"
+#include "sdio_host.h"
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+void aicwf_rxframe_queue_init_2(struct rx_frame_queue *pq, int max_len)
+{
+ memset(pq, 0,
+ offsetof(struct rx_frame_queue, queuelist) +
+ (sizeof(struct list_head)));
+ pq->qmax = (u16)max_len;
+ INIT_LIST_HEAD(&pq->queuelist);
+}
+
+void rxbuff_queue_flush(struct aicwf_rx_priv *rx_priv)
+{
+ struct rx_frame_queue *pq = &rx_priv->rxq;
+ struct list_head *pos;
+ struct list_head *n;
+ struct list_head *head;
+ struct rx_buff *tempbuf = NULL;
+
+ head = &pq->queuelist;
+ list_for_each_safe(pos, n, head) {
+ tempbuf = list_entry(pos, struct rx_buff, queue);
+ list_del_init(&tempbuf->queue);
+ aicwf_prealloc_rxbuff_free(tempbuf, &rx_priv->rxbuff_lock);
+ pq->qcnt--;
+ }
+}
+#endif
+
+int aicwf_bus_init(uint bus_hdrlen, struct device *dev)
+{
+ int ret = 0;
+ struct aicwf_bus *bus_if;
+
+ if (!dev) {
+ dev_err(dev, "device not found\n");
+ return -1;
+ }
+ bus_if = dev_get_drvdata(dev);
+ bus_if->cmd_buf = kzalloc(CMD_BUF_MAX, GFP_KERNEL);
+ if (!bus_if->cmd_buf) {
+ ret = -ENOMEM;
+ dev_err(dev, "proto_attach failed\n");
+ goto out;
+ }
+ memset(bus_if->cmd_buf, '\0', CMD_BUF_MAX);
+
+ init_completion(&bus_if->bustx_trgg);
+ init_completion(&bus_if->busrx_trgg);
+ // new oob feature
+ init_completion(&bus_if->busirq_trgg);
+ spin_lock_init(&bus_if->sdiodev->wslock);
+ bus_if->bustx_thread =
+ kthread_run(sdio_bustx_thread, (void *)bus_if, "aicwf_bustx_thread");
+ bus_if->busrx_thread =
+ kthread_run(sdio_busrx_thread, (void *)bus_if->sdiodev->rx_priv,
+ "aicwf_busrx_thread");
+ // new oob feature
+#ifdef CONFIG_OOB
+ if (bus_if->sdiodev->oob_enable) {
+ bus_if->busirq_thread = kthread_run(sdio_busirq_thread,
+ (void *)bus_if->sdiodev->rx_priv,
+ "aicwf_busirq_thread");
+ if (IS_ERR(bus_if->busirq_thread)) {
+ ret = PTR_ERR(bus_if->busirq_thread);
+ bus_if->busirq_thread = NULL;
+ }
+ }
+#endif // CONFIG_OOB
+
+ if (IS_ERR(bus_if->bustx_thread)) {
+ bus_if->bustx_thread = NULL;
+ dev_err(dev, "aicwf_bustx_thread run fail\n");
+ ret = -1;
+ }
+
+ if (IS_ERR(bus_if->busrx_thread)) {
+ bus_if->busrx_thread = NULL;
+ dev_err(dev, "aicwf_busrx_thread run fail\n");
+ ret = -1;
+ }
+
+ if (ret < 0)
+ goto out;
+
+ return ret;
+
+out:
+ return ret;
+}
+
+void aicwf_bus_deinit(struct device *dev)
+{
+ struct aicwf_bus *bus_if = dev_get_drvdata(dev);
+
+ /* Command work and the TX thread have stopped before this point. */
+ kfree(bus_if->cmd_buf);
+ bus_if->cmd_buf = NULL;
+}
+
+void aicwf_frame_tx(void *dev, struct sk_buff *skb)
+{
+ struct aic_sdio_dev *sdiodev = (struct aic_sdio_dev *)dev;
+
+ aicwf_bus_txdata(sdiodev->bus_if, skb);
+}
+
+struct aicwf_tx_priv *aicwf_tx_init(void *arg)
+{
+ struct aicwf_tx_priv *tx_priv;
+ struct device *dev;
+
+ tx_priv =
+ kzalloc_obj(*tx_priv, GFP_KERNEL);
+ if (!tx_priv)
+ return NULL;
+
+ tx_priv->sdiodev = (struct aic_sdio_dev *)arg;
+ dev = tx_priv->sdiodev->dev;
+
+ atomic_set(&tx_priv->aggr_count, 0);
+#ifdef CONFIG_RESV_MEM_SUPPORT
+ tx_priv->aggr_buf = aicwf_resv_mem_alloc_skb(&tx_priv->sdiodev->resv_mem,
+ MAX_AGGR_TXPKT_LEN,
+ AIC_RESV_MEM_TXDATA);
+#else
+ tx_priv->aggr_buf =
+ dev_alloc_skb(MAX_AGGR_TXPKT_LEN);
+#endif
+ if (!tx_priv->aggr_buf) {
+ dev_err(dev, "alloc bus->txdata_buf failed\n");
+ kfree(tx_priv);
+ return NULL;
+ }
+ tx_priv->head = tx_priv->aggr_buf->data;
+ tx_priv->tail = tx_priv->aggr_buf->data;
+
+ return tx_priv;
+}
+
+void aicwf_tx_deinit(struct aicwf_tx_priv *tx_priv)
+{
+ if (tx_priv && tx_priv->aggr_buf) {
+#ifdef CONFIG_RESV_MEM_SUPPORT
+ aicwf_resv_mem_kfree_skb(&tx_priv->sdiodev->resv_mem, tx_priv->aggr_buf,
+ AIC_RESV_MEM_TXDATA);
+#else
+ dev_kfree_skb(tx_priv->aggr_buf);
+#endif
+ kfree(tx_priv);
+ }
+}
+
+/* Validate a complete frame before copying it out of the SDIO aggregate. */
+static bool aicwf_rx_frame_len(const u8 *data, unsigned int remaining,
+ unsigned int *frame_len, unsigned int *consume)
+{
+ unsigned int pkt_len, hdr_len, param_len;
+
+ if (remaining < 4)
+ return false;
+
+ pkt_len = get_unaligned_le16(data);
+ if (!pkt_len)
+ return false;
+
+ *frame_len = pkt_len + ((data[2] & SDIO_TYPE_CFG) ? 4 : RX_HWHRD_LEN);
+ if (*frame_len > remaining)
+ return false;
+
+ if (data[2] & SDIO_TYPE_CFG) {
+ switch (data[2] & 0x7f) {
+ case SDIO_TYPE_CFG_CMD_RSP:
+ hdr_len = offsetof(struct ipc_e2a_msg, param);
+ if (pkt_len < hdr_len)
+ return false;
+ param_len = get_unaligned_le16(data + 4 +
+ offsetof(struct ipc_e2a_msg, param_len));
+ if (param_len > pkt_len - hdr_len ||
+ param_len > sizeof_field(struct ipc_e2a_msg, param))
+ return false;
+ break;
+ case SDIO_TYPE_CFG_DATA_CFM:
+ if (pkt_len < 2 * sizeof(u32))
+ return false;
+ break;
+ }
+ }
+
+ /* The last complete frame need not have trailing alignment padding. */
+ *consume = min_t(unsigned int, ALIGN(*frame_len, RX_ALIGNMENT), remaining);
+ return true;
+}
+
+int aicwf_process_rxframes(struct aicwf_rx_priv *rx_priv)
+{
+ int ret = 0;
+ unsigned long flags = 0;
+#ifndef CONFIG_PREALLOC_RX_SKB
+ struct sk_buff *skb = NULL;
+#endif
+ struct sk_buff *skb_inblock = NULL;
+ unsigned int aggr_len, adjust_len;
+ u8 *data = NULL;
+ u8 *msg = NULL;
+#ifdef CONFIG_PREALLOC_RX_SKB
+ struct rx_buff *buffer = NULL;
+
+ while (1) {
+ spin_lock_irqsave(&rx_priv->rxqlock, flags);
+ if (!rx_priv->rxq.qcnt) {
+ spin_unlock_irqrestore(&rx_priv->rxqlock, flags);
+ break;
+ }
+ buffer = rxbuff_dequeue(&rx_priv->rxq);
+ spin_unlock_irqrestore(&rx_priv->rxqlock, flags);
+ if (!buffer) {
+ dev_err(rx_priv->sdiodev->dev, "skb_error\n");
+ break;
+ }
+ while (aicwf_rx_frame_len(buffer->read, buffer->end - buffer->read,
+ &aggr_len, &adjust_len)) {
+ data = buffer->read;
+
+ if ((data[2] & SDIO_TYPE_CFG) != SDIO_TYPE_CFG) {
+ // type: data
+ skb_inblock =
+ __dev_alloc_skb(aggr_len + CCMP_OR_WEP_INFO, GFP_KERNEL);
+ if (!skb_inblock) {
+ dev_err(rx_priv->sdiodev->dev, "no more space! skip\n");
+ buffer->read = buffer->read + adjust_len;
+ continue;
+ }
+
+ skb_put(skb_inblock, aggr_len);
+ memcpy(skb_inblock->data, data, aggr_len);
+ aicwf_rxdataind(rx_priv->sdiodev->aicwf_hw, skb_inblock,
+ (void *)rx_priv);
+ buffer->read = buffer->read + adjust_len;
+ } else {
+ // type: config
+ msg =
+ kmalloc(aggr_len, GFP_KERNEL);
+ if (!msg) {
+ dev_err(rx_priv->sdiodev->dev, "no more space for msg\n");
+ ret = -ENOMEM;
+ break;
+ }
+
+ memcpy(msg, data, aggr_len);
+ if (((*(msg + 2) & 0x7f) == SDIO_TYPE_CFG_CMD_RSP) &&
+ rx_priv->sdiodev->bus_if->state != BUS_DOWN_ST)
+ aicwf_rx_handle_msg(rx_priv->sdiodev->aicwf_hw,
+ (struct ipc_e2a_msg *)(msg + 4));
+
+ if ((*(msg + 2) & 0x7f) == SDIO_TYPE_CFG_DATA_CFM)
+ aicwf_sdio_host_tx_cfm_handler(&(rx_priv->sdiodev
+ ->aicwf_hw->sdio_env),
+ (u32 *)(msg + 4));
+
+ if ((*(msg + 2) & 0x7f) == SDIO_TYPE_CFG_PRINT)
+ aicwf_rx_handle_print(rx_priv->sdiodev->aicwf_hw, msg + 4,
+ aggr_len - 4);
+
+ buffer->read = buffer->read + adjust_len;
+ kfree(msg);
+ }
+ }
+
+ aicwf_prealloc_rxbuff_free(buffer, &rx_priv->rxbuff_lock);
+
+ atomic_dec(&rx_priv->rx_cnt);
+ }
+
+#else
+
+ while (1) {
+ spin_lock_irqsave(&rx_priv->rxqlock, flags);
+ if (aicwf_is_framequeue_empty(&rx_priv->rxq)) {
+ spin_unlock_irqrestore(&rx_priv->rxqlock, flags);
+ break;
+ }
+ skb = aicwf_frame_dequeue(&rx_priv->rxq);
+ spin_unlock_irqrestore(&rx_priv->rxqlock, flags);
+ if (!skb) {
+ dev_err(rx_priv->sdiodev->dev, "skb_error\n");
+ break;
+ }
+ while (aicwf_rx_frame_len(skb->data, skb->len,
+ &aggr_len, &adjust_len)) {
+ data = skb->data;
+
+ if ((skb->data[2] & SDIO_TYPE_CFG) != SDIO_TYPE_CFG) {
+ // type: data
+ skb_inblock =
+ __dev_alloc_skb(aggr_len + CCMP_OR_WEP_INFO, GFP_KERNEL);
+ if (!skb_inblock) {
+ dev_err(rx_priv->sdiodev->dev, "no more space! skip\n");
+ skb_pull(skb, adjust_len);
+ continue;
+ }
+
+ skb_put(skb_inblock, aggr_len);
+ memcpy(skb_inblock->data, data, aggr_len);
+ aicwf_rxdataind(rx_priv->sdiodev->aicwf_hw, skb_inblock,
+ (void *)rx_priv);
+ skb_pull(skb, adjust_len);
+ } else {
+ // type: config
+ msg =
+ kmalloc(aggr_len, GFP_KERNEL);
+ if (!msg) {
+ dev_err(rx_priv->sdiodev->dev, "no more space for msg\n");
+ ret = -ENOMEM;
+ break;
+ }
+
+ memcpy(msg, data, aggr_len);
+ if (((*(msg + 2) & 0x7f) == SDIO_TYPE_CFG_CMD_RSP) &&
+ rx_priv->sdiodev->bus_if->state != BUS_DOWN_ST)
+ aicwf_rx_handle_msg(rx_priv->sdiodev->aicwf_hw,
+ (struct ipc_e2a_msg *)(msg + 4));
+
+ struct sdio_host_env_tag *env =
+ &rx_priv->sdiodev->aicwf_hw->sdio_env;
+ if ((*(msg + 2) & 0x7f) == SDIO_TYPE_CFG_DATA_CFM)
+ aicwf_sdio_host_tx_cfm_handler(env, (u32 *)(msg + 4));
+
+ if ((*(msg + 2) & 0x7f) == SDIO_TYPE_CFG_PRINT)
+ aicwf_rx_handle_print(rx_priv->sdiodev->aicwf_hw,
+ msg + 4, aggr_len - 4);
+
+ skb_pull(skb, adjust_len);
+ kfree(msg);
+ }
+ }
+
+ dev_kfree_skb(skb);
+ atomic_dec(&rx_priv->rx_cnt);
+ }
+#endif
+
+#if defined(CONFIG_AIC8800_SDIO_PWRCTRL)
+ aicwf_sdio_pwr_stctl(rx_priv->sdiodev, SDIO_ACTIVE_ST);
+#endif
+
+ return ret;
+}
+
+static struct recv_msdu *aicwf_rxframe_queue_init(struct list_head *q,
+ int qsize)
+{
+ int i;
+ struct recv_msdu *req, *reqs;
+
+ reqs = vmalloc(qsize * sizeof(struct recv_msdu));
+ if (!reqs)
+ return NULL;
+
+ req = reqs;
+ for (i = 0; i < qsize; i++) {
+ INIT_LIST_HEAD(&req->rxframe_list);
+ list_add(&req->rxframe_list, q);
+ req++;
+ }
+
+ return reqs;
+}
+
+struct aicwf_rx_priv *aicwf_rx_init(void *arg)
+{
+ struct aicwf_rx_priv *rx_priv;
+ struct device *dev;
+
+ rx_priv = kzalloc_obj(*rx_priv, GFP_KERNEL);
+ if (!rx_priv)
+ return NULL;
+
+ rx_priv->sdiodev = (struct aic_sdio_dev *)arg;
+ dev = rx_priv->sdiodev->dev;
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+ aicwf_rxframe_queue_init_2(&rx_priv->rxq, MAX_RXQLEN);
+#else
+ aicwf_frame_queue_init(&rx_priv->rxq, 1, MAX_RXQLEN);
+#endif
+ spin_lock_init(&rx_priv->rxqlock);
+#ifdef CONFIG_PREALLOC_RX_SKB
+ spin_lock_init(&rx_priv->rxbuff_lock);
+ aicwf_prealloc_init();
+#endif
+ atomic_set(&rx_priv->rx_cnt, 0);
+
+#ifdef CONFIG_AIC8800_RX_REORDER
+ struct list_head *q = &rx_priv->rxframes_freequeue;
+
+ INIT_LIST_HEAD(&rx_priv->rxframes_freequeue);
+ spin_lock_init(&rx_priv->freeq_lock);
+ rx_priv->recv_frames = aicwf_rxframe_queue_init(q, MAX_REORD_RXFRAME);
+ if (!rx_priv->recv_frames) {
+ dev_err(dev, "no enough buffer for free recv frame queue\n");
+ kfree(rx_priv);
+ return NULL;
+ }
+ spin_lock_init(&rx_priv->stas_reord_lock);
+ INIT_LIST_HEAD(&rx_priv->stas_reord_list);
+#endif
+
+ return rx_priv;
+}
+
+static void aicwf_recvframe_queue_deinit(struct list_head *q)
+{
+ struct recv_msdu *req, *next;
+
+ list_for_each_entry_safe(req, next, q, rxframe_list) {
+ list_del_init(&req->rxframe_list);
+ }
+}
+
+void aicwf_rx_deinit(struct aicwf_rx_priv *rx_priv)
+{
+#ifdef CONFIG_AIC8800_RX_REORDER
+ struct reord_ctrl_info *reord_info, *tmp;
+
+ spin_lock_bh(&rx_priv->stas_reord_lock);
+ list_for_each_entry_safe(reord_info, tmp, &rx_priv->stas_reord_list, list) {
+ reord_deinit_sta(rx_priv, reord_info);
+ }
+ spin_unlock_bh(&rx_priv->stas_reord_lock);
+#endif
+
+ pr_debug("sdio rx thread\n");
+ if (rx_priv->sdiodev->bus_if->busrx_thread) {
+ sched_set_normal(rx_priv->sdiodev->bus_if->busrx_thread, 0);
+ complete_all(&rx_priv->sdiodev->bus_if->busrx_trgg);
+ kthread_stop(rx_priv->sdiodev->bus_if->busrx_thread);
+ rx_priv->sdiodev->bus_if->busrx_thread = NULL;
+ }
+#ifdef CONFIG_OOB
+ if (rx_priv->sdiodev->oob_enable) {
+ // new oob feature
+ if (rx_priv->sdiodev->bus_if->busirq_thread) {
+ complete_all(&rx_priv->sdiodev->bus_if->busirq_trgg);
+ kthread_stop(rx_priv->sdiodev->bus_if->busirq_thread);
+ rx_priv->sdiodev->bus_if->busirq_thread = NULL;
+ }
+ }
+#endif // CONFIG_OOB
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+ rxbuff_queue_flush(rx_priv);
+#else
+ aicwf_frame_queue_flush(&rx_priv->rxq);
+#endif
+
+#ifdef CONFIG_AIC8800_RX_REORDER
+ aicwf_recvframe_queue_deinit(&rx_priv->rxframes_freequeue);
+ if (rx_priv->recv_frames)
+ vfree(rx_priv->recv_frames);
+#endif
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+ aicwf_prealloc_exit();
+#endif
+ kfree(rx_priv);
+}
+
+bool aicwf_rxframe_enqueue(struct device *dev, struct frame_queue *q,
+ struct sk_buff *pkt)
+{
+ return aicwf_frame_enq(dev, q, pkt, 0);
+}
+
+void aicwf_dev_skb_free(struct sk_buff *skb)
+{
+ if (!skb)
+ return;
+
+ dev_kfree_skb_any(skb);
+}
+
+static struct sk_buff *aicwf_frame_queue_penq(struct frame_queue *pq, int prio,
+ struct sk_buff *p)
+{
+ struct sk_buff_head *q;
+
+ if (pq->queuelist[prio].qlen >= pq->qmax)
+ return NULL;
+
+ q = &pq->queuelist[prio];
+ __skb_queue_tail(q, p);
+ pq->qcnt++;
+ if (pq->hi_prio < prio)
+ pq->hi_prio = (u16)prio;
+
+ return p;
+}
+
+void aicwf_frame_queue_flush(struct frame_queue *pq)
+{
+ int prio;
+ struct sk_buff_head *q;
+ struct sk_buff *p, *next;
+
+ for (prio = 0; prio < pq->num_prio; prio++) {
+ q = &pq->queuelist[prio];
+ skb_queue_walk_safe(q, p, next)
+ {
+ skb_unlink(p, q);
+ aicwf_dev_skb_free(p);
+ pq->qcnt--;
+ }
+ }
+}
+
+void aicwf_frame_queue_init(struct frame_queue *pq, int num_prio, int max_len)
+{
+ int prio;
+
+ memset(pq, 0,
+ offsetof(struct frame_queue, queuelist) +
+ (sizeof(struct sk_buff_head) * num_prio));
+ pq->num_prio = (u16)num_prio;
+ pq->qmax = (u16)max_len;
+
+ for (prio = 0; prio < num_prio; prio++)
+ skb_queue_head_init(&pq->queuelist[prio]);
+}
+
+bool aicwf_is_framequeue_empty(struct frame_queue *pq)
+{
+ int prio, len = 0;
+
+ for (prio = 0; prio <= pq->hi_prio; prio++)
+ len += pq->queuelist[prio].qlen;
+
+ if (len > 0)
+ return false;
+ else
+ return true;
+}
+
+struct sk_buff *aicwf_frame_dequeue(struct frame_queue *pq)
+{
+ struct sk_buff_head *q;
+ struct sk_buff *p;
+ int prio;
+
+ if (pq->qcnt == 0)
+ return NULL;
+
+ while ((prio = pq->hi_prio) > 0 && skb_queue_empty(&pq->queuelist[prio]))
+ pq->hi_prio--;
+
+ q = &pq->queuelist[prio];
+ p = __skb_dequeue(q);
+ if (!p)
+ return NULL;
+
+ pq->qcnt--;
+
+ return p;
+}
+
+bool aicwf_frame_enq(struct device *dev, struct frame_queue *q,
+ struct sk_buff *pkt, int prio)
+{
+ if (q->queuelist[prio].qlen < q->qmax && q->qcnt < q->qmax) {
+ aicwf_frame_queue_penq(q, prio, pkt);
+ return true;
+ }
+ return false;
+}
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+
+static struct rx_buff *rxbuff_queue_penq(struct rx_frame_queue *pq,
+ struct rx_buff *p)
+{
+ struct list_head *q;
+
+ if (pq->qcnt >= pq->qmax)
+ return NULL;
+
+ q = &pq->queuelist;
+ list_add_tail(&p->queue, q);
+
+ pq->qcnt++;
+
+ return p;
+}
+
+struct rx_buff *rxbuff_dequeue(struct rx_frame_queue *pq)
+{
+ struct rx_buff *p = NULL;
+
+ if (pq->qcnt == 0) {
+ pr_err("%d, rxq is empty\n", __LINE__);
+ return NULL;
+ }
+
+ if (list_empty(&pq->queuelist)) {
+ pr_err("%d, rxq is empty\n", __LINE__);
+ return NULL;
+ }
+ p = list_first_entry(&pq->queuelist, struct rx_buff, queue);
+ list_del_init(&p->queue);
+ pq->qcnt--;
+
+ return p;
+}
+
+bool aicwf_rxbuff_enqueue(struct device *dev, struct rx_frame_queue *rxq,
+ struct rx_buff *pkt)
+{
+ if (!rxq || !pkt) {
+ dev_err(dev, "%d, rxq or pkt is NULL\n", __LINE__);
+ return false;
+ }
+
+ if (rxq->qcnt < rxq->qmax) {
+ if (rxbuff_queue_penq(rxq, pkt))
+ return true;
+ dev_err(dev, "%d, rxbuff enqueue fail\n", __LINE__);
+ return false;
+ }
+ dev_err(dev, "%d, rxq or pkt is full\n", __LINE__);
+ return false;
+}
+#endif
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txrxif.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txrxif.h
new file mode 100644
index 000000000000..8ba2dd26b365
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txrxif.h
@@ -0,0 +1,161 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _AICWF_TXRXIF_H_
+#define _AICWF_TXRXIF_H_
+
+#include "aicwf_rx_prealloc.h"
+#include "ipc_shared.h"
+#include <linux/sched.h>
+#include <linux/skbuff.h>
+#include "aicwf_sdio.h"
+#include "aic_bus.h"
+
+#define CMD_BUF_MAX 1536
+#define TXPKT_BLOCKSIZE 512
+#define MAX_AGGR_TXPKT_LEN (1536 * 64)
+#define CMD_TX_TIMEOUT 5000
+#define TX_ALIGNMENT 4
+
+#define RX_HWHRD_LEN 60 // 58->60 word allined
+#define CCMP_OR_WEP_INFO 8
+#define MAX_RXQLEN 2000
+#define RX_ALIGNMENT 4
+
+#define DEFRAG_MAX_WAIT 40 // 100
+
+#ifdef CONFIG_AIC8800_RX_REORDER
+#define MAX_REORD_RXFRAME 250
+#define REORDER_UPDATE_TIME 100//50
+#define AICWF_REORDER_WINSIZE 64
+#define SN_LESS(a, b) ((((a) - (b)) & 0x800) != 0)
+#define SN_EQUAL(a, b) ((a) == (b))
+#endif
+
+struct frame_queue {
+ u16 num_prio;
+ u16 hi_prio;
+ u16 qmax; /* max number of queued frames */
+ u16 qcnt;
+ struct sk_buff_head queuelist[8];
+};
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+struct rx_frame_queue {
+ u16 qmax; /* max number of queued frames */
+ u16 qcnt;
+ struct list_head queuelist;
+};
+#endif
+
+struct aicwf_tx_priv {
+ struct aic_sdio_dev *sdiodev;
+ int fw_avail_bufcnt;
+ // for cmd tx
+ u8 *cmd_buf;
+ uint cmd_len;
+ bool cmd_txstate;
+ bool cmd_tx_succ;
+ struct semaphore cmd_txsema;
+ wait_queue_head_t cmd_txdone_wait;
+ // for data tx
+ atomic_t tx_pktcnt;
+
+ struct frame_queue txq;
+ /* lock for tx */
+ spinlock_t txqlock;
+ struct semaphore txctl_sema;
+ struct sk_buff *aggr_buf;
+ atomic_t aggr_count;
+ u8 *head;
+ u8 *tail;
+};
+
+#ifdef CONFIG_AIC8800_RX_REORDER
+struct reord_ctrl {
+ struct aicwf_rx_priv *rx_priv;
+ u8 enable;
+ u16 ind_sn;
+ u8 wsize_b;
+ /* lock for reord_list */
+ spinlock_t reord_list_lock;
+ struct list_head reord_list;
+ struct timer_list reord_timer;
+ struct work_struct reord_timer_work;
+};
+
+struct reord_ctrl_info {
+ u8 mac_addr[6];
+ struct reord_ctrl preorder_ctrl[8];
+ struct list_head list;
+};
+
+struct recv_msdu {
+ struct sk_buff *pkt;
+ u8 tid;
+ u16 seq_num;
+ u8 forward;
+ u32 is_amsdu;
+ u8 *rx_data;
+ // for pending rx reorder list
+ struct list_head reord_pending_list;
+ // for total frame list, when rxframe from busif, dequeue, when submit frame
+ // to net, enqueue
+ struct list_head rxframe_list;
+ struct reord_ctrl *preorder_ctrl;
+};
+#endif
+
+struct aicwf_rx_priv {
+ struct aic_sdio_dev *sdiodev;
+ void *aicwf_vif;
+ atomic_t rx_cnt;
+ u32 data_len;
+ /* lock for aicwf_rx */
+ spinlock_t rxqlock;
+#ifdef CONFIG_PREALLOC_RX_SKB
+ struct rx_frame_queue rxq;
+#else
+ struct frame_queue rxq;
+#endif
+
+#ifdef CONFIG_AIC8800_RX_REORDER
+ /* lock for freeq */
+ spinlock_t freeq_lock;
+ struct list_head rxframes_freequeue;
+ struct list_head stas_reord_list;
+ /* lock for stas reord */
+ spinlock_t stas_reord_lock;
+ struct recv_msdu *recv_frames;
+#endif
+#ifdef CONFIG_PREALLOC_RX_SKB
+ /* lock for rxbuff */
+ spinlock_t rxbuff_lock;
+#endif
+};
+
+void aicwf_tx_deinit(struct aicwf_tx_priv *tx_priv);
+void aicwf_rx_deinit(struct aicwf_rx_priv *rx_priv);
+struct aicwf_tx_priv *aicwf_tx_init(void *arg);
+struct aicwf_rx_priv *aicwf_rx_init(void *arg);
+void aicwf_frame_queue_init(struct frame_queue *pq, int num_prio, int max_len);
+void aicwf_frame_queue_flush(struct frame_queue *pq);
+bool aicwf_frame_enq(struct device *dev, struct frame_queue *q,
+ struct sk_buff *pkt, int prio);
+bool aicwf_rxframe_enqueue(struct device *dev, struct frame_queue *q,
+ struct sk_buff *pkt);
+bool aicwf_is_framequeue_empty(struct frame_queue *pq);
+void aicwf_frame_tx(void *dev, struct sk_buff *skb);
+void aicwf_dev_skb_free(struct sk_buff *skb);
+struct sk_buff *aicwf_frame_dequeue(struct frame_queue *pq);
+#ifdef CONFIG_PREALLOC_RX_SKB
+void rxbuff_queue_flush(struct aicwf_rx_priv *rx_priv);
+void aicwf_rxframe_queue_init_2(struct rx_frame_queue *pq, int max_len);
+struct rx_buff *rxbuff_dequeue(struct rx_frame_queue *pq);
+bool aicwf_rxbuff_enqueue(struct device *dev, struct rx_frame_queue *rxq,
+ struct rx_buff *pkt);
+#endif
+
+#endif /* _AICWF_TXRXIF_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_utils.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_utils.c
new file mode 100644
index 000000000000..72093a0af26b
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_utils.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ****************************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file aicwf_utils.c
+ *
+ * @brief IPC utility function declarations
+ *
+ ****************************************************************************************
+ */
+
+#include "aicwf_utils.h"
+#include "aicwf_defs.h"
+#include "aicwf_msg_rx.h"
+#include "aicwf_rx.h"
+#include "aicwf_tx.h"
+
+int aicwf_init_aic(struct aicwf_hw *aicwf_hw)
+{
+ int ret;
+
+ aicwf_sdio_host_init(&aicwf_hw->sdio_env, NULL, NULL, aicwf_hw);
+ ret = aicwf_cmd_mgr_init(aicwf_hw->cmd_mgr);
+ if (ret)
+ return ret;
+
+ aicwf_hw->testmode = 0;
+
+ return 0;
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_utils.h b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_utils.h
new file mode 100644
index 000000000000..26cef77a0904
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_utils.h
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ****************************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file aicwf_utils.h
+ *
+ * @brief IPC utility function declarations
+ *
+ ****************************************************************************************
+ */
+
+#ifndef _AICWF_IPC_UTILS_H_
+#define _AICWF_IPC_UTILS_H_
+
+#include <linux/dma-mapping.h>
+#include <linux/skbuff.h>
+#include "lmac_msg.h"
+#include "aicwf_config.h"
+
+/*
+ * Maximum Length of Radiotap header vendor specific data(in bytes)
+ */
+#define RADIOTAP_HDR_VEND_MAX_LEN 16
+
+/*
+ * Maximum Radiotap Header Length without vendor specific data (in bytes)
+ */
+#define RADIOTAP_HDR_MAX_LEN 80
+
+/*
+ * Unsupported HT Frame data length (in bytes)
+ */
+#define UNSUP_RX_VEC_DATA_LEN 2
+
+struct aicwf_hw;
+struct aicwf_sta;
+
+enum aicwf_dev_flag {
+ AICWF_DEV_RESTARTING,
+ AICWF_DEV_STACK_RESTARTING,
+ AICWF_DEV_STARTED,
+};
+
+/**
+ * struct aicwf_ipc_elem_var - Generic IPC buffer of variable size
+ *
+ * @addr: Host address of the buffer.
+ * @dma_addr: DMA address of the buffer.
+ * @size: Size, in bytes, of the buffer
+ */
+struct aicwf_ipc_elem_var {
+ void *addr;
+ dma_addr_t dma_addr;
+ size_t size;
+};
+
+int aicwf_init_aic(struct aicwf_hw *aicwf_hw);
+
+#endif /* _AICWF_IPC_UTILS_H_ */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/hal_desc.h b/drivers/net/wireless/aic/aic8800_fdrv/hal_desc.h
new file mode 100644
index 000000000000..b7a96c8a4c8f
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/hal_desc.h
@@ -0,0 +1,359 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file hal_desc.c
+ *
+ * @brief File containing the definition of HW descriptors
+ *
+ ******************************************************************************
+ */
+
+#ifndef _HAL_DESC_H_
+#define _HAL_DESC_H_
+
+#include "lmac_types.h"
+#include "aicwf_config.h"
+
+/* Rate and policy table */
+
+#define N_CCK 8
+#define N_OFDM 8
+#define N_HT (8 * 2 * 2 * 4)
+#define N_VHT (10 * 4 * 2 * 8)
+#define N_HE_SU (12 * 4 * 3 * 8)
+#define N_HE_MU (12 * 6 * 3 * 8)
+#define N_HE_ER (3 * 3 + 3) // RU242 + RU106
+
+/* Values for formatModTx */
+#define FORMATMOD_NON_HT 0
+#define FORMATMOD_NON_HT_DUP_OFDM 1
+#define FORMATMOD_HT_MF 2
+#define FORMATMOD_HT_GF 3
+#define FORMATMOD_VHT 4
+#define FORMATMOD_HE_SU 5
+#define FORMATMOD_HE_MU 6
+#define FORMATMOD_HE_ER 7
+#define FORMATMOD_HE_TB 8
+
+/* Values for navProtFrmEx */
+#define NAV_PROT_NO_PROT_BIT 0
+#define NAV_PROT_SELF_CTS_BIT 1
+#define NAV_PROT_RTS_CTS_BIT 2
+#define NAV_PROT_RTS_CTS_WITH_QAP_BIT 3
+#define NAV_PROT_STBC_BIT 4
+
+/* THD MACCTRLINFO2 fields, used in struct umacdesc umac.flags */
+/// WhichDescriptor definition - contains aMPDU bit and position value
+/// Offset of WhichDescriptor field in the MAC CONTROL INFO 2 word
+#define WHICHDESC_OFT 19
+/// Mask of the WhichDescriptor field
+#define WHICHDESC_MSK (0x07 << WHICHDESC_OFT)
+/// Only 1 THD possible, describing an unfragmented MSDU
+#define WHICHDESC_UNFRAGMENTED_MSDU (0x00 << WHICHDESC_OFT)
+/// THD describing the first MPDU of a fragmented MSDU
+#define WHICHDESC_FRAGMENTED_MSDU_FIRST (0x01 << WHICHDESC_OFT)
+/// THD describing intermediate MPDUs of a fragmented MSDU
+#define WHICHDESC_FRAGMENTED_MSDU_INT (0x02 << WHICHDESC_OFT)
+/// THD describing the last MPDU of a fragmented MSDU
+#define WHICHDESC_FRAGMENTED_MSDU_LAST (0x03 << WHICHDESC_OFT)
+/// THD for extra descriptor starting an AMPDU
+#define WHICHDESC_AMPDU_EXTRA (0x04 << WHICHDESC_OFT)
+/// THD describing the first MPDU of an A-MPDU
+#define WHICHDESC_AMPDU_FIRST (0x05 << WHICHDESC_OFT)
+/// THD describing intermediate MPDUs of an A-MPDU
+#define WHICHDESC_AMPDU_INT (0x06 << WHICHDESC_OFT)
+/// THD describing the last MPDU of an A-MPDU
+#define WHICHDESC_AMPDU_LAST (0x07 << WHICHDESC_OFT)
+
+/// aMPDU bit offset
+#define AMPDU_OFT 21
+/// aMPDU bit
+#define AMPDU_BIT CO_BIT(AMPDU_OFT)
+
+union aicwf_mcs_index {
+ struct {
+ u32 mcs : 3;
+ u32 nss : 2;
+ } ht;
+ struct {
+ u32 mcs : 4;
+ u32 nss : 3;
+ } vht;
+ struct {
+ u32 mcs : 4;
+ u32 nss : 3;
+ } he;
+ u32 legacy : 7;
+};
+
+/* c.f RW-WLAN-nX-MAC-HW-UM */
+union aicwf_rate_ctrl_info {
+ struct {
+ u32 mcs_index_tx : 7;
+ u32 bw_tx : 2;
+ u32 gi_and_pre_type_tx : 2;
+ u32 format_mod_tx : 3;
+ u32 nav_prot_frm_ex : 3;
+ u32 mcs_index_prot_tx : 7;
+ u32 bw_prot_tx : 2;
+ u32 format_mod_prot_tx : 3;
+ u32 n_retry : 3;
+ };
+ u32 value;
+};
+
+/* c.f RW-WLAN-nX-MAC-HW-UM */
+struct aicwf_power_ctrl_info {
+ u32 tx_pwr_level_pt : 8;
+ u32 tx_pwr_level_prot_pt : 8;
+ u32 reserved : 16;
+};
+
+/* c.f RW-WLAN-nX-MAC-HW-UM */
+union aicwf_pol_phy_ctrl_info_1 {
+ struct {
+ u32 rsvd1 : 3;
+ u32 bf_frm_ex : 1;
+ u32 num_extn_ss : 2;
+ u32 fec_coding : 1;
+ u32 stbc : 2;
+ u32 rsvd2 : 5;
+ u32 n_tx : 3;
+ u32 n_tx_prot : 3;
+ };
+ u32 value;
+};
+
+/* c.f RW-WLAN-nX-MAC-HW-UM */
+union aicwf_pol_phy_ctrl_info_2 {
+ struct {
+ u32 antenna_set : 8;
+ u32 smm_index : 8;
+ u32 beam_formed : 1;
+ };
+ u32 value;
+};
+
+/* c.f RW-WLAN-nX-MAC-HW-UM */
+union aicwf_pol_mac_ctrl_info_1 {
+ struct {
+ u32 key_sram_index : 10;
+ u32 key_sram_index_ra : 10;
+ };
+ u32 value;
+};
+
+/* c.f RW-WLAN-nX-MAC-HW-UM */
+union aicwf_pol_mac_ctrl_info_2 {
+ struct {
+ u32 long_retry_limit : 8;
+ u32 short_retry_limit : 8;
+ u32 rts_threshold : 12;
+ };
+ u32 value;
+};
+
+#define POLICY_TABLE_PATTERN 0xBADCAB1E
+
+struct tx_policy_tbl {
+ /* Unique Pattern at the start of Policy Table */
+ u32 upatterntx;
+ /* PHY Control 1 Information used by MAC HW */
+ union aicwf_pol_phy_ctrl_info_1 phyctrlinfo_1;
+ /* PHY Control 2 Information used by MAC HW */
+ union aicwf_pol_phy_ctrl_info_2 phyctrlinfo_2;
+ /* MAC Control 1 Information used by MAC HW */
+ union aicwf_pol_mac_ctrl_info_1 macctrlinfo_1;
+ /* MAC Control 2 Information used by MAC HW */
+ union aicwf_pol_mac_ctrl_info_2 macctrlinfo_2;
+
+ union aicwf_rate_ctrl_info ratectrlinfos[NX_TX_MAX_RATES];
+ struct aicwf_power_ctrl_info powerctrlinfos[NX_TX_MAX_RATES];
+};
+
+#ifdef CONFIG_AICWF_FULLMAC
+
+/**
+ * union aicwf_hw_txstatus - Bitfield of confirmation status
+ *
+ * @tx_done: Packet has been processed by the firmware
+ * @retry_required: Packet was transmitted but not acknowledged and must be
+ * submitted again by the driver
+ * @sw_retry_required: Packet was not transmitted by the firmware and must be
+ * submitted again by the driver
+ * @acknowledged: Packet was acknowledged by the peer
+ * @reserved: Reserved status bits
+ * @value: Complete status word
+ */
+union aicwf_hw_txstatus {
+ struct {
+ u32 tx_done : 1;
+ u32 retry_required : 1;
+ u32 sw_retry_required : 1;
+ u32 acknowledged : 1;
+ u32 reserved : 28;
+ };
+ u32 value;
+};
+
+/**
+ * struct tx_cfm_tag - Structure indicating the status and other
+ * information about the transmission
+ *
+ * @credits: Number of credits returned to the TX queue (0 or 1)
+ * @ampdu_size: Number of frames in the A-MPDU when this was its last frame,
+ * 0 when this was not the last frame, or 1 for a singleton
+ * @amsdu_size: Maximum A-MSDU size in bytes
+ * @status: Transmission status
+ * @hostid: Host identifier of the transmitted buffer
+ */
+struct tx_cfm_tag {
+ /*
+ * u16 pn[4];
+ * u16 sn;
+ * u16 timestamp;
+ */
+ s8 credits;
+ u8 ampdu_size;
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+ u16 amsdu_size;
+#endif
+ union aicwf_hw_txstatus status;
+ u32 hostid;
+};
+
+/**
+ * struct aicwf_hw_txhdr - Hardware part of tx header
+ *
+ * @cfm: Information updated by fw/hardware after sending a frame
+ */
+struct aicwf_hw_txhdr {
+ struct tx_cfm_tag cfm;
+};
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+/* Modem */
+
+#define MDM_PHY_CONFIG_TRIDENT 0
+#define MDM_PHY_CONFIG_ELMA 1
+#define MDM_PHY_CONFIG_KARST 2
+
+// MODEM features (from reg_mdm_stat.h)
+/// MUMIMOTX field bit
+#define MDM_MUMIMOTX_BIT ((u32)0x80000000)
+/// MUMIMOTX field position
+#define MDM_MUMIMOTX_POS 31
+/// MUMIMORX field bit
+#define MDM_MUMIMORX_BIT ((u32)0x40000000)
+/// MUMIMORX field position
+#define MDM_MUMIMORX_POS 30
+/// BFMER field bit
+#define MDM_BFMER_BIT ((u32)0x20000000)
+/// BFMER field position
+#define MDM_BFMER_POS 29
+/// BFMEE field bit
+#define MDM_BFMEE_BIT ((u32)0x10000000)
+/// BFMEE field position
+#define MDM_BFMEE_POS 28
+/// LDPCDEC field bit
+#define MDM_LDPCDEC_BIT ((u32)0x08000000)
+/// LDPCDEC field position
+#define MDM_LDPCDEC_POS 27
+/// LDPCENC field bit
+#define MDM_LDPCENC_BIT ((u32)0x04000000)
+/// LDPCENC field position
+#define MDM_LDPCENC_POS 26
+/// CHBW field mask
+#define MDM_CHBW_MASK ((u32)0x03000000)
+/// CHBW field LSB position
+#define MDM_CHBW_LSB 24
+/// CHBW field width
+#define MDM_CHBW_WIDTH ((u32)0x00000002)
+/// DSSSCCK field bit
+#define MDM_DSSSCCK_BIT ((u32)0x00800000)
+/// DSSSCCK field position
+#define MDM_DSSSCCK_POS 23
+/// VHT field bit
+#define MDM_VHT_BIT ((u32)0x00400000)
+/// VHT field position
+#define MDM_VHT_POS 22
+/// HE field bit
+#define MDM_HE_BIT ((u32)0x00200000)
+/// HE field position
+#define MDM_HE_POS 21
+/// ESS field bit
+#define MDM_ESS_BIT ((u32)0x00100000)
+/// ESS field position
+#define MDM_ESS_POS 20
+/// RFMODE field mask
+#define MDM_RFMODE_MASK ((u32)0x000F0000)
+/// RFMODE field LSB position
+#define MDM_RFMODE_LSB 16
+/// RFMODE field width
+#define MDM_RFMODE_WIDTH ((u32)0x00000004)
+/// NSTS field mask
+#define MDM_NSTS_MASK ((u32)0x0000F000)
+/// NSTS field LSB position
+#define MDM_NSTS_LSB 12
+/// NSTS field width
+#define MDM_NSTS_WIDTH ((u32)0x00000004)
+/// NSS field mask
+#define MDM_NSS_MASK ((u32)0x00000F00)
+/// NSS field LSB position
+#define MDM_NSS_LSB 8
+/// NSS field width
+#define MDM_NSS_WIDTH ((u32)0x00000004)
+/// NTX field mask
+#define MDM_NTX_MASK ((u32)0x000000F0)
+/// NTX field LSB position
+#define MDM_NTX_LSB 4
+/// NTX field width
+#define MDM_NTX_WIDTH ((u32)0x00000004)
+/// NRX field mask
+#define MDM_NRX_MASK ((u32)0x0000000F)
+/// NRX field LSB position
+#define MDM_NRX_LSB 0
+/// NRX field width
+#define MDM_NRX_WIDTH ((u32)0x00000004)
+
+#define __MDM_PHYCFG_FROM_VERS(v) (((v) & MDM_RFMODE_MASK) >> MDM_RFMODE_LSB)
+
+#define RIU_FCU_PRESENT_MASK ((u32)0xFF000000)
+#define RIU_FCU_PRESENT_LSB 24
+
+#define __RIU_FCU_PRESENT(v) \
+ (((v) & RIU_FCU_PRESENT_MASK) >> RIU_FCU_PRESENT_LSB == 5)
+
+/// AGC load version field mask
+#define RIU_AGC_LOAD_MASK ((u32)0x00C00000)
+/// AGC load version field LSB position
+#define RIU_AGC_LOAD_LSB 22
+
+#define __RIU_AGCLOAD_FROM_VERS(v) \
+ (((v) & RIU_AGC_LOAD_MASK) >> RIU_AGC_LOAD_LSB)
+
+#define __FPGA_TYPE(v) (((v) & 0xFFFF0000) >> 16)
+
+#define __MDM_MAJOR_VERSION(v) (((v) & 0xFF000000) >> 24)
+#define __MDM_MINOR_VERSION(v) (((v) & 0x00FF0000) >> 16)
+/*
+ * #define __MDM_VERSION(v) \
+ * ((__MDM_MAJOR_VERSION(v) + 2) * 10 + __MDM_MINOR_VERSION(v))
+ */
+#define __MDM_VERSION(v) \
+({ \
+ u32 __v = (v); \
+ (__MDM_MAJOR_VERSION(__v) + 2) * 10 + __MDM_MINOR_VERSION(__v); \
+})
+
+/* conversion table from NL80211 to MACHW enum */
+extern const int chnl2bw[];
+
+/* conversion table from MACHW to NL80211 enum */
+extern const int bw2chnl[];
+
+#endif // _HAL_DESC_H_
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/ipc_shared.h b/drivers/net/wireless/aic/aic8800_fdrv/ipc_shared.h
new file mode 100644
index 000000000000..2b5c31f3abae
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/ipc_shared.h
@@ -0,0 +1,767 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief Shared data between both IPC modules
+ *
+ ******************************************************************************
+ */
+
+#ifndef _IPC_SHARED_H_
+#define _IPC_SHARED_H_
+
+/*
+ * INCLUDE FILES
+ ****************************************************************************************
+ */
+#include "lmac_mac.h"
+#include "aicwf_config.h"
+
+/*
+ * DEFINES AND MACROS
+ ****************************************************************************************
+ */
+#define CO_BIT(pos) (1U << (pos))
+
+#define IPC_TXQUEUE_CNT NX_TXQ_CNT
+#define NX_TXDESC_CNT0 8
+#define NX_TXDESC_CNT1 64
+#define NX_TXDESC_CNT2 64
+#define NX_TXDESC_CNT3 32
+#if NX_TXQ_CNT == 5
+#define NX_TXDESC_CNT4 8
+#endif
+
+/*
+ * Number of Host buffers available for Data Rx handling (through DMA)
+ */
+#define IPC_RXBUF_CNT 128
+
+/*
+ * Number of shared descriptors available for Data RX handling
+ */
+#define IPC_RXDESC_CNT 128
+
+/*
+ * Number of Host buffers available for Radar events handling (through DMA)
+ */
+#define IPC_RADARBUF_CNT 16
+
+/*
+ * Number of Host buffers available for unsupported Rx vectors handling (through
+ * DMA)
+ */
+#define IPC_UNSUPRXVECBUF_CNT 8
+
+/*
+ * Size of RxVector
+ */
+#define IPC_RXVEC_SIZE 16
+
+/*
+ * Number of Host buffers available for Emb->App MSGs sending (through DMA)
+ */
+#ifdef CONFIG_AICWF_FULLMAC
+#define IPC_MSGE2A_BUF_CNT 64
+#endif
+/*
+ * Number of Host buffers available for Debug Messages sending (through DMA)
+ */
+#define IPC_DBGBUF_CNT 32
+
+/*
+ * Length used in MSGs structures
+ */
+#define IPC_A2E_MSG_BUF_SIZE 127 // size in 4-byte words
+#ifdef CONFIG_AICWF_FULLMAC
+#define IPC_E2A_MSG_SIZE_BASE 256 // size in 4-byte words
+#endif
+
+#define IPC_E2A_MSG_PARAM_SIZE IPC_E2A_MSG_SIZE_BASE
+
+/*
+ * Debug messages buffers size (in bytes)
+ */
+#define IPC_DBG_PARAM_SIZE 256
+
+/*
+ * Define used for Rx hostbuf validity.
+ * This value should appear only when hostbuf was used for a Reception.
+ */
+#define RX_DMA_OVER_PATTERN 0xAAAAAA00
+
+/*
+ * Define used for MSG buffers validity.
+ * This value will be written only when a MSG buffer is used for sending from
+ * Emb to App.
+ */
+#define IPC_MSGE2A_VALID_PATTERN 0xADDEDE2A
+
+/*
+ * Define used for Debug messages buffers validity.
+ * This value will be written only when a DBG buffer is used for sending from
+ * Emb to App.
+ */
+#define IPC_DBG_VALID_PATTERN 0x000CACA0
+
+/*
+ * Length of the receive vectors, in bytes
+ */
+#define DMA_HDR_PHYVECT_LEN 36
+
+/*
+ * Maximum number of payload addresses and lengths present in the descriptor
+ */
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+#define NX_TX_PAYLOAD_MAX 6
+#else
+#define NX_TX_PAYLOAD_MAX 1
+#endif
+
+/*
+ * Message struct/ID API version
+ */
+#define MSG_API_VER 33
+
+/*
+ ****************************************************************************************
+ */
+// c.f LMAC/src/tx/tx_swdesc.h
+/// Descriptor filled by the Host
+struct hostdesc {
+ /// Pointer to packet payload
+ // u32 packet_addr;
+ /// Size of the payload
+ u16 packet_len;
+ u16 flags_ext;
+
+ u32 hostid;
+#ifdef CONFIG_AICWF_FULLMAC
+ /// Address of the status descriptor in host memory (used for confirmation
+ /// upload)
+ // u32 status_desc_addr;
+ /// Destination Address
+ struct mac_addr eth_dest_addr;
+ /// Source Address
+ struct mac_addr eth_src_addr;
+ /// Ethernet Type
+ __be16 ethertype;
+#else /* ! CONFIG_AICWF_FULLMAC */
+#ifdef CONFIG_AICWF_AGG_TX
+ /// Sequence Number for AMPDU MPDUs - for quick check if it's allowed within
+ /// window
+ u16 sn;
+#endif /* CONFIG_AICWF_AGG_TX */
+ /// Padding between the buffer control structure and the MPDU in host memory
+ u8 padding;
+#endif /* CONFIG_AICWF_FULLMAC */
+ u8 ac;
+ /// Packet TID (0xFF if not a QoS frame)
+ u8 tid;
+ /// Interface Id
+ u8 vif_idx;
+ /// Station Id (0xFF if station is unknown)
+ u8 staid;
+#ifdef CONFIG_AICWF_MUMIMO_TX
+ /// MU-MIMO information (GroupId and User Position in the group) - The
+ /// GroupId is located on bits 0-5 and the User Position on bits 6-7. The
+ /// GroupId value is set to 63 if MU-MIMO shall not be used
+ u8 mumimo_info;
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+#ifdef CONFIG_AICWF_FULLMAC
+ /// TX flags
+ u16 flags;
+#endif /* CONFIG_AICWF_FULLMAC */
+};
+
+/// Descriptor filled by the UMAC
+struct umacdesc {
+#ifdef CONFIG_AICWF_AGG_TX
+ /// First Sequence Number of the BlockAck window
+ u16 sn_win;
+ /// Flags from UMAC (match tx_hd.macctrlinfo2 format)
+ u32 flags;
+ /// PHY related flags field - rate, GI type, BW type - filled by driver
+ u32 phy_flags;
+#endif //(CONFIG_AICWF_AGG_TX)
+};
+
+struct txdesc_api {
+ /// Information provided by Host
+ struct hostdesc host;
+};
+
+struct txdesc_host {
+ u32 ready;
+
+ /// API of the embedded part
+ struct txdesc_api api;
+};
+
+/// Comes from ipc_dma.h
+/// Element in the pool of TX DMA bridge descriptors.
+struct dma_desc {
+ /* Application subsystem address which is used as source address for DMA
+ * payload transfer
+ */
+ u32 src;
+ /** Points to the start of the embedded data buffer associated with this
+ * descriptor. This address acts as the destination address for the DMA
+ * payload transfer
+ */
+ u32 dest;
+ /// Complete length of the buffer in memory
+ u16 length;
+ /// Control word for the DMA engine (e.g. for interrupt generation)
+ u16 ctrl;
+ /// Pointer to the next element of the chained list
+ u32 next;
+};
+
+// Comes from la.h
+/// Length of the configuration data of a logic analyzer
+#define LA_CONF_LEN 10
+
+/// Structure containing the configuration data of a logic analyzer
+struct la_conf_tag {
+ u32 conf[LA_CONF_LEN];
+ u32 trace_len;
+ u32 diag_conf;
+};
+
+/// Size of a logic analyzer memory
+#define LA_MEM_LEN (1024 * 1024)
+
+/// Type of errors
+enum {
+ /// Recoverable error, not requiring any action from Upper MAC
+ DBG_ERROR_RECOVERABLE = 0,
+ /// Fatal error, requiring Upper MAC to reset Lower MAC and HW and restart
+ /// operation
+ DBG_ERROR_FATAL
+};
+
+/// Maximum length of the SW diag trace
+#define DBG_SW_DIAG_MAX_LEN 1024
+
+/// Maximum length of the error trace
+#define DBG_ERROR_TRACE_SIZE 256
+
+/// Number of MAC diagnostic port banks
+#define DBG_DIAGS_MAC_MAX 48
+
+/// Number of PHY diagnostic port banks
+#define DBG_DIAGS_PHY_MAX 32
+
+/// Maximum size of the RX header descriptor information in the debug dump
+#define DBG_RHD_MEM_LEN (5 * 1024)
+
+/// Maximum size of the RX buffer descriptor information in the debug dump
+#define DBG_RBD_MEM_LEN (5 * 1024)
+
+/// Maximum size of the TX header descriptor information in the debug dump
+#define DBG_THD_MEM_LEN (10 * 1024)
+
+/// Structure containing the information about the PHY channel that is used
+struct phy_channel_info {
+ /// PHY channel information 1
+ u32 info1;
+ /// PHY channel information 2
+ u32 info2;
+};
+
+/// Debug information forwarded to host when an error occurs
+struct dbg_debug_info_tag {
+ /// Type of error (0: recoverable, 1: fatal)
+ u32 error_type;
+ /// Pointer to the first RX Header Descriptor chained to the MAC HW
+ u32 rhd;
+ /// Size of the RX header descriptor buffer
+ u32 rhd_len;
+ /// Pointer to the first RX Buffer Descriptor chained to the MAC HW
+ u32 rbd;
+ /// Size of the RX buffer descriptor buffer
+ u32 rbd_len;
+ /// Pointer to the first TX Header Descriptors chained to the MAC HW
+ u32 thd[NX_TXQ_CNT];
+ /// Size of the TX header descriptor buffer
+ u32 thd_len[NX_TXQ_CNT];
+ /// MAC HW diag configuration
+ u32 hw_diag;
+ /// Error message
+ u32 error[DBG_ERROR_TRACE_SIZE / 4];
+ /// SW diag configuration length
+ u32 sw_diag_len;
+ /// SW diag configuration
+ u32 sw_diag[DBG_SW_DIAG_MAX_LEN / 4];
+ /// PHY channel information
+ struct phy_channel_info chan_info;
+ /// Embedded LA configuration
+ struct la_conf_tag la_conf;
+ /// MAC diagnostic port state
+ u16 diags_mac[DBG_DIAGS_MAC_MAX];
+ /// PHY diagnostic port state
+ u16 diags_phy[DBG_DIAGS_PHY_MAX];
+ /// MAC HW RX Header descriptor pointer
+ u32 rhd_hw_ptr;
+ /// MAC HW RX Buffer descriptor pointer
+ u32 rbd_hw_ptr;
+};
+
+/// Full debug dump that is forwarded to host in case of error
+struct dbg_debug_dump_tag {
+ /// Debug information
+ struct dbg_debug_info_tag dbg_info;
+
+ /// RX header descriptor memory
+ u32 rhd_mem[DBG_RHD_MEM_LEN / 4];
+
+ /// RX buffer descriptor memory
+ u32 rbd_mem[DBG_RBD_MEM_LEN / 4];
+
+ /// TX header descriptor memory
+ u32 thd_mem[NX_TXQ_CNT][DBG_THD_MEM_LEN / 4];
+
+ /// Logic analyzer memory
+ u32 la_mem[LA_MEM_LEN / 4];
+};
+
+/// Number of pulses in a radar event structure
+#define RADAR_PULSE_MAX 4
+
+/// Definition of an array of radar pulses
+struct radar_pulse_array_desc {
+ /// Buffer containing the radar pulses
+ u32 pulse[RADAR_PULSE_MAX];
+ /// Index of the radar detection chain that detected those pulses
+ u32 idx;
+ /// Number of valid pulses in the buffer
+ u32 cnt;
+};
+
+/// Bit mapping inside a radar pulse element
+struct radar_pulse {
+ s32
+ freq : 6; /** Freq (resolution is 2Mhz range is [-Fadc/4 .. Fadc/4]) */
+ u32 fom : 4; /** Figure of Merit */
+ u32 len : 6; /** Length of the current radar pulse (resolution is 2us) */
+ u32 rep : 16; /* Time interval between previous and current event (in us) */
+};
+
+/// Definition of a RX vector descriptor
+struct rx_vector_desc {
+ /// PHY channel information
+ struct phy_channel_info phy_info;
+
+ /// RX vector 1
+ u32 rx_vect1[IPC_RXVEC_SIZE / 4];
+
+ /// Used to print a valid rx vector
+ u32 pattern;
+};
+
+///
+struct rxdesc_tag {
+ /// Host Buffer Address
+ u32 host_id;
+ /// Length
+ u32 frame_len;
+ /// Status
+ u16 status;
+};
+
+/*
+ ****************************************************************************************
+ * @addtogroup IPC_TX IPC Tx path
+ * @ingroup IPC
+ * @brief IPC Tx path structures and functions
+ *
+ * A typical use case of the IPC Tx path API:
+ * @msc
+ * hscale = "2";
+ *
+ * a [label=Driver],
+ * b [label="IPC host"],
+ * c [label="IPC emb"],
+ * d [label=Firmware];
+ *
+ * --- [label="Tx descriptor queue example"];
+ * a=>a [label="Driver receives a Tx packet from OS"];
+ * a=>b [label="ipc_host_txdesc_get()"];
+ * a<<b [label="struct txdesc_host *"];
+ * a=>a [label="Driver fill the descriptor"];
+ * a=>b [label="ipc_host_txdesc_push()"];
+ * ... [label="(several Tx desc can be pushed)"];
+ * b:>c [label="Tx desc queue filled IRQ"];
+ * c=>>d [label="EDCA sub-scheduler callback"];
+ * c<<d [label="Tx desc queue to pop"];
+ * c=>>d [label="UMAC Tx desc callback"];
+ * ... [label="(several Tx desc can be popped)"];
+ * d=>d [label="Packets are sent or discarded"];
+ * --- [label="Tx confirm queue example"];
+ * c<=d [label="ipc_emb_txcfm_push()"];
+ * c>>d [label="Request accepted"];
+ * ... [label="(several Tx cfm can be pushed)"];
+ * b<:c [label="Tx cfm queue filled IRQ"];
+ * a<<=b [label="Driver's Tx Confirm callback"];
+ * a=>b [label="ipc_host_txcfm_pop()"];
+ * a<<b [label="struct ipc_txcfm"];
+ * a<=a [label="Packets are freed by the driver"];
+ * @endmsc
+ *
+ * @{
+ ****************************************************************************************
+ */
+
+/// @} IPC_TX
+
+/*
+ ****************************************************************************************
+ * @defgroup IPC_RX IPC Rx path
+ * @ingroup IPC
+ * @brief IPC Rx path functions and structures
+ *
+ * A typical use case of the IPC Rx path API:
+ * @msc
+ * hscale = "2";
+ *
+ * a [label=Firmware],
+ * b [label="IPC emb"],
+ * c [label="IPC host"],
+ * d [label=Driver];
+ *
+ * --- [label="Rx buffer and desc queues usage example"];
+ * d=>c [label="ipc_host_rxbuf_push()"];
+ * d=>c [label="ipc_host_rxbuf_push()"];
+ * d=>c [label="ipc_host_rxbuf_push()"];
+ * ... [label="(several Rx buffer are pushed)"];
+ * a=>a [label=" Frame is received\n from the medium"];
+ * a<<b [label="struct ipc_rxbuf"];
+ * a=>a [label=" Firmware fill the buffer\n with received frame"];
+ * a<<b [label="Push accepted"];
+ * ... [label="(several Rx desc can be pushed)"];
+ * b:>c [label="Rx desc queue filled IRQ"];
+ * c=>>d [label="Driver Rx packet callback"];
+ * c<=d [label="ipc_host_rxdesc_pop()"];
+ * d=>d [label="Rx packet is handed\nover to the OS "];
+ * ... [label="(several Rx desc can be poped)"];
+ * --- [label="Rx buffer request exemple"];
+ * b:>c [label="Low Rx buffer count IRQ"];
+ * a<<b [label="struct ipc_rxbuf"];
+ * c=>>d [label="Driver Rx buffer callback"];
+ * d=>c [label="ipc_host_rxbuf_push()"];
+ * d=>c [label="ipc_host_rxbuf_push()"];
+ * d=>c [label="ipc_host_rxbuf_push()"];
+ * ... [label="(several Rx buffer are pushed)"];
+ * @endmsc
+ *
+ * @addtogroup IPC_RX
+ * @{
+ ****************************************************************************************
+ */
+
+/// @} IPC_RX
+
+/*
+ ****************************************************************************************
+ * @defgroup IPC_MISC IPC Misc
+ * @ingroup IPC
+ * @brief IPC miscellaneous functions
+ ****************************************************************************************
+ */
+/** IPC header structure. This structure is stored at the beginning of every
+ * IPC message.
+ * @warning This structure's size must NOT exceed 4 bytes in length.
+ */
+struct ipc_header {
+ /// IPC message type.
+ u16 type;
+ /// IPC message size in number of bytes.
+ u16 size;
+};
+
+struct ipc_msg_elt {
+ /// Message header (alignment forced on word size, see allocation in shared
+ /// env).
+ struct ipc_header header __aligned(4);
+};
+
+/// Message structure for MSGs from Emb to App
+struct ipc_e2a_msg {
+ u16 id; ///< Message id.
+ u16 dummy_dest_id;
+ u16 dummy_src_id;
+ u16 param_len; ///< Parameter embedded struct length.
+ u32 pattern; ///< Used to stamp a valid MSG buffer
+ u32 param[IPC_E2A_MSG_PARAM_SIZE]; ///< Parameter embedded struct. Must be
+ ///< word-aligned.
+};
+
+/// Message structure for Debug messages from Emb to App
+struct ipc_dbg_msg {
+ u32 string[IPC_DBG_PARAM_SIZE / 4]; ///< Debug string
+ u32 pattern; ///< Used to stamp a valid buffer
+};
+
+/// Message structure for MSGs from App to Emb.
+/// Actually a sub-structure will be used when filling the messages.
+struct ipc_a2e_msg {
+ u32 dummy_word; // used to cope with kernel message structure
+ u32 msg[IPC_A2E_MSG_BUF_SIZE]; // body of the msg
+};
+
+struct ipc_shared_rx_buf {
+ /// < ptr to hostbuf client (ipc_host client) structure
+ u32 hostid;
+ /// < ptr to real hostbuf dma address
+ u32 dma_addr;
+};
+
+struct ipc_shared_rx_desc {
+ /// DMA Address
+ u32 dma_addr;
+};
+
+/// Structure containing FW characteristics for compatibility checking
+struct compatibility_tag {
+ /// Size of IPC shared memory
+ u16 ipc_shared_size;
+ /// Message struct/ID API version
+ u16 msg_api;
+ /// Version of IPC shared
+ u8 ipc_shared_version;
+ /// Number of host buffers available for Emb->App MSGs sending
+ u8 msge2a_buf_cnt;
+ /// Number of host buffers available for Debug Messages sending
+ u8 dbgbuf_cnt;
+ /// Number of host buffers available for Radar events handling
+ u8 radarbuf_cnt;
+ /// Number of host buffers available for unsupported Rx vectors handling
+ u8 unsuprxvecbuf_cnt;
+ /// Number of shared descriptors available for Data RX handling
+ u8 rxdesc_cnt;
+ /// Number of host buffers available for Data Rx handling
+ u8 rxbuf_cnt;
+ /// Number of descriptors in BK TX queue (power of 2, min 4, max 64)
+ u8 bk_txq;
+ /// Number of descriptors in BE TX queue (power of 2, min 4, max 64)
+ u8 be_txq;
+ /// Number of descriptors in VI TX queue (power of 2, min 4, max 64)
+ u8 vi_txq;
+ /// Number of descriptors in VO TX queue (power of 2, min 4, max 64)
+ u8 vo_txq;
+ /// Number of descriptors in BCN TX queue (power of 2, min 4, max 64)
+ u8 bcn_txq;
+};
+
+/*
+ * TYPE and STRUCT DEFINITIONS
+ ****************************************************************************************
+ */
+
+// Indexes are defined in the MIB shared structure
+struct ipc_shared_env_tag {
+ struct compatibility_tag comp_info; // FW characteristics
+
+ struct ipc_a2e_msg
+ msg_a2e_buf; // room for MSG to be sent from App to Emb
+
+ // Fields for MSGs sending from Emb to App
+ struct ipc_e2a_msg
+ msg_e2a_buf; // room to build the MSG to be DMA Xferred
+ struct dma_desc
+ msg_dma_desc; // DMA descriptor for Emb->App MSGs Xfers
+ u32 msg_e2a_hostbuf_addr[IPC_MSGE2A_BUF_CNT]; // buffers @ for DMA Xfers
+
+ // Fields for Debug MSGs sending from Emb to App
+ struct ipc_dbg_msg
+ dbg_buf; // room to build the MSG to be DMA Xferred
+ struct dma_desc
+ dbg_dma_desc; // DMA descriptor for Emb->App MSGs Xfers
+ u32 dbg_hostbuf_addr[IPC_DBGBUF_CNT]; // buffers @ for MSGs DMA Xfers
+ u32 la_dbginfo_addr; // Host buffer address for the debug information
+ u32 pattern_addr;
+
+ u32 radarbuf_hostbuf[IPC_RADARBUF_CNT]; // buffers @ for Radar Events
+ u32 unsuprxvecbuf_hostbuf[IPC_UNSUPRXVECBUF_CNT]; // buffers @ for
+ // unsupported Rx vectors
+ struct txdesc_host txdesc0[NX_USER_MAX][NX_TXDESC_CNT0];
+ struct txdesc_host txdesc1[NX_USER_MAX][NX_TXDESC_CNT1];
+ struct txdesc_host txdesc2[NX_USER_MAX][NX_TXDESC_CNT2];
+ struct txdesc_host txdesc3[NX_USER_MAX][NX_TXDESC_CNT3];
+#if NX_TXQ_CNT == 5
+ struct txdesc_host txdesc4[1][NX_TXDESC_CNT4];
+#endif
+#ifdef CONFIG_AICWF_FULLMAC
+ // RX Descriptors Array
+ struct ipc_shared_rx_desc host_rxdesc[IPC_RXDESC_CNT];
+ // RX Buffers Array
+ struct ipc_shared_rx_buf host_rxbuf[IPC_RXBUF_CNT];
+#else
+ // buffers @ for Data Rx
+ u32 host_rxbuf[IPC_RXBUF_CNT];
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ u32 buffered[NX_REMOTE_STA_MAX][TID_MAX];
+
+ u16 trace_pattern;
+ u32 trace_start;
+ u32 trace_end;
+ u32 trace_size;
+ u32 trace_offset;
+ u32 trace_nb_compo;
+ u32 trace_offset_compo;
+};
+
+extern struct ipc_shared_env_tag ipc_shared_env;
+
+/*
+ * TYPE and STRUCT DEFINITIONS
+ ****************************************************************************************
+ */
+
+// IRQs from app to emb
+/// Interrupts bits used for the TX descriptors of the AC queues
+#ifdef CONFIG_AICWF_MUMIMO_TX
+/// Interrupts bits used
+#if NX_USER_MAX > 3
+#define IPC_IRQ_A2E_USER_MSK 0xF
+#elif NX_USER_MAX > 2
+#define IPC_IRQ_A2E_USER_MSK 0x7
+#else
+#define IPC_IRQ_A2E_USER_MSK 0x3
+#endif
+
+/// Offset of the interrupts for AC0
+#define IPC_IRQ_A2E_AC0_OFT 8
+/// Mask of the interrupts for AC0
+#define IPC_IRQ_A2E_AC0_MSK (IPC_IRQ_A2E_USER_MSK << IPC_IRQ_A2E_AC0_OFT)
+/// Offset of the interrupts for AC1
+#define IPC_IRQ_A2E_AC1_OFT (IPC_IRQ_A2E_AC0_OFT + NX_USER_MAX)
+/// Mask of the interrupts for AC1
+#define IPC_IRQ_A2E_AC1_MSK (IPC_IRQ_A2E_USER_MSK << IPC_IRQ_A2E_AC1_OFT)
+/// Offset of the interrupts for AC2
+#define IPC_IRQ_A2E_AC2_OFT (IPC_IRQ_A2E_AC1_OFT + NX_USER_MAX)
+/// Mask of the interrupts for AC2
+#define IPC_IRQ_A2E_AC2_MSK (IPC_IRQ_A2E_USER_MSK << IPC_IRQ_A2E_AC2_OFT)
+/// Offset of the interrupts for AC3
+#define IPC_IRQ_A2E_AC3_OFT (IPC_IRQ_A2E_AC2_OFT + NX_USER_MAX)
+/// Mask of the interrupts for AC3
+#define IPC_IRQ_A2E_AC3_MSK (IPC_IRQ_A2E_USER_MSK << IPC_IRQ_A2E_AC3_OFT)
+/// Offset of the interrupts for BCN
+#define IPC_IRQ_A2E_BCN_OFT (IPC_IRQ_A2E_AC3_OFT + NX_USER_MAX)
+/// Mask of the interrupts for BCN
+#define IPC_IRQ_A2E_BCN_MSK CO_BIT(IPC_IRQ_A2E_BCN_OFT)
+
+#define IPC_IRQ_A2E_AC_TXDESC \
+ (IPC_IRQ_A2E_AC0_MSK | IPC_IRQ_A2E_AC1_MSK | IPC_IRQ_A2E_AC2_MSK | \
+ IPC_IRQ_A2E_AC3_MSK)
+
+/// Interrupts bits used for the TX descriptors of the BCN queue
+#if NX_TXQ_CNT < 5
+#define IPC_IRQ_A2E_BCN_TXDESC 0
+#else
+#define IPC_IRQ_A2E_BCN_TXDESC (0x01 << IPC_IRQ_A2E_BCN_OFT)
+#endif
+
+/// IPC TX descriptor interrupt mask
+#define IPC_IRQ_A2E_TXDESC (IPC_IRQ_A2E_AC_TXDESC | IPC_IRQ_A2E_BCN_TXDESC)
+#else
+/// IPC TX descriptor interrupt mask
+#define IPC_IRQ_A2E_TXDESC 0xFF00
+#endif
+
+#define IPC_IRQ_A2E_TXDESC_FIRSTBIT (8)
+#define IPC_IRQ_A2E_RXBUF_BACK CO_BIT(5)
+#define IPC_IRQ_A2E_RXDESC_BACK CO_BIT(4)
+
+#define IPC_IRQ_A2E_MSG CO_BIT(1)
+#define IPC_IRQ_A2E_DBG CO_BIT(0)
+
+#define IPC_IRQ_A2E_ALL (IPC_IRQ_A2E_TXDESC | IPC_IRQ_A2E_MSG | IPC_IRQ_A2E_DBG)
+
+// IRQs from emb to app
+#define IPC_IRQ_E2A_TXCFM_POS 7
+
+#ifdef CONFIG_AICWF_MUMIMO_TX
+/// Interrupts bits used
+#if NX_USER_MAX > 3
+#define IPC_IRQ_E2A_USER_MSK 0xF
+#elif NX_USER_MAX > 2
+#define IPC_IRQ_E2A_USER_MSK 0x7
+#else
+#define IPC_IRQ_E2A_USER_MSK 0x3
+#endif
+
+/// Offset of the interrupts for AC0
+#define IPC_IRQ_E2A_AC0_OFT IPC_IRQ_E2A_TXCFM_POS
+/// Mask of the interrupts for AC0
+#define IPC_IRQ_E2A_AC0_MSK (IPC_IRQ_E2A_USER_MSK << IPC_IRQ_E2A_AC0_OFT)
+/// Offset of the interrupts for AC1
+#define IPC_IRQ_E2A_AC1_OFT (IPC_IRQ_E2A_AC0_OFT + NX_USER_MAX)
+/// Mask of the interrupts for AC1
+#define IPC_IRQ_E2A_AC1_MSK (IPC_IRQ_E2A_USER_MSK << IPC_IRQ_E2A_AC1_OFT)
+/// Offset of the interrupts for AC2
+#define IPC_IRQ_E2A_AC2_OFT (IPC_IRQ_E2A_AC1_OFT + NX_USER_MAX)
+/// Mask of the interrupts for AC2
+#define IPC_IRQ_E2A_AC2_MSK (IPC_IRQ_E2A_USER_MSK << IPC_IRQ_E2A_AC2_OFT)
+/// Offset of the interrupts for AC3
+#define IPC_IRQ_E2A_AC3_OFT (IPC_IRQ_E2A_AC2_OFT + NX_USER_MAX)
+/// Mask of the interrupts for AC3
+#define IPC_IRQ_E2A_AC3_MSK (IPC_IRQ_E2A_USER_MSK << IPC_IRQ_E2A_AC3_OFT)
+/// Offset of the interrupts for BCN
+#define IPC_IRQ_E2A_BCN_OFT (IPC_IRQ_E2A_AC3_OFT + NX_USER_MAX)
+/// Mask of the interrupts for BCN
+#define IPC_IRQ_E2A_BCN_MSK CO_BIT(IPC_IRQ_E2A_BCN_OFT)
+
+#define IPC_IRQ_E2A_AC_TXCFM \
+ (IPC_IRQ_E2A_AC0_MSK | IPC_IRQ_E2A_AC1_MSK | IPC_IRQ_E2A_AC2_MSK | \
+ IPC_IRQ_E2A_AC3_MSK)
+
+/// Interrupts bits used for the TX descriptors of the BCN queue
+#if NX_TXQ_CNT < 5
+#define IPC_IRQ_E2A_BCN_TXCFM 0
+#else
+#define IPC_IRQ_E2A_BCN_TXCFM (0x01 << IPC_IRQ_E2A_BCN_OFT)
+#endif
+
+/// IPC TX descriptor interrupt mask
+#define IPC_IRQ_E2A_TXCFM (IPC_IRQ_E2A_AC_TXCFM | IPC_IRQ_E2A_BCN_TXCFM)
+
+#else
+
+#define IPC_IRQ_E2A_TXCFM (((1 << NX_TXQ_CNT) - 1) << IPC_IRQ_E2A_TXCFM_POS)
+
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+
+#define IPC_IRQ_E2A_UNSUP_RX_VEC CO_BIT(7)
+#define IPC_IRQ_E2A_RADAR CO_BIT(6)
+#define IPC_IRQ_E2A_TBTT_SEC CO_BIT(5)
+#define IPC_IRQ_E2A_TBTT_PRIM CO_BIT(4)
+#define IPC_IRQ_E2A_RXDESC CO_BIT(3)
+#define IPC_IRQ_E2A_MSG_ACK CO_BIT(2)
+#define IPC_IRQ_E2A_MSG CO_BIT(1)
+#define IPC_IRQ_E2A_DBG CO_BIT(0)
+
+#define IPC_IRQ_E2A_ALL \
+ (IPC_IRQ_E2A_TXCFM | IPC_IRQ_E2A_RXDESC | IPC_IRQ_E2A_MSG_ACK | \
+ IPC_IRQ_E2A_MSG | IPC_IRQ_E2A_DBG | IPC_IRQ_E2A_TBTT_PRIM | \
+ IPC_IRQ_E2A_TBTT_SEC | IPC_IRQ_E2A_RADAR | IPC_IRQ_E2A_UNSUP_RX_VEC)
+
+// FLAGS for RX desc
+#define IPC_RX_FORWARD CO_BIT(1)
+#define IPC_RX_INTRABSS CO_BIT(0)
+
+// IPC message TYPE
+enum {
+ IPC_MSG_NONE = 0,
+ IPC_MSG_WRAP,
+ IPC_MSG_KMSG,
+
+ IPC_DBG_STRING,
+
+};
+
+#endif // _IPC_SHARED_H_
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/lmac_mac.h b/drivers/net/wireless/aic/aic8800_fdrv/lmac_mac.h
new file mode 100644
index 000000000000..114ed14f4ad5
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/lmac_mac.h
@@ -0,0 +1,437 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ****************************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief MAC related definitions.
+ *
+ * Adapted from mac_types.h to used lmac_types.h instead of standard types
+ * eg: perl -pi -e '$_ =~ s/uint(\d{1,2})_t/u$1_l/g; \
+ * $_ =~ s/int(\d{1,2})_t/s$1_l/g; \
+ * $_ =~ s/CO_BIT/BIT/g;'
+ *
+ ****************************************************************************************
+ */
+
+#ifndef LMAC_MAC_H_
+#define LMAC_MAC_H_
+
+#include "lmac_types.h"
+
+/// Interface types
+enum mac_vif_type {
+ /// ESS STA interface
+ VIF_STA,
+ /// IBSS STA interface
+ VIF_IBSS,
+ /// AP interface
+ VIF_AP,
+ /// Mesh Point interface
+ VIF_MESH_POINT,
+ /// Monitor interface
+ VIF_MONITOR,
+ /// Unknown type
+ VIF_UNKNOWN
+};
+
+/// MAC address length in bytes.
+#define MAC_ADDR_LEN 6
+
+/// MAC address structure.
+struct mac_addr {
+ /// Array of 16-bit words that make up the MAC address.
+ u16 array[MAC_ADDR_LEN / 2];
+};
+
+/// SSID maximum length.
+#define MAC_SSID_LEN 32
+
+/// SSID.
+struct mac_ssid {
+ /// Actual length of the SSID.
+ u8 length;
+ /// Array containing the SSID name.
+ u8 array[MAC_SSID_LEN];
+};
+
+/// BSS type
+enum mac_bss_type {
+ INFRASTRUCTURE_MODE = 1,
+ INDEPENDENT_BSS_MODE,
+ ANY_BSS_MODE
+};
+
+/// Channel Band
+enum mac_chan_band {
+ /// 2.4GHz Band
+ PHY_BAND_2G4,
+ /// 5GHz band
+ PHY_BAND_5G,
+ /// Number of bands
+ PHY_BAND_MAX,
+};
+
+/// Operating Channel Bandwidth
+enum mac_chan_bandwidth {
+ /// 20MHz BW
+ PHY_CHNL_BW_20,
+ /// 40MHz BW
+ PHY_CHNL_BW_40,
+ /// 80MHz BW
+ PHY_CHNL_BW_80,
+ /// 160MHz BW
+ PHY_CHNL_BW_160,
+ /// 80+80MHz BW
+ PHY_CHNL_BW_80P80,
+ /// Reserved BW
+ PHY_CHNL_BW_OTHER,
+};
+
+/// max number of channels in the 2.4 GHZ band
+#define MAC_DOMAINCHANNEL_24G_MAX 14
+
+/// max number of channels in the 5 GHZ band
+#define MAC_DOMAINCHANNEL_5G_MAX 28
+
+/// Channel Flag
+enum mac_chan_flags {
+ /// Cannot initiate radiation on this channel
+ CHAN_NO_IR = BIT(0),
+ /// Channel is not allowed
+ CHAN_DISABLED = BIT(1),
+ /// Radar detection required on this channel
+ CHAN_RADAR = BIT(2),
+};
+
+/// Primary Channel definition
+struct mac_chan_def {
+ /// Frequency of the channel (in MHz)
+ u16 freq;
+ /// RF band (@ref mac_chan_band)
+ u8 band;
+ /// Additional information (@ref mac_chan_flags)
+ u8 flags;
+ /// Max transmit power allowed on this channel (dBm)
+ s8 tx_power;
+};
+
+/// Operating Channel
+struct mac_chan_op {
+ /// Band (@ref mac_chan_band)
+ u8 band;
+ /// Channel type (@ref mac_chan_bandwidth)
+ u8 type;
+ /// Frequency for Primary 20MHz channel (in MHz)
+ u16 prim20_freq;
+ /// Frequency center of the contiguous channel or center of Primary 80+80
+ /// (in MHz)
+ u16 center1_freq;
+ /// Frequency center of the non-contiguous secondary 80+80 (in MHz)
+ u16 center2_freq;
+ /// Max transmit power allowed on this channel (dBm)
+ s8 tx_power;
+ /// Additional information (@ref mac_chan_flags)
+ u8 flags;
+};
+
+/// Cipher suites (order is important as it is used by MACHW)
+enum mac_cipher_suite {
+ /// 00-0F-AC 1
+ MAC_CIPHER_WEP40 = 0,
+ /// 00-0F-AC 2
+ MAC_CIPHER_TKIP = 1,
+ /// 00-0F-AC 4
+ MAC_CIPHER_CCMP = 2,
+ /// 00-0F-AC 5
+ MAC_CIPHER_WEP104 = 3,
+ /// 00-14-72 1
+ MAC_CIPHER_WPI_SMS4 = 4,
+ /// 00-0F-AC 6 (aka AES_CMAC)
+ MAC_CIPHER_BIP_CMAC_128 = 5,
+
+ // following cipher are not supported by MACHW
+ /// 00-0F-AC 08
+ MAC_CIPHER_GCMP_128,
+ /// 00-0F-AC 09
+ MAC_CIPHER_GCMP_256,
+ /// 00-0F-AC 10
+ MAC_CIPHER_CCMP_256,
+ /// 00-0F-AC 11
+ MAC_CIPHER_BIP_GMAC_128,
+ /// 00-0F-AC 12
+ MAC_CIPHER_BIP_GMAC_256,
+ /// 00-0F-AC 13
+ MAC_CIPHER_BIP_CMAC_256,
+
+ MAC_CIPHER_INVALID = 0xFF
+};
+
+/// Authentication and Key Management suite
+enum mac_akm_suite {
+ /// No security
+ MAC_AKM_NONE,
+ /// Pre RSN (WEP or WPA)
+ MAC_AKM_PRE_RSN,
+ /// 00-0F-AC 1
+ MAC_AKM_8021X,
+ /// 00-0F-AC 2
+ MAC_AKM_PSK,
+ /// 00-0F-AC 3
+ MAC_AKM_FT_8021X,
+ /// 00-0F-AC 4
+ MAC_AKM_FT_PSK,
+ /// 00-0F-AC 5
+ MAC_AKM_8021X_SHA256,
+ /// 00-0F-AC 6
+ MAC_AKM_PSK_SHA256,
+ /// 00-0F-AC 7
+ MAC_AKM_TDLS,
+ /// 00-0F-AC 8
+ MAC_AKM_SAE,
+ /// 00-0F-AC 9
+ MAC_AKM_FT_OVER_SAE,
+ /// 00-0F-AC 11
+ MAC_AKM_8021X_SUITE_B,
+ /// 00-0F-AC 12
+ MAC_AKM_8021X_SUITE_B_192,
+ /// 00-0F-AC 14
+ MAC_AKM_FILS_SHA256,
+ /// 00-0F-AC 15
+ MAC_AKM_FILS_SHA384,
+ /// 00-0F-AC 16
+ MAC_AKM_FT_FILS_SHA256,
+ /// 00-0F-AC 17
+ MAC_AKM_FT_FILS_SHA384,
+ /// 00-0F-AC 18
+ MAC_AKM_OWE,
+
+ /// 00-14-72 1
+ MAC_AKM_WAPI_CERT,
+ /// 00-14-72 2
+ MAC_AKM_WAPI_PSK,
+};
+
+/// Scan result element, parsed from beacon or probe response frames.
+struct mac_scan_result {
+ /// Scan result is valid
+ bool valid_flag;
+ /// Network BSSID.
+ struct mac_addr bssid;
+ /// Network name.
+ struct mac_ssid ssid;
+ /// Network type (@ref mac_bss_type).
+ u16 bsstype;
+ /// Network channel.
+ struct mac_chan_def *chan;
+ /// Network beacon period (in TU).
+ u16 beacon_period;
+ /// Capability information
+ u16 cap_info;
+ /// Supported AKM (bit-field of @ref mac_akm_suite)
+ u32 akm;
+ /// Group cipher (bit-field of @ref mac_cipher_suite)
+ u16 group_cipher;
+ /// Group cipher (bit-field of @ref mac_cipher_suite)
+ u16 pairwise_cipher;
+ /// RSSI of the scanned BSS (in dBm)
+ s8 rssi;
+};
+
+/// Legacy rate 802.11 definitions
+enum mac_legacy_rates {
+ /// DSSS/CCK 1Mbps
+ MAC_RATE_1MBPS = 2,
+ /// DSSS/CCK 2Mbps
+ MAC_RATE_2MBPS = 4,
+ /// DSSS/CCK 5.5Mbps
+ MAC_RATE_5_5MBPS = 11,
+ /// OFDM 6Mbps
+ MAC_RATE_6MBPS = 12,
+ /// OFDM 9Mbps
+ MAC_RATE_9MBPS = 18,
+ /// DSSS/CCK 11Mbps
+ MAC_RATE_11MBPS = 22,
+ /// OFDM 12Mbps
+ MAC_RATE_12MBPS = 24,
+ /// OFDM 18Mbps
+ MAC_RATE_18MBPS = 36,
+ /// OFDM 24Mbps
+ MAC_RATE_24MBPS = 48,
+ /// OFDM 36Mbps
+ MAC_RATE_36MBPS = 72,
+ /// OFDM 48Mbps
+ MAC_RATE_48MBPS = 96,
+ /// OFDM 54Mbps
+ MAC_RATE_54MBPS = 108
+};
+
+/// BSS Membership Selector definitions
+enum mac_bss_membership {
+ /// HT PHY
+ MAC_BSS_MEMBERSHIP_HT_PHY = 127,
+ /// VHT PHY
+ MAC_BSS_MEMBERSHIP_VHT_PHY = 126,
+};
+
+/// MAC rateset maximum length
+#define MAC_RATESET_LEN 12
+
+/// Structure containing the legacy rateset of a station
+struct mac_rateset {
+ /// Number of legacy rates supported
+ u8 length;
+ /// Array of legacy rates
+ u8 array[MAC_RATESET_LEN];
+};
+
+/// MAC Security Key maximum length
+#define MAC_SEC_KEY_LEN 32 // TKIP keys 256 bits (max length) with MIC keys
+
+/// Structure defining a security key
+struct mac_sec_key {
+ /// Key material length
+ u8 length;
+ /// Key material
+ u32 array[MAC_SEC_KEY_LEN / 4];
+};
+
+/// Access Category enumeration
+enum mac_ac {
+ /// Background
+ AC_BK = 0,
+ /// Best-effort
+ AC_BE,
+ /// Video
+ AC_VI,
+ /// Voice
+ AC_VO,
+ /// Number of access categories
+ AC_MAX
+};
+
+/// Traffic ID enumeration
+enum mac_tid {
+ /// TID_0. Mapped to @ref AC_BE as per 802.11 standard.
+ TID_0,
+ /// TID_1. Mapped to @ref AC_BK as per 802.11 standard.
+ TID_1,
+ /// TID_2. Mapped to @ref AC_BK as per 802.11 standard.
+ TID_2,
+ /// TID_3. Mapped to @ref AC_BE as per 802.11 standard.
+ TID_3,
+ /// TID_4. Mapped to @ref AC_VI as per 802.11 standard.
+ TID_4,
+ /// TID_5. Mapped to @ref AC_VI as per 802.11 standard.
+ TID_5,
+ /// TID_6. Mapped to @ref AC_VO as per 802.11 standard.
+ TID_6,
+ /// TID_7. Mapped to @ref AC_VO as per 802.11 standard.
+ TID_7,
+ /// Non standard Management TID used internally
+ TID_MGT,
+ /// Number of TID supported
+ TID_MAX
+};
+
+/// MCS bitfield maximum size (in bytes)
+#define MAX_MCS_LEN 16 // 16 * 8 = 128
+
+/// MAC HT capability information element
+struct mac_htcapability {
+ /// HT capability information
+ __le16 ht_capa_info;
+ /// A-MPDU parameters
+ u8 a_mpdu_param;
+ /// Supported MCS
+ u8 mcs_rate[MAX_MCS_LEN];
+ /// HT extended capability information
+ __le16 ht_extended_capa;
+ /// Beamforming capability information
+ __le32 tx_beamforming_capa;
+ /// Antenna selection capability information
+ u8 asel_capa;
+};
+
+/// MAC VHT capability information element
+struct mac_vhtcapability {
+ /// VHT capability information
+ __le32 vht_capa_info;
+ /// RX MCS map
+ __le16 rx_mcs_map;
+ /// RX highest data rate
+ __le16 rx_highest;
+ /// TX MCS map
+ __le16 tx_mcs_map;
+ /// TX highest data rate
+ __le16 tx_highest;
+};
+
+/// Length (in bytes) of the MAC HE capability field
+#define MAC_HE_MAC_CAPA_LEN 6
+/// Length (in bytes) of the PHY HE capability field
+#define MAC_HE_PHY_CAPA_LEN 11
+/// Maximum length (in bytes) of the PPE threshold data
+#define MAC_HE_PPE_THRES_MAX_LEN 25
+
+/// Structure listing the per-NSS, per-BW supported MCS combinations
+struct mac_he_mcs_nss_supp {
+ /// per-NSS supported MCS in RX, for BW <= 80MHz
+ __le16 rx_mcs_80;
+ /// per-NSS supported MCS in TX, for BW <= 80MHz
+ __le16 tx_mcs_80;
+ /// per-NSS supported MCS in RX, for BW = 160MHz
+ __le16 rx_mcs_160;
+ /// per-NSS supported MCS in TX, for BW = 160MHz
+ __le16 tx_mcs_160;
+ /// per-NSS supported MCS in RX, for BW = 80+80MHz
+ __le16 rx_mcs_80p80;
+ /// per-NSS supported MCS in TX, for BW = 80+80MHz
+ __le16 tx_mcs_80p80;
+};
+
+/// MAC HE capability information element
+struct mac_hecapability {
+ /// MAC HE capabilities
+ u8 mac_cap_info[MAC_HE_MAC_CAPA_LEN];
+ /// PHY HE capabilities
+ u8 phy_cap_info[MAC_HE_PHY_CAPA_LEN];
+ /// Supported MCS combinations
+ struct mac_he_mcs_nss_supp mcs_supp;
+ /// PPE Thresholds data
+ u8 ppe_thres[MAC_HE_PPE_THRES_MAX_LEN];
+};
+
+/// Station flags
+enum mac_sta_flags {
+ /// Bit indicating that a STA has QoS (WMM) capability
+ STA_QOS_CAPA = BIT(0),
+ /// Bit indicating that a STA has HT capability
+ STA_HT_CAPA = BIT(1),
+ /// Bit indicating that a STA has VHT capability
+ STA_VHT_CAPA = BIT(2),
+ /// Bit indicating that a STA has MFP capability
+ STA_MFP_CAPA = BIT(3),
+ /// Bit indicating that the STA included the Operation Notification IE
+ STA_OPMOD_NOTIF = BIT(4),
+ /// Bit indicating that a STA has HE capability
+ STA_HE_CAPA = BIT(5),
+};
+
+/// Connection flags
+enum mac_connection_flags {
+ /// Flag indicating whether the control port is controlled by host or not
+ CONTROL_PORT_HOST = BIT(0),
+ /// Flag indicating whether the control port frame shall be sent unencrypted
+ CONTROL_PORT_NO_ENC = BIT(1),
+ /// Flag indicating whether HT and VHT shall be disabled or not
+ DISABLE_HT = BIT(2),
+ /// Flag indicating whether WPA or WPA2 authentication is in use
+ WPA_WPA2_IN_USE = BIT(3),
+ /// Flag indicating whether MFP is in use
+ MFP_IN_USE = BIT(4),
+ // Flag indicating Roam
+ REASSOCIATION = BIT(5),
+};
+
+#endif // LMAC_MAC_H_
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/lmac_msg.h b/drivers/net/wireless/aic/aic8800_fdrv/lmac_msg.h
new file mode 100644
index 000000000000..4a9713d3209e
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/lmac_msg.h
@@ -0,0 +1,3092 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ****************************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief Main definitions for message exchanges with LMAC
+ *
+ ****************************************************************************************
+ */
+
+#ifndef LMAC_MSG_H_
+#define LMAC_MSG_H_
+
+#include "lmac_mac.h"
+
+/* Task identifiers for communication between LMAC and DRIVER */
+enum {
+ TASK_NONE = 0xff,
+
+ // MAC Management task.
+ TASK_MM = 0,
+ // DEBUG task
+ TASK_DBG,
+ /// SCAN task
+ TASK_SCAN,
+ /// TDLS task
+ TASK_TDLS,
+ /// SCANU task
+ TASK_SCANU,
+ /// ME task
+ TASK_ME,
+ /// SM task
+ TASK_SM,
+ /// APM task
+ TASK_APM,
+ /// BAM task
+ TASK_BAM,
+ /// MESH task
+ TASK_MESH,
+ /// RXU task
+ TASK_RXU,
+ /// RM_task
+ TASK_RM,
+ /// TWT task
+ TASK_TWT,
+#if defined CONFIG_AICWF_FULLMAC
+ // This is used to define the last task that is running on the EMB processor
+ TASK_LAST_EMB = TASK_TWT,
+#else
+#error "Need to define SOFTMAC or FULLMAC"
+#endif
+ // nX API task
+ TASK_API,
+ TASK_MAX,
+};
+
+/// For MAC HW States copied from "hal_machw.h"
+enum {
+ /// MAC HW IDLE State.
+ HW_IDLE = 0,
+ /// MAC HW RESERVED State.
+ HW_RESERVED,
+ /// MAC HW DOZE State.
+ HW_DOZE,
+ /// MAC HW ACTIVE State.
+ HW_ACTIVE
+};
+
+/// Power Save mode setting
+enum mm_ps_mode_state {
+ MM_PS_MODE_OFF,
+ MM_PS_MODE_ON,
+ MM_PS_MODE_ON_DYN,
+};
+
+/// Status/error codes used in the MAC software.
+enum {
+ CO_OK,
+ CO_FAIL,
+ CO_EMPTY,
+ CO_FULL,
+ CO_BAD_PARAM,
+ CO_NOT_FOUND,
+ CO_NO_MORE_ELT_AVAILABLE,
+ CO_NO_ELT_IN_USE,
+ CO_BUSY,
+ CO_OP_IN_PROGRESS,
+};
+
+/// Remain on channel operation codes
+enum mm_remain_on_channel_op {
+ MM_ROC_OP_START = 0,
+ MM_ROC_OP_CANCEL,
+};
+
+#define DRV_TASK_ID 100
+
+/// Message Identifier. The number of messages is limited to 0xFFFF.
+/// The message ID is divided in two parts:
+/// - bits[15..10] : task index (no more than 64 tasks supported).
+/// - bits[9..0] : message index (no more that 1024 messages per task).
+typedef u16 lmac_msg_id_t;
+
+typedef u16 lmac_task_id_t;
+
+/// Build the first message ID of a task.
+#define LMAC_FIRST_MSG(task) ((lmac_msg_id_t)((task) << 10))
+
+#define MSG_T(msg) ((lmac_task_id_t)((msg) >> 10))
+#define MSG_I(msg) ((msg) & ((1 << 10) - 1))
+
+/// Message structure.
+struct lmac_msg {
+ lmac_msg_id_t id; ///< Message id.
+ lmac_task_id_t dest_id; ///< Destination kernel identifier.
+ lmac_task_id_t src_id; ///< Source kernel identifier.
+ u16 param_len; ///< Parameter embedded struct length.
+ u32 param[]; ///< Parameter embedded struct. Must be word-aligned.
+};
+
+/// List of messages related to the task.
+enum mm_msg_tag {
+ /// RESET Request.
+ MM_RESET_REQ = LMAC_FIRST_MSG(TASK_MM),
+ /// RESET Confirmation.
+ MM_RESET_CFM,
+ /// START Request.
+ MM_START_REQ,
+ /// START Confirmation.
+ MM_START_CFM,
+ /// Read Version Request.
+ MM_VERSION_REQ,
+ /// Read Version Confirmation.
+ MM_VERSION_CFM,
+ /// ADD INTERFACE Request.
+ MM_ADD_IF_REQ,
+ /// ADD INTERFACE Confirmation.
+ MM_ADD_IF_CFM,
+ /// REMOVE INTERFACE Request.
+ MM_REMOVE_IF_REQ,
+ /// REMOVE INTERFACE Confirmation.
+ MM_REMOVE_IF_CFM,
+ /// STA ADD Request.
+ MM_STA_ADD_REQ,
+ /// STA ADD Confirm.
+ MM_STA_ADD_CFM,
+ /// STA DEL Request.
+ MM_STA_DEL_REQ,
+ /// STA DEL Confirm.
+ MM_STA_DEL_CFM,
+ /// RX FILTER CONFIGURATION Request.
+ MM_SET_FILTER_REQ,
+ /// RX FILTER CONFIGURATION Confirmation.
+ MM_SET_FILTER_CFM,
+ /// CHANNEL CONFIGURATION Request.
+ MM_SET_CHANNEL_REQ,
+ /// CHANNEL CONFIGURATION Confirmation.
+ MM_SET_CHANNEL_CFM,
+ /// DTIM PERIOD CONFIGURATION Request.
+ MM_SET_DTIM_REQ,
+ /// DTIM PERIOD CONFIGURATION Confirmation.
+ MM_SET_DTIM_CFM,
+ /// BEACON INTERVAL CONFIGURATION Request.
+ MM_SET_BEACON_INT_REQ,
+ /// BEACON INTERVAL CONFIGURATION Confirmation.
+ MM_SET_BEACON_INT_CFM,
+ /// BASIC RATES CONFIGURATION Request.
+ MM_SET_BASIC_RATES_REQ,
+ /// BASIC RATES CONFIGURATION Confirmation.
+ MM_SET_BASIC_RATES_CFM,
+ /// BSSID CONFIGURATION Request.
+ MM_SET_BSSID_REQ,
+ /// BSSID CONFIGURATION Confirmation.
+ MM_SET_BSSID_CFM,
+ /// EDCA PARAMETERS CONFIGURATION Request.
+ MM_SET_EDCA_REQ,
+ /// EDCA PARAMETERS CONFIGURATION Confirmation.
+ MM_SET_EDCA_CFM,
+ /// ABGN MODE CONFIGURATION Request.
+ MM_SET_MODE_REQ,
+ /// ABGN MODE CONFIGURATION Confirmation.
+ MM_SET_MODE_CFM,
+ /// Request setting the VIF active state (i.e associated or AP started)
+ MM_SET_VIF_STATE_REQ,
+ /// Confirmation of the @ref MM_SET_VIF_STATE_REQ message.
+ MM_SET_VIF_STATE_CFM,
+ /// SLOT TIME PARAMETERS CONFIGURATION Request.
+ MM_SET_SLOTTIME_REQ,
+ /// SLOT TIME PARAMETERS CONFIGURATION Confirmation.
+ MM_SET_SLOTTIME_CFM,
+ /// Power Mode Change Request.
+ MM_SET_IDLE_REQ,
+ /// Power Mode Change Confirm.
+ MM_SET_IDLE_CFM,
+ /// KEY ADD Request.
+ MM_KEY_ADD_REQ,
+ /// KEY ADD Confirm.
+ MM_KEY_ADD_CFM,
+ /// KEY DEL Request.
+ MM_KEY_DEL_REQ,
+ /// KEY DEL Confirm.
+ MM_KEY_DEL_CFM,
+ /// Block Ack agreement info addition
+ MM_BA_ADD_REQ,
+ /// Block Ack agreement info addition confirmation
+ MM_BA_ADD_CFM,
+ /// Block Ack agreement info deletion
+ MM_BA_DEL_REQ,
+ /// Block Ack agreement info deletion confirmation
+ MM_BA_DEL_CFM,
+ /// Indication of the primary TBTT to the upper MAC. Upon the reception of
+ /// this
+ // message the upper MAC has to push the beacon(s) to the beacon
+ // transmission queue.
+ MM_PRIMARY_TBTT_IND,
+ /// Indication of the secondary TBTT to the upper MAC. Upon the reception of
+ /// this
+ // message the upper MAC has to push the beacon(s) to the beacon
+ // transmission queue.
+ MM_SECONDARY_TBTT_IND,
+ /// Request for changing the TX power
+ MM_SET_POWER_REQ,
+ /// Confirmation of the TX power change
+ MM_SET_POWER_CFM,
+ /// Request to the LMAC to trigger the embedded logic analyzer and forward
+ /// the debug
+ /// dump.
+ MM_DBG_TRIGGER_REQ,
+ /// Set Power Save mode
+ MM_SET_PS_MODE_REQ,
+ /// Set Power Save mode confirmation
+ MM_SET_PS_MODE_CFM,
+ /// Request to add a channel context
+ MM_CHAN_CTXT_ADD_REQ,
+ /// Confirmation of the channel context addition
+ MM_CHAN_CTXT_ADD_CFM,
+ /// Request to delete a channel context
+ MM_CHAN_CTXT_DEL_REQ,
+ /// Confirmation of the channel context deletion
+ MM_CHAN_CTXT_DEL_CFM,
+ /// Request to link a channel context to a VIF
+ MM_CHAN_CTXT_LINK_REQ,
+ /// Confirmation of the channel context link
+ MM_CHAN_CTXT_LINK_CFM,
+ /// Request to unlink a channel context from a VIF
+ MM_CHAN_CTXT_UNLINK_REQ,
+ /// Confirmation of the channel context unlink
+ MM_CHAN_CTXT_UNLINK_CFM,
+ /// Request to update a channel context
+ MM_CHAN_CTXT_UPDATE_REQ,
+ /// Confirmation of the channel context update
+ MM_CHAN_CTXT_UPDATE_CFM,
+ /// Request to schedule a channel context
+ MM_CHAN_CTXT_SCHED_REQ,
+ /// Confirmation of the channel context scheduling
+ MM_CHAN_CTXT_SCHED_CFM,
+ /// Request to change the beacon template in LMAC
+ MM_BCN_CHANGE_REQ,
+ /// Confirmation of the beacon change
+ MM_BCN_CHANGE_CFM,
+ /// Request to update the TIM in the beacon (i.e to indicate traffic
+ /// bufferized at AP)
+ MM_TIM_UPDATE_REQ,
+ /// Confirmation of the TIM update
+ MM_TIM_UPDATE_CFM,
+ /// Connection loss indication
+ MM_CONNECTION_LOSS_IND,
+ /// Channel context switch indication to the upper layers
+ MM_CHANNEL_SWITCH_IND,
+ /// Channel context pre-switch indication to the upper layers
+ MM_CHANNEL_PRE_SWITCH_IND,
+ /// Request to remain on channel or cancel remain on channel
+ MM_REMAIN_ON_CHANNEL_REQ,
+ /// Confirmation of the (cancel) remain on channel request
+ MM_REMAIN_ON_CHANNEL_CFM,
+ /// Remain on channel expired indication
+ MM_REMAIN_ON_CHANNEL_EXP_IND,
+ /// Indication of a PS state change of a peer device
+ MM_PS_CHANGE_IND,
+ /// Indication that some buffered traffic should be sent to the peer device
+ MM_TRAFFIC_REQ_IND,
+ /// Request to modify the STA Power-save mode options
+ MM_SET_PS_OPTIONS_REQ,
+ /// Confirmation of the PS options setting
+ MM_SET_PS_OPTIONS_CFM,
+ /// Indication of PS state change for a P2P VIF
+ MM_P2P_VIF_PS_CHANGE_IND,
+ /// Indication that CSA counter has been updated
+ MM_CSA_COUNTER_IND,
+ /// Channel occupation report indication
+ MM_CHANNEL_SURVEY_IND,
+ /// Message containing Beamformer Information
+ MM_BFMER_ENABLE_REQ,
+ /// Request to Start/Stop/Update NOA - GO Only
+ MM_SET_P2P_NOA_REQ,
+ /// Request to Start/Stop/Update Opportunistic PS - GO Only
+ MM_SET_P2P_OPPPS_REQ,
+ /// Start/Stop/Update NOA Confirmation
+ MM_SET_P2P_NOA_CFM,
+ /// Start/Stop/Update Opportunistic PS Confirmation
+ MM_SET_P2P_OPPPS_CFM,
+ /// P2P NoA Update Indication - GO Only
+ MM_P2P_NOA_UPD_IND,
+ /// Request to set RSSI threshold and RSSI hysteresis
+ MM_CFG_RSSI_REQ,
+ /// Indication that RSSI level is below or above the threshold
+ MM_RSSI_STATUS_IND,
+ /// Indication that CSA is done
+ MM_CSA_FINISH_IND,
+ /// Indication that CSA is in prorgess (resp. done) and traffic must be
+ /// stopped (resp. restarted)
+ MM_CSA_TRAFFIC_IND,
+ /// Request to update the group information of a station
+ MM_MU_GROUP_UPDATE_REQ,
+ /// Confirmation of the @ref MM_MU_GROUP_UPDATE_REQ message
+ MM_MU_GROUP_UPDATE_CFM,
+ /// Request to initialize the antenna diversity algorithm
+ MM_ANT_DIV_INIT_REQ,
+ /// Request to stop the antenna diversity algorithm
+ MM_ANT_DIV_STOP_REQ,
+ /// Request to update the antenna switch status
+ MM_ANT_DIV_UPDATE_REQ,
+ /// Request to switch the antenna connected to path_0
+ MM_SWITCH_ANTENNA_REQ,
+ /// Indication that a packet loss has occurred
+ MM_PKTLOSS_IND,
+
+ MM_SET_ARPOFFLOAD_REQ,
+ MM_SET_ARPOFFLOAD_CFM,
+ MM_SET_AGG_DISABLE_REQ,
+ MM_SET_AGG_DISABLE_CFM,
+ MM_SET_COEX_REQ,
+ MM_SET_COEX_CFM,
+ MM_SET_RF_CONFIG_REQ,
+ MM_SET_RF_CONFIG_CFM,
+ MM_SET_RF_CALIB_REQ,
+ MM_SET_RF_CALIB_CFM,
+
+ /// MU EDCA PARAMETERS Configuration Request.
+ MM_SET_MU_EDCA_REQ,
+ /// MU EDCA PARAMETERS Configuration Confirmation.
+ MM_SET_MU_EDCA_CFM,
+ /// UORA PARAMETERS Configuration Request.
+ MM_SET_UORA_REQ,
+ /// UORA PARAMETERS Configuration Confirmation.
+ MM_SET_UORA_CFM,
+ /// TXOP RTS THRESHOLD Configuration Request.
+ MM_SET_TXOP_RTS_THRES_REQ,
+ /// TXOP RTS THRESHOLD Configuration Confirmation.
+ MM_SET_TXOP_RTS_THRES_CFM,
+ /// HE BSS Color Configuration Request.
+ MM_SET_BSS_COLOR_REQ,
+ /// HE BSS Color Configuration Confirmation.
+ MM_SET_BSS_COLOR_CFM,
+
+ MM_GET_MAC_ADDR_REQ,
+ MM_GET_MAC_ADDR_CFM,
+
+ MM_GET_STA_INFO_REQ,
+ MM_GET_STA_INFO_CFM,
+
+ MM_SET_TXPWR_IDX_LVL_REQ,
+ MM_SET_TXPWR_IDX_LVL_CFM,
+
+ MM_SET_TXPWR_OFST_REQ,
+ MM_SET_TXPWR_OFST_CFM,
+
+ MM_SET_STACK_START_REQ,
+ MM_SET_STACK_START_CFM,
+
+ MM_APM_STALOSS_IND,
+
+ MM_SET_VENDOR_HWCONFIG_REQ,
+ MM_SET_VENDOR_HWCONFIG_CFM,
+
+ MM_GET_FW_VERSION_REQ,
+ MM_GET_FW_VERSION_CFM,
+
+ MM_SET_RESUME_RESTORE_REQ,
+ MM_SET_RESUME_RESTORE_CFM,
+
+ MM_GET_WIFI_DISABLE_REQ,
+ MM_GET_WIFI_DISABLE_CFM,
+
+ MM_CFG_RSSI_CFM,
+
+ MM_SET_VENDOR_SWCONFIG_REQ,
+ MM_SET_VENDOR_SWCONFIG_CFM,
+
+ MM_SET_TXPWR_LVL_ADJ_REQ,
+ MM_SET_TXPWR_LVL_ADJ_CFM,
+
+ MM_RADAR_DETECT_IND,
+
+ MM_SET_APF_PROG_REQ,
+ MM_SET_APF_PROG_CFM,
+
+ MM_GET_APF_PROG_REQ,
+ MM_GET_APF_PROG_CFM,
+
+ /// arp announcement frame reception indication
+ MM_ARP_ANNOUNCEMENT_IND,
+
+ /// MAX number of messages
+ MM_MAX,
+};
+
+/// Interface types
+enum {
+ /// ESS STA interface
+ MM_STA,
+ /// IBSS STA interface
+ MM_IBSS,
+ /// AP interface
+ MM_AP,
+ // Mesh Point interface
+ MM_MESH_POINT,
+ // Monitor interface
+ MM_MONITOR,
+};
+
+/// BA agreement types
+enum {
+ /// BlockAck agreement for TX
+ BA_AGMT_TX,
+ /// BlockAck agreement for RX
+ BA_AGMT_RX,
+};
+
+/// BA agreement related status
+enum {
+ /// Correct BA agreement establishment
+ BA_AGMT_ESTABLISHED,
+ /// BA agreement already exists for STA+TID requested, cannot override it
+ /// (should have been deleted first)
+ BA_AGMT_ALREADY_EXISTS,
+ /// Correct BA agreement deletion
+ BA_AGMT_DELETED,
+ /// BA agreement for the (STA, TID) doesn't exist so nothing to delete
+ BA_AGMT_DOESNT_EXIST,
+};
+
+/// Features supported by LMAC - Positions
+enum mm_features {
+ /// Beaconing
+ MM_FEAT_BCN_BIT = 0,
+ /*
+ * /// Autonomous Beacon Transmission
+ * MM_FEAT_AUTOBCN_BIT,
+ * /// Scan in LMAC
+ * MM_FEAT_HWSCAN_BIT,
+ * /// Connection Monitoring
+ * MM_FEAT_CMON_BIT,
+ * /// Multi Role
+ * MM_FEAT_MROLE_BIT,
+ */
+ /// Radar Detection
+ MM_FEAT_RADAR_BIT,
+ /// Power Save
+ MM_FEAT_PS_BIT,
+ /// UAPSD
+ MM_FEAT_UAPSD_BIT,
+ /// DPSM
+ // MM_FEAT_DPSM_BIT,
+ /// A-MPDU
+ MM_FEAT_AMPDU_BIT,
+ /// A-MSDU
+ MM_FEAT_AMSDU_BIT,
+ /// Channel Context
+ // MM_FEAT_CHNL_CTXT_BIT,
+ /// Packet reordering
+ // MM_FEAT_REORD_BIT,
+ /// P2P
+ MM_FEAT_P2P_BIT,
+ /// P2P Go
+ MM_FEAT_P2P_GO_BIT,
+ /// UMAC Present
+ MM_FEAT_UMAC_BIT,
+ /// VHT support
+ MM_FEAT_VHT_BIT,
+ /// Beamformee
+ MM_FEAT_BFMEE_BIT,
+ /// Beamformer
+ MM_FEAT_BFMER_BIT,
+ /// WAPI
+ MM_FEAT_WAPI_BIT,
+ /// MFP
+ MM_FEAT_MFP_BIT,
+ /// Mu-MIMO RX support
+ MM_FEAT_MU_MIMO_RX_BIT,
+ /// Mu-MIMO TX support
+ MM_FEAT_MU_MIMO_TX_BIT,
+ /// Wireless Mesh Networking
+ MM_FEAT_MESH_BIT,
+ /// TDLS support
+ MM_FEAT_TDLS_BIT,
+ /// Antenna Diversity support
+ MM_FEAT_ANT_DIV_BIT,
+ /// UF support
+ MM_FEAT_UF_BIT,
+ /// A-MSDU maximum size (bit0)
+ MM_AMSDU_MAX_SIZE_BIT0,
+ /// A-MSDU maximum size (bit1)
+ MM_AMSDU_MAX_SIZE_BIT1,
+ /// MON_DATA support
+ MM_FEAT_MON_DATA_BIT,
+ /// HE (802.11ax) support
+ MM_FEAT_HE_BIT,
+ /// TWT support
+ MM_FEAT_TWT_BIT,
+};
+
+/// Maximum number of words in the configuration buffer
+#define PHY_CFG_BUF_SIZE 16
+
+/// Structure containing the parameters of the PHY configuration
+struct phy_cfg_tag {
+ /// Buffer containing the parameters specific for the PHY used
+ u32 parameters[PHY_CFG_BUF_SIZE];
+};
+
+/// Structure containing the parameters of the Trident PHY configuration
+struct phy_trd_cfg_tag {
+ /// MDM type(nxm)(upper nibble) and MDM2RF path mapping(lower nibble)
+ u8 path_mapping;
+ /// TX DC offset compensation
+ u32 tx_dc_off_comp;
+};
+
+/// Structure containing the parameters of the Karst PHY configuration
+struct phy_karst_cfg_tag {
+ /// TX IQ mismatch compensation in 2.4GHz
+ u32 tx_iq_comp_2_4G[2];
+ /// RX IQ mismatch compensation in 2.4GHz
+ u32 rx_iq_comp_2_4G[2];
+ /// TX IQ mismatch compensation in 5GHz
+ u32 tx_iq_comp_5G[2];
+ /// RX IQ mismatch compensation in 5GHz
+ u32 rx_iq_comp_5G[2];
+ /// RF path used by default (0 or 1)
+ u8 path_used;
+};
+
+/// Structure containing the parameters of the @ref MM_START_REQ message
+struct mm_start_req {
+ /// PHY configuration
+ struct phy_cfg_tag phy_cfg;
+ /// UAPSD timeout
+ u32 uapsd_timeout;
+ /// Local LP clock accuracy (in ppm)
+ u16 lp_clk_accuracy;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_CHANNEL_REQ message
+struct mm_set_channel_req {
+ /// Channel information
+ struct mac_chan_op chan;
+ /// Index of the RF for which the channel has to be set (0: operating
+ /// (primary), 1: secondary RF (used for additional radar detection). This
+ /// parameter is reserved if no secondary RF is available in the system
+ u8 index;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_CHANNEL_CFM message
+struct mm_set_channel_cfm {
+ /// Radio index to be used in policy table
+ u8 radio_idx;
+ /// TX power configured (in dBm)
+ s8 power;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_DTIM_REQ message
+struct mm_set_dtim_req {
+ /// DTIM period
+ u8 dtim_period;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_POWER_REQ message
+struct mm_set_power_req {
+ /// Index of the interface for which the parameter is configured
+ u8 inst_nbr;
+ /// TX power (in dBm)
+ s8 power;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_POWER_CFM message
+struct mm_set_power_cfm {
+ /// Radio index to be used in policy table
+ u8 radio_idx;
+ /// TX power configured (in dBm)
+ s8 power;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_BEACON_INT_REQ
+/// message
+struct mm_set_beacon_int_req {
+ /// Beacon interval
+ u16 beacon_int;
+ /// Index of the interface for which the parameter is configured
+ u8 inst_nbr;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_BASIC_RATES_REQ
+/// message
+struct mm_set_basic_rates_req {
+ /// Basic rate set (as expected by bssBasicRateSet field of Rates MAC HW
+ /// register)
+ u32 rates;
+ /// Index of the interface for which the parameter is configured
+ u8 inst_nbr;
+ /// Band on which the interface will operate
+ u8 band;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_BSSID_REQ message
+struct mm_set_bssid_req {
+ /// BSSID to be configured in HW
+ struct mac_addr bssid;
+ /// Index of the interface for which the parameter is configured
+ u8 inst_nbr;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_FILTER_REQ message
+struct mm_set_filter_req {
+ /// RX filter to be put into rxCntrlReg HW register
+ u32 filter;
+};
+
+/// Structure containing the parameters of the @ref MM_ADD_IF_REQ message.
+struct mm_add_if_req {
+ /// Type of the interface (AP, STA, ADHOC, ...)
+ u8 type;
+ /// MAC ADDR of the interface to start
+ struct mac_addr addr;
+ /// P2P Interface
+ bool p2p;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_EDCA_REQ message
+struct mm_set_edca_req {
+ /// EDCA parameters of the queue (as expected by edcaACxReg HW register)
+ u32 ac_param;
+ /// Flag indicating if UAPSD can be used on this queue
+ bool uapsd;
+ /// HW queue for which the parameters are configured
+ u8 hw_queue;
+ /// Index of the interface for which the parameters are configured
+ u8 inst_nbr;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_MU_EDCA_REQ message
+struct mm_set_mu_edca_req {
+ /// MU EDCA parameters of the different HE queues
+ u32 param[AC_MAX];
+};
+
+/// Structure containing the parameters of the @ref MM_SET_UORA_REQ message
+struct mm_set_uora_req {
+ /// Minimum exponent of OFDMA Contention Window.
+ u8 eocw_min;
+ /// Maximum exponent of OFDMA Contention Window.
+ u8 eocw_max;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_TXOP_RTS_THRES_REQ
+/// message
+struct mm_set_txop_rts_thres_req {
+ /// TXOP RTS threshold
+ u16 txop_dur_rts_thres;
+ /// Index of the interface for which the parameter is configured
+ u8 inst_nbr;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_BSS_COLOR_REQ message
+struct mm_set_bss_color_req {
+ /// HE BSS color, formatted as per BSS_COLOR MAC HW register
+ u32 bss_color;
+};
+
+struct mm_set_idle_req {
+ u8 hw_idle;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_SLOTTIME_REQ message
+struct mm_set_slottime_req {
+ /// Slot time expressed in us
+ u8 slottime;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_MODE_REQ message
+struct mm_set_mode_req {
+ /// abgnMode field of macCntrl1Reg register
+ u8 abgnmode;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_VIF_STATE_REQ message
+struct mm_set_vif_state_req {
+ /// Association Id received from the AP (valid only if the VIF is of STA
+ /// type)
+ __le16 aid;
+ /// Flag indicating if the VIF is active or not
+ bool active;
+ /// Interface index
+ u8 inst_nbr;
+};
+
+/// Structure containing the parameters of the @ref MM_ADD_IF_CFM message.
+struct mm_add_if_cfm {
+ /// Status of operation (different from 0 if unsuccessful)
+ u8 status;
+ /// Interface index assigned by the LMAC
+ u8 inst_nbr;
+};
+
+/// Structure containing the parameters of the @ref MM_REMOVE_IF_REQ message.
+struct mm_remove_if_req {
+ /// Interface index assigned by the LMAC
+ u8 inst_nbr;
+};
+
+/// Structure containing the parameters of the @ref MM_VERSION_CFM message.
+struct mm_version_cfm {
+ /// Version of the LMAC FW
+ u32 version_lmac;
+ /// Version1 of the MAC HW (as encoded in version1Reg MAC HW register)
+ u32 version_machw_1;
+ /// Version2 of the MAC HW (as encoded in version2Reg MAC HW register)
+ u32 version_machw_2;
+ /// Version1 of the PHY (depends on actual PHY)
+ u32 version_phy_1;
+ /// Version2 of the PHY (depends on actual PHY)
+ u32 version_phy_2;
+ /// Supported Features
+ u32 features;
+ /// Maximum number of supported stations
+ u16 max_sta_nb;
+ /// Maximum number of supported virtual interfaces
+ u8 max_vif_nb;
+};
+
+/// Structure containing the parameters of the @ref MM_STA_ADD_REQ message.
+struct mm_sta_add_req {
+ /// Bitfield showing some capabilities of the STA (@ref enum mac_sta_flags)
+ u32 capa_flags;
+ /// Maximum A-MPDU size, in bytes, for HE frames
+ u32 ampdu_size_max_he;
+ /// Maximum A-MPDU size, in bytes, for VHT frames
+ u32 ampdu_size_max_vht;
+ /// PAID/GID
+ u32 paid_gid;
+ /// Maximum A-MPDU size, in bytes, for HT frames
+ u16 ampdu_size_max_ht;
+ /// MAC address of the station to be added
+ struct mac_addr mac_addr;
+ /// A-MPDU spacing, in us
+ u8 ampdu_spacing_min;
+ /// Interface index
+ u8 inst_nbr;
+ /// TDLS station
+ bool tdls_sta;
+ /// Indicate if the station is TDLS link initiator station
+ bool tdls_sta_initiator;
+ /// Indicate if the TDLS Channel Switch is allowed
+ bool tdls_chsw_allowed;
+ /// nonTransmitted BSSID index, set to the BSSID index in case the STA added
+ /// is an AP that is a nonTransmitted BSSID. Should be set to 0 otherwise
+ u8 bssid_index;
+ /// Maximum BSSID indicator, valid if the STA added is an AP that is a
+ /// nonTransmitted BSSID
+ u8 max_bssid_ind;
+};
+
+/// Structure containing the parameters of the @ref MM_STA_ADD_CFM message.
+struct mm_sta_add_cfm {
+ /// Status of the operation (different from 0 if unsuccessful)
+ u8 status;
+ /// Index assigned by the LMAC to the newly added station
+ u8 sta_idx;
+ /// MAC HW index of the newly added station
+ u8 hw_sta_idx;
+};
+
+/// Structure containing the parameters of the @ref MM_STA_DEL_REQ message.
+struct mm_sta_del_req {
+ /// Index of the station to be deleted
+ u8 sta_idx;
+};
+
+/// Structure containing the parameters of the @ref MM_STA_DEL_CFM message.
+struct mm_sta_del_cfm {
+ /// Status of the operation (different from 0 if unsuccessful)
+ u8 status;
+};
+
+/// Structure containing the parameters of the SET_POWER_MODE REQ message.
+struct mm_setpowermode_req {
+ u8 mode;
+ u8 sta_idx;
+};
+
+/// Structure containing the parameters of the SET_POWER_MODE CFM message.
+struct mm_setpowermode_cfm {
+ u8 status;
+};
+
+/// Structure containing the parameters of the @ref MM_KEY_ADD REQ message.
+struct mm_key_add_req {
+ /// Key index (valid only for default keys)
+ u8 key_idx;
+ /// STA index (valid only for pairwise or mesh group keys)
+ u8 sta_idx;
+ /// Key material
+ struct mac_sec_key key;
+ /// Cipher suite (WEP64, WEP128, TKIP, CCMP)
+ u8 cipher_suite;
+ /// Index of the interface for which the key is set (valid only for default
+ /// keys or mesh group keys)
+ u8 inst_nbr;
+ /// A-MSDU SPP parameter
+ u8 spp;
+ /// Indicate if provided key is a pairwise key or not
+ bool pairwise;
+};
+
+/// Structure containing the parameters of the @ref MM_KEY_ADD_CFM message.
+struct mm_key_add_cfm {
+ /// Status of the operation (different from 0 if unsuccessful)
+ u8 status;
+ /// HW index of the key just added
+ u8 hw_key_idx;
+};
+
+/// Structure containing the parameters of the @ref MM_KEY_DEL_REQ message.
+struct mm_key_del_req {
+ /// HW index of the key to be deleted
+ u8 hw_key_idx;
+};
+
+/// Structure containing the parameters of the @ref MM_BA_ADD_REQ message.
+struct mm_ba_add_req {
+ /// Type of agreement (0: TX, 1: RX)
+ u8 type;
+ /// Index of peer station with which the agreement is made
+ u8 sta_idx;
+ /// TID for which the agreement is made with peer station
+ u8 tid;
+ /// Buffer size - number of MPDUs that can be held in its buffer per TID
+ u8 bufsz;
+ /// Start sequence number negotiated during BA setup - the one in first
+ /// aggregated MPDU counts more
+ u16 ssn;
+};
+
+/// Structure containing the parameters of the @ref MM_BA_ADD_CFM message.
+struct mm_ba_add_cfm {
+ /// Index of peer station for which the agreement is being confirmed
+ u8 sta_idx;
+ /// TID for which the agreement is being confirmed
+ u8 tid;
+ /// Status of ba establishment
+ u8 status;
+};
+
+/// Structure containing the parameters of the @ref MM_BA_DEL_REQ message.
+struct mm_ba_del_req {
+ /// Type of agreement (0: TX, 1: RX)
+ u8 type;
+ /// Index of peer station for which the agreement is being deleted
+ u8 sta_idx;
+ /// TID for which the agreement is being deleted
+ u8 tid;
+};
+
+/// Structure containing the parameters of the @ref MM_BA_DEL_CFM message.
+struct mm_ba_del_cfm {
+ /// Index of peer station for which the agreement deletion is being
+ /// confirmed
+ u8 sta_idx;
+ /// TID for which the agreement deletion is being confirmed
+ u8 tid;
+ /// Status of ba deletion
+ u8 status;
+};
+
+/// Structure containing the parameters of the @ref MM_CHAN_CTXT_ADD_REQ message
+struct mm_chan_ctxt_add_req {
+ /// Operating channel
+ struct mac_chan_op chan;
+};
+
+/// Structure containing the parameters of the @ref MM_CHAN_CTXT_ADD_REQ message
+struct mm_chan_ctxt_add_cfm {
+ /// Status of the addition
+ u8 status;
+ /// Index of the new channel context
+ u8 index;
+};
+
+/// Structure containing the parameters of the @ref MM_CHAN_CTXT_DEL_REQ message
+struct mm_chan_ctxt_del_req {
+ /// Index of the new channel context to be deleted
+ u8 index;
+};
+
+/// Structure containing the parameters of the @ref MM_CHAN_CTXT_LINK_REQ
+/// message
+struct mm_chan_ctxt_link_req {
+ /// VIF index
+ u8 vif_index;
+ /// Channel context index
+ u8 chan_index;
+ /// Indicate if this is a channel switch (unlink current ctx first if true)
+ u8 chan_switch;
+};
+
+/// Structure containing the parameters of the @ref MM_CHAN_CTXT_UNLINK_REQ
+/// message
+struct mm_chan_ctxt_unlink_req {
+ /// VIF index
+ u8 vif_index;
+};
+
+/// Structure containing the parameters of the @ref MM_CHAN_CTXT_UPDATE_REQ
+/// message
+struct mm_chan_ctxt_update_req {
+ /// Channel context index
+ u8 chan_index;
+ /// New channel information
+ struct mac_chan_op chan;
+};
+
+/// Structure containing the parameters of the @ref MM_CHAN_CTXT_SCHED_REQ
+/// message
+struct mm_chan_ctxt_sched_req {
+ /// VIF index
+ u8 vif_index;
+ /// Channel context index
+ u8 chan_index;
+ /// Type of the scheduling request (0: normal scheduling, 1: derogatory
+ /// scheduling)
+ u8 type;
+};
+
+/// Structure containing the parameters of the @ref MM_CHANNEL_SWITCH_IND
+/// message
+struct mm_channel_switch_ind {
+ /// Index of the channel context we will switch to
+ u8 chan_index;
+ /// Indicate if the switch has been triggered by a Remain on channel request
+ bool roc;
+ /// VIF on which remain on channel operation has been started (if roc == 1)
+ u8 vif_index;
+ /// Indicate if the switch has been triggered by a TDLS Remain on channel
+ /// request
+ bool roc_tdls;
+};
+
+/// Structure containing the parameters of the @ref MM_CHANNEL_PRE_SWITCH_IND
+/// message
+struct mm_channel_pre_switch_ind {
+ /// Index of the channel context we will switch to
+ u8 chan_index;
+};
+
+/// Structure containing the parameters of the @ref MM_CONNECTION_LOSS_IND
+/// message.
+struct mm_connection_loss_ind {
+ /// VIF instance number
+ u8 inst_nbr;
+};
+
+/// Structure containing the parameters of the @ref MM_DBG_TRIGGER_REQ message.
+struct mm_dbg_trigger_req {
+ /// Error trace to be reported by the LMAC
+ char error[64];
+};
+
+/// Structure containing the parameters of the @ref MM_SET_PS_MODE_REQ message.
+struct mm_set_ps_mode_req {
+ /// Power Save is activated or deactivated
+ u8 new_state;
+};
+
+/// Structure containing the parameters of the @ref MM_BCN_CHANGE_REQ message.
+#define BCN_MAX_CSA_CPT 2
+struct mm_bcn_change_req {
+ /// Pointer, in host memory, to the new beacon template
+ u32 bcn_ptr;
+ /// Length of the beacon template
+ u16 bcn_len;
+ /// Offset of the TIM IE in the beacon
+ u16 tim_oft;
+ /// Length of the TIM IE
+ u8 tim_len;
+ /// Index of the VIF for which the beacon is updated
+ u8 inst_nbr;
+ /// Offset of CSA (channel switch announcement) counters (0 means no
+ /// counter)
+ u8 csa_oft[BCN_MAX_CSA_CPT];
+};
+
+/// Structure containing the parameters of the @ref MM_TIM_UPDATE_REQ message.
+struct mm_tim_update_req {
+ /// Association ID of the STA the bit of which has to be updated (0 for
+ /// BC/MC traffic)
+ u16 aid;
+ /// Flag indicating the availability of data packets for the given STA
+ u8 tx_avail;
+ /// Index of the VIF for which the TIM is updated
+ u8 inst_nbr;
+};
+
+/// Structure containing the parameters of the @ref MM_REMAIN_ON_CHANNEL_REQ
+/// message.
+struct mm_remain_on_channel_req {
+ /// Operation Code
+ u8 op_code;
+ /// VIF Index
+ u8 vif_index;
+ /// Band (2.4GHz or 5GHz)
+ u8 band;
+ /// Channel type: 20,40,80,160 or 80+80 MHz
+ u8 type;
+ /// Frequency for Primary 20MHz channel (in MHz)
+ u16 prim20_freq;
+ /// Frequency for Center of the contiguous channel or center of Primary
+ /// 80+80
+ u16 center1_freq;
+ /// Frequency for Center of the non-contiguous secondary 80+80
+ u16 center2_freq;
+ /// Duration (in ms)
+ u32 duration_ms;
+ /// TX power (in dBm)
+ s8 tx_power;
+};
+
+/// Structure containing the parameters of the @ref MM_REMAIN_ON_CHANNEL_CFM
+/// message
+struct mm_remain_on_channel_cfm {
+ /// Operation Code
+ u8 op_code;
+ /// Status of the operation
+ u8 status;
+ /// Channel Context index
+ u8 chan_ctxt_index;
+};
+
+/// Structure containing the parameters of the @ref MM_REMAIN_ON_CHANNEL_EXP_IND
+/// message
+struct mm_remain_on_channel_exp_ind {
+ /// VIF Index
+ u8 vif_index;
+ /// Channel Context index
+ u8 chan_ctxt_index;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_UAPSD_TMR_REQ
+/// message.
+struct mm_set_uapsd_tmr_req {
+ /// action: Start or Stop the timer
+ u8 action;
+ /// timeout value, in milliseconds
+ u32 timeout;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_UAPSD_TMR_CFM
+/// message.
+struct mm_set_uapsd_tmr_cfm {
+ /// Status of the operation (different from 0 if unsuccessful)
+ u8 status;
+};
+
+/// Structure containing the parameters of the @ref MM_PS_CHANGE_IND message
+struct mm_ps_change_ind {
+ /// Index of the peer device that is switching its PS state
+ u8 sta_idx;
+ /// New PS state of the peer device (0: active, 1: sleeping)
+ u8 ps_state;
+};
+
+/// Structure containing the parameters of the @ref MM_P2P_VIF_PS_CHANGE_IND
+/// message
+struct mm_p2p_vif_ps_change_ind {
+ /// Index of the P2P VIF that is switching its PS state
+ u8 vif_index;
+ /// New PS state of the P2P VIF interface (0: active, 1: sleeping)
+ u8 ps_state;
+};
+
+/// Structure containing the parameters of the @ref MM_TRAFFIC_REQ_IND message
+struct mm_traffic_req_ind {
+ /// Index of the peer device that needs traffic
+ u8 sta_idx;
+ /// Number of packets that need to be sent (if 0, all buffered traffic shall
+ /// be sent and if set to @ref PS_SP_INTERRUPTED, it means that current
+ /// service period has been interrupted)
+ u8 pkt_cnt;
+ /// Flag indicating if the traffic request concerns U-APSD queues or not
+ bool uapsd;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_PS_OPTIONS_REQ
+/// message.
+struct mm_set_ps_options_req {
+ /// VIF Index
+ u8 vif_index;
+ /// Listen interval (0 if wake up shall be based on DTIM period)
+ u16 listen_interval;
+ /// Flag indicating if we shall listen the BC/MC traffic or not
+ bool dont_listen_bc_mc;
+};
+
+/// Structure containing the parameters of the @ref MM_CSA_COUNTER_IND message
+struct mm_csa_counter_ind {
+ /// Index of the VIF
+ u8 vif_index;
+ /// Updated CSA counter value
+ u8 csa_count;
+};
+
+/// Structure containing the parameters of the @ref MM_CHANNEL_SURVEY_IND
+/// message
+struct mm_channel_survey_ind {
+ /// Frequency of the channel
+ u16 freq;
+ /// Noise in dbm
+ s8 noise_dbm;
+ /// Amount of time spent of the channel (in ms)
+ u32 chan_time_ms;
+ /// Amount of time the primary channel was sensed busy
+ u32 chan_time_busy_ms;
+};
+
+/// Structure containing the parameters of the @ref MM_BFMER_ENABLE_REQ message.
+struct mm_bfmer_enable_req {
+ /**
+ * Address of the beamforming report space allocated in host memory
+ * (Valid only if vht_su_bfmee is true)
+ */
+ u32 host_bfr_addr;
+ /**
+ * Size of the beamforming report space allocated in host memory. This space
+ * should be twice the maximum size of the expected beamforming reports as
+ * the FW will divide it in two in order to be able to upload a new report
+ * while another one is used in transmission
+ */
+ u16 host_bfr_size;
+ /// AID
+ u16 aid;
+ /// Station Index
+ u8 sta_idx;
+ /// Maximum number of spatial streams the station can receive
+ u8 rx_nss;
+ /**
+ * Indicate if peer STA is MU Beamformee (VHT) capable
+ * (Valid only if vht_su_bfmee is true)
+ */
+ bool vht_mu_bfmee;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_P2P_NOA_REQ message.
+struct mm_set_p2p_noa_req {
+ /// VIF Index
+ u8 vif_index;
+ /// Allocated NOA Instance Number - Valid only if count = 0
+ u8 noa_inst_nb;
+ /// Count
+ u8 count;
+ /// Indicate if NoA can be paused for traffic reason
+ bool dyn_noa;
+ /// Duration (in us)
+ u32 duration_us;
+ /// Interval (in us)
+ u32 interval_us;
+ /// Start Time offset from next TBTT (in us)
+ u32 start_offset;
+};
+
+#ifdef CONFIG_AIC8800_ARP_OFFLOAD
+struct mm_set_arpoffload_en_req {
+ u32 ipaddr;
+ u8 enable;
+ u8 vif_idx;
+};
+
+struct mm_set_arpoffload_en_cfm {
+ u8 status;
+};
+#endif
+
+struct mm_set_agg_disable_req {
+ u8 disable;
+ u8 staidx;
+ u8 disable_rx;
+};
+
+struct mm_set_rf_config_req {
+ u8 table_sel;
+ u8 table_ofst;
+ u8 table_num;
+ u8 deft_page;
+ u32 data[64];
+};
+
+struct mm_set_rf_calib_req {
+ u32 cal_cfg_24g;
+ u32 cal_cfg_5g;
+ u32 param_alpha;
+ u32 bt_calib_en;
+ u32 bt_calib_param;
+ u8 xtal_cap;
+ u8 xtal_cap_fine;
+};
+
+struct mm_set_rf_calib_cfm {
+ u32 rxgain_24g_addr;
+ u32 rxgain_5g_addr;
+ u32 txgain_24g_addr;
+ u32 txgain_5g_addr;
+};
+
+struct mm_get_mac_addr_req {
+ u32 get;
+};
+
+struct mm_get_mac_addr_cfm {
+ u8 mac_addr[6];
+};
+
+struct mm_get_sta_info_req {
+ u8 sta_idx;
+};
+
+struct mm_get_sta_info_cfm {
+ u32 rate_info;
+ u32 txfailed;
+ u8 rssi;
+};
+
+#define REGION_NUM_MAX 5
+
+struct txpwr_lvl_conf {
+ u8 enable;
+ u8 dsss;
+ u8 ofdmlowrate_2g4;
+ u8 ofdm64qam_2g4;
+ u8 ofdm256qam_2g4;
+ u8 ofdm1024qam_2g4;
+ u8 ofdmlowrate_5g;
+ u8 ofdm64qam_5g;
+ u8 ofdm256qam_5g;
+ u8 ofdm1024qam_5g;
+};
+
+struct txpwr_lvl_conf_v2 {
+ u8 enable;
+ s8 pwrlvl_11b_11ag_2g4[12];
+ s8 pwrlvl_11n_11ac_2g4[10];
+ s8 pwrlvl_11ax_2g4[12];
+};
+
+struct txpwr_lvl_conf_v3 {
+ u8 enable;
+ s8 pwrlvl_11b_11ag_2g4[12];
+ s8 pwrlvl_11n_11ac_2g4[10];
+ s8 pwrlvl_11ax_2g4[12];
+ s8 pwrlvl_11a_5g[12];
+ s8 pwrlvl_11n_11ac_5g[10];
+ s8 pwrlvl_11ax_5g[12];
+};
+
+struct txpwr_lvl_adj_conf {
+ u8 enable;
+ s8 pwrlvl_adj_tbl_2g4[3];
+ s8 pwrlvl_adj_tbl_5g[6];
+};
+
+struct txpwr_loss_conf {
+ u8 loss_enable_2g4;
+ s8 loss_value_2g4;
+ u8 loss_enable_5g;
+ s8 loss_value_5g;
+};
+
+struct mm_set_txpwr_lvl_req {
+ union {
+ struct txpwr_lvl_conf txpwr_lvl;
+ struct txpwr_lvl_conf_v2 txpwr_lvl_v2;
+ struct txpwr_lvl_conf_v3 txpwr_lvl_v3;
+ };
+};
+
+struct mm_set_txpwr_lvl_adj_req {
+ struct txpwr_lvl_adj_conf txpwr_lvl_adj;
+};
+
+struct txpwr_idx_conf {
+ u8 enable;
+ u8 dsss;
+ u8 ofdmlowrate_2g4;
+ u8 ofdm64qam_2g4;
+ u8 ofdm256qam_2g4;
+ u8 ofdm1024qam_2g4;
+ u8 ofdmlowrate_5g;
+ u8 ofdm64qam_5g;
+ u8 ofdm256qam_5g;
+ u8 ofdm1024qam_5g;
+};
+
+struct mm_set_txpwr_idx_req {
+ struct txpwr_idx_conf txpwr_idx;
+};
+
+struct txpwr_ofst_conf {
+ u8 enable;
+ s8 chan_1_4;
+ s8 chan_5_9;
+ s8 chan_10_13;
+ s8 chan_36_64;
+ s8 chan_100_120;
+ s8 chan_122_140;
+ s8 chan_142_165;
+};
+
+/*
+ * pwrofst2x_tbl_2g4[3][3]:
+ * +---------------+----------+----------+----------+
+ * | RateTyp\ChGrp | CH_1_4 | CH_5_9 | CH_10_13 |
+ * +---------------+----------+----------+----------+
+ * | DSSS | [0][0] | [0][1] | [0][2] |
+ * +---------------+----------+----------+----------+
+ * | OFDM_HIGHRATE | [1][0] | [1][1] | [1][2] |
+ * +---------------+----------+----------+----------+
+ * | OFDM_LOWRATE | [2][0] | [2][1] | [2][2] |
+ * +---------------+----------+----------+----------+
+ * pwrofst2x_tbl_5g[3][6]:
+ * +---------------+--------------+--------------+----------------+----------------+--+--+
+ * | RateTyp\ChGrp | CH_42(36~50) | CH_58(51~64) | CH_106(98~114) |
+ * CH_122(115~130)| CH_138(131~146)| CH_155(147~166)|
+ * +---------------+--------------+--------------+----------------+----------------+--+--+
+ * | OFDM_LOWRATE | [0][0] | [0][1] | [0][2] | [0][3]
+ * | [0][4] | [0][5] |
+ * +---------------+--------------+--------------+----------------+----------------+--+--+
+ * | OFDM_HIGHRATE | [1][0] | [1][1] | [1][2] | [1][3]
+ * | [1][4] | [1][5] |
+ * +---------------+--------------+--------------+----------------+----------------+--+--+
+ * | OFDM_MIDRATE | [2][0] | [2][1] | [2][2] | [2][3]
+ * | [2][4] | [2][5] |
+ * +---------------+--------------+--------------+----------------+----------------+--+--+
+ */
+
+struct txpwr_ofst2x_conf {
+ s8 enable;
+ s8 pwrofst2x_tbl_2g4[3][3];
+ s8 pwrofst2x_tbl_5g[3][6];
+};
+
+struct xtal_cap_conf {
+ u8 enable;
+ u8 xtal_cap;
+ u8 xtal_cap_fine;
+};
+
+struct mm_set_txpwr_ofst_req {
+ union {
+ struct txpwr_ofst_conf txpwr_ofst;
+ struct txpwr_ofst2x_conf txpwr_ofst2x;
+ };
+};
+
+struct mm_set_stack_start_req {
+ u8 is_stack_start;
+ u8 efuse_valid;
+ u8 set_vendor_info;
+ u8 fwtrace_redir;
+};
+
+struct mm_set_stack_start_cfm {
+ u8 is_5g_support;
+ u8 vendor_info;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_P2P_OPPPS_REQ
+/// message.
+struct mm_set_p2p_oppps_req {
+ /// VIF Index
+ u8 vif_index;
+ /// CTWindow
+ u8 ctwindow;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_P2P_NOA_CFM message.
+struct mm_set_p2p_noa_cfm {
+ /// Request status
+ u8 status;
+};
+
+/// Structure containing the parameters of the @ref MM_SET_P2P_OPPPS_CFM
+/// message.
+struct mm_set_p2p_oppps_cfm {
+ /// Request status
+ u8 status;
+};
+
+/// Structure containing the parameters of the @ref MM_P2P_NOA_UPD_IND message.
+struct mm_p2p_noa_upd_ind {
+ /// VIF Index
+ u8 vif_index;
+ /// NOA Instance Number
+ u8 noa_inst_nb;
+ /// NoA Type
+ u8 noa_type;
+ /// Count
+ u8 count;
+ /// Duration (in us)
+ u32 duration_us;
+ /// Interval (in us)
+ u32 interval_us;
+ /// Start Time
+ u32 start_time;
+};
+
+/// Structure containing the parameters of the @ref MM_CFG_RSSI_REQ message
+struct mm_cfg_rssi_req {
+ /// Index of the VIF
+ u8 vif_index;
+ /// RSSI threshold
+ s8 rssi_thold;
+ /// RSSI hysteresis
+ u8 rssi_hyst;
+};
+
+/// Structure containing the parameters of the @ref MM_RSSI_STATUS_IND message
+struct mm_rssi_status_ind {
+ /// Index of the VIF
+ u8 vif_index;
+ /// Status of the RSSI
+ bool rssi_status;
+ /// Current RSSI
+ s8 rssi;
+};
+
+/// Structure containing the parameters of the @ref MM_PKTLOSS_IND message
+struct mm_pktloss_ind {
+ /// Index of the VIF
+ u8 vif_index;
+ /// Address of the STA for which there is a packet loss
+ struct mac_addr mac_addr;
+ /// Number of packets lost
+ u32 num_packets;
+};
+
+/// Structure containing the parameters of the @ref MM_CSA_FINISH_IND message
+struct mm_csa_finish_ind {
+ /// Index of the VIF
+ u8 vif_index;
+ /// Status of the operation
+ u8 status;
+ /// New channel ctx index
+ u8 chan_idx;
+};
+
+/// Structure containing the parameters of the @ref MM_CSA_TRAFFIC_IND message
+struct mm_csa_traffic_ind {
+ /// Index of the VIF
+ u8 vif_index;
+ /// Is tx traffic enable or disable
+ bool enable;
+};
+
+/// Structure containing the parameters of the @ref MM_MU_GROUP_UPDATE_REQ
+/// message. Size allocated for the structure depends of the number of group
+struct mm_mu_group_update_req {
+ /// Station index
+ u8 sta_idx;
+ /// Number of groups the STA belongs to
+ u8 group_cnt;
+ /// Group information
+ struct {
+ /// Group Id
+ u8 group_id;
+ /// User position
+ u8 user_pos;
+ } groups[];
+};
+
+///////////////////////////////////////////////////////////////////////////////
+/////////// For Scan messages
+///////////////////////////////////////////////////////////////////////////////
+enum scan_msg_tag {
+ /// Scanning start Request.
+ SCAN_START_REQ = LMAC_FIRST_MSG(TASK_SCAN),
+ /// Scanning start Confirmation.
+ SCAN_START_CFM,
+ /// End of scanning indication.
+ SCAN_DONE_IND,
+ /// Cancel scan request
+ SCAN_CANCEL_REQ,
+ /// Cancel scan confirmation
+ SCAN_CANCEL_CFM,
+
+ /// MAX number of messages
+ SCAN_MAX,
+};
+
+/// Maximum number of SSIDs in a scan request
+#define SCAN_SSID_MAX 3
+
+/// Maximum number of channels in a scan request
+#define SCAN_CHANNEL_MAX (MAC_DOMAINCHANNEL_24G_MAX + MAC_DOMAINCHANNEL_5G_MAX)
+
+/// Maximum length of the ProbeReq IEs (SoftMAC mode)
+#define SCAN_MAX_IE_LEN 300
+
+/// Maximum number of PHY bands supported
+#define SCAN_BAND_MAX 2
+
+/// Structure containing the parameters of the @ref SCAN_START_REQ message
+struct scan_start_req {
+ /// List of channel to be scanned
+ struct mac_chan_def chan[SCAN_CHANNEL_MAX];
+ /// List of SSIDs to be scanned
+ struct mac_ssid ssid[SCAN_SSID_MAX];
+ /// BSSID to be scanned
+ struct mac_addr bssid;
+ /// Pointer (in host memory) to the additional IEs that need to be added to
+ /// the ProbeReq (following the SSID element)
+ u32 add_ies;
+ /// Length of the additional IEs
+ u16 add_ie_len;
+ /// Index of the VIF that is scanning
+ u8 vif_idx;
+ /// Number of channels to scan
+ u8 chan_cnt;
+ /// Number of SSIDs to scan for
+ u8 ssid_cnt;
+ /// no CCK - For P2P frames not being sent at CCK rate in 2GHz band.
+ bool no_cck;
+ /// Scan duration, in us
+ u32 duration;
+};
+
+/// Structure containing the parameters of the @ref SCAN_START_CFM message
+struct scan_start_cfm {
+ /// Status of the request
+ u8 status;
+};
+
+/// Structure containing the parameters of the @ref SCAN_CANCEL_REQ message
+struct scan_cancel_req {
+};
+
+/// Structure containing the parameters of the @ref SCAN_START_CFM message
+struct scan_cancel_cfm {
+ /// Status of the request
+ u8 status;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+/////////// For Scanu messages
+///////////////////////////////////////////////////////////////////////////////
+/// Messages that are logically related to the task.
+enum {
+ /// Scan request from host.
+ SCANU_START_REQ = LMAC_FIRST_MSG(TASK_SCANU),
+ /// Scanning start Confirmation.
+ SCANU_START_CFM,
+ /// Join request
+ SCANU_JOIN_REQ,
+ /// Join confirmation.
+ SCANU_JOIN_CFM,
+ /// Scan result indication.
+ SCANU_RESULT_IND,
+ /// Fast scan request from any other module.
+ SCANU_FAST_REQ,
+ /// Confirmation of fast scan request.
+ SCANU_FAST_CFM,
+
+ SCANU_VENDOR_IE_REQ,
+ SCANU_VENDOR_IE_CFM,
+ SCANU_START_CFM_ADDTIONAL,
+ SCANU_CANCEL_REQ,
+ SCANU_CANCEL_CFM,
+
+ /// MAX number of messages
+ SCANU_MAX,
+};
+
+/// Maximum length of the additional ProbeReq IEs (FullMAC mode)
+#define SCANU_MAX_IE_LEN 200
+
+/// Structure containing the parameters of the @ref SCANU_START_REQ message
+struct scanu_start_req {
+ /// List of channel to be scanned
+ struct mac_chan_def chan[SCAN_CHANNEL_MAX];
+ /// List of SSIDs to be scanned
+ struct mac_ssid ssid[SCAN_SSID_MAX];
+ /// BSSID to be scanned (or WILDCARD BSSID if no BSSID is searched in
+ /// particular)
+ struct mac_addr bssid;
+ /// Address (in host memory) of the additional IEs that need to be added to
+ /// the ProbeReq (following the SSID element)
+ u32 add_ies;
+ /// Length of the additional IEs
+ u16 add_ie_len;
+ /// Index of the VIF that is scanning
+ u8 vif_idx;
+ /// Number of channels to scan
+ u8 chan_cnt;
+ /// Number of SSIDs to scan for
+ u8 ssid_cnt;
+ /// no CCK - For P2P frames not being sent at CCK rate in 2GHz band.
+ bool no_cck;
+ /// Scan duration, in us
+ u32 duration;
+};
+
+struct scanu_vendor_ie_req {
+ u16 add_ie_len;
+ u8 vif_idx;
+ u8 ie[256];
+};
+
+/// Structure containing the parameters of the @ref SCANU_START_CFM message
+struct scanu_start_cfm {
+ /// Index of the VIF that was scanning
+ u8 vif_idx;
+ /// Status of the request
+ u8 status;
+ /// Number of scan results available
+ u8 result_cnt;
+};
+
+/// Parameters of the @SCANU_RESULT_IND message
+struct scanu_result_ind {
+ /// Length of the frame
+ u16 length;
+ /// Frame control field of the frame.
+ u16 framectrl;
+ /// Center frequency on which we received the packet
+ u16 center_freq;
+ /// PHY band
+ u8 band;
+ /// Index of the station that sent the frame. 0xFF if unknown.
+ u8 sta_idx;
+ /// Index of the VIF that received the frame. 0xFF if unknown.
+ u8 inst_nbr;
+ /// RSSI of the received frame.
+ s8 rssi;
+ /// Frame payload.
+ u32 payload[];
+};
+
+struct rxu_arp_announcement_ind {
+ /// index of the vif
+ u8 vif_index;
+ u8 offset;
+ /// length of the frame
+ u16 length;
+ u32 rx_status;
+ /// frame payload
+ u8 payload[];
+};
+
+/// Structure containing the parameters of the message.
+struct scanu_fast_req {
+ /// The SSID to scan in the channel.
+ struct mac_ssid ssid;
+ /// BSSID.
+ struct mac_addr bssid;
+ /// Probe delay.
+ u16 probe_delay;
+ /// Minimum channel time.
+ u16 minch_time;
+ /// Maximum channel time.
+ u16 maxch_time;
+ /// The channel number to scan.
+ u16 ch_nbr;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+/////////// For ME messages
+///////////////////////////////////////////////////////////////////////////////
+/// Messages that are logically related to the task.
+enum {
+ /// Configuration request from host.
+ ME_CONFIG_REQ = LMAC_FIRST_MSG(TASK_ME),
+ /// Configuration confirmation.
+ ME_CONFIG_CFM,
+ /// Configuration request from host.
+ ME_CHAN_CONFIG_REQ,
+ /// Configuration confirmation.
+ ME_CHAN_CONFIG_CFM,
+ /// Set control port state for a station.
+ ME_SET_CONTROL_PORT_REQ,
+ /// Control port setting confirmation.
+ ME_SET_CONTROL_PORT_CFM,
+ /// TKIP MIC failure indication.
+ ME_TKIP_MIC_FAILURE_IND,
+ /// Add a station to the FW (AP mode)
+ ME_STA_ADD_REQ,
+ /// Confirmation of the STA addition
+ ME_STA_ADD_CFM,
+ /// Delete a station from the FW (AP mode)
+ ME_STA_DEL_REQ,
+ /// Confirmation of the STA deletion
+ ME_STA_DEL_CFM,
+ /// Indication of a TX RA/TID queue credit update
+ ME_TX_CREDITS_UPDATE_IND,
+ /// Request indicating to the FW that there is traffic buffered on host
+ ME_TRAFFIC_IND_REQ,
+ /// Confirmation that the @ref ME_TRAFFIC_IND_REQ has been executed
+ ME_TRAFFIC_IND_CFM,
+ /// Request of RC statistics to a station
+ ME_RC_STATS_REQ,
+ /// RC statistics confirmation
+ ME_RC_STATS_CFM,
+ /// RC fixed rate request
+ ME_RC_SET_RATE_REQ,
+ /// Configure monitor interface
+ ME_CONFIG_MONITOR_REQ,
+ /// Configure monitor interface response
+ ME_CONFIG_MONITOR_CFM,
+ /// Setting power Save mode request from host
+ ME_SET_PS_MODE_REQ,
+ /// Set power Save mode confirmation
+ ME_SET_PS_MODE_CFM,
+ /// Setting Low Power level request from host
+ ME_SET_LP_LEVEL_REQ,
+ /// Set Low Power level confirmation
+ ME_SET_LP_LEVEL_CFM,
+ /// MAX number of messages
+ ME_MAX,
+};
+
+/// Structure containing the parameters of the @ref ME_START_REQ message
+struct me_config_req {
+ /// HT Capabilities
+ struct mac_htcapability ht_cap;
+ /// VHT Capabilities
+ struct mac_vhtcapability vht_cap;
+ /// HE capabilities
+ struct mac_hecapability he_cap;
+ /// Lifetime of packets sent under a BlockAck agreement (expressed in TUs)
+ u16 tx_lft;
+ /// Maximum supported BW
+ u8 phy_bw_max;
+ /// Boolean indicating if HT is supported or not
+ bool ht_supp;
+ /// Boolean indicating if VHT is supported or not
+ bool vht_supp;
+ /// Boolean indicating if HE is supported or not
+ bool he_supp;
+ /// Boolean indicating if HE OFDMA UL is enabled or not
+ bool he_ul_on;
+ /// Boolean indicating if PS mode shall be enabled or not
+ bool ps_on;
+ /// Boolean indicating if Antenna Diversity shall be enabled or not
+ bool ant_div_on;
+ /// Boolean indicating if Dynamic PS mode shall be used or not
+ bool dpsm;
+};
+
+/// Structure containing the parameters of the @ref ME_CHAN_CONFIG_REQ message
+struct me_chan_config_req {
+ /// List of 2.4GHz supported channels
+ struct mac_chan_def chan2G4[MAC_DOMAINCHANNEL_24G_MAX];
+ /// List of 5GHz supported channels
+ struct mac_chan_def chan5G[MAC_DOMAINCHANNEL_5G_MAX];
+ /// Number of 2.4GHz channels in the list
+ u8 chan2G4_cnt;
+ /// Number of 5GHz channels in the list
+ u8 chan5G_cnt;
+};
+
+/// Structure containing the parameters of the @ref ME_SET_CONTROL_PORT_REQ
+/// message
+struct me_set_control_port_req {
+ /// Index of the station for which the control port is opened
+ u8 sta_idx;
+ /// Control port state
+ bool control_port_open;
+};
+
+/// Structure containing the parameters of the @ref ME_TKIP_MIC_FAILURE_IND
+/// message
+struct me_tkip_mic_failure_ind {
+ /// Address of the sending STA
+ struct mac_addr addr;
+ /// TSC value
+ u64 tsc;
+ /// Boolean indicating if the packet was a group or unicast one (true if
+ /// group)
+ bool ga;
+ /// Key Id
+ u8 keyid;
+ /// VIF index
+ u8 vif_idx;
+};
+
+/// Structure containing the parameters of the @ref ME_STA_ADD_REQ message
+struct me_sta_add_req {
+ /// MAC address of the station to be added
+ struct mac_addr mac_addr;
+ /// Supported legacy rates
+ struct mac_rateset rate_set;
+ /// HT Capabilities
+ struct mac_htcapability ht_cap;
+ /// VHT Capabilities
+ struct mac_vhtcapability vht_cap;
+ /// HE capabilities
+ struct mac_hecapability he_cap;
+ /// Flags giving additional information about the station (@ref
+ /// mac_sta_flags)
+ u32 flags;
+ /// Association ID of the station
+ __le16 aid;
+ /// Bit field indicating which queues have U-APSD enabled
+ u8 uapsd_queues;
+ /// Maximum size, in frames, of a APSD service period
+ u8 max_sp_len;
+ /// Operation mode information (valid if bit @ref STA_OPMOD_NOTIF is
+ /// set in the flags)
+ u8 opmode;
+ /// Index of the VIF the station is attached to
+ u8 vif_idx;
+ /// Whether the station is TDLS station
+ bool tdls_sta;
+ /// Indicate if the station is TDLS link initiator station
+ bool tdls_sta_initiator;
+ /// Indicate if the TDLS Channel Switch is allowed
+ bool tdls_chsw_allowed;
+};
+
+/// Structure containing the parameters of the @ref ME_STA_ADD_CFM message
+struct me_sta_add_cfm {
+ /// Station index
+ u8 sta_idx;
+ /// Status of the station addition
+ u8 status;
+ /// PM state of the station
+ u8 pm_state;
+};
+
+/// Structure containing the parameters of the @ref ME_STA_DEL_REQ message.
+struct me_sta_del_req {
+ /// Index of the station to be deleted
+ u8 sta_idx;
+ /// Whether the station is TDLS station
+ bool tdls_sta;
+};
+
+/// Structure containing the parameters of the @ref ME_TX_CREDITS_UPDATE_IND
+/// message.
+struct me_tx_credits_update_ind {
+ /// Index of the station for which the credits are updated
+ u8 sta_idx;
+ /// TID for which the credits are updated
+ u8 tid;
+ /// Offset to be applied on the credit count
+ s8 credits;
+};
+
+/// Structure containing the parameters of the @ref ME_TRAFFIC_IND_REQ message.
+struct me_traffic_ind_req {
+ /// Index of the station for which UAPSD traffic is available on host
+ u8 sta_idx;
+ /// Flag indicating the availability of UAPSD packets for the given STA
+ u8 tx_avail;
+ /// Indicate if traffic is on uapsd-enabled queues
+ bool uapsd;
+};
+
+struct mm_apm_staloss_ind {
+ u8 sta_idx;
+ u8 vif_idx;
+ u8 mac_addr[6];
+};
+
+enum vendor_hwconfig_tag {
+ ACS_TXOP_REQ = 0,
+ CHANNEL_ACCESS_REQ,
+ MAC_TIMESCALE_REQ,
+ CCA_THRESHOLD_REQ,
+ BWMODE_REQ,
+ CHIP_TEMP_GET_REQ,
+ AP_PS_LEVEL_SET_REQ,
+ CUSTOMIZED_FREQ_REQ,
+ WAKEUP_INFO_REQ,
+ KEEPALIVE_PKT_REQ,
+};
+
+enum {
+ BWMODE20M = 0,
+ BWMODE10M,
+ BWMODE5M,
+};
+
+struct mm_set_acs_txop_req {
+ u32 hwconfig_id;
+ u16 txop_bk;
+ u16 txop_be;
+ u16 txop_vi;
+ u16 txop_vo;
+};
+
+struct mm_set_channel_access_req {
+ u32 hwconfig_id;
+ u32 edca[4];
+ u8 vif_idx;
+ u8 retry_cnt;
+ u8 rts_en;
+ u8 long_nav_en;
+ u8 cfe_en;
+ u8 rc_retry_cnt[3];
+ s8 ccademod_th;
+};
+
+struct mm_set_mac_timescale_req {
+ u32 hwconfig_id;
+ u8 sifs_a_time;
+ u8 sifs_b_time;
+ u8 slot_time;
+ u8 rx_startdelay_ofdm;
+ u8 rx_startdelay_long;
+ u8 rx_startdelay_short;
+};
+
+struct mm_set_cca_threshold_req {
+ u32 hwconfig_id;
+ u8 auto_cca_en;
+ s8 cca20p_rise_th;
+ s8 cca20s_rise_th;
+ s8 cca20p_fall_th;
+ s8 cca20s_fall_th;
+};
+
+struct mm_set_bwmode_req {
+ u32 hwconfig_id;
+ u8 bwmode;
+};
+
+struct mm_get_chip_temp_req {
+ u32 hwconfig_id;
+};
+
+struct mm_get_chip_temp_cfm {
+ /// Temp degree val
+ s8 degree;
+};
+
+struct mm_set_ap_ps_level_req {
+ u32 hwconfig_id;
+ u8 ap_ps_level;
+};
+
+struct mm_set_vendor_hwconfig_cfm {
+ u32 hwconfig_id;
+ union {
+ struct mm_get_chip_temp_cfm chip_temp_cfm;
+ };
+};
+
+struct mm_set_customized_freq_req {
+ u32 hwconfig_id;
+ u16 raw_freq[4];
+ u16 map_freq[4];
+};
+
+struct mm_set_keepalive_req {
+ u32 hwconfig_id;
+ u16 code;
+ u16 length;
+ u32 intv;
+ u8 payload[];
+};
+
+struct mm_set_txop_req {
+ u16 txop_bk;
+ u16 txop_be;
+ u16 txop_vi;
+ u16 txop_vo;
+ u8 long_nav_en;
+ u8 cfe_en;
+};
+
+struct mm_set_wakeup_info_req {
+ u32 hwconfig_id;
+ u16 code;
+ u16 offset;
+ u16 length;
+ u16 length_win;
+ u8 mask_and_pattern[];
+};
+
+struct mm_get_fw_version_cfm {
+ u8 fw_version_len;
+ u8 fw_version[63];
+};
+
+struct mm_get_wifi_disable_cfm {
+ u8 wifi_disable;
+};
+
+enum vendor_swconfig_tag {
+ BCN_CFG_REQ = 0,
+ TEMP_COMP_SET_REQ,
+ TEMP_COMP_GET_REQ,
+ EXT_FLAGS_SET_REQ,
+ EXT_FLAGS_GET_REQ,
+ EXT_FLAGS_MASK_SET_REQ,
+};
+
+struct mm_set_bcn_cfg_req {
+ /// Ignore or not bcn tim bcmc bit
+ bool tim_bcmc_ignored_enable;
+};
+
+struct mm_set_bcn_cfg_cfm {
+ /// Request status
+ bool tim_bcmc_ignored_status;
+};
+
+struct mm_set_temp_comp_req {
+ /// Enable or not temp comp
+ u8 enable;
+ u8 reserved[3];
+ u32 tmr_period_ms;
+};
+
+struct mm_set_temp_comp_cfm {
+ /// Request status
+ u8 status;
+};
+
+struct mm_get_temp_comp_cfm {
+ /// Request status
+ u8 status;
+ /// Temp degree val
+ s8 degree;
+};
+
+struct mm_set_ext_flags_req {
+ u32 user_flags;
+};
+
+struct mm_set_ext_flags_cfm {
+ u32 user_flags;
+};
+
+struct mm_get_ext_flags_cfm {
+ u32 user_flags;
+};
+
+struct mm_mask_set_ext_flags_req {
+ u32 user_flags_mask;
+ u32 user_flags_val;
+};
+
+struct mm_mask_set_ext_flags_cfm {
+ u32 user_flags;
+};
+
+struct mm_set_vendor_swconfig_req {
+ u32 swconfig_id;
+ union {
+ struct mm_set_bcn_cfg_req bcn_cfg_req;
+ struct mm_set_temp_comp_req temp_comp_set_req;
+ struct mm_set_ext_flags_req ext_flags_set_req;
+ struct mm_mask_set_ext_flags_req ext_flags_mask_set_req;
+ };
+};
+
+struct mm_set_vendor_swconfig_cfm {
+ u32 swconfig_id;
+ union {
+ struct mm_set_bcn_cfg_cfm bcn_cfg_cfm;
+ struct mm_set_temp_comp_cfm temp_comp_set_cfm;
+ struct mm_get_temp_comp_cfm temp_comp_get_cfm;
+ struct mm_set_ext_flags_cfm ext_flags_set_cfm;
+ struct mm_get_ext_flags_cfm ext_flags_get_cfm;
+ struct mm_mask_set_ext_flags_cfm ext_flags_mask_set_cfm;
+ };
+};
+
+/// Structure containing the parameters of the @ref ME_RC_STATS_REQ message.
+struct me_rc_stats_req {
+ /// Index of the station for which the RC statistics are requested
+ u8 sta_idx;
+};
+
+/// Structure containing the rate control statistics
+struct rc_rate_stats {
+ /// Number of attempts (per sampling interval)
+ u16 attempts;
+ /// Number of success (per sampling interval)
+ u16 success;
+ /// Estimated probability of success (EWMA)
+ u16 probability;
+ /// Rate configuration of the sample
+ u16 rate_config;
+ union {
+ struct {
+ /// Number of times the sample has been skipped (per sampling
+ /// interval)
+ u8 sample_skipped;
+ /// Whether the old probability is available
+ bool old_prob_available;
+ /// Whether the rate can be used in the retry chain
+ bool rate_allowed;
+ };
+ struct {
+ /// RU size and UL length received in the latest HE trigger frame
+ u16 ru_and_length;
+ };
+ };
+};
+
+/// Number of RC samples
+#define RC_MAX_N_SAMPLE 10
+/// Index of the HE statistics element in the table
+#define RC_HE_STATS_IDX RC_MAX_N_SAMPLE
+
+/// Structure containing the parameters of the @ref ME_RC_STATS_CFM message.
+struct me_rc_stats_cfm {
+ /// Index of the station for which the RC statistics are provided
+ u8 sta_idx;
+ /// Number of samples used in the RC algorithm
+ u16 no_samples;
+ /// Number of MPDUs transmitted (per sampling interval)
+ u16 ampdu_len;
+ /// Number of AMPDUs transmitted (per sampling interval)
+ u16 ampdu_packets;
+ /// Average number of MPDUs in each AMPDU frame (EWMA)
+ u32 avg_ampdu_len;
+ // Current step 0 of the retry chain
+ u8 sw_retry_step;
+ /// Trial transmission period
+ u8 sample_wait;
+ /// Retry chain steps
+ u16 retry_step_idx[4];
+ /// RC statistics - Max number of RC samples, plus one for the HE TB
+ /// statistics
+ struct rc_rate_stats rate_stats[RC_MAX_N_SAMPLE + 1];
+ /// Throughput - Max number of RC samples, plus one for the HE TB statistics
+ u32 tp[RC_MAX_N_SAMPLE + 1];
+};
+
+/// Structure containing the parameters of the @ref ME_RC_SET_RATE_REQ message.
+struct me_rc_set_rate_req {
+ /// Index of the station for which the fixed rate is set
+ u8 sta_idx;
+ /// Rate configuration to be set
+ u16 fixed_rate_cfg;
+};
+
+/// Structure containing the parameters of the @ref ME_CONFIG_MONITOR_REQ
+/// message.
+struct me_config_monitor_req {
+ /// Channel to configure
+ struct mac_chan_op chan;
+ /// Is channel data valid
+ bool chan_set;
+ /// Enable report of unsupported HT frames
+ bool uf;
+ /// Enable auto-reply as the mac_addr matches
+ bool auto_reply;
+};
+
+/// Structure containing the parameters of the @ref ME_CONFIG_MONITOR_CFM
+/// message.
+struct me_config_monitor_cfm {
+ /// Channel context index
+ u8 chan_index;
+ /// Channel parameters
+ struct mac_chan_op chan;
+};
+
+/// Structure containing the parameters of the @ref ME_SET_PS_MODE_REQ message.
+struct me_set_ps_mode_req {
+ /// Power Save is activated or deactivated
+ u8 ps_state;
+};
+
+/// Structure containing the parameters of the @ref ME_SET_LP_LEVEL_REQ message.
+struct me_set_lp_level_req {
+ /// Low Power level
+ u8 lp_level;
+ u8 disable_filter;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+/////////// For SM messages
+///////////////////////////////////////////////////////////////////////////////
+/// Message API of the SM task
+enum sm_msg_tag {
+ /// Request to connect to an AP
+ SM_CONNECT_REQ = LMAC_FIRST_MSG(TASK_SM),
+ /// Confirmation of connection
+ SM_CONNECT_CFM,
+ /// Indicates that the SM associated to the AP
+ SM_CONNECT_IND,
+ /// Request to disconnect
+ SM_DISCONNECT_REQ,
+ /// Confirmation of disconnection
+ SM_DISCONNECT_CFM,
+ /// Indicates that the SM disassociated the AP
+ SM_DISCONNECT_IND,
+ /// Request to start external authentication
+ SM_EXTERNAL_AUTH_REQUIRED_IND,
+ /// Response to external authentication request
+ SM_EXTERNAL_AUTH_REQUIRED_RSP,
+ /// Request to update assoc elements after FT over the air authentication
+ SM_FT_AUTH_IND,
+ /// Response to FT authentication with updated assoc elements
+ SM_FT_AUTH_RSP,
+
+ SM_RSP_TIMEOUT_IND,
+
+ SM_COEX_TS_TIMEOUT_IND,
+
+ SM_EXTERNAL_AUTH_REQUIRED_RSP_CFM,
+ /// MAX number of messages
+ SM_MAX,
+};
+
+/// Structure containing the parameters of @ref SM_CONNECT_REQ message.
+struct sm_connect_req {
+ /// SSID to connect to
+ struct mac_ssid ssid;
+ /// BSSID to connect to (if not specified, set this field to WILDCARD BSSID)
+ struct mac_addr bssid;
+ /// Channel on which we have to connect (if not specified, set -1 in the
+ /// chan.freq field)
+ struct mac_chan_def chan;
+ /// Connection flags (see @ref mac_connection_flags)
+ u32 flags;
+ /// Control port Ethertype (in network endianness)
+ __be16 ctrl_port_ethertype;
+ /// Length of the association request IEs
+ u16 ie_len;
+ /// Listen interval to be used for this connection
+ u16 listen_interval;
+ /// Flag indicating if the we have to wait for the BC/MC traffic after
+ /// beacon or not
+ bool dont_wait_bcmc;
+ /// Authentication type
+ u8 auth_type;
+ /// UAPSD queues (bit0: VO, bit1: VI, bit2: BE, bit3: BK)
+ u8 uapsd_queues;
+ /// VIF index
+ u8 vif_idx;
+ /// Buffer containing the additional information elements to be put in the
+ /// association request
+ u32 ie_buf[64];
+};
+
+/// Structure containing the parameters of the @ref SM_CONNECT_CFM message.
+struct sm_connect_cfm {
+ /// Status. If 0, it means that the connection procedure will be performed
+ /// and that a subsequent @ref SM_CONNECT_IND message will be forwarded once
+ /// the procedure is completed
+ u8 status;
+};
+
+#define SM_ASSOC_IE_LEN 800
+/// Structure containing the parameters of the @ref SM_CONNECT_IND message.
+struct sm_connect_ind {
+ /// Status code of the connection procedure
+ u16 status_code;
+ /// BSSID
+ struct mac_addr bssid;
+ /// Flag indicating if the indication refers to an internal roaming or from
+ /// a host request
+ bool roamed;
+ /// Index of the VIF for which the association process is complete
+ u8 vif_idx;
+ /// Index of the STA entry allocated for the AP
+ u8 ap_idx;
+ /// Index of the LMAC channel context the connection is attached to
+ u8 ch_idx;
+ /// Flag indicating if the AP is supporting QoS
+ bool qos;
+ /// ACM bits set in the AP WMM parameter element
+ u8 acm;
+ /// Length of the AssocReq IEs
+ u16 assoc_req_ie_len;
+ /// Length of the AssocRsp IEs
+ u16 assoc_rsp_ie_len;
+ /// IE buffer
+ u32 assoc_ie_buf[SM_ASSOC_IE_LEN / 4];
+
+ u16 aid;
+ u8 band;
+ u16 center_freq;
+ u8 width;
+ u32 center_freq1;
+ u32 center_freq2;
+
+ /// EDCA parameters
+ u32 ac_param[AC_MAX];
+};
+
+/// Structure containing the parameters of the @ref SM_DISCONNECT_REQ message.
+struct sm_disconnect_req {
+ /// Reason of the deauthentication.
+ u16 reason_code;
+ /// Index of the VIF.
+ u8 vif_idx;
+};
+
+/// Structure containing the parameters of SM_ASSOCIATION_IND the message
+struct sm_association_ind {
+ // MAC ADDR of the STA
+ struct mac_addr me_mac_addr;
+};
+
+/// Structure containing the parameters of the @ref SM_DISCONNECT_IND message.
+struct sm_disconnect_ind {
+ /// Reason of the disconnection.
+ u16 reason_code;
+ /// Index of the VIF.
+ u8 vif_idx;
+ /// FT over DS is ongoing
+ bool ft_over_ds;
+ u8 reassoc;
+};
+
+/// Structure containing the parameters of the @ref
+/// SM_EXTERNAL_AUTH_REQUIRED_IND
+struct sm_external_auth_required_ind {
+ /// Index of the VIF.
+ u8 vif_idx;
+ /// SSID to authenticate to
+ struct mac_ssid ssid;
+ /// BSSID to authenticate to
+ struct mac_addr bssid;
+ /// AKM suite of the respective authentication
+ u32 akm;
+};
+
+/// Structure containing the parameters of the @ref
+/// SM_EXTERNAL_AUTH_REQUIRED_RSP
+struct sm_external_auth_required_rsp {
+ /// Index of the VIF.
+ u8 vif_idx;
+ /// Authentication status
+ u16 status;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+/////////// For APM messages
+///////////////////////////////////////////////////////////////////////////////
+/// Message API of the APM task
+enum apm_msg_tag {
+ /// Request to start the AP.
+ APM_START_REQ = LMAC_FIRST_MSG(TASK_APM),
+ /// Confirmation of the AP start.
+ APM_START_CFM,
+ /// Request to stop the AP.
+ APM_STOP_REQ,
+ /// Confirmation of the AP stop.
+ APM_STOP_CFM,
+ /// Request to start CAC
+ APM_START_CAC_REQ,
+ /// Confirmation of the CAC start
+ APM_START_CAC_CFM,
+ /// Request to stop CAC
+ APM_STOP_CAC_REQ,
+ /// Confirmation of the CAC stop
+ APM_STOP_CAC_CFM,
+
+ APM_SET_BEACON_IE_REQ,
+ APM_SET_BEACON_IE_CFM,
+
+ /// MAX number of messages
+ APM_MAX,
+};
+
+/// Structure containing the parameters of the @ref APM_START_REQ message.
+struct apm_start_req {
+ /// Basic rate set
+ struct mac_rateset basic_rates;
+ /// Control channel on which we have to enable the AP
+ struct mac_chan_def chan;
+ /// Center frequency of the first segment
+ u32 center_freq1;
+ /// Center frequency of the second segment (only in 80+80 configuration)
+ u32 center_freq2;
+ /// Width of channel
+ u8 ch_width;
+ /// Address, in host memory, to the beacon template
+ u32 bcn_addr;
+ /// Length of the beacon template
+ u16 bcn_len;
+ /// Offset of the TIM IE in the beacon
+ u16 tim_oft;
+ /// Beacon interval
+ u16 bcn_int;
+ /// Flags (@ref mac_connection_flags)
+ u32 flags;
+ /// Control port Ethertype
+ __be16 ctrl_port_ethertype;
+ /// Length of the TIM IE
+ u8 tim_len;
+ /// Index of the VIF for which the AP is started
+ u8 vif_idx;
+};
+
+struct apm_set_bcn_ie_req {
+ u8 vif_idx;
+ u16 bcn_ie_len;
+ u8 bcn_ie[512];
+};
+
+/// Structure containing the parameters of the @ref APM_START_CFM message.
+struct apm_start_cfm {
+ /// Status of the AP starting procedure
+ u8 status;
+ /// Index of the VIF for which the AP is started
+ u8 vif_idx;
+ /// Index of the channel context attached to the VIF
+ u8 ch_idx;
+ /// Index of the STA used for BC/MC traffic
+ u8 bcmc_idx;
+};
+
+/// Structure containing the parameters of the @ref APM_STOP_REQ message.
+struct apm_stop_req {
+ /// Index of the VIF for which the AP has to be stopped
+ u8 vif_idx;
+};
+
+/// Structure containing the parameters of the @ref APM_START_CAC_REQ message.
+struct apm_start_cac_req {
+ /// Control channel on which we have to start the CAC
+ struct mac_chan_def chan;
+ /// Center frequency of the first segment
+ u32 center_freq1;
+ /// Center frequency of the second segment (only in 80+80 configuration)
+ u32 center_freq2;
+ /// Width of channel
+ u8 ch_width;
+ /// Index of the VIF for which the CAC is started
+ u8 vif_idx;
+};
+
+/// Structure containing the parameters of the @ref APM_START_CAC_CFM message.
+struct apm_start_cac_cfm {
+ /// Status of the CAC starting procedure
+ u8 status;
+ /// Index of the channel context attached to the VIF for CAC
+ u8 ch_idx;
+};
+
+/// Structure containing the parameters of the @ref APM_STOP_CAC_REQ message.
+struct apm_stop_cac_req {
+ /// Index of the VIF for which the CAC has to be stopped
+ u8 vif_idx;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+/////////// For MESH messages
+///////////////////////////////////////////////////////////////////////////////
+
+/// Maximum length of the Mesh ID
+#define MESH_MESHID_MAX_LEN (32)
+
+/// Message API of the MESH task
+enum mesh_msg_tag {
+ /// Request to start the MP
+ MESH_START_REQ = LMAC_FIRST_MSG(TASK_MESH),
+ /// Confirmation of the MP start.
+ MESH_START_CFM,
+
+ /// Request to stop the MP.
+ MESH_STOP_REQ,
+ /// Confirmation of the MP stop.
+ MESH_STOP_CFM,
+
+ // Request to update the MP
+ MESH_UPDATE_REQ,
+ /// Confirmation of the MP update
+ MESH_UPDATE_CFM,
+
+ /// Request information about a given link
+ MESH_PEER_INFO_REQ,
+ /// Response to the MESH_PEER_INFO_REQ message
+ MESH_PEER_INFO_CFM,
+
+ /// Request automatic establishment of a path with a given mesh STA
+ MESH_PATH_CREATE_REQ,
+ /// Confirmation to the MESH_PATH_CREATE_REQ message
+ MESH_PATH_CREATE_CFM,
+
+ /// Request a path update (delete path, modify next hop mesh STA)
+ MESH_PATH_UPDATE_REQ,
+ /// Confirmation to the MESH_PATH_UPDATE_REQ message
+ MESH_PATH_UPDATE_CFM,
+
+ /// Indication from Host that the indicated Mesh Interface is a proxy for an
+ /// external STA
+ MESH_PROXY_ADD_REQ,
+
+ /// Indicate that a connection has been established or lost
+ MESH_PEER_UPDATE_IND,
+ /// Notification that a connection has been established or lost (when MPM
+ /// handled by userspace)
+ MESH_PEER_UPDATE_NTF = MESH_PEER_UPDATE_IND,
+
+ /// Indicate that a path is now active or inactive
+ MESH_PATH_UPDATE_IND,
+ /// Indicate that proxy information have been updated
+ MESH_PROXY_UPDATE_IND,
+
+ /// MAX number of messages
+ MESH_MAX,
+};
+
+/// Structure containing the parameters of the @ref MESH_START_REQ message.
+struct mesh_start_req {
+ /// Basic rate set
+ struct mac_rateset basic_rates;
+ /// Control channel on which we have to enable the AP
+ struct mac_chan_def chan;
+ /// Center frequency of the first segment
+ u32 center_freq1;
+ /// Center frequency of the second segment (only in 80+80 configuration)
+ u32 center_freq2;
+ /// Width of channel
+ u8 ch_width;
+ /// DTIM Period
+ u8 dtim_period;
+ /// Beacon Interval
+ u16 bcn_int;
+ /// Index of the VIF for which the MP is started
+ u8 vif_index;
+ /// Length of the Mesh ID
+ u8 mesh_id_len;
+ /// Mesh ID
+ u8 mesh_id[MESH_MESHID_MAX_LEN];
+ /// Address of the IEs to download
+ u32 ie_addr;
+ /// Length of the provided IEs
+ u8 ie_len;
+ /// Indicate if Mesh Peering Management (MPM) protocol is handled in
+ /// userspace
+ bool user_mpm;
+ /// Indicate if Mesh Point is using authentication
+ bool is_auth;
+ /// Indicate which authentication method is used
+ u8 auth_id;
+};
+
+/// Structure containing the parameters of the @ref MESH_START_CFM message.
+struct mesh_start_cfm {
+ /// Status of the MP starting procedure
+ u8 status;
+ /// Index of the VIF for which the MP is started
+ u8 vif_idx;
+ /// Index of the channel context attached to the VIF
+ u8 ch_idx;
+ /// Index of the STA used for BC/MC traffic
+ u8 bcmc_idx;
+};
+
+/// Structure containing the parameters of the @ref MESH_STOP_REQ message.
+struct mesh_stop_req {
+ /// Index of the VIF for which the MP has to be stopped
+ u8 vif_idx;
+};
+
+/// Structure containing the parameters of the @ref MESH_STOP_CFM message.
+struct mesh_stop_cfm {
+ /// Index of the VIF for which the MP has to be stopped
+ u8 vif_idx;
+ /// Status
+ u8 status;
+};
+
+/// Bit fields for mesh_update_req message's flags value
+enum mesh_update_flags_bit {
+ /// Root Mode
+ MESH_UPDATE_FLAGS_ROOT_MODE_BIT = 0,
+ /// Gate Mode
+ MESH_UPDATE_FLAGS_GATE_MODE_BIT,
+ /// Mesh Forwarding
+ MESH_UPDATE_FLAGS_MESH_FWD_BIT,
+ /// Local Power Save Mode
+ MESH_UPDATE_FLAGS_LOCAL_PSM_BIT,
+};
+
+/// Structure containing the parameters of the @ref MESH_UPDATE_REQ message.
+struct mesh_update_req {
+ /// Flags, indicate fields which have been updated
+ u8 flags;
+ /// VIF Index
+ u8 vif_idx;
+ /// Root Mode
+ u8 root_mode;
+ /// Gate Announcement
+ bool gate_announ;
+ /// Mesh Forwarding
+ bool mesh_forward;
+ /// Local PS Mode
+ u8 local_ps_mode;
+};
+
+/// Structure containing the parameters of the @ref MESH_UPDATE_CFM message.
+struct mesh_update_cfm {
+ /// Status
+ u8 status;
+};
+
+/// Structure containing the parameters of the @ref MESH_PEER_INFO_REQ message.
+struct mesh_peer_info_req {
+ /// Index of the station allocated for the peer
+ u8 sta_idx;
+};
+
+/// Structure containing the parameters of the @ref MESH_PEER_INFO_CFM message.
+struct mesh_peer_info_cfm {
+ /// Response status
+ u8 status;
+ /// Index of the station allocated for the peer
+ u8 sta_idx;
+ /// Local Link ID
+ u16 local_link_id;
+ /// Peer Link ID
+ u16 peer_link_id;
+ /// Local PS Mode
+ u8 local_ps_mode;
+ /// Peer PS Mode
+ u8 peer_ps_mode;
+ /// Non-peer PS Mode
+ u8 non_peer_ps_mode;
+ /// Link State
+ u8 link_state;
+};
+
+/// Structure containing the parameters of the @ref MESH_PATH_CREATE_REQ
+/// message.
+struct mesh_path_create_req {
+ /// Index of the interface on which path has to be created
+ u8 vif_idx;
+ /// Indicate if originator MAC Address is provided
+ bool has_orig_addr;
+ /// Path Target MAC Address
+ struct mac_addr tgt_mac_addr;
+ /// Originator MAC Address
+ struct mac_addr orig_mac_addr;
+};
+
+/// Structure containing the parameters of the @ref MESH_PATH_CREATE_CFM
+/// message.
+struct mesh_path_create_cfm {
+ /// Confirmation status
+ u8 status;
+ /// VIF Index
+ u8 vif_idx;
+};
+
+/// Structure containing the parameters of the @ref MESH_PATH_UPDATE_REQ
+/// message.
+struct mesh_path_update_req {
+ /// Indicate if path must be deleted
+ bool delete;
+ /// Index of the interface on which path has to be created
+ u8 vif_idx;
+ /// Path Target MAC Address
+ struct mac_addr tgt_mac_addr;
+ /// Next Hop MAC Address
+ struct mac_addr nhop_mac_addr;
+};
+
+/// Structure containing the parameters of the @ref MESH_PATH_UPDATE_CFM
+/// message.
+struct mesh_path_update_cfm {
+ /// Confirmation status
+ u8 status;
+ /// VIF Index
+ u8 vif_idx;
+};
+
+/// Structure containing the parameters of the @ref MESH_PROXY_ADD_REQ message.
+struct mesh_proxy_add_req {
+ /// VIF Index
+ u8 vif_idx;
+ /// MAC Address of the External STA
+ struct mac_addr ext_sta_addr;
+};
+
+/// Structure containing the parameters of the @ref MESH_PROXY_UPDATE_IND
+struct mesh_proxy_update_ind {
+ /// Indicate if proxy information has been added or deleted
+ bool delete;
+ /// Indicate if we are a proxy for the external STA
+ bool local;
+ /// VIF Index
+ u8 vif_idx;
+ /// MAC Address of the External STA
+ struct mac_addr ext_sta_addr;
+ /// MAC Address of the proxy (only valid if local is false)
+ struct mac_addr proxy_mac_addr;
+};
+
+/// Structure containing the parameters of the @ref MESH_PEER_UPDATE_IND
+/// message.
+struct mesh_peer_update_ind {
+ /// Indicate if connection has been established or lost
+ bool estab;
+ /// VIF Index
+ u8 vif_idx;
+ /// STA Index
+ u8 sta_idx;
+ /// Peer MAC Address
+ struct mac_addr peer_addr;
+};
+
+/// Structure containing the parameters of the @ref MESH_PEER_UPDATE_NTF
+/// message.
+struct mesh_peer_update_ntf {
+ /// VIF Index
+ u8 vif_idx;
+ /// STA Index
+ u8 sta_idx;
+ /// Mesh Link State
+ u8 state;
+};
+
+/// Structure containing the parameters of the @ref MESH_PATH_UPDATE_IND
+/// message.
+struct mesh_path_update_ind {
+ /// Indicate if path is deleted or not
+ bool delete;
+ /// Indicate if path is towards an external STA (not part of MBSS)
+ bool ext_sta;
+ /// VIF Index
+ u8 vif_idx;
+ /// Path Index
+ u8 path_idx;
+ /// Target MAC Address
+ struct mac_addr tgt_mac_addr;
+ /// External STA MAC Address (only if ext_sta is true)
+ struct mac_addr ext_sta_mac_addr;
+ /// Next Hop STA Index
+ u8 nhop_sta_idx;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+/////////// For Debug messages
+///////////////////////////////////////////////////////////////////////////////
+
+/// Messages related to Debug Task
+enum dbg_msg_tag {
+ /// Memory read request
+ DBG_MEM_READ_REQ = LMAC_FIRST_MSG(TASK_DBG),
+ /// Memory read confirm
+ DBG_MEM_READ_CFM,
+ /// Memory write request
+ DBG_MEM_WRITE_REQ,
+ /// Memory write confirm
+ DBG_MEM_WRITE_CFM,
+ /// Module filter request
+ DBG_SET_MOD_FILTER_REQ,
+ /// Module filter confirm
+ DBG_SET_MOD_FILTER_CFM,
+ /// Severity filter request
+ DBG_SET_SEV_FILTER_REQ,
+ /// Severity filter confirm
+ DBG_SET_SEV_FILTER_CFM,
+ /// LMAC/MAC HW fatal error indication
+ DBG_ERROR_IND,
+ /// Request to get system statistics
+ DBG_GET_SYS_STAT_REQ,
+ /// COnfirmation of system statistics
+ DBG_GET_SYS_STAT_CFM,
+ /// Memory block write request
+ DBG_MEM_BLOCK_WRITE_REQ,
+ /// Memory block write confirm
+ DBG_MEM_BLOCK_WRITE_CFM,
+ /// Start app request
+ DBG_START_APP_REQ,
+ /// Start app confirm
+ DBG_START_APP_CFM,
+ /// Start npc request
+ DBG_START_NPC_REQ,
+ /// Start npc confirm
+ DBG_START_NPC_CFM,
+ /// Memory mask write request
+ DBG_MEM_MASK_WRITE_REQ,
+ /// Memory mask write confirm
+ DBG_MEM_MASK_WRITE_CFM,
+
+ DBG_RFTEST_CMD_REQ,
+ DBG_RFTEST_CMD_CFM,
+ DBG_BINDING_REQ,
+ DBG_BINDING_CFM,
+ DBG_BINDING_IND,
+
+ DBG_CUSTOM_MSG_REQ,
+ DBG_CUSTOM_MSG_CFM,
+ DBG_CUSTOM_MSG_IND,
+
+ DBG_GPIO_WRITE_REQ,
+ DBG_GPIO_WRITE_CFM,
+ DBG_GPIO_READ_REQ,
+ DBG_GPIO_READ_CFM,
+ DBG_GPIO_INIT_REQ,
+ DBG_GPIO_INIT_CFM,
+
+ /// EF usrdata read request
+ DBG_EF_USRDATA_READ_REQ,
+ /// EF usrdata read confirm
+ DBG_EF_USRDATA_READ_CFM,
+ /// Memory block read request
+ DBG_MEM_BLOCK_READ_REQ,
+ /// Memory block read confirm
+ DBG_MEM_BLOCK_READ_CFM,
+
+ DBG_PWM_INIT_REQ,
+ DBG_PWM_INIT_CFM,
+ DBG_PWM_DEINIT_REQ,
+ DBG_PWM_DEINIT_CFM,
+
+ /// Max number of Debug messages
+ DBG_MAX,
+};
+
+/// Structure containing the parameters of the @ref DBG_MEM_READ_REQ message.
+struct dbg_mem_read_req {
+ u32 memaddr;
+};
+
+/// Structure containing the parameters of the @ref DBG_MEM_READ_CFM message.
+struct dbg_mem_read_cfm {
+ u32 memaddr;
+ u32 memdata;
+};
+
+/// Structure containing the parameters of the @ref DBG_MEM_WRITE_REQ message.
+struct dbg_mem_write_req {
+ u32 memaddr;
+ u32 memdata;
+};
+
+/// Structure containing the parameters of the @ref DBG_MEM_WRITE_CFM message.
+struct dbg_mem_write_cfm {
+ u32 memaddr;
+ u32 memdata;
+};
+
+/// Structure containing the parameters of the @ref DBG_MEM_MASK_WRITE_REQ
+/// message.
+struct dbg_mem_mask_write_req {
+ u32 memaddr;
+ u32 memmask;
+ u32 memdata;
+};
+
+/// Structure containing the parameters of the @ref DBG_MEM_MASK_WRITE_CFM
+/// message.
+struct dbg_mem_mask_write_cfm {
+ u32 memaddr;
+ u32 memdata;
+};
+
+struct dbg_rftest_cmd_req {
+ u32 cmd;
+ u32 argc;
+ u8 argv[30];
+};
+
+struct dbg_rftest_cmd_cfm {
+ u32 rftest_result[18];
+};
+
+struct dbg_gpio_write_req {
+ u8 gpio_idx;
+ u8 gpio_val;
+};
+
+struct dbg_gpio_read_req {
+ u8 gpio_idx;
+};
+
+struct dbg_gpio_read_cfm {
+ u8 gpio_idx;
+ u8 gpio_val;
+};
+
+struct dbg_gpio_init_req {
+ u8 gpio_idx;
+ u8 gpio_dir; // 1 output, 0 input;
+ u8 gpio_val; // for output, 1 high, 0 low;
+};
+
+/// Structure containing the parameters of the @ref DBG_SET_MOD_FILTER_REQ
+/// message.
+struct dbg_set_mod_filter_req {
+ /// Bit field indicating for each module if the traces are enabled or not
+ u32 mod_filter;
+};
+
+/// Structure containing the parameters of the @ref DBG_SEV_MOD_FILTER_REQ
+/// message.
+struct dbg_set_sev_filter_req {
+ /// Bit field indicating the severity threshold for the traces
+ u32 sev_filter;
+};
+
+/// Structure containing the parameters of the @ref DBG_GET_SYS_STAT_CFM
+/// message.
+struct dbg_get_sys_stat_cfm {
+ /// Time spent in CPU sleep since last reset of the system statistics
+ u32 cpu_sleep_time;
+ /// Time spent in DOZE since last reset of the system statistics
+ u32 doze_time;
+ /// Total time spent since last reset of the system statistics
+ u32 stats_time;
+};
+
+/// Structure containing the parameters of the @ref DBG_MEM_BLOCK_WRITE_REQ
+/// message.
+struct dbg_mem_block_write_req {
+ u32 memaddr;
+ u32 memsize;
+ u32 memdata[1024 / sizeof(u32)];
+};
+
+/// Structure containing the parameters of the @ref DBG_MEM_BLOCK_WRITE_CFM
+/// message.
+struct dbg_mem_block_write_cfm {
+ u32 wstatus;
+};
+
+/// Structure containing the parameters of the @ref DBG_START_APP_REQ message.
+struct dbg_start_app_req {
+ u32 bootaddr;
+ u32 boottype;
+};
+
+/// Structure containing the parameters of the @ref DBG_START_APP_CFM message.
+struct dbg_start_app_cfm {
+ u32 bootstatus;
+};
+
+enum {
+ HOST_START_APP_AUTO = 1,
+ HOST_START_APP_CUSTOM,
+ HOST_START_APP_FNCALL = 4,
+ HOST_START_APP_DUMMY = 5,
+};
+
+///////////////////////////////////////////////////////////////////////////////
+/////////// For TDLS messages
+///////////////////////////////////////////////////////////////////////////////
+
+/// List of messages related to the task.
+enum tdls_msg_tag {
+ /// TDLS channel Switch Request.
+ TDLS_CHAN_SWITCH_REQ = LMAC_FIRST_MSG(TASK_TDLS),
+ /// TDLS channel switch confirmation.
+ TDLS_CHAN_SWITCH_CFM,
+ /// TDLS channel switch indication.
+ TDLS_CHAN_SWITCH_IND,
+ /// TDLS channel switch to base channel indication.
+ TDLS_CHAN_SWITCH_BASE_IND,
+ /// TDLS cancel channel switch request.
+ TDLS_CANCEL_CHAN_SWITCH_REQ,
+ /// TDLS cancel channel switch confirmation.
+ TDLS_CANCEL_CHAN_SWITCH_CFM,
+ /// TDLS peer power save indication.
+ TDLS_PEER_PS_IND,
+ /// TDLS peer traffic indication request.
+ TDLS_PEER_TRAFFIC_IND_REQ,
+ /// TDLS peer traffic indication confirmation.
+ TDLS_PEER_TRAFFIC_IND_CFM,
+
+ /// MAX number of messages
+ TDLS_MAX
+};
+
+/// Structure containing the parameters of the @ref TDLS_CHAN_SWITCH_REQ message
+struct tdls_chan_switch_req {
+ /// Index of the VIF
+ u8 vif_index;
+ /// STA Index
+ u8 sta_idx;
+ /// MAC address of the TDLS station
+ struct mac_addr peer_mac_addr;
+ bool initiator;
+ /// Band (2.4GHz or 5GHz)
+ u8 band;
+ /// Channel type: 20,40,80,160 or 80+80 MHz
+ u8 type;
+ /// Frequency for Primary 20MHz channel (in MHz)
+ u16 prim20_freq;
+ /// Frequency for Center of the contiguous channel or center of Primary
+ /// 80+80
+ u16 center1_freq;
+ /// Frequency for Center of the non-contiguous secondary 80+80
+ u16 center2_freq;
+ /// TX power (in dBm)
+ s8 tx_power;
+ /// Operating class
+ u8 op_class;
+};
+
+/// Structure containing the parameters of the @ref TDLS_CANCEL_CHAN_SWITCH_REQ
+/// message
+struct tdls_cancel_chan_switch_req {
+ /// Index of the VIF
+ u8 vif_index;
+ /// STA Index
+ u8 sta_idx;
+ /// MAC address of the TDLS station
+ struct mac_addr peer_mac_addr;
+};
+
+/// Structure containing the parameters of the @ref TDLS_CHAN_SWITCH_CFM message
+struct tdls_chan_switch_cfm {
+ /// Status of the operation
+ u8 status;
+};
+
+/// Structure containing the parameters of the @ref TDLS_CANCEL_CHAN_SWITCH_CFM
+/// message
+struct tdls_cancel_chan_switch_cfm {
+ /// Status of the operation
+ u8 status;
+};
+
+/// Structure containing the parameters of the @ref TDLS_CHAN_SWITCH_IND message
+struct tdls_chan_switch_ind {
+ /// VIF Index
+ u8 vif_index;
+ /// Channel Context Index
+ u8 chan_ctxt_index;
+ /// Status of the operation
+ u8 status;
+};
+
+/// Structure containing the parameters of the @ref TDLS_CHAN_SWITCH_BASE_IND
+/// message
+struct tdls_chan_switch_base_ind {
+ /// VIF Index
+ u8 vif_index;
+ /// Channel Context index
+ u8 chan_ctxt_index;
+};
+
+/// Structure containing the parameters of the @ref TDLS_PEER_PS_IND message
+struct tdls_peer_ps_ind {
+ /// VIF Index
+ u8 vif_index;
+ /// STA Index
+ u8 sta_idx;
+ /// MAC ADDR of the TDLS STA
+ struct mac_addr peer_mac_addr;
+ /// Flag to indicate if the TDLS peer is going to sleep
+ bool ps_on;
+};
+
+/// Structure containing the parameters of the @ref TDLS_PEER_TRAFFIC_IND_REQ
+/// message
+struct tdls_peer_traffic_ind_req {
+ /// VIF Index
+ u8 vif_index;
+ /// STA Index
+ u8 sta_idx;
+ // MAC ADDR of the TDLS STA
+ struct mac_addr peer_mac_addr;
+ /// Dialog token
+ u8 dialog_token;
+ /// TID of the latest MPDU transmitted over the TDLS direct link to the TDLS
+ /// STA
+ u8 last_tid;
+ /// Sequence number of the latest MPDU transmitted over the TDLS direct link
+ /// to the TDLS STA
+ u16 last_sn;
+};
+
+/// Structure containing the parameters of the @ref TDLS_PEER_TRAFFIC_IND_CFM
+/// message
+struct tdls_peer_traffic_ind_cfm {
+ /// Status of the operation
+ u8 status;
+};
+
+#endif // LMAC_MSG_H_
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/lmac_types.h b/drivers/net/wireless/aic/aic8800_fdrv/lmac_types.h
new file mode 100644
index 000000000000..2f486f0d3389
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/lmac_types.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ ****************************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file co_types.h
+ *
+ * @brief Provides the kernel fixed-width types used by LMAC interfaces.
+ *
+ ****************************************************************************************
+ */
+
+#ifndef _LMAC_INT_H_
+#define _LMAC_INT_H_
+
+#include <linux/types.h>
+#include <linux/bits.h>
+
+/// @} CO_INT
+#endif // _LMAC_INT_H_
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/sdio_host.c b/drivers/net/wireless/aic/aic8800_fdrv/sdio_host.c
new file mode 100644
index 000000000000..24408fbac3d0
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/sdio_host.c
@@ -0,0 +1,136 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ****************************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file sdio_host.c
+ *
+ * @brief SDIO host function declarations
+ *
+ ****************************************************************************************
+ */
+
+#include "sdio_host.h"
+#include "aicwf_platform.h"
+#include "aicwf_tx.h"
+
+/*
+ ****************************************************************************************
+ */
+void aicwf_sdio_host_init(struct sdio_host_env_tag *env, void *cb,
+ void *shared_env_ptr, void *pthis)
+{
+ // Reset the environments
+
+ // Reset the Host environment
+ memset(env, 0, sizeof(struct sdio_host_env_tag));
+ // Save the pointer to the register base
+ env->pthis = pthis;
+}
+
+/*
+ ****************************************************************************************
+ */
+struct txdesc_host *
+aicwf_sdio_host_txdesc_get(struct sdio_host_env_tag *env, const int queue_idx)
+{
+ struct txdesc_host *txdesc_free = NULL;
+ u32 used_idx = env->txdesc_used_idx[queue_idx];
+ u32 free_idx = env->txdesc_free_idx[queue_idx];
+
+ // Check if a free descriptor is available
+ if (free_idx != (used_idx + SDIO_TXDESC_CNT)) {
+ // Get the pointer to the first free descriptor
+ // txdesc_free = shared_env_ptr->txdesc[queue_idx] + (free_idx %
+ // IPC_TXDESC_CNT);
+ } else {
+ txdesc_free = NULL;
+ }
+
+ return txdesc_free;
+}
+
+/*
+ ****************************************************************************************
+ */
+void aicwf_sdio_host_txdesc_push(struct sdio_host_env_tag *env,
+ const int queue_idx, const uint64_t host_id)
+{
+ // Save the host id in the environment
+ env->tx_host_id[queue_idx][env->txdesc_free_idx[queue_idx] %
+ SDIO_TXDESC_CNT] = host_id;
+
+ // Increment the index
+ env->txdesc_free_idx[queue_idx]++;
+ if (env->txdesc_free_idx[queue_idx] == 0x80000000)
+ env->txdesc_free_idx[queue_idx] = 0;
+}
+
+/*
+ ****************************************************************************************
+ */
+void aicwf_sdio_host_tx_cfm_handler(struct sdio_host_env_tag *env, u32 *data)
+{
+ u32 queue_idx = 0;
+ struct sk_buff *skb = NULL;
+ struct aicwf_txhdr *txhdr;
+
+ // Get the used index and increase it. We do the increase before knowing if
+ // the current buffer is confirmed because the callback function may call
+ // the ipc_host_txdesc_get() in case flow control was enabled and the index
+ // has to be already at the good value to ensure that the test of FIFO full
+ // is correct
+ u32 used_idx = data[1];
+ unsigned long host_id =
+ env->tx_host_id[queue_idx][used_idx % SDIO_TXDESC_CNT];
+
+ // Reset the host id in the array
+ env->tx_host_id[queue_idx][used_idx % SDIO_TXDESC_CNT] = 0;
+
+ // call the external function to indicate that a TX packet is freed
+ if (host_id == 0) {
+ // No more confirmations, so put back the used index at its initial
+ // value
+ env->txdesc_used_idx[queue_idx] = used_idx;
+ pr_err_ratelimited("ERROR:No more confirmations\n");
+ return;
+ }
+ // set the cfm status
+ skb = (struct sk_buff *)host_id;
+ txhdr = (struct aicwf_txhdr *)skb->data;
+ txhdr->hw_hdr.cfm.status = (union aicwf_hw_txstatus)data[0];
+ pr_debug("sdio_host_tx_cfm_handler:used_idx=%d, 0x%p, status=%x\n",
+ used_idx, env->pthis, txhdr->hw_hdr.cfm.status.value);
+ // if (env->cb.send_data_cfm(env->pthis, host_id) != 0)
+ if (aicwf_txdatacfm(env->pthis, (void *)host_id) != 0) {
+ // No more confirmations, so put back the used index at its initial
+ // value
+ env->txdesc_used_idx[queue_idx] = used_idx;
+ env->tx_host_id[queue_idx][used_idx % SDIO_TXDESC_CNT] = host_id;
+ // and exit the loop
+ pr_err("ERROR:aicwf_txdatacfm,\n");
+ }
+}
+
+int aicwf_sdio_platform_init(struct aic_sdio_dev *sdiodev)
+{
+ struct aicwf_plat *aicwf_plat = NULL;
+ void *drvdata;
+ int ret = -ENODEV;
+
+ aicwf_plat = kzalloc_obj(*aicwf_plat, GFP_KERNEL);
+
+ if (!aicwf_plat)
+ return -ENOMEM;
+
+ aicwf_plat->sdiodev = sdiodev;
+ ret = aicwf_platform_init(aicwf_plat, &drvdata);
+ if (ret) {
+ kfree(aicwf_plat);
+ return ret;
+ }
+ sdiodev->plat = aicwf_plat;
+
+ return ret;
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/sdio_host.h b/drivers/net/wireless/aic/aic8800_fdrv/sdio_host.h
new file mode 100644
index 000000000000..bbe911c2d5fc
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/sdio_host.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 AIC semiconductor.
+ */
+
+#ifndef _SDIO_HOST_H_
+#define _SDIO_HOST_H_
+
+#include "aicwf_sdio.h"
+#include "lmac_types.h"
+
+#define SDIO_TXQUEUE_CNT NX_TXQ_CNT
+#define SDIO_TXDESC_CNT NX_TXDESC_CNT
+
+/// Definition of the IPC Host environment structure.
+struct sdio_host_env_tag {
+ // Index used that points to the first free TX desc
+ u32 txdesc_free_idx[SDIO_TXQUEUE_CNT];
+ // Index used that points to the first used TX desc
+ u32 txdesc_used_idx[SDIO_TXQUEUE_CNT];
+ // Array storing the currently pushed host ids, per IPC queue
+ u64 tx_host_id[SDIO_TXQUEUE_CNT][SDIO_TXDESC_CNT];
+
+ /// Pointer to the attached object (used in callbacks and register accesses)
+ void *pthis;
+};
+
+struct txdesc_host *
+aicwf_sdio_host_txdesc_get(struct sdio_host_env_tag *env, const int queue_idx);
+
+void aicwf_sdio_host_init(struct sdio_host_env_tag *env, void *cb,
+ void *shared_env_ptr, void *pthis);
+
+void aicwf_sdio_host_txdesc_push(struct sdio_host_env_tag *env,
+ const int queue_idx,
+ const uint64_t host_id);
+
+void aicwf_sdio_host_tx_cfm_handler(struct sdio_host_env_tag *env,
+ u32 *data);
+
+int aicwf_sdio_platform_init(struct aic_sdio_dev *sdiodev);
+
+#endif
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH wireless-next v5 4/4] wifi: aic: Integrate the AIC8800 SDIO driver
2026-11-16 7:23 [PATCH wireless-next v5 0/4] wifi: aic: Add AIC8800D80 and D80N SDIO FullMAC driver Yanli Yang
` (2 preceding siblings ...)
2026-11-16 7:23 ` [PATCH wireless-next v5 1/4] dt-bindings: net: wireless: Add AIC8800D80 SDIO Wi-Fi Yanli Yang
@ 2026-11-16 7:23 ` Yanli Yang
3 siblings, 0 replies; 5+ messages in thread
From: Yanli Yang @ 2026-11-16 7:23 UTC (permalink / raw)
To: linux-wireless
Cc: Johannes Berg, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
devicetree, linux-kernel, Zhirun Liu, Dijia Xu, Chunqiu Liu,
Liheng Wei, yanli.yang
From: Zhirun Liu <zhirunliu@aicsemi.com>
Connect the AIC vendor directory to the wireless Kconfig and Makefile
so the complete AIC8800D80 and AIC8800D80N FullMAC driver can be selected.
Add the driver maintainers, reviewers and linux-wireless mailing list to
MAINTAINERS. Keep the parent build integration last so that intermediate
patches do not expose an incomplete driver configuration.
Signed-off-by: Chunqiu Liu <chunqiuliu@aicsemi.com>
Signed-off-by: Zhirun Liu <zhirunliu@aicsemi.com>
Signed-off-by: Yanli Yang <yanli.yang@bedmex.com>
---
MAINTAINERS | 10 ++++++++++
drivers/net/wireless/Kconfig | 1 +
drivers/net/wireless/Makefile | 1 +
3 files changed, 12 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 7336600952c8..4e327fd62b26 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -746,6 +746,16 @@ L: linux-scsi@vger.kernel.org
S: Maintained
F: drivers/scsi/aic7xxx/
+AIC8800 WIRELESS DRIVER
+M: Zhirun Liu <zhirunliu@aicsemi.com>
+M: Dijia Xu <dijiaxu@aicsemi.com>
+M: Chunqiu Liu <chunqiuliu@aicsemi.com>
+R: Liheng Wei <liheng.wei@bedmex.com>
+R: Yanli Yang <yanli.yang@bedmex.com>
+L: linux-wireless@vger.kernel.org
+S: Maintained
+F: drivers/net/wireless/aic/
+
AIMSLAB FM RADIO RECEIVER DRIVER
M: Hans Verkuil <hverkuil@kernel.org>
L: linux-media@vger.kernel.org
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index f4f969fdbc02..964e633898ca 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -19,6 +19,7 @@ menuconfig WLAN
if WLAN
source "drivers/net/wireless/admtek/Kconfig"
+source "drivers/net/wireless/aic/Kconfig"
source "drivers/net/wireless/ath/Kconfig"
source "drivers/net/wireless/atmel/Kconfig"
source "drivers/net/wireless/broadcom/Kconfig"
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index fa3100ff3bf7..47b999e8014c 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -4,6 +4,7 @@
#
obj-$(CONFIG_WLAN_VENDOR_ADMTEK) += admtek/
+obj-$(CONFIG_WLAN_VENDOR_AIC) += aic/
obj-$(CONFIG_WLAN_VENDOR_ATH) += ath/
obj-$(CONFIG_WLAN_VENDOR_ATMEL) += atmel/
obj-$(CONFIG_WLAN_VENDOR_BROADCOM) += broadcom/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH wireless-next v5 0/4] wifi: aic: Add AIC8800D80 and D80N SDIO FullMAC driver
@ 2026-11-16 7:23 Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 3/4] wifi: aic: Add the AIC8800D80 and D80N " Yanli Yang
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Yanli Yang @ 2026-11-16 7:23 UTC (permalink / raw)
To: linux-wireless
Cc: Johannes Berg, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
devicetree, linux-kernel, Zhirun Liu, Dijia Xu, Chunqiu Liu,
Liheng Wei, yanli.yang
This series adds an SDIO FullMAC Wi-Fi driver for AIC8800D80 U02 and
AIC8800D80N devices, with an initial station-mode configuration using
cfg80211/nl80211 on the 2.4 GHz and 5 GHz bands.
This is the first non-RFC revision, following RFC v1 through v4. It
reworks the driver into a single aic8800_fdrv module, adds D80N support
and documents the SDIO device tree binding. Firmware boot, transport and
network-interface lifecycle are managed within the same driver.
The series is organized as follows:
1. register the vendor prefix and document the SDIO Wi-Fi binding;
2. add firmware definitions, command/event handling, SDIO transport
and D80/D80N chip-specific initialization;
3. add cfg80211 operations, TX/RX paths and driver build configuration;
4. connect the complete driver to the wireless build and MAINTAINERS.
Parent build integration is last so that intermediate source states are
not selectable through the wireless Kconfig.
Changes since RFC v4:
- merge the BSP and FullMAC implementation into one module; remove
aic8800_bsp/ and its private cross-module exported interface;
- consolidate driver sources under aic8800_fdrv/ and rename
the FullMAC rwnx_* source files and core driver symbols to aicwf_*;
- add D80N chip operations, SDIO IDs and U02/U02C firmware boot paths;
- remove the private generic-netlink family and private-command
implementation retained in RFC v4;
- remove the bundled regulatory database and rwnx_settings.ini parser;
use cfg80211 channel restrictions and transmit-power limits when
configuring firmware;
- remove module-parameter entry points and use internal configuration
defaults and standard cfg80211 operations;
- replace Makefile-generated CONFIG_* definitions with Kconfig symbols
and internal resource-limit definitions;
- load firmware through the standard firmware loader under aic/ and
declare the required filenames with MODULE_FIRMWARE();
- add the shared D80/D80N device tree binding and vendor prefix; and
- rebase and repartition the series for the current source layout.
Because the BSP layer has been removed and the source layout and patch
boundaries have changed, RFC v4 patches do not map one-to-one to this
revision. This is a new-driver series against wireless-next; the changes
above describe its evolution from the earlier submissions.
Scope:
- the selectable baseline is SDIO station mode on D80 U02 and D80N;
- AP, P2P, monitor and mesh modes are not enabled by this configuration;
some associated source and disabled branches remain;
- optional per-device TX-buffer and TX-queue preallocation remain;
- the binding documents optional out-of-band wake lines; this revision
uses the SDIO interrupt path and does not consume those optional
wake-line properties; and
- firmware binaries and user configuration files are not part of this
kernel series. The driver requests them from aic/aic8800d80/ and
aic/aic8800d80n/ in the firmware search path.
Validation of the current source:
- Both AIC8800D80 and AIC8800D80N passed probe and firmware boot,
module unload/reload, active/passive scanning on 2.4 and 5 GHz, open,
WPA2-PSK and WPA3-SAE station connections, disconnect/reconnect,
IPv4/IPv6 connectivity, suspend/resume and rfkill tests.
- TCP and UDP TX/RX throughput testing was completed on both chips.
Reported TCP TX/RX rates were 196/210 Mbit/s on 2.4 GHz and
375/445 Mbit/s on 5 GHz; UDP TX/RX rates were 218/225 Mbit/s and
422/511 Mbit/s, respectively.
- Both chips passed 10 hours of sustained traffic testing. No kernel
crashes, warnings, lockdep reports or firmware crashes were observed
during testing.
- GCC module builds, sparse and coccicheck checks passed, with no new
compiler or sparse warnings reported.
- 32-bit, allmodconfig warning-check and Clang builds succeeded in a
newly created container.
AP mode and smatch were not run.
Previous submissions:
RFC v4: https://lore.kernel.org/r/cover.1787991457.git.yanli.yang@bedmex.com
RFC v3: https://lore.kernel.org/r/cover.1787903339.git.yanli.yang@bedmex.com
RFC v2: https://lore.kernel.org/r/cover.1784724170.git.yanli.yang@bedmex.com
RFC v1: https://lore.kernel.org/r/cover.1784544076.git.yanli.yang@bedmex.com
Tool assistance: OpenAI Codex assisted with the cover letter, commit
descriptions and patch-series preparation.
Zhirun Liu (4):
dt-bindings: net: wireless: Add AIC8800D80 SDIO Wi-Fi
wifi: aic: Add firmware protocol and SDIO chip support
wifi: aic: Add the AIC8800D80 and D80N FullMAC driver
wifi: aic: Integrate the AIC8800 SDIO driver
.../net/wireless/aicsemi,aic8800d80-fmac.yaml | 78 +
.../devicetree/bindings/vendor-prefixes.yaml | 2 +
MAINTAINERS | 10 +
drivers/net/wireless/Kconfig | 1 +
drivers/net/wireless/Makefile | 1 +
drivers/net/wireless/aic/Kconfig | 16 +
drivers/net/wireless/aic/Makefile | 3 +
drivers/net/wireless/aic/aic8800_fdrv/Kconfig | 90 +
.../net/wireless/aic/aic8800_fdrv/Makefile | 36 +
.../net/wireless/aic/aic8800_fdrv/aic_bus.h | 99 +
.../wireless/aic/aic8800_fdrv/aicwf_bfmer.c | 93 +
.../wireless/aic/aic8800_fdrv/aicwf_bfmer.h | 100 +
.../aic/aic8800_fdrv/aicwf_chip_8800d80.c | 96 +
.../aic/aic8800_fdrv/aicwf_chip_8800d80n.c | 74 +
.../aic/aic8800_fdrv/aicwf_chip_ops.c | 197 +
.../aic/aic8800_fdrv/aicwf_chip_ops.h | 116 +
.../wireless/aic/aic8800_fdrv/aicwf_cmds.c | 629 ++
.../wireless/aic/aic8800_fdrv/aicwf_cmds.h | 122 +
.../aic/aic8800_fdrv/aicwf_compat_8800d80.c | 281 +
.../aic/aic8800_fdrv/aicwf_compat_8800d80.h | 17 +
.../aic/aic8800_fdrv/aicwf_compat_8800d80n.c | 402 ++
.../aic/aic8800_fdrv/aicwf_compat_8800d80n.h | 17 +
.../wireless/aic/aic8800_fdrv/aicwf_config.h | 33 +
.../wireless/aic/aic8800_fdrv/aicwf_defs.h | 657 +++
.../wireless/aic/aic8800_fdrv/aicwf_events.h | 938 +++
.../wireless/aic/aic8800_fdrv/aicwf_main.c | 5114 +++++++++++++++++
.../wireless/aic/aic8800_fdrv/aicwf_main.h | 22 +
.../wireless/aic/aic8800_fdrv/aicwf_mesh.c | 33 +
.../wireless/aic/aic8800_fdrv/aicwf_mesh.h | 39 +
.../aic/aic8800_fdrv/aicwf_mod_params.c | 644 +++
.../aic/aic8800_fdrv/aicwf_mod_params.h | 59 +
.../wireless/aic/aic8800_fdrv/aicwf_msg_rx.c | 1412 +++++
.../wireless/aic/aic8800_fdrv/aicwf_msg_rx.h | 12 +
.../wireless/aic/aic8800_fdrv/aicwf_msg_tx.c | 2499 ++++++++
.../wireless/aic/aic8800_fdrv/aicwf_msg_tx.h | 201 +
.../aic/aic8800_fdrv/aicwf_mu_group.c | 653 +++
.../aic/aic8800_fdrv/aicwf_mu_group.h | 163 +
.../aic/aic8800_fdrv/aicwf_platform.c | 1507 +++++
.../aic/aic8800_fdrv/aicwf_platform.h | 91 +
.../wireless/aic/aic8800_fdrv/aicwf_radar.c | 1969 +++++++
.../wireless/aic/aic8800_fdrv/aicwf_radar.h | 289 +
.../aic/aic8800_fdrv/aicwf_resv_mem.c | 106 +
.../aic/aic8800_fdrv/aicwf_resv_mem.h | 54 +
.../net/wireless/aic/aic8800_fdrv/aicwf_rx.c | 2434 ++++++++
.../net/wireless/aic/aic8800_fdrv/aicwf_rx.h | 363 ++
.../aic/aic8800_fdrv/aicwf_rx_prealloc.c | 99 +
.../aic/aic8800_fdrv/aicwf_rx_prealloc.h | 39 +
.../wireless/aic/aic8800_fdrv/aicwf_sdio.c | 2439 ++++++++
.../wireless/aic/aic8800_fdrv/aicwf_sdio.h | 280 +
.../wireless/aic/aic8800_fdrv/aicwf_strs.c | 267 +
.../wireless/aic/aic8800_fdrv/aicwf_strs.h | 31 +
.../net/wireless/aic/aic8800_fdrv/aicwf_tx.c | 1469 +++++
.../net/wireless/aic/aic8800_fdrv/aicwf_tx.h | 165 +
.../net/wireless/aic/aic8800_fdrv/aicwf_txq.c | 1368 +++++
.../net/wireless/aic/aic8800_fdrv/aicwf_txq.h | 353 ++
.../aic/aic8800_fdrv/aicwf_txq_prealloc.c | 55 +
.../aic/aic8800_fdrv/aicwf_txq_prealloc.h | 31 +
.../wireless/aic/aic8800_fdrv/aicwf_txrxif.c | 666 +++
.../wireless/aic/aic8800_fdrv/aicwf_txrxif.h | 161 +
.../wireless/aic/aic8800_fdrv/aicwf_utils.c | 32 +
.../wireless/aic/aic8800_fdrv/aicwf_utils.h | 61 +
.../net/wireless/aic/aic8800_fdrv/hal_desc.h | 359 ++
.../wireless/aic/aic8800_fdrv/ipc_shared.h | 767 +++
.../net/wireless/aic/aic8800_fdrv/lmac_mac.h | 437 ++
.../net/wireless/aic/aic8800_fdrv/lmac_msg.h | 3092 ++++++++++
.../wireless/aic/aic8800_fdrv/lmac_types.h | 21 +
.../net/wireless/aic/aic8800_fdrv/sdio_host.c | 136 +
.../net/wireless/aic/aic8800_fdrv/sdio_host.h | 43 +
68 files changed, 34143 insertions(+)
create mode 100644 Documentation/devicetree/bindings/net/wireless/aicsemi,aic8800d80-fmac.yaml
create mode 100644 drivers/net/wireless/aic/Kconfig
create mode 100644 drivers/net/wireless/aic/Makefile
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/Kconfig
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/Makefile
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aic_bus.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_bfmer.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_bfmer.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_8800d80.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_8800d80n.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_ops.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_chip_ops.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_cmds.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_cmds.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80n.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_compat_8800d80n.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_config.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_defs.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_events.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_main.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_main.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mesh.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mesh.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mod_params.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mod_params.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_rx.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_rx.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_tx.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_msg_tx.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mu_group.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mu_group.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_platform.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_platform.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_radar.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_radar.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_resv_mem.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_resv_mem.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx_prealloc.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx_prealloc.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_sdio.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_sdio.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_strs.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_strs.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_tx.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_tx.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq_prealloc.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq_prealloc.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txrxif.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txrxif.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_utils.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_utils.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/hal_desc.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/ipc_shared.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/lmac_mac.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/lmac_msg.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/lmac_types.h
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/sdio_host.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/sdio_host.h
base-commit: b8e5b0ae8ff47240366d38e5d12c65f878724316
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH wireless-next v5 3/4] wifi: aic: Add the AIC8800D80 and D80N FullMAC driver
2026-11-16 7:23 [PATCH wireless-next v5 0/4] wifi: aic: Add AIC8800D80 and D80N SDIO FullMAC driver Yanli Yang
@ 2026-11-16 7:23 ` Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 2/4] wifi: aic: Add firmware protocol and SDIO chip support Yanli Yang
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Yanli Yang @ 2026-11-16 7:23 UTC (permalink / raw)
To: linux-wireless
Cc: Johannes Berg, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
devicetree, linux-kernel, Zhirun Liu, Dijia Xu, Chunqiu Liu,
Liheng Wei, yanli.yang
From: Zhirun Liu <zhirunliu@aicsemi.com>
Add the cfg80211 interface and TX/RX data paths for AIC8800D80 U02 and
AIC8800D80N SDIO Wi-Fi. Expose station operation on the 2.4 GHz and 5 GHz
bands through cfg80211/nl80211, with scanning, connection management,
key configuration and station statistics.
Implement transmit queues, receive reordering and packet delivery, and
register firmware-derived capabilities with cfg80211. Propagate the
cfg80211 channel restrictions and power limits to the firmware through
the regulatory notifier.
Add the AIC Kconfig and Makefiles and build a single aic8800_fdrv module.
Keep the initial selectable configuration restricted to station mode.
Retain the existing non-station source behind disabled configuration
branches, together with the optional allocation helpers.
This patch depends on the firmware and transport sources in patch 2.
The next patch connects the complete driver to the wireless build.
Signed-off-by: Chunqiu Liu <chunqiuliu@aicsemi.com>
Signed-off-by: Zhirun Liu <zhirunliu@aicsemi.com>
Signed-off-by: Yanli Yang <yanli.yang@bedmex.com>
---
drivers/net/wireless/aic/Kconfig | 16 +
drivers/net/wireless/aic/Makefile | 3 +
drivers/net/wireless/aic/aic8800_fdrv/Kconfig | 90 +
.../net/wireless/aic/aic8800_fdrv/Makefile | 36 +
.../wireless/aic/aic8800_fdrv/aicwf_bfmer.c | 93 +
.../wireless/aic/aic8800_fdrv/aicwf_main.c | 5114 +++++++++++++++++
.../wireless/aic/aic8800_fdrv/aicwf_mesh.c | 33 +
.../aic/aic8800_fdrv/aicwf_mod_params.c | 644 +++
.../aic/aic8800_fdrv/aicwf_mu_group.c | 653 +++
.../wireless/aic/aic8800_fdrv/aicwf_radar.c | 1969 +++++++
.../aic/aic8800_fdrv/aicwf_resv_mem.c | 106 +
.../net/wireless/aic/aic8800_fdrv/aicwf_rx.c | 2434 ++++++++
.../aic/aic8800_fdrv/aicwf_rx_prealloc.c | 99 +
.../net/wireless/aic/aic8800_fdrv/aicwf_tx.c | 1469 +++++
.../net/wireless/aic/aic8800_fdrv/aicwf_txq.c | 1368 +++++
.../aic/aic8800_fdrv/aicwf_txq_prealloc.c | 55 +
16 files changed, 14182 insertions(+)
create mode 100644 drivers/net/wireless/aic/Kconfig
create mode 100644 drivers/net/wireless/aic/Makefile
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/Kconfig
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/Makefile
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_bfmer.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_main.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mesh.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mod_params.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_mu_group.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_radar.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_resv_mem.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx_prealloc.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_tx.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq.c
create mode 100644 drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq_prealloc.c
diff --git a/drivers/net/wireless/aic/Kconfig b/drivers/net/wireless/aic/Kconfig
new file mode 100644
index 000000000000..338ab1cb97ff
--- /dev/null
+++ b/drivers/net/wireless/aic/Kconfig
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config WLAN_VENDOR_AIC
+ bool "AIC devices"
+ default y
+ help
+ Say Y to expose the AIC8800D80 U02 / AIC8800D80N SDIO Wi-Fi driver.
+ The first upstreaming target is a narrow D80/D80N SDIO station
+ configuration; legacy transport, Bluetooth, Android, test and
+ manufacturing build switches are intentionally not exposed.
+
+if WLAN_VENDOR_AIC
+
+source "drivers/net/wireless/aic/aic8800_fdrv/Kconfig"
+
+endif # WLAN_VENDOR_AIC
diff --git a/drivers/net/wireless/aic/Makefile b/drivers/net/wireless/aic/Makefile
new file mode 100644
index 000000000000..3e4620989aaf
--- /dev/null
+++ b/drivers/net/wireless/aic/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_AIC8800_WLAN_SUPPORT) += aic8800_fdrv/
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/Kconfig b/drivers/net/wireless/aic/aic8800_fdrv/Kconfig
new file mode 100644
index 000000000000..6416c9c7a5b0
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/Kconfig
@@ -0,0 +1,90 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+menuconfig AIC8800_WLAN_SUPPORT
+ tristate "AIC8800D80 U02 / AIC8800D80N SDIO station support"
+ depends on MMC
+ depends on CFG80211
+ select CRYPTO_LIB_MD5
+ help
+ Enable the AIC8800D80 U02 and AIC8800D80N (D80N, D80LN, D40N,
+ D40LN) FullMAC Wi-Fi driver for the first upstreaming baseline.
+ This build is restricted to the SDIO station path and uses
+ cfg80211/nl80211 for normal Wi-Fi operation. The driver also
+ downloads and starts the chip firmware.
+
+ Firmware files are loaded from the aic/aic8800d80/ and
+ aic/aic8800d80n/ subdirectories of the kernel firmware search
+ path for AIC8800D80 and AIC8800D80N, respectively.
+
+ If unsure, say N.
+
+if AIC8800_WLAN_SUPPORT
+
+config AIC8800_SDIO_SUPPORT
+ def_bool y
+ help
+ Build the shared SDIO transport for AIC8800D80 and AIC8800D80N.
+
+config AIC8800_SDIO_PWRCTRL
+ def_bool y
+ depends on AIC8800_SDIO_SUPPORT
+ help
+ Enable SDIO active/sleep transitions and the inactivity timer used
+ by the driver. This is a required feature of the AIC8800D80 and
+ AIC8800D80N SDIO configurations, independent of system suspend support.
+
+config AIC8800_AUTO_POWERSAVE
+ def_bool y
+ depends on AIC8800_SDIO_PWRCTRL
+ help
+ Low-power configuration within the chip
+
+config AIC8800_USE_5G
+ def_bool y
+ help
+ Enable the 5 GHz band. The AIC8800D80 is a dual-band device;
+ keep this on for the upstream station baseline.
+
+config RESV_MEM_SUPPORT
+ bool "Reserve the SDIO TX aggregation buffer per device"
+ depends on AIC8800_SDIO_SUPPORT
+ help
+ Allocate the SDIO TX aggregation buffer as soon as the device is
+ probed and keep it until the device is removed, instead of
+ allocating it when the SDIO bus is brought up.
+
+ If unsure, say N.
+
+config PREALLOC_TXQ
+ bool "Preallocate the TX queue array"
+ help
+ Allocate the TX queue array separately and keep it until the
+ device is removed, instead of embedding it in the wiphy private
+ data.
+
+ If unsure, say N.
+
+config AICWF_FULLMAC
+ def_bool y
+
+# Preserve the enabled features of the SDIO station baseline.
+config AIC8800_RX_REORDER
+ def_bool y
+
+config AIC8800_ARP_OFFLOAD
+ def_bool y
+
+config AIC8800_RX_NETIF_RECV_SKB
+ def_bool y
+
+config AIC8800_STA_ONLY
+ def_bool y
+ help
+ Limit the initial upstream driver to station mode. The AP, P2P,
+ monitor and mesh implementations remain in the source tree
+ so they can be enabled when those modes are ready for upstream.
+
+config AIC8800_NONSTA_SUPPORT
+ def_bool y if !AIC8800_STA_ONLY
+
+endif # AIC8800_WLAN_SUPPORT
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/Makefile b/drivers/net/wireless/aic/aic8800_fdrv/Makefile
new file mode 100644
index 000000000000..d80b3f134e75
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/Makefile
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: GPL-2.0
+
+
+obj-$(CONFIG_AIC8800_WLAN_SUPPORT) += aic8800_fdrv.o
+
+aic8800_fdrv-y := \
+ aicwf_msg_tx.o \
+ aicwf_msg_rx.o \
+ aicwf_utils.o \
+ aicwf_cmds.o \
+ aicwf_strs.o \
+ aicwf_rx.o \
+ aicwf_tx.o \
+ aicwf_txq.o \
+ aicwf_main.o \
+ aicwf_mod_params.o \
+ aicwf_platform.o \
+ aicwf_chip_8800d80.o \
+ aicwf_chip_8800d80n.o \
+ aicwf_chip_ops.o \
+ aicwf_compat_8800d80.o \
+ aicwf_compat_8800d80n.o
+
+aic8800_fdrv-$(CONFIG_AIC8800_SDIO_SUPPORT) += \
+ sdio_host.o \
+ aicwf_txrxif.o \
+ aicwf_sdio.o \
+ aicwf_rx_prealloc.o
+
+aic8800_fdrv-$(CONFIG_AIC8800_NONSTA_SUPPORT) += aicwf_mesh.o
+aic8800_fdrv-$(CONFIG_RESV_MEM_SUPPORT) += aicwf_resv_mem.o
+aic8800_fdrv-$(CONFIG_PREALLOC_TXQ) += aicwf_txq_prealloc.o
+
+ccflags-y += -I$(srctree)
+ccflags-y += -I$(src)
+ccflags-y += -DAIC_TRACE_INCLUDE_PATH=$(src)
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_bfmer.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_bfmer.c
new file mode 100644
index 000000000000..56102ce0dab4
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_bfmer.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief VHT Beamformer function definitions
+ *
+ ******************************************************************************
+ */
+
+#include "aicwf_bfmer.h"
+#include <linux/slab.h>
+
+int aicwf_bfmer_report_add(struct aicwf_hw *aicwf_hw, struct aicwf_sta *aicwf_sta,
+ unsigned int length)
+{
+ gfp_t flags;
+ struct aicwf_bfmer_report *bfm_report;
+
+ if (in_softirq())
+ flags = GFP_ATOMIC;
+ else
+ flags = GFP_KERNEL;
+
+ /* Allocate a structure that will contain the beamforming report */
+ bfm_report = kmalloc(sizeof(*bfm_report) + length, flags);
+
+ /* Check report allocation */
+ if (!bfm_report) {
+ /* Do not use beamforming */
+ return -1;
+ }
+
+ /* Store report length */
+ bfm_report->length = length;
+
+ /*
+ * Need to provide a Virtual Address to the MAC so that it can
+ * upload the received Beamforming Report in driver memory
+ */
+ bfm_report->dma_addr = dma_map_single(aicwf_hw->dev, &bfm_report->report[0],
+ length, DMA_FROM_DEVICE);
+
+ /* Check DMA mapping result */
+ if (dma_mapping_error(aicwf_hw->dev, bfm_report->dma_addr)) {
+ /* Free allocated report */
+ kfree(bfm_report);
+ /* And leave */
+ return -1;
+ }
+
+ /* Store report structure */
+ aicwf_sta->bfm_report = bfm_report;
+
+ return 0;
+}
+
+void aicwf_bfmer_report_del(struct aicwf_hw *aicwf_hw, struct aicwf_sta *aicwf_sta)
+{
+ /* Verify if a report has been allocated */
+ if (aicwf_sta->bfm_report) {
+ struct aicwf_bfmer_report *bfm_report = aicwf_sta->bfm_report;
+
+ /* Unmap DMA region */
+ dma_unmap_single(aicwf_hw->dev, bfm_report->dma_addr, bfm_report->length,
+ DMA_BIDIRECTIONAL);
+
+ /* Free allocated report structure and clean the pointer */
+ kfree(bfm_report);
+ aicwf_sta->bfm_report = NULL;
+ }
+}
+
+#ifdef CONFIG_AICWF_FULLMAC
+u8 aicwf_bfmer_get_rx_nss(const struct ieee80211_vht_cap *vht_capa)
+{
+ int i;
+ u8 rx_nss = 0;
+ u16 rx_mcs_map = le16_to_cpu(vht_capa->supp_mcs.rx_mcs_map);
+
+ for (i = 7; i >= 0; i--) {
+ u8 mcs = (rx_mcs_map >> (2 * i)) & 3;
+
+ if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
+ rx_nss = i + 1;
+ break;
+ }
+ }
+
+ return rx_nss;
+}
+#endif /* CONFIG_AICWF_FULLMAC */
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_main.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_main.c
new file mode 100644
index 000000000000..6cc6eb349023
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_main.c
@@ -0,0 +1,5114 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief Entry point of the driver
+ *
+ ******************************************************************************
+ */
+
+#include "hal_desc.h"
+#include "aicwf_defs.h"
+#include "aicwf_msg_tx.h"
+#include "aicwf_radar.h"
+#include <linux/ctype.h>
+#include <linux/etherdevice.h>
+#include <linux/if_arp.h>
+#include <linux/inetdevice.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/pm.h>
+#include <linux/vmalloc.h>
+#include <generated/utsrelease.h>
+#include <net/cfg80211.h>
+#include <net/ip.h>
+#include <net/netlink.h>
+#ifdef CONFIG_AICWF_BFMER
+#include "aicwf_bfmer.h"
+#endif //(CONFIG_AICWF_BFMER)
+#include "aicwf_txrxif.h"
+#include "aicwf_config.h"
+#include "aicwf_events.h"
+#include "aicwf_main.h"
+#include "aicwf_sdio.h"
+#include "aicwf_compat_8800d80.h"
+#include "aicwf_chip_ops.h"
+
+#define RW_DRV_DESCRIPTION "RivieraWaves 11nac driver for Linux cfg80211"
+#define RW_DRV_COPYRIGHT "Copyright(c) 2015-2017 RivieraWaves"
+#define RW_DRV_AUTHOR "RivieraWaves S.A.S"
+
+#define AICWF_HT_CAPABILITIES \
+ { \
+ .ht_supported = true, \
+ .cap = 0, \
+ .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, \
+ .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16, \
+ .mcs = \
+ { \
+ .rx_mask = \
+ { \
+ 0xff, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ }, \
+ .rx_highest = cpu_to_le16(65), \
+ .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
+ }, \
+ }
+
+#define AICWF_VHT_CAPABILITIES \
+ { \
+ .vht_supported = false, \
+ .cap = (7 << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT), \
+ .vht_mcs = { \
+ .rx_mcs_map = cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 14), \
+ .tx_mcs_map = cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 | \
+ IEEE80211_VHT_MCS_NOT_SUPPORTED << 14), \
+ } \
+ }
+
+#define AICWF_HE_CAPABILITIES \
+ { \
+ .has_he = false, \
+ .he_cap_elem = { \
+ .mac_cap_info[0] = 0, \
+ .mac_cap_info[1] = 0, \
+ .mac_cap_info[2] = 0, \
+ .mac_cap_info[3] = 0, \
+ .mac_cap_info[4] = 0, \
+ .mac_cap_info[5] = 0, \
+ .phy_cap_info[0] = 0, \
+ .phy_cap_info[1] = 0, \
+ .phy_cap_info[2] = 0, \
+ .phy_cap_info[3] = 0, \
+ .phy_cap_info[4] = 0, \
+ .phy_cap_info[5] = 0, \
+ .phy_cap_info[6] = 0, \
+ .phy_cap_info[7] = 0, \
+ .phy_cap_info[8] = 0, \
+ .phy_cap_info[9] = 0, \
+ .phy_cap_info[10] = 0, \
+ }, \
+ .he_mcs_nss_supp = { \
+ .rx_mcs_80 = cpu_to_le16(0xfffa), \
+ .tx_mcs_80 = cpu_to_le16(0xfffa), \
+ .rx_mcs_160 = cpu_to_le16(0xffff), \
+ .tx_mcs_160 = cpu_to_le16(0xffff), \
+ .rx_mcs_80p80 = cpu_to_le16(0xffff), \
+ .tx_mcs_80p80 = cpu_to_le16(0xffff), \
+ }, \
+ .ppe_thres = {0x08, 0x1c, 0x07}, \
+ }
+
+#define RATE(_bitrate, _hw_rate, _flags) \
+ { \
+ .bitrate = (_bitrate), \
+ .flags = (_flags), \
+ .hw_value = (_hw_rate), \
+ }
+
+#define CHAN(_freq) \
+ { \
+ .center_freq = (_freq), .max_power = 30, /* FIXME */ \
+ }
+
+static struct ieee80211_rate aicwf_ratetable[] = {
+ RATE(10, 0x00, 0),
+ RATE(20, 0x01, IEEE80211_RATE_SHORT_PREAMBLE),
+ RATE(55, 0x02, IEEE80211_RATE_SHORT_PREAMBLE),
+ RATE(110, 0x03, IEEE80211_RATE_SHORT_PREAMBLE),
+ RATE(60, 0x04, 0),
+ RATE(90, 0x05, 0),
+ RATE(120, 0x06, 0),
+ RATE(180, 0x07, 0),
+ RATE(240, 0x08, 0),
+ RATE(360, 0x09, 0),
+ RATE(480, 0x0A, 0),
+ RATE(540, 0x0B, 0),
+};
+
+/* The channels indexes here are not used anymore */
+static struct ieee80211_channel aicwf_2ghz_channels[] = {
+ CHAN(2412),
+ CHAN(2417),
+ CHAN(2422),
+ CHAN(2427),
+ CHAN(2432),
+ CHAN(2437),
+ CHAN(2442),
+ CHAN(2447),
+ CHAN(2452),
+ CHAN(2457),
+ CHAN(2462),
+ CHAN(2467),
+ CHAN(2472),
+ CHAN(2484),
+};
+
+static struct ieee80211_channel aicwf_5ghz_channels[] = {
+ CHAN(5180), // 36 - 20MHz
+ CHAN(5200), // 40 - 20MHz
+ CHAN(5220), // 44 - 20MHz
+ CHAN(5240), // 48 - 20MHz
+ CHAN(5260), // 52 - 20MHz
+ CHAN(5280), // 56 - 20MHz
+ CHAN(5300), // 60 - 20MHz
+ CHAN(5320), // 64 - 20MHz
+ CHAN(5500), // 100 - 20MHz
+ CHAN(5520), // 104 - 20MHz
+ CHAN(5540), // 108 - 20MHz
+ CHAN(5560), // 112 - 20MHz
+ CHAN(5580), // 116 - 20MHz
+ CHAN(5600), // 120 - 20MHz
+ CHAN(5620), // 124 - 20MHz
+ CHAN(5640), // 128 - 20MHz
+ CHAN(5660), // 132 - 20MHz
+ CHAN(5680), // 136 - 20MHz
+ CHAN(5700), // 140 - 20MHz
+ CHAN(5720), // 144 - 20MHz
+ CHAN(5745), // 149 - 20MHz
+ CHAN(5765), // 153 - 20MHz
+ CHAN(5785), // 157 - 20MHz
+ CHAN(5805), // 161 - 20MHz
+ CHAN(5825), // 165 - 20MHz
+};
+
+static const struct ieee80211_sband_iftype_data aicwf_he_capa[1] = {
+ {
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ .types_mask = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP),
+#else
+ .types_mask = BIT(NL80211_IFTYPE_STATION),
+#endif
+ .he_cap = AICWF_HE_CAPABILITIES,
+ },
+};
+
+static const struct ieee80211_supported_band aicwf_band_2ghz = {
+ .channels = aicwf_2ghz_channels,
+ .n_channels = ARRAY_SIZE(aicwf_2ghz_channels),
+ .bitrates = aicwf_ratetable,
+ .n_bitrates = ARRAY_SIZE(aicwf_ratetable),
+ .ht_cap = AICWF_HT_CAPABILITIES,
+ .vht_cap = AICWF_VHT_CAPABILITIES,
+};
+
+static const struct ieee80211_supported_band aicwf_band_5ghz = {
+ .channels = aicwf_5ghz_channels,
+ .n_channels = ARRAY_SIZE(aicwf_5ghz_channels),
+ .bitrates = &aicwf_ratetable[4],
+ .n_bitrates = ARRAY_SIZE(aicwf_ratetable) - 4,
+ .ht_cap = AICWF_HT_CAPABILITIES,
+ .vht_cap = AICWF_VHT_CAPABILITIES,
+};
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+static struct ieee80211_iface_limit aicwf_limits[] = {
+ {.max = 1, .types = BIT(NL80211_IFTYPE_STATION)},
+ {.max = 1, .types = BIT(NL80211_IFTYPE_AP)},
+#ifdef CONFIG_AIC8800_USE_P2P0
+ {.max = 2,
+#else
+ {.max = 1,
+#endif
+ .types = BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO)},
+#ifndef CONFIG_AIC8800_USE_P2P0
+ {
+ .max = 1,
+ .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
+ }
+#endif
+};
+
+static struct ieee80211_iface_limit aicwf_limits_dfs[] = {
+ {.max = NX_VIRT_DEV_MAX, .types = BIT(NL80211_IFTYPE_AP)}};
+
+static const struct ieee80211_iface_combination aicwf_combinations[] = {
+ {
+ .limits = aicwf_limits,
+ .n_limits = ARRAY_SIZE(aicwf_limits),
+#ifdef CONFIG_AIC8800_MCC
+ .num_different_channels = NX_CHAN_CTXT_CNT,
+#else
+ .num_different_channels = 1,
+#endif
+ .max_interfaces = NX_VIRT_DEV_MAX,
+ },
+ /* Keep this combination as the last one */
+ {
+ .limits = aicwf_limits_dfs,
+ .n_limits = ARRAY_SIZE(aicwf_limits_dfs),
+ .num_different_channels = 1,
+ .max_interfaces = NX_VIRT_DEV_MAX,
+ .radar_detect_widths =
+ (BIT(NL80211_CHAN_WIDTH_20_NOHT) | BIT(NL80211_CHAN_WIDTH_20) |
+ BIT(NL80211_CHAN_WIDTH_40) | BIT(NL80211_CHAN_WIDTH_80)),
+ }};
+#endif
+
+/* There isn't a lot of sense in it, but you can transmit anything you like */
+static const struct ieee80211_txrx_stypes
+ aicwf_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
+ [NL80211_IFTYPE_STATION] = {
+ .tx = 0xffff,
+ .rx = (BIT(IEEE80211_STYPE_ACTION >> 4) |
+ BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
+ BIT(IEEE80211_STYPE_AUTH >> 4)),
+ },
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ [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_AP_VLAN] = {
+ /* copy 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)),
+ },
+ [NL80211_IFTYPE_P2P_GO] = {
+ .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_DEVICE] = {
+ .tx = 0xffff,
+ .rx = (BIT(IEEE80211_STYPE_ACTION >> 4) |
+ BIT(IEEE80211_STYPE_PROBE_REQ >> 4)),
+ },
+ [NL80211_IFTYPE_MESH_POINT] = {
+ .tx = 0xffff,
+ .rx = (BIT(IEEE80211_STYPE_ACTION >> 4) |
+ BIT(IEEE80211_STYPE_AUTH >> 4) |
+ BIT(IEEE80211_STYPE_DEAUTH >> 4)),
+ },
+#endif
+};
+
+static const u32 aicwf_cipher_suites[] = {
+ WLAN_CIPHER_SUITE_WEP40,
+ WLAN_CIPHER_SUITE_WEP104,
+ WLAN_CIPHER_SUITE_TKIP,
+ WLAN_CIPHER_SUITE_CCMP,
+ WLAN_CIPHER_SUITE_AES_CMAC,
+ WLAN_CIPHER_SUITE_SMS4,
+};
+
+static const int aicwf_ac2hwq[1][NL80211_NUM_ACS] = {
+ {[NL80211_TXQ_Q_VO] = AICWF_HWQ_VO,
+ [NL80211_TXQ_Q_VI] = AICWF_HWQ_VI,
+ [NL80211_TXQ_Q_BE] = AICWF_HWQ_BE,
+ [NL80211_TXQ_Q_BK] = AICWF_HWQ_BK}};
+
+const int aicwf_tid2hwq[IEEE80211_NUM_TIDS] = {
+ AICWF_HWQ_BE,
+ AICWF_HWQ_BK,
+ AICWF_HWQ_BK,
+ AICWF_HWQ_BE,
+ AICWF_HWQ_VI,
+ AICWF_HWQ_VI,
+ AICWF_HWQ_VO,
+ AICWF_HWQ_VO,
+ /* TID_8 is used for management frames */
+ AICWF_HWQ_VO,
+ /* At the moment, all others TID are mapped to BE */
+ AICWF_HWQ_BE,
+ AICWF_HWQ_BE,
+ AICWF_HWQ_BE,
+ AICWF_HWQ_BE,
+ AICWF_HWQ_BE,
+ AICWF_HWQ_BE,
+ AICWF_HWQ_BE,
+};
+
+static const int aicwf_hwq2uapsd[NL80211_NUM_ACS] = {
+ [AICWF_HWQ_VO] = IEEE80211_WMM_IE_STA_QOSINFO_AC_VO,
+ [AICWF_HWQ_VI] = IEEE80211_WMM_IE_STA_QOSINFO_AC_VI,
+ [AICWF_HWQ_BE] = IEEE80211_WMM_IE_STA_QOSINFO_AC_BE,
+ [AICWF_HWQ_BK] = IEEE80211_WMM_IE_STA_QOSINFO_AC_BK,
+};
+
+#define P2P_ALIVE_TIME_MS (1 * 1000)
+#define P2P_ALIVE_TIME_COUNT 200
+
+/*********************************************************************
+ * helper
+ *********************************************************************/
+struct aicwf_sta *aicwf_get_sta(struct aicwf_hw *aicwf_hw, const u8 *mac_addr)
+{
+ int i;
+
+ for (i = 0; i < NX_REMOTE_STA_MAX; i++) {
+ struct aicwf_sta *sta = &aicwf_hw->sta_table[i];
+
+ if (sta->valid && memcmp(mac_addr, &sta->mac_addr, 6) == 0)
+ return sta;
+ }
+ return NULL;
+}
+
+void aicwf_enable_wapi(struct aicwf_hw *aicwf_hw)
+{
+ aicwf_hw->wiphy->n_cipher_suites++;
+ aicwf_hw->wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
+}
+
+u8 *aicwf_build_bcn(struct aicwf_bcn *bcn, struct cfg80211_beacon_data *new)
+{
+ u8 *buf, *pos;
+
+ if (new->head) {
+ u8 *head = kmalloc(new->head_len, GFP_KERNEL);
+
+ if (!head)
+ return NULL;
+
+ kfree(bcn->head);
+
+ bcn->head = head;
+ bcn->head_len = new->head_len;
+ memcpy(bcn->head, new->head, new->head_len);
+ }
+ if (new->tail) {
+ u8 *tail = kmalloc(new->tail_len, GFP_KERNEL);
+
+ if (!tail)
+ return NULL;
+
+ kfree(bcn->tail);
+
+ bcn->tail = tail;
+ bcn->tail_len = new->tail_len;
+ memcpy(bcn->tail, new->tail, new->tail_len);
+ }
+
+ if (!bcn->head)
+ return NULL;
+
+ bcn->tim_len = 6;
+ bcn->len = bcn->head_len + bcn->tail_len + bcn->ies_len + bcn->tim_len;
+
+ buf = kmalloc(bcn->len, GFP_KERNEL);
+ if (!buf)
+ return NULL;
+
+ // Build the beacon buffer
+ pos = buf;
+ memcpy(pos, bcn->head, bcn->head_len);
+ pos += bcn->head_len;
+ *pos++ = WLAN_EID_TIM;
+ *pos++ = 4;
+ *pos++ = 0;
+ *pos++ = bcn->dtim;
+ *pos++ = 0;
+ *pos++ = 0;
+
+ if (bcn->tail) {
+ memcpy(pos, bcn->tail, bcn->tail_len);
+ pos += bcn->tail_len;
+ }
+ if (bcn->ies)
+ memcpy(pos, bcn->ies, bcn->ies_len);
+
+ return buf;
+}
+
+static void aicwf_del_bcn(struct aicwf_bcn *bcn)
+{
+ kfree(bcn->head);
+ bcn->head = NULL;
+ bcn->head_len = 0;
+
+ kfree(bcn->tail);
+ bcn->tail = NULL;
+
+ bcn->tail_len = 0;
+
+ kfree(bcn->ies);
+ bcn->ies = NULL;
+ bcn->ies_len = 0;
+ bcn->tim_len = 0;
+ bcn->dtim = 0;
+ bcn->len = 0;
+}
+
+/*
+ * Link channel ctxt to a vif and thus increments count for this context.
+ */
+void aicwf_chanctx_link(struct aicwf_vif *vif, u8 ch_idx,
+ struct cfg80211_chan_def *chandef)
+{
+ struct aicwf_chanctx *ctxt;
+
+ if (ch_idx >= NX_CHAN_CTXT_CNT) {
+ WARN(1, "Invalid channel ctxt id %d", ch_idx);
+ return;
+ }
+
+ vif->ch_index = ch_idx;
+ ctxt = &vif->aicwf_hw->chanctx_table[ch_idx];
+ ctxt->count++;
+
+ // For now chandef is NULL for STATION interface
+ if (chandef && !ctxt->chan_def.chan)
+ ctxt->chan_def = *chandef;
+}
+
+/*
+ * Unlink channel ctxt from a vif and thus decrements count for this context
+ */
+void aicwf_chanctx_unlink(struct aicwf_vif *vif)
+{
+ struct aicwf_chanctx *ctxt;
+
+ if (vif->ch_index == AICWF_CH_NOT_SET)
+ return;
+
+ ctxt = &vif->aicwf_hw->chanctx_table[vif->ch_index];
+
+ if (ctxt->count == 0)
+ WARN(1, "Chan ctxt ref count is already 0");
+ else
+ ctxt->count--;
+
+ if (ctxt->count == 0) {
+ if (vif->ch_index == vif->aicwf_hw->cur_chanctx) {
+ /* If current chan ctxt is no longer linked to a vif
+ * disable radar detection (no need to check if it was activated)
+ */
+ aicwf_radar_detection_enable(&vif->aicwf_hw->radar,
+ AICWF_RADAR_DETECT_DISABLE,
+ AICWF_RADAR_RIU);
+ }
+ /* set chan to null, so that if this ctxt is relinked to a vif that
+ * don't have channel information, don't use wrong information
+ */
+ ctxt->chan_def.chan = NULL;
+ }
+ vif->ch_index = AICWF_CH_NOT_SET;
+}
+
+int aicwf_chanctx_valid(struct aicwf_hw *aicwf_hw, u8 ch_idx)
+{
+ if (ch_idx >= NX_CHAN_CTXT_CNT ||
+ !aicwf_hw->chanctx_table[ch_idx].chan_def.chan) {
+ return 0;
+ }
+
+ return 1;
+}
+
+static void aicwf_del_csa(struct aicwf_vif *vif)
+{
+ struct aicwf_csa *csa = vif->ap.csa;
+
+ if (!csa)
+ return;
+
+ aicwf_del_bcn(&csa->bcn);
+ kfree(csa);
+ vif->ap.csa = NULL;
+}
+
+static void aicwf_csa_finish(struct work_struct *ws)
+{
+ struct aicwf_csa *csa = container_of(ws, struct aicwf_csa, work);
+ struct aicwf_vif *vif = csa->vif;
+ struct aicwf_hw *aicwf_hw = vif->aicwf_hw;
+ int error = csa->status;
+ u8 *buf, *pos;
+
+ buf = kmalloc(csa->bcn.len, GFP_KERNEL);
+ if (!buf)
+ return;
+ pos = buf;
+
+ memcpy(pos, csa->bcn.head, csa->bcn.head_len);
+ pos += csa->bcn.head_len;
+ *pos++ = WLAN_EID_TIM;
+ *pos++ = 4;
+ *pos++ = 0;
+ *pos++ = csa->bcn.dtim;
+ *pos++ = 0;
+ *pos++ = 0;
+ if (csa->bcn.tail) {
+ memcpy(pos, csa->bcn.tail, csa->bcn.tail_len);
+ pos += csa->bcn.tail_len;
+ }
+ if (csa->bcn.ies)
+ memcpy(pos, csa->bcn.ies, csa->bcn.ies_len);
+
+ if (!error) {
+ error = aicwf_send_bcn(aicwf_hw, buf, vif->vif_index, csa->bcn.len);
+ if (error)
+ return;
+ error = aicwf_send_bcn_change(aicwf_hw, vif->vif_index, 0, csa->bcn.len,
+ csa->bcn.head_len, csa->bcn.tim_len, NULL);
+ }
+
+ if (error) {
+ cfg80211_stop_iface(aicwf_hw->wiphy, &vif->wdev, GFP_KERNEL);
+ } else {
+ wiphy_lock(aicwf_hw->wiphy);
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_chanctx_unlink(vif);
+ aicwf_chanctx_link(vif, csa->ch_idx, &csa->chandef);
+ if (aicwf_hw->cur_chanctx == csa->ch_idx) {
+ aicwf_radar_detection_enable_on_cur_channel(aicwf_hw);
+ aicwf_txq_vif_start(vif, AICWF_TXQ_STOP_CHAN, aicwf_hw);
+ } else {
+ aicwf_txq_vif_stop(vif, AICWF_TXQ_STOP_CHAN, aicwf_hw);
+ }
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ cfg80211_ch_switch_notify(vif->ndev, &csa->chandef, 0);
+ wiphy_unlock(aicwf_hw->wiphy);
+ }
+
+ aicwf_del_csa(vif);
+}
+
+/**
+ * aicwf_external_auth_enable - Enable external authentication on a vif
+ *
+ * @vif: VIF on which external authentication must be enabled
+ *
+ * External authentication requires to start TXQ for unknown STA in
+ * order to send auth frame pusehd by user space.
+ * Note: It is assumed that fw is on the correct channel.
+ */
+void aicwf_external_auth_enable(struct aicwf_vif *vif)
+{
+ vif->sta.external_auth = true;
+ aicwf_txq_unk_vif_init(vif);
+ aicwf_txq_start(aicwf_txq_vif_get(vif, NX_UNK_TXQ_TYPE), 0);
+}
+
+/**
+ * aicwf_external_auth_disable - Disable external authentication on a vif
+ *
+ * @vif: VIF on which external authentication must be disabled
+ */
+void aicwf_external_auth_disable(struct aicwf_vif *vif)
+{
+ if (!vif->sta.external_auth)
+ return;
+
+ vif->sta.external_auth = false;
+ aicwf_txq_unk_vif_deinit(vif);
+}
+
+/**
+ * aicwf_update_mesh_power_mode - Recompute the power mode of a mesh VIF
+ *
+ * @vif: mesh VIF for which power mode is updated
+ *
+ * Does nothing if vif is not a mesh point interface.
+ * Since firmware doesn't support one power save mode per link select the
+ * most "active" power mode among all mesh links.
+ * Indeed as soon as we have to be active on one link we might as well be
+ * active on all links.
+ *
+ * If there is no link then the power mode for next peer is used;
+ */
+void aicwf_update_mesh_power_mode(struct aicwf_vif *vif)
+{
+ enum nl80211_mesh_power_mode mesh_pm;
+ struct aicwf_sta *sta;
+ struct mesh_config mesh_conf;
+ struct mesh_update_cfm cfm;
+ u32 mask;
+
+ if (AICWF_VIF_TYPE(vif) != NL80211_IFTYPE_MESH_POINT)
+ return;
+
+ if (list_empty(&vif->ap.sta_list)) {
+ mesh_pm = vif->ap.next_mesh_pm;
+ } else {
+ mesh_pm = NL80211_MESH_POWER_DEEP_SLEEP;
+ list_for_each_entry(sta, &vif->ap.sta_list, list) {
+ if (sta->valid && sta->mesh_pm < mesh_pm)
+ mesh_pm = sta->mesh_pm;
+ }
+ }
+
+ if (mesh_pm == vif->ap.mesh_pm)
+ return;
+
+ mask = BIT(NL80211_MESHCONF_POWER_MODE - 1);
+ mesh_conf.power_mode = mesh_pm;
+ if (aicwf_send_mesh_update_req(vif->aicwf_hw, vif, mask, &mesh_conf, &cfm) ||
+ cfm.status)
+ return;
+
+ vif->ap.mesh_pm = mesh_pm;
+}
+
+static const char *const s_conn_state[] = {
+ "AICWF_DRV_STATUS_DISCONNECTED",
+ "AICWF_DRV_STATUS_DISCONNECTING",
+ "AICWF_DRV_STATUS_CONNECTING",
+ "AICWF_DRV_STATUS_CONNECTED",
+ "AICWF_DRV_STATUS_ROAMING",
+};
+
+void aicwf_set_conn_state(atomic_t *drv_conn_state, int state)
+{
+ if ((int)atomic_read(drv_conn_state) != state) {
+ pr_debug("drv_conn_state:%p %s --> %s\n",
+ drv_conn_state,
+ s_conn_state[(int)atomic_read(drv_conn_state)],
+ s_conn_state[state]);
+ atomic_set(drv_conn_state, state);
+ }
+}
+
+/*********************************************************************
+ * netdev callbacks
+ ********************************************************************/
+/*
+ * int (*ndo_open)(struct net_device *dev);
+ * This function is called when network device transistions to the up
+ * state.
+ *
+ * - Start FW if this is the first interface opened
+ * - Add interface at fw level
+ */
+static int aicwf_open(struct net_device *dev)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+ struct mm_add_if_cfm add_if_cfm;
+ int error = 0;
+ u8 aicwf_rx_gain = 0x0E;
+ int err = 0;
+ int waiting_counter = 10;
+
+ while (test_bit(AICWF_DEV_STARTED, &aicwf_vif->drv_flags)) {
+ msleep(100);
+ dev_dbg(&dev->dev, "waiting for aicwf_close\n");
+ waiting_counter--;
+ if (waiting_counter == 0) {
+ dev_err(aicwf_hw->dev, "error waiting for close time out\n");
+ break;
+ }
+ }
+
+ if (READ_ONCE(aicwf_hw->regdom_failed))
+ return -EIO;
+
+ // Check if it is the first opened VIF
+ if (aicwf_hw->vif_started == 0) {
+ error = aicwf_send_me_chan_config_req(aicwf_hw);
+ if (error)
+ return error;
+
+ // Start the FW
+ error = aicwf_send_start(aicwf_hw);
+ if (error)
+ return error;
+
+ error = aic_chip_set_rx_gain(aicwf_hw, aicwf_rx_gain);
+ if (error)
+ return error;
+
+ /* Device is now started */
+ }
+
+ set_bit(AICWF_DEV_STARTED, &aicwf_vif->drv_flags);
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state, AICWF_DRV_STATUS_DISCONNECTED);
+ dev_dbg(&dev->dev, "aicwf_vif->drv_flags:%d\n",
+ (int)aicwf_vif->drv_flags);
+
+ if (AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_P2P_CLIENT ||
+ AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_P2P_GO) {
+ if (!aicwf_hw->is_p2p_alive &&
+ (aicwf_hw->p2p_dev_vif && !aicwf_hw->p2p_dev_vif->up)) {
+ err = aicwf_send_add_if(aicwf_hw,
+ aicwf_hw->p2p_dev_vif->wdev.address,
+ AICWF_VIF_TYPE(aicwf_hw->p2p_dev_vif),
+ false, &add_if_cfm);
+ if (err)
+ return -EIO;
+
+ if (add_if_cfm.status != 0)
+ return -EIO;
+
+ /* Save the index retrieved from LMAC */
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_hw->p2p_dev_vif->vif_index = add_if_cfm.inst_nbr;
+ aicwf_hw->p2p_dev_vif->up = true;
+ aicwf_hw->vif_started++;
+ aicwf_hw->vif_table[add_if_cfm.inst_nbr] = aicwf_hw->p2p_dev_vif;
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ aicwf_hw->is_p2p_alive = 1;
+#ifndef CONFIG_AIC8800_USE_P2P0
+ mod_timer(&aicwf_hw->p2p_alive_timer,
+ jiffies + msecs_to_jiffies(1000));
+ atomic_set(&aicwf_hw->p2p_alive_timer_count, 0);
+#endif
+ }
+ }
+
+ if (AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_AP_VLAN) {
+ /* For AP_vlan use same fw and drv indexes. We ensure that this index
+ * will not be used by fw for another vif by taking index >=
+ * NX_VIRT_DEV_MAX
+ */
+ add_if_cfm.inst_nbr = aicwf_vif->drv_vif_index;
+ netif_tx_stop_all_queues(dev);
+
+ /* Save the index retrieved from LMAC */
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_vif->vif_index = add_if_cfm.inst_nbr;
+ aicwf_vif->up = true;
+ aicwf_hw->vif_started++;
+ aicwf_hw->vif_table[add_if_cfm.inst_nbr] = aicwf_vif;
+ dev_dbg(&dev->dev, "ap create vif in aicwf_hw->vif_table[%d]\n", aicwf_vif->vif_index);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ } else {
+ /* Forward the information to the LMAC,
+ * p2p value not used in FMAC configuration, iftype is sufficient
+ */
+ error = aicwf_send_add_if(aicwf_hw, aicwf_vif->wdev.address,
+ AICWF_VIF_TYPE(aicwf_vif), false, &add_if_cfm);
+ if (error) {
+ dev_dbg(&dev->dev, "add if fail\n");
+ return error;
+ }
+
+ if (add_if_cfm.status != 0) {
+ dev_err(aicwf_hw->dev, "add_if: Status Error(%d)\n", add_if_cfm.status);
+ return -EIO;
+ }
+
+ /* Save the index retrieved from LMAC */
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_vif->vif_index = add_if_cfm.inst_nbr;
+ aicwf_vif->up = true;
+ aicwf_hw->vif_started++;
+ aicwf_hw->vif_table[add_if_cfm.inst_nbr] = aicwf_vif;
+ dev_dbg(&dev->dev, "sta create vif in aicwf_hw->vif_table[%d]\n", aicwf_vif->vif_index);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+
+#ifdef CONFIG_AIC8800_USE_P2P0
+ if (aicwf_vif->is_p2p_vif) {
+ aicwf_hw->p2p_dev_vif = aicwf_vif;
+ aicwf_hw->is_p2p_alive = 1;
+ }
+#endif
+ }
+
+ if (AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_MONITOR) {
+ aicwf_hw->monitor_vif = aicwf_vif->vif_index;
+ if (aicwf_vif->ch_index != AICWF_CH_NOT_SET) {
+ // Configure the monitor channel
+ error = aicwf_send_config_monitor_req
+ (aicwf_hw,
+ &aicwf_hw->chanctx_table[aicwf_vif->ch_index].chan_def,
+ NULL);
+ }
+ }
+
+ netif_start_queue(dev);
+
+ return error;
+}
+
+bool aicwf_scan_complete(struct aicwf_hw *aicwf_hw, struct wireless_dev *wdev,
+ bool aborted)
+{
+ struct cfg80211_scan_info info = { .aborted = aborted };
+ struct cfg80211_scan_request *request;
+
+ spin_lock_bh(&aicwf_hw->scan_lock);
+ request = aicwf_hw->scan_request;
+ if (!request || (wdev && request->wdev != wdev)) {
+ spin_unlock_bh(&aicwf_hw->scan_lock);
+ return false;
+ }
+
+ aicwf_hw->scan_request = NULL;
+ WRITE_ONCE(aicwf_hw->scanning, 0);
+ /* Serialize notification with ndo_stop and release PM before a new scan. */
+#ifdef CONFIG_AIC8800_SCHED_SCAN
+ if (aicwf_hw->is_sched_scan) {
+ if (!aborted)
+ cfg80211_sched_scan_results(aicwf_hw->wiphy,
+ aicwf_hw->sched_scan_req->reqid);
+ kfree(request);
+ aicwf_hw->is_sched_scan = false;
+ } else {
+#endif
+ cfg80211_scan_done(request, &info);
+#ifdef CONFIG_AIC8800_SCHED_SCAN
+ }
+#endif
+ aicwf_sdio_scan_activity_put(aicwf_hw);
+ spin_unlock_bh(&aicwf_hw->scan_lock);
+
+ return true;
+}
+
+static bool aicwf_scan_pending(struct aicwf_hw *aicwf_hw,
+ struct wireless_dev *wdev)
+{
+ bool pending;
+
+ spin_lock_bh(&aicwf_hw->scan_lock);
+ pending = aicwf_hw->scan_request &&
+ aicwf_hw->scan_request->wdev == wdev;
+ spin_unlock_bh(&aicwf_hw->scan_lock);
+
+ return pending;
+}
+
+/*
+ * int (*ndo_stop)(struct net_device *dev);
+ * This function is called when network device transistions to the down
+ * state.
+ *
+ * - Remove interface at fw level
+ * - Reset FW if this is the last interface opened
+ */
+static int aicwf_close(struct net_device *dev)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+ int ret;
+ struct aicwf_bus *bus_if = NULL;
+ struct aic_sdio_dev *sdiodev = NULL;
+ int waiting_counter = 20;
+ int test_counter = 0;
+
+ test_counter = waiting_counter;
+ while (atomic_read(&aicwf_vif->drv_conn_state) == (int)AICWF_DRV_STATUS_DISCONNECTING ||
+ atomic_read(&aicwf_vif->drv_conn_state) == (int)AICWF_DRV_STATUS_CONNECTING) {
+ dev_dbg(&dev->dev, "wifi is connecting or disconnecting, waiting 200ms for state to stable\n");
+ msleep(200);
+ test_counter--;
+ if (test_counter == 0) {
+ dev_err(aicwf_hw->dev, "connecting or disconnecting, not finish\n");
+ //WARN_ON(1);
+ break;
+ }
+ }
+
+ netdev_info(dev, "close\n");
+
+ aicwf_radar_cancel_cac(&aicwf_hw->radar);
+
+ /* Abort scan request on the vif */
+ if (aicwf_scan_complete(aicwf_hw, &aicwf_vif->wdev, true)) {
+ ret = aicwf_send_scanu_cancel_req(aicwf_hw, NULL);
+ mdelay(35); // make sure firmware take affect
+ if (ret)
+ netdev_warn(dev, "scan cancel failed during close: %d\n", ret);
+ }
+
+ if (aicwf_hw->roc_elem && aicwf_hw->roc_elem->wdev == &aicwf_vif->wdev) {
+ dev_dbg(&dev->dev, "clear roc\n");
+ /* Initialize RoC element pointer to NULL, indicate that RoC can be
+ * started
+ */
+ kfree(aicwf_hw->roc_elem);
+ aicwf_hw->roc_elem = NULL;
+ }
+
+ aicwf_vif->up = false;
+ dev_dbg(&dev->dev, "aicwf_vif[%d] down\n",
+ aicwf_vif->vif_index);
+
+ if (netif_carrier_ok(dev)) {
+ if (AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_STATION ||
+ AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_P2P_CLIENT) {
+ cfg80211_disconnected(dev, WLAN_REASON_DEAUTH_LEAVING, NULL, 0,
+ true, GFP_ATOMIC);
+ netif_tx_stop_all_queues(dev);
+ netif_carrier_off(dev);
+ usleep_range(1000, 2000);
+ } else if (AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_AP_VLAN) {
+ netif_carrier_off(dev);
+ } else {
+ netdev_warn(dev, "ap not stopped when disabling interface\n");
+ }
+ }
+
+ bus_if = dev_get_drvdata(aicwf_hw->dev);
+ if (bus_if)
+ sdiodev = bus_if->sdiodev;
+ if (sdiodev && sdiodev->bus_if->state != BUS_DOWN_ST) {
+ if (AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_STATION ||
+ AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_P2P_CLIENT) {
+ test_counter = waiting_counter;
+ if (atomic_read(&aicwf_vif->drv_conn_state) ==
+ (int)AICWF_DRV_STATUS_CONNECTED) {
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state,
+ AICWF_DRV_STATUS_DISCONNECTING);
+ aicwf_send_sm_disconnect_req(aicwf_hw, aicwf_vif, 3);
+ while (atomic_read(&aicwf_vif->drv_conn_state) ==
+ (int)AICWF_DRV_STATUS_DISCONNECTING) {
+ dev_dbg(&dev->dev, "wifi is disconnecting, waiting 100ms for state to stable\n");
+ msleep(100);
+ test_counter--;
+ if (test_counter == 0)
+ break;
+ }
+ }
+ }
+#ifdef CONFIG_AIC8800_USE_P2P0
+ if (!aicwf_vif->is_p2p_vif ||
+ (aicwf_vif->is_p2p_vif && aicwf_hw->is_p2p_alive)) {
+ if (aicwf_vif->is_p2p_vif)
+ aicwf_hw->is_p2p_alive = 0;
+#endif
+ aicwf_send_remove_if(aicwf_hw, aicwf_vif->vif_index, false);
+#ifdef CONFIG_AIC8800_USE_P2P0
+ }
+#endif
+ }
+ /* Ensure that we won't process disconnect ind */
+ spin_lock_bh(&aicwf_hw->cb_lock);
+
+ aicwf_hw->vif_table[aicwf_vif->vif_index] = NULL;
+
+ aicwf_chanctx_unlink(aicwf_vif);
+
+ if (AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_MONITOR)
+ aicwf_hw->monitor_vif = AICWF_INVALID_VIF;
+
+ aicwf_hw->vif_started--;
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+
+ if (aicwf_hw->vif_started == 0) {
+ /* This also lets both ipc sides remain in sync before resetting */
+ if (sdiodev->bus_if->state != BUS_DOWN_ST) {
+ ret = aicwf_send_reset(aicwf_hw);
+ if (!ret && aicwf_hw->testmode == 0)
+ ret = aicwf_send_me_config_req(aicwf_hw);
+ if (!ret && !READ_ONCE(aicwf_hw->regdom_failed))
+ ret = aicwf_send_me_chan_config_req(aicwf_hw);
+ if (ret) {
+ WRITE_ONCE(aicwf_hw->regdom_failed, true);
+ wiphy_err(aicwf_hw->wiphy,
+ "Failed to restore firmware configuration: %d\n",
+ ret);
+ }
+ }
+ }
+
+ clear_bit(AICWF_DEV_STARTED, &aicwf_vif->drv_flags);
+ dev_dbg(&dev->dev, "aicwf_vif->drv_flags:%d\n",
+ (int)aicwf_vif->drv_flags);
+
+ return 0;
+}
+
+/*
+ * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
+ * Called when a user wants to get the network device usage
+ * statistics. Drivers must do one of the following:
+ * 1. Define @ndo_get_stats64 to fill in a zero-initialised
+ * rtnl_link_stats64 structure passed by the caller.
+ * 2. Define @ndo_get_stats to update a net_device_stats structure
+ * (which should normally be dev->stats) and return a pointer to
+ * it. The structure may be changed asynchronously only if each
+ * field is written atomically.
+ * 3. Update dev->stats asynchronously and atomically, and define
+ * neither operation.
+ */
+static struct net_device_stats *aicwf_get_stats(struct net_device *dev)
+{
+ struct aicwf_vif *vif = netdev_priv(dev);
+
+ return &vif->net_stats;
+}
+
+/*
+ * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb,
+ * struct net_device *sb_dev);
+ * Called to decide which queue to when device supports multiple
+ * transmit queues.
+ */
+
+#ifndef CONFIG_AIC8800_ONE_TXQ
+static u16 aicwf_select_queue(struct net_device *dev,
+ struct sk_buff *skb,
+ struct net_device *sb_dev)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+
+ return aicwf_select_txq(aicwf_vif, skb);
+}
+#endif
+
+/*
+ * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
+ * This function is called when the Media Access Control address
+ * needs to be changed. If this interface is not defined, the
+ * mac address can not be changed.
+ */
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY) || defined(CONFIG_AIC8800_SUPPORT_REALTIME_CHANGE_MAC)
+static int aicwf_set_mac_address(struct net_device *dev, void *addr)
+{
+ struct sockaddr *sa = addr;
+ int ret = 0;
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+
+ dev_dbg(&dev->dev, "enter\n");
+
+ ret = eth_mac_addr(dev, sa);
+ dev_dbg(&dev->dev, "set %02X:%02X:%02X:%02X:%02X:%02X\n",
+ dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
+ dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
+ memcpy(aicwf_vif->wdev.address, dev->dev_addr, 6);
+
+ return ret;
+}
+#endif
+
+static const struct net_device_ops aicwf_netdev_ops = {
+ .ndo_open = aicwf_open,
+ .ndo_stop = aicwf_close,
+ .ndo_start_xmit = aicwf_start_xmit,
+ .ndo_get_stats = aicwf_get_stats,
+#ifndef CONFIG_AIC8800_ONE_TXQ
+ .ndo_select_queue = aicwf_select_queue,
+#endif
+#ifdef CONFIG_AIC8800_SUPPORT_REALTIME_CHANGE_MAC
+ .ndo_set_mac_address = aicwf_set_mac_address
+#endif
+ /* unused interface */
+ // .ndo_set_features = aicwf_set_features,
+ // .ndo_set_rx_mode != aicwf_set_multicast_list,
+};
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+static const struct net_device_ops aicwf_netdev_monitor_ops = {
+ .ndo_open = aicwf_open,
+ .ndo_stop = aicwf_close,
+ .ndo_get_stats = aicwf_get_stats,
+ .ndo_set_mac_address = aicwf_set_mac_address,
+};
+#endif
+
+static void aicwf_netdev_setup(struct net_device *dev)
+{
+ ether_setup(dev);
+ dev->priv_flags &= ~IFF_TX_SKB_SHARING;
+ dev->netdev_ops = &aicwf_netdev_ops;
+ dev->needs_free_netdev = true;
+ dev->watchdog_timeo = AICWF_TX_LIFETIME_MS;
+
+ dev->needed_headroom = sizeof(struct aicwf_txhdr) + AICWF_SWTXHDR_ALIGN_SZ;
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ dev->needed_headroom =
+ max(dev->needed_headroom,
+ (unsigned short)(sizeof(struct aicwf_amsdu_txhdr) +
+ sizeof(struct ethhdr) + 4 +
+ sizeof(rfc1042_header) + 2));
+#endif /* CONFIG_AICWF_AMSDUS_TX */
+
+ dev->hw_features = 0;
+}
+
+/*********************************************************************
+ * Cfg80211 callbacks (and helper)
+ *********************************************************************/
+static struct aicwf_vif *aicwf_interface_add(struct aicwf_hw *aicwf_hw,
+ const char *name,
+ unsigned char name_assign_type,
+ enum nl80211_iftype type,
+ struct vif_params *params)
+{
+ struct net_device *ndev;
+ struct aicwf_vif *vif;
+ int min_idx, max_idx;
+ int vif_idx = -1;
+ int i;
+
+ if (IS_ENABLED(CONFIG_AIC8800_STA_ONLY) &&
+ type != NL80211_IFTYPE_STATION)
+ return NULL;
+
+#ifndef CONFIG_AIC8800_ONE_TXQ
+ int nx_nb_ndev_txq = NX_NB_NDEV_TXQ;
+
+ if (aicwf_hw->chip_ops->is_old_ic)
+ nx_nb_ndev_txq = NX_NB_NDEV_TXQ_FOR_OLD_IC;
+#endif
+
+ dev_dbg(aicwf_hw->dev, "%s, %d\n", name, type);
+ // Look for an available VIF
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ if (type == NL80211_IFTYPE_AP_VLAN) {
+ min_idx = NX_VIRT_DEV_MAX;
+ max_idx = NX_VIRT_DEV_MAX + NX_REMOTE_STA_MAX;
+ } else {
+#endif
+ min_idx = 0;
+ max_idx = NX_VIRT_DEV_MAX;
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ }
+#endif
+
+ for (i = min_idx; i < max_idx; i++) {
+ if (aicwf_hw->avail_idx_map & BIT(i)) {
+ vif_idx = i;
+ break;
+ }
+ }
+ if (vif_idx < 0)
+ return NULL;
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY) && !defined(CONFIG_AICWF_MON_DATA)
+ list_for_each_entry(vif, &aicwf_hw->vifs, list) {
+ // Check if monitor interface already exists or type is monitor
+ if (AICWF_VIF_TYPE(vif) == NL80211_IFTYPE_MONITOR ||
+ type == NL80211_IFTYPE_MONITOR) {
+ wiphy_err(aicwf_hw->wiphy,
+ "Monitor+Data interface support (MON_DATA) disabled\n");
+ return NULL;
+ }
+ }
+#endif
+
+#ifndef CONFIG_AIC8800_ONE_TXQ
+ ndev = alloc_netdev_mqs(sizeof(*vif), name, name_assign_type,
+ aicwf_netdev_setup, nx_nb_ndev_txq, 1);
+#else
+ ndev = alloc_netdev_mqs(sizeof(*vif), name, name_assign_type,
+ aicwf_netdev_setup, 1, 1);
+#endif
+
+ if (!ndev)
+ return NULL;
+
+ vif = netdev_priv(ndev);
+ vif->key_has_add = 0;
+ ndev->ieee80211_ptr = &vif->wdev;
+ vif->wdev.wiphy = aicwf_hw->wiphy;
+ vif->aicwf_hw = aicwf_hw;
+ vif->ndev = ndev;
+ vif->drv_vif_index = vif_idx;
+ SET_NETDEV_DEV(ndev, wiphy_dev(vif->wdev.wiphy));
+ vif->wdev.netdev = ndev;
+ vif->wdev.iftype = type;
+ vif->up = false;
+ vif->ch_index = AICWF_CH_NOT_SET;
+ memset(&vif->net_stats, 0, sizeof(vif->net_stats));
+ vif->is_p2p_vif = 0;
+
+ switch (type) {
+ case NL80211_IFTYPE_STATION:
+ vif->sta.ap = NULL;
+ vif->sta.tdls_sta = NULL;
+ vif->sta.external_auth = false;
+ break;
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ case NL80211_IFTYPE_P2P_CLIENT:
+ vif->sta.ap = NULL;
+ vif->sta.tdls_sta = NULL;
+ vif->sta.external_auth = false;
+ vif->is_p2p_vif = 1;
+ break;
+ case NL80211_IFTYPE_MESH_POINT:
+ INIT_LIST_HEAD(&vif->ap.mpath_list);
+ INIT_LIST_HEAD(&vif->ap.proxy_list);
+ vif->ap.create_path = false;
+ vif->ap.generation = 0;
+ vif->ap.mesh_pm = NL80211_MESH_POWER_ACTIVE;
+ vif->ap.next_mesh_pm = NL80211_MESH_POWER_ACTIVE;
+ fallthrough;
+ // no break
+ case NL80211_IFTYPE_AP:
+ INIT_LIST_HEAD(&vif->ap.sta_list);
+ memset(&vif->ap.bcn, 0, sizeof(vif->ap.bcn));
+ break;
+ case NL80211_IFTYPE_P2P_GO:
+ INIT_LIST_HEAD(&vif->ap.sta_list);
+ memset(&vif->ap.bcn, 0, sizeof(vif->ap.bcn));
+ vif->is_p2p_vif = 1;
+ break;
+ case NL80211_IFTYPE_AP_VLAN: {
+ struct aicwf_vif *master_vif;
+ bool found = false;
+
+ list_for_each_entry(master_vif, &aicwf_hw->vifs, list) {
+ if (AICWF_VIF_TYPE(master_vif) == NL80211_IFTYPE_AP &&
+ !(!memcmp(master_vif->ndev->dev_addr, params->macaddr,
+ ETH_ALEN))) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ goto err;
+
+ vif->ap_vlan.master = master_vif;
+ vif->ap_vlan.sta_4a = NULL;
+ break;
+ }
+ case NL80211_IFTYPE_MONITOR:
+ ndev->type = ARPHRD_IEEE80211_RADIOTAP;
+ ndev->netdev_ops = &aicwf_netdev_monitor_ops;
+ break;
+#endif
+ default:
+ break;
+ }
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ if (type == NL80211_IFTYPE_AP_VLAN) {
+ memcpy((void *)ndev->dev_addr, (const void *)params->macaddr, ETH_ALEN);
+ memcpy((void *)vif->wdev.address, (const void *)params->macaddr,
+ ETH_ALEN);
+ } else {
+#endif
+ unsigned char mac_addr[6];
+
+ memcpy(mac_addr, aicwf_hw->wiphy->perm_addr, ETH_ALEN);
+ mac_addr[5] ^= vif_idx;
+ eth_hw_addr_set(ndev, mac_addr);
+ memcpy(vif->wdev.address, mac_addr, ETH_ALEN);
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ }
+#endif
+
+ dev_dbg(aicwf_hw->dev, "interface add:%x %x %x %x %x %x\n", vif->wdev.address[0],
+ vif->wdev.address[1], vif->wdev.address[2], vif->wdev.address[3],
+ vif->wdev.address[4], vif->wdev.address[5]);
+
+ if (params) {
+ vif->use_4addr = params->use_4addr;
+ ndev->ieee80211_ptr->use_4addr = params->use_4addr;
+ } else {
+ vif->use_4addr = false;
+ }
+ if (cfg80211_register_netdevice(ndev))
+ goto err;
+
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ list_add_tail(&vif->list, &aicwf_hw->vifs);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ aicwf_hw->avail_idx_map &= ~BIT(vif_idx);
+
+ return vif;
+
+err:
+ free_netdev(ndev);
+ return NULL;
+}
+
+void aicwf_p2p_alive_timeout(struct timer_list *t)
+{
+ struct aicwf_hw *aicwf_hw;
+ struct aicwf_vif *aicwf_vif;
+ struct aicwf_vif *aicwf_vif1, *tmp;
+ u8 p2p = 0;
+
+ //aicwf_hw = from_timer(aicwf_hw, t, p2p_alive_timer);
+ aicwf_hw = timer_container_of(aicwf_hw, t, p2p_alive_timer);
+ aicwf_vif = aicwf_hw->p2p_dev_vif;
+
+ list_for_each_entry_safe(aicwf_vif1, tmp, &aicwf_hw->vifs, list) {
+ if ((aicwf_hw->avail_idx_map & BIT(aicwf_vif1->drv_vif_index)) == 0) {
+ switch (AICWF_VIF_TYPE(aicwf_vif1)) {
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ case NL80211_IFTYPE_P2P_CLIENT:
+ case NL80211_IFTYPE_P2P_GO:
+ aicwf_hw->is_p2p_alive = 1;
+ p2p = 1;
+ break;
+#endif
+ default:
+ break;
+ }
+ }
+ }
+
+ if (p2p)
+ atomic_set(&aicwf_hw->p2p_alive_timer_count, 0);
+ else
+ atomic_inc(&aicwf_hw->p2p_alive_timer_count);
+
+ if (atomic_read(&aicwf_hw->p2p_alive_timer_count) < P2P_ALIVE_TIME_COUNT) {
+ mod_timer(&aicwf_hw->p2p_alive_timer,
+ jiffies + msecs_to_jiffies(P2P_ALIVE_TIME_MS));
+ return;
+ }
+ atomic_set(&aicwf_hw->p2p_alive_timer_count, 0);
+
+ aicwf_hw->is_p2p_alive = 0;
+ if (aicwf_vif->up) {
+ aicwf_send_remove_if(aicwf_hw, aicwf_vif->vif_index, true);
+
+ /* Ensure that we won't process disconnect ind */
+ spin_lock_bh(&aicwf_hw->cb_lock);
+
+ aicwf_vif->up = false;
+ aicwf_hw->vif_table[aicwf_vif->vif_index] = NULL;
+ pr_debug("aicwf_vif[%d] down\n",
+ aicwf_vif->vif_index);
+ aicwf_hw->vif_started--;
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ }
+}
+
+/*********************************************************************
+ * Cfg80211 callbacks (and helper)
+ *********************************************************************/
+static struct wireless_dev *
+aicwf_virtual_interface_add(struct aicwf_hw *aicwf_hw, const char *name,
+ unsigned char name_assign_type,
+ enum nl80211_iftype type, struct vif_params *params)
+{
+ struct wireless_dev *wdev = NULL;
+ struct aicwf_vif *vif;
+ int min_idx, max_idx;
+ int vif_idx = -1;
+ int i;
+
+ pr_debug("%d, %s\n", type, name);
+
+ if (type == NL80211_IFTYPE_AP_VLAN) {
+ min_idx = NX_VIRT_DEV_MAX;
+ max_idx = NX_VIRT_DEV_MAX + NX_REMOTE_STA_MAX;
+ } else {
+ min_idx = 0;
+ max_idx = NX_VIRT_DEV_MAX;
+ }
+
+ for (i = min_idx; i < max_idx; i++) {
+ if (aicwf_hw->avail_idx_map & BIT(i)) {
+ vif_idx = i;
+ break;
+ }
+ }
+
+ if (vif_idx < 0) {
+ pr_debug("virtual_interface_add %s fail\n", name);
+ return NULL;
+ }
+
+ vif = kzalloc_obj(*vif, GFP_KERNEL);
+ if (unlikely(!vif)) {
+ pr_debug("could not allocate wireless device\n");
+ return NULL;
+ }
+ wdev = &vif->wdev;
+ wdev->wiphy = aicwf_hw->wiphy;
+ wdev->iftype = type;
+
+ pr_debug("ifname=%s, wdev=%p, vif_idx=%d\n", name,
+ wdev, vif_idx);
+
+#ifndef CONFIG_AIC8800_USE_P2P0
+ vif->is_p2p_vif = 1;
+ vif->aicwf_hw = aicwf_hw;
+ vif->vif_index = vif_idx;
+ vif->wdev.wiphy = aicwf_hw->wiphy;
+ vif->drv_vif_index = vif_idx;
+ vif->up = false;
+ vif->ch_index = AICWF_CH_NOT_SET;
+ memset(&vif->net_stats, 0, sizeof(vif->net_stats));
+ vif->use_4addr = false;
+
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ list_add_tail(&vif->list, &aicwf_hw->vifs);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+
+ if (aicwf_hw->is_p2p_alive == 0) {
+ aicwf_hw->is_p2p_alive = 0;
+ aicwf_hw->is_p2p_connected = 0;
+ aicwf_hw->p2p_dev_vif = vif;
+ atomic_set(&aicwf_hw->p2p_alive_timer_count, 0);
+ }
+#endif
+ aicwf_hw->avail_idx_map &= ~BIT(vif_idx);
+
+ memcpy(vif->wdev.address, aicwf_hw->wiphy->perm_addr, ETH_ALEN);
+ vif->wdev.address[5] ^= vif_idx;
+ pr_debug("p2p dev addr=%x %x %x %x %x %x\n", vif->wdev.address[0],
+ vif->wdev.address[1], vif->wdev.address[2], vif->wdev.address[3],
+ vif->wdev.address[4], vif->wdev.address[5]);
+
+ return wdev;
+}
+
+/*
+ * @brief Retrieve the aicwf_sta object allocated for a given MAC address
+ * and a given role.
+ */
+static struct aicwf_sta *aicwf_retrieve_sta(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif, u8 *addr,
+ __le16 fc, bool ap)
+{
+ if (ap) {
+ /* only deauth, disassoc and action are bufferable MMPDUs */
+ bool bufferable = ieee80211_is_deauth(fc) ||
+ ieee80211_is_disassoc(fc) ||
+ ieee80211_is_action(fc);
+
+ /* Check if the packet is bufferable or not */
+ if (bufferable) {
+ /* Check if address is a broadcast or a multicast address */
+ if (is_broadcast_ether_addr(addr) ||
+ is_multicast_ether_addr(addr)) {
+ /* Returned STA pointer */
+ struct aicwf_sta *aicwf_sta =
+ &aicwf_hw->sta_table[aicwf_vif->ap.bcmc_index];
+
+ if (aicwf_sta->valid)
+ return aicwf_sta;
+ } else {
+ /* Returned STA pointer */
+ struct aicwf_sta *aicwf_sta;
+
+ /* Go through list of STAs linked with the provided VIF */
+ spin_lock_bh(&aicwf_vif->aicwf_hw->cb_lock);
+ list_for_each_entry(aicwf_sta, &aicwf_vif->ap.sta_list, list) {
+ if (aicwf_sta->valid &&
+ ether_addr_equal(aicwf_sta->mac_addr, addr)) {
+ /* Return the found STA */
+ spin_unlock_bh(&aicwf_vif->aicwf_hw->cb_lock);
+ return aicwf_sta;
+ }
+ }
+ spin_unlock_bh(&aicwf_vif->aicwf_hw->cb_lock);
+ }
+ }
+ } else {
+ return aicwf_vif->sta.ap;
+ }
+
+ return NULL;
+}
+
+/*
+ * @add_virtual_intf: create a new virtual interface with the given name,
+ * must set the struct wireless_dev's iftype. Beware: You must create
+ * the new netdev in the wiphy's network namespace! Returns the struct
+ * wireless_dev, or an ERR_PTR. For P2P device wdevs, the driver must
+ * also set the address member in the wdev.
+ */
+static struct wireless_dev *
+aicwf_cfg80211_add_iface(struct wiphy *wiphy, const char *name,
+ unsigned char name_assign_type,
+ enum nl80211_iftype type, struct vif_params *params)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct wireless_dev *wdev;
+
+ if (IS_ENABLED(CONFIG_AIC8800_STA_ONLY) &&
+ type != NL80211_IFTYPE_STATION)
+ return ERR_PTR(-EOPNOTSUPP);
+
+ if (type != NL80211_IFTYPE_P2P_DEVICE) {
+ struct aicwf_vif *vif =
+ aicwf_interface_add(aicwf_hw, name, name_assign_type, type, params);
+ if (!vif)
+ return ERR_PTR(-EINVAL);
+ return &vif->wdev;
+ }
+ wdev = aicwf_virtual_interface_add(aicwf_hw, name, name_assign_type, type,
+ params);
+ if (!wdev)
+ return ERR_PTR(-EINVAL);
+ return wdev;
+}
+
+/*
+ * @del_virtual_intf: remove the virtual interface
+ */
+static int aicwf_cfg80211_del_iface(struct wiphy *wiphy,
+ struct wireless_dev *wdev)
+{
+ struct net_device *dev = wdev->netdev;
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = container_of(wdev, struct aicwf_vif, wdev);
+
+ dev_dbg(&wiphy->dev, "del_iface: %p, %x\n", wdev, wdev->address[5]);
+
+ if (!dev || !aicwf_vif->ndev) {
+ cfg80211_unregister_wdev(wdev);
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ list_del(&aicwf_vif->list);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ aicwf_hw->avail_idx_map |= BIT(aicwf_vif->drv_vif_index);
+ aicwf_vif->ndev = NULL;
+ kfree(aicwf_vif);
+ return 0;
+ }
+
+ netdev_info(dev, "remove interface\n");
+
+ if (dev->reg_state == NETREG_REGISTERED) {
+ /* Will call aicwf_close if interface is UP */
+ cfg80211_unregister_netdevice(dev);
+ }
+
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ list_del(&aicwf_vif->list);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ aicwf_hw->avail_idx_map |= BIT(aicwf_vif->drv_vif_index);
+ aicwf_vif->ndev = NULL;
+
+ /* Clear the priv in adapter */
+ dev->ieee80211_ptr = NULL;
+
+ return 0;
+}
+
+/*
+ * @change_virtual_intf: change type/configuration of virtual interface,
+ * keep the struct wireless_dev's iftype updated.
+ */
+static int aicwf_cfg80211_change_iface(struct wiphy *wiphy,
+ struct net_device *dev,
+ enum nl80211_iftype type,
+ struct vif_params *params)
+{
+#ifndef CONFIG_AICWF_MON_DATA
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+#endif
+ struct aicwf_vif *vif = netdev_priv(dev);
+ struct mm_add_if_cfm add_if_cfm;
+ bool p2p = false;
+ int ret;
+
+ dev_dbg(&wiphy->dev, "change_if: %d to %d, %d, %d", vif->wdev.iftype, type,
+ NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_STATION);
+
+ if (IS_ENABLED(CONFIG_AIC8800_STA_ONLY) &&
+ type != NL80211_IFTYPE_STATION)
+ return -EOPNOTSUPP;
+
+#ifndef CONFIG_AICWF_MON_DATA
+ if (type == NL80211_IFTYPE_MONITOR &&
+ AICWF_VIF_TYPE(vif) != NL80211_IFTYPE_MONITOR) {
+ struct aicwf_vif *vif_el;
+
+ list_for_each_entry(vif_el, &aicwf_hw->vifs, list) {
+ // Check if data interface already exists
+ if (vif_el != vif &&
+ AICWF_VIF_TYPE(vif) != NL80211_IFTYPE_MONITOR) {
+ wiphy_err(aicwf_hw->wiphy,
+ "Monitor+Data interface support (MON_DATA) disabled\n");
+ return -EIO;
+ }
+ }
+ }
+#endif
+
+ // Reset to default case (i.e. not monitor)
+ dev->type = ARPHRD_ETHER;
+ dev->netdev_ops = &aicwf_netdev_ops;
+
+ switch (type) {
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ case NL80211_IFTYPE_P2P_CLIENT:
+#endif
+ case NL80211_IFTYPE_STATION:
+ vif->sta.ap = NULL;
+ vif->sta.tdls_sta = NULL;
+ vif->sta.external_auth = false;
+ break;
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ case NL80211_IFTYPE_MESH_POINT:
+ INIT_LIST_HEAD(&vif->ap.mpath_list);
+ INIT_LIST_HEAD(&vif->ap.proxy_list);
+ vif->ap.create_path = false;
+ vif->ap.generation = 0;
+ fallthrough;
+ // no break
+ case NL80211_IFTYPE_AP:
+ case NL80211_IFTYPE_P2P_GO:
+ INIT_LIST_HEAD(&vif->ap.sta_list);
+ memset(&vif->ap.bcn, 0, sizeof(vif->ap.bcn));
+ break;
+ case NL80211_IFTYPE_AP_VLAN:
+ return -EPERM;
+ case NL80211_IFTYPE_MONITOR:
+ dev->type = ARPHRD_IEEE80211_RADIOTAP;
+ dev->netdev_ops = &aicwf_netdev_monitor_ops;
+ break;
+#endif
+ default:
+ break;
+ }
+
+ vif->wdev.iftype = type;
+ if (params->use_4addr != -1)
+ vif->use_4addr = params->use_4addr;
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ if (type == NL80211_IFTYPE_P2P_CLIENT || type == NL80211_IFTYPE_P2P_GO)
+ p2p = true;
+#endif
+
+ if (vif->up) {
+ /* Abort scan request on the vif */
+ if (aicwf_scan_pending(vif->aicwf_hw, &vif->wdev)) {
+ ret = aicwf_send_scanu_cancel_req(vif->aicwf_hw, NULL);
+ if (ret) {
+ dev_err(&wiphy->dev, "scanu_cancel fail\n");
+ return ret;
+ }
+ }
+ ret = aicwf_send_remove_if(vif->aicwf_hw, vif->vif_index, false);
+ if (ret) {
+ dev_dbg(&wiphy->dev, "remove_if fail\n");
+ return ret;
+ }
+ vif->aicwf_hw->vif_table[vif->vif_index] = NULL;
+ dev_dbg(&wiphy->dev, "change_if from %d\n", vif->vif_index);
+ ret = aicwf_send_add_if(vif->aicwf_hw, vif->wdev.address,
+ AICWF_VIF_TYPE(vif), p2p, &add_if_cfm);
+ if (ret) {
+ dev_dbg(&wiphy->dev, "add if fail\n");
+ return ret;
+ }
+ if (add_if_cfm.status != 0) {
+ dev_dbg(&wiphy->dev, "add if status fail\n");
+ return -EIO;
+ }
+
+ dev_dbg(&wiphy->dev, "change_if to %d\n", add_if_cfm.inst_nbr);
+ /* Save the index retrieved from LMAC */
+ spin_lock_bh(&vif->aicwf_hw->cb_lock);
+ vif->vif_index = add_if_cfm.inst_nbr;
+ vif->aicwf_hw->vif_table[add_if_cfm.inst_nbr] = vif;
+ spin_unlock_bh(&vif->aicwf_hw->cb_lock);
+ }
+
+ return 0;
+}
+
+static int __maybe_unused aicwf_cfgp2p_start_p2p_device(struct wiphy *wiphy,
+ struct wireless_dev *wdev)
+{
+ int ret = 0;
+
+ // do nothing
+ dev_dbg(&wiphy->dev, "p2P interface started\n");
+
+ return ret;
+}
+
+static void __maybe_unused aicwf_cfgp2p_stop_p2p_device(struct wiphy *wiphy,
+ struct wireless_dev *wdev)
+{
+ int ret = 0;
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = container_of(wdev, struct aicwf_vif, wdev);
+ /* Abort scan request on the vif */
+ if (aicwf_scan_complete(aicwf_hw, &aicwf_vif->wdev, true)) {
+ ret = aicwf_send_scanu_cancel_req(aicwf_hw, NULL);
+ if (ret)
+ dev_dbg(&wiphy->dev, "scanu_cancel fail\n");
+ }
+
+ if (aicwf_vif == aicwf_hw->p2p_dev_vif) {
+ aicwf_hw->is_p2p_alive = 0;
+ if (timer_pending(&aicwf_hw->p2p_alive_timer))
+ //del_timer_sync(&aicwf_hw->p2p_alive_timer);
+ timer_delete_sync(&aicwf_hw->p2p_alive_timer);
+
+ if (aicwf_vif->up) {
+ aicwf_send_remove_if(aicwf_hw, aicwf_vif->vif_index, true);
+ /* Ensure that we won't process disconnect ind */
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_vif->up = false;
+ aicwf_hw->vif_table[aicwf_vif->vif_index] = NULL;
+ dev_dbg(&wiphy->dev, "aicwf_vif[%d] down\n",
+ aicwf_vif->vif_index);
+ aicwf_hw->vif_started--;
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ }
+ }
+ dev_dbg(&wiphy->dev, "exit. P2P interface stopped\n");
+}
+
+/*
+ * @scan: 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.
+ */
+static int aicwf_scan(struct wiphy *wiphy,
+ struct cfg80211_scan_request *request, bool sched_scan)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif =
+ container_of(request->wdev, struct aicwf_vif, wdev);
+ int error;
+
+ if (aicwf_hw->testmode)
+ return -EBUSY;
+
+ if ((int)atomic_read(&aicwf_vif->drv_conn_state) == (int)AICWF_DRV_STATUS_CONNECTING) {
+ dev_err(&wiphy->dev, "wifi is connecting, return it\n");
+ return -EBUSY;
+ }
+
+ if ((AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_STATION ||
+ AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_P2P_CLIENT) &&
+ aicwf_vif->sta.external_auth) {
+ dev_err(&wiphy->dev, "scan about: external auth\n");
+ return -EBUSY;
+ }
+
+ spin_lock_bh(&aicwf_hw->scan_lock);
+ if (aicwf_hw->scan_request || !aicwf_sdio_scan_activity_get(aicwf_hw)) {
+ spin_unlock_bh(&aicwf_hw->scan_lock);
+ return -EBUSY;
+ }
+
+ aicwf_hw->scan_request = request;
+ WRITE_ONCE(aicwf_hw->scanning, 1);
+#ifdef CONFIG_AIC8800_SCHED_SCAN
+ aicwf_hw->is_sched_scan = sched_scan;
+#endif
+ spin_unlock_bh(&aicwf_hw->scan_lock);
+
+ error = aicwf_send_scanu_req(aicwf_hw, aicwf_vif, request);
+ if (error) {
+ spin_lock_bh(&aicwf_hw->scan_lock);
+ if (aicwf_hw->scan_request == request) {
+ aicwf_hw->scan_request = NULL;
+ WRITE_ONCE(aicwf_hw->scanning, 0);
+#ifdef CONFIG_AIC8800_SCHED_SCAN
+ aicwf_hw->is_sched_scan = false;
+#endif
+ aicwf_sdio_scan_activity_put(aicwf_hw);
+ } else {
+ /* A completion already accepted this request; do not reject it. */
+ error = 0;
+ }
+ spin_unlock_bh(&aicwf_hw->scan_lock);
+ return error;
+ }
+
+ return 0;
+}
+
+static int aicwf_cfg80211_scan(struct wiphy *wiphy,
+ struct cfg80211_scan_request *request)
+{
+ return aicwf_scan(wiphy, request, false);
+}
+
+/*
+ * @add_key: add a key with the given parameters. @mac_addr will be %NULL
+ * when adding a group key.
+ */
+static int aicwf_cfg80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev,
+ int link_id,
+ u8 key_index, enum nl80211_key_type key_type,
+ const u8 *mac_addr, struct key_params *params)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct net_device *netdev = wdev->netdev;
+ struct aicwf_vif *vif = netdev_priv(netdev);
+ int i, error = 0;
+ struct mm_key_add_cfm key_add_cfm;
+ u8 cipher = 0;
+ struct aicwf_sta *sta = NULL;
+ struct aicwf_key *aicwf_key;
+
+ if (key_type != NL80211_KEYTYPE_GROUP &&
+ key_type != NL80211_KEYTYPE_PAIRWISE)
+ return -EOPNOTSUPP;
+
+ if (mac_addr) {
+ sta = aicwf_get_sta(aicwf_hw, mac_addr);
+ if (!sta)
+ return -EINVAL;
+ aicwf_key = &sta->key;
+ if (vif->wdev.iftype == NL80211_IFTYPE_STATION ||
+ vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)
+ vif->sta.paired_cipher_type = params->cipher;
+ } else {
+ aicwf_key = &vif->key[key_index];
+ vif->key_has_add = 1;
+ if (vif->wdev.iftype == NL80211_IFTYPE_STATION ||
+ vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)
+ vif->sta.group_cipher_type = params->cipher;
+ }
+
+ /* Retrieve the cipher suite selector */
+ switch (params->cipher) {
+ case WLAN_CIPHER_SUITE_WEP40:
+ cipher = MAC_CIPHER_WEP40;
+ break;
+ case WLAN_CIPHER_SUITE_WEP104:
+ cipher = MAC_CIPHER_WEP104;
+ break;
+ case WLAN_CIPHER_SUITE_TKIP:
+ cipher = MAC_CIPHER_TKIP;
+ break;
+ case WLAN_CIPHER_SUITE_CCMP:
+ cipher = MAC_CIPHER_CCMP;
+ break;
+ case WLAN_CIPHER_SUITE_AES_CMAC:
+ cipher = MAC_CIPHER_BIP_CMAC_128;
+ break;
+ case WLAN_CIPHER_SUITE_SMS4: {
+ // Need to reverse key order
+ u8 tmp, *key = (u8 *)params->key;
+
+ cipher = MAC_CIPHER_WPI_SMS4;
+ for (i = 0; i < WPI_SUBKEY_LEN / 2; i++) {
+ tmp = key[i];
+ key[i] = key[WPI_SUBKEY_LEN - 1 - i];
+ key[WPI_SUBKEY_LEN - 1 - i] = tmp;
+ }
+ for (i = 0; i < WPI_SUBKEY_LEN / 2; i++) {
+ tmp = key[i + WPI_SUBKEY_LEN];
+ key[i + WPI_SUBKEY_LEN] = key[WPI_KEY_LEN - 1 - i];
+ key[WPI_KEY_LEN - 1 - i] = tmp;
+ }
+ break;
+ }
+ default:
+ return -EINVAL;
+ }
+
+ vif->key_flag = false;
+ error = aicwf_send_key_add(aicwf_hw, vif->vif_index,
+ (sta ? sta->sta_idx : 0xFF),
+ key_type == NL80211_KEYTYPE_PAIRWISE,
+ (u8 *)params->key, params->key_len,
+ key_index, cipher, &key_add_cfm);
+ if (error)
+ return error;
+
+ if (key_add_cfm.status != 0) {
+ dev_err(&wiphy->dev, "key_add: Status Error(%d)\n", key_add_cfm.status);
+ return -EIO;
+ }
+
+ /* Save the index retrieved from LMAC */
+ aicwf_key->hw_idx = key_add_cfm.hw_key_idx;
+
+ return 0;
+}
+
+/*
+ * @get_key: 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.
+ *
+ */
+static int aicwf_cfg80211_get_key(struct wiphy *wiphy, struct wireless_dev *wdev,
+ int link_id,
+ u8 key_index, enum nl80211_key_type key_type,
+ const u8 *mac_addr, void *cookie,
+ void (*callback)(void *cookie, struct key_params *))
+{
+ return -1;
+}
+
+/*
+ * @del_key: remove a key given the @mac_addr (%NULL for a group key)
+ * and @key_index, return -ENOENT if the key doesn't exist.
+ */
+static int aicwf_cfg80211_del_key(struct wiphy *wiphy, struct wireless_dev *wdev,
+ int link_id,
+ u8 key_index, enum nl80211_key_type key_type,
+ const u8 *mac_addr)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct net_device *netdev = wdev->netdev;
+ struct aicwf_vif *vif = netdev_priv(netdev);
+ int error;
+ struct aicwf_sta *sta = NULL;
+ struct aicwf_key *aicwf_key;
+
+ if (!vif->key_flag && vif->wdev.iftype == NL80211_IFTYPE_STATION)
+ return 0;
+
+ if (mac_addr) {
+ sta = aicwf_get_sta(aicwf_hw, mac_addr);
+ if (!sta)
+ return -EINVAL;
+ aicwf_key = &sta->key;
+ if (vif->wdev.iftype == NL80211_IFTYPE_STATION ||
+ vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)
+ vif->sta.paired_cipher_type = 0xff;
+ } else {
+ aicwf_key = &vif->key[key_index];
+ vif->key_has_add = 0;
+ if (vif->wdev.iftype == NL80211_IFTYPE_STATION ||
+ vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)
+ vif->sta.group_cipher_type = 0xff;
+ }
+
+ error = aicwf_send_key_del(aicwf_hw, aicwf_key->hw_idx);
+
+ aicwf_key->hw_idx = 0;
+ return error;
+}
+
+/*
+ * @set_default_key: set the default key on an interface
+ */
+static int aicwf_cfg80211_set_default_key(struct wiphy *wiphy,
+ struct net_device *netdev,
+ int link_id,
+ u8 key_index, bool unicast,
+ bool multicast)
+{
+ return 0;
+}
+
+/*
+ * @set_default_mgmt_key: set the default management frame key on an interface
+ */
+static int aicwf_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
+ struct wireless_dev *wdev,
+ int link_id,
+ u8 key_index)
+{
+ return 0;
+}
+
+/*
+ * @connect: 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.
+ * (invoked with the wireless_dev mutex held)
+ */
+static int aicwf_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
+ struct cfg80211_connect_params *sme)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct sm_connect_cfm sm_connect_cfm;
+ int error = 0;
+ int is_wep = (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40 ||
+ sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104 ||
+ sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_WEP40 ||
+ sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_WEP104);
+
+ if ((int)atomic_read(&aicwf_vif->drv_conn_state) == (int)AICWF_DRV_STATUS_CONNECTED) {
+ dev_dbg(&wiphy->dev, "this connection is roam\n");
+ aicwf_vif->sta.is_roam = true;
+ } else {
+ aicwf_vif->sta.is_roam = false;
+ }
+
+ if ((int)atomic_read(&aicwf_vif->drv_conn_state) == (int)AICWF_DRV_STATUS_DISCONNECTING ||
+ (int)atomic_read(&aicwf_vif->drv_conn_state) == (int)AICWF_DRV_STATUS_CONNECTING) {
+ dev_err(&wiphy->dev, "driver is disconnecting or connecting ,return it\n");
+ return 0;
+ }
+
+ if (aicwf_vif->sta.is_roam)
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state, (int)AICWF_DRV_STATUS_ROAMING);
+ else
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state, (int)AICWF_DRV_STATUS_CONNECTING);
+
+ if (is_wep) {
+ if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
+ if (aicwf_vif->wep_enabled && aicwf_vif->wep_auth_err) {
+ if (aicwf_vif->last_auth_type == NL80211_AUTHTYPE_SHARED_KEY)
+ sme->auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
+ else
+ sme->auth_type = NL80211_AUTHTYPE_SHARED_KEY;
+ } else {
+ if (aicwf_vif->wep_enabled && !aicwf_vif->wep_auth_err)
+ sme->auth_type = aicwf_vif->last_auth_type;
+ else
+ sme->auth_type = NL80211_AUTHTYPE_SHARED_KEY;
+ }
+ dev_dbg(&wiphy->dev, "auto: use sme->auth_type = %d\n",
+ sme->auth_type);
+ } else {
+ if (aicwf_vif->wep_enabled && aicwf_vif->wep_auth_err &&
+ sme->auth_type == aicwf_vif->last_auth_type) {
+ if (sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
+ sme->auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
+ dev_dbg(&wiphy->dev, "start connect, auth_type changed, shared --> open\n");
+ } else if (sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) {
+ sme->auth_type = NL80211_AUTHTYPE_SHARED_KEY;
+ dev_dbg(&wiphy->dev, "start connect, auth_type changed, open --> shared\n");
+ }
+ }
+ }
+ }
+
+ /* For SHARED-KEY authentication, must install key first */
+ if (sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY && sme->key) {
+ struct key_params key_params;
+
+ key_params.key = (u8 *)sme->key;
+ key_params.seq = NULL;
+ key_params.key_len = sme->key_len;
+ key_params.seq_len = 0;
+ key_params.cipher = sme->crypto.cipher_group;
+ aicwf_cfg80211_add_key(wiphy, &aicwf_vif->wdev, 0,
+ sme->key_idx, NL80211_KEYTYPE_GROUP,
+ NULL, &key_params);
+ } else if (sme->auth_type == NL80211_AUTHTYPE_SAE &&
+ !(sme->flags & CONNECT_REQ_EXTERNAL_AUTH_SUPPORT)) {
+ netdev_err(dev,
+ "does not support sae without external authentication\n");
+ return -EINVAL;
+ }
+
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)
+ aicwf_hw->is_p2p_connected = 1;
+
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_STATION ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
+ aicwf_vif->sta.paired_cipher_type = 0xff;
+ aicwf_vif->sta.group_cipher_type = 0xff;
+ }
+
+ /* Forward the information to the LMAC */
+ error = aicwf_send_sm_connect_req(aicwf_hw, aicwf_vif, sme, &sm_connect_cfm);
+ if (error)
+ return error;
+
+ // Check the status
+ switch (sm_connect_cfm.status) {
+ case CO_OK:
+ error = 0;
+ break;
+ case CO_BUSY:
+ error = -EINPROGRESS;
+ break;
+ case CO_OP_IN_PROGRESS:
+ error = -EALREADY;
+ break;
+ default:
+ error = -EIO;
+ break;
+ }
+
+ return error;
+}
+
+/*
+ * @disconnect: Disconnect from the BSS/ESS.
+ * (invoked with the wireless_dev mutex held)
+ */
+static int aicwf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
+ u16 reason_code)
+{
+ int ret = 0;
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+
+ dev_dbg(&wiphy->dev, "drv_vif_index:%d disconnect reason:%d\n",
+ aicwf_vif->drv_vif_index, reason_code);
+
+ if (atomic_read(&aicwf_vif->drv_conn_state) == AICWF_DRV_STATUS_DISCONNECTED) {
+ dev_err(&wiphy->dev, "this\n");
+ WARN_ON(1);
+ return -EBUSY;
+ }
+
+ if (atomic_read(&aicwf_vif->drv_conn_state) == AICWF_DRV_STATUS_DISCONNECTING) {
+ dev_err(&wiphy->dev, "wifi is disconnecting, return it:%d\n", reason_code);
+ return -EBUSY;
+ }
+
+ if (atomic_read(&aicwf_vif->drv_conn_state) == AICWF_DRV_STATUS_CONNECTED ||
+ atomic_read(&aicwf_vif->drv_conn_state) == AICWF_DRV_STATUS_CONNECTING ||
+ atomic_read(&aicwf_vif->drv_conn_state) == AICWF_DRV_STATUS_ROAMING) {
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state, AICWF_DRV_STATUS_DISCONNECTING);
+ aicwf_vif->key_flag = true;
+ ret = aicwf_send_sm_disconnect_req(aicwf_hw, aicwf_vif, reason_code);
+ if (aicwf_hw->sdiodev->bus_if->state == BUS_DOWN_ST) {
+ dev_dbg(&wiphy->dev, "bus is down %d\n", ret);
+ aicwf_set_conn_state(&aicwf_vif->drv_conn_state,
+ AICWF_DRV_STATUS_DISCONNECTED);
+ }
+ return ret;
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_AIC8800_SCHED_SCAN
+static int aicwf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
+ struct net_device *ndev,
+ u64 reqid)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ // struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ dev_dbg(&wiphy->dev, "enter wiphy:%p\n", wiphy);
+
+ if (aicwf_scan_pending(aicwf_hw, ndev->ieee80211_ptr)) {
+ dev_dbg(&wiphy->dev, "aicwf_send_scanu_cancel_req\n");
+ return aicwf_send_scanu_cancel_req(aicwf_hw, NULL);
+ } else {
+ return 0;
+ }
+}
+
+static int
+aicwf_cfg80211_sched_scan_start(struct wiphy *wiphy, struct net_device *dev,
+ struct cfg80211_sched_scan_request *request)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct cfg80211_scan_request *scan_request = NULL;
+
+ int ret = 0;
+ int index = 0;
+
+ dev_dbg(&wiphy->dev, "enter wiphy:%p\n", wiphy);
+
+ if (aicwf_hw->is_sched_scan || aicwf_hw->scanning) {
+ dev_err(&wiphy->dev, "is_sched_scanning and scanning, busy");
+ return -EBUSY;
+ }
+
+ scan_request = (struct cfg80211_scan_request *)
+ kmalloc_obj(struct cfg80211_scan_request, GFP_KERNEL);
+
+ scan_request->ssids = request->ssids;
+ scan_request->n_channels = request->n_channels;
+ scan_request->n_ssids = request->n_match_sets;
+ scan_request->no_cck = false;
+ scan_request->ie = request->ie;
+ scan_request->ie_len = request->ie_len;
+ scan_request->flags = request->flags;
+
+ scan_request->wiphy = wiphy;
+ scan_request->scan_start = request->scan_start;
+ memcpy(scan_request->mac_addr, request->mac_addr, ETH_ALEN);
+ memcpy(scan_request->mac_addr_mask, request->mac_addr_mask, ETH_ALEN);
+ aicwf_hw->sched_scan_req = request;
+ scan_request->wdev = &aicwf_vif->wdev;
+ dev_dbg(&wiphy->dev, "scan_request->n_channels:%d\n",
+ scan_request->n_channels);
+ dev_dbg(&wiphy->dev, "scan_request->n_ssids:%d\n",
+ scan_request->n_ssids);
+
+ for (index = 0; index < scan_request->n_ssids; index++) {
+ memset(scan_request->ssids[index].ssid, 0, IEEE80211_MAX_SSID_LEN);
+
+ memcpy(scan_request->ssids[index].ssid,
+ request->match_sets[index].ssid.ssid, IEEE80211_MAX_SSID_LEN);
+
+ scan_request->ssids[index].ssid_len = request->match_sets[index].ssid.ssid_len;
+
+ dev_dbg(&wiphy->dev, "request ssid:%s len:%d\n",
+ scan_request->ssids[index].ssid,
+ scan_request->ssids[index].ssid_len);
+ }
+
+ for (index = 0; index < scan_request->n_channels; index++) {
+ scan_request->channels[index] = request->channels[index];
+
+ dev_dbg(&wiphy->dev, "scan_request->channels[%d]:%d\n",
+ index, scan_request->channels[index]->center_freq);
+
+ if (!scan_request->channels[index]) {
+ dev_err(&wiphy->dev, "channels is null!\n");
+ continue;
+ }
+ }
+
+ if (aicwf_hw->scanning) {
+ dev_err(&wiphy->dev, "scanning, about it");
+ kfree(scan_request);
+ return -EBUSY;
+ }
+ ret = aicwf_scan(wiphy, scan_request, true);
+ if (ret)
+ kfree(scan_request);
+ return ret;
+}
+#endif // CONFIG_AIC8800_SCHED_SCAN
+
+/*
+ * @external_auth: indicates result of offloaded authentication processing from
+ * user space
+ */
+static int
+aicwf_cfg80211_external_auth(struct wiphy *wiphy, struct net_device *dev,
+ struct cfg80211_external_auth_params *params)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+
+ if (!aicwf_vif->sta.external_auth)
+ return -EINVAL;
+
+ aicwf_external_auth_disable(aicwf_vif);
+ return aicwf_send_sm_external_auth_required_rsp(aicwf_hw, aicwf_vif,
+ params->status);
+}
+
+/*
+ * @add_station: Add a new station.
+ */
+static int __maybe_unused aicwf_cfg80211_add_station(struct wiphy *wiphy,
+ struct wireless_dev *wdev,
+ const u8 *mac,
+ struct station_parameters *params)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct net_device *dev = wdev->netdev;
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct me_sta_add_cfm me_sta_add_cfm;
+ int error = 0;
+
+ WARN_ON(AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_AP_VLAN);
+
+ /* Do not add TDLS station */
+ if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
+ return 0;
+
+ /* Indicate we are in a STA addition process - This will allow handling
+ * potential PS mode change indications correctly
+ */
+ aicwf_hw->adding_sta = true;
+
+ /* Forward the information to the LMAC */
+ error = aicwf_send_me_sta_add(aicwf_hw, params, mac, aicwf_vif->vif_index,
+ &me_sta_add_cfm);
+ if (error)
+ return error;
+
+ // Check the status
+ switch (me_sta_add_cfm.status) {
+ case CO_OK: {
+ struct aicwf_sta *sta = &aicwf_hw->sta_table[me_sta_add_cfm.sta_idx];
+ int tid;
+
+ sta->aid = params->aid;
+ sta->sta_idx = me_sta_add_cfm.sta_idx;
+ sta->ch_idx = aicwf_vif->ch_index;
+ sta->vif_idx = aicwf_vif->vif_index;
+ sta->vlan_idx = sta->vif_idx;
+ sta->qos = (params->sta_flags_set & BIT(NL80211_STA_FLAG_WME)) != 0;
+ sta->ht = params->link_sta_params.ht_capa ? 1 : 0;
+ sta->vht = params->link_sta_params.vht_capa ? 1 : 0;
+ sta->acm = 0;
+ sta->key.hw_idx = 0;
+
+ if (params->local_pm != NL80211_MESH_POWER_UNKNOWN)
+ sta->mesh_pm = params->local_pm;
+ else
+ sta->mesh_pm = aicwf_vif->ap.next_mesh_pm;
+ aicwf_update_mesh_power_mode(aicwf_vif);
+
+ for (tid = 0; tid < NX_NB_TXQ_PER_STA; tid++) {
+ int uapsd_bit = aicwf_hwq2uapsd[aicwf_tid2hwq[tid]];
+
+ if (params->uapsd_queues & uapsd_bit)
+ sta->uapsd_tids |= 1 << tid;
+ else
+ sta->uapsd_tids &= ~(1 << tid);
+ }
+ memcpy(sta->mac_addr, mac, ETH_ALEN);
+
+ /* Ensure that we won't process PS change or channel switch ind */
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_txq_sta_init(aicwf_hw, sta, aicwf_txq_vif_get_status(aicwf_vif));
+ list_add_tail(&sta->list, &aicwf_vif->ap.sta_list);
+ sta->valid = true;
+ aicwf_ps_bh_enable(aicwf_hw, sta,
+ sta->ps.active || me_sta_add_cfm.pm_state);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+
+ error = 0;
+
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_AP ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
+ struct station_info sinfo;
+
+ memset(&sinfo, 0, sizeof(struct station_info));
+ sinfo.assoc_req_ies = NULL;
+ sinfo.assoc_req_ies_len = 0;
+ cfg80211_new_sta(&aicwf_vif->wdev, sta->mac_addr, &sinfo,
+ GFP_KERNEL);
+ }
+#ifdef CONFIG_AICWF_BFMER
+ if (aicwf_hw->mod_params->bfmer)
+ aicwf_send_bfmer_enable(aicwf_hw, sta,
+ params->link_sta_params.vht_capa);
+
+ aicwf_mu_group_sta_init(sta, params->link_sta_params.vht_capa);
+#endif /* CONFIG_AICWF_BFMER */
+
+#define PRINT_STA_FLAG(f) \
+ (params->sta_flags_set & BIT(NL80211_STA_FLAG_##f) ? "[" #f "]" : "")
+
+ netdev_info(dev, "add sta %d %pM flags=%s%s%s%s%s%s%s\n", sta->sta_idx,
+ mac, PRINT_STA_FLAG(AUTHORIZED),
+ PRINT_STA_FLAG(SHORT_PREAMBLE), PRINT_STA_FLAG(WME),
+ PRINT_STA_FLAG(MFP), PRINT_STA_FLAG(AUTHENTICATED),
+ PRINT_STA_FLAG(TDLS_PEER), PRINT_STA_FLAG(ASSOCIATED));
+#undef PRINT_STA_FLAG
+ break;
+ }
+ default:
+ error = -EBUSY;
+ break;
+ }
+
+ aicwf_hw->adding_sta = false;
+
+ return error;
+}
+
+/*
+ * @del_station: Remove a station
+ */
+static int aicwf_cfg80211_del_station(struct wiphy *wiphy,
+ struct wireless_dev *wdev,
+ struct station_del_parameters *params)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct net_device *dev = wdev->netdev;
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_sta *cur, *tmp;
+ int error = 0, found = 0;
+ const u8 *mac = NULL;
+#ifdef CONFIG_AIC8800_RX_REORDER
+ struct reord_ctrl_info *reord_info, *reord_tmp;
+ u8 *macaddr;
+ struct aicwf_rx_priv *rx_priv;
+#endif
+ dev_dbg(&wiphy->dev, "%pM\n", mac);
+
+ if (params)
+ mac = params->mac;
+
+ do {
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ if (list_empty(&aicwf_vif->ap.sta_list)) {
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ break;
+ }
+
+ list_for_each_entry_safe(cur, tmp, &aicwf_vif->ap.sta_list, list) {
+ if (!mac || !memcmp(cur->mac_addr, mac, ETH_ALEN)) {
+ found = 1;
+ break;
+ }
+ }
+
+ if (found) {
+ cur->ps.active = false;
+ cur->valid = false;
+ list_del(&cur->list);
+ }
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+
+ if (found) {
+ netdev_info(dev, "del sta %d %pM\n", cur->sta_idx, cur->mac_addr);
+ if (cur->vif_idx != cur->vlan_idx) {
+ struct aicwf_vif *vlan_vif;
+
+ vlan_vif = aicwf_hw->vif_table[cur->vlan_idx];
+ if (vlan_vif->up) {
+ if (AICWF_VIF_TYPE(vlan_vif) == NL80211_IFTYPE_AP_VLAN &&
+ vlan_vif->use_4addr) {
+ vlan_vif->ap_vlan.sta_4a = NULL;
+ } else {
+ WARN(1,
+ "Deleting sta belonging to VLAN other than AP_VLAN 4A");
+ }
+ }
+ }
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_AP ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
+ cfg80211_del_sta(&aicwf_vif->wdev, cur->mac_addr,
+ GFP_KERNEL);
+ }
+
+#ifdef CONFIG_AIC8800_RX_REORDER
+ rx_priv = aicwf_hw->sdiodev->rx_priv;
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_STATION ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
+ //WARN_ON_ONCE(); // should be other function
+ } else if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_AP ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
+ macaddr = cur->mac_addr;
+ dev_dbg(&wiphy->dev, "deinit:macaddr:%x,%x,%x,%x,%x,%x\n",
+ macaddr[0], macaddr[1], macaddr[2],
+ macaddr[3], macaddr[4], macaddr[5]);
+ spin_lock_bh(&rx_priv->stas_reord_lock);
+ list_for_each_entry_safe(reord_info, reord_tmp,
+ &rx_priv->stas_reord_list, list) {
+ dev_dbg(&wiphy->dev, "reord_mac:%x,%x,%x,%x,%x,%x\n",
+ reord_info->mac_addr[0], reord_info->mac_addr[1],
+ reord_info->mac_addr[2], reord_info->mac_addr[3],
+ reord_info->mac_addr[4], reord_info->mac_addr[5]);
+ if (!memcmp(reord_info->mac_addr, macaddr, 6)) {
+ reord_deinit_sta(rx_priv, reord_info);
+ break;
+ }
+ }
+ spin_unlock_bh(&rx_priv->stas_reord_lock);
+ }
+#endif
+ aicwf_txq_sta_deinit(aicwf_hw, cur);
+ error = aicwf_send_me_sta_del(aicwf_hw, cur->sta_idx, false);
+ if (error != 0 && error != -EPIPE)
+ return error;
+
+#ifdef CONFIG_AICWF_BFMER
+ // Disable Beamformer if supported
+ aicwf_bfmer_report_del(aicwf_hw, cur);
+ aicwf_mu_group_sta_del(aicwf_hw, cur);
+#endif /* CONFIG_AICWF_BFMER */
+ }
+
+ if (mac)
+ break;
+ } while (1);
+
+ aicwf_update_mesh_power_mode(aicwf_vif);
+
+ if (!found && mac)
+ return -ENOENT;
+ else
+ return 0;
+}
+
+void apm_staloss_work_process(struct work_struct *work)
+{
+ struct aicwf_hw *aicwf_hw = container_of(work, struct aicwf_hw, apm_staloss_work);
+ struct aicwf_sta *cur, *tmp;
+ int error = 0;
+
+#ifdef CONFIG_AIC8800_RX_REORDER
+ struct reord_ctrl_info *reord_info, *reord_tmp;
+ u8 *macaddr;
+ struct aicwf_rx_priv *rx_priv;
+#endif
+ struct aicwf_vif *aicwf_vif;
+ bool found = false;
+ const u8 *mac = aicwf_hw->sta_mac_addr;
+
+ // Look for VIF entry
+ list_for_each_entry(aicwf_vif, &aicwf_hw->vifs, list) {
+ if (aicwf_vif->vif_index == aicwf_hw->apm_vif_idx) {
+ found = true;
+ break;
+ }
+ }
+
+ pr_debug("apm vif idx=%d, found=%d, mac addr=%pM\n",
+ aicwf_hw->apm_vif_idx, found, mac);
+ if (!found || !aicwf_vif ||
+ (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_AP &&
+ AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_P2P_GO)) {
+ return;
+ }
+
+ found = false;
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ list_for_each_entry_safe(cur, tmp, &aicwf_vif->ap.sta_list, list) {
+ if (mac && !memcmp(cur->mac_addr, mac, ETH_ALEN)) {
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ cur->ps.active = false;
+ cur->valid = false;
+ list_del(&cur->list);
+ }
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+
+ if (found) {
+ netdev_info(aicwf_vif->ndev, "del sta %d %pM\n", cur->sta_idx,
+ cur->mac_addr);
+ if (cur->vif_idx != cur->vlan_idx) {
+ struct aicwf_vif *vlan_vif;
+
+ vlan_vif = aicwf_hw->vif_table[cur->vlan_idx];
+ if (vlan_vif->up) {
+ if (AICWF_VIF_TYPE(vlan_vif) == NL80211_IFTYPE_AP_VLAN &&
+ vlan_vif->use_4addr)
+ vlan_vif->ap_vlan.sta_4a = NULL;
+ WARN(1, "Deleting sta belonging to VLAN other than AP_VLAN 4A");
+ }
+ }
+
+#ifdef CONFIG_AIC8800_RX_REORDER
+ rx_priv = aicwf_hw->sdiodev->rx_priv;
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_STATION ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
+ //WARN_ON_ONCE(); // should be other function
+ } else if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_AP ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
+ macaddr = cur->mac_addr;
+ pr_debug("deinit:macaddr:%x,%x,%x,%x,%x,%x\n",
+ macaddr[0], macaddr[1], macaddr[2],
+ macaddr[3], macaddr[4], macaddr[5]);
+ spin_lock_bh(&rx_priv->stas_reord_lock);
+ list_for_each_entry_safe(reord_info, reord_tmp,
+ &rx_priv->stas_reord_list, list) {
+ pr_debug("reord_mac:%x,%x,%x,%x,%x,%x\n",
+ reord_info->mac_addr[0], reord_info->mac_addr[1],
+ reord_info->mac_addr[2], reord_info->mac_addr[3],
+ reord_info->mac_addr[4], reord_info->mac_addr[5]);
+ if (!memcmp(reord_info->mac_addr, macaddr, 6)) {
+ reord_deinit_sta(rx_priv, reord_info);
+ break;
+ }
+ }
+ spin_unlock_bh(&rx_priv->stas_reord_lock);
+ }
+#endif
+ aicwf_txq_sta_deinit(aicwf_hw, cur);
+ error = aicwf_send_me_sta_del(aicwf_hw, cur->sta_idx, false);
+ if (error != 0 && error != -EPIPE)
+ return;
+#ifdef CONFIG_AICWF_BFMER
+ // Disable Beamformer if supported
+ aicwf_bfmer_report_del(aicwf_hw, cur);
+ aicwf_mu_group_sta_del(aicwf_hw, cur);
+#endif /* CONFIG_AICWF_BFMER */
+
+ } else {
+ pr_debug("sta not found: %pM\n", mac);
+ return;
+ }
+
+ aicwf_update_mesh_power_mode(aicwf_vif);
+}
+
+void apm_probe_sta_work_process(struct work_struct *work)
+{
+ struct apm_probe_sta *probe_sta =
+ container_of(work, struct apm_probe_sta, apmprobesta_work);
+ struct aicwf_vif *aicwf_vif =
+ container_of(probe_sta, struct aicwf_vif, sta_probe);
+ bool found = false;
+ struct aicwf_sta *cur, *tmp;
+
+ u8 *mac = aicwf_vif->sta_probe.sta_mac_addr;
+
+ spin_lock_bh(&aicwf_vif->aicwf_hw->cb_lock);
+ list_for_each_entry_safe(cur, tmp, &aicwf_vif->ap.sta_list, list) {
+ if (!memcmp(cur->mac_addr, mac, ETH_ALEN)) {
+ found = true;
+ break;
+ }
+ }
+ spin_unlock_bh(&aicwf_vif->aicwf_hw->cb_lock);
+
+ pr_debug("sta %pM found = %d\n", mac, found);
+ if (found)
+ cfg80211_probe_status(aicwf_vif->ndev, mac,
+ (u64)aicwf_vif->sta_probe.probe_id, -1,
+ true, 0, false, GFP_ATOMIC);
+ else
+ cfg80211_probe_status(aicwf_vif->ndev, mac,
+ (u64)aicwf_vif->sta_probe.probe_id, -1,
+ false, 0, false, GFP_ATOMIC);
+ aicwf_vif->sta_probe.probe_id++;
+}
+
+/*
+ * @change_station: Modify a given station. Note that flags changes are not much
+ * validated in cfg80211, in particular the auth/assoc/authorized flags
+ * might come to the driver in invalid combinations -- make sure to check
+ * them, also against the existing state! Drivers must call
+ * cfg80211_check_station_change() to validate the information.
+ */
+static int __maybe_unused aicwf_cfg80211_change_station(struct wiphy *wiphy,
+ struct wireless_dev *wdev,
+ const u8 *mac,
+ struct station_parameters *params)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct net_device *dev = wdev->netdev;
+ struct aicwf_vif *vif = netdev_priv(dev);
+ struct aicwf_sta *sta;
+
+ sta = aicwf_get_sta(aicwf_hw, mac);
+ if (!sta) {
+ /* Add the TDLS station */
+ if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct me_sta_add_cfm me_sta_add_cfm;
+ int error = 0;
+
+ /* Indicate we are in a STA addition process - This will allow
+ * handling potential PS mode change indications correctly
+ */
+ aicwf_hw->adding_sta = true;
+
+ /* Forward the information to the LMAC */
+ error = aicwf_send_me_sta_add(aicwf_hw, params, mac,
+ aicwf_vif->vif_index, &me_sta_add_cfm);
+ if (error)
+ return error;
+
+ // Check the status
+ switch (me_sta_add_cfm.status) {
+ case CO_OK: {
+ int tid;
+
+ sta = &aicwf_hw->sta_table[me_sta_add_cfm.sta_idx];
+ sta->aid = params->aid;
+ sta->sta_idx = me_sta_add_cfm.sta_idx;
+ sta->ch_idx = aicwf_vif->ch_index;
+ sta->vif_idx = aicwf_vif->vif_index;
+ sta->vlan_idx = sta->vif_idx;
+ sta->qos =
+ (params->sta_flags_set & BIT(NL80211_STA_FLAG_WME)) != 0;
+ sta->ht = params->link_sta_params.ht_capa ? 1 : 0;
+ sta->vht = params->link_sta_params.vht_capa ? 1 : 0;
+ sta->acm = 0;
+ for (tid = 0; tid < NX_NB_TXQ_PER_STA; tid++) {
+ int uapsd_bit = aicwf_hwq2uapsd[aicwf_tid2hwq[tid]];
+
+ if (params->uapsd_queues & uapsd_bit)
+ sta->uapsd_tids |= 1 << tid;
+ else
+ sta->uapsd_tids &= ~(1 << tid);
+ }
+ memcpy(sta->mac_addr, mac, ETH_ALEN);
+ /* Ensure that we won't process PS change or channel switch ind
+ */
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_txq_sta_init(aicwf_hw, sta,
+ aicwf_txq_vif_get_status(aicwf_vif));
+ if (aicwf_vif->tdls_status == TDLS_SETUP_RSP_TX) {
+ aicwf_vif->tdls_status = TDLS_LINK_ACTIVE;
+ sta->tdls.initiator = true;
+ sta->tdls.active = true;
+ }
+ /* Set TDLS channel switch capability */
+ if ((params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH) &&
+ !aicwf_vif->tdls_chsw_prohibited)
+ sta->tdls.chsw_allowed = true;
+ aicwf_vif->sta.tdls_sta = sta;
+ sta->valid = true;
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+#ifdef CONFIG_AICWF_BFMER
+ if (aicwf_hw->mod_params->bfmer)
+ aicwf_send_bfmer_enable(aicwf_hw, sta,
+ params->link_sta_params.vht_capa);
+
+ aicwf_mu_group_sta_init(sta, NULL);
+#endif /* CONFIG_AICWF_BFMER */
+
+#define PRINT_STA_FLAG(f) \
+ (params->sta_flags_set & BIT(NL80211_STA_FLAG_##f) ? "[" #f "]" : "")
+
+ netdev_info(dev, "add %s TDLS sta %d %pM flags=%s%s%s%s%s%s%s\n",
+ sta->tdls.initiator ? "initiator" : "responder",
+ sta->sta_idx, mac, PRINT_STA_FLAG(AUTHORIZED),
+ PRINT_STA_FLAG(SHORT_PREAMBLE), PRINT_STA_FLAG(WME),
+ PRINT_STA_FLAG(MFP), PRINT_STA_FLAG(AUTHENTICATED),
+ PRINT_STA_FLAG(TDLS_PEER), PRINT_STA_FLAG(ASSOCIATED));
+#undef PRINT_STA_FLAG
+
+ break;
+ }
+ default:
+ error = -EBUSY;
+ break;
+ }
+ aicwf_hw->adding_sta = false;
+ } else {
+ return -EINVAL;
+ }
+ }
+
+ if (params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
+ aicwf_send_me_set_control_port_req
+ (aicwf_hw,
+ (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED)) != 0,
+ sta->sta_idx);
+
+ if (AICWF_VIF_TYPE(vif) == NL80211_IFTYPE_MESH_POINT) {
+ if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
+ if (params->plink_state < NUM_NL80211_PLINK_STATES) {
+ aicwf_send_mesh_peer_update_ntf(aicwf_hw, vif, sta->sta_idx,
+ params->plink_state);
+ }
+ }
+
+ if (params->local_pm != NL80211_MESH_POWER_UNKNOWN) {
+ sta->mesh_pm = params->local_pm;
+ aicwf_update_mesh_power_mode(vif);
+ }
+ }
+
+ if (params->vlan) {
+ u8 vlan_idx;
+
+ vif = netdev_priv(params->vlan);
+ vlan_idx = vif->vif_index;
+
+ if (sta->vlan_idx != vlan_idx) {
+ struct aicwf_vif *old_vif;
+
+ old_vif = aicwf_hw->vif_table[sta->vlan_idx];
+ aicwf_txq_sta_switch_vif(sta, old_vif, vif);
+ sta->vlan_idx = vlan_idx;
+
+ if (AICWF_VIF_TYPE(vif) == NL80211_IFTYPE_AP_VLAN &&
+ vif->use_4addr) {
+ WARN(vif->ap_vlan.sta_4a,
+ "4A AP_VLAN interface with more than one sta");
+ vif->ap_vlan.sta_4a = sta;
+ }
+
+ if (AICWF_VIF_TYPE(old_vif) == NL80211_IFTYPE_AP_VLAN &&
+ old_vif->use_4addr) {
+ old_vif->ap_vlan.sta_4a = NULL;
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * @start_ap: Start acting in AP mode defined by the parameters.
+ */
+static int __maybe_unused aicwf_cfg80211_start_ap(struct wiphy *wiphy,
+ struct net_device *dev,
+ struct cfg80211_ap_settings *settings)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct apm_start_cfm apm_start_cfm;
+ struct aicwf_ipc_elem_var elem;
+ struct aicwf_sta *sta;
+ int error = 0;
+
+ INIT_WORK(&aicwf_vif->sta_probe.apmprobesta_work, apm_probe_sta_work_process);
+ aicwf_vif->sta_probe.apmprobesta_wq =
+ create_singlethread_workqueue("apmprobe_wq");
+ if (!aicwf_vif->sta_probe.apmprobesta_wq) {
+ dev_err(&wiphy->dev, "insufficient memory to create apmprobe_wq\n");
+ return -ENOBUFS;
+ }
+
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_GO)
+ aicwf_hw->is_p2p_connected = 1;
+ /* Forward the information to the LMAC */
+ error = aicwf_send_apm_start_req(aicwf_hw, aicwf_vif, settings,
+ &apm_start_cfm, &elem);
+ if (error)
+ goto end;
+
+ // Check the status
+ switch (apm_start_cfm.status) {
+ case CO_OK: {
+ u8 txq_status = 0;
+
+ aicwf_vif->ap.bcmc_index = apm_start_cfm.bcmc_idx;
+ aicwf_vif->ap.flags = 0;
+ aicwf_vif->ap.csa = NULL;
+ sta = &aicwf_hw->sta_table[apm_start_cfm.bcmc_idx];
+ sta->valid = true;
+ sta->aid = 0;
+ sta->sta_idx = apm_start_cfm.bcmc_idx;
+ sta->ch_idx = apm_start_cfm.ch_idx;
+ sta->vif_idx = aicwf_vif->vif_index;
+ sta->qos = false;
+ sta->acm = 0;
+ sta->ps.active = false;
+ aicwf_mu_group_sta_init(sta, NULL);
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_chanctx_link(aicwf_vif, apm_start_cfm.ch_idx, &settings->chandef);
+ if (aicwf_hw->cur_chanctx != apm_start_cfm.ch_idx)
+ txq_status = AICWF_TXQ_STOP_CHAN;
+
+ aicwf_txq_vif_init(aicwf_hw, aicwf_vif, txq_status);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+
+ netif_tx_start_all_queues(dev);
+ netif_carrier_on(dev);
+ error = 0;
+ /* If the AP channel is already the active, we probably skip radar
+ * activation on MM_CHANNEL_SWITCH_IND (unless another vif use this
+ * ctxt). In anycase retest if radar detection must be activated
+ */
+ if (txq_status == 0)
+ aicwf_radar_detection_enable_on_cur_channel(aicwf_hw);
+ break;
+ }
+ case CO_BUSY:
+ error = -EINPROGRESS;
+ break;
+ case CO_OP_IN_PROGRESS:
+ error = -EALREADY;
+ break;
+ default:
+ error = -EIO;
+ break;
+ }
+
+ if (error)
+ netdev_info(dev, "failed to start AP %d\n", error);
+ else
+ netdev_info(dev, "ap started: ch=%d, bcmc_idx=%d channel=%d bw=%d\n",
+ aicwf_vif->ch_index, aicwf_vif->ap.bcmc_index,
+ ((settings->chandef).chan)->center_freq,
+ ((settings->chandef).width));
+
+end:
+ return error;
+}
+
+/*
+ * @change_beacon: Change the beacon parameters for an access point mode
+ * interface. This should reject the call when AP mode wasn't started.
+ */
+
+static int __maybe_unused aicwf_cfg80211_change_beacon(struct wiphy *wiphy,
+ struct net_device *dev,
+ struct cfg80211_ap_update *info)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *vif = netdev_priv(dev);
+ struct aicwf_bcn *bcn = &vif->ap.bcn;
+ u8 *buf;
+ int error = 0;
+
+ // Build the beacon
+ buf = aicwf_build_bcn(bcn, &info->beacon);
+ if (!buf)
+ return -ENOMEM;
+
+ aicwf_send_bcn(aicwf_hw, buf, vif->vif_index, bcn->len);
+
+ // Forward the information to the LMAC
+ error = aicwf_send_bcn_change(aicwf_hw, vif->vif_index, 0, bcn->len,
+ bcn->head_len, bcn->tim_len, NULL);
+
+ return error;
+}
+
+/*
+ * * @stop_ap: Stop being an AP, including stopping beaconing.
+ */
+static int __maybe_unused aicwf_cfg80211_stop_ap(struct wiphy *wiphy,
+ struct net_device *dev,
+ unsigned int link_id)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+
+ netif_tx_stop_all_queues(dev);
+ netif_carrier_off(dev);
+
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_GO)
+ aicwf_hw->is_p2p_connected = 0;
+ aicwf_radar_cancel_cac(&aicwf_hw->radar);
+ aicwf_send_apm_stop_req(aicwf_hw, aicwf_vif);
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_chanctx_unlink(aicwf_vif);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+
+ /* delete any remaining STA */
+ while (!list_empty(&aicwf_vif->ap.sta_list))
+ aicwf_cfg80211_del_station(wiphy, &aicwf_vif->wdev, NULL);
+
+ /* delete BC/MC STA */
+ aicwf_txq_vif_deinit(aicwf_hw, aicwf_vif);
+ aicwf_del_bcn(&aicwf_vif->ap.bcn);
+ aicwf_del_csa(aicwf_vif);
+
+ flush_workqueue(aicwf_vif->sta_probe.apmprobesta_wq);
+ destroy_workqueue(aicwf_vif->sta_probe.apmprobesta_wq);
+
+ netdev_info(dev, "ap stopped\n");
+
+ return 0;
+}
+
+/*
+ * @set_monitor_channel: Set the monitor mode channel for the device. If other
+ * interfaces are active this callback should reject the configuration.
+ * If no interfaces are active or the device is down, the channel should
+ * be stored for when a monitor interface becomes active.
+ *
+ * Also called internaly with chandef set to NULL simply to retrieve the channel
+ * configured at firmware level.
+ */
+static int aicwf_cfg80211_set_monitor_channel(struct wiphy *wiphy, struct net_device *dev,
+ struct cfg80211_chan_def *chandef)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif;
+ struct me_config_monitor_cfm cfm;
+
+ if (aicwf_hw->monitor_vif == AICWF_INVALID_VIF)
+ return -EINVAL;
+
+ aicwf_vif = aicwf_hw->vif_table[aicwf_hw->monitor_vif];
+
+ // Do nothing if monitor interface is already configured with the requested
+ // channel
+ if (aicwf_chanctx_valid(aicwf_hw, aicwf_vif->ch_index)) {
+ struct aicwf_chanctx *ctxt;
+
+ ctxt = &aicwf_vif->aicwf_hw->chanctx_table[aicwf_vif->ch_index];
+ if (chandef && cfg80211_chandef_identical(&ctxt->chan_def, chandef))
+ return 0;
+ }
+
+ // Always send command to firmware. It allows to retrieve channel context
+ // index and its configuration.
+ if (aicwf_send_config_monitor_req(aicwf_hw, chandef, &cfm))
+ return -EIO;
+
+ // Always re-set channel context info
+ aicwf_chanctx_unlink(aicwf_vif);
+
+ // If there is also a STA interface not yet connected then monitor interface
+ // will only have a channel context after the connection of the STA
+ // interface.
+ if (cfm.chan_index != AICWF_CH_NOT_SET) {
+ struct cfg80211_chan_def mon_chandef;
+
+ if (aicwf_hw->vif_started > 1) {
+ // In this case we just want to update the channel context index not
+ // the channel configuration
+ aicwf_chanctx_link(aicwf_vif, cfm.chan_index, NULL);
+ return -EBUSY;
+ }
+
+ mon_chandef.chan = ieee80211_get_channel(wiphy, cfm.chan.prim20_freq);
+ mon_chandef.center_freq1 = cfm.chan.center1_freq;
+ mon_chandef.center_freq2 = cfm.chan.center2_freq;
+ mon_chandef.width = chnl2bw[cfm.chan.type];
+ aicwf_chanctx_link(aicwf_vif, cfm.chan_index, &mon_chandef);
+ }
+
+ return 0;
+}
+
+/*
+ * @set_wiphy_params: Notify that wiphy parameters have changed;
+ * @changed bitfield (see &enum wiphy_params_flags) describes which values
+ * have changed. The actual parameter values are available in
+ * struct wiphy. If returning an error, no value should be changed.
+ */
+static int aicwf_cfg80211_set_wiphy_params(struct wiphy *wiphy, int radio_idx,
+ u32 changed)
+{
+ return 0;
+}
+
+/*
+ * @set_tx_power: set the transmit power according to the parameters,
+ * the power passed is in mBm, to get dBm use MBM_TO_DBM(). The
+ * wdev may be %NULL if power was set for the wiphy, and will
+ * always be %NULL unless the driver supports per-vif TX power
+ * (as advertised by the nl80211 feature flag.)
+ */
+static int aicwf_cfg80211_set_tx_power(struct wiphy *wiphy,
+ struct wireless_dev *wdev,
+ int radio_idx,
+ enum nl80211_tx_power_setting type,
+ int mbm)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *vif;
+ int limit, ret;
+
+ if (READ_ONCE(aicwf_hw->regdom_failed))
+ return -EIO;
+
+ switch (type) {
+ case NL80211_TX_POWER_AUTOMATIC:
+ limit = S8_MAX;
+ break;
+ case NL80211_TX_POWER_LIMITED:
+ if (mbm < DBM_TO_MBM(S8_MIN) || mbm >= DBM_TO_MBM(S8_MAX))
+ return -ERANGE;
+ /* Round down so the firmware never exceeds the requested limit. */
+ limit = mbm < 0 ? -DIV_ROUND_UP(-mbm, 100) : MBM_TO_DBM(mbm);
+ break;
+ case NL80211_TX_POWER_FIXED:
+ /* The per-channel firmware interface only specifies upper limits. */
+ return -EOPNOTSUPP;
+ default:
+ return -EINVAL;
+ }
+
+ WRITE_ONCE(aicwf_hw->tx_power_limit, limit);
+ ret = aicwf_send_me_chan_config_req(aicwf_hw);
+ if (ret) {
+ list_for_each_entry(vif, &aicwf_hw->vifs, list) {
+ if (vif->up)
+ cfg80211_stop_iface(wiphy, &vif->wdev, GFP_KERNEL);
+ }
+ }
+ return ret;
+}
+
+static int aicwf_cfg80211_set_txq_params(struct wiphy *wiphy,
+ struct net_device *dev,
+ struct ieee80211_txq_params *params)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ u8 hw_queue, aifs, cwmin, cwmax;
+ u32 param;
+
+ hw_queue = aicwf_ac2hwq[0][params->ac];
+
+ aifs = params->aifs;
+ cwmin = fls(params->cwmin);
+ cwmax = fls(params->cwmax);
+
+ /* Store queue information in general structure */
+ param = (u32)(aifs << 0);
+ param |= (u32)(cwmin << 4);
+ param |= (u32)(cwmax << 8);
+ param |= (u32)(params->txop) << 12;
+
+ /* Send the MM_SET_EDCA_REQ message to the FW */
+ return aicwf_send_set_edca(aicwf_hw, hw_queue, param, false,
+ aicwf_vif->vif_index);
+}
+
+/*
+ * @remain_on_channel: 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().
+ */
+static int aicwf_cfg80211_remain_on_channel_(struct wiphy *wiphy,
+ struct wireless_dev *wdev,
+ struct ieee80211_channel *chan,
+ unsigned int duration, u64 cookie,
+ bool mgmt_roc_flag)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ // struct aicwf_vif *aicwf_vif = netdev_priv(wdev->netdev);
+ struct aicwf_vif *aicwf_vif = container_of(wdev, struct aicwf_vif, wdev);
+ struct aicwf_roc_elem *roc_elem;
+ struct mm_add_if_cfm add_if_cfm;
+ struct mm_remain_on_channel_cfm roc_cfm;
+ int error;
+
+ /* For debug purpose (use ftrace kernel option) */
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_roc(aicwf_vif->vif_index, chan->center_freq, duration);
+#endif
+ /* Check that no other RoC procedure has been launched */
+ if (aicwf_hw->roc_elem) {
+ usleep_range(2000, 4000);
+ if (aicwf_hw->roc_elem) {
+ dev_dbg(&wiphy->dev, "remain_on_channel fail\n");
+ return -EBUSY;
+ }
+ }
+
+ dev_dbg(&wiphy->dev, "remain:%d,%d,%d\n",
+ aicwf_vif->vif_index, aicwf_vif->is_p2p_vif,
+ aicwf_hw->is_p2p_alive);
+#ifdef CONFIG_AIC8800_USE_P2P0
+ if (aicwf_vif->is_p2p_vif) {
+#else
+ if (aicwf_vif == aicwf_hw->p2p_dev_vif && !aicwf_vif->up) {
+#endif
+ if (!aicwf_hw->is_p2p_alive) {
+ error = aicwf_send_add_if(aicwf_hw, aicwf_vif->wdev.address,
+ // wdev->netdev->dev_addr,
+ AICWF_VIF_TYPE(aicwf_vif),
+ false, &add_if_cfm);
+ if (error)
+ return -EIO;
+
+ if (add_if_cfm.status != 0)
+ return -EIO;
+
+ /* Save the index retrieved from LMAC */
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_vif->vif_index = add_if_cfm.inst_nbr;
+ aicwf_vif->up = true;
+ aicwf_hw->vif_started++;
+ aicwf_hw->vif_table[add_if_cfm.inst_nbr] = aicwf_vif;
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ aicwf_hw->is_p2p_alive = 1;
+#ifndef CONFIG_AIC8800_USE_P2P0
+ mod_timer(&aicwf_hw->p2p_alive_timer,
+ jiffies + msecs_to_jiffies(1000));
+ atomic_set(&aicwf_hw->p2p_alive_timer_count, 0);
+#endif
+ } else {
+#ifndef CONFIG_AIC8800_USE_P2P0
+ mod_timer(&aicwf_hw->p2p_alive_timer,
+ jiffies + msecs_to_jiffies(1000));
+ atomic_set(&aicwf_hw->p2p_alive_timer_count, 0);
+#endif
+ }
+ }
+ /* Allocate a temporary RoC element */
+ roc_elem = kmalloc_obj(*roc_elem, GFP_KERNEL);
+
+ /* Verify that element has well been allocated */
+ if (!roc_elem)
+ return -ENOMEM;
+
+ /* Initialize the RoC information element */
+ roc_elem->wdev = wdev;
+ roc_elem->chan = chan;
+ roc_elem->duration = duration;
+ roc_elem->cookie = cookie;
+ roc_elem->mgmt_roc = mgmt_roc_flag;
+ roc_elem->on_chan = false;
+
+ /* Initialize the OFFCHAN TX queue to allow off-channel transmissions */
+ aicwf_txq_offchan_init(aicwf_vif);
+
+ /* Forward the information to the FMAC */
+ aicwf_hw->roc_elem = roc_elem;
+ error = aicwf_send_roc(aicwf_hw, aicwf_vif, chan, duration, &roc_cfm);
+
+ /* If no error, keep all the information for handling of end of procedure */
+ if (error == 0) {
+ if (roc_cfm.status) {
+ // failed to roc
+ aicwf_hw->roc_elem = NULL;
+ kfree(roc_elem);
+ aicwf_txq_offchan_deinit(aicwf_vif);
+ return -EBUSY;
+ }
+ } else {
+ /* Free the allocated element */
+ aicwf_hw->roc_elem = NULL;
+ kfree(roc_elem);
+ aicwf_txq_offchan_deinit(aicwf_vif);
+ }
+
+ return error;
+}
+
+static int aicwf_cfg80211_remain_on_channel(struct wiphy *wiphy,
+ struct wireless_dev *wdev,
+ struct ieee80211_channel *chan,
+ unsigned int duration, u64 cookie,
+ const u8 *rx_addr)
+{
+ return aicwf_cfg80211_remain_on_channel_(wiphy, wdev, chan,
+ duration, cookie, false);
+}
+
+/*
+ * @cancel_remain_on_channel: Cancel an on-going remain-on-channel operation.
+ * This allows the operation to be terminated prior to timeout based on
+ * the duration value.
+ */
+static int aicwf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
+ struct wireless_dev *wdev,
+ u64 cookie)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ struct aicwf_vif *aicwf_vif =
+ container_of(wdev, struct aicwf_vif, wdev); // netdev_priv(wdev->netdev);
+#endif
+
+ /* For debug purpose (use ftrace kernel option) */
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_cancel_roc(aicwf_vif->vif_index);
+#endif
+ /* Check if a RoC procedure is pending */
+ if (!aicwf_hw->roc_elem)
+ return 0;
+
+ /* Forward the information to the FMAC */
+ return aicwf_send_cancel_roc(aicwf_hw);
+}
+
+static inline bool IS_2P4GHZ(int freq)
+{
+ return (freq >= 2412 && freq <= 2484);
+}
+
+static inline bool IS_5GHZ(int freq)
+{
+ return (freq >= 4000 && freq <= 5895);
+}
+
+#define DEFAULT_NOISE_FLOOR_2GHZ (-89)
+#define DEFAULT_NOISE_FLOOR_5GHZ (-92)
+
+/*
+ * @dump_survey: get site survey information.
+ */
+static int aicwf_cfg80211_dump_survey(struct wiphy *wiphy,
+ struct net_device *netdev, int idx,
+ struct survey_info *info)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct ieee80211_supported_band *sband;
+ struct aicwf_survey_info *aicwf_survey;
+
+ if (idx >= ARRAY_SIZE(aicwf_hw->survey))
+ return -ENOENT;
+
+ aicwf_survey = &aicwf_hw->survey[idx];
+
+ // Check if provided index matches with a supported 2.4GHz channel
+ sband = wiphy->bands[NL80211_BAND_2GHZ];
+ if (sband && idx >= sband->n_channels) {
+ idx -= sband->n_channels;
+ sband = NULL;
+ }
+
+ if (aicwf_hw->band_5g_support) {
+ if (!sband) {
+ // Check if provided index matches with a supported 5GHz channel
+ sband = wiphy->bands[NL80211_BAND_5GHZ];
+
+ if (!sband || idx >= sband->n_channels)
+ return -ENOENT;
+ }
+ } else {
+ if (!sband || idx >= sband->n_channels)
+ return -ENOENT;
+ }
+
+ // Fill the survey
+ info->channel = &sband->channels[idx];
+ info->filled = aicwf_survey->filled;
+
+ if (aicwf_survey->filled != 0) {
+ info->time = (u64)aicwf_survey->chan_time_ms;
+ info->time_busy = (u64)aicwf_survey->chan_time_busy_ms;
+ // info->noise = aicwf_survey->noise_dbm;
+ info->noise =
+ ((IS_2P4GHZ(info->channel->center_freq)) ? DEFAULT_NOISE_FLOOR_2GHZ
+ : (IS_5GHZ(info->channel->center_freq))
+ ? DEFAULT_NOISE_FLOOR_5GHZ
+ : DEFAULT_NOISE_FLOOR_5GHZ);
+
+ // Set the survey report as not used
+ if (info->noise == 0)
+ aicwf_survey->filled = 0;
+ else
+ aicwf_survey->filled |= SURVEY_INFO_NOISE_DBM;
+ }
+
+ return 0;
+}
+
+/*
+ * @get_channel: Get the current operating channel for the virtual interface.
+ * For monitor interfaces, it should return %NULL unless there's a single
+ * current monitoring channel.
+ */
+static int aicwf_cfg80211_get_channel(struct wiphy *wiphy,
+ struct wireless_dev *wdev,
+ unsigned int link_id,
+ struct cfg80211_chan_def *chandef)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = container_of(wdev, struct aicwf_vif, wdev);
+ struct aicwf_chanctx *ctxt;
+
+ if (!aicwf_vif->up)
+ return -ENODATA;
+
+ if (aicwf_vif->vif_index == aicwf_hw->monitor_vif)
+ // retrieve channel from firmware
+ aicwf_cfg80211_set_monitor_channel(wiphy, aicwf_vif->ndev, NULL);
+
+ // Check if channel context is valid
+ if (!aicwf_chanctx_valid(aicwf_hw, aicwf_vif->ch_index))
+ return -ENODATA;
+
+ ctxt = &aicwf_hw->chanctx_table[aicwf_vif->ch_index];
+ *chandef = ctxt->chan_def;
+ return 0;
+}
+
+/*
+ * @mgmt_tx: Transmit a management frame.
+ */
+
+static int aicwf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
+ struct cfg80211_mgmt_tx_params *params,
+ u64 cookie)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif =
+ container_of(wdev, struct aicwf_vif, wdev); // netdev_priv(wdev->netdev);
+ struct aicwf_sta *aicwf_sta;
+ struct ieee80211_channel *channel = params->chan;
+ const u8 *buf = params->buf;
+ struct ieee80211_mgmt *mgmt = (void *)buf;
+ bool ap = false;
+ bool offchan = false;
+
+ /* Check if provided VIF is an AP or a STA one */
+ switch (AICWF_VIF_TYPE(aicwf_vif)) {
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ case NL80211_IFTYPE_AP_VLAN:
+ aicwf_vif = aicwf_vif->ap_vlan.master;
+ fallthrough;
+ case NL80211_IFTYPE_AP:
+ case NL80211_IFTYPE_P2P_GO:
+ case NL80211_IFTYPE_MESH_POINT:
+ ap = true;
+ break;
+ case NL80211_IFTYPE_P2P_CLIENT:
+#endif
+ case NL80211_IFTYPE_STATION:
+ default:
+ break;
+ }
+
+ /* Get STA on which management frame has to be sent */
+ aicwf_sta =
+ aicwf_retrieve_sta(aicwf_hw, aicwf_vif, mgmt->da, mgmt->frame_control, ap);
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_mgmt_tx((channel) ? channel->center_freq : 0, aicwf_vif->vif_index,
+ (aicwf_sta) ? aicwf_sta->sta_idx : 0xFF, mgmt);
+#endif
+ if (ap || aicwf_sta)
+ goto send_frame;
+
+ /* Not an AP interface sending frame to unknown STA:
+ * This is allowed for external authetication
+ */
+ if (aicwf_vif->sta.external_auth && ieee80211_is_auth(mgmt->frame_control))
+ goto send_frame;
+
+ /* Otherwise ROC is needed */
+ if (!channel) {
+ dev_dbg(&wiphy->dev, "mgmt_tx fail since channel\n");
+ return -EINVAL;
+ }
+
+ /* Check that a RoC is already pending */
+ if (aicwf_hw->roc_elem) {
+ /* Get VIF used for current ROC */
+ struct aicwf_vif *aicwf_roc_vif =
+ container_of(aicwf_hw->roc_elem->wdev, struct aicwf_vif,
+ wdev); // netdev_priv(aicwf_hw->roc_elem->wdev->netdev);
+
+ /* Check if RoC channel is the same than the required one */
+ if (aicwf_hw->roc_elem->chan->center_freq != channel->center_freq ||
+ aicwf_vif->vif_index != aicwf_roc_vif->vif_index) {
+ dev_dbg(&wiphy->dev, "mgmt rx chan invalid: %d, %d",
+ aicwf_hw->roc_elem->chan->center_freq, channel->center_freq);
+ return -EINVAL;
+ }
+ } else {
+ int error;
+
+ dev_dbg(&wiphy->dev, "mgmt rx remain on chan\n");
+
+ /* Start a ROC procedure for 30ms */
+ error = aicwf_cfg80211_remain_on_channel_(wiphy, wdev, channel, 30,
+ cookie, true);
+ if (error) {
+ dev_dbg(&wiphy->dev, "mgmt rx chan err\n");
+ return error;
+ }
+ }
+ offchan = true;
+
+send_frame:
+ return aicwf_start_mgmt_xmit(aicwf_vif, aicwf_sta, params, offchan, cookie);
+}
+
+/*
+ * @start_radar_detection: Start radar detection in the driver.
+ */
+static int __maybe_unused aicwf_cfg80211_start_radar_detection(struct wiphy *wiphy,
+ struct net_device *dev,
+ struct cfg80211_chan_def *chandef,
+ u32 cac_time_ms, int link_id)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct apm_start_cac_cfm cfm;
+
+ aicwf_radar_start_cac(&aicwf_hw->radar, cac_time_ms, aicwf_vif);
+ aicwf_send_apm_start_cac_req(aicwf_hw, aicwf_vif, chandef, &cfm);
+
+ if (cfm.status == CO_OK) {
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_chanctx_link(aicwf_vif, cfm.ch_idx, chandef);
+ if (aicwf_hw->cur_chanctx == aicwf_vif->ch_index)
+ aicwf_radar_detection_enable(&aicwf_hw->radar,
+ AICWF_RADAR_DETECT_REPORT,
+ AICWF_RADAR_RIU);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ } else {
+ return -EIO;
+ }
+ return 0;
+}
+
+/*
+ * @update_ft_ies: Provide updated Fast BSS Transition information to the
+ * driver. If the SME is in the driver/firmware, this information can be
+ * used in building Authentication and Reassociation Request frames.
+ */
+static int aicwf_cfg80211_update_ft_ies(struct wiphy *wiphy, struct net_device *dev,
+ struct cfg80211_update_ft_ies_params *ftie)
+{
+ return 0;
+}
+
+/*
+ * @set_cqm_rssi_config: Configure connection quality monitor RSSI threshold.
+ */
+static int aicwf_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
+ struct net_device *dev,
+ s32 rssi_thold,
+ u32 rssi_hyst)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+
+ return aicwf_send_cfg_rssi_req(aicwf_hw, aicwf_vif->vif_index, rssi_thold,
+ rssi_hyst);
+}
+
+/*
+ *
+ * @channel_switch: initiate channel-switch procedure (with CSA). Driver is
+ * responsible for veryfing if the switch is possible. Since this is
+ * inherently tricky driver may decide to disconnect an interface later
+ * with cfg80211_stop_iface(). This doesn't mean driver can accept
+ * everything. It should do it's best to verify requests and reject them
+ * as soon as possible.
+ */
+static int __maybe_unused aicwf_cfg80211_channel_switch(struct wiphy *wiphy,
+ struct net_device *dev,
+ struct cfg80211_csa_settings *params)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *vif = netdev_priv(dev);
+ struct aicwf_bcn *bcn, *bcn_after;
+ struct aicwf_csa *csa;
+ u16 csa_oft[BCN_MAX_CSA_CPT];
+ u8 *buf;
+ int i, error = 0;
+
+ if (vif->ap.csa)
+ return -EBUSY;
+
+ if (params->n_counter_offsets_beacon > BCN_MAX_CSA_CPT)
+ return -EINVAL;
+
+ /* Build the new beacon with CSA IE */
+ bcn = &vif->ap.bcn;
+ buf = aicwf_build_bcn(bcn, ¶ms->beacon_csa);
+ if (!buf)
+ return -ENOMEM;
+
+ memset(csa_oft, 0, sizeof(csa_oft));
+ for (i = 0; i < params->n_counter_offsets_beacon; i++)
+ csa_oft[i] =
+ params->counter_offsets_beacon[i] + bcn->head_len + bcn->tim_len;
+
+ /* If count is set to 0 (i.e anytime after this beacon) force it to 2 */
+ if (params->count == 0) {
+ params->count = 2;
+ for (i = 0; i < params->n_counter_offsets_beacon; i++)
+ buf[csa_oft[i]] = 2;
+ }
+
+ error = aicwf_send_bcn(aicwf_hw, buf, vif->vif_index, bcn->len);
+ if (error)
+ goto end;
+
+ /* Build the beacon to use after CSA. It will only be sent to fw once
+ * CSA is over, but do it before sending the beacon as it must be ready
+ * when CSA is finished.
+ */
+ csa = kzalloc_obj(*csa, GFP_KERNEL);
+ if (!csa) {
+ error = -ENOMEM;
+ goto end;
+ }
+
+ bcn_after = &csa->bcn;
+ buf = aicwf_build_bcn(bcn_after, ¶ms->beacon_after);
+ if (!buf) {
+ error = -ENOMEM;
+ aicwf_del_csa(vif);
+ goto end;
+ }
+
+ error = aicwf_send_bcn(aicwf_hw, buf, vif->vif_index, bcn_after->len);
+ if (error)
+ goto end;
+
+ vif->ap.csa = csa;
+ csa->vif = vif;
+ csa->chandef = params->chandef;
+
+ /* Send new Beacon. FW will extract channel and count from the beacon */
+ error = aicwf_send_bcn_change(aicwf_hw, vif->vif_index, 0, bcn->len,
+ bcn->head_len, bcn->tim_len, csa_oft);
+
+ if (error) {
+ aicwf_del_csa(vif);
+ goto end;
+ } else {
+ INIT_WORK(&csa->work, aicwf_csa_finish);
+ cfg80211_ch_switch_started_notify(dev, &csa->chandef, 0, params->count,
+ false);
+ }
+end:
+ return error;
+}
+
+/*
+ * @tdls_oper: execute TDLS operation
+ */
+static int __maybe_unused aicwf_cfg80211_tdls_oper(struct wiphy *wiphy,
+ struct net_device *dev,
+ const u8 *peer, enum nl80211_tdls_operation oper)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ int error;
+
+ if (oper != NL80211_TDLS_DISABLE_LINK)
+ return 0;
+
+ if (!aicwf_vif->sta.tdls_sta) {
+ dev_dbg(&wiphy->dev, "tdls station %pM does not exist\n", peer);
+ return -ENOLINK;
+ }
+
+ if (memcmp(aicwf_vif->sta.tdls_sta->mac_addr, peer, ETH_ALEN) == 0) {
+ /* Disable Channel Switch */
+ if (!aicwf_send_tdls_cancel_chan_switch_req(aicwf_hw, aicwf_vif,
+ aicwf_vif->sta.tdls_sta, NULL))
+ aicwf_vif->sta.tdls_sta->tdls.chsw_en = false;
+
+ netdev_info(dev, "del TDLS sta %d %pM\n",
+ aicwf_vif->sta.tdls_sta->sta_idx,
+ aicwf_vif->sta.tdls_sta->mac_addr);
+ /* Ensure that we won't process PS change ind */
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_vif->sta.tdls_sta->ps.active = false;
+ aicwf_vif->sta.tdls_sta->valid = false;
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ aicwf_txq_sta_deinit(aicwf_hw, aicwf_vif->sta.tdls_sta);
+ error = aicwf_send_me_sta_del(aicwf_hw,
+ aicwf_vif->sta.tdls_sta->sta_idx,
+ true);
+ if (error != 0 && error != -EPIPE)
+ return error;
+
+#ifdef CONFIG_AICWF_BFMER
+ // Disable Beamformer if supported
+ aicwf_bfmer_report_del(aicwf_hw, aicwf_vif->sta.tdls_sta);
+ aicwf_mu_group_sta_del(aicwf_hw, aicwf_vif->sta.tdls_sta);
+#endif /* CONFIG_AICWF_BFMER */
+
+ /* Set TDLS not active */
+ aicwf_vif->sta.tdls_sta->tdls.active = false;
+ // Remove TDLS station
+ aicwf_vif->tdls_status = TDLS_LINK_IDLE;
+ aicwf_vif->sta.tdls_sta = NULL;
+ }
+
+ return 0;
+}
+
+/*
+ * @tdls_channel_switch: enable TDLS channel switch
+ */
+static int __maybe_unused aicwf_cfg80211_tdls_channel_switch(struct wiphy *wiphy,
+ struct net_device *dev,
+ const u8 *addr, u8 oper_class,
+ struct cfg80211_chan_def *chandef)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_sta *aicwf_sta = aicwf_vif->sta.tdls_sta;
+ struct tdls_chan_switch_cfm cfm;
+ int error;
+
+ if (!aicwf_sta || memcmp(addr, aicwf_sta->mac_addr, ETH_ALEN)) {
+ dev_dbg(&wiphy->dev, "tdls station %pM doesn't exist\n", addr);
+ return -ENOLINK;
+ }
+
+ if (!aicwf_sta->tdls.chsw_allowed) {
+ dev_dbg(&wiphy->dev, "tdls station %pM does not support TDLS channel switch\n", addr);
+ return -EOPNOTSUPP;
+ }
+
+ error = aicwf_send_tdls_chan_switch_req(aicwf_hw, aicwf_vif, aicwf_sta,
+ aicwf_sta->tdls.initiator, oper_class,
+ chandef, &cfm);
+ if (error)
+ return error;
+
+ if (!cfm.status) {
+ aicwf_sta->tdls.chsw_en = true;
+ return 0;
+ }
+ dev_dbg(&wiphy->dev, "tdls channel switch already enabled and only one is supported\n");
+ return -EALREADY;
+}
+
+/*
+ * @tdls_cancel_channel_switch: disable TDLS channel switch
+ */
+static void __maybe_unused
+aicwf_cfg80211_tdls_cancel_channel_switch(struct wiphy *wiphy,
+ struct net_device *dev,
+ const u8 *addr)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_sta *aicwf_sta = aicwf_vif->sta.tdls_sta;
+ struct tdls_cancel_chan_switch_cfm cfm;
+
+ if (!aicwf_sta)
+ return;
+
+ if (!aicwf_send_tdls_cancel_chan_switch_req(aicwf_hw, aicwf_vif, aicwf_sta,
+ &cfm))
+ aicwf_sta->tdls.chsw_en = false;
+}
+
+/*
+ * @change_bss: Modify parameters for a given BSS (mainly for AP mode).
+ */
+static int __maybe_unused aicwf_cfg80211_change_bss(struct wiphy *wiphy,
+ struct net_device *dev,
+ struct bss_parameters *params)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ int res = -EOPNOTSUPP;
+
+ if ((AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_AP ||
+ AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_P2P_GO) &&
+ params->ap_isolate > -1) {
+ if (params->ap_isolate)
+ aicwf_vif->ap.flags |= AICWF_AP_ISOLATE;
+ else
+ aicwf_vif->ap.flags &= ~AICWF_AP_ISOLATE;
+ res = 0;
+ }
+ return res;
+}
+
+static void aicwf_convert_sta_flags(u32 flags, struct station_info *sinfo)
+{
+ struct nl80211_sta_flag_update *sfu;
+
+ sinfo->filled |= BIT(NL80211_STA_INFO_STA_FLAGS);
+ sfu = &sinfo->sta_flags;
+ sfu->mask = BIT(NL80211_STA_FLAG_WME) | BIT(NL80211_STA_FLAG_AUTHORIZED) |
+ BIT(NL80211_STA_FLAG_ASSOCIATED) |
+ BIT(NL80211_STA_FLAG_AUTHENTICATED);
+
+ if (flags == (u32)AICWF_DRV_STATUS_CONNECTED) {
+ sfu->set |= (BIT(NL80211_STA_FLAG_WME) | BIT(NL80211_STA_FLAG_AUTHORIZED) |
+ BIT(NL80211_STA_FLAG_ASSOCIATED) |
+ BIT(NL80211_STA_FLAG_AUTHENTICATED));
+ }
+ sfu->mask |= BIT(NL80211_STA_FLAG_TDLS_PEER);
+ sfu->set &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
+}
+
+static void aicwf_fill_bss_param(struct station_info *sinfo,
+ struct aicwf_vif *vif)
+{
+ u16 capability = 0;
+
+ sinfo->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
+ sinfo->bss_param.beacon_interval =
+ (vif->sta.b_interval > 0) ? vif->sta.b_interval : 100;
+ sinfo->bss_param.dtim_period =
+ (vif->sta.dtim_peroid > 0) ? vif->sta.dtim_peroid : 1;
+
+ capability = vif->sta.capability;
+ if (capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
+ sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
+ if (capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
+ sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
+}
+
+static int aicwf_fill_station_info(struct aicwf_sta *sta, struct aicwf_vif *vif,
+ struct station_info *sinfo)
+{
+ struct aicwf_sta_stats *stats = &sta->stats;
+ struct rx_vector_1 *rx_vect1 = &stats->last_rx.rx_vect1;
+ union aicwf_rate_ctrl_info *rate_info;
+ struct mm_get_sta_info_cfm cfm;
+
+ aicwf_send_get_sta_info_req(vif->aicwf_hw, sta->sta_idx, &cfm);
+ sinfo->tx_failed = cfm.txfailed;
+ rate_info = (union aicwf_rate_ctrl_info *)&cfm.rate_info;
+
+ struct aicwf_hw *aicwf_hw = vif->aicwf_hw;
+
+ if (aicwf_hw)
+ dev_dbg(aicwf_hw->dev,
+ "modTx%d:%d TxIndex:%d ModRx%d:%d RxHTIndex:%d RxVHTIndex:%d RxHEIndex:%d RSSI:%d\n",
+ rate_info->bw_tx, rate_info->format_mod_tx,
+ rate_info->mcs_index_tx, rx_vect1->ch_bw, rx_vect1->format_mod,
+ rx_vect1->ht.mcs, rx_vect1->vht.mcs, rx_vect1->he.mcs,
+ (s8)cfm.rssi);
+
+ switch (rate_info->format_mod_tx) {
+ case FORMATMOD_NON_HT:
+ case FORMATMOD_NON_HT_DUP_OFDM:
+ sinfo->txrate.flags = 0;
+ sinfo->txrate.legacy = tx_legrates_lut_rate[rate_info->mcs_index_tx];
+ break;
+ case FORMATMOD_HT_MF:
+ case FORMATMOD_HT_GF:
+ sinfo->txrate.flags = RATE_INFO_FLAGS_MCS;
+ sinfo->txrate.mcs = rate_info->mcs_index_tx;
+ break;
+ case FORMATMOD_VHT:
+ sinfo->txrate.flags = RATE_INFO_FLAGS_VHT_MCS;
+ sinfo->txrate.mcs = rate_info->mcs_index_tx;
+ break;
+ case FORMATMOD_HE_MU:
+ case FORMATMOD_HE_SU:
+ case FORMATMOD_HE_ER:
+ sinfo->txrate.flags = RATE_INFO_FLAGS_HE_MCS;
+ sinfo->txrate.mcs = rate_info->mcs_index_tx;
+ break;
+ default:
+ return -EINVAL;
+ }
+ switch (rate_info->bw_tx) {
+ case PHY_CHNL_BW_20:
+ sinfo->txrate.bw = RATE_INFO_BW_20;
+ break;
+ case PHY_CHNL_BW_40:
+ sinfo->txrate.bw = RATE_INFO_BW_40;
+ break;
+ case PHY_CHNL_BW_80:
+ sinfo->txrate.bw = RATE_INFO_BW_80;
+ break;
+ case PHY_CHNL_BW_160:
+ sinfo->txrate.bw = RATE_INFO_BW_160;
+ break;
+ default:
+ sinfo->txrate.bw = RATE_INFO_BW_HE_RU;
+ break;
+ }
+
+ sinfo->txrate.nss = 1;
+ sinfo->filled |=
+ (BIT(NL80211_STA_INFO_TX_BITRATE) | BIT(NL80211_STA_INFO_TX_FAILED));
+
+ if (AICWF_VIF_TYPE(vif) == NL80211_IFTYPE_STATION ||
+ AICWF_VIF_TYPE(vif) == NL80211_IFTYPE_P2P_CLIENT) {
+ sinfo->connected_time =
+ jiffies_to_msecs(jiffies - vif->sta.link_time) / 1000;
+ sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME);
+ }
+
+ sinfo->inactive_time =
+ jiffies_to_msecs(jiffies - vif->aicwf_hw->stats.last_tx);
+ sinfo->rx_bytes = vif->net_stats.rx_bytes;
+ sinfo->tx_bytes = vif->net_stats.tx_bytes;
+ sinfo->tx_packets = vif->net_stats.tx_packets;
+ sinfo->rx_packets = vif->net_stats.rx_packets;
+ sinfo->signal = (s8)cfm.rssi;
+ sinfo->rxrate.nss = 1;
+
+ switch (rx_vect1->ch_bw) {
+ case PHY_CHNL_BW_20:
+ sinfo->rxrate.bw = RATE_INFO_BW_20;
+ break;
+ case PHY_CHNL_BW_40:
+ sinfo->rxrate.bw = RATE_INFO_BW_40;
+ break;
+ case PHY_CHNL_BW_80:
+ sinfo->rxrate.bw = RATE_INFO_BW_80;
+ break;
+ case PHY_CHNL_BW_160:
+ sinfo->rxrate.bw = RATE_INFO_BW_160;
+ break;
+ default:
+ sinfo->rxrate.bw = RATE_INFO_BW_HE_RU;
+ break;
+ }
+
+ switch (rx_vect1->format_mod) {
+ case FORMATMOD_NON_HT:
+ case FORMATMOD_NON_HT_DUP_OFDM:
+ sinfo->rxrate.flags = 0;
+ sinfo->rxrate.legacy = legrates_lut[rx_vect1->leg_rate].rate;
+ break;
+ case FORMATMOD_HT_MF:
+ case FORMATMOD_HT_GF:
+ sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS;
+ if (rx_vect1->ht.short_gi)
+ sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
+ sinfo->rxrate.mcs = rx_vect1->ht.mcs;
+ break;
+ case FORMATMOD_VHT:
+ sinfo->rxrate.flags = RATE_INFO_FLAGS_VHT_MCS;
+ if (rx_vect1->vht.short_gi)
+ sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
+ sinfo->rxrate.mcs = rx_vect1->vht.mcs;
+ break;
+ case FORMATMOD_HE_MU:
+ sinfo->rxrate.he_ru_alloc = rx_vect1->he.ru_size;
+ fallthrough;
+ case FORMATMOD_HE_SU:
+ case FORMATMOD_HE_ER:
+ sinfo->rxrate.flags = RATE_INFO_FLAGS_HE_MCS;
+ sinfo->rxrate.mcs = rx_vect1->he.mcs;
+ sinfo->rxrate.he_gi = rx_vect1->he.gi_type;
+ sinfo->rxrate.he_dcm = rx_vect1->he.dcm;
+ break;
+ default:
+ return -EINVAL;
+ }
+ sinfo->filled |=
+ (BIT(NL80211_STA_INFO_INACTIVE_TIME) |
+ BIT(NL80211_STA_INFO_RX_BYTES64) | BIT(NL80211_STA_INFO_TX_BYTES64) |
+ BIT(NL80211_STA_INFO_RX_PACKETS) | BIT(NL80211_STA_INFO_TX_PACKETS) |
+ BIT(NL80211_STA_INFO_SIGNAL) | BIT(NL80211_STA_INFO_RX_BITRATE));
+ return 0;
+}
+
+/*
+ * @get_station: get station information for the station identified by @mac
+ */
+static int aicwf_cfg80211_get_station(struct wiphy *wiphy,
+ struct wireless_dev *wdev,
+ const u8 *mac,
+ struct station_info *sinfo)
+{
+ struct net_device *dev = wdev->netdev;
+ struct aicwf_vif *vif = netdev_priv(dev);
+ struct aicwf_sta *sta = NULL;
+
+ if (AICWF_VIF_TYPE(vif) == NL80211_IFTYPE_MONITOR) {
+ return -EINVAL;
+ } else if (AICWF_VIF_TYPE(vif) == NL80211_IFTYPE_STATION ||
+ AICWF_VIF_TYPE(vif) == NL80211_IFTYPE_P2P_CLIENT) {
+ if (vif->sta.ap && ether_addr_equal(vif->sta.ap->mac_addr, mac))
+ sta = vif->sta.ap;
+ if (sta) {
+ aicwf_convert_sta_flags((u32)atomic_read(&vif->drv_conn_state),
+ sinfo);
+ aicwf_fill_bss_param(sinfo, vif);
+ return aicwf_fill_station_info(sta, vif, sinfo);
+ }
+ } else {
+ struct aicwf_sta *sta_iter;
+
+ spin_lock_bh(&vif->aicwf_hw->cb_lock);
+ list_for_each_entry(sta_iter, &vif->ap.sta_list, list) {
+ if (sta_iter->valid && ether_addr_equal(sta_iter->mac_addr, mac)) {
+ sta = sta_iter;
+ break;
+ }
+ }
+ spin_unlock_bh(&vif->aicwf_hw->cb_lock);
+ if (sta)
+ return aicwf_fill_station_info(sta, vif, sinfo);
+ }
+
+ return -ENOENT;
+}
+
+/*
+ * @dump_station: dump station callback -- resume dump at index @idx
+ */
+static int aicwf_cfg80211_dump_station(struct wiphy *wiphy,
+ struct wireless_dev *wdev, int idx, u8 *mac,
+ struct station_info *sinfo)
+{
+ struct net_device *dev = wdev->netdev;
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_sta *sta_iter, *sta = NULL;
+ struct mesh_peer_info_cfm peer_info_cfm;
+ struct cfg80211_bss *bss = NULL;
+ const struct cfg80211_bss_ies *ies;
+ const u8 *tim = NULL;
+ int i = 0;
+
+ if (AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_STATION ||
+ AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_P2P_CLIENT) {
+ if (idx == 0) {
+ bss = cfg80211_get_bss(wiphy, NULL, aicwf_vif->sta.bssid,
+ aicwf_vif->sta.ssid, aicwf_vif->sta.ssid_len,
+ dev->ieee80211_ptr->conn_bss_type,
+ IEEE80211_PRIVACY_ANY);
+ if (bss) {
+ aicwf_vif->sta.capability = bss->capability;
+ aicwf_vif->sta.b_interval = bss->beacon_interval;
+ rcu_read_lock();
+ ies = rcu_dereference(bss->beacon_ies);
+ if (ies && ies->len > 0) {
+ tim = cfg80211_find_ie(WLAN_EID_TIM,
+ ies->data, ies->len);
+ if (tim && tim[1] >= 2)
+ aicwf_vif->sta.dtim_peroid = *(tim + 3);
+ }
+ rcu_read_unlock();
+ cfg80211_put_bss(wiphy, bss);
+ }
+ memcpy(mac, aicwf_vif->sta.bssid, ETH_ALEN);
+ return aicwf_cfg80211_get_station(wiphy, wdev, mac, sinfo);
+ }
+ return -ENOENT;
+ }
+
+ if (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ list_for_each_entry(sta_iter, &aicwf_vif->ap.sta_list, list) {
+ if (i < idx) {
+ i++;
+ continue;
+ }
+ sta = sta_iter;
+ break;
+ }
+
+ if (!sta)
+ return -ENOENT;
+
+ /* Forward the information to the UMAC */
+ if (aicwf_send_mesh_peer_info_req(aicwf_hw, aicwf_vif, sta->sta_idx,
+ &peer_info_cfm))
+ return -ENOMEM;
+
+ /* Copy peer MAC address */
+ memcpy(mac, &sta->mac_addr, ETH_ALEN);
+
+ /* Fill station information */
+ sinfo->llid = peer_info_cfm.local_link_id;
+ sinfo->plid = peer_info_cfm.peer_link_id;
+ sinfo->plink_state = peer_info_cfm.link_state;
+ sinfo->local_pm = peer_info_cfm.local_ps_mode;
+ sinfo->peer_pm = peer_info_cfm.peer_ps_mode;
+ sinfo->nonpeer_pm = peer_info_cfm.non_peer_ps_mode;
+ sinfo->filled =
+ (BIT(NL80211_STA_INFO_LLID) | BIT(NL80211_STA_INFO_PLID) |
+ BIT(NL80211_STA_INFO_PLINK_STATE) | BIT(NL80211_STA_INFO_LOCAL_PM) |
+ BIT(NL80211_STA_INFO_PEER_PM) | BIT(NL80211_STA_INFO_NONPEER_PM));
+
+ return 0;
+}
+
+/*
+ * @add_mpath: add a fixed mesh path
+ */
+static int __maybe_unused aicwf_cfg80211_add_mpath(struct wiphy *wiphy,
+ struct net_device *dev,
+ const u8 *dst, const u8 *next_hop)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct mesh_path_update_cfm cfm;
+
+ if (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ return aicwf_send_mesh_path_update_req(aicwf_hw, aicwf_vif, dst, next_hop,
+ &cfm);
+}
+
+/*
+ * @del_mpath: delete a given mesh path
+ */
+static int __maybe_unused aicwf_cfg80211_del_mpath(struct wiphy *wiphy,
+ struct net_device *dev,
+ const u8 *dst)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct mesh_path_update_cfm cfm;
+
+ if (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ return aicwf_send_mesh_path_update_req(aicwf_hw, aicwf_vif, dst, NULL, &cfm);
+}
+
+/*
+ * @change_mpath: change a given mesh path
+ */
+static int __maybe_unused aicwf_cfg80211_change_mpath(struct wiphy *wiphy,
+ struct net_device *dev,
+ const u8 *dst, const u8 *next_hop)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct mesh_path_update_cfm cfm;
+
+ if (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ return aicwf_send_mesh_path_update_req(aicwf_hw, aicwf_vif,
+ dst, next_hop, &cfm);
+}
+
+/*
+ * @get_mpath: get a mesh path for the given parameters
+ */
+static int __maybe_unused aicwf_cfg80211_get_mpath(struct wiphy *wiphy,
+ struct net_device *dev,
+ u8 *dst, u8 *next_hop,
+ struct mpath_info *pinfo)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_mesh_path *mesh_path = NULL;
+ struct aicwf_mesh_path *cur;
+
+ if (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ list_for_each_entry(cur, &aicwf_vif->ap.mpath_list, list) {
+ /*
+ * Compare the path target address and the provided destination address
+ */
+ if (memcmp(dst, &cur->tgt_mac_addr, ETH_ALEN))
+ continue;
+
+ mesh_path = cur;
+ break;
+ }
+
+ if (!mesh_path)
+ return -ENOENT;
+
+ /* Copy next HOP MAC address */
+ if (mesh_path->p_nhop_sta)
+ memcpy(next_hop, &mesh_path->p_nhop_sta->mac_addr, ETH_ALEN);
+
+ /* Fill path information */
+ pinfo->filled = 0;
+ pinfo->generation = aicwf_vif->ap.generation;
+
+ return 0;
+}
+
+/*
+ * @dump_mpath: dump mesh path callback -- resume dump at index @idx
+ */
+static int __maybe_unused aicwf_cfg80211_dump_mpath(struct wiphy *wiphy,
+ struct net_device *dev,
+ int idx, u8 *dst, u8 *next_hop,
+ struct mpath_info *pinfo)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_mesh_path *mesh_path = NULL;
+ struct aicwf_mesh_path *cur;
+ int i = 0;
+
+ if (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ list_for_each_entry(cur, &aicwf_vif->ap.mpath_list, list) {
+ if (i < idx) {
+ i++;
+ continue;
+ }
+
+ mesh_path = cur;
+ break;
+ }
+
+ if (!mesh_path)
+ return -ENOENT;
+
+ /* Copy target and next hop MAC address */
+ memcpy(dst, &mesh_path->tgt_mac_addr, ETH_ALEN);
+ if (mesh_path->p_nhop_sta)
+ memcpy(next_hop, &mesh_path->p_nhop_sta->mac_addr, ETH_ALEN);
+
+ /* Fill path information */
+ pinfo->filled = 0;
+ pinfo->generation = aicwf_vif->ap.generation;
+
+ return 0;
+}
+
+/*
+ * @get_mpp: get a mesh proxy path for the given parameters
+ */
+static int __maybe_unused aicwf_cfg80211_get_mpp(struct wiphy *wiphy,
+ struct net_device *dev,
+ u8 *dst, u8 *mpp, struct mpath_info *pinfo)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_mesh_proxy *mesh_proxy = NULL;
+ struct aicwf_mesh_proxy *cur;
+
+ if (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ list_for_each_entry(cur, &aicwf_vif->ap.proxy_list, list) {
+ if (cur->local)
+ continue;
+
+ /*
+ * Compare the path target address and the provided destination address
+ */
+ if (memcmp(dst, &cur->ext_sta_addr, ETH_ALEN))
+ continue;
+
+ mesh_proxy = cur;
+ break;
+ }
+
+ if (!mesh_proxy)
+ return -ENOENT;
+
+ memcpy(mpp, &mesh_proxy->proxy_addr, ETH_ALEN);
+
+ /* Fill path information */
+ pinfo->filled = 0;
+ pinfo->generation = aicwf_vif->ap.generation;
+
+ return 0;
+}
+
+/*
+ * @dump_mpp: dump mesh proxy path callback -- resume dump at index @idx
+ */
+static int __maybe_unused aicwf_cfg80211_dump_mpp(struct wiphy *wiphy,
+ struct net_device *dev,
+ int idx, u8 *dst, u8 *mpp,
+ struct mpath_info *pinfo)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_mesh_proxy *mesh_proxy = NULL;
+ struct aicwf_mesh_proxy *cur;
+ int i = 0;
+
+ if (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ list_for_each_entry(cur, &aicwf_vif->ap.proxy_list, list) {
+ if (cur->local)
+ continue;
+
+ if (i < idx) {
+ i++;
+ continue;
+ }
+
+ mesh_proxy = cur;
+ break;
+ }
+
+ if (!mesh_proxy)
+ return -ENOENT;
+
+ /* Copy target MAC address */
+ memcpy(dst, &mesh_proxy->ext_sta_addr, ETH_ALEN);
+ memcpy(mpp, &mesh_proxy->proxy_addr, ETH_ALEN);
+
+ /* Fill path information */
+ pinfo->filled = 0;
+ pinfo->generation = aicwf_vif->ap.generation;
+
+ return 0;
+}
+
+/*
+ * @get_mesh_config: Get the current mesh configuration
+ */
+static int __maybe_unused aicwf_cfg80211_get_mesh_config(struct wiphy *wiphy,
+ struct net_device *dev,
+ struct mesh_config *conf)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+
+ if (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ return 0;
+}
+
+/*
+ * @update_mesh_config: Update mesh parameters on a running mesh.
+ */
+static int __maybe_unused aicwf_cfg80211_update_mesh_config(struct wiphy *wiphy,
+ struct net_device *dev, u32 mask,
+ const struct mesh_config *nconf)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct mesh_update_cfm cfm;
+ int status;
+
+ if (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ if (mask & CO_BIT(NL80211_MESHCONF_POWER_MODE - 1)) {
+ aicwf_vif->ap.next_mesh_pm = nconf->power_mode;
+
+ if (!list_empty(&aicwf_vif->ap.sta_list)) {
+ // If there are mesh links we don't want to update the power mode
+ // It will be updated with aicwf_update_mesh_power_mode() when the
+ // ps mode of a link is updated or when a new link is added/removed
+ mask &= ~BIT(NL80211_MESHCONF_POWER_MODE - 1);
+
+ if (!mask)
+ return 0;
+ }
+ }
+
+ status = aicwf_send_mesh_update_req(aicwf_hw, aicwf_vif, mask, nconf, &cfm);
+
+ if (!status && cfm.status != 0)
+ status = -EINVAL;
+
+ return status;
+}
+
+/*
+ * @join_mesh: join the mesh network with the specified parameters
+ * (invoked with the wireless_dev mutex held)
+ */
+static int __maybe_unused aicwf_cfg80211_join_mesh(struct wiphy *wiphy,
+ struct net_device *dev,
+ const struct mesh_config *conf,
+ const struct mesh_setup *setup)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct mesh_start_cfm mesh_start_cfm;
+ int error = 0;
+ u8 txq_status = 0;
+ /* STA for BC/MC traffic */
+ struct aicwf_sta *sta;
+
+ if (AICWF_VIF_TYPE(aicwf_vif) != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ /* Forward the information to the UMAC */
+ error = aicwf_send_mesh_start_req(aicwf_hw, aicwf_vif, conf, setup,
+ &mesh_start_cfm);
+ if (error)
+ return error;
+
+ /* Check the status */
+ switch (mesh_start_cfm.status) {
+ case CO_OK:
+ aicwf_vif->ap.bcmc_index = mesh_start_cfm.bcmc_idx;
+ aicwf_vif->ap.flags = 0;
+ aicwf_vif->use_4addr = true;
+ aicwf_vif->user_mpm = setup->user_mpm;
+
+ sta = &aicwf_hw->sta_table[mesh_start_cfm.bcmc_idx];
+ sta->valid = true;
+ sta->aid = 0;
+ sta->sta_idx = mesh_start_cfm.bcmc_idx;
+ sta->ch_idx = mesh_start_cfm.ch_idx;
+ sta->vif_idx = aicwf_vif->vif_index;
+ sta->qos = true;
+ sta->acm = 0;
+ sta->ps.active = false;
+ aicwf_mu_group_sta_init(sta, NULL);
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_chanctx_link(aicwf_vif, mesh_start_cfm.ch_idx,
+ (struct cfg80211_chan_def *)(&setup->chandef));
+
+ if (aicwf_hw->cur_chanctx != mesh_start_cfm.ch_idx)
+ txq_status = AICWF_TXQ_STOP_CHAN;
+
+ aicwf_txq_vif_init(aicwf_hw, aicwf_vif, txq_status);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+
+ netif_tx_start_all_queues(dev);
+ netif_carrier_on(dev);
+
+ /* If the AP channel is already the active, we probably skip radar
+ * activation on MM_CHANNEL_SWITCH_IND (unless another vif use this
+ * ctxt). In anycase retest if radar detection must be activated
+ */
+ if (aicwf_hw->cur_chanctx == mesh_start_cfm.ch_idx)
+ aicwf_radar_detection_enable_on_cur_channel(aicwf_hw);
+
+ break;
+
+ case CO_BUSY:
+ error = -EINPROGRESS;
+ break;
+
+ default:
+ error = -EIO;
+ break;
+ }
+
+ /* Print information about the operation */
+ if (error)
+ netdev_info(dev, "failed to start MP %d\n", error);
+ else
+ netdev_info(dev, "mp started: ch=%d, bcmc_idx=%d\n", aicwf_vif->ch_index,
+ aicwf_vif->ap.bcmc_index);
+
+ return error;
+}
+
+/*
+ * @leave_mesh: leave the current mesh network
+ * (invoked with the wireless_dev mutex held)
+ */
+static int __maybe_unused aicwf_cfg80211_leave_mesh(struct wiphy *wiphy,
+ struct net_device *dev)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct mesh_stop_cfm mesh_stop_cfm;
+ int error = 0;
+
+ error = aicwf_send_mesh_stop_req(aicwf_hw, aicwf_vif, &mesh_stop_cfm);
+
+ if (error == 0) {
+ /* Check the status */
+ switch (mesh_stop_cfm.status) {
+ case CO_OK:
+ spin_lock_bh(&aicwf_hw->cb_lock);
+ aicwf_chanctx_unlink(aicwf_vif);
+ aicwf_radar_cancel_cac(&aicwf_hw->radar);
+ spin_unlock_bh(&aicwf_hw->cb_lock);
+ /* delete BC/MC STA */
+ aicwf_txq_vif_deinit(aicwf_hw, aicwf_vif);
+ aicwf_del_bcn(&aicwf_vif->ap.bcn);
+
+ netif_tx_stop_all_queues(dev);
+ netif_carrier_off(dev);
+
+ break;
+
+ default:
+ error = -EIO;
+ break;
+ }
+ }
+
+ if (error)
+ netdev_info(dev, "failed to stop MP\n");
+ else
+ netdev_info(dev, "mp stopped\n");
+
+ return 0;
+}
+
+static struct cfg80211_ops aicwf_cfg80211_ops = {
+ .add_virtual_intf = aicwf_cfg80211_add_iface,
+ .del_virtual_intf = aicwf_cfg80211_del_iface,
+ .change_virtual_intf = aicwf_cfg80211_change_iface,
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ .start_p2p_device = aicwf_cfgp2p_start_p2p_device,
+ .stop_p2p_device = aicwf_cfgp2p_stop_p2p_device,
+#endif
+ .scan = aicwf_cfg80211_scan,
+ .connect = aicwf_cfg80211_connect,
+ .disconnect = aicwf_cfg80211_disconnect,
+ .add_key = aicwf_cfg80211_add_key,
+ .get_key = aicwf_cfg80211_get_key,
+ .del_key = aicwf_cfg80211_del_key,
+ .set_default_key = aicwf_cfg80211_set_default_key,
+ .set_default_mgmt_key = aicwf_cfg80211_set_default_mgmt_key,
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ .add_station = aicwf_cfg80211_add_station,
+ .del_station = aicwf_cfg80211_del_station,
+#endif
+ .change_station = aicwf_cfg80211_change_station,
+ .mgmt_tx = aicwf_cfg80211_mgmt_tx,
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ .start_ap = aicwf_cfg80211_start_ap,
+ .change_beacon = aicwf_cfg80211_change_beacon,
+ .stop_ap = aicwf_cfg80211_stop_ap,
+ .set_monitor_channel = aicwf_cfg80211_set_monitor_channel,
+#endif
+ // .mgmt_frame_register = aicwf_cfg80211_mgmt_frame_register,
+ /*
+ * unused interface
+ */
+ .set_wiphy_params = aicwf_cfg80211_set_wiphy_params,
+ .set_txq_params = aicwf_cfg80211_set_txq_params,
+ .set_tx_power = aicwf_cfg80211_set_tx_power,
+ // .get_tx_power = aicwf_cfg80211_get_tx_power,
+ .get_station = aicwf_cfg80211_get_station,
+ .dump_station = aicwf_cfg80211_dump_station,
+ .remain_on_channel = aicwf_cfg80211_remain_on_channel,
+ .cancel_remain_on_channel = aicwf_cfg80211_cancel_remain_on_channel,
+ .dump_survey = aicwf_cfg80211_dump_survey,
+ .get_channel = aicwf_cfg80211_get_channel,
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ .start_radar_detection = aicwf_cfg80211_start_radar_detection,
+#endif
+ .update_ft_ies = aicwf_cfg80211_update_ft_ies,
+ .set_cqm_rssi_config = aicwf_cfg80211_set_cqm_rssi_config,
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ .channel_switch = aicwf_cfg80211_channel_switch,
+ .tdls_channel_switch = aicwf_cfg80211_tdls_channel_switch,
+ .tdls_cancel_channel_switch = aicwf_cfg80211_tdls_cancel_channel_switch,
+ //.tdls_mgmt = aicwf_cfg80211_tdls_mgmt,
+ /*
+ * unused interface
+ */
+ .tdls_oper = aicwf_cfg80211_tdls_oper,
+ .change_bss = aicwf_cfg80211_change_bss,
+#endif
+ .external_auth = aicwf_cfg80211_external_auth,
+#ifdef CONFIG_AIC8800_SCHED_SCAN
+ .sched_scan_start = aicwf_cfg80211_sched_scan_start,
+ .sched_scan_stop = aicwf_cfg80211_sched_scan_stop,
+#endif
+};
+
+/*********************************************************************
+ * Init/Exit functions
+ *********************************************************************/
+static void aicwf_wdev_unregister(struct aicwf_hw *aicwf_hw)
+{
+ struct aicwf_vif *aicwf_vif, *tmp;
+
+ /* RX must not queue APM work again while interfaces are being removed. */
+ disable_work_sync(&aicwf_hw->apm_staloss_work);
+ timer_shutdown_sync(&aicwf_hw->p2p_alive_timer);
+ rtnl_lock();
+ /* ndo_stop still needs TX, RX and firmware confirmations. */
+ cfg80211_shutdown_all_interfaces(aicwf_hw->wiphy);
+ wiphy_lock(aicwf_hw->wiphy);
+ aicwf_sdio_quiesce(aicwf_hw->sdiodev);
+ aicwf_platform_off(aicwf_hw, NULL);
+ aicwf_cmd_mgr_deinit(aicwf_hw->cmd_mgr);
+ list_for_each_entry_safe(aicwf_vif, tmp, &aicwf_hw->vifs, list)
+ aicwf_cfg80211_del_iface(aicwf_hw->wiphy, &aicwf_vif->wdev);
+ wiphy_unlock(aicwf_hw->wiphy);
+ rtnl_unlock();
+}
+
+static void aicwf_set_vers(struct aicwf_hw *aicwf_hw)
+{
+ u32 vers = aicwf_hw->version_cfm.version_lmac;
+
+ snprintf(aicwf_hw->wiphy->fw_version, sizeof(aicwf_hw->wiphy->fw_version),
+ "%d.%d.%d.%d", (vers & (0xff << 24)) >> 24,
+ (vers & (0xff << 16)) >> 16, (vers & (0xff << 8)) >> 8,
+ (vers & (0xff << 0)) >> 0);
+}
+
+static void aicwf_reg_notifier(struct wiphy *wiphy,
+ struct regulatory_request *request)
+{
+ struct aicwf_hw *aicwf_hw = wiphy_priv(wiphy);
+ int ret;
+
+ /* cfg80211 has already applied the rules to this wiphy's channels. */
+ aicwf_radar_set_domain(&aicwf_hw->radar, request->dfs_region);
+ ret = aicwf_send_me_chan_config_req(aicwf_hw);
+ if (ret)
+ cfg80211_shutdown_all_interfaces(wiphy);
+}
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+static void aicwf_enable_mesh(struct aicwf_hw *aicwf_hw)
+{
+ struct wiphy *wiphy = aicwf_hw->wiphy;
+
+ if (!aicwf_mod_params.mesh)
+ return;
+
+ aicwf_cfg80211_ops.get_station = aicwf_cfg80211_get_station;
+ aicwf_cfg80211_ops.dump_station = aicwf_cfg80211_dump_station;
+ aicwf_cfg80211_ops.add_mpath = aicwf_cfg80211_add_mpath;
+ aicwf_cfg80211_ops.del_mpath = aicwf_cfg80211_del_mpath;
+ aicwf_cfg80211_ops.change_mpath = aicwf_cfg80211_change_mpath;
+ aicwf_cfg80211_ops.get_mpath = aicwf_cfg80211_get_mpath;
+ aicwf_cfg80211_ops.dump_mpath = aicwf_cfg80211_dump_mpath;
+ aicwf_cfg80211_ops.get_mpp = aicwf_cfg80211_get_mpp;
+ aicwf_cfg80211_ops.dump_mpp = aicwf_cfg80211_dump_mpp;
+ aicwf_cfg80211_ops.get_mesh_config = aicwf_cfg80211_get_mesh_config;
+ aicwf_cfg80211_ops.update_mesh_config = aicwf_cfg80211_update_mesh_config;
+ aicwf_cfg80211_ops.join_mesh = aicwf_cfg80211_join_mesh;
+ aicwf_cfg80211_ops.leave_mesh = aicwf_cfg80211_leave_mesh;
+
+ wiphy->flags |= (WIPHY_FLAG_MESH_AUTH | WIPHY_FLAG_IBSS_RSN);
+ wiphy->features |= NL80211_FEATURE_USERSPACE_MPM;
+ wiphy->interface_modes |= BIT(NL80211_IFTYPE_MESH_POINT);
+
+ aicwf_limits[0].types |= BIT(NL80211_IFTYPE_MESH_POINT);
+ aicwf_limits_dfs[0].types |= BIT(NL80211_IFTYPE_MESH_POINT);
+}
+#endif
+
+/*
+ *
+ */
+
+int aicwf_ic_system_init(struct aicwf_hw *aicwf_hw)
+{
+ u32 mem_addr;
+ struct dbg_mem_read_cfm rd_mem_addr_cfm;
+
+ mem_addr = 0x40500000;
+
+ if (aicwf_send_dbg_mem_read_req(aicwf_hw, mem_addr, &rd_mem_addr_cfm))
+ return -1;
+
+ aicwf_hw->chip_id = (u8)(rd_mem_addr_cfm.memdata >> 16);
+
+ if (aicwf_send_dbg_mem_read_req(aicwf_hw, 0x00000020, &rd_mem_addr_cfm)) {
+ dev_err(aicwf_hw->dev, "[0x00000020] rd fail\n");
+ return -1;
+ }
+ aicwf_hw->chip_sub_id = (u8)(rd_mem_addr_cfm.memdata);
+
+ dev_dbg(aicwf_hw->dev, "chip_id=%x, chip_sub_id=%x!!\n", aicwf_hw->chip_id,
+ aicwf_hw->chip_sub_id);
+
+#ifdef CONFIG_OOB
+ int ret;
+
+ ret = aic_chip_ic_system_init(aicwf_hw, &rd_mem_addr_cfm);
+ if (ret) {
+ dev_err(aicwf_hw->dev, "aic_chip_ic_system_init fail: %d\n", ret);
+ return -1;
+ }
+#endif
+
+ if (aicwf_platform_on(aicwf_hw, NULL))
+ return -1;
+ return 0;
+}
+
+int aicwf_ic_rf_init(struct aicwf_hw *aicwf_hw)
+{
+ struct mm_set_rf_calib_cfm cfm;
+ int ret = 0;
+
+ ret = aic_chip_set_rf_config(aicwf_hw, &cfm);
+ if (ret)
+ return -1;
+ return 0;
+}
+
+/**
+ * aicwf_task - Process the TX hardware queues
+ * @data: Driver private data passed to the tasklet
+ */
+static void aicwf_task(unsigned long data)
+{
+ struct aicwf_hw *aicwf_hw = (struct aicwf_hw *)data;
+
+ spin_lock_bh(&aicwf_hw->tx_lock);
+ aicwf_hwq_process_all(aicwf_hw);
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+}
+
+static void aicwf_wakeup_sources_deinit(struct aicwf_hw *aicwf_hw)
+{
+ wakeup_source_unregister(aicwf_hw->ws_tx);
+ wakeup_source_unregister(aicwf_hw->ws_rx);
+ wakeup_source_unregister(aicwf_hw->ws_irqrx);
+ wakeup_source_unregister(aicwf_hw->ws_pwrctrl);
+ wakeup_source_unregister(aicwf_hw->ws_scan);
+ aicwf_hw->ws_tx = NULL;
+ aicwf_hw->ws_rx = NULL;
+ aicwf_hw->ws_irqrx = NULL;
+ aicwf_hw->ws_pwrctrl = NULL;
+ aicwf_hw->ws_scan = NULL;
+}
+
+static int aicwf_wakeup_sources_init(struct aicwf_hw *aicwf_hw)
+{
+ if (!IS_ENABLED(CONFIG_PM_SLEEP))
+ return 0;
+
+ aicwf_hw->ws_tx = wakeup_source_register(aicwf_hw->dev, "aicwf-tx");
+ if (!aicwf_hw->ws_tx)
+ goto err;
+
+ aicwf_hw->ws_rx = wakeup_source_register(aicwf_hw->dev, "aicwf-rx");
+ if (!aicwf_hw->ws_rx)
+ goto err;
+
+ aicwf_hw->ws_irqrx = wakeup_source_register(aicwf_hw->dev, "aicwf-irq-rx");
+ if (!aicwf_hw->ws_irqrx)
+ goto err;
+
+ aicwf_hw->ws_pwrctrl = wakeup_source_register(aicwf_hw->dev, "aicwf-pwrctrl");
+ if (!aicwf_hw->ws_pwrctrl)
+ goto err;
+
+ aicwf_hw->ws_scan = wakeup_source_register(aicwf_hw->dev, "aicwf-scan");
+ if (aicwf_hw->ws_scan)
+ return 0;
+
+err:
+ aicwf_wakeup_sources_deinit(aicwf_hw);
+ return -ENOMEM;
+}
+
+int aicwf_cfg80211_init(struct aicwf_plat *aicwf_plat, void **platform_data)
+{
+ struct aicwf_hw *aicwf_hw;
+ int ret = 0;
+ struct wiphy *wiphy;
+ struct aicwf_vif *vif;
+ int i;
+ struct mm_get_fw_version_cfm fw_version = {};
+ size_t fw_version_len;
+ struct mm_get_mac_addr_cfm mac_addr_cfm __aligned(2) = {};
+ struct mm_set_stack_start_cfm set_start_cfm;
+#ifdef CONFIG_AIC8800_TEMP_COMP
+ struct mm_set_vendor_swconfig_cfm swconfig_cfm;
+#endif
+ /* create a new wiphy for use with cfg80211 */
+ pr_debug("sizeof(struct aicwf_hw):%d\n",
+ (int)sizeof(struct aicwf_hw));
+ wiphy = wiphy_new(&aicwf_cfg80211_ops, sizeof(struct aicwf_hw));
+
+ if (!wiphy) {
+ dev_err(aicwf_platform_get_dev(aicwf_plat),
+ "failed to create new wiphy\n");
+ ret = -ENOMEM;
+ goto err_out;
+ }
+
+ aicwf_hw = wiphy_priv(wiphy);
+ aicwf_hw->wiphy = wiphy;
+ aicwf_hw->plat = aicwf_plat;
+ aicwf_hw->dev = aicwf_platform_get_dev(aicwf_plat);
+ aicwf_hw->sdiodev = aicwf_plat->sdiodev;
+ aicwf_hw->chip_ops = aic_chip_ops_select(aicwf_hw->sdiodev->chipid);
+ aicwf_defrag_init(aicwf_hw);
+ aicwf_plat->sdiodev->aicwf_hw = aicwf_hw;
+ aicwf_hw->cmd_mgr = &aicwf_plat->sdiodev->cmd_mgr;
+ aicwf_hw->mod_params = &aicwf_mod_params;
+ aicwf_plat_userconfig_init(aicwf_hw);
+ aicwf_hw->tcp_pacing_shift = 7;
+ atomic_set(&aicwf_hw->scan_activity_held, 0);
+ spin_lock_init(&aicwf_hw->scan_lock);
+
+#ifdef CONFIG_AIC8800_SCHED_SCAN
+ aicwf_hw->is_sched_scan = false;
+#endif // CONFIG_AIC8800_SCHED_SCAN
+
+ INIT_LIST_HEAD(&aicwf_hw->vifs);
+ mutex_init(&aicwf_hw->reg_lock);
+ init_completion(&aicwf_hw->chan_config_complete);
+ aicwf_hw->tx_power_limit = S8_MAX;
+ mutex_init(&aicwf_hw->mutex);
+ spin_lock_init(&aicwf_hw->tx_lock);
+ spin_lock_init(&aicwf_hw->cb_lock);
+
+ tasklet_init(&aicwf_hw->task, aicwf_task, (unsigned long)aicwf_hw);
+ timer_setup(&aicwf_hw->p2p_alive_timer, aicwf_p2p_alive_timeout, 0);
+
+ INIT_WORK(&aicwf_hw->apm_staloss_work, apm_staloss_work_process);
+ aicwf_hw->apm_staloss_wq = create_singlethread_workqueue("apm_staloss_wq");
+ if (!aicwf_hw->apm_staloss_wq) {
+ dev_err(aicwf_hw->dev, "insufficient memory to create apm_staloss workqueue\n");
+ ret = -ENOMEM;
+ goto err_cache;
+ }
+
+ ret = aicwf_wakeup_sources_init(aicwf_hw);
+ if (ret)
+ goto err_cache;
+ ret = aicwf_init_aic(aicwf_hw);
+ if (ret)
+ goto err_cache;
+
+ ret = aicwf_bus_start(aicwf_hw->sdiodev->bus_if);
+ if (ret)
+ goto err_cache;
+
+ ret = aic_chip_fw_download(aicwf_hw);
+ if (ret)
+ goto err_cache;
+ ret = aicwf_sdio_fw_started(aicwf_hw->sdiodev);
+ if (ret)
+ goto err_cache;
+
+ /* set device pointer for wiphy */
+ set_wiphy_dev(wiphy, aicwf_hw->dev);
+
+ /* Create cache to allocate sw_txhdr */
+ aicwf_hw->sw_txhdr_cache = KMEM_CACHE(aicwf_sw_txhdr, 0);
+ if (!aicwf_hw->sw_txhdr_cache) {
+ wiphy_err(wiphy, "Cannot allocate cache for sw TX header\n");
+ ret = -ENOMEM;
+ goto err_cache;
+ }
+
+ aicwf_hw->vif_started = 0;
+ aicwf_hw->monitor_vif = AICWF_INVALID_VIF;
+ aicwf_hw->adding_sta = false;
+
+ for (i = 0; i < NX_VIRT_DEV_MAX + NX_REMOTE_STA_MAX; i++)
+ aicwf_hw->avail_idx_map |= BIT(i);
+
+ aicwf_hwq_init(aicwf_hw);
+
+#ifdef CONFIG_PREALLOC_TXQ
+ aicwf_hw->txq = aicwf_prealloc_txq_alloc(&aicwf_hw->sdiodev->prealloc_txq,
+ sizeof(struct aicwf_txq) * NX_NB_TXQ);
+ if (!aicwf_hw->txq) {
+ ret = -ENOMEM;
+ goto err_cache;
+ }
+#endif
+
+ for (i = 0; i < NX_NB_TXQ; i++)
+ aicwf_hw->txq[i].idx = TXQ_INACTIVE;
+
+ aicwf_mu_group_init(aicwf_hw);
+
+ /*
+ * Initialize RoC element pointer to NULL, indicate that RoC can be started
+ */
+ aicwf_hw->roc_elem = NULL;
+
+ wiphy->mgmt_stypes = aicwf_default_mgmt_stypes;
+
+ // init ic system
+ ret = aicwf_ic_system_init(aicwf_hw);
+ if (ret)
+ goto err_lmac_reqs;
+
+ ret = aic_chip_set_stack_start(aicwf_hw, &set_start_cfm);
+ if (ret)
+ goto err_lmac_reqs;
+
+ pr_debug("is 5g support = %d, vendor_info = 0x%02X\n",
+ set_start_cfm.is_5g_support, set_start_cfm.vendor_info);
+ aicwf_hw->band_5g_support = set_start_cfm.is_5g_support;
+ aicwf_hw->vendor_info = set_start_cfm.vendor_info;
+
+ ret = aicwf_send_get_fw_version_req(aicwf_hw, &fw_version);
+ if (ret)
+ goto err_lmac_reqs;
+ if (fw_version.fw_version_len > sizeof(fw_version.fw_version)) {
+ dev_err(aicwf_hw->dev, "invalid firmware version length: %u\n",
+ fw_version.fw_version_len);
+ ret = -EBADMSG;
+ goto err_lmac_reqs;
+ }
+ dev_info(aicwf_hw->dev, "firmware version: %.*s\n",
+ (int)fw_version.fw_version_len, fw_version.fw_version);
+ fw_version_len = min_t(size_t, fw_version.fw_version_len,
+ sizeof(wiphy->fw_version) - 1);
+ memcpy(wiphy->fw_version, fw_version.fw_version, fw_version_len);
+ wiphy->fw_version[fw_version_len] = '\0';
+ fw_version_len = min_t(size_t, fw_version.fw_version_len,
+ sizeof(aicwf_hw->fw_version) - 1);
+ memcpy(aicwf_hw->fw_version, fw_version.fw_version, fw_version_len);
+ aicwf_hw->fw_version[fw_version_len] = '\0';
+
+ memcpy(aicwf_hw->he_capa, aicwf_he_capa, sizeof(aicwf_he_capa));
+ aicwf_hw->bands[NL80211_BAND_2GHZ] = aicwf_band_2ghz;
+ memcpy(aicwf_hw->channels_2ghz, aicwf_2ghz_channels,
+ sizeof(aicwf_2ghz_channels));
+ aicwf_hw->bands[NL80211_BAND_2GHZ].channels = aicwf_hw->channels_2ghz;
+ ieee80211_set_sband_iftype_data(&aicwf_hw->bands[NL80211_BAND_2GHZ],
+ aicwf_hw->he_capa);
+ wiphy->bands[NL80211_BAND_2GHZ] = &aicwf_hw->bands[NL80211_BAND_2GHZ];
+ if (aicwf_hw->band_5g_support) {
+ aicwf_hw->bands[NL80211_BAND_5GHZ] = aicwf_band_5ghz;
+ memcpy(aicwf_hw->channels_5ghz, aicwf_5ghz_channels,
+ sizeof(aicwf_5ghz_channels));
+ aicwf_hw->bands[NL80211_BAND_5GHZ].channels = aicwf_hw->channels_5ghz;
+ ieee80211_set_sband_iftype_data(&aicwf_hw->bands[NL80211_BAND_5GHZ],
+ aicwf_hw->he_capa);
+ wiphy->bands[NL80211_BAND_5GHZ] = &aicwf_hw->bands[NL80211_BAND_5GHZ];
+ }
+
+ wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ wiphy->interface_modes |=
+ BIT(NL80211_IFTYPE_AP) |
+ BIT(NL80211_IFTYPE_AP_VLAN) | BIT(NL80211_IFTYPE_P2P_CLIENT) |
+ BIT(NL80211_IFTYPE_P2P_GO) |
+#ifndef CONFIG_AIC8800_USE_P2P0
+ BIT(NL80211_IFTYPE_P2P_DEVICE) |
+#endif
+ BIT(NL80211_IFTYPE_MONITOR);
+#endif
+
+ wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH |
+ WIPHY_FLAG_4ADDR_STATION | WIPHY_FLAG_4ADDR_AP;
+ wiphy->max_num_csa_counters = BCN_MAX_CSA_CPT;
+#endif
+
+ wiphy->max_remain_on_channel_duration = aicwf_hw->mod_params->roc_dur_max;
+ wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
+ NL80211_FEATURE_VIF_TXPOWER;
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN |
+ NL80211_FEATURE_ACTIVE_MONITOR |
+ NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
+#endif
+ wiphy->features |= NL80211_FEATURE_SAE;
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ if (aicwf_mod_params.tdls)
+ /* TDLS support */
+ wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
+ wiphy->iface_combinations = aicwf_combinations;
+ /* -1 not to include combination with radar detection, will be re-added in
+ * aicwf_handle_dynparams if supported
+ */
+ wiphy->n_iface_combinations = ARRAY_SIZE(aicwf_combinations) - 1;
+#endif
+ wiphy->reg_notifier = aicwf_reg_notifier;
+ wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
+ aicwf_enable_wapi(aicwf_hw);
+ wiphy->cipher_suites = aicwf_cipher_suites;
+ wiphy->n_cipher_suites = ARRAY_SIZE(aicwf_cipher_suites);
+ aicwf_hw->ext_capa[0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING;
+ aicwf_hw->ext_capa[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF;
+ wiphy->extended_capabilities = aicwf_hw->ext_capa;
+ wiphy->extended_capabilities_mask = aicwf_hw->ext_capa;
+ wiphy->extended_capabilities_len = ARRAY_SIZE(aicwf_hw->ext_capa);
+
+#ifdef CONFIG_AIC8800_SCHED_SCAN
+ wiphy->max_sched_scan_reqs = 1;
+ wiphy->max_sched_scan_ssids = SCAN_SSID_MAX; // 16;
+ wiphy->max_match_sets = SCAN_SSID_MAX; // 16;
+ wiphy->max_sched_scan_ie_len = 2048;
+#endif // CONFIG_AIC8800_SCHED_SCAN
+
+ // init ic rf
+ ret = aicwf_ic_rf_init(aicwf_hw);
+ if (ret)
+ goto err_lmac_reqs;
+
+ ret = aicwf_send_get_macaddr_req(aicwf_hw, &mac_addr_cfm);
+ if (ret)
+ goto err_lmac_reqs;
+
+ if (is_valid_ether_addr(mac_addr_cfm.mac_addr)) {
+ ether_addr_copy(wiphy->perm_addr, mac_addr_cfm.mac_addr);
+ dev_dbg(aicwf_hw->dev, "using EFUSE MAC address %pM\n",
+ wiphy->perm_addr);
+ } else {
+ eth_random_addr(wiphy->perm_addr);
+ dev_warn(aicwf_hw->dev,
+ "invalid EFUSE MAC address, using random address %pM\n",
+ wiphy->perm_addr);
+ }
+
+ /* Reset FW */
+ ret = aicwf_send_reset(aicwf_hw);
+ if (ret)
+ goto err_lmac_reqs;
+
+#ifdef CONFIG_AIC8800_TEMP_COMP
+ aicwf_send_set_temp_comp_req(aicwf_hw, &swconfig_cfm);
+#endif
+
+ ret = aicwf_send_version_req(aicwf_hw, &aicwf_hw->version_cfm);
+ if (ret)
+ goto err_lmac_reqs;
+ aicwf_set_vers(aicwf_hw);
+
+ ret = aicwf_handle_dynparams(aicwf_hw, aicwf_hw->wiphy);
+ if (ret)
+ goto err_lmac_reqs;
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ aicwf_enable_mesh(aicwf_hw);
+#endif
+ aicwf_radar_detection_init(&aicwf_hw->radar);
+
+ /* Set parameters to firmware */
+ if (!aicwf_hw->chip_ops->limit_by_testmode || !aicwf_hw->testmode) {
+ ret = aicwf_send_me_config_req(aicwf_hw);
+ if (ret)
+ goto err_lmac_reqs;
+ }
+
+ ret = wiphy_register(wiphy);
+ if (ret) {
+ wiphy_err(wiphy, "Could not register wiphy device\n");
+ goto err_register_wiphy;
+ }
+
+ /* Do not expose an interface until the effective limits are confirmed. */
+ wiphy_lock(wiphy);
+ ret = aicwf_send_me_chan_config_req(aicwf_hw);
+ wiphy_unlock(wiphy);
+ if (ret)
+ goto err_add_interface;
+
+ *platform_data = aicwf_hw;
+
+ rtnl_lock();
+
+ /* Add an initial station interface */
+ vif = aicwf_interface_add(aicwf_hw, "wlan%d", NET_NAME_UNKNOWN,
+ NL80211_IFTYPE_STATION, NULL);
+
+ rtnl_unlock();
+
+ if (!vif) {
+ wiphy_err(wiphy, "Failed to instantiate a network device\n");
+ ret = -ENOMEM;
+ goto err_add_interface;
+ }
+
+ pr_debug("new interface create %s\n", vif->ndev->name);
+
+#if defined(CONFIG_AIC8800_USE_P2P0) && \
+ !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+
+ rtnl_lock();
+ /* Add an initial p2p0 interface */
+ vif = aicwf_interface_add(aicwf_hw, "p2p%d", NET_NAME_UNKNOWN,
+ NL80211_IFTYPE_STATION, NULL);
+ if (vif)
+ vif->is_p2p_vif = 1;
+ rtnl_unlock();
+
+ if (!vif) {
+ wiphy_err(wiphy, "Failed to instantiate a network device\n");
+ ret = -ENOMEM;
+ goto err_add_interface;
+ }
+
+ pr_debug("new interface create %s\n", vif->ndev->name);
+ aicwf_hw->is_p2p_alive = 0;
+ aicwf_hw->is_p2p_connected = 0;
+ atomic_set(&aicwf_hw->p2p_alive_timer_count, 0);
+#endif
+
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+ aicwf_hw->started_jiffies = 0;
+ aicwf_hw->temp = 0;
+ aicwf_tp_ctrl_init(aicwf_hw->sdiodev);
+#endif
+
+ return 0;
+
+err_add_interface:
+ aicwf_wdev_unregister(aicwf_hw);
+ wiphy_unregister(aicwf_hw->wiphy);
+err_register_wiphy:
+err_lmac_reqs:
+err_cache:
+ timer_shutdown_sync(&aicwf_hw->p2p_alive_timer);
+ if (aicwf_hw->apm_staloss_wq)
+ disable_work_sync(&aicwf_hw->apm_staloss_work);
+ aicwf_sdio_quiesce(aicwf_hw->sdiodev);
+ aicwf_platform_off(aicwf_hw, NULL);
+ aicwf_cmd_mgr_deinit(aicwf_hw->cmd_mgr);
+ aicwf_defrag_deinit(aicwf_hw);
+ if (aicwf_hw->apm_staloss_wq)
+ destroy_workqueue(aicwf_hw->apm_staloss_wq);
+ kmem_cache_destroy(aicwf_hw->sw_txhdr_cache);
+ aicwf_wakeup_sources_deinit(aicwf_hw);
+ aicwf_plat->sdiodev->aicwf_hw = NULL;
+ wiphy_free(wiphy);
+err_out:
+ return ret;
+}
+
+void aicwf_cfg80211_deinit(struct aicwf_hw *aicwf_hw)
+{
+ struct mm_set_stack_start_cfm set_start_cfm;
+
+ if (aicwf_hw->sdiodev->bus_if->state != BUS_DOWN_ST)
+ aicwf_send_set_stack_start_req(aicwf_hw, 0, 0, 0, 0, &set_start_cfm);
+
+ aicwf_hw->fwlog_en = 0;
+#ifdef CONFIG_AIC8800_TEMP_CONTROL
+ aicwf_tp_ctrl_deinit(aicwf_hw->sdiodev);
+#endif
+
+ aicwf_wdev_unregister(aicwf_hw);
+ wiphy_unregister(aicwf_hw->wiphy);
+ destroy_workqueue(aicwf_hw->apm_staloss_wq);
+ aicwf_defrag_deinit(aicwf_hw);
+ aicwf_radar_detection_deinit(&aicwf_hw->radar);
+ kmem_cache_destroy(aicwf_hw->sw_txhdr_cache);
+ aicwf_wakeup_sources_deinit(aicwf_hw);
+ aicwf_hw->sdiodev->aicwf_hw = NULL;
+ wiphy_free(aicwf_hw->wiphy);
+}
+
+static int __init aicwf_mod_init(void)
+{
+ return aicwf_sdio_register();
+}
+
+static void __exit aicwf_mod_exit(void)
+{
+ aicwf_sdio_exit();
+}
+
+module_init(aicwf_mod_init);
+module_exit(aicwf_mod_exit);
+
+MODULE_DESCRIPTION(RW_DRV_DESCRIPTION);
+MODULE_AUTHOR(RW_DRV_COPYRIGHT " " RW_DRV_AUTHOR);
+MODULE_LICENSE("GPL");
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mesh.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mesh.c
new file mode 100644
index 000000000000..88934428ffdd
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mesh.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief mesh function
+ *
+ ******************************************************************************
+ */
+
+#include "aicwf_mesh.h"
+
+struct aicwf_mesh_proxy *aicwf_get_mesh_proxy_info(struct aicwf_vif *p_aicwf_vif,
+ u8 *p_sta_addr, bool local)
+{
+ struct aicwf_mesh_proxy *p_mesh_proxy = NULL;
+ struct aicwf_mesh_proxy *p_cur_proxy;
+
+ /* Look for proxied devices with provided address */
+ list_for_each_entry(p_cur_proxy, &p_aicwf_vif->ap.proxy_list, list) {
+ if (p_cur_proxy->local != local)
+ continue;
+
+ if (!memcmp(&p_cur_proxy->ext_sta_addr, p_sta_addr, ETH_ALEN)) {
+ p_mesh_proxy = p_cur_proxy;
+ break;
+ }
+ }
+
+ /* Return the found information */
+ return p_mesh_proxy;
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mod_params.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mod_params.c
new file mode 100644
index 000000000000..a9e6eadfc686
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mod_params.c
@@ -0,0 +1,644 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief Set driver configuration defaults
+ *
+ ******************************************************************************
+ */
+#include <linux/rtnetlink.h>
+
+#include "hal_desc.h"
+#include "aicwf_defs.h"
+#include "aicwf_main.h"
+#include "aicwf_tx.h"
+
+#ifdef CONFIG_AICWF_FULLMAC
+#define COMMON_PARAM(name, default) .name = default,
+#define SOFTMAC_PARAM(name, default)
+#define FULLMAC_PARAM(name, default) .name = default,
+#endif /* CONFIG_AICWF_FULLMAC */
+
+struct aicwf_mod_params aicwf_mod_params = {
+ /* common parameters */
+ COMMON_PARAM(ht_on, true)
+ COMMON_PARAM(vht_on, true)
+ COMMON_PARAM(he_on, true)
+ COMMON_PARAM(mcs_map, IEEE80211_VHT_MCS_SUPPORT_0_9)
+ COMMON_PARAM(he_mcs_map, IEEE80211_HE_MCS_SUPPORT_0_11)
+ COMMON_PARAM(he_ul_on, false)
+ COMMON_PARAM(ldpc_on, true)
+ COMMON_PARAM(stbc_on, true)
+ COMMON_PARAM(gf_rx_on, false)
+ COMMON_PARAM(phy_cfg, 2)
+ COMMON_PARAM(uapsd_timeout, 300)
+ COMMON_PARAM(ap_uapsd_on, false)
+ COMMON_PARAM(sgi, true)
+ COMMON_PARAM(sgi80, false)
+ COMMON_PARAM(use_2040, 1)
+ COMMON_PARAM(nss, 1)
+ COMMON_PARAM(amsdu_rx_max, 2)
+ COMMON_PARAM(bfmee, true)
+ COMMON_PARAM(bfmer, false)
+ COMMON_PARAM(mesh, false)
+ COMMON_PARAM(murx, true)
+ COMMON_PARAM(mutx, true)
+ COMMON_PARAM(mutx_on, true)
+ COMMON_PARAM(use_80, false)
+ COMMON_PARAM(roc_dur_max, 500)
+ COMMON_PARAM(listen_itv, 0)
+ COMMON_PARAM(listen_bcmc, true)
+ COMMON_PARAM(lp_clk_ppm, 20)
+ COMMON_PARAM(ps_on, true)
+ COMMON_PARAM(tx_lft, AICWF_TX_LIFETIME_MS)
+ COMMON_PARAM(amsdu_maxnb, NX_TX_PAYLOAD_MAX)
+ // By default, only enable UAPSD for Voice queue (see
+ // IEEE80211_DEFAULT_UAPSD_QUEUE comment)
+ COMMON_PARAM(uapsd_queues, IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
+ COMMON_PARAM(tdls, false)
+ COMMON_PARAM(uf, false)
+ COMMON_PARAM(auto_reply, false)
+ COMMON_PARAM(ftl, "")
+ COMMON_PARAM(dpsm, false)
+
+ /* SOFTMAC only parameters */
+ SOFTMAC_PARAM(mfp_on, false)
+ SOFTMAC_PARAM(gf_on, false)
+ SOFTMAC_PARAM(bwsig_on, true)
+ SOFTMAC_PARAM(dynbw_on, true)
+ SOFTMAC_PARAM(agg_tx, true)
+ SOFTMAC_PARAM(amsdu_force, 2)
+ SOFTMAC_PARAM(rc_probes_on, false)
+ SOFTMAC_PARAM(cmon, true)
+ SOFTMAC_PARAM(hwscan, true)
+ SOFTMAC_PARAM(autobcn, true)
+ SOFTMAC_PARAM(dpsm, true)
+
+ /* FULLMAC only parameters */
+ FULLMAC_PARAM(ant_div, true)
+};
+
+static const int mcs_map_to_rate[4][3] = {
+ [PHY_CHNL_BW_20][IEEE80211_VHT_MCS_SUPPORT_0_7] = 65,
+ [PHY_CHNL_BW_20][IEEE80211_VHT_MCS_SUPPORT_0_8] = 78,
+ [PHY_CHNL_BW_20][IEEE80211_VHT_MCS_SUPPORT_0_9] = 78,
+ [PHY_CHNL_BW_40][IEEE80211_VHT_MCS_SUPPORT_0_7] = 135,
+ [PHY_CHNL_BW_40][IEEE80211_VHT_MCS_SUPPORT_0_8] = 162,
+ [PHY_CHNL_BW_40][IEEE80211_VHT_MCS_SUPPORT_0_9] = 180,
+ [PHY_CHNL_BW_80][IEEE80211_VHT_MCS_SUPPORT_0_7] = 292,
+ [PHY_CHNL_BW_80][IEEE80211_VHT_MCS_SUPPORT_0_8] = 351,
+ [PHY_CHNL_BW_80][IEEE80211_VHT_MCS_SUPPORT_0_9] = 390,
+ [PHY_CHNL_BW_160][IEEE80211_VHT_MCS_SUPPORT_0_7] = 585,
+ [PHY_CHNL_BW_160][IEEE80211_VHT_MCS_SUPPORT_0_8] = 702,
+ [PHY_CHNL_BW_160][IEEE80211_VHT_MCS_SUPPORT_0_9] = 780,
+};
+
+#define MAX_VHT_RATE(map, nss, bw) (mcs_map_to_rate[bw][map] * (nss))
+
+static void aicwf_set_vht_capa(struct aicwf_hw *aicwf_hw, struct wiphy *wiphy)
+{
+ struct ieee80211_supported_band *band_5ghz =
+ wiphy->bands[NL80211_BAND_5GHZ];
+ struct ieee80211_supported_band *band_2ghz =
+ wiphy->bands[NL80211_BAND_2GHZ];
+
+ int i;
+ int nss = aicwf_hw->mod_params->nss;
+ int mcs_map;
+ int mcs_map_max;
+ int bw_max;
+
+ if (!aicwf_hw->mod_params->vht_on)
+ return;
+
+ band_2ghz->vht_cap.vht_supported = true;
+ if (aicwf_hw->mod_params->sgi80)
+ band_2ghz->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
+ if (aicwf_hw->mod_params->stbc_on)
+ band_2ghz->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
+ if (aicwf_hw->mod_params->ldpc_on)
+ band_2ghz->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
+ if (aicwf_hw->mod_params->bfmee) {
+ band_2ghz->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
+ band_2ghz->vht_cap.cap |= 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
+ }
+ if (nss > 1)
+ band_2ghz->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
+
+ // Update the AMSDU max RX size (not shifted as located at offset 0 of the
+ // VHT cap)
+ band_2ghz->vht_cap.cap |= aicwf_hw->mod_params->amsdu_rx_max;
+
+ if (aicwf_hw->mod_params->bfmer) {
+ band_2ghz->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
+ /* Set number of sounding dimensions */
+ band_2ghz->vht_cap.cap |=
+ (nss - 1) << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
+ }
+ if (aicwf_hw->mod_params->murx)
+ band_2ghz->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
+ if (aicwf_hw->mod_params->mutx)
+ band_2ghz->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
+
+ /*
+ * MCS map:
+ * These capabilities are filled according to the configured MCS map.
+ * However currently we have some limitations due to FPGA clock constraints
+ * that prevent always using the range of MCS that is defined by the
+ * parameter:
+ * - in RX, 2SS, we support up to MCS7
+ * - in TX, 2SS, we support up to MCS8
+ */
+ // Get max supported BW
+ if (aicwf_hw->mod_params->use_80)
+ bw_max = PHY_CHNL_BW_80;
+ else if (aicwf_hw->mod_params->use_2040)
+ bw_max = PHY_CHNL_BW_40;
+ else
+ bw_max = PHY_CHNL_BW_20;
+
+ // Check if MCS map should be limited to MCS0_8 due to the standard. Indeed
+ // in BW20, MCS9 is not supported in 1 and 2 SS
+ if (aicwf_hw->mod_params->use_2040)
+ mcs_map_max = IEEE80211_VHT_MCS_SUPPORT_0_9;
+ else
+ mcs_map_max = IEEE80211_VHT_MCS_SUPPORT_0_8;
+
+ mcs_map = min_t(int, aicwf_hw->mod_params->mcs_map, mcs_map_max);
+
+ nss = min_t(int, nss, 16);
+
+ band_2ghz->vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(0);
+ for (i = 0; i < nss; i++) {
+ band_2ghz->vht_cap.vht_mcs.rx_mcs_map |=
+ cpu_to_le16(mcs_map << (i * 2));
+ band_2ghz->vht_cap.vht_mcs.rx_highest =
+ cpu_to_le16(MAX_VHT_RATE(mcs_map, nss, bw_max));
+ mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_7;
+ }
+ for (; i < 8; i++) {
+ band_2ghz->vht_cap.vht_mcs.rx_mcs_map |=
+ cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2));
+ }
+
+ mcs_map = min_t(int, aicwf_hw->mod_params->mcs_map, mcs_map_max);
+ band_2ghz->vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(0);
+ for (i = 0; i < nss; i++) {
+ band_2ghz->vht_cap.vht_mcs.tx_mcs_map |=
+ cpu_to_le16(mcs_map << (i * 2));
+ band_2ghz->vht_cap.vht_mcs.tx_highest =
+ cpu_to_le16(MAX_VHT_RATE(mcs_map, nss, bw_max));
+ mcs_map = min_t(int, aicwf_hw->mod_params->mcs_map,
+ IEEE80211_VHT_MCS_SUPPORT_0_8);
+ }
+ for (; i < 8; i++) {
+ band_2ghz->vht_cap.vht_mcs.tx_mcs_map |=
+ cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2));
+ }
+
+ if (!aicwf_hw->mod_params->use_80) {
+#ifdef CONFIG_VENDOR_AICWF_VHT_NO80
+ band_2ghz->vht_cap.cap |= IEEE80211_VHT_CAP_NOT_SUP_WIDTH_80;
+#endif
+ band_2ghz->vht_cap.cap &= ~IEEE80211_VHT_CAP_SHORT_GI_80;
+ }
+
+ if (aicwf_hw->band_5g_support) {
+ band_5ghz->vht_cap.vht_supported = true;
+ if (aicwf_hw->mod_params->sgi80)
+ band_5ghz->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
+ if (aicwf_hw->mod_params->stbc_on)
+ band_5ghz->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
+ if (aicwf_hw->mod_params->ldpc_on)
+ band_5ghz->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
+ if (aicwf_hw->mod_params->bfmee) {
+ band_5ghz->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
+ band_5ghz->vht_cap.cap |= 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
+ }
+ if (nss > 1)
+ band_5ghz->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
+
+ // Update the AMSDU max RX size (not shifted as located at offset 0 of
+ // the VHT cap)
+ band_5ghz->vht_cap.cap |= aicwf_hw->mod_params->amsdu_rx_max;
+
+ if (aicwf_hw->mod_params->bfmer) {
+ band_5ghz->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
+ /* Set number of sounding dimensions */
+ band_5ghz->vht_cap.cap |=
+ (nss - 1) << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
+ }
+ if (aicwf_hw->mod_params->murx)
+ band_5ghz->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
+ if (aicwf_hw->mod_params->mutx)
+ band_5ghz->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
+
+ /*
+ * MCS map:
+ * This capabilities are filled according to the mcs_map module
+ * parameter. However currently we have some limitations due to FPGA
+ * clock constraints that prevent always using the range of MCS that is
+ * defined by the parameter:
+ * - in RX, 2SS, we support up to MCS7
+ * - in TX, 2SS, we support up to MCS8
+ */
+ // Get max supported BW
+ if (aicwf_hw->mod_params->use_80)
+ bw_max = PHY_CHNL_BW_80;
+ else if (aicwf_hw->mod_params->use_2040)
+ bw_max = PHY_CHNL_BW_40;
+ else
+ bw_max = PHY_CHNL_BW_20;
+
+ // Check if MCS map should be limited to MCS0_8 due to the standard.
+ // Indeed in BW20, MCS9 is not supported in 1 and 2 SS
+ if (aicwf_hw->mod_params->use_2040)
+ mcs_map_max = IEEE80211_VHT_MCS_SUPPORT_0_9;
+ else
+ mcs_map_max = IEEE80211_VHT_MCS_SUPPORT_0_8;
+
+ mcs_map = min_t(int, aicwf_hw->mod_params->mcs_map, mcs_map_max);
+ band_5ghz->vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(0);
+ for (i = 0; i < nss; i++) {
+ band_5ghz->vht_cap.vht_mcs.rx_mcs_map |=
+ cpu_to_le16(mcs_map << (i * 2));
+ band_5ghz->vht_cap.vht_mcs.rx_highest =
+ cpu_to_le16(MAX_VHT_RATE(mcs_map, nss, bw_max));
+ mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_7;
+ }
+ for (; i < 8; i++) {
+ band_5ghz->vht_cap.vht_mcs.rx_mcs_map |=
+ cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2));
+ }
+
+ mcs_map = min_t(int, aicwf_hw->mod_params->mcs_map, mcs_map_max);
+ band_5ghz->vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(0);
+ for (i = 0; i < nss; i++) {
+ band_5ghz->vht_cap.vht_mcs.tx_mcs_map |=
+ cpu_to_le16(mcs_map << (i * 2));
+ band_5ghz->vht_cap.vht_mcs.tx_highest =
+ cpu_to_le16(MAX_VHT_RATE(mcs_map, nss, bw_max));
+ mcs_map = min_t(int, aicwf_hw->mod_params->mcs_map,
+ IEEE80211_VHT_MCS_SUPPORT_0_8);
+ }
+ for (; i < 8; i++) {
+ band_5ghz->vht_cap.vht_mcs.tx_mcs_map |=
+ cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2));
+ }
+
+ if (!aicwf_hw->mod_params->use_80) {
+#ifdef CONFIG_VENDOR_AICWF_VHT_NO80
+ band_5ghz->vht_cap.cap |= IEEE80211_VHT_CAP_NOT_SUP_WIDTH_80;
+#endif
+ band_5ghz->vht_cap.cap &= ~IEEE80211_VHT_CAP_SHORT_GI_80;
+ }
+ }
+}
+
+static void aicwf_set_ht_capa(struct aicwf_hw *aicwf_hw, struct wiphy *wiphy)
+{
+ struct ieee80211_supported_band *band_5ghz =
+ wiphy->bands[NL80211_BAND_5GHZ];
+ struct ieee80211_supported_band *band_2ghz =
+ wiphy->bands[NL80211_BAND_2GHZ];
+ int i;
+ int nss = aicwf_hw->mod_params->nss;
+
+ if (!aicwf_hw->mod_params->ht_on) {
+ band_2ghz->ht_cap.ht_supported = false;
+ if (aicwf_hw->band_5g_support)
+ band_5ghz->ht_cap.ht_supported = false;
+ return;
+ }
+
+ if (aicwf_hw->mod_params->stbc_on)
+ band_2ghz->ht_cap.cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
+ if (aicwf_hw->mod_params->ldpc_on)
+ band_2ghz->ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
+ if (aicwf_hw->mod_params->use_2040) {
+ band_2ghz->ht_cap.mcs.rx_mask[4] = 0x1; /* MCS32 */
+ band_2ghz->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
+ band_2ghz->ht_cap.mcs.rx_highest = cpu_to_le16(135 * nss);
+ } else {
+ band_2ghz->ht_cap.mcs.rx_highest = cpu_to_le16(65 * nss);
+ }
+ if (nss > 1)
+ band_2ghz->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
+
+ // Update the AMSDU max RX size
+ if (aicwf_hw->mod_params->amsdu_rx_max)
+ band_2ghz->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
+
+ if (aicwf_hw->mod_params->sgi) {
+ band_2ghz->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
+ if (aicwf_hw->mod_params->use_2040) {
+ band_2ghz->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
+ band_2ghz->ht_cap.mcs.rx_highest = cpu_to_le16(150 * nss);
+ } else {
+ band_2ghz->ht_cap.mcs.rx_highest = cpu_to_le16(72 * nss);
+ }
+ }
+ if (aicwf_hw->mod_params->gf_rx_on)
+ band_2ghz->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
+
+ nss = min_t(int, nss, IEEE80211_HT_MCS_MASK_LEN);
+
+ for (i = 0; i < nss; i++)
+ band_2ghz->ht_cap.mcs.rx_mask[i] = 0xFF;
+
+ if (aicwf_hw->band_5g_support)
+ band_5ghz->ht_cap = band_2ghz->ht_cap;
+}
+
+static void aicwf_set_he_capa(struct aicwf_hw *aicwf_hw, struct wiphy *wiphy)
+{
+ struct ieee80211_supported_band *band_5ghz =
+ wiphy->bands[NL80211_BAND_5GHZ];
+ struct ieee80211_supported_band *band_2ghz =
+ wiphy->bands[NL80211_BAND_2GHZ];
+ int i;
+ int nss = aicwf_hw->mod_params->nss;
+ struct ieee80211_sta_he_cap *he_cap;
+ int mcs_map;
+
+ if (!aicwf_hw->mod_params->he_on) {
+ band_2ghz->iftype_data = NULL;
+ band_2ghz->n_iftype_data = 0;
+
+ if (aicwf_hw->band_5g_support) {
+ band_5ghz->iftype_data = NULL;
+ band_5ghz->n_iftype_data = 0;
+ }
+ return;
+ }
+ he_cap = &aicwf_hw->he_capa[0].he_cap;
+ he_cap->has_he = true;
+ he_cap->he_cap_elem.mac_cap_info[2] |= IEEE80211_HE_MAC_CAP2_ALL_ACK;
+
+ if (aicwf_hw->mod_params->use_2040) {
+ he_cap->he_cap_elem.phy_cap_info[0] |=
+ IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
+ he_cap->ppe_thres[0] |= 0x10;
+ }
+ if (aicwf_hw->mod_params->use_80) {
+ he_cap->ppe_thres[0] |= 0x20;
+ he_cap->ppe_thres[2] |= 0xc0;
+ he_cap->ppe_thres[3] |= 0x07;
+ }
+ he_cap->he_cap_elem.phy_cap_info[0] |=
+ IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G;
+ if (aicwf_hw->mod_params->ldpc_on) {
+ he_cap->he_cap_elem.phy_cap_info[1] |=
+ IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD;
+ } else {
+ // If no LDPC is supported, we have to limit to MCS0_9, as LDPC is
+ // mandatory for MCS 10 and 11
+ aicwf_hw->mod_params->he_mcs_map = min_t(int, aicwf_hw->mod_params->mcs_map,
+ IEEE80211_HE_MCS_SUPPORT_0_9);
+ }
+ he_cap->he_cap_elem.phy_cap_info[1] |=
+ IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US |
+ IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS;
+
+ he_cap->he_cap_elem.phy_cap_info[2] |=
+ IEEE80211_HE_PHY_CAP2_MIDAMBLE_RX_TX_MAX_NSTS |
+ IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
+ IEEE80211_HE_PHY_CAP2_DOPPLER_RX;
+ if (aicwf_hw->mod_params->stbc_on)
+ he_cap->he_cap_elem.phy_cap_info[2] |=
+ IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ;
+
+ he_cap->he_cap_elem.phy_cap_info[3] |=
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_16_QAM |
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1 |
+ IEEE80211_HE_PHY_CAP3_RX_PARTIAL_BW_SU_IN_20MHZ_MU;
+
+ if (aicwf_hw->mod_params->bfmee) {
+ he_cap->he_cap_elem.phy_cap_info[4] |=
+ IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE;
+ he_cap->he_cap_elem.phy_cap_info[4] |=
+ IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4;
+ }
+ he_cap->he_cap_elem.phy_cap_info[5] |=
+ IEEE80211_HE_PHY_CAP5_NG16_SU_FEEDBACK |
+ IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK;
+ he_cap->he_cap_elem.phy_cap_info[6] |=
+ IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU |
+ IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU |
+ IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMING_FB |
+ IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB |
+ IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT |
+ IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO;
+ he_cap->he_cap_elem.phy_cap_info[7] |=
+ IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI;
+ he_cap->he_cap_elem.phy_cap_info[8] |=
+ IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G;
+ he_cap->he_cap_elem.phy_cap_info[9] |=
+ IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
+ IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
+
+ if (aicwf_hw->chip_ops->is_old_ic) {
+ mcs_map = min_t(int, aicwf_hw->mod_params->he_mcs_map,
+ IEEE80211_HE_MCS_SUPPORT_0_9);
+ } else {
+ mcs_map = aicwf_hw->mod_params->he_mcs_map;
+ }
+
+ memset(&he_cap->he_mcs_nss_supp, 0, sizeof(he_cap->he_mcs_nss_supp));
+
+ nss = min_t(int, nss, 16);
+
+ for (i = 0; i < nss; i++) {
+ __le16 unsup_for_ss =
+ cpu_to_le16(IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
+ he_cap->he_mcs_nss_supp.rx_mcs_80 |= cpu_to_le16(mcs_map << (i * 2));
+ he_cap->he_mcs_nss_supp.rx_mcs_160 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.rx_mcs_80p80 |= unsup_for_ss;
+ mcs_map = IEEE80211_HE_MCS_SUPPORT_0_7;
+ }
+ for (; i < 8; i++) {
+ __le16 unsup_for_ss =
+ cpu_to_le16(IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
+ he_cap->he_mcs_nss_supp.rx_mcs_80 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.rx_mcs_160 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.rx_mcs_80p80 |= unsup_for_ss;
+ }
+ mcs_map = aicwf_hw->mod_params->he_mcs_map;
+ for (i = 0; i < nss; i++) {
+ __le16 unsup_for_ss =
+ cpu_to_le16(IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
+ he_cap->he_mcs_nss_supp.tx_mcs_80 |= cpu_to_le16(mcs_map << (i * 2));
+ he_cap->he_mcs_nss_supp.tx_mcs_160 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.tx_mcs_80p80 |= unsup_for_ss;
+ mcs_map = min_t(int, aicwf_hw->mod_params->he_mcs_map,
+ IEEE80211_HE_MCS_SUPPORT_0_7);
+ }
+ for (; i < 8; i++) {
+ __le16 unsup_for_ss =
+ cpu_to_le16(IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
+ he_cap->he_mcs_nss_supp.tx_mcs_80 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.tx_mcs_160 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.tx_mcs_80p80 |= unsup_for_ss;
+ }
+
+ if (aicwf_hw->band_5g_support) {
+ he_cap = &aicwf_hw->he_capa[0].he_cap;
+ he_cap->has_he = true;
+ he_cap->he_cap_elem.mac_cap_info[2] |= IEEE80211_HE_MAC_CAP2_ALL_ACK;
+ if (aicwf_hw->mod_params->use_2040) {
+ he_cap->he_cap_elem.phy_cap_info[0] |=
+ IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
+ he_cap->ppe_thres[0] |= 0x10;
+ }
+ if (aicwf_hw->mod_params->use_80) {
+ he_cap->ppe_thres[0] |= 0x20;
+ he_cap->ppe_thres[2] |= 0xc0;
+ he_cap->ppe_thres[3] |= 0x07;
+ }
+
+ he_cap->he_cap_elem.phy_cap_info[0] |=
+ IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G;
+
+ if (aicwf_hw->mod_params->ldpc_on) {
+ he_cap->he_cap_elem.phy_cap_info[1] |=
+ IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD;
+ } else {
+ // If no LDPC is supported, we have to limit to MCS0_9, as LDPC is
+ // mandatory for MCS 10 and 11
+ aicwf_hw->mod_params->he_mcs_map = min_t(int, aicwf_hw->mod_params->mcs_map,
+ IEEE80211_HE_MCS_SUPPORT_0_9);
+ }
+ he_cap->he_cap_elem.phy_cap_info[1] |=
+ IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US |
+ IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS;
+ he_cap->he_cap_elem.phy_cap_info[2] |=
+ IEEE80211_HE_PHY_CAP2_MIDAMBLE_RX_TX_MAX_NSTS |
+ IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
+ IEEE80211_HE_PHY_CAP2_DOPPLER_RX;
+ if (aicwf_hw->mod_params->stbc_on)
+ he_cap->he_cap_elem.phy_cap_info[2] |=
+ IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ;
+ he_cap->he_cap_elem.phy_cap_info[3] |=
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_16_QAM |
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1 |
+ IEEE80211_HE_PHY_CAP3_RX_PARTIAL_BW_SU_IN_20MHZ_MU;
+ if (aicwf_hw->mod_params->bfmee) {
+ he_cap->he_cap_elem.phy_cap_info[4] |=
+ IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE;
+ he_cap->he_cap_elem.phy_cap_info[4] |=
+ IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4;
+ }
+ he_cap->he_cap_elem.phy_cap_info[5] |=
+ IEEE80211_HE_PHY_CAP5_NG16_SU_FEEDBACK |
+ IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK;
+ he_cap->he_cap_elem.phy_cap_info[6] |=
+ IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU |
+ IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU |
+ IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMING_FB |
+ IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB |
+ IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT |
+ IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO;
+
+ he_cap->he_cap_elem.phy_cap_info[7] |=
+ IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI;
+ he_cap->he_cap_elem.phy_cap_info[8] |=
+ IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G;
+ he_cap->he_cap_elem.phy_cap_info[9] |=
+ IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
+ IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
+
+ if (aicwf_hw->chip_ops->is_old_ic) {
+ mcs_map = min_t(int, aicwf_hw->mod_params->he_mcs_map,
+ IEEE80211_HE_MCS_SUPPORT_0_9);
+ } else {
+ mcs_map = aicwf_hw->mod_params->he_mcs_map;
+ }
+
+ memset(&he_cap->he_mcs_nss_supp, 0, sizeof(he_cap->he_mcs_nss_supp));
+ for (i = 0; i < nss; i++) {
+ __le16 unsup_for_ss =
+ cpu_to_le16(IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
+ he_cap->he_mcs_nss_supp.rx_mcs_80 |=
+ cpu_to_le16(mcs_map << (i * 2));
+ he_cap->he_mcs_nss_supp.rx_mcs_160 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.rx_mcs_80p80 |= unsup_for_ss;
+ mcs_map = IEEE80211_HE_MCS_SUPPORT_0_7;
+ }
+ for (; i < 8; i++) {
+ __le16 unsup_for_ss =
+ cpu_to_le16(IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
+ he_cap->he_mcs_nss_supp.rx_mcs_80 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.rx_mcs_160 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.rx_mcs_80p80 |= unsup_for_ss;
+ }
+ mcs_map = aicwf_hw->mod_params->he_mcs_map;
+ for (i = 0; i < nss; i++) {
+ __le16 unsup_for_ss =
+ cpu_to_le16(IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
+ he_cap->he_mcs_nss_supp.tx_mcs_80 |=
+ cpu_to_le16(mcs_map << (i * 2));
+ he_cap->he_mcs_nss_supp.tx_mcs_160 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.tx_mcs_80p80 |= unsup_for_ss;
+ mcs_map = min_t(int, aicwf_hw->mod_params->he_mcs_map,
+ IEEE80211_HE_MCS_SUPPORT_0_7);
+ }
+ for (; i < 8; i++) {
+ __le16 unsup_for_ss =
+ cpu_to_le16(IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
+ he_cap->he_mcs_nss_supp.tx_mcs_80 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.tx_mcs_160 |= unsup_for_ss;
+ he_cap->he_mcs_nss_supp.tx_mcs_80p80 |= unsup_for_ss;
+ }
+ }
+}
+
+static void aicwf_set_wiphy_params(struct aicwf_hw *aicwf_hw, struct wiphy *wiphy)
+{
+#ifdef CONFIG_AICWF_FULLMAC
+ /* FULLMAC specific parameters */
+ wiphy->flags |= WIPHY_FLAG_REPORTS_OBSS;
+ wiphy->max_scan_ssids = SCAN_SSID_MAX;
+ wiphy->max_scan_ie_len = SCANU_MAX_IE_LEN;
+#endif /* CONFIG_AICWF_FULLMAC */
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ if (aicwf_hw->mod_params->tdls) {
+ /* TDLS support */
+ wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
+#ifdef CONFIG_AICWF_FULLMAC
+ /* TDLS external setup support */
+ wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
+#endif
+ }
+
+ if (aicwf_hw->mod_params->ap_uapsd_on)
+ wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
+#endif
+
+#ifdef CONFIG_AICWF_FULLMAC
+ if (aicwf_hw->mod_params->ps_on)
+ wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
+ else
+ wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
+#endif
+}
+
+int aicwf_handle_dynparams(struct aicwf_hw *aicwf_hw, struct wiphy *wiphy)
+{
+ /* Set chip capabilities */
+ aic_chip_init_capa(aicwf_hw);
+ /* Set wiphy parameters */
+ aicwf_set_wiphy_params(aicwf_hw, wiphy);
+ /* Set VHT capabilities */
+ aicwf_set_vht_capa(aicwf_hw, wiphy);
+ /* Set HE capabilities */
+ aicwf_set_he_capa(aicwf_hw, wiphy);
+ /* Set HT capabilities */
+ aicwf_set_ht_capa(aicwf_hw, wiphy);
+ /* Set RF specific parameters (shall be done last as it might change some
+ * capabilities previously set)
+ */
+ return 0;
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mu_group.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mu_group.c
new file mode 100644
index 000000000000..be67912434c8
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_mu_group.c
@@ -0,0 +1,653 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief mu group information
+ *
+ ******************************************************************************
+ */
+
+#include "aicwf_defs.h"
+#include "aicwf_events.h"
+#include "aicwf_msg_tx.h"
+
+/**
+ * aicwf_mu_group_sta_init - Initialize group information for a STA
+ * @sta: STA to initialize
+ * @vht_cap: VHT capabilities advertised by the STA, or %NULL
+ */
+void aicwf_mu_group_sta_init(struct aicwf_sta *sta,
+ const struct ieee80211_vht_cap *vht_cap)
+{
+ sta->group_info.map = 0;
+ sta->group_info.cnt = 0;
+ sta->group_info.active.next = LIST_POISON1;
+ sta->group_info.update.next = LIST_POISON1;
+ sta->group_info.last_update = 0;
+ sta->group_info.traffic = 0;
+ sta->group_info.group = 0;
+
+ if (!vht_cap ||
+ !(le32_to_cpu(vht_cap->vht_cap_info) &
+ IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
+ sta->group_info.map = AICWF_SU_GROUP;
+ }
+}
+
+/**
+ * aicwf_mu_group_sta_del - Remove a sta from all MU group
+ *
+ * @aicwf_hw: main driver data
+ * @sta: STA to remove
+ *
+ * Remove one sta from all the MU groups it belongs to.
+ */
+void aicwf_mu_group_sta_del(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta)
+{
+ struct aicwf_mu_info *mu = &aicwf_hw->mu;
+ int i, j, group_id;
+ bool lock_taken;
+ u64 map;
+
+ lock_taken = (down_interruptible(&mu->lock) == 0);
+
+ map = sta->group_info.map & AICWF_MU_GROUP_MASK;
+ for (group_id = (fls64(map) - 1); group_id > 0;
+ map &= ~(u64)BIT_ULL(group_id), group_id = (fls64(map) - 1)) {
+ struct aicwf_mu_group *group = aicwf_mu_group_from_id(mu, group_id);
+
+ for (i = 0; i < NX_USER_MAX && group->users[i] == sta; i++) {
+ group->users[i] = NULL;
+ group->user_cnt--;
+ /* Don't keep group with only one user */
+ if (group->user_cnt == 1) {
+ for (j = 0; j < NX_USER_MAX && group->users[j]; j++) {
+ group->users[j]->group_info.cnt--;
+ group->users[j]->group_info.map &=
+ ~BIT_ULL(group->group_id);
+ if (group->users[j]->group_info.group == group_id)
+ group->users[j]->group_info.group = 0;
+ group->user_cnt--;
+ break;
+ }
+ mu->group_cnt--;
+ trace_mu_group_delete(group->group_id);
+ } else {
+ trace_mu_group_update(group);
+ }
+ break;
+ }
+
+ WARN((i == NX_USER_MAX), "sta %d doesn't belongs to group %d",
+ sta->sta_idx, group_id);
+ }
+
+ sta->group_info.map = 0;
+ sta->group_info.cnt = 0;
+ sta->group_info.traffic = 0;
+
+ if (sta->group_info.active.next != LIST_POISON1)
+ list_del(&sta->group_info.active);
+
+ if (sta->group_info.update.next != LIST_POISON1)
+ list_del(&sta->group_info.update);
+
+ if (lock_taken)
+ up(&mu->lock);
+}
+
+/**
+ * aicwf_mu_group_sta_get_map - Get the list of group a STA belongs to
+ *
+ * @sta: pointer to the sta
+ *
+ * Return: Bitfield of groups to which the STA belongs, or 0 for a NULL STA.
+ */
+u64 aicwf_mu_group_sta_get_map(struct aicwf_sta *sta)
+{
+ if (sta)
+ return sta->group_info.map;
+ return 0;
+}
+
+/**
+ * aicwf_mu_group_sta_get_pos - Get sta position in a group
+ *
+ * @aicwf_hw: main driver data
+ * @sta: pointer to the sta
+ * @group_id: Group id
+ *
+ * Return: Position of @sta in @group_id, or -1 if the STA does not belong to
+ * the group or the group identifier is invalid.
+ */
+int aicwf_mu_group_sta_get_pos(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta,
+ int group_id)
+{
+ struct aicwf_mu_group *group;
+ int i;
+
+ group = aicwf_mu_group_from_id(&aicwf_hw->mu, group_id);
+ if (!group)
+ return -1;
+
+ for (i = 0; i < NX_USER_MAX; i++) {
+ if (group->users[i] == sta)
+ return i;
+ }
+
+ WARN(1, "sta %d doesn't belongs to group %d", sta->sta_idx, group_id);
+ return -1;
+}
+
+/**
+ * aicwf_mu_group_move_head - Move (or add) one element at the top of a list
+ *
+ * @list: list pointer
+ * @elem: element to move (or add) at the top of @list
+ *
+ */
+static inline void aicwf_mu_group_move_head(struct list_head *list,
+ struct list_head *elem)
+{
+ if (elem->next != LIST_POISON1)
+ __list_del_entry(elem);
+
+ list_add(elem, list);
+}
+
+/**
+ * aicwf_mu_group_remove_users - Remove all the users of a group
+ *
+ * @mu: pointer on MU info
+ * @group: pointer on group to remove users from
+ *
+ * Loop over all users one group and remove this group from their
+ * map (and count).
+ * Each users is also added to the update_sta list, so that group info
+ * will be resent to fw for this user.
+ */
+static inline void aicwf_mu_group_remove_users(struct aicwf_mu_info *mu,
+ struct aicwf_mu_group *group)
+{
+ struct aicwf_sta *sta;
+ int i, group_id = group->group_id;
+
+ for (i = 0; i < NX_USER_MAX && group->users[i]; i++) {
+ sta = group->users[i];
+ group->users[i] = NULL;
+ sta->group_info.cnt--;
+ sta->group_info.map &= ~BIT_ULL(group_id);
+ aicwf_mu_group_move_head(&mu->update_sta, &sta->group_info.update);
+ }
+
+ if (group->user_cnt)
+ mu->group_cnt--;
+ group->user_cnt = 0;
+ trace_mu_group_delete(group_id);
+}
+
+/**
+ * aicwf_mu_group_add_users - Add users to a group
+ *
+ * @mu: pointer on MU info
+ * @group: pointer on group to add users in
+ * @nb_user: number of users to ad
+ * @users: table of user to add
+ *
+ * Add @nb_users to @group (which may already have users)
+ * Each new users is added to the first free position.
+ * It is assume that @group has at least @nb_user free position. If it is not
+ * case it only add the number of users needed to complete the group.
+ * Each users (effectively added to @group) is also added to the update_sta
+ * list, so that group info will be resent to fw for this user.
+ */
+static inline void aicwf_mu_group_add_users(struct aicwf_mu_info *mu,
+ struct aicwf_mu_group *group,
+ int nb_user, struct aicwf_sta **users)
+{
+ int i, j, group_id = group->group_id;
+
+ if (!group->user_cnt)
+ mu->group_cnt++;
+
+ j = 0;
+
+ for (i = 0; i < nb_user; i++) {
+ for (; j < NX_USER_MAX; j++) {
+ if (!group->users[j]) {
+ group->users[j] = users[i];
+ users[i]->group_info.cnt++;
+ users[i]->group_info.map |= BIT_ULL(group_id);
+
+ aicwf_mu_group_move_head(&mu->update_sta,
+ &users[i]->group_info.update);
+ group->user_cnt++;
+ j++;
+ break;
+ }
+
+ WARN(j == (NX_USER_MAX - 1),
+ "Too many user for group %d (nb_user=%d)", group_id,
+ group->user_cnt + nb_user - i);
+ }
+ }
+
+ trace_mu_group_update(group);
+}
+
+/*
+ * aicwf_mu_group_create_one - create on group with a specific group of user
+ *
+ * @mu: pointer on MU info
+ * @nb_user: number of user to include in the group (<= NX_USER_MAX)
+ * @users: table of users
+ *
+ * Try to create a new group with a specific group of users.
+ * 1- First it checks if a group containing all this users already exists.
+ *
+ * 2- Then it checks if it is possible to complete a group which already
+ * contains at least one user.
+ *
+ * 3- Finally it create a new group. To do so, it take the last group of
+ * the active_groups list, remove all its current users and add the new ones
+ *
+ * In all cases, the group selected is moved at the top of the active_groups
+ * list
+ *
+ * @return 1 if a new group has been created and 0 otherwise
+ */
+static int aicwf_mu_group_create_one(struct aicwf_mu_info *mu, int nb_user,
+ struct aicwf_sta **users, int *nb_group_left)
+{
+ int i, group_id;
+ struct aicwf_mu_group *group;
+ u64 group_match;
+#if NX_USER_MAX > 2
+ u64 group_avail;
+#endif
+
+ group_match = users[0]->group_info.map;
+#if NX_USER_MAX > 2
+ group_avail = users[0]->group_info.map;
+#endif
+ for (i = 1; i < nb_user; i++) {
+ group_match &= users[i]->group_info.map;
+#if NX_USER_MAX > 2
+ group_avail |= users[i]->group_info.map;
+#endif
+ }
+
+ if (group_match) {
+ /* a group (or more) with all the users already exist */
+ group_id = AICWF_GET_FIRST_GROUP_ID(group_match);
+ group = aicwf_mu_group_from_id(mu, group_id);
+ aicwf_mu_group_move_head(&mu->active_groups, &group->list);
+ return 0;
+ }
+#if NX_USER_MAX > 2
+ if (group_avail) {
+ /* check if we can complete a group */
+ struct aicwf_sta *users2[NX_USER_MAX];
+ int nb_user2;
+
+ for (group_id = (fls64(group_avail) - 1); group_id > 0;
+ group_avail &= ~(u64)BIT_ULL(group_id),
+ group_id = (fls64(group_avail) - 1)) {
+ group = aicwf_mu_group_from_id(mu, group_id);
+ if (group->user_cnt == NX_USER_MAX)
+ continue;
+
+ nb_user2 = 0;
+ for (i = 0; i < nb_user; i++) {
+ if (!(users[i]->group_info.map & BIT_ULL(group_id))) {
+ users2[nb_user2] = users[i];
+ nb_user2++;
+ }
+ }
+
+ if ((group->user_cnt + nb_user2) <= NX_USER_MAX) {
+ aicwf_mu_group_add_users(mu, group, nb_user2, users2);
+ aicwf_mu_group_move_head(&mu->active_groups, &group->list);
+ return 0;
+ }
+ }
+ }
+#endif /* NX_USER_MAX > 2 */
+
+ /* create a new group */
+ group = list_last_entry(&mu->active_groups, struct aicwf_mu_group, list);
+ aicwf_mu_group_remove_users(mu, group);
+ aicwf_mu_group_add_users(mu, group, nb_user, users);
+ aicwf_mu_group_move_head(&mu->active_groups, &group->list);
+ (*nb_group_left)--;
+
+ return 1;
+}
+
+/**
+ * aicwf_mu_group_create - Create new groups containing one specific sta
+ *
+ * @mu: pointer on MU info
+ * @sta: sta to add in each group
+ * @nb_group_left: maximum number to new group allowed. (updated on exit)
+ *
+ * This will try to create "all the possible" group with a specific sta being
+ * a member of all these group.
+ * The function simply loops over the @active_sta list (starting from @sta).
+ * When it has (NX_USER_MAX - 1) users it try to create a new group with
+ * these users (plus @sta).
+ * Loops end when there is no more users, or no more new group is allowed
+ *
+ */
+static void aicwf_mu_group_create(struct aicwf_mu_info *mu, struct aicwf_sta *sta,
+ int *nb_group_left)
+{
+ struct aicwf_sta *user_sta = sta;
+ struct aicwf_sta *users[NX_USER_MAX];
+ int nb_user = 1;
+
+ users[0] = sta;
+ while (*nb_group_left) {
+ list_for_each_entry_continue(user_sta, &mu->active_sta,
+ group_info.active) {
+ users[nb_user] = user_sta;
+ if (++nb_user == NX_USER_MAX)
+ break;
+ }
+
+ if (nb_user > 1) {
+ if (aicwf_mu_group_create_one(mu, nb_user, users, nb_group_left))
+ (*nb_group_left)--;
+
+ if (nb_user < NX_USER_MAX)
+ break;
+ nb_user = 1;
+ } else {
+ break;
+ }
+ }
+}
+
+/*
+ * aicwf_mu_group_work - process function of the "group_work"
+ *
+ * The work is scheduled when several sta (MU beamformee capable) are active.
+ * When called, the @active_sta contains the list of the active sta (starting
+ * from the most recent one), and @active_groups is the list of all possible
+ * groups ordered so that the first one is the most recently used.
+ *
+ * This function will create new groups, starting from group containing the
+ * most "active" sta.
+ * For example if the list of sta is :
+ * sta8 -> sta3 -> sta4 -> sta7 -> sta1
+ * and the number of user per group is 3, it will create grooups :
+ * - sta8 / sta3 / sta4
+ * - sta8 / sta7 / sta1
+ * - sta3 / sta4 / sta7
+ * - sta3 / sta1
+ * - sta4 / sta7 / sta1
+ * - sta7 / sta1
+ *
+ * To create new group, the least used group are first selected.
+ * It is only allowed to create NX_MU_GROUP_MAX per iteration.
+ *
+ * Once groups have been updated, mu group information is update to the fw.
+ * To do so it use the @update_sta list to know which sta has been affected.
+ * As it is necessary to wait for fw confirmation before using this new group
+ * MU is temporarily disabled during group update
+ *
+ * Work is then rescheduled.
+ *
+ * At the end of the function, both @active_sta and @update_sta list are empty.
+ *
+ * Note:
+ * - This is still a WIP, and will require more tuning
+ * - not all combinations are created, to avoid to much processing.
+ * - reschedule delay should be adaptative
+ */
+static void aicwf_mu_group_work(struct work_struct *ws)
+{
+ struct delayed_work *dw = container_of(ws, struct delayed_work, work);
+ struct aicwf_mu_info *mu = container_of(dw, struct aicwf_mu_info, group_work);
+ struct aicwf_hw *aicwf_hw = container_of(mu, struct aicwf_hw, mu);
+ struct aicwf_sta *sta, *next;
+ int nb_group_left = NX_MU_GROUP_MAX;
+
+ if (WARN(!aicwf_hw->mod_params->mutx,
+ "In group formation work, but mutx disabled"))
+ return;
+
+ if (down_interruptible(&mu->lock) != 0)
+ return;
+
+ mu->update_count++;
+ if (!mu->update_count)
+ mu->update_count++;
+
+ list_for_each_entry_safe(sta, next, &mu->active_sta, group_info.active) {
+ if (nb_group_left)
+ aicwf_mu_group_create(mu, sta, &nb_group_left);
+
+ sta->group_info.last_update = mu->update_count;
+ list_del(&sta->group_info.active);
+ }
+
+ if (!list_empty(&mu->update_sta)) {
+ list_for_each_entry_safe(sta, next, &mu->update_sta, group_info.update) {
+ aicwf_send_mu_group_update_req(aicwf_hw, sta);
+ list_del(&sta->group_info.update);
+ }
+ }
+
+ mu->next_group_select = jiffies;
+ aicwf_mu_group_sta_select(aicwf_hw);
+ up(&mu->lock);
+}
+
+/**
+ * aicwf_mu_group_init - Initialize MU groups
+ *
+ * @aicwf_hw: main driver data
+ *
+ * Initialize all MU group
+ */
+void aicwf_mu_group_init(struct aicwf_hw *aicwf_hw)
+{
+ struct aicwf_mu_info *mu = &aicwf_hw->mu;
+ int i;
+
+ INIT_LIST_HEAD(&mu->active_groups);
+ INIT_LIST_HEAD(&mu->active_sta);
+ INIT_LIST_HEAD(&mu->update_sta);
+
+ for (i = 0; i < NX_MU_GROUP_MAX; i++) {
+ int j;
+
+ mu->groups[i].user_cnt = 0;
+ mu->groups[i].group_id = i + 1;
+ for (j = 0; j < NX_USER_MAX; j++)
+ mu->groups[i].users[j] = NULL;
+ list_add(&mu->groups[i].list, &mu->active_groups);
+ }
+
+ mu->update_count = 1;
+ mu->group_cnt = 0;
+ mu->next_group_select = jiffies;
+ INIT_DELAYED_WORK(&mu->group_work, aicwf_mu_group_work);
+ sema_init(&mu->lock, 1);
+}
+
+/**
+ * aicwf_mu_set_active_sta - mark a STA as active
+ *
+ * @aicwf_hw: main driver data
+ * @sta: pointer to the sta
+ * @traffic: Number of buffers to add in the sta's traffic counter
+ *
+ * If @sta is MU beamformee capable (and MU-MIMO tx is enabled) move the
+ * sta at the top of the @active_sta list.
+ * It also schedule the group_work if not already scheduled and the list
+ * contains more than one sta.
+ *
+ * If a STA was already in the list during the last group update
+ * (i.e. sta->group_info.last_update == mu->update_count) it is not added
+ * back to the list until a sta that wasn't active during the last update is
+ * added. This is to avoid scheduling group update with a list of sta that
+ * were all already in the list during previous update.
+ *
+ * It is called with mu->lock taken.
+ */
+void aicwf_mu_set_active_sta(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta,
+ int traffic)
+{
+ struct aicwf_mu_info *mu = &aicwf_hw->mu;
+
+ if (!sta || (sta->group_info.map & AICWF_SU_GROUP))
+ return;
+
+ sta->group_info.traffic += traffic;
+
+ if (sta->group_info.last_update != mu->update_count ||
+ !list_empty(&mu->active_sta)) {
+ aicwf_mu_group_move_head(&mu->active_sta, &sta->group_info.active);
+
+ if (!delayed_work_pending(&mu->group_work) &&
+ !list_is_singular(&mu->active_sta)) {
+ schedule_delayed_work(&mu->group_work,
+ msecs_to_jiffies(AICWF_MU_GROUP_INTERVAL));
+ }
+ }
+}
+
+/**
+ * aicwf_mu_set_active_group - mark a MU group as active
+ *
+ * @aicwf_hw: main driver data
+ * @group_id: Group id
+ *
+ * move a group at the top of the @active_groups list
+ */
+void aicwf_mu_set_active_group(struct aicwf_hw *aicwf_hw, int group_id)
+{
+ struct aicwf_mu_info *mu = &aicwf_hw->mu;
+ struct aicwf_mu_group *group = aicwf_mu_group_from_id(mu, group_id);
+
+ aicwf_mu_group_move_head(&mu->active_groups, &group->list);
+}
+
+/**
+ * aicwf_mu_group_sta_select - Select the best group for MU stas
+ *
+ * @aicwf_hw: main driver data
+ *
+ * For each MU capable client of AP interfaces this function tries to select
+ * the best group to use.
+ *
+ * In first pass, gather information from all stations to form statistics
+ * for each group for the previous @AICWF_MU_GROUP_SELECT_INTERVAL interval:
+ * - number of buffers transmitted
+ * - number of user
+ *
+ * Then groups with more than 2 active users, are assigned after being ordered
+ * by traffic :
+ * - group with highest traffic is selected: set this group for all its users
+ * - update nb_users for all others group (as one sta may be in several groups)
+ * - select the next group that have still mor than 2 users and assign it.
+ * - continue until all group are processed
+ *
+ */
+void aicwf_mu_group_sta_select(struct aicwf_hw *aicwf_hw)
+{
+ struct aicwf_mu_info *mu = &aicwf_hw->mu;
+ int nb_users[NX_MU_GROUP_MAX + 1];
+ int traffic[NX_MU_GROUP_MAX + 1];
+ int order[NX_MU_GROUP_MAX + 1];
+ struct aicwf_sta *sta;
+ struct aicwf_vif *vif;
+ struct list_head *head;
+ u64 map;
+ int i, j, update, group_id, tmp, cnt = 0;
+
+ if (!mu->group_cnt || time_before(jiffies, mu->next_group_select))
+ return;
+
+ list_for_each_entry(vif, &aicwf_hw->vifs, list) {
+ if (AICWF_VIF_TYPE(vif) != NL80211_IFTYPE_AP)
+ continue;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ head = &vif->ap.sta_list;
+#else
+ head = &vif->stations;
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ memset(nb_users, 0, sizeof(nb_users));
+ memset(traffic, 0, sizeof(traffic));
+ list_for_each_entry(sta, head, list) {
+ int sta_traffic = sta->group_info.traffic;
+
+ /* reset statistics for next selection */
+ sta->group_info.traffic = 0;
+ if (sta->group_info.group)
+ trace_mu_group_selection(sta, 0);
+ sta->group_info.group = 0;
+
+ if (sta->group_info.cnt == 0 ||
+ sta_traffic < AICWF_MU_GROUP_MIN_TRAFFIC)
+ continue;
+
+ map = sta->group_info.map & AICWF_MU_GROUP_MASK;
+ for (group_id = (fls64(map) - 1); group_id > 0;
+ map &= ~(u64)BIT_ULL(group_id), group_id = (fls64(map) - 1)) {
+ nb_users[group_id]++;
+ traffic[group_id] += sta_traffic;
+
+ /* list group with 2 users or more */
+ if (nb_users[group_id] == 2)
+ order[cnt++] = group_id;
+ }
+ }
+
+ /* reorder list of group with more that 2 users */
+ update = 1;
+ while (update) {
+ update = 0;
+ for (i = 0; i < cnt - 1; i++) {
+ if (traffic[order[i]] < traffic[order[i + 1]]) {
+ tmp = order[i];
+ order[i] = order[i + 1];
+ order[i + 1] = tmp;
+ update = 1;
+ }
+ }
+ }
+
+ /* now assign group in traffic order */
+ for (i = 0; i < cnt; i++) {
+ struct aicwf_mu_group *group;
+
+ group_id = order[i];
+ if (nb_users[group_id] < 2)
+ continue;
+
+ group = aicwf_mu_group_from_id(mu, group_id);
+ for (j = 0; j < NX_USER_MAX && group->users[j]; j++) {
+ trace_mu_group_selection(group->users[j], group_id);
+ group->users[j]->group_info.group = group_id;
+
+ map = group->users[j]->group_info.map & AICWF_MU_GROUP_MASK;
+ for (tmp = (fls64(map) - 1); tmp > 0;
+ map &= ~(u64)BIT_ULL(tmp), tmp = (fls64(map) - 1)) {
+ if (group_id != tmp)
+ nb_users[tmp]--;
+ }
+ }
+ }
+ }
+
+ mu->next_group_select =
+ jiffies + msecs_to_jiffies(AICWF_MU_GROUP_SELECT_INTERVAL);
+ mu->next_group_select |= 1;
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_radar.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_radar.c
new file mode 100644
index 000000000000..c682c4f192a7
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_radar.c
@@ -0,0 +1,1969 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file aicwf_radar.c
+ *
+ * @brief Functions to handle radar detection
+ * Radar detection is copied (and adapted) from ath driver source code.
+ *
+ ******************************************************************************
+ */
+#include <linux/kernel.h>
+#include <linux/ktime.h>
+#include <linux/list.h>
+#include <net/mac80211.h>
+
+#include "aicwf_defs.h"
+#include "aicwf_events.h"
+#include "aicwf_msg_tx.h"
+#include "aicwf_radar.h"
+
+/*
+ * tolerated deviation of radar time stamp in usecs on both sides
+ * TODO: this might need to be HW-dependent
+ */
+#define PRI_TOLERANCE 16
+
+/**
+ * struct radar_types - contains array of patterns defined for one DFS domain
+ * @region: DFS regulatory domain
+ * @num_radar_types: number of radar types to follow
+ * @spec_riu: radar patterns for the RIU detector
+ * @spec_fcu: radar patterns for the FCU detector
+ */
+struct radar_types {
+ enum nl80211_dfs_regions region;
+ u32 num_radar_types;
+ const struct radar_detector_specs *spec_riu;
+ const struct radar_detector_specs *spec_fcu;
+};
+
+/* percentage on ppb threshold to trigger detection */
+#define MIN_PPB_THRESH 50
+#define PPB_THRESH(PPB) (((PPB) * MIN_PPB_THRESH + 50) / 100)
+//#define PRF2PRI(PRF) ((1000000 + (PRF) / 2) / (PRF))
+#define PRF2PRI(PRF) \
+ ({ \
+ typeof(PRF) _prf = (PRF); \
+ ((1000000 + (_prf) / 2) / (_prf)); \
+ })
+
+/* width tolerance */
+#define WIDTH_TOLERANCE 2
+#define WIDTH_LOWER(X) (X)
+#define WIDTH_UPPER(X) (X)
+
+static inline struct radar_detector_specs
+ ETSI_PATTERN_SHORT(u8 ID, u8 WMIN, u8 WMAX, u16 PMIN, u16 PMAX, u8 PPB)
+{
+ struct radar_detector_specs spec = {
+ .type_id = ID,
+ .width_min = WIDTH_LOWER(WMIN),
+ .width_max = WIDTH_UPPER(WMAX),
+ .pri_min = (PRF2PRI(PMAX) - PRI_TOLERANCE),
+ .pri_max = (PRF2PRI(PMIN) + PRI_TOLERANCE),
+ .num_pri = 1,
+ .ppb = PPB,
+ .ppb_thresh = PPB_THRESH(PPB),
+ .max_pri_tolerance = PRI_TOLERANCE,
+ .type = RADAR_WAVEFORM_SHORT
+ };
+ return spec;
+}
+
+static inline struct radar_detector_specs
+ ETSI_PATTERN_INTERLEAVED(u8 ID, u8 WMIN, u8 WMAX, u16 PMIN, u16 PMAX,
+ u16 PRFMIN, u16 PRFMAX, u8 PPB)
+{
+ struct radar_detector_specs spec = {
+ .type_id = ID,
+ .width_min = WIDTH_LOWER(WMIN),
+ .width_max = WIDTH_UPPER(WMAX),
+ .pri_min = (PRF2PRI(PMAX) * (PRFMIN) - PRI_TOLERANCE),
+ .pri_max = (PRF2PRI(PMIN) * (PRFMAX) + PRI_TOLERANCE),
+ .num_pri = PRFMAX,
+ .ppb = (PPB) * (PRFMAX),
+ .ppb_thresh = PPB_THRESH(PPB),
+ .max_pri_tolerance = PRI_TOLERANCE,
+ .type = RADAR_WAVEFORM_INTERLEAVED
+ };
+ return spec;
+}
+
+/* radar types as defined by ETSI EN-301-893 v1.7.1 */
+static const struct radar_detector_specs etsi_radar_ref_types_v17_riu[] = {
+ {0,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ (((1000000 + (700) / 2) / (700)) - PRI_TOLERANCE),
+ (((1000000 + (700) / 2) / (700)) + PRI_TOLERANCE),
+ 1,
+ 18,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {1,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(10),
+ (((1000000 + (1000) / 2) / (1000)) - PRI_TOLERANCE),
+ (((1000000 + (200) / 2) / (200)) + PRI_TOLERANCE),
+ 1,
+ 10,
+ PPB_THRESH(10),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {2,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(22),
+ (((1000000 + (1600) / 2) / (1600)) - PRI_TOLERANCE),
+ (((1000000 + (200) / 2) / (200)) + PRI_TOLERANCE),
+ 1,
+ 15,
+ PPB_THRESH(15),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {3,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(22),
+ (((1000000 + (4000) / 2) / (4000)) - PRI_TOLERANCE),
+ (((1000000 + (2300) / 2) / (2300)) + PRI_TOLERANCE),
+ 1,
+ 25,
+ PPB_THRESH(25),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {4,
+ WIDTH_LOWER(20),
+ WIDTH_UPPER(38),
+ (((1000000 + (4000) / 2) / (4000)) - PRI_TOLERANCE),
+ (((1000000 + (2000) / 2) / (2000)) + PRI_TOLERANCE),
+ 1,
+ 20,
+ PPB_THRESH(20),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {5,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ (((1000000 + (400) / 2) / (400)) * 2 - PRI_TOLERANCE),
+ (((1000000 + (300) / 2) / (300)) * 3 + PRI_TOLERANCE),
+ 3,
+ 10 * 3,
+ PPB_THRESH(10),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_INTERLEAVED},
+ {6,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ (((1000000 + (1200) / 2) / (1200)) * 2 - PRI_TOLERANCE),
+ (((1000000 + (400) / 2) / (400)) * 3 + PRI_TOLERANCE),
+ 3,
+ 15 * 3,
+ PPB_THRESH(15),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_INTERLEAVED},
+};
+
+static const struct radar_detector_specs etsi_radar_ref_types_v17_fcu[] = {
+ {0,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ (((1000000 + (700) / 2) / (700)) - PRI_TOLERANCE),
+ (((1000000 + (700) / 2) / (700)) + PRI_TOLERANCE),
+ 1,
+ 18,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {1,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ (((1000000 + (1000) / 2) / (1000)) - PRI_TOLERANCE),
+ (((1000000 + (200) / 2) / (200)) + PRI_TOLERANCE),
+ 1,
+ 10,
+ PPB_THRESH(10),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {2,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(16),
+ (((1000000 + (1600) / 2) / (1600)) - PRI_TOLERANCE),
+ (((1000000 + (200) / 2) / (200)) + PRI_TOLERANCE),
+ 1,
+ 15,
+ PPB_THRESH(15),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {3,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(16),
+ (((1000000 + (4000) / 2) / (4000)) - PRI_TOLERANCE),
+ (((1000000 + (2300) / 2) / (2300)) + PRI_TOLERANCE),
+ 1,
+ 25,
+ PPB_THRESH(25),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {4,
+ WIDTH_LOWER(20),
+ WIDTH_UPPER(34),
+ (((1000000 + (4000) / 2) / (4000)) - PRI_TOLERANCE),
+ (((1000000 + (2000) / 2) / (2000)) + PRI_TOLERANCE),
+ 1,
+ 20,
+ PPB_THRESH(20),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {5,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ (((1000000 + (400) / 2) / (400)) * 2 - PRI_TOLERANCE),
+ (((1000000 + (300) / 2) / (300)) * 3 + PRI_TOLERANCE),
+ 3,
+ 10 * 3,
+ PPB_THRESH(10),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_INTERLEAVED},
+ {6,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ (((1000000 + (1200) / 2) / (1200)) * 2 - PRI_TOLERANCE),
+ (((1000000 + (400) / 2) / (400)) * 3 + PRI_TOLERANCE),
+ 3,
+ 15 * 3,
+ PPB_THRESH(15),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_INTERLEAVED},
+};
+
+static const struct radar_types etsi_radar_types_v17 = {
+ .region = NL80211_DFS_ETSI,
+ .num_radar_types = ARRAY_SIZE(etsi_radar_ref_types_v17_riu),
+ .spec_riu = etsi_radar_ref_types_v17_riu,
+ .spec_fcu = etsi_radar_ref_types_v17_fcu,
+};
+
+static inline struct radar_detector_specs
+ FCC_PATTERN(u8 ID, u8 WMIN, u8 WMAX, u16 PMIN, u16 PMAX,
+ u16 PRF, u8 PPB, enum radar_waveform_type TYPE)
+{
+ struct radar_detector_specs spec = {
+ .type_id = ID,
+ .width_min = WIDTH_LOWER(WMIN),
+ .width_max = WIDTH_UPPER(WMAX),
+ .pri_min = (PMIN) - PRI_TOLERANCE,
+ .pri_max = (PMAX) * (PRF) + PRI_TOLERANCE,
+ .num_pri = PRF,
+ .ppb = (PPB) * (PRF),
+ .ppb_thresh = PPB_THRESH(PPB),
+ .max_pri_tolerance = PRI_TOLERANCE,
+ .type = TYPE
+ };
+ return spec;
+}
+
+static const struct radar_detector_specs fcc_radar_ref_types_riu[] = {
+ {0,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 1428 - PRI_TOLERANCE,
+ 1428 * 1 + PRI_TOLERANCE,
+ 1,
+ 18 * 1,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {1,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 518 - PRI_TOLERANCE,
+ 3066 * 1 + PRI_TOLERANCE,
+ 1,
+ 102 * 1,
+ PPB_THRESH(102),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_WEATHER},
+ {2,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 150 - PRI_TOLERANCE,
+ 230 * 1 + PRI_TOLERANCE,
+ 1,
+ 23 * 1,
+ PPB_THRESH(23),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {3,
+ WIDTH_LOWER(6),
+ WIDTH_UPPER(20),
+ 200 - PRI_TOLERANCE,
+ 500 * 1 + PRI_TOLERANCE,
+ 1,
+ 16 * 1,
+ PPB_THRESH(16),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {4,
+ WIDTH_LOWER(10),
+ WIDTH_UPPER(28),
+ 200 - PRI_TOLERANCE,
+ 500 * 1 + PRI_TOLERANCE,
+ 1,
+ 12 * 1,
+ PPB_THRESH(12),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {5,
+ WIDTH_LOWER(50),
+ WIDTH_UPPER(110),
+ 1000 - PRI_TOLERANCE,
+ 2000 * 1 + PRI_TOLERANCE,
+ 1,
+ 8 * 1,
+ PPB_THRESH(8),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_LONG},
+ {6,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 333 - PRI_TOLERANCE,
+ 333 * 1 + PRI_TOLERANCE,
+ 1,
+ 9 * 1,
+ PPB_THRESH(9),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+};
+
+static const struct radar_detector_specs fcc_radar_ref_types_fcu[] = {
+ {0,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 1428 - PRI_TOLERANCE,
+ 1428 * 1 + PRI_TOLERANCE,
+ 1,
+ 18 * 1,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {1,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 518 - PRI_TOLERANCE,
+ 3066 * 1 + PRI_TOLERANCE,
+ 1,
+ 102 * 1,
+ PPB_THRESH(102),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_WEATHER},
+ {2,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 150 - PRI_TOLERANCE,
+ 230 * 1 + PRI_TOLERANCE,
+ 1,
+ 23 * 1,
+ PPB_THRESH(23),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {3,
+ WIDTH_LOWER(6),
+ WIDTH_UPPER(12),
+ 200 - PRI_TOLERANCE,
+ 500 * 1 + PRI_TOLERANCE,
+ 1,
+ 16 * 1,
+ PPB_THRESH(16),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {4,
+ WIDTH_LOWER(10),
+ WIDTH_UPPER(22),
+ 200 - PRI_TOLERANCE,
+ 500 * 1 + PRI_TOLERANCE,
+ 1,
+ 12 * 1,
+ PPB_THRESH(12),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {5,
+ WIDTH_LOWER(50),
+ WIDTH_UPPER(104),
+ 1000 - PRI_TOLERANCE,
+ 2000 * 1 + PRI_TOLERANCE,
+ 1,
+ 8 * 1,
+ PPB_THRESH(8),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_LONG},
+ {6,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 333 - PRI_TOLERANCE,
+ 333 * 1 + PRI_TOLERANCE,
+ 1,
+ 9 * 1,
+ PPB_THRESH(9),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+};
+
+static const struct radar_types fcc_radar_types = {
+ .region = NL80211_DFS_FCC,
+ .num_radar_types = ARRAY_SIZE(fcc_radar_ref_types_riu),
+ .spec_riu = fcc_radar_ref_types_riu,
+ .spec_fcu = fcc_radar_ref_types_fcu,
+};
+
+#define JP_PATTERN FCC_PATTERN
+static const struct radar_detector_specs jp_radar_ref_types_riu[] = {
+ {0,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 1428 - PRI_TOLERANCE,
+ 1428 * 1 + PRI_TOLERANCE,
+ 1,
+ 18 * 1,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {1,
+ WIDTH_LOWER(2),
+ WIDTH_UPPER(8),
+ 3846 - PRI_TOLERANCE,
+ 3846 * 1 + PRI_TOLERANCE,
+ 1,
+ 18 * 1,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {2,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 1388 - PRI_TOLERANCE,
+ 1388 * 1 + PRI_TOLERANCE,
+ 1,
+ 18 * 1,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {3,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 4000 - PRI_TOLERANCE,
+ 4000 * 1 + PRI_TOLERANCE,
+ 1,
+ 18 * 1,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {4,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 150 - PRI_TOLERANCE,
+ 230 * 1 + PRI_TOLERANCE,
+ 1,
+ 23 * 1,
+ PPB_THRESH(23),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {5,
+ WIDTH_LOWER(6),
+ WIDTH_UPPER(20),
+ 200 - PRI_TOLERANCE,
+ 500 * 1 + PRI_TOLERANCE,
+ 1,
+ 16 * 1,
+ PPB_THRESH(16),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {6,
+ WIDTH_LOWER(10),
+ WIDTH_UPPER(28),
+ 200 - PRI_TOLERANCE,
+ 500 * 1 + PRI_TOLERANCE,
+ 1,
+ 12 * 1,
+ PPB_THRESH(12),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {7,
+ WIDTH_LOWER(50),
+ WIDTH_UPPER(110),
+ 1000 - PRI_TOLERANCE,
+ 2000 * 1 + PRI_TOLERANCE,
+ 1,
+ 8 * 1,
+ PPB_THRESH(8),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_LONG},
+ {8,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 333 - PRI_TOLERANCE,
+ 333 * 1 + PRI_TOLERANCE,
+ 1,
+ 9 * 1,
+ PPB_THRESH(9),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+};
+
+static const struct radar_detector_specs jp_radar_ref_types_fcu[] = {
+ {0,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 1428 - PRI_TOLERANCE,
+ 1428 * 1 + PRI_TOLERANCE,
+ 1,
+ 18 * 1,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {1,
+ WIDTH_LOWER(2),
+ WIDTH_UPPER(6),
+ 3846 - PRI_TOLERANCE,
+ 3846 * 1 + PRI_TOLERANCE,
+ 1,
+ 18 * 1,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {2,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 1388 - PRI_TOLERANCE,
+ 1388 * 1 + PRI_TOLERANCE,
+ 1,
+ 18 * 1,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {3,
+ WIDTH_LOWER(2),
+ WIDTH_UPPER(2),
+ 4000 - PRI_TOLERANCE,
+ 4000 * 1 + PRI_TOLERANCE,
+ 1,
+ 18 * 1,
+ PPB_THRESH(18),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {4,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 150 - PRI_TOLERANCE,
+ 230 * 1 + PRI_TOLERANCE,
+ 1,
+ 23 * 1,
+ PPB_THRESH(23),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {5,
+ WIDTH_LOWER(6),
+ WIDTH_UPPER(12),
+ 200 - PRI_TOLERANCE,
+ 500 * 1 + PRI_TOLERANCE,
+ 1,
+ 16 * 1,
+ PPB_THRESH(16),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {6,
+ WIDTH_LOWER(10),
+ WIDTH_UPPER(22),
+ 200 - PRI_TOLERANCE,
+ 500 * 1 + PRI_TOLERANCE,
+ 1,
+ 12 * 1,
+ PPB_THRESH(12),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+ {7,
+ WIDTH_LOWER(50),
+ WIDTH_UPPER(104),
+ 1000 - PRI_TOLERANCE,
+ 2000 * 1 + PRI_TOLERANCE,
+ 1,
+ 8 * 1,
+ PPB_THRESH(8),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_LONG},
+ {8,
+ WIDTH_LOWER(0),
+ WIDTH_UPPER(8),
+ 333 - PRI_TOLERANCE,
+ 333 * 1 + PRI_TOLERANCE,
+ 1,
+ 9 * 1,
+ PPB_THRESH(9),
+ PRI_TOLERANCE,
+ RADAR_WAVEFORM_SHORT},
+};
+
+static const struct radar_types jp_radar_types = {
+ .region = NL80211_DFS_JP,
+ .num_radar_types = ARRAY_SIZE(jp_radar_ref_types_riu),
+ .spec_riu = jp_radar_ref_types_riu,
+ .spec_fcu = jp_radar_ref_types_fcu,
+};
+
+static const struct radar_types *dfs_domains[] = {
+ &etsi_radar_types_v17,
+ &fcc_radar_types,
+ &jp_radar_types,
+};
+
+/**
+ * struct pri_detector_ops - PRI detector ops (dependent of waveform type)
+ * @init : Initialize pri_detector structure
+ * @add_pulse : Add a pulse to the pri-detector
+ * @reset_on_pri_overflow : Should the pri_detector be resetted when pri
+ * overflow
+ */
+struct pri_detector_ops {
+ void (*init)(struct pri_detector *pde);
+ struct pri_sequence *(*add_pulse)(struct pri_detector *pde, u16 len, u64 ts,
+ u16 pri);
+ int reset_on_pri_overflow;
+};
+
+/******************************************************************************
+ * PRI (pulse repetition interval) sequence detection
+ *****************************************************************************/
+/*
+ * Singleton Pulse and Sequence Pools
+ *
+ * Instances of pri_sequence and pulse_elem are kept in singleton pools to
+ * reduce the number of dynamic allocations. They are shared between all
+ * instances and grow up to the peak number of simultaneously used objects.
+ *
+ * Memory is freed after all references to the pools are released.
+ */
+static u32 singleton_pool_references;
+static LIST_HEAD(pulse_pool);
+static LIST_HEAD(pseq_pool);
+static DEFINE_SPINLOCK(pool_lock);
+
+static void pool_register_ref(void)
+{
+ spin_lock_bh(&pool_lock);
+ singleton_pool_references++;
+ spin_unlock_bh(&pool_lock);
+}
+
+static void pool_deregister_ref(void)
+{
+ spin_lock_bh(&pool_lock);
+ singleton_pool_references--;
+ if (singleton_pool_references == 0) {
+ /* free singleton pools with no references left */
+ struct pri_sequence *ps, *ps0;
+ struct pulse_elem *p, *p0;
+
+ list_for_each_entry_safe(p, p0, &pulse_pool, head) {
+ list_del(&p->head);
+ kfree(p);
+ }
+ list_for_each_entry_safe(ps, ps0, &pseq_pool, head) {
+ list_del(&ps->head);
+ kfree(ps);
+ }
+ }
+ spin_unlock_bh(&pool_lock);
+}
+
+static void pool_put_pulse_elem(struct pulse_elem *pe)
+{
+ spin_lock_bh(&pool_lock);
+ list_add(&pe->head, &pulse_pool);
+ spin_unlock_bh(&pool_lock);
+}
+
+static void pool_put_pseq_elem(struct pri_sequence *pse)
+{
+ spin_lock_bh(&pool_lock);
+ list_add(&pse->head, &pseq_pool);
+ spin_unlock_bh(&pool_lock);
+}
+
+static struct pri_sequence *pool_get_pseq_elem(void)
+{
+ struct pri_sequence *pse = NULL;
+
+ spin_lock_bh(&pool_lock);
+ if (!list_empty(&pseq_pool)) {
+ pse = list_first_entry(&pseq_pool, struct pri_sequence, head);
+ list_del(&pse->head);
+ }
+ spin_unlock_bh(&pool_lock);
+
+ if (!pse)
+ pse = kmalloc_obj(*pse, GFP_ATOMIC);
+ return pse;
+}
+
+static struct pulse_elem *pool_get_pulse_elem(void)
+{
+ struct pulse_elem *pe = NULL;
+
+ spin_lock_bh(&pool_lock);
+ if (!list_empty(&pulse_pool)) {
+ pe = list_first_entry(&pulse_pool, struct pulse_elem, head);
+ list_del(&pe->head);
+ }
+ spin_unlock_bh(&pool_lock);
+ return pe;
+}
+
+static struct pulse_elem *pulse_queue_get_tail(struct pri_detector *pde)
+{
+ struct list_head *l = &pde->pulses;
+
+ if (list_empty(l))
+ return NULL;
+ return list_entry(l->prev, struct pulse_elem, head);
+}
+
+static bool pulse_queue_dequeue(struct pri_detector *pde)
+{
+ struct pulse_elem *p = pulse_queue_get_tail(pde);
+
+ if (p) {
+ list_del_init(&p->head);
+ pde->count--;
+ /* give it back to pool */
+ pool_put_pulse_elem(p);
+ }
+ return (pde->count > 0);
+}
+
+/**
+ * pulse_queue_check_window - remove pulses older than window
+ * @pde: pointer on pri_detector
+ *
+ * dequeue pulse that are too old.
+ */
+static void pulse_queue_check_window(struct pri_detector *pde)
+{
+ u64 min_valid_ts;
+ struct pulse_elem *p;
+
+ /* there is no delta time with less than 2 pulses */
+ if (pde->count < 2)
+ return;
+
+ if (pde->last_ts <= pde->window_size)
+ return;
+
+ min_valid_ts = pde->last_ts - pde->window_size;
+ while ((p = pulse_queue_get_tail(pde)) != NULL) {
+ if (p->ts >= min_valid_ts)
+ return;
+ pulse_queue_dequeue(pde);
+ }
+}
+
+/*
+ * pulse_queue_enqueue - Queue one pulse
+ * @pde: pointer on pri_detector
+ *
+ * Add one pulse to the list. If the maximum number of pulses
+ * if reached, remove oldest one.
+ */
+static bool pulse_queue_enqueue(struct pri_detector *pde, u64 ts)
+{
+ struct pulse_elem *p = pool_get_pulse_elem();
+
+ if (!p) {
+ p = kmalloc_obj(*p, GFP_ATOMIC);
+ if (!p)
+ return false;
+ }
+ INIT_LIST_HEAD(&p->head);
+ p->ts = ts;
+ list_add(&p->head, &pde->pulses);
+ pde->count++;
+ pde->last_ts = ts;
+ pulse_queue_check_window(pde);
+ if (pde->count >= pde->max_count)
+ pulse_queue_dequeue(pde);
+
+ return true;
+}
+
+/***************************************************************************
+ * Short waveform
+ **************************************************************************/
+/*
+ * pde_get_multiple() - get number of multiples considering a given tolerance
+ * @return factor if abs(val - factor*fraction) <= tolerance, 0 otherwise
+ */
+static u32 pde_get_multiple(u32 val, u32 fraction, u32 tolerance)
+{
+ u32 remainder;
+ u32 factor;
+ u32 delta;
+
+ if (fraction == 0)
+ return 0;
+
+ delta = (val < fraction) ? (fraction - val) : (val - fraction);
+
+ if (delta <= tolerance)
+ /* val and fraction are within tolerance */
+ return 1;
+
+ factor = val / fraction;
+ remainder = val % fraction;
+ if (remainder > tolerance) {
+ /* no exact match */
+ if ((fraction - remainder) <= tolerance)
+ /* remainder is within tolerance */
+ factor++;
+ else
+ factor = 0;
+ }
+ return factor;
+}
+
+/**
+ * pde_short_create_sequences - create_sequences function for
+ * SHORT/WEATHER/INTERLEAVED radar waveform
+ * @pde: pointer on pri_detector
+ * @ts: timestamp of the pulse
+ * @min_count: Minimum number of pulse to be present in the sequence.
+ * (With this pulse there is already a sequence with @min_count
+ * pulse, so if we can't create a sequence with more pulse don't
+ * create it)
+ * @return: false if an error occurred (memory allocation) true otherwise
+ *
+ * For each pulses queued check if we can create a sequence with
+ * pri = (ts - pulse_queued.ts) which contains more than @min_count pulses.
+ *
+ */
+static bool pde_short_create_sequences(struct pri_detector *pde, u64 ts,
+ u32 min_count)
+{
+ struct pulse_elem *p;
+ u16 pulse_idx = 0;
+
+ list_for_each_entry(p, &pde->pulses, head) {
+ struct pri_sequence ps, *new_ps;
+ struct pulse_elem *p2;
+ u32 tmp_false_count;
+ u64 min_valid_ts;
+ u32 delta_ts = ts - p->ts;
+
+ pulse_idx++;
+
+ if (delta_ts < pde->rs->pri_min)
+ /* ignore too small pri */
+ continue;
+
+ if (delta_ts > pde->rs->pri_max)
+ /* stop on too large pri (sorted list) */
+ break;
+
+ /* build a new sequence with new potential pri */
+ ps.count = 2;
+ ps.count_falses = pulse_idx - 1;
+ ps.first_ts = p->ts;
+ ps.last_ts = ts;
+ ps.pri = ts - p->ts;
+ ps.dur = ps.pri * (pde->rs->ppb - 1) + 2 * pde->rs->max_pri_tolerance;
+
+ p2 = p;
+ tmp_false_count = 0;
+ if (ps.dur > ts)
+ min_valid_ts = 0;
+ else
+ min_valid_ts = ts - ps.dur;
+ /* check which past pulses are candidates for new sequence */
+ list_for_each_entry_continue(p2, &pde->pulses, head) {
+ u32 factor;
+
+ if (p2->ts < min_valid_ts)
+ /* stop on crossing window border */
+ break;
+ /* check if pulse match (multi)PRI */
+ factor = pde_get_multiple(ps.last_ts - p2->ts, ps.pri,
+ pde->rs->max_pri_tolerance);
+ if (factor > 0) {
+ ps.count++;
+ ps.first_ts = p2->ts;
+ /*
+ * on match, add the intermediate falses
+ * and reset counter
+ */
+ ps.count_falses += tmp_false_count;
+ tmp_false_count = 0;
+ } else {
+ /* this is a potential false one */
+ tmp_false_count++;
+ }
+ }
+ if (ps.count <= min_count) {
+ /* did not reach minimum count, drop sequence */
+ continue;
+ }
+ /* this is a valid one, add it */
+ ps.deadline_ts = ps.first_ts + ps.dur;
+ if (pde->rs->type == RADAR_WAVEFORM_WEATHER) {
+ ps.ppb_thresh = 19000000 / (360 * ps.pri);
+ ps.ppb_thresh = PPB_THRESH(ps.ppb_thresh);
+ } else {
+ ps.ppb_thresh = pde->rs->ppb_thresh;
+ }
+
+ new_ps = pool_get_pseq_elem();
+ if (!new_ps)
+ return false;
+ memcpy(new_ps, &ps, sizeof(ps));
+ INIT_LIST_HEAD(&new_ps->head);
+ list_add(&new_ps->head, &pde->sequences);
+ }
+ return true;
+}
+
+/**
+ * pde_short_add_to_existing_seqs - add_to_existing_seqs function for
+ * SHORT/WEATHER/INTERLEAVED radar waveform
+ * @pde: pointer on pri_detector
+ * @ts: timestamp of the pulse
+ *
+ * Check all sequemces created for this pde.
+ * - If the sequence is too old delete it.
+ * - Else if the delta with the previous pulse match the pri of the sequence
+ * add the pulse to this sequence. If the pulse cannot be added it is added
+ * to the false pulses for this sequence
+ *
+ * Return: Length of the longest sequence to which the pulse was added.
+ */
+static u32 pde_short_add_to_existing_seqs(struct pri_detector *pde, u64 ts)
+{
+ u32 max_count = 0;
+ struct pri_sequence *ps, *ps2;
+
+ list_for_each_entry_safe(ps, ps2, &pde->sequences, head) {
+ u32 delta_ts;
+ u32 factor;
+
+ /* first ensure that sequence is within window */
+ if (ts > ps->deadline_ts) {
+ list_del_init(&ps->head);
+ pool_put_pseq_elem(ps);
+ continue;
+ }
+
+ delta_ts = ts - ps->last_ts;
+ factor =
+ pde_get_multiple(delta_ts, ps->pri, pde->rs->max_pri_tolerance);
+
+ if (factor > 0) {
+ ps->last_ts = ts;
+ ps->count++;
+
+ if (max_count < ps->count)
+ max_count = ps->count;
+ } else {
+ ps->count_falses++;
+ }
+ }
+ return max_count;
+}
+
+/**
+ * pde_short_check_detection - check_detection function for
+ * SHORT/WEATHER/INTERLEAVED radar waveform
+ * @pde: pointer on pri_detector
+ *
+ * Check all sequemces created for this pde.
+ * - If a sequence contains more pulses than the threshold and more matching
+ * that false pulses.
+ *
+ * Return: The first complete sequence, or %NULL if none is complete.
+ */
+static struct pri_sequence *pde_short_check_detection(struct pri_detector *pde)
+{
+ struct pri_sequence *ps;
+
+ if (list_empty(&pde->sequences))
+ return NULL;
+
+ list_for_each_entry(ps, &pde->sequences, head) {
+ /*
+ * we assume to have enough matching confidence if we
+ * 1) have enough pulses
+ * 2) have more matching than false pulses
+ */
+ if (ps->count >= ps->ppb_thresh &&
+ ps->count * pde->rs->num_pri > ps->count_falses) {
+ return ps;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * pde_short_init - init function for
+ * SHORT/WEATHER/INTERLEAVED radar waveform
+ * @pde: pointer on pri_detector
+ *
+ * Initialize pri_detector window size to the maximun size of one burst
+ * for the radar specification associated.
+ */
+static void pde_short_init(struct pri_detector *pde)
+{
+ pde->window_size = pde->rs->pri_max * pde->rs->ppb * pde->rs->num_pri;
+ pde->max_count = pde->rs->ppb * 2;
+}
+
+static void pri_detector_reset(struct pri_detector *pde, u64 ts);
+/**
+ * pde_short_add_pulse - Add pulse to a pri_detector for
+ * SHORT/WEATHER/INTERLEAVED radar waveform
+ *
+ * @pde : pointer on pri_detector
+ * @len : width of the pulse
+ * @ts : timestamp of the pulse received
+ * @pri : Delta in us with the previous pulse.
+ * (0 means that delta in bigger than 65535 us)
+ *
+ * Process on pulse within this pri_detector
+ * - First try to add it to existing sequence
+ * - Then try to create a new and longest sequence
+ * - Check if this pulse complete a sequence
+ * - If not save this pulse in the list
+ *
+ * Return: The completed sequence, or %NULL if the pulse did not complete one.
+ */
+static struct pri_sequence *pde_short_add_pulse(struct pri_detector *pde,
+ u16 len, u64 ts, u16 pri)
+{
+ u32 max_updated_seq;
+ struct pri_sequence *ps;
+ const struct radar_detector_specs *rs = pde->rs;
+
+ if (pde->count == 0) {
+ /* This is the first pulse after reset, no need to check sequences */
+ pulse_queue_enqueue(pde, ts);
+ return NULL;
+ }
+
+ if ((ts - pde->last_ts) < rs->max_pri_tolerance) {
+ /* if delta to last pulse is too short, don't use this pulse */
+ return NULL;
+ }
+
+ max_updated_seq = pde_short_add_to_existing_seqs(pde, ts);
+
+ if (!pde_short_create_sequences(pde, ts, max_updated_seq)) {
+ pri_detector_reset(pde, ts);
+ return NULL;
+ }
+
+ ps = pde_short_check_detection(pde);
+
+ if (!ps)
+ pulse_queue_enqueue(pde, ts);
+
+ return ps;
+}
+
+/*
+ * pri detector ops to detect short radar waveform
+ * A Short waveform is defined by :
+ * The width of pulses.
+ * The interval between two pulses inside a burst (called pri)
+ * (some waveform may have or 2/3 interleaved pri)
+ * The number of pulses per burst (ppb)
+ */
+static struct pri_detector_ops pri_detector_short = {
+ .init = pde_short_init,
+ .add_pulse = pde_short_add_pulse,
+ .reset_on_pri_overflow = 1,
+};
+
+/***************************************************************************
+ * Long waveform
+ **************************************************************************/
+#define LONG_RADAR_DURATION 12000000
+#define LONG_RADAR_BURST_MIN_DURATION (12000000 / 20)
+#define LONG_RADAR_MAX_BURST 20
+
+/**
+ * pde_long_init - init function for LONG radar waveform
+ * @pde: pointer on pri_detector
+ *
+ * Initialize pri_detector window size to the long waveform radar
+ * waveform (ie. 12s) and max_count
+ */
+static void pde_long_init(struct pri_detector *pde)
+{
+ pde->window_size = LONG_RADAR_DURATION;
+ pde->max_count = LONG_RADAR_MAX_BURST; /* only count burst not pulses */
+}
+
+/**
+ * pde_long_add_pulse - Add pulse to a pri_detector for
+ * LONG radar waveform
+ *
+ * @pde : pointer on pri_detector
+ * @len : width of the pulse
+ * @ts : timestamp of the pulse received
+ * @pri : Delta in us with the previous pulse.
+ *
+ *
+ * For long pulse we only handle one sequence. Since each burst
+ * have a different set of parameters (number of pulse, pri) than
+ * the previous one we only use pulse width to add the pulse in the
+ * sequence.
+ * We only queue one pulse per burst and valid the radar when enough burst
+ * has been detected.
+ *
+ * Return: The completed sequence, or %NULL if radar was not detected.
+ */
+static struct pri_sequence *pde_long_add_pulse(struct pri_detector *pde,
+ u16 len, u64 ts, u16 pri)
+{
+ struct pri_sequence *ps;
+ const struct radar_detector_specs *rs = pde->rs;
+
+ if (list_empty(&pde->sequences)) {
+ /* First pulse, create a new sequence */
+ ps = pool_get_pseq_elem();
+ if (!ps)
+ return NULL;
+
+ /*For long waveform, "count" represents the number of burst detected */
+ ps->count = 1;
+ /*"count_false" represents the number of pulse in the current burst */
+ ps->count_falses = 1;
+ ps->first_ts = ts;
+ ps->last_ts = ts;
+ ps->deadline_ts = ts + pde->window_size;
+ ps->pri = 0;
+ INIT_LIST_HEAD(&ps->head);
+ list_add(&ps->head, &pde->sequences);
+ pulse_queue_enqueue(pde, ts);
+ } else {
+ u32 delta_ts;
+
+ ps = (struct pri_sequence *)pde->sequences.next;
+
+ delta_ts = ts - ps->last_ts;
+ ps->last_ts = ts;
+
+ if (delta_ts < rs->pri_max) {
+ /* ignore pulse too close from previous one */
+ } else if ((delta_ts >= rs->pri_min) && (delta_ts <= rs->pri_max)) {
+ /*
+ * this is a new pulse in the current burst, ignore it
+ * (i.e don't queue it)
+ */
+ ps->count_falses++;
+ } else if ((ps->count > 2) &&
+ (ps->dur + delta_ts) < LONG_RADAR_BURST_MIN_DURATION) {
+ /* not enough time between burst, ignore pulse */
+ } else {
+ /* a new burst */
+ ps->count++;
+ ps->count_falses = 1;
+
+ /* reset the start of the sequence if deadline reached */
+ if (ts > ps->deadline_ts) {
+ struct pulse_elem *p;
+ u64 min_valid_ts;
+
+ min_valid_ts = ts - pde->window_size;
+ while ((p = pulse_queue_get_tail(pde)) != NULL) {
+ if (p->ts >= min_valid_ts) {
+ ps->first_ts = p->ts;
+ ps->deadline_ts = p->ts + pde->window_size;
+ break;
+ }
+ pulse_queue_dequeue(pde);
+ ps->count--;
+ }
+ }
+
+ /*
+ * valid radar if enough burst detected and delta with first burst
+ * is at least duration/2
+ */
+ if (ps->count > pde->rs->ppb_thresh &&
+ (ts - ps->first_ts) > (pde->window_size / 2)) {
+ return ps;
+ }
+ pulse_queue_enqueue(pde, ts);
+ ps->dur = delta_ts;
+ }
+ }
+ return NULL;
+}
+
+/*
+ * pri detector ops to detect long radar waveform
+ */
+static struct pri_detector_ops pri_detector_long = {
+ .init = pde_long_init,
+ .add_pulse = pde_long_add_pulse,
+ .reset_on_pri_overflow = 0,
+};
+
+/***************************************************************************
+ * PRI detector init/reset/exit/get
+ **************************************************************************/
+/**
+ * pri_detector_init - Create a new PRI detector
+ *
+ * @dpd: dfs_pattern_detector instance pointer
+ * @radar_type: index of radar pattern
+ * @freq: Frequency of the pri detector
+ *
+ * Return: The allocated detector, or %NULL if allocation failed.
+ */
+struct pri_detector *pri_detector_init(struct dfs_pattern_detector *dpd,
+ u16 radar_type, u16 freq)
+{
+ struct pri_detector *pde;
+
+ pde = kzalloc_obj(*pde, GFP_ATOMIC);
+ if (!pde)
+ return NULL;
+
+ INIT_LIST_HEAD(&pde->sequences);
+ INIT_LIST_HEAD(&pde->pulses);
+ INIT_LIST_HEAD(&pde->head);
+ list_add(&pde->head, &dpd->detectors[radar_type]);
+
+ pde->rs = &dpd->radar_spec[radar_type];
+ pde->freq = freq;
+
+ if (pde->rs->type == RADAR_WAVEFORM_LONG) {
+ /* for LONG WAVEFORM */
+ pde->ops = &pri_detector_long;
+ } else {
+ /* for SHORT, WEATHER and INTERLEAVED */
+ pde->ops = &pri_detector_short;
+ }
+
+ /* Init dependent of specs */
+ pde->ops->init(pde);
+
+ pool_register_ref();
+ return pde;
+}
+
+/**
+ * pri_detector_reset - Reset pri_detector
+ *
+ * @pde: pointer on pri_detector
+ * @ts: New ts reference for the pri_detector
+ *
+ * free pulse queue and sequences list and give objects back to pools
+ */
+static void pri_detector_reset(struct pri_detector *pde, u64 ts)
+{
+ struct pri_sequence *ps, *ps0;
+ struct pulse_elem *p, *p0;
+
+ list_for_each_entry_safe(ps, ps0, &pde->sequences, head) {
+ list_del_init(&ps->head);
+ pool_put_pseq_elem(ps);
+ }
+ list_for_each_entry_safe(p, p0, &pde->pulses, head) {
+ list_del_init(&p->head);
+ pool_put_pulse_elem(p);
+ }
+ pde->count = 0;
+ pde->last_ts = ts;
+}
+
+/**
+ * pri_detector_exit - Delete pri_detector
+ *
+ * @pde: pointer on pri_detector
+ */
+static void pri_detector_exit(struct pri_detector *pde)
+{
+ pri_detector_reset(pde, 0);
+ pool_deregister_ref();
+ list_del(&pde->head);
+ kfree(pde);
+}
+
+/**
+ * pri_detector_get - Get a PRI detector for a given frequency and type
+ * @dpd: dfs_pattern_detector instance pointer
+ * @freq: frequency in MHz
+ * @radar_type: index of radar pattern
+ *
+ * Return existing pri detector for the given frequency or return a
+ * newly create one.
+ * Pri detector are "merged" by frequency so that if a pri detector for a freq
+ * of +/- 2Mhz already exists don't create a new one.
+ *
+ * Maybe will need to adapt frequency merge for pattern with chirp.
+ *
+ * Return: An existing or newly allocated detector, or %NULL on allocation
+ * failure.
+ */
+static struct pri_detector *pri_detector_get(struct dfs_pattern_detector *dpd,
+ u16 freq, u16 radar_type)
+{
+ struct pri_detector *pde, *cur = NULL;
+
+ list_for_each_entry(pde, &dpd->detectors[radar_type], head) {
+ if (pde->freq == freq) {
+ if (pde->count)
+ return pde;
+ cur = pde;
+ } else if (pde->freq - 2 == freq && pde->count) {
+ return pde;
+ } else if (pde->freq + 2 == freq && pde->count) {
+ return pde;
+ }
+ }
+
+ if (cur)
+ return cur;
+ else
+ return pri_detector_init(dpd, radar_type, freq);
+}
+
+/******************************************************************************
+ * DFS Pattern Detector
+ *****************************************************************************/
+/**
+ * dfs_pattern_detector_reset() - reset all channel detectors
+ *
+ * @dpd: dfs_pattern_detector
+ */
+static void dfs_pattern_detector_reset(struct dfs_pattern_detector *dpd)
+{
+ struct pri_detector *pde;
+ int i;
+
+ for (i = 0; i < dpd->num_radar_types; i++) {
+ if (!list_empty(&dpd->detectors[i]))
+ list_for_each_entry(pde, &dpd->detectors[i], head)
+ pri_detector_reset(pde, dpd->last_pulse_ts);
+ }
+
+ dpd->last_pulse_ts = 0;
+ dpd->prev_jiffies = jiffies;
+}
+
+/*
+ * dfs_pattern_detector_reset() - delete all channel detectors
+ *
+ * @dpd: dfs_pattern_detector
+ */
+static void dfs_pattern_detector_exit(struct dfs_pattern_detector *dpd)
+{
+ struct pri_detector *pde, *pde0;
+ int i;
+
+ for (i = 0; i < dpd->num_radar_types; i++) {
+ if (!list_empty(&dpd->detectors[i]))
+ list_for_each_entry_safe(pde, pde0, &dpd->detectors[i], head)
+ pri_detector_exit(pde);
+ }
+
+ kfree(dpd);
+}
+
+/**
+ * dfs_pattern_detector_pri_overflow - reset all channel detectors on pri
+ * overflow
+ * @dpd: dfs_pattern_detector
+ */
+static void dfs_pattern_detector_pri_overflow(struct dfs_pattern_detector *dpd)
+{
+ struct pri_detector *pde;
+ int i;
+
+ for (i = 0; i < dpd->num_radar_types; i++) {
+ if (!list_empty(&dpd->detectors[i]))
+ list_for_each_entry(pde, &dpd->detectors[i], head)
+ if (pde->ops->reset_on_pri_overflow)
+ pri_detector_reset(pde, dpd->last_pulse_ts);
+ }
+}
+
+/**
+ * dfs_pattern_detector_add_pulse - Process one pulse
+ *
+ * @dpd: dfs_pattern_detector
+ * @chain: Chain that correspond to this pattern_detector (only for debug)
+ * @freq: frequency of the pulse
+ * @pri: Delta with previous pulse. (0 if delta is too big for u16)
+ * @len: width of the pulse
+ * @now: jiffies value when pulse was received
+ *
+ * Get (or create) the channel_detector for this frequency. Then add the pulse
+ * in each pri_detector created in this channel_detector.
+ *
+ *
+ * Return: %true if the pulse completes a radar pattern, otherwise %false.
+ */
+static bool dfs_pattern_detector_add_pulse(struct dfs_pattern_detector *dpd,
+ enum aicwf_radar_chain chain,
+ u16 freq, u16 pri, u16 len, u32 now)
+{
+ u32 i;
+
+ /*
+ * pulses received for a non-supported or un-initialized
+ * domain are treated as detected radars for fail-safety
+ */
+ if (dpd->region == NL80211_DFS_UNSET)
+ return true;
+
+ /* Compute pulse time stamp */
+ if (pri == 0) {
+ u32 delta_jiffie;
+
+ if (unlikely(now < dpd->prev_jiffies))
+ delta_jiffie = 0xffffffff - dpd->prev_jiffies + now;
+ else
+ delta_jiffie = now - dpd->prev_jiffies;
+ dpd->last_pulse_ts += jiffies_to_usecs(delta_jiffie);
+ dpd->prev_jiffies = now;
+ dfs_pattern_detector_pri_overflow(dpd);
+ } else {
+ dpd->last_pulse_ts += pri;
+ }
+
+ for (i = 0; i < dpd->num_radar_types; i++) {
+ struct pri_sequence *ps;
+ struct pri_detector *pde;
+ const struct radar_detector_specs *rs = &dpd->radar_spec[i];
+
+ /* no need to look up for pde if len is not within range */
+ if (rs->width_min > len || rs->width_max < len)
+ continue;
+
+ pde = pri_detector_get(dpd, freq, i);
+ ps = pde->ops->add_pulse(pde, len, dpd->last_pulse_ts, pri);
+
+ if (ps) {
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_radar_detected(chain, dpd->region, pde->freq, i, ps->pri);
+#endif
+ // reset everything instead of just the channel detector
+ dfs_pattern_detector_reset(dpd);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/*
+ * get_dfs_domain_radar_types() - get radar types for a given DFS domain
+ * @param domain DFS domain
+ * @return radar_types ptr on success, NULL if DFS domain is not supported
+ */
+static const struct radar_types *
+get_dfs_domain_radar_types(enum nl80211_dfs_regions region)
+{
+ u32 i;
+
+ for (i = 0; i < ARRAY_SIZE(dfs_domains); i++) {
+ if (dfs_domains[i]->region == region)
+ return dfs_domains[i];
+ }
+ return NULL;
+}
+
+/**
+ * get_dfs_max_radar_types - Get the maximum number of radar types
+ *
+ * Return: Maximum number of radar patterns supported by any region.
+ */
+static u16 get_dfs_max_radar_types(void)
+{
+ u32 i;
+ u16 max = 0;
+
+ for (i = 0; i < ARRAY_SIZE(dfs_domains); i++) {
+ if (dfs_domains[i]->num_radar_types > max)
+ max = dfs_domains[i]->num_radar_types;
+ }
+ return max;
+}
+
+/*
+ * dfs_pattern_detector_set_domain - set DFS domain
+ *
+ * @dpd: dfs_pattern_detector
+ * @region: DFS region
+ *
+ * set DFS domain, resets detector lines upon domain changes
+ */
+static bool dfs_pattern_detector_set_domain(struct dfs_pattern_detector *dpd,
+ enum nl80211_dfs_regions region,
+ u8 chain)
+{
+ const struct radar_types *rt;
+ struct pri_detector *pde, *pde0;
+ int i;
+
+ if (dpd->region == region)
+ return true;
+
+ dpd->region = NL80211_DFS_UNSET;
+
+ rt = get_dfs_domain_radar_types(region);
+ if (!rt)
+ return false;
+
+ /* delete all pri detectors for previous DFS domain */
+ for (i = 0; i < dpd->num_radar_types; i++) {
+ if (!list_empty(&dpd->detectors[i]))
+ list_for_each_entry_safe(pde, pde0, &dpd->detectors[i], head)
+ pri_detector_exit(pde);
+ }
+
+ if (chain == AICWF_RADAR_RIU)
+ dpd->radar_spec = rt->spec_riu;
+ else
+ dpd->radar_spec = rt->spec_fcu;
+ dpd->num_radar_types = rt->num_radar_types;
+
+ dpd->region = region;
+ return true;
+}
+
+/*
+ * dfs_pattern_detector_init - Initialize dfs_pattern_detector
+ *
+ * @region: DFS region
+ * @return: pointer on dfs_pattern_detector
+ *
+ */
+static struct dfs_pattern_detector *
+dfs_pattern_detector_init(enum nl80211_dfs_regions region, u8 chain)
+{
+ struct dfs_pattern_detector *dpd;
+ u16 i, max_radar_type = get_dfs_max_radar_types();
+
+ dpd = kmalloc(sizeof(*dpd) + max_radar_type * sizeof(dpd->detectors[0]),
+ GFP_KERNEL);
+ if (!dpd)
+ return NULL;
+
+ dpd->region = NL80211_DFS_UNSET;
+ dpd->enabled = AICWF_RADAR_DETECT_DISABLE;
+ dpd->last_pulse_ts = 0;
+ dpd->prev_jiffies = jiffies;
+ dpd->num_radar_types = 0;
+ for (i = 0; i < max_radar_type; i++)
+ INIT_LIST_HEAD(&dpd->detectors[i]);
+
+ if (dfs_pattern_detector_set_domain(dpd, region, chain))
+ return dpd;
+
+ kfree(dpd);
+ return NULL;
+}
+
+/******************************************************************************
+ * driver interface
+ *****************************************************************************/
+static u16 aicwf_radar_get_center_freq(struct aicwf_hw *aicwf_hw, u8 chain)
+{
+ if (chain == AICWF_RADAR_FCU)
+ return aicwf_hw->phy.sec_chan.center_freq1;
+
+ if (chain == AICWF_RADAR_RIU) {
+#ifdef CONFIG_AICWF_FULLMAC
+ if (!aicwf_chanctx_valid(aicwf_hw, aicwf_hw->cur_chanctx)) {
+ WARN(1, "Radar pulse without channel information");
+ } else {
+ return aicwf_hw->chanctx_table[aicwf_hw->cur_chanctx]
+ .chan_def.center_freq1;
+ }
+#endif /* CONFIG_AICWF_FULLMAC */
+ }
+
+ return 0;
+}
+
+static void aicwf_radar_detected(struct aicwf_hw *aicwf_hw)
+{
+#ifdef CONFIG_AICWF_FULLMAC
+ struct cfg80211_chan_def chan_def;
+
+ if (!aicwf_chanctx_valid(aicwf_hw, aicwf_hw->cur_chanctx)) {
+ WARN(1, "Radar detected without channel information");
+ return;
+ }
+
+ /*
+ * recopy chan_def in local variable because aicwf_radar_cancel_cac may
+ * clean the variable (if in CAC and it's the only vif using this context)
+ * and CAC should be aborted before reporting the radar.
+ */
+ chan_def = aicwf_hw->chanctx_table[aicwf_hw->cur_chanctx].chan_def;
+
+ aicwf_radar_cancel_cac(&aicwf_hw->radar);
+ cfg80211_radar_event(aicwf_hw->wiphy, &chan_def, GFP_KERNEL);
+
+#endif /* CONFIG_AICWF_FULLMAC */
+}
+
+static void aicwf_radar_process_pulse(struct work_struct *ws)
+{
+ struct aicwf_radar *radar =
+ container_of(ws, struct aicwf_radar, detection_work);
+ struct aicwf_hw *aicwf_hw = container_of(radar, struct aicwf_hw, radar);
+ int chain;
+ u32 pulses[AICWF_RADAR_LAST][AICWF_RADAR_PULSE_MAX];
+ u16 pulses_count[AICWF_RADAR_LAST];
+ u32 now =
+ jiffies; /* would be better to store jiffies value in IT handler */
+
+ /* recopy pulses locally to avoid too long spin_lock */
+ spin_lock_bh(&radar->lock);
+ for (chain = AICWF_RADAR_RIU; chain < AICWF_RADAR_LAST; chain++) {
+ int start, count;
+
+ count = radar->pulses[chain].count;
+ start = radar->pulses[chain].index - count;
+ if (start < 0)
+ start += AICWF_RADAR_PULSE_MAX;
+
+ pulses_count[chain] = count;
+ if (count == 0)
+ continue;
+
+ if ((start + count) > AICWF_RADAR_PULSE_MAX) {
+ u16 count1 = (AICWF_RADAR_PULSE_MAX - start);
+
+ memcpy(&pulses[chain][0], &radar->pulses[chain].buffer[start],
+ count1 * sizeof(struct radar_pulse));
+ memcpy(&pulses[chain][count1], &radar->pulses[chain].buffer[0],
+ (count - count1) * sizeof(struct radar_pulse));
+ } else {
+ memcpy(&pulses[chain][0], &radar->pulses[chain].buffer[start],
+ count * sizeof(struct radar_pulse));
+ }
+ radar->pulses[chain].count = 0;
+ }
+ spin_unlock_bh(&radar->lock);
+
+ /* now process pulses */
+ for (chain = AICWF_RADAR_RIU; chain < AICWF_RADAR_LAST; chain++) {
+ int i;
+ u16 freq;
+
+ if (pulses_count[chain] == 0)
+ continue;
+
+ freq = aicwf_radar_get_center_freq(aicwf_hw, chain);
+
+ for (i = 0; i < pulses_count[chain]; i++) {
+ struct radar_pulse *p = (struct radar_pulse *)&pulses[chain][i];
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_radar_pulse(chain, p);
+#endif
+ if (dfs_pattern_detector_add_pulse(radar->dpd[chain], chain,
+ (s16)freq + (2 * p->freq),
+ p->rep, (p->len * 2), now)) {
+ u16 idx = radar->detected[chain].index;
+
+ if (chain == AICWF_RADAR_RIU) {
+ /* operating chain, inform upper layer to change channel */
+ if (radar->dpd[chain]->enabled ==
+ AICWF_RADAR_DETECT_REPORT) {
+ aicwf_radar_detected(aicwf_hw);
+ /*
+ * no need to report new radar until upper layer
+ * set a new channel. This prevent warning if a
+ * new radar is detected while mac80211 is
+ * changing channel
+ */
+ aicwf_radar_detection_enable
+ (radar, AICWF_RADAR_DETECT_DISABLE, chain);
+ /*
+ * purge any event received since the beginning
+ * of the function (we are sure not to interfer
+ * with tasklet as we disable detection just
+ * before)
+ */
+ radar->pulses[chain].count = 0;
+ }
+ }
+
+ radar->detected[chain].freq[idx] = (s16)freq + (2 * p->freq);
+ radar->detected[chain].time[idx] = ktime_get_real_seconds();
+ radar->detected[chain].index =
+ ((idx + 1) % NX_NB_RADAR_DETECTED);
+ radar->detected[chain].count++;
+ /* no need to process next pulses for this chain */
+ break;
+ }
+ }
+ }
+}
+
+#ifdef CONFIG_AICWF_FULLMAC
+static void aicwf_radar_cac_work(struct work_struct *ws)
+{
+ struct delayed_work *dw = container_of(ws, struct delayed_work, work);
+ struct aicwf_radar *radar = container_of(dw, struct aicwf_radar, cac_work);
+ struct aicwf_hw *aicwf_hw = container_of(radar, struct aicwf_hw, radar);
+ struct aicwf_chanctx *ctxt;
+
+ if (!radar->cac_vif) {
+ WARN(1, "CAC finished but no vif set");
+ return;
+ }
+
+ ctxt = &aicwf_hw->chanctx_table[radar->cac_vif->ch_index];
+ cfg80211_cac_event(radar->cac_vif->ndev, &ctxt->chan_def,
+ NL80211_RADAR_CAC_FINISHED, GFP_KERNEL, 0);
+ aicwf_send_apm_stop_cac_req(aicwf_hw, radar->cac_vif);
+ aicwf_chanctx_unlink(radar->cac_vif);
+
+ radar->cac_vif = NULL;
+}
+#endif /* CONFIG_AICWF_FULLMAC */
+
+bool aicwf_radar_detection_init(struct aicwf_radar *radar)
+{
+ spin_lock_init(&radar->lock);
+
+ radar->dpd[AICWF_RADAR_RIU] =
+ dfs_pattern_detector_init(NL80211_DFS_UNSET, AICWF_RADAR_RIU);
+ if (!radar->dpd[AICWF_RADAR_RIU])
+ return false;
+
+ radar->dpd[AICWF_RADAR_FCU] =
+ dfs_pattern_detector_init(NL80211_DFS_UNSET, AICWF_RADAR_FCU);
+ if (!radar->dpd[AICWF_RADAR_FCU]) {
+ aicwf_radar_detection_deinit(radar);
+ return false;
+ }
+
+ INIT_WORK(&radar->detection_work, aicwf_radar_process_pulse);
+#ifdef CONFIG_AICWF_FULLMAC
+ INIT_DELAYED_WORK(&radar->cac_work, aicwf_radar_cac_work);
+ radar->cac_vif = NULL;
+#endif /* CONFIG_AICWF_FULLMAC */
+ return true;
+}
+
+void aicwf_radar_detection_deinit(struct aicwf_radar *radar)
+{
+ if (radar->dpd[AICWF_RADAR_RIU]) {
+ dfs_pattern_detector_exit(radar->dpd[AICWF_RADAR_RIU]);
+ radar->dpd[AICWF_RADAR_RIU] = NULL;
+ }
+ if (radar->dpd[AICWF_RADAR_FCU]) {
+ dfs_pattern_detector_exit(radar->dpd[AICWF_RADAR_FCU]);
+ radar->dpd[AICWF_RADAR_FCU] = NULL;
+ }
+}
+
+bool aicwf_radar_set_domain(struct aicwf_radar *radar,
+ enum nl80211_dfs_regions region)
+{
+ if (!radar->dpd[0])
+ return false;
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_radar_set_region(region);
+#endif
+ return (dfs_pattern_detector_set_domain(radar->dpd[AICWF_RADAR_RIU], region,
+ AICWF_RADAR_RIU) &&
+ dfs_pattern_detector_set_domain(radar->dpd[AICWF_RADAR_FCU], region,
+ AICWF_RADAR_FCU));
+}
+
+void aicwf_radar_detection_enable(struct aicwf_radar *radar, u8 enable, u8 chain)
+{
+ if (chain < AICWF_RADAR_LAST) {
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_radar_enable_detection(radar->dpd[chain]->region, enable, chain);
+#endif
+ spin_lock_bh(&radar->lock);
+ radar->dpd[chain]->enabled = enable;
+ spin_unlock_bh(&radar->lock);
+ }
+}
+
+bool aicwf_radar_detection_is_enable(struct aicwf_radar *radar, u8 chain)
+{
+ return radar->dpd[chain]->enabled != AICWF_RADAR_DETECT_DISABLE;
+}
+
+#ifdef CONFIG_AICWF_FULLMAC
+void aicwf_radar_start_cac(struct aicwf_radar *radar, u32 cac_time_ms,
+ struct aicwf_vif *vif)
+{
+ WARN(radar->cac_vif, "CAC already in progress");
+ radar->cac_vif = vif;
+ schedule_delayed_work(&radar->cac_work, msecs_to_jiffies(cac_time_ms));
+}
+
+void aicwf_radar_cancel_cac(struct aicwf_radar *radar)
+{
+ struct aicwf_hw *aicwf_hw = container_of(radar, struct aicwf_hw, radar);
+
+ if (!radar->cac_vif)
+ return;
+
+ if (cancel_delayed_work(&radar->cac_work)) {
+ struct aicwf_chanctx *ctxt;
+
+ ctxt = &aicwf_hw->chanctx_table[radar->cac_vif->ch_index];
+ aicwf_send_apm_stop_cac_req(aicwf_hw, radar->cac_vif);
+ cfg80211_cac_event(radar->cac_vif->ndev, &ctxt->chan_def,
+ NL80211_RADAR_CAC_ABORTED, GFP_KERNEL, 0);
+ aicwf_chanctx_unlink(radar->cac_vif);
+ }
+
+ radar->cac_vif = NULL;
+}
+
+void aicwf_radar_detection_enable_on_cur_channel(struct aicwf_hw *aicwf_hw)
+{
+ struct aicwf_chanctx *ctxt;
+
+ /* If no information on current channel do nothing */
+ if (!aicwf_chanctx_valid(aicwf_hw, aicwf_hw->cur_chanctx))
+ return;
+
+ ctxt = &aicwf_hw->chanctx_table[aicwf_hw->cur_chanctx];
+ if (ctxt->chan_def.chan->flags & IEEE80211_CHAN_RADAR) {
+ aicwf_radar_detection_enable(&aicwf_hw->radar, AICWF_RADAR_DETECT_REPORT,
+ AICWF_RADAR_RIU);
+ } else {
+ aicwf_radar_detection_enable(&aicwf_hw->radar, AICWF_RADAR_DETECT_DISABLE,
+ AICWF_RADAR_RIU);
+ }
+}
+#endif /* CONFIG_AICWF_FULLMAC */
+
+/*****************************************************************************
+ * Debug functions
+ *****************************************************************************/
+static int aicwf_radar_dump_pri_detector(char *buf, size_t len,
+ struct pri_detector *pde)
+{
+ char freq_info[] = "Freq = %3.dMhz\n";
+ char seq_info[] = " pri | count | false\n";
+ struct pri_sequence *seq;
+ int res, write = 0;
+
+ if (list_empty(&pde->sequences))
+ return 0;
+
+ if (!buf) {
+ int nb_seq = 1;
+
+ list_for_each_entry(seq, &pde->sequences, head) {
+ nb_seq++;
+ }
+
+ return (sizeof(freq_info) + nb_seq * sizeof(seq_info));
+ }
+
+ res = scnprintf(buf, len, freq_info, pde->freq);
+ write += res;
+ len -= res;
+
+ res = scnprintf(&buf[write], len, "%s", seq_info);
+ write += res;
+ len -= res;
+
+ list_for_each_entry(seq, &pde->sequences, head) {
+ res = scnprintf(&buf[write], len, " %6.d | %2.d | %.2d\n",
+ seq->pri, seq->count, seq->count_falses);
+ write += res;
+ len -= res;
+ }
+
+ return write;
+}
+
+int aicwf_radar_dump_pattern_detector(char *buf, size_t len,
+ struct aicwf_radar *radar, u8 chain)
+{
+ struct dfs_pattern_detector *dpd = radar->dpd[chain];
+ char info[] = "Type = %3.d\n";
+ struct pri_detector *pde;
+ int i, res, write = 0;
+
+ /* if buf is NULL return size needed for dump */
+ if (!buf) {
+ int size_needed = 0;
+
+ for (i = 0; i < dpd->num_radar_types; i++) {
+ list_for_each_entry(pde, &dpd->detectors[i], head) {
+ size_needed += aicwf_radar_dump_pri_detector(NULL, 0, pde);
+ }
+ size_needed += sizeof(info);
+
+ return size_needed;
+ }
+ }
+
+ /* */
+ for (i = 0; i < dpd->num_radar_types; i++) {
+ res = scnprintf(&buf[write], len, info, i);
+
+ write += res;
+ len -= res;
+
+ list_for_each_entry(pde, &dpd->detectors[i], head) {
+ res = aicwf_radar_dump_pri_detector(&buf[write], len, pde);
+ write += res;
+ len -= res;
+ }
+ }
+
+ return write;
+}
+
+int aicwf_radar_dump_radar_detected(char *buf, size_t len,
+ struct aicwf_radar *radar, u8 chain)
+{
+ struct aicwf_radar_detected *detect = &radar->detected[chain];
+ char info[] = "2001/02/02 - 02:20 5126MHz\n";
+ int idx, i, res, write = 0;
+ int count = detect->count;
+
+ if (count > NX_NB_RADAR_DETECTED)
+ count = NX_NB_RADAR_DETECTED;
+
+ if (!buf)
+ return (count * sizeof(info)) + 1;
+
+ idx = (detect->index - detect->count) % NX_NB_RADAR_DETECTED;
+
+ for (i = 0; i < count; i++) {
+ struct tm tm;
+
+ time64_to_tm(detect->time[idx], 0, &tm);
+ res =
+ scnprintf(&buf[write], len, "%.4d/%.2d/%.2d - %.2d:%.2d %4.4dMHz\n",
+ (int)tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+ tm.tm_hour, tm.tm_min, detect->freq[idx]);
+ write += res;
+ len -= res;
+
+ idx = (idx + 1) % NX_NB_RADAR_DETECTED;
+ }
+
+ return write;
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_resv_mem.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_resv_mem.c
new file mode 100644
index 000000000000..b3ee4ba83104
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_resv_mem.c
@@ -0,0 +1,106 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief reserved skb memory
+ *
+ ******************************************************************************
+ */
+#include <linux/printk.h>
+#include <linux/skbuff.h>
+
+#include "aicwf_resv_mem.h"
+
+static const u32 aicwf_resv_mem_size[AIC_RESV_MEM_NUM] = {
+ [AIC_RESV_MEM_TXDATA] = 1536 * 64,
+};
+
+static const char *const aicwf_resv_mem_name[AIC_RESV_MEM_NUM] = {
+ [AIC_RESV_MEM_TXDATA] = "resv_mem_txdata",
+};
+
+/**
+ * aicwf_resv_mem_init - Reserve the buffers for the lifetime of a device
+ * @pool: Pool to fill, owned by the SDIO device
+ *
+ * A buffer that cannot be allocated here is allocated on first use by
+ * aicwf_resv_mem_alloc_skb().
+ */
+void aicwf_resv_mem_init(struct aicwf_resv_mem *pool)
+{
+ int i;
+
+ for (i = 0; i < AIC_RESV_MEM_NUM; i++) {
+ pool->entry[i].used = false;
+ pool->entry[i].skb = dev_alloc_skb(aicwf_resv_mem_size[i]);
+ }
+}
+
+/**
+ * aicwf_resv_mem_deinit - Release the buffers that are not handed out
+ * @pool: Pool filled by aicwf_resv_mem_init()
+ */
+void aicwf_resv_mem_deinit(struct aicwf_resv_mem *pool)
+{
+ int i;
+
+ for (i = 0; i < AIC_RESV_MEM_NUM; i++) {
+ if (!pool->entry[i].used && pool->entry[i].skb)
+ dev_kfree_skb(pool->entry[i].skb);
+ pool->entry[i].skb = NULL;
+ }
+}
+
+/**
+ * aicwf_resv_mem_alloc_skb - Acquire a reserved socket buffer
+ * @pool: Pool filled by aicwf_resv_mem_init()
+ * @length: Minimum required buffer size
+ * @id: Reserved-buffer identifier
+ *
+ * Return: The reserved buffer, or %NULL if it is too small, already in use,
+ * or cannot be allocated.
+ */
+struct sk_buff *aicwf_resv_mem_alloc_skb(struct aicwf_resv_mem *pool,
+ unsigned int length,
+ enum aicwf_resv_mem_id id)
+{
+ struct aicwf_resv_mem_entry *entry = &pool->entry[id];
+
+ if (aicwf_resv_mem_size[id] < length) {
+ pr_err("no enough mem\n");
+ return NULL;
+ }
+
+ if (entry->used) {
+ pr_err("mem in use\n");
+ return NULL;
+ }
+
+ if (!entry->skb) {
+ entry->skb = dev_alloc_skb(aicwf_resv_mem_size[id]);
+ if (!entry->skb)
+ return NULL;
+ }
+
+ pr_debug("alloc %s success, id: %d, size: %u\n",
+ aicwf_resv_mem_name[id], id, aicwf_resv_mem_size[id]);
+
+ entry->used = true;
+ return entry->skb;
+}
+
+/**
+ * aicwf_resv_mem_kfree_skb - Release a reserved socket buffer for reuse
+ * @pool: Pool filled by aicwf_resv_mem_init()
+ * @skb: Reserved buffer returned by aicwf_resv_mem_alloc_skb()
+ * @id: Reserved-buffer identifier
+ */
+void aicwf_resv_mem_kfree_skb(struct aicwf_resv_mem *pool, struct sk_buff *skb,
+ enum aicwf_resv_mem_id id)
+{
+ pool->entry[id].used = false;
+ pr_debug("free %s success, id: %d, size: %u\n",
+ aicwf_resv_mem_name[id], id, aicwf_resv_mem_size[id]);
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx.c
new file mode 100644
index 000000000000..748467719b7c
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx.c
@@ -0,0 +1,2434 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file aicwf_rx.c
+ *
+ * @brief RX handle
+ *
+ ******************************************************************************
+ */
+
+#include <linux/bitfield.h>
+#include <linux/etherdevice.h>
+#include <linux/ieee80211.h>
+#include <net/ieee80211_radiotap.h>
+
+#include "aicwf_txrxif.h"
+#include "aicwf_config.h"
+#include "aicwf_defs.h"
+#include "aicwf_events.h"
+#include "aicwf_rx.h"
+#include "aicwf_tx.h"
+#ifdef CONFIG_AIC8800_ARP_OFFLOAD
+#include "aicwf_msg_tx.h"
+#include <linux/ip.h>
+#include <linux/udp.h>
+#include <net/ip.h>
+#endif
+
+#ifndef IEEE80211_MAX_CHAINS
+#define IEEE80211_MAX_CHAINS 4
+#endif
+
+const u16 tx_legrates_lut_rate[] = {10, 20, 55, 110, 60, 90,
+ 120, 180, 240, 360, 480, 540};
+
+const struct aicwf_legrate legrates_lut[] = {
+ [0] = {.idx = 0, .rate = 10}, [1] = {.idx = 1, .rate = 20},
+ [2] = {.idx = 2, .rate = 55}, [3] = {.idx = 3, .rate = 110},
+ [4] = {.idx = -1, .rate = 0}, [5] = {.idx = -1, .rate = 0},
+ [6] = {.idx = -1, .rate = 0}, [7] = {.idx = -1, .rate = 0},
+ [8] = {.idx = 10, .rate = 480}, [9] = {.idx = 8, .rate = 240},
+ [10] = {.idx = 6, .rate = 120}, [11] = {.idx = 4, .rate = 60},
+ [12] = {.idx = 11, .rate = 540}, [13] = {.idx = 9, .rate = 360},
+ [14] = {.idx = 7, .rate = 180}, [15] = {.idx = 5, .rate = 90},
+};
+
+struct vendor_radiotap_hdr {
+ u8 oui[3];
+ u8 subns;
+ u16 len;
+ u8 data[];
+};
+
+/**
+ * aicwf_rx_get_vif - Return pointer to the destination vif
+ *
+ * @aicwf_hw: main driver data
+ * @vif_idx: vif index present in rx descriptor
+ *
+ * Select the vif that should receive this frame. Returns NULL if the
+ * destination vif is not active or vif is not specified in the descriptor.
+ *
+ * Return: The active destination VIF, or %NULL if none was selected.
+ */
+static inline struct aicwf_vif *aicwf_rx_get_vif(struct aicwf_hw *aicwf_hw,
+ int vif_idx)
+{
+ struct aicwf_vif *aicwf_vif = NULL;
+
+ if (vif_idx >= 0 && vif_idx < NX_VIRT_DEV_MAX) {
+ aicwf_vif = aicwf_hw->vif_table[vif_idx];
+
+ if (!aicwf_vif) {
+ dev_err(aicwf_hw->dev, "aicwf_hw->vif_table[%d] NULL\n",
+ vif_idx);
+ return NULL;
+ } else if (!aicwf_vif->up) {
+ dev_err(aicwf_hw->dev, "aicwf_hw->vif_table[%d] is down\n", vif_idx);
+ return NULL;
+ }
+ }
+
+ return aicwf_vif;
+}
+
+/**
+ * aicwf_rx_vector_convert - Convert a legacy RX vector into a new RX vector
+ * format
+ *
+ * @aicwf_hw: main driver data.
+ * @rx_vect1: Rx vector 1 descriptor of the received frame.
+ * @rx_vect2: Rx vector 2 descriptor of the received frame.
+ */
+static void aicwf_rx_vector_convert(struct aicwf_hw *aicwf_hw,
+ struct rx_vector_1 *rx_vect1,
+ struct rx_vector_2 *rx_vect2)
+{
+ struct rx_vector_1_old rx_vect1_leg;
+ struct rx_vector_2_old rx_vect2_leg;
+ u32 phy_vers = aicwf_hw->version_cfm.version_phy_2;
+
+ // Check if we need to do the conversion. Only if old modem is used
+ if (__MDM_MAJOR_VERSION(phy_vers) > 0) {
+ rx_vect1->rssi1 = rx_vect1->rssi_leg;
+ return;
+ }
+ // Copy the received vector locally
+ memcpy(&rx_vect1_leg, rx_vect1, sizeof(struct rx_vector_1_old));
+
+ // Reset it
+ memset(rx_vect1, 0, sizeof(struct rx_vector_1));
+
+ // Perform the conversion
+ rx_vect1->format_mod = rx_vect1_leg.format_mod;
+ rx_vect1->ch_bw = rx_vect1_leg.ch_bw;
+ rx_vect1->antenna_set = rx_vect1_leg.antenna_set;
+ rx_vect1->leg_length = rx_vect1_leg.leg_length;
+ rx_vect1->leg_rate = rx_vect1_leg.leg_rate;
+ rx_vect1->rssi1 = rx_vect1_leg.rssi1;
+
+ switch (rx_vect1->format_mod) {
+ case FORMATMOD_NON_HT:
+ case FORMATMOD_NON_HT_DUP_OFDM:
+ rx_vect1->leg.lsig_valid = rx_vect1_leg.lsig_valid;
+ rx_vect1->leg.chn_bw_in_non_ht = rx_vect1_leg.num_extn_ss;
+ rx_vect1->leg.dyn_bw_in_non_ht = rx_vect1_leg.dyn_bw;
+ break;
+ case FORMATMOD_HT_MF:
+ case FORMATMOD_HT_GF:
+ rx_vect1->ht.aggregation = rx_vect1_leg.aggregation;
+ rx_vect1->ht.fec = rx_vect1_leg.fec_coding;
+ rx_vect1->ht.lsig_valid = rx_vect1_leg.lsig_valid;
+ rx_vect1->ht.length = rx_vect1_leg.ht_length;
+ rx_vect1->ht.mcs = rx_vect1_leg.mcs;
+ rx_vect1->ht.num_extn_ss = rx_vect1_leg.num_extn_ss;
+ rx_vect1->ht.short_gi = rx_vect1_leg.short_gi;
+ rx_vect1->ht.smoothing = rx_vect1_leg.smoothing;
+ rx_vect1->ht.sounding = rx_vect1_leg.sounding;
+ rx_vect1->ht.stbc = rx_vect1_leg.stbc;
+ break;
+ case FORMATMOD_VHT:
+ rx_vect1->vht.beamformed = !rx_vect1_leg.smoothing;
+ rx_vect1->vht.fec = rx_vect1_leg.fec_coding;
+ rx_vect1->vht.length = rx_vect1_leg.ht_length | rx_vect1_leg._ht_length << 8;
+ rx_vect1->vht.mcs = rx_vect1_leg.mcs & 0x0F;
+ rx_vect1->vht.nss =
+ rx_vect1_leg.stbc ? rx_vect1_leg.n_sts / 2 : rx_vect1_leg.n_sts;
+ rx_vect1->vht.doze_not_allowed = rx_vect1_leg.doze_not_allowed;
+ rx_vect1->vht.short_gi = rx_vect1_leg.short_gi;
+ rx_vect1->vht.sounding = rx_vect1_leg.sounding;
+ rx_vect1->vht.stbc = rx_vect1_leg.stbc;
+ rx_vect1->vht.group_id = rx_vect1_leg.group_id;
+ rx_vect1->vht.partial_aid = rx_vect1_leg.partial_aid;
+ rx_vect1->vht.first_user = rx_vect1_leg.first_user;
+ break;
+ }
+
+ if (!rx_vect2)
+ return;
+
+ // Copy the received vector 2 locally
+ memcpy(&rx_vect2_leg, rx_vect2, sizeof(struct rx_vector_2_old));
+
+ // Reset it
+ memset(rx_vect2, 0, sizeof(struct rx_vector_2));
+
+ rx_vect2->rcpi1 = rx_vect2_leg.rcpi;
+ rx_vect2->rcpi2 = rx_vect2_leg.rcpi;
+ rx_vect2->rcpi3 = rx_vect2_leg.rcpi;
+ rx_vect2->rcpi4 = rx_vect2_leg.rcpi;
+
+ rx_vect2->evm1 = rx_vect2_leg.evm1;
+ rx_vect2->evm2 = rx_vect2_leg.evm2;
+ rx_vect2->evm3 = rx_vect2_leg.evm3;
+ rx_vect2->evm4 = rx_vect2_leg.evm4;
+}
+
+/**
+ * aicwf_rx_statistic - save some statistics about received frames
+ *
+ * @aicwf_hw: main driver data.
+ * @hw_rxhdr: Rx Hardware descriptor of the received frame.
+ * @sta: STA that sent the frame.
+ */
+static void aicwf_rx_statistic(struct aicwf_hw *aicwf_hw,
+ struct hw_rxhdr *hw_rxhdr, struct aicwf_sta *sta)
+{
+ struct aicwf_stats *stats = &aicwf_hw->stats;
+ struct aicwf_rx_rate_stats *rate_stats = &sta->stats.rx_rate;
+ struct rx_vector_1 *rxvect = &hw_rxhdr->hwvect.rx_vect1;
+ int mpdu, ampdu, mpdu_prev, rate_idx;
+
+ /* save complete hwvect */
+ sta->stats.last_rx = hw_rxhdr->hwvect;
+
+ /* update ampdu rx stats */
+ mpdu = hw_rxhdr->hwvect.mpdu_cnt;
+ ampdu = hw_rxhdr->hwvect.ampdu_cnt;
+ mpdu_prev = stats->ampdus_rx_map[ampdu];
+
+ if (mpdu_prev < mpdu)
+ stats->ampdus_rx_miss += mpdu - mpdu_prev - 1;
+ else
+ stats->ampdus_rx[mpdu_prev]++;
+ stats->ampdus_rx_map[ampdu] = mpdu;
+
+ /* update rx rate statistic */
+ if (!rate_stats->size)
+ return;
+
+ if (rxvect->format_mod > FORMATMOD_NON_HT_DUP_OFDM) {
+ int mcs;
+ int bw = rxvect->ch_bw;
+ int sgi;
+ int nss;
+
+ switch (rxvect->format_mod) {
+ case FORMATMOD_HT_MF:
+ case FORMATMOD_HT_GF:
+ mcs = rxvect->ht.mcs % 8;
+ nss = rxvect->ht.mcs / 8;
+ sgi = rxvect->ht.short_gi;
+ rate_idx = N_CCK + N_OFDM + nss * 32 + mcs * 4 + bw * 2 + sgi;
+ break;
+ case FORMATMOD_VHT:
+ mcs = rxvect->vht.mcs;
+ nss = rxvect->vht.nss;
+ sgi = rxvect->vht.short_gi;
+ rate_idx =
+ N_CCK + N_OFDM + N_HT + nss * 80 + mcs * 8 + bw * 2 + sgi;
+ break;
+ case FORMATMOD_HE_SU:
+ mcs = rxvect->he.mcs;
+ nss = rxvect->he.nss;
+ sgi = rxvect->he.gi_type;
+ rate_idx = N_CCK + N_OFDM + N_HT + N_VHT + nss * 144 + mcs * 12 +
+ bw * 3 + sgi;
+ break;
+ default:
+ mcs = rxvect->he.mcs;
+ nss = rxvect->he.nss;
+ sgi = rxvect->he.gi_type;
+ rate_idx = N_CCK + N_OFDM + N_HT + N_VHT + N_HE_SU + nss * 216 +
+ mcs * 18 + rxvect->he.ru_size * 3 + sgi;
+ break;
+ }
+ } else {
+ int idx = legrates_lut[rxvect->leg_rate].idx;
+
+ if (idx < 4)
+ rate_idx = idx * 2 + rxvect->pre_type;
+ else
+ rate_idx = N_CCK + idx - 4;
+ }
+ if (rate_idx >= 0 && rate_idx < rate_stats->size) {
+ if (!rate_stats->table[rate_idx])
+ rate_stats->rate_cnt++;
+ rate_stats->table[rate_idx]++;
+ rate_stats->cpt++;
+ } else {
+ wiphy_err(aicwf_hw->wiphy, "RX: Invalid index conversion => %d/%d\n",
+ rate_idx, rate_stats->size);
+ }
+}
+
+/**
+ * aicwf_rx_data_skb_resend - Resend one received data frame
+ *
+ * @aicwf_hw: Main driver data
+ * @aicwf_vif: VIF that received the buffer
+ * @skb: Received socket buffer
+ * @rxhdr: Hardware receive descriptor
+ *
+ * Copy the received frame into a buffer with enough headroom and queue it for
+ * transmission on the same wireless interface.
+ */
+
+void aicwf_rx_data_skb_resend(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ struct sk_buff *skb, struct hw_rxhdr *rxhdr)
+{
+ struct sk_buff *rx_skb = skb;
+ struct sk_buff *skb_copy;
+
+ rx_skb->dev = aicwf_vif->ndev;
+ skb_reset_mac_header(rx_skb);
+ /* resend pkt on wireless interface */
+ /*
+ * always need to copy buffer when forward=0 to get enough headrom for
+ * tsdesc
+ */
+ skb_copy = skb_copy_expand
+ (rx_skb, sizeof(struct aicwf_txhdr) + AICWF_SWTXHDR_ALIGN_SZ + 3 + 24 + 8,
+ 0, GFP_ATOMIC);
+
+ if (skb_copy) {
+ int res;
+
+ skb_copy->protocol = htons(ETH_P_802_3);
+ skb_reset_network_header(skb_copy);
+ skb_reset_mac_header(skb_copy);
+
+ aicwf_vif->is_resending = true;
+ res = dev_queue_xmit(skb_copy);
+ aicwf_vif->is_resending = false;
+ /* note: buffer is always consummed by dev_queue_xmit */
+ if (res == NET_XMIT_DROP) {
+ aicwf_vif->net_stats.rx_dropped++;
+ aicwf_vif->net_stats.tx_dropped++;
+ } else if (res != NET_XMIT_SUCCESS) {
+ netdev_err(aicwf_vif->ndev,
+ "failed to re-send buffer to driver: %d\n", res);
+ aicwf_vif->net_stats.tx_errors++;
+ }
+ } else {
+ netdev_err(aicwf_vif->ndev, "failed to copy skb\n");
+ }
+}
+
+static void aicwf_rx_data_skb_forward(struct aicwf_hw *aicwf_hw,
+ struct aicwf_vif *aicwf_vif,
+ struct sk_buff *skb,
+ struct hw_rxhdr *rxhdr)
+{
+ struct sk_buff *rx_skb;
+
+ rx_skb = skb;
+ rx_skb->dev = aicwf_vif->ndev;
+ skb_reset_mac_header(rx_skb);
+
+ /* Update statistics */
+ aicwf_vif->net_stats.rx_packets++;
+ aicwf_vif->net_stats.rx_bytes += rx_skb->len;
+
+ rx_skb->protocol = eth_type_trans(rx_skb, aicwf_vif->ndev);
+ memset(rx_skb->cb, 0, sizeof(rx_skb->cb));
+
+#ifdef CONFIG_AIC8800_RX_NETIF_RECV_SKB // modify by aic
+ local_bh_disable();
+ netif_receive_skb(rx_skb);
+ local_bh_enable();
+#else
+ if (in_interrupt()) {
+ netif_rx(rx_skb);
+ } else {
+ /*
+ * If the receive is not processed inside an ISR, the softirqd must be
+ * woken explicitly to service the NET_RX_SOFTIRQ.
+ * * In 2.6 kernels, this is handledby netif_rx_ni(), but in earlier
+ * kernels, we need to do it manually.
+ */
+ netif_rx_ni(rx_skb);
+ }
+#endif
+
+ aicwf_hw->stats.last_rx = jiffies;
+}
+
+bool aicwf_rx_data_skb(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ struct sk_buff *skb, struct hw_rxhdr *rxhdr)
+{
+ struct sk_buff_head list;
+ struct sk_buff *rx_skb;
+ bool amsdu = rxhdr->flags_is_amsdu;
+ u8 flags_dst_idx = rxhdr->flags_dst_idx;
+ bool resend = false, forward = true;
+
+ skb->dev = aicwf_vif->ndev;
+
+ __skb_queue_head_init(&list);
+
+ if (amsdu) {
+ aicwf_rxdata_process_amsdu
+ (aicwf_hw, skb, rxhdr->flags_vif_idx,
+ &list); // rxhdr not used below since skb free!
+ } else {
+ aicwf_hw->stats.amsdus_rx[0]++;
+ __skb_queue_head(&list, skb);
+ }
+
+ if (skb_queue_empty(&list))
+ return forward;
+
+ if ((AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_AP ||
+ AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_AP_VLAN ||
+ AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_P2P_GO) &&
+ !(aicwf_vif->ap.flags & AICWF_AP_ISOLATE)) {
+ const struct ethhdr *eth;
+
+ rx_skb = skb_peek(&list);
+ skb_reset_mac_header(rx_skb);
+ eth = eth_hdr(rx_skb);
+
+ if (unlikely(is_multicast_ether_addr(eth->h_dest))) {
+ /*
+ * broadcast pkt need to be forward to upper layer and resent
+ * on wireless interface
+ */
+ resend = true;
+ } else {
+ /*
+ * unicast pkt for STA inside the BSS, no need to forward to upper
+ * layer simply resend on wireless interface
+ */
+ if (flags_dst_idx != AICWF_INVALID_STA) {
+ struct aicwf_sta *sta = &aicwf_hw->sta_table[flags_dst_idx];
+
+ if (sta->valid && sta->vlan_idx == aicwf_vif->vif_index) {
+ forward = false;
+ resend = true;
+ }
+ }
+ }
+ } else if (AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_MESH_POINT) {
+ const struct ethhdr *eth;
+
+ rx_skb = skb_peek(&list);
+ skb_reset_mac_header(rx_skb);
+ eth = eth_hdr(rx_skb);
+
+ if (!is_multicast_ether_addr(eth->h_dest)) {
+ /*
+ * unicast pkt for STA inside the BSS, no need to forward to upper
+ * layer simply resend on wireless interface
+ */
+ if (flags_dst_idx != AICWF_INVALID_STA) {
+ forward = false;
+ resend = true;
+ }
+ }
+ }
+
+ while (!skb_queue_empty(&list)) {
+ rx_skb = __skb_dequeue(&list);
+
+ /* resend pkt on wireless interface */
+ if (resend) {
+ struct sk_buff *skb_copy;
+ /*
+ * always need to copy buffer when forward=0 to get enough headrom
+ * for tsdesc
+ */
+ skb_copy = skb_copy_expand(rx_skb,
+ sizeof(struct aicwf_txhdr) +
+ AICWF_SWTXHDR_ALIGN_SZ + 3 + 24 + 8,
+ 0, GFP_ATOMIC);
+
+ if (skb_copy) {
+ int res;
+
+ skb_copy->protocol = htons(ETH_P_802_3);
+ skb_reset_network_header(skb_copy);
+ skb_reset_mac_header(skb_copy);
+
+ aicwf_vif->is_resending = true;
+ res = dev_queue_xmit(skb_copy);
+ aicwf_vif->is_resending = false;
+ /* note: buffer is always consummed by dev_queue_xmit */
+ if (res == NET_XMIT_DROP) {
+ aicwf_vif->net_stats.rx_dropped++;
+ aicwf_vif->net_stats.tx_dropped++;
+ } else if (res != NET_XMIT_SUCCESS) {
+ netdev_err(aicwf_vif->ndev,
+ "failed to re-send buffer to driver: %d\n",
+ res);
+ aicwf_vif->net_stats.tx_errors++;
+ }
+ } else {
+ netdev_err(aicwf_vif->ndev, "failed to copy skb\n");
+ }
+ }
+
+ /* forward pkt to upper layer */
+ if (forward) {
+ /* Update statistics */
+ aicwf_vif->net_stats.rx_packets++;
+ aicwf_vif->net_stats.rx_bytes += rx_skb->len;
+
+ rx_skb->protocol = eth_type_trans(rx_skb, aicwf_vif->ndev);
+#ifdef CONFIG_AIC8800_ARP_OFFLOAD
+ if (AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_STATION ||
+ AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_P2P_CLIENT)
+ arpoffload_proc(rx_skb, aicwf_vif);
+#endif
+ memset(rx_skb->cb, 0, sizeof(rx_skb->cb));
+
+#ifdef CONFIG_AIC8800_RX_NETIF_RECV_SKB // modify by aic
+ local_bh_disable();
+ netif_receive_skb(rx_skb);
+ local_bh_enable();
+#else
+ if (in_interrupt()) {
+ netif_rx(rx_skb);
+ } else {
+ /*
+ * If the receive is not processed inside an ISR, the softirqd
+ * must be woken explicitly to service the NET_RX_SOFTIRQ.
+ * * In 2.6 kernels, this is handledby netif_rx_ni(), but in
+ * earlier kernels, we need to do it manually.
+ */
+ netif_rx_ni(rx_skb);
+ }
+#endif
+
+ aicwf_hw->stats.last_rx = jiffies;
+ }
+ }
+
+ return forward;
+}
+
+/*
+ * aicwf_rx_mgmt - Process one 802.11 management frame
+ *
+ * @aicwf_hw: main driver data
+ * @aicwf_vif: vif to upload the buffer to
+ * @skb: skb received
+ * @rxhdr: HW rx descriptor
+ *
+ * Forward the management frame to a given interface.
+ */
+static void aicwf_rx_mgmt(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ struct sk_buff *skb, struct hw_rxhdr *hw_rxhdr)
+{
+ struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
+ struct rx_vector_1 *rxvect = &hw_rxhdr->hwvect.rx_vect1;
+
+ if (ieee80211_is_mgmt(mgmt->frame_control) &&
+ (skb->len <= 24 || skb->len > 768)) {
+ dev_dbg(aicwf_hw->dev, "mgmt err\n");
+ return;
+ }
+ if (ieee80211_is_beacon(mgmt->frame_control)) {
+ if (skb->len < offsetof(struct ieee80211_mgmt, u.beacon.variable))
+ return;
+ if ((AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_MESH_POINT) &&
+ hw_rxhdr->flags_new_peer) {
+ /* TODO: the value of parameter sig_dbm need to be confirmed */
+ cfg80211_notify_new_peer_candidate
+ (aicwf_vif->ndev, mgmt->sa, mgmt->u.beacon.variable,
+ skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable),
+ rxvect->rssi1, GFP_ATOMIC);
+ } else {
+ cfg80211_report_obss_beacon(aicwf_hw->wiphy, skb->data, skb->len,
+ hw_rxhdr->phy_info.phy_prim20_freq,
+ rxvect->rssi1);
+ }
+ } else if (skb->len >= offsetofend(struct ieee80211_mgmt, u.deauth.reason_code) &&
+ (ieee80211_is_deauth(mgmt->frame_control) ||
+ ieee80211_is_disassoc(mgmt->frame_control)) &&
+ (le16_to_cpu(mgmt->u.deauth.reason_code) ==
+ WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
+ le16_to_cpu(mgmt->u.deauth.reason_code) ==
+ WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA)) {
+ cfg80211_rx_unprot_mlme_mgmt(aicwf_vif->ndev, skb->data, skb->len);
+ } else if ((AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_STATION) &&
+ (ieee80211_is_action(mgmt->frame_control) &&
+ (mgmt->u.action.category == 6))) {
+ struct cfg80211_ft_event_params ft_event;
+
+ ft_event.target_ap = (uint8_t *)&mgmt->u.action + ETH_ALEN + 2;
+ ft_event.ies = (uint8_t *)&mgmt->u.action + ETH_ALEN * 2 + 2;
+ if (skb->len < ft_event.ies - (uint8_t *)mgmt)
+ return;
+ ft_event.ies_len = skb->len - (ft_event.ies - (uint8_t *)mgmt);
+ ft_event.ric_ies = NULL;
+ ft_event.ric_ies_len = 0;
+ cfg80211_ft_event(aicwf_vif->ndev, &ft_event);
+ } else {
+ cfg80211_rx_mgmt(&aicwf_vif->wdev, hw_rxhdr->phy_info.phy_prim20_freq,
+ rxvect->rssi1, skb->data, skb->len, 0);
+ }
+}
+
+/*
+ * aicwf_rx_mgmt_any - Process one 802.11 management frame
+ *
+ * @aicwf_hw: main driver data
+ * @skb: skb received
+ * @rxhdr: HW rx descriptor
+ *
+ * Process the management frame and free the corresponding skb.
+ * If vif is not specified in the rx descriptor, the frame is uploaded
+ * on all active vifs.
+ */
+static void aicwf_rx_mgmt_any(struct aicwf_hw *aicwf_hw, struct sk_buff *skb,
+ struct hw_rxhdr *hw_rxhdr)
+{
+ struct aicwf_vif *aicwf_vif;
+ int vif_idx = hw_rxhdr->flags_vif_idx;
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_mgmt_rx(hw_rxhdr->phy_info.phy_prim20_freq, vif_idx,
+ hw_rxhdr->flags_sta_idx, (struct ieee80211_mgmt *)skb->data);
+#endif
+ if (vif_idx == AICWF_INVALID_VIF) {
+ list_for_each_entry(aicwf_vif, &aicwf_hw->vifs, list) {
+ if (!aicwf_vif->up)
+ continue;
+ aicwf_rx_mgmt(aicwf_hw, aicwf_vif, skb, hw_rxhdr);
+ }
+ } else {
+ aicwf_vif = aicwf_rx_get_vif(aicwf_hw, vif_idx);
+ if (aicwf_vif)
+ aicwf_rx_mgmt(aicwf_hw, aicwf_vif, skb, hw_rxhdr);
+ }
+
+ dev_kfree_skb(skb);
+}
+
+/**
+ * aicwf_rx_rtap_hdrlen - Return radiotap header length
+ *
+ * @rxvect: Rx vector used to fill the radiotap header
+ * @has_vend_rtap: boolean indicating if vendor specific data is present
+ *
+ * Compute the length of the radiotap header based on @rxvect and vendor
+ * specific data (if any).
+ *
+ * Return: Required radiotap header length in bytes.
+ */
+static u8 aicwf_rx_rtap_hdrlen(struct rx_vector_1 *rxvect, bool has_vend_rtap)
+{
+ u8 rtap_len;
+
+ /* Compute radiotap header length */
+ rtap_len = sizeof(struct ieee80211_radiotap_header) + 8;
+
+ // Check for multiple antennas
+ if (hweight32(rxvect->antenna_set) > 1)
+ // antenna and antenna signal fields
+ rtap_len += 4 * hweight8(rxvect->antenna_set);
+
+ // TSFT
+ if (!has_vend_rtap) {
+ rtap_len = ALIGN(rtap_len, 8);
+ rtap_len += 8;
+ }
+
+ // IEEE80211_HW_SIGNAL_DBM
+ rtap_len++;
+
+ // Check if single antenna
+ if (hweight32(rxvect->antenna_set) == 1)
+ rtap_len++; // Single antenna
+
+ // padding for RX FLAGS
+ rtap_len = ALIGN(rtap_len, 2);
+
+ // Check for HT frames
+ if (rxvect->format_mod == FORMATMOD_HT_MF ||
+ rxvect->format_mod == FORMATMOD_HT_GF)
+ rtap_len += 3;
+
+ // Check for AMPDU
+ if (!(has_vend_rtap) &&
+ (rxvect->format_mod >= FORMATMOD_VHT ||
+ (rxvect->format_mod > FORMATMOD_NON_HT_DUP_OFDM &&
+ rxvect->ht.aggregation))) {
+ rtap_len = ALIGN(rtap_len, 4);
+ rtap_len += 8;
+ }
+
+ // Check for VHT frames
+ if (rxvect->format_mod == FORMATMOD_VHT) {
+ rtap_len = ALIGN(rtap_len, 2);
+ rtap_len += 12;
+ }
+
+ // Check for HE frames
+ if (rxvect->format_mod == FORMATMOD_HE_SU) {
+ rtap_len = ALIGN(rtap_len, 2);
+ rtap_len += sizeof(struct ieee80211_radiotap_he);
+ }
+
+ // Check for multiple antennas
+ if (hweight32(rxvect->antenna_set) > 1) {
+ // antenna and antenna signal fields
+ rtap_len += 2 * hweight8(rxvect->antenna_set);
+ }
+
+ // Check for vendor specific data
+ if (has_vend_rtap) {
+ /* vendor presence bitmap */
+ rtap_len += 4;
+ /* alignment for fixed 6-byte vendor data header */
+ rtap_len = ALIGN(rtap_len, 2);
+ }
+
+ return rtap_len;
+}
+
+/**
+ * aicwf_rx_add_rtap_hdr - Add radiotap header to sk_buff
+ *
+ * @aicwf_hw: main driver data
+ * @skb: skb received (will include the radiotap header)
+ * @rxvect: Rx vector
+ * @phy_info: Information regarding the phy
+ * @hwvect: HW Info (NULL if vendor specific data is available)
+ * @rtap_len: Length of the radiotap header
+ * @vend_rtap_len: radiotap vendor length (0 if not present)
+ * @vend_it_present: radiotap vendor present
+ *
+ * Builds a radiotap header and add it to @skb.
+ */
+static void aicwf_rx_add_rtap_hdr(struct aicwf_hw *aicwf_hw, struct sk_buff *skb,
+ struct rx_vector_1 *rxvect,
+ struct phy_channel_info_desc *phy_info,
+ struct hw_vect *hwvect, int rtap_len,
+ u8 vend_rtap_len, u32 vend_it_present)
+{
+ struct ieee80211_radiotap_header *rtap;
+ u8 *pos;
+ int rate_idx;
+ __le32 *it_present;
+ u32 it_present_val = 0;
+ bool fec_coding = false;
+ bool short_gi = false;
+ bool stbc = false;
+ bool aggregation = false;
+
+ rtap = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
+ memset((u8 *)rtap, 0, rtap_len);
+
+ rtap->it_version = 0;
+ rtap->it_pad = 0;
+ rtap->it_len = cpu_to_le16(rtap_len + vend_rtap_len);
+
+ it_present = &rtap->it_present;
+
+ // Check for multiple antennas
+ if (hweight32(rxvect->antenna_set) > 1) {
+ int chain;
+ unsigned long chains = rxvect->antenna_set;
+
+ for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
+ it_present_val |= BIT(IEEE80211_RADIOTAP_EXT) |
+ BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
+ put_unaligned_le32(it_present_val, it_present);
+ it_present++;
+ it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
+ BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
+ }
+ }
+
+ // Check if vendor specific data is present
+ if (vend_rtap_len) {
+ it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
+ BIT(IEEE80211_RADIOTAP_EXT);
+ put_unaligned_le32(it_present_val, it_present);
+ it_present++;
+ it_present_val = vend_it_present;
+ }
+
+ put_unaligned_le32(it_present_val, it_present);
+ pos = (void *)(it_present + 1);
+
+ // IEEE80211_RADIOTAP_TSFT
+ if (hwvect) {
+ rtap->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
+ // padding
+ while ((pos - (u8 *)rtap) & 7)
+ *pos++ = 0;
+ put_unaligned_le64((((u64)le32_to_cpu(hwvect->tsf_hi) << 32) +
+ (u64)le32_to_cpu(hwvect->tsf_lo)),
+ pos);
+ pos += 8;
+ }
+
+ // IEEE80211_RADIOTAP_FLAGS
+ rtap->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_FLAGS);
+ if (hwvect && !hwvect->frm_successful_rx)
+ *pos |= IEEE80211_RADIOTAP_F_BADFCS;
+ if (!rxvect->pre_type && rxvect->format_mod <= FORMATMOD_NON_HT_DUP_OFDM)
+ *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
+ pos++;
+
+ // IEEE80211_RADIOTAP_RATE
+ // check for HT, VHT or HE frames
+ if (rxvect->format_mod >= FORMATMOD_HE_SU) {
+ rate_idx = rxvect->he.mcs;
+ fec_coding = rxvect->he.fec;
+ stbc = rxvect->he.stbc;
+ aggregation = true;
+ *pos = 0;
+ } else if (rxvect->format_mod == FORMATMOD_VHT) {
+ rate_idx = rxvect->vht.mcs;
+ fec_coding = rxvect->vht.fec;
+ short_gi = rxvect->vht.short_gi;
+ stbc = rxvect->vht.stbc;
+ aggregation = true;
+ *pos = 0;
+ } else if (rxvect->format_mod > FORMATMOD_NON_HT_DUP_OFDM) {
+ rate_idx = rxvect->ht.mcs;
+ fec_coding = rxvect->ht.fec;
+ short_gi = rxvect->ht.short_gi;
+ stbc = rxvect->ht.stbc;
+ aggregation = rxvect->ht.aggregation;
+ *pos = 0;
+ } else {
+ struct ieee80211_supported_band *band =
+ aicwf_hw->wiphy->bands[phy_info->phy_band];
+ rtap->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
+ rate_idx = legrates_lut[rxvect->leg_rate].idx;
+ if (phy_info->phy_band == NL80211_BAND_5GHZ)
+ rate_idx -= 4;
+ if (WARN_ON_ONCE(rate_idx < 0 || rate_idx >= band->n_bitrates))
+ *pos = 0;
+ else
+ *pos = DIV_ROUND_UP(band->bitrates[rate_idx].bitrate, 5);
+ }
+ pos++;
+
+ // IEEE80211_RADIOTAP_CHANNEL
+ rtap->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
+ put_unaligned_le16(phy_info->phy_prim20_freq, pos);
+ pos += 2;
+
+ if (phy_info->phy_band == NL80211_BAND_5GHZ)
+ put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ, pos);
+ else if (rxvect->format_mod > FORMATMOD_NON_HT_DUP_OFDM)
+ put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ, pos);
+ else
+ put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ, pos);
+ pos += 2;
+
+ if (hweight32(rxvect->antenna_set) == 1) {
+ // IEEE80211_RADIOTAP_DBM_ANTSIGNAL
+ rtap->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
+ *pos++ = rxvect->rssi1;
+
+ // IEEE80211_RADIOTAP_ANTENNA
+ rtap->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_ANTENNA);
+ *pos++ = rxvect->antenna_set;
+ }
+
+ // IEEE80211_RADIOTAP_RX_FLAGS
+ rtap->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RX_FLAGS);
+ // 2 byte alignment
+ if ((pos - (u8 *)rtap) & 1)
+ *pos++ = 0;
+ put_unaligned_le16(0, pos);
+ // Right now, we only support fcs error (no RX_FLAG_FAILED_PLCP_CRC)
+ pos += 2;
+
+ // Check if HT
+ if (rxvect->format_mod == FORMATMOD_HT_MF ||
+ rxvect->format_mod == FORMATMOD_HT_GF) {
+ rtap->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
+ *pos++ = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
+ IEEE80211_RADIOTAP_MCS_HAVE_GI |
+ IEEE80211_RADIOTAP_MCS_HAVE_BW;
+ *pos = 0;
+ if (short_gi)
+ *pos |= IEEE80211_RADIOTAP_MCS_SGI;
+ if (rxvect->ch_bw == PHY_CHNL_BW_40)
+ *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
+ if (rxvect->format_mod == FORMATMOD_HT_GF)
+ *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
+ if (fec_coding)
+ *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
+ *pos++ |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
+ *pos++ = rate_idx;
+ }
+
+ // check for HT or VHT frames
+ if (aggregation && hwvect) {
+ // 4 byte alignment
+ while ((pos - (u8 *)rtap) & 3)
+ pos++;
+ rtap->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
+ put_unaligned_le32(hwvect->ampdu_cnt, pos);
+ pos += 4;
+ put_unaligned_le32(0, pos);
+ pos += 4;
+ }
+
+ // Check for VHT frames
+ if (rxvect->format_mod == FORMATMOD_VHT) {
+ u16 vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
+ IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
+ u8 vht_nss = rxvect->vht.nss + 1;
+
+ rtap->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
+
+ if (rxvect->ch_bw == PHY_CHNL_BW_160 && phy_info->phy_center2_freq)
+ vht_details &= ~IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
+ put_unaligned_le16(vht_details, pos);
+ pos += 2;
+
+ // flags
+ if (short_gi)
+ *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
+ if (stbc)
+ *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
+ pos++;
+
+ // bandwidth
+ if (rxvect->ch_bw == PHY_CHNL_BW_40)
+ *pos++ = 1;
+ if (rxvect->ch_bw == PHY_CHNL_BW_80)
+ *pos++ = 4;
+ else if ((rxvect->ch_bw == PHY_CHNL_BW_160) &&
+ phy_info->phy_center2_freq)
+ *pos++ = 0; // 80P80
+ else if (rxvect->ch_bw == PHY_CHNL_BW_160)
+ *pos++ = 11;
+ else // 20 MHz
+ *pos++ = 0;
+
+ // MCS/NSS
+ *pos = (rate_idx << 4) | vht_nss;
+ pos += 4;
+ if (fec_coding)
+ *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
+ pos++;
+ // group ID
+ pos++;
+ // partial_aid
+ pos += 2;
+ }
+
+ // Check for HE frames
+ if (rxvect->format_mod == FORMATMOD_HE_SU) {
+ struct ieee80211_radiotap_he he;
+#define HE_PREP(f, val) cpu_to_le16(FIELD_PREP(IEEE80211_RADIOTAP_HE_##f, val))
+#define D1_KNOWN(f) cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_##f##_KNOWN)
+#define D2_KNOWN(f) cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_##f##_KNOWN)
+
+ he.data1 = D1_KNOWN(DATA_MCS) | D1_KNOWN(BSS_COLOR) |
+ D1_KNOWN(BEAM_CHANGE) | D1_KNOWN(UL_DL) | D1_KNOWN(CODING) |
+ D1_KNOWN(STBC) | D1_KNOWN(BW_RU_ALLOC) | D1_KNOWN(DOPPLER) |
+ D1_KNOWN(DATA_DCM);
+ he.data2 = D2_KNOWN(GI) | D2_KNOWN(TXBF);
+
+ if (stbc) {
+ he.data6 |= HE_PREP(DATA6_NSTS, 2);
+ he.data3 |= HE_PREP(DATA3_STBC, 1);
+ } else {
+ he.data6 |= HE_PREP(DATA6_NSTS, rxvect->he.nss);
+ }
+
+ he.data3 |= HE_PREP(DATA3_BSS_COLOR, rxvect->he.bss_color);
+ he.data3 |= HE_PREP(DATA3_BEAM_CHANGE, rxvect->he.beam_change);
+ he.data3 |= HE_PREP(DATA3_UL_DL, rxvect->he.uplink_flag);
+ he.data3 |= HE_PREP(DATA3_BSS_COLOR, rxvect->he.bss_color);
+ he.data3 |= HE_PREP(DATA3_DATA_MCS, rxvect->he.mcs);
+ he.data3 |= HE_PREP(DATA3_DATA_DCM, rxvect->he.dcm);
+ he.data3 |= HE_PREP(DATA3_CODING, rxvect->he.fec);
+
+ he.data5 |= HE_PREP(DATA5_GI, rxvect->he.gi_type);
+ he.data5 |= HE_PREP(DATA5_TXBF, rxvect->he.beamformed);
+ he.data5 |= HE_PREP(DATA5_LTF_SIZE, rxvect->he.he_ltf_type + 1);
+
+ switch (rxvect->ch_bw) {
+ case PHY_CHNL_BW_20:
+ he.data5 |=
+ HE_PREP(DATA5_DATA_BW_RU_ALLOC,
+ IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
+ break;
+ case PHY_CHNL_BW_40:
+ he.data5 |=
+ HE_PREP(DATA5_DATA_BW_RU_ALLOC,
+ IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
+ break;
+ case PHY_CHNL_BW_80:
+ he.data5 |=
+ HE_PREP(DATA5_DATA_BW_RU_ALLOC,
+ IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
+ break;
+ case PHY_CHNL_BW_160:
+ he.data5 |=
+ HE_PREP(DATA5_DATA_BW_RU_ALLOC,
+ IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
+ break;
+ default:
+ WARN_ONCE(1, "Invalid SU BW %d\n", rxvect->ch_bw);
+ }
+
+ he.data6 |= HE_PREP(DATA6_DOPPLER, rxvect->he.doppler);
+
+ /* ensure 2 byte alignment */
+ while ((pos - (u8 *)rtap) & 1)
+ pos++;
+ rtap->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE);
+ if ((pos + sizeof(he)) <= (u8 *)rtap + rtap_len) {
+ u8 *src = (u8 *)&he;
+ u8 *dst = pos;
+
+ for (size_t i = 0; i < sizeof(he); i++)
+ dst[i] = src[i];
+ pos += sizeof(he);
+ } else {
+ dev_err(aicwf_hw->dev, "not enough space for HE radiotap data\n");
+ return;
+ }
+ //memcpy(pos, &he, sizeof(he));
+ //pos += sizeof(he);
+ }
+
+ // Rx Chains
+ if (hweight32(rxvect->antenna_set) > 1) {
+ int chain;
+ unsigned long chains = rxvect->antenna_set;
+ u8 rssis[4] = {rxvect->rssi1, rxvect->rssi1, rxvect->rssi1,
+ rxvect->rssi1};
+
+ for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
+ *pos++ = rssis[chain];
+ *pos++ = chain;
+ }
+ }
+}
+
+/**
+ * aicwf_rx_monitor - Add a radiotap header and deliver a monitor frame
+ *
+ * @aicwf_hw: main driver data
+ * @aicwf_vif: vif that received the buffer
+ * @skb: sk_buff received
+ * @hw_rxhdr_ptr: Pointer to HW RX header
+ * @rtap_len: Radiotap Header length
+ *
+ * Add a radiotap header to the received socket buffer and send it to netdev.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+static int aicwf_rx_monitor(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ struct sk_buff *skb, struct hw_rxhdr *hw_rxhdr_ptr,
+ u8 rtap_len)
+{
+ skb->dev = aicwf_vif->ndev;
+
+ if (aicwf_vif->wdev.iftype != NL80211_IFTYPE_MONITOR) {
+ netdev_err(aicwf_vif->ndev, "not a monitor vif\n");
+ return -1;
+ }
+
+ /* Add RadioTap Header */
+ if (skb_headroom(skb) < rtap_len) {
+ if (pskb_expand_head(skb, rtap_len, 0, GFP_ATOMIC)) {
+ dev_err(aicwf_hw->dev, "failed to expand skb headroom for radiotap header\n");
+ return -ENOMEM;
+ }
+ aicwf_rx_add_rtap_hdr(aicwf_hw, skb, &hw_rxhdr_ptr->hwvect.rx_vect1,
+ &hw_rxhdr_ptr->phy_info, &hw_rxhdr_ptr->hwvect,
+ rtap_len, 0, 0);
+ } else {
+ aicwf_rx_add_rtap_hdr(aicwf_hw, skb, &hw_rxhdr_ptr->hwvect.rx_vect1,
+ &hw_rxhdr_ptr->phy_info, &hw_rxhdr_ptr->hwvect,
+ rtap_len, 0, 0);
+ }
+
+ skb_reset_mac_header(skb);
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
+ skb->pkt_type = PACKET_OTHERHOST;
+ skb->protocol = htons(ETH_P_802_2);
+
+ local_bh_disable();
+ netif_receive_skb(skb);
+ local_bh_enable();
+
+ return 0;
+}
+
+#ifdef CONFIG_AIC8800_ARP_OFFLOAD
+
+static void handle_dhcp_ack(u8 *option, u16 offset, struct dhcpinfo *dhcph,
+ struct aicwf_vif *aicwf_vif)
+{
+ if (option[offset] == DHCP_OPTION_MESSAGE_TYPE &&
+ option[offset + 2] == DHCP_ACK) {
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+
+ if (aicwf_hw)
+ dev_dbg(aicwf_hw->dev, "paired=%x, should=%x\n",
+ aicwf_vif->sta.paired_cipher_type,
+ WLAN_CIPHER_SUITE_CCMP);
+
+ if (aicwf_vif->sta.paired_cipher_type == WLAN_CIPHER_SUITE_CCMP ||
+ aicwf_vif->sta.paired_cipher_type == WLAN_CIPHER_SUITE_AES_CMAC ||
+ (aicwf_vif->sta.group_cipher_type == 0xff &&
+ aicwf_vif->sta.paired_cipher_type == 0xff)) {
+ aicwf_send_arpoffload_en_req(aicwf_vif->aicwf_hw, aicwf_vif, dhcph->yiaddr, 1);
+ } else {
+ aicwf_send_arpoffload_en_req(aicwf_vif->aicwf_hw, aicwf_vif, dhcph->yiaddr, 0);
+ }
+ }
+}
+
+void arpoffload_proc(struct sk_buff *skb, struct aicwf_vif *aicwf_vif)
+{
+ struct iphdr *iphead;
+ struct udphdr *udph;
+ struct dhcpinfo *dhcph;
+ unsigned int ip_len, ip_hdr_len, udp_len, length, offset = 0;
+ u8 *option;
+
+ if (skb->protocol != htons(ETH_P_IP) ||
+ !pskb_may_pull(skb, sizeof(*iphead)))
+ return;
+
+ iphead = (struct iphdr *)skb->data;
+ if (iphead->version != 4 || iphead->ihl < 5 ||
+ iphead->protocol != IPPROTO_UDP || ip_is_fragment(iphead))
+ return;
+
+ ip_hdr_len = iphead->ihl * 4;
+ ip_len = ntohs(iphead->tot_len);
+ if (ip_len > skb->len || ip_len < ip_hdr_len + sizeof(*udph) ||
+ !pskb_may_pull(skb, ip_hdr_len + sizeof(*udph)))
+ return;
+
+ udph = (struct udphdr *)(skb->data + ip_hdr_len);
+ udp_len = ntohs(udph->len);
+ if (udph->source != htons(SERVER_PORT) ||
+ udph->dest != htons(CLIENT_PORT) ||
+ udp_len > ip_len - ip_hdr_len ||
+ udp_len < sizeof(*udph) + offsetof(struct dhcpinfo, options) ||
+ !pskb_may_pull(skb, ip_hdr_len + udp_len))
+ return;
+
+ dhcph = (struct dhcpinfo *)(skb->data + ip_hdr_len + sizeof(*udph));
+ if (dhcph->cookie != htonl(DHCP_MAGIC) || dhcph->op != 2 ||
+ memcmp(dhcph->chaddr, aicwf_vif->ndev->dev_addr, ETH_ALEN))
+ return;
+
+ length = udp_len - sizeof(*udph) - offsetof(struct dhcpinfo, options);
+ option = (u8 *)dhcph + offsetof(struct dhcpinfo, options);
+ while (offset < length) {
+ u8 code = option[offset];
+ u8 option_len;
+
+ if (code == DHCP_OPTION_END)
+ break;
+ if (!code) { /* DHCP padding is a single byte. */
+ offset++;
+ continue;
+ }
+ if (length - offset < 2)
+ break;
+ option_len = option[offset + 1];
+ if (option_len > length - offset - 2)
+ break;
+ if (code == DHCP_OPTION_MESSAGE_TYPE && option_len == 1)
+ handle_dhcp_ack(option, offset, dhcph, aicwf_vif);
+ offset += 2 + option_len;
+ }
+}
+#endif
+
+#ifdef CONFIG_AIC8800_RX_REORDER
+void reord_rxframe_free(spinlock_t *lock, struct list_head *q,
+ struct list_head *list)
+{
+ spin_lock_bh(lock);
+ list_add(list, q);
+ spin_unlock_bh(lock);
+}
+
+struct recv_msdu *reord_rxframe_alloc(spinlock_t *lock, struct list_head *q)
+{
+ struct recv_msdu *rxframe;
+
+ spin_lock_bh(lock);
+ if (list_empty(q)) {
+ spin_unlock_bh(lock);
+ return NULL;
+ }
+ rxframe = list_entry(q->next, struct recv_msdu, rxframe_list);
+ list_del_init(q->next);
+ spin_unlock_bh(lock);
+ return rxframe;
+}
+
+struct reord_ctrl_info *reord_init_sta(struct aicwf_rx_priv *rx_priv,
+ const u8 *mac_addr)
+{
+ u8 i = 0;
+ struct reord_ctrl *preorder_ctrl = NULL;
+ struct reord_ctrl_info *reord_info;
+ struct aicwf_bus *bus_if = rx_priv->sdiodev->bus_if;
+
+ if (bus_if->state == BUS_DOWN_ST || !rx_priv) {
+ dev_err(bus_if->dev, "bad stat!\n");
+ return NULL;
+ }
+
+ pr_debug("%pM\n", mac_addr);
+ reord_info = kmalloc_obj(*reord_info, GFP_ATOMIC);
+ if (!reord_info)
+ return NULL;
+
+ memcpy(reord_info->mac_addr, mac_addr, ETH_ALEN);
+ for (i = 0; i < 8; i++) {
+ preorder_ctrl = &reord_info->preorder_ctrl[i];
+ preorder_ctrl->enable = true;
+ preorder_ctrl->ind_sn = 0xffff;
+ preorder_ctrl->wsize_b = AICWF_REORDER_WINSIZE;
+ preorder_ctrl->rx_priv = rx_priv;
+ INIT_LIST_HEAD(&preorder_ctrl->reord_list);
+ spin_lock_init(&preorder_ctrl->reord_list_lock);
+ timer_setup(&preorder_ctrl->reord_timer, reord_timeout_handler, 0);
+ INIT_WORK(&preorder_ctrl->reord_timer_work, reord_timeout_worker);
+ }
+
+ return reord_info;
+}
+
+int reord_flush_tid(struct aicwf_rx_priv *rx_priv, struct sk_buff *skb, u8 tid)
+{
+ struct reord_ctrl_info *reord_info;
+ struct reord_ctrl *preorder_ctrl;
+ struct aicwf_vif *aicwf_vif = (struct aicwf_vif *)rx_priv->aicwf_vif;
+ struct ethhdr *eh = (struct ethhdr *)(skb->data);
+ u8 *mac;
+ unsigned long flags;
+ u8 found = 0;
+ struct list_head *phead, *plist;
+ struct recv_msdu *prframe;
+
+ if (!aicwf_vif || skb->len < ETH_HLEN ||
+ tid >= ARRAY_SIZE(reord_info->preorder_ctrl))
+ return -EINVAL;
+
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_STATION ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
+ mac = eh->h_dest;
+ } else if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_AP ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
+ mac = eh->h_source;
+ } else {
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+
+ if (aicwf_hw)
+ dev_err(aicwf_hw->dev, "error mode:%d!\n", aicwf_vif->wdev.iftype);
+ dev_kfree_skb(skb);
+ return -1;
+ }
+
+ spin_lock_bh(&rx_priv->stas_reord_lock);
+ list_for_each_entry(reord_info, &rx_priv->stas_reord_list, list) {
+ if (!memcmp(mac, reord_info->mac_addr, ETH_ALEN)) {
+ found = 1;
+ preorder_ctrl = &reord_info->preorder_ctrl[tid];
+ break;
+ }
+ }
+ if (!found) {
+ spin_unlock_bh(&rx_priv->stas_reord_lock);
+ return 0;
+ }
+ spin_unlock_bh(&rx_priv->stas_reord_lock);
+
+ if (!preorder_ctrl->enable)
+ return 0;
+ spin_lock_irqsave(&preorder_ctrl->reord_list_lock, flags);
+ phead = &preorder_ctrl->reord_list;
+ while (1) {
+ if (list_empty(phead))
+ break;
+ plist = phead->next;
+ prframe = list_entry(plist, struct recv_msdu, reord_pending_list);
+ reord_single_frame_ind(rx_priv, prframe);
+ list_del_init(&prframe->reord_pending_list);
+ }
+
+ pr_debug("flush:tid=%d", tid);
+ preorder_ctrl->enable = false;
+ spin_unlock_irqrestore(&preorder_ctrl->reord_list_lock, flags);
+ if (timer_pending(&preorder_ctrl->reord_timer))
+ timer_delete_sync(&preorder_ctrl->reord_timer);
+ cancel_work_sync(&preorder_ctrl->reord_timer_work);
+
+ return 0;
+}
+
+void reord_deinit_sta(struct aicwf_rx_priv *rx_priv,
+ struct reord_ctrl_info *reord_info)
+{
+ u8 i = 0;
+ unsigned long flags;
+ struct reord_ctrl *preorder_ctrl = NULL;
+
+ if (!rx_priv) {
+ pr_err("bad rx_priv!\n");
+ return;
+ }
+
+ for (i = 0; i < 8; i++) {
+ struct recv_msdu *req, *next;
+
+ preorder_ctrl = &reord_info->preorder_ctrl[i];
+ spin_lock_irqsave(&preorder_ctrl->reord_list_lock, flags);
+ list_for_each_entry_safe(req, next, &preorder_ctrl->reord_list,
+ reord_pending_list) {
+ list_del_init(&req->reord_pending_list);
+ if (req->pkt)
+ dev_kfree_skb(req->pkt);
+ req->pkt = NULL;
+ reord_rxframe_free(&rx_priv->freeq_lock,
+ &rx_priv->rxframes_freequeue,
+ &req->rxframe_list);
+ }
+ spin_unlock_irqrestore(&preorder_ctrl->reord_list_lock, flags);
+ if (timer_pending(&preorder_ctrl->reord_timer))
+ timer_delete_sync(&preorder_ctrl->reord_timer);
+ cancel_work_sync(&preorder_ctrl->reord_timer_work);
+ }
+ list_del(&reord_info->list);
+ kfree(reord_info);
+}
+
+int reord_single_frame_ind(struct aicwf_rx_priv *rx_priv,
+ struct recv_msdu *prframe)
+{
+ struct list_head *rxframes_freequeue = NULL;
+ struct sk_buff *skb = NULL;
+ struct aicwf_vif *aicwf_vif = (struct aicwf_vif *)rx_priv->aicwf_vif;
+ struct sk_buff_head list;
+ struct sk_buff *rx_skb;
+
+ rxframes_freequeue = &rx_priv->rxframes_freequeue;
+ skb = prframe->pkt;
+
+ if (!skb) {
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+
+ if (aicwf_hw)
+ dev_err(aicwf_hw->dev, "skb is NULL\n");
+ return -1;
+ }
+
+ if (!prframe->forward) {
+ dev_kfree_skb(skb);
+ prframe->pkt = NULL;
+ reord_rxframe_free(&rx_priv->freeq_lock, rxframes_freequeue,
+ &prframe->rxframe_list);
+ return 0;
+ }
+
+ __skb_queue_head_init(&list);
+ if (prframe->is_amsdu) {
+ aicwf_rxdata_process_amsdu
+ (aicwf_vif->aicwf_hw, skb, aicwf_vif->vif_index,
+ &list); // rxhdr not used below since skb free!
+ } else {
+ __skb_queue_head(&list, skb);
+ }
+
+ while (!skb_queue_empty(&list)) {
+ rx_skb = __skb_dequeue(&list);
+
+ aicwf_vif->net_stats.rx_packets++;
+ aicwf_vif->net_stats.rx_bytes += rx_skb->len;
+
+ rx_skb->dev = aicwf_vif->ndev;
+ rx_skb->protocol = eth_type_trans(rx_skb, aicwf_vif->ndev);
+
+#ifdef CONFIG_AIC8800_ARP_OFFLOAD
+ if (AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_STATION ||
+ AICWF_VIF_TYPE(aicwf_vif) == NL80211_IFTYPE_P2P_CLIENT) {
+ arpoffload_proc(rx_skb, aicwf_vif);
+ }
+#endif
+ memset(rx_skb->cb, 0, sizeof(rx_skb->cb));
+
+#ifdef CONFIG_AIC8800_RX_NETIF_RECV_SKB // AIDEN test
+ local_bh_disable();
+ netif_receive_skb(rx_skb);
+ local_bh_enable();
+#else
+ if (in_interrupt()) {
+ netif_rx(rx_skb);
+ } else {
+ /*
+ * If the receive is not processed inside an ISR, the softirqd must
+ * be woken explicitly to service the NET_RX_SOFTIRQ.
+ * * In 2.6 kernels, this is handledby netif_rx_ni(), but in earlier
+ * kernels, we need to do it manually.
+ */
+ netif_rx_ni(rx_skb);
+ }
+#endif /* CONFIG_AIC8800_RX_NETIF_RECV_SKB */
+ }
+
+ prframe->pkt = NULL;
+ reord_rxframe_free(&rx_priv->freeq_lock, rxframes_freequeue,
+ &prframe->rxframe_list);
+
+ return 0;
+}
+
+bool reord_rxframes_process(struct aicwf_rx_priv *rx_priv,
+ struct reord_ctrl *preorder_ctrl, int bforced)
+{
+ struct list_head *phead, *plist;
+ struct recv_msdu *prframe;
+ bool b_pkt_in_buf = false;
+
+ if (bforced) {
+ phead = &preorder_ctrl->reord_list;
+ if (list_empty(phead))
+ return false;
+
+ plist = phead->next;
+ prframe = list_entry(plist, struct recv_msdu, reord_pending_list);
+ preorder_ctrl->ind_sn = prframe->seq_num;
+ }
+
+ phead = &preorder_ctrl->reord_list;
+ if (list_empty(phead))
+ return b_pkt_in_buf;
+
+ list_for_each_entry(prframe, phead, reord_pending_list) {
+ if (!SN_LESS(preorder_ctrl->ind_sn, prframe->seq_num)) {
+ if (SN_EQUAL(preorder_ctrl->ind_sn, prframe->seq_num))
+ preorder_ctrl->ind_sn = (preorder_ctrl->ind_sn + 1) & 0xFFF;
+ } else {
+ b_pkt_in_buf = true;
+ break;
+ }
+ }
+
+ return b_pkt_in_buf;
+}
+
+void reord_rxframes_ind(struct aicwf_rx_priv *rx_priv,
+ struct reord_ctrl *preorder_ctrl)
+{
+ struct list_head *phead, *plist;
+ struct recv_msdu *prframe;
+
+ phead = &preorder_ctrl->reord_list;
+ while (1) {
+ if (list_empty(phead))
+ break;
+
+ plist = phead->next;
+ prframe = list_entry(plist, struct recv_msdu, reord_pending_list);
+
+ if (!SN_LESS(preorder_ctrl->ind_sn, prframe->seq_num)) {
+ list_del_init(&prframe->reord_pending_list);
+ reord_single_frame_ind(rx_priv, prframe);
+ } else {
+ break;
+ }
+ }
+}
+
+void reord_timeout_handler(struct timer_list *t)
+{
+ //struct reord_ctrl *preorder_ctrl = from_timer(preorder_ctrl, t, reord_timer);
+ struct reord_ctrl *preorder_ctrl = timer_container_of(preorder_ctrl, t, reord_timer);
+
+ if (!work_pending(&preorder_ctrl->reord_timer_work))
+ schedule_work(&preorder_ctrl->reord_timer_work);
+}
+
+void reord_timeout_worker(struct work_struct *work)
+{
+ struct reord_ctrl *preorder_ctrl =
+ container_of(work, struct reord_ctrl, reord_timer_work);
+ struct aicwf_rx_priv *rx_priv = preorder_ctrl->rx_priv;
+
+ spin_lock_bh(&preorder_ctrl->reord_list_lock);
+ if (reord_rxframes_process(rx_priv, preorder_ctrl, true) == true) {
+ mod_timer(&preorder_ctrl->reord_timer,
+ jiffies + msecs_to_jiffies(REORDER_UPDATE_TIME));
+ }
+
+ reord_rxframes_ind(rx_priv, preorder_ctrl);
+ spin_unlock_bh(&preorder_ctrl->reord_list_lock);
+}
+
+int reord_process_unit(struct aicwf_rx_priv *rx_priv, struct sk_buff *skb,
+ u16 seq_num, u8 tid, u8 forward, u8 is_amsdu)
+{
+ int ret = 0;
+ u8 *mac;
+ struct recv_msdu *pframe;
+ struct reord_ctrl *preorder_ctrl;
+ struct reord_ctrl_info *reord_info;
+ struct aicwf_vif *aicwf_vif = (struct aicwf_vif *)rx_priv->aicwf_vif;
+ struct ethhdr *eh = (struct ethhdr *)(skb->data);
+ u8 is_mcast;
+
+ if (!aicwf_vif || skb->len <= ETH_HLEN ||
+ tid >= ARRAY_SIZE(reord_info->preorder_ctrl)) {
+ dev_kfree_skb(skb);
+ return -1;
+ }
+
+ is_mcast = is_multicast_ether_addr(eh->h_dest);
+
+ pframe =
+ reord_rxframe_alloc(&rx_priv->freeq_lock, &rx_priv->rxframes_freequeue);
+ if (!pframe) {
+ dev_kfree_skb(skb);
+ return -1;
+ }
+
+ INIT_LIST_HEAD(&pframe->reord_pending_list);
+ pframe->seq_num = seq_num;
+ pframe->tid = tid;
+ pframe->rx_data = skb->data;
+ pframe->pkt = skb;
+ pframe->forward = forward;
+ preorder_ctrl = pframe->preorder_ctrl;
+ pframe->is_amsdu = is_amsdu;
+
+ if ((ntohs(eh->h_proto) == ETH_P_PAE) || is_mcast)
+ return reord_single_frame_ind(rx_priv, pframe);
+
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_STATION ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
+ mac = eh->h_dest;
+ } else if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_AP ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
+ mac = eh->h_source;
+ } else {
+ dev_kfree_skb(skb);
+ return -1;
+ }
+
+ spin_lock_bh(&rx_priv->stas_reord_lock);
+ list_for_each_entry(reord_info, &rx_priv->stas_reord_list, list) {
+ if (!memcmp(mac, reord_info->mac_addr, ETH_ALEN)) {
+ preorder_ctrl = &reord_info->preorder_ctrl[pframe->tid];
+ break;
+ }
+ }
+
+ if (&reord_info->list == &rx_priv->stas_reord_list) {
+ reord_info = reord_init_sta(rx_priv, mac);
+ if (!reord_info) {
+ spin_unlock_bh(&rx_priv->stas_reord_lock);
+ dev_kfree_skb(skb);
+ return -1;
+ }
+ list_add_tail(&reord_info->list, &rx_priv->stas_reord_list);
+ preorder_ctrl = &reord_info->preorder_ctrl[pframe->tid];
+ } else {
+ if (!preorder_ctrl->enable) {
+ preorder_ctrl->enable = true;
+ preorder_ctrl->ind_sn = 0xffff;
+ preorder_ctrl->wsize_b = AICWF_REORDER_WINSIZE;
+ preorder_ctrl->rx_priv = rx_priv;
+ }
+ }
+ spin_unlock_bh(&rx_priv->stas_reord_lock);
+
+ if (!preorder_ctrl->enable) {
+ spin_lock_bh(&preorder_ctrl->reord_list_lock);
+ preorder_ctrl->ind_sn = pframe->seq_num;
+ reord_single_frame_ind(rx_priv, pframe);
+ preorder_ctrl->ind_sn = (preorder_ctrl->ind_sn + 1) % 4096;
+ spin_unlock_bh(&rx_priv->stas_reord_lock);
+ return 0;
+ }
+
+ spin_lock_bh(&preorder_ctrl->reord_list_lock);
+ if (reord_need_check(preorder_ctrl, pframe->seq_num)) {
+ if (skb->len > 42 && pframe->rx_data[42] == 0x80) { // RTP packet
+ if (pframe->seq_num == preorder_ctrl->ind_sn) {
+ pr_debug("pframe->seq_num1:%d\n",
+ pframe->seq_num);
+ reord_single_frame_ind(rx_priv, pframe); // not need to reorder
+ } else {
+ pr_debug("free pframe->seq_num:%d\n",
+ pframe->seq_num);
+ if (pframe->pkt) {
+ dev_kfree_skb(pframe->pkt);
+ pframe->pkt = NULL;
+ }
+ reord_rxframe_free(&rx_priv->freeq_lock,
+ &rx_priv->rxframes_freequeue,
+ &pframe->rxframe_list);
+ }
+ } else {
+ reord_single_frame_ind(rx_priv, pframe); // not need to reorder
+ }
+ spin_unlock_bh(&preorder_ctrl->reord_list_lock);
+ return 0;
+ }
+
+ if (reord_rxframe_enqueue(preorder_ctrl, pframe)) {
+ spin_unlock_bh(&preorder_ctrl->reord_list_lock);
+ goto fail;
+ }
+
+ if (reord_rxframes_process(rx_priv, preorder_ctrl, false) == true) {
+ if (!timer_pending(&preorder_ctrl->reord_timer)) {
+ ret = mod_timer(&preorder_ctrl->reord_timer,
+ jiffies +
+ msecs_to_jiffies(REORDER_UPDATE_TIME));
+ }
+ } else {
+ if (timer_pending(&preorder_ctrl->reord_timer))
+ //ret = del_timer(&preorder_ctrl->reord_timer);
+ ret = timer_delete(&preorder_ctrl->reord_timer);
+ }
+
+ reord_rxframes_ind(rx_priv, preorder_ctrl);
+ spin_unlock_bh(&preorder_ctrl->reord_list_lock);
+
+ return 0;
+
+fail:
+ if (pframe->pkt) {
+ dev_kfree_skb(pframe->pkt);
+ pframe->pkt = NULL;
+ }
+ reord_rxframe_free(&rx_priv->freeq_lock, &rx_priv->rxframes_freequeue,
+ &pframe->rxframe_list);
+ return ret;
+}
+
+int reord_need_check(struct reord_ctrl *preorder_ctrl, u16 seq_num)
+{
+ u8 wsize = preorder_ctrl->wsize_b;
+ u16 wend = (preorder_ctrl->ind_sn + wsize - 1) & 0xFFF;
+
+ if (preorder_ctrl->ind_sn == 0xFFFF)
+ preorder_ctrl->ind_sn = seq_num;
+
+ if (SN_LESS(seq_num, preorder_ctrl->ind_sn))
+ return -1;
+
+ if (SN_EQUAL(seq_num, preorder_ctrl->ind_sn)) {
+ preorder_ctrl->ind_sn = (preorder_ctrl->ind_sn + 1) & 0xFFF;
+ } else if (SN_LESS(wend, seq_num)) {
+ if (seq_num >= (wsize - 1))
+ preorder_ctrl->ind_sn = seq_num - (wsize - 1);
+ else
+ preorder_ctrl->ind_sn = 0xFFF - (wsize - (seq_num + 1)) + 1;
+ }
+
+ return 0;
+}
+
+int reord_rxframe_enqueue(struct reord_ctrl *preorder_ctrl,
+ struct recv_msdu *prframe)
+{
+ struct list_head *preord_list = &preorder_ctrl->reord_list;
+ struct list_head *phead, *plist;
+ struct recv_msdu *pnextrframe;
+
+ phead = preord_list;
+ plist = phead->next;
+
+ while (phead != plist) {
+ pnextrframe = list_entry(plist, struct recv_msdu, reord_pending_list);
+ if (SN_LESS(pnextrframe->seq_num, prframe->seq_num)) {
+ plist = plist->next;
+ continue;
+ } else if (SN_EQUAL(pnextrframe->seq_num, prframe->seq_num)) {
+ return -1;
+ }
+ break;
+ }
+ list_add_tail(&prframe->reord_pending_list, plist);
+
+ return 0;
+}
+#endif /* CONFIG_AIC8800_RX_REORDER */
+
+void remove_sec_hdr_mgmt_frame(struct hw_rxhdr *hw_rxhdr, struct sk_buff *skb)
+{
+ u8 hdr_len = 24;
+ u8 mgmt_header[24] = {0};
+
+ if (!hw_rxhdr->hwvect.ga_frame) {
+ if (((skb->data[0] & 0x0C) == 0) &&
+ (skb->data[1] & 0x40) == 0x40) { // protect management frame
+ pr_debug("frame type %x\n", skb->data[0]);
+ if (hw_rxhdr->hwvect.decr_status == AICWF_RX_HD_DECR_CCMP128) {
+ memcpy(mgmt_header, skb->data, hdr_len);
+ skb_pull(skb, 8);
+ memcpy(skb->data, mgmt_header, hdr_len);
+ hw_rxhdr->hwvect.len -= 8;
+ } else {
+ pr_debug("unsupport decr_status:%d\n",
+ hw_rxhdr->hwvect.decr_status);
+ }
+ }
+ }
+}
+
+void aicwf_defrag_init(struct aicwf_hw *aicwf_hw)
+{
+ INIT_LIST_HEAD(&aicwf_hw->defrag_list);
+ INIT_LIST_HEAD(&aicwf_hw->defrag_expired_list);
+ spin_lock_init(&aicwf_hw->defrag_lock);
+ aicwf_hw->defrag_stopping = false;
+}
+
+void defrag_timeout_cb(struct timer_list *t)
+{
+ struct defrag_ctrl_info *defrag_ctrl =
+ timer_container_of(defrag_ctrl, t, defrag_timer);
+ struct aicwf_hw *aicwf_hw = defrag_ctrl->aicwf_hw;
+
+ spin_lock_bh(&aicwf_hw->defrag_lock);
+ if (!list_empty(&defrag_ctrl->list)) {
+ dev_kfree_skb(defrag_ctrl->skb);
+ defrag_ctrl->skb = NULL;
+ /* Keep the timer reachable until another context can join it. */
+ list_move_tail(&defrag_ctrl->list, &aicwf_hw->defrag_expired_list);
+ }
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+}
+
+static void aicwf_defrag_drain(struct aicwf_hw *aicwf_hw, struct list_head *head)
+{
+ struct defrag_ctrl_info *defrag_ctrl;
+
+ spin_lock_bh(&aicwf_hw->defrag_lock);
+ while (!list_empty(head)) {
+ defrag_ctrl = list_first_entry(head, struct defrag_ctrl_info, list);
+ /* An empty node transfers ownership away from the timer callback. */
+ list_del_init(&defrag_ctrl->list);
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+
+ timer_shutdown_sync(&defrag_ctrl->defrag_timer);
+ dev_kfree_skb(defrag_ctrl->skb);
+ kfree(defrag_ctrl);
+
+ spin_lock_bh(&aicwf_hw->defrag_lock);
+ }
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+}
+
+void aicwf_defrag_deinit(struct aicwf_hw *aicwf_hw)
+{
+ /* The caller must join RX before releasing aicwf_hw. */
+ spin_lock_bh(&aicwf_hw->defrag_lock);
+ aicwf_hw->defrag_stopping = true;
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+
+ aicwf_defrag_drain(aicwf_hw, &aicwf_hw->defrag_list);
+ aicwf_defrag_drain(aicwf_hw, &aicwf_hw->defrag_expired_list);
+}
+
+void aicwf_rxdata_process_amsdu(struct aicwf_hw *aicwf_hw, struct sk_buff *skb,
+ u8 vif_idx, struct sk_buff_head *list)
+{
+ unsigned int len_alligned = 0;
+ unsigned int sublen = 0;
+ struct sk_buff *sub_skb = NULL;
+ struct aicwf_vif *aicwf_vif;
+
+ /* |amsdu sub1 | amsdu sub2 | ... */
+ len_alligned = 0;
+ sublen = 0;
+ sub_skb = NULL;
+ while (skb->len >= ETH_HLEN) {
+ sublen = (skb->data[12] << 8) | (skb->data[13]);
+ /* The existing conversion removes six LLC bytes. */
+ if (sublen < 8 || sublen > skb->len - ETH_HLEN)
+ break;
+ if (skb->len > (sublen + 14)) {
+ len_alligned = roundup(sublen + 14, 4);
+ } else if (skb->len == (sublen + 14)) {
+ len_alligned = sublen + 14;
+ } else {
+ dev_dbg(aicwf_hw->dev, "accroding to amsdu: this will not happen\n");
+ break;
+ }
+ /* debug trace */
+ // sublen,skb->data[0], skb->data[1], skb->data[12],
+ // skb->data[13]);
+ sub_skb = __dev_alloc_skb(sublen - 6 + 12, GFP_ATOMIC);
+ if (!sub_skb)
+ break;
+ skb_put(sub_skb, sublen - 6 + 12);
+ memcpy(sub_skb->data, skb->data, MAC_ADDR_LEN);
+ memcpy(&sub_skb->data[6], &skb->data[6], MAC_ADDR_LEN);
+ memcpy(&sub_skb->data[12], &skb->data[14 + 6], sublen - 6);
+
+ aicwf_vif = aicwf_rx_get_vif(aicwf_hw, vif_idx);
+ if (!aicwf_vif) {
+ dev_dbg(aicwf_hw->dev, "frame received but no active vif %d", vif_idx);
+ dev_kfree_skb(sub_skb);
+ break;
+ }
+
+ __skb_queue_tail(list, sub_skb);
+
+ /* debug trace */
+ // if (!aicwf_rx_data_skb(aicwf_hw, aicwf_vif, sub_skb, hw_rxhdr))
+ // dev_kfree_skb(sub_skb);
+ /* The final subframe need not include alignment padding. */
+ skb_pull(skb, min_t(unsigned int, len_alligned, skb->len));
+ }
+ dev_kfree_skb(skb);
+}
+
+static void find_defrag_info(struct aicwf_hw *aicwf_hw, u16 seq_num,
+ u8 tid, u8 sta_idx,
+ struct defrag_ctrl_info **defrag_info,
+ struct defrag_ctrl_info **defrag_info_tmp)
+{
+ struct defrag_ctrl_info *iter;
+
+ if (!list_empty(&aicwf_hw->defrag_list)) {
+ list_for_each_entry(iter, &aicwf_hw->defrag_list, list) {
+ if (iter->sn == seq_num &&
+ iter->tid == tid &&
+ iter->sta_idx == sta_idx) {
+ *defrag_info_tmp = iter;
+ *defrag_info = *defrag_info_tmp;
+ break;
+ }
+ }
+ }
+}
+
+static int process_fragment_reassembly(struct defrag_ctrl_info *defrag_info,
+ u16 frag_num, struct sk_buff *skb,
+ u8 pull_len, struct aicwf_hw *aicwf_hw,
+ u8 *is_frag)
+{
+ if (!defrag_info)
+ return 1;
+
+ *is_frag = 1;
+ if (defrag_info->next_fn != frag_num) {
+ dev_dbg(aicwf_hw->dev, "discard:%d:%d\n",
+ defrag_info->next_fn, frag_num);
+ dev_kfree_skb(skb);
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ return 0;
+ }
+
+ if (pull_len < 8 || skb->len < pull_len - 8 ||
+ skb->len - (pull_len - 8) > skb_tailroom(defrag_info->skb)) {
+ dev_kfree_skb(skb);
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ return 0;
+ }
+
+ skb_put_data(defrag_info->skb, skb->data + pull_len - 8,
+ skb->len - (pull_len - 8));
+
+ defrag_info->frm_len += skb->len - (pull_len - 8);
+ defrag_info->next_fn++;
+
+ dev_kfree_skb(skb);
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+
+ return 0;
+}
+
+static inline void find_matching_defrag_info(struct aicwf_hw *aicwf_hw,
+ u16 seq_num, u8 tid, u8 sta_idx,
+ struct defrag_ctrl_info **defrag_info,
+ struct defrag_ctrl_info **defrag_info_tmp)
+{
+ struct defrag_ctrl_info *iter;
+
+ list_for_each_entry(iter, &aicwf_hw->defrag_list, list) {
+ if (iter->sn == seq_num &&
+ iter->tid == tid &&
+ iter->sta_idx == sta_idx) {
+ *defrag_info_tmp = iter;
+ *defrag_info = *defrag_info_tmp;
+ break;
+ }
+ }
+}
+
+static int process_defrag_reassembly(struct aicwf_hw *aicwf_hw,
+ struct defrag_ctrl_info *defrag_info,
+ u16 frag_num,
+ struct sk_buff *skb,
+ u8 pull_len,
+ struct hw_rxhdr *hw_rxhdr,
+ u8 *is_frag,
+ struct aicwf_vif **aicwf_vif,
+ struct sk_buff **skb_tmp)
+{
+ struct hw_rxhdr hw_rxhdr_copy;
+
+ if (!defrag_info) {
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ return 1;
+ }
+
+ if (defrag_info->next_fn != frag_num) {
+ dev_dbg(aicwf_hw->dev, "discard:%d:%d\n",
+ defrag_info->next_fn, frag_num);
+ dev_kfree_skb(skb);
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ return 0;
+ }
+
+ if (pull_len < 8 || skb->len < pull_len - 8 ||
+ skb->len - (pull_len - 8) > skb_tailroom(defrag_info->skb)) {
+ dev_kfree_skb(skb);
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ return 0;
+ }
+
+ skb_put_data(defrag_info->skb, skb->data + pull_len - 8,
+ skb->len - (pull_len - 8));
+ defrag_info->frm_len += skb->len - (pull_len - 8);
+ *is_frag = 1;
+
+ *aicwf_vif = aicwf_rx_get_vif(aicwf_hw, hw_rxhdr->flags_vif_idx);
+ if (!*aicwf_vif) {
+ dev_dbg(aicwf_hw->dev, "frame received but no active vif %d",
+ hw_rxhdr->flags_vif_idx);
+ dev_kfree_skb(skb);
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ return 0;
+ }
+
+ hw_rxhdr_copy = *hw_rxhdr;
+ dev_kfree_skb(skb);
+ *skb_tmp = defrag_info->skb;
+ defrag_info->skb = NULL;
+ list_del_init(&defrag_info->list);
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ timer_shutdown_sync(&defrag_info->defrag_timer);
+ kfree(defrag_info);
+
+ if (!aicwf_rx_data_skb(aicwf_hw, *aicwf_vif, *skb_tmp, &hw_rxhdr_copy))
+ dev_kfree_skb(*skb_tmp);
+
+ return 0;
+}
+
+static inline void check_packet_forward_flags(struct aicwf_hw *aicwf_hw,
+ struct hw_rxhdr *hw_rxhdr,
+ struct aicwf_vif *aicwf_vif,
+ bool *resend,
+ bool *forward)
+{
+ if (hw_rxhdr->flags_dst_idx != AICWF_INVALID_STA) {
+ struct aicwf_sta *sta = &aicwf_hw->sta_table[hw_rxhdr->flags_dst_idx];
+
+ if (sta->valid && sta->vlan_idx == aicwf_vif->vif_index) {
+ *resend = true;
+ *forward = false;
+ }
+ }
+}
+
+u8 aicwf_rxdataind(struct aicwf_hw *aicwf_hw, void *hostid, void *rx_priv)
+{
+ struct hw_rxhdr *hw_rxhdr;
+ struct rxdesc_tag *rxdesc = NULL;
+ struct aicwf_vif *aicwf_vif;
+ struct sk_buff *skb = hostid;
+ int msdu_offset = sizeof(struct hw_rxhdr) + 2;
+ u16 status = 0;
+ struct aicwf_rx_priv *rx_priv_tmp;
+ u8 hdr_len = 24;
+ u8 ra[MAC_ADDR_LEN] = {0};
+ u8 ta[MAC_ADDR_LEN] = {0};
+ u8 ether_type[2] = {0};
+ u8 pull_len = 0;
+ u16 seq_num = 0;
+ u8 frag_num = 0;
+ u8 tid = 0;
+ u8 is_qos = 0;
+ u8 is_frag = 0;
+ struct defrag_ctrl_info *defrag_info = NULL;
+ struct defrag_ctrl_info *defrag_info_tmp = NULL;
+ struct sk_buff *skb_tmp = NULL;
+ u8 sta_idx = 0;
+ u16 frame_ctrl;
+ u8 is_amsdu = 0;
+ bool resend = false, forward = true;
+ const struct ethhdr *eth;
+
+ if (skb->len < msdu_offset + 2)
+ goto drop;
+ hw_rxhdr = (struct hw_rxhdr *)skb->data;
+ if (hw_rxhdr->hwvect.len > skb->len - (msdu_offset + 2))
+ goto drop;
+
+ if (hw_rxhdr->is_monitor_vif) {
+ status = RX_STAT_MONITOR;
+ dev_dbg(aicwf_hw->dev, "monitor rx\n");
+ }
+
+ if (hw_rxhdr->flags_upload)
+ status |= RX_STAT_FORWARD;
+
+ /* Check if we need to delete the buffer */
+ if (status & RX_STAT_DELETE) {
+ /* Remove the SK buffer from the rxbuf_elems table */
+ /* Free the buffer */
+ dev_kfree_skb(skb);
+ goto end;
+ }
+
+ /* Check if we need to forward the buffer coming from a monitor interface */
+ if (status & RX_STAT_MONITOR) {
+ struct sk_buff *skb_monitor;
+ struct hw_rxhdr hw_rxhdr_copy;
+ u8 rtap_len;
+ u16 frm_len;
+
+ // Check if monitor interface exists and is open
+ aicwf_vif = aicwf_rx_get_vif(aicwf_hw, aicwf_hw->monitor_vif);
+ if (!aicwf_vif) {
+ dev_err(aicwf_hw->dev,
+ "received monitor frame but there is no monitor interface open\n");
+ goto check_len_update;
+ }
+
+ aicwf_rx_vector_convert(aicwf_hw, &hw_rxhdr->hwvect.rx_vect1,
+ &hw_rxhdr->hwvect.rx_vect2);
+ rtap_len = aicwf_rx_rtap_hdrlen(&hw_rxhdr->hwvect.rx_vect1, false);
+
+ // Move skb->data pointer to MAC Header or Ethernet header
+ skb->data += (msdu_offset + 2); // sdio/usb word align
+
+ // Save frame length
+ frm_len = hw_rxhdr->hwvect.len;
+
+ // Reserve space for frame
+ skb->len = frm_len;
+
+ if (status == RX_STAT_MONITOR) {
+ /*
+ * Remove the SK buffer from the rxbuf_elems table. It will also
+ * unmap the buffer and then sync the buffer for the cpu
+ */
+
+ // Check if there is enough space to add the radiotap header
+ if (skb_headroom(skb) > rtap_len) {
+ skb_monitor = skb;
+
+ // Duplicate the HW Rx Header to override with the radiotap
+ // header
+ memcpy(&hw_rxhdr_copy, hw_rxhdr, sizeof(hw_rxhdr_copy));
+
+ hw_rxhdr = &hw_rxhdr_copy;
+
+ skb_reset_tail_pointer(skb);
+ skb->len = 0;
+ skb_reset_tail_pointer(skb_monitor);
+ skb_monitor->len = 0;
+ skb_put(skb_monitor, frm_len);
+ if (aicwf_rx_monitor(aicwf_hw, aicwf_vif,
+ skb_monitor, hw_rxhdr, rtap_len))
+ dev_kfree_skb(skb_monitor);
+ } else {
+ // Duplicate the skb and extend the headroom
+ skb_monitor = skb_copy_expand(skb, rtap_len, 0, GFP_ATOMIC);
+
+ // Reset original skb->data pointer
+ skb->data = (void *)hw_rxhdr;
+
+ skb_reset_tail_pointer(skb);
+ skb->len = 0;
+ skb_reset_tail_pointer(skb_monitor);
+ skb_monitor->len = 0;
+ skb_put(skb_monitor, frm_len);
+ if (aicwf_rx_monitor(aicwf_hw, aicwf_vif,
+ skb_monitor, hw_rxhdr, rtap_len))
+ dev_kfree_skb(skb_monitor);
+ }
+ } else {
+ skb->data = (void *)hw_rxhdr;
+
+ wiphy_err(aicwf_hw->wiphy,
+ "RX status %d is invalid when MON_DATA is disabled\n",
+ status);
+ goto check_len_update;
+ }
+
+ if (status == RX_STAT_MONITOR) {
+ status |= RX_STAT_ALLOC;
+ if (skb_monitor != skb)
+ dev_kfree_skb(skb);
+ }
+ }
+
+check_len_update:
+ /* Check if we need to update the length */
+ if (status & RX_STAT_LEN_UPDATE) {
+ if (rxdesc)
+ hw_rxhdr->hwvect.len = rxdesc->frame_len;
+
+ if (status & RX_STAT_ETH_LEN_UPDATE) {
+ /* Update Length Field inside the Ethernet Header */
+ struct ethhdr *hdr =
+ (struct ethhdr *)((u8 *)hw_rxhdr + msdu_offset);
+
+ if (rxdesc)
+ hdr->h_proto = htons(rxdesc->frame_len - sizeof(struct ethhdr));
+ }
+
+ goto end;
+ }
+
+ /* Check if it must be discarded after informing upper layer */
+ if (status & RX_STAT_SPURIOUS) {
+ struct ieee80211_hdr *hdr;
+
+ hdr = (struct ieee80211_hdr *)(skb->data + msdu_offset);
+ aicwf_vif = aicwf_rx_get_vif(aicwf_hw, hw_rxhdr->flags_vif_idx);
+ if (aicwf_vif) {
+ cfg80211_rx_spurious_frame(aicwf_vif->ndev, hdr->addr2, 0,
+ GFP_ATOMIC);
+ }
+ goto end;
+ }
+
+ /* Check if we need to forward the buffer */
+ if (status & RX_STAT_FORWARD) {
+ aicwf_rx_vector_convert(aicwf_hw, &hw_rxhdr->hwvect.rx_vect1,
+ &hw_rxhdr->hwvect.rx_vect2);
+ skb_pull(skb, msdu_offset + 2); //+2 since sdio align 58->60
+ if (skb->len < 24)
+ goto drop;
+
+#define MAC_FCTRL_MOREFRAG 0x0400
+ frame_ctrl = (skb->data[1] << 8) | skb->data[0];
+ seq_num = ((skb->data[22] & 0xf0) >> 4) | (skb->data[23] << 4);
+ frag_num = (skb->data[22] & 0x0f);
+ is_amsdu = 0;
+
+ if ((skb->data[0] & 0x0f) == 0x08) {
+ if ((skb->data[0] & 0x80) == 0x80) { // qos data
+ hdr_len = 26;
+ if (skb->len < hdr_len)
+ goto drop;
+ tid = skb->data[24] & 0x0F;
+ is_qos = 1;
+ if (skb->data[24] & 0x80)
+ is_amsdu = 1;
+ }
+
+ if (skb->data[1] & 0x80) // htc
+ hdr_len += 4;
+
+ if ((skb->data[1] & 0x3) == 0x1) { // to ds
+ memcpy(ra, &skb->data[16], MAC_ADDR_LEN);
+ memcpy(ta, &skb->data[10], MAC_ADDR_LEN);
+ } else if ((skb->data[1] & 0x3) == 0x2) { // from ds
+ memcpy(ta, &skb->data[16], MAC_ADDR_LEN);
+ memcpy(ra, &skb->data[4], MAC_ADDR_LEN);
+ }
+
+ pull_len += (hdr_len + 8);
+
+ switch (hw_rxhdr->hwvect.decr_status) {
+ case AICWF_RX_HD_DECR_CCMP128:
+ pull_len += 8; // ccmp_header
+ break;
+ case AICWF_RX_HD_DECR_TKIP:
+ pull_len += 8; // tkip_header
+ break;
+ case AICWF_RX_HD_DECR_WEP:
+ pull_len += 4; // wep_header
+ break;
+ case AICWF_RX_HD_DECR_WAPI:
+ pull_len += 18; // wapi_header
+ break;
+
+ default:
+ break;
+ }
+ if (skb->len < pull_len - 8)
+ goto drop;
+ /* Only the first non-A-MSDU fragment carries an LLC header. */
+ if (!frag_num && !is_amsdu) {
+ if (skb->len < pull_len)
+ goto drop;
+ memcpy(ether_type, skb->data + pull_len - 2, 2);
+ }
+ if (is_amsdu)
+ hw_rxhdr->flags_is_amsdu = 1;
+ else
+ hw_rxhdr->flags_is_amsdu = 0;
+
+ if (is_amsdu)
+ skb_pull(skb, pull_len - 8);
+
+ if (hw_rxhdr->flags_dst_idx != AICWF_INVALID_STA)
+ sta_idx = hw_rxhdr->flags_dst_idx;
+
+ if (!hw_rxhdr->flags_need_reord &&
+ ((frame_ctrl & MAC_FCTRL_MOREFRAG) || frag_num)) {
+ aicwf_defrag_drain(aicwf_hw, &aicwf_hw->defrag_expired_list);
+ dev_dbg(aicwf_hw->dev, "rxfrag:%d,%d,%d,sn=%d,%d\n",
+ (frame_ctrl & MAC_FCTRL_MOREFRAG), frag_num, skb->len,
+ seq_num, pull_len);
+ if (frame_ctrl & MAC_FCTRL_MOREFRAG) {
+ spin_lock_bh(&aicwf_hw->defrag_lock);
+ if (aicwf_hw->defrag_stopping) {
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ goto drop;
+ }
+ if (!list_empty(&aicwf_hw->defrag_list)) {
+ find_defrag_info(aicwf_hw, seq_num, tid, sta_idx,
+ &defrag_info, &defrag_info_tmp);
+ }
+ /* debug trace */
+ // frag_num, skb->len);
+ if (process_fragment_reassembly(defrag_info, frag_num,
+ skb, pull_len,
+ aicwf_hw, &is_frag) == 0)
+ return 0;
+ if (frag_num) {
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ goto drop;
+ }
+ defrag_info =
+ kzalloc_obj(struct defrag_ctrl_info, GFP_ATOMIC);
+ if (!defrag_info) {
+ dev_dbg(aicwf_hw->dev, "no defrag_ctrl_info\n");
+ dev_kfree_skb(skb);
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ return 0;
+ }
+ defrag_info->skb = __dev_alloc_skb(2000, GFP_ATOMIC);
+ if (!defrag_info->skb) {
+ dev_kfree_skb(skb);
+ kfree(defrag_info);
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ return 0;
+ }
+ is_frag = 1;
+ skb_pull(skb, pull_len);
+ skb_push(skb, 14);
+ memcpy(skb->data, ra, MAC_ADDR_LEN);
+ memcpy(&skb->data[6], ta, MAC_ADDR_LEN);
+ memcpy(&skb->data[12], ether_type, 2);
+ defrag_info->sn = seq_num;
+ defrag_info->next_fn = 1;
+ defrag_info->tid = tid;
+ defrag_info->sta_idx = sta_idx;
+
+ if (skb->len > skb_tailroom(defrag_info->skb)) {
+ dev_kfree_skb(defrag_info->skb);
+ kfree(defrag_info);
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ goto drop;
+ }
+ skb_put_data(defrag_info->skb, skb->data, skb->len);
+ defrag_info->frm_len = skb->len;
+ defrag_info->aicwf_hw = aicwf_hw;
+ /* debug trace */
+ // defrag_info->skb, defrag_info->skb->head,
+ // defrag_info->skb->tail, defrag_info->skb->end,
+ // defrag_info->frm_len, skb->len);
+ INIT_LIST_HEAD(&defrag_info->list);
+ timer_setup(&defrag_info->defrag_timer,
+ defrag_timeout_cb, 0);
+ list_add_tail(&defrag_info->list,
+ &aicwf_hw->defrag_list);
+ mod_timer(&defrag_info->defrag_timer,
+ jiffies + msecs_to_jiffies(DEFRAG_MAX_WAIT));
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ dev_kfree_skb(skb);
+ return 0;
+ }
+ spin_lock_bh(&aicwf_hw->defrag_lock);
+ if (aicwf_hw->defrag_stopping) {
+ spin_unlock_bh(&aicwf_hw->defrag_lock);
+ goto drop;
+ }
+ find_matching_defrag_info(aicwf_hw, seq_num, tid, sta_idx,
+ &defrag_info, &defrag_info_tmp);
+ if (process_defrag_reassembly(aicwf_hw, defrag_info, frag_num,
+ skb, pull_len, hw_rxhdr, &is_frag,
+ &aicwf_vif, &skb_tmp) == 0)
+ return 0;
+ }
+
+ /* A continuation without a matching reassembly cannot be decoded. */
+ if (frag_num)
+ goto drop;
+
+ if (!is_frag && !is_amsdu) {
+ skb_pull(skb, pull_len);
+ skb_push(skb, 14);
+ memcpy(skb->data, ra, MAC_ADDR_LEN);
+ memcpy(&skb->data[6], ta, MAC_ADDR_LEN);
+ memcpy(&skb->data[12], ether_type, 2);
+ }
+ }
+
+ if (hw_rxhdr->flags_is_80211_mpdu) {
+ if (!hw_rxhdr->hwvect.ga_frame &&
+ ieee80211_is_mgmt(cpu_to_le16(frame_ctrl)) &&
+ ieee80211_has_protected(cpu_to_le16(frame_ctrl)) &&
+ hw_rxhdr->hwvect.decr_status == AICWF_RX_HD_DECR_CCMP128 &&
+ skb->len < 24 + 8)
+ goto drop;
+ remove_sec_hdr_mgmt_frame(hw_rxhdr, skb);
+ aicwf_rx_mgmt_any(aicwf_hw, skb, hw_rxhdr);
+ } else {
+ aicwf_vif = aicwf_rx_get_vif(aicwf_hw, hw_rxhdr->flags_vif_idx);
+
+ if (!aicwf_vif) {
+ dev_err(aicwf_hw->dev, "frame received but no active vif %d\n",
+ hw_rxhdr->flags_vif_idx);
+ dev_kfree_skb(skb);
+ goto end;
+ }
+
+ if ((hw_rxhdr->flags_sta_idx != AICWF_INVALID_STA &&
+ hw_rxhdr->flags_sta_idx >= ARRAY_SIZE(aicwf_hw->sta_table)) ||
+ (hw_rxhdr->flags_dst_idx != AICWF_INVALID_STA &&
+ hw_rxhdr->flags_dst_idx >= ARRAY_SIZE(aicwf_hw->sta_table)))
+ goto drop;
+
+ if (hw_rxhdr->flags_sta_idx != AICWF_INVALID_STA) {
+ struct aicwf_sta *sta;
+
+ sta = &aicwf_hw->sta_table[hw_rxhdr->flags_sta_idx];
+ aicwf_rx_statistic(aicwf_hw, hw_rxhdr, sta);
+
+ if (sta->vlan_idx != aicwf_vif->vif_index) {
+ if (sta->vlan_idx >= ARRAY_SIZE(aicwf_hw->vif_table))
+ goto drop;
+ aicwf_vif = aicwf_hw->vif_table[sta->vlan_idx];
+ if (!aicwf_vif) {
+ dev_kfree_skb(skb);
+ goto end;
+ }
+ }
+
+ if (hw_rxhdr->flags_is_4addr && !aicwf_vif->use_4addr) {
+ cfg80211_rx_unexpected_4addr_frame
+ (aicwf_vif->ndev, sta->mac_addr, 0,
+ GFP_ATOMIC);
+ }
+ }
+
+ skb->priority = 256 + tid; // hw_rxhdr->flags_user_prio;
+
+#ifdef CONFIG_AIC8800_RX_REORDER
+ rx_priv_tmp = rx_priv;
+ rx_priv_tmp->aicwf_vif = (void *)aicwf_vif;
+
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_STATION ||
+ aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
+ if (is_qos && hw_rxhdr->flags_need_reord)
+ reord_process_unit((struct aicwf_rx_priv *)rx_priv, skb,
+ seq_num, tid, 1,
+ hw_rxhdr->flags_is_amsdu);
+ else if (is_qos && !hw_rxhdr->flags_need_reord) {
+ reord_flush_tid((struct aicwf_rx_priv *)rx_priv, skb, tid);
+ if (!aicwf_rx_data_skb(aicwf_hw, aicwf_vif, skb, hw_rxhdr) &&
+ !hw_rxhdr->flags_is_amsdu)
+ dev_kfree_skb(skb);
+ } else {
+ if (!aicwf_rx_data_skb(aicwf_hw, aicwf_vif, skb, hw_rxhdr) &&
+ !hw_rxhdr->flags_is_amsdu)
+ dev_kfree_skb(skb);
+ }
+ } else if ((aicwf_vif->wdev.iftype == NL80211_IFTYPE_AP) ||
+ (aicwf_vif->wdev.iftype == NL80211_IFTYPE_P2P_GO)) {
+ skb_reset_mac_header(skb);
+ eth = eth_hdr(skb);
+ /* debug trace */
+ // skb->data[13], skb->len);
+
+ if (unlikely(is_multicast_ether_addr(eth->h_dest))) {
+ /*
+ * broadcast pkt need to be forwarded to upper layer and
+ * resent on wireless interface
+ */
+ resend = true;
+ } else {
+ /*
+ * unicast pkt for STA inside the BSS, no need to forward to
+ * upper layer simply resend on wireless interface
+ */
+ check_packet_forward_flags(aicwf_hw, hw_rxhdr,
+ aicwf_vif, &resend,
+ &forward);
+ }
+
+ if (resend)
+ aicwf_rx_data_skb_resend(aicwf_hw, aicwf_vif, skb, hw_rxhdr);
+
+ if (forward) {
+ if (is_qos && hw_rxhdr->flags_need_reord) {
+ reord_process_unit
+ ((struct aicwf_rx_priv *)rx_priv, skb,
+ seq_num, tid, 1,
+ hw_rxhdr->flags_is_amsdu);
+ } else if (is_qos && !hw_rxhdr->flags_need_reord) {
+ reord_flush_tid
+ ((struct aicwf_rx_priv *)rx_priv, skb,
+ tid);
+ aicwf_rx_data_skb_forward(aicwf_hw, aicwf_vif, skb,
+ hw_rxhdr);
+ } else {
+ aicwf_rx_data_skb_forward(aicwf_hw, aicwf_vif, skb,
+ hw_rxhdr);
+ }
+ } else if (resend) {
+ if (is_qos && hw_rxhdr->flags_need_reord)
+ reord_process_unit
+ ((struct aicwf_rx_priv *)rx_priv, skb,
+ seq_num, tid, 0,
+ hw_rxhdr->flags_is_amsdu);
+ else if (is_qos && !hw_rxhdr->flags_need_reord) {
+ reord_flush_tid
+ ((struct aicwf_rx_priv *)rx_priv, skb,
+ tid);
+ dev_kfree_skb(skb);
+ }
+ } else {
+ dev_kfree_skb(skb);
+ }
+ }
+#else
+ if (!aicwf_rx_data_skb(aicwf_hw, aicwf_vif, skb, hw_rxhdr))
+ dev_kfree_skb(skb);
+#endif
+ }
+ }
+
+end:
+ return 0;
+
+drop:
+ dev_kfree_skb(skb);
+ return 0;
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx_prealloc.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx_prealloc.c
new file mode 100644
index 000000000000..2cec88fc8c20
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_rx_prealloc.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief rx memory prealloc function
+ *
+ ******************************************************************************
+ */
+
+#include "aicwf_rx_prealloc.h"
+
+#ifdef CONFIG_PREALLOC_RX_SKB
+struct aicwf_rx_buff_list aic_rx_buff_list;
+
+static int aic_rxbuff_num_max = 30;
+
+struct rx_buff *aicwf_prealloc_rxbuff_alloc(spinlock_t *lock)
+{
+ unsigned long flags;
+ struct rx_buff *rxbuff = NULL;
+
+ spin_lock_irqsave(lock, flags);
+ if (list_empty(&aic_rx_buff_list.rxbuff_list)) {
+ spin_unlock_irqrestore(lock, flags);
+ pr_err("%d, rxbuff list is empty\n", __LINE__);
+ return NULL;
+ }
+ rxbuff = list_first_entry(&aic_rx_buff_list.rxbuff_list, struct rx_buff,
+ queue);
+ list_del_init(&rxbuff->queue);
+ atomic_dec(&aic_rx_buff_list.rxbuff_list_len);
+
+ spin_unlock_irqrestore(lock, flags);
+ memset(rxbuff->data, 0, AICWF_RXBUFF_SIZE);
+ rxbuff->len = 0;
+ rxbuff->start = NULL;
+ rxbuff->read = NULL;
+ rxbuff->end = NULL;
+
+ return rxbuff;
+}
+
+void aicwf_prealloc_rxbuff_free(struct rx_buff *rxbuff, spinlock_t *lock)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(lock, flags);
+ list_add_tail(&rxbuff->queue, &aic_rx_buff_list.rxbuff_list);
+ atomic_inc(&aic_rx_buff_list.rxbuff_list_len);
+ spin_unlock_irqrestore(lock, flags);
+}
+
+int aicwf_prealloc_init(void)
+{
+ struct rx_buff *rxbuff;
+ int i = 0;
+
+ INIT_LIST_HEAD(&aic_rx_buff_list.rxbuff_list);
+
+ for (i = 0; i < aic_rxbuff_num_max; i++) {
+ rxbuff = kzalloc_obj(*rxbuff, GFP_KERNEL);
+ if (rxbuff) {
+ rxbuff->data =
+ kzalloc(AICWF_RXBUFF_SIZE, GFP_KERNEL);
+ if (!rxbuff->data) {
+ pr_err("failed to alloc rxbuff data\n");
+ kfree(rxbuff);
+ continue;
+ }
+ rxbuff->len = 0;
+ rxbuff->start = NULL;
+ rxbuff->read = NULL;
+ rxbuff->end = NULL;
+ list_add_tail(&rxbuff->queue, &aic_rx_buff_list.rxbuff_list);
+ atomic_inc(&aic_rx_buff_list.rxbuff_list_len);
+ }
+ }
+
+ pr_debug("pre alloc rxbuff list len: %d\n",
+ (int)atomic_read(&aic_rx_buff_list.rxbuff_list_len));
+ return 0;
+}
+
+void aicwf_prealloc_exit(void)
+{
+ struct rx_buff *rxbuff;
+ struct rx_buff *pos;
+
+ pr_debug("free pre alloc rxbuff list %d\n",
+ (int)atomic_read(&aic_rx_buff_list.rxbuff_list_len));
+ list_for_each_entry_safe(rxbuff, pos, &aic_rx_buff_list.rxbuff_list, queue) {
+ list_del_init(&rxbuff->queue);
+ kfree(rxbuff->data);
+ kfree(rxbuff);
+ }
+}
+#endif
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_tx.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_tx.c
new file mode 100644
index 000000000000..3b0c95827a76
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_tx.c
@@ -0,0 +1,1469 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file aicwf_tx.c
+ *
+ * @brief tx handle
+ *
+ ******************************************************************************
+ */
+
+#include <linux/dma-mapping.h>
+#include <linux/etherdevice.h>
+#include <net/sock.h>
+
+#include "aicwf_txrxif.h"
+#include "aicwf_config.h"
+#include "aicwf_defs.h"
+#include "aicwf_events.h"
+#include "aicwf_mesh.h"
+#include "aicwf_msg_tx.h"
+#include "aicwf_tx.h"
+
+/******************************************************************************
+ * Power Save functions
+ *****************************************************************************/
+/**
+ * aicwf_set_traffic_status - Inform FW if traffic is available for STA in PS
+ *
+ * @aicwf_hw: Driver main data
+ * @sta: Sta in PS mode
+ * @available: whether traffic is buffered for the STA
+ * @ps_id: type of PS data requested (@LEGACY_PS_ID or @UAPSD_ID)
+ */
+void aicwf_set_traffic_status(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta,
+ bool available, u8 ps_id)
+{
+ if (sta->tdls.active) {
+ aicwf_send_tdls_peer_traffic_ind_req(aicwf_hw,
+ aicwf_hw->vif_table[sta->vif_idx]);
+ } else {
+ bool uapsd = (ps_id != LEGACY_PS_ID);
+
+ aicwf_send_me_traffic_ind(aicwf_hw, sta->sta_idx, uapsd, available);
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_ps_traffic_update(sta->sta_idx, available, uapsd);
+#endif
+ }
+}
+
+/**
+ * aicwf_ps_bh_enable - Enable/disable PS mode for one STA
+ *
+ * @aicwf_hw: Driver main data
+ * @sta: Sta which enters/leaves PS mode
+ * @enable: PS mode status
+ *
+ * This function will enable/disable PS mode for one STA.
+ * When enabling PS mode:
+ * - Stop all STA's txq for AICWF_TXQ_STOP_STA_PS reason
+ * - Count how many buffers are already ready for this STA
+ * - For BC/MC sta, update all queued SKB to use hw_queue BCMC
+ * - Update TIM if some packet are ready
+ *
+ * When disabling PS mode:
+ * - Start all STA's txq for AICWF_TXQ_STOP_STA_PS reason
+ * - For BC/MC sta, update all queued SKB to use hw_queue AC_BE
+ * - Update TIM if some packet are ready (otherwise fw will not update TIM
+ * in beacon for this STA)
+ *
+ * All counter/skb updates are protected from TX path by taking tx_lock
+ *
+ * NOTE: _bh_ in function name indicates that this function is called
+ * from a bottom_half tasklet.
+ */
+void aicwf_ps_bh_enable(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta,
+ bool enable)
+{
+ struct aicwf_txq *txq;
+
+ if (enable) {
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_ps_enable(sta);
+#endif
+ spin_lock_bh(&aicwf_hw->tx_lock);
+ sta->ps.active = true;
+ sta->ps.sp_cnt[LEGACY_PS_ID] = 0;
+ sta->ps.sp_cnt[UAPSD_ID] = 0;
+ aicwf_txq_sta_stop(sta, AICWF_TXQ_STOP_STA_PS, aicwf_hw);
+
+ if (is_multicast_sta(aicwf_hw, sta->sta_idx)) {
+ txq = aicwf_txq_sta_get(sta, 0, aicwf_hw);
+ sta->ps.pkt_ready[LEGACY_PS_ID] = skb_queue_len(&txq->sk_list);
+ sta->ps.pkt_ready[UAPSD_ID] = 0;
+ // txq->hwq = &aicwf_hw->hwq[AICWF_HWQ_BCMC];
+ } else {
+ int i;
+
+ sta->ps.pkt_ready[LEGACY_PS_ID] = 0;
+ sta->ps.pkt_ready[UAPSD_ID] = 0;
+
+#ifdef CONFIG_MAC80211_TXQ
+ for (i = 0, txq = aicwf_txq_sta_get(sta, 0);
+ i < NX_NB_TXQ_PER_STA;
+ i++, txq = aicwf_txq_sta_get(sta, i))
+#elif defined(CONFIG_AICWF_FULLMAC)
+ for (i = 0, txq = aicwf_txq_sta_get(sta,
+ 0, aicwf_hw);
+ i < (is_multicast_sta(aicwf_hw, sta->sta_idx) ? 1 : NX_NB_TXQ_PER_STA);
+ i++, txq++)
+#endif
+ {
+ sta->ps.pkt_ready[txq->ps_id] += skb_queue_len(&txq->sk_list);
+ }
+ }
+
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+ } else {
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_ps_disable(sta->sta_idx);
+#endif
+ spin_lock_bh(&aicwf_hw->tx_lock);
+ sta->ps.active = false;
+
+ if (is_multicast_sta(aicwf_hw, sta->sta_idx)) {
+ txq = aicwf_txq_sta_get(sta, 0, aicwf_hw);
+ txq->hwq = &aicwf_hw->hwq[AICWF_HWQ_BE];
+ txq->push_limit = 0;
+ } else {
+ int i;
+
+#ifdef CONFIG_MAC80211_TXQ
+ for (i = 0, txq = aicwf_txq_sta_get(sta, 0);
+ i < NX_NB_TXQ_PER_STA;
+ i++, txq = aicwf_txq_sta_get(sta, i))
+#elif defined(CONFIG_AICWF_FULLMAC)
+ for (i = 0, txq = aicwf_txq_sta_get(sta,
+ 0, aicwf_hw);
+ i < (is_multicast_sta(aicwf_hw, sta->sta_idx) ? 1 : NX_NB_TXQ_PER_STA);
+ i++, txq++)
+#endif
+ {
+ txq->push_limit = 0;
+ }
+ }
+
+ aicwf_txq_sta_start(sta, AICWF_TXQ_STOP_STA_PS, aicwf_hw);
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+ tasklet_schedule(&aicwf_hw->task);
+ }
+}
+
+/**
+ * aicwf_ps_bh_traffic_req - Handle traffic request for STA in PS mode
+ *
+ * @aicwf_hw: Driver main data
+ * @sta: Sta which enters/leaves PS mode
+ * @pkt_req: number of pkt to push
+ * @ps_id: type of PS data requested (@LEGACY_PS_ID or @UAPSD_ID)
+ *
+ * This function will make sure that @pkt_req are pushed to fw
+ * whereas the STA is in PS mode.
+ * If request is 0, send all traffic
+ * If request is greater than available pkt, reduce request
+ * Note: request will also be reduce if txq credits are not available
+ *
+ * All counter updates are protected from TX path by taking tx_lock
+ *
+ * NOTE: _bh_ in function name indicates that this function is called
+ * from the bottom_half tasklet.
+ */
+void aicwf_ps_bh_traffic_req(struct aicwf_hw *aicwf_hw, struct aicwf_sta *sta,
+ u16 pkt_req, u8 ps_id)
+{
+ int pkt_ready_all;
+ struct aicwf_txq *txq;
+ int schedule = 0;
+
+ if (!sta->ps.active) {
+ dev_dbg(aicwf_hw->dev, "sta %pM is not in Power Save mode", sta->mac_addr);
+ return;
+ }
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_ps_traffic_req(sta, pkt_req, ps_id);
+#endif
+ spin_lock_bh(&aicwf_hw->tx_lock);
+
+ /*
+ * Fw may ask to stop a service period with PS_SP_INTERRUPTED. This only
+ * happens for p2p-go interface if NOA starts during a service period
+ */
+ if (pkt_req == PS_SP_INTERRUPTED && ps_id == UAPSD_ID) {
+ int tid;
+
+ sta->ps.sp_cnt[ps_id] = 0;
+#ifdef CONFIG_MAC80211_TXQ
+ for (tid = 0, txq = aicwf_txq_sta_get(sta, 0); tid < NX_NB_TXQ_PER_STA;
+ tid++, txq = aicwf_txq_sta_get(sta, tid))
+#elif defined(CONFIG_AICWF_FULLMAC)
+ for (tid = 0, txq = aicwf_txq_sta_get(sta, 0, aicwf_hw);
+ tid < (is_multicast_sta(aicwf_hw, sta->sta_idx) ? 1 : NX_NB_TXQ_PER_STA);
+ tid++, txq++)
+#endif
+ {
+ txq->push_limit = 0;
+ }
+
+ goto done;
+ }
+
+ pkt_ready_all = (sta->ps.pkt_ready[ps_id] - sta->ps.sp_cnt[ps_id]);
+
+ /*
+ * Don't start SP until previous one is finished or we don't have
+ * packet ready (which must not happen for U-APSD)
+ */
+ if (sta->ps.sp_cnt[ps_id] || pkt_ready_all <= 0)
+ goto done;
+
+ /* Adapt request to what is available. */
+ if (pkt_req == 0 || pkt_req > pkt_ready_all)
+ pkt_req = pkt_ready_all;
+
+ /* Reset the SP counter */
+ sta->ps.sp_cnt[ps_id] = 0;
+ schedule = 1;
+
+ /* "dispatch" the request between txq */
+ if (is_multicast_sta(aicwf_hw, sta->sta_idx)) {
+ txq = aicwf_txq_sta_get(sta, 0, aicwf_hw);
+ // if (txq->credits <= 0)
+ // goto done;
+ if (pkt_req > txq->credits)
+ pkt_req = txq->credits;
+ txq->push_limit = pkt_req;
+ sta->ps.sp_cnt[ps_id] = pkt_req;
+ aicwf_txq_add_to_hw_list(txq);
+ } else {
+ int i, tid;
+#ifdef CONFIG_AICWF_FULLMAC
+ for (i = 0, tid = nx_tid_prio[0],
+ txq = aicwf_txq_sta_get(sta, tid, aicwf_hw);
+ i < NX_NB_TID_PER_STA;
+ i++, tid = nx_tid_prio[i], txq = aicwf_txq_sta_get(sta, tid, aicwf_hw))
+#endif
+ {
+ u16 txq_len = skb_queue_len(&txq->sk_list);
+
+ if (txq->ps_id != ps_id)
+ continue;
+
+ if (txq_len > txq->credits)
+ txq_len = txq->credits;
+
+ if (txq_len == 0)
+ continue;
+
+ if (txq_len < pkt_req) {
+ /*
+ * Not enough pkt queued in this txq, add this
+ * txq to hwq list and process next txq
+ */
+ pkt_req -= txq_len;
+ txq->push_limit = txq_len;
+ sta->ps.sp_cnt[ps_id] += txq_len;
+ aicwf_txq_add_to_hw_list(txq);
+ } else {
+ /*
+ * Enough pkt in this txq to comlete the request
+ * add this txq to hwq list and stop processing txq
+ */
+ txq->push_limit = pkt_req;
+ sta->ps.sp_cnt[ps_id] += pkt_req;
+ aicwf_txq_add_to_hw_list(txq);
+ break;
+ }
+ }
+ }
+
+done:
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+ if (schedule)
+ tasklet_schedule(&aicwf_hw->task);
+}
+
+/******************************************************************************
+ * TX functions
+ *****************************************************************************/
+#define PRIO_STA_NULL 0xAA
+
+static const int aicwf_down_hwq2tid[3] = {
+ [AICWF_HWQ_BK] = 2,
+ [AICWF_HWQ_BE] = 3,
+ [AICWF_HWQ_VI] = 5,
+};
+
+static void aicwf_downgrade_ac(struct aicwf_sta *sta, struct sk_buff *skb)
+{
+ s8 ac = aicwf_tid2hwq[skb->priority];
+
+ if (WARN(ac > AICWF_HWQ_VO, "Unexepcted ac %d for skb before downgrade", ac))
+ ac = AICWF_HWQ_VO;
+
+ while (sta->acm & BIT(ac)) {
+ if (ac == AICWF_HWQ_BK) {
+ skb->priority = 1;
+ return;
+ }
+ ac--;
+ skb->priority = aicwf_down_hwq2tid[ac];
+ }
+}
+
+u16 aicwf_select_txq(struct aicwf_vif *aicwf_vif, struct sk_buff *skb)
+{
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+ struct wireless_dev *wdev = &aicwf_vif->wdev;
+ struct aicwf_sta *sta = NULL;
+ struct aicwf_txq *txq;
+ u16 netdev_queue;
+ bool tdls_mgmgt_frame = false;
+ int nx_bcmc_txq_ndev_idx = NX_BCMC_TXQ_NDEV_IDX;
+
+ if (aicwf_hw->chip_ops->is_old_ic)
+ nx_bcmc_txq_ndev_idx = NX_BCMC_TXQ_NDEV_IDX_FOR_OLD_IC;
+
+ switch (wdev->iftype) {
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ case NL80211_IFTYPE_P2P_CLIENT:
+#endif
+ case NL80211_IFTYPE_STATION: {
+ struct ethhdr *eth;
+
+ eth = (struct ethhdr *)skb->data;
+ if (eth->h_proto == cpu_to_be16(ETH_P_TDLS))
+ tdls_mgmgt_frame = true;
+
+ if (aicwf_vif->tdls_status == TDLS_LINK_ACTIVE &&
+ aicwf_vif->sta.tdls_sta &&
+ memcmp(eth->h_dest, aicwf_vif->sta.tdls_sta->mac_addr, ETH_ALEN) == 0)
+ sta = aicwf_vif->sta.tdls_sta;
+ else
+ sta = aicwf_vif->sta.ap;
+ break;
+ }
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ case NL80211_IFTYPE_AP_VLAN:
+ if (aicwf_vif->ap_vlan.sta_4a) {
+ sta = aicwf_vif->ap_vlan.sta_4a;
+ break;
+ }
+
+ /*
+ * AP_VLAN interface is not used for a 4A STA,
+ * fallback searching sta amongs all AP's clients
+ */
+ aicwf_vif = aicwf_vif->ap_vlan.master;
+ fallthrough;
+ case NL80211_IFTYPE_AP:
+ case NL80211_IFTYPE_P2P_GO: {
+ struct aicwf_sta *cur;
+ struct ethhdr *eth = (struct ethhdr *)skb->data;
+
+ if (is_multicast_ether_addr(eth->h_dest)) {
+ sta = &aicwf_hw->sta_table[aicwf_vif->ap.bcmc_index];
+ } else {
+ spin_lock_bh(&aicwf_vif->aicwf_hw->cb_lock);
+ list_for_each_entry(cur, &aicwf_vif->ap.sta_list, list) {
+ if (!memcmp(cur->mac_addr, eth->h_dest, ETH_ALEN)) {
+ sta = cur;
+ break;
+ }
+ }
+ spin_unlock_bh(&aicwf_vif->aicwf_hw->cb_lock);
+ }
+
+ break;
+ }
+#if IS_ENABLED(CONFIG_AIC8800_NONSTA_SUPPORT)
+ case NL80211_IFTYPE_MESH_POINT: {
+ struct ethhdr *eth = (struct ethhdr *)skb->data;
+
+ if (!aicwf_vif->is_resending) {
+ /*
+ * If ethernet source address is not the address of a mesh wireless
+ * interface, we are proxy for this address and have to inform the
+ * HW
+ */
+ if (memcmp(ð->h_source[0], &aicwf_vif->ndev->perm_addr[0],
+ ETH_ALEN)) {
+ /* Check if LMAC is already informed */
+ if (!aicwf_get_mesh_proxy_info(aicwf_vif, (u8 *)ð->h_source,
+ true)) {
+ aicwf_send_mesh_proxy_add_req(aicwf_hw, aicwf_vif,
+ (u8 *)ð->h_source);
+ }
+ }
+ }
+
+ if (is_multicast_ether_addr(eth->h_dest)) {
+ sta = &aicwf_hw->sta_table[aicwf_vif->ap.bcmc_index];
+ } else {
+ /* Path to be used */
+ struct aicwf_mesh_path *p_mesh_path = NULL;
+ struct aicwf_mesh_path *p_cur_path;
+ /* Check if destination is proxied by a peer Mesh STA */
+ struct aicwf_mesh_proxy *p_mesh_proxy =
+ aicwf_get_mesh_proxy_info(aicwf_vif, (u8 *)ð->h_dest, false);
+ /* Mesh Target address */
+ struct mac_addr *p_tgt_mac_addr;
+
+ if (p_mesh_proxy)
+ p_tgt_mac_addr = &p_mesh_proxy->proxy_addr;
+ else
+ p_tgt_mac_addr = (struct mac_addr *)ð->h_dest;
+
+ /* Look for path with provided target address */
+ list_for_each_entry(p_cur_path, &aicwf_vif->ap.mpath_list, list) {
+ if (!memcmp(&p_cur_path->tgt_mac_addr, p_tgt_mac_addr,
+ ETH_ALEN)) {
+ p_mesh_path = p_cur_path;
+ break;
+ }
+ }
+
+ if (p_mesh_path) {
+ sta = p_mesh_path->p_nhop_sta;
+ } else {
+ aicwf_send_mesh_path_create_req(aicwf_hw, aicwf_vif,
+ (u8 *)p_tgt_mac_addr);
+ }
+ }
+
+ break;
+ }
+#endif
+#endif
+ default:
+ break;
+ }
+
+ if (sta && sta->qos) {
+ if (tdls_mgmgt_frame) {
+ skb_set_queue_mapping(skb,
+ NX_STA_NDEV_IDX(skb->priority, sta->sta_idx));
+ } else {
+ /* use the data classifier to determine what 802.1d tag the
+ * data frame has
+ */
+ skb->priority = cfg80211_classify8021d(skb, NULL) &
+ IEEE80211_QOS_CTL_TAG1D_MASK;
+ }
+ if (sta->acm)
+ aicwf_downgrade_ac(sta, skb);
+
+ txq = aicwf_txq_sta_get(sta, skb->priority, aicwf_hw);
+ netdev_queue = txq->ndev_idx;
+ } else if (sta) {
+ skb->priority = 0xFF;
+ txq = aicwf_txq_sta_get(sta, 0, aicwf_hw);
+ netdev_queue = txq->ndev_idx;
+ } else {
+ /*
+ * This packet will be dropped in xmit function, still need to select
+ * an active queue for xmit to be called. As it most likely to happen
+ * for AP interface, select BCMC queue
+ * (TODO: select another queue if BCMC queue is stopped)
+ */
+ skb->priority = PRIO_STA_NULL;
+ netdev_queue = nx_bcmc_txq_ndev_idx;
+ }
+
+#ifndef CONFIG_AIC8800_ONE_TXQ
+ WARN_ON_ONCE(netdev_queue >= NX_NB_NDEV_TXQ);
+#endif
+
+ return netdev_queue;
+}
+
+/**
+ * aicwf_set_more_data_flag - Update MORE_DATA flag in tx sw desc
+ *
+ * @aicwf_hw: Driver main data
+ * @sw_txhdr: Header for pkt to be pushed
+ *
+ * If STA is in PS mode
+ * - Set EOSP in case the packet is the last of the UAPSD service period
+ * - Set MORE_DATA flag if more pkt are ready for this sta
+ * - Update TIM if this is the last pkt buffered for this sta
+ *
+ * note: tx_lock already taken.
+ */
+static inline void aicwf_set_more_data_flag(struct aicwf_hw *aicwf_hw,
+ struct aicwf_sw_txhdr *sw_txhdr)
+{
+ struct aicwf_sta *sta = sw_txhdr->aicwf_sta;
+ struct aicwf_vif *vif = sw_txhdr->aicwf_vif;
+ struct aicwf_txq *txq = sw_txhdr->txq;
+
+ if (unlikely(sta->ps.active)) {
+ sta->ps.pkt_ready[txq->ps_id]--;
+ sta->ps.sp_cnt[txq->ps_id]--;
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_ps_push(sta);
+#endif
+ if ((txq->ps_id == UAPSD_ID ||
+ vif->wdev.iftype == NL80211_IFTYPE_MESH_POINT ||
+ sta->tdls.active) &&
+ !sta->ps.sp_cnt[txq->ps_id]) {
+ sw_txhdr->desc.host.flags |= TXU_CNTRL_EOSP;
+ }
+
+ if (sta->ps.pkt_ready[txq->ps_id])
+ sw_txhdr->desc.host.flags |= TXU_CNTRL_MORE_DATA;
+ else
+ aicwf_set_traffic_status(aicwf_hw, sta, false, txq->ps_id);
+ }
+}
+
+/**
+ * aicwf_get_tx_priv - Get STA and tid for one skb
+ *
+ * @aicwf_vif: vif ptr
+ * @skb: skb
+ * @tid: pointer updated with the tid to use for this skb
+ *
+ * @return: pointer on the destination STA (may be NULL)
+ *
+ * skb has already been parsed in aicwf_select_queue function
+ * simply re-read information form skb.
+ */
+static struct aicwf_sta *aicwf_get_tx_priv(struct aicwf_vif *aicwf_vif,
+ struct sk_buff *skb, u8 *tid)
+{
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+ struct aicwf_sta *sta;
+ int sta_idx;
+ int nx_remote_sta_max = NX_REMOTE_STA_MAX;
+ int nx_bcmc_txq_ndev_idx = NX_BCMC_TXQ_NDEV_IDX;
+
+ if (aicwf_hw->chip_ops->is_old_ic) {
+ nx_remote_sta_max = NX_REMOTE_STA_MAX_FOR_OLD_IC;
+ nx_bcmc_txq_ndev_idx = NX_BCMC_TXQ_NDEV_IDX_FOR_OLD_IC;
+ }
+
+ *tid = skb->priority;
+ if (unlikely(skb->priority == PRIO_STA_NULL))
+ return NULL;
+
+ int ndev_idx = skb_get_queue_mapping(skb);
+
+ if (ndev_idx == nx_bcmc_txq_ndev_idx)
+ sta_idx = nx_remote_sta_max + master_vif_idx(aicwf_vif);
+ else
+ sta_idx = ndev_idx / NX_NB_TID_PER_STA;
+ sta = &aicwf_hw->sta_table[sta_idx];
+
+ return sta;
+}
+
+/**
+ * aicwf_prep_tx - Prepare buffer for DMA transmission
+ *
+ * @aicwf_hw: Driver main data
+ * @txhdr: Tx descriptor
+ *
+ * Maps hw_txhdr and buffer data for transmission via DMA.
+ * - Data buffer with be downloaded by embebded side.
+ * - hw_txhdr will be uploaded by embedded side when buffer has been
+ * transmitted over the air.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+static int aicwf_prep_tx(struct aicwf_hw *aicwf_hw, struct aicwf_txhdr *txhdr)
+{
+ return 0;
+}
+
+/**
+ * aicwf_tx_push - Push one packet to fw
+ *
+ * @aicwf_hw: Driver main data
+ * @txhdr: tx desc of the buffer to push
+ * @flags: push flags (see @aicwf_push_flags)
+ *
+ * Push one packet to fw. Sw desc of the packet has already been updated.
+ * Only MORE_DATA flag will be set if needed.
+ */
+void aicwf_tx_push(struct aicwf_hw *aicwf_hw, struct aicwf_txhdr *txhdr, int flags)
+{
+ struct aicwf_sw_txhdr *sw_txhdr = txhdr->sw_hdr;
+ struct sk_buff *skb = sw_txhdr->skb;
+ struct aicwf_txq *txq = sw_txhdr->txq;
+ u16 hw_queue = txq->hwq->id;
+ int user = 0;
+
+ lockdep_assert_held(&aicwf_hw->tx_lock);
+
+ /* RETRY flag is not always set so retest here */
+ if (txq->nb_retry) {
+ flags |= AICWF_PUSH_RETRY;
+ txq->nb_retry--;
+ if (txq->nb_retry == 0) {
+ WARN(skb != txq->last_retry_skb,
+ "last retry buffer is not the expected one");
+ txq->last_retry_skb = NULL;
+ }
+ } else if (!(flags & AICWF_PUSH_RETRY)) {
+ txq->pkt_sent++;
+ }
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ if (txq->amsdu == sw_txhdr) {
+ WARN((flags & AICWF_PUSH_RETRY), "End A-MSDU on a retry");
+ aicwf_hw->stats.amsdus[sw_txhdr->amsdu.nb - 1].done++;
+ txq->amsdu = NULL;
+ } else if (!(flags & AICWF_PUSH_RETRY) &&
+ !(sw_txhdr->desc.host.flags & TXU_CNTRL_AMSDU)) {
+ aicwf_hw->stats.amsdus[0].done++;
+ }
+#endif /* CONFIG_AICWF_AMSDUS_TX */
+
+ /*
+ * Wait here to update hw_queue, as for multicast STA hwq may change
+ * between queue and push (because of PS)
+ */
+ sw_txhdr->hw_queue = hw_queue;
+
+ // sw_txhdr->desc.host.packet_addr = hw_queue; //use packet_addr field for
+ // hw_txq
+ sw_txhdr->desc.host.ac = hw_queue; // use ac field for hw_txq
+#ifdef CONFIG_AICWF_MUMIMO_TX
+ /* MU group is only selected during hwq processing */
+ sw_txhdr->desc.host.mumimo_info = txq->mumimo_info;
+ user = AICWF_TXQ_POS_ID(txq);
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+
+ if (sw_txhdr->aicwf_sta) {
+ /* only for AP mode */
+ aicwf_set_more_data_flag(aicwf_hw, sw_txhdr);
+ }
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_push_desc(skb, sw_txhdr, flags);
+#endif
+
+ txq->pkt_pushed[user]++;
+
+ if (txq->push_limit)
+ txq->push_limit--;
+
+ if (((sw_txhdr->desc.host.flags & TXU_CNTRL_MGMT) &&
+ (*(skb->data + sw_txhdr->headroom) == 0xd0 ||
+ *(skb->data + sw_txhdr->headroom) == 0x10 ||
+ *(skb->data + sw_txhdr->headroom) == 0x30)) ||
+ sw_txhdr->desc.host.ethertype == cpu_to_be16(ETH_P_PAE) ||
+ sw_txhdr->desc.host.ethertype == cpu_to_be16(0x88b4)) {
+ sw_txhdr->need_cfm = 1;
+ sw_txhdr->desc.host.hostid =
+ ((1 << 31) | aicwf_hw->sdio_env.txdesc_free_idx[0]);
+ aicwf_sdio_host_txdesc_push(&aicwf_hw->sdio_env, 0, (long)skb);
+ dev_dbg(aicwf_hw->dev, "need cfm ethertype:%8x,user_idx=%d, skb=%p\n",
+ sw_txhdr->desc.host.ethertype,
+ aicwf_hw->sdio_env.txdesc_free_idx[0], skb);
+ } else {
+ sw_txhdr->need_cfm = 0;
+ sw_txhdr->desc.host.hostid = 0;
+
+ sw_txhdr->aicwf_vif->net_stats.tx_packets++;
+ sw_txhdr->aicwf_vif->net_stats.tx_bytes += sw_txhdr->frame_len;
+ aicwf_hw->stats.last_tx = jiffies;
+ }
+ aicwf_frame_tx((void *)(aicwf_hw->sdiodev), skb);
+ aicwf_hw->stats.cfm_balance[hw_queue]++;
+}
+
+/**
+ * aicwf_tx_retry - Push an AMPDU pkt that need to be retried
+ *
+ * @aicwf_hw: Driver main data
+ * @skb: pkt to re-push
+ * @txhdr: tx desc of the pkt to re-push
+ * @sw_retry: Indicates if fw decide to retry this buffer
+ * (i.e. it has never been transmitted over the air)
+ *
+ * Called when a packet needs to be repushed to the firmware.
+ * First update sw descriptor and then queue it in the retry list.
+ */
+static void aicwf_tx_retry(struct aicwf_hw *aicwf_hw, struct sk_buff *skb,
+ struct aicwf_txhdr *txhdr, bool sw_retry)
+{
+ struct aicwf_sw_txhdr *sw_txhdr = txhdr->sw_hdr;
+ struct tx_cfm_tag *cfm = &txhdr->hw_hdr.cfm;
+ struct aicwf_txq *txq = sw_txhdr->txq;
+
+ if (!sw_retry) {
+ /* update sw desc */
+ sw_txhdr->desc.host.flags |= TXU_CNTRL_RETRY;
+
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ if (sw_txhdr->desc.host.flags & TXU_CNTRL_AMSDU)
+ aicwf_hw->stats.amsdus[sw_txhdr->amsdu.nb - 1].failed++;
+#endif
+ }
+
+ /* MORE_DATA will be re-set if needed when pkt will be repushed */
+ sw_txhdr->desc.host.flags &= ~TXU_CNTRL_MORE_DATA;
+
+ cfm->status.value = 0;
+
+ txq->credits++;
+ if (txq->credits > 0)
+ aicwf_txq_start(txq, AICWF_TXQ_STOP_FULL);
+
+ /* Queue the buffer */
+ aicwf_txq_queue_skb(skb, txq, aicwf_hw, true);
+}
+
+#ifdef CONFIG_AICWF_AMSDUS_TX
+/* return size of subframe (including header) */
+static inline int aicwf_amsdu_subframe_length(struct ethhdr *eth, int eth_len)
+{
+ /*
+ * ethernet header is replaced with amdsu header that have the same size
+ * Only need to check if LLC/SNAP header will be added
+ */
+ int len = eth_len;
+
+ if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN)
+ len += sizeof(rfc1042_header) + 2;
+ return len;
+}
+
+static inline bool aicwf_amsdu_is_aggregable(struct sk_buff *skb)
+{
+ /* need to add some check on buffer to see if it can be aggregated ? */
+ return true;
+}
+
+/*
+ * aicwf_amsdu_del_subframe_header - remove AMSDU header
+ *
+ * amsdu_txhdr: amsdu tx descriptor
+ *
+ * Move back the ethernet header at the "beginning" of the data buffer.
+ * (which has been moved in @aicwf_amsdu_add_subframe_header)
+ */
+static void aicwf_amsdu_del_subframe_header(struct aicwf_amsdu_txhdr *amsdu_txhdr)
+{
+ struct sk_buff *skb = amsdu_txhdr->skb;
+ struct ethhdr *eth;
+ u8 *pos;
+
+ pos = skb->data;
+ pos += sizeof(struct aicwf_amsdu_txhdr);
+ eth = (struct ethhdr *)pos;
+ pos += amsdu_txhdr->pad + sizeof(struct ethhdr);
+
+ if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN)
+ pos += sizeof(rfc1042_header) + 2;
+
+ memmove(pos, eth, sizeof(*eth));
+ skb_pull(skb, (pos - skb->data));
+}
+
+/*
+ * aicwf_amsdu_add_subframe_header - Add AMSDU header and link subframe
+ *
+ * @aicwf_hw Driver main data
+ * @skb Buffer to aggregate
+ * @sw_txhdr Tx descriptor for the first A-MSDU subframe
+ *
+ * return 0 on success, -1 otherwise
+ *
+ * This functions Add A-MSDU header and LLC/SNAP header in the buffer
+ * and update sw_txhdr of the first subframe to link this buffer.
+ * If an error happens, the buffer will be queued as a normal buffer.
+ *
+ *
+ * Before After
+ * +-------------+ +-------------+
+ * | HEADROOM | | HEADROOM |
+ * | | +-------------+ <- data
+ * | | | amsdu_txhdr |
+ * | | | * pad size |
+ * | | +-------------+
+ * | | | ETH hdr | keep original eth hdr
+ * | | | | to restore it once transmitted
+ * | | +-------------+ <- packet_addr[x]
+ * | | | Pad |
+ * | | +-------------+
+ * data -> +-------------+ | AMSDU HDR |
+ * | ETH hdr | +-------------+
+ * | | | LLC/SNAP |
+ * +-------------+ +-------------+
+ * | DATA | | DATA |
+ * | | | |
+ * +-------------+ +-------------+
+ *
+ * Called with tx_lock hold
+ */
+static int aicwf_amsdu_add_subframe_header(struct aicwf_hw *aicwf_hw,
+ struct sk_buff *skb,
+ struct aicwf_sw_txhdr *sw_txhdr)
+{
+ struct aicwf_amsdu *amsdu = &sw_txhdr->amsdu;
+ struct aicwf_amsdu_txhdr *amsdu_txhdr;
+ struct ethhdr *amsdu_hdr, *eth = (struct ethhdr *)skb->data;
+ int headroom_need, map_len, msdu_len;
+ dma_addr_t dma_addr;
+ u8 *pos, *map_start;
+
+ msdu_len = skb->len - sizeof(*eth);
+ headroom_need = sizeof(*amsdu_txhdr) + amsdu->pad + sizeof(*amsdu_hdr);
+ if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN) {
+ headroom_need += sizeof(rfc1042_header) + 2;
+ msdu_len += sizeof(rfc1042_header) + 2;
+ }
+
+ /* we should have enough headroom (checked in xmit) */
+ if (WARN_ON(skb_headroom(skb) < headroom_need))
+ return -1;
+
+ /* allocate headroom */
+ pos = skb_push(skb, headroom_need);
+ amsdu_txhdr = (struct aicwf_amsdu_txhdr *)pos;
+ pos += sizeof(*amsdu_txhdr);
+
+ /* move eth header */
+ memmove(pos, eth, sizeof(*eth));
+ eth = (struct ethhdr *)pos;
+ pos += sizeof(*eth);
+
+ /* Add padding from previous subframe */
+ map_start = pos;
+ memset(pos, 0, amsdu->pad);
+ pos += amsdu->pad;
+
+ /* Add AMSDU hdr */
+ amsdu_hdr = (struct ethhdr *)pos;
+ memcpy(amsdu_hdr->h_dest, eth->h_dest, ETH_ALEN);
+ memcpy(amsdu_hdr->h_source, eth->h_source, ETH_ALEN);
+ amsdu_hdr->h_proto = htons(msdu_len);
+ pos += sizeof(*amsdu_hdr);
+
+ if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN) {
+ memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
+ pos += sizeof(rfc1042_header);
+ }
+
+ /* MAP (and sync) memory for DMA */
+ map_len = msdu_len + amsdu->pad + sizeof(*amsdu_hdr);
+ dma_addr =
+ dma_map_single(aicwf_hw->dev, map_start, map_len, DMA_BIDIRECTIONAL);
+ if (WARN_ON(dma_mapping_error(aicwf_hw->dev, dma_addr))) {
+ pos -= sizeof(*eth);
+ memmove(pos, eth, sizeof(*eth));
+ skb_pull(skb, headroom_need);
+ return -1;
+ }
+
+ /* update amdsu_txhdr */
+ amsdu_txhdr->map_len = map_len;
+ amsdu_txhdr->dma_addr = dma_addr;
+ amsdu_txhdr->skb = skb;
+ amsdu_txhdr->pad = amsdu->pad;
+ amsdu_txhdr->msdu_len = msdu_len;
+
+ /* update aicwf_sw_txhdr (of the first subframe) */
+ WARN_ON_ONCE(amsdu->nb != sw_txhdr->desc.host.packet_cnt);
+
+ sw_txhdr->desc.host.packet_addr[amsdu->nb] = dma_addr;
+ sw_txhdr->desc.host.packet_len[amsdu->nb] = map_len;
+ sw_txhdr->desc.host.packet_cnt++;
+ amsdu->nb++;
+
+ amsdu->pad = AMSDU_PADDING(map_len - amsdu->pad);
+ list_add_tail(&amsdu_txhdr->list, &amsdu->hdrs);
+ amsdu->len += map_len;
+
+ trace_amsdu_subframe(sw_txhdr);
+ return 0;
+}
+
+/*
+ * aicwf_amsdu_add_subframe - Add this buffer as an A-MSDU subframe if possible
+ *
+ * @aicwf_hw Driver main data
+ * @skb Buffer to aggregate if possible
+ * @sta Destination STA
+ * @txq sta's txq used for this buffer
+ *
+ * Tyr to aggregate the buffer in an A-MSDU. If it succeed then the
+ * buffer is added as a new A-MSDU subframe with AMSDU and LLC/SNAP
+ * headers added (so FW won't have to modify this subframe).
+ *
+ * To be added as subframe :
+ * - sta must allow amsdu
+ * - buffer must be aggregable (to be defined)
+ * - at least one other aggregable buffer is pending in the queue
+ * or an a-msdu (with enough free space) is currently in progress
+ *
+ * returns true if buffer has been added as A-MDSP subframe, false otherwise
+ *
+ */
+static bool aicwf_amsdu_add_subframe(struct aicwf_hw *aicwf_hw,
+ struct sk_buff *skb, struct aicwf_sta *sta,
+ struct aicwf_txq *txq)
+{
+ bool res = false;
+ struct ethhdr *eth;
+
+ /* immediately return if amsdu are not allowed for this sta */
+ if (!txq->amsdu_len || aicwf_hw->mod_params->amsdu_maxnb < 2 ||
+ !aicwf_amsdu_is_aggregable(skb))
+ return false;
+
+ spin_lock_bh(&aicwf_hw->tx_lock);
+ if (txq->amsdu) {
+ /*
+ * aggreagation already in progress, add this buffer if enough space
+ * available, otherwise end the current amsdu
+ */
+ struct aicwf_sw_txhdr *sw_txhdr = txq->amsdu;
+
+ eth = (struct ethhdr *)(skb->data);
+
+ if (((sw_txhdr->amsdu.len + sw_txhdr->amsdu.pad +
+ aicwf_amsdu_subframe_length(eth, skb->len)) > txq->amsdu_len) ||
+ aicwf_amsdu_add_subframe_header(aicwf_hw, skb, sw_txhdr)) {
+ txq->amsdu = NULL;
+ goto end;
+ }
+
+ if (sw_txhdr->amsdu.nb >= aicwf_hw->mod_params->amsdu_maxnb) {
+ aicwf_hw->stats.amsdus[sw_txhdr->amsdu.nb - 1].done++;
+ /* max number of subframes reached */
+ txq->amsdu = NULL;
+ }
+ } else {
+ /*
+ * Check if a new amsdu can be started with the previous buffer
+ * (if any) and this one
+ */
+ struct sk_buff *skb_prev = skb_peek_tail(&txq->sk_list);
+ struct aicwf_txhdr *txhdr;
+ struct aicwf_sw_txhdr *sw_txhdr;
+ int len1, len2;
+
+ if (!skb_prev || !aicwf_amsdu_is_aggregable(skb_prev))
+ goto end;
+
+ txhdr = (struct aicwf_txhdr *)skb_prev->data;
+ sw_txhdr = txhdr->sw_hdr;
+ if (sw_txhdr->amsdu.len ||
+ (sw_txhdr->desc.host.flags & TXU_CNTRL_RETRY))
+ /* previous buffer is already a complete amsdu or a retry */
+ goto end;
+
+ eth = (struct ethhdr *)(skb_prev->data + sw_txhdr->headroom);
+ len1 = aicwf_amsdu_subframe_length(eth,
+ (sw_txhdr->frame_len + sizeof(struct ethhdr)));
+
+ eth = (struct ethhdr *)(skb->data);
+ len2 = aicwf_amsdu_subframe_length(eth, skb->len);
+
+ if (len1 + AMSDU_PADDING(len1) + len2 > txq->amsdu_len)
+ /* not enough space to aggregate those two buffers */
+ goto end;
+
+ /*
+ * Add subframe header.
+ * Note: Fw will take care of adding AMDSU header for the first
+ * subframe while generating 802.11 MAC header
+ */
+ INIT_LIST_HEAD(&sw_txhdr->amsdu.hdrs);
+ sw_txhdr->amsdu.len = len1;
+ sw_txhdr->amsdu.nb = 1;
+ sw_txhdr->amsdu.pad = AMSDU_PADDING(len1);
+ if (aicwf_amsdu_add_subframe_header(aicwf_hw, skb, sw_txhdr))
+ goto end;
+
+ sw_txhdr->desc.host.flags |= TXU_CNTRL_AMSDU;
+
+ if (sw_txhdr->amsdu.nb < aicwf_hw->mod_params->amsdu_maxnb)
+ txq->amsdu = sw_txhdr;
+ else
+ aicwf_hw->stats.amsdus[sw_txhdr->amsdu.nb - 1].done++;
+ }
+
+ res = true;
+
+end:
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+ return res;
+}
+#endif /* CONFIG_AICWF_AMSDUS_TX */
+
+/*
+ * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
+ * struct net_device *dev);
+ * Called when a packet needs to be transmitted.
+ * Must return NETDEV_TX_OK , NETDEV_TX_BUSY.
+ * (can also return NETDEV_TX_LOCKED if NETIF_F_LLTX)
+ *
+ * - Initialize the descriptor for this pkt (stored in skb before data)
+ * - Push the pkt in the corresponding Txq
+ * - If possible (i.e. credit available and not in PS) the pkt is pushed
+ * to fw
+ */
+netdev_tx_t aicwf_start_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+ struct aicwf_vif *aicwf_vif = netdev_priv(dev);
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+ struct aicwf_txhdr *txhdr;
+ struct aicwf_sw_txhdr *sw_txhdr;
+ struct txdesc_api *desc;
+ struct aicwf_sta *sta;
+ struct aicwf_txq *txq;
+ int headroom;
+ int max_headroom;
+ int hdr_pads;
+
+ u16 frame_len;
+ u8 tid;
+
+ struct ethhdr eth_t;
+
+#ifdef CONFIG_AIC8800_ONE_TXQ
+ skb->queue_mapping = aicwf_select_txq(aicwf_vif, skb);
+#endif
+
+ if (unlikely(READ_ONCE(aicwf_hw->regdom_failed)))
+ goto free;
+
+ sk_pacing_shift_update(skb->sk, aicwf_hw->tcp_pacing_shift);
+ max_headroom = sizeof(struct aicwf_txhdr);
+
+ /* check whether the current skb can be used */
+ if (skb_shared(skb) || (skb_headroom(skb) < max_headroom) ||
+ (skb_cloned(skb) && (dev->priv_flags & IFF_BRIDGE_PORT))) {
+ struct sk_buff *newskb =
+ skb_copy_expand(skb, max_headroom, 0, GFP_ATOMIC);
+ if (unlikely(!newskb))
+ goto free;
+
+ dev_kfree_skb_any(skb);
+
+ skb = newskb;
+ }
+
+ //if (skb->priority < 3)
+ // skb->priority = 0;
+
+ memcpy(ð_t, skb->data, sizeof(struct ethhdr));
+
+ /* Get the STA id and TID information */
+ sta = aicwf_get_tx_priv(aicwf_vif, skb, &tid);
+ if (!sta)
+ goto free;
+
+ txq = aicwf_txq_sta_get(sta, tid, aicwf_hw);
+ if (txq->idx == TXQ_INACTIVE)
+ goto free;
+
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ if (aicwf_amsdu_add_subframe(aicwf_hw, skb, sta, txq))
+ return NETDEV_TX_OK;
+#endif
+
+ /* Retrieve the pointer to the Ethernet data */
+ // eth = (struct ethhdr *)skb->data;
+
+ skb_pull(skb, 14);
+ // hdr_pads = AICWF_SWTXHDR_ALIGN_PADS((long)eth);
+ hdr_pads = AICWF_SWTXHDR_ALIGN_PADS((long)skb->data);
+ headroom = sizeof(struct aicwf_txhdr) + hdr_pads;
+
+ skb_push(skb, headroom);
+
+ txhdr = (struct aicwf_txhdr *)skb->data;
+ sw_txhdr = kmem_cache_alloc(aicwf_hw->sw_txhdr_cache, GFP_ATOMIC);
+ if (unlikely(!sw_txhdr))
+ goto free;
+ txhdr->sw_hdr = sw_txhdr;
+ desc = &sw_txhdr->desc;
+
+ frame_len = (u16)skb->len - headroom; // - sizeof(*eth);
+
+ sw_txhdr->txq = txq;
+ sw_txhdr->frame_len = frame_len;
+ sw_txhdr->aicwf_sta = sta;
+ sw_txhdr->aicwf_vif = aicwf_vif;
+ sw_txhdr->skb = skb;
+ sw_txhdr->headroom = headroom;
+
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ sw_txhdr->amsdu.len = 0;
+ sw_txhdr->amsdu.nb = 0;
+#endif
+ // Fill-in the descriptor
+ memcpy(&desc->host.eth_dest_addr, eth_t.h_dest, ETH_ALEN);
+ memcpy(&desc->host.eth_src_addr, eth_t.h_source, ETH_ALEN);
+ desc->host.ethertype = eth_t.h_proto;
+ desc->host.staid = sta->sta_idx;
+ desc->host.tid = tid;
+ desc->host.vif_idx = aicwf_vif->vif_index;
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ if (unlikely(aicwf_vif->wdev.iftype == NL80211_IFTYPE_AP_VLAN))
+ desc->host.vif_idx = aicwf_vif->ap_vlan.master->vif_index;
+#endif
+
+ if (aicwf_vif->use_4addr && sta->sta_idx < NX_REMOTE_STA_MAX)
+ desc->host.flags = TXU_CNTRL_USE_4ADDR;
+ else
+ desc->host.flags = 0;
+
+ if (aicwf_vif->tdls_status == TDLS_LINK_ACTIVE && aicwf_vif->sta.tdls_sta &&
+ (memcmp(desc->host.eth_dest_addr.array,
+ aicwf_vif->sta.tdls_sta->mac_addr, ETH_ALEN) == 0)) {
+ desc->host.flags |= TXU_CNTRL_TDLS;
+ aicwf_vif->sta.tdls_sta->tdls.last_tid = desc->host.tid;
+ // aicwf_vif->sta.tdls_sta->tdls.last_sn = desc->host.sn;
+ }
+
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_MESH_POINT) {
+ if (aicwf_vif->is_resending)
+ desc->host.flags |= TXU_CNTRL_MESH_FWD;
+ }
+#endif
+
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+ desc->host.packet_len[0] = frame_len;
+#else
+ desc->host.packet_len = frame_len;
+#endif
+
+ txhdr->hw_hdr.cfm.status.value = 0;
+
+ if (unlikely(aicwf_prep_tx(aicwf_hw, txhdr))) {
+ kmem_cache_free(aicwf_hw->sw_txhdr_cache, sw_txhdr);
+ skb_pull(skb, headroom);
+ dev_kfree_skb_any(skb);
+ return NETDEV_TX_BUSY;
+ }
+
+ spin_lock_bh(&aicwf_hw->tx_lock);
+ if (aicwf_txq_queue_skb(skb, txq, aicwf_hw, false))
+ aicwf_hwq_process(aicwf_hw, txq->hwq);
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+
+ return NETDEV_TX_OK;
+
+free:
+ dev_kfree_skb_any(skb);
+
+ return NETDEV_TX_OK;
+}
+
+/**
+ * aicwf_start_mgmt_xmit - Transmit a management frame
+ *
+ * @vif: Vif that send the frame
+ * @sta: Destination of the frame. May be NULL if the destiantion is unknown
+ * to the AP.
+ * @params: Mgmt frame parameters
+ * @offchan: Indicate whether the frame must be send via the offchan TXQ.
+ * (is is redundant with params->offchan ?)
+ * @cookie: identifies the frame with upper layers
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+
+int aicwf_start_mgmt_xmit(struct aicwf_vif *vif, struct aicwf_sta *sta,
+ struct cfg80211_mgmt_tx_params *params, bool offchan,
+ u64 cookie)
+{
+ struct aicwf_hw *aicwf_hw = vif->aicwf_hw;
+ struct aicwf_txhdr *txhdr;
+ struct aicwf_sw_txhdr *sw_txhdr;
+ struct txdesc_api *desc;
+ struct sk_buff *skb;
+ u16 frame_len, headroom;
+ u8 *data;
+ int nx_off_chan_txq_idx = NX_OFF_CHAN_TXQ_IDX;
+ struct aicwf_txq *txq;
+ bool robust;
+ const u8 *buf = params->buf;
+ size_t len = params->len;
+ bool no_cck = params->no_cck;
+
+ if (READ_ONCE(aicwf_hw->regdom_failed))
+ return -EIO;
+
+ dev_dbg(aicwf_hw->dev, "mgmt xmit %x %x ", buf[0], buf[1]);
+
+ if (aicwf_hw->chip_ops->is_old_ic)
+ nx_off_chan_txq_idx = NX_OFF_CHAN_TXQ_IDX_FOR_OLD_IC;
+
+ headroom = sizeof(struct aicwf_txhdr);
+ frame_len = len;
+
+ /* Set TID and Queues indexes */
+ if (sta) {
+ txq = aicwf_txq_sta_get(sta, 8, aicwf_hw);
+ } else {
+ if (offchan)
+ txq = &aicwf_hw->txq[nx_off_chan_txq_idx];
+ else
+ txq = aicwf_txq_vif_get(vif, NX_UNK_TXQ_TYPE);
+ }
+
+ /* Ensure that TXQ is active */
+ if (txq->idx == TXQ_INACTIVE) {
+ netdev_dbg(vif->ndev, "txq inactive\n");
+ return -EBUSY;
+ }
+
+ /*
+ * Create a SK Buff object that will contain the provided data
+ */
+ skb = dev_alloc_skb(headroom + frame_len);
+
+ if (!skb)
+ return -ENOMEM;
+
+ /*
+ * Move skb->data pointer in order to reserve room for aicwf_txhdr
+ * headroom value will be equal to sizeof(struct aicwf_txhdr)
+ */
+ skb_reserve(skb, headroom);
+
+ /*
+ * Extend the buffer data area in order to contain the provided packet
+ * len value (for skb) will be equal to param->len
+ */
+ data = skb_put(skb, frame_len);
+ /* Copy the provided data */
+ memcpy(data, buf, frame_len);
+
+ robust = ieee80211_is_robust_mgmt_frame(skb);
+
+ /* Update CSA counter if present */
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ if (unlikely(params->n_csa_offsets) &&
+ vif->wdev.iftype == NL80211_IFTYPE_AP && vif->ap.csa) {
+ int i;
+
+ data = skb->data;
+ for (i = 0; i < params->n_csa_offsets; i++)
+ data[params->csa_offsets[i]] = vif->ap.csa->count;
+ }
+#endif
+
+ /*
+ * Go back to the beginning of the allocated data area
+ * skb->data pointer will move backward
+ */
+ skb_push(skb, headroom);
+
+ /* Fill the TX Header */
+ txhdr = (struct aicwf_txhdr *)skb->data;
+
+ txhdr->hw_hdr.cfm.status.value = 0;
+
+ /* Fill the SW TX Header */
+ sw_txhdr = kmem_cache_alloc(aicwf_hw->sw_txhdr_cache, GFP_ATOMIC);
+ if (unlikely(!sw_txhdr)) {
+ dev_kfree_skb(skb);
+ return -ENOMEM;
+ }
+ txhdr->sw_hdr = sw_txhdr;
+
+ sw_txhdr->txq = txq;
+ sw_txhdr->frame_len = frame_len;
+ sw_txhdr->cookie = cookie;
+ sw_txhdr->aicwf_sta = sta;
+ sw_txhdr->aicwf_vif = vif;
+ sw_txhdr->skb = skb;
+ sw_txhdr->headroom = headroom;
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ sw_txhdr->amsdu.len = 0;
+ sw_txhdr->amsdu.nb = 0;
+#endif
+
+ /* Fill the Descriptor to be provided to the MAC SW */
+ desc = &sw_txhdr->desc;
+
+ desc->host.ethertype = 0;
+ desc->host.staid = (sta) ? sta->sta_idx : 0xFF;
+ desc->host.vif_idx = vif->vif_index;
+ desc->host.tid = 0xFF;
+ desc->host.flags = TXU_CNTRL_MGMT;
+ if (robust)
+ desc->host.flags |= TXU_CNTRL_MGMT_ROBUST;
+
+#ifdef CONFIG_AICWF_SPLIT_TX_BUF
+ desc->host.packet_len[0] = frame_len;
+#else
+ desc->host.packet_len = frame_len;
+#endif
+
+ if (no_cck)
+ desc->host.flags |= TXU_CNTRL_MGMT_NO_CCK;
+
+ /* Get DMA Address */
+ if (unlikely(aicwf_prep_tx(aicwf_hw, txhdr))) {
+ kmem_cache_free(aicwf_hw->sw_txhdr_cache, sw_txhdr);
+ dev_kfree_skb(skb);
+ return -EBUSY;
+ }
+
+ spin_lock_bh(&aicwf_hw->tx_lock);
+ if (aicwf_txq_queue_skb(skb, txq, aicwf_hw, false))
+ aicwf_hwq_process(aicwf_hw, txq->hwq);
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+
+ return 0;
+}
+
+/**
+ * aicwf_txdatacfm - FW callback for TX confirmation
+ * @pthis: Main driver data
+ * @host_id: Socket buffer associated with the confirmation
+ *
+ * Context: Called with the TX lock held.
+ * Return: 0 when the confirmation was handled, or a negative error code.
+ */
+int aicwf_txdatacfm(void *pthis, void *host_id)
+{
+ struct aicwf_hw *aicwf_hw = (struct aicwf_hw *)pthis;
+ struct sk_buff *skb = host_id;
+ struct aicwf_txhdr *txhdr;
+ union aicwf_hw_txstatus aicwf_txst;
+ struct aicwf_sw_txhdr *sw_txhdr;
+ struct aicwf_hwq *hwq;
+ struct aicwf_txq *txq;
+ int headroom;
+
+ txhdr = (struct aicwf_txhdr *)skb->data;
+ sw_txhdr = txhdr->sw_hdr;
+
+ /* Read status in the TX control header */
+ aicwf_txst = txhdr->hw_hdr.cfm.status;
+
+ /* Check status in the header. If status is null, it means that the buffer
+ * was not transmitted and we have to return immediately
+ */
+ if (aicwf_txst.value == 0)
+ return -1;
+
+ if (aicwf_hw->sdiodev->bus_if->state == BUS_DOWN_ST) {
+ headroom = sw_txhdr->headroom;
+ kmem_cache_free(aicwf_hw->sw_txhdr_cache, sw_txhdr);
+ skb_pull(skb, headroom);
+ consume_skb(skb);
+ return 0;
+ }
+
+ txq = sw_txhdr->txq;
+ /* don't use txq->hwq as it may have changed between push and confirm */
+ hwq = &aicwf_hw->hwq[sw_txhdr->hw_queue];
+ aicwf_txq_confirm_any(aicwf_hw, txq, hwq, sw_txhdr);
+
+ /* Update txq and HW queue credits */
+ if (sw_txhdr->desc.host.flags & TXU_CNTRL_MGMT) {
+ pr_debug("done=%d retry_required=%d sw_retry_required=%d acknowledged=%d\n",
+ aicwf_txst.tx_done, aicwf_txst.retry_required,
+ aicwf_txst.sw_retry_required, aicwf_txst.acknowledged);
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_mgmt_cfm(sw_txhdr->aicwf_vif->vif_index,
+ (sw_txhdr->aicwf_sta) ? sw_txhdr->aicwf_sta->sta_idx : 0xFF,
+ aicwf_txst.acknowledged);
+#endif
+ /* Confirm transmission to CFG80211 */
+ cfg80211_mgmt_tx_status(&sw_txhdr->aicwf_vif->wdev, sw_txhdr->cookie,
+ (skb->data + sw_txhdr->headroom),
+ sw_txhdr->frame_len, aicwf_txst.acknowledged,
+ GFP_ATOMIC);
+ } else if ((txq->idx != TXQ_INACTIVE) &&
+ (aicwf_txst.retry_required || aicwf_txst.sw_retry_required)) {
+ bool sw_retry = (aicwf_txst.sw_retry_required) ? true : false;
+
+ /* Reset the status */
+ txhdr->hw_hdr.cfm.status.value = 0;
+
+ /* The confirmed packet was part of an AMPDU and not acked
+ * correctly, so reinject it in the TX path to be retried
+ */
+ aicwf_tx_retry(aicwf_hw, skb, txhdr, sw_retry);
+ return 0;
+ }
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_skb_confirm(skb, txq, hwq, &txhdr->hw_hdr.cfm);
+#endif
+ /* STA may have disconnect (and txq stopped) when buffers were stored
+ * in fw. In this case do nothing when they're returned
+ */
+ if (txq->idx != TXQ_INACTIVE) {
+ /* continue service period */
+ if (unlikely(txq->push_limit && !aicwf_txq_is_full(txq)))
+ aicwf_txq_add_to_hw_list(txq);
+ }
+
+ if (txhdr->hw_hdr.cfm.ampdu_size)
+ aicwf_hw->stats.ampdus_tx[txhdr->hw_hdr.cfm.ampdu_size - 1]++;
+
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ txq->amsdu_len = txhdr->hw_hdr.cfm.amsdu_size;
+#endif
+
+ /* Update statistics */
+ sw_txhdr->aicwf_vif->net_stats.tx_packets++;
+ sw_txhdr->aicwf_vif->net_stats.tx_bytes += sw_txhdr->frame_len;
+
+ /* Release SKBs */
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ if (sw_txhdr->desc.host.flags & TXU_CNTRL_AMSDU) {
+ struct aicwf_amsdu_txhdr *amsdu_txhdr;
+
+ list_for_each_entry(amsdu_txhdr, &sw_txhdr->amsdu.hdrs, list) {
+ aicwf_amsdu_del_subframe_header(amsdu_txhdr);
+ consume_skb(amsdu_txhdr->skb);
+ }
+ }
+#endif /* CONFIG_AICWF_AMSDUS_TX */
+
+ headroom = sw_txhdr->headroom;
+ kmem_cache_free(aicwf_hw->sw_txhdr_cache, sw_txhdr);
+ skb_pull(skb, headroom);
+ consume_skb(skb);
+
+ return 0;
+}
+
+/**
+ * aicwf_txq_credit_update - Update credit for one txq
+ *
+ * @aicwf_hw: Driver main data
+ * @sta_idx: STA idx
+ * @tid: TID
+ * @update: offset to apply in txq credits
+ *
+ * Called when fw send ME_TX_CREDITS_UPDATE_IND message.
+ * Apply @update to txq credits, and stop/start the txq if needed
+ */
+void aicwf_txq_credit_update(struct aicwf_hw *aicwf_hw, int sta_idx, u8 tid,
+ s8 update)
+{
+ struct aicwf_sta *sta = &aicwf_hw->sta_table[sta_idx];
+ struct aicwf_txq *txq;
+
+ txq = aicwf_txq_sta_get(sta, tid, aicwf_hw);
+
+ spin_lock_bh(&aicwf_hw->tx_lock);
+
+ if (txq->idx != TXQ_INACTIVE) {
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_credit_update(txq, update);
+#endif
+ if (txq->credits <= 0)
+ aicwf_txq_stop(txq, AICWF_TXQ_STOP_FULL);
+ else
+ aicwf_txq_start(txq, AICWF_TXQ_STOP_FULL);
+ }
+
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq.c
new file mode 100644
index 000000000000..5b56aa9501ad
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq.c
@@ -0,0 +1,1368 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ****************************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @file aicwf_txq.c
+ *
+ * @brief tx queue function
+ *
+ ****************************************************************************************
+ */
+
+#include "aicwf_defs.h"
+#include "aicwf_events.h"
+#include "aicwf_tx.h"
+
+/******************************************************************************
+ * Utils functions
+ *****************************************************************************/
+#ifdef CONFIG_AICWF_FULLMAC
+const int nx_tid_prio[NX_NB_TID_PER_STA] = {7, 6, 5, 4, 3, 0, 2, 1};
+
+static inline int aicwf_txq_sta_idx(struct aicwf_hw *aicwf_hw,
+ struct aicwf_sta *sta, u8 tid)
+{
+ if (is_multicast_sta(aicwf_hw, sta->sta_idx)) {
+ if (aicwf_hw->chip_ops->is_old_ic)
+ return NX_FIRST_VIF_TXQ_IDX_FOR_OLD_IC + sta->vif_idx;
+
+ return NX_FIRST_VIF_TXQ_IDX + sta->vif_idx;
+ }
+
+ return (sta->sta_idx * NX_NB_TXQ_PER_STA) + tid;
+}
+
+static inline int aicwf_txq_vif_idx(struct aicwf_vif *vif, u8 type)
+{
+ if (vif->aicwf_hw->chip_ops->is_old_ic)
+ return NX_FIRST_VIF_TXQ_IDX_FOR_OLD_IC + master_vif_idx(vif) +
+ (type * NX_VIRT_DEV_MAX);
+
+ return NX_FIRST_VIF_TXQ_IDX + master_vif_idx(vif) +
+ (type * NX_VIRT_DEV_MAX);
+}
+
+struct aicwf_txq *aicwf_txq_sta_get(struct aicwf_sta *sta, u8 tid,
+ struct aicwf_hw *aicwf_hw)
+{
+ if (tid >= NX_NB_TXQ_PER_STA)
+ tid = 0;
+
+ return &aicwf_hw->txq[aicwf_txq_sta_idx(aicwf_hw, sta, tid)];
+}
+
+struct aicwf_txq *aicwf_txq_vif_get(struct aicwf_vif *vif, u8 type)
+{
+ if (type > NX_UNK_TXQ_TYPE)
+ type = NX_BCMC_TXQ_TYPE;
+
+ return &vif->aicwf_hw->txq[aicwf_txq_vif_idx(vif, type)];
+}
+
+static inline struct aicwf_sta *aicwf_txq_2_sta(struct aicwf_txq *txq)
+{
+ return txq->sta;
+}
+
+#endif /* CONFIG_AICWF_FULLMAC */
+
+/******************************************************************************
+ * Init/Deinit functions
+ *****************************************************************************/
+/*
+ * aicwf_txq_init - Initialize a TX queue
+ *
+ * @txq: TX queue to be initialized
+ * @idx: TX queue index
+ * @status: TX queue initial status
+ * @hwq: Associated HW queue
+ * @ndev: Net device this queue belongs to
+ * (may be null for non netdev txq)
+ *
+ * Each queue is initialized with the credit of @NX_TXQ_INITIAL_CREDITS.
+ */
+static void aicwf_txq_init(struct aicwf_hw *aicwf_hw, struct aicwf_txq *txq,
+ int idx, u8 status,
+ struct aicwf_hwq *hwq, int tid,
+#ifdef CONFIG_AICWF_FULLMAC
+ struct aicwf_sta *sta, struct net_device *ndev
+#endif
+ )
+{
+ int i;
+ int nx_first_unk_txq_idx = NX_FIRST_UNK_TXQ_IDX;
+ int nx_bcmc_txq_ndev_idx = NX_BCMC_TXQ_NDEV_IDX;
+ int nx_first_vif_txq_idx = NX_FIRST_VIF_TXQ_IDX;
+
+ if (aicwf_hw->chip_ops->is_old_ic) {
+ nx_first_unk_txq_idx = NX_FIRST_UNK_TXQ_IDX_FOR_OLD_IC;
+ nx_bcmc_txq_ndev_idx = NX_BCMC_TXQ_NDEV_IDX_FOR_OLD_IC;
+ nx_first_vif_txq_idx = NX_FIRST_VIF_TXQ_IDX_FOR_OLD_IC;
+ }
+
+ txq->idx = idx;
+ txq->status = status;
+ txq->credits = NX_TXQ_INITIAL_CREDITS;
+ txq->pkt_sent = 0;
+ skb_queue_head_init(&txq->sk_list);
+ txq->last_retry_skb = NULL;
+ txq->nb_retry = 0;
+ txq->hwq = hwq;
+ txq->sta = sta;
+ for (i = 0; i < NX_USER_MAX; i++)
+ txq->pkt_pushed[i] = 0;
+ txq->push_limit = 0;
+ txq->tid = tid;
+#ifdef CONFIG_MAC80211_TXQ
+ txq->nb_ready_mac80211 = 0;
+#endif
+#ifdef CONFIG_AICWF_FULLMAC
+ txq->ps_id = LEGACY_PS_ID;
+ if (idx < nx_first_vif_txq_idx) {
+ int sta_idx = sta->sta_idx;
+ int tid = idx - (sta_idx * NX_NB_TXQ_PER_STA);
+
+ if (tid < NX_NB_TID_PER_STA)
+ txq->ndev_idx = NX_STA_NDEV_IDX(tid, sta_idx);
+ else
+ txq->ndev_idx = NDEV_NO_TXQ;
+ } else if (idx < nx_first_unk_txq_idx) {
+ txq->ndev_idx = nx_bcmc_txq_ndev_idx;
+ } else {
+ txq->ndev_idx = NDEV_NO_TXQ;
+ }
+ txq->ndev = ndev;
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ txq->amsdu = NULL;
+ txq->amsdu_len = 0;
+#endif /* CONFIG_AICWF_AMSDUS_TX */
+#endif /* CONFIG_AICWF_FULLMAC */
+}
+
+/**
+ * aicwf_txq_flush - Flush all buffers queued for a TXQ
+ *
+ * @aicwf_hw: main driver data
+ * @txq: txq to flush
+ */
+void aicwf_txq_flush(struct aicwf_hw *aicwf_hw, struct aicwf_txq *txq)
+{
+ struct sk_buff *skb;
+
+ while ((skb = skb_dequeue(&txq->sk_list)) != NULL) {
+ struct aicwf_sw_txhdr *sw_txhdr =
+ ((struct aicwf_txhdr *)skb->data)->sw_hdr;
+
+#ifdef CONFIG_AICWF_AMSDUS_TX
+ if (sw_txhdr->desc.host.packet_cnt > 1) {
+ struct aicwf_amsdu_txhdr *amsdu_txhdr;
+
+ list_for_each_entry(amsdu_txhdr, &sw_txhdr->amsdu.hdrs, list) {
+ dev_kfree_skb_any(amsdu_txhdr->skb);
+ }
+ }
+#endif
+ kmem_cache_free(aicwf_hw->sw_txhdr_cache, sw_txhdr);
+
+#ifdef CONFIG_AICWF_FULLMAC
+ dev_kfree_skb_any(skb);
+#endif /* CONFIG_AICWF_FULLMAC */
+ }
+}
+
+/**
+ * aicwf_txq_deinit - De-initialize a TX queue
+ *
+ * @aicwf_hw: Driver main data
+ * @txq: TX queue to be de-initialized
+ * Any buffer stuck in a queue will be freed.
+ */
+static void aicwf_txq_deinit(struct aicwf_hw *aicwf_hw, struct aicwf_txq *txq)
+{
+ if (txq->idx == TXQ_INACTIVE)
+ return;
+
+ spin_lock_bh(&aicwf_hw->tx_lock);
+ aicwf_txq_del_from_hw_list(txq);
+ txq->idx = TXQ_INACTIVE;
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+
+ aicwf_txq_flush(aicwf_hw, txq);
+}
+
+/**
+ * aicwf_txq_vif_init - Initialize all TXQ linked to a vif
+ *
+ * @aicwf_hw: main driver data
+ * @aicwf_vif: Pointer on VIF
+ * @status: Initial txq status
+ *
+ * Softmac : 1 VIF TXQ per HWQ
+ *
+ * Fullmac : 1 VIF TXQ for BC/MC
+ * 1 VIF TXQ for MGMT to unknown STA
+ */
+void aicwf_txq_vif_init(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ u8 status)
+{
+ struct aicwf_txq *txq;
+ int idx;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ txq = aicwf_txq_vif_get(aicwf_vif, NX_BCMC_TXQ_TYPE);
+ idx = aicwf_txq_vif_idx(aicwf_vif, NX_BCMC_TXQ_TYPE);
+ aicwf_txq_init(aicwf_hw, txq, idx, status, &aicwf_hw->hwq[AICWF_HWQ_BE], 0,
+ &aicwf_hw->sta_table[aicwf_vif->ap.bcmc_index], aicwf_vif->ndev);
+
+ txq = aicwf_txq_vif_get(aicwf_vif, NX_UNK_TXQ_TYPE);
+ idx = aicwf_txq_vif_idx(aicwf_vif, NX_UNK_TXQ_TYPE);
+ aicwf_txq_init(aicwf_hw, txq, idx, status, &aicwf_hw->hwq[AICWF_HWQ_VO], TID_MGT, NULL,
+ aicwf_vif->ndev);
+
+#endif /* CONFIG_AICWF_FULLMAC */
+}
+
+/**
+ * aicwf_txq_vif_deinit - Deinitialize all TXQ linked to a vif
+ *
+ * @aicwf_hw: main driver data
+ * @aicwf_vif: Pointer on VIF
+ */
+void aicwf_txq_vif_deinit(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif)
+{
+ struct aicwf_txq *txq;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ txq = aicwf_txq_vif_get(aicwf_vif, NX_BCMC_TXQ_TYPE);
+ aicwf_txq_deinit(aicwf_hw, txq);
+
+ txq = aicwf_txq_vif_get(aicwf_vif, NX_UNK_TXQ_TYPE);
+ aicwf_txq_deinit(aicwf_hw, txq);
+
+#endif /* CONFIG_AICWF_FULLMAC */
+}
+
+/**
+ * aicwf_txq_sta_init - Initialize TX queues for a STA
+ *
+ * @aicwf_hw: Main driver data
+ * @aicwf_sta: STA for which tx queues need to be initialized
+ * @status: Initial txq status
+ *
+ * This function initialize all the TXQ associated to a STA.
+ * Softmac : 1 TXQ per TID
+ *
+ * Fullmac : 1 TXQ per TID (limited to 8)
+ * 1 TXQ for MGMT
+ */
+void aicwf_txq_sta_init(struct aicwf_hw *aicwf_hw, struct aicwf_sta *aicwf_sta,
+ u8 status)
+{
+ struct aicwf_txq *txq;
+ int tid, idx;
+
+#ifdef CONFIG_AICWF_FULLMAC
+ struct aicwf_vif *aicwf_vif = aicwf_hw->vif_table[aicwf_sta->vif_idx];
+
+ idx = aicwf_txq_sta_idx(aicwf_hw, aicwf_sta, 0);
+
+#ifdef CONFIG_MAC80211_TXQ
+ for (tid = 0, txq = aicwf_txq_sta_get(aicwf_sta, 0); tid < NX_NB_TXQ_PER_STA;
+ tid++, txq = aicwf_txq_sta_get(aicwf_sta, tid))
+#elif defined(CONFIG_AICWF_FULLMAC)
+ for (tid = 0, txq = aicwf_txq_sta_get(aicwf_sta, 0, aicwf_hw);
+ tid < (is_multicast_sta(aicwf_hw, aicwf_sta->sta_idx) ? 1 : NX_NB_TXQ_PER_STA);
+ tid++, txq++)
+#endif
+ {
+ aicwf_txq_init(aicwf_hw, txq, idx, status, &aicwf_hw->hwq[aicwf_tid2hwq[tid]], tid,
+ aicwf_sta, aicwf_vif->ndev);
+ txq->ps_id =
+ aicwf_sta->uapsd_tids & (1 << tid) ? UAPSD_ID : LEGACY_PS_ID;
+ idx++;
+ }
+
+#endif /* CONFIG_AICWF_FULLMAC */
+}
+
+/**
+ * aicwf_txq_sta_deinit - Deinitialize TX queues for a STA
+ *
+ * @aicwf_hw: Main driver data
+ * @aicwf_sta: STA for which tx queues need to be deinitialized
+ */
+void aicwf_txq_sta_deinit(struct aicwf_hw *aicwf_hw, struct aicwf_sta *aicwf_sta)
+{
+ struct aicwf_txq *txq;
+ int tid;
+
+#ifdef CONFIG_MAC80211_TXQ
+ for (tid = 0, txq = aicwf_txq_sta_get(aicwf_sta, 0); tid < NX_NB_TXQ_PER_STA;
+ tid++, txq = aicwf_txq_sta_get(aicwf_sta, tid))
+#elif defined(CONFIG_AICWF_FULLMAC)
+ for (tid = 0, txq = aicwf_txq_sta_get(aicwf_sta, 0, aicwf_hw);
+ tid < (is_multicast_sta(aicwf_hw, aicwf_sta->sta_idx) ? 1 : NX_NB_TXQ_PER_STA);
+ tid++, txq++)
+#endif
+ {
+ aicwf_txq_deinit(aicwf_hw, txq);
+ }
+}
+
+#ifdef CONFIG_AICWF_FULLMAC
+/**
+ * aicwf_txq_unk_vif_init - Initialize TXQ for unknown STA linked to a vif
+ *
+ * @aicwf_vif: Pointer on VIF
+ */
+void aicwf_txq_unk_vif_init(struct aicwf_vif *aicwf_vif)
+{
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+ struct aicwf_txq *txq;
+ int idx;
+
+ txq = aicwf_txq_vif_get(aicwf_vif, NX_UNK_TXQ_TYPE);
+ idx = aicwf_txq_vif_idx(aicwf_vif, NX_UNK_TXQ_TYPE);
+ aicwf_txq_init(aicwf_hw, txq, idx, 0, &aicwf_hw->hwq[AICWF_HWQ_VO], TID_MGT, NULL,
+ aicwf_vif->ndev);
+}
+
+/**
+ * aicwf_txq_unk_vif_deinit - Deinitialize the unknown-STA TX queue for a VIF
+ *
+ * @aicwf_vif: VIF that owns the queue
+ */
+void aicwf_txq_unk_vif_deinit(struct aicwf_vif *aicwf_vif)
+{
+ struct aicwf_txq *txq;
+
+ txq = aicwf_txq_vif_get(aicwf_vif, NX_UNK_TXQ_TYPE);
+ aicwf_txq_deinit(aicwf_vif->aicwf_hw, txq);
+}
+
+/**
+ * aicwf_txq_offchan_init - Initialize the off-channel TX queue
+ *
+ * @aicwf_vif: VIF that owns the queue
+ *
+ * The off-channel queue is active only for the duration of remain-on-channel.
+ */
+void aicwf_txq_offchan_init(struct aicwf_vif *aicwf_vif)
+{
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+ struct aicwf_txq *txq;
+ int nx_off_chan_txq_idx = NX_OFF_CHAN_TXQ_IDX;
+
+ if (aicwf_hw->chip_ops->is_old_ic)
+ nx_off_chan_txq_idx = NX_OFF_CHAN_TXQ_IDX_FOR_OLD_IC;
+
+ txq = &aicwf_hw->txq[nx_off_chan_txq_idx];
+ aicwf_txq_init(aicwf_hw, txq, nx_off_chan_txq_idx, AICWF_TXQ_STOP_CHAN,
+ &aicwf_hw->hwq[AICWF_HWQ_VO], TID_MGT, NULL, aicwf_vif->ndev);
+}
+
+/**
+ * aicwf_txq_offchan_deinit - Deinitialize the off-channel TX queue
+ *
+ * @aicwf_vif: Interface that owns the queue
+ *
+ * Any buffer remaining in the queue is freed.
+ */
+void aicwf_txq_offchan_deinit(struct aicwf_vif *aicwf_vif)
+{
+ struct aicwf_txq *txq;
+
+ int nx_off_chan_txq_idx = NX_OFF_CHAN_TXQ_IDX;
+
+ if (aicwf_vif->aicwf_hw->chip_ops->is_old_ic)
+ nx_off_chan_txq_idx = NX_OFF_CHAN_TXQ_IDX_FOR_OLD_IC;
+
+ txq = &aicwf_vif->aicwf_hw->txq[nx_off_chan_txq_idx];
+ aicwf_txq_deinit(aicwf_vif->aicwf_hw, txq);
+}
+
+/**
+ * aicwf_txq_tdls_vif_init - Initialize TXQ vif for TDLS
+ *
+ * @aicwf_vif: Pointer on VIF
+ */
+void aicwf_txq_tdls_vif_init(struct aicwf_vif *aicwf_vif)
+{
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+
+ if (!(aicwf_hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
+ return;
+
+ aicwf_txq_unk_vif_init(aicwf_vif);
+}
+
+/**
+ * aicwf_txq_tdls_vif_deinit - Deinitialize TXQ vif for TDLS
+ *
+ * @aicwf_vif: Pointer on VIF
+ */
+void aicwf_txq_tdls_vif_deinit(struct aicwf_vif *aicwf_vif)
+{
+ struct aicwf_hw *aicwf_hw = aicwf_vif->aicwf_hw;
+
+ if (!(aicwf_hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
+ return;
+
+ aicwf_txq_unk_vif_deinit(aicwf_vif);
+}
+#endif
+
+/******************************************************************************
+ * Start/Stop functions
+ *****************************************************************************/
+/**
+ * aicwf_txq_add_to_hw_list - Add TX queue to a HW queue schedule list.
+ *
+ * @txq: TX queue to add
+ *
+ * Add the TX queue if not already present in the HW queue list.
+ * To be called with tx_lock hold
+ */
+void aicwf_txq_add_to_hw_list(struct aicwf_txq *txq)
+{
+ if (!(txq->status & AICWF_TXQ_IN_HWQ_LIST)) {
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_add_to_hw(txq);
+#endif
+ txq->status |= AICWF_TXQ_IN_HWQ_LIST;
+ list_add_tail(&txq->sched_list, &txq->hwq->list);
+ txq->hwq->need_processing = true;
+ }
+}
+
+/**
+ * aicwf_txq_del_from_hw_list - Delete TX queue from a HW queue schedule list.
+ *
+ * @txq: TX queue to delete
+ *
+ * Remove the TX queue from the HW queue list if present.
+ * To be called with tx_lock hold
+ */
+void aicwf_txq_del_from_hw_list(struct aicwf_txq *txq)
+{
+ if (txq->status & AICWF_TXQ_IN_HWQ_LIST) {
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_del_from_hw(txq);
+#endif
+ txq->status &= ~AICWF_TXQ_IN_HWQ_LIST;
+ list_del(&txq->sched_list);
+ }
+}
+
+/**
+ * aicwf_txq_skb_ready - Check if skb are available for the txq
+ *
+ * @txq: Pointer on txq
+ * Return: %true if buffers are ready to be pushed, otherwise %false.
+ */
+static inline bool aicwf_txq_skb_ready(struct aicwf_txq *txq)
+{
+#ifdef CONFIG_MAC80211_TXQ
+ if (txq->nb_ready_mac80211 != NOT_MAC80211_TXQ)
+ return ((txq->nb_ready_mac80211 > 0) ||
+ !skb_queue_empty(&txq->sk_list));
+ else
+#endif
+ return !skb_queue_empty(&txq->sk_list);
+}
+
+/**
+ * aicwf_txq_start - Try to Start one TX queue
+ *
+ * @txq: TX queue to start
+ * @reason: reason why the TX queue is started (among AICWF_TXQ_STOP_xxx)
+ *
+ * Re-start the TX queue for one reason.
+ * If after this the txq is no longer stopped and some buffers are ready,
+ * the TX queue is also added to HW queue list.
+ * To be called with tx_lock hold
+ */
+void aicwf_txq_start(struct aicwf_txq *txq, u16 reason)
+{
+ WARN_ON_ONCE(!txq);
+ if (txq->idx != TXQ_INACTIVE && (txq->status & reason)) {
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_start(txq, reason);
+#endif
+ txq->status &= ~reason;
+ if (!aicwf_txq_is_stopped(txq) && aicwf_txq_skb_ready(txq))
+ aicwf_txq_add_to_hw_list(txq);
+ }
+}
+
+/**
+ * aicwf_txq_stop - Stop one TX queue
+ *
+ * @txq: TX queue to stop
+ * @reason: reason why the TX queue is stopped (among AICWF_TXQ_STOP_xxx)
+ *
+ * Stop the TX queue. It will remove the TX queue from HW queue list
+ * To be called with tx_lock hold
+ */
+void aicwf_txq_stop(struct aicwf_txq *txq, u16 reason)
+{
+ WARN_ON_ONCE(!txq);
+ if (txq->idx != TXQ_INACTIVE) {
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_stop(txq, reason);
+#endif
+ txq->status |= reason;
+ aicwf_txq_del_from_hw_list(txq);
+ }
+}
+
+/**
+ * aicwf_txq_sta_start - Start all TX queues linked to a STA
+ *
+ * @aicwf_sta: STA whose TX queues must be re-started
+ * @reason: Stop-reason bits to clear
+ * @aicwf_hw: Driver main data
+ *
+ * Restart all the TX queues of the STA for the specified reason:
+ * - AICWF_TXQ_STOP_STA_PS: the STA is no longer in power save mode
+ * - AICWF_TXQ_STOP_VIF_PS: the VIF is in power save mode (p2p absence)
+ * - AICWF_TXQ_STOP_CHAN: the STA's VIF is now on the current active channel
+ *
+ * A queue with a ready buffer and no other stop reason is added to its hardware
+ * queue list.
+ *
+ * Context: Called with the TX lock held.
+ */
+void aicwf_txq_sta_start(struct aicwf_sta *aicwf_sta, u16 reason
+#ifdef CONFIG_AICWF_FULLMAC
+ ,
+ struct aicwf_hw *aicwf_hw
+#endif
+)
+{
+ struct aicwf_txq *txq;
+ int tid;
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_sta_start(aicwf_sta->sta_idx);
+#endif
+#ifdef CONFIG_MAC80211_TXQ
+ for (tid = 0, txq = aicwf_txq_sta_get(aicwf_sta, 0); tid < NX_NB_TXQ_PER_STA;
+ tid++, txq = aicwf_txq_sta_get(aicwf_sta, tid))
+#elif defined(CONFIG_AICWF_FULLMAC)
+ for (tid = 0, txq = aicwf_txq_sta_get(aicwf_sta, 0, aicwf_hw);
+ tid < (is_multicast_sta(aicwf_hw, aicwf_sta->sta_idx) ? 1 : NX_NB_TXQ_PER_STA);
+ tid++, txq++)
+#endif
+ {
+ aicwf_txq_start(txq, reason);
+ }
+}
+
+/**
+ * aicwf_txq_sta_stop - Stop all TX queues linked to a STA
+ *
+ * @aicwf_sta: STA whose TX queues must be stopped
+ * @reason: Stop-reason bits to set
+ * @aicwf_hw: Driver main data
+ *
+ * Stop all the TX queues of the STA for the specified reason:
+ * - AICWF_TXQ_STOP_STA_PS: the STA is in power save mode
+ * - AICWF_TXQ_STOP_VIF_PS: the VIF is in power save mode (p2p absence)
+ * - AICWF_TXQ_STOP_CHAN: the STA's VIF is not on the current active channel
+ *
+ * Affected queues are removed from their hardware queue lists.
+ *
+ * Context: Called with the TX lock held.
+ */
+void aicwf_txq_sta_stop(struct aicwf_sta *aicwf_sta, u16 reason
+#ifdef CONFIG_AICWF_FULLMAC
+ ,
+ struct aicwf_hw *aicwf_hw
+#endif
+)
+{
+ struct aicwf_txq *txq;
+ int tid;
+
+ if (!aicwf_sta)
+ return;
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_sta_stop(aicwf_sta->sta_idx);
+#endif
+#ifdef CONFIG_MAC80211_TXQ
+ for (tid = 0, txq = aicwf_txq_sta_get(aicwf_sta, 0); tid < NX_NB_TXQ_PER_STA;
+ tid++, txq = aicwf_txq_sta_get(aicwf_sta, tid))
+#elif defined(CONFIG_AICWF_FULLMAC)
+ for (tid = 0, txq = aicwf_txq_sta_get(aicwf_sta, 0, aicwf_hw);
+ tid < (is_multicast_sta(aicwf_hw, aicwf_sta->sta_idx) ? 1 : NX_NB_TXQ_PER_STA);
+ tid++, txq++)
+#endif
+ {
+ aicwf_txq_stop(txq, reason);
+ }
+}
+
+#ifdef CONFIG_AICWF_FULLMAC
+void aicwf_txq_tdls_sta_start(struct aicwf_vif *aicwf_vif, u16 reason,
+ struct aicwf_hw *aicwf_hw)
+{
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_vif_start(aicwf_vif->vif_index);
+#endif
+ spin_lock_bh(&aicwf_hw->tx_lock);
+
+ if (aicwf_vif->sta.tdls_sta)
+ aicwf_txq_sta_start(aicwf_vif->sta.tdls_sta, reason, aicwf_hw);
+
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+}
+#endif
+
+#ifdef CONFIG_AICWF_FULLMAC
+void aicwf_txq_tdls_sta_stop(struct aicwf_vif *aicwf_vif, u16 reason,
+ struct aicwf_hw *aicwf_hw)
+{
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_vif_stop(aicwf_vif->vif_index);
+#endif
+ spin_lock_bh(&aicwf_hw->tx_lock);
+
+ if (aicwf_vif->sta.tdls_sta)
+ aicwf_txq_sta_stop(aicwf_vif->sta.tdls_sta, reason, aicwf_hw);
+
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+}
+#endif
+
+#ifdef CONFIG_AICWF_FULLMAC
+static inline void
+aicwf_txq_vif_for_each_sta(struct aicwf_hw *aicwf_hw, struct aicwf_vif *aicwf_vif,
+ void (*f)(struct aicwf_sta *, u16, struct aicwf_hw *),
+ u16 reason) {
+ switch (AICWF_VIF_TYPE(aicwf_vif)) {
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ case NL80211_IFTYPE_P2P_CLIENT:
+#endif
+ case NL80211_IFTYPE_STATION: {
+ if (aicwf_vif->tdls_status == TDLS_LINK_ACTIVE)
+ f(aicwf_vif->sta.tdls_sta, reason, aicwf_hw);
+ if (!WARN_ON(!aicwf_vif->sta.ap))
+ f(aicwf_vif->sta.ap, reason, aicwf_hw);
+ break;
+ }
+#if !IS_ENABLED(CONFIG_AIC8800_STA_ONLY)
+ case NL80211_IFTYPE_AP_VLAN:
+ aicwf_vif = aicwf_vif->ap_vlan.master;
+ fallthrough;
+ case NL80211_IFTYPE_AP:
+ case NL80211_IFTYPE_MESH_POINT:
+ case NL80211_IFTYPE_P2P_GO: {
+ struct aicwf_sta *sta;
+
+ list_for_each_entry(sta, &aicwf_vif->ap.sta_list, list) {
+ f(sta, reason, aicwf_hw);
+ }
+ break;
+ }
+#endif
+ default:
+ //WARN_ON_ONCE();
+ break;
+ }
+}
+#endif
+
+/**
+ * aicwf_txq_vif_start - Start the TX queues associated with a VIF
+ *
+ * @aicwf_vif: VIF whose queues should be started
+ * @reason: Stop-reason bits to clear
+ * @aicwf_hw: Driver main data
+ *
+ * Iterate over all STAs associated with the VIF and restart their queues for
+ * @reason. This function takes the TX lock.
+ */
+void aicwf_txq_vif_start(struct aicwf_vif *aicwf_vif, u16 reason,
+ struct aicwf_hw *aicwf_hw)
+{
+ struct aicwf_txq *txq;
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_vif_start(aicwf_vif->vif_index);
+#endif
+ spin_lock_bh(&aicwf_hw->tx_lock);
+
+#ifdef CONFIG_AICWF_FULLMAC
+ // Reject if monitor interface
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_MONITOR)
+ goto end;
+
+ if (aicwf_vif->roc_tdls && aicwf_vif->sta.tdls_sta &&
+ aicwf_vif->sta.tdls_sta->tdls.chsw_en) {
+ aicwf_txq_sta_start(aicwf_vif->sta.tdls_sta, reason, aicwf_hw);
+ }
+ if (!aicwf_vif->roc_tdls) {
+ aicwf_txq_vif_for_each_sta(aicwf_hw, aicwf_vif, aicwf_txq_sta_start,
+ reason);
+ }
+
+ txq = aicwf_txq_vif_get(aicwf_vif, NX_BCMC_TXQ_TYPE);
+ aicwf_txq_start(txq, reason);
+ txq = aicwf_txq_vif_get(aicwf_vif, NX_UNK_TXQ_TYPE);
+ aicwf_txq_start(txq, reason);
+
+end:
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+}
+
+/**
+ * aicwf_txq_vif_stop - Stop the TX queues associated with a VIF
+ *
+ * @aicwf_vif: VIF whose queues should be stopped
+ * @reason: Stop-reason bits to set
+ * @aicwf_hw: Driver main data
+ *
+ * Iterate over all STAs associated with the VIF and stop their queues for
+ * @reason. This function takes the TX lock.
+ */
+void aicwf_txq_vif_stop(struct aicwf_vif *aicwf_vif, u16 reason,
+ struct aicwf_hw *aicwf_hw)
+{
+ struct aicwf_txq *txq;
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_vif_stop(aicwf_vif->vif_index);
+#endif
+ spin_lock_bh(&aicwf_hw->tx_lock);
+
+#ifdef CONFIG_AICWF_FULLMAC
+ // Reject if monitor interface
+ if (aicwf_vif->wdev.iftype == NL80211_IFTYPE_MONITOR)
+ goto end;
+
+ aicwf_txq_vif_for_each_sta(aicwf_hw, aicwf_vif, aicwf_txq_sta_stop, reason);
+
+ txq = aicwf_txq_vif_get(aicwf_vif, NX_BCMC_TXQ_TYPE);
+ aicwf_txq_stop(txq, reason);
+ txq = aicwf_txq_vif_get(aicwf_vif, NX_UNK_TXQ_TYPE);
+ aicwf_txq_stop(txq, reason);
+
+end:
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+}
+
+#ifdef CONFIG_AICWF_FULLMAC
+
+/**
+ * aicwf_txq_offchan_start - Start the TX queue for off-channel frames
+ *
+ * @aicwf_hw: Driver main data
+ */
+void aicwf_txq_offchan_start(struct aicwf_hw *aicwf_hw)
+{
+ struct aicwf_txq *txq;
+ int nx_off_chan_txq_idx = NX_OFF_CHAN_TXQ_IDX;
+
+ if (aicwf_hw->chip_ops->is_old_ic)
+ nx_off_chan_txq_idx = NX_OFF_CHAN_TXQ_IDX_FOR_OLD_IC;
+
+ txq = &aicwf_hw->txq[nx_off_chan_txq_idx];
+ spin_lock_bh(&aicwf_hw->tx_lock);
+ aicwf_txq_start(txq, AICWF_TXQ_STOP_CHAN);
+ spin_unlock_bh(&aicwf_hw->tx_lock);
+}
+
+/**
+ * aicwf_txq_sta_switch_vif - Associate TXQs linked to a STA with a new VIF
+ *
+ * @sta: STA whose TX queues must be switched
+ * @old_vif: VIF currently associated with the STA (may no longer be active)
+ * @new_vif: New VIF to associate with the STA
+ *
+ * This function will switch the vif (i.e. the netdev) associated to all STA's
+ * TX queues. This is used when AP_VLAN interfaces are created or removed.
+ */
+void aicwf_txq_sta_switch_vif(struct aicwf_sta *sta, struct aicwf_vif *old_vif,
+ struct aicwf_vif *new_vif)
+{
+ struct aicwf_hw *aicwf_hw = new_vif->aicwf_hw;
+ struct aicwf_txq *txq;
+ int i;
+
+ /* start TXQ on the new interface, and update ndev field in txq */
+ if (!netif_carrier_ok(new_vif->ndev))
+ netif_carrier_on(new_vif->ndev);
+ txq = aicwf_txq_sta_get(sta, 0, aicwf_hw);
+ for (i = 0; i < NX_NB_TID_PER_STA; i++, txq++) {
+ txq->ndev = new_vif->ndev;
+ netif_wake_subqueue(txq->ndev, txq->ndev_idx);
+ }
+}
+#endif /* CONFIG_AICWF_FULLMAC */
+
+/******************************************************************************
+ * TXQ queue/schedule functions
+ *****************************************************************************/
+/**
+ * aicwf_txq_queue_skb - Queue a buffer in a TX queue
+ *
+ * @skb: Buffer to queue
+ * @txq: TX Queue in which the buffer must be added
+ * @aicwf_hw: Driver main data
+ * @retry: Should it be queued in the retry list
+ *
+ * @return: Return 1 if txq has been added to hwq list, 0 otherwise
+ *
+ * Add a buffer in the buffer list of the TX queue
+ * and add this TX queue in the HW queue list if the txq is not stopped.
+ * If this is a retry packet it is added after the last retry packet or at the
+ * beginning if there is no retry packet queued.
+ *
+ * If the STA is in PS mode and this is the first packet queued for this txq
+ * update TIM.
+ *
+ * To be called with tx_lock hold
+ */
+int aicwf_txq_queue_skb(struct sk_buff *skb, struct aicwf_txq *txq,
+ struct aicwf_hw *aicwf_hw, bool retry)
+{
+#ifdef CONFIG_AICWF_FULLMAC
+ if (unlikely(txq->sta && txq->sta->ps.active)) {
+ txq->sta->ps.pkt_ready[txq->ps_id]++;
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_ps_queue(txq->sta);
+#endif
+ if (txq->sta->ps.pkt_ready[txq->ps_id] == 1)
+ aicwf_set_traffic_status(aicwf_hw, txq->sta, true, txq->ps_id);
+ }
+#endif
+
+ if (!retry) {
+ /* add buffer in the sk_list */
+ skb_queue_tail(&txq->sk_list, skb);
+ } else {
+ if (txq->last_retry_skb)
+ skb_append(txq->last_retry_skb, skb, &txq->sk_list);
+ else
+ skb_queue_head(&txq->sk_list, skb);
+
+ txq->last_retry_skb = skb;
+ txq->nb_retry++;
+ }
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_queue_skb(skb, txq, retry);
+#endif
+ /* Flowctrl corresponding netdev queue if needed */
+#ifdef CONFIG_AICWF_FULLMAC
+#ifndef CONFIG_AIC8800_ONE_TXQ
+
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+ if (txq->ndev_idx != NDEV_NO_TXQ &&
+ ((skb_queue_len(&txq->sk_list) > AICWF_NDEV_FLOW_CTRL_STOP) &&
+ !aicwf_hw->sdiodev->flowctrl)) {
+#else
+ /* If too many buffer are queued for this TXQ stop netdev queue */
+ if (txq->ndev_idx != NDEV_NO_TXQ &&
+ (skb_queue_len(&txq->sk_list) > AICWF_NDEV_FLOW_CTRL_STOP)) {
+#endif
+
+ txq->status |= AICWF_TXQ_NDEV_FLOW_CTRL;
+ netif_stop_subqueue(txq->ndev, txq->ndev_idx);
+#ifdef CREATE_TRACE_POINT
+ trace_txq_flowctrl_stop(txq);
+#endif
+ }
+#endif /* CONFIG_AIC8800_ONE_TXQ */
+#else /* ! CONFIG_AICWF_FULLMAC */
+
+ if (!retry && ++txq->hwq->len == txq->hwq->len_stop) {
+ trace_hwq_flowctrl_stop(txq->hwq->id);
+ ieee80211_stop_queue(aicwf_hw->hw, txq->hwq->id);
+ aicwf_hw->stats.queues_stops++;
+ }
+#endif /* CONFIG_AICWF_FULLMAC */
+
+ /* add it in the hwq list if not stopped and not yet present */
+ if (!aicwf_txq_is_stopped(txq)) {
+ aicwf_txq_add_to_hw_list(txq);
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * aicwf_txq_confirm_any - Process buffer confirmed by fw
+ *
+ * @aicwf_hw: Driver main data
+ * @txq: TX Queue
+ * @hwq: HW Queue
+ * @sw_txhdr: software descriptor of the confirmed packet
+ *
+ * Process a buffer returned by the fw. It doesn't check buffer status
+ * and only does systematic counter update:
+ * - hw credit
+ * - buffer pushed to fw
+ *
+ * To be called with tx_lock hold
+ */
+void aicwf_txq_confirm_any(struct aicwf_hw *aicwf_hw, struct aicwf_txq *txq,
+ struct aicwf_hwq *hwq, struct aicwf_sw_txhdr *sw_txhdr)
+{
+ int user = 0;
+
+#ifdef CONFIG_AICWF_MUMIMO_TX
+ user = AICWF_MUMIMO_INFO_POS_ID(sw_txhdr->desc.host.mumimo_info);
+
+ if (txq->idx != TXQ_INACTIVE && txq->pkt_pushed[user] == 1 &&
+ txq->status & AICWF_TXQ_STOP_MU_POS)
+ aicwf_txq_start(txq, AICWF_TXQ_STOP_MU_POS);
+
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+
+ if (txq->pkt_pushed[user])
+ txq->pkt_pushed[user]--;
+
+ hwq->need_processing = true;
+ aicwf_hw->stats.cfm_balance[hwq->id]--;
+}
+
+/******************************************************************************
+ * HWQ processing
+ *****************************************************************************/
+static inline bool aicwf_txq_take_mu_lock(struct aicwf_hw *aicwf_hw)
+{
+ bool res = false;
+#ifdef CONFIG_AICWF_MUMIMO_TX
+ if (aicwf_hw->mod_params->mutx)
+ res = (down_trylock(&aicwf_hw->mu.lock) == 0);
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+ return res;
+}
+
+static inline void aicwf_txq_release_mu_lock(struct aicwf_hw *aicwf_hw)
+{
+#ifdef CONFIG_AICWF_MUMIMO_TX
+ up(&aicwf_hw->mu.lock);
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+}
+
+static inline void aicwf_txq_set_mu_info(struct aicwf_hw *aicwf_hw,
+ struct aicwf_txq *txq, int group_id,
+ int pos)
+{
+#ifdef CONFIG_AICWF_MUMIMO_TX
+ trace_txq_select_mu_group(txq, group_id, pos);
+ if (group_id) {
+ txq->mumimo_info = group_id | (pos << 6);
+ aicwf_mu_set_active_group(aicwf_hw, group_id);
+ } else {
+ txq->mumimo_info = 0;
+ }
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+}
+
+static inline s8 aicwf_txq_get_credits(struct aicwf_txq *txq)
+{
+ s8 cred = txq->credits;
+ /*
+ * if destination is in PS mode, push_limit indicates the maximum
+ * number of packet that can be pushed on this txq.
+ */
+ if (txq->push_limit && cred > txq->push_limit)
+ cred = txq->push_limit;
+ return cred;
+}
+
+/**
+ * skb_queue_extract - Extract buffer from skb list
+ *
+ * @list: List of skb to extract from
+ * @head: List of skb to append to
+ * @nb_elt: Number of skb to extract
+ *
+ * extract the first @nb_elt of @list and append them to @head
+ * It is assume that:
+ * - @list contains more that @nb_elt
+ * - There is no need to take @list nor @head lock to modify them
+ */
+static inline void skb_queue_extract(struct sk_buff_head *list,
+ struct sk_buff_head *head, int nb_elt)
+{
+ int i;
+ struct sk_buff *first, *last, *ptr;
+
+ ptr = list->next;
+ first = ptr;
+ for (i = 0; i < nb_elt; i++)
+ ptr = ptr->next;
+
+ last = ptr->prev;
+
+ /* unlink nb_elt in list */
+ list->qlen -= nb_elt;
+ list->next = ptr;
+ ptr->prev = (struct sk_buff *)list;
+
+ /* append nb_elt at end of head */
+ head->qlen += nb_elt;
+ last->next = (struct sk_buff *)head;
+ head->prev->next = first;
+ first->prev = head->prev;
+ head->prev = last;
+}
+
+#ifdef CONFIG_MAC80211_TXQ
+/**
+ * aicwf_txq_mac80211_dequeue - Dequeue buffer from mac80211 txq and
+ * add them to push list
+ *
+ * @aicwf_hw: Main driver data
+ * @sk_list: List of buffer to push (initialized without lock)
+ * @txq: TXQ to dequeue buffers from
+ * @max: Max number of buffer to dequeue
+ *
+ * Dequeue buffer from mac80211 txq, prepare them for transmission and chain
+ * them to the list of buffer to push.
+ *
+ * Return: %true if no buffers remain in the mac80211 TX queue, otherwise
+ * %false.
+ */
+static bool aicwf_txq_mac80211_dequeue(struct aicwf_hw *aicwf_hw,
+ struct sk_buff_head *sk_list,
+ struct aicwf_txq *txq, int max)
+{
+ struct ieee80211_txq *mac_txq;
+ struct sk_buff *skb;
+ unsigned long mac_txq_len;
+
+ if (txq->nb_ready_mac80211 == NOT_MAC80211_TXQ)
+ return true;
+
+ mac_txq = container_of((void *)txq, struct ieee80211_txq, drv_priv);
+
+ for (; max > 0; max--) {
+ skb = aicwf_tx_dequeue_prep(aicwf_hw, mac_txq);
+ if (!skb)
+ return true;
+
+ __skb_queue_tail(sk_list, skb);
+ }
+
+ /*
+ * re-read mac80211 txq current length.
+ * It is mainly for debug purpose to trace dropped packet. There is no
+ * problems to have nb_ready_mac80211 != actual mac80211 txq length
+ */
+ ieee80211_txq_get_depth(mac_txq, &mac_txq_len, NULL);
+ if (txq->nb_ready_mac80211 > mac_txq_len)
+ trace_txq_drop(txq, txq->nb_ready_mac80211 - mac_txq_len);
+ txq->nb_ready_mac80211 = mac_txq_len;
+
+ return (txq->nb_ready_mac80211 == 0);
+}
+#endif
+
+/**
+ * aicwf_txq_get_skb_to_push - Get list of buffer to push for one txq
+ *
+ * @aicwf_hw: main driver data
+ * @hwq: HWQ on wich buffers will be pushed
+ * @txq: TXQ to get buffers from
+ * @user: user position to use
+ * @sk_list_push: list to update
+ *
+ *
+ * This function will returned a list of buffer to push for one txq.
+ * It will take into account the number of credit of the HWQ for this user
+ * position and TXQ (and push_limit).
+ * This allow to get a list that can be pushed without having to test for
+ * hwq/txq status after each push
+ *
+ * If a MU group has been selected for this txq, it will also update the
+ * counter for the group
+ *
+ * Return: %true if the TX queue has no ready buffer after this batch,
+ * otherwise %false.
+ */
+static bool aicwf_txq_get_skb_to_push(struct aicwf_hw *aicwf_hw,
+ struct aicwf_hwq *hwq, struct aicwf_txq *txq,
+ int user,
+ struct sk_buff_head *sk_list_push)
+{
+ int nb_ready = skb_queue_len(&txq->sk_list);
+ int credits = aicwf_txq_get_credits(txq);
+ bool res = false;
+
+ __skb_queue_head_init(sk_list_push);
+
+ if (credits >= nb_ready) {
+ skb_queue_splice_init(&txq->sk_list, sk_list_push);
+#ifdef CONFIG_MAC80211_TXQ
+ res = aicwf_txq_mac80211_dequeue(aicwf_hw, sk_list_push, txq,
+ credits - nb_ready);
+ credits = skb_queue_len(sk_list_push);
+#else
+ res = true;
+ credits = nb_ready;
+#endif
+ } else {
+ skb_queue_extract(&txq->sk_list, sk_list_push, credits);
+
+ /*
+ * When processing PS service period (i.e. push_limit != 0), no longer
+ * process this txq if the buffers extracted will complete the SP for
+ * this txq
+ */
+ if (txq->push_limit && credits == txq->push_limit)
+ res = true;
+ }
+
+ aicwf_mu_set_active_sta(aicwf_hw, aicwf_txq_2_sta(txq), credits);
+
+ return res;
+}
+
+/**
+ * aicwf_txq_select_user - Select User queue for a txq
+ *
+ * @aicwf_hw: main driver data
+ * @mu_lock: true is MU lock is taken
+ * @txq: TXQ to select MU group for
+ * @hwq: HWQ for the TXQ
+ * @user: Updated with user position selected
+ *
+ * Return: %true if the TX queue can be processed, otherwise %false.
+ *
+ * This function selects the MU group to use for a TXQ.
+ * The selection is done as follow:
+ *
+ * - return immediately for STA that don't belongs to any group and select
+ * group 0 / user 0
+ *
+ * - If MU tx is disabled (by user mutx_on, or because mu group are being
+ * updated !mu_lock), select group 0 / user 0
+ *
+ * - Use the best group selected by @aicwf_mu_group_sta_select.
+ *
+ * Each time a group is selected (except for the first case where sta
+ * doesn't belongs to a MU group), the function checks that no buffer is
+ * pending for this txq on another user position. If this is the case stop
+ * the txq (AICWF_TXQ_STOP_MU_POS) and return false.
+ *
+ */
+static bool aicwf_txq_select_user(struct aicwf_hw *aicwf_hw, bool mu_lock,
+ struct aicwf_txq *txq, struct aicwf_hwq *hwq,
+ int *user)
+{
+ int pos = 0;
+#ifdef CONFIG_AICWF_MUMIMO_TX
+ int id, group_id = 0;
+ struct aicwf_sta *sta = aicwf_txq_2_sta(txq);
+
+ /* for sta that belong to no group return immediately */
+ if (!sta || !sta->group_info.cnt)
+ goto end;
+
+ /* If MU is disabled, need to check user */
+ if (!aicwf_hw->mod_params->mutx_on || !mu_lock)
+ goto check_user;
+
+ /* Use the "best" group selected */
+ group_id = sta->group_info.group;
+
+ if (group_id > 0)
+ pos = aicwf_mu_group_sta_get_pos(aicwf_hw, sta, group_id);
+
+check_user:
+ /* check that we can push on this user position */
+#if NX_USER_MAX == 2
+ id = (pos + 1) & 0x1;
+ if (txq->pkt_pushed[id]) {
+ aicwf_txq_stop(txq, AICWF_TXQ_STOP_MU_POS);
+ return false;
+ }
+
+#else
+ for (id = 0; id < NX_USER_MAX; id++) {
+ if (id != pos && txq->pkt_pushed[id]) {
+ aicwf_txq_stop(txq, AICWF_TXQ_STOP_MU_POS);
+ return false;
+ }
+ }
+#endif
+
+end:
+ aicwf_txq_set_mu_info(aicwf_hw, txq, group_id, pos);
+#endif /* CONFIG_AICWF_MUMIMO_TX */
+
+ *user = pos;
+ return true;
+}
+
+#define ALL_HWQ_MASK ((1 << NX_USER_MAX) - 1)
+
+/**
+ * aicwf_hwq_process - Process one HW queue list
+ *
+ * @aicwf_hw: Driver main data
+ * @hwq: HW queue to process
+ *
+ * Iterate over all TX queues linked to this hardware queue and push as many
+ * buffers as possible. A TX queue on the list has at least one buffer.
+ * - If a TX queue has no buffer, remove it and process the next queue.
+ * - If a TX queue has no credit or reaches its push limit, remove it and
+ * process the next queue.
+ * - If the hardware queue is full, preserve fair ordering for the next call.
+ *
+ * To be called when HW queue list is modified:
+ * - when a buffer is pushed on a TX queue
+ * - when new credits are received
+ * - when a STA returns from Power Save mode or receives traffic request.
+ * - when Channel context change
+ *
+ * Context: Called with the TX lock held.
+ */
+void aicwf_hwq_process(struct aicwf_hw *aicwf_hw, struct aicwf_hwq *hwq)
+{
+ struct aicwf_txq *txq, *next;
+ int user;
+ bool mu_enable;
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_process_hw_queue(hwq);
+#endif
+ hwq->need_processing = false;
+
+ mu_enable = aicwf_txq_take_mu_lock(aicwf_hw);
+
+ list_for_each_entry_safe(txq, next, &hwq->list, sched_list) {
+ struct aicwf_txhdr *txhdr = NULL;
+ struct sk_buff_head sk_list_push;
+ struct sk_buff *skb;
+ bool txq_empty;
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_process_txq(txq);
+#endif
+ /* sanity check for debug */
+ WARN_ON_ONCE(!(txq->status & AICWF_TXQ_IN_HWQ_LIST));
+ if (txq->idx == TXQ_INACTIVE) {
+ dev_dbg(aicwf_hw->dev, "txq->idx == TXQ_INACTIVE\n");
+ aicwf_txq_del_from_hw_list(txq);
+ aicwf_txq_flush(aicwf_hw, txq);
+ continue;
+ }
+ WARN_ON_ONCE(txq->idx == TXQ_INACTIVE);
+ WARN_ON_ONCE(txq->credits <= 0);
+ WARN_ON_ONCE(!aicwf_txq_skb_ready(txq));
+
+ if (!aicwf_txq_select_user(aicwf_hw, mu_enable, txq, hwq, &user)) {
+ dev_dbg(aicwf_hw->dev, "select user:%d\n", user);
+ continue;
+ }
+
+ txq_empty =
+ aicwf_txq_get_skb_to_push(aicwf_hw, hwq, txq, user, &sk_list_push);
+ while ((skb = __skb_dequeue(&sk_list_push)) != NULL) {
+ txhdr = (struct aicwf_txhdr *)skb->data;
+ aicwf_tx_push(aicwf_hw, txhdr, 0);
+ }
+
+ if (txq_empty) {
+ aicwf_txq_del_from_hw_list(txq);
+ txq->pkt_sent = 0;
+ } else if (aicwf_txq_is_scheduled(txq)) {
+ /* txq not empty,
+ * To avoid starving need to process other txq in the list
+ * For better aggregation, need to send "as many consecutive
+ * pkt as possible" for he same txq
+ * ==> Add counter to trigger txq switch
+ */
+ if (txq->pkt_sent > hwq->size) {
+ txq->pkt_sent = 0;
+ list_rotate_left(&hwq->list);
+ }
+ }
+
+#ifdef CONFIG_AICWF_FULLMAC
+ /* Unable to complete PS traffic request because of hwq credit */
+ if (txq->push_limit && txq->sta) {
+ if (txq->ps_id == LEGACY_PS_ID) {
+ /* for legacy PS abort SP and wait next ps-poll */
+ txq->sta->ps.sp_cnt[txq->ps_id] -= txq->push_limit;
+ txq->push_limit = 0;
+ }
+ /* for u-apsd need to complete the SP to send EOSP frame */
+ }
+#ifndef CONFIG_AIC8800_ONE_TXQ
+ /* restart netdev queue if number of queued buffer is below threshold */
+#ifdef CONFIG_AIC8800_TX_NETIF_FLOWCTRL
+ if (unlikely(txq->status & AICWF_TXQ_NDEV_FLOW_CTRL) &&
+ (skb_queue_len(&txq->sk_list) < AICWF_NDEV_FLOW_CTRL_RESTART)) {
+#else
+ if (unlikely(txq->status & AICWF_TXQ_NDEV_FLOW_CTRL) &&
+ skb_queue_len(&txq->sk_list) < AICWF_NDEV_FLOW_CTRL_RESTART) {
+#endif
+
+ txq->status &= ~AICWF_TXQ_NDEV_FLOW_CTRL;
+ netif_wake_subqueue(txq->ndev, txq->ndev_idx);
+#ifdef AIC8800_CREATE_TRACE_POINTS
+ trace_txq_flowctrl_restart(txq);
+#endif
+ }
+#endif /* CONFIG_AIC8800_ONE_TXQ */
+#endif /* CONFIG_AICWF_FULLMAC */
+ }
+
+ if (mu_enable)
+ aicwf_txq_release_mu_lock(aicwf_hw);
+}
+
+/**
+ * aicwf_hwq_process_all - Process all HW queue list
+ *
+ * @aicwf_hw: Driver main data
+ *
+ * Loop over all HWQ, and process them if needed
+ * To be called with tx_lock hold
+ */
+void aicwf_hwq_process_all(struct aicwf_hw *aicwf_hw)
+{
+ int id;
+
+ aicwf_mu_group_sta_select(aicwf_hw);
+
+ for (id = ARRAY_SIZE(aicwf_hw->hwq) - 1; id >= 0; id--) {
+ if (aicwf_hw->hwq[id].need_processing)
+ aicwf_hwq_process(aicwf_hw, &aicwf_hw->hwq[id]);
+ }
+}
+
+static const int nx_txdesc_cnt[] = {
+ NX_TXDESC_CNT0, NX_TXDESC_CNT1, NX_TXDESC_CNT2, NX_TXDESC_CNT3,
+#if NX_TXQ_CNT == 5
+ NX_TXDESC_CNT4,
+#endif
+};
+
+/**
+ * aicwf_hwq_init - Initialize all hwq structures
+ *
+ * @aicwf_hw: Driver main data
+ *
+ */
+void aicwf_hwq_init(struct aicwf_hw *aicwf_hw)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(aicwf_hw->hwq); i++) {
+ struct aicwf_hwq *hwq = &aicwf_hw->hwq[i];
+
+ hwq->id = i;
+ hwq->size = nx_txdesc_cnt[i];
+ INIT_LIST_HEAD(&hwq->list);
+ }
+}
diff --git a/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq_prealloc.c b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq_prealloc.c
new file mode 100644
index 000000000000..695a208af7f1
--- /dev/null
+++ b/drivers/net/wireless/aic/aic8800_fdrv/aicwf_txq_prealloc.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ ******************************************************************************
+ *
+ * Copyright (C) 2020 AIC semiconductor.
+ *
+ * @brief txq prealloc mem
+ *
+ ******************************************************************************
+ */
+#include <linux/bug.h>
+#include <linux/printk.h>
+#include <linux/slab.h>
+
+#include "aicwf_txq_prealloc.h"
+
+#define MAX_TXQ_SIZE (100 * 1024)
+
+/**
+ * aicwf_prealloc_txq_alloc - Allocate or reuse the preallocated TX queue
+ * @prealloc: Queue holder owned by the SDIO device
+ * @size: Required queue size in bytes
+ *
+ * Return: Pointer to the queue buffer, or %NULL if allocation failed.
+ */
+void *aicwf_prealloc_txq_alloc(struct aicwf_prealloc_txq *prealloc,
+ size_t size)
+{
+ WARN_ON_ONCE(size > MAX_TXQ_SIZE);
+
+ if (prealloc->txq && prealloc->size != size) {
+ pr_debug("size is diff will to be kzalloc\n");
+ kfree(prealloc->txq);
+ prealloc->txq = NULL;
+ }
+
+ if (!prealloc->txq) {
+ prealloc->txq = kzalloc(size, GFP_KERNEL);
+ prealloc->size = size;
+ } else {
+ pr_debug("txq not need to kzalloc\n");
+ }
+
+ return prealloc->txq;
+}
+
+/**
+ * aicwf_prealloc_txq_free - Free the preallocated TX queue
+ * @prealloc: Queue holder owned by the SDIO device
+ */
+void aicwf_prealloc_txq_free(struct aicwf_prealloc_txq *prealloc)
+{
+ kfree(prealloc->txq);
+ prealloc->txq = NULL;
+}
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-16 7:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 7:23 [PATCH wireless-next v5 0/4] wifi: aic: Add AIC8800D80 and D80N SDIO FullMAC driver Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 3/4] wifi: aic: Add the AIC8800D80 and D80N " Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 2/4] wifi: aic: Add firmware protocol and SDIO chip support Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 1/4] dt-bindings: net: wireless: Add AIC8800D80 SDIO Wi-Fi Yanli Yang
2026-11-16 7:23 ` [PATCH wireless-next v5 4/4] wifi: aic: Integrate the AIC8800 SDIO driver Yanli Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®